作者 jinglong
1 个管道 的构建 通过 耗费 1 秒

修改结算优惠券

@@ -398,85 +398,61 @@ class Cars extends Api @@ -398,85 +398,61 @@ class Cars extends Api
398 $res1 = Common::selectSoftWhereData('goods',['id'=>['in',$goods_id_s],'type'=>$flag[1]],'id,t_id'); 398 $res1 = Common::selectSoftWhereData('goods',['id'=>['in',$goods_id_s],'type'=>$flag[1]],'id,t_id');
399 $b_id_s = array_unique(array_values(array_column($res1,'t_id'))); 399 $b_id_s = array_unique(array_values(array_column($res1,'t_id')));
400 400
401 - //普通商品  
402 - $where1['bg_id'] = ['in',$goods_id_s];  
403 - $where1['type'] = $type[2];  
404 -  
405 $time = time(); 401 $time = time();
406 $where['id'] = ['in',$receive_s]; 402 $where['id'] = ['in',$receive_s];
407 $where['end_time'] = ['>',$time]; 403 $where['end_time'] = ['>',$time];
408 404
409 - //包含品牌中的商品  
410 - if(!empty($b_id_s)){  
411 - $where2['bg_id'] = ['in',$b_id_s];  
412 - $where2['type'] = $type[1];  
413 - $data = Common::selectWhereOrData('coupon',$where,$where1,$where2,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','sort desc,id desc');  
414 - }else{  
415 - $data = Common::selectWhereOrData1('coupon',$where,$where1,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','sort desc,id desc');  
416 - } 405 + $data = Common::selectWhereData('coupon',$where,'id,type,coupon_name,c_type,bg_id,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','sort desc,id desc');
  406 +
417 $res = []; 407 $res = [];
418 $key = 0; 408 $key = 0;
419 foreach($data as $value){ 409 foreach($data as $value){
420 $key+=0; 410 $key+=0;
421 - //无门槛,有门槛  
422 - if($value['c_type'] == 0){  
423 - $res[$key]['id'] = $value['id'];  
424 - //无门槛  
425 - if($value['coupon_type'] == 0){  
426 - //减少券,去掉满减金额,折扣字段,  
427 - unset($value['full_reduce']);  
428 - unset($value['discount']);  
429 - $res[$key]['coupon_tag'] = '无门槛';  
430 - $res[$key]['coupon_price'] = '¥'.$value['reduce'];  
431 - $res[$key]['coupon_tag1'] = '无门槛';  
432 -  
433 - $res[$key]['is_discount'] = 0;//是否为折扣(0:否,1:是)  
434 - $res[$key]['price_tag'] = $value['reduce']; 411 + $flag = 0;
  412 + if(!empty($b_id_s)){
  413 + //有品牌,看商品所属品牌
  414 + if($value['type'] != $type[0]){
  415 + $flag = 1;
435 }else{ 416 }else{
436 - //折扣券,去掉满减金额,减少金额字段,  
437 - unset($value['full_reduce']);  
438 - unset($value['reduce']);  
439 - $res[$key]['coupon_tag'] = '折扣券';  
440 - $res[$key]['coupon_price'] = $value['discount'].'折';  
441 - $res[$key]['coupon_tag1'] = '无门槛';  
442 -  
443 - $res[$key]['is_discount'] = 1;//是否为折扣(0:否,1:是)  
444 - $res[$key]['price_tag'] = $value['discount']; 417 + if($value['type'] == $type[1] && in_array($value['bg_id'],$b_id_s)){
  418 + //去除不是该商品的
  419 + $flag = 1;
  420 + }
445 } 421 }
446 - $res[$key]['coupon_name'] = $value['coupon_name'];//优惠券名称  
447 - $res[$key]['end_time'] = date('Y.n.j',$value['end_time']);//优惠券有效期  
448 - //全场,品牌,商品  
449 - if($value['type'] == 0){  
450 - $res[$key]['type'] = '全场通用';  
451 -  
452 - }else if($value['type'] == 1){  
453 - $res[$key]['type'] = '部分品牌可用';  
454 422
  423 + }else{
  424 + //无品牌
  425 + if($value['type'] == $type[0]){//是全场券
  426 + $flag = 1;
455 }else{ 427 }else{
456 - $res[$key]['type'] = '部分商品可用';  
457 - 428 + if($value['type'] == $type[2] && in_array($value['bg_id'],$goods_id_s)){
  429 + //去除不是该商品的
  430 + $flag = 1;
  431 + }
458 } 432 }
459 - $key++;  
460 - }else{  
461 - //有门槛  
462 - if(($total_goods_price <=> $value['full_reduce']) >= 0){ 433 + }
  434 + if($flag == 1){
  435 + //无门槛,有门槛
  436 + if($value['c_type'] == 0){
463 $res[$key]['id'] = $value['id']; 437 $res[$key]['id'] = $value['id'];
464 - //商品总金额大于等于满减金额 438 + //无门槛
465 if($value['coupon_type'] == 0){ 439 if($value['coupon_type'] == 0){
466 - //减少券,去掉折扣字段, 440 + //减少券,去掉满减金额,折扣字段,
  441 + unset($value['full_reduce']);
467 unset($value['discount']); 442 unset($value['discount']);
468 - $res[$key]['coupon_tag'] = '满减券'; 443 + $res[$key]['coupon_tag'] = '无门槛';
469 $res[$key]['coupon_price'] = '¥'.$value['reduce']; 444 $res[$key]['coupon_price'] = '¥'.$value['reduce'];
470 - $res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用'; 445 + $res[$key]['coupon_tag1'] = '无门槛';
471 446
472 $res[$key]['is_discount'] = 0;//是否为折扣(0:否,1:是) 447 $res[$key]['is_discount'] = 0;//是否为折扣(0:否,1:是)
473 $res[$key]['price_tag'] = $value['reduce']; 448 $res[$key]['price_tag'] = $value['reduce'];
474 }else{ 449 }else{
475 - //折扣券,去掉减少金额字段, 450 + //折扣券,去掉满减金额,减少金额字段,
  451 + unset($value['full_reduce']);
476 unset($value['reduce']); 452 unset($value['reduce']);
477 $res[$key]['coupon_tag'] = '折扣券'; 453 $res[$key]['coupon_tag'] = '折扣券';
478 $res[$key]['coupon_price'] = $value['discount'].'折'; 454 $res[$key]['coupon_price'] = $value['discount'].'折';
479 - $res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用'; 455 + $res[$key]['coupon_tag1'] = '无门槛';
480 456
481 $res[$key]['is_discount'] = 1;//是否为折扣(0:否,1:是) 457 $res[$key]['is_discount'] = 1;//是否为折扣(0:否,1:是)
482 $res[$key]['price_tag'] = $value['discount']; 458 $res[$key]['price_tag'] = $value['discount'];
@@ -495,6 +471,45 @@ class Cars extends Api @@ -495,6 +471,45 @@ class Cars extends Api
495 471
496 } 472 }
497 $key++; 473 $key++;
  474 + }else{
  475 + //有门槛
  476 + if(($total_goods_price <=> $value['full_reduce']) >= 0){
  477 + $res[$key]['id'] = $value['id'];
  478 + //商品总金额大于等于满减金额
  479 + if($value['coupon_type'] == 0){
  480 + //减少券,去掉折扣字段,
  481 + unset($value['discount']);
  482 + $res[$key]['coupon_tag'] = '满减券';
  483 + $res[$key]['coupon_price'] = '¥'.$value['reduce'];
  484 + $res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
  485 +
  486 + $res[$key]['is_discount'] = 0;//是否为折扣(0:否,1:是)
  487 + $res[$key]['price_tag'] = $value['reduce'];
  488 + }else{
  489 + //折扣券,去掉减少金额字段,
  490 + unset($value['reduce']);
  491 + $res[$key]['coupon_tag'] = '折扣券';
  492 + $res[$key]['coupon_price'] = $value['discount'].'折';
  493 + $res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
  494 +
  495 + $res[$key]['is_discount'] = 1;//是否为折扣(0:否,1:是)
  496 + $res[$key]['price_tag'] = $value['discount'];
  497 + }
  498 + $res[$key]['coupon_name'] = $value['coupon_name'];//优惠券名称
  499 + $res[$key]['end_time'] = date('Y.n.j',$value['end_time']);//优惠券有效期
  500 + //全场,品牌,商品
  501 + if($value['type'] == 0){
  502 + $res[$key]['type'] = '全场通用';
  503 +
  504 + }else if($value['type'] == 1){
  505 + $res[$key]['type'] = '部分品牌可用';
  506 +
  507 + }else{
  508 + $res[$key]['type'] = '部分商品可用';
  509 +
  510 + }
  511 + $key++;
  512 + }
498 } 513 }
499 } 514 }
500 } 515 }
@@ -77,43 +77,6 @@ class Common @@ -77,43 +77,6 @@ class Common
77 * 查找多条数据 77 * 查找多条数据
78 * @ApiInternal 78 * @ApiInternal
79 */ 79 */
80 - public static function selectWhereOrData($table,$where,$where1,$where2,$field,$order='id desc'){  
81 - $res = Db::name($table)  
82 - ->where(function(Query $query) use($where,$where1){  
83 - $query->where($where);  
84 - $query->where($where1);  
85 - })  
86 - ->whereOr(function(Query $query) use($where,$where2){  
87 - if(!empty($where2)){  
88 - $query->where($where);  
89 - $query->where($where2);  
90 - }  
91 - })  
92 - ->field($field)  
93 - ->order($order)  
94 - ->select();  
95 - // SELECT * FROM `ffg_coupon` WHERE (`id` IN (9,4) AND `end_time` > 1575427684 AND `bg_id` IN (2) AND `type` = 2 ) OR ( `id` IN (9,4) AND `end_time` > 1575427665 AND `bg_id` IN (1) AND `type` = 1 ) ORDER BY `c_type` ASC,`coupon_type` DESC  
96 - return $res;  
97 - }  
98 -  
99 - /**  
100 - * 查找多条数据  
101 - * @ApiInternal  
102 - */  
103 - public static function selectWhereOrData1($table,$where,$where1,$field,$order='id desc'){  
104 - $res = Db::name($table)  
105 - ->where($where)  
106 - ->where($where1)  
107 - ->field($field)  
108 - ->order($order)  
109 - ->select();  
110 - return $res;  
111 - }  
112 -  
113 - /**  
114 - * 查找多条数据  
115 - * @ApiInternal  
116 - */  
117 public static function selectWherePageData($table,$where,$field,$page,$limit='',$order='id desc'){ 80 public static function selectWherePageData($table,$where,$field,$page,$limit='',$order='id desc'){
118 if($limit == ''){ 81 if($limit == ''){
119 $limit = config('verify.limit'); 82 $limit = config('verify.limit');