wanghousheng 8 months ago
parent b05ef66043
commit 913524fcca
  1. 5
      app/api/controller/Order.php
  2. 19
      app/api/model/OrderRefund.php
  3. 7
      app/common/enum/order/refund/RefundType.php
  4. 64
      app/store/model/OrderRefund.php

@ -78,11 +78,6 @@ class Order extends Controller
{
// 订单详情
$model = OrderModel::getUserOrderDetail($orderId);
//自提时间
// $model->ziti_time = '2024-03-02 22:22:22';
// $model->ziti_status = 0;//0没提 1已提货
// $model->ziti_image = ['https://www.saas.njrenzhou.com/uploads/10001/20240116/18adc22ad9ea021ab2586878fe1035b0.png'];
return $this->renderSuccess([
'order' => $model, // 订单详情
'setting' => [

@ -12,13 +12,12 @@ declare (strict_types=1);
namespace app\api\model;
use app\api\service\User as UserService;
use app\api\model\OrderGoods as OrderGoodsModel;
use app\common\enum\order\PayStatus;
use app\common\model\OrderRefund as OrderRefundModel;
use app\common\enum\order\refund\RefundType as RefundTypeEnum;
use app\api\service\User as UserService;
use app\common\enum\order\refund\AuditStatus as AuditStatusEnum;
use app\common\enum\order\refund\RefundStatus as RefundStatusEnum;
use app\common\enum\order\refund\RefundType as RefundTypeEnum;
use app\common\model\OrderRefund as OrderRefundModel;
use cores\exception\BaseException;
/**
@ -55,7 +54,7 @@ class OrderRefund extends OrderRefundModel
{
// 已完成
if ($data['status'] == RefundStatusEnum::COMPLETED) {
$text = [RefundTypeEnum::RETURN => '已同意退货并已退款', RefundTypeEnum::EXCHANGE => '已同意换货'];
$text = [RefundTypeEnum::RETURN => '已同意退货并已退款', RefundTypeEnum::EXCHANGE => '已同意换货', RefundTypeEnum::RETURNPRICE => '已同意退款'];
return $text[$data['type']];
}
// 已取消
@ -65,7 +64,13 @@ class OrderRefund extends OrderRefundModel
// 已拒绝
if ($data['status'] == RefundStatusEnum::REJECTED) {
// return '已拒绝';
return $data['type'] == RefundTypeEnum::RETURN ? '已拒绝退货退款' : '已拒绝换货';
if ($data['type'] == RefundTypeEnum::RETURN) {
return '已拒绝退货退款';
} elseif ($data['type'] == RefundTypeEnum::EXCHANGE) {
return '已拒绝换货';
} else {
return '已拒绝退款';
}
}
// 进行中
if ($data['status'] == RefundStatusEnum::NORMAL) {
@ -209,7 +214,7 @@ class OrderRefund extends OrderRefundModel
]);
// 记录凭证图片关系
if (isset($data['images']) && !empty($data['images'])) {
$this->saveImages((int)$this['order_refund_id'], explode(",",$data['images']));
$this->saveImages((int)$this['order_refund_id'], explode(",", $data['images']));
}
return true;
});

@ -27,6 +27,9 @@ class RefundType extends EnumBasics
// 换货
const EXCHANGE = 20;
//退款
const RETURNPRICE = 30;
/**
* 获取枚举数据
* @return array
@ -41,6 +44,10 @@ class RefundType extends EnumBasics
self::EXCHANGE => [
'name' => '换货',
'value' => self::EXCHANGE
],
self::RETURNPRICE => [
'name' => '退款',
'value' => self::RETURNPRICE
]
];
}

@ -13,16 +13,15 @@ declare (strict_types=1);
namespace app\store\model;
use app\api\service\User as UserService;
use app\common\enum\dealer\withdraw\PayType;
use app\common\enum\order\DeliveryType;
use app\common\enum\payment\Method;
use app\store\model\User as UserModel;
use app\common\model\OrderRefund as OrderRefundModel;
use app\common\enum\order\refund\RefundType as RefundTypeEnum;
use app\common\enum\order\refund\AuditStatus as AuditStatusEnum;
use app\common\enum\order\refund\RefundStatus as RefundStatusEnum;
use app\common\enum\order\refund\RefundType as RefundTypeEnum;
use app\common\enum\payment\Method;
use app\common\model\OrderRefund as OrderRefundModel;
use app\common\service\Message as MessageService;
use app\common\service\order\Refund as RefundService;
use app\store\model\User as UserModel;
/**
* 售后单模型
@ -55,7 +54,7 @@ class OrderRefund extends OrderRefundModel
->join('order', 'order.order_id = refund.order_id')
->join('user', 'user.user_id = order.user_id')
->where($filter);
if(!empty($filterOr)){
if (!empty($filterOr)) {
$query = $query->whereOr($filterOr);
}
$list = $query->order(['refund.create_time' => 'desc', 'refund.' . $this->getPk()])
@ -74,12 +73,12 @@ class OrderRefund extends OrderRefundModel
// 检索查询条件
$filter = $this->getFilter($param);
//不是店长查询当前用户订单
if(!UserService::isStore()) {
$filter[] = ['user.user_id' ,'=', UserService::getCurrentLoginUserId() ];
}
if (!UserService::isStore()) {
$filter[] = ['user.user_id', '=', UserService::getCurrentLoginUserId()];
}
//普通会员和plus会员查询条件
if (!empty($param['user_id'])) {
$filter[] = ['user.user_id' ,'=', $param['user_id']];
$filter[] = ['user.user_id', '=', $param['user_id']];
}
if (!empty($param['delivery_type'])) {
$filter[] = ['order.delivery_type', '=', DeliveryType::EXPRESS];
@ -104,14 +103,14 @@ class OrderRefund extends OrderRefundModel
->join('order', 'order.order_id = refund.order_id')
->join('user', 'user.user_id = order.user_id')
->where($filter);
if(!empty($filterOr)){
if (!empty($filterOr)) {
// $query = $query->whereOr($filterOr);
$query = $query->where($filterOr);
}
$list = $query->order(['refund.create_time' => 'desc', 'refund.' . $this->getPk()])
->paginate(10);
// 加载关联订单数据
$list = static::preload($list, ['goods.image', 'orderData', 'user.avatar','images.file'], true);
$list = static::preload($list, ['goods.image', 'orderData', 'user.avatar', 'images.file'], true);
foreach ($list['data'] as $key => $row) {
$row['orderData']['pay_method_text'] = Method::data()[$row['orderData']['pay_method']]['name'];//支付方式
$row['orderData']['delivery_type_text'] = DeliveryType::data()[$row['orderData']['delivery_type']]['name'];//配送方式
@ -188,10 +187,14 @@ class OrderRefund extends OrderRefundModel
$this->error = '请输入拒绝原因';
return false;
}
if ($data['audit_status'] == AuditStatusEnum::REVIEWED && empty($data['address_id'])) {
if ($data['audit_status'] == AuditStatusEnum::REVIEWED && empty($data['address_id']) && $this['type'] == RefundTypeEnum::RETURN) {
$this->error = '请选择退货地址';
return false;
}
//如果只是退款
if ($data['audit_status'] == AuditStatusEnum::REVIEWED && $this['type'] == RefundTypeEnum::RETURNPRICE) {
return $this->returnPrice($data);
}
$this->transaction(function () use ($data) {
// 拒绝申请, 标记售后单状态为已拒绝
$data['audit_status'] == AuditStatusEnum::REJECTED && $data['status'] = RefundStatusEnum::REJECTED;
@ -214,6 +217,41 @@ class OrderRefund extends OrderRefundModel
return true;
}
public function returnPrice(array $data): bool
{
// 订单详情
$order = Order::detail($this['order_id']);
if ($data['refund_money'] > min($order['pay_price'], $this['orderGoods']['total_pay_price'])) {
$this->error = '退款金额不能大于商品实付款金额';
return false;
}
// 事务处理
$this->transaction(function () use ($order, $data) {
// 执行退款操作
if (!(new RefundService)->handle($order, (string)$data['refund_money'])) {
throwError('执行订单退款失败');
}
// 更新售后单状态
$this->save([
'refund_money' => $data['refund_money'],
'is_receipt' => 1,
'audit_status' => AuditStatusEnum::REVIEWED,
'status' => RefundStatusEnum::COMPLETED
]);
// 消减用户的实际消费金额
// 条件:判断订单是否已结算
if ($order['is_settled']) {
(new UserModel)->setDecUserExpend($order['user_id'], $data['refund_money']);
}
// 发送消息通知
MessageService::send('order.refund', [
'refund' => $this, // 售后单信息
'order_no' => $order['order_no'], // 订单信息
], $this['store_id']);
});
return true;
}
/**
* 确认收货并退款
* @param array $data

Loading…
Cancel
Save