模型类
模型会自动对应数据表,模型类的命名规则是除去表前缀的数据表名称,采用驼峰法命名,并且首字母大写。
模型文件存放目录:app/common/model,继承模型基类BaseModel,使用模型ModelTrait,以新闻表(tm_news)为例
<?php
namespace app\common\model;
use tmcore\base\BaseModel;
use tmcore\traits\ModelTrait;
use think\model\concern\SoftDelete;
/**
* 新闻模型
*/
class News extends BaseModel
{
use ModelTrait; //模型trait
use SoftDelete; //软删除trait
}内置方法
使用模型::方法(参数...)静态调用方法
/**
* 获取一条数据
*/
public static function get($where)
/**
* 添加多条数据
*/
public static function addAll($group, $limit = 0)
/**
* 增加一条数据
*/
public static function add($data, $is_return_pk = false)
/**
* 修改一条数据
*/
public static function edit($data, $id, $field = null)
/**
* 查询一条数据是否存在
*/
public static function be($map, $field = '')
/**
* 删除数据
*/
public static function del($data, $force = false)
/**
* 分页函数
*/
public static function page($where, $page = ['limit' => '20'], $field = '*', $order = ['id'=>'desc'], $append = [], $with = [], $extend = [])
/**
* 获取时间段之间的model
*/
public static function getModelTime($where, $prefix = 'create_time', $data = 'data', $field = ' - ')
/**
* 获取本季度 time
*/
public static function getMonth($time = '', $ceil = 0)
/**
* 高精度 加法
*/
public static function bcInc($where, $incField, $inc, $acc = 2)
/**
* 高精度 减法
*/
public static function bcDec($where, $decField, $dec, $minus = false, $acc = 2)