ShopAdminController.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace hd\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizGhs\admin\services\AdminService;
  6. use bizGhs\shop\classes\ShopAdminClass;
  7. use bizHd\admin\services\AdminRoleService;
  8. use bizHd\admin\services\ShopAdminService;
  9. use bizHd\wx\services\WxOpenService;
  10. use common\components\dict;
  11. use common\components\imgUtil;
  12. use common\components\sms;
  13. use common\components\stringUtil;
  14. use common\components\util;
  15. use Yii;
  16. class ShopAdminController extends BaseController
  17. {
  18. public $guestAccess = ['generate-admin'];
  19. //获取添加员工的验证码 shish 20210117
  20. public function actionGetStaffAuthCode()
  21. {
  22. $get = Yii::$app->request->get();
  23. $mobile = $get['mobile'] ?? '';
  24. if (stringUtil::isMobile($mobile) == false) {
  25. util::fail('请输入正确手机号');
  26. }
  27. $rand = rand(11111, 99999);
  28. $minute = 10;
  29. sms::send($mobile . ',' . $rand . ',' . $minute, '您的员工验证码:{$var},{$var}分钟内有效');
  30. $ptStyle = Yii::$app->params['ptStyle'];
  31. $cacheKey = 'add_staff_auth_code_' . $ptStyle . '_' . $mobile;
  32. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 600, $rand]);
  33. util::complete();
  34. }
  35. //添加员工
  36. public function actionAddStaff()
  37. {
  38. $post = Yii::$app->request->post();
  39. $authCode = $post['authCode'] ?? '';
  40. $mobile = $post['mobile'] ?? '';
  41. $name = $post['name'] ?? '';
  42. //避免重复提交
  43. util::checkRepeatCommit($mobile, 10);
  44. $ptStyle = Yii::$app->params['ptStyle'];
  45. $cacheKey = 'add_staff_auth_code_' . $ptStyle . '_' . $mobile;
  46. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  47. if (empty($saveAuthCode)) {
  48. util::fail('请填写验证码哦');
  49. }
  50. if (empty($authCode)) {
  51. util::fail('请填写验证码');
  52. }
  53. if ($saveAuthCode != $authCode) {
  54. util::fail('验证码错误');
  55. }
  56. $adminInfo = ['name' => $name, 'mobile' => $mobile, 'style' => $ptStyle,];
  57. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  58. $admin = AdminService::replaceAdmin($adminInfo, $fromApp);
  59. $post['shopId'] = $this->shopId;
  60. $respond = \bizGhs\shop\services\ShopAdminService::appGenerateStaff($post, $admin);
  61. util::success($respond);
  62. }
  63. //创建管理员数据准备 ssh 2020.4.17
  64. public function actionPrepareBind()
  65. {
  66. $post = Yii::$app->request->post();
  67. $roleId = isset($post['roleId']) ? $post['roleId'] : 0;
  68. $shopAdmin = $this->shopAdmin->attributes;
  69. if ($shopAdmin['super'] != 1) {
  70. util::fail('超管才能操作');
  71. }
  72. $role = AdminRoleService::getById($roleId);
  73. if (empty($role) || isset($role['sjId']) != $this->sjId) {
  74. util::fail('请选择角色!');
  75. }
  76. unset($post['userId']);
  77. unset($post['status']);
  78. $post['shopId'] = $this->shopId;
  79. $post['adminId'] = $this->adminId;
  80. $merchant = WxOpenService::getWxInfo();
  81. $post['merchant'] = $merchant;
  82. $respond = ShopAdminService::prepareBindAdmin($post);
  83. $miniCode = isset($respond['miniCode']) ? imgUtil::getPrefix() . $respond['miniCode'] : '';
  84. util::success(['miniCode' => $miniCode]);
  85. }
  86. //创建管理员 ssh 2020.4.20
  87. public function actionGenerateAdmin()
  88. {
  89. $post = Yii::$app->request->post();
  90. $post['adminId'] = $this->adminId;
  91. $admin = $this->admin->attributes;
  92. $currentShopId = $admin['currentShopId'] ?? 0;
  93. if (!empty($currentShopId)) {
  94. $shop = ShopClass::getShopInfo($currentShopId);
  95. //一个人不能同时在二个商家门店下工作
  96. if (isset($shop['sjId']) && $shop['sjId'] != $this->sjId) {
  97. util::fail('您已经是别的商家员工');
  98. }
  99. }
  100. $openShop = $admin['openShop'] ?? AdminClass::OPEN_SHOP_NO;
  101. if ($openShop != AdminClass::OPEN_SHOP_NO) {
  102. util::fail('您已申请开过店,不能成为别人的员工');
  103. }
  104. $respond = ShopAdminService::generateAdmin($post, $admin);
  105. util::success($respond);
  106. }
  107. //收款通知 ssh 2020.1.4
  108. public function actionUpdateRemind()
  109. {
  110. $get = Yii::$app->request->get();
  111. $id = isset($get['id']) ? $get['id'] : 0;
  112. $remind = isset($get['remind']) && is_numeric($get['remind']) ? $get['remind'] : 0;
  113. $shopAdmin = ShopAdminService::getById($id);
  114. ShopAdminService::valid($shopAdmin, $this->shopId);
  115. ShopAdminService::updateById($id, ['remind' => $remind]);
  116. util::complete();
  117. }
  118. //启用与停用 ssh 2020.1.4
  119. public function actionUpdateStatus()
  120. {
  121. $get = Yii::$app->request->get();
  122. $id = isset($get['id']) && is_numeric($get['id']) ? $get['id'] : 0;
  123. if ($id == $this->shopAdminId) {
  124. util::fail('不能禁用自己');
  125. }
  126. $status = isset($get['status']) ? $get['status'] : 0;
  127. $shopAdmin = ShopAdminService::getById($id);
  128. ShopAdminService::valid($shopAdmin, $this->shopId);
  129. ShopAdminService::updateById($id, ['status' => $status]);
  130. util::complete();
  131. }
  132. //员工列表 ssh 2019.12.8
  133. public function actionList()
  134. {
  135. $where = [];
  136. $where['shopId'] = $this->shopId;
  137. $where['delStatus'] = 0;
  138. $list = ShopAdminService::getAdminList($where);
  139. util::success($list);
  140. }
  141. //获取员工信息 ssh 2021.1.13
  142. public function actionDetail()
  143. {
  144. $get = Yii::$app->request->get();
  145. $id = isset($get['id']) ? $get['id'] : 0;
  146. $respond = ShopAdminClass::getAdminInfo($id);
  147. ShopAdminClass::valid($respond, $this->shopId);
  148. util::success($respond);
  149. }
  150. //修改员工信息
  151. public function actionUpdate()
  152. {
  153. $post = Yii::$app->request->post();
  154. $id = $post['id'] ?? 0;
  155. $shopAdmin = $this->shopAdmin->attributes;
  156. if ($shopAdmin['super'] != 1) {
  157. util::fail('超管才能操作');
  158. }
  159. if (empty($id)) {
  160. util::fail('请选择员工');
  161. }
  162. $relation = ShopAdminClass::getById($id, true);
  163. if (empty($relation)) {
  164. util::fail('没有找到员工');
  165. }
  166. ShopAdminClass::valid($relation, $this->shopId);
  167. unset($post['id']);
  168. $roleId = $post['roleId'] ?? 0;
  169. $remind = $post['remind'] ?? 0;
  170. $status = $post['status'] ?? 1;
  171. $relation->roleId = $roleId;
  172. $relation->remind = $remind;
  173. $relation->status = $status;
  174. if (isset($post['name']) && !empty($post['name'])) {
  175. $relation->name = $post['name'];
  176. }
  177. $relation->save();
  178. //若有传密码,则修改密码
  179. $password = $post['password'] ?? '';
  180. if (!empty($password)) {
  181. $adminId = $relation->adminId;
  182. $password = password_hash($password, PASSWORD_BCRYPT);
  183. AdminClass::updateById($adminId, ['password' => $password]);
  184. }
  185. util::complete('修改成功');
  186. }
  187. //删除员工关系 ssh 2021.1.14
  188. public function actionDelete()
  189. {
  190. $id = Yii::$app->request->get('id');
  191. $shopAdmin = $this->shopAdmin->attributes;
  192. if ($shopAdmin['super'] != 1) {
  193. util::fail('超管才能操作');
  194. }
  195. $relation = ShopAdminClass::getById($id, true);
  196. \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->shopId);
  197. util::complete();
  198. }
  199. }