diff --git a/app/api/model/OrderRefund.php b/app/api/model/OrderRefund.php index 48278f5d..7f66095f 100644 --- a/app/api/model/OrderRefund.php +++ b/app/api/model/OrderRefund.php @@ -153,7 +153,10 @@ class OrderRefund extends OrderRefundModel { $goods = OrderGoodsModel::detail($orderGoodsId); if (isset($goods['refund']) && !empty($goods['refund'])) { - throwError('当前商品已申请售后'); + //是否已经同意 + if (!empty($goods['refund']['audit_status']) == AuditStatusEnum::REVIEWED) { + throwError('当前商品已申请售后'); + } } return $goods; } @@ -200,6 +203,28 @@ class OrderRefund extends OrderRefundModel { // 订单商品详情 $goods = $this->getRefundGoods($orderGoodsId); + if (!empty($goods['refund']) && !empty($goods['refund']['audit_status']) != AuditStatusEnum::REVIEWED) { + if (empty($goods['refund']['order_refund_id'])) { + throwError('当前记录数据异常'); + } + return $this->transaction(function () use ($orderGoodsId, $data, $goods) { + $order_refund_id = $goods['refund']['order_refund_id']; + // //更新售后单记录 + $this->where(['order_refund_id' => $order_refund_id])->update([ + 'type' => $data['type'], + 'apply_desc' => $data['content'], + 'audit_status' => AuditStatusEnum::WAIT, + 'status' => 0, + 'store_id' => self::$storeId + ]); + // 记录凭证图片关系 + if (!empty($data['images'])) { + (new OrderRefundImage)->where(['order_refund_id' => $order_refund_id])->delete(); + $this->saveImages((int)$this['order_refund_id'], explode(",", $data['images'])); + } + return true; + }); + } return $this->transaction(function () use ($orderGoodsId, $data, $goods) { // 新增售后单记录 $this->save([ @@ -213,7 +238,7 @@ class OrderRefund extends OrderRefundModel 'store_id' => self::$storeId ]); // 记录凭证图片关系 - if (isset($data['images']) && !empty($data['images'])) { + if (!empty($data['images'])) { $this->saveImages((int)$this['order_refund_id'], explode(",", $data['images'])); } return true;