Sellergoodsclass.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 商品分类控制器
  10. */
  11. class Sellergoodsclass extends MobileSeller
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellergoodsclass.lang.php');
  17. }
  18. /**
  19. * @api {POST} api/Sellergoodsclass/index 卖家商品分类
  20. * @apiVersion 1.0.0
  21. * @apiGroup Sellergoodsclass
  22. *
  23. * @apiHeader {String} X-DS-KEY 卖家授权token
  24. *
  25. * @apiSuccess {String} code 返回码,10000为成功
  26. * @apiSuccess {String} message 返回消息
  27. * @apiSuccess {Object} result 返回数据
  28. * @apiSuccess {Object[]} result.goods_class 商品分类列表
  29. * @apiSuccess {Int} result.goods_class.deep 深度
  30. * @apiSuccess {Int} result.goods_class.store_id 店铺ID
  31. * @apiSuccess {Int} result.goods_class.storegc_id 店铺分类ID
  32. * @apiSuccess {Int} result.goods_class.storegc_name 店铺分类名称
  33. * @apiSuccess {Int} result.goods_class.storegc_parent_id 上级分类ID
  34. * @apiSuccess {Int} result.goods_class.storegc_sort 排序
  35. * @apiSuccess {Int} result.goods_class.storegc_state 状态 0不显示1显示
  36. */
  37. public function index()
  38. {
  39. $storegoodsclass_model = model('storegoodsclass');
  40. $goods_class = $storegoodsclass_model->getTreeClassList(array('store_id' => $this->store_info['store_id']), 2);
  41. ds_json_encode(10000, '', array('goods_class' => $goods_class));
  42. }
  43. public function get_tree()
  44. {
  45. $storegoodsclass_model = model('storegoodsclass');
  46. $goods_class = $storegoodsclass_model->getTreeClassList(array('store_id' => $this->store_info['store_id']), 2);
  47. $result = array('class_list' => []);
  48. if ($goods_class) {
  49. $tree = new \mall\Tree();
  50. $tree->setTree($goods_class, 'storegc_id', 'storegc_parent_id', 'storegc_name');
  51. $result['class_list'] = $tree->getArrayList();
  52. }
  53. ds_json_encode(10000, '', $result);
  54. }
  55. /**
  56. * @api {POST} api/Sellergoodsclass/get_common_data 卖家商品分类新增/编辑公共数据
  57. * @apiVersion 1.0.0
  58. * @apiGroup Sellergoodsclass
  59. *
  60. * @apiHeader {String} X-DS-KEY 卖家授权token
  61. *
  62. * @apiSuccess {String} code 返回码,10000为成功
  63. * @apiSuccess {String} message 返回消息
  64. * @apiSuccess {Object} result 返回数据
  65. * @apiSuccess {Object[]} result.goods_class 商品分类列表 (返回字段参考storegoodsclass表)
  66. */
  67. public function get_common_data()
  68. {
  69. $storegoodsclass_model = model('storegoodsclass');
  70. $goods_class = $storegoodsclass_model->getStoregoodsclassList(array(
  71. 'store_id' => $this->store_info['store_id'],
  72. 'storegc_parent_id' => 0
  73. ));
  74. ds_json_encode(10000, '', array('goods_class' => $goods_class));
  75. }
  76. /**
  77. * @api {POST} api/Sellergoodsclass/goods_class_edit 店铺商品分类编辑信息
  78. * @apiVersion 1.0.0
  79. * @apiGroup Sellergoodsclass
  80. *
  81. * @apiParam {Int} top_class_id 分类ID
  82. *
  83. * @apiHeader {String} X-DS-KEY 卖家授权token
  84. *
  85. * @apiSuccess {String} code 返回码,10000为成功
  86. * @apiSuccess {String} message 返回消息
  87. * @apiSuccess {Object} result 返回数据
  88. */
  89. public function goods_class_edit()
  90. {
  91. $class_id = input('param.top_class_id');
  92. $storegoodsclass_model = model('storegoodsclass');
  93. $class_info = $storegoodsclass_model->getStoregoodsclassInfo(array('storegc_id' => intval($class_id)));
  94. ds_json_encode(10000, '', array('class_info' => $class_info));
  95. }
  96. /**
  97. * @api {POST} api/Sellergoodsclass/goods_class_save 卖家商品分类保存
  98. * @apiVersion 1.0.0
  99. * @apiGroup Sellergoodsclass
  100. *
  101. * @apiParam {Int} storegc_id 分类ID 0新增
  102. * @apiParam {String} storegc_name 分类名称
  103. * @apiParam {Int} storegc_parent_id 父分类ID
  104. * @apiParam {Int} storegc_state 分类状态 1启用0禁用
  105. * @apiParam {Int} storegc_sort 分类排序
  106. *
  107. * @apiHeader {String} X-DS-KEY 卖家授权token
  108. *
  109. * @apiSuccess {String} code 返回码,10000为成功
  110. * @apiSuccess {String} message 返回消息
  111. * @apiSuccess {Object} result 返回数据
  112. */
  113. public function goods_class_save()
  114. {
  115. $storegoodsclass_model = model('storegoodsclass');
  116. $storegc_id = intval(input('post.storegc_id'));
  117. if ($storegc_id) {
  118. $class_array = array();
  119. if (input('post.storegc_name') != '') {
  120. $class_array['storegc_name'] = input('post.storegc_name');
  121. }
  122. if (input('post.storegc_parent_id') != '') {
  123. $class_array['storegc_parent_id'] = input('post.storegc_parent_id');
  124. }
  125. if (input('post.storegc_state') != '') {
  126. $class_array['storegc_state'] = input('post.storegc_state');
  127. }
  128. if (input('post.storegc_sort') != '') {
  129. $class_array['storegc_sort'] = input('post.storegc_sort');
  130. }
  131. if ($class_array['storegc_parent_id'] == $storegc_id) {
  132. ds_json_encode(10001, lang('storegc_parent_goods_class_equal_self_error'));
  133. }
  134. $condition = array();
  135. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  136. $condition[] = array('storegc_id', '=', intval(input('post.storegc_id')));
  137. $state = $storegoodsclass_model->editStoregoodsclass($class_array, $condition, $this->store_info['store_id']);
  138. if ($state) {
  139. ds_json_encode(10000, lang('ds_common_op_succ'));
  140. } else {
  141. ds_json_encode(10001, lang('ds_common_op_fail'));
  142. }
  143. } else {
  144. $class_array = array();
  145. $class_array['storegc_name'] = input('post.storegc_name');
  146. $class_array['storegc_parent_id'] = input('post.storegc_parent_id', 0);
  147. $class_array['storegc_state'] = input('post.storegc_state');
  148. $class_array['store_id'] = $this->store_info['store_id'];
  149. $class_array['storegc_sort'] = input('post.storegc_sort');
  150. $state = $storegoodsclass_model->addStoregoodsclass($class_array);
  151. if ($state) {
  152. ds_json_encode(10000, lang('ds_common_op_succ'));
  153. } else {
  154. ds_json_encode(10001, lang('ds_common_op_fail'));
  155. }
  156. }
  157. }
  158. /**
  159. * @api {POST} api/Sellergoodsclass/goods_class_save 卖家商品分类删除
  160. * @apiVersion 1.0.0
  161. * @apiGroup Sellergoodsclass
  162. *
  163. * @apiParam {String} class_id 分类ID 用,分隔多个ID
  164. *
  165. * @apiHeader {String} X-DS-KEY 卖家授权token
  166. *
  167. * @apiSuccess {String} code 返回码,10000为成功
  168. * @apiSuccess {String} message 返回消息
  169. * @apiSuccess {Object} result 返回数据
  170. */
  171. public function drop_goods_class()
  172. {
  173. $storegoodsclass_model = model('storegoodsclass');
  174. $stcid_array = explode(',', input('param.class_id'));
  175. foreach ($stcid_array as $key => $val) {
  176. if (!is_numeric($val))
  177. unset($stcid_array[$key]);
  178. }
  179. $where = array();
  180. $where[] = array('storegc_id|storegc_parent_id', 'in', $stcid_array);
  181. $where[] = array('store_id', '=', $this->store_info['store_id']);
  182. $drop_state = $storegoodsclass_model->delStoregoodsclass($where, $this->store_info['store_id']);
  183. if ($drop_state) {
  184. ds_json_encode(10000, lang('ds_common_del_succ'));
  185. } else {
  186. ds_json_encode(10001, lang('ds_common_del_fail'));
  187. }
  188. }
  189. }