订单退款,退用户红包,撤销活动订单
This commit is contained in:
parent
665eb57c5e
commit
f6b212da22
@ -12,6 +12,7 @@ use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\StoreActivityOrder;
|
||||
use app\common\model\user\User;
|
||||
use app\common\repositories\user\UserBillRepository;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
|
||||
class StoreConsumptionUserDao extends BaseDao
|
||||
@ -367,4 +368,38 @@ class StoreConsumptionUserDao extends BaseDao
|
||||
return [$payPrice, $groupOrderTotalPrice, $useAmount, $consumptionBalance];
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过订单id退用户红包
|
||||
* @param $refundOrder
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function refundByOrder($refundOrder)
|
||||
{
|
||||
$order = StoreOrder::where('order_id', $refundOrder['order_id'])->find();
|
||||
$model = StoreConsumptionUser::where('uid', $refundOrder['uid'])->where('coupon_user_id', $order['consumption_id'])->find();
|
||||
if (empty($model)) {
|
||||
return;
|
||||
}
|
||||
$model->balance = bcadd($model->balance, $refundOrder['refund_consumption'], 2);
|
||||
$model->status = StoreConsumptionUser::STATUS_UNUSED;
|
||||
if (!$model->save()) {
|
||||
throw new ValidateException('红包退还失败');
|
||||
}
|
||||
// 写入红包日志
|
||||
/** @var $userBillRepository UserBillRepository */
|
||||
$userBillRepository = app()->make(UserBillRepository::class);
|
||||
$title = $model['type'] == StoreConsumptionUser::TYPE_TWO ? '现金抵扣红包' : '无门槛实物通用红包';
|
||||
$userBillRepository->incBill($refundOrder['uid'], 'red_pack', "red_pack_{$model['type']}", [
|
||||
'link_id' => $refundOrder['order_id'],
|
||||
'status' => 1,
|
||||
'title' => '订单退款,获得' . $title,
|
||||
'number' => $refundOrder['refund_consumption'],
|
||||
'mark' => '订单退款,获得' . $title . $refundOrder['refund_consumption'] . ",退款订单ID:{$refundOrder['order_id']}",
|
||||
'balance' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ namespace app\common\repositories\store\order;
|
||||
|
||||
use app\common\dao\store\consumption\StoreConsumptionUserDao;
|
||||
use app\common\dao\store\order\StoreRefundOrderDao;
|
||||
use app\common\dao\store\StoreActivityOrderDao;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreRefundOrder;
|
||||
@ -1176,6 +1177,12 @@ class StoreRefundOrderRepository extends BaseRepository
|
||||
//退还赠送积分
|
||||
$this->refundGiveIntegral($refundOrder);
|
||||
|
||||
if ($refundOrder['refund_consumption'] > 0) {
|
||||
(new StoreConsumptionUserDao())->refundByOrder($refundOrder);
|
||||
}
|
||||
|
||||
(new StoreActivityOrderDao())->repeal($refundOrder->order->group_order_id);
|
||||
|
||||
app()->make(FinancialRecordRepository::class)->dec([
|
||||
'order_id' => $refundOrder->refund_order_id,
|
||||
'order_sn' => $refundOrder->refund_order_sn,
|
||||
|
Loading…
x
Reference in New Issue
Block a user