654 lines
26 KiB
PHP
654 lines
26 KiB
PHP
<?php
|
|
/**
|
|
* ThinkShop商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2019-2029 成都云之牛科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.cdcloudshop.com
|
|
* =========================================================
|
|
*/
|
|
|
|
namespace app\model\member;
|
|
|
|
use addon\aliapp\model\AliPayApplet;
|
|
use addon\wechat\model\Message as WechatMessage;
|
|
use app\model\BaseModel;
|
|
use app\model\message\Sms;
|
|
use think\Exception;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 登录
|
|
*
|
|
* @author Administrator
|
|
*
|
|
*/
|
|
class Login extends BaseModel{
|
|
/**
|
|
* 用户登录
|
|
* @param unknown $data 必然传输username
|
|
*/
|
|
public function login($data){
|
|
|
|
//必然传输usern
|
|
$info = model("member")->getInfo([
|
|
['username|mobile|email','=',$data['username']],
|
|
['password','=',data_md5($data['password'])],
|
|
['site_id','=',$data['site_id']],
|
|
['is_delete','=',0]
|
|
],'member_id,
|
|
username, nickname, mobile, email, status,last_login_time,can_receive_registergift');
|
|
if(empty($info)){
|
|
return $this->error('','USERNAME_OR_PASSWORD_ERROR');
|
|
}
|
|
elseif($info['status'] == 0){
|
|
return $this->error('','MEMBER_IS_LOCKED');
|
|
}
|
|
else{
|
|
if($info['can_receive_registergift'] == 1){
|
|
event("MemberReceiveRegisterGift",['member_id' => $info['member_id'],'site_id' => $data['site_id']]);
|
|
}
|
|
//更新登录时间
|
|
model("member")->update([
|
|
'login_time' => time(),
|
|
'last_login_time' => time(),
|
|
'can_receive_registergift' => 0,
|
|
'login_ip' => request()->ip(),
|
|
'login_type' => $data['app_type'] ?? '',
|
|
'login_type_name' => $data['app_type_name'] ?? '',
|
|
],[['member_id','=',$info['member_id']]]);
|
|
//执行登录奖励
|
|
event("MemberLogin",['member_id' => $info['member_id'],'site_id' => $data['site_id']],TRUE);
|
|
//用户第三方信息刷新
|
|
$this->refreshAuth($info['member_id'],$data);
|
|
return $this->success($info);
|
|
}
|
|
}
|
|
/**
|
|
* 第三方登录
|
|
* @param array $data 必然传输auth_tag, auth_openid
|
|
*/
|
|
public function authLogin($data){
|
|
$info = [];
|
|
$auth_tag = '';
|
|
foreach($data as $key => $value){
|
|
if(in_array($key,[
|
|
'wx_unionid',
|
|
'wx_openid',
|
|
'weapp_openid',
|
|
'qq_openid',
|
|
'ali_openid',
|
|
'baidu_openid',
|
|
'toutiao_openid'
|
|
])){
|
|
$auth_tag = $key;
|
|
if(empty($value)) return $this->error('','PARAMETER_ERROR');
|
|
$info = model("member")->getInfo([
|
|
[$key,'=',$value],
|
|
['site_id','=',$data['site_id']],
|
|
['is_delete','=',0]
|
|
],'member_id,username, nickname, mobile, email, status, last_login_time, can_receive_registergift');
|
|
if(!empty($info)) break;
|
|
}
|
|
}
|
|
if(empty($auth_tag)) return $this->error('','PARAMETER_ERROR');
|
|
if(empty($info)){
|
|
// 会员不存在 第三方自动注册开启 未开启绑定手机 则进行自动注册
|
|
$config = new Config();
|
|
$config_info = $config->getRegisterConfig($data['site_id'],'shop');
|
|
if($config_info['data']['value']['third_party'] && !$config_info['data']['value']['bind_mobile']){
|
|
$register = new Register();
|
|
$register_res = $register->authRegister($data);
|
|
if($register_res['code'] == 0){
|
|
$info = model("member")->getInfo([
|
|
[
|
|
'member_id',
|
|
'=',
|
|
$register_res['data']
|
|
]
|
|
],'member_id,username, nickname, mobile, email, status, last_login_time,can_receive_registergift');
|
|
$info['is_register'] = 1;
|
|
}
|
|
}
|
|
}
|
|
if(empty($info)){
|
|
return $this->error('','MEMBER_NOT_EXIST');
|
|
}
|
|
elseif($info['status'] == 0){
|
|
return $this->error('','MEMBER_IS_LOCKED');
|
|
}
|
|
else{
|
|
// 登录成功后信息处理
|
|
$this->loginSuccessOperation($info,$data);
|
|
//用户第三方信息刷新
|
|
if(!isset($info['is_register'])) $this->refreshAuth($info['member_id'],$data);
|
|
|
|
return $this->success($info);
|
|
}
|
|
}
|
|
|
|
// 承诺登录(需要同意承诺书后方可登录)
|
|
public function promiseLogin($data){
|
|
$data['wx_unionid'] = $data['wx_unionid'] ?? '';
|
|
// 获取用户信息
|
|
$info = (array)Db::name('member')
|
|
->field('member_id,username, nickname, mobile, email, status, last_login_time, can_receive_registergift')
|
|
->where(function($query) use ($data){
|
|
if($data['weapp_openid'] && $data['wx_unionid']) $query->where('weapp_openid',$data['weapp_openid'])->whereOr('wx_unionid',$data['wx_unionid']);
|
|
else if($data['weapp_openid']) $query->where('weapp_openid',$data['weapp_openid']);
|
|
else if($data['wx_unionid']) $query->where('wx_unionid',$data['wx_unionid']);
|
|
})
|
|
->where('site_id',$data['site_id'])
|
|
->where('is_delete',0)
|
|
->find();
|
|
// 判断用户是否存在 进行对应的操作
|
|
if(!$info){
|
|
$config = new Config();
|
|
$configInfo = $config->getRegisterConfig($data['site_id'])['data'];
|
|
$configInfo = $configInfo['value'] ?? [];
|
|
// 会员不存在 并且存在承诺书 进行承诺书判断
|
|
if(trim($configInfo['promise']) && trim($data['promise_text']) != trim($configInfo['promise'])) {
|
|
if($data['request_type'] == 'login') return $this->error('','MEMBER_NOT_EXIST_REQUEST_REGISTER');
|
|
else return $this->error('','PLEASE_ENTER_THE_CORRECT_CONTENT_OF_THE_LETTER_OF_COMMITMENT');
|
|
}
|
|
// 会员不存在 第三方自动注册开启 未开启绑定手机 则进行自动注册
|
|
if($configInfo['third_party'] && !$configInfo['bind_mobile']){
|
|
$register = new Register();
|
|
$register_res = $register->authRegister($data);
|
|
if($register_res['code'] == 0){
|
|
$info = model("member")->getInfo([
|
|
[
|
|
'member_id',
|
|
'=',
|
|
$register_res['data']
|
|
]
|
|
],'member_id,username, nickname, mobile, email, status, last_login_time,can_receive_registergift');
|
|
$info['is_register'] = 1;
|
|
}
|
|
}
|
|
}
|
|
// 根据登录结果进行返回操作
|
|
if(!$info) return $this->error('','MEMBER_NOT_EXIST');
|
|
elseif($info['status'] == 0) return $this->error('','MEMBER_IS_LOCKED');
|
|
else{
|
|
// 登录成功后信息处理
|
|
$this->loginSuccessOperation($info,$data);
|
|
//用户第三方信息刷新
|
|
if(!isset($info['is_register'])) $this->refreshAuth($info['member_id'],$data);
|
|
return $this->success($info);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 授权登录仅登录
|
|
* @param $data
|
|
* @return array
|
|
*/
|
|
public function authOnlyLogin($data){
|
|
$info = [];
|
|
$auth_tag = '';
|
|
foreach($data as $key => $value){
|
|
if(in_array($key,[
|
|
'wx_unionid',
|
|
'wx_openid',
|
|
'weapp_openid',
|
|
'qq_openid',
|
|
'ali_openid',
|
|
'baidu_openid',
|
|
'toutiao_openid'
|
|
])){
|
|
$auth_tag = $key;
|
|
if(empty($value)) return $this->error('','PARAMETER_ERROR');
|
|
$info = model("member")->getInfo([
|
|
[$key,'=',$value],
|
|
['site_id','=',$data['site_id']],
|
|
['is_delete','=',0]
|
|
],'member_id,username, nickname, mobile, email, status, last_login_time, can_receive_registergift');
|
|
if(!empty($info)) break;
|
|
}
|
|
}
|
|
if(empty($auth_tag)) return $this->error('','PARAMETER_ERROR');
|
|
if(empty($info)){
|
|
return $this->error('','MEMBER_NOT_EXIST');
|
|
}
|
|
elseif($info['status'] == 0){
|
|
return $this->error('','MEMBER_IS_LOCKED');
|
|
}
|
|
else{
|
|
//更新登录时间
|
|
model("member")->update([
|
|
'login_time' => time(),
|
|
'last_login_time' => time(),
|
|
'can_receive_registergift' => 0,
|
|
'login_ip' => request()->ip(),
|
|
'login_type' => $data['app_type'] ?? '',
|
|
'login_type_name' => $data['app_type_name'] ?? '',
|
|
],[['member_id','=',$info['member_id']]]);
|
|
//执行登录奖励
|
|
event("MemberLogin",['member_id' => $info['member_id'],'site_id' => $data['site_id']],TRUE);
|
|
//用户第三方信息刷新
|
|
$this->refreshAuth($info['member_id'],$data);
|
|
return $this->success($info);
|
|
}
|
|
}
|
|
/**
|
|
* 刷新第三方信息
|
|
* @param unknown $member_id
|
|
* @param unknown $data
|
|
* @return multitype:string
|
|
*/
|
|
private function refreshAuth($member_id,$data){
|
|
Member::modifyLastVisitTime($member_id);
|
|
$data = [
|
|
'qq_openid' => isset($data['qq_openid']) ? $data['qq_openid'] : '',
|
|
'wx_openid' => isset($data['wx_openid']) ? $data['wx_openid'] : '',
|
|
'weapp_openid' => isset($data['weapp_openid']) ? $data['weapp_openid'] : '',
|
|
'wx_unionid' => isset($data['wx_unionid']) ? $data['wx_unionid'] : '',
|
|
'ali_openid' => isset($data['ali_openid']) ? $data['ali_openid'] : '',
|
|
'baidu_openid' => isset($data['baidu_openid']) ? $data['baidu_openid'] : '',
|
|
'toutiao_openid' => isset($data['toutiao_openid']) ? $data['toutiao_openid'] : '',
|
|
'site_id' => $data['site_id']
|
|
];
|
|
if(!empty($data['qq_openid'])){
|
|
model("member")->update(['qq_openid' => ''],[
|
|
['qq_openid','=',$data['qq_openid']],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
model("member")->update(['qq_openid' => $data['qq_openid']],[
|
|
['member_id','=',$member_id],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
}
|
|
if(!empty($data['wx_openid'])){
|
|
model("member")->update(['wx_openid' => ''],[
|
|
['wx_openid','=',$data['wx_openid']],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
model("member")->update(['wx_openid' => $data['wx_openid']],[
|
|
['member_id','=',$member_id],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
}
|
|
if(!empty($data['weapp_openid'])){
|
|
model("member")->update(['weapp_openid' => ''],[
|
|
['weapp_openid','=',$data['weapp_openid']],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
model("member")->update(['weapp_openid' => $data['weapp_openid']],[
|
|
['member_id','=',$member_id],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
}
|
|
if(!empty($data['wx_unionid'])){
|
|
model("member")->update(['wx_unionid' => ''],[
|
|
['wx_unionid','=',$data['wx_unionid']],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
model("member")->update(['wx_unionid' => $data['wx_unionid']],[
|
|
['member_id','=',$member_id],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
}
|
|
if(!empty($data['ali_openid'])){
|
|
model("member")->update(['ali_openid' => ''],[
|
|
['ali_openid','=',$data['ali_openid']],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
model("member")->update(['ali_openid' => $data['ali_openid']],[
|
|
['member_id','=',$member_id],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
}
|
|
if(!empty($data['baidu_openid'])){
|
|
model("member")->update(['baidu_openid' => ''],[
|
|
['baidu_openid','=',$data['baidu_openid']],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
model("member")->update(['baidu_openid' => $data['baidu_openid']],[
|
|
['member_id','=',$member_id],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
}
|
|
if(!empty($data['toutiao_openid'])){
|
|
model("member")->update(['toutiao_openid' => ''],[
|
|
['toutiao_openid','=',$data['toutiao_openid']],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
model("member")->update(['toutiao_openid' => $data['toutiao_openid']],[
|
|
['member_id','=',$member_id],
|
|
['site_id','=',$data['site_id']]
|
|
]);
|
|
}
|
|
return $this->success();
|
|
}
|
|
/**
|
|
* 检测openid是否存在
|
|
* @param array $data
|
|
*/
|
|
public function openidIsExits(array $data){
|
|
if(isset($data['wx_unionid']) && !empty($data['wx_unionid'])){
|
|
$count = model("member")->getCount([
|
|
['wx_unionid','=',$data['wx_unionid']],
|
|
['site_id','=',$data['site_id']],
|
|
['is_delete','=',0]
|
|
]);
|
|
if($count) return $this->success($count);
|
|
}
|
|
if(isset($data['wx_openid']) && !empty($data['wx_openid'])){
|
|
$count = model("member")->getCount([
|
|
['wx_openid','=',$data['wx_openid']],
|
|
['site_id','=',$data['site_id']],
|
|
['is_delete','=',0]
|
|
]);
|
|
if($count) return $this->success($count);
|
|
}
|
|
if(isset($data['weapp_openid']) && !empty($data['weapp_openid'])){
|
|
$count = model("member")->getCount([
|
|
['weapp_openid','=',$data['weapp_openid']],
|
|
['site_id','=',$data['site_id']],
|
|
['is_delete','=',0]
|
|
]);
|
|
if($count) return $this->success($count);
|
|
}
|
|
if(isset($data['qq_openid']) && !empty($data['qq_openid'])){
|
|
$count = model("member")->getCount([
|
|
['qq_openid','=',$data['qq_openid']],
|
|
['site_id','=',$data['site_id']],
|
|
['is_delete','=',0]
|
|
]);
|
|
if($count) return $this->success($count);
|
|
}
|
|
if(isset($data['ali_openid']) && !empty($data['ali_openid'])){
|
|
$count = model("member")->getCount([
|
|
['ali_openid','=',$data['ali_openid']],
|
|
['site_id','=',$data['site_id']],
|
|
['is_delete','=',0]
|
|
]);
|
|
if($count) return $this->success($count);
|
|
}
|
|
if(isset($data['baidu_openid']) && !empty($data['baidu_openid'])){
|
|
$count = model("member")->getCount([
|
|
['baidu_openid','=',$data['baidu_openid']],
|
|
['site_id','=',$data['site_id']],
|
|
['is_delete','=',0]
|
|
]);
|
|
if($count) return $this->success($count);
|
|
}
|
|
if(isset($data['toutiao_openid']) && !empty($data['toutiao_openid'])){
|
|
$count = model("member")->getCount([
|
|
['toutiao_openid','=',$data['toutiao_openid']],
|
|
['site_id','=',$data['site_id']],
|
|
['is_delete','=',0]
|
|
]);
|
|
if($count) return $this->success($count);
|
|
}
|
|
return $this->success(0);
|
|
}
|
|
/**
|
|
* 用户登录
|
|
* @param unknown $data 必然传输username
|
|
*/
|
|
public function mobileLogin($data){
|
|
//必然传输usern
|
|
$info = model("member")->getInfo([
|
|
['mobile','=',$data['mobile']],
|
|
['site_id','=',$data['site_id']],
|
|
['is_delete','=',0]
|
|
],'member_id,username, nickname, mobile, email, status,last_login_time, can_receive_registergift');
|
|
if(empty($info)){
|
|
return $this->error('','MEMBER_NOT_EXIST');
|
|
}
|
|
elseif($info['status'] == 0){
|
|
return $this->error('','MEMBER_IS_LOCKED');
|
|
}
|
|
else{
|
|
if($info['can_receive_registergift'] == 1){
|
|
event("MemberReceiveRegisterGift",['member_id' => $info['member_id'],'site_id' => $data['site_id']]);
|
|
}
|
|
//更新登录时间
|
|
model("member")->update([
|
|
'login_time' => time(),
|
|
'last_login_time' => time(),
|
|
'can_receive_registergift' => 0,
|
|
'login_ip' => request()->ip(),
|
|
'login_type' => $data['app_type'] ?? '',
|
|
'login_type_name' => $data['app_type_name'] ?? '',
|
|
],[['member_id','=',$info['member_id']]]);
|
|
event("MemberLogin",['member_id' => $info['member_id'],'site_id' => $data['site_id']],TRUE);
|
|
//用户第三方信息刷新
|
|
$this->refreshAuth($info['member_id'],$data);
|
|
return $this->success($info);
|
|
}
|
|
}
|
|
/**
|
|
* 登录动态码
|
|
* @param $data
|
|
*/
|
|
public function loginCode($data){
|
|
//发送短信
|
|
$sms_model = new Sms();
|
|
$var_parse = [
|
|
"code" => $data["code"],
|
|
];
|
|
$data["sms_account"] = $data["mobile"] ?? '';//手机号
|
|
$data["var_parse"] = $var_parse;
|
|
$sms_result = $sms_model->sendMessage($data);
|
|
if($sms_result["code"] < 0) return $sms_result;
|
|
return $this->success();
|
|
}
|
|
/**
|
|
* 登录通知
|
|
* @param $data
|
|
* @return array|mixed|void
|
|
*/
|
|
public function loginSuccess($data){
|
|
$member_model = new Member();
|
|
$member_info_result = $member_model->getMemberInfo([
|
|
[
|
|
"member_id",
|
|
"=",
|
|
$data["member_id"]
|
|
]
|
|
],"username,mobile,email,reg_time,wx_openid,last_login_type,login_time, nickname");
|
|
$member_info = $member_info_result["data"];
|
|
//发送短信
|
|
$sms_model = new Sms();
|
|
$name = $member_info["nickname"] == '' ? $member_info["mobile"] : $member_info["nickname"];
|
|
$var_parse = [
|
|
"name" => replaceSpecialChar($name),//验证码
|
|
];
|
|
$data["sms_account"] = $member_info["mobile"] ?? '';//手机号
|
|
$data["var_parse"] = $var_parse;
|
|
$sms_result = $sms_model->sendMessage($data);
|
|
// if($sms_result["code"] < 0)
|
|
// return $sms_result;
|
|
//发送模板消息
|
|
$wechat_model = new WechatMessage();
|
|
$data["openid"] = $member_info["wx_openid"];
|
|
// if(!empty($member_info["username"])){
|
|
// $user_account = $member_info["username"];
|
|
// }else{
|
|
// if(!empty($member_info["mobile"])){
|
|
// $user_account = $member_info["mobile"];
|
|
// }else{
|
|
// $user_account = $member_info["email"];
|
|
// }
|
|
// }
|
|
$data["template_data"] = [
|
|
'keyword1' => !empty($member_info["nickname"]) ? $member_info["nickname"] : $member_info["mobile"],
|
|
'keyword2' => '登录成功',
|
|
'keyword3' => time_to_date($member_info["login_time"]),
|
|
];
|
|
$data["page"] = '';
|
|
$wechat_model->sendMessage($data);
|
|
return $this->success();
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Common: 支付宝小程序登录 —— 开始处理
|
|
* Author: wu-hui
|
|
* Time: 2023/01/05 15:02
|
|
* @param $wholeParams
|
|
* @return array
|
|
* @throws Exception
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function alipayLoginHandle($wholeParams){
|
|
$aliPayAppletModel = new AliPayApplet($wholeParams['site_id']);
|
|
// 获取用户基本信息
|
|
$baseInfo = $aliPayAppletModel->loginBaseInfo($wholeParams['code']);
|
|
if($baseInfo['code'] != 0) throw new Exception($baseInfo['message']);
|
|
// 获取用户详细信息
|
|
$detailsInfo = $aliPayAppletModel->loginDetailsInfo($baseInfo['data']['access_token']);
|
|
if($detailsInfo['code'] != 0) throw new Exception($detailsInfo['message']);
|
|
// 处理用户信息
|
|
$loginInfo = array_merge($baseInfo['data'],$detailsInfo['data']);
|
|
$loginInfo['site_id'] = $wholeParams['site_id'];
|
|
$loginInfo['provider'] = $wholeParams['provider'];
|
|
$loginInfo['app_type'] = $wholeParams['app_type'];
|
|
// 获取用户本平台信息
|
|
$userInfo = $this->alipayLoginGetUserInfo($loginInfo['user_id'],$wholeParams['site_id']);
|
|
if(!$userInfo) $userInfo = $this->alipayLoginRegister($wholeParams,$loginInfo);
|
|
// 粉丝信息处理
|
|
$this->loginFansHandle($userInfo,$loginInfo);
|
|
// 登录成功后的操作
|
|
$this->loginSuccessOperation($userInfo,$wholeParams);
|
|
|
|
return $this->success($userInfo);
|
|
}
|
|
/**
|
|
* Common: 支付宝小程序登录 —— 获取用户信息
|
|
* Author: wu-hui
|
|
* Time: 2023/01/05 14:37
|
|
* @param $userId
|
|
* @return array|mixed|Db|\think\Model|null
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function alipayLoginGetUserInfo($userId,$siteId){
|
|
return Db::name('member')
|
|
->field('member_id,username,headimg,nickname, mobile, email, status, last_login_time, can_receive_registergift')
|
|
->where('site_id',$siteId)
|
|
->where('ali_openid',$userId)
|
|
->find();
|
|
}
|
|
/**
|
|
* Common: 支付宝小程序登录 —— 用户注册
|
|
* Author: wu-hui
|
|
* Time: 2023/01/05 14:48
|
|
* @param $wholeParams
|
|
* @param $loginInfo
|
|
* @return array|mixed|Db|\think\Model
|
|
* @throws Exception
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function alipayLoginRegister($wholeParams,$loginInfo){
|
|
$registerData = [
|
|
'site_id' => $wholeParams['site_id'] ?? '',
|
|
'source_member' => $wholeParams['source_member'] ?? '',
|
|
'nickName' => $loginInfo['nick_name'] ?? '',
|
|
'ali_openid' => $loginInfo['user_id'] ?? '',
|
|
'avatarUrl' => $loginInfo['avatar'] ?? '',
|
|
'app_type' => $wholeParams['app_type'] ?? '',
|
|
'app_type_name' => $wholeParams['app_type_name'] ?? '',
|
|
];
|
|
|
|
$registerResult = (new Register())->authRegister($registerData);
|
|
if($registerResult['code'] == 0){
|
|
$userInfo = $this->alipayLoginGetUserInfo($loginInfo['user_id'],$wholeParams['site_id']);
|
|
$userInfo['is_register'] = 1;
|
|
|
|
return $userInfo;
|
|
}
|
|
|
|
throw new Exception('注册失败:'.$registerResult['message']);
|
|
}
|
|
/**
|
|
* Common: 登录处理 —— 粉丝信息处理
|
|
* Author: wu-hui
|
|
* Time: 2023/01/05 15:28
|
|
* @param $userInfo
|
|
* @param $loginInfo
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function loginFansHandle($userInfo,$loginInfo){
|
|
$time = time();
|
|
$ip = request()->ip();
|
|
// 判断:粉丝是否存在
|
|
$has = (int)Db::name('uni_fans')->where('site_id',$loginInfo['site_id'])->where('uid',$userInfo['member_id'])->value('id');
|
|
if($has > 0){
|
|
// 用户存在 修改信息
|
|
$updateData = [
|
|
'update_time' => $time,
|
|
'login_time' => $time,
|
|
'login_ip' => $ip,
|
|
];
|
|
Db::name('uni_fans')->where('site_id',$loginInfo['site_id'])->where('uid',$userInfo['member_id'])->update($updateData);
|
|
}
|
|
else{
|
|
// 用户不存在 添加
|
|
$insertData = [
|
|
'site_id' => $loginInfo['site_id'],
|
|
'uid' => $userInfo['member_id'],
|
|
'app_type' => $loginInfo['app_type'],
|
|
'open_id' => $loginInfo['user_id'] ?? '',
|
|
'unionid' => $loginInfo['unionid'] ?? '',
|
|
'nickname' => $userInfo['nickname'] ?? '',
|
|
'headimg' => $userInfo['headimg'] ?? '',
|
|
'create_time' => $time,
|
|
'update_time' => $time,
|
|
'login_time' => $time,
|
|
'login_ip' => $ip,
|
|
];
|
|
|
|
Db::name('uni_fans')->insert($insertData);
|
|
}
|
|
}
|
|
/**
|
|
* Common: 登录处理 —— 登录成功后的信息处理
|
|
* Author: wu-hui
|
|
* Time: 2023/01/05 14:58
|
|
* @param $userInfo
|
|
* @param $wholeParams
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function loginSuccessOperation($userInfo,$wholeParams){
|
|
$time = time();
|
|
// 是否可以领取新人礼包
|
|
if($userInfo['can_receive_registergift'] == 1) {
|
|
$params = [
|
|
'member_id' => $userInfo['member_id'],
|
|
'site_id' => $wholeParams['site_id']
|
|
];
|
|
event("MemberReceiveRegisterGift",$params);
|
|
}
|
|
// 更新用户信息
|
|
$updateLoginTime = [
|
|
'login_time' => $time,
|
|
'last_login_time' => $time,
|
|
'last_visit_time' => $time,
|
|
'can_receive_registergift' => 0,
|
|
'login_ip' => request()->ip(),
|
|
'login_type' => $wholeParams['app_type'] ?? '',
|
|
'login_type_name' => $wholeParams['app_type_name'] ?? '',
|
|
];
|
|
Db::name('member')->where('site_id',$wholeParams['site_id'])->where('member_id',$userInfo['member_id'])->update($updateLoginTime);
|
|
// 执行登录奖励
|
|
$loginReward = [
|
|
'member_id' => $userInfo['member_id'],
|
|
'site_id' => $wholeParams['site_id']
|
|
];
|
|
event("MemberLogin",$loginReward,TRUE);
|
|
}
|
|
|
|
|
|
|
|
} |