Selleraccount.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 卖家子账号控制器
  10. */
  11. class Selleraccount extends MobileSeller
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/selleraccount.lang.php');
  17. }
  18. /**
  19. * @api {POST} api/Selleraccount/account_list 获取子账户列表
  20. * @apiVersion 1.0.0
  21. * @apiGroup Selleraccount
  22. *
  23. * @apiHeader {String} X-DS-KEY 卖家授权token
  24. *
  25. * @apiSuccess {String} code 返回码,10000为成功
  26. * @apiSuccess {String} message 返回消息
  27. * @apiSuccess {Object} result 返回数据
  28. * @apiSuccess {Object[]} result.seller_list 子账号列表 (返回字段参考seller表)
  29. */
  30. public function account_list()
  31. {
  32. $seller_model = model('seller');
  33. $condition = array(
  34. 'seller.store_id' => $this->store_info['store_id'],
  35. 'seller.is_admin' => 0,
  36. );
  37. $seller_list = $seller_model->getSellerList($condition);
  38. $result = array(
  39. 'seller_list' => $seller_list
  40. );
  41. ds_json_encode(10000, lang('ds_common_op_succ'), $result);
  42. }
  43. /**
  44. * @api {POST} api/Selleraccount/group_list 获取店铺账户组
  45. * @apiVersion 1.0.0
  46. * @apiGroup Selleraccount
  47. *
  48. * @apiHeader {String} X-DS-KEY 卖家授权token
  49. *
  50. * @apiSuccess {String} code 返回码,10000为成功
  51. * @apiSuccess {String} message 返回消息
  52. * @apiSuccess {Object} result 返回数据
  53. * @apiSuccess {Object[]} result.sellergroup_list 账号组列表 (返回字段参考sellergroup表)
  54. */
  55. public function group_list()
  56. {
  57. $sellergroup_model = model('sellergroup');
  58. $seller_group_list = $sellergroup_model->getSellergroupList(array('store_id' => $this->store_info['store_id']));
  59. if (empty($seller_group_list)) {
  60. ds_json_encode(10001, lang('please_set_account_group_first'));
  61. }
  62. $result = array(
  63. 'sellergroup_list' => $seller_group_list,
  64. );
  65. ds_json_encode(10000, lang('ds_common_op_fail'), $result);
  66. }
  67. /**
  68. * @api {POST} api/Selleraccount/account_add 新增店铺子账户
  69. * @apiVersion 1.0.0
  70. * @apiGroup Selleraccount
  71. *
  72. * @apiHeader {String} X-DS-KEY 卖家授权token
  73. *
  74. * @apiParam {String} member_name 用户名
  75. * @apiParam {String} password 密码
  76. * @apiParam {String} seller_name 店铺账号名
  77. * @apiParam {Int} group_id 账户组ID
  78. *
  79. * @apiSuccess {String} code 返回码,10000为成功
  80. * @apiSuccess {String} message 返回消息
  81. * @apiSuccess {Object} result 返回数据
  82. */
  83. public function account_add()
  84. {
  85. $member_name = input('post.member_name');
  86. $password = input('post.password');
  87. $member_info = $this->_check_seller_member($member_name, $password);
  88. if (!$member_info) {
  89. ds_json_encode(10001, lang('user_authentication_failed'));
  90. }
  91. $seller_name = $member_name;
  92. $group_id = intval(input('post.group_id'));
  93. $seller_info = array(
  94. 'seller_name' => $seller_name,
  95. 'member_id' => $member_info['member_id'],
  96. 'sellergroup_id' => $group_id,
  97. 'store_id' => $this->store_info['store_id'],
  98. 'is_admin' => 0
  99. );
  100. $seller_model = model('seller');
  101. $result = $seller_model->addSeller($seller_info);
  102. if ($result) {
  103. $this->recordSellerlog(lang('add_account_successfully') . $result);
  104. ds_json_encode(10000, lang('ds_common_op_succ'));
  105. } else {
  106. $this->recordSellerlog(lang('failed_add_account'));
  107. ds_json_encode(10001, lang('ds_common_op_fail'));
  108. }
  109. }
  110. /**
  111. * @api {POST} api/Selleraccount/account_info 获取店铺单个子账户信息
  112. * @apiVersion 1.0.0
  113. * @apiGroup Selleraccount
  114. *
  115. * @apiHeader {String} X-DS-KEY 卖家授权token
  116. *
  117. * @apiParam {Int} seller_id 子账户ID
  118. *
  119. * @apiSuccess {String} code 返回码,10000为成功
  120. * @apiSuccess {String} message 返回消息
  121. * @apiSuccess {Object} result 返回数据
  122. * @apiSuccess {Object} seller_info 卖家信息 (返回字段参考seller表)
  123. * @apiSuccess {Object} seller_info.sellergroup_name 账号组名称
  124. */
  125. public function account_info()
  126. {
  127. $seller_id = intval(input('param.seller_id'));
  128. if ($seller_id <= 0) {
  129. ds_json_encode(10001, lang('param_error'));
  130. }
  131. $seller_model = model('seller');
  132. $seller_info = $seller_model->getSellerInfo(array('seller_id' => $seller_id));
  133. if (empty($seller_info) || intval($seller_info['store_id']) !== intval($this->store_info['store_id'])) {
  134. ds_json_encode(10001, lang('account_not_exist'));
  135. }
  136. //获取当前用户选择的账号组
  137. $sellergroup_model = model('sellergroup');
  138. $seller_group = $sellergroup_model->getSellergroupInfo(array('sellergroup_id' => $seller_info['sellergroup_id']));
  139. $seller_info['sellergroup_name'] = $seller_group['sellergroup_name'];
  140. $result = array(
  141. 'seller_info' => $seller_info
  142. );
  143. ds_json_encode(10000, '', $result);
  144. }
  145. /**
  146. * @api {POST} api/Selleraccount/account_edit 编辑店铺子账户
  147. * @apiVersion 1.0.0
  148. * @apiGroup Selleraccount
  149. *
  150. * @apiHeader {String} X-DS-KEY 卖家授权token
  151. *
  152. * @apiParam {Int} seller_id 子账户ID
  153. * @apiParam {Int} group_id 账户组ID
  154. *
  155. * @apiSuccess {String} code 返回码,10000为成功
  156. * @apiSuccess {String} message 返回消息
  157. * @apiSuccess {Object} result 返回数据
  158. */
  159. public function account_edit()
  160. {
  161. $param = array('sellergroup_id' => intval(input('post.group_id')));
  162. $condition = array(
  163. 'seller_id' => intval(input('post.seller_id')),
  164. 'store_id' => $this->store_info['store_id']
  165. );
  166. $seller_model = model('seller');
  167. $result = $seller_model->editSeller($param, $condition);
  168. if ($result) {
  169. $this->recordSellerlog(lang('edit_account_successfully') . input('post.seller_id'));
  170. ds_json_encode(10000, lang('ds_common_op_succ'));
  171. } else {
  172. $this->recordSellerlog(lang('edit_account_failed') . input('post.seller_id'), 0);
  173. ds_json_encode(10001, lang('ds_common_op_fail'));
  174. }
  175. }
  176. /**
  177. * @api {POST} api/Selleraccount/account_del 删除店铺子账户
  178. * @apiVersion 1.0.0
  179. * @apiGroup Selleraccount
  180. *
  181. * @apiHeader {String} X-DS-KEY 卖家授权token
  182. *
  183. * @apiParam {Int} seller_id 子账户ID
  184. *
  185. * @apiSuccess {String} code 返回码,10000为成功
  186. * @apiSuccess {String} message 返回消息
  187. * @apiSuccess {Object} result 返回数据
  188. */
  189. public function account_del()
  190. {
  191. $seller_id = intval(input('post.seller_id'));
  192. if ($seller_id > 0) {
  193. $condition = array();
  194. $condition[] = array('seller_id', '=', $seller_id);
  195. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  196. $seller_model = model('seller');
  197. $result = $seller_model->delSeller($condition);
  198. if ($result) {
  199. $this->recordSellerlog(lang('delete_account_successfully') . $seller_id);
  200. ds_json_encode(10000, lang('ds_common_op_succ'));
  201. } else {
  202. $this->recordSellerlog(lang('deletion_account_failed') . $seller_id);
  203. ds_json_encode(10001, lang('ds_common_op_fail'));
  204. }
  205. } else {
  206. ds_json_encode(10001, lang('param_error'));
  207. }
  208. }
  209. public function check_seller_name_exist()
  210. {
  211. $seller_name = input('param.seller_name');
  212. $result = $this->_is_seller_name_exist($seller_name);
  213. if ($result) {
  214. echo 'true';
  215. } else {
  216. echo 'false';
  217. }
  218. }
  219. private function _is_seller_name_exist($seller_name)
  220. {
  221. $condition = array();
  222. $condition[] = array('seller_name', '=', $seller_name);
  223. $seller_model = model('seller');
  224. return $seller_model->isSellerExist($condition);
  225. }
  226. public function check_seller_member()
  227. {
  228. $member_name = input('param.member_name');
  229. $password = input('param.password');
  230. $result = $this->_check_seller_member($member_name, $password);
  231. if ($result) {
  232. echo 'true';
  233. } else {
  234. echo 'false';
  235. }
  236. }
  237. private function _check_seller_member($member_name, $password)
  238. {
  239. $member_info = $this->_check_member_password($member_name, $password);
  240. if ($member_info && !$this->_is_seller_member_exist($member_info['member_id'])) {
  241. return $member_info;
  242. } else {
  243. return false;
  244. }
  245. }
  246. private function _check_member_password($member_name, $password)
  247. {
  248. $condition = array();
  249. $condition[] = array('member_name', '=', $member_name);
  250. $condition[] = array('member_password', '=', md5($password));
  251. $member_model = model('member');
  252. $member_info = $member_model->getMemberInfo($condition);
  253. return $member_info;
  254. }
  255. private function _is_seller_member_exist($member_id)
  256. {
  257. $condition = array();
  258. $condition[] = array('member_id', '=', $member_id);
  259. $seller_model = model('seller');
  260. return $seller_model->isSellerExist($condition);
  261. }
  262. }