模型
模型where
TuiModel::where(['order_id' => $post['id'], 'status' => ['>', 0]])->find(); //正确获取
$fq_list=afModel::where('status',0)->where('pay_time','<>','')->select(); //pay_time不会走模型转换
$fq_list=afModel::where(['status'=>0,'pay_time'=>['<>','']])->select(); //pay_time会走模型转换
关联模型支持field
public function users()
{
return $this->belongsTo('User','uid','id')->field('id,nickname,headpic');
}
或者直接使用
afModel::withfield()
加了field如何显示with内容
只需要在原语句的field中加入with的关联字段即可,如
ShopModel::with('imgs')->where('shop_id','in',$shop_ids)->field('shop_id,shop_name,img_id')->select();
本月销量前10排名
OrderModel::with(['shop'])->where(['pay_status'=>'1'])->whereTime('create_time', 'month')
->field('goods_id,shop_id,message,count(*) as num')->order('num desc')->group('goods_id')->limit(10)->select();
查询时间周期
// 查询某天
Db::name('user')
->whereBetweenTime('create_time', '2017-06-01') ->select();
// 查询今天
Db::name('blog')
->whereTime('create_time', 'today') ->select();
// 查询昨天
Db::name('blog')
->whereTime('create_time', 'yesterday') ->select();
// 查询本周的
Db::name('blog')
->whereTime('create_time', 'week') ->select();
// 时间区间查询
Db::name('user')
->whereTime('birthday', 'between', ['1970-10-1', '2000-10-1']) ->select();
接收请求数据
//前端
sku:[{"a":"a1","b":"b1","price":"1","stock_num":"2"},{"a":"a1","b":"b2","price":"3","stock_num":"4"}]
//后端
$post=input('post.'); //接收到的是json字符串
$arr=json_decode($post['sku'],true);//转数组
dump($arr);
IN查询 排序
$exp = new \think\db\Expression('field(id,'.$res['c_imgs'].')');
$imgs = ImageModel::where('id', 'in', $res['c_imgs'])->order($exp)->select();
网友评论