From 42b4e8e7bbdbbb1bcd413422e07bd7560e86eee7 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Wed, 10 Jan 2024 18:15:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E6=98=AF=E5=90=A6=E8=B5=A0?= =?UTF-8?q?=E9=80=81=E5=85=91=E6=8D=A2=E9=A2=9D=E5=BA=A6=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=EF=BC=9A=E8=B4=AD=E4=B9=B0=E5=95=86=E5=93=81=E8=B5=A0?= =?UTF-8?q?=E9=80=81=E5=85=91=E6=8D=A2=E9=A2=9D=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/user/ExchangeQuotaDao.php | 23 ++++++ .../dao/user/ExchangeQuotaRecordDao.php | 23 ++++++ app/common/model/user/ExchangeQuota.php | 47 ++++++++++++ app/common/model/user/ExchangeQuotaRecord.php | 47 ++++++++++++ .../store/order/StoreOrderRepository.php | 2 + .../store/product/ProductRepository.php | 76 ++++++++++--------- .../user/ExchangeQuotaRecordRepository.php | 19 +++++ .../user/ExchangeQuotaRepository.php | 19 +++++ app/event.php | 9 +++ .../exchangeQuota/OrderPaySuccessEvent.php | 68 +++++++++++++++++ 10 files changed, 297 insertions(+), 36 deletions(-) create mode 100644 app/common/dao/user/ExchangeQuotaDao.php create mode 100644 app/common/dao/user/ExchangeQuotaRecordDao.php create mode 100644 app/common/model/user/ExchangeQuota.php create mode 100644 app/common/model/user/ExchangeQuotaRecord.php create mode 100644 app/common/repositories/user/ExchangeQuotaRecordRepository.php create mode 100644 app/common/repositories/user/ExchangeQuotaRepository.php create mode 100644 app/listener/exchangeQuota/OrderPaySuccessEvent.php diff --git a/app/common/dao/user/ExchangeQuotaDao.php b/app/common/dao/user/ExchangeQuotaDao.php new file mode 100644 index 0000000..ff95121 --- /dev/null +++ b/app/common/dao/user/ExchangeQuotaDao.php @@ -0,0 +1,23 @@ +hasOne(User::class, 'uid', 'uid'); + } + + +} diff --git a/app/common/model/user/ExchangeQuotaRecord.php b/app/common/model/user/ExchangeQuotaRecord.php new file mode 100644 index 0000000..91f6aeb --- /dev/null +++ b/app/common/model/user/ExchangeQuotaRecord.php @@ -0,0 +1,47 @@ +hasOne(User::class, 'uid', 'uid'); + } + + +} diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 439a781..aba7db8 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -1377,6 +1377,8 @@ class StoreOrderRepository extends BaseRepository if (isset($temp_code)) Queue::push(SendSmsJob::class, ['tempId' => $temp_code, 'id' => $order->order_id]); event('order.delivery', compact('order', 'data')); + + if($data['status'] == 2) event('order.take', compact('order')); return $data; } diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index e5fdcdf..85e9474 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -75,6 +75,8 @@ class ProductRepository extends BaseRepository // 积分抵扣 ['integral_deduction_type',0], ['integral_deduction_money',0], + // 是否赠送兑换额度 + ['is_give_quota',0], ]; protected $admin_filed = 'Product.product_id,Product.mer_id,brand_id,spec_type,unit_name,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,U.rank,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,Product.ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,star,ficti,integral_total,integral_price_total,sys_labels,param_temp_id,mer_svip_status,svip_price,svip_price_type'; protected $filed = 'Product.product_id,Product.mer_id,brand_id,unit_name,spec_type,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,Product.ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,integral_total,integral_price_total,mer_labels,Product.is_good,Product.is_del,type,param_temp_id,mer_svip_status,svip_price,svip_price_type'; @@ -448,44 +450,46 @@ class ProductRepository extends BaseRepository if($data['integral_rate'] > 100) $integral_rate = 100; } $result = [ - 'store_name' => $data['store_name'], - 'image' => $data['image'], - 'slider_image' => is_array($data['slider_image']) ? implode(',',$data['slider_image']) : '', - 'store_info' => $data['store_info'] ?? '', - 'keyword' => $data['keyword'] ?? '', - 'brand_id' => $data['brand_id'] ?? 0, - 'cate_id' => $data['cate_id'] ?? 0, - 'unit_name' => $data['unit_name'] ?? '件', - 'sort' => $data['sort'] ?? 0, - 'is_show' => $data['is_show'] ?? 0, - 'is_used' => (isset($data['status']) && $data['status'] == 1) ? 1 : 0, - 'is_good' => $data['is_good'] ?? 0, - 'video_link' => $data['video_link'] ?? '', - 'temp_id' => $data['delivery_free'] ? 0 : ($data['temp_id'] ?? 0), - 'extension_type' => $data['extension_type'] ?? 0, - 'spec_type' => $data['spec_type'] ?? 0, - 'status' => $data['status'] ?? 0, - 'give_coupon_ids' => $give_coupon_ids, - 'mer_status' => $data['mer_status'], - 'guarantee_template_id' => $data['guarantee_template_id'] ?? 0, - 'is_gift_bag' => $data['is_gift_bag'] ?? 0, - 'integral_rate' => $integral_rate ?? 0, - 'delivery_way' => implode(',',$data['delivery_way']), - 'delivery_free' => $data['delivery_free'] ?? 0, - 'once_min_count' => $data['once_min_count'] ?? 0, - 'once_max_count' => $data['once_max_count'] ?? 0, - 'pay_limit' => $data['pay_limit'] ?? 0, - 'svip_price_type' => $data['svip_price_type'] ?? 0, - 'refund_switch' => $data['refund_switch'] ?? 0, + 'store_name' => $data['store_name'], + 'image' => $data['image'], + 'slider_image' => is_array($data['slider_image']) ? implode(',',$data['slider_image']) : '', + 'store_info' => $data['store_info'] ?? '', + 'keyword' => $data['keyword'] ?? '', + 'brand_id' => $data['brand_id'] ?? 0, + 'cate_id' => $data['cate_id'] ?? 0, + 'unit_name' => $data['unit_name'] ?? '件', + 'sort' => $data['sort'] ?? 0, + 'is_show' => $data['is_show'] ?? 0, + 'is_used' => (isset($data['status']) && $data['status'] == 1) ? 1 : 0, + 'is_good' => $data['is_good'] ?? 0, + 'video_link' => $data['video_link'] ?? '', + 'temp_id' => $data['delivery_free'] ? 0 : ($data['temp_id'] ?? 0), + 'extension_type' => $data['extension_type'] ?? 0, + 'spec_type' => $data['spec_type'] ?? 0, + 'status' => $data['status'] ?? 0, + 'give_coupon_ids' => $give_coupon_ids, + 'mer_status' => $data['mer_status'], + 'guarantee_template_id' => $data['guarantee_template_id'] ?? 0, + 'is_gift_bag' => $data['is_gift_bag'] ?? 0, + 'integral_rate' => $integral_rate ?? 0, + 'delivery_way' => implode(',',$data['delivery_way']), + 'delivery_free' => $data['delivery_free'] ?? 0, + 'once_min_count' => $data['once_min_count'] ?? 0, + 'once_max_count' => $data['once_max_count'] ?? 0, + 'pay_limit' => $data['pay_limit'] ?? 0, + 'svip_price_type' => $data['svip_price_type'] ?? 0, + 'refund_switch' => $data['refund_switch'] ?? 0, // 赠送积分 - 'integral_give_switch' => $data['integral_give_switch'] ?? 0, - 'integral_give_set' => $data['integral_give_set'] ?? 0, - 'integral_give_type' => $data['integral_give_type'] ?? 0, - 'integral_give_rate' => $data['integral_give_rate'] ?? 0, - 'integral_give_money' => $data['integral_give_money'] ?? 0, + 'integral_give_switch' => $data['integral_give_switch'] ?? 0, + 'integral_give_set' => $data['integral_give_set'] ?? 0, + 'integral_give_type' => $data['integral_give_type'] ?? 0, + 'integral_give_rate' => $data['integral_give_rate'] ?? 0, + 'integral_give_money' => $data['integral_give_money'] ?? 0, // 积分抵扣 - 'integral_deduction_type' => $data['integral_deduction_type'] ?? 0, - 'integral_deduction_money' => $data['integral_deduction_money'] ?? 0, + 'integral_deduction_type' => $data['integral_deduction_type'] ?? 0, + 'integral_deduction_money' => $data['integral_deduction_money'] ?? 0, + // 赠送兑换额度 + 'is_give_quota' => $data['is_give_quota'] ?? 0, ]; if (isset($data['extend'])) $result['extend'] = $data['extend'] ? json_encode($data['extend'], JSON_UNESCAPED_UNICODE) : ''; diff --git a/app/common/repositories/user/ExchangeQuotaRecordRepository.php b/app/common/repositories/user/ExchangeQuotaRecordRepository.php new file mode 100644 index 0000000..61e4f6f --- /dev/null +++ b/app/common/repositories/user/ExchangeQuotaRecordRepository.php @@ -0,0 +1,19 @@ +dao = $dao; + } + + + + +} diff --git a/app/common/repositories/user/ExchangeQuotaRepository.php b/app/common/repositories/user/ExchangeQuotaRepository.php new file mode 100644 index 0000000..ba98f9a --- /dev/null +++ b/app/common/repositories/user/ExchangeQuotaRepository.php @@ -0,0 +1,19 @@ +dao = $dao; + } + + + + +} diff --git a/app/event.php b/app/event.php index 38c1e8e..42a975b 100644 --- a/app/event.php +++ b/app/event.php @@ -53,6 +53,15 @@ return [ 'pay_success_order' => [\crmeb\listens\pay\OrderPaySuccessListen::class], 'pay_success_presell' => [\crmeb\listens\pay\PresellPaySuccessListen::class], 'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class], + // 订单支付成功事件触发 + 'order.paySuccess' => [ + // 支付成功 赠送兑换额度 + 'app\listener\exchangeQuota\OrderPaySuccessEvent' + ], + // 订单完成事件触发(进入待评价) + 'order.take' => [], + // 订单退款事件 + 'refund.agree' => [], ], 'subscribe' => [], diff --git a/app/listener/exchangeQuota/OrderPaySuccessEvent.php b/app/listener/exchangeQuota/OrderPaySuccessEvent.php new file mode 100644 index 0000000..8314125 --- /dev/null +++ b/app/listener/exchangeQuota/OrderPaySuccessEvent.php @@ -0,0 +1,68 @@ +$groupOrder->uid,'group_order_id'=>$groupOrder->group_order_id],1)); + $this->orderPaySuccessHandle($groupOrder); + + }catch(\Exception $e){ + $data = [ + 'uid' => $groupOrder->uid, + 'group_order_id' => $groupOrder->group_order_id, + 'msg' => $e->getMessage() + ]; + Log::info('支付成功 - 赠送兑换额度 - 错误: '.var_export($data,1)); + } + } + // 支付成功 - 赠送兑换额度 + public function orderPaySuccessHandle($groupOrder):bool{ + // 获取用户当前持有 + $userHoldInfo = ExchangeQuota::where('uid',$groupOrder->uid)->findOrEmpty(); + if((int)$userHoldInfo->uid <= 0) $userHoldInfo->uid = $groupOrder->uid; + // 循环处理单个商品 + $insertData = []; + foreach($groupOrder->orderList as $orderInfo){ + foreach($orderInfo->orderProduct as $orderProductInfo){ + // 判断:商品是否开启赠送兑换额度 当前商品实际支付的金额=赠送的兑换额度 + if($orderProductInfo->product->is_give_quota == 1 && $orderProductInfo->product_price > 0){ + // 赠送 + $changeFront = (float)$userHoldInfo->surplus_quota; + $userHoldInfo->total_quota += (float)$orderProductInfo->product_price;// 总额度 + $userHoldInfo->surplus_quota += (float)$orderProductInfo->product_price;// 剩余额度 + $userHoldInfo->freeze_quota += (float)$orderProductInfo->product_price;// 冻结额度 + // 记录 + $insertData[] = [ + 'uid' => $orderProductInfo->uid, + 'product_id' => $orderProductInfo->product_id, + 'order_id' => $orderProductInfo->order_id, + 'order_product_id' => $orderProductInfo->order_product_id, + 'change_type' => 1, + 'change_quantity' => (float)$orderProductInfo->product_price, + 'change_front' => $changeFront, + 'change_after' => (float)$userHoldInfo->surplus_quota, + 'remark' => "购买商品赠送兑换额度", + ]; + } + } + } + // 修改用户持有 + $userHoldInfo->save(); + // 记录兑换额度信息 + if(count($insertData) > 0) ExchangeQuotaRecord::insertAll($insertData); + + return true; + } + + + +} \ No newline at end of file