190 lines
5.5 KiB
PHP
190 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller\user;
|
|
|
|
use app\common\controller\Api;
|
|
use app\common\library\Ems;
|
|
use app\common\library\Sms;
|
|
use fast\Random;
|
|
use think\Config;
|
|
use think\Validate;
|
|
use app\common\model\User;
|
|
use app\common\library\Wechat;
|
|
use app\common\model\user\Oauth;
|
|
use think\Db;
|
|
/**
|
|
* 账号合并
|
|
*/
|
|
class Merge extends Api
|
|
{
|
|
protected $noNeedLogin = [];
|
|
protected $noNeedRight = '*';
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
}
|
|
|
|
/**
|
|
* 获取需要合并的账号
|
|
* @return void
|
|
*/
|
|
public function getMergeAccount()
|
|
{
|
|
$this->check();
|
|
$key = input('key');
|
|
$mobile = input('mobile');
|
|
$bindUser = \app\common\model\User::where('mobile', $mobile)->where('password',$key)->find();
|
|
$this->success("获取成功",[
|
|
'avatar'=>$bindUser['avatar'],
|
|
'nickname'=>$bindUser['nickname'],
|
|
'username'=>$bindUser['username'],
|
|
'money'=>$bindUser['money'],
|
|
'score'=>$bindUser['score'],
|
|
'platform'=>$bindUser['platform']
|
|
]);
|
|
}
|
|
|
|
|
|
/**
|
|
* 合并账号
|
|
* @return void
|
|
*/
|
|
public function submit(){
|
|
$this->check();
|
|
$key = input('key');
|
|
$mobile = input('mobile');
|
|
|
|
$type = input('type','main');//合并方式
|
|
|
|
$bindUser = \app\common\model\User::where('mobile', $mobile)->where('password',$key)->find();
|
|
|
|
$bindMobile = '';
|
|
|
|
if($type == 'main'){
|
|
$delUser = $bindUser;
|
|
$getUser = $this->auth->getUserinfo();
|
|
}else{
|
|
$delUser = $this->auth->getUserinfo();
|
|
$getUser = $bindUser;
|
|
}
|
|
|
|
$createtime = $getUser['createtime'];
|
|
|
|
if($getUser['mobile']){
|
|
$bindMobile = $getUser['mobile'];
|
|
}else{
|
|
$bindMobile = $delUser['mobile'];
|
|
}
|
|
|
|
if($getUser['createtime'] > $delUser['createtime']){
|
|
$createtime = $delUser['createtime'];
|
|
}
|
|
|
|
|
|
|
|
|
|
$updateTableField = [
|
|
['app_activity_apply_form','user_id'],
|
|
['app_activity_user_ticket','user_id'],
|
|
['app_agent_member','user_id'],
|
|
['app_agent_member_money_log','user_id'],
|
|
['app_agent_order','beneficiary_user_id'],
|
|
['app_agent_order','order_user_id'],
|
|
['app_agent_relation','user_id'],
|
|
['app_agent_relation','parent_id'],
|
|
['app_agent_withdraw','user_id'],
|
|
['app_agent_withdraw_card','user_id'],
|
|
['app_exam_exercises_log','user_id'],
|
|
['app_exam_exercises_log_answer','user_id'],
|
|
['app_exam_exercises_subscribe','user_id'],
|
|
['app_exchange_code','user_id'],
|
|
['app_exchange_use_log','user_id'],
|
|
['app_sign_log','user_id'],
|
|
['app_vip_card_user','user_id'],
|
|
['attachment','user_id'],
|
|
['collect','user_id'],
|
|
['comment_like','user_id'],
|
|
['comment','user_id'],
|
|
['comment','reply_user_id'],
|
|
['live_message','user_id'],
|
|
['order','user_id'],
|
|
['order_evaluate','user_id'],
|
|
['order_item','user_id'],
|
|
['study','user_id'],
|
|
['subscription','user_id'],
|
|
['user_course','user_id'],
|
|
['user_money_log','user_id'],
|
|
['user_oauth','user_id'],
|
|
['user_score_log','user_id'],
|
|
['user_token','user_id'],
|
|
];
|
|
|
|
Db::startTrans();
|
|
try{
|
|
foreach ($updateTableField as $item){
|
|
Db::name($item[0])->where([
|
|
$item[1] => $delUser['id']
|
|
])->update([
|
|
$item[1] => $getUser['id']
|
|
]);
|
|
}
|
|
if($delUser['money']){
|
|
User::money($delUser['money'], $getUser['id'], "账号合并");
|
|
}
|
|
if($delUser['score']){
|
|
User::score($delUser['score'], $getUser['id'], "账号合并");
|
|
}
|
|
\app\common\model\User::where('id', $getUser['id'])->update([
|
|
'mobile'=>$bindMobile,
|
|
'jointime'=>$createtime,
|
|
'createtime'=>$createtime,
|
|
'updatetime'=>time()
|
|
]);
|
|
\app\common\model\User::where('id', $delUser['id'])->delete();
|
|
// 提交事务
|
|
Db::commit();
|
|
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
Db::rollback();
|
|
$this->error("合并失败,请重试");
|
|
}
|
|
|
|
$this->success("合并成功");
|
|
}
|
|
|
|
/**
|
|
* 检测被绑定账号合规
|
|
* @return void
|
|
*/
|
|
public function check(){
|
|
$key = input('key');
|
|
$mobile = input('mobile');
|
|
|
|
//用户通过微信登录,需要绑定手机号,绑定的手机号已经注册过了。现在需要合并微信与手机号
|
|
//验证手机号
|
|
$bindUser = \app\common\model\User::where([
|
|
'mobile'=> $mobile,
|
|
'password'=>$key
|
|
])->find();
|
|
|
|
if(!$bindUser){
|
|
$this->error("获取被绑定用户信息失败");
|
|
}
|
|
|
|
if($mobile == $this->auth->mobile){
|
|
$this->error("重复绑定");
|
|
}
|
|
|
|
$isBindWechat = Oauth::where([
|
|
'user_id'=>$bindUser['id'],
|
|
'platform'=>\app\common\library\Platform::getPlatform()
|
|
])->find();
|
|
|
|
if($isBindWechat){
|
|
$this->error("被绑定手机号已经绑定微信了");
|
|
}
|
|
}
|
|
|
|
} |