root_id = request()->employee['root_id']; } /** * 显示资源列表 * * @return \think\Response */ public function index() { if(!request()->isAjax()) return View::fetch(); $data = ModelBuildingLabel::where(['root_id' => $this->root_id])->field('id,name')->select(); return json(['code'=>0, 'data'=>$data]); } /** * 保存新建的资源 * * @param \think\Request $request * @return \think\Response */ public function save($name) { ModelBuildingLabel::create([ 'name' => $name, 'addtime' => time(), 'root_id' => $this->root_id ]); return json(['code' => 0, 'msg' => '保存成功']); } /** * 保存更新的资源 * * @param \think\Request $request * @param int $id * @return \think\Response */ public function update($name, $id) { ModelBuildingLabel::where(['id' => $id, 'root_id' => $this->root_id])->update(['name'=>$name]); return json(['code' => 0, 'msg' => '修改成功']); } /** * 删除指定资源 * * @param int $id * @return \think\Response */ public function delete($id) { ModelBuildingLabel::where(['id' => $id, 'root_id' => $this->root_id])->delete(); BuildingProgress::where(['label_id' => $id, 'root_id' => $this->root_id])->update(['label_id'=>null]); return json(['code' => 0, 'msg' => '删除成功']); } }