6
0
Fork 0

添加老配额分红统计

release
vine_liutk 2022-01-05 19:48:54 +08:00
parent aafd381dcf
commit f3ce94002c
3 changed files with 40 additions and 20 deletions

View File

@ -33,6 +33,26 @@ class QuotaV1SendLogTable extends Grid
if ($jobId) {
$grid->model()->where('job_id', $jobId);
}
$grid->header(function ($collection) use ($grid) {
$query = QuotaV1SendLog::query();
// 拿到表格筛选 where 条件数组进行遍历
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
return;
}
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
});
// 查出统计数据
$receivedAmount = (clone $query)->where('status', QuotaV1SendLog::STATUS_SUCCESS)->sum('amount');
$failedAmount = (clone $query)->where('status', QuotaV1SendLog::STATUS_FAILED)->sum('amount');
$totalAmount = (clone $query)->sum('amount');
// 自定义组件
return "<div style='padding: 10px;'>已领取:".bcdiv($receivedAmount, 100, 2).' 元 | 未领取:'.bcdiv($failedAmount, 100, 2).' 元 | 共计:'.bcdiv($totalAmount, 100, 2).' 元</div>';
});
return $grid;
}
}

View File

@ -41,25 +41,25 @@ class QuotaV1SendCommand extends Command
$walletService = new WalletService();
//依次分红
foreach ($userInfos as $userInfo) {
if ($userInfo->bonusable) {//只针对享受分红的人发放
$quotaV1amount = round(bcmul(bcdiv($job->amount, $totalQuotaV1, 5), $userInfo->quota_v1, 3));
if ($quotaV1amount >0) {
$log = new QuotaV1SendLog();
$log->user_id = $userInfo->user_id;
$log->job_id = $job->id;
$log->amount = $quotaV1amount;
$log->save();
try {
DB::beginTransaction();
$log->update(['status'=>1]);
$walletService->changeBalance($userInfo->user, $log->amount, WalletLog::ACTION_QUOTA_V1, '老配额分红', $log);
DB::commit();
} catch (Throwable $th) {
DB::rollBack();
report($th);
}
}
// if ($userInfo->bonusable) {//只针对享受分红的人发放
$quotaV1amount = round(bcmul(bcdiv($job->amount, $totalQuotaV1, 5), $userInfo->quota_v1, 3));
if ($quotaV1amount >0) {
$log = new QuotaV1SendLog();
$log->user_id = $userInfo->user_id;
$log->job_id = $job->id;
$log->amount = $quotaV1amount;
$log->save();
// try {
// DB::beginTransaction();
// $log->update(['status'=>1]);
// $walletService->changeBalance($userInfo->user, $log->amount, WalletLog::ACTION_QUOTA_V1, '老配额分红', $log);
// DB::commit();
// } catch (Throwable $th) {
// DB::rollBack();
// report($th);
// }
}
// }
}
});
}

View File

@ -23,8 +23,8 @@ class QuotaV1SendLog extends Model
];
public static $statusText = [
self::STATUS_FAILED=>'失败',
self::STATUS_SUCCESS=>'成功',
self::STATUS_FAILED=>'未领取',
self::STATUS_SUCCESS=>'已领取',
];
public function user()