Skip to content

traits类

liaofei edited this page Jan 20, 2021 · 1 revision

Trait类

目录:

├─traits
│  │  CurdControllerTrait.php
│  │  ErrorTrait.php
│  │  JwtAuthModelTrait.php
│  │  ModelTrait.php
│  │  ServicesTrait.php
  
  • CurdControllerTrait数据模型操作类 类中方法介绍:
change_field($id, $field) 改变某一个字段的值
model_save($id, array $updateData = null) 保存数据
  • ErrorTrait错误设置输出类 类中方法介绍:
setError(?string $error = null) 设置错误信息返回false
getError()  获取设置的错误信息
  • JwtAuthModelTrait 获取token类 类中方法介绍:
getToken(string $type, array $params = []) 获取到token相关的结果数组
parseToken(string $jwt) 解密token 获取保存在其中的信息
  • ModelTrait数据模型类 类中方法介绍:
searchTimeAttr($query, $value, $data) 时间段搜索器 
getMonth(int $ceil = 0) 获取本月起始时间
getFieldValue($value, string $filed, ?string $valueKey = '', ?array $where = []) 获取某些条件下某个字段值

searchTimeAttr时间搜索器可搜索:

查询今天产生的数据

$this->search(['time'=>'today'])->select();

查询本周产生的数据,

$this->search(['time'=>'week'])->select();

查询本月产生的数据,时间字段为update_time

$this->search(['time'=>'month','timeKey'=>'update_time'])->select();

查询本年产生的数据,时间字段为update_time

$this->search(['time'=>'year','timeKey'=>'update_time'])->select();

查询昨天产生的数据

$this->search(['time'=>'yesterday'])->select();

查询去年产生的数据

$this->search(['time'=>'last year'])->select();

查询上周产生的数据

$this->search(['time'=>'last week'])->select();

上月产生的数据

$this->search(['time'=>'last month'])->select();

本季度产生的数据

$this->search(['time'=>'quarter'])->select();

最近7天产生的数据

$this->search(['time'=>'lately7'])->select();

最近30天产生的数据

$this->search(['time'=>'lately30'])->select();

其他自定义搜索

$this->search(['time'=>'2021/01/01-2021/01/08'])->select();
  • ServicesTrait 兼容IDE识别services中使用BaseDao中的方法
Clone this wiki locally