From f07dab03f31915f8bbc92a8f45b1ff4084ae8e5c Mon Sep 17 00:00:00 2001 From: yanzai Date: Thu, 31 Oct 2024 23:12:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=8D=B7=E4=BB=85=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E8=87=AA=E9=80=89=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/API/H5/ComboController.php | 115 ++++++++++-------- .../Controllers/API/H5/OrderController.php | 105 +++++++++------- 2 files changed, 121 insertions(+), 99 deletions(-) diff --git a/Laravel/app/Http/Controllers/API/H5/ComboController.php b/Laravel/app/Http/Controllers/API/H5/ComboController.php index c6d38b8..9e2f1b2 100644 --- a/Laravel/app/Http/Controllers/API/H5/ComboController.php +++ b/Laravel/app/Http/Controllers/API/H5/ComboController.php @@ -367,10 +367,14 @@ select combo_id as c_id,count(*) as sale_count from orders where status in(2,4) } } if(isset($wj_flag) and $wj_flag==1){ - $item_price=$item_price*$wj_zhekou; - + $item_price=number_format($item_price*$wj_zhekou, 2, '.', '') ; + } + //使用优惠券 + if(isset($coupon_id) and !empty($coupon_id)){ + if($item_price==0) return \Yz::echoError1("自选项目金额为0,无需使用优惠券"); + $item_price=$this->useYouHuiQuan($item_price,$person,$coupon_id); } - $items_info['price'] =number_format($item_price, 2, '.', '') ; + $items_info['price'] =$item_price; $items_info['original_price'] = $items_original_price; foreach ($groupedData as $keshiName => $children) { $items_info['items'][] = [ @@ -463,57 +467,7 @@ select combo_id as c_id,count(*) as sale_count from orders where status in(2,4) ]; } - $env=config('app.globals.Env'); - //如果使用了代金券 - if(isset($coupon_id) and !empty($coupon_id)){ - if($true_price==0) return \Yz::echoError1("无需使用代金券"); - $quanInfo=false; - - if($env=='pro') { //如果是正式环境 - $AspNet=new AspNetZhuanController(); - - $data=[ - 'ghzid'=>$person->ghzid, - 'action'=>1, - ]; - $YouHuiQuanList=$AspNet::YouHuiQuan($data); - foreach ($YouHuiQuanList as $key=>$quan){ - if($quan['DZJID']==$coupon_id){ - $quanInfo=$quan; - } - } - - if(!!$quanInfo and $quanInfo['是否在有效内']===true and $quanInfo['TimeNuZTTextm']=="有效" and $quanInfo['ZT']==1){ - - }else{ - return \Yz::echoError1("此代金券不可用"); - } - - $quanType=false; - $YouHuiQuanType=$AspNet::YouHuiQuan(['action'=>2]); - foreach ($YouHuiQuanType as $key=>$type){ - if($quanInfo['DZJLBID']==$type['DZJLBID']){ - $quanType=$type; - } -// if($type['TJXCXHX']==1 and ($type['MKJE']===0 || $type['MKJE']>=$true_price)){ -// $YouHuiQuanType_ids[]=$type['DZJLBID']; -// } - } - if($quanType===false or $quanInfo===false) return \Yz::echoError1("此代金券不可用"); - if($quanType['TJXCXHX']!=1 ) return \Yz::echoError1("此代金券不可用"); - if($quanType['MKJE']==0 or $quanType['MKJE']>=$true_price){ - //抵扣代金券金额 - if($quanType['YHLX']==1){//抵扣券 - $true_price=($true_price-$quanInfo['JE'])>0 ? $true_price-$quanInfo['JE']:0; - } - if($quanType['YHLX']==2){//抵扣券 - $true_price=number_format($true_price*$quanType['DZBL'],2, '.', ''); - } - - } - } - } $data = [ @@ -643,6 +597,7 @@ select combo_id as c_id,count(*) as count from orders where status in(2,4) group return \Yz::Return(true, "查询完成", ['combos' => $list]); } + function jaccard_similarity($set1, $set2) { // 计算交集 $intersection = array_intersect($set1, $set2); @@ -655,4 +610,58 @@ select combo_id as c_id,count(*) as count from orders where status in(2,4) group // 返回Jaccard相似度 return count($intersection) / count($union); } + //使用优惠券 + public function useYouHuiQuan($true_price,$person,$coupon_id){ + $env=config('app.globals.Env'); + //如果使用了代金券 + if(isset($coupon_id) and !empty($coupon_id)){ + if($true_price==0) return \Yz::echoError1("无需使用代金券"); + $quanInfo=false; + + if($env=='pro') { //如果是正式环境 + $AspNet=new AspNetZhuanController(); + + $data=[ + 'ghzid'=>$person->ghzid, + 'action'=>1, + ]; + $YouHuiQuanList=$AspNet::YouHuiQuan($data); + foreach ($YouHuiQuanList as $key=>$quan){ + if($quan['DZJID']==$coupon_id){ + $quanInfo=$quan; + } + } + + if(!!$quanInfo and $quanInfo['是否在有效内']===true and $quanInfo['TimeNuZTTextm']=="有效" and $quanInfo['ZT']==1){ + + }else{ + return \Yz::echoError1("此代金券不可用"); + } + + $quanType=false; + $YouHuiQuanType=$AspNet::YouHuiQuan(['action'=>2]); + foreach ($YouHuiQuanType as $key=>$type){ + if($quanInfo['DZJLBID']==$type['DZJLBID']){ + $quanType=$type; + } +// if($type['TJXCXHX']==1 and ($type['MKJE']===0 || $type['MKJE']>=$true_price)){ +// $YouHuiQuanType_ids[]=$type['DZJLBID']; +// } + } + if($quanType===false or $quanInfo===false) return \Yz::echoError1("此代金券不可用"); + if($quanType['TJXCXHX']!=1 ) return \Yz::echoError1("此代金券不可用"); + if($quanType['MKJE']==0 or $quanType['MKJE']>=$true_price){ + //抵扣代金券金额 + if($quanType['YHLX']==1){//抵扣券 + $true_price=($true_price-$quanInfo['JE'])>0 ? $true_price-$quanInfo['JE']:0; + } + if($quanType['YHLX']==2){//抵扣券 + $true_price=number_format($true_price*$quanType['DZBL'],2, '.', ''); + } + + } + } + return $true_price; + } + } } diff --git a/Laravel/app/Http/Controllers/API/H5/OrderController.php b/Laravel/app/Http/Controllers/API/H5/OrderController.php index 3138ee1..9ba7dc5 100644 --- a/Laravel/app/Http/Controllers/API/H5/OrderController.php +++ b/Laravel/app/Http/Controllers/API/H5/OrderController.php @@ -114,6 +114,7 @@ class OrderController extends Controller if (!$person) return \Yz::echoError1('体检人不存在'); $title = "自选项目"; $price = 0; + $quanInfo=false; $true_price = 0;//订单真实支付金额 $buy_info = [ 'combo' => [ @@ -208,6 +209,14 @@ class OrderController extends Controller if (isset($wj_flag) and $wj_flag == 1) { $item_price = $item_price * $wj_zhekou; } + //使用优惠券 + if (isset($coupon_id) and !empty($coupon_id)) { + if($item_price==0) return \Yz::echoError1("自选项目金额为0,无需使用优惠券"); + $use_quan=$this->useYouHuiQuan($item_price,$person,$coupon_id); + $quanInfo=$use_quan['quanInfo']; + $item_price=$use_quan['price']; + } + $price += $item_price; $missingIds = array_diff($item_ids, $existingIds); if (count($missingIds) > 0) return \Yz::echoError1("部分自选项目不可用,Id:" . implode(', ', $missingIds)); @@ -341,53 +350,7 @@ class OrderController extends Controller if ($true_price < -1) return \Yz::echoError1("预抵扣金额超过订单金额,操作失败"); if ($true_price < 0) $true_price = 0; - //如果使用了代金券 - $quanInfo = false; - if (isset($coupon_id) and !empty($coupon_id)) { - if ($true_price == 0) return \Yz::echoError1("无需使用代金券"); - - $AspNet = new AspNetZhuanController(); - $data = [ - 'ghzid' => $person->ghzid, - 'action' => 1, - ]; - $YouHuiQuanList = $AspNet::YouHuiQuan($data); - foreach ($YouHuiQuanList as $key => $quan) { - if ($quan['DZJID'] == $coupon_id) { - $quanInfo = $quan; - } - } - - if ($quanInfo['是否在有效内'] === true and $quanInfo['TimeNuZTTextm'] == "有效" and $quanInfo['ZT'] == 1) { - - } else { - return \Yz::echoError1("此代金券不可用"); - } - - $quanType = false; - $YouHuiQuanType = $AspNet::YouHuiQuan(['action' => 2]); - foreach ($YouHuiQuanType as $key => $qtype) { - if ($quanInfo['DZJLBID'] == $qtype['DZJLBID']) { - $quanType = $qtype; - } -// if($qtype['TJXCXHX']==1 and ($qtype['MKJE']===0 || $qtype['MKJE']>=$true_price)){ -// $YouHuiQuanType_ids[]=$qtype['DZJLBID']; -// } - } - if ($quanType === false or $quanInfo === false) return \Yz::echoError1("此代金券不可用"); - if ($quanType['TJXCXHX'] != 1) return \Yz::echoError1("此代金券不可用"); - if ($quanType['MKJE'] == 0 or $quanType['MKJE'] >= $true_price) { - //抵扣代金券金额 - if($quanType['YHLX']==1){//抵扣券 - $true_price=($true_price-$quanInfo['JE'])>0 ? $true_price-$quanInfo['JE']:0; - } - if($quanType['YHLX']==2){//抵扣券 - $true_price=number_format($true_price*$quanType['DZBL'],2, '.', ''); - } - } - - } if (isset($plan_nmr_info) and !empty($plan_nmr_info)) { $plan_nmr_temp = []; foreach ($plan_nmr_info as $key => $plan_nmr) { @@ -822,4 +785,54 @@ class OrderController extends Controller $info = $peis::Post($url_code, $hospital, $data); return $info; } + public function useYouHuiQuan($true_price,$person,$coupon_id){ + //如果使用了代金券 + $quanInfo = false; + if (isset($coupon_id) and !empty($coupon_id)) { + if ($true_price == 0) return \Yz::echoError1("无需使用代金券"); + + $AspNet = new AspNetZhuanController(); + $data = [ + 'ghzid' => $person->ghzid, + 'action' => 1, + ]; + $YouHuiQuanList = $AspNet::YouHuiQuan($data); + foreach ($YouHuiQuanList as $key => $quan) { + if ($quan['DZJID'] == $coupon_id) { + $quanInfo = $quan; + } + } + + if ($quanInfo['是否在有效内'] === true and $quanInfo['TimeNuZTTextm'] == "有效" and $quanInfo['ZT'] == 1) { + + } else { + return \Yz::echoError1("此代金券不可用"); + } + + $quanType = false; + $YouHuiQuanType = $AspNet::YouHuiQuan(['action' => 2]); + foreach ($YouHuiQuanType as $key => $qtype) { + if ($quanInfo['DZJLBID'] == $qtype['DZJLBID']) { + $quanType = $qtype; + } +// if($qtype['TJXCXHX']==1 and ($qtype['MKJE']===0 || $qtype['MKJE']>=$true_price)){ +// $YouHuiQuanType_ids[]=$qtype['DZJLBID']; +// } + } + if ($quanType === false or $quanInfo === false) return \Yz::echoError1("此代金券不可用"); + if ($quanType['TJXCXHX'] != 1) return \Yz::echoError1("此代金券不可用"); + if ($quanType['MKJE'] == 0 or $quanType['MKJE'] >= $true_price) { + //抵扣代金券金额 + if($quanType['YHLX']==1){//抵扣券 + $true_price=($true_price-$quanInfo['JE'])>0 ? $true_price-$quanInfo['JE']:0; + } + if($quanType['YHLX']==2){//抵扣券 + $true_price=number_format($true_price*$quanType['DZBL'],2, '.', ''); + } + } + + + } + return ['price'=>$true_price,'quanInfo'=>$quanInfo]; + } }