Selleraccountgroup.php 7.9 KB

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