Goodsclass.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Goodsclass extends AdminControl
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/goodsclass.lang.php');
  18. }
  19. /**
  20. * 分类管理
  21. */
  22. public function goods_class()
  23. {
  24. $goodsclass_model = model('goodsclass');
  25. //父ID
  26. $parent_id = input('param.gc_parent_id') ? intval(input('param.gc_parent_id')) : 0;
  27. //列表
  28. $tmp_list = $goodsclass_model->getTreeClassList(3);
  29. $class_list = array();
  30. if (is_array($tmp_list)) {
  31. foreach ($tmp_list as $k => $v) {
  32. if ($v['gc_parent_id'] == $parent_id) {
  33. //判断是否有子类
  34. if (isset($tmp_list[$k + 1]['deep']) && $tmp_list[$k + 1]['deep'] > $v['deep']) {
  35. $v['have_child'] = 1;
  36. }
  37. $class_list[] = $v;
  38. }
  39. }
  40. }
  41. if (input('param.ajax') == '1') {
  42. $output = json_encode($class_list);
  43. echo $output;
  44. exit;
  45. } else {
  46. View::assign('class_list', $class_list);
  47. $this->setAdminCurItem('goods_class');
  48. return View::fetch('goods_class');
  49. }
  50. }
  51. /**
  52. * 商品分类添加
  53. */
  54. public function goods_class_add()
  55. {
  56. $goodsclass_model = model('goodsclass');
  57. if (!request()->isPost()) {
  58. //父类列表,只取到第二级
  59. $parent_list = $goodsclass_model->getTreeClassList(2);
  60. $gc_list = array();
  61. if (is_array($parent_list)) {
  62. foreach ($parent_list as $k => $v) {
  63. $parent_list[$k]['gc_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['gc_name'];
  64. if ($v['deep'] == 1)
  65. $gc_list[$k] = $v;
  66. }
  67. }
  68. View::assign('gc_list', $gc_list);
  69. //类型列表
  70. $type_model = model('type');
  71. $type_list = $type_model->getTypeList(array(), '', 'type_id,type_name,class_id,class_name');
  72. $t_list = array();
  73. if (is_array($type_list) && !empty($type_list)) {
  74. foreach ($type_list as $k => $val) {
  75. $t_list[$val['class_id']]['type'][$k] = $val;
  76. $t_list[$val['class_id']]['name'] = $val['class_name'] == '' ? lang('ds_default') : $val['class_name'];
  77. }
  78. }
  79. ksort($t_list);
  80. View::assign('type_list', $t_list);
  81. View::assign('gc_parent_id', input('get.gc_parent_id'));
  82. View::assign('parent_list', $parent_list);
  83. $this->setAdminCurItem('goods_class_add');
  84. return View::fetch('goods_class_add');
  85. } else {
  86. $insert_array = array();
  87. $insert_array['gc_name'] = input('post.gc_name');
  88. $insert_array['type_id'] = intval(input('post.t_id'));
  89. $insert_array['type_name'] = trim(input('post.t_name'));
  90. $insert_array['gc_parent_id'] = intval(input('post.gc_parent_id'));
  91. $insert_array['commis_rate'] = intval(input('post.commis_rate'));
  92. $insert_array['gc_sort'] = intval(input('post.gc_sort'));
  93. $insert_array['gc_virtual'] = intval(input('post.gc_virtual'));
  94. if (!empty($_FILES['pic']['name'])) { //上传图片
  95. $res = ds_upload_pic(ATTACH_COMMON, 'pic');
  96. if ($res['code']) {
  97. $file_name = $res['data']['file_name'];
  98. $insert_array['gc_image'] = $file_name;
  99. } else {
  100. $this->error($res['msg']);
  101. }
  102. }
  103. $goods_validate = ds_validate('goods');
  104. if (!$goods_validate->scene('goods_class_add')->check($insert_array)) {
  105. $this->error($goods_validate->getError());
  106. }
  107. $result = $goodsclass_model->addGoodsclass($insert_array);
  108. if ($result) {
  109. $this->log(lang('ds_add') . lang('goods_class_index_class') . '[' . input('post.gc_name') . ']', 1);
  110. $this->success(lang('ds_common_save_succ'), (string) url('Goodsclass/goods_class'));
  111. } else {
  112. $this->log(lang('ds_add') . lang('goods_class_index_class') . '[' . input('post.gc_name') . ']', 0);
  113. $this->error(lang('ds_common_save_fail'));
  114. }
  115. }
  116. }
  117. /**
  118. * 编辑
  119. */
  120. public function goods_class_edit()
  121. {
  122. $goodsclass_model = model('goodsclass');
  123. $gc_id = intval(input('param.gc_id'));
  124. if (!request()->isPost()) {
  125. $class_array = $goodsclass_model->getGoodsclassInfoById($gc_id);
  126. if (empty($class_array)) {
  127. $this->error(lang('goods_class_batch_edit_paramerror'));
  128. }
  129. //类型列表
  130. $type_model = model('type');
  131. $type_list = $type_model->getTypeList(array(), '', 'type_id,type_name,class_id,class_name');
  132. $t_list = array();
  133. if (is_array($type_list) && !empty($type_list)) {
  134. foreach ($type_list as $k => $val) {
  135. $t_list[$val['class_id']]['type'][$k] = $val;
  136. $t_list[$val['class_id']]['name'] = $val['class_name'] == '' ? lang('ds_default') : $val['class_name'];
  137. }
  138. }
  139. ksort($t_list);
  140. //父类列表,只取到第二级
  141. $parent_list = $goodsclass_model->getTreeClassList(2);
  142. if (is_array($parent_list)) {
  143. foreach ($parent_list as $k => $v) {
  144. $parent_list[$k]['gc_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['gc_name'];
  145. }
  146. }
  147. View::assign('parent_list', $parent_list);
  148. // 一级分类列表
  149. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  150. View::assign('gc_list', $gc_list);
  151. $class_array['pic'] = ds_get_pic(ATTACH_COMMON, $class_array['gc_image']);
  152. View::assign('type_list', $t_list);
  153. View::assign('class_array', $class_array);
  154. $this->setAdminCurItem('goods_class_edit');
  155. return View::fetch('goods_class_edit');
  156. } else {
  157. $update_array = array();
  158. $update_array['gc_name'] = input('post.gc_name');
  159. $update_array['type_id'] = intval(input('post.t_id'));
  160. $update_array['type_name'] = trim(input('post.t_name'));
  161. $update_array['commis_rate'] = intval(input('post.commis_rate'));
  162. $update_array['gc_sort'] = intval(input('post.gc_sort'));
  163. $update_array['gc_virtual'] = intval(input('post.gc_virtual'));
  164. $update_array['gc_parent_id'] = intval(input('post.gc_parent_id'));
  165. if (!empty($_FILES['pic']['name'])) { //上传图片
  166. $res = ds_upload_pic(ATTACH_COMMON, 'pic');
  167. if ($res['code']) {
  168. $file_name = $res['data']['file_name'];
  169. $update_array['gc_image'] = $file_name;
  170. } else {
  171. $this->error($res['msg']);
  172. }
  173. }
  174. $goods_validate = ds_validate('goods');
  175. if (!$goods_validate->scene('goods_class_edit')->check($update_array)) {
  176. $this->error($goods_validate->getError());
  177. }
  178. $parent_class = $goodsclass_model->getGoodsclassInfoById($update_array['gc_parent_id']);
  179. if ($parent_class) {
  180. if ($parent_class['gc_parent_id'] == $gc_id) {
  181. $this->error(lang('parent_parent_goods_class_equal_self_error'));
  182. }
  183. }
  184. if ($update_array['gc_parent_id'] == $gc_id) {
  185. $this->error(lang('parent_goods_class_equal_self_error'));
  186. }
  187. // 更新分类信息
  188. $condition = array();
  189. $condition[] = array('gc_id', '=', $gc_id);
  190. $result = $goodsclass_model->editGoodsclass($update_array, $condition);
  191. if ($result < 0) {
  192. $this->log(lang('ds_edit') . lang('goods_class_index_class') . '[' . input('post.gc_name') . ']', 0);
  193. $this->error(lang('goods_class_batch_edit_fail'));
  194. }
  195. // 检测是否需要关联自己操作,统一查询子分类
  196. if (input('post.t_commis_rate') == '1' || input('post.t_associated') == '1' || input('post.t_gc_virtual') == '1') {
  197. $gc_id_list = $goodsclass_model->getChildClass($gc_id);
  198. $gc_ids = array();
  199. if (is_array($gc_id_list) && !empty($gc_id_list)) {
  200. foreach ($gc_id_list as $val) {
  201. $gc_ids[] = $val['gc_id'];
  202. }
  203. }
  204. }
  205. // 更新该分类下子分类的所有分佣比例
  206. if (input('post.t_commis_rate') == '1' && !empty($gc_ids)) {
  207. $goodsclass_model->editGoodsclass(array('commis_rate' => $update_array['commis_rate']), array(array('gc_id', 'in', $gc_ids)));
  208. }
  209. // 更新该分类下子分类的所有类型
  210. if (input('post.t_associated') == '1' && !empty($gc_ids)) {
  211. $where = array();
  212. $where[] = array('gc_id', 'in', $gc_ids);
  213. $update = array();
  214. $update['type_id'] = intval(input('post.t_id'));
  215. $update['type_name'] = trim(input('post.t_name'));
  216. $goodsclass_model->editGoodsclass($update, $where);
  217. }
  218. // 虚拟商品
  219. if (input('post.t_gc_virtual') == '1' && !empty($gc_ids)) {
  220. $goodsclass_model->editGoodsclass(array('gc_virtual' => $update_array['gc_virtual']), array(array('gc_id', 'in', $gc_ids)));
  221. }
  222. $this->log(lang('ds_edit') . lang('goods_class_index_class') . '[' . input('post.gc_name') . ']', 1);
  223. $this->success(lang('goods_class_batch_edit_ok'), (string) url('Goodsclass/goods_class'));
  224. }
  225. }
  226. /**
  227. * 删除分类
  228. */
  229. public function goods_class_del()
  230. {
  231. $gc_id = input('param.gc_id');
  232. $gc_id_array = ds_delete_param($gc_id);
  233. if ($gc_id_array === FALSE) {
  234. $this->log(lang('ds_del') . lang('goods_class_index_class') . '[ID:' . $gc_id . ']', 0);
  235. ds_json_encode('10001', lang('param_error'));
  236. }
  237. $goodsclass_model = model('goodsclass');
  238. //删除分类
  239. $goodsclass_model->delGoodsclassByGcIdString($gc_id);
  240. $this->log(lang('ds_del') . lang('goods_class_index_class') . '[ID:' . $gc_id . ']', 1);
  241. ds_json_encode('10000', lang('ds_common_del_succ'));
  242. }
  243. /**
  244. * tag列表
  245. */
  246. public function tag()
  247. {
  248. /**
  249. * 处理商品分类
  250. */
  251. $choose_gcid = ($t = intval(input('param.choose_gcid'))) > 0 ? $t : 0;
  252. $gccache_arr = model('goodsclass')->getGoodsclassCache($choose_gcid, 3);
  253. View::assign('gc_json', json_encode($gccache_arr['showclass']));
  254. View::assign('gc_choose_json', json_encode($gccache_arr['choose_gcid']));
  255. $classtag_model = model('goodsclasstag');
  256. if (!request()->isPost()) {
  257. $condition = array();
  258. if ($choose_gcid > 0) {
  259. $condition[] = array('gc_id_' . ($gccache_arr['showclass'][$choose_gcid]['depth']), '=', $choose_gcid);
  260. }
  261. $tag_list = $classtag_model->getGoodsclasstagList($condition, 10);
  262. View::assign('tag_list', $tag_list);
  263. View::assign('show_page', $classtag_model->page_info->render());
  264. $this->setAdminCurItem('tag');
  265. return View::fetch('goods_class_tag');
  266. } else {
  267. //删除
  268. if (input('post.submit_type') == 'del') {
  269. $tag_id_array = input('post.tag_id/a');
  270. if (is_array($tag_id_array) && !empty($tag_id_array)) {
  271. //删除TAG
  272. $classtag_model->delGoodsclasstagByIds(implode(',', $tag_id_array));
  273. $this->log(lang('ds_del') . 'tag[ID:' . implode(',', $tag_id_array) . ']', 1);
  274. $this->success(lang('ds_common_del_succ'));
  275. } else {
  276. $this->log(lang('ds_del') . 'tag', 0);
  277. $this->error(lang('ds_common_del_fail'));
  278. }
  279. }
  280. }
  281. }
  282. /**
  283. * 重置TAG
  284. */
  285. public function tag_reset()
  286. {
  287. //实例化模型
  288. $goodsclass_model = model('goodsclass');
  289. $classtag_model = model('goodsclasstag');
  290. //清空TAG
  291. $return = $classtag_model->clearGoodsclasstag();
  292. // if (!$return) {
  293. // $this->error(lang('goods_class_reset_tag_fail_no_class'), (string)url('Goodsclass/tag'));
  294. // }
  295. //商品分类
  296. $goods_class = $goodsclass_model->getTreeClassList(3);
  297. //格式化分类。组成三维数组
  298. if (is_array($goods_class) and !empty($goods_class)) {
  299. $goods_class_array = array();
  300. foreach ($goods_class as $val) {
  301. //一级分类
  302. if ($val['gc_parent_id'] == 0) {
  303. $goods_class_array[$val['gc_id']]['gc_name'] = $val['gc_name'];
  304. $goods_class_array[$val['gc_id']]['gc_id'] = $val['gc_id'];
  305. $goods_class_array[$val['gc_id']]['type_id'] = $val['type_id'];
  306. } else {
  307. //二级分类
  308. if (isset($goods_class_array[$val['gc_parent_id']])) {
  309. $goods_class_array[$val['gc_parent_id']]['sub_class'][$val['gc_id']]['gc_name'] = $val['gc_name'];
  310. $goods_class_array[$val['gc_parent_id']]['sub_class'][$val['gc_id']]['gc_id'] = $val['gc_id'];
  311. $goods_class_array[$val['gc_parent_id']]['sub_class'][$val['gc_id']]['gc_parent_id'] = $val['gc_parent_id'];
  312. $goods_class_array[$val['gc_parent_id']]['sub_class'][$val['gc_id']]['type_id'] = $val['type_id'];
  313. } else {
  314. foreach ($goods_class_array as $v) {
  315. //三级分类
  316. if (isset($v['sub_class'][$val['gc_parent_id']])) {
  317. $goods_class_array[$v['sub_class'][$val['gc_parent_id']]['gc_parent_id']]['sub_class'][$val['gc_parent_id']]['sub_class'][$val['gc_id']]['gc_name'] = $val['gc_name'];
  318. $goods_class_array[$v['sub_class'][$val['gc_parent_id']]['gc_parent_id']]['sub_class'][$val['gc_parent_id']]['sub_class'][$val['gc_id']]['gc_id'] = $val['gc_id'];
  319. $goods_class_array[$v['sub_class'][$val['gc_parent_id']]['gc_parent_id']]['sub_class'][$val['gc_parent_id']]['sub_class'][$val['gc_id']]['type_id'] = $val['type_id'];
  320. }
  321. }
  322. }
  323. }
  324. }
  325. $return = $classtag_model->addGoodsclasstag($goods_class_array);
  326. // if ($return) {
  327. $this->log(lang('ds_reset') . 'tag', 1);
  328. $this->success(lang('ds_common_op_succ'), (string) url('Goodsclass/tag'));
  329. // } else {
  330. // $this->log(lang('ds_reset') . 'tag', 0);
  331. // $this->error(lang('ds_common_op_fail'), (string)url('Goodsclass/tag'));
  332. // }
  333. } else {
  334. $this->log(lang('ds_reset') . 'tag', 0);
  335. $this->error(lang('goods_class_reset_tag_fail_no_class'), (string) url('Goodsclass/tag'));
  336. }
  337. }
  338. /**
  339. * 更新TAG名称
  340. */
  341. public function tag_update()
  342. {
  343. $goodsclass_model = model('goodsclass');
  344. $classtag_model = model('goodsclasstag');
  345. //需要更新的TAG列表
  346. $tag_list = $classtag_model->getGoodsclasstagList(array(), '', 'gctag_id,gc_id_1,gc_id_2,gc_id_3');
  347. if (is_array($tag_list) && !empty($tag_list)) {
  348. foreach ($tag_list as $val) {
  349. //查询分类信息
  350. $in_gc_id = array();
  351. if ($val['gc_id_1'] != '0') {
  352. $in_gc_id[] = $val['gc_id_1'];
  353. }
  354. if ($val['gc_id_2'] != '0') {
  355. $in_gc_id[] = $val['gc_id_2'];
  356. }
  357. if ($val['gc_id_3'] != '0') {
  358. $in_gc_id[] = $val['gc_id_3'];
  359. }
  360. $gc_list = $goodsclass_model->getGoodsclassListByIds($in_gc_id);
  361. //更新TAG信息
  362. $update_tag = array();
  363. if (isset($gc_list['0']['gc_id']) && $gc_list['0']['gc_id'] != '0') {
  364. $update_tag['gc_id_1'] = $gc_list['0']['gc_id'];
  365. if (!isset($update_tag['gctag_name'])) {
  366. $update_tag['gctag_name'] = '';
  367. }
  368. $update_tag['gctag_name'] .= $gc_list['0']['gc_name'];
  369. }
  370. if (isset($gc_list['1']['gc_id']) && $gc_list['1']['gc_id'] != '0') {
  371. $update_tag['gc_id_2'] = $gc_list['1']['gc_id'];
  372. if (!isset($update_tag['gctag_name'])) {
  373. $update_tag['gctag_name'] = '';
  374. }
  375. $update_tag['gctag_name'] .= "&nbsp;&gt;&nbsp;" . $gc_list['1']['gc_name'];
  376. }
  377. if (isset($gc_list['2']['gc_id']) && $gc_list['2']['gc_id'] != '0') {
  378. $update_tag['gc_id_3'] = $gc_list['2']['gc_id'];
  379. if (!isset($update_tag['gctag_name'])) {
  380. $update_tag['gctag_name'] = '';
  381. }
  382. $update_tag['gctag_name'] .= "&nbsp;&gt;&nbsp;" . $gc_list['2']['gc_name'];
  383. }
  384. unset($gc_list);
  385. $return = $classtag_model->editGoodsclasstag($update_tag, $val['gctag_id']);
  386. if (!$return) {
  387. $this->log(lang('ds_update') . 'tag', 0);
  388. $this->error(lang('ds_common_op_fail'), 'Goodsclass/tag');
  389. }
  390. }
  391. $this->log(lang('ds_update') . 'tag', 1);
  392. $this->success(lang('ds_common_op_succ'), 'Goodsclass/tag');
  393. } else {
  394. $this->log(lang('ds_update') . 'tag', 0);
  395. $this->error(lang('goods_class_update_tag_fail_no_class'), 'Goodsclass/tag');
  396. }
  397. }
  398. /**
  399. * 删除TAG
  400. */
  401. public function tag_del()
  402. {
  403. $id = intval(input('get.tag_id'));
  404. $classtag_model = model('goodsclasstag');
  405. if ($id > 0) {
  406. //删除TAG
  407. $classtag_model->delGoodsclasstagByIds($id);
  408. $this->log(lang('ds_del') . 'tag[ID:' . $id . ']', 1);
  409. ds_json_encode('10000', lang('ds_common_op_succ'));
  410. } else {
  411. $this->log(lang('ds_del') . 'tag[ID:' . $id . ']', 0);
  412. ds_json_encode('10001', lang('ds_common_op_fail'));
  413. }
  414. }
  415. /**
  416. * 分类导航
  417. */
  418. public function nav_edit()
  419. {
  420. $gc_id = input('param.gc_id');
  421. $goodsclass_model = model('goodsclass');
  422. $class_info = $goodsclass_model->getGoodsclassInfoById($gc_id);
  423. $goodsclassnav_model = model('goodsclassnav');
  424. $nav_info = $goodsclassnav_model->getGoodsclassnavInfoByGcId($gc_id);
  425. if (request()->isPost()) {
  426. $update = array();
  427. $update['gc_id'] = $gc_id;
  428. $update['goodscn_alias'] = input('post.goodscn_alias');
  429. $class_id_array = input('post.class_id/a');
  430. if (empty($class_id_array)) {
  431. $update['goodscn_classids'] = '';
  432. } else if (is_array($class_id_array) && !empty($class_id_array)) {
  433. $update['goodscn_classids'] = implode(',', $class_id_array);
  434. }
  435. $brand_id_array = input('post.brand_id/a');
  436. if (empty($brand_id_array)) {
  437. $update['goodscn_brandids'] = '';
  438. } else if (is_array($brand_id_array) && !empty($brand_id_array)) {
  439. $update['goodscn_brandids'] = implode(',', $brand_id_array);
  440. }
  441. $update['goodscn_adv1_link'] = input('post.goodscn_adv1_link');
  442. $update['goodscn_adv2_link'] = input('post.goodscn_adv2_link');
  443. if (!empty($_FILES['pic']['name'])) { //上传图片
  444. @unlink(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS_CLASS . '/' . $nav_info['goodscn_pic']);
  445. $file_name = date('YmdHis') . rand(10000, 99999) . '.png';
  446. $res = ds_upload_pic(ATTACH_GOODS_CLASS, 'pic', $file_name);
  447. if ($res['code']) {
  448. $file_name = $res['data']['file_name'];
  449. $update['goodscn_pic'] = $file_name;
  450. } else {
  451. $this->error($res['msg']);
  452. }
  453. }
  454. if (!empty($_FILES['adv1']['name'])) { //上传广告图片
  455. @unlink(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS_CLASS . '/' . $nav_info['goodscn_adv1']);
  456. $file_name = date('YmdHis') . rand(10000, 99999) . '.png';
  457. $res = ds_upload_pic(ATTACH_GOODS_CLASS, 'adv1', $file_name);
  458. if ($res['code']) {
  459. $file_name = $res['data']['file_name'];
  460. $update['goodscn_adv1'] = $file_name;
  461. } else {
  462. $this->error($res['msg']);
  463. }
  464. }
  465. if (!empty($_FILES['adv2']['name'])) { //上传广告图片
  466. @unlink(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS_CLASS . '/' . $nav_info['goodscn_adv2']);
  467. $file_name = date('YmdHis') . rand(10000, 99999) . '.png';
  468. $res = ds_upload_pic(ATTACH_GOODS_CLASS, 'adv2', $file_name);
  469. if ($res['code']) {
  470. $file_name = $res['data']['file_name'];
  471. $update['goodscn_adv2'] = $file_name;
  472. } else {
  473. $this->error($res['msg']);
  474. }
  475. }
  476. if (empty($nav_info)) {
  477. $result = $goodsclassnav_model->addGoodsclassnav($update);
  478. } else {
  479. $result = $goodsclassnav_model->editGoodsclassnav($update, $gc_id);
  480. }
  481. if ($result) {
  482. $this->log('编辑分类导航,' . $class_info['gc_name'], 1);
  483. $this->success(lang('ds_common_op_succ'));
  484. } else {
  485. $this->log('编辑分类导航,' . $class_info['gc_name'], 0);
  486. $this->success(lang('ds_common_op_succ'));
  487. }
  488. } else {
  489. if (isset($nav_info)) {
  490. $nav_info['goodscn_pic'] = ds_get_pic(ATTACH_GOODS_CLASS, $nav_info['goodscn_pic']);
  491. $nav_info['goodscn_adv1'] = ds_get_pic(ATTACH_GOODS_CLASS, $nav_info['goodscn_adv1']);
  492. $nav_info['goodscn_adv2'] = ds_get_pic(ATTACH_GOODS_CLASS, $nav_info['goodscn_adv2']);
  493. }
  494. $nav_info['goodscn_classids'] = isset($nav_info['goodscn_classids']) ? explode(',', $nav_info['goodscn_classids']) : array();
  495. $nav_info['goodscn_brandids'] = isset($nav_info['goodscn_brandids']) ? explode(',', $nav_info['goodscn_brandids']) : array();
  496. View::assign('nav_info', $nav_info);
  497. View::assign('class_info', $class_info);
  498. // 一级分类列表
  499. $gc_list = $goodsclass_model->getGoodsclassListByParentId(0);
  500. View::assign('gc_list', $gc_list);
  501. // 全部三级分类
  502. $third_class = $goodsclass_model->getChildClassByFirstId($gc_id);
  503. View::assign('third_class', $third_class);
  504. // 品牌列表
  505. $brand_model = model('brand');
  506. $brand_list = $brand_model->getBrandPassedList(array());
  507. $b_list = array();
  508. if (is_array($brand_list) && !empty($brand_list)) {
  509. foreach ($brand_list as $k => $val) {
  510. $b_list[$val['gc_id']]['brand'][$k] = $val;
  511. $b_list[$val['gc_id']]['name'] = $val['brand_class'] == '' ? lang('ds_default') : $val['brand_class'];
  512. }
  513. }
  514. ksort($b_list);
  515. View::assign('brand_list', $b_list);
  516. return View::fetch('nav_edit');
  517. }
  518. }
  519. /**
  520. * ajax操作
  521. */
  522. public function ajax()
  523. {
  524. $branch = input('param.branch');
  525. $condition = array();
  526. switch ($branch) {
  527. /**
  528. * 更新分类
  529. */
  530. case 'goods_class_name':
  531. $goodsclass_model = model('goodsclass');
  532. $class_array = $goodsclass_model->getGoodsclassInfoById(intval(input('param.id')));
  533. $condition[] = array('gc_name', '=', trim(input('param.value')));
  534. $condition[] = array('gc_parent_id', '=', $class_array['gc_parent_id']);
  535. $condition[] = array('gc_id', '<>', intval(input('param.id')));
  536. $class_list = $goodsclass_model->getGoodsclassList($condition);
  537. if (empty($class_list)) {
  538. $condition = array();
  539. $condition[] = array('gc_id', '=', intval(input('param.id')));
  540. $update_array = array();
  541. $update_array['gc_name'] = trim(input('param.value'));
  542. $goodsclass_model->editGoodsclass($update_array, $condition);
  543. echo 'true';
  544. exit;
  545. } else {
  546. echo 'false';
  547. exit;
  548. }
  549. break;
  550. /**
  551. * 分类 排序 显示 设置
  552. */
  553. case 'goods_class_sort':
  554. case 'goods_class_show':
  555. case 'goods_class_index_show':
  556. $goodsclass_model = model('goodsclass');
  557. $condition = array();
  558. $condition[] = array('gc_id', '=', intval(input('param.id')));
  559. $update_array = array();
  560. $update_array[input('param.column')] = input('param.value');
  561. $goodsclass_model->editGoodsclass($update_array, $condition);
  562. echo 'true';
  563. exit;
  564. break;
  565. /**
  566. * 添加、修改操作中 检测类别名称是否有重复
  567. */
  568. case 'check_class_name':
  569. $goodsclass_model = model('goodsclass');
  570. $condition[] = array('gc_name', '=', trim(input('get.gc_name')));
  571. $condition[] = array('gc_parent_id', '=', intval(input('get.gc_parent_id')));
  572. $condition[] = array('gc_id', '<>', intval(input('get.gc_id')));
  573. $class_list = $goodsclass_model->getGoodsclassList($condition);
  574. if (empty($class_list)) {
  575. echo 'true';
  576. exit;
  577. } else {
  578. echo 'false';
  579. exit;
  580. }
  581. break;
  582. /**
  583. * TAG值编辑
  584. */
  585. case 'goods_class_tag_value':
  586. $classtag_model = model('goodsclasstag');
  587. $update_array = array();
  588. /**
  589. * 转码 防止GBK下用中文逗号截取不正确
  590. */
  591. $comma = ',';
  592. $update_array[input('param.column')] = trim(str_replace($comma, ',', input('param.value')));
  593. $classtag_model->editGoodsclasstag($update_array, intval(input('param.id')));
  594. echo 'true';
  595. exit;
  596. break;
  597. }
  598. }
  599. /**
  600. * 获取卖家栏目列表,针对控制器下的栏目
  601. */
  602. protected function getAdminItemList()
  603. {
  604. $menu_array = array(
  605. array(
  606. 'name' => 'goods_class',
  607. 'text' => lang('ds_manage'),
  608. 'url' => (string) url('Goodsclass/goods_class')
  609. ),
  610. );
  611. if (request()->action() == 'goods_class_add' || request()->action() == 'goods_class') {
  612. $menu_array[] = array(
  613. 'name' => 'goods_class_add',
  614. 'text' => lang('ds_add'),
  615. 'url' => (string) url('Goodsclass/goods_class_add')
  616. );
  617. }
  618. if (request()->action() == 'goods_class_edit') {
  619. $menu_array[] = array(
  620. 'name' => 'goods_class_edit',
  621. 'text' => lang('ds_edit'),
  622. 'url' => 'javascript:void(0)'
  623. );
  624. }
  625. $menu_array[] = array(
  626. 'name' => 'tag',
  627. 'text' => lang('ds_tag'),
  628. 'url' => (string) url('Goodsclass/tag')
  629. );
  630. return $menu_array;
  631. }
  632. }