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

修改结算优惠券

... ... @@ -398,85 +398,61 @@ class Cars extends Api
$res1 = Common::selectSoftWhereData('goods',['id'=>['in',$goods_id_s],'type'=>$flag[1]],'id,t_id');
$b_id_s = array_unique(array_values(array_column($res1,'t_id')));
//普通商品
$where1['bg_id'] = ['in',$goods_id_s];
$where1['type'] = $type[2];
$time = time();
$where['id'] = ['in',$receive_s];
$where['end_time'] = ['>',$time];
//包含品牌中的商品
if(!empty($b_id_s)){
$where2['bg_id'] = ['in',$b_id_s];
$where2['type'] = $type[1];
$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');
}else{
$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');
}
$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');
$res = [];
$key = 0;
foreach($data as $value){
$key+=0;
//无门槛,有门槛
if($value['c_type'] == 0){
$res[$key]['id'] = $value['id'];
//无门槛
if($value['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($value['full_reduce']);
unset($value['discount']);
$res[$key]['coupon_tag'] = '无门槛';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
$res[$key]['coupon_tag1'] = '无门槛';
$res[$key]['is_discount'] = 0;//是否为折扣(0:否,1:是)
$res[$key]['price_tag'] = $value['reduce'];
$flag = 0;
if(!empty($b_id_s)){
//有品牌,看商品所属品牌
if($value['type'] != $type[0]){
$flag = 1;
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($value['full_reduce']);
unset($value['reduce']);
$res[$key]['coupon_tag'] = '折扣券';
$res[$key]['coupon_price'] = $value['discount'].'折';
$res[$key]['coupon_tag1'] = '无门槛';
$res[$key]['is_discount'] = 1;//是否为折扣(0:否,1:是)
$res[$key]['price_tag'] = $value['discount'];
if($value['type'] == $type[1] && in_array($value['bg_id'],$b_id_s)){
//去除不是该商品的
$flag = 1;
}
}
$res[$key]['coupon_name'] = $value['coupon_name'];//优惠券名称
$res[$key]['end_time'] = date('Y.n.j',$value['end_time']);//优惠券有效期
//全场,品牌,商品
if($value['type'] == 0){
$res[$key]['type'] = '全场通用';
}else if($value['type'] == 1){
$res[$key]['type'] = '部分品牌可用';
}else{
//无品牌
if($value['type'] == $type[0]){//是全场券
$flag = 1;
}else{
$res[$key]['type'] = '部分商品可用';
if($value['type'] == $type[2] && in_array($value['bg_id'],$goods_id_s)){
//去除不是该商品的
$flag = 1;
}
}
$key++;
}else{
//有门槛
if(($total_goods_price <=> $value['full_reduce']) >= 0){
}
if($flag == 1){
//无门槛,有门槛
if($value['c_type'] == 0){
$res[$key]['id'] = $value['id'];
//商品总金额大于等于满减金额
//无门槛
if($value['coupon_type'] == 0){
//减少券,去掉折扣字段,
//减少券,去掉满减金额,折扣字段,
unset($value['full_reduce']);
unset($value['discount']);
$res[$key]['coupon_tag'] = '满减券';
$res[$key]['coupon_tag'] = '无门槛';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
$res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
$res[$key]['coupon_tag1'] = '无门槛';
$res[$key]['is_discount'] = 0;//是否为折扣(0:否,1:是)
$res[$key]['price_tag'] = $value['reduce'];
}else{
//折扣券,去掉减少金额字段,
//折扣券,去掉满减金额,减少金额字段,
unset($value['full_reduce']);
unset($value['reduce']);
$res[$key]['coupon_tag'] = '折扣券';
$res[$key]['coupon_price'] = $value['discount'].'折';
$res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
$res[$key]['coupon_tag1'] = '无门槛';
$res[$key]['is_discount'] = 1;//是否为折扣(0:否,1:是)
$res[$key]['price_tag'] = $value['discount'];
... ... @@ -495,6 +471,45 @@ class Cars extends Api
}
$key++;
}else{
//有门槛
if(($total_goods_price <=> $value['full_reduce']) >= 0){
$res[$key]['id'] = $value['id'];
//商品总金额大于等于满减金额
if($value['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($value['discount']);
$res[$key]['coupon_tag'] = '满减券';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
$res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
$res[$key]['is_discount'] = 0;//是否为折扣(0:否,1:是)
$res[$key]['price_tag'] = $value['reduce'];
}else{
//折扣券,去掉减少金额字段,
unset($value['reduce']);
$res[$key]['coupon_tag'] = '折扣券';
$res[$key]['coupon_price'] = $value['discount'].'折';
$res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
$res[$key]['is_discount'] = 1;//是否为折扣(0:否,1:是)
$res[$key]['price_tag'] = $value['discount'];
}
$res[$key]['coupon_name'] = $value['coupon_name'];//优惠券名称
$res[$key]['end_time'] = date('Y.n.j',$value['end_time']);//优惠券有效期
//全场,品牌,商品
if($value['type'] == 0){
$res[$key]['type'] = '全场通用';
}else if($value['type'] == 1){
$res[$key]['type'] = '部分品牌可用';
}else{
$res[$key]['type'] = '部分商品可用';
}
$key++;
}
}
}
}
... ...
... ... @@ -77,43 +77,6 @@ class Common
* 查找多条数据
* @ApiInternal
*/
public static function selectWhereOrData($table,$where,$where1,$where2,$field,$order='id desc'){
$res = Db::name($table)
->where(function(Query $query) use($where,$where1){
$query->where($where);
$query->where($where1);
})
->whereOr(function(Query $query) use($where,$where2){
if(!empty($where2)){
$query->where($where);
$query->where($where2);
}
})
->field($field)
->order($order)
->select();
// 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
return $res;
}
/**
* 查找多条数据
* @ApiInternal
*/
public static function selectWhereOrData1($table,$where,$where1,$field,$order='id desc'){
$res = Db::name($table)
->where($where)
->where($where1)
->field($field)
->order($order)
->select();
return $res;
}
/**
* 查找多条数据
* @ApiInternal
*/
public static function selectWherePageData($table,$where,$field,$page,$limit='',$order='id desc'){
if($limit == ''){
$limit = config('verify.limit');
... ...