Commit 60a190ca by yink

refactor: 优化订单处理和分账逻辑

- 在TransferBillsPlatForm类中添加注释,明确手动分账功能
- 格式化支付金额,确保金额精度
- 优化分账逻辑,确保手续费由平台承担
- 调整订单支付逻辑,处理多次支付情况
- 移除冗余的核销信息展示代码,优化订单详情展示
parent 829e82b3
...@@ -107,6 +107,14 @@ protected function grid() ...@@ -107,6 +107,14 @@ protected function grid()
$content .= "<strong>核销码:</strong><br/>" . '<img src="' . $domain . $this->verification_code_img . '" style="max-width:100px;max-height:100px;" />' . "<br/><br/>"; $content .= "<strong>核销码:</strong><br/>" . '<img src="' . $domain . $this->verification_code_img . '" style="max-width:100px;max-height:100px;" />' . "<br/><br/>";
} }
// 核销员信息
if ($this->verifier) {
$content .= "<strong>核销员:</strong> " . $this->verifier . "<br/><br/>";
}
if ($this->verification_at) {
$content .= "<strong>核销时间:</strong> " . $this->verification_at . "<br/><br/>";
}
$card = new Card(null, $content); $card = new Card(null, $content);
return "<div style='padding:10px 10px 0;width:100%;'>$card</div>"; return "<div style='padding:10px 10px 0;width:100%;'>$card</div>";
}); });
...@@ -131,28 +139,6 @@ protected function grid() ...@@ -131,28 +139,6 @@ protected function grid()
// 传递当前行字段值 // 传递当前行字段值
return VerifierCodeForm::make()->payload(['id' => $this->id]); return VerifierCodeForm::make()->payload(['id' => $this->id]);
}); });
$grid->column('verifier', '核销信息')->if(function ($column) {
return $column->getValue();
})->display('点击查看')->modal(function ($modal) {
//设置弹窗标题
$modal->title('核销信息');
$content = "";
if ($this->verifier) {
$content .= "核销员:" . $this->verifier . "<br/>";
}
if ($this->verification_at) {
$content .= "核销时间:" . $this->verification_at . "<br/>";
}
$card = new Card(null, $content);
return "<div style='padding:10px 10px 0;width:100%;'>$card</div>";
})->else(function ($column) {
return '';
});
$grid->column('created_at', '下单时间'); $grid->column('created_at', '下单时间');
//$grid->column('updated_at')->sortable(); //$grid->column('updated_at')->sortable();
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Request;
//手动分账给平台
class TransferBillsPlatForm extends Form implements LazyRenderable class TransferBillsPlatForm extends Form implements LazyRenderable
{ {
use LazyWidget; use LazyWidget;
......
...@@ -310,16 +310,12 @@ public function pay(Request $request) ...@@ -310,16 +310,12 @@ public function pay(Request $request)
$userObj = $request->user(); $userObj = $request->user();
$openid = $userObj->openid; $openid = $userObj->openid;
$pay_type = $request->pay_type; //支付方式 1:微信 2:积分 3:混合
if (!in_array($pay_type, [1, 2, 3])) {
return $this->JsonResponse('', '请选择支付方式', 500);
}
DB::beginTransaction(); DB::beginTransaction();
try { try {
// 订单不存在直接返回错误 // 订单不存在直接返回错误
$order = OrderInfoModel::find($order_id); $order = OrderInfoModel::find($order_id);
if (!$order) { if (!$order) {
return $this->JsonResponse('', '订单不存在', 404); return $this->JsonResponse('', '订单不存在', 404);
} }
...@@ -329,13 +325,25 @@ public function pay(Request $request) ...@@ -329,13 +325,25 @@ public function pay(Request $request)
return $this->JsonResponse('', '请勿重复支付!', 500); return $this->JsonResponse('', '请勿重复支付!', 500);
} }
if ($order->pay_cs < 20) { $pay_type = $order->pay_type;
if (!$pay_type) {
//第二次支付不用选择,从订单查询支付方式,
$pay_type = $request->pay_type; //支付方式 1:微信 2:积分 3:混合
if (!in_array($pay_type, [1, 2, 3])) {
return $this->JsonResponse('', '请选择支付方式', 500);
}
} else {
$pay_type = 4;
}
if ($order->pay_cs < 20) {//微信每次支付需要重新生成订单号
$order_record = $order->order_record ?? $order->order_sn; $order_record = $order->order_record ?? $order->order_sn;
$order->order_sn = $this->getOrderSn(); $order->order_sn = $this->getOrderSn();
$order->order_record = $order_record . "|" . $order->order_sn; $order->order_record = $order_record . "|" . $order->order_sn;
$order->pay_type = $pay_type; //订单支付方式
$order->save(); $order->save();
}else{
return $this->JsonResponse('', '支付次数达到上限!', 500);
} }
$point_amount = 0; //积分抵扣金额 $point_amount = 0; //积分抵扣金额
...@@ -343,6 +351,7 @@ public function pay(Request $request) ...@@ -343,6 +351,7 @@ public function pay(Request $request)
//判断支付方式 //判断支付方式
if ($pay_type == 1) { if ($pay_type == 1) {
$order->point_amount = $point_amount; //积分抵扣金额 $order->point_amount = $point_amount; //积分抵扣金额
$order->pay_cs += 1;
} else if ($pay_type == 2) { } else if ($pay_type == 2) {
if ($userObj->balance < $order_amount) { if ($userObj->balance < $order_amount) {
return $this->JsonResponse('', '积分不足!', 500); return $this->JsonResponse('', '积分不足!', 500);
...@@ -370,14 +379,18 @@ public function pay(Request $request) ...@@ -370,14 +379,18 @@ public function pay(Request $request)
} }
//扣除积分 //扣除积分
if (!UserPointChangeRec::pointChangeRecord($userObj->id, $userObj->balance, 0, 2, 1, $order_id)) { if (!UserPointChangeRec::pointChangeRecord($userObj->id, $userObj->balance, 0, 3, 1, $order_id)) {
return $this->JsonResponse('', '网络异常,积分抵扣失败!003', 500); return $this->JsonResponse('', '网络异常,积分抵扣失败!003', 500);
} }
$order_amount = $order_amount - $userObj->balance; $order_amount = $order_amount - $userObj->balance;
$order->point_amount = $userObj->balance; //积分抵扣金额 $order->point_amount = $userObj->balance; //积分抵扣金额
$order->order_amount = $order_amount; $order->order_amount = $order_amount;
$order->pay_cs += 1;
$order->save(); $order->save();
} else {
//微信或者混合支付第二次进来支付,不用做任何处理
Log::add('--第n次支付--', ['order_id' => $order_id, 'order_sn' => $order->order_sn]);
$order->pay_cs += 1;
} }
$res = ''; $res = '';
...@@ -386,7 +399,6 @@ public function pay(Request $request) ...@@ -386,7 +399,6 @@ public function pay(Request $request)
$order_title = $orderGoodsObj ? $orderGoodsObj->goods_name : ''; $order_title = $orderGoodsObj ? $orderGoodsObj->goods_name : '';
Log::add('--支付订单号ID--', ['order_id' => $order_id, 'order_sn' => $order->order_sn]); Log::add('--支付订单号ID--', ['order_id' => $order_id, 'order_sn' => $order->order_sn]);
$res = (new Adapay())->pay($order_title, $order->order_sn, $order_amount, $openid); $res = (new Adapay())->pay($order_title, $order->order_sn, $order_amount, $openid);
$order->pay_cs += 1;
$order->save(); $order->save();
DB::commit(); DB::commit();
...@@ -504,7 +516,7 @@ public static function canceOrderFunc($order) ...@@ -504,7 +516,7 @@ public static function canceOrderFunc($order)
$Adapay = new Adapay(); $Adapay = new Adapay();
//未支付订单--改状态直接退出 //未支付订单--改状态直接退出
if ($order->order_status == 0) { if ($order->order_status == 0) {
$order->order_status = 7; $order->order_status = 7;
$order->save(); $order->save();
...@@ -512,14 +524,14 @@ public static function canceOrderFunc($order) ...@@ -512,14 +524,14 @@ public static function canceOrderFunc($order)
//未支付直接取消 //未支付直接取消
Log::info($order->id); Log::info($order->id);
return (new self())->JsonResponse(''); return (new self())->JsonResponse('');
} }
//判断状态是否正常;订单状态 0:待付款 1:待到货 2:待领取 3: 待评价 4:已完成 7:已取消 8:已退款 //判断状态是否正常;订单状态 0:待付款 1:待到货 2:待领取 3: 待评价 4:已完成 7:已取消 8:已退款
if (!in_array($order->order_status, [1, 2,3,4]) ) { if (!in_array($order->order_status, [1, 2, 3, 4])) {
return (new self())->JsonResponse('', '订单状态不可退款!', 500); return (new self())->JsonResponse('', '订单状态不可退款!', 500);
} }
$Adapay->updateGoodsStock($order); $Adapay->updateGoodsStock($order);
...@@ -532,7 +544,7 @@ public static function canceOrderFunc($order) ...@@ -532,7 +544,7 @@ public static function canceOrderFunc($order)
$order_sn = $order->order_sn; $order_sn = $order->order_sn;
$refund_no = "R" . date("YmdHis") . rand(100000, 999999); //退单号 $refund_no = "R" . date("YmdHis") . rand(100000, 999999); //退单号
$result = $Adapay->refund($order_sn, $refund_no); $result = $Adapay->refund($order_sn, $refund_no);
Log::add('refund_result',$result); Log::add('refund_result', $result);
} }
$order->order_status = 8; //已退款 $order->order_status = 8; //已退款
...@@ -655,7 +667,6 @@ public function scanCodeVerifi(Request $request) ...@@ -655,7 +667,6 @@ public function scanCodeVerifi(Request $request)
$orderObj->save(); $orderObj->save();
Log::add('核销操作', $orderObj->toArray()); Log::add('核销操作', $orderObj->toArray());
return $this->JsonResponse(''); return $this->JsonResponse('');
} }
......
...@@ -108,11 +108,11 @@ public function info(Request $request) ...@@ -108,11 +108,11 @@ public function info(Request $request)
$balance02= $orderDivideRecord->where('is_div', 0)->sum('divide_price'); //冻结中 $balance02= $orderDivideRecord->where('is_div', 0)->sum('divide_price'); //冻结中
//已提现==分佣记录中,状态为2的 //已提现==分佣记录中,状态为2的
$cashout= $orderDivideRecord->where('is_div', 1)->sum('divide_price'); //已分账 $cashout = number_format($orderDivideRecord->where('is_div', 1)->sum('divide_price'), 4); //已分账
//冻结中=分佣记录中,状态为1的+订单状态为已支付,未分账的应该分佣金额 //冻结中=分佣记录中,状态为1的+订单状态为已支付,未分账的应该分佣金额
$balance= $balance01+ $balance02; //冻结中 $balance = number_format($balance01 + $balance02, 4); //冻结中
$total_revenue= $balance+ $cashout; //总佣金 $total_revenue = number_format($balance + $cashout, 4); //总佣金
Log::info('balance:'.$balance); Log::info('balance:'.$balance);
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
use App\Models\OrderDivideRecord; use App\Models\OrderDivideRecord;
use App\Models\OrderInfo; use App\Models\OrderInfo;
use App\Models\PaymentRecord; use App\Models\PaymentRecord;
use App\Models\User; use App\Models\StoreAdminUsers;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
...@@ -43,10 +43,13 @@ public function __construct($um_id, $delay) ...@@ -43,10 +43,13 @@ public function __construct($um_id, $delay)
public function handle() public function handle()
{ {
$payment_confirm = new \NwVVVS\AdapaySdk\PaymentConfirm(); //支付确认 $payment_confirm = new \NwVVVS\AdapaySdk\PaymentConfirm(); //支付确认
$spObj = User::find($this->um_id); $spObj = StoreAdminUsers::find($this->um_id);
$member_id = $spObj->member_id; $member_id = $spObj->member_id;
$chunkSize = 10; // 每次处理数量 $chunkSize = 10; // 每次处理数量
$orders = OrderDivideRecord::where(['um_id' => $this->um_id, 'is_div' => 0])->whereIn('sh_type', [1, 2])->orderBy('id')->take($chunkSize); $orders = OrderDivideRecord::where(['um_id' => $member_id, 'is_div' => 0])->whereIn('sh_type', [5])->orderBy('id')->take($chunkSize);
Log::add('AutoOrderDivide', ['member_id' => $member_id, 'count' => $orders->count(),'um_id' => $this->um_id]);
while ($orders->count() > 0) { while ($orders->count() > 0) {
$orders->chunk($chunkSize, function ($batch) use ($member_id, $payment_confirm) { $orders->chunk($chunkSize, function ($batch) use ($member_id, $payment_confirm) {
foreach ($batch as $item) { foreach ($batch as $item) {
...@@ -61,12 +64,17 @@ public function handle() ...@@ -61,12 +64,17 @@ public function handle()
"description" => "", "description" => "",
"div_members" => "" //分账参数列表 默认是数组List "div_members" => "" //分账参数列表 默认是数组List
); );
// 分账列表 // 分账列表-[每次分账请求,必须有且只能有一个分账方为手续费承担方]
$payment_params['div_members'] = [ $payment_params['div_members'] = [
'member_id' => $member_id, 'member_id' => $member_id,
'amount' => $item->divide_price, 'amount' => $item->divide_price,
'fee_flag' => 'N' 'fee_flag' => 'Y'
]; ];
//分账参数打印
Log::add('payment_params', $payment_params);
# 发起支付确认创建 # 发起支付确认创建
$payment_confirm->create($payment_params); $payment_confirm->create($payment_params);
# 对支付确认创建结果进行处理 # 对支付确认创建结果进行处理
...@@ -74,7 +82,7 @@ public function handle() ...@@ -74,7 +82,7 @@ public function handle()
//失败处理 //失败处理
Log::add('用户绑卡,支付确认失败', $payment_confirm->result); Log::add('用户绑卡,支付确认失败', $payment_confirm->result);
$result = $payment_confirm->result; $result = $payment_confirm->result;
//throw new Exception($result['error_msg']); //throw new Exception($result['error_msg']);//手续费承担方有且只能有一个,给平台承担
} else { } else {
//成功处理 //成功处理
Log::add('支付确认成功', $payment_confirm->result); Log::add('支付确认成功', $payment_confirm->result);
......
...@@ -38,7 +38,7 @@ public function pay($order_title, $order_sn, $order_amount, $openid) ...@@ -38,7 +38,7 @@ public function pay($order_title, $order_sn, $order_amount, $openid)
"pay_channel" => "wx_lite", "pay_channel" => "wx_lite",
"pay_mode" => "delay", "pay_mode" => "delay",
"time_expire" => date('YmdHis', time() + 300), "time_expire" => date('YmdHis', time() + 300),
"pay_amt" => $order_amount, "pay_amt" => number_format($order_amount, 2, '.', ''),
"goods_title" => $order_title, "goods_title" => $order_title,
"goods_desc" => $order_title, "goods_desc" => $order_title,
"description" => "", "description" => "",
......
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