订单退款,退购物卡和抵扣券
This commit is contained in:
parent
4b4d52c1f2
commit
df2bdc1f1b
@ -207,7 +207,8 @@ class StoreCouponUserDao extends BaseDao
|
||||
if (!$storeCouponUser->save()) {
|
||||
throw new ValidateException('优惠券余额更新出错');
|
||||
}
|
||||
StoreCouponDetail::expend($order, $id, $amount);
|
||||
$mark = '订单支付,使用' . $storeCouponUser->coupon_title;
|
||||
StoreCouponDetail::expend($order, $id, $amount, $mark);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,9 +47,10 @@ class StoreCouponDetail extends BaseModel
|
||||
* @param $order
|
||||
* @param $id
|
||||
* @param $amount
|
||||
* @param $mark
|
||||
* @return void
|
||||
*/
|
||||
public static function expend($order, $id, $amount)
|
||||
public static function expend($order, $id, $amount, $mark)
|
||||
{
|
||||
$detailModel = new self();
|
||||
$detailModel->uid = $order['uid'];
|
||||
@ -59,6 +60,7 @@ class StoreCouponDetail extends BaseModel
|
||||
$detailModel->type = StoreCouponDetail::TYPE_EXPEND;
|
||||
$detailModel->amount = $amount;
|
||||
$detailModel->pay_price = $order['pay_price'];
|
||||
$detailModel->mark = $mark;
|
||||
$detailModel->create_time = time();
|
||||
$detailModel->save();
|
||||
}
|
||||
|
@ -37,6 +37,11 @@ class StoreOrderProduct extends BaseModel
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
public function getCouponInfoAttr($value)
|
||||
{
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
public function orderInfo()
|
||||
{
|
||||
return $this->hasOne(StoreOrder::class, 'order_id', 'order_id');
|
||||
|
@ -394,7 +394,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
[$payPrice, $useAmount, $couponUsed] = $storeCouponUserDao->couponByProduct($coupon['coupon_type']);
|
||||
$coupon_price = bcadd($coupon_price, $useAmount, 2);
|
||||
$_pay_price = bcsub($_pay_price, $useAmount, 2);
|
||||
$cartCoupon[$cart['cart_id']] = ['coupon_price' => $useAmount, 'true_price' => $payPrice];
|
||||
$cartCoupon[$cart['cart_id']] = ['coupon_price' => $useAmount, 'coupon_user_id' => $coupon['coupon_user_id'], 'cart_id' => $cart['cart_id'], 'true_price' => $payPrice];
|
||||
if (!isset($userUsedCoupon[$coupon['coupon_user_id']])) {
|
||||
$userUsedCoupon[$coupon['coupon_user_id']] = ['coupon_user_id' => $coupon['coupon_user_id'], 'coupon_price' => $useAmount];
|
||||
} else {
|
||||
@ -544,6 +544,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
|
||||
//计算平台券优惠金额
|
||||
// if ($total_true_price > 0) {
|
||||
$cartCoupon = array_values($cartCoupon);
|
||||
$StoreCouponUser = app()->make(StoreCouponUserRepository::class);
|
||||
$platformCoupon = $StoreCouponUser->validUserPlatformCoupon($uid);
|
||||
if ($enabledPlatformCoupon && count($platformCoupon)) {
|
||||
@ -680,6 +681,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
} else {
|
||||
$couponPrice = min(max(0.01, bcmul($_coupon_price, bcdiv($cart['true_price'], $platformCouponRate['price'], 6), 2)), $cart['true_price']);
|
||||
}
|
||||
$cartCoupon[] = ['coupon_price' => $couponPrice, 'coupon_user_id' => $platformCouponRate['id'], 'cart_id' => $cart['cart_id']];
|
||||
$platformCouponRate['coupon_price'] = bcsub($platformCouponRate['coupon_price'], $couponPrice, 2);
|
||||
$cart['true_price'] = bcsub($cart['true_price'], $couponPrice, 2);
|
||||
$cart['platform_coupon_price'] = $couponPrice;
|
||||
@ -867,7 +869,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
'useIntegral',
|
||||
'key',
|
||||
'order_refund_switch',
|
||||
'order'
|
||||
'order',
|
||||
'cartCoupon'
|
||||
) + ['allow_address' => !$allow_no_address, 'order_delivery_status' => $orderDeliveryStatus];
|
||||
Cache::set('order_create_cache' . $uid . '_' . $key, $data, 600);
|
||||
return $data;
|
||||
@ -1203,6 +1206,12 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
|
||||
$orderProduct = [];
|
||||
$orderStatus = [];
|
||||
$cartCouponPrice = [];
|
||||
foreach ($orderInfo['cartCoupon'] as $item) {
|
||||
$cartId = $item['cart_id'];
|
||||
unset($item['true_price'], $item['cart_id']);
|
||||
$cartCouponPrice[$cartId][] = $item;
|
||||
}
|
||||
foreach ($orderList as $order) {
|
||||
$cartInfo = $order['cartInfo'];
|
||||
unset($order['cartInfo']);
|
||||
@ -1324,6 +1333,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
'product_type' => $cart['product_type'],
|
||||
'cart_info' => json_encode($order_cart),
|
||||
'refund_switch' => $cart['refund_switch'],
|
||||
'coupon_info' => json_encode($cartCouponPrice[$cart['cart_id']] ?? []),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
namespace app\common\repositories\store\order;
|
||||
|
||||
|
||||
use app\common\dao\store\coupon\StoreCouponUserDao;
|
||||
use app\common\dao\store\order\StoreRefundOrderDao;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreRefundOrder;
|
||||
@ -1301,6 +1302,18 @@ class StoreRefundOrderRepository extends BaseRepository
|
||||
Queue::push(SendSmsJob::class, ['tempId' => 'REFUND_CONFORM_CODE', 'id' => $refundOrder->refund_order_id]);
|
||||
$this->descBrokerage($refundOrder);
|
||||
|
||||
//退店铺抵扣券和平台购物卡
|
||||
$storeCouponUserDao = new StoreCouponUserDao();
|
||||
foreach ($refundOrder->refundProduct as $refundProduct) {
|
||||
$orderProduct = $refundProduct->product;
|
||||
if (!empty($orderProduct['coupon_info'])) {
|
||||
foreach ($orderProduct['coupon_info'] as $coupon) {
|
||||
$mark = '订单退款';
|
||||
$storeCouponUserDao->increase($coupon['coupon_user_id'], $coupon['coupon_price'], $refundOrder->order, $mark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//退回平台优惠
|
||||
if ($refundOrder->platform_refund_price > 0) {
|
||||
if ($refundOrder->order->firstProfitsharing) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user