Goodsclass.php 30 KB

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