美文网首页
Thinkphp 笔记

Thinkphp 笔记

作者: wyc0859 | 来源:发表于2019-05-13 16:53 被阅读0次

模型

模型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();

相关文章

  • 学习thinkPHP的笔记

    学习thinkPHP的笔记 thinkPHP的文件结构的介绍 thinkPHP核心文件的介绍├─ThinkPHP....

  • think-queue之redis

    [TOC] thinkphp-queue 笔记 前言 当前笔记中的内容针对的是 thinkphp-queue 的 ...

  • thinkPHP学习笔记之基础概念(一)

    这里记录的是本人学习的thinkPHP笔记官方开发手册http://document.thinkphp.cn/ma...

  • 转载 thinkphp-queue在使用过程中 遇到的一个教训

    thinkphp-queue在使用过程中 遇到的一个教训thinkphp-queue 笔记 在项目中我们使用了适合...

  • ThinkPhp 笔记

    控制器 新建控制器的定义 1/声明命名空间 app\模块\controller 2/控制器文件名首字母大写,采用驼...

  • ThinkPHP笔记

    基础 文件目录 www WEB部署目录(或者子目录)├─index.php 入口文件,保留在www目...

  • Thinkphp 笔记

    模型 模型where 关联模型支持field 加了field如何显示with内容 只需要在原语句的field中加入...

  • PHP全栈学习笔记20

    thinkphp概述,thinkphp项目构建流程,thinkphp项目结构,thinkphp配置,thinkph...

  • PHP全栈学习笔记20

    thinkphp概述,thinkphp项目构建流程,thinkphp项目结构,thinkphp配置,thinkph...

  • ThinkPHP笔记-模型

    模型定义 ThinkPHP中的模型类主要用于操作数据表。 模型类通常需要继承系统的\Think\Model类或其子...

网友评论

      本文标题:Thinkphp 笔记

      本文链接:https://www.haomeiwen.com/subject/gujraqtx.html