Wind.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace catchAdmin\wind\controller;
  3. use catcher\base\CatchRequest as Request;
  4. use catcher\CatchResponse;
  5. use catcher\base\CatchController;
  6. use catchAdmin\wind\model\Wind as windModel;
  7. class Wind extends CatchController
  8. {
  9. protected $windModel;
  10. public function __construct(WindModel $windModel)
  11. {
  12. $this->windModel = $windModel;
  13. }
  14. /**
  15. * 列表
  16. * @time 2022年04月27日 10:49
  17. * @param Request $request
  18. */
  19. public function index(Request $request) : \think\Response
  20. {
  21. return CatchResponse::paginate($this->windModel->getList());
  22. }
  23. /**
  24. * 列表
  25. * @time 2022年04月27日 10:49
  26. * @param Request $request
  27. */
  28. public function getWindList(Request $request) : \think\Response
  29. {
  30. return CatchResponse::success($this->windModel->getWindList());
  31. }
  32. /**
  33. * 保存信息
  34. * @time 2022年04月27日 10:49
  35. * @param Request $request
  36. */
  37. public function save(Request $request) : \think\Response
  38. {
  39. $post = $request->post();
  40. if (!isset($post['name']) || !$post['name']) {
  41. return CatchResponse::fail('风场名称不能为空');
  42. }
  43. if (!isset($post['wind_shape']) || !$post['wind_shape']) {
  44. return CatchResponse::fail('获取风场类型失败');
  45. }
  46. if (!isset($post['wind_info']) || !is_array($post['wind_info'])) {
  47. return CatchResponse::fail('获取风场坐标数据失败');
  48. }
  49. if (!isset($post['department_id']) || !is_array($post['department_id'])) {
  50. return CatchResponse::fail('获取风场所属部门失败');
  51. }
  52. // 检测名称重复
  53. if($this->windModel->where('name',$post['name'])->count()){
  54. return CatchResponse::fail('风场名称已存在');
  55. }
  56. $post['wind_info'] = json_encode($post['wind_info']);
  57. $post['department_id'] = array_pop($post['department_id']);
  58. return CatchResponse::success($this->windModel->storeBy($post));
  59. }
  60. /**
  61. * 读取
  62. * @time 2022年04月27日 10:49
  63. * @param $id
  64. */
  65. public function read($id) : \think\Response
  66. {
  67. return CatchResponse::success($this->windModel->findBy($id));
  68. }
  69. /**
  70. * 更新
  71. * @time 2022年04月27日 10:49
  72. * @param Request $request
  73. * @param $id
  74. */
  75. public function update(Request $request, $id) : \think\Response
  76. {
  77. $post = $request->post();
  78. if(isset($post['name'])){
  79. // 检测名称重复
  80. $n_id = $this->windModel->where('name',$post['name'])->value('id');
  81. if($n_id && ($n_id != $id)){
  82. return CatchResponse::fail('风场名称已存在');
  83. }
  84. }
  85. if(isset($post['department_id']) && is_array($post['department_id'])){
  86. $post['department_id'] = array_pop($post['department_id']);
  87. }
  88. $post['wind_info'] = json_encode($post['wind_info']);
  89. return CatchResponse::success($this->windModel->updateBy($id, $post));
  90. }
  91. /**
  92. * 删除
  93. * @time 2022年04月27日 10:49
  94. * @param $id
  95. */
  96. public function delete($id) : \think\Response
  97. {
  98. return CatchResponse::success($this->windModel->deleteBy($id,true));
  99. }
  100. /**
  101. * 获取风场下拉菜单
  102. * @time 2022年04月28日 19:53
  103. */
  104. public function getWindOptions(Request $request){
  105. $data = $request->get();
  106. $where = [];
  107. if($data["name"])
  108. {
  109. $where[] = ["name",'like','%'.$data['name'].'%'];
  110. }
  111. $list=$this->windModel->where($where)->field('id as value,name as text')->select();
  112. return CatchResponse::success($list);
  113. }
  114. }