取消订单,退回未使用的红包

This commit is contained in:
luofei 2024-02-04 17:51:50 +08:00
parent 181fe6ecb4
commit a74c1308b6
2 changed files with 25 additions and 0 deletions

View File

@ -308,6 +308,26 @@ class StoreConsumptionUserDao extends BaseDao
return strtotime('+1 year', strtotime($datetime));
}
/**
* 增加红包余额
* @param $id
* @param $amount
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function increase($id, $amount)
{
$storeConsumptionUser = StoreConsumptionUser::where('coupon_user_id', $id)->find();
if (empty($storeConsumptionUser)) {
throw new \Exception('红包记录不存在');
}
$storeConsumptionUser->balance = bcadd($storeConsumptionUser->balance, $amount, 2);
if (!$storeConsumptionUser->save()) {
throw new \Exception('红包余额更新出错');
}
}
/**
* 扣减红包余额
* @param $id

View File

@ -14,6 +14,7 @@
namespace app\common\repositories\store\order;
use app\common\dao\store\consumption\StoreConsumptionUserDao;
use app\common\dao\store\order\StoreGroupOrderDao;
use app\common\model\store\order\StoreGroupOrder;
use app\common\model\store\order\StoreOrder;
@ -226,6 +227,10 @@ class StoreGroupOrderRepository extends BaseRepository
}
$groupOrder->save();
$storeOrderStatusRepository->batchCreateLog($orderStatus);
if ($groupOrder->consumption_id > 0 && $groupOrder->consumption_money > 0) {
$storeConsumptionUserDao = new StoreConsumptionUserDao();
$storeConsumptionUserDao->increase($groupOrder['consumption_id'], $groupOrder['consumption_money']);
}
});
Queue::push(CancelGroupOrderJob::class, $id);
}