|
|
@@ -20,46 +20,7 @@ class CustomClass extends BaseClass
|
|
|
return 'hd_custom_key_' . $sjId . '_' . $userId;
|
|
|
}
|
|
|
|
|
|
- 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]);
|
|
|
- //需要创建客户信息
|
|
|
- $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;
|
|
|
- }
|
|
|
-
|
|
|
- //创建获取客户信息 ssh 2021.3.19
|
|
|
+ //创建或获取客户信息 ssh 2021.3.19
|
|
|
public static function replaceCustom($sjId, $user)
|
|
|
{
|
|
|
$userId = $user['id'];
|
|
|
@@ -68,7 +29,8 @@ class CustomClass extends BaseClass
|
|
|
$key = self::getCustomCacheKey($sjId, $userId);
|
|
|
$currentId = Yii::$app->redis->executeCommand('GET', [$key]);
|
|
|
if (!empty($currentId)) {
|
|
|
- return $currentId;
|
|
|
+ $info = self::getById($currentId);
|
|
|
+ return $info;
|
|
|
}
|
|
|
$info = self::getByCondition(['sjId' => $sjId, 'userId' => $userId]);
|
|
|
if (empty($info)) {
|
|
|
@@ -84,9 +46,12 @@ class CustomClass extends BaseClass
|
|
|
];
|
|
|
$info = self::addCustom($data);
|
|
|
}
|
|
|
+ if (empty($info)) {
|
|
|
+ util::fail('没有生成客户信息');
|
|
|
+ }
|
|
|
$id = $info['id'];
|
|
|
Yii::$app->redis->executeCommand('SET', [$key, $id]);
|
|
|
- return $id;
|
|
|
+ return $info;
|
|
|
}
|
|
|
|
|
|
//获取客户信息
|