request->get(); $newAccountKey = isset($get['newAccount']) ? $get['newAccount'] : ''; //解密获取新帐号 $newAccount = urldecode(stringUtil::authcode($newAccountKey,'DECODE')); if(empty($newAccount)){ util::stop('链接已经失效,请重新授权'); } $session = Yii::$app->session; $session['usable_new_account'] = $newAccount; $relation = xhAdminToMerchantService::getByAdminId($this->adminId); if(!empty($relation)){ $this->redirect(['admin/result','account' => $this->merchant['id']]); util::end(); } return $this->renderPartial('generate',['admin' => $this->admin,'merchant' => $this->merchant]); } /** * 检查手机是否已经生成管理员 */ public function actionCheckMobile() { $get = Yii::$app->request->get(); $mobile = isset($get['mobile']) ? $get['mobile'] : ''; $admin = xhAdminService::getByMobile($mobile); if(empty($admin)){ util::successInfo('可以使用'); } util::failInfo('手机号已使用'); } /** * 生成管理员,生成验证码 */ public function actionGenerateCode() { $get = Yii::$app->request->get(); $mobile = isset($get['mobile']) ? $get['mobile'] : ''; if(preg_match("/^1[0-9]\d{9}$/",$mobile) == false){ util::failInfo('手机号填写有误'); } $admin = xhAdminService::getByMobile($mobile); if(!empty($admin)){ util::failInfo('这个手机号已经使用过了'); } $session = Yii::$app->session; $now = time(); if(isset($session['authCode']) == false || ($now - $session['authCodeTime']) > 120){ $num = stringUtil::getRandNum(5); $session['authCode'] = $num; $session['authCodeTime'] = time(); $msg = "您正在设置管理员,验证码:".$num; xhCommonService::sendMobileMsg($mobile, $msg); util::successInfo(); } } /** * 检测验证码 */ public function actionCheckCode() { $get = Yii::$app->request->get(); $authCode = isset($get['authCode']) ? $get['authCode'] : ''; $session = Yii::$app->session; if(isset($session['authCode']) && $authCode == $session['authCode']){ util::successInfo(''); } util::failInfo('验证号不正确'); } public function actionResult() { return $this->renderPartial('result',['merchant' => $this->merchant]); } /** * 绑定 */ public function actionBinding() { $post = Yii::$app->request->post(); $session = Yii::$app->session; if(isset($session['usable_new_account']) == false || empty($session['usable_new_account'])){ util::failInfo('授权已经失效,请重新授权'); } if(isset($session['authCode']) == false){ util::failInfo('没有验证码'); } $code = isset($post['code']) ? $post['code'] : ''; if($code != $session['authCode']){ util::failInfo('验证码不正确'); } $mobile = isset($post['mobile']) ? $post['mobile'] : ''; if(stringUtil::isMobieNumber($mobile) == false){ util::failInfo('手机号填写有误'); } $admin = xhAdminService::getByMobile($mobile); if(!empty($admin)){ util::failInfo('手机号已经被使用'); } $relation = xhAdminToMerchantService::getByAdminId($this->adminId); if(!empty($relation)){ util::failInfo('管理员已经绑定商家'); } $newAccount = $session['usable_new_account']; $newMerchant = xhMerchantService::getByAccount($newAccount); if(empty($newMerchant)){ util::failInfo('商家信息不完整'); } $merchantId = $this->merchant['id']; $account = $this->merchant['id']; $adminId = $this->adminId; $data['mobile'] = $mobile; $data['password'] = md5($post['password']); xhAdminService::updateById($adminId, $data); $addAdminData = ['merchantId'=>$newMerchant['id'],'adminId'=>$this->adminId,'receiveMsg'=>1,'createTime'=>date("Y-m-d H:i:s")]; xhAdminToMerchantService::add($addAdminData); unset($session['usable_new_account']); util::successInfo('设置成功'); } public function actionGetReplaceQrCode() { $get = Yii::$app->request->get(); $url = Yii::$app->params['adminUrl'].'/admin/replace?account='.$this->merchant['id']; $logo = Yii::getAlias("@app").'/../images'.$this->merchant['logo'];//取商家的logo $imgUrl = qrCodeUtil::generateFixQrCode($url,'backend_replace_admin_url_'.$this->merchant['id'],$logo); xhAdminService::logout(); echo Json::encode(['code' => 'A0001','msg' => 'success','data' => ['url' => $imgUrl]]); } /** * 替换页 */ public function actionReplace() { if($this->isWeixin == false){ util::stop('请使用微信访问'); } $preAdmin = xhAdminToMerchantService::getAdminByMerchantId($this->merchantId); $preAdminId = $preAdmin['id']; $newAdminId = $this->adminId; if($newAdminId == $preAdminId){ util::stop('您已经绑定过了'); } $relation = xhAdminToMerchantService::getByAdminId($newAdminId); if(!empty($relation)){ util::stop('您的微信已经绑定商家,请先解除绑定'); } return $this->renderPartial('replace',['preAdmin'=>$preAdmin]); } /** * 显示新管理员页 */ public function actionExecReplace() { $get = Yii::$app->request->get(); $replaceAdminAuthCode = isset($get['replaceAdminAuthCode']) ? $get['replaceAdminAuthCode'] : ''; $admin = $this->admin; return $this->renderPartial('execReplace',['replaceAdminAuthCode'=>$replaceAdminAuthCode,'admin'=>$admin]); } /** * 更换管理员生成验证码 */ public function actionRelaceAdminGenerateCode() { $get = Yii::$app->request->get(); $preAdmin = xhAdminToMerchantService::getAdminByMerchantId($this->merchantId); $mobile = $preAdmin['mobile']; $session = Yii::$app->session; $now = time(); if(isset($session['replaceAdminAuthCode']) == false || ($now - $session['replaceAdminAuthCodeTime']) > 120){ $num = stringUtil::getRandNum(5); $session['replaceAdminAuthCode'] = $num; $session['replaceAdminAuthCodeTime'] = time(); $msg = "您正在更换管理员,验证码:".$num; xhCommonService::sendMobileMsg($mobile, $msg); util::successInfo(); } } /** * 检查验证码 */ public function actionCheckRelaceAdminGenerateCode() { $get = Yii::$app->request->get(); $authCode = isset($get['authCode']) ? $get['authCode'] : ''; $session = Yii::$app->session; if(isset($session['replaceAdminAuthCode']) && $authCode == $session['replaceAdminAuthCode']){ util::successInfo(''); } util::failInfo('验证号不正确'); } public function actionAjaxExecReplace() { $post = Yii::$app->request->post(); $replaceAdminAuthCode = isset($post['replaceAdminAuthCode']) ? $post['replaceAdminAuthCode'] : ''; $code = isset($post['code']) ? $post['code'] : ''; $mobile = isset($post['mobile']) ? $post['mobile'] : ''; $password = isset($post['password']) ? $post['password'] : ''; $session = Yii::$app->session; if(isset($session['replaceAdminAuthCode']) == false || $session['replaceAdminAuthCode'] != $replaceAdminAuthCode){ util::stop('验证码已经失效了'); } if(isset($session['authCode']) == false || $session['authCode'] != $code){ util::stop('验证码已经失效'); } $preAdmin = xhAdminToMerchantService::getAdminByMerchantId($this->merchantId); $preAdminId = $preAdmin['id']; $newAdminId = $this->adminId; $relation = xhAdminToMerchantService::getByAdminId($newAdminId); if(!empty($relation)){ util::stop('您的微信已经绑定商家了,请先解除绑定'); } //删除原有管理关系 xhAdminToMerchantService::delByAdminId($preAdminId); //更新原管理员信息 xhAdminService::updateById($preAdminId, ['mobile'=>'','password'=>'']); //添加新管理员 xhAdminToMerchantService::add(['adminId'=>$newAdminId,'merchantId'=>$this->merchantId,'createTime'=>date("Y-m-d H:i:s"),'receiveMsg'=>1]); //更新管理员的信息 xhAdminService::updateById($newAdminId, ['mobile'=>$mobile,'password'=>md5($password)]); unset($session['replaceAdminAuthCode']); unset($session['authCode']); util::successInfo(); } public function actionReplaceResult() { return $this->renderPartial('replaceResult'); } }