| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- <?php
- namespace ghs\controllers;
- use biz\admin\classes\AdminClass;
- use biz\shop\classes\ShopClass;
- use bizGhs\admin\services\AdminService;
- use bizHd\wx\classes\WxOpenClass;
- use bizGhs\shop\classes\ShopAdminClass;
- use bizGhs\admin\services\AdminRoleService;
- use bizGhs\shop\services\ShopAdminService;
- 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'];
- //获取所有在职员工 ssh 20220507
- public function actionGetAllStaff()
- {
- $list = ShopAdminClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0, 'status' => 1, 'isPt' => 0,], null, 'id,name', null, true);
- util::success(['list' => $list]);
- }
- //获取添加员工的验证码 ssh 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()
- {
- $shop = $this->shop;
- $join = $shop->join ?? 0;
- $default = $shop->default ?? 0;
- if ($join == 0 && $default == 0) {
- util::fail('请在总店操作');
- }
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('没有权限');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $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('验证码错误');
- }
- $ptStyle = Yii::$app->params['ptStyle'];
- $adminInfo = ['name' => $name, 'mobile' => $mobile, 'style' => $ptStyle, 'currentGhsShopId' => $this->shopId];
- $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
- $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
- $post['shopId'] = $this->shopId;
- $respond = ShopAdminClass::appGenerateStaff($post, $admin);
- $transaction->commit();
- util::success($respond);
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("失败原因:" . $exception->getMessage());
- util::fail('添加失败');
- }
- }
- //创建管理员数据准备 ssh 2020.4.17
- public function actionPrepareBind()
- {
- $post = Yii::$app->request->post();
- $shopAdmin = $this->shopAdmin->attributes;
- if ($shopAdmin['super'] != 1) {
- util::fail('超管才能操作');
- }
- $roleId = isset($post['roleId']) ? $post['roleId'] : 0;
- $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['sjId'] = $this->sjId;
- $post['adminId'] = $this->adminId;
- $post['mainId'] = $this->mainId;
- $merchant = WxOpenClass::getGhsWxInfo();
- $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;
- $post['mainId'] = $this->mainId;
- $admin = $this->admin->attributes;
- $currentShopId = $admin['currentGhsShopId'] ?? 0;
- if (!empty($currentShopId)) {
- $shop = ShopClass::getShopInfo($currentShopId);
- //一个人不能同时在二个商家门店下工作
- if (isset($shop['sjId']) && $shop['sjId'] != $this->sjId) {
- util::fail('您已经是别的商家员工');
- }
- }
- $openShop = $admin['openGhsShop'] ?? AdminClass::OPEN_SHOP_NO;
- if ($openShop != AdminClass::OPEN_SHOP_NO) {
- util::fail('您已申请开过店,不能成为别人的员工');
- }
- $respond = ShopAdminService::generateAdmin($post, $admin);
- util::success($respond);
- }
- //收款通知 ssh 2021.1.14
- public function actionUpdateRemind()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $remind = $get['remind'] ?? 0;
- $relation = ShopAdminClass::getById($id, true);
- if (empty($relation)) {
- util::fail('没有找到员工');
- }
- ShopAdminClass::valid($relation->attributes, $this->mainId);
- $relation->remind = $remind;
- $relation->save();
- util::complete();
- }
- //启用与停用 ssh 2021.1.14
- public function actionUpdateStatus()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $status = $get['status'] ?? 0;
- $relation = ShopAdminClass::getById($id, true);
- if (empty($relation)) {
- util::fail('没有找到员工');
- }
- ShopAdminClass::valid($relation->attributes, $this->mainId);
- $relation->status = $status;
- $relation->save();
- util::complete();
- }
- //员工列表 ssh 2019.12.8
- public function actionList()
- {
- $where = [];
- $where['mainId'] = $this->mainId;
- $where['delStatus'] = 0;
- $where['isPt'] = 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 = ShopAdminService::getAdminInfo($id);
- ShopAdminClass::valid($respond, $this->mainId);
- util::success($respond);
- }
- //修改员工信息
- public function actionUpdate()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $shop = $this->shop;
- $join = $shop->join ?? 0;
- $default = $shop->default ?? 0;
- if ($join == 0 && $default == 0) {
- util::fail('请在总店操作');
- }
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('没有权限');
- }
- if (empty($id)) {
- util::fail('请选择员工');
- }
- $relation = ShopAdminClass::getById($id, true);
- if (empty($relation)) {
- util::fail('没有找到员工');
- }
- ShopAdminClass::valid($relation, $this->mainId);
- unset($post['id']);
- $roleId = $post['roleId'] ?? 0;
- $remind = $post['remind'] ?? 0;
- $status = $post['status'] ?? 1;
- $super = $post['super'] ?? 0;
- $founder = $relation->founder ?? 1;
- if ($founder == 2 && $super == 0) {
- util::fail('不能关闭超管权限');
- }
- $adminId = $relation->adminId;
- $relation->roleId = $roleId;
- $relation->remind = $remind;
- $relation->status = $status;
- $relation->super = $super;
- if (isset($post['name']) && !empty($post['name'])) {
- $name = $post['name'];
- $relation->name = $name;
- AdminClass::updateById($adminId, ['name' => $name]);
- ShopAdminClass::updateByCondition(['adminId' => $adminId], ['name' => $name]);
- }
- $relation->save();
- //若有传密码,则修改密码
- $password = $post['password'] ?? '';
- if (!empty($password)) {
- if (ctype_alnum($password)) {
- util::fail('密码必须是字母、数字和符号的组合');
- }
- $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');
- $shop = $this->shop;
- $join = $shop->join ?? 0;
- $default = $shop->default ?? 0;
- if ($join == 0 && $default == 0) {
- util::fail('请在总店操作');
- }
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('没有权限');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $relation = ShopAdminClass::getById($id, true);
- \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->mainId);
- $transaction->commit();
- util::complete();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("失败原因:" . $exception->getMessage());
- util::fail('删除失败');
- }
- }
- }
|