字符串转数组
引用Utils
use catcher\Utils;
使用方法
Utils::stringToArrayBy($exe_date,'|')
//stringToArrayBy(string $string, $dep = ',')---参数1字符串,参数2分隔符
关联多张表查询
功能说明
该功能支持多表查询、联合同张表不同字段以及其中副表与其他表联合查询
使用catchLeftJoin()
$list = $this->withoutField(['updated_at'], true)
->catchSearch()
->catchLeftJoin([Cate::class,'nurse_project_cate'], 'id', 'nurse_project_cate', ['textvalue nurse_project_cate'])
->catchLeftJoin([Cate::class, 'cost_method'], 'id', 'cost_method', ['textvalue cost_method'])
->catchLeftJoin([NursePlan::class,'nurse_plan'], 'nurse_project_id', 'id',['nurse_level_id,exe_rate_id,nurse_project_id,exe_date,exe_time'])
->catchLeftJoin([Cate::class,'exe_rate','nurse_plan'], 'id', 'exe_rate_id',['textvalue exe_rate'])
->order($this->aliasField('id'), 'desc')
->paginate();
修改catchJoin方法
public function catchJoin($model, string $joinField, string $currentJoinField, array $field = [], string $type = 'INNER', array $bind = []): CatchQuery
{
$tableAlias = null; //主表别名
$otherTableAlias = null; //副表别名,其中副表跟其他表联合查询
if (is_string($model)) {
$table = app($model)->getTable();
$tableAlias = $table;
} else {
if (count($model) == 3) {
list($model, $tableAlias, $otherTable) = $model;
} else {
list($model, $tableAlias) = $model;
}
$table = sprintf('%s %s', app($model)->getTable(), $tableAlias);
}
$otherTable = empty($otherTable) ? $this->getAlias() : $otherTable;
// 合并字段
$this->options['field'] = array_merge($this->options['field'] ?? [], array_map(function ($value) use ($tableAlias) {
return $tableAlias . '.' . $value;
}, $field));
return $this->join($table, sprintf('%s.%s=%s.%s', $tableAlias, $joinField, $otherTable, $currentJoinField), $type, $bind);
}
结合搜索多条件查询
model文件下创建search文件夹,并且创建相对于的search文件
命名规范:module名+Search