1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace app\admin\controller\coupon;
- use app\controller\Curd;
- use app\model\CardMain;
- use support\exception\BusinessException;
- use support\Request;
- class CardMainController extends Curd
- {
- public function __construct()
- {
- $this->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];
- }
- }
|