Selleraccount.php 10 KB

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