search($where,false) ->page($page, $limit) ->order('id DESC') ->select() ->toArray(); } /** * 获取单个采购商身份信息 * @param int $id * @param string $field * @return array|\think\Model|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getInfo(int $id, string $field = '*') { return $this->getModel()->field($field)->find($id); } /** * 根据等级获取采购商身份 * @param int $level * @param string $field * @return array|\think\Model|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getIdentityByLevel(int $level, string $field = '*') { return $this->getModel()->field($field)->where('level', $level)->where('is_show', 1)->find(); } /** * 检查等级是否已存在 * @param int $level * @param int $id * @return bool */ public function isLevelExist(int $level, int $id = 0) { return $this->getModel()->where('level', $level) ->when($id > 0, function ($query) use ($id) { $query->where('id', '<>', $id); }) ->count() > 0; } /** * 检查名称是否已存在 * @param string $name * @param int $id * @return bool */ public function isNameExist(string $name, int $id = 0) { return $this->getModel()->where('name', $name) ->when($id > 0, function ($query) use ($id) { $query->where('id', '<>', $id); }) ->count() > 0; } }