用户资产相关通用门面
大约 1 分钟
因为用户资产高度敏感,所以单独拿出一章来说明
提示
注意需要结合DTO BusinessChangeUserAssetDTO
以下分别是 用户资产变更事件
- 用户现金资产变更 ChangeUserCashAssetEvent
- 用户积分资产变更 ChangeUserScoreAssetEvent
- 用户奖金资产变更 ChangeUserBonusAssetEvent
- 用户系统币资产变更 ChangeUserCoinAssetEvent
use App\DTOs\Common\V1\User\Asset\BusinessChangeUserAssetDTO;
use App\Events\Common\V1\User\Asset\ChangeUserBonusAssetEvent;
use App\Events\Common\V1\User\Asset\ChangeUserCashAssetEvent;
use App\Events\Common\V1\User\Asset\ChangeUserCoinAssetEvent;
use App\Events\Common\V1\User\Asset\ChangeUserScoreAssetEvent;使用示例:
示例代码是后台聚合使用,在不同业务场景中,也可以单独使用.万变不离其宗,参数的传递都是一样的.
#[DocNote('后台修改账户映射数组')]
protected $change_amount_ke_map = [
10=>'available_cash_amount',
20=>'available_coin_amount',
30=>'available_score_amount',
40=>'available_bonus_amount',
];
#[DocNote('修改用户账户事件映射数组')]
protected $event_map = [
10=>ChangeUserCashAssetEvent::class,
20=>ChangeUserCoinAssetEvent::class,
30=>ChangeUserScoreAssetEvent::class,
40=>ChangeUserBonusAssetEvent::class,
];
$businessDTO = new BusinessChangeUserAssetDTO;
$businessDTO->user_uid = $user_uid;
$businessDTO->account_type = $account_type;
$businessDTO->action_type = $action_type;
$businessDTO->amount = (string)$amount;
$businessDTO->reason = '后台管理员操作';
$businessDTO->relation_uid = get_snow_flake_id();
$businessDTO->relation_type = 60;
$businessDTO->change_amount_key = $this->change_amount_ke_map[$account_type];
DB::beginTransaction();
$this->event_map[$account_type]::dispatch($businessDTO,true);
CommonEvent::dispatch($adminObject, $requestDTO, ['code'=>10000,'info'=>'设置用户账户','event'=>'SetUserAccount'], true);
DB::commit();