|
|
|
@ -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 |
|
|
|
|