From fa6f42abe4e1c46b97d23278ca493c06f1e1f5b3 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Wed, 3 Jul 2024 13:54:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E5=B0=8F=E9=85=92?= =?UTF-8?q?=E9=A6=86=E8=A1=A5=E5=B7=AE=E5=AE=9E=E9=99=85=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E9=87=91=E9=A2=9D=20=20=E6=9F=90=E4=B8=AA=E5=95=86=E6=88=B7?= =?UTF-8?q?=E6=80=BB=E9=A2=9D=E8=BE=BE=E5=88=B0=E6=8C=87=E5=AE=9A=E9=87=91?= =?UTF-8?q?=E9=A2=9D=E6=97=B6=EF=BC=8C=E8=87=AA=E5=8A=A8=E6=88=90=E4=B8=BA?= =?UTF-8?q?=E8=AF=A5=E5=95=86=E6=88=B7=E7=9A=84=E5=85=B1=E5=88=9B=E8=82=A1?= =?UTF-8?q?=E4=B8=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/ExchangeQuotaRepository.php | 2 + app/controller/admin/user/ExchangeQuota.php | 2 + .../exchangeQuota/OrderPaySuccessEvent.php | 178 ++++++++++++++---- 3 files changed, 150 insertions(+), 32 deletions(-) diff --git a/app/common/repositories/user/ExchangeQuotaRepository.php b/app/common/repositories/user/ExchangeQuotaRepository.php index 7fc4fa9..03e7114 100644 --- a/app/common/repositories/user/ExchangeQuotaRepository.php +++ b/app/common/repositories/user/ExchangeQuotaRepository.php @@ -200,6 +200,8 @@ class ExchangeQuotaRepository extends BaseRepository{ 'quota_integral_diff_rate', 'quota_integral_give_money', 'quota_integral_give_card', + 'quota_integral_shareholder_money', + 'quota_integral_shareholder_level_id' ]); // 信息处理 $config['quota_integral_switch'] = (int)$config['quota_integral_switch']; diff --git a/app/controller/admin/user/ExchangeQuota.php b/app/controller/admin/user/ExchangeQuota.php index fd364b4..cc4928f 100644 --- a/app/controller/admin/user/ExchangeQuota.php +++ b/app/controller/admin/user/ExchangeQuota.php @@ -207,6 +207,8 @@ class ExchangeQuota extends BaseController{ ['quota_integral_diff_rate',0], ['quota_integral_give_money',0], ['quota_integral_give_card',0], + ['quota_integral_shareholder_money',0], + ['quota_integral_shareholder_level_id',0], ]); // 保存信息 $cid = app()->make(ConfigClassifyRepository::class)->getConfigClassifyKeyById('quota_config', '额度与积分配置'); diff --git a/app/listener/exchangeQuota/OrderPaySuccessEvent.php b/app/listener/exchangeQuota/OrderPaySuccessEvent.php index 9248b2c..274422f 100644 --- a/app/listener/exchangeQuota/OrderPaySuccessEvent.php +++ b/app/listener/exchangeQuota/OrderPaySuccessEvent.php @@ -13,13 +13,18 @@ use app\common\model\user\User; use app\common\model\user\UserInviteCode; use app\common\repositories\marketing\activity\RecordRepository; use app\common\repositories\marketing\AgentBrokerageRepository; +use app\common\repositories\store\order\StoreOrderRepository; +use app\common\repositories\system\groupData\GroupDataRepository; use app\common\repositories\system\merchant\MerchantQuotaRecordRepository; use app\common\repositories\system\merchant\MerchantRepository; +use app\common\repositories\system\merchant\MerchantShareholderLevelRepository; use app\common\repositories\system\merchant\MerchantShareholderRepository; use app\common\repositories\user\ExchangePickupPointRepository; use app\common\repositories\user\ExchangeQuotaRepository; use app\common\repositories\user\UserInviteCodeRepository; +use app\common\repositories\user\UserOrderRepository; use crmeb\jobs\UserBrokerageLevelJob; +use think\exception\ValidateException; use think\facade\Log; use think\facade\Queue; @@ -49,7 +54,14 @@ class OrderPaySuccessEvent{ // 进货订单 case 35:break; // 酒道馆和小酒馆兑换订单 - case 36:break; + case 36: + // 补差实际支付总金额达标 - 赠送会员卡 + $this->giveVip($groupOrder); + // 某个商户补差实际支付金额达标 - 自动成为该商户共创股东 + $this->autoBecomeShareholder($groupOrder); + + + break; // 共创股东加入 case 37: foreach($groupOrder->orderList as $orderInfo){ @@ -80,28 +92,29 @@ class OrderPaySuccessEvent{ 'group_order_id' => $groupOrder->group_order_id, 'msg' => $e->getMessage() ]; - if($groupOrder->activity_type == 30){ + $title = '支付成功'; + // 根据订单类型进行对应的处理 + switch((int)$groupOrder->activity_type){ // 在线支付订单 - Log::info('支付成功 - 赠送酒水卡积分 - 错误: '.var_export($data,1)); - } - else if($groupOrder->activity_type == 31){ - Log::info('支付成功 - 兑换商品补差价处理 - 错误: '.var_export($data,1)); - } - else if($groupOrder->activity_type == 32){ - Log::info('支付成功 - 邀请代理人员奖励及免审核 - 错误: '.var_export($data,1)); - } - else if($groupOrder->activity_type == 33){ - Log::info('支付成功 - 加入活动支付成功 - 错误: '.var_export($data,1)); - } - else if($groupOrder->activity_type == 34){ - Log::info('支付成功 - 邀请码激活 - 错误: '.var_export($data,1)); - } - else if($groupOrder->activity_type == 35){ - Log::info('支付成功 - 进货订单 - 错误: '.var_export($data,1)); - } - else{ - Log::info('支付成功 - 赠送酒卡额度 - 错误: '.var_export($data,1)); + case 30:$title = '支付成功 - 在线支付订单';break; + // 兑换商品补差价处理 + case 31:$title = '支付成功 - 兑换商品补差价处理';break; + // 代理入驻支付 + case 32:$title = '支付成功 - 代理入驻';break; + // 加入活动支付成功 + case 33:$title = '支付成功 - 加入活动';break; + // 邀请码激活 + case 34:$title = '支付成功 - 邀请码激活';break; + // 进货订单 + case 35:$title = '支付成功 - 进货订单';break; + // 酒道馆和小酒馆兑换订单 + case 36:$title = '支付成功 - 酒道馆和小酒馆兑换订单';break; + // 共创股东加入 + case 37:$title = '支付成功 - 共创股东加入';break; + // 配送商缴费支付成功 + case 38:$title = '支付成功 - 配送商缴费支付成功';break; } + Log::info($title . ' - 错误: '.var_export($data,1)); } } // 支付成功 - 赠送酒卡额度 @@ -332,15 +345,122 @@ class OrderPaySuccessEvent{ return true; } + // 小酒馆补差实际支付金额 补差实际支付总金额达标 - 赠送会员卡 + public function giveVip($groupOrder){ + // 订单状态(0:待发货;1:待收货;2:待评价;3:已完成; 9: 拼团中 10: 待付尾款 11:尾款超时未付 -1:已退款) + try{ + // 设置信息获取 + $config = app()->make(ExchangeQuotaRepository::class)->getConfig(); + $targetMoney = (float)$config['quota_integral_give_money']; + if($targetMoney <= 0) throw new ValidateException('未设置目标金额!'); + // 获取总有效金额 查看是否达标 + $totalMoney = app()->make(StoreOrderRepository::class) + ->getSearch([ + 'uid' => $groupOrder->uid, + 'activity_type' => 36, + 'paid' => 1 + ]) + ->whereIn('status', [0,1,2,3]) + ->sum('quota_integral_diff_money'); + if($targetMoney > $totalMoney) throw new ValidateException("未达标!要求:{$targetMoney};当前:{$totalMoney}"); + // 判断:当前用户是否已经领取 + $isGet = app()->make(UserOrderRepository::class)->getSearch(['source'=>3])->value('order_id'); + if($isGet > 0) throw new ValidateException("当前用户已发放!"); + // 判断:是否符合会员卡开通条件 + $user = User::where('uid', $groupOrder->uid)->findOrEmpty(); + $vipInfo = app()->make(GroupDataRepository::class)->getWhere(['group_data_id' => $config['quota_integral_give_card'], 'status' => 1]); + if (!$vipInfo) throw new ValidateException('会员卡不存在!'); + if ($user->is_svip == 3) throw new ValidateException('会员已经是终身会员!'); + if ($user->is_svip !== -1 && $vipInfo['value']['svip_type'] == 1) throw new ValidateException('会员已开通该类型会员!'); + // 模拟下单 + $params['pay_type'] = 'free'; + $params['return_url'] = ''; + $params['is_app'] = request()->isApp(); + $params['source'] = 3; + app()->make(UserOrderRepository::class)->add($vipInfo, $user, $params); + }catch(\Exception $e){ + $data = [ + 'uid' => $groupOrder->uid, + 'group_order_id' => $groupOrder->group_order_id, + 'msg' => $e->getMessage() + ]; + Log::info('小酒馆补差实际支付金额达标赠送会员卡 - 错误: '.var_export($data,1)); + } + + return true; + } + // 小酒馆补差实际支付金额 某个商户补差实际支付金额达标 - 自动成为该商户共创股东 + public function autoBecomeShareholder($groupOrder){ + try{ + // 设置信息获取 + $config = app()->make(ExchangeQuotaRepository::class)->getConfig(); + $targetMoney = (float)$config['quota_integral_shareholder_money']; + if($targetMoney <= 0) throw new ValidateException('未设置目标金额!'); + // 获取共创股东等级信息 + $levelInfo = app()->make(MerchantShareholderLevelRepository::class) + ->getSearchModel(['id' => $config['quota_integral_shareholder_level_id']]) + ->findOrEmpty() + ->toArray(); + // 循环处理每个订单 + if($levelInfo){ + foreach($groupOrder->orderList as $orderInfo){ + $totalMoney = app()->make(StoreOrderRepository::class) + ->getSearch([ + 'uid' => $orderInfo->uid, + 'activity_type' => 36, + 'paid' => 1, + 'mer_id' => $orderInfo->mer_id, + ]) + ->whereIn('status', [0,1,2,3]) + ->sum('quota_integral_diff_money'); + // 未达标 + if($targetMoney > $totalMoney) continue; + // 是否已经是当前商户的共创股东 + $isExistence = (int)app()->make(MerchantShareholderRepository::class)->getSearchModel([ + 'mer_id' => $orderInfo->mer_id, + 'uid' => $orderInfo->uid, + ])->value('id'); + if($isExistence > 0) continue; + // 判断:当前商户的本等级共创股东是否已经达到上限 + if($levelInfo['mer_quota'] > 0){ + $quotaUsed = (int)app()->make(MerchantShareholderRepository::class) + ->getSearchModel(['mer_id' => $orderInfo->mer_id,'level_id' => $levelInfo['id']]) + ->count(); + // 等级名额限制 小于等于 已邀请名额;禁止加入 + if($levelInfo['mer_quota'] <= $quotaUsed) continue; + } + // 自动成为共创股东 + $merchantShareholderId = app()->make(MerchantShareholderRepository::class)->createJoinInfo([ + 'uid' => $orderInfo->uid, + 'mer_id' => $orderInfo->mer_id, + 'level_id' => $levelInfo['id'], + ]); + app()->make(MerchantShareholderRepository::class)->joinSuccess($merchantShareholderId); + } + } + }catch(\Exception $e){ + $data = [ + 'uid' => $groupOrder->uid, + 'group_order_id' => $groupOrder->group_order_id, + 'msg' => $e->getMessage() + ]; + Log::info('小酒馆补差实际支付金额达标成为共创股东 - 错误: '.var_export($data,1)); + } + + return true; + } + + /** * Common: 赠送惠民积分处理 * Author: wu-hui * Time: 2024/07/01 14:35 - * @param $uid - * @param $merId - * @param $orderInfo - * @param $remark - * @param $source + * @param $orderInfo + * @param $remark + * @param $source + * @param $payPrice + * @param int $productId + * @param int $orderProductId * @return bool */ private function giveQuotaIntegral($orderInfo, $remark, $source, $payPrice, $productId = 0, $orderProductId = 0){ @@ -377,10 +497,4 @@ class OrderPaySuccessEvent{ return true; } - - - - - - } \ No newline at end of file