瀏覽代碼

生成客户

shish 5 年之前
父節點
當前提交
286f602fb5

+ 0 - 3
app-mall/controllers/BaseController.php

@@ -68,9 +68,6 @@ class BaseController extends PublicController
             $this->user = $userInfo;
             if (in_array($action->id, $this->guestAccess) == false) {
                 $custom = CustomClass::getCurrentCustom($sjId, $userInfo);
-                if (empty($custom)) {
-                    util::fail('客户信息无效');
-                }
                 $this->custom = $custom;
                 $customId = $custom['id'] ?? 0;
                 $this->customId = $customId;

+ 2 - 1
biz-ghs/admin/classes/AdminClass.php

@@ -428,7 +428,8 @@ class AdminClass extends BaseClass
     //切换门店 linqh 2021.1.31
     public static function toggleShop($admin, $toggleShopId, $sjId, $originShopAdmin)
     {
-        if (isset($originShopAdmin['super']) == false || $originShopAdmin['super'] != 1) {
+        $right = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($originShopAdmin);
+        if (empty($right)) {
             util::fail("您没有权限");
         }
         $adminId = $admin['id'];

+ 24 - 3
biz-hd/custom/classes/CustomClass.php

@@ -23,17 +23,38 @@ class CustomClass extends BaseClass
     public static function getCurrentCustom($sjId, $user)
     {
         $userId = $user['id'];
+        //从缓存获取客户信息
         $key = self::getCustomCacheKey($sjId, $userId);
         $currentId = Yii::$app->redis->executeCommand('GET', [$key]);
         $info = [];
         if (!empty($currentId)) {
             $info = self::getById($currentId);
         }
+        //从数据库获取客户信息
         if (empty($info)) {
             $info = self::getByCondition(['sjId' => $sjId, 'userId' => $userId]);
-        } else {
-            $id = $info['id'];
-            Yii::$app->redis->executeCommand('SET', [$key, $id]);
+            //需要创建客户信息
+            $name = $user['name'] ?? '';
+            $avatar = $user['avatar'] ?? '';
+            $py = stringUtil::py($name);
+            if (empty($info)) {
+                $data = [
+                    'userId' => $userId,
+                    'sjId' => $sjId,
+                    'name' => $name,
+                    'avatar' => $avatar,
+                    'py' => $py,
+                    'visitTime' => date("Y-m-d H:i:s")
+                ];
+                $info = self::addCustom($data);
+            }
+            $id = $info['id'] ?? 0;
+            if (!empty($id)) {
+                Yii::$app->redis->executeCommand('SET', [$key, $id]);
+            }
+        }
+        if (empty($info)) {
+            util::fail('没有找到客户信息');
         }
         return $info;
     }