BuildingLabel.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\Sys\controller;
  4. use app\model\BuildingLabel as ModelBuildingLabel;
  5. use app\model\BuildingProgress;
  6. use think\facade\View;
  7. class BuildingLabel
  8. {
  9. private $root_id;
  10. public function __construct()
  11. {
  12. $this->root_id = request()->employee['root_id'];
  13. }
  14. /**
  15. * 显示资源列表
  16. *
  17. * @return \think\Response
  18. */
  19. public function index()
  20. {
  21. if(!request()->isAjax()) return View::fetch();
  22. $data = ModelBuildingLabel::where(['root_id' => $this->root_id])->field('id,name')->select();
  23. return json(['code'=>0, 'data'=>$data]);
  24. }
  25. /**
  26. * 保存新建的资源
  27. *
  28. * @param \think\Request $request
  29. * @return \think\Response
  30. */
  31. public function save($name)
  32. {
  33. ModelBuildingLabel::create([
  34. 'name' => $name,
  35. 'addtime' => time(),
  36. 'root_id' => $this->root_id
  37. ]);
  38. return json(['code' => 0, 'msg' => '保存成功']);
  39. }
  40. /**
  41. * 保存更新的资源
  42. *
  43. * @param \think\Request $request
  44. * @param int $id
  45. * @return \think\Response
  46. */
  47. public function update($name, $id)
  48. {
  49. ModelBuildingLabel::where(['id' => $id, 'root_id' => $this->root_id])->update(['name'=>$name]);
  50. return json(['code' => 0, 'msg' => '修改成功']);
  51. }
  52. /**
  53. * 删除指定资源
  54. *
  55. * @param int $id
  56. * @return \think\Response
  57. */
  58. public function delete($id)
  59. {
  60. ModelBuildingLabel::where(['id' => $id, 'root_id' => $this->root_id])->delete();
  61. BuildingProgress::where(['label_id' => $id, 'root_id' => $this->root_id])->update(['label_id'=>null]);
  62. return json(['code' => 0, 'msg' => '删除成功']);
  63. }
  64. }