CardMainController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\admin\controller\coupon;
  3. use app\controller\Curd;
  4. use app\model\CardMain;
  5. use support\exception\BusinessException;
  6. use support\Request;
  7. class CardMainController extends Curd
  8. {
  9. public function __construct()
  10. {
  11. $this->model = new CardMain();
  12. }
  13. /**
  14. * @Desc 插入前置方法
  15. * @Author Gorden
  16. * @Date 2024/11/14 14:29
  17. *
  18. * @param Request $request
  19. * @return array
  20. * @throws BusinessException
  21. */
  22. public function insertInput(Request $request): array
  23. {
  24. $data = $this->inputFilter($request->post());
  25. if ($data['card_main_valid_mode'] == 'DATE') {
  26. $data['card_main_valid_begin'] = date('Y-m-d 00:00:00', strtotime($data['card_main_valid_begin']));
  27. $data['card_main_valid_end'] = date('Y-m-d 23:59:59', strtotime($data['card_main_valid_end']));
  28. }
  29. return $data;
  30. }
  31. /**
  32. * 更新前置方法
  33. * @param Request $request
  34. * @return array
  35. * @throws BusinessException
  36. */
  37. protected function updateInput(Request $request): array
  38. {
  39. $primary_key = $this->model->getKeyName();
  40. $id = $request->post($primary_key);
  41. $data = $this->inputFilter($request->post());
  42. $model = $this->model->find($id);
  43. if (!$model) {
  44. throw new BusinessException('记录不存在', 2);
  45. }
  46. if ($data['card_main_valid_mode'] == 'DATE') {
  47. $data['card_main_valid_begin'] = date('Y-m-d 00:00:00', strtotime($data['card_main_valid_begin']));
  48. $data['card_main_valid_end'] = date('Y-m-d 23:59:59', strtotime($data['card_main_valid_end']));
  49. }
  50. unset($data[$primary_key]);
  51. return [$id, $data];
  52. }
  53. }