Properties

$modelClass

$modelClass : mixed

Type

mixed

$modelInstance

$modelInstance : ?\think\Model

Type

Model

Methods

__construct()

__construct(\think\Model|string|null  $model = null) : mixed

构造函数.

Parameters

\think\Model|string|null $model

模型类名或实例

Returns

mixed —

getModel()

getModel() : \think\Model

获取模型实例 (懒加载).

Returns

\think\Model —

count()

count(array  $where = [], bool  $search = false) : int

获取条数

Parameters

array $where
bool $search

Returns

int —

selectList()

selectList(array  $where, array|string  $field = '*', int  $page, int  $limit, string  $order = '', array  $with = [], bool  $search = false, ?array  $withoutScopes = null) : ?\think\Collection

查询列表

Parameters

array $where
array|string $field
int $page
int $limit
string $order
array $with
bool $search
?array $withoutScopes

Returns

?\think\Collection —

selectModel()

selectModel(array  $where, array|string  $field = '*', int  $page, int  $limit, string  $order = '', array  $with = [], bool  $search = false, ?array  $withoutScopes = null) : \think\db\Query|\think\Paginator

获取查询构建器或分页结果

Parameters

array $where
array|string $field
int $page
int $limit
string $order
array $with
bool $search
?array $withoutScopes

Returns

\think\db\Query|\think\Paginator —

getCount()

getCount(array  $where) : int

获取条数 (别名)

Parameters

array $where

Returns

int —

getDistinctCount()

getDistinctCount(array  $where, string  $field, bool  $search = true) : int

计算符合条件的唯一记录数量

Parameters

array $where
string $field
bool $search

Returns

int —

getPk()

getPk() : string

Returns

string —

getTableName()

getTableName() : string

Returns

string —

get()

get(mixed  $id, array|string|null  $field = null, ?array  $with = [], string  $order = '', ?array  $withoutScopes = null) : ?\think\Model

获取一条数据

Parameters

mixed $id
array|string|null $field
?array $with
string $order
?array $withoutScopes

Returns

?\think\Model —

be()

be(mixed  $map, string  $field = '') : bool

查询一条数据是否存在

Parameters

mixed $map
string $field

Returns

bool —

getOne()

getOne(array  $where, array|string|null  $field = '*', array  $with = []) : ?\think\Model

根据条件获取一条数据

Parameters

array $where
array|string|null $field
array $with

Returns

?\think\Model —

value()

value(mixed  $where, ?string  $field = null) : mixed

获取某字段的值

Parameters

mixed $where
?string $field

Returns

mixed —

getColumn()

getColumn(array  $where, string  $field, string  $key = '') : array

获取某个字段数组

Parameters

array $where
string $field
string $key

Returns

array —

delete()

delete(array|int|string  $id, ?string  $key = null) : int

删除

Parameters

array|int|string $id
?string $key

Returns

int —

destroy()

destroy(mixed  $id, bool  $force = false) : bool

销毁记录 (直接通过主键)

Parameters

mixed $id
bool $force

Returns

bool —

update()

update(string|int|array  $id, array  $data, ?string  $key = null) : mixed

更新

Parameters

string|int|array $id
array $data
?string $key

Returns

mixed —

batchUpdate()

batchUpdate(array  $ids, array  $data, ?string  $key = null) : bool

批量更新

Parameters

array $ids
array $data
?string $key

Returns

bool —

save()

save(array  $data) : ?\think\Model

保存返回模型

Parameters

array $data

Returns

?\think\Model —

saveAll()

saveAll(array  $data) : bool

批量插入

Parameters

array $data

Returns

bool —

getFieldValue()

getFieldValue(mixed  $value, string  $field, ?string  $valueKey = null, ?array  $where = []) : mixed

获取某字段内的值

Parameters

mixed $value
string $field
?string $valueKey
?array $where

Returns

mixed —

search()

search(array  $where = [], bool  $search = true) : \think\Model|\think\db\Query

搜索

Parameters

array $where
bool $search

Returns

\think\Model|\think\db\Query —

sum()

sum(array  $where, string  $field, bool  $search = false) : float

求和

Parameters

array $where
string $field
bool $search

Returns

float —

bcInc()

bcInc(mixed  $key, string  $incField, string  $inc, ?string  $keyField = null, int  $acc = 2) : bool

高精度加法

Parameters

mixed $key
string $incField
string $inc
?string $keyField
int $acc

Returns

bool —

bcDec()

bcDec(mixed  $key, string  $decField, string  $dec, ?string  $keyField = null, int  $acc = 2) : bool

高精度 减法

Parameters

mixed $key
string $decField
string $dec
?string $keyField
int $acc

Returns

bool —

bc()

bc(mixed  $key, string  $field, string  $value, ?string  $keyField = null, int  $type = 1, int  $acc = 2) : bool

高精度计算并保存 (应用层计算)

Parameters

mixed $key
string $field
string $value
?string $keyField
int $type
int $acc

Returns

bool —

decStockIncSales()

decStockIncSales(array  $where, int  $num, string  $stock = 'stock', string  $sales = 'sales') : bool

减库存加销量 (原子更新) 适配 ThinkPHP: dec() / inc()

Parameters

array $where
int $num
string $stock
string $sales

Returns

bool —

incStockDecSales()

incStockDecSales(array  $where, int  $num, string  $stock = 'stock', string  $sales = 'sales') : bool

加库存减销量 (原子更新)

Parameters

array $where
int $num
string $stock
string $sales

Returns

bool —

getMax()

getMax(array  $where = [], string  $field = '') : mixed

获取最大值

Parameters

array $where
string $field

Returns

mixed —

getMin()

getMin(array  $where = [], string  $field = '') : mixed

获取最小值

Parameters

array $where
string $field

Returns

mixed —

tableExists()

tableExists(mixed  $table) : bool

Parameters

mixed $table

Returns

bool —

setWhere()

setWhere(mixed  $where, ?string  $key = null) : array

Parameters

mixed $where
?string $key

Returns

array —

withSearchSelect()

withSearchSelect(array  $where, bool  $search) : \think\db\Query

根据搜索器获取内容 (内部使用)

Parameters

array $where
bool $search

Returns

\think\db\Query —

filterWhere()

filterWhere(array  $where = []) : array

Parameters

array $where

Returns

array —

applyScopeRemoval()

applyScopeRemoval(\think\db\Query  $query, ?array  $scopes) : void

Parameters

\think\db\Query $query
?array $scopes

buildQuery()

buildQuery(array  $where, bool  $search = false, ?array  $withoutScopes = null) : \think\db\Query

核心优化:统一查询条件构建器 适配 ThinkPHP 的 Query 对象

Parameters

array $where
bool $search
?array $withoutScopes

Returns

\think\db\Query —

splitWhere()

splitWhere(array  $where) : array

Parameters

array $where

Returns

array —

applyConditions()

applyConditions(\think\db\Query  $query, array  $where) : void

Parameters

\think\db\Query $query
array $where

applyFields()

applyFields(\think\db\Query  $query, array|string  $field) : void

Parameters

\think\db\Query $query
array|string $field

applySearchScopes()

applySearchScopes(\think\db\Query  $query, array  $where) : \think\db\Query

辅助方法:应用搜索器逻辑 (ThinkPHP withSearch)

Parameters

\think\db\Query $query
array $where

Returns

\think\db\Query —

getSearchData()

getSearchData(array  $where) : array

获取搜索器和搜索条件 适配 ThinkPHP: searchFieldNameAttr

Parameters

array $where

Returns

array —

studly()

studly(string  $string) : string

Parameters

string $string

Returns

string —