shish před 5 roky
rodič
revize
85d2f64a8c

+ 8 - 6
app-hd/controllers/BaseController.php

@@ -52,19 +52,21 @@ class BaseController extends PublicController
 		$this->admin = $admin;
 		$this->adminId = $adminId;
 		$header = httpUtil::getHeader();
-		$shopId = $header['shop-id'] ?? 0;
-
-		if (!empty($shopId)) {
+		$lookShopId = $header['shop-id'] ?? 0;
+		
+		if (!empty($lookShopId)) {
 			//商城
 			if (in_array($action->id, $this->guestAccessAction) == false) {
 				util::fail('您没有权限访问哦');
 			}
-			$shop = ShopClass::getById($shopId);
+			$shop = ShopClass::getById($lookShopId);
 			if (empty($shop)) {
 				util::fail('没有找到店铺');
 			}
 			$sjId = $shop['merchantId'] ?? 0;
-			$custom = CustomClass::getCustom(['sjId' => $sjId, 'adminId' => $adminId]);
+			//新增并获取客户信息
+			$custom = CustomClass::replaceCustom($sjId, $admin);
+			dd($custom);
 			$customId = $custom['id'] ?? 0;
 			if (empty($customId)) {
 				util::fail('没有找到客户信息');
@@ -102,5 +104,5 @@ class BaseController extends PublicController
 		}
 		return parent::beforeAction($action);
 	}
-
+	
 }

+ 2 - 0
app-hd/controllers/MainController.php

@@ -11,6 +11,8 @@ use common\components\util;
 class MainController extends BaseController
 {
 
+	public $guestAccessAction = ['index'];
+	
     public function actionDemo()
     {
         return $this->renderPartial('demo');

+ 87 - 56
biz-hd/custom/classes/CustomClass.php

@@ -3,66 +3,97 @@
 namespace bizHd\custom\classes;
 
 use bizHd\admin\classes\AdminClass;
+use common\components\stringUtil;
 use common\components\util;
 use Yii;
 use bizHd\base\classes\BaseClass;
 
 class CustomClass extends BaseClass
 {
-
-    public static $baseFile = '\bizHd\custom\models\Custom';
-
-    //获取客户信息
-    public static function getCustom($data)
-    {
-        $custom = self::getByCondition($data);
-        if (empty($custom)) {
-            $custom = self::add($data);
-        }
-        return $custom;
-    }
-
-    //获取客户信息 shish 2021.2.1
-    public static function getCustomInfo($id)
-    {
-        $custom = self::getById($id);
-        if (empty($custom)) {
-            return $custom;
-        }
-        $list = self::groupBaseInfo([$custom]);
-        return current($list);
-    }
-
-    public static function valid($info, $sjId)
-    {
-        if (isset($info['sjId']) && $info['sjId'] == $sjId) {
-            return true;
-        }
-        util::fail('客户信息无效');
-    }
-
-    //整合基本信息 shish 2021.1.31
-    public static function groupBaseInfo($list)
-    {
-        if (empty($list)) {
-            return $list;
-        }
-
-        $adminIds = array_column($list, 'adminId');
-        $adminInfo = AdminClass::getByIds($adminIds, null, 'id');
-
-        foreach ($list as $key => $val) {
-            $adminId = $val['adminId'];
-            $subscribe = $adminInfo[$adminId]['subscribe'] ?? 0;
-            $list[$key]['subscribe'] = $subscribe;
-        }
-        return $list;
-    }
-
-    //添加客户 shish 2021.2.28
-    public static function addCustom($data)
-    {
-        return self::add($data);
-    }
-
+	
+	public static $baseFile = '\bizHd\custom\models\Custom';
+	
+	//创建获取客户信息 shish 2021.3.19
+	public static function replaceCustom($sjId, $admin)
+	{
+		$adminId = $admin['id'];
+		$cacheKey = "custom_info_{$sjId}_{$adminId}";
+		$id = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+		if (!empty($id)) {
+			$info = self::getCustomInfo($id);
+			if (!empty($info)) {
+				return $info;
+			}
+		}
+		$name = $admin['adminName'] ?? '';
+		$mobile = $admin['mobile'] ?? '';
+		$py = stringUtil::getSpelling($name);
+		$visitTime = date("Y-m-d H:i:s");
+		$data = [
+			'adminId' => $adminId,
+			'sjId' => $sjId,
+			'name' => $name,
+			'py' => $py,
+			'mobile' => $mobile,
+			'visitTime' => $visitTime,
+		];
+		$info = self::addCustom($data);
+		$id = $info['id'] ?? 0;
+		Yii::$app->redis->executeCommand('SET', [$cacheKey, $id]);
+		return $info;
+	}
+	
+	//获取客户信息
+	public static function getCustom($data)
+	{
+		$custom = self::getByCondition($data);
+		if (empty($custom)) {
+			$custom = self::add($data);
+		}
+		return $custom;
+	}
+	
+	//获取客户信息 shish 2021.2.1
+	public static function getCustomInfo($id)
+	{
+		$custom = self::getById($id);
+		if (empty($custom)) {
+			return $custom;
+		}
+		$list = self::groupBaseInfo([$custom]);
+		return current($list);
+	}
+	
+	public static function valid($info, $sjId)
+	{
+		if (isset($info['sjId']) && $info['sjId'] == $sjId) {
+			return true;
+		}
+		util::fail('客户信息无效');
+	}
+	
+	//整合基本信息 shish 2021.1.31
+	public static function groupBaseInfo($list)
+	{
+		if (empty($list)) {
+			return $list;
+		}
+		
+		$adminIds = array_column($list, 'adminId');
+		$adminInfo = AdminClass::getByIds($adminIds, null, 'id');
+		
+		foreach ($list as $key => $val) {
+			$adminId = $val['adminId'];
+			$subscribe = $adminInfo[$adminId]['subscribe'] ?? 0;
+			$list[$key]['subscribe'] = $subscribe;
+		}
+		return $list;
+	}
+	
+	//添加客户 shish 2021.2.28
+	public static function addCustom($data)
+	{
+		return self::add($data);
+	}
+	
 }

+ 31 - 34
common/components/stringUtil.php

@@ -44,7 +44,7 @@ class stringUtil
 		}
 		return false;
 	}
-
+	
 	//是否所有都是英文字母 shish 2021.1
 	public static function isLetter()
 	{
@@ -53,7 +53,7 @@ class stringUtil
 		}
 		return false;
 	}
-
+	
 	static function subStringUtf8($string, $length, $ext = '')
 	{
 		$num = self::getWordNum($string);
@@ -130,10 +130,34 @@ class stringUtil
 		return ceil($count);
 	}
 	
-	/*
-	 * 取汉字拼音首字母
-	*/
-	static function getfirstchar($s0)
+	//取汉字拼音首字母
+	public static function getSpelling($string)
+	{
+		if (empty($string)) {
+			return '';
+		}
+		$string = str_replace('圳', 'z', $string);
+		$ret = "";
+		$s1 = iconv("UTF-8", "gb2312", $string);
+		$s2 = iconv("gb2312", "UTF-8", $s1);
+		if ($s2 == $string) {
+			$string = $s1;
+		}
+		for ($i = 0; $i < strlen($string); $i++) {
+			$s1 = substr($string, $i, 1);
+			$p = ord($s1);
+			if ($p > 160) {
+				$s2 = substr($string, $i++, 2);
+				$ret .= self::getFirstChar($s2);
+			} else {
+				$ret .= $s1;
+			}
+		}
+		return strtolower($ret);
+	}
+	
+	//取汉字拼音首字母 子方法
+	static function getFirstChar($s0)
 	{
 		$fchar = ord($s0{0});
 		if ($fchar >= ord("A") and $fchar <= ord("z")) return strtoupper($s0{0});
@@ -171,33 +195,6 @@ class stringUtil
 		return null;
 	}
 	
-	/**
-	 * 取汉字拼音首字母
-	 * @param unknown_type $zh
-	 * @return string
-	 */
-	function getSpelling($zh)
-	{
-		$zh = str_replace('圳', 'z', $zh);
-		$ret = "";
-		$s1 = iconv("UTF-8", "gb2312", $zh);
-		$s2 = iconv("gb2312", "UTF-8", $s1);
-		if ($s2 == $zh) {
-			$zh = $s1;
-		}
-		for ($i = 0; $i < strlen($zh); $i++) {
-			$s1 = substr($zh, $i, 1);
-			$p = ord($s1);
-			if ($p > 160) {
-				$s2 = substr($zh, $i++, 2);
-				$ret .= self::getfirstchar($s2);
-			} else {
-				$ret .= $s1;
-			}
-		}
-		return strtolower($ret);
-	}
-	
 	/*
 	 * 取随机数
 	 */
@@ -361,7 +358,7 @@ class stringUtil
 	{
 		return "C" . date('ymdHis') . $merchantId . mt_rand(10000, 99999);
 	}
-
+	
 	//生成用户需要使用的订单号 shish 2019.4.20
 	public static function generateOrderNo($merchantId, $userId)
 	{