Selleraccountgroup.php 8.2 KB

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