|
|
@@ -57,6 +57,7 @@ class PartyController extends Controller
|
|
|
$key = $req->input('key');
|
|
|
$appid = $req->input('appid');
|
|
|
$partyUserName = $req->input('username');
|
|
|
+ $partyNickName = $req->input('nickname');
|
|
|
//$partyInfo = \App\Models\Party::where('key', $key)->first();
|
|
|
$partyInfo = $partyModel->where('key', $key)->first();
|
|
|
|
|
|
@@ -83,6 +84,7 @@ class PartyController extends Controller
|
|
|
$partyUserModel->insert([
|
|
|
'party_id' => $partyInfo['id'],
|
|
|
'party_username' => $partyUserName,
|
|
|
+ 'nickname' => $partyNickName,
|
|
|
'password' => $req->input('password'),
|
|
|
'login_time' => now(),
|
|
|
'login_ip' => $this->get_real_ip(),
|
|
|
@@ -97,16 +99,17 @@ class PartyController extends Controller
|
|
|
$adapter = new Adapter();
|
|
|
//查询是否已创建对于应用的用户
|
|
|
$appUserModel = new Models\AppUser();
|
|
|
- $appUsername = $this->buildAppUsername($partyInfo['id'], $partyUserName, $appid);
|
|
|
- $appUserInfo = $appUserModel->where('app_username',$appUsername)->first();
|
|
|
- if(empty($appUserInfo)){
|
|
|
+
|
|
|
+ $info = $this->findAppUsername($partyInfo['id'], $partyUserName, $appid);
|
|
|
+ if($info == false){
|
|
|
+ $appUsername = $this->buildAppUsername($partyInfo['id'], $partyUserName, $appid);
|
|
|
$result = $adapter->syncUser($appid, $appUsername, $req->input('password')); //检测用户并创建用户
|
|
|
if($result['code'] != 1){
|
|
|
$this->logger->addError('login out: status:-102;创建应用用户失败; '.json_encode($result));
|
|
|
return toJson(-102, $result['msg'], []);
|
|
|
}
|
|
|
|
|
|
- $appUserModel->insert([
|
|
|
+ $appUserId = $appUserModel->insert([
|
|
|
'app_id' => $appInfo['id'],
|
|
|
'party_username' => $partyUserName,
|
|
|
'app_username' => $appUsername,
|
|
|
@@ -114,8 +117,19 @@ class PartyController extends Controller
|
|
|
'login_time' => now(),
|
|
|
'login_ip' => $this->get_real_ip(),
|
|
|
]);
|
|
|
+
|
|
|
+ $UserMapModel = new Models\PartyAppUserMap();
|
|
|
+ $UserMapModel->insert([
|
|
|
+ 'party_id' => $partyInfo['id'],
|
|
|
+ 'party_username' => $partyUserName,
|
|
|
+ 'app_id' => $appInfo['id'],
|
|
|
+ 'app_username' => $appUsername,
|
|
|
+ 'app_user_id' => $appUserId,
|
|
|
+ ]);
|
|
|
}else{
|
|
|
- $appUserModel->where('id', $appUserInfo['id'])->update([
|
|
|
+ $appUsername = $info['appUsername'];
|
|
|
+ $appUserId = $info['appUserId'];
|
|
|
+ $appUserModel->where('id', $appUserId)->update([
|
|
|
'login_time' => now(),
|
|
|
'login_ip' => $this->get_real_ip(),
|
|
|
]);
|
|
|
@@ -131,18 +145,20 @@ class PartyController extends Controller
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
//更新额度
|
|
|
+ $partyBalance = $partyInfo['balance'] - $money;
|
|
|
$result1 = $partyModel->where('id', $partyInfo['id'])->update(array(
|
|
|
- 'balance' => $partyInfo['balance'] - $money
|
|
|
+ 'balance' => $partyBalance
|
|
|
));
|
|
|
|
|
|
//更新额度
|
|
|
+ $appBalance = $appInfo['balance'] - $money;
|
|
|
$result2 = $appModel->where('id', $appInfo['id'])->update(array(
|
|
|
- 'balance' => $appInfo['balance'] - $money
|
|
|
+ 'balance' => $appBalance
|
|
|
));
|
|
|
|
|
|
- //记录日志
|
|
|
- $result3 = $balanceLogModel = new Models\BalanceLog();
|
|
|
- $balanceLogModel->insert([
|
|
|
+ //记录第三方日志
|
|
|
+ $balanceLogModel = new Models\BalanceLog();
|
|
|
+ $result3 = $balanceLogModel->insert([
|
|
|
'type' => 2,
|
|
|
'money' => $money,
|
|
|
'app_id' => $appInfo['id'],
|
|
|
@@ -150,8 +166,21 @@ class PartyController extends Controller
|
|
|
'party_id' =>$partyInfo['id'],
|
|
|
'party_username' => $partyUserName,
|
|
|
'billno' => $billno,
|
|
|
+ 'balance' => $partyBalance
|
|
|
]);
|
|
|
- if($result1 === false || $result2 === false || $result3 === false){
|
|
|
+ //记录平台日志
|
|
|
+ $appBalanceLogModel = new Models\AppBalanceLog();
|
|
|
+ $result4 = $appBalanceLogModel->insert([
|
|
|
+ 'type' => 2,
|
|
|
+ 'money' => $money,
|
|
|
+ 'app_id' => $appInfo['id'],
|
|
|
+ 'app_username' => $appUsername,
|
|
|
+ 'party_id' =>$partyInfo['id'],
|
|
|
+ 'party_username' => $partyUserName,
|
|
|
+ 'billno' => $billno,
|
|
|
+ 'balance' => $appBalance
|
|
|
+ ]);
|
|
|
+ if($result1 === false || $result2 === false || $result3 === false || $result4 === false){
|
|
|
DB::rollBack();
|
|
|
$this->logger->addError('login out: status:-104;更新数据库失败');
|
|
|
return toJson(-104, '系统繁忙', []);
|
|
|
@@ -171,6 +200,22 @@ class PartyController extends Controller
|
|
|
|
|
|
}//end login()
|
|
|
|
|
|
+
|
|
|
+ private function findAppUsername($partyId, $partyUsername, $appid){
|
|
|
+ $UserMapModel = new Models\PartyAppUserMap();
|
|
|
+
|
|
|
+ $info = $UserMapModel->where([
|
|
|
+ ['party_id',$partyId],
|
|
|
+ ['party_username',$partyUsername],
|
|
|
+ ['app_id', $appid]
|
|
|
+ ])->first();
|
|
|
+ if(empty($info)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return array('appUsername' => $info['app_username'], 'appUserId' => $info['app_user_id']);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 组装内容用户名称
|
|
|
* @param $partyId
|