Sellergoodsclass.php 8.2 KB

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