|
|
@@ -9,6 +9,7 @@ use bizHd\message\classes\ChatClass;
|
|
|
use bizHd\user\services\UserIntegralService;
|
|
|
use common\components\business;
|
|
|
use common\components\dict;
|
|
|
+use common\components\stringUtil;
|
|
|
use common\components\util;
|
|
|
use common\components\wxUtil;
|
|
|
use common\services\ImageService;
|
|
|
@@ -96,8 +97,17 @@ class UserClass extends BaseClass
|
|
|
return self::getByCondition(['sjId' => $sjId, 'mobile' => $mobile]);
|
|
|
}
|
|
|
|
|
|
- public static function generateUser($getUserInfo, $sjId)
|
|
|
+ public static function replaceUser($getUserInfo)
|
|
|
{
|
|
|
+ $mobile = $getUserInfo['mobile'] ?? '';
|
|
|
+ if (stringUtil::isMobile($mobile) == false) {
|
|
|
+ util::fail('请填写正确手机号');
|
|
|
+ }
|
|
|
+ $user = self::getByCondition(['mobile' => $mobile], true);
|
|
|
+ if (!empty($user)) {
|
|
|
+ return $user;
|
|
|
+ }
|
|
|
+
|
|
|
$date = date("Y-m-d H:i:s");
|
|
|
$time = time();
|
|
|
//替换掉微信名称不支持的图片
|
|
|
@@ -121,13 +131,10 @@ class UserClass extends BaseClass
|
|
|
$getUserInfo['source'] = isset($getUserInfo['source']) ? $getUserInfo['source'] : 0;
|
|
|
$getUserInfo['hasSubscribe'] = 0;
|
|
|
//生成用户基础信息
|
|
|
- $user = self::add($getUserInfo);
|
|
|
- $userId = $user['id'];
|
|
|
-
|
|
|
+ $user = self::add($getUserInfo, true);
|
|
|
+ $userId = $user->id ?? 0;
|
|
|
$assetData = ['userId' => $userId, 'createTime' => $date];
|
|
|
- //生成用户资产信息
|
|
|
UserAssetClass::add($assetData);
|
|
|
-
|
|
|
//保存头像
|
|
|
if (isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl'])) {
|
|
|
if (empty($preUser) || (isset($preUser['avatar']) && empty($preUser['avatar']))) {
|
|
|
@@ -201,11 +208,6 @@ class UserClass extends BaseClass
|
|
|
return self::getByCondition(['miniOpenId' => $miniOpenId]);
|
|
|
}
|
|
|
|
|
|
- public static function getByAlipayId($alipayId, $sjId)
|
|
|
- {
|
|
|
- return self::getByCondition(['sjId' => $sjId, 'alipayId' => $alipayId]);
|
|
|
- }
|
|
|
-
|
|
|
public static function getByOpenId($openId)
|
|
|
{
|
|
|
return self::getByCondition(['openId' => $openId]);
|
|
|
@@ -471,56 +473,4 @@ class UserClass extends BaseClass
|
|
|
return $info;
|
|
|
}
|
|
|
|
|
|
- //创建以及更新用户 ssh 2020.2.7
|
|
|
- public static function replaceUser($userInfo, $source, $sjId)
|
|
|
- {
|
|
|
- $userInfo = self::switchUserInfo($userInfo, $source);
|
|
|
- $unionId = isset($userInfo['unionId']) && !empty($userInfo['unionId']) ? $userInfo['unionId'] : '';
|
|
|
- $user = UserClass::getByUnionId($unionId);
|
|
|
- if (empty($user)) {
|
|
|
- $user = self::generateUser($userInfo, 0);
|
|
|
- } else {
|
|
|
- $user = self::updateUser($user, $userInfo, 0);
|
|
|
- }
|
|
|
- return $user;
|
|
|
- }
|
|
|
-
|
|
|
- //拉取粉丝 ssh 2020.2.7
|
|
|
- public static function syncWxUser($sjId, $nextOpenId = '')
|
|
|
- {
|
|
|
- $merchant = MerchantClass::getMerchantById($sjId);
|
|
|
- //一次拉取调用最多拉取10000个关注者的OpenID
|
|
|
- $result = wxUtil::getSubscribeUserList($merchant, $nextOpenId);
|
|
|
- $total = isset($result['total']) ? $result['total'] : 0;
|
|
|
- $next_openid = isset($result['next_openid']) ? $result['next_openid'] : '';
|
|
|
- $count = isset($result['count']) ? $result['count'] : 0;
|
|
|
- $openIdList = isset($result['data']['openid']) ? $result['data']['openid'] : [];
|
|
|
- $currentTotal = count($openIdList);
|
|
|
- if ($count == 0 || $currentTotal == 0) {
|
|
|
- return ['total' => $total, 'count' => $count, 'nextOpenId' => $next_openid];
|
|
|
- }
|
|
|
- $currentTotalPage = $currentTotal > 100 ? ceil($currentTotal / 100) : 1;
|
|
|
- $source = dict::getDict('userSourceGetId', 'official', 'name');
|
|
|
- for ($m = 1; $m <= $currentTotalPage; $m++) {
|
|
|
- $offset = ($m - 1) * 100;
|
|
|
- $subIdList = array_slice($openIdList, $offset, 100);
|
|
|
- $info = wxUtil::batchGetUserInfo($merchant, $subIdList);
|
|
|
- if (empty($info) || isset($info['user_info_list']) == false || empty($info['user_info_list'])) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $user_info_list = $info['user_info_list'];
|
|
|
- foreach ($user_info_list as $val) {
|
|
|
- $val['isFull'] = 1;
|
|
|
- $val['unionId'] = $val['unionid'];
|
|
|
- $val['headImgUrl'] = $val['headimgurl'];
|
|
|
- $val['openId'] = $val['openid'];
|
|
|
- //去掉不支持的字符
|
|
|
- $val['nickName'] = isset($val['nickname']) ? preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $val['nickname']) : '';
|
|
|
- $val['sjId'] = $sjId;
|
|
|
- self::replaceUser($val, $source, $sjId);
|
|
|
- }
|
|
|
- }
|
|
|
- return ['total' => $total, 'count' => $count, 'nextOpenId' => $next_openid];
|
|
|
- }
|
|
|
-
|
|
|
}
|