admin; $admin->noticeHasMoreGhs = 1; $admin->save(); util::complete(); } //清空登录信息 ssh 20240428 public function actionClearLogin() { $admin = $this->admin; $admin->miniOpenId = ''; $admin->ghsMiniOpenId = ''; $admin->save(); util::complete(); } //我已离职(从某门店离职) public function actionDelStaff() { $admin = $this->admin; $staff = $this->shopAdmin; if ($staff->founder == 2) { util::fail('老板不能离职'); } if ($staff->delStatus == 1) { util::fail('您已离职'); } $adminId = $this->adminId; $shop = $this->shop; if ($shop->adminId == $adminId) { util::fail('老板不能离职哦'); } // 使用事务保证数据一致性 $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { // 执行离职操作,多处使用,关键词 staff_lz $respond = StaffClass::executeStaffResignation($admin, $staff); $transaction->commit(); util::success($respond); } catch (\Exception $exception) { $transaction->rollBack(); Yii::error("员工离职失败:" . $exception->getMessage()); util::fail('离职操作失败'); } } //个人信息 ssh 20230505 public function actionInfo() { $admin = $this->admin; util::success(['info' => $admin]); } //修改个人信息 ssh 20230505 public function actionUpdateAdmin() { $post = Yii::$app->request->post(); $openId = $post['openId'] ?? ''; $name = $post['name'] ?? ''; $admin = $this->admin; $admin->openId = $openId; if (!empty($name)) { $admin->name = $name; } $admin->save(); if (!empty($name)) { $adminId = $this->adminId; ShopAdminClass::updateByCondition(['adminId' => $adminId], ['name' => $name]); } util::complete(); } //修改miniOpenId ssh 20220912 public function actionUpdateMiniOpenId() { $admin = $this->admin; $miniOpenId = Yii::$app->request->get('miniOpenId'); $admin->miniOpenId = $miniOpenId; $admin->save(); noticeUtil::push("已经重新获取并更新了openId", '15280215347'); util::complete(); } public function actionHasTokenAutoLogin() { $admin = $this->admin; if (empty($admin)) { util::fail('请先注册'); } $openShop = $admin['openShop'] ?? 1; $currentShopId = $admin['currentShopId'] ?? 0; if (empty($currentShopId)) { if ($openShop == 2) { util::fail('审核中'); } util::fail('请先注册'); } $currentShop = ShopClass::getById($currentShopId, true); if (empty($currentShop)) { util::fail('没有找到门店34'); } $pfShopId = $currentShop->pfShopId ?? 0; $onlyCg = $currentShop->onlyCg ?? 1; $shareLogo = imgUtil::groupImg('buy_logo.jpg'); if (isset($currentShop->shareLogo) && !empty($currentShop->shareLogo)) { $shareLogo = imgUtil::groupImg($currentShop->shareLogo); } $mainId = $currentShop->mainId ?? 0; $adminId = $admin['id']; $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $mainId, 'delStatus' => 0], true); if (empty($shopAdmin)) { util::fail('无法操作'); } if (!empty($shopAdmin) && $shopAdmin->status == 0) { util::fail("您的账号已被冻结"); } $shopAdmin->lastLogin = date("Y-m-d H:i:s"); $shopAdmin->save(); $shopAdminId = $shopAdmin->id ?? 0; //是否有切换门店的权限 $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin); $showDemo = 1; $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND'); $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING'); if ($hdUpgrading == 1) { util::fail('系统升级中,稍后再试'); } $apiHost = Yii::$app->params['hdHost']; $imgUploadApi = $apiHost . '/upload/save-file'; //惠雅鲜花员工不能看收入情况 if (in_array($adminId, [2366, 2812, 4004])) { $shopAdmin->super = 0; } //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info util::success([ 'token' => '', 'admin' => $admin, 'shopId' => $currentShopId, 'shopAdminId' => $shopAdminId, 'switchShop' => $switchShop, 'pfShopId' => $pfShopId, 'onlyCg' => $onlyCg, 'shareLogo' => $shareLogo, 'showDemo' => $showDemo, 'imgUploadApi' => $imgUploadApi, //有小程序新版本提示更新 'update' => $remind, 'staff' => $shopAdmin, ]); } //最近店铺 ssh 2021.2.27 public function actionRecentShop() { util::success([]); } //获取登陆员工的权限 ssh 2019.11.24 public function actionLoginAuth() { $auth = AdminService::getAuth($this->adminId, $this->sjId); util::success($auth); } //添加员工 ssh 2019.12.8 public function actionAdd() { $post = Yii::$app->request->post(); $post['sjId'] = $this->sjId; $admin = AdminService::addAdmin($post); $id = $admin['id']; $info = AdminService::getDetail($id); util::success($info); } //删除员工 ssh 2019.12.9 public function actionDelete() { $id = Yii::$app->request->post('id'); $admin = AdminClass::getById($id); AdminService::valid($admin, $this->sjId); AdminService::deleteAdmin($admin, $this->adminId); util::complete(); } //修改员工 ssh 2019.12.9 public function actionUpdate() { $post = Yii::$app->request->post(); $id = isset($post['id']) && is_numeric($post['id']) ? $post['id'] : 0; unset($post['id']); $originalAdmin = AdminService::getById($id); $post['sjId'] = $this->sjId; AdminService::updateAdmin($originalAdmin, $post); util::complete('修改成功'); } //查看员工详情 ssh 2019.12.9 public function actionDetail() { $id = Yii::$app->request->get('id'); $admin = AdminService::getDetail($id); AdminService::valid($admin, $this->sjId); util::success($admin); } //密码修改 public function actionPassword() { $post = Yii::$app->request->post(); $old = isset($post['old']) ? $post['old'] : ''; $new = isset($post['new']) ? $post['new'] : ''; $confirm = isset($post['confirm']) ? $post['confirm'] : ''; if (empty($new)) { util::fail('请输入新密码'); } if ($new != $confirm) { util::fail('二次密码不一致'); } $admin = $this->admin->attributes; $adminId = $this->adminId; if (!empty($admin['password'])) { if (empty($old)) { util::fail('请填写旧密码'); } if (password_verify($old, $admin['password']) == false) { util::fail('旧密码错误'); } } AdminService::updateById($adminId, ['password' => password_hash($new, PASSWORD_BCRYPT)]); util::complete('修改成功'); } //确认密码修改 public function actionConfirmPassword() { $post = Yii::$app->request->post(); $old = isset($post['old']) ? $post['old'] : ''; $new = isset($post['new']) ? $post['new'] : ''; $confirm = isset($post['confirm']) ? $post['confirm'] : ''; if (empty($new)) { util::fail('请输入新密码'); } if ($new != $confirm) { util::fail('二次密码不一致'); } $admin = $this->admin->attributes; $adminId = $this->adminId; if (!empty($admin['payPassword'])) { if (empty($old)) { util::fail('请填写旧密码'); } if (password_verify($old, $admin['payPassword']) == false) { util::fail('旧密码错误'); } } AdminService::updateById($adminId, ['payPassword' => password_hash($new, PASSWORD_BCRYPT)]); util::complete('修改成功'); } //登陆员工的详情 ssh 2019.12.26 public function actionLoginDetail() { $detail = AdminService::getDetail($this->adminId); util::success($detail); } //绑定帐号自动登录 ssh 20210121 public function actionBindAutoLogin() { $post = Yii::$app->request->post(); $iv = isset($post['iv']) ? $post['iv'] : ''; $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : ''; $merchant = WxOpenService::getWxInfo(); $appId = $merchant['miniAppId']; $miniOpenId = $post['miniOpenId']; if (empty($miniOpenId)) { util::fail('绑定失败'); } $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId; $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]); $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret"); require_once($wxMiniSecret . '/wxBizDataCrypt.php'); $pc = new \WXBizDataCrypt($appId, $sessionKey); $errCode = $pc->decryptData($encryptedData, $iv, $result); if ($errCode != 0) { Yii::info($result . ' ' . $errCode); util::fail('绑定失败了'); } Yii::info('小程序获取用户信息:' . $result); $wxInfo = Json::decode($result); $nickName = $wxInfo['nickName'] ?? ''; if (empty($nickName)) { util::fail('绑定失败'); } $admin = $this->admin ?? []; if (empty($admin)) { util::fail('绑定失败'); } $admin->miniOpenId = $miniOpenId; $admin->save(); util::complete(); } //小程序用户完整信息 ssh 2019.12.12 public function actionMiniFullInfo() { $post = Yii::$app->request->post(); $iv = isset($post['iv']) ? $post['iv'] : ''; $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : ''; $merchant = WxOpenService::getWxInfo(); $appId = $merchant['miniAppId']; $admin = $this->admin->attributes; $miniOpenId = $admin['miniOpenId']; if (empty($miniOpenId)) { util::fail('没有找到管理员信息(miniOpenId)'); } $unionId = $admin['unionId'] ?? ''; if (empty($unionId)) { util::fail('没有找到管理员信息(unionId)'); } $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId; $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]); $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret"); require_once($wxMiniSecret . '/wxBizDataCrypt.php'); $pc = new \WXBizDataCrypt($appId, $sessionKey); $errCode = $pc->decryptData($encryptedData, $iv, $result); if ($errCode != 0) { Yii::info($result . ' ' . $errCode); util::fail('获取用户信息失败'); } Yii::info('小程序获取用户信息:' . $result); $wxInfo = Json::decode($result); $source = UserClass::$userSourceId['mini']['name']; $wxInfo['miniOpenId'] = $admin['miniOpenId'] ?? ''; //这个接口没有提供unionId,这边补充一下 $wxInfo['unionId'] = $unionId; $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($wxInfo, $source); $adminId = $admin['id']; $admin = AdminService::getAdminById($adminId); util::success($admin); } //小程序用户手机号 public function actionMiniMobile() { $post = Yii::$app->request->post(); $iv = $post['iv']; $encryptedData = $post['encryptedData']; $merchant = WxOpenService::getWxInfo(); $appId = $merchant['miniAppId']; $admin = $this->admin->attributes; $miniOpenId = $admin['miniOpenId']; if (empty($miniOpenId)) { util::fail('没有找到管理员信息(miniOpenId)'); } $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId; $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]); if (empty($sessionKey)) { util::fail('sesstion key empty'); } $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret"); require_once($wxMiniSecret . '/wxBizDataCrypt.php'); $pc = new \WXBizDataCrypt($appId, $sessionKey); $errCode = $pc->decryptData($encryptedData, $iv, $result); if ($errCode != 0) { util::fail('解密失败'); } $arr = Json::decode($result); $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : ''; $originalMobile = $admin['mobile'] ?? ''; if (empty($originalMobile)) { \biz\admin\classes\AdminClass::updateById($this->adminId, ['mobile' => $mobile]); } util::success(['mobile' => $mobile]); } //设置支付密码 ssh 2021.1.24 public function actionSetPayPassword() { $get = Yii::$app->request->get(); $adminId = $this->adminId; $info = AdminClass::getAdminById($adminId); if (isset($info['payPassword']) && !empty($info['payPassword'])) { util::fail('您已经设置了支付密码'); } $password = $get['password'] ?? ''; if (empty($password)) { util::fail('请输入支付密码'); } $string = password_hash($password, PASSWORD_BCRYPT); AdminClass::updateById($adminId, ['payPassword' => $string]); $data = ['payPassword' => $string]; util::success($data); } //修改或保存 clientId public function actionReplaceClientId() { $get = Yii::$app->request->get(); $clientId = $get['id'] ?? ''; $autoLogin = $get['auto'] ?? 0; // 是否自动登录的请求 if (empty($clientId)) { util::success(['returnStatus' => 'FAILURE']); } $hdDevice = HdDeviceClass::getByCondition(['clientId'=>$clientId], true); if ($hdDevice == null) { $device = [ 'clientId' => $clientId, 'mainId' => $this->mainId, 'shopId' => $this->shopId, 'adminId' => $this->adminId, 'status' => 1 ]; if ($autoLogin == 1) { $device['autoLoginTime'] = date('Y-m-d H:i:s'); } else { $device['pwdLoginTime'] = date('Y-m-d H:i:s'); } HdDeviceClass::add($device); } else { if ($autoLogin == 1) { $hdDevice->autoLoginTime = date('Y-m-d H:i:s'); } else { $hdDevice->pwdLoginTime = date('Y-m-d H:i:s'); } $hdDevice->mainId = $this->mainId; $hdDevice->shopId = $this->shopId; $hdDevice->adminId = $this->adminId; $hdDevice->save(); } //noticeUtil::push("保存花店零售客户端ID:" . $clientId, '15280215347'); util::complete(); } //修改密码 ssh 20220106 public function actionModifyPassword() { $get = Yii::$app->request->get(); $password = $get['password'] ?? ''; if (empty($password)) { util::fail('请填写密码'); } if (ctype_alnum($password)) { util::fail('密码必须是字母、数字和符号的组合'); } $adminId = $this->adminId; $password = password_hash($password, PASSWORD_BCRYPT); AdminClass::updateById($adminId, ['password' => $password]); util::complete('操作成功'); } }