【think-orm】BaseModel类

<?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,
    ]);
  }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值