You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
771 B
32 lines
771 B
<?php
|
|
|
|
namespace app;
|
|
|
|
use think\Model;
|
|
|
|
class BaseModel extends Model
|
|
{
|
|
public $withJoin = false;
|
|
|
|
/**
|
|
* 转换获取with,根据参数with替换为withData中自定义with数据
|
|
* @param array $with
|
|
* @param array $withData
|
|
* @return array|null
|
|
*/
|
|
public function buildWith(array $with, array $withData) {
|
|
if ($with['withJoin'] ?? false){
|
|
$this->withJoin = $with['withJoin'];
|
|
unset($with['withJoin']);
|
|
}
|
|
foreach ($withData as $k => $v){
|
|
if (in_array($k, $with)){
|
|
$with_key = array_search($k, $with);
|
|
unset($with[$with_key]);
|
|
$with[$k] = $v;
|
|
}
|
|
}
|
|
return $with; //添加 withDiff 中数据
|
|
}
|
|
|
|
}
|