Explorar el Código

Merge branch 'master' of http://git.huaml.com/zhh/huahuibao

林琦海 hace 5 años
padre
commit
543ace372e

+ 183 - 186
app/ghs/controllers/AuthController.php

@@ -26,190 +26,187 @@ use yii\helpers\Json;
  */
 class AuthController extends PublicController
 {
-	
-	//准备授权 shish 2019.11.19
-	public function actionPrepare()
-	{
-		$get = Yii::$app->request->get();
-		$url = isset($get['url']) && !empty($get['url']) ? $get['url'] : '';
-		if (empty($url)) {
-			util::fail('没有网址');
-		}
-		$account = httpUtil::getAccount($url);
-		if (empty($account)) {
-			util::fail('没有商家帐号');
-		}
-		$merchant = MerchantService::getById($account);
-		if (empty($merchant)) {
-			util::fail('商家无效');
-		}
-		/**
-		 * authScope 参数的说明
-		 * 1.用户通过公众号菜单打开网页,因为已经关注过了公众号,已经生成过用户信息,所以只要使用snsapi_base静默方式拿到openid就可以
-		 * 2.为了保证付款页的访问速度,暂时只要通过snsapi_base静默方式拿到openid先生成可以用的用户信息即可
-		 * 3.其它情况需要获取用户完整信息的,使用snsapi_userinfo让用户授权获取信息即可
-		 * 4.snsapi_base静默方式使用的场景更多,所以参数authScope默认使用snsapi_base
-		 */
-		$authScope = isset($get['authScope']) ? $get['authScope'] : 'snsapi_base';
-		$urlEncode = stringUtil::urlSafeB64Encode($url);
-		//微信授权获取code shish 2019.11.24
-		wxUtil::getCode($urlEncode, $merchant, $authScope);
-		util::end();
-	}
-	
-	//微信授权获取用户信息 shish 2019.11.20
-	public function actionGetUserInfo()
-	{
-		$get = Yii::$app->request->get();
-		$code = isset($get['code']) ? $get['code'] : '';
-		if (empty($code)) {
-			util::fail('没有获取用户code');
-		}
-		if (isset($get['state']) && $get['state'] == 'authdeny') {
-			util::fail('auth fail');
-		}
-		$urlEncode = $get['url'];
-		$url = stringUtil::urlSafeBase64Decode($urlEncode);
-		$account = httpUtil::getAccount($url);
-		if (empty($account)) {
-			util::stop('商店ID无效!!');
-		}
-		$merchant = xhMerchantService::getByAccount($account);
-		if (empty($merchant)) {
-			util::stop('商店无效');
-		}
-		$merchantId = $merchant['id'];
-		$authScope = isset($get['authScope']) ? $get['authScope'] : '';
-		if (empty($authScope)) {
-			util::stop('没有授权类型');
-		}
-		$data = wxUtil::getOpenId($code, $merchant);
-		if ($data === false) {
-			//微信授权获取code shish 2019.11.24
-			wxUtil::getCode($urlEncode, $merchant, $authScope);
-			util::end();
-		}
-		$openId = $data['openid'];
-		$access_token = $data['access_token'];
-		$user = UserService::getByOpenId($openId, $merchantId);
-		//用户来源
-		$userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
-		$source = $userSource['name'];
-		if (empty($user)) {
-			//$authScope 默认是 snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
-			$originalInfo = [];
-			$originalInfo['openId'] = $openId;
-			$originalInfo['merchantId'] = $merchantId;
-			
-			//没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
-			if ($authScope == 'snsapi_userinfo') {
-				$baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
-				$originalInfo = array_merge($baseInfo, $originalInfo);
-				$originalInfo['isFull'] = 1;
-				$originalInfo['unionId'] = $baseInfo['unionid'];
-				$originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
-				$originalInfo['nickName'] = $baseInfo['nickName'];
-			}
-			$user = UserService::replaceUser($originalInfo, $source, $merchantId);
-		} else {
-			if ($user['isFull'] == 0) {
-				if ($authScope == 'snsapi_userinfo') {
-					$baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
-					$originalInfo = $baseInfo;
-					$originalInfo['isFull'] = 1;
-					$originalInfo['unionId'] = $baseInfo['unionid'];
-					$originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
-					$originalInfo['openId'] = $baseInfo['openid'];
-					$originalInfo['nickName'] = $baseInfo['nickName'];
-					$originalInfo['merchantId'] = $merchantId;
-					$user = UserService::replaceUser($originalInfo, $source, $merchantId);
-				}
-			}
-		}
-		//这个的基类没有设置统一的全局变量,这里进行设置一次
-		$userId = $user['id'];
-		$admin = AdminService::getByCondition(['userId' => $userId]);
-		if (empty($admin)) {
-			util::fail('您没有权限访问');
-		}
-		$adminId = $admin['id'];
-		//获取token
-		$token = jwt::getNewToken($adminId);
-		$url = strpos($url, '?') === false ? $url . '?token=' . $token : $url . '&token=' . $token;
-		$this->redirect($url);
-	}
-	
-	//登陆并拿到token shish 2019.11.23
-	public function actionLogin()
-	{
-		$get = Yii::$app->request->get();
-		$mobile = isset($get['mobile']) ? $get['mobile'] : 0;
-		if (stringUtil::isMobile($mobile) == false) {
-			util::fail('请填写正常的手机号');
-		}
-		$password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
-		if (empty($password)) {
-			util::fail('请输入密码');
-		}
-		$admin = AdminService::getByCondition(['mobile' => $mobile]);
-		if (password_verify($password, $admin['password']) == false) {
-			util::fail('密码错误');
-		}
-		$adminId = $admin['id'];
-		$shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId]);
-		$merchantId = isset($shopAdmin['merchantId']) ? $shopAdmin['merchantId'] : 0;
-		$shopId = isset($shopAdmin['shopId']) ? $shopAdmin['shopId'] : 0;
-		if (empty($shopId)) {
-			util::fail('您不是管理员');
-		}
-		//管理员关联门店
-		Yii::$app->redis->executeCommand('SET', ['LOGIN_ADMIN_SHOP' . $adminId, $shopId]);
-		//获取token
-		$token = jwt::getNewToken($adminId);
-		util::success(['token' => $token, 'account' => $merchantId, 'shopId' => $shopId]);
-	}
-	
-	//静默获取小程序用户信息
-	public function actionMiniInfo()
-	{
-		$code = Yii::$app->request->get('code', '');
-		if (empty($code)) {
-			util::fail('没有CODE信息');
-		}
-		$wxMiniBase = WxOpenClass::getGhsWxInfo();
-		$appId = $wxMiniBase['miniAppId'];
-		$appSecret = $wxMiniBase['miniAppSecret'];
-		if (empty($appSecret)) {
-			util::fail('没有找到小程序的密钥');
-		}
-		$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$arr = Json::decode($result);
-		$sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
-		$openid = isset($arr['openid']) ? $arr['openid'] : '';
-		if (empty($openid)) {
-			Yii::info(json_encode($arr));
-			util::fail('没有获取到小程序openId');
-		}
-		$cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $openid;
-		Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
-		//用户来源
-		$userSource = UserClass::$userSourceId['mini']['name'];
-		$admin = AdminService::getByMiniOpenId($openid);
-		if (empty($admin)) {
-			$adminInfo = ['miniOpenId' => $openid];
-			$admin = AdminService::replaceAdmin($adminInfo, $userSource);
-		}
-		$adminId = $admin['id'];
-		$staff = ShopAdminService::getByCondition(['adminId' => $adminId]);
-		$shopId = isset($staff['shopId']) ? $staff['shopId'] : 0;
-		//头像
-		$admin['avatar'] = Yii::$app->params['imgHost'] . '/retail/default-img.png';
-		//管理员关联商家
-		//Yii::$app->redis->executeCommand('SET', ['LOGIN_ADMIN_SHOP' . $adminId, $shopId]);
-		$token = jwt::getNewToken($adminId);
-		util::success(['token' => $token, 'admin' => $admin, 'shopId' => $shopId]);
-	}
-	
+
+    //准备授权 shish 2019.11.19
+    public function actionPrepare()
+    {
+        $get = Yii::$app->request->get();
+        $url = isset($get['url']) && !empty($get['url']) ? $get['url'] : '';
+        if (empty($url)) {
+            util::fail('没有网址');
+        }
+        $account = httpUtil::getAccount($url);
+        if (empty($account)) {
+            util::fail('没有商家帐号');
+        }
+        $merchant = MerchantService::getById($account);
+        if (empty($merchant)) {
+            util::fail('商家无效');
+        }
+        /**
+         * authScope 参数的说明
+         * 1.用户通过公众号菜单打开网页,因为已经关注过了公众号,已经生成过用户信息,所以只要使用snsapi_base静默方式拿到openid就可以
+         * 2.为了保证付款页的访问速度,暂时只要通过snsapi_base静默方式拿到openid先生成可以用的用户信息即可
+         * 3.其它情况需要获取用户完整信息的,使用snsapi_userinfo让用户授权获取信息即可
+         * 4.snsapi_base静默方式使用的场景更多,所以参数authScope默认使用snsapi_base
+         */
+        $authScope = isset($get['authScope']) ? $get['authScope'] : 'snsapi_base';
+        $urlEncode = stringUtil::urlSafeB64Encode($url);
+        //微信授权获取code shish 2019.11.24
+        wxUtil::getCode($urlEncode, $merchant, $authScope);
+        util::end();
+    }
+
+    //微信授权获取用户信息 shish 2019.11.20
+    public function actionGetUserInfo()
+    {
+        $get = Yii::$app->request->get();
+        $code = isset($get['code']) ? $get['code'] : '';
+        if (empty($code)) {
+            util::fail('没有获取用户code');
+        }
+        if (isset($get['state']) && $get['state'] == 'authdeny') {
+            util::fail('auth fail');
+        }
+        $urlEncode = $get['url'];
+        $url = stringUtil::urlSafeBase64Decode($urlEncode);
+        $account = httpUtil::getAccount($url);
+        if (empty($account)) {
+            util::stop('商店ID无效!!');
+        }
+        $merchant = xhMerchantService::getByAccount($account);
+        if (empty($merchant)) {
+            util::stop('商店无效');
+        }
+        $merchantId = $merchant['id'];
+        $authScope = isset($get['authScope']) ? $get['authScope'] : '';
+        if (empty($authScope)) {
+            util::stop('没有授权类型');
+        }
+        $data = wxUtil::getOpenId($code, $merchant);
+        if ($data === false) {
+            //微信授权获取code shish 2019.11.24
+            wxUtil::getCode($urlEncode, $merchant, $authScope);
+            util::end();
+        }
+        $openId = $data['openid'];
+        $access_token = $data['access_token'];
+        $user = UserService::getByOpenId($openId, $merchantId);
+        //用户来源
+        $userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
+        $source = $userSource['name'];
+        if (empty($user)) {
+            //$authScope 默认是 snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
+            $originalInfo = [];
+            $originalInfo['openId'] = $openId;
+            $originalInfo['merchantId'] = $merchantId;
+
+            //没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
+            if ($authScope == 'snsapi_userinfo') {
+                $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
+                $originalInfo = array_merge($baseInfo, $originalInfo);
+                $originalInfo['isFull'] = 1;
+                $originalInfo['unionId'] = $baseInfo['unionid'];
+                $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
+                $originalInfo['nickName'] = $baseInfo['nickName'];
+            }
+            $user = UserService::replaceUser($originalInfo, $source, $merchantId);
+        } else {
+            if ($user['isFull'] == 0) {
+                if ($authScope == 'snsapi_userinfo') {
+                    $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
+                    $originalInfo = $baseInfo;
+                    $originalInfo['isFull'] = 1;
+                    $originalInfo['unionId'] = $baseInfo['unionid'];
+                    $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
+                    $originalInfo['openId'] = $baseInfo['openid'];
+                    $originalInfo['nickName'] = $baseInfo['nickName'];
+                    $originalInfo['merchantId'] = $merchantId;
+                    $user = UserService::replaceUser($originalInfo, $source, $merchantId);
+                }
+            }
+        }
+        //这个的基类没有设置统一的全局变量,这里进行设置一次
+        $userId = $user['id'];
+        $admin = AdminService::getByCondition(['userId' => $userId]);
+        if (empty($admin)) {
+            util::fail('您没有权限访问');
+        }
+        $adminId = $admin['id'];
+        //获取token
+        $token = jwt::getNewToken($adminId);
+        $url = strpos($url, '?') === false ? $url . '?token=' . $token : $url . '&token=' . $token;
+        $this->redirect($url);
+    }
+
+    //登陆并拿到token shish 2019.11.23
+    public function actionLogin()
+    {
+        $get = Yii::$app->request->get();
+        $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
+        if (stringUtil::isMobile($mobile) == false) {
+            util::fail('请填写正常的手机号');
+        }
+        $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
+        if (empty($password)) {
+            util::fail('请输入密码');
+        }
+        $admin = AdminService::getByCondition(['mobile' => $mobile]);
+        if (password_verify($password, $admin['password']) == false) {
+            util::fail('密码错误');
+        }
+        $adminId = $admin['id'];
+        $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId]);
+        $merchantId = isset($shopAdmin['merchantId']) ? $shopAdmin['merchantId'] : 0;
+        $shopId = isset($shopAdmin['shopId']) ? $shopAdmin['shopId'] : 0;
+        if (empty($shopId)) {
+            util::fail('您不是管理员');
+        }
+        //管理员关联门店
+        Yii::$app->redis->executeCommand('SET', ['LOGIN_ADMIN_SHOP' . $adminId, $shopId]);
+        //获取token
+        $token = jwt::getNewToken($adminId);
+        util::success(['token' => $token, 'account' => $merchantId, 'shopId' => $shopId]);
+    }
+
+    //静默获取小程序用户信息
+    public function actionMiniInfo()
+    {
+        $code = Yii::$app->request->get('code', '');
+        if (empty($code)) {
+            util::fail('没有CODE信息');
+        }
+        $wxMiniBase = WxOpenClass::getGhsWxInfo();
+        $appId = $wxMiniBase['miniAppId'];
+        $appSecret = $wxMiniBase['miniAppSecret'];
+        if (empty($appSecret)) {
+            util::fail('没有找到小程序的密钥');
+        }
+        $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $arr = Json::decode($result);
+        $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
+        $openid = isset($arr['openid']) ? $arr['openid'] : '';
+        if (empty($openid)) {
+            Yii::info(json_encode($arr));
+            util::fail('没有获取到小程序openId');
+        }
+        $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $openid;
+        Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
+        //用户来源
+        $userSource = UserClass::$userSourceId['mini']['name'];
+        $admin = AdminService::getByMiniOpenId($openid);
+        if (empty($admin)) {
+            $adminInfo = ['miniOpenId' => $openid];
+            $admin = AdminService::replaceAdmin($adminInfo, $userSource);
+        }
+        $adminId = $admin['id'];
+        $shopId = $admin['currentShopId'] ?? 0;
+        //头像
+        $admin['avatar'] = Yii::$app->params['imgHost'] . '/retail/default-img.png';
+        $token = jwt::getNewToken($adminId);
+        util::success(['token' => $token, 'admin' => $admin, 'shopId' => $shopId]);
+    }
+
 }

+ 4 - 7
app/ghs/controllers/BaseController.php

@@ -28,9 +28,9 @@ class BaseController extends PublicController
     public function beforeAction($action)
     {
         //token验证
-	    //$adminId = jwt::getLoginId();
+        $adminId = jwt::getLoginId();
         //模拟用户
-	    $adminId = 1;
+        //$adminId = 1;
         $ghsId = 0;
         $ghs = [];
         $ghsExtend = [];
@@ -42,18 +42,15 @@ class BaseController extends PublicController
             if (empty($admin)) {
                 util::fail('帐号无效');
             }
-            $adminId = $admin['id'];
-            //$shopId = Yii::$app->redis->executeCommand('GET', ['LOGIN_ADMIN_SHOP' . $adminId]);
             //取不到门店id可能被清缓存,需要重新登陆,$shopId = 0 则表示非管理员,没有关联的门店,只可以访问官网
-            $staff = ShopAdminService::getByCondition(['adminId' => $adminId]);
-            $shopId = isset($staff['shopId']) ? $staff['shopId'] : 0;
+            $shopId = $admin['currentShopId'] ?? 0;
             if (is_numeric($shopId) == false) {
                 util::notLogin('登陆已失效,请重新登陆');
             }
             if (!empty($shopId)) {
                 $shop = ShopService::getById($shopId);
                 if (empty($shop)) {
-                    util::fail('没有找到门店');
+                    util::fail('没有找到您的门店');
                 }
                 $ghsId = $shop['ghsId'];
                 $ghs = MerchantService::getMerchantById($ghsId);

+ 10 - 10
app/ghs/controllers/UploadController.php

@@ -28,7 +28,7 @@ class UploadController extends BaseController
 		if (!empty($categoryIds)) {
 			$categoryList = CategoryService::getByIds($categoryIds);
 			foreach ($categoryList as $cat) {
-				if ($cat['merchantId'] != $this->merchantId) {
+				if ($cat['ghsId'] != $this->ghsId) {
 					util::fail('请选择自己的分类');
 				}
 			}
@@ -37,10 +37,10 @@ class UploadController extends BaseController
 		//匹配出图片的格式
 		if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
 			$type = $result[2];
-			$merchantId = $this->merchantId;
+			$ghsId = $this->ghsId;
 			$month = date("Ym");
 			$date = date("d");
-			$path = dirUtil::getImgUploadDir() . "/{$merchantId}/{$month}/{$date}/";
+			$path = dirUtil::getImgUploadDir() . "/{$ghsId}/{$month}/{$date}/";
 			if (!file_exists($path)) {
 				//检查是否有该文件夹,如果没有就创建,并给予最高权限
 				mkdir($path, 0700, true);
@@ -51,7 +51,7 @@ class UploadController extends BaseController
 			if (file_put_contents($fullPathFile, base64_decode(str_replace($result[1], '', $base64_image_content))) == false) {
 				util::fail('上传失败!!');
 			}
-			$img = "/uploads/{$merchantId}/{$month}/{$date}/" . $newFile;
+			$img = "/uploads/{$ghsId}/{$month}/{$date}/" . $newFile;
 			$imgInfo = getimagesize($fullPathFile);
 			$width = $imgInfo[0];
 			$height = $imgInfo[1];
@@ -66,7 +66,7 @@ class UploadController extends BaseController
 				Image::thumbnail($fullPathFile, $newWidth, $newHeight)->save($newFullPathFile, ['quality' => 100]);
 				$width = $newWidth;
 				$height = $newHeight;
-				$img = "/uploads/{$merchantId}/{$month}/{$date}/" . $newFile;
+				$img = "/uploads/{$ghsId}/{$month}/{$date}/" . $newFile;
 				unlink($fullPathFile);
 				$fullPathFile = $newFullPathFile;
 			}
@@ -81,12 +81,12 @@ class UploadController extends BaseController
 
 			if (!empty($categoryIds)) {
 				$time = time();
-				$data = ['img' => $img, 'merchantId' => $merchantId, 'name' => '未命名', 'addTime' => $time];
+				$data = ['img' => $img, 'ghsId' => $ghsId, 'name' => '未命名', 'addTime' => $time];
 				$pic = PicService::add($data);
 				$currentId = $pic['id'];
 				$add = [];
 				foreach ($categoryIds as $cat) {
-					$add[] = ['categoryId' => $cat, 'picId' => $currentId, 'merchantId' => $this->merchantId];
+					$add[] = ['categoryId' => $cat, 'picId' => $currentId, 'ghsId' => $this->ghsId];
 				}
 				PicCategoryService::batchAdd($add);
 			}
@@ -105,10 +105,10 @@ class UploadController extends BaseController
 		//匹配出图片的格式
 		if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
 			$type = $result[2];
-			$merchantId = 12358;
+			$ghsId = 12358;
 			$month = date("Ym");
 			$date = date("d");
-			$path = dirUtil::getImgUploadDir() . "/{$merchantId}/{$month}/{$date}/";
+			$path = dirUtil::getImgUploadDir() . "/{$ghsId}/{$month}/{$date}/";
 			if (!file_exists($path)) {
 				//检查是否有该文件夹,如果没有就创建,并给予最高权限
 				mkdir($path, 0700, true);
@@ -119,7 +119,7 @@ class UploadController extends BaseController
 			if (file_put_contents($fullPath, base64_decode(str_replace($result[1], '', $base64_image_content))) == false) {
 				util::fail('上传失败');
 			}
-			$img = "/uploads/{$merchantId}/{$month}/{$date}/" . $newFile;
+			$img = "/uploads/{$ghsId}/{$month}/{$date}/" . $newFile;
 			$data = business::formatUploadImg($img);
 			$data['shortUrl'] = $img;
 			util::success($data);

+ 1 - 3
biz-ghs/custom/services/CustomService.php

@@ -25,7 +25,7 @@ class CustomService extends BaseService
 		$data['allNum'] = 80;
 		return $data;
 	}
-	
+
 	//获取客户信息 shish 2021.1.8
 	public static function getFullInfo($ghsId, $shopId)
 	{
@@ -36,10 +36,8 @@ class CustomService extends BaseService
 		$list = CustomClass::groupBaseInfo([$custom]);
 		$custom = current($list);
 		$custom['no'] = 1254358;
-		
 		$shopInfo = ShopClass::getAddressAndManager($shopId);
 		$custom['shopInfo'] = $shopInfo;
-		
 		return $custom;
 	}
 	

+ 3 - 1
sql.sql

@@ -515,4 +515,6 @@ CREATE TABLE `xhGhsStatOrderCount` (
   `shopId` INT(11) NOT NULL DEFAULT '0' COMMENT '门店id',
   PRIMARY KEY (`id`),
   KEY `ghs` (`ghsId`,`time`)
-) COMMENT='供货商月订单量,包括未付款';
+) COMMENT='供货商月订单量,包括未付款';
+ALTER TABLE xhGhsAdmin ADD currentShopId INT NOT NULL DEFAULT 0 COMMENT '当前管理的门店' AFTER `openId`;
+ALTER TABLE xhAdmin ADD currentShopId INT NOT NULL DEFAULT 0 COMMENT '当前管理的门店' AFTER `openId`;