FieldController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace app\admin\controller\sys_manage;
  3. use app\admin\service\sys_manage\FieldService;
  4. use app\admin\validate\sys_manage\FieldValidate;
  5. use app\controller\Curd;
  6. use app\model\Content;
  7. use app\model\SysField;
  8. use Illuminate\Support\Facades\Schema;
  9. use support\Request;
  10. use support\Response;
  11. class FieldController extends Curd
  12. {
  13. public function __construct()
  14. {
  15. $this->model = new SysField();
  16. }
  17. /**
  18. * @Desc 字段列表
  19. * @Author Gorden
  20. * @Date 2024/2/22 14:49
  21. *
  22. * @param Request $request
  23. * @return \support\Response
  24. */
  25. public function fieldList(Request $request)
  26. {
  27. return FieldService::fieldList($request);
  28. }
  29. public function selectList(Request $request): Response
  30. {
  31. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  32. $query = $this->doSelect($where, $field, $order);
  33. return $this->doFormat($query, $format, 1000);
  34. }
  35. /**
  36. * @Desc 字段详情
  37. * @Author Gorden
  38. * @Date 2024/2/22 14:54
  39. *
  40. * @param $id
  41. * @return \support\Response
  42. */
  43. public function fieldInfo($id)
  44. {
  45. return FieldService::fieldInfo($id);
  46. }
  47. /**
  48. * @Desc 新建字段
  49. * @Author Gorden
  50. * @Date 2024/2/22 14:32
  51. *
  52. * @param Request $request
  53. * @return \support\Response
  54. */
  55. public function addField(Request $request)
  56. {
  57. $validate = new FieldValidate();
  58. if (!$validate->scene('add')->check($request->post())) {
  59. return json_fail($validate->getError());
  60. }
  61. // 验证数据表是否存在
  62. if (!FieldService::checkTableExist($request->post('field_table'))) {
  63. return json_fail('数据表不存在');
  64. }
  65. // 验证字段重复
  66. if (FieldService::checkFieldExist($request->post('field_table'), $request->post('field_column_key'))) {
  67. return json_fail('字段已存在,请勿重复添加');
  68. }
  69. return FieldService::addField($request->post());
  70. }
  71. /**
  72. * @Desc 修改字段
  73. * @Author Gorden
  74. * @Date 2024/2/22 14:41
  75. *
  76. * @param $id
  77. * @param Request $request
  78. * @return \support\Response
  79. */
  80. public function updateFields($id, Request $request)
  81. {
  82. $validate = new FieldValidate();
  83. if (!$validate->scene('update')->check($request->post())) {
  84. return json_fail($validate->getError());
  85. }
  86. // 验证数据表是否存在
  87. if (!FieldService::checkTableExist($request->post('field_table'))) {
  88. return json_fail('数据表不存在');
  89. }
  90. return FieldService::updateField($id, $request->post());
  91. }
  92. /**
  93. * @Desc 修改字段状态
  94. * @Author Gorden
  95. * @Date 2024/2/22 15:05
  96. *
  97. * @param $id
  98. * @param Request $request
  99. * @return \support\Response
  100. */
  101. public function updateStatus($id, Request $request)
  102. {
  103. $validate = new FieldValidate();
  104. if (!$validate->scene('update_status')->check($request->post())) {
  105. return json_fail($validate->getError());
  106. }
  107. return FieldService::updateStatus($id, $request->post());
  108. }
  109. /**
  110. * @Desc 删除字段
  111. * @Author Gorden
  112. * @Date 2024/2/22 15:08
  113. *
  114. * @param $id
  115. * @return \support\Response
  116. */
  117. public function delField(Request $request)
  118. {
  119. $fieldId = $request->post('field_id');
  120. return FieldService::delField($fieldId);
  121. }
  122. }