<?php
declare (strict_types = 1);
namespace App\Model;
use think\model\concern\SoftDelete;
use think\Collection;
use think\db\concern\WhereQuery;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException as Exception;
use think\db\exception\ModelNotFoundException;
use think\helper\Str;
use think\Model;
use think\Paginator;
/**
* @method $this where($field, $op = null, $condition = null)
* @method $this whereOr($field, $op = null, $condition = null)
* @method $this whereXor($field, $op = null, $condition = null)
* @method $this whereNull(string $field, string $logic = 'AND')
* @method $this whereNotNull(string $field, string $logic = 'AND')
* @method $this whereExists(string $field, string $logic = 'AND')
* @method $this whereNotExists(string $field, string $logic = 'AND')
* @method $this whereIn(string $field, $condition, string $logic = 'AND')
* @method $this whereNotIn(string $field, $condition, string $logic = 'AND')
* @method $this whereLike(string $field, $condition, string $logic = 'AND')
* @method $this whereNotLike(string $field, $condition, string $logic = 'AND')
* @method $this whereBetween(string $field, $condition, string $logic = 'AND')
* @method $this whereNotBetween(string $field, $condition, string $logic = 'AND')
* @method $this whereFindInSet(string $field, $condition, string $logic = 'AND')
* @method $this whereColumn(string $field1, string $operator, string $field2 = null, string $logic = 'AND')
* @method $this whereExp(string $field, string $where, array $bind = [], string $logic = 'AND')
* @method $this whereFieldRaw(string $field, $op, $condition = null, string $logic = 'AND')
* @method $this whereRaw(string $where, array $bind = [], string $logic = 'AND')
* @method $this whereOrRaw(string $where, array $bind = [])
*
*
* @method $this join($join, string $condition = null, string $type = 'INNER', array $bind = [])
* @method $this leftJoin($join, string $condition = null, array $bind = [])
* @method $this rightJoin($join, string $condition = null, array $bind = [])
* @method $this fullJoin($join, string $condition = null, array $bind = [])
*
*
* @method $this order($field, string $order = '')
* @method Paginator paginate($listRows = null, $simple = false)
* @method Paginator paginateX($listRows = null, string $key = null, string $sort = null)
* @method Collection select($data = null)
* @method array|Model|null find($data = null)
* @method integer|string insertAll(array $dataSet = [], int $limit = 0)
* @method integer|string insertGetId(array $data)
* @method integer|string insert(array $data = [], bool $getLastInsID = false)
* @method integer save(array $data = [], bool $forceInsert = false)
*
* @method $this alias($alias)
* @method $this table($table)
* @method $this limit(int $offset, int $length = null)
* @method $this data(array $data)
*
* @method $this field($field)
* @method $this union($union, bool $all = false)
*
*
* @method array column($field, string $key = '')
* @method mixed value(string $field, $default = null)
* @method string getLastSql()
*
*/
class BaseModel extends \think\Model
{
use SoftDelete;
protected $insert = ['create_time'];
protected $update = ['update_time'];
protected $deleteTime = 'delete_time';
public function getCreateTimeAttr() : int
{
return time();
}
public function getUpdateTimeAttr() : int
{
return time();
}
/**
* 没被删除的
* @access public
* @return $this
*/
public function notDelete()
{
return $this->whereNull('delete_time');
}
/**
* 分页
* @param int $limit
* @param int $page
*/
public function pagex($limit = 10,$page = null)
{
return $this
->paginate([
'page' => $page ?: request()->input('page', 1),
'list_rows' => $limit ?: 10,
]);
}
}