优惠卷仅可用于自选项目

main
yanzai 1 year ago
parent 207f3e8180
commit f07dab03f3

@ -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;
}
}
}

@ -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];
}
}

Loading…
Cancel
Save