CinemaController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace app\admin\controller\life;
  3. use app\admin\validate\life\CinemaValidate;
  4. use app\controller\Curd;
  5. use app\model\Cinema as CinemaModel;
  6. use support\exception\BusinessException;
  7. use support\Request;
  8. use support\Response;
  9. class CinemaController extends Curd
  10. {
  11. public function __construct()
  12. {
  13. $this->model = new CinemaModel();
  14. $this->validate = true;
  15. $this->validateClass = new CinemaValidate();
  16. }
  17. /**
  18. * @Desc 影片列表
  19. * @Author Gorden
  20. * @Date 2024/2/26 13:42
  21. *
  22. * @param Request $request
  23. * @return Response
  24. * @throws \support\exception\BusinessException
  25. */
  26. public function select(Request $request): Response
  27. {
  28. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  29. $where['cinema_is_del'] = 0;
  30. $order = $request->get('order', 'desc');
  31. $field = $field ?? 'cinema_addTime';
  32. $query = $this->doSelect($where, $field, $order);
  33. return $this->doFormat($query, $format, $limit);
  34. }
  35. /**
  36. * @Desc 查询后数据处理
  37. * @Author Gorden
  38. * @Date 2024/3/21 14:13
  39. *
  40. * @param $items
  41. * @return void
  42. */
  43. public function afterQuery($items)
  44. {
  45. foreach ($items as &$item) {
  46. $item->cinema_img = !empty($item->cinema_img) ? getenv('STORAGE_DOMAIN') . $item->cinema_img : '';
  47. $item->cinema_video = !empty($item->cinema_video) ? getenv('STORAGE_DOMAIN') . $item->cinema_video : '';
  48. $item->cinema_time = !empty($item->cinema_time) ? date('Y-m-d H:i:s', strtotime($item->cinema_time)) : '';
  49. $item->cinema_label = !empty($item->cinema_label) ? explode(',', $item->cinema_label) : '';
  50. $item->cinema_mold = !empty($item->cinema_mold) ? explode(',', $item->cinema_mold) : '';
  51. $item->cinema_director = !empty($item->cinema_director) ? array_map('intval', explode(',', $item->cinema_director)) : '';
  52. $item->cinema_star = !empty($item->cinema_star) ? array_map('intval', explode(',', $item->cinema_star)) : '';
  53. $item->cinema_performers = !empty($item->cinema_performers) ? array_map('intval', explode(',', $item->cinema_performers)) : '';
  54. }
  55. return $items;
  56. }
  57. /**
  58. * @Desc 新增数据处理
  59. * @Author Gorden
  60. * @Date 2024/3/21 14:11
  61. *
  62. * @param Request $request
  63. * @return array
  64. * @throws \support\exception\BusinessException
  65. */
  66. protected function insertInput(Request $request): array
  67. {
  68. $data = $this->inputFilter($request->post());
  69. if (!empty($data['cinema_img'])) {
  70. $data['cinema_img'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['cinema_img']);
  71. }
  72. if (!empty($data['cinema_video'])) {
  73. $data['cinema_video'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['cinema_video']);
  74. }
  75. return $data;
  76. }
  77. protected function updateInput(Request $request): array
  78. {
  79. $primary_key = $this->model->getKeyName();
  80. $id = $request->post($primary_key);
  81. $data = $this->inputFilter($request->post());
  82. $data['cinema_img'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['cinema_img']);
  83. $data['cinema_video'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['cinema_video']);
  84. $model = $this->model->find($id);
  85. if (!$model) {
  86. throw new BusinessException('记录不存在', 2);
  87. }
  88. unset($data[$primary_key]);
  89. return [$id, $data];
  90. }
  91. /**
  92. * @Desc 影片软删除
  93. * @Author Gorden
  94. * @Date 2024/2/26 13:43
  95. *
  96. * @param Request $request
  97. * @return Response
  98. * @throws \support\exception\BusinessException
  99. */
  100. public function delete(Request $request): Response
  101. {
  102. $ids = $this->deleteInput($request);
  103. $this->doSoftDelete($ids, ['cinema_is_del' => 1]);
  104. return json_success('success');
  105. }
  106. }