| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <?php
- namespace hd\controllers;
- use biz\admin\classes\AdminClass;
- use biz\shop\classes\ShopClass;
- use bizGhs\admin\services\AdminService;
- use bizGhs\shop\classes\ShopAdminClass;
- use bizHd\admin\services\AdminRoleService;
- use bizHd\admin\services\ShopAdminService;
- use bizHd\wx\services\WxOpenService;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\sms;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class ShopAdminController extends BaseController
- {
- public $guestAccess = ['generate-admin'];
- //获取添加员工的验证码 shish 20210117
- public function actionGetStaffAuthCode()
- {
- $get = Yii::$app->request->get();
- $mobile = $get['mobile'] ?? '';
- if (stringUtil::isMobile($mobile) == false) {
- util::fail('请输入正确手机号');
- }
- $rand = rand(11111, 99999);
- $minute = 10;
- sms::send($mobile . ',' . $rand . ',' . $minute, '您的员工验证码:{$var},{$var}分钟内有效');
- $ptStyle = Yii::$app->params['ptStyle'];
- $cacheKey = 'add_staff_auth_code_' . $ptStyle . '_' . $mobile;
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 600, $rand]);
- util::complete();
- }
- //添加员工
- public function actionAddStaff()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('没有权限');
- }
- $post = Yii::$app->request->post();
- $authCode = $post['authCode'] ?? '';
- $mobile = $post['mobile'] ?? '';
- $name = $post['name'] ?? '';
- //避免重复提交
- util::checkRepeatCommit($mobile, 10);
- $ptStyle = Yii::$app->params['ptStyle'];
- $cacheKey = 'add_staff_auth_code_' . $ptStyle . '_' . $mobile;
- $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (empty($saveAuthCode)) {
- util::fail('请填写验证码哦');
- }
- if (empty($authCode)) {
- util::fail('请填写验证码');
- }
- if ($saveAuthCode != $authCode) {
- util::fail('验证码错误');
- }
- $adminInfo = ['name' => $name, 'mobile' => $mobile, 'style' => $ptStyle,];
- $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
- $admin = AdminService::replaceAdmin($adminInfo, $fromApp);
- $post['shopId'] = $this->shopId;
- $respond = \bizGhs\shop\services\ShopAdminService::appGenerateStaff($post, $admin);
- util::success($respond);
- }
- //创建管理员数据准备 ssh 2020.4.17
- public function actionPrepareBind()
- {
- $post = Yii::$app->request->post();
- $roleId = isset($post['roleId']) ? $post['roleId'] : 0;
- $shopAdmin = $this->shopAdmin->attributes;
- if ($shopAdmin['super'] != 1) {
- util::fail('超管才能操作');
- }
- $role = AdminRoleService::getById($roleId);
- if (empty($role) || isset($role['sjId']) != $this->sjId) {
- util::fail('请选择角色!');
- }
- unset($post['userId']);
- unset($post['status']);
- $post['shopId'] = $this->shopId;
- $post['adminId'] = $this->adminId;
- $merchant = WxOpenService::getWxInfo();
- $post['merchant'] = $merchant;
- $respond = ShopAdminService::prepareBindAdmin($post);
- $miniCode = isset($respond['miniCode']) ? imgUtil::getPrefix() . $respond['miniCode'] : '';
- util::success(['miniCode' => $miniCode]);
- }
- //创建管理员 ssh 2020.4.20
- public function actionGenerateAdmin()
- {
- $post = Yii::$app->request->post();
- $post['adminId'] = $this->adminId;
- $admin = $this->admin->attributes;
- $currentShopId = $admin['currentShopId'] ?? 0;
- if (!empty($currentShopId)) {
- $shop = ShopClass::getShopInfo($currentShopId);
- //一个人不能同时在二个商家门店下工作
- if (isset($shop['sjId']) && $shop['sjId'] != $this->sjId) {
- util::fail('您已经是别的商家员工');
- }
- }
- $openShop = $admin['openShop'] ?? AdminClass::OPEN_SHOP_NO;
- if ($openShop != AdminClass::OPEN_SHOP_NO) {
- util::fail('您已申请开过店,不能成为别人的员工');
- }
- $respond = ShopAdminService::generateAdmin($post, $admin);
- util::success($respond);
- }
- //收款通知 ssh 2020.1.4
- public function actionUpdateRemind()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $remind = isset($get['remind']) && is_numeric($get['remind']) ? $get['remind'] : 0;
- $shopAdmin = ShopAdminService::getById($id);
- ShopAdminService::valid($shopAdmin, $this->shopId);
- ShopAdminService::updateById($id, ['remind' => $remind]);
- util::complete();
- }
- //启用与停用 ssh 2020.1.4
- public function actionUpdateStatus()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) && is_numeric($get['id']) ? $get['id'] : 0;
- if ($id == $this->shopAdminId) {
- util::fail('不能禁用自己');
- }
- $status = isset($get['status']) ? $get['status'] : 0;
- $shopAdmin = ShopAdminService::getById($id);
- ShopAdminService::valid($shopAdmin, $this->shopId);
- ShopAdminService::updateById($id, ['status' => $status]);
- util::complete();
- }
- //员工列表 ssh 2019.12.8
- public function actionList()
- {
- $where = [];
- $where['shopId'] = $this->shopId;
- $where['delStatus'] = 0;
- $list = ShopAdminService::getAdminList($where);
- util::success($list);
- }
- //获取员工信息 ssh 2021.1.13
- public function actionDetail()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $respond = ShopAdminClass::getAdminInfo($id);
- ShopAdminClass::valid($respond, $this->shopId);
- util::success($respond);
- }
- //修改员工信息
- public function actionUpdate()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $shopAdmin = $this->shopAdmin->attributes;
- if ($shopAdmin['super'] != 1) {
- util::fail('超管才能操作');
- }
- if (empty($id)) {
- util::fail('请选择员工');
- }
- $relation = ShopAdminClass::getById($id, true);
- if (empty($relation)) {
- util::fail('没有找到员工');
- }
- ShopAdminClass::valid($relation, $this->shopId);
- unset($post['id']);
- $roleId = $post['roleId'] ?? 0;
- $remind = $post['remind'] ?? 0;
- $status = $post['status'] ?? 1;
- $super = $post['super'] ?? 0;
- $relation->roleId = $roleId;
- $relation->remind = $remind;
- $relation->status = $status;
- $relation->super = $super;
- if (isset($post['name']) && !empty($post['name'])) {
- $relation->name = $post['name'];
- }
- $relation->save();
- //若有传密码,则修改密码
- $password = $post['password'] ?? '';
- if (!empty($password)) {
- $adminId = $relation->adminId;
- $password = password_hash($password, PASSWORD_BCRYPT);
- AdminClass::updateById($adminId, ['password' => $password]);
- }
- util::complete('修改成功');
- }
- //删除员工关系 ssh 2021.1.14
- public function actionDelete()
- {
- $id = Yii::$app->request->get('id');
- $shopAdmin = $this->shopAdmin->attributes;
- if ($shopAdmin['super'] != 1) {
- util::fail('超管才能操作');
- }
- $relation = ShopAdminClass::getById($id, true);
- \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->shopId);
- util::complete();
- }
- }
|