Selleraccount.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 = $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. $seller_id = intval(input('param.seller_id'));
  127. if ($seller_id <= 0) {
  128. ds_json_encode(10001, lang('param_error'));
  129. }
  130. $seller_model = model('seller');
  131. $seller_info = $seller_model->getSellerInfo(array('seller_id' => $seller_id));
  132. if (empty($seller_info) || intval($seller_info['store_id']) !== intval($this->store_info['store_id'])) {
  133. ds_json_encode(10001, lang('account_not_exist'));
  134. }
  135. //获取当前用户选择的账号组
  136. $sellergroup_model = model('sellergroup');
  137. $seller_group = $sellergroup_model->getSellergroupInfo(array('sellergroup_id' => $seller_info['sellergroup_id']));
  138. $seller_info['sellergroup_name'] = $seller_group['sellergroup_name'];
  139. $result = array(
  140. 'seller_info' => $seller_info
  141. );
  142. ds_json_encode(10000, '', $result);
  143. }
  144. /**
  145. * @api {POST} api/Selleraccount/account_edit 编辑店铺子账户
  146. * @apiVersion 1.0.0
  147. * @apiGroup Selleraccount
  148. *
  149. * @apiHeader {String} X-DS-KEY 卖家授权token
  150. *
  151. * @apiParam {Int} seller_id 子账户ID
  152. * @apiParam {Int} group_id 账户组ID
  153. *
  154. * @apiSuccess {String} code 返回码,10000为成功
  155. * @apiSuccess {String} message 返回消息
  156. * @apiSuccess {Object} result 返回数据
  157. */
  158. public function account_edit() {
  159. $param = array('sellergroup_id' => intval(input('post.group_id')));
  160. $condition = array(
  161. 'seller_id' => intval(input('post.seller_id')),
  162. 'store_id' => $this->store_info['store_id']
  163. );
  164. $seller_model = model('seller');
  165. $result = $seller_model->editSeller($param, $condition);
  166. if ($result) {
  167. $this->recordSellerlog(lang('edit_account_successfully') . input('post.seller_id'));
  168. ds_json_encode(10000, lang('ds_common_op_succ'));
  169. } else {
  170. $this->recordSellerlog(lang('edit_account_failed') . input('post.seller_id'), 0);
  171. ds_json_encode(10001, lang('ds_common_op_fail'));
  172. }
  173. }
  174. /**
  175. * @api {POST} api/Selleraccount/account_del 删除店铺子账户
  176. * @apiVersion 1.0.0
  177. * @apiGroup Selleraccount
  178. *
  179. * @apiHeader {String} X-DS-KEY 卖家授权token
  180. *
  181. * @apiParam {Int} seller_id 子账户ID
  182. *
  183. * @apiSuccess {String} code 返回码,10000为成功
  184. * @apiSuccess {String} message 返回消息
  185. * @apiSuccess {Object} result 返回数据
  186. */
  187. public function account_del() {
  188. $seller_id = intval(input('post.seller_id'));
  189. if ($seller_id > 0) {
  190. $condition = array();
  191. $condition[] = array('seller_id','=',$seller_id);
  192. $condition[] = array('store_id','=',$this->store_info['store_id']);
  193. $seller_model = model('seller');
  194. $result = $seller_model->delSeller($condition);
  195. if ($result) {
  196. $this->recordSellerlog(lang('delete_account_successfully') . $seller_id);
  197. ds_json_encode(10000, lang('ds_common_op_succ'));
  198. } else {
  199. $this->recordSellerlog(lang('deletion_account_failed') . $seller_id);
  200. ds_json_encode(10001, lang('ds_common_op_fail'));
  201. }
  202. } else {
  203. ds_json_encode(10001, lang('param_error'));
  204. }
  205. }
  206. public function check_seller_name_exist() {
  207. $seller_name = input('param.seller_name');
  208. $result = $this->_is_seller_name_exist($seller_name);
  209. if ($result) {
  210. echo 'true';
  211. } else {
  212. echo 'false';
  213. }
  214. }
  215. private function _is_seller_name_exist($seller_name) {
  216. $condition = array();
  217. $condition[] = array('seller_name','=',$seller_name);
  218. $seller_model = model('seller');
  219. return $seller_model->isSellerExist($condition);
  220. }
  221. public function check_seller_member() {
  222. $member_name = input('param.member_name');
  223. $password = input('param.password');
  224. $result = $this->_check_seller_member($member_name, $password);
  225. if ($result) {
  226. echo 'true';
  227. } else {
  228. echo 'false';
  229. }
  230. }
  231. private function _check_seller_member($member_name, $password) {
  232. $member_info = $this->_check_member_password($member_name, $password);
  233. if ($member_info && !$this->_is_seller_member_exist($member_info['member_id'])) {
  234. return $member_info;
  235. } else {
  236. return false;
  237. }
  238. }
  239. private function _check_member_password($member_name, $password) {
  240. $condition = array();
  241. $condition[] = array('member_name','=',$member_name);
  242. $condition[] = array('member_password','=',md5($password));
  243. $member_model = model('member');
  244. $member_info = $member_model->getMemberInfo($condition);
  245. return $member_info;
  246. }
  247. private function _is_seller_member_exist($member_id) {
  248. $condition = array();
  249. $condition[] = array('member_id','=',$member_id);
  250. $seller_model = model('seller');
  251. return $seller_model->isSellerExist($condition);
  252. }
  253. }