model = new CardMain(); } /** * @Desc 插入前置方法 * @Author Gorden * @Date 2024/11/14 14:29 * * @param Request $request * @return array * @throws BusinessException */ public function insertInput(Request $request): array { $data = $this->inputFilter($request->post()); if ($data['card_main_valid_mode'] == 'DATE') { $data['card_main_valid_begin'] = date('Y-m-d 00:00:00', strtotime($data['card_main_valid_begin'])); $data['card_main_valid_end'] = date('Y-m-d 23:59:59', strtotime($data['card_main_valid_end'])); } return $data; } /** * 更新前置方法 * @param Request $request * @return array * @throws BusinessException */ protected function updateInput(Request $request): array { $primary_key = $this->model->getKeyName(); $id = $request->post($primary_key); $data = $this->inputFilter($request->post()); $model = $this->model->find($id); if (!$model) { throw new BusinessException('记录不存在', 2); } if ($data['card_main_valid_mode'] == 'DATE') { $data['card_main_valid_begin'] = date('Y-m-d 00:00:00', strtotime($data['card_main_valid_begin'])); $data['card_main_valid_end'] = date('Y-m-d 23:59:59', strtotime($data['card_main_valid_end'])); } unset($data[$primary_key]); return [$id, $data]; } }