feat(dashboard): 从专业财富观角度重构升级后台收益与分成统计仪表盘
这个提交包含在:
@@ -51,11 +51,30 @@ class Daily extends Common
|
||||
->whereBetween('createtime', [$yStart, $yEnd])
|
||||
->whereIn('reward_type', \addons\shopro\service\partner\PartnerConfig::instantTypes())
|
||||
->sum('amount');
|
||||
|
||||
$yesterdayReport = DailyReport::where('settle_date', $yesterday)->find();
|
||||
$yesterdayGmv = $yesterdayReport ? (float) $yesterdayReport->gmv : 0;
|
||||
$yesterdayTotalCash = $sumCash($yesterday) + $instantYesterday;
|
||||
$yesterdayPayoutRatio = $yesterdayGmv > 0 ? round(($yesterdayTotalCash / $yesterdayGmv) * 100, 2) : 0;
|
||||
|
||||
$voucherTotal = (float) \app\admin\model\shopro\partner\VoucherPlan::where('status', 1)->sum('total_amount');
|
||||
$voucherReleased = (float) \app\admin\model\shopro\partner\VoucherPlan::where('status', 1)->sum('released_amount');
|
||||
$voucherDebt = max(0, $voucherTotal - $voucherReleased);
|
||||
|
||||
$activeService = new \addons\shopro\service\partner\ActiveService();
|
||||
$venueActiveCount = count($activeService->activeUserIds($since, time(), ['is_venue' => 1]));
|
||||
$countyActiveCount = count($activeService->activeUserIds($since, time(), ['is_county' => 1]));
|
||||
|
||||
$result['kpi'] = [
|
||||
'today' => DailyReport::where('settle_date', $today)->find(),
|
||||
'yesterday' => DailyReport::where('settle_date', $yesterday)->find(),
|
||||
'yesterday' => $yesterdayReport,
|
||||
'today_cash' => number_format($todayCash + $instantToday, 2, '.', ''),
|
||||
'yesterday_cash' => number_format($sumCash($yesterday) + $instantYesterday, 2, '.', ''),
|
||||
'yesterday_cash' => number_format($yesterdayTotalCash, 2, '.', ''),
|
||||
'yesterday_payout_ratio' => $yesterdayPayoutRatio . '%',
|
||||
'yesterday_payout_ratio_val' => $yesterdayPayoutRatio,
|
||||
'voucher_debt' => number_format($voucherDebt, 2, '.', ''),
|
||||
'venue_active_count' => $venueActiveCount,
|
||||
'county_active_count' => $countyActiveCount,
|
||||
'inactive_count' => \app\admin\model\shopro\commission\Agent::where(function ($q) use ($since) {
|
||||
$q->whereNull('last_self_order_time')->whereOr('last_self_order_time', '<', $since);
|
||||
})->count(),
|
||||
@@ -63,6 +82,13 @@ class Daily extends Common
|
||||
$this->success('获取成功', null, $result);
|
||||
}
|
||||
|
||||
public function preview()
|
||||
{
|
||||
$date = $this->request->param('settle_date', date('Y-m-d', strtotime('-1 day')));
|
||||
$data = (new DailySettleService())->preview($date);
|
||||
$this->success('试算成功', null, $data);
|
||||
}
|
||||
|
||||
public function rerun()
|
||||
{
|
||||
$date = $this->request->param('settle_date');
|
||||
|
||||
@@ -92,7 +92,20 @@ class Reward extends Common
|
||||
$totalAmount += array_sum(array_column($newDatas, 'amount'));
|
||||
$totalMadow += array_sum(array_column($newDatas, 'madow'));
|
||||
if ($pages['is_last_page']) {
|
||||
$newDatas[] = ['id' => "总数:{$total};金额:{$totalAmount};马豆:{$totalMadow}"];
|
||||
$newDatas[] = [
|
||||
'id' => '财务合计',
|
||||
'createtime' => '-',
|
||||
'user_nickname' => "共 {$total} 笔流水",
|
||||
'buyer_nickname' => '-',
|
||||
'order_id' => '-',
|
||||
'reward_type_text' => '-',
|
||||
'role_text' => '-',
|
||||
'amount' => number_format($totalAmount, 2, '.', ''),
|
||||
'madow' => number_format($totalMadow, 8, '.', ''),
|
||||
'base_amount' => '-',
|
||||
'status_text' => '已汇总',
|
||||
'formula' => "总现金: {$totalAmount}, 总马豆: {$totalMadow}",
|
||||
];
|
||||
}
|
||||
return $newDatas;
|
||||
});
|
||||
@@ -109,6 +122,9 @@ class Reward extends Common
|
||||
if ($amount == 0) {
|
||||
$this->error('请输入金额');
|
||||
}
|
||||
if ($amount > 10000) {
|
||||
$this->error('单笔补发金额不能超过 10,000 元(财务风控限制)');
|
||||
}
|
||||
Db::transaction(function () use ($params, $amount) {
|
||||
$row = PartnerRewardService::write([
|
||||
'order_id' => intval($params['order_id'] ?? 0) ?: -time(),
|
||||
@@ -167,4 +183,79 @@ class Reward extends Common
|
||||
(new PartnerRewardService())->refund($orderId);
|
||||
$this->success('整单已退回');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单整单利益分配透视(财务与客服一键对账)
|
||||
*/
|
||||
public function orderTree()
|
||||
{
|
||||
$orderId = intval($this->request->param('order_id'));
|
||||
if ($orderId <= 0) {
|
||||
$this->error('订单ID不合法');
|
||||
}
|
||||
|
||||
$order = \app\admin\model\shopro\order\Order::with(['user'])->where('id', $orderId)->find();
|
||||
if (!$order) {
|
||||
$this->error('订单不存在');
|
||||
}
|
||||
|
||||
$rewards = $this->model->with(['user', 'buyer'])
|
||||
->where('order_id', $orderId)
|
||||
->order('id', 'asc')
|
||||
->select();
|
||||
|
||||
$rows = [];
|
||||
$totalCash = 0;
|
||||
$totalMadow = 0;
|
||||
foreach ($rewards as $r) {
|
||||
$rows[] = [
|
||||
'id' => $r->id,
|
||||
'reward_type' => $r->reward_type,
|
||||
'reward_type_text' => $r->reward_type_text,
|
||||
'user_id' => $r->user_id,
|
||||
'user_nickname' => $r->user ? ($r->user->nickname ?: $r->user->mobile) : '平台/买家',
|
||||
'role_text' => $r->role_text ?: $r->role,
|
||||
'amount' => $r->amount,
|
||||
'madow' => $r->madow,
|
||||
'base_amount' => $r->base_amount,
|
||||
'status' => $r->status,
|
||||
'status_text' => $r->status_text,
|
||||
'formula' => $r->formula,
|
||||
'createtime' => $r->createtime,
|
||||
];
|
||||
if ($r->status == 1) {
|
||||
if (in_array($r->reward_type, PartnerConfig::instantTypes())) {
|
||||
$totalCash = bcadd((string)$totalCash, (string)$r->amount, 2);
|
||||
}
|
||||
$totalMadow = bcadd((string)$totalMadow, (string)$r->madow, 8);
|
||||
}
|
||||
}
|
||||
|
||||
$voucherPlan = \app\admin\model\shopro\partner\VoucherPlan::where('order_id', $orderId)->find();
|
||||
$payFee = floatval($order->pay_fee);
|
||||
$payoutRatio = $payFee > 0 ? round(($totalCash / $payFee) * 100, 2) : 0;
|
||||
|
||||
$this->success('获取成功', null, [
|
||||
'order' => [
|
||||
'id' => $order->id,
|
||||
'order_sn' => $order->order_sn,
|
||||
'pay_fee' => $order->pay_fee,
|
||||
'status_text' => $order->status_text,
|
||||
'paid_time' => $order->paid_time ? date('Y-m-d H:i:s', $order->paid_time) : '-',
|
||||
'buyer_nickname' => $order->user ? ($order->user->nickname ?: $order->user->mobile) : '',
|
||||
],
|
||||
'rewards' => $rows,
|
||||
'summary' => [
|
||||
'total_cash' => number_format($totalCash, 2, '.', ''),
|
||||
'total_madow' => number_format($totalMadow, 8, '.', ''),
|
||||
'payout_ratio' => $payoutRatio . '%',
|
||||
],
|
||||
'voucher_plan' => $voucherPlan ? [
|
||||
'total_amount' => $voucherPlan->total_amount,
|
||||
'released_amount' => $voucherPlan->released_amount,
|
||||
'released_days' => $voucherPlan->released_days,
|
||||
'status_text' => $voucherPlan->status_text,
|
||||
] : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户