ShopProduct.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 易而优团队 by 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\admin\controller;
  14. use think\Page;
  15. use think\Db;
  16. use app\common\logic\ArctypeLogic;
  17. use app\admin\logic\ProductLogic;
  18. use app\admin\logic\ProductSpecLogic; // 用于商品规格逻辑功能处理
  19. class ShopProduct extends Base
  20. {
  21. // 模型标识
  22. public $nid = 'product';
  23. // 模型ID
  24. public $channeltype = '';
  25. // 表单类型
  26. public $attrInputTypeArr = array();
  27. public function _initialize() {
  28. parent::_initialize();
  29. $this->language_access(); // 多语言功能操作权限
  30. $channeltype_list = config('global.channeltype_list');
  31. $this->channeltype = $channeltype_list[$this->nid];
  32. empty($this->channeltype) && $this->channeltype = 2;
  33. $this->attrInputTypeArr = config('global.attr_input_type_arr');
  34. $this->assign('nid', $this->nid);
  35. $this->assign('channeltype', $this->channeltype);
  36. // 产品属性表
  37. $this->product_attrlist_db = Db::name('product_attrlist');
  38. // 商城产品参数表
  39. $this->shop_product_attrlist_db = Db::name('shop_product_attrlist');
  40. // 产品规格表
  41. $this->product_spec_preset_db = Db::name('product_spec_preset');
  42. // 产品规格值表
  43. $this->product_spec_value_db = Db::name('product_spec_value');
  44. // 规格业务层
  45. $this->ProductSpecLogic = new ProductSpecLogic;
  46. // 规格名称模型层
  47. $this->ProductSpecPresetModel = model('ProductSpecPreset');
  48. // 规格值模型层
  49. $this->ProductSpecValueModel = model('ProductSpecValue');
  50. }
  51. /**
  52. * 文章列表
  53. */
  54. public function index()
  55. {
  56. $assign_data = array();
  57. $condition = array();
  58. // 获取到所有GET参数
  59. $param = input('param.');
  60. $flag = input('flag/s');
  61. $typeid = input('typeid/d', 0);
  62. $begin = strtotime(input('add_time_begin'));
  63. $end = strtotime(input('add_time_end'));
  64. // 应用搜索条件
  65. foreach (['keywords','typeid','flag','is_release'] as $key) {
  66. if (isset($param[$key]) && $param[$key] !== '') {
  67. if ($key == 'keywords') {
  68. $condition['a.title'] = array('LIKE', "%{$param[$key]}%");
  69. } else if ($key == 'typeid') {
  70. $typeid = $param[$key];
  71. $hasRow = model('Arctype')->getHasChildren($typeid);
  72. $typeids = get_arr_column($hasRow, 'id');
  73. /*权限控制 by 小虎哥*/
  74. $admin_info = session('admin_info');
  75. if (0 < intval($admin_info['role_id'])) {
  76. $auth_role_info = $admin_info['auth_role_info'];
  77. if(! empty($auth_role_info)){
  78. if(! empty($auth_role_info['permission']['arctype'])){
  79. if (!empty($typeid)) {
  80. $typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
  81. }
  82. }
  83. }
  84. }
  85. /*--end*/
  86. $condition['a.typeid'] = array('IN', $typeids);
  87. } else if ($key == 'flag') {
  88. if ('is_release' == $param[$key]) {
  89. $condition['a.users_id'] = array('gt', 0);
  90. } else {
  91. $condition['a.'.$param[$key]] = array('eq', 1);
  92. }
  93. // } else if ($key == 'is_release') {
  94. // if (0 < intval($param[$key])) {
  95. // $condition['a.users_id'] = array('gt', intval($param[$key]));
  96. // }
  97. } else {
  98. $condition['a.'.$key] = array('eq', $param[$key]);
  99. }
  100. }
  101. }
  102. /*权限控制 by 小虎哥*/
  103. $admin_info = session('admin_info');
  104. if (0 < intval($admin_info['role_id'])) {
  105. $auth_role_info = $admin_info['auth_role_info'];
  106. if(! empty($auth_role_info)){
  107. if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
  108. $condition['a.admin_id'] = $admin_info['admin_id'];
  109. }
  110. }
  111. }
  112. /*--end*/
  113. // 时间检索
  114. if ($begin > 0 && $end > 0) {
  115. $condition['a.add_time'] = array('between',"$begin,$end");
  116. } else if ($begin > 0) {
  117. $condition['a.add_time'] = array('egt', $begin);
  118. } else if ($end > 0) {
  119. $condition['a.add_time'] = array('elt', $end);
  120. }
  121. // 模型ID
  122. $condition['a.channel'] = array('eq', $this->channeltype);
  123. // 多语言
  124. $condition['a.lang'] = array('eq', $this->admin_lang);
  125. // 回收站
  126. $condition['a.is_del'] = array('eq', 0);
  127. /*自定义排序*/
  128. $orderby = input('param.orderby/s');
  129. $orderway = input('param.orderway/s');
  130. if (!empty($orderby)) {
  131. $orderby = "a.{$orderby} {$orderway}";
  132. $orderby .= ", a.aid desc";
  133. } else {
  134. $orderby = "a.aid desc";
  135. }
  136. /*end*/
  137. /**
  138. * 数据查询,搜索出主键ID的值
  139. */
  140. $count = DB::name('archives')->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
  141. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  142. $list = DB::name('archives')
  143. ->field("a.aid")
  144. ->alias('a')
  145. ->where($condition)
  146. ->order($orderby)
  147. ->limit($Page->firstRow.','.$Page->listRows)
  148. ->getAllWithIndex('aid');
  149. /**
  150. * 完善数据集信息
  151. * 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
  152. */
  153. if ($list) {
  154. $aids = array_keys($list);
  155. $fields = "b.*, a.*, a.aid as aid";
  156. $row = DB::name('archives')
  157. ->field($fields)
  158. ->alias('a')
  159. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  160. ->where('a.aid', 'in', $aids)
  161. ->getAllWithIndex('aid');
  162. foreach ($list as $key => $val) {
  163. $row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
  164. $row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']); // 支持子目录
  165. $list[$key] = $row[$val['aid']];
  166. }
  167. }
  168. $show = $Page->show(); // 分页显示输出
  169. $assign_data['page'] = $show; // 赋值分页输出
  170. $assign_data['list'] = $list; // 赋值数据集
  171. $assign_data['pager'] = $Page; // 赋值分页对象
  172. /*允许发布文档列表的栏目*/
  173. $arctype_html = allow_release_arctype($typeid, array($this->channeltype));
  174. $assign_data['arctype_html'] = $arctype_html;
  175. /*--end*/
  176. /*当前栏目信息*/
  177. $assign_data['typeid'] = $typeid; // 栏目ID
  178. $arctype_info = array();
  179. if ($typeid > 0) $arctype_info = M('arctype')->field('typename')->find($typeid);
  180. $assign_data['arctype_info'] = $arctype_info;
  181. /*--end*/
  182. /*选项卡*/
  183. $tab = input('param.tab/d', 3);
  184. $assign_data['tab'] = $tab;
  185. /*--end*/
  186. $this->assign($assign_data);
  187. return $this->fetch();
  188. }
  189. /**
  190. * 添加
  191. */
  192. public function add()
  193. {
  194. if (IS_POST) {
  195. $post = input('post.');
  196. $content = input('post.addonFieldExt.content', '', null);
  197. // 根据标题自动提取相关的关键字
  198. $seo_keywords = $post['seo_keywords'];
  199. if (!empty($seo_keywords)) {
  200. $seo_keywords = str_replace(',', ',', $seo_keywords);
  201. } else {
  202. // $seo_keywords = get_split_word($post['title'], $content);
  203. }
  204. // 自动获取内容第一张图片作为封面图
  205. $is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
  206. $litpic = '';
  207. if ($is_remote == 1) {
  208. $litpic = $post['litpic_remote'];
  209. } else {
  210. $litpic = $post['litpic_local'];
  211. }
  212. if (empty($litpic)) {
  213. $litpic = get_html_first_imgurl($content);
  214. }
  215. $post['litpic'] = $litpic;
  216. /*是否有封面图*/
  217. if (empty($post['litpic'])) {
  218. $is_litpic = 0; // 无封面图
  219. } else {
  220. $is_litpic = 1; // 有封面图
  221. }
  222. // SEO描述
  223. $seo_description = '';
  224. if (empty($post['seo_description']) && !empty($content)) {
  225. $seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
  226. } else {
  227. $seo_description = $post['seo_description'];
  228. }
  229. // 外部链接跳转
  230. $jumplinks = '';
  231. $is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
  232. if (intval($is_jump) > 0) {
  233. $jumplinks = $post['jumplinks'];
  234. }
  235. // 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
  236. if ($post['type_tempview'] == $post['tempview']) {
  237. unset($post['type_tempview']);
  238. unset($post['tempview']);
  239. }
  240. //处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
  241. if (!empty($post['htmlfilename'])) {
  242. $post['htmlfilename'] = preg_replace("/[^a-zA-Z0-9_-]+/", "", $post['htmlfilename']);
  243. $post['htmlfilename'] = strtolower($post['htmlfilename']);
  244. //判断是否存在相同的自定义文件名
  245. $filenameCount = Db::name('archives')->where([
  246. 'htmlfilename' => $post['htmlfilename'],
  247. ])->count();
  248. if (!empty($filenameCount)) {
  249. $this->error("自定义文件名已存在,请重新设置!");
  250. }
  251. }
  252. // 产品类型
  253. if (!empty($post['prom_type'])) {
  254. if ($post['prom_type_vir'] == 2) {
  255. $post['netdisk_url'] = trim($post['netdisk_url']);
  256. if (empty($post['netdisk_url'])) {
  257. $this->error("网盘地址不能为空!");
  258. }
  259. $post['prom_type'] = 2;
  260. } else if ($post['prom_type_vir'] == 3) {
  261. $post['text_content'] = trim($post['text_content']);
  262. if (empty($post['text_content'])) {
  263. $this->error("虚拟文本内容不能为空!");
  264. }
  265. $post['prom_type'] = 3;
  266. }
  267. }
  268. // --存储数据
  269. $newData = array(
  270. 'typeid'=> empty($post['typeid']) ? 0 : $post['typeid'],
  271. 'channel' => $this->channeltype,
  272. 'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
  273. 'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
  274. 'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
  275. 'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
  276. 'is_jump' => $is_jump,
  277. 'is_litpic' => $is_litpic,
  278. 'jumplinks' => $jumplinks,
  279. 'seo_keywords' => $seo_keywords,
  280. 'seo_description' => $seo_description,
  281. 'admin_id' => session('admin_info.admin_id'),
  282. 'stock_show' => empty($post['stock_show']) ? 0 : $post['stock_show'],
  283. 'lang' => $this->admin_lang,
  284. 'sort_order' => 100,
  285. 'add_time' => strtotime($post['add_time']),
  286. 'update_time' => strtotime($post['add_time']),
  287. );
  288. $data = array_merge($post, $newData);
  289. $aid = Db::name('archives')->insertGetId($data);
  290. $_POST['aid'] = $aid;
  291. if ($aid) {
  292. // ---------后置操作
  293. model('Product')->afterSave($aid, $data, 'add', true);
  294. // ---------end
  295. // 添加产品规格
  296. model('ProductSpecPreset')->ProductSpecInsertAll($aid, $data);
  297. adminLog('新增产品:'.$data['title']);
  298. //虚拟商品保存
  299. if (!empty($post['prom_type']) && in_array($post['prom_type'], [2,3])) {
  300. model('ProductNetdisk')->saveProductNetdisk($aid, $data);
  301. }
  302. // 生成静态页面代码
  303. $successData = [
  304. 'aid' => $aid,
  305. 'tid' => $post['typeid'],
  306. ];
  307. $this->success("操作成功!", url('ShopProduct/index'), $successData);
  308. }
  309. $this->error("操作失败!");
  310. }
  311. $typeid = input('param.typeid/d', 0);
  312. $assign_data['typeid'] = $typeid; // 栏目ID
  313. // 栏目信息
  314. $arctypeInfo = Db::name('arctype')->find($typeid);
  315. /*允许发布文档列表的栏目*/
  316. $arctype_html = allow_release_arctype($typeid, array($this->channeltype));
  317. $assign_data['arctype_html'] = $arctype_html;
  318. /*--end*/
  319. /*自定义字段*/
  320. $addonFieldExtList = model('Field')->getChannelFieldList($this->channeltype);
  321. $channelfieldBindRow = Db::name('channelfield_bind')->where([
  322. 'typeid' => ['IN', [0,$typeid]],
  323. ])->column('field_id');
  324. if (!empty($channelfieldBindRow)) {
  325. foreach ($addonFieldExtList as $key => $val) {
  326. if (!in_array($val['id'], $channelfieldBindRow)) {
  327. unset($addonFieldExtList[$key]);
  328. }
  329. }
  330. }
  331. $assign_data['addonFieldExtList'] = $addonFieldExtList;
  332. $assign_data['aid'] = 0;
  333. /*--end*/
  334. /*可控制的字段列表*/
  335. $assign_data['ifcontrolRow'] = Db::name('channelfield')->field('id,name')->where([
  336. 'channel_id' => $this->channeltype,
  337. 'ifmain' => 1,
  338. 'ifeditable' => 1,
  339. 'ifcontrol' => 0,
  340. 'status' => 1,
  341. ])->getAllWithIndex('name');
  342. // 阅读权限
  343. $arcrank_list = get_arcrank_list();
  344. $assign_data['arcrank_list'] = $arcrank_list;
  345. /*产品参数*/
  346. $assign_data['canshu'] = $this->ajax_get_attr_input($typeid);
  347. /*--end*/
  348. /*模板列表*/
  349. $archivesLogic = new \app\admin\logic\ArchivesLogic;
  350. $templateList = $archivesLogic->getTemplateList($this->nid);
  351. $this->assign('templateList', $templateList);
  352. /*--end*/
  353. /*默认模板文件*/
  354. $tempview = 'view_'.$this->nid.'.'.config('template.view_suffix');
  355. !empty($arctypeInfo['tempview']) && $tempview = $arctypeInfo['tempview'];
  356. $this->assign('tempview', $tempview);
  357. /*--end*/
  358. // 商城配置
  359. $shopConfig = getUsersConfigData('shop');
  360. $assign_data['shopConfig'] = $shopConfig;
  361. // 商品规格
  362. if (isset($shopConfig['shop_open_spec']) && 1 == $shopConfig['shop_open_spec']) {
  363. // 预设值名称
  364. $assign_data['preset_value'] = Db::name('product_spec_preset')->where('lang',$this->admin_lang)->field('preset_id,preset_mark_id,preset_name')->group('preset_mark_id')->order('preset_mark_id desc')->select();
  365. }
  366. /*商品参数列表*/
  367. $where = [
  368. 'is_del' => 0,
  369. 'status' => 1
  370. ];
  371. $assign_data['AttrList'] = $this->shop_product_attrlist_db->where($where)->order('sort_order asc')->select();
  372. /*END*/
  373. // URL模式
  374. $tpcache = config('tpcache');
  375. $assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
  376. $this->assign($assign_data);
  377. return $this->fetch();
  378. }
  379. /**
  380. * 编辑
  381. */
  382. public function edit()
  383. {
  384. if (IS_POST) {
  385. $post = input('post.');
  386. $typeid = input('post.typeid/d', 0);
  387. $content = input('post.addonFieldExt.content', '', null);
  388. // 根据标题自动提取相关的关键字
  389. $seo_keywords = $post['seo_keywords'];
  390. if (!empty($seo_keywords)) {
  391. $seo_keywords = str_replace(',', ',', $seo_keywords);
  392. } else {
  393. // $seo_keywords = get_split_word($post['title'], $content);
  394. }
  395. // 自动获取内容第一张图片作为封面图
  396. $is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
  397. $litpic = '';
  398. if ($is_remote == 1) {
  399. $litpic = $post['litpic_remote'];
  400. } else {
  401. $litpic = $post['litpic_local'];
  402. }
  403. if (empty($litpic)) {
  404. $litpic = get_html_first_imgurl($content);
  405. }
  406. $post['litpic'] = $litpic;
  407. /*是否有封面图*/
  408. if (empty($post['litpic'])) {
  409. $is_litpic = 0; // 无封面图
  410. } else {
  411. $is_litpic = !empty($post['is_litpic']) ? $post['is_litpic'] : 0; // 有封面图
  412. }
  413. // SEO描述
  414. $seo_description = '';
  415. if (empty($post['seo_description']) && !empty($content)) {
  416. $seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
  417. } else {
  418. $seo_description = $post['seo_description'];
  419. }
  420. // --外部链接
  421. $jumplinks = '';
  422. $is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
  423. if (intval($is_jump) > 0) {
  424. $jumplinks = $post['jumplinks'];
  425. }
  426. // 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
  427. if ($post['type_tempview'] == $post['tempview']) {
  428. unset($post['type_tempview']);
  429. unset($post['tempview']);
  430. }
  431. // 产品类型
  432. if (!empty($post['prom_type'])) {
  433. if ($post['prom_type_vir'] == 2) {
  434. $post['netdisk_url'] = trim($post['netdisk_url']);
  435. if (empty($post['netdisk_url'])) {
  436. $this->error("网盘地址不能为空!");
  437. }
  438. $post['prom_type'] = 2;
  439. } else if ($post['prom_type_vir'] == 3) {
  440. $post['text_content'] = trim($post['text_content']);
  441. if (empty($post['text_content'])) {
  442. $this->error("虚拟文本内容不能为空!");
  443. }
  444. $post['prom_type'] = 3;
  445. }
  446. }
  447. //处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
  448. if (!empty($post['htmlfilename'])) {
  449. $post['htmlfilename'] = preg_replace("/[^a-zA-Z0-9_-]+/", "", $post['htmlfilename']);
  450. $post['htmlfilename'] = strtolower($post['htmlfilename']);
  451. //判断是否存在相同的自定义文件名
  452. $filenameCount = Db::name('archives')->where([
  453. 'aid' => ['NEQ', $post['aid']],
  454. 'htmlfilename' => $post['htmlfilename'],
  455. ])->count();
  456. if (!empty($filenameCount)) {
  457. $this->error("自定义文件名已存在,请重新设置!");
  458. }
  459. }
  460. // 同步栏目切换模型之后的文档模型
  461. $channel = Db::name('arctype')->where(['id'=>$typeid])->getField('current_channel');
  462. // --存储数据
  463. $newData = array(
  464. 'typeid'=> $typeid,
  465. 'channel' => $channel,
  466. 'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
  467. 'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
  468. 'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
  469. 'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
  470. 'is_jump' => $is_jump,
  471. 'is_litpic' => $is_litpic,
  472. 'jumplinks' => $jumplinks,
  473. 'seo_keywords' => $seo_keywords,
  474. 'seo_description' => $seo_description,
  475. 'stock_show' => empty($post['stock_show']) ? 0 : $post['stock_show'],
  476. 'add_time' => strtotime($post['add_time']),
  477. 'update_time' => getTime(),
  478. );
  479. $data = array_merge($post, $newData);
  480. $r = Db::name('archives')->where([
  481. 'aid' => $data['aid'],
  482. 'lang' => $this->admin_lang,
  483. ])->update($data);
  484. if ($r) {
  485. // ---------后置操作
  486. model('Product')->afterSave($data['aid'], $data, 'edit', true);
  487. // 更新规格名称数据
  488. // model('ProductSpecData')->ProducSpecNameEditSave($data);
  489. //虚拟商品保存
  490. if (!empty($post['prom_type']) && in_array($post['prom_type'], [2,3])) {
  491. model('ProductNetdisk')->saveProductNetdisk($data['aid'], $data);
  492. }
  493. // 更新规格值及金额数据
  494. model('ProductSpecValue')->ProducSpecValueEditSave($data);
  495. // ---------end
  496. adminLog('编辑产品:'.$data['title']);
  497. // 生成静态页面代码
  498. $successData = [
  499. 'aid' => $data['aid'],
  500. 'tid' => $typeid,
  501. ];
  502. $this->success("操作成功!", url('ShopProduct/index'), $successData);
  503. }
  504. $this->error("操作失败!");
  505. }
  506. $assign_data = array();
  507. $id = input('id/d');
  508. $info = model('Product')->getInfo($id);
  509. // 获取规格数据信息
  510. // 包含:SpecSelectName、HtmlTable、spec_mark_id_arr、preset_value
  511. $assign_data = model('ProductSpecData')->GetProductSpecData($id);
  512. if (empty($info)) {
  513. $this->error('数据不存在,请联系管理员!');
  514. exit;
  515. }
  516. /*兼容采集没有归属栏目的文档*/
  517. if (empty($info['channel'])) {
  518. $channelRow = Db::name('channeltype')->field('id as channel')
  519. ->where('id',$this->channeltype)
  520. ->find();
  521. $info = array_merge($info, $channelRow);
  522. }
  523. /*--end*/
  524. $typeid = $info['typeid'];
  525. // 栏目信息
  526. $arctypeInfo = Db::name('arctype')->find($typeid);
  527. $info['channel'] = $arctypeInfo['current_channel'];
  528. if (is_http_url($info['litpic'])) {
  529. $info['is_remote'] = 1;
  530. $info['litpic_remote'] = handle_subdir_pic($info['litpic']);
  531. } else {
  532. $info['is_remote'] = 0;
  533. $info['litpic_local'] = handle_subdir_pic($info['litpic']);
  534. }
  535. // SEO描述
  536. if (!empty($info['seo_description'])) {
  537. $info['seo_description'] = @msubstr(checkStrHtml($info['seo_description']), 0, config('global.arc_seo_description_length'), false);
  538. }
  539. $assign_data['field'] = $info;
  540. // 产品相册
  541. $proimg_list = model('ProductImg')->getProImg($id);
  542. foreach ($proimg_list as $key => $val) {
  543. $proimg_list[$key]['image_url'] = handle_subdir_pic($val['image_url']); // 支持子目录
  544. }
  545. $assign_data['proimg_list'] = $proimg_list;
  546. /*允许发布文档列表的栏目,文档所在模型以栏目所在模型为主,兼容切换模型之后的数据编辑*/
  547. $arctype_html = allow_release_arctype($typeid, array($info['channel']));
  548. $assign_data['arctype_html'] = $arctype_html;
  549. /*--end*/
  550. /*自定义字段*/
  551. $addonFieldExtList = model('Field')->getChannelFieldList($info['channel'], 0, $id, $info);
  552. $channelfieldBindRow = Db::name('channelfield_bind')->where([
  553. 'typeid' => ['IN', [0,$typeid]],
  554. ])->column('field_id');
  555. if (!empty($channelfieldBindRow)) {
  556. foreach ($addonFieldExtList as $key => $val) {
  557. if (!in_array($val['id'], $channelfieldBindRow)) {
  558. unset($addonFieldExtList[$key]);
  559. }
  560. }
  561. }
  562. $assign_data['addonFieldExtList'] = $addonFieldExtList;
  563. $assign_data['aid'] = $id;
  564. /*--end*/
  565. /*可控制的主表字段列表*/
  566. $assign_data['ifcontrolRow'] = Db::name('channelfield')->field('id,name')->where([
  567. 'channel_id' => $this->channeltype,
  568. 'ifmain' => 1,
  569. 'ifeditable' => 1,
  570. 'ifcontrol' => 0,
  571. 'status' => 1,
  572. ])->getAllWithIndex('name');
  573. /*虚拟商品内容读取*/
  574. $assign_data['netdisk'] = Db::name("product_netdisk")->where('aid', $id)->find();
  575. /*end*/
  576. // 阅读权限
  577. $arcrank_list = get_arcrank_list();
  578. $assign_data['arcrank_list'] = $arcrank_list;
  579. /*产品参数*/
  580. $assign_data['canshu'] = $this->ajax_get_attr_input($typeid, $id);
  581. /*--end*/
  582. /*模板列表*/
  583. $archivesLogic = new \app\admin\logic\ArchivesLogic;
  584. $templateList = $archivesLogic->getTemplateList($this->nid);
  585. $this->assign('templateList', $templateList);
  586. /*--end*/
  587. /*默认模板文件*/
  588. $tempview = $info['tempview'];
  589. empty($tempview) && $tempview = $arctypeInfo['tempview'];
  590. $this->assign('tempview', $tempview);
  591. /*--end*/
  592. // 商城配置
  593. $shopConfig = getUsersConfigData('shop');
  594. $assign_data['shopConfig'] = $shopConfig;
  595. // 处理产品价格属性
  596. $IsSame = '';
  597. if (empty($shopConfig['shop_type']) || 1 == $shopConfig['shop_type']) {
  598. if ($shopConfig['shop_type'] == $assign_data['field']['prom_type']) {
  599. $IsSame = '0'; // 相同
  600. }else{
  601. $IsSame = '1'; // 不相同
  602. }
  603. }
  604. $assign_data['IsSame'] = $IsSame;
  605. // URL模式
  606. $tpcache = config('tpcache');
  607. $assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
  608. /*商品参数列表*/
  609. $where = [
  610. 'is_del' => 0,
  611. 'status' => 1
  612. ];
  613. $assign_data['AttrList'] = $this->shop_product_attrlist_db->where($where)->order('sort_order asc')->select();
  614. /*END*/
  615. /*商品参数值*/
  616. $assign_data['canshu'] = '';
  617. if (!empty($info['attrlist_id'])) {
  618. $assign_data['canshu'] = $this->ajax_get_shop_attr_input($typeid, $id, $info['attrlist_id']);
  619. }
  620. /*--end*/
  621. $this->assign($assign_data);
  622. return $this->fetch();
  623. }
  624. /**
  625. * 删除
  626. */
  627. public function del()
  628. {
  629. if (IS_POST) {
  630. $archivesLogic = new \app\admin\logic\ArchivesLogic;
  631. $archivesLogic->del();
  632. }
  633. }
  634. /**
  635. * 删除商品相册图
  636. */
  637. public function del_proimg()
  638. {
  639. if (IS_POST) {
  640. $filename= input('filename/s');
  641. $filename= str_replace('../','',$filename);
  642. $filename= trim($filename,'.');
  643. if(eyPreventShell($filename) && !empty($filename)){
  644. $filename_new = trim($filename,'/');
  645. $filetype = preg_replace('/^(.*)\.(\w+)$/i', '$2', $filename);
  646. $phpfile = strtolower(strstr($filename,'.php')); //排除PHP文件
  647. $size = getimagesize($filename_new);
  648. $fileInfo = explode('/',$size['mime']);
  649. if((file_exists($filename_new) && $fileInfo[0] != 'image') || $phpfile || !in_array($filetype, explode(',', config('global.image_ext')))){
  650. exit;
  651. }
  652. if (!empty($filename)) {
  653. M('product_img')->where("image_url = '$filename'")->delete();
  654. }
  655. }
  656. }
  657. }
  658. // 商品编号查重效验
  659. public function product_number_check()
  660. {
  661. if (IS_AJAX_POST) {
  662. $post = input('post.');
  663. $where = [];
  664. if (!empty($post['aid'])) $where['aid'] = ['NOT IN', $post['aid']];
  665. if (!empty($post['product_number'])) {
  666. $where['product_number'] = $post['product_number'];
  667. } else {
  668. $this->error('请填写商品编号');
  669. }
  670. $Result = Db::name('archives')->where($where)->count('aid');
  671. if (!empty($Result)) {
  672. $this->error('商品编号已存在');
  673. } else {
  674. $this->success('商品编号正常');
  675. }
  676. }
  677. }
  678. // 商品规格列表
  679. public function spec_index()
  680. {
  681. // 获取所有商品规格名称,分页返回
  682. $PresetData = $this->ProductSpecPresetModel->GetAllSpecPreset(input('param.'));
  683. $this->assign($PresetData);
  684. return $this->fetch();
  685. }
  686. // 保存规格
  687. public function spec_save()
  688. {
  689. if (IS_AJAX_POST) {
  690. $param = input('param.');
  691. $SaveData = [];
  692. foreach ($param['preset_name'] as $key => $value) {
  693. // 规格名称为空则跳过
  694. if (empty($value)) continue;
  695. // 可添加数据
  696. $SaveData[$key] = [
  697. 'preset_id' => $param['preset_id'][$key],
  698. 'preset_name' => $value,
  699. 'preset_desc' => $param['preset_desc'][$key],
  700. 'preset_type' => $param['preset_type'][$key],
  701. 'sort_order' => $param['sort_order'][$key],
  702. 'update_time' => getTime()
  703. ];
  704. // 若为空则清除主键字段
  705. if (empty($SaveData[$key]['preset_id'])) {
  706. $SaveData[$key]['add_time'] = getTime();
  707. unset($SaveData[$key]['preset_id']);
  708. }
  709. }
  710. $ResultID = $this->ProductSpecPresetModel->saveAll($SaveData);
  711. if (!empty($ResultID)) {
  712. $this->success('更新成功');
  713. } else {
  714. $this->error('更新失败');
  715. }
  716. }
  717. }
  718. // 删除规格值
  719. public function spec_del()
  720. {
  721. $PresetID = input('del_id/a');
  722. $PresetID = eyIntval($PresetID);
  723. if(!empty($PresetID)) {
  724. $Result = $this->product_spec_preset_db->where('preset_id', 'IN', $PresetID)->delete();
  725. if($Result) {
  726. adminLog('删除商品规格-id:'.implode(',', $PresetID));
  727. $this->success('删除成功');
  728. } else {
  729. $this->error('删除失败');
  730. }
  731. } else {
  732. $this->error('参数有误');
  733. }
  734. }
  735. // 规格值列表
  736. public function spec_value_index()
  737. {
  738. $PresetID = input('id/d');
  739. // 获取单条规格名称数据
  740. $PresetData = $this->ProductSpecPresetModel->GetFindSpecPreset($PresetID);
  741. if (empty($PresetData)) $this->error('请先添加规格名称');
  742. $this->assign('PresetData', $PresetData);
  743. $Where['preset_id'] = $PresetID;
  744. $keywords = input('keywords/s');
  745. if (!empty($keywords)) $Where['preset_value'] = ['LIKE', "%{$keywords}%"];
  746. // 分页
  747. $count = $this->product_spec_value_db->where($Where)->count('preset_id');
  748. $pageObj = new Page($count, 10);
  749. $pageStr = $pageObj->show();
  750. $this->assign('pageObj', $pageObj);
  751. $this->assign('pageStr', $pageStr);
  752. // 查询规格数据
  753. $ValueData = $this->product_spec_value_db
  754. ->where($Where)
  755. ->order('sort_order asc, value_id asc')
  756. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  757. ->select();
  758. foreach ($ValueData as $key => $value) {
  759. $ValueData[$key]['value_img_src'] = get_default_pic($value['value_img']);
  760. if (0 == $PresetData['preset_type']) unset($value['value_img']);
  761. }
  762. $this->assign('ValueData', $ValueData);
  763. return $this->fetch();
  764. }
  765. // 保存规格值
  766. public function spec_value_save()
  767. {
  768. if (IS_AJAX_POST) {
  769. $param = input('param.');
  770. $SaveData = [];
  771. $AddNum = 0;
  772. foreach ($param['value_name'] as $key => $value) {
  773. if (empty($value)) continue;
  774. // 可添加数据
  775. $SaveData[$key] = [
  776. 'value_id' => $param['value_id'][$key],
  777. 'preset_id' => $param['preset_id'],
  778. 'value_name' => $value,
  779. 'value_img' => !empty($param['value_img'][$key]) ? $param['value_img'][$key] : '',
  780. 'sort_order' => $param['sort_order'][$key],
  781. 'update_time' => getTime()
  782. ];
  783. // 若为空则清除主键字段
  784. if (empty($SaveData[$key]['value_id'])) {
  785. $AddNum++;
  786. $SaveData[$key]['add_time'] = getTime();
  787. unset($SaveData[$key]['value_id']);
  788. }
  789. }
  790. $ResultID = $this->ProductSpecValueModel->saveAll($SaveData);
  791. if (!empty($ResultID)) {
  792. /*更新规格名称表的规格值数量*/
  793. $this->product_spec_preset_db->where('preset_id', $param['preset_id'])->setInc('preset_value', $AddNum);
  794. /*END*/
  795. $this->success('更新成功');
  796. } else {
  797. $this->error('更新失败');
  798. }
  799. }
  800. }
  801. // 删除规格值
  802. public function spec_value_del()
  803. {
  804. $ValueID = input('del_id/a');
  805. $ValueID = eyIntval($ValueID);
  806. if(!empty($ValueID)){
  807. $Result = $this->product_spec_value_db->where('value_id', 'IN', $ValueID)->delete();
  808. if($Result){
  809. adminLog('删除商品规格值-id:'.implode(',', $ValueID));
  810. /*更新规格名称表的规格值数量*/
  811. $DelNum = count($ValueID);
  812. $this->product_spec_preset_db->where('preset_id', input('post.preset_id/d'))->setDec('preset_value', $DelNum);
  813. /*END*/
  814. $this->success('删除成功');
  815. }else{
  816. $this->error('删除失败');
  817. }
  818. }else{
  819. $this->error('参数有误');
  820. }
  821. }
  822. // 规格模板
  823. public function spec_template()
  824. {
  825. // 查询规格数据
  826. $PresetData = $this->product_spec_preset_db->where('status', 1)->order('sort_order asc')->select();
  827. $PresetID = get_arr_column($PresetData, 'preset_id');
  828. $where = [
  829. 'status' => 1,
  830. 'preset_id' => ['IN', $PresetID]
  831. ];
  832. $ValueData = $this->product_spec_value_db->where($where)->order('sort_order asc')->select();
  833. $ValueData = group_same_key($ValueData, 'preset_id');
  834. foreach ($PresetData as $key => $value) {
  835. $PresetData[$key]['SpecValue'] = !empty($ValueData[$value['preset_id']]) ? $ValueData[$value['preset_id']] : [];
  836. }
  837. $this->assign('PresetData', $PresetData);
  838. return $this->fetch('spec_template');
  839. }
  840. public function combi_spec_data()
  841. {
  842. if (IS_AJAX_POST) {
  843. $post = input('post.');
  844. // 刷新或重新进入产品添加页则清除关于产品session
  845. if (isset($post['initialization']) && !empty($post['initialization'])) {
  846. session('SpecID', null); $this->success('初始化完成');
  847. }
  848. // 初始化变量
  849. $HtmlTable = $SelectedSpec = null;
  850. // 获取已选规格拼装及生成规格HTML的ID
  851. if (!empty($post['preset_id'])) {
  852. $ResultData = $this->ProductSpecLogic->GetSelectedSpec($post);
  853. $SelectedSpec = $ResultData['SelectedSpec'];
  854. }
  855. // 清除一整条规格信息,清除session中相应的数据
  856. if (!empty($post['del_preset_id']) && empty($post['del_value_id'])) {
  857. $ResultData = $this->ProductSpecLogic->ClearSpecPresetMarkID($post);
  858. }
  859. // 删除单个规格值则清除session对应的值
  860. if (!empty($post['del_preset_id']) && !empty($post['del_value_id'])) {
  861. $ResultData = $this->ProductSpecLogic->ClearSpecPresetValueID($post);
  862. }
  863. // 获取规格拼装后的html表格
  864. if (isset($post['aid']) && !empty($post['aid'])) {
  865. // 编辑
  866. $HtmlTable = $this->ProductSpecLogic->SpecAssembly($ResultData['ResultID'], $post['aid']);
  867. } else {
  868. // 新增
  869. $HtmlTable = $this->ProductSpecLogic->SpecAssembly($ResultData['ResultID'], $post['aid']);
  870. }
  871. // 返回数据
  872. $ReturnData = [
  873. 'HtmlTable' => $HtmlTable,
  874. 'SelectedSpec' => $SelectedSpec
  875. ];
  876. $this->success('加载成功!', null, $ReturnData);
  877. }
  878. }
  879. // 商品属性列表
  880. public function attrlist_index()
  881. {
  882. // 查询条件
  883. $Where['is_del'] = 0;
  884. $keywords = input('keywords/s');
  885. if (!empty($keywords)) $Where['list_name'] = ['LIKE', "%{$keywords}%"];
  886. // 分页
  887. $count = $this->shop_product_attrlist_db->where($Where)->count('list_id');
  888. $pageObj = new Page($count, config('paginate.list_rows'));
  889. $pageStr = $pageObj->show();
  890. $this->assign('pageObj', $pageObj);
  891. $this->assign('pageStr', $pageStr);
  892. // 数据
  893. $list = $this->shop_product_attrlist_db
  894. ->where($Where)
  895. ->order('sort_order asc')
  896. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  897. ->select();
  898. $this->assign('list', $list);
  899. return $this->fetch();
  900. }
  901. // 新增商品属性
  902. public function attrlist_add()
  903. {
  904. function_exists('set_time_limit') && set_time_limit(0);
  905. if(IS_AJAX_POST) {
  906. $post = input('post.');
  907. // 参数名称不可重复
  908. $ListName = array_unique($post['list_name']);
  909. if (count($ListName) != count($post['list_name'])) $this->error('参数名称不可重复!');
  910. // 数据拼装
  911. $SaveData = [];
  912. foreach ($ListName as $key => $value) {
  913. if (!empty($value)) {
  914. $list_id = $post['list_id'][$key];
  915. $list_name = trim($value);
  916. $SaveData[$key] = [
  917. 'list_id' => !empty($list_id) ? $list_id : 0,
  918. 'list_name' => $list_name,
  919. 'desc' => !empty($post['desc'][$key]) ? $post['desc'][$key] : '',
  920. 'sort_order' => !empty($post['sort_order'][$key]) ? $post['sort_order'][$key] : 100,
  921. 'update_time' => getTime()
  922. ];
  923. if (empty($list_id)) {
  924. $SaveData[$key]['add_time'] = getTime();
  925. unset($SaveData[$key]['list_id']);
  926. }
  927. }
  928. }
  929. $ReturnId = model('ShopProductAttrlist')->saveAll($SaveData);
  930. if ($ReturnId) {
  931. adminLog('新增商品参数:'.implode(',', $post['list_name']));
  932. $this->success('操作成功', url('Product/attrlist_index'));
  933. } else {
  934. $this->error('操作失败');
  935. }
  936. }
  937. }
  938. // 参数删除
  939. public function attrlist_del()
  940. {
  941. $id_arr = input('del_id/a');
  942. $id_arr = eyIntval($id_arr);
  943. if(!empty($id_arr)){
  944. $Result = $this->shop_product_attrlist_db->where('list_id', 'IN', $id_arr)->delete();
  945. if($Result){
  946. adminLog('删除商品参数-id:'.implode(',', $id_arr));
  947. $this->success('删除成功');
  948. }else{
  949. $this->error('删除失败');
  950. }
  951. }else{
  952. $this->error('参数有误');
  953. }
  954. }
  955. /**
  956. * 商品参数值列表
  957. */
  958. public function attribute_index()
  959. {
  960. $condition = array();
  961. // 获取到所有GET参数
  962. $get = input('get.');
  963. $list_id = input('list_id/d', 0);
  964. // 应用搜索条件
  965. foreach (['keywords', 'list_id'] as $key) {
  966. if (isset($get[$key]) && $get[$key] !== '') {
  967. if ($key == 'keywords') {
  968. $condition['a.attr_name'] = ['LIKE', "%{$get[$key]}%"];
  969. } else if ($key == 'list_id') {
  970. $condition['a.list_id'] = $list_id;
  971. } else {
  972. $condition['a.'.$key] = ['eq', $get[$key]];
  973. }
  974. }
  975. }
  976. $condition['a.is_del'] = 0;
  977. // 分页
  978. $count = DB::name('shop_product_attribute')->alias('a')->where($condition)->count();
  979. $pageObj = new Page($count, config('paginate.list_rows'));
  980. $pageStr = $pageObj->show();
  981. $this->assign('pageObj', $pageObj);
  982. $this->assign('pageStr', $pageStr);
  983. // 数据
  984. $list = DB::name('shop_product_attribute')
  985. ->alias('a')
  986. ->where($condition)
  987. ->order('a.sort_order asc, a.attr_id asc')
  988. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  989. ->select();
  990. $attrInputTypeArr = [
  991. 0 => '手工录入',
  992. 1 => '选取默认值'
  993. ];
  994. $this->assign('attrInputTypeArr', $attrInputTypeArr);
  995. $this->assign('list', $list);
  996. return $this->fetch();
  997. }
  998. /**
  999. * 新增商品参数
  1000. */
  1001. public function attribute_add()
  1002. {
  1003. //防止php超时
  1004. function_exists('set_time_limit') && set_time_limit(0);
  1005. if(IS_AJAX_POST) {
  1006. $attr_values = str_replace('_', '', input('attr_values')); // 替换特殊字符
  1007. $attr_values = str_replace('@', '', $attr_values); // 替换特殊字符
  1008. $attr_values = trim($attr_values);
  1009. $post_data = input('post.');
  1010. $post_data['attr_values'] = $attr_values;
  1011. $SaveData = array(
  1012. 'attr_name' => $post_data['attr_name'],
  1013. 'list_id' => $post_data['list_id'],
  1014. 'attr_input_type' => isset($post_data['attr_input_type']) ? $post_data['attr_input_type'] : '',
  1015. 'attr_values' => isset($post_data['attr_values']) ? $post_data['attr_values'] : '',
  1016. 'sort_order' => $post_data['sort_order'],
  1017. 'status' => 1,
  1018. 'add_time' => getTime(),
  1019. 'update_time' => getTime(),
  1020. );
  1021. $ReturnId = Db::name('shop_product_attribute')->add($SaveData);
  1022. if ($ReturnId) {
  1023. // 参数值合计增加
  1024. Db::name('shop_product_attrlist')->where('list_id', $post_data['list_id'])->setInc('attr_count');
  1025. adminLog('新增商品参数:'.$SaveData['attr_name']);
  1026. $this->success('操作成功');
  1027. } else {
  1028. $this->error('操作失败');
  1029. }
  1030. }
  1031. $list_id = input('param.list_id/d', 0);
  1032. $list = $this->shop_product_attrlist_db->where('list_id', $list_id)->find();
  1033. $this->assign('list', $list);
  1034. return $this->fetch();
  1035. }
  1036. /**
  1037. * 编辑商品参数
  1038. */
  1039. public function attribute_edit()
  1040. {
  1041. //防止php超时
  1042. function_exists('set_time_limit') && set_time_limit(0);
  1043. if(IS_AJAX_POST) {
  1044. $attr_values = str_replace('_', '', input('attr_values')); // 替换特殊字符
  1045. $attr_values = str_replace('@', '', $attr_values); // 替换特殊字符
  1046. $attr_values = trim($attr_values);
  1047. $post_data = input('post.');
  1048. $post_data['attr_values'] = $attr_values;
  1049. $SaveData = array(
  1050. 'attr_name' => $post_data['attr_name'],
  1051. 'list_id' => $post_data['list_id'],
  1052. 'attr_input_type' => isset($post_data['attr_input_type']) ? $post_data['attr_input_type'] : '',
  1053. 'attr_values' => isset($post_data['attr_values']) ? $post_data['attr_values'] : '',
  1054. 'sort_order' => $post_data['sort_order'],
  1055. 'update_time' => getTime(),
  1056. );
  1057. $ReturnId = Db::name('shop_product_attribute')->where('attr_id', $post_data['attr_id'])->update($SaveData);
  1058. if ($ReturnId) {
  1059. adminLog('编辑商品参数:'.$SaveData['attr_name']);
  1060. $this->success('操作成功');
  1061. } else {
  1062. $this->error('操作失败');
  1063. }
  1064. }
  1065. $info = Db::name('shop_product_attribute')->where('attr_id', input('id/d'))->find();
  1066. if (empty($info)) $this->error('数据不存在,请联系管理员!');
  1067. $this->assign('field', $info);
  1068. $list = $this->shop_product_attrlist_db->where('list_id', $info['list_id'])->find();
  1069. $this->assign('list', $list);
  1070. return $this->fetch();
  1071. }
  1072. /**
  1073. * 删除商品参数
  1074. */
  1075. public function attribute_del()
  1076. {
  1077. $id_arr = input('del_id/a');
  1078. $id_arr = eyIntval($id_arr);
  1079. if(!empty($id_arr)){
  1080. $r = Db::name('shop_product_attribute')->where(['attr_id' => ['IN', $id_arr]])->delete();
  1081. if($r){
  1082. $IDCount = count($id_arr);
  1083. Db::name('shop_product_attrlist')->where('list_id', input('list_id/d'))->setDec('attr_count', $IDCount);
  1084. adminLog('删除商品参数-id:'.implode(',', $id_arr));
  1085. $this->success('删除成功');
  1086. } else {
  1087. $this->error('删除失败');
  1088. }
  1089. } else {
  1090. $this->error('参数有误');
  1091. }
  1092. }
  1093. /**
  1094. * 动态获取商品参数输入框 根据不同的数据返回不同的输入框类型
  1095. */
  1096. public function ajax_get_shop_attr_input($typeid = '', $aid = '', $list_id = '')
  1097. {
  1098. $productLogic = new ProductLogic();
  1099. $str = $productLogic->getShopAttrInput($aid, $typeid, $list_id);
  1100. if (empty($str)) {
  1101. $str = '<div style="font-size: 12px;text-align: center;">提示:该参数还没有参数值,若有需要请点击【<a href="'.url('Product/attribute_index', array('list_id'=>$list_id)).'">商品参数</a>】进行更多操作。</div>';
  1102. }
  1103. if (IS_AJAX) {
  1104. exit($str);
  1105. } else {
  1106. return $str;
  1107. }
  1108. }
  1109. /**
  1110. * 动态获取商品参数输入框 根据不同的数据返回不同的输入框类型
  1111. */
  1112. public function ajax_get_attr_input($typeid = '', $aid = '', $list_id = '')
  1113. {
  1114. $productLogic = new ProductLogic();
  1115. $str = $productLogic->getAttrInput($aid, $typeid, $list_id);
  1116. if (empty($str)) {
  1117. $str = '<div style="font-size: 12px;text-align: center;">提示:该参数还没有参数值,若有需要请点击【<a href="'.url('Product/attribute_index', array('list_id'=>$list_id)).'">商品参数</a>】进行更多操作。</div>';
  1118. }
  1119. if (IS_AJAX) {
  1120. exit($str);
  1121. } else {
  1122. return $str;
  1123. }
  1124. }
  1125. }