class Goods extends Model { protected $table='good'; public function type(){ return $this->hasOne(Type::class); } }
分页
public function index(\app\common\model\Goods $goodsmodel) {
$goodname=\request()->get('name'); $where[]=[ 'name','like',"%$goodname%" ]; $page=\request()->get('page',1); $limit=\request()->get('limit',10); $goods_min_price=\request()->get('goods_min_price'); $goods_max_price=\request()->get('goods_max_price'); $where[]=[ 'price','>',$goods_min_price ]; $where[]=[ 'price','<',$goods_max_price ]; $goods_name = \request()->get('goods_name');//搜索条件
$create_time = \request()->get('create_time');//搜索条件
$where = [];
// 判断商品名称是否传送
if ($goods_name) {
$where[] = ['goods_name','like', "%{$goods_name}%"];
}
// 判断查询时间是否传送
if ($create_time ) {
$where[] = ['create_time' ,'=' ,strtotime($create_time)];
}
$data=$goodsmodel->where($where) ->order('price') ->paginate([ 'list_rows'=>$limit, 'page'=>$page ]); return success(200,'查询成功',$data);
//列表分页
public function index(Request $request) { try { //接口安全优化 $myTime=$request->all('myTime'); if(!apiTime($myTime)){ return fail('加载时间过长,请重试'); } //搜索条件 根据状态搜索 $state=$request->get('state'); //当前页 默认为第1页 $page=$request->get('page',1); //每页显示多少条 默认10条 $list_rows=$re