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

写优惠券相关接口

... ... @@ -11,7 +11,7 @@
namespace app\api\controller;
use think\Db;
use think\db\Query;
/**
* 公共方法
*/
... ... @@ -72,10 +72,16 @@ class Common
* 查找多条数据
* @ApiInternal
*/
public static function selectWhereOrData($table,$where,$where1,$field,$order='id desc'){
public static function selectWhereOrData($table,$where,$where1,$where2,$field,$order='id desc'){
$res = Db::name($table)
->where($where)
->whereOr($where1)
->where(function (Query $query) use ($where1, $where2) {
if(empty($where2)){
$query->where($where1);
}else{
$query->where($where1)->whereOr($where2);
}
})
->field($field)
->order($order)
->select();
... ...
... ... @@ -368,18 +368,21 @@ class User extends Api
//查询商品所属品牌id
$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')));
if(!empty($b_id_s)){
$where2['bg_id'] = ['in',$b_id_s];
$where2['type'] = $type[1];
}else{
$where2 = [];
}
//包含品牌中的商品
$time = time();
$where2['id'] = ['in',$receive_s];
$where2['end_time'] = ['>',$time];
$where2['bg_id'] = ['in',$b_id_s];
$where2['type'] = $type[1];
$where['id'] = ['in',$receive_s];
$where['end_time'] = ['>',$time];
//普通商品
$where1['id'] = ['in',$receive_s];
$where1['end_time'] = ['>',$time];
$where1['bg_id'] = ['in',$goods_id_s];
$where1['type'] = $type[2];
$data = Common::selectWhereOrData('coupon',$where1,$where2,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','c_type asc,coupon_type desc');
$data = Common::selectWhereOrData('coupon',$where,$where1,$where2,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','c_type asc,coupon_type desc');
}else{
$where['id'] = ['in',$receive_s];
$data = Common::selectWhereData('coupon',$where,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','c_type asc,coupon_type desc');
... ...
... ... @@ -4586,7 +4586,7 @@
<div class="row mt0 footer">
<div class="col-md-6" align="left">
Generated on 2019-12-03 20:23:19 </div>
Generated on 2019-12-04 09:47:26 </div>
<div class="col-md-6" align="right">
<a href="https://www.fastadmin.net" target="_blank">FastAdmin</a>
</div>
... ...