autoParams($params); $keyword = $this->pg('keyword'); $valid = $this->pg('valid'); $where = WhereBuilder::builder() ->like('name|address', $keyword) ->eq('valid', $valid) ->build(); $page = (new Repo) ->where($where) ->paginate($this->tp6Page()); return $page; } public function all($params = []) { return (new Repo)->select(); } public function create($params = []) { $params = $this->autoParams($params); return Repo::create($params); } public function update($params = []) { $params = $this->autoParams($params); if (!$params) { throw $this->exception('未选中任何商品进行更新'); } return (new Repo)->allowField(['name', 'desc', 'address', 'valid'])->update($params); } public function delete($params = []) { $params = $this->autoParams($params); $this->validate($params, Validate::rule(['id' => 'array'])); $id = $this->req('id'); $force = $this->pgd(false, 'force'); if (is_int($id)) { $id = [$id]; } // 非强制删除检查仓库库存 if (!$force) { foreach ($id as $i) { $sum = (new Stock)->where('repo_id', '=', $i)->sum('num'); if ($sum > 0) { $repo = (new Repo)->find($id); throw $this->exception("仓库{$repo->name}仍有库存未处理,请使用调拨/出库清理库存,或使用强制删除", 1); } } } return Repo::destroy($id); } }