Răsfoiți Sursa

最近访问门店

shish 5 ani în urmă
părinte
comite
7554f2dcbc

+ 39 - 26
app-mall/controllers/BaseController.php

@@ -27,27 +27,34 @@ class BaseController extends PublicController
         Yii::$app->params['ptStyle'] = 3;
 
         $userId = jwt::getLoginId();
-        $header = httpUtil::getHeader();
-        $shopId = isset($header['account']) ? $header['account'] : 0;
-        if (empty($shopId)) {
-            util::fail('没有找到门店');
-        }
-        $shop = ShopClass::getById($shopId);
-        if (empty($shop)) {
-            util::fail('没有找到门店哦');
-        }
-        $sjId = $shop['merchantId'] ?? 0;
-        if (empty($sjId)) {
-            util::fail('没有找到商家哦');
-        }
-        $sj = MerchantService::getMerchantById($sjId);
-        if (empty($sj)) {
-            util::fail('没有找到商家');
+
+        $sjId = 0;
+        if (in_array($action->id, $this->guestAccessAction) == false){
+
+            $header = httpUtil::getHeader();
+            $shopId = isset($header['account']) ? $header['account'] : 0;
+            if (empty($shopId)) {
+                util::fail('没有找到门店');
+            }
+            $shop = ShopClass::getById($shopId);
+            if (empty($shop)) {
+                util::fail('没有找到门店哦');
+            }
+            $sjId = $shop['merchantId'] ?? 0;
+            if (empty($sjId)) {
+                util::fail('没有找到商家哦');
+            }
+            $sj = MerchantService::getMerchantById($sjId);
+            if (empty($sj)) {
+                util::fail('没有找到商家');
+            }
+            $this->sjId = $sjId;
+            $this->sj = $sj;
+            $this->shopId = $shopId;
+            $this->sjExtend = MerchantExtendService::getByMerchantId($sjId);
+
         }
-        $this->sjId = $sjId;
-        $this->sj = $sj;
-        $this->shopId = $shopId;
-        $this->sjExtend = MerchantExtendService::getByMerchantId($sjId);
+
         $this->isWx = util::isWx();
 
         if (empty($userId)) {
@@ -60,13 +67,19 @@ class BaseController extends PublicController
                 util::fail('没有用户信息');
             }
             $this->user = $userInfo;
-            $custom = CustomClass::getCurrentCustom($sjId, $userInfo);
-            if (empty($custom)) {
-                util::fail('没有找到客户');
+
+            if (in_array($action->id, $this->guestAccessAction) == false) {
+
+                $custom = CustomClass::getCurrentCustom($sjId, $userInfo);
+                if (empty($custom)) {
+                    util::fail('没有找到客户');
+                }
+                $this->custom = $custom;
+                $customId = $custom['id'] ?? 0;
+                $this->customId = $customId;
+
             }
-            $this->custom = $custom;
-            $customId = $custom['id'] ?? 0;
-            $this->customId = $customId;
+
         }
         //游客可以访问的方法
         if (in_array($action->id, $this->guestAccessAction)) {

+ 9 - 0
app-mall/controllers/UserController.php

@@ -16,6 +16,15 @@ use yii\helpers\Json;
 class UserController extends BaseController
 {
 
+    public $guestAccessAction = ['recent-shop'];
+
+    //最近店铺 ssh 2021.2.27
+    public function actionRecentShop()
+    {
+        $respond = UserClass::getRecentShop($this->user);
+        util::success($respond);
+    }
+
     //获取登陆客户的资产 ssh 2019.11.22
     public function actionAsset()
     {

+ 7 - 12
app-pt/controllers/BaseController.php

@@ -7,9 +7,6 @@ use common\components\jwt;
 use common\components\util;
 use Yii;
 
-/**
- * 平台次级基类,次于PublicController
- */
 class BaseController extends PublicController
 {
 
@@ -22,27 +19,25 @@ class BaseController extends PublicController
     {
         //6表示总后台
         Yii::$app->params['ptStyle'] = 6;
-
         $staffId = jwt::getLoginId();
-
         if (empty($staffId)) {
             $this->validate = false;
         }
         //游客可以访问的方法
         if (in_array($action->id, $this->guestAccessAction)) {
             $this->validate = true;
+        } else {
+            $staff = StaffService::getById($staffId);
+            if (empty($staff)) {
+                util::fail('没有找到管理员');
+            }
+            $this->staff = $staff;
+            $this->user = $staff;
         }
         if ($this->validate == false) {
             util::notLogin();
         }
-        $staff = StaffService::getById($staffId);
-        if (empty($staff)) {
-            util::fail('没有找到管理员');
-        }
-
-        $this->staff = $staff;
         $this->staffId = $staffId;
-        $this->user = $staff;
         return parent::beforeAction($action);
     }
 

+ 32 - 30
app-pt/controllers/StaffController.php

@@ -10,35 +10,37 @@ use Yii;
 
 class StaffController extends BaseController
 {
-	
-	public function actionLogin()
-	{
-		//登陆并拿到token ssh 2019.11.23
-		$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('请输入密码');
-		}
-		
-		$staff = StaffService::getByCondition(['mobile' => $mobile]);
-		if (password_verify($password, $staff['password']) == false) {
-			util::fail('密码错误');
-		}
-		$staffId = $staff['id'];
-		//获取token
-		$token = jwt::getNewToken($staffId);
-		util::success(['token' => $token]);
-	}
-
-	//登陆员工的详情 ssh 2019.12.26
-	public function actionLoginDetail()
-	{
-		$detail = StaffService::getDetail($this->staffId);
-		util::success($detail);
-	}
+
+    public $guestAccessAction = ['login'];
+
+    public function actionLogin()
+    {
+        //登陆并拿到token ssh 2019.11.23
+        $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('请输入密码');
+        }
+
+        $staff = StaffService::getByCondition(['mobile' => $mobile]);
+        if (password_verify($password, $staff['password']) == false) {
+            util::fail('密码错误');
+        }
+        $staffId = $staff['id'];
+        //获取token
+        $token = jwt::getNewToken($staffId);
+        util::success(['token' => $token]);
+    }
+
+    //登陆员工的详情 ssh 2019.12.26
+    public function actionLoginDetail()
+    {
+        $detail = StaffService::getDetail($this->staffId);
+        util::success($detail);
+    }
 
 }

+ 39 - 0
biz-mall/user/classes/UserClass.php

@@ -2,6 +2,7 @@
 
 namespace bizMall\user\classes;
 
+use biz\shop\classes\ShopClass;
 use bizHd\custom\classes\CustomClass;
 use bizMall\merchant\classes\MerchantAssetClass;
 use bizMall\merchant\classes\MerchantClass;
@@ -53,6 +54,44 @@ class UserClass extends BaseClass
         'system' => ['id' => 5, 'name' => 'system'],
     ];
 
+    //最近访问的门店 ssh 2021.4.10
+    public static function getRecentShop($user)
+    {
+        $recent = $user['recentShop'];
+        $arr = [];
+        if (!empty($recent)) {
+            $ids = json_decode($recent, true);
+            $list = ShopClass::getShopByIds($ids);
+            if (!empty($list)) {
+                foreach ($list as $key => $val) {
+                    $arr[] = [
+                        'shopId' => $val['id'],
+                        'shopName' => $val['shopName'],
+                        'shopImg' => $val['avatar'],
+                    ];
+                }
+            }
+        }
+        return $arr;
+    }
+
+    //添加最近访问的门店 ssh 2021.4.10
+    public static function addRecentShop($lookShopId, $user)
+    {
+        if (empty($lookShopId)) {
+            return false;
+        }
+        $hasRecentShop = $user['recentShop'];
+        $userId = $user['id'];
+        $newShopIds = [];
+        if (!empty($hasRecentShop)) {
+            $newShopIds = json_decode($hasRecentShop, true);
+        }
+        $newShopIds = array_merge($newShopIds, [$lookShopId]);
+        $newShopIds = array_unique(array_filter($newShopIds));
+        self::updateById($userId, ['recentShop' => json_encode($newShopIds)]);
+    }
+
     //组合客户基本和资产信息
     public static function groupUserBaseInfo($list, $sensitive = true)
     {

+ 2 - 1
sql.sql

@@ -2015,9 +2015,10 @@ ADD COLUMN `smallUnit`  smallint(6) NOT NULL DEFAULT 0 COMMENT '小单位' AFTER
 
 ====== shish 2021-4-9
 ALTER TABLE xhCustom DROP COLUMN `totalBuyNum`;
+ALTER TABLE `xhUser` ADD recentShop VARCHAR(800) NOT NULL DEFAULT '' COMMENT '最近访问的店铺' AFTER `visitTime`;
 
 ========
-==linqh 2021.4.9
+==linqh 2021-4-9
 ALTER TABLE `xhGoods`
 ADD COLUMN `py`  varchar(20) NOT NULL DEFAULT '' COMMENT '拼音' AFTER `shortUrl`;