From a6d33770ac933354c05eea47586f83e1d927a094 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Mon, 3 Jun 2024 14:49:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E8=B4=AD?= =?UTF-8?q?=E8=B5=A0=E9=80=81=E5=B0=81=E5=9D=9B=E9=85=92=E9=A2=9D=E5=BA=A6?= =?UTF-8?q?=E5=92=8C=E9=85=92=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 25 +++++++------ .../exchangeQuota/OrderPaySuccessEvent.php | 35 +++++++++++++++++++ 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index e3774b6..d3db7a7 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -84,6 +84,9 @@ class ProductRepository extends BaseRepository ['give_quota_num',0], ['is_give_dish',0], ['give_dish_num',0], + ['is_give_wine',0], + ['give_wine_num',0], + ['wine_type',0], // 按照批量购买设置 ['is_batch',0], ['batch_num',0], @@ -528,6 +531,9 @@ class ProductRepository extends BaseRepository 'give_quota_num' => $data['give_quota_num'] ?? 0, 'is_give_dish' => $data['is_give_dish'] ?? 0, 'give_dish_num' => $data['give_dish_num'] ?? 0, + 'is_give_wine' => $data['is_give_wine'] ?? 0, + 'give_wine_num' => $data['give_wine_num'] ?? 0, + 'wine_type' => $data['wine_type'] ?? 0, // 按照批量购买设置 'is_batch' => $data['is_batch'] ?? 0, 'batch_num' => $data['batch_num'] ?? 0, @@ -2514,17 +2520,12 @@ class ProductRepository extends BaseRepository return app()->make(ProductAttrValueRepository::class)->getSearch(['product_id' => $id])->select()->append(['is_svip_price']); } - public function checkParams($data,$merId,$id = null) - { + public function checkParams($data,$merId,$id = null){ if (!$data['pay_limit']) $data['once_max_count'] = 0; - if ($data['brand_id'] > 0 && !$this->merBrandExists($data['brand_id'])) - throw new ValidateException('品牌不存在'); - if (!$this->CatExists($data['cate_id'])) - throw new ValidateException('平台分类不存在'); - if (isset($data['mer_cate_id']) && !$this->merCatExists($data['mer_cate_id'], $merId)) - throw new ValidateException('不存在的商户分类'); - if ($data['delivery_way'] == 2 && !$this->merShippingExists($merId, $data['temp_id'])) - throw new ValidateException('运费模板不存在'); + if ($data['brand_id'] > 0 && !$this->merBrandExists($data['brand_id'])) throw new ValidateException('品牌不存在'); + if (!$this->CatExists($data['cate_id'])) throw new ValidateException('平台分类不存在'); + if (isset($data['mer_cate_id']) && !$this->merCatExists($data['mer_cate_id'], $merId)) $data['mer_cate_id'] = []; + if ($data['delivery_way'] == 2 && !$this->merShippingExists($merId, $data['temp_id'])) throw new ValidateException('运费模板不存在'); if (isset($data['type']) && $data['type'] == 1 && $data['extend']) { $key = ['email','text','number','date','time','idCard','mobile','image']; if (count($data['extend']) > 10) throw new ValidateException('附加表单不能超过10条'); @@ -2605,7 +2606,8 @@ class ProductRepository extends BaseRepository */ public function getWineList($search, $page, $limit){ // 获取信息 - $query = (new Product())->alias('Product') + $query = (new Product()) + ->alias('Product') ->join('Merchant', 'Product.mer_id = Merchant.mer_id and Merchant.is_del = 0', 'LEFT') ->where('Product.delete', 0) ->where('Product.product_type', 0) @@ -2615,6 +2617,7 @@ class ProductRepository extends BaseRepository ->where('Merchant.status', 1) ->where('Merchant.mer_state', 1) ->where('Merchant.merchant_type', 1) + ->whereIn('Product.wine_type', [1,2]) ->when(isset($search['store_name']) && $search['store_name'] !== '', function ($query) use ($search) { $query->whereLike('Product.store_name', "%{$search['store_name']}%"); }) diff --git a/app/listener/exchangeQuota/OrderPaySuccessEvent.php b/app/listener/exchangeQuota/OrderPaySuccessEvent.php index 5847109..c790cc1 100644 --- a/app/listener/exchangeQuota/OrderPaySuccessEvent.php +++ b/app/listener/exchangeQuota/OrderPaySuccessEvent.php @@ -106,6 +106,12 @@ class OrderPaySuccessEvent{ $userHoldInfoDish->uid = $groupOrder->uid; $userHoldInfoDish->quota_type = 2; } + // 用户当前持有 封坛酒额度 + $userHoldInfoWine = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$groupOrder->uid,'quota_type'=>3])->findOrEmpty(); + if((int)$userHoldInfoWine->uid <= 0) { + $userHoldInfoWine->uid = $groupOrder->uid; + $userHoldInfoWine->quota_type = 3; + } // 总平台统一设置 赠送酒卡额度倍数 $exchangeQuotaMultiple = (int)systemConfig('exchange_quota_multiple'); // 循环处理单个商品 @@ -170,11 +176,40 @@ class OrderPaySuccessEvent{ 'quota_type' => 2 ]; } + // 判断:商品是否开启赠送封坛酒额度 + if($orderProductInfo->product->is_give_wine == 1){ + // 计算默认额度 + $giveNum = (float)$orderProductInfo->product_price;// 默认为支付金额 + $merExchangeQuotaMultiple = (int)app()->make(MerchantRepository::class)->getSearch(['mer_id' => $orderInfo->mer_id])->value('mer_exchange_quota_multiple'); + if($merExchangeQuotaMultiple > 0) $giveNum = (float)sprintf("%2.f",$giveNum * $merExchangeQuotaMultiple); + else if($exchangeQuotaMultiple > 0) $giveNum = (float)sprintf("%2.f",$giveNum * $exchangeQuotaMultiple); + // 判断:独立设置 还是使用统一设置 + if((float)$orderProductInfo->product->give_wine_num > 0) $giveNum = (float)$orderProductInfo->product->give_wine_num; + // 赠送 + $changeFront = (float)$userHoldInfoWine->surplus_quota; + $userHoldInfoWine->total_quota += (float)$giveNum;// 总额度 + $userHoldInfoWine->surplus_quota += (float)$giveNum;// 剩余额度 + $userHoldInfoWine->freeze_quota += (float)$giveNum;// 冻结额度 + // 记录 + $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)$giveNum, + 'change_front' => $changeFront, + 'change_after' => (float)$userHoldInfoWine->surplus_quota, + 'remark' => "购买商品赠送", + 'quota_type' => 3 + ]; + } } } // 修改用户持有 $userHoldInfo->save(); $userHoldInfoDish->save(); + $userHoldInfoWine->save(); // 记录酒卡额度信息 if(count($insertData) > 0) ExchangeQuotaRecord::insertAll($insertData);