From 8d2e9e8814c5e001b40151389a328a24228fdcea Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Sat, 9 Mar 2024 11:31:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E4=BE=9B=E5=BA=94?= =?UTF-8?q?=E5=95=86=E7=AE=A1=E7=90=86=E5=90=8E=E5=8F=B0=E4=B8=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=85=92=E9=81=93=E9=A6=86=E8=BF=9B=E8=B4=A7=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=88=97=E8=A1=A8=20=E4=BF=AE=E5=A4=8D=EF=BC=9A?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=AB=AF=E8=8E=B7=E5=8F=96=E9=85=92=E9=81=93?= =?UTF-8?q?=E9=A6=86=E8=BF=9B=E8=B4=A7=E8=AE=A2=E5=8D=95=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/order/StoreOrderDao.php | 36 +++++++++--- .../store/order/StoreOrderRepository.php | 29 +++++++--- .../store/product/ProductRepository.php | 6 +- app/listener/exchangeQuota/OrderTakeEvent.php | 57 ++++++++++++------- 4 files changed, 88 insertions(+), 40 deletions(-) diff --git a/app/common/dao/store/order/StoreOrderDao.php b/app/common/dao/store/order/StoreOrderDao.php index f993547..39055c5 100644 --- a/app/common/dao/store/order/StoreOrderDao.php +++ b/app/common/dao/store/order/StoreOrderDao.php @@ -14,6 +14,7 @@ use app\common\model\user\User; use app\common\repositories\store\order\StoreOrderStatusRepository; use app\common\repositories\store\product\ProductAssistSetRepository; use app\common\repositories\store\product\ProductGroupBuyingRepository; +use app\common\repositories\system\merchant\MerchantRepository; use think\db\BaseQuery; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; @@ -57,15 +58,35 @@ class StoreOrderDao extends BaseDao * @author xaboyCRMEB * @day 2020/6/16 */ - public function search(array $where, $sysDel = 0) - { + public function search(array $where, $sysDel = 0){ $query = StoreOrder::hasWhere('merchant', function ($query) use ($where) { if (isset($where['is_trader']) && $where['is_trader'] !== '') { $query->where('is_trader', $where['is_trader']); } $query->where('is_del',0); }); - $query->whereNotIn('StoreOrder.activity_type',[20,30]); + // 存在商户id是否 判断商户id类型,显示对应的订单 + if(isset($where['mer_id']) && $where['mer_id'] !== ''){ + $merchantType = app()->make(MerchantRepository::class) + ->getSearch([]) + ->where('mer_id', $where['mer_id']) + ->value('merchant_type'); + // 供应商 仅显示酒道馆进货订单 + if($merchantType == 2) $where['activity_type'] = 35; + } + + + + + + $isWithGoods = $where['is_with_goods'] ?? 0; + $activityType = $where['activity_type'] ?? 0; + if($isWithGoods == 1 || $activityType == 35){ + $query->whereNotIn('StoreOrder.activity_type',[20,30]); + }else{ + $query->whereNotIn('StoreOrder.activity_type',[20,30,35]); + } + $query->when(($sysDel !== null), function ($query) use ($sysDel) { $query->where('is_system_del', $sysDel); }); @@ -100,12 +121,9 @@ class StoreOrderDao extends BaseDao ->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) { $query->where('uid', $where['uid']); }) - ->when(isset($where['with_goods_mer_id']) && $where['with_goods_mer_id'] !== '', function ($query) use ($where) { - if($where['with_goods_mer_id'] > 0) $query->where('with_goods_mer_id', $where['with_goods_mer_id']); - },function($query){ - $query->where(function($orQuery){ - $orQuery->where('with_goods_mer_id', null)->whereOr('with_goods_mer_id','<=', 0); - }); + ->when(isset($where['with_goods_mer_id']) && $where['with_goods_mer_id'] !== '' && $where['with_goods_mer_id'] > 0, function ($query) use ($where) { + // 酒道馆查看自己进货订单 + $query->where('with_goods_mer_id', $where['with_goods_mer_id']); }) ->when(isset($where['is_spread']) && $where['is_spread'] !== '', function ($query) use ($where) { if ($where['is_spread']) { diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index eff7308..36f3632 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -615,15 +615,15 @@ class StoreOrderRepository extends BaseRepository public function merOrderNumber(int $merId) { - $noPay =app()->make(StoreGroupOrderRepository::class)->search(['with_goods_mer_id' => $merId,'is_del' => 0,'paid' => 0],0)->count(); - $noPostage = $this->dao->search(['with_goods_mer_id' => $merId, 'status' => 0, 'paid' => 1,'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); - $all = $this->dao->search(['with_goods_mer_id' => $merId, 'status' => -2,'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); - $noDeliver = $this->dao->search(['with_goods_mer_id' => $merId, 'status' => 1, 'paid' => 1])->where('StoreOrder.is_del', 0)->count(); - $noComment = $this->dao->search(['with_goods_mer_id' => $merId, 'status' => 2, 'paid' => 1,'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); - $done = $this->dao->search(['with_goods_mer_id' => $merId, 'status' => 3, 'paid' => 1,'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); + $noPay =app()->make(StoreGroupOrderRepository::class)->search(['with_goods_mer_id' => $merId,'activity_type' => 35,'is_del' => 0,'paid' => 0],0)->count(); + $noPostage = $this->dao->search(['with_goods_mer_id' => $merId,'activity_type' => 35, 'status' => 0, 'paid' => 1,'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); + $all = $this->dao->search(['with_goods_mer_id' => $merId,'activity_type' => 35, 'status' => -2,'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); + $noDeliver = $this->dao->search(['with_goods_mer_id' => $merId,'activity_type' => 35, 'status' => 1, 'paid' => 1])->where('StoreOrder.is_del', 0)->count(); + $noComment = $this->dao->search(['with_goods_mer_id' => $merId,'activity_type' => 35, 'status' => 2, 'paid' => 1,'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); + $done = $this->dao->search(['with_goods_mer_id' => $merId,'activity_type' => 35, 'status' => 3, 'paid' => 1,'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); $refund = 0;//app()->make(StoreRefundOrderRepository::class)->getWhereCount(['with_goods_mer_id' => $merId, 'status' => [0, 1, 2]]); - $orderPrice = $this->dao->search(['with_goods_mer_id' => $merId, 'paid' => 1])->sum('pay_price'); - $orderCount = $this->dao->search(['with_goods_mer_id' => $merId, 'paid' => 1,'is_user' => 1])->count(); + $orderPrice = $this->dao->search(['with_goods_mer_id' => $merId,'activity_type' => 35, 'paid' => 1])->sum('pay_price'); + $orderCount = $this->dao->search(['with_goods_mer_id' => $merId,'activity_type' => 35, 'paid' => 1,'is_user' => 1])->count(); return compact('orderPrice','noComment', 'done', 'refund', 'noDeliver', 'noPay', 'noPostage', 'orderCount', 'all'); } @@ -657,7 +657,18 @@ class StoreOrderRepository extends BaseRepository return $query->field('uid,nickname'); }; } - $order = $this->dao->search($where)->where('order_id', $id)->where('StoreOrder.is_del', 0)->with($with)->append(['refund_status','open_receipt'])->find(); + $order = + // $this->dao->search($where) + $this->dao->getSearch([]) + ->hasWhere('merchant',function($query) use ($where){ + $query->where('is_del',0); + }) + ->where('order_id',$id) + ->where('StoreOrder.is_del',0) + ->with($with) + ->append(['refund_status','open_receipt']) + ->find(); + if (!$order) { return null; } diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 43ed81e..be5aaa7 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -56,7 +56,7 @@ class ProductRepository extends BaseRepository const CREATE_PARAMS = [ "is_copy", "image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "guarantee_template_id", "cate_id", "unit_name", "sort" , "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free','param_temp_id','extend', ["mer_cate_id",[]], - ['refund_switch',1], + ['refund_switch',0], ["brand_id",0], ['once_max_count',0], ['once_min_count',0], @@ -2441,6 +2441,10 @@ class ProductRepository extends BaseRepository if (!$count) throw new ValidateException('平台分类不存在或不可用'); app()->make(StoreProductValidate::class)->check($data); $data['extend'] = $extend ?? []; + // 判断:如果当前为供应商商品 则强制禁止退款 + $merchantType = app()->make(MerchantRepository::class)->getSearch([])->where('mer_id', $merId)->value('merchant_type'); + if($merchantType == 2) $data['refund_switch'] = 0; + return $data; } diff --git a/app/listener/exchangeQuota/OrderTakeEvent.php b/app/listener/exchangeQuota/OrderTakeEvent.php index 430fe01..035128b 100644 --- a/app/listener/exchangeQuota/OrderTakeEvent.php +++ b/app/listener/exchangeQuota/OrderTakeEvent.php @@ -16,27 +16,42 @@ class OrderTakeEvent{ public function handle($data){ try{ $order = $data['order']; - // Log::info('订单进入待评价 - 酒卡额度相关处理 - 开始: '.var_export(['order_id' => $order->order_id,'uid' => $order->uid],1)); - # 获取变更记录 条件:order_id=当前订单id、变更类型=增加 - $sum = (float)app()->make(ExchangeQuotaRecordRepository::class) - ->searchModel([ - 'order_id' => $order->order_id, - 'change_type' => 1, - 'source' => 0,// 仅查询购买赠送 进行解冻 - ])->sum('change_quantity'); - $refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class) - ->searchModel([ - 'order_id' => $order->order_id, - 'change_type' => 0, - 'source' => 1,// 仅查询订单退款 减少内容 - ])->sum('change_quantity'); - // 剩余数量 解冻 - $surplusQuota = (float)sprintf("%.2f",$sum - $refundSum); - if($surplusQuota > 0){ - $hold = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$order->uid])->findOrEmpty(); - $freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota); - $hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota; - $hold->save(); + Log::info('订单进入待评价 - 酒卡额度相关处理 - 开始: '.var_export([ + 'order_id' => $order->order_id, + 'uid' => $order->uid, + 'activity_type' => $order->activity_type + ],1)); + + if($order->activity_type == 35){ + // 酒道馆进货商品确认收货 复制商品||增加库存 + + + + + } + else{ + // 其他商品 + # 获取变更记录 条件:order_id=当前订单id、变更类型=增加 + $sum = (float)app()->make(ExchangeQuotaRecordRepository::class) + ->searchModel([ + 'order_id' => $order->order_id, + 'change_type' => 1, + 'source' => 0,// 仅查询购买赠送 进行解冻 + ])->sum('change_quantity'); + $refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class) + ->searchModel([ + 'order_id' => $order->order_id, + 'change_type' => 0, + 'source' => 1,// 仅查询订单退款 减少内容 + ])->sum('change_quantity'); + // 剩余数量 解冻 + $surplusQuota = (float)sprintf("%.2f",$sum - $refundSum); + if($surplusQuota > 0){ + $hold = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$order->uid])->findOrEmpty(); + $freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota); + $hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota; + $hold->save(); + } } }catch(\Exception $e){ Log::info('订单进入待评价 - 酒卡额度相关处理 - 错误: '.$e->getMessage());