request->get(); $id = $get['id'] ?? 0; $staff = ShopAdminClass::getById($id, true); if (empty($staff)) { util::fail('没有员工'); } if ($staff->mainId != $this->mainId) { util::fail('不是你的'); } $current = $this->shopAdmin; if ($current->mobile != 15280215347) { util::fail('无效操作'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $newAdminId = $staff->adminId; $mainId = $staff->mainId; $shopList = ShopClass::getAllByCondition(['mainId' => $mainId], null, 'id,shopName,mainId,adminId', null, true); $adminId = 0; if (!empty($shopList)) { foreach ($shopList as $shop) { if (!empty($shop->adminId)) { $adminId = $shop->adminId; } $shop->adminId = $newAdminId; $shop->save(); } if (!empty($adminId)) { ShopAdminClass::updateByCondition(['mainId' => $mainId, 'adminId' => $adminId], ['founder' => 1]); } } $staff->super = 1; $staff->finance = 1; $staff->switchShop = 1; $staff->founder = 2; $staff->save(); $transaction->commit(); util::complete('操作成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("操作失败原因:" . $e->getMessage()); util::fail('操作失败'); } } //获取当前登录员工的信息 ssh 20230802 public function actionGetStaffInfo() { $staff = $this->shopAdmin; util::success(['staff' => $staff]); } //获取所有在职员工 ssh 20220507 public function actionGetAllStaff() { $where = ['mainId' => $this->mainId, 'delStatus' => 0, 'status' => 1, 'isPt' => 0,]; $list = ShopAdminClass::getAllByCondition($where, 'inTurn DESC', 'id,name,mobile', 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() { $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('没有权限'); } $adminId = $this->adminId; $shop = $this->shop; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $post = Yii::$app->request->post(); $authCode = $post['authCode'] ?? ''; $mobile = $post['mobile'] ?? ''; $name = $post['name'] ?? ''; $finance = $post['finance'] ?? 0; $identity = $post['identity'] ?? 0; $switchShop = $post['switchShop'] ?? 0; $ptSuperAdminId = AdminClass::getPtSuperAdminId(); if ($shop->adminId != $adminId && $adminId != $ptSuperAdminId) { if ($finance == 1) { util::fail('超管才能开启员工财务权限'); } if ($switchShop == 1) { util::fail('超管才能开启员工分店管理权限'); } } util::checkRepeatCommit($mobile, 10); $ptStyle = Yii::$app->params['ptStyle']; //验证码取消验证,临时使用的方法 if ($authCode != 19640123) { $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, 'identity' => $identity]; $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; $shopAdmin = $this->shopAdmin; $adminId = $this->adminId; $shop = $this->shop; 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('没有找到员工'); } if ($relation->mainId != $this->mainId) { util::fail('不能修改'); } $roleId = $post['roleId'] ?? 0; $remind = $post['remind'] ?? 0; $status = $post['status'] ?? 1; $super = $post['super'] ?? 0; $name = $post['name'] ?? ''; $finance = $post['finance'] ?? 0; $switchShop = $post['switchShop'] ?? 0; $identity = $post['identity'] ?? 0; $founder = $relation->founder ?? 1; $ptSuperAdminId = AdminClass::getPtSuperAdminId(); if ($shop->adminId != $adminId && $adminId != $ptSuperAdminId) { if ($finance == 1) { util::fail('超管才能修改财务权限'); } if ($switchShop == 1) { util::fail('超管才能修改管理分店权限'); } } if ($founder == 2) { if ($super == 0) { util::fail('超管不能关闭改库存改价权限'); } } if (!empty($name)) { $relation->name = $name; } $relation->roleId = $roleId; $relation->remind = $remind; $relation->status = $status; $relation->super = $super; $relation->finance = $finance; $relation->switchShop = $switchShop; $relation->identity = $identity; $relation->save(); //需要更改原名,下单环节的下单人取的是人家原名的名称 $currentId = $relation->adminId ?? 0; $current = AdminClass::getById($currentId, true); if (!empty($current)) { $current->name = $name; $current->save(); } util::complete('修改成功'); } //删除员工关系 ssh 2021.1.14 public function actionDelete() { $id = Yii::$app->request->get('id'); $shopAdmin = $this->shopAdmin; if (!isset($shopAdmin->super) || $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('删除失败'); } } }