ShopAdminController.php 7.8 KB

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