@@ -180,9 +180,140 @@ class Order extends Common
|
||||
// 处理未支付订单 item status_code
|
||||
$order = $order->setOrderItemStatusByOrder($order);
|
||||
|
||||
$order->partner_split = $this->buildPartnerSplit($order);
|
||||
|
||||
$this->success('获取成功', null, $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 合伙股东分成明细:即时奖列人;均分只汇总人数/人均
|
||||
*/
|
||||
protected function buildPartnerSplit($order)
|
||||
{
|
||||
$orderId = intval($order->id ?? 0);
|
||||
$shareTypes = ['venue_share', 'county_share', 'madow_share'];
|
||||
$items = [];
|
||||
$totalCash = 0;
|
||||
|
||||
$rows = \app\admin\model\shopro\partner\Reward::with(['user'])
|
||||
->where('order_id', $orderId)
|
||||
->order('id', 'asc')
|
||||
->select();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$type = (string) ($row->reward_type ?? '');
|
||||
if (in_array($type, $shareTypes, true)) {
|
||||
continue;
|
||||
}
|
||||
$amount = round((float) $row->amount, 2);
|
||||
$madow = (float) ($row->madow ?? 0);
|
||||
if (intval($row->status) === 1 && $amount > 0) {
|
||||
$totalCash = round($totalCash + $amount, 2);
|
||||
}
|
||||
$items[] = [
|
||||
'display' => 'user',
|
||||
'id' => intval($row->id),
|
||||
'reward_type' => $type,
|
||||
'reward_type_text' => $row->reward_type_text,
|
||||
'role_text' => $row->role_text ?? '',
|
||||
'user_id' => intval($row->user_id),
|
||||
'user' => $row->user,
|
||||
'amount' => number_format($amount, 2, '.', ''),
|
||||
'madow' => \addons\shopro\service\partner\IdentityService::formatMadow($madow),
|
||||
'status' => intval($row->status),
|
||||
'status_text' => $row->status_text,
|
||||
'formula' => $row->formula,
|
||||
'skip_reason_text' => $row->skip_reason_text,
|
||||
];
|
||||
}
|
||||
|
||||
$settleDate = null;
|
||||
$paidRaw = $order->getData('paid_time') ?? ($order['paid_time'] ?? null);
|
||||
if ($paidRaw) {
|
||||
$paidTs = is_numeric($paidRaw) ? intval($paidRaw) : strtotime((string) $paidRaw);
|
||||
if ($paidTs > 0) {
|
||||
$settleDate = date('Y-m-d', $paidTs);
|
||||
}
|
||||
}
|
||||
|
||||
if ($settleDate) {
|
||||
foreach ($shareTypes as $type) {
|
||||
$shareRows = \app\admin\model\shopro\partner\Reward::where('settle_date', $settleDate)
|
||||
->where('reward_type', $type)
|
||||
->where('status', 1)
|
||||
->where('user_id', '>', 0)
|
||||
->select();
|
||||
$userCount = count($shareRows);
|
||||
if ($userCount <= 0) {
|
||||
// 分母为 0 进平台的记录
|
||||
$platform = \app\admin\model\shopro\partner\Reward::where('settle_date', $settleDate)
|
||||
->where('reward_type', $type)
|
||||
->where('status', 1)
|
||||
->where('user_id', 0)
|
||||
->find();
|
||||
if (!$platform) {
|
||||
continue;
|
||||
}
|
||||
$items[] = [
|
||||
'display' => 'share',
|
||||
'reward_type' => $type,
|
||||
'reward_type_text' => \addons\shopro\service\partner\PartnerConfig::rewardTypeText($type),
|
||||
'user_count' => 0,
|
||||
'each_amount' => '0.00',
|
||||
'each_madow' => '0.00000000',
|
||||
'total_amount' => number_format((float) $platform->amount, 2, '.', ''),
|
||||
'total_madow' => \addons\shopro\service\partner\IdentityService::formatMadow($platform->madow ?? 0),
|
||||
'settle_date' => $settleDate,
|
||||
'status_text' => '已入账',
|
||||
'unit' => $type === 'madow_share' ? '马豆' : '元',
|
||||
'formula' => $platform->formula,
|
||||
'tip' => '付款日日结均分:当日无人参与,奖池进平台',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$totalAmount = 0;
|
||||
$totalMadow = 0;
|
||||
foreach ($shareRows as $sr) {
|
||||
$totalAmount = round($totalAmount + (float) $sr->amount, 2);
|
||||
$totalMadow = function_exists('bcadd')
|
||||
? (float) bcadd((string) $totalMadow, (string) ($sr->madow ?? 0), 8)
|
||||
: ($totalMadow + (float) ($sr->madow ?? 0));
|
||||
}
|
||||
$first = $shareRows[0];
|
||||
$eachAmount = number_format((float) $first->amount, 2, '.', '');
|
||||
$eachMadow = \addons\shopro\service\partner\IdentityService::formatMadow($first->madow ?? 0);
|
||||
$ext = is_array($first->ext) ? $first->ext : [];
|
||||
if (!empty($ext['share_user_count'])) {
|
||||
$userCount = intval($ext['share_user_count']);
|
||||
}
|
||||
|
||||
$items[] = [
|
||||
'display' => 'share',
|
||||
'reward_type' => $type,
|
||||
'reward_type_text' => \addons\shopro\service\partner\PartnerConfig::rewardTypeText($type),
|
||||
'user_count' => $userCount,
|
||||
'each_amount' => $eachAmount,
|
||||
'each_madow' => $eachMadow,
|
||||
'total_amount' => number_format($totalAmount, 2, '.', ''),
|
||||
'total_madow' => \addons\shopro\service\partner\IdentityService::formatMadow($totalMadow),
|
||||
'settle_date' => $settleDate,
|
||||
'status_text' => '已入账',
|
||||
'unit' => $type === 'madow_share' ? '马豆' : '元',
|
||||
'formula' => $first->formula,
|
||||
'tip' => '付款日日结均分(不列出参与用户名单)',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'items' => $items,
|
||||
'total_cash' => number_format($totalCash, 2, '.', ''),
|
||||
'settle_date' => $settleDate,
|
||||
'has_data' => count($items) > 0,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量发货渲染模板
|
||||
|
||||
在新工单中引用
屏蔽一个用户