调整订单退款

This commit is contained in:
lewis 2025-01-06 17:41:34 +08:00
parent df13985929
commit 429e02120c
3 changed files with 9 additions and 6 deletions

View File

@ -21,6 +21,7 @@ use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product\WarehouseProduct;
use app\common\service\RefundOrderService;
use app\common\service\xlsx\Beforehand; use app\common\service\xlsx\Beforehand;
use app\common\service\xlsx\OrderDetail; use app\common\service\xlsx\OrderDetail;
use support\exception\BusinessException; use support\exception\BusinessException;
@ -124,17 +125,16 @@ class StoreOrderController extends BaseAdminController
* @return \support\Response * @return \support\Response
* @throws \Exception * @throws \Exception
*/ */
public function refund() public function refund(RefundOrderService $refundOrderService)
{ {
$params = $this->request->post(); $params = $this->request->post();
$detail = StoreOrder::where('order_id', $params['order_id'])->findOrEmpty(); $detail = StoreOrder::where('order_id', $params['order_id'])->findOrEmpty();
if (empty($detail)) { if (empty($detail)) {
return $this->fail('无该订单请检查'); return $this->fail('无该订单请检查');
} }
$res = StoreOrderLogic::refund($detail, $params); $params['id'] = $detail['id'];
if ($res == false) { $params['old_cart_id'] = StoreOrderCartInfo::where('oid', $detail['id'])->column('id');
return $this->fail('退款失败'); $refundOrderService->refund($detail['uid'], $params);
}
return $this->success('退款成功',[],1,1); return $this->success('退款成功',[],1,1);
} }

View File

@ -129,7 +129,7 @@ class StoreOrder extends BaseModel
public function allowRefund(): bool public function allowRefund(): bool
{ {
if (in_array($this->status, [0, 1]) && $this->paid == 1) { if (in_array($this->status, [0, 1, 2])) {
return true; return true;
} }
return false; return false;

View File

@ -31,6 +31,9 @@ class RefundOrderService
if (empty($order)) { if (empty($order)) {
throw new BusinessException('订单不存在'); throw new BusinessException('订单不存在');
} }
if (!$order->allowRefund()) {
throw new BusinessException('订单不能退款');
}
$orderCartProducts = StoreOrderCartInfo::where('oid', $order['id'])->whereIn('id', $params['old_cart_id'])->select(); $orderCartProducts = StoreOrderCartInfo::where('oid', $order['id'])->whereIn('id', $params['old_cart_id'])->select();
if ($order->status == 2 && $order->is_writeoff == 1) { if ($order->status == 2 && $order->is_writeoff == 1) {
$this->refundStoreMoney($order); $this->refundStoreMoney($order);