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

修改结算优惠券

@@ -398,26 +398,40 @@ class Cars extends Api @@ -398,26 +398,40 @@ 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;
  411 + $flag = 0;
  412 + if(!empty($b_id_s)){
  413 + //有品牌,看商品所属品牌
  414 + if($value['type'] != $type[0]){
  415 + $flag = 1;
  416 + }else{
  417 + if($value['type'] == $type[1] && in_array($value['bg_id'],$b_id_s)){
  418 + //去除不是该商品的
  419 + $flag = 1;
  420 + }
  421 + }
  422 +
  423 + }else{
  424 + //无品牌
  425 + if($value['type'] == $type[0]){//是全场券
  426 + $flag = 1;
  427 + }else{
  428 + if($value['type'] == $type[2] && in_array($value['bg_id'],$goods_id_s)){
  429 + //去除不是该商品的
  430 + $flag = 1;
  431 + }
  432 + }
  433 + }
  434 + if($flag == 1){
421 //无门槛,有门槛 435 //无门槛,有门槛
422 if($value['c_type'] == 0){ 436 if($value['c_type'] == 0){
423 $res[$key]['id'] = $value['id']; 437 $res[$key]['id'] = $value['id'];
@@ -498,6 +512,7 @@ class Cars extends Api @@ -498,6 +512,7 @@ class Cars extends Api
498 } 512 }
499 } 513 }
500 } 514 }
  515 + }
501 516
502 $this->success('成功',$res); 517 $this->success('成功',$res);
503 }else{ 518 }else{
@@ -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');