param('wxapp_id'); } /** * 定义全局的查询范围 * @param \think\db\Query $query */ protected function base($query) { if (self::$wxapp_id > 0) { $query->where($query->getTable() . '.wxapp_id', self::$wxapp_id); } } /** * 设置默认的检索数据 * @param $query * @param array $default * @return array */ protected function setQueryDefaultValue(&$query, $default = []) { $data = array_merge($default, $query); foreach ($query as $key => $val) { if (empty($val) && isset($default[$key])) { $data[$key] = $default[$key]; } } return $data; } /** * 设置基础查询条件(用于简化基础alias和field) * @test 2019-4-25 * @param string $alias * @param array $join * @return BaseModel */ public function setBaseQuery($alias = '', $join = []) { // 设置别名 $aliasValue = $alias ?: $this->alias; $model = $this->alias($aliasValue)->field("{$aliasValue}.*"); // join条件 if (!empty($join)) : foreach ($join as $item): $model->join($item[0], "{$item[0]}.{$item[1]}={$aliasValue}." . (isset($item[2]) ? $item[2] : $item[1])); endforeach; endif; return $model; } /** * 批量更新数据(支持带where条件) * @param array $data [0 => ['data'=>[], 'where'=>[]]] * @return \think\Collection */ public function updateAll($data) { return $this->transaction(function () use ($data) { $result = []; foreach ($data as $key => $item) { $result[$key] = self::update($item['data'], $item['where']); } return $this->toCollection($result); }); } }