Sellergoodsclass.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 商品分类控制器
  15. */
  16. class Sellergoodsclass extends MobileSeller {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellergoodsclass.lang.php');
  20. }
  21. /**
  22. * @api {POST} api/Sellergoodsclass/index 卖家商品分类
  23. * @apiVersion 1.0.0
  24. * @apiGroup Sellergoodsclass
  25. *
  26. * @apiHeader {String} X-DS-KEY 卖家授权token
  27. *
  28. * @apiSuccess {String} code 返回码,10000为成功
  29. * @apiSuccess {String} message 返回消息
  30. * @apiSuccess {Object} result 返回数据
  31. * @apiSuccess {Object[]} result.goods_class 商品分类列表
  32. * @apiSuccess {Int} result.goods_class.deep 深度
  33. * @apiSuccess {Int} result.goods_class.store_id 店铺ID
  34. * @apiSuccess {Int} result.goods_class.storegc_id 店铺分类ID
  35. * @apiSuccess {Int} result.goods_class.storegc_name 店铺分类名称
  36. * @apiSuccess {Int} result.goods_class.storegc_parent_id 上级分类ID
  37. * @apiSuccess {Int} result.goods_class.storegc_sort 排序
  38. * @apiSuccess {Int} result.goods_class.storegc_state 状态 0不显示1显示
  39. */
  40. public function index() {
  41. $storegoodsclass_model = model('storegoodsclass');
  42. $goods_class = $storegoodsclass_model->getTreeClassList(array('store_id' => $this->store_info['store_id']), 2);
  43. ds_json_encode(10000, '', array('goods_class' => $goods_class));
  44. }
  45. public function get_tree() {
  46. $storegoodsclass_model = model('storegoodsclass');
  47. $goods_class = $storegoodsclass_model->getTreeClassList(array('store_id' => $this->store_info['store_id']), 2);
  48. $result = array('class_list' => []);
  49. if ($goods_class) {
  50. $tree = new \mall\Tree();
  51. $tree->setTree($goods_class, 'storegc_id', 'storegc_parent_id', 'storegc_name');
  52. $result['class_list'] = $tree->getArrayList();
  53. }
  54. ds_json_encode(10000, '', $result);
  55. }
  56. /**
  57. * @api {POST} api/Sellergoodsclass/get_common_data 卖家商品分类新增/编辑公共数据
  58. * @apiVersion 1.0.0
  59. * @apiGroup Sellergoodsclass
  60. *
  61. * @apiHeader {String} X-DS-KEY 卖家授权token
  62. *
  63. * @apiSuccess {String} code 返回码,10000为成功
  64. * @apiSuccess {String} message 返回消息
  65. * @apiSuccess {Object} result 返回数据
  66. * @apiSuccess {Object[]} result.goods_class 商品分类列表 (返回字段参考storegoodsclass表)
  67. */
  68. public function get_common_data() {
  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. $class_id = input('param.top_class_id');
  91. $storegoodsclass_model = model('storegoodsclass');
  92. $class_info = $storegoodsclass_model->getStoregoodsclassInfo(array('storegc_id' => intval($class_id)));
  93. ds_json_encode(10000, '', array('class_info' => $class_info));
  94. }
  95. /**
  96. * @api {POST} api/Sellergoodsclass/goods_class_save 卖家商品分类保存
  97. * @apiVersion 1.0.0
  98. * @apiGroup Sellergoodsclass
  99. *
  100. * @apiParam {Int} storegc_id 分类ID 0新增
  101. * @apiParam {String} storegc_name 分类名称
  102. * @apiParam {Int} storegc_parent_id 父分类ID
  103. * @apiParam {Int} storegc_state 分类状态 1启用0禁用
  104. * @apiParam {Int} storegc_sort 分类排序
  105. *
  106. * @apiHeader {String} X-DS-KEY 卖家授权token
  107. *
  108. * @apiSuccess {String} code 返回码,10000为成功
  109. * @apiSuccess {String} message 返回消息
  110. * @apiSuccess {Object} result 返回数据
  111. */
  112. public function goods_class_save() {
  113. $storegoodsclass_model = model('storegoodsclass');
  114. $storegc_id = intval(input('post.storegc_id'));
  115. if ($storegc_id) {
  116. $class_array = array();
  117. if (input('post.storegc_name') != '') {
  118. $class_array['storegc_name'] = input('post.storegc_name');
  119. }
  120. if (input('post.storegc_parent_id') != '') {
  121. $class_array['storegc_parent_id'] = input('post.storegc_parent_id');
  122. }
  123. if (input('post.storegc_state') != '') {
  124. $class_array['storegc_state'] = input('post.storegc_state');
  125. }
  126. if (input('post.storegc_sort') != '') {
  127. $class_array['storegc_sort'] = input('post.storegc_sort');
  128. }
  129. if ($class_array['storegc_parent_id'] == $storegc_id) {
  130. ds_json_encode(10001,lang('storegc_parent_goods_class_equal_self_error'));
  131. }
  132. $condition = array();
  133. $condition[] = array('store_id','=',$this->store_info['store_id']);
  134. $condition[] = array('storegc_id','=',intval(input('post.storegc_id')));
  135. $state = $storegoodsclass_model->editStoregoodsclass($class_array, $condition,$this->store_info['store_id']);
  136. if ($state) {
  137. ds_json_encode(10000, lang('ds_common_op_succ'));
  138. } else {
  139. ds_json_encode(10001, lang('ds_common_op_fail'));
  140. }
  141. } else {
  142. $class_array = array();
  143. $class_array['storegc_name'] = input('post.storegc_name');
  144. $class_array['storegc_parent_id'] = input('post.storegc_parent_id', 0);
  145. $class_array['storegc_state'] = input('post.storegc_state');
  146. $class_array['store_id'] = $this->store_info['store_id'];
  147. $class_array['storegc_sort'] = input('post.storegc_sort');
  148. $state = $storegoodsclass_model->addStoregoodsclass($class_array);
  149. if ($state) {
  150. ds_json_encode(10000, lang('ds_common_op_succ'));
  151. } else {
  152. ds_json_encode(10001, lang('ds_common_op_fail'));
  153. }
  154. }
  155. }
  156. /**
  157. * @api {POST} api/Sellergoodsclass/goods_class_save 卖家商品分类删除
  158. * @apiVersion 1.0.0
  159. * @apiGroup Sellergoodsclass
  160. *
  161. * @apiParam {String} class_id 分类ID 用,分隔多个ID
  162. *
  163. * @apiHeader {String} X-DS-KEY 卖家授权token
  164. *
  165. * @apiSuccess {String} code 返回码,10000为成功
  166. * @apiSuccess {String} message 返回消息
  167. * @apiSuccess {Object} result 返回数据
  168. */
  169. public function drop_goods_class() {
  170. $storegoodsclass_model = model('storegoodsclass');
  171. $stcid_array = explode(',', input('param.class_id'));
  172. foreach ($stcid_array as $key => $val) {
  173. if (!is_numeric($val))
  174. unset($stcid_array[$key]);
  175. }
  176. $where = array();
  177. $where[] = array('storegc_id|storegc_parent_id', 'in', $stcid_array);
  178. $where[] = array('store_id', '=', $this->store_info['store_id']);
  179. $drop_state = $storegoodsclass_model->delStoregoodsclass($where,$this->store_info['store_id']);
  180. if ($drop_state) {
  181. ds_json_encode(10000, lang('ds_common_del_succ'));
  182. } else {
  183. ds_json_encode(10001, lang('ds_common_del_fail'));
  184. }
  185. }
  186. }