Selleraccountgroup.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 Selleraccountgroup extends MobileSeller {
  16. public function initialize() {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/selleraccount.lang.php');
  19. }
  20. /**
  21. * @api {POST} api/Selleraccountgroup/group_list 账户组列表
  22. * @apiVersion 1.0.0
  23. * @apiGroup Selleraccountgroup
  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.seller_group_list 卖家账户组列表 (返回字段参考sellergroup表)
  31. */
  32. public function group_list() {
  33. $sellergroup_model = model('sellergroup');
  34. $seller_group_list = $sellergroup_model->getSellergroupList(array('store_id' => $this->store_info['store_id']));
  35. ds_json_encode(10000, '', array('seller_group_list' => $seller_group_list));
  36. }
  37. /**
  38. * @api {POST} api/Selleraccountgroup/get_common_data 新增/编辑账户组公共数据
  39. * @apiVersion 1.0.0
  40. * @apiGroup Selleraccountgroup
  41. *
  42. * @apiHeader {String} X-DS-KEY 卖家授权token
  43. *
  44. * @apiSuccess {String} code 返回码,10000为成功
  45. * @apiSuccess {String} message 返回消息
  46. * @apiSuccess {Object} result 返回数据
  47. * @apiSuccess {Object[]} result.smt_list 店铺消息模板列表
  48. * @apiSuccess {String} result.smt_list.storemt_code 店铺消息模板代码
  49. * @apiSuccess {String} result.smt_list.storemt_name 店铺消息模板名称
  50. * @apiSuccess {Object[]} result.seller_menu 卖家功能菜单列表 (返回字段参考\app\home\controller\BaseSeller::getSellerMenuList)
  51. */
  52. public function get_common_data() {
  53. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/baseseller.lang.php');
  54. // 店铺消息模板列表
  55. $smt_list = model('storemsgtpl')->getStoremsgtplList(array(), 'storemt_code,storemt_name');
  56. $seller_menu = \app\home\controller\BaseSeller::getSellerMenuList($this->store_info['store_id']);
  57. ds_json_encode(10000, '', array('smt_list' => $smt_list, 'seller_menu' => $seller_menu));
  58. }
  59. /**
  60. * @api {POST} api/Selleraccountgroup/group_edit 获取账户组数据
  61. * @apiVersion 1.0.0
  62. * @apiGroup Selleraccountgroup
  63. *
  64. * @apiHeader {String} X-DS-KEY 卖家授权token
  65. *
  66. * @apiParam {Int} group_id 账户组ID
  67. *
  68. * @apiSuccess {String} code 返回码,10000为成功
  69. * @apiSuccess {String} message 返回消息
  70. * @apiSuccess {Object} result 返回数据
  71. * @apiSuccess {String} result.group_name 帐号组名称
  72. * @apiSuccess {String[]} result.group_limits 卖家按钮列表
  73. * @apiSuccess {String[]} result.smt_limits 店铺消息模板列表
  74. */
  75. public function group_edit() {
  76. $group_id = intval(input('param.group_id'));
  77. if ($group_id <= 0) {
  78. ds_json_encode(10001, lang('param_error'));
  79. }
  80. $sellergroup_model = model('sellergroup');
  81. $seller_group_info = $sellergroup_model->getSellergroupInfo(array('sellergroup_id' => $group_id, 'store_id' => $this->store_info['store_id']));
  82. if (empty($seller_group_info)) {
  83. ds_json_encode(10001, lang('there_no_group'));
  84. }
  85. ds_json_encode(10000, '', array('group_name' => $seller_group_info['sellergroup_name'], 'group_limits' => explode(',', $seller_group_info['sellergroup_limits']), 'smt_limits' => explode(',', $seller_group_info['smt_limits'])));
  86. }
  87. /**
  88. * @api {POST} api/Selleraccountgroup/group_save 保存账户组数据
  89. * @apiVersion 1.0.0
  90. * @apiGroup Selleraccountgroup
  91. *
  92. * @apiHeader {String} X-DS-KEY 卖家授权token
  93. *
  94. * @apiParam {Int} group_id 账户组ID 0新增
  95. * @apiParam {String} seller_group_name 账户组名称
  96. * @apiParam {Array} limits 操作权限
  97. * @apiParam {Array} smt_limits 消息接收权限
  98. *
  99. * @apiSuccess {String} code 返回码,10000为成功
  100. * @apiSuccess {String} message 返回消息
  101. * @apiSuccess {Object} result 返回数据
  102. */
  103. public function group_save() {
  104. $seller_info = array();
  105. $group_id = intval(input('param.group_id'));
  106. $seller_info['sellergroup_name'] = input('post.seller_group_name');
  107. $seller_info['sellergroup_limits'] = implode(',', input('post.limits/a'));
  108. $seller_info['smt_limits'] = empty(input('post.smt_limits/a')) ? '' : implode(',', input('post.smt_limits/a'));
  109. $seller_info['store_id'] = $this->store_info['store_id'];
  110. $sellergroup_model = model('sellergroup');
  111. if (empty($group_id)) {
  112. $result = $sellergroup_model->addSellergroup($seller_info);
  113. $this->recordSellerlog(lang('add_group_successfully') . $result);
  114. if ($result) {
  115. ds_json_encode(10000, lang('add_success'));
  116. } else {
  117. ds_json_encode(10001, lang('add_failure'));
  118. }
  119. } else {
  120. $condition = array();
  121. $condition[] = array('sellergroup_id','=',$group_id);
  122. $condition[] = array('store_id','=',$this->store_info['store_id']);
  123. $result = $sellergroup_model->editSellergroup($seller_info, $condition);
  124. $this->recordSellerlog(lang('editorial_team_succeeds') . $group_id);
  125. if ($result) {
  126. ds_json_encode(10000, lang('edit_success'));
  127. } else {
  128. ds_json_encode(10001, lang('edit_failure'));
  129. }
  130. }
  131. }
  132. /**
  133. * @api {POST} api/Selleraccountgroup/group_del 删除账户组
  134. * @apiVersion 1.0.0
  135. * @apiGroup Selleraccountgroup
  136. *
  137. * @apiHeader {String} X-DS-KEY 卖家授权token
  138. *
  139. * @apiParam {Int} group_id 账户组ID 0新增
  140. *
  141. * @apiSuccess {String} code 返回码,10000为成功
  142. * @apiSuccess {String} message 返回消息
  143. * @apiSuccess {Object} result 返回数据
  144. */
  145. public function group_del() {
  146. $group_id = intval(input('param.group_id'));
  147. if ($group_id > 0) {
  148. //判断当前用户组下是否有用户
  149. $condition = array(
  150. 'seller.store_id' => $this->store_info['store_id'],
  151. 'seller.sellergroup_id' => $group_id
  152. );
  153. $seller_list = model('seller')->getSellerList($condition);
  154. if (!empty($seller_list)) {
  155. ds_json_encode(10001, lang('please_change_account_group'));
  156. }
  157. $condition = array();
  158. $condition[] = array('sellergroup_id','=',$group_id);
  159. $condition[] = array('store_id','=',$this->store_info['store_id']);
  160. $sellergroup_model = model('sellergroup');
  161. $result = $sellergroup_model->delSellergroup($condition);
  162. if ($result) {
  163. $this->recordSellerlog(lang('group_deleted_successfully') . $group_id);
  164. ds_json_encode(10000, lang('ds_common_op_succ'));
  165. } else {
  166. $this->recordSellerlog(lang('deletion_group_failed') . $group_id);
  167. ds_json_encode(10001, lang('ds_common_op_fail'));
  168. }
  169. } else {
  170. ds_json_encode(10001, lang('param_error'));
  171. }
  172. }
  173. }