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 { $staff->founder = 2; $staff->save(); $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]); } } $transaction->commit(); util::complete('操作成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("操作失败原因:" . $e->getMessage()); util::fail('操作失败'); } } //获取添加员工的验证码 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('没有权限'); } $pfShopId = $this->shop->pfShopId ?? 0; if (!empty($pfShopId)) { 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']; //验证码取消验证,临时使用的方法 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('验证码错误'); } } $adminInfo = ['name' => $name, 'mobile' => $mobile, 'style' => $ptStyle, 'currentShopId' => $this->shopId]; $fromApp = dict::getDict('userSourceGetId', 'app', 'id'); $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp); $post['shopId'] = $this->shopId; $respond = StaffClass::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(); $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; $post['mainId'] = $this->mainId; $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; $post['mainId'] = $this->mainId; $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->mainId); 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->mainId); ShopAdminService::updateById($id, ['status' => $status]); 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 = ShopAdminClass::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; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('没有权限'); } if (empty($id)) { util::fail('请选择员工'); } $finance = $post['finance'] ?? 0; $switchShop = $post['switchShop'] ?? 0; $super = $post['super'] ?? 0; $relation = ShopAdminClass::getById($id, true); if (empty($relation)) { util::fail('没有找到员工'); } ShopAdminClass::valid($relation, $this->mainId); $founder = $relation->founder ?? 1; $shop = $this->shop; $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('超管不能关闭改库存改价权限'); } } $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; $relation->finance = $finance; $relation->switchShop = $switchShop; $relation->save(); 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('超管才能操作'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $relation = ShopAdminClass::getById($id, true); StaffClass::deleteStaff($relation, $this->shopAdminId, $this->mainId); $transaction->commit(); util::complete(); } catch (\Exception $exception) { $transaction->rollBack(); Yii::info("失败原因:" . $exception->getMessage()); util::fail('删除失败'); } } //获取所有在职员工 ssh 20220507 public function actionGetAllStaff() { $list = \bizHd\admin\classes\ShopAdminClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0, 'status' => 1, 'isPt' => 0,], null, 'id,name', null, true); util::success(['list' => $list]); } }