master
elf 2 years ago
parent 9f6307850f
commit e0c3aa652b

@ -11,4 +11,6 @@ class Promote extends Model
use PromoteScopes; use PromoteScopes;
protected $table = 'tab_promote'; protected $table = 'tab_promote';
public static $levelColumns = ['level1_id', 'level2_id', 'level3_id', 'level3_id'];
} }

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace App\Repository;
use App\Model\Promote;
class PromoteRepository
{
public function getLevelPromotesById($id, $columns = ['*']) {
$promote = Promote::query()->where('id', $id)->first(Promote::$levelColumns);
$levelIds = [];
foreach (Promote::$levelColumns as $column) {
if ($promote->{$column} > 0) {
$levelIds[] = $promote->{$column};
}
}
return Promote::query()->whereIn('id', $levelIds)->get($columns);
}
}

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace App\Service;
use App\Model\Promote;
class PromoteService extends Service
{
}

@ -12,9 +12,17 @@ use App\Model\UserData;
use App\Model\UserPlayDataCount; use App\Model\UserPlayDataCount;
use App\Helper\Log; use App\Helper\Log;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
use App\Repository\PromoteRepository;
class SpendService extends Service class SpendService extends Service
{ {
/**
* @Inject
* @var PromoteRepository
*/
private $promoteRepository;
public function afterSpend($payOrderNumber) public function afterSpend($payOrderNumber)
{ {
Log::info('[GAME-RECHARGE]产生充值订单:' . $payOrderNumber); Log::info('[GAME-RECHARGE]产生充值订单:' . $payOrderNumber);
@ -38,6 +46,8 @@ class SpendService extends Service
$spend->save(); $spend->save();
if (in_array($spend->game_id, [335, 336])) { if (in_array($spend->game_id, [335, 336])) {
$levelPromotes = $this->promoteRepository->getLevelPromotesById($spend->promote_id, ['id', 'level', 'account']);
$levelPromotes = $levelPromotes->indexBy('level');
Lanhuo::addOrder([ Lanhuo::addOrder([
'order_code' => $spend->pay_order_number, 'order_code' => $spend->pay_order_number,
'user_id' => $spend->user_id, 'user_id' => $spend->user_id,
@ -50,6 +60,12 @@ class SpendService extends Service
'order_amount' => $spend->pay_amount, 'order_amount' => $spend->pay_amount,
'pay_time' => date('Y-m-d H:i:s', $spend->spend_time), 'pay_time' => date('Y-m-d H:i:s', $spend->spend_time),
'status' => $spend->pay_status, //支付状态(待支付 0 已支付 1 支付失败 2) 'status' => $spend->pay_status, //支付状态(待支付 0 已支付 1 支付失败 2)
'minister_id' => isset($levelPromotes[2]) ? $levelPromotes[2]->id : 0,
'minister_name' => isset($levelPromotes[2]) ? $levelPromotes[2]->account : '',
'headman_id' => isset($levelPromotes[3]) ? $levelPromotes[3]->id : 0,
'headman_name' => isset($levelPromotes[3]) ? $levelPromotes[3]->account : '',
'promoter_id' => isset($levelPromotes[4]) ? $levelPromotes[4]->id : 0,
'promoter_name' => isset($levelPromotes[4]) ? $levelPromotes[4]->account : '',
]); ]);
} }
} }

@ -10,9 +10,18 @@ use App\Model\Player;
use App\Model\PlayerRetention; use App\Model\PlayerRetention;
use App\Model\User; use App\Model\User;
use App\Helper\Log; use App\Helper\Log;
use Hyperf\Di\Annotation\Inject;
use App\Repository\PromoteRepository;
class UserService extends Service class UserService extends Service
{ {
/**
* @Inject
* @var PromoteRepository
*/
private $promoteRepository;
public function afterLogin($params) public function afterLogin($params)
{ {
$gameId = $params['game_id']; $gameId = $params['game_id'];
@ -88,6 +97,7 @@ class UserService extends Service
'real_name', 'real_name',
'idcard', 'idcard',
'age_status', 'age_status',
'promote_id'
]); ]);
if (!$user) { if (!$user) {
throw new BusinessException('用户不存在'); throw new BusinessException('用户不存在');
@ -104,6 +114,8 @@ class UserService extends Service
} }
if (in_array($user->fgame_id, [335, 336])) { if (in_array($user->fgame_id, [335, 336])) {
$levelPromotes = $this->promoteRepository->getLevelPromotesById($user->promote_id, ['id', 'level', 'account']);
$levelPromotes = $levelPromotes->indexBy('level');
Lanhuo::addUser([ Lanhuo::addUser([
'user_id' => $user->id, 'user_id' => $user->id,
'account' => $user->account, 'account' => $user->account,
@ -113,6 +125,12 @@ class UserService extends Service
'name' => $user->real_name, 'name' => $user->real_name,
'id_card' => $user->idcard, 'id_card' => $user->idcard,
'is_real' => $user->age_status == 2 ? 1 : 0, // 是否实名(1-实名 0-未实名) 'is_real' => $user->age_status == 2 ? 1 : 0, // 是否实名(1-实名 0-未实名)
'minister_id' => isset($levelPromotes[2]) ? $levelPromotes[2]->id : 0,
'minister_name' => isset($levelPromotes[2]) ? $levelPromotes[2]->account : '',
'headman_id' => isset($levelPromotes[3]) ? $levelPromotes[3]->id : 0,
'headman_name' => isset($levelPromotes[3]) ? $levelPromotes[3]->account : '',
'promoter_id' => isset($levelPromotes[4]) ? $levelPromotes[4]->id : 0,
'promoter_name' => isset($levelPromotes[4]) ? $levelPromotes[4]->account : '',
]); ]);
} }
} }

Loading…
Cancel
Save