Selleraccount.php 10 KB

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