Kaynağa Gözat

各端权限控制

shish 6 yıl önce
ebeveyn
işleme
caa9df1d7e

+ 9 - 249
app/admin/controllers/AdminController.php

@@ -1,260 +1,20 @@
 <?php
+
 namespace admin\controllers;
+
 use Yii;
 use yii\web\Controller;
-use yii\helpers\Json;
-use common\services\xhAdminService;
-use common\services\xhCommonService;
-use common\services\xhMerchantService;
-use common\components\util;
-use common\components\stringUtil;
-use common\components\qrCodeUtil;
-use common\services\xhAdminToMerchantService;
-
-class AdminController extends BackendController{
-
-	public $withoutLogin	= ['check-mobile'];
-
-	/**
-	 * 生成管理员
-	 */
-	public function actionGenerate()
-	{
-		$get			= Yii::$app->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();
-		}
-	}
+class AdminController extends BackendController
+{
 	
-	/**
-	 * 检测验证码
-	 */
-	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 $withoutLogin = [];
 	
-	public function actionAjaxExecReplace()
+	//获取登陆员工的权限 shish 2019.11.24
+	public function actionGetLoginAuth()
 	{
-		$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();
+		$adminId = $this->adminId;
+		
 	}
 
-	public function actionReplaceResult()
-	{
-		return $this->renderPartial('replaceResult');
-	}
-	
 }

+ 2 - 40
app/admin/controllers/MainController.php

@@ -249,50 +249,12 @@ class MainController extends BackendController
 	{
 	
 	}
-	
+
 	public function actionLogin()
 	{
 		return $this->renderPartial('login');
 	}
-	
-	private static function asyncRequest($host, $path, $param = []){
-		
-		$query = isset($param) ? http_build_query($param) : '';
-		
-		$port = 80;
-		$errno = 0;
-		$errstr = '';
-		$timeout = 30; //连接超时时间(S)
-		
-		$fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
-		//$fp = stream_socket_client("tcp://".$host.":".$port, $errno, $errstr, $timeout);
-		
-		if (!$fp) {
-			
-			return '连接失败';
-		}
-		if ($errno || !$fp) {
-			
-			
-			return $errstr;
-		}
-		
-		stream_set_blocking($fp,0); //非阻塞
-		stream_set_timeout($fp, 1);//响应超时时间(S)
-		$out  = "POST " . $path . " HTTP/1.1\r\n";
-		$out .= "host:" . $host . "\r\n";
-		$out .= "content-length:" . strlen($query) . "\r\n";
-		$out .= "content-type:application/x-www-form-urlencoded\r\n";
-		$out .= "connection:close\r\n\r\n";
-		$out .= $query;
-		
-		$result = @fputs($fp, $out);
-		
-		@fclose($fp);
-		return $result;
-		
-	}
-	
+
 	/**
 	 * 重复登陆,记录登陆名
 	 * @return string

+ 13 - 0
biz/merchant/classes/SetAuthClass.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\merchant\classes;
+
+use Yii;
+use biz\base\classes\BaseClass;
+
+class SetAuthClass extends BaseClass
+{
+	
+	public static $baseFile = '\biz\merchant\models\SetAuth';
+
+}

+ 13 - 0
biz/merchant/classes/SetMealClass.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\merchant\classes;
+
+use Yii;
+use biz\base\classes\BaseClass;
+
+class SetMealClass extends BaseClass
+{
+	
+	public static $baseFile = '\biz\merchant\models\SetMeal';
+
+}

+ 15 - 0
biz/merchant/models/SetAuth.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace biz\merchant\models;
+
+use biz\base\models\Base;
+
+class SetAuth extends Base
+{
+
+	public static function tableName()
+	{
+		return 'xhSetAuth';
+	}
+	
+}

+ 15 - 0
biz/merchant/models/SetMeal.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace biz\merchant\models;
+
+use biz\base\models\Base;
+
+class SetMeal extends Base
+{
+
+	public static function tableName()
+	{
+		return 'xhSetMeal';
+	}
+	
+}

+ 12 - 0
biz/merchant/services/SetAuthService.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace biz\merchant\services;
+use biz\base\services\BaseService;
+use Yii;
+
+class SetAuthService extends BaseService
+{
+
+	public static $baseFile = '\biz\merchant\classes\SetAuthClass';
+
+}

+ 12 - 0
biz/merchant/services/SetMealService.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace biz\merchant\services;
+use biz\base\services\BaseService;
+use Yii;
+
+class SetMealService extends BaseService
+{
+
+	public static $baseFile = '\biz\merchant\classes\SetMealClass';
+
+}

+ 2 - 0
sql.txt

@@ -1,4 +1,6 @@
 shish 2019.11.24
+ALTER TABLE xhAdminRoleAuth ADD endId TINYINT NOT NULL DEFAULT 0 COMMENT '业务端id' AFTER roleId;
+ALTER TABLE xhMerchant ADD setDeadline INT NOT NULL DEFAULT 0 COMMENT '套餐到期时间' AFTER `setId`;
 ALTER TABLE xhMerchant ADD setId TINYINT NOT NULL DEFAULT 0 COMMENT '套餐id' AFTER `wxRefreshToken`;
 
 shish 2019.11.23