diff --git a/app/Admin/Forms/AfterSaleVerify.php b/app/Admin/Forms/AfterSaleVerify.php index 4f4740ac..7730724f 100644 --- a/app/Admin/Forms/AfterSaleVerify.php +++ b/app/Admin/Forms/AfterSaleVerify.php @@ -2,11 +2,13 @@ namespace App\Admin\Forms; +use App\Exceptions\BizException; use App\Models\AfterSale; use App\Services\AfterSaleService; use Dcat\Admin\Contracts\LazyRenderable; use Dcat\Admin\Traits\LazyWidget; use Dcat\Admin\Widgets\Form; +use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; use Throwable; @@ -40,6 +42,10 @@ class AfterSaleVerify extends Form implements LazyRenderable DB::beginTransaction(); $afterSale = AfterSale::where('state', AfterSale::STATE_VERIFY)->findOrFail($this->payload['id']); if ($input['state'] == 3) {//审核通过 + $amount = Arr::get($input, 'amount', 0); + if ($amount > $afterSale->orderProduct->total_amount) { + throw new BizException('退款金额不能大于商品实付金额'); + } $afterSaleService->verify($afterSale, $input['remarks3'], (int) $input['amount']); } elseif ($input['state'] == 1) {//需要补充资料 $afterSaleService->backApply($afterSale, $input['remarks1']); diff --git a/app/Services/AfterSaleService.php b/app/Services/AfterSaleService.php index ea76249d..440d8d8f 100644 --- a/app/Services/AfterSaleService.php +++ b/app/Services/AfterSaleService.php @@ -329,22 +329,23 @@ class AfterSaleService if ($this->isWaitFinance($afterSale)) { $order = $afterSale->order; if (in_array($afterSale->type, [AfterSale::TYPE_REFUND_AND_RETURN, AfterSale::TYPE_REFUND])) { - //todo-执行实际退款操作; - $order->refundLogs()->create([ - 'sn' => OrderHelper::serialNumber(), - 'amount' => $afterSale->amount, - 'reason' => '取消订单', - ]); + //执行实际退款操作; + if ($afterSale->amount > 0) {//退款金额大于0才做实际退款 + $order->refundLogs()->create([ + 'sn' => OrderHelper::serialNumber(), + 'amount' => $afterSale->amount, + 'reason' => '售后退款', + ]); + } } elseif (in_array($afterSale->type, [AfterSale::TYPE_CHANGE])) {//换货流程 - //todo -- 换货单的分润记录; //复制一个订单(存商品价格,支付价格为0;) $changeOrder = new Order(); $changeOrder->user_id = $order->user_id; $changeOrder->sn = OrderHelper::serialNumber(); - $changeOrder->products_total_amount = $afterSale->amount; + $changeOrder->products_total_amount = bcmul($afterSale->orderProduct->sell_price, $afterSale->num); $changeOrder->coupon_discount_amount = 0; - $changeOrder->vip_discount_amount = 0; + $changeOrder->vip_discount_amount = bcmul(($afterSale->orderProduct->sell_price-$afterSale->orderProduct->vip_price), $afterSale->num); $changeOrder->reduced_amount = 0; $changeOrder->shipping_fee = 0; $changeOrder->total_amount = 0; @@ -370,7 +371,7 @@ class AfterSaleService 'vip_price' => $afterSale->orderProduct->vip_price, 'quantity' => $afterSale->num, 'coupon_discount_amount'=> 0, - 'vip_discount_amount' => 0, + 'vip_discount_amount' => $afterSale->orderProduct->sell_price - $afterSale->orderProduct->vip_price, 'reduced_amount' => 0, 'total_amount' => $afterSale->amount, ]);