From f1a67ff8d7cd2890b7b556d90cc070c7f43cd0ef Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 20 Jan 2024 15:16:37 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 161 +++++++++++------- .../merchant/FinancialRecordRepository.php | 9 +- .../system/merchant/MerchantRepository.php | 6 +- crmeb/services/ExcelService.php | 4 +- 4 files changed, 109 insertions(+), 71 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index e51f682e..ddd36ac4 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -314,7 +314,7 @@ class StoreOrderRepository extends BaseRepository 'financial_record_sn' => $financeSn . ($i++) ]; - if($order->source==103){ + if ($order->source == 103) { $_payPrice = $order->procure_price; $finance[] = [ 'order_id' => $order->order_id, @@ -328,33 +328,61 @@ class StoreOrderRepository extends BaseRepository 'mer_id' => $order->mer_id, 'financial_record_sn' => $financeSn . ($i++) ]; + //市级供应链 + $product_mer_id = Db::name('store_order_product')->where('order_id', $order->order_id)->value('product_mer_id'); + if ($product_mer_id) { + //市级供应链押金计算 + if ($_payPrice > 0) { + /** @var MerchantRepository $merchantRepo */ + $merchantRepo = app()->make(MerchantRepository::class); + $merchantRepo->merId = $product_mer_id; + $merchantRepo->forceMargin = false; + [$_payPrice, $a, $increase] = $merchantRepo->autoMargin($_payPrice, $order, $finance, $financeSn, $i++); + } + $finance[] = [ + 'order_id' => $order->order_id, + 'order_sn' => $order->order_sn, + 'user_info' => $groupOrder->user->nickname, + 'user_id' => $uid, + 'financial_type' => 'supply_chain', + 'financial_pm' => 0, + 'type' => 1, + 'number' => $_payPrice, + 'mer_id' => $product_mer_id, + 'financial_record_sn' => $financeSn . (($i++)+1) + ]; + if (!$is_combine) { + app()->make(MerchantRepository::class)->addLockMoney($product_mer_id, 'order', $order->order_id, $_payPrice); + } + } + //计算手续费 - $_order_rate=bcsub($order->pay_price,$_payPrice,2); + $_order_rate = bcsub($order->pay_price, $_payPrice, 2); //计算镇级供应链云仓实际获得金额 - if($_order_rate>0){ - $commission_rate = bcdiv(3,100,2); + if ($_order_rate > 0) { + $commission_rate = bcdiv(3, 100, 2); $_payPrice = bcmul($_order_rate, $commission_rate, 2); - }else{ - $_payPrice=0; + } else { + $_payPrice = 0; } - }else{ + } else { $_payPrice = $order->pay_price; $_order_rate = 0; //平台手续费 if ($order['commission_rate'] > 0) { - + $commission_rate = ($order['commission_rate'] / 100); - + $_order_rate = bcmul($_payPrice, $commission_rate, 2); - + $_payPrice = bcsub($_payPrice, $_order_rate, 2); // 结算各镇 小组佣金 // event('order.paySuccessOrder', compact('order', '_order_rate')); } } - + // bcsub($order->pay_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2); // if ($presell) { // if (isset($order->orderProduct[0]['cart_info']['presell_extension_one']) && $order->orderProduct[0]['cart_info']['presell_extension_one'] > 0) { @@ -368,7 +396,7 @@ class StoreOrderRepository extends BaseRepository if (!$presell) { - if ($order['commission_rate'] > 0 ||$order->source==103) { + if ($order['commission_rate'] > 0 || $order->source == 103) { $finance[] = [ 'order_id' => $order->order_id, 'order_sn' => $order->order_sn, @@ -390,18 +418,34 @@ class StoreOrderRepository extends BaseRepository $merchantRepo->forceMargin = false; [$_payPrice, $finance, $increase] = $merchantRepo->autoMargin($_payPrice, $order, $finance, $financeSn, $i++); } - $finance[] = [ - 'order_id' => $order->order_id, - 'order_sn' => $order->order_sn, - 'user_info' => $groupOrder->user->nickname, - 'user_id' => $uid, - 'financial_type' => 'order_true', - 'financial_pm' => 0, - 'type' => 2, - 'number' => $_payPrice, - 'mer_id' => $order->mer_id, - 'financial_record_sn' => $financeSn . ($i++) - ]; + if ($order->source == 103) { + $finance[] = [ + 'order_id' => $order->order_id, + 'order_sn' => $order->order_sn, + 'user_info' => $groupOrder->user->nickname, + 'user_id' => $uid, + 'financial_type' => 'commission_to_cloud_warehouse', + 'financial_pm' => 0, + 'type' => 1, + 'number' => $_payPrice, + 'mer_id' => $order->mer_id, + 'financial_record_sn' => $financeSn . ($i++) + ]; + } else { + $finance[] = [ + 'order_id' => $order->order_id, + 'order_sn' => $order->order_sn, + 'user_info' => $groupOrder->user->nickname, + 'user_id' => $uid, + 'financial_type' => 'order_true', + 'financial_pm' => 0, + 'type' => 2, + 'number' => $_payPrice, + 'mer_id' => $order->mer_id, + 'financial_record_sn' => $financeSn . ($i++) + ]; + } + // if ($order->platform_coupon_price > 0) { // $finance[] = [ @@ -469,23 +513,21 @@ class StoreOrderRepository extends BaseRepository if (count($groupOrder['give_coupon_ids']) > 0) $groupOrder['give_coupon_ids'] = app()->make(StoreCouponRepository::class)->getGiveCoupon($groupOrder['give_coupon_ids'])->column('coupon_id'); $groupOrder->save(); - $group_id=0; - if($order->activity_type==98){ - $group_id=Db::name('system_group')->where('group_key','city_operations')->value('group_id'); - }else{ - $group_id=Db::name('system_group')->where('group_key','town_operation')->value('group_id'); + $group_id = 0; + if ($order->activity_type == 98) { + $group_id = Db::name('system_group')->where('group_key', 'city_operations')->value('group_id'); + } else { + $group_id = Db::name('system_group')->where('group_key', 'town_operation')->value('group_id'); } - if($group_id){ - $group_value=Db::name('system_group_data')->where('group_id',$group_id)->column('value'); - if($group_value){ - foreach($group_value as $k=>$v){ - $phone=json_decode($v,true); - Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'phone' => $phone['phone'],'orderId'=>$order->order_id,'id'=>0]);//短信通知 + if ($group_id) { + $group_value = Db::name('system_group_data')->where('group_id', $group_id)->column('value'); + if ($group_value) { + foreach ($group_value as $k => $v) { + $phone = json_decode($v, true); + Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'phone' => $phone['phone'], 'orderId' => $order->order_id, 'id' => 0]); //短信通知 } } - } - }); if (count($groupOrder['give_coupon_ids']) > 0) { @@ -568,7 +610,7 @@ class StoreOrderRepository extends BaseRepository } } - public function cartByPrice($cart,$type=0) + public function cartByPrice($cart, $type = 0) { if ($cart['product_type'] == '2') { return $cart['productPresellAttr']['presell_price']; @@ -578,10 +620,10 @@ class StoreOrderRepository extends BaseRepository return $cart['activeSku']['active_price']; // 更新调货价格 } else if ($cart['product_type'] == '98') { - if($type==1){ + if ($type == 1) { return $cart['productAttr']['procure_price']; - }else{ - if (in_array($cart['source'],[9,10,11,12,13])) { + } else { + if (in_array($cart['source'], [9, 10, 11, 12, 13])) { return $cart['productAttr']['procure_price']; } else { return $cart['productAttr']['price']; @@ -601,9 +643,9 @@ class StoreOrderRepository extends BaseRepository return $cart['productAttr']['price']; } } else { - if($type==0){ + if ($type == 0) { return $cart['productAttr']['price']; - }else{ + } else { return $cart['productAttr']['procure_price']; } } @@ -656,7 +698,7 @@ class StoreOrderRepository extends BaseRepository * @author xaboy * @day 2020/6/10 */ - public function userOrderNumber(int $uid, $product_type = 0,$source=2) + public function userOrderNumber(int $uid, $product_type = 0, $source = 2) { //activity_type:0普通订单 98采购订单 99委托商品 //$noPay = app()->make(StoreGroupOrderRepository::class)->orderNumber($uid, $product_type); @@ -664,10 +706,10 @@ class StoreOrderRepository extends BaseRepository if ($product_type == 98 || $product_type == 99) { $isUser = 0; } - $where['activity_type']=$product_type; - if($source==103){ - $where['activity_type']=[0,98]; - $where['source']=[0,2,103]; + $where['activity_type'] = $product_type; + if ($source == 103) { + $where['activity_type'] = [0, 98]; + $where['source'] = [0, 2, 103]; } $noComment = $this->dao->search(['uid' => $uid, 'is_user' => $isUser])->where($this->getOrderType(4))->where($where)->where('StoreOrder.is_del', 0)->count(); $noPay = $this->dao->search(['uid' => $uid, 'is_user' => $isUser])->where($this->getOrderType(1))->whereRaw("(StoreOrder.paid=0 and StoreOrder.pay_type!=8) or (StoreOrder.paid=1 and StoreOrder.pay_type=8 and StoreOrder.status=2)")->where($where)->where('StoreOrder.is_del', 0)->count(); @@ -1516,10 +1558,10 @@ class StoreOrderRepository extends BaseRepository ] ); if (!$res) throw new ValidateException('数据不存在'); - if(in_array($res['source'],[13])){ - $res['bank_info']=Db::name('merchant_intention')->where('status',1)->where('uid',$res['uid'])->field('company_name,bank_username,bank_opening,bank_code')->find(); - }else{ - $res['bank_info']=[]; + if (in_array($res['source'], [13])) { + $res['bank_info'] = Db::name('merchant_intention')->where('status', 1)->where('uid', $res['uid'])->field('company_name,bank_username,bank_opening,bank_code')->find(); + } else { + $res['bank_info'] = []; } $res['integral'] = (int)$res['integral']; @@ -2540,10 +2582,10 @@ class StoreOrderRepository extends BaseRepository $attr = []; $arr = []; - if(!$attr_one){ + if (!$attr_one) { $attr_one[] = '规格'; } - if(!$attr_two){ + if (!$attr_two) { $attr_two[] = '默认'; } foreach ($attr_one as $key => $value) { @@ -2604,9 +2646,9 @@ class StoreOrderRepository extends BaseRepository $detail = $attr; /**查询平台分类 */ - $cate_id_one = Db::name('store_category')->where('is_show',1)->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_one'])->value('store_category_id'); + $cate_id_one = Db::name('store_category')->where('is_show', 1)->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_one'])->value('store_category_id'); if ($cate_id_one) { - $cate_id_two = Db::name('store_category')->where('is_show',1)->where('mer_id', 0)->where('pid',$cate_id_one)->where('cate_name', $datum['value']['cate_id_two'])->value('store_category_id'); + $cate_id_two = Db::name('store_category')->where('is_show', 1)->where('mer_id', 0)->where('pid', $cate_id_one)->where('cate_name', $datum['value']['cate_id_two'])->value('store_category_id'); if ($cate_id_two) { $cate_id = $cate_id_two; } @@ -2710,7 +2752,7 @@ class StoreOrderRepository extends BaseRepository "ot_price" => $datum['value']['price'], "svip_price" => null, "procure_price" => $procure_price, - "stock" =>$datum['value']['stock']??1, + "stock" => $datum['value']['stock'] ?? 1, "bar_code" => (int)$datum['value']['bar_code'], "weight" => 0, "volume" => 0, @@ -2738,7 +2780,6 @@ class StoreOrderRepository extends BaseRepository } } return true; - } catch (\Exception $e) { $datas['product_id'] = $product_id ?? 0; $datas['mer_id'] = $merId; @@ -2766,7 +2807,7 @@ class StoreOrderRepository extends BaseRepository if (!empty($datum['value']['procure_price'])) { $procure_price = $datum['value']['procure_price']; } - $stock=$datum['value']['stock']??1; + $stock = $datum['value']['stock'] ?? 1; $attrValue['stock'] = $stock; $unique = app(ProductRepository::class)->setUnique($find['product_id'], $datum['value']['bar_code'], $product_type); $attrValue['unique'] = $unique; @@ -2779,7 +2820,7 @@ class StoreOrderRepository extends BaseRepository $attrValue['price'] = $datum['value']['price']; $attrValue['procure_price'] = $procure_price; $attrValue["image"] = "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png"; - Db::name('store_product')->where('product_id',$find['product_id'])->update(['spec_type'=>1,'stock'=>Db::raw('stock+'.$stock)]); + Db::name('store_product')->where('product_id', $find['product_id'])->update(['spec_type' => 1, 'stock' => Db::raw('stock+' . $stock)]); Db::name('store_product_attr_value')->insert($attrValue); } /** diff --git a/app/common/repositories/system/merchant/FinancialRecordRepository.php b/app/common/repositories/system/merchant/FinancialRecordRepository.php index c5f26e99..817ceeb3 100644 --- a/app/common/repositories/system/merchant/FinancialRecordRepository.php +++ b/app/common/repositories/system/merchant/FinancialRecordRepository.php @@ -714,13 +714,10 @@ class FinancialRecordRepository extends BaseRepository //平台手续费 =( order_charge + 预售手续费 presell_charge - 平台退给商户的手续费 refund_charge ) $number_1 = bcsub($data['number_order_charge'], $data['number_charge'], 2); if($data['number_supply_chain']>0){ - $financialType = ['order_true']; - $where['type']=2; - $where['mer_id']=$where['is_mer']; - unset($where['is_mer']); - [$data['count_order'], $data['number_order']] = $this->dao->getDataByType($type, $where, $date, $financialType); + $financialType = ['commission_to_cloud_warehouse']; + [$data['count_commission_to_cloud_warehouse'], $data['number_commission_to_cloud_warehouse']] = $this->dao->getDataByType($type, $where, $date, $financialType); $number_1=bcadd($number_1, $data['number_supply_chain'], 2); - $number_1=bcsub( $number_1, $data['number_order'], 2); + $number_1=bcsub( $number_1, $data['number_commission_to_cloud_warehouse'], 2); } //退回收入 refund_order + 退回佣金 diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index ad037fe1..002f1fda 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -687,9 +687,9 @@ class MerchantRepository extends BaseRepository public function autoMargin($income, $order, $finance, $financeSn, $index = 0) { $merchant = Merchant::find($this->merId); - $margin_type = Db::name('MerchantType')->where('mer_type_id', $merchant['type_id'])->value('margin'); + // $margin_type = Db::name('MerchantType')->where('mer_type_id', $merchant['type_id'])->value('margin'); //商户押金大于支付押金 或者forceMargin==false 直接返回 不计算押金 - if ($merchant['paid_margin']>= $margin_type|| ($this->forceMargin === false && $merchant['auto_margin_rate'] == 0)) { + if ($merchant['paid_margin']>= $merchant['margin']|| ($this->forceMargin === false && $merchant['auto_margin_rate'] == 0)) { return [$income, $finance, false]; } $rate = $this->forceMargin ? 100 : $merchant['auto_margin_rate']; @@ -712,7 +712,7 @@ class MerchantRepository extends BaseRepository 'mer_id' => $this->merId, 'financial_record_sn' => $financeSn . $index ]; - if(bcadd($merchant['paid_margin'],$margin)>=$margin_type){ + if(bcadd($merchant['paid_margin'],$margin)>=$merchant['margin']){ $is_margin=10; }else{ $is_margin=1; diff --git a/crmeb/services/ExcelService.php b/crmeb/services/ExcelService.php index ea30dad9..a8a7b79d 100644 --- a/crmeb/services/ExcelService.php +++ b/crmeb/services/ExcelService.php @@ -366,8 +366,8 @@ class ExcelService 'commission_to_village_refund' => '退回平台佣金', 'commission_to_town_refund' => '退回平台佣金', 'auto_margin_refund' => '退回押金', - 'commission_to_entry_merchant' => '订单平台佣金', - 'commission_to_cloud_warehouse' => '订单平台佣金', + 'commission_to_entry_merchant' => '订单平台佣金',//入口店铺佣金 + 'commission_to_cloud_warehouse' => '订单平台佣金',//云仓佣金 'commission_to_entry_merchant_refund' => '退回平台佣金', 'commission_to_cloud_warehouse_refund' => '退回平台佣金', 'first_order_commission' => '首单拉新', From 3a7e8e71b7c9ff3fe3f063e5bed3a839a3d35c42 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 20 Jan 2024 15:34:57 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 32 +++++++++++++------ crmeb/services/ExcelService.php | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index ddd36ac4..64f527ac 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -331,28 +331,40 @@ class StoreOrderRepository extends BaseRepository //市级供应链 $product_mer_id = Db::name('store_order_product')->where('order_id', $order->order_id)->value('product_mer_id'); if ($product_mer_id) { - //市级供应链押金计算 - if ($_payPrice > 0) { - /** @var MerchantRepository $merchantRepo */ - $merchantRepo = app()->make(MerchantRepository::class); - $merchantRepo->merId = $product_mer_id; - $merchantRepo->forceMargin = false; - [$_payPrice, $a, $increase] = $merchantRepo->autoMargin($_payPrice, $order, $finance, $financeSn, $i++); - } $finance[] = [ 'order_id' => $order->order_id, 'order_sn' => $order->order_sn, 'user_info' => $groupOrder->user->nickname, 'user_id' => $uid, - 'financial_type' => 'supply_chain', + 'financial_type' => 'order', 'financial_pm' => 0, 'type' => 1, 'number' => $_payPrice, 'mer_id' => $product_mer_id, 'financial_record_sn' => $financeSn . (($i++)+1) + ]; + //市级供应链押金计算 + if ($_payPrice > 0) { + /** @var MerchantRepository $merchantRepo */ + $merchantRepo = app()->make(MerchantRepository::class); + $merchantRepo->merId = $product_mer_id; + $merchantRepo->forceMargin = false; + [$_payCityPrice, $finance, $increase] = $merchantRepo->autoMargin($_payPrice, $order, $finance, $financeSn, $i++); + } + $finance[] = [ + 'order_id' => $order->order_id, + 'order_sn' => $order->order_sn, + 'user_info' => $groupOrder->user->nickname, + 'user_id' => $uid, + 'financial_type' => 'order_true', + 'financial_pm' => 0, + 'type' => 1, + 'number' => $_payCityPrice, + 'mer_id' => $product_mer_id, + 'financial_record_sn' => $financeSn . (($i++)+2) ]; if (!$is_combine) { - app()->make(MerchantRepository::class)->addLockMoney($product_mer_id, 'order', $order->order_id, $_payPrice); + app()->make(MerchantRepository::class)->addLockMoney($product_mer_id, 'order', $order->order_id, $_payCityPrice); } } diff --git a/crmeb/services/ExcelService.php b/crmeb/services/ExcelService.php index a8a7b79d..9afd75f2 100644 --- a/crmeb/services/ExcelService.php +++ b/crmeb/services/ExcelService.php @@ -373,7 +373,7 @@ class ExcelService 'first_order_commission' => '首单拉新', ]; $sys_pm_1 = ['first_order_commission','supply_chain','order', 'presell', 'order_charge', 'order_presell', 'presell_charge', 'refund_brokerage_one', 'refund_brokerage_two', 'commission_to_platform']; - $mer_pm_1 = ['order', 'presell', 'refund_brokerage_one', 'refund_brokerage_two', 'mer_presell', + $mer_pm_1 = ['order_true','order', 'presell', 'refund_brokerage_one', 'refund_brokerage_two', 'mer_presell', 'order_platform_coupon', 'commission_to_cloud_warehouse', 'commission_to_entry_merchant', 'commission_to_town', 'commission_to_village', 'commission_to_service_team']; $date_ = $where['date']; unset($where['date']); From 49e8327ac8596665635aea42773dc2e6a6f0f335 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 20 Jan 2024 15:37:11 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/services/ExcelService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crmeb/services/ExcelService.php b/crmeb/services/ExcelService.php index 9afd75f2..28e1264c 100644 --- a/crmeb/services/ExcelService.php +++ b/crmeb/services/ExcelService.php @@ -372,8 +372,8 @@ class ExcelService 'commission_to_cloud_warehouse_refund' => '退回平台佣金', 'first_order_commission' => '首单拉新', ]; - $sys_pm_1 = ['first_order_commission','supply_chain','order', 'presell', 'order_charge', 'order_presell', 'presell_charge', 'refund_brokerage_one', 'refund_brokerage_two', 'commission_to_platform']; - $mer_pm_1 = ['order_true','order', 'presell', 'refund_brokerage_one', 'refund_brokerage_two', 'mer_presell', + $sys_pm_1 = ['auto_margin','order', 'presell', 'order_charge', 'order_presell', 'presell_charge', 'refund_brokerage_one', 'refund_brokerage_two', 'commission_to_platform']; + $mer_pm_1 = ['first_order_commission','order_true','order', 'presell', 'refund_brokerage_one', 'refund_brokerage_two', 'mer_presell', 'order_platform_coupon', 'commission_to_cloud_warehouse', 'commission_to_entry_merchant', 'commission_to_town', 'commission_to_village', 'commission_to_service_team']; $date_ = $where['date']; unset($where['date']); From 22a326303cfefd00ae797c0f3715b5ca1ca8b9ac Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 20 Jan 2024 16:03:26 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/system/merchant/MerchantDao.php.bak | 294 ------------------ .../store/order/StoreOrderRepository.php | 2 +- 2 files changed, 1 insertion(+), 295 deletions(-) delete mode 100644 app/common/dao/system/merchant/MerchantDao.php.bak diff --git a/app/common/dao/system/merchant/MerchantDao.php.bak b/app/common/dao/system/merchant/MerchantDao.php.bak deleted file mode 100644 index f8618203..00000000 --- a/app/common/dao/system/merchant/MerchantDao.php.bak +++ /dev/null @@ -1,294 +0,0 @@ - -// +---------------------------------------------------------------------- - - -namespace app\common\dao\system\merchant; - - -use app\common\dao\BaseDao; -use app\common\model\system\merchant\Merchant; -use crmeb\services\VicWordService; -use think\db\BaseQuery; -use think\db\exception\DataNotFoundException; -use think\db\exception\DbException; -use think\db\exception\ModelNotFoundException; -use think\facade\Db; -use think\Model; - -class MerchantDao extends BaseDao -{ - - /** - * @return string - * @author xaboy - * @day 2020-04-16 - */ - protected function getModel(): string - { - return Merchant::class; - } - - /** - * @param array $where - * @return BaseQuery - * @author xaboy - * @day 2020-04-16 - */ - public function search(array $where, $is_del = 0) - { - $query = Merchant::getDB() - ->when($is_del !== null, function ($query) use ($is_del) { - $query->where('is_del', $is_del); - }) - ->when(isset($where['is_trader']) && $where['is_trader'] !== '', function ($query) use ($where) { - $query->where('is_trader', $where['is_trader']); - }) - ->when(isset($where['is_best']) && $where['is_best'] !== '', function ($query) use ($where) { - $query->where('is_best', $where['is_best']); - }) - ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) { - getModelTime($query, $where['date']); - }) - ->when(isset($where['mer_state']) && $where['mer_state'] !== '', function ($query) use ($where) { - $query->where('mer_state', $where['mer_state']); - }) - ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) { - $query->where('mer_id', $where['mer_id']); - }) - ->when(isset($where['category_id']) && $where['category_id'] !== '', function ($query) use ($where) { - $query->whereIn('category_id', is_array($where['category_id']) ? $where['category_id'] : explode(',', $where['category_id'])); - }) - ->when(isset($where['type_id']) && $where['type_id'] !== '', function ($query) use ($where) { - $query->whereIn('type_id', is_array($where['type_id']) ? $where['type_id'] : explode(',', $where['type_id'])); - }) - ->when(isset($where['delivery_way']) && $where['delivery_way'] !== '', function ($query) use ($where) { - $query->whereLike('delivery_way', "%{$where['delivery_way']}%"); - }); - - - if (isset($where['keyword']) && $where['keyword']) { - if (is_numeric($where['keyword'])) { - $query->whereLike('mer_name|mer_keyword|mer_phone', "%{$where['keyword']}%"); - } else { - $word = app()->make(VicWordService::class)->getWord($where['keyword']); - $query->where(function ($query) use ($word, $where) { - foreach ($word as $item) { - if(mb_strlen($item) > 1) { - $query->whereOr('mer_name', 'LIKE', "%$item%"); - } - } - $query->whereOr('mer_name|mer_keyword', 'LIKE', "%{$where['keyword']}%"); - }); - } - } - if (isset($where['status']) && $where['status'] !== '') - $query->where('status', $where['status']); - $order = $where['order'] ?? ''; - $query->when($order, function ($query) use ($where, $order) { - if ($order == 'rate') { - $query->order('is_best DESC, product_score DESC,service_score DESC,postage_score DESC'); - } else if ($order == 'location' && isset($where['location']['long'], $where['location']['lat'])) { - $lng = (float)$where['location']['long']; - $lat = (float)$where['location']['lat']; - $query->whereNotNull('lat')->whereNotNull('long') - ->order(Db::raw("(2 * 6378.137 * ASIN( - SQRT( - POW( SIN( PI( ) * ( $lng- `long` ) / 360 ), 2 ) + COS( PI( ) * $lat / 180 ) * COS( `lat` * PI( ) / 180 ) * POW( SIN( PI( ) * ( $lat- `lat` ) / 360 ), 2 ) - ) - ) - ) ASC ")); - } else { - $query->order('is_best DESC, sales DESC,sort DESC'); - } - }, function ($query) use ($order) { - $query->order('is_best DESC, sort DESC,sales DESC'); - }); - return $query; - } - - /** - * @param int $id - * @return array|Model|null - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - * @author xaboy - * @day 2020-04-17 - */ - public function get($id) - { - return Merchant::getInstance()->where('is_del', 0)->find($id); - } - - /** - * @param $id - * @author Qinii - */ - public function apiGetOne($id) - { - return Merchant::getInstance()->where(['is_del' => 0, 'status' => 1, 'mer_state' => 1])->find($id); - } - - /** - * @param int $merId - * @author Qinii - */ - public function incCareCount(int $merId) - { - ($this->getModel()::getDB())->where($this->getPk(), $merId)->inc('care_count', 1)->update(); - } - - /** - * @param int $merId - * @param int $inc - * @author xaboy - * @day 2020/9/25 - */ - public function incSales($merId, $inc) - { - ($this->getModel()::getDB())->where($this->getPk(), $merId)->inc('sales', $inc)->update(); - } - - /** - * @param int $merId - * @author Qinii - */ - public function decCareCount(array $merId) - { - ($this->getModel()::getDB())->whereIn($this->getPk(), $merId)->where('care_count', '>', 0)->dec('care_count', 1)->update(); - } - - public function dateMerchantNum($date) - { - return Merchant::getDB()->where('is_del', 0)->when($date, function ($query, $date) { - getModelTime($query, $date); - })->count(); - } - - /** - * TODO 获取复制商品次数 - * @param int $merId - * @return mixed - * @author Qinii - * @day 2020-08-06 - */ - public function getCopyNum(int $merId) - { - return Merchant::getDB()->where('mer_id', $merId)->value('copy_product_num'); - } - - /** - * TODO 变更复制次数 - * @param int $merId - * @param int $num 正负数 - * @return mixed - * @author Qinii - * @day 2020-08-06 - */ - public function changeCopyNum(int $merId, int $num) - { - return $this->getModel()::where('mer_id', $merId)->inc('copy_product_num', $num)->update(); - } - - /** - * @param $field - * @param $value - * @param int|null $except - * @return bool - * @author xaboy - * @day 2020-03-30 - */ - public function fieldExists($field, $value, ?int $except = null): bool - { - $query = ($this->getModel())::getDB()->where($field, $value); - if (!is_null($except)) $query->where($this->getPk(), '<>', $except); - return $query->where('is_del', 0)->count() > 0; - } - - public function names(array $ids) - { - return Merchant::getDB()->whereIn('mer_id',$ids)->column('mer_name'); - } - - /** - * TODO 增加商户余额 - * @param int $merId - * @param float $num - * @author Qinii - * @day 3/19/21 - */ - public function addMoney(int $merId, float $num) - { - $field = 'mer_money'; - $merchant = $this->getModel()::getDB()->where('mer_id', $merId)->find(); - if ($merchant) { - $mer_money = bcadd($merchant[$field], $num, 2); - $merchant[$field] = $mer_money; - $merchant->save(); - } - } - - /** - * TODO 减少商户余额 - * @param int $merId - * @param float $num - * @author Qinii - * @day 3/19/21 - */ - public function subMoney(int $merId, float $num) - { - $field = 'mer_money'; - $merchant = $this->getModel()::getDB()->where('mer_id', $merId)->find(); - if ($merchant) { - $mer_money = bcsub($merchant[$field], $num, 2); - $merchant[$field] = $mer_money; - $merchant->save(); - } - } - - public function clearTypeId(int $typeId) - { - return Merchant::getDB()->where('type_id', $typeId)->update(['type_id' => 0]); - } - - public function addFieldNum(int $merId, int $num, string $field) - { - if ($num < 0) $num = -$num; - $merchant = $this->getModel()::getDB()->where('mer_id', $merId)->find(); - $number = $merchant[$field] + $num; - $merchant[$field] = $number; - $merchant->save(); - } - - public function sumFieldNum(int $merId, int $num, string $field) - { - if ($num < 0) $num = -$num; - $merchant = $this->getModel()::getDB()->where('mer_id', $merId)->find(); - $number = $merchant[$field] - $num; - $merchant[$field] = $number; - $merchant->save(); - } - - public function merIdByImage($merIds) - { - return $this->getModel()::getDB()->whereIn('mer_id', $merIds)->column('mer_id,mer_avatar'); - } - - public function updateMargin($typeId, $margin, $is_margin) - { - return $this->getModel()::where('type_id',$typeId)->where('is_margin','in',[0,1])->update([ - 'is_margin' => $is_margin, - 'margin' => $margin - ]); - } - -} diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 64f527ac..9f82fea9 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -358,7 +358,7 @@ class StoreOrderRepository extends BaseRepository 'user_id' => $uid, 'financial_type' => 'order_true', 'financial_pm' => 0, - 'type' => 1, + 'type' => 2, 'number' => $_payCityPrice, 'mer_id' => $product_mer_id, 'financial_record_sn' => $financeSn . (($i++)+2)