diff --git a/app/common/repositories/user/UserOrderRepository.php b/app/common/repositories/user/UserOrderRepository.php index a1b8af8..bb20593 100644 --- a/app/common/repositories/user/UserOrderRepository.php +++ b/app/common/repositories/user/UserOrderRepository.php @@ -132,12 +132,16 @@ class UserOrderRepository extends BaseRepository $type = explode('-',$res['order_type'])[0].'-'; // 付费会员充值 if ($type == self::TYPE_SVIP) { - return Db::transaction(function () use($data, $res) { + $result = Db::transaction(function () use($data, $res) { $res->paid = 1; $res->pay_time = date('y_m-d H:i:s', time()); $res->save(); return $this->payAfter($res, $res); }); + + event('user.vipPay', [$res]); + + return $result; } } diff --git a/app/event.php b/app/event.php index e5e8b9a..a00e453 100644 --- a/app/event.php +++ b/app/event.php @@ -73,6 +73,11 @@ return [ // 酒卡额度相关处理 'app\listener\exchangeQuota\OrderAgreeRefundEvent' ], + // 会员卡开通 支付成功 + 'user.vipPay' => [ + // 酒卡额度相关处理 + 'app\listener\exchangeQuota\OrderVipPayEvent' + ], ], 'subscribe' => [], diff --git a/app/listener/exchangeQuota/OrderVipPayEvent.php b/app/listener/exchangeQuota/OrderVipPayEvent.php new file mode 100644 index 0000000..e5787ce --- /dev/null +++ b/app/listener/exchangeQuota/OrderVipPayEvent.php @@ -0,0 +1,61 @@ + $order->order_id ?? '', + // 'uid' => $order->uid ?? '', + // 'order_info' => $order->order_info ?? '' + // ],1)); + // 获取用户当前持有 + $userHoldInfo = ExchangeQuota::where('uid',$order->uid )->findOrEmpty(); + if((int)$userHoldInfo->uid <= 0) $userHoldInfo->uid = $order->uid; + // 赠送数量 + $vipInfo = json_decode($order->order_info,TRUE); + $giveNum = (float)$vipInfo['quota'] ?? 0; + // Log::info('会员卡开通成功 - 酒卡额度相关处理 - 开始1111111111111: '.var_export([ + // '$giveNum' => $giveNum ?? '', + // '$vipInfo' => $vipInfo ?? '' + // ],1)); + + if((float)$giveNum > 0){ + // 赠送 + $changeFront = (float)$userHoldInfo->surplus_quota; + $userHoldInfo->total_quota += (float)$giveNum;// 总额度 + $userHoldInfo->surplus_quota += (float)$giveNum;// 剩余额度 + $userHoldInfo->save(); + // 记录 + $insertData[] = [ + 'uid' => $order->uid, + 'product_id' => 0, + 'order_id' => $order->order_id, + 'order_product_id' => 0, + 'change_type' => 1, + 'change_quantity' => (float)$giveNum, + 'change_front' => $changeFront, + 'change_after' => (float)$userHoldInfo->surplus_quota, + 'remark' => "购买会员卡赠送", + 'source' => 3, + ]; + ExchangeQuotaRecord::insertAll($insertData); + } + }catch(\Exception $e){ + Log::info('会员卡开通成功 - 酒卡额度相关处理 - 错误: '.$e->getMessage()); + } + } + + + +} \ No newline at end of file