Selleraccount.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 Selleraccount 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/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. $seller_model = model('seller');
  35. $condition = array(
  36. 'seller.store_id' => $this->store_info['store_id'],
  37. 'seller.is_admin' => 0,
  38. );
  39. $seller_list = $seller_model->getSellerList($condition);
  40. $result = array(
  41. 'seller_list' => $seller_list
  42. );
  43. ds_json_encode(10000, lang('ds_common_op_succ'), $result);
  44. }
  45. /**
  46. * @api {POST} api/Selleraccount/group_list 获取店铺账户组
  47. * @apiVersion 1.0.0
  48. * @apiGroup Selleraccount
  49. *
  50. * @apiHeader {String} X-DS-KEY 卖家授权token
  51. *
  52. * @apiSuccess {String} code 返回码,10000为成功
  53. * @apiSuccess {String} message 返回消息
  54. * @apiSuccess {Object} result 返回数据
  55. * @apiSuccess {Object[]} result.sellergroup_list 账号组列表 (返回字段参考sellergroup表)
  56. */
  57. public function group_list() {
  58. $sellergroup_model = model('sellergroup');
  59. $seller_group_list = $sellergroup_model->getSellergroupList(array('store_id' => $this->store_info['store_id']));
  60. if (empty($seller_group_list)) {
  61. ds_json_encode(10001, lang('please_set_account_group_first'));
  62. }
  63. $result = array(
  64. 'sellergroup_list' => $seller_group_list,
  65. );
  66. ds_json_encode(10000, lang('ds_common_op_fail'), $result);
  67. }
  68. /**
  69. * @api {POST} api/Selleraccount/account_add 新增店铺子账户
  70. * @apiVersion 1.0.0
  71. * @apiGroup Selleraccount
  72. *
  73. * @apiHeader {String} X-DS-KEY 卖家授权token
  74. *
  75. * @apiParam {String} member_name 用户名
  76. * @apiParam {String} password 密码
  77. * @apiParam {String} seller_name 店铺账号名
  78. * @apiParam {Int} group_id 账户组ID
  79. *
  80. * @apiSuccess {String} code 返回码,10000为成功
  81. * @apiSuccess {String} message 返回消息
  82. * @apiSuccess {Object} result 返回数据
  83. */
  84. public function account_add() {
  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 = input('post.seller_name');
  92. if ($this->_is_seller_name_exist($seller_name)) {
  93. ds_json_encode(10001, lang('seller_account_already_exists'));
  94. }
  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. $seller_id = intval(input('param.seller_id'));
  130. if ($seller_id <= 0) {
  131. ds_json_encode(10001, lang('param_error'));
  132. }
  133. $seller_model = model('seller');
  134. $seller_info = $seller_model->getSellerInfo(array('seller_id' => $seller_id));
  135. if (empty($seller_info) || intval($seller_info['store_id']) !== intval($this->store_info['store_id'])) {
  136. ds_json_encode(10001, lang('account_not_exist'));
  137. }
  138. //获取当前用户选择的账号组
  139. $sellergroup_model = model('sellergroup');
  140. $seller_group = $sellergroup_model->getSellergroupInfo(array('sellergroup_id' => $seller_info['sellergroup_id']));
  141. $seller_info['sellergroup_name'] = $seller_group['sellergroup_name'];
  142. $result = array(
  143. 'seller_info' => $seller_info
  144. );
  145. ds_json_encode(10000, '', $result);
  146. }
  147. /**
  148. * @api {POST} api/Selleraccount/account_edit 编辑店铺子账户
  149. * @apiVersion 1.0.0
  150. * @apiGroup Selleraccount
  151. *
  152. * @apiHeader {String} X-DS-KEY 卖家授权token
  153. *
  154. * @apiParam {Int} seller_id 子账户ID
  155. * @apiParam {Int} group_id 账户组ID
  156. *
  157. * @apiSuccess {String} code 返回码,10000为成功
  158. * @apiSuccess {String} message 返回消息
  159. * @apiSuccess {Object} result 返回数据
  160. */
  161. public function account_edit() {
  162. $param = array('sellergroup_id' => intval(input('post.group_id')));
  163. $condition = array(
  164. 'seller_id' => intval(input('post.seller_id')),
  165. 'store_id' => $this->store_info['store_id']
  166. );
  167. $seller_model = model('seller');
  168. $result = $seller_model->editSeller($param, $condition);
  169. if ($result) {
  170. $this->recordSellerlog(lang('edit_account_successfully') . input('post.seller_id'));
  171. ds_json_encode(10000, lang('ds_common_op_succ'));
  172. } else {
  173. $this->recordSellerlog(lang('edit_account_failed') . input('post.seller_id'), 0);
  174. ds_json_encode(10001, lang('ds_common_op_fail'));
  175. }
  176. }
  177. /**
  178. * @api {POST} api/Selleraccount/account_del 删除店铺子账户
  179. * @apiVersion 1.0.0
  180. * @apiGroup Selleraccount
  181. *
  182. * @apiHeader {String} X-DS-KEY 卖家授权token
  183. *
  184. * @apiParam {Int} seller_id 子账户ID
  185. *
  186. * @apiSuccess {String} code 返回码,10000为成功
  187. * @apiSuccess {String} message 返回消息
  188. * @apiSuccess {Object} result 返回数据
  189. */
  190. public function account_del() {
  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. $seller_name = input('param.seller_name');
  211. $result = $this->_is_seller_name_exist($seller_name);
  212. if ($result) {
  213. echo 'true';
  214. } else {
  215. echo 'false';
  216. }
  217. }
  218. private function _is_seller_name_exist($seller_name) {
  219. $condition = array();
  220. $condition[] = array('seller_name','=',$seller_name);
  221. $seller_model = model('seller');
  222. return $seller_model->isSellerExist($condition);
  223. }
  224. public function check_seller_member() {
  225. $member_name = input('param.member_name');
  226. $password = input('param.password');
  227. $result = $this->_check_seller_member($member_name, $password);
  228. if ($result) {
  229. echo 'true';
  230. } else {
  231. echo 'false';
  232. }
  233. }
  234. private function _check_seller_member($member_name, $password) {
  235. $member_info = $this->_check_member_password($member_name, $password);
  236. if ($member_info && !$this->_is_seller_member_exist($member_info['member_id'])) {
  237. return $member_info;
  238. } else {
  239. return false;
  240. }
  241. }
  242. private function _check_member_password($member_name, $password) {
  243. $condition = array();
  244. $condition[] = array('member_name','=',$member_name);
  245. $condition[] = array('member_password','=',md5($password));
  246. $member_model = model('member');
  247. $member_info = $member_model->getMemberInfo($condition);
  248. return $member_info;
  249. }
  250. private function _is_seller_member_exist($member_id) {
  251. $condition = array();
  252. $condition[] = array('member_id','=',$member_id);
  253. $seller_model = model('seller');
  254. return $seller_model->isSellerExist($condition);
  255. }
  256. }