Commit 762c96ed by yink

feat(订单分佣): 优化商户分佣记录统计逻辑和展示

- 将getCommissionAmount方法改为静态以便复用
- 重构OrderDivideRecordController中的金额计算逻辑,使用静态方法计算未分账金额
- 增加订单ID和用户手机号显示列
- 添加筛选功能和导出功能
- 优化统计信息展示样式和文案
- 注释掉UserController中未使用的头像删除代码
parent 20ab9b18
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use App\Models\Store; use App\Models\Store;
use App\Models\SystemCity; use App\Models\SystemCity;
use App\Models\UserAddress; use App\Models\UserAddress;
use App\Models\Merchant;
use Dcat\Admin\Form; use Dcat\Admin\Form;
use Dcat\Admin\Grid; use Dcat\Admin\Grid;
use Dcat\Admin\Show; use Dcat\Admin\Show;
...@@ -159,7 +160,9 @@ protected function grid() ...@@ -159,7 +160,9 @@ protected function grid()
$filter->panel(); $filter->panel();
$filter->equal('order_sn', '订单号')->width(3); $filter->equal('order_sn', '订单号')->width(3);
$filter->like('mobile', '手机号')->width(3); $filter->like('mobile', '手机号')->width(3);
$filter->like('merchant.name', '所属商家')->width(3); $filter->equal('merchant.id', '所属商家')->select(function () {
return Merchant::all()->pluck('name', 'id');
})->width(3);
//订单状态 - 修改为多选 //订单状态 - 修改为多选
$filter->in('order_status', '订单状态') $filter->in('order_status', '订单状态')
->multipleSelect(OrderInfo::STATUS_OPTIONS) ->multipleSelect(OrderInfo::STATUS_OPTIONS)
......
...@@ -249,7 +249,7 @@ public function getEmployeeUserList(Request $request) ...@@ -249,7 +249,7 @@ public function getEmployeeUserList(Request $request)
* 4. 混合支付(pay_type=2)会计算现金支付比例调整分佣金额 * 4. 混合支付(pay_type=2)会计算现金支付比例调整分佣金额
* 5. 所有金额计算保留2位小数 * 5. 所有金额计算保留2位小数
*/ */
public function getCommissionAmount($type, $obj_id) public static function getCommissionAmount($type, $obj_id)
{ {
$objUser = []; $objUser = [];
$orderObjList = []; $orderObjList = [];
......
...@@ -49,6 +49,9 @@ public function collectList(Request $request) ...@@ -49,6 +49,9 @@ public function collectList(Request $request)
$userObj = $request->user(); $userObj = $request->user();
$user_id = $userObj->id; $user_id = $userObj->id;
$merchant_id = $userObj->merchant_id; $merchant_id = $userObj->merchant_id;
$buycode = $request->buycode ?? null; //直购码,不传即原价购买
$page = $request->page ?? 1; $page = $request->page ?? 1;
$limit = $request->limit ?? 10; $limit = $request->limit ?? 10;
$sql = UserCollect::where(['uid' => $user_id, 'deleted_at' => null]); $sql = UserCollect::where(['uid' => $user_id, 'deleted_at' => null]);
...@@ -69,7 +72,9 @@ public function collectList(Request $request) ...@@ -69,7 +72,9 @@ public function collectList(Request $request)
'goods_name' => $goodObj->goods_name ?? '', 'goods_name' => $goodObj->goods_name ?? '',
'attr' => $attrRowObj ? $attrRowObj->attr_val : '', 'attr' => $attrRowObj ? $attrRowObj->attr_val : '',
'tags' => $tags, 'tags' => $tags,
'goods_price' => $merchant_id ? sprintf("%.2f", $attrRowObj->cg_price) : sprintf("%.2f", $attrRowObj->market_price), 'goods_price' => $buycode ? sprintf("%.2f", $attrRowObj->cg_price) : sprintf("%.2f", $attrRowObj->market_price),
'dg_price' => sprintf('%.2f', $attrRowObj->cg_price),
'market_price' => sprintf('%.2f', $attrRowObj->market_price),
'cover_img' => ($goodObj->cover_img ? togetherFilePath($goodObj->cover_img) : ''), 'cover_img' => ($goodObj->cover_img ? togetherFilePath($goodObj->cover_img) : ''),
'addtime' => date('Y-m-d H:i:s', strtotime($datum->created_at)) 'addtime' => date('Y-m-d H:i:s', strtotime($datum->created_at))
]; ];
......
...@@ -250,9 +250,11 @@ public function editUser(Request $request) ...@@ -250,9 +250,11 @@ public function editUser(Request $request)
$avatar = ''; $avatar = '';
} }
if ($avatar) { if ($avatar) {
if (is_file(public_path() . '/uploads' . $user->avatar)) {
unlink(public_path() . '/uploads' . $user->avatar); // if (is_file(public_path() . '/uploads' . $user->avatar)) {
} // unlink(public_path() . '/uploads' . $user->avatar);
// }
$user->avatar = $avatar ? str_replace(env('IMAGE_URL'), '', $avatar) : ''; $user->avatar = $avatar ? str_replace(env('IMAGE_URL'), '', $avatar) : '';
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
use Dcat\Admin\Widgets\Card; use Dcat\Admin\Widgets\Card;
use Dcat\Admin\Layout\Content; use Dcat\Admin\Layout\Content;
use Dcat\Admin\Widgets\Box; use Dcat\Admin\Widgets\Box;
use App\Http\Controllers\Api\StoreAdminUsersController;
class OrderDivideRecordController extends AdminController class OrderDivideRecordController extends AdminController
{ {
...@@ -24,50 +25,60 @@ class OrderDivideRecordController extends AdminController ...@@ -24,50 +25,60 @@ class OrderDivideRecordController extends AdminController
*/ */
protected function grid() protected function grid()
{ {
return Grid::make(new OrderDivideRecord(), function (Grid $grid) { return Grid::make(OrderDivideRecord::with(['users']), function (Grid $grid) {
$merchant_id = Admin::user()->merchant_id; $merchant_id = Admin::user()->merchant_id;
$total_revenue = $balance = $cashout = 0; $total_revenue = $balance = $cashout = 0;
if ($merchant_id) { if ($merchant_id) {
$merObj = Merchant::where('id', $merchant_id)->first(); $merObj = Merchant::where('id', $merchant_id)->first();
$total_revenue = $merObj->total_revenue ?? 0;
$balanceValue = $merObj->balance ?? 0; // 获取分佣记录
$orderDivideRecord = OrderDivideRecord::where(['um_id' => $merchant_id])
// 使用 Tools 类计算 T+1 未到账金额 ->select('divide_price', 'is_div', 'created_at')
$pendingCashout = Tools::calculatePendingCashout($merchant_id); ->orderBy('created_at', 'desc')
->get();
// 调整金额计算公式
$displayBalance = $balanceValue + $pendingCashout; // 使用getCommissionAmount计算未分账金额
$displayCashout = $total_revenue - $displayBalance; $balance01 = StoreAdminUsersController::getCommissionAmount(1, $merchant_id);
$balance = number_format($displayBalance, 2, '.', ''); // 计算冻结中金额(状态为0的未绑卡金额)
$cashout = number_format($displayCashout, 2, '.', ''); $balance02 = $orderDivideRecord->where('is_div', 0)->sum('divide_price');
// 计算已提现金额(状态为1的已分账金额)
$cashout = number_format($orderDivideRecord->where('is_div', 1)->sum('divide_price'), 2);
// 计算冻结中金额 = 未分账金额 + 已冻结金额
$balance = number_format($balance01 + $balance02, 2);
// 总收益 = 冻结中 + 已提现
$total_revenue = number_format($balance + $cashout, 2);
Log::add('balance金额', $balance); Log::add('balance金额', $balance);
Log::add('cashout金额', $cashout); Log::add('cashout金额', $cashout);
} }
$grid->header(function () use ($total_revenue, $balance, $cashout) { $grid->header(function () use ($total_revenue, $balance, $cashout) {
$box = new Box('统计信息', '这里可以放置统计数据'); $box = new Box('统计信息', '商户收益统计');
// 自定义统计框样式 // 自定义统计框样式
$box->style('info'); // 可选的样式:primary, info, warning, danger, success, default $box->style('info');
$content = '<div style="height: 135px;display: flex;align-items: center;text-align: center;"> $content = '<div style="height: 135px;display: flex;align-items: center;text-align: center;">
<div style="flex: 1;display: flex;flex-direction: column;border-right: 1px solid #b9c3cd;"> <div style="flex: 1;display: flex;flex-direction: column;border-right: 1px solid #b9c3cd;">
<h2 style="font-size: 25px;margin-top: 25px;">总金额(元)</h2> <h2 style="font-size: 25px;margin-top: 25px;">总收益(元)</h2>
<p style="color: orange;font-size: 45px;font-weight: bold;">' . $total_revenue . '</p> <p style="color: orange;font-size: 45px;font-weight: bold;">' . number_format($total_revenue, 2) . '</p>
</div> </div>
<div style="flex: 1;display: flex;flex-direction: column;border-right: 1px solid #b9c3cd;"> <div style="flex: 1;display: flex;flex-direction: column;border-right: 1px solid #b9c3cd;">
<h2 style="font-size: 25px;margin-top: 25px;">已提现金额(元)</h2><p style="color:#21b978;font-size: 45px;font-weight: bold;">' . $cashout . '</p> <h2 style="font-size: 25px;margin-top: 25px;">冻结中(元)</h2>
<p style="color: #3399ff;font-size: 45px;font-weight: bold;">' . $balance . '</p>
</div> </div>
<div style="flex: 1;display: flex;flex-direction: column;"> <div style="flex: 1;display: flex;flex-direction: column;">
<h2 style="font-size: 25px;margin-top: 25px;">总余额(元)</h2><p style="color: red;font-size: 45px;font-weight: bold;">' . $balance . '</p> <h2 style="font-size: 25px;margin-top: 25px;">已提现(元)</h2>
<p style="color: #21b978;font-size: 45px;font-weight: bold;">' . $cashout . '</p>
</div></div>'; </div></div>';
// 添加统计数据
$box->content( $box->content($content);
$content
);
return $box->render(); return $box->render();
}); });
$grid->addTableClass(['table-text-center']); $grid->addTableClass(['table-text-center']);
$grid->model()->where(['sh_type' => 3, 'um_id' => $merchant_id])->orderBy('created_at', 'DESC'); $grid->model()->where(['sh_type' => 3, 'um_id' => $merchant_id])->orderBy('created_at', 'DESC');
...@@ -75,9 +86,22 @@ protected function grid() ...@@ -75,9 +86,22 @@ protected function grid()
$grid->column('title', '来源名称')->display(function ($val) { $grid->column('title', '来源名称')->display(function ($val) {
return $val ?? '用户取货佣金'; return $val ?? '用户取货佣金';
}); });
$grid->column('order_id', '关联订单ID');
$grid->column('users.phone', '用户手机号');
$grid->column('divide_price', '金额'); $grid->column('divide_price', '金额');
$grid->column('created_at', '时间'); $grid->column('created_at', '时间');
// 添加筛选功能
$grid->filter(function (Grid\Filter $filter) {
$filter->panel();
$filter->equal('order_id', '订单ID')->width(3);
$filter->like('users.phone', '用户手机号')->width(3);
$filter->between('created_at', '时间范围')->datetime()->width(6);
});
// 启用导出功能
$grid->export()->filename('分佣记录-'.date('Y-m-d'));
$grid->disableDeleteButton(); $grid->disableDeleteButton();
$grid->disableViewButton(); $grid->disableViewButton();
$grid->disableCreateButton(); $grid->disableCreateButton();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment