12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- declare(strict_types=1);
- namespace app\Sys\controller;
- use app\model\BuildingLabel as ModelBuildingLabel;
- use app\model\BuildingProgress;
- use think\facade\View;
- class BuildingLabel
- {
- private $root_id;
- public function __construct()
- {
- $this->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' => '删除成功']);
- }
- }
|