ShopAdminController.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizGhs\admin\services\AdminService;
  6. use bizHd\wx\classes\WxOpenClass;
  7. use bizGhs\shop\classes\ShopAdminClass;
  8. use bizGhs\admin\services\AdminRoleService;
  9. use bizGhs\shop\services\ShopAdminService;
  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. $shopAdmin = $this->shopAdmin;
  39. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  40. util::fail('没有权限');
  41. }
  42. $post = Yii::$app->request->post();
  43. $authCode = $post['authCode'] ?? '';
  44. $mobile = $post['mobile'] ?? '';
  45. $name = $post['name'] ?? '';
  46. //避免重复提交
  47. util::checkRepeatCommit($mobile, 10);
  48. $ptStyle = Yii::$app->params['ptStyle'];
  49. $cacheKey = 'add_staff_auth_code_' . $ptStyle . '_' . $mobile;
  50. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  51. if (empty($saveAuthCode)) {
  52. util::fail('请填写验证码哦');
  53. }
  54. if (empty($authCode)) {
  55. util::fail('请填写验证码');
  56. }
  57. if ($saveAuthCode != $authCode) {
  58. util::fail('验证码错误');
  59. }
  60. $ptStyle = Yii::$app->params['ptStyle'];
  61. $adminInfo = ['name' => $name, 'mobile' => $mobile, 'style' => $ptStyle,];
  62. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  63. $admin = AdminService::replaceAdmin($adminInfo, $fromApp);
  64. $post['shopId'] = $this->shopId;
  65. $respond = ShopAdminService::appGenerateStaff($post, $admin);
  66. util::success($respond);
  67. }
  68. //创建管理员数据准备 ssh 2020.4.17
  69. public function actionPrepareBind()
  70. {
  71. $post = Yii::$app->request->post();
  72. $shopAdmin = $this->shopAdmin->attributes;
  73. if ($shopAdmin['super'] != 1) {
  74. util::fail('超管才能操作');
  75. }
  76. $roleId = isset($post['roleId']) ? $post['roleId'] : 0;
  77. $role = AdminRoleService::getById($roleId);
  78. if (empty($role) || isset($role['sjId']) != $this->sjId) {
  79. util::fail('请选择角色!');
  80. }
  81. unset($post['userId']);
  82. unset($post['status']);
  83. $post['shopId'] = $this->shopId;
  84. $post['sjId'] = $this->sjId;
  85. $post['adminId'] = $this->adminId;
  86. $merchant = WxOpenClass::getGhsWxInfo();
  87. $post['merchant'] = $merchant;
  88. $respond = ShopAdminService::prepareBindAdmin($post);
  89. $miniCode = isset($respond['miniCode']) ? imgUtil::getPrefix() . $respond['miniCode'] : '';
  90. util::success(['miniCode' => $miniCode]);
  91. }
  92. //创建员工 ssh 2020.4.20
  93. public function actionGenerateAdmin()
  94. {
  95. $post = Yii::$app->request->post();
  96. $post['adminId'] = $this->adminId;
  97. $admin = $this->admin->attributes;
  98. $currentShopId = $admin['currentShopId'] ?? 0;
  99. if (!empty($currentShopId)) {
  100. $shop = ShopClass::getShopInfo($currentShopId);
  101. //一个人不能同时在二个商家门店下工作
  102. if (isset($shop['sjId']) && $shop['sjId'] != $this->sjId) {
  103. util::fail('您已经是别的商家员工');
  104. }
  105. }
  106. $openShop = $admin['openShop'] ?? AdminClass::OPEN_SHOP_NO;
  107. if ($openShop != AdminClass::OPEN_SHOP_NO) {
  108. util::fail('您已申请开过店,不能成为别人的员工');
  109. }
  110. $respond = ShopAdminService::generateAdmin($post, $admin);
  111. util::success($respond);
  112. }
  113. //收款通知 ssh 2021.1.14
  114. public function actionUpdateRemind()
  115. {
  116. $get = Yii::$app->request->get();
  117. $id = $get['id'] ?? 0;
  118. $remind = $get['remind'] ?? 0;
  119. $relation = ShopAdminClass::getById($id, true);
  120. if (empty($relation)) {
  121. util::fail('没有找到员工');
  122. }
  123. ShopAdminClass::valid($relation->attributes, $this->shopId);
  124. $relation->remind = $remind;
  125. $relation->save();
  126. util::complete();
  127. }
  128. //启用与停用 ssh 2021.1.14
  129. public function actionUpdateStatus()
  130. {
  131. $get = Yii::$app->request->get();
  132. $id = $get['id'] ?? 0;
  133. $status = $get['status'] ?? 0;
  134. $relation = ShopAdminClass::getById($id, true);
  135. if (empty($relation)) {
  136. util::fail('没有找到员工');
  137. }
  138. ShopAdminClass::valid($relation->attributes, $this->shopId);
  139. $relation->status = $status;
  140. $relation->save();
  141. util::complete();
  142. }
  143. //员工列表 ssh 2019.12.8
  144. public function actionList()
  145. {
  146. $where = [];
  147. $where['shopId'] = $this->shopId;
  148. $where['delStatus'] = 0;
  149. $where['isPt'] = 0;
  150. $list = ShopAdminService::getAdminList($where);
  151. util::success($list);
  152. }
  153. //获取员工信息 ssh 2021.1.13
  154. public function actionDetail()
  155. {
  156. $get = Yii::$app->request->get();
  157. $id = isset($get['id']) ? $get['id'] : 0;
  158. $respond = ShopAdminService::getAdminInfo($id);
  159. ShopAdminClass::valid($respond, $this->shopId);
  160. util::success($respond);
  161. }
  162. //修改员工信息
  163. public function actionUpdate()
  164. {
  165. $post = Yii::$app->request->post();
  166. $id = $post['id'] ?? 0;
  167. $shopAdmin = $this->shopAdmin;
  168. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  169. util::fail('没有权限');
  170. }
  171. if (empty($id)) {
  172. util::fail('请选择员工');
  173. }
  174. $relation = ShopAdminClass::getById($id, true);
  175. if (empty($relation)) {
  176. util::fail('没有找到员工');
  177. }
  178. ShopAdminClass::valid($relation, $this->shopId);
  179. unset($post['id']);
  180. $roleId = $post['roleId'] ?? 0;
  181. $remind = $post['remind'] ?? 0;
  182. $status = $post['status'] ?? 1;
  183. $super = $post['super'] ?? 0;
  184. $founder = $relation->founder ?? 1;
  185. if ($founder == 2 && $super == 0) {
  186. util::fail('不能关闭超管权限');
  187. }
  188. $relation->roleId = $roleId;
  189. $relation->remind = $remind;
  190. $relation->status = $status;
  191. $relation->super = $super;
  192. if (isset($post['name']) && !empty($post['name'])) {
  193. $relation->name = $post['name'];
  194. }
  195. $relation->save();
  196. //若有传密码,则修改密码
  197. $password = $post['password'] ?? '';
  198. if (!empty($password)) {
  199. if (ctype_alnum($password)) {
  200. util::fail('密码必须是字母、数字和符号的组合');
  201. }
  202. $adminId = $relation->adminId;
  203. $password = password_hash($password, PASSWORD_BCRYPT);
  204. AdminClass::updateById($adminId, ['password' => $password]);
  205. }
  206. util::complete('修改成功');
  207. }
  208. //删除员工关系 ssh 2021.1.14
  209. public function actionDelete()
  210. {
  211. $id = Yii::$app->request->get('id');
  212. $shopAdmin = $this->shopAdmin;
  213. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  214. util::fail('没有权限');
  215. }
  216. $relation = ShopAdminClass::getById($id, true);
  217. \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->shopId);
  218. util::complete();
  219. }
  220. }