12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- class PreOrder extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = '*';
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = Db::name('pre_order');
- }
- /**
- * 保存
- * @return void
- */
- public function save()
- {
- try {
- //验证参数
- $id = $this->request->param('id',0);
- $carId = $this->request->param('car_id',0);
- $preTime = $this->request->param('pre_time','');
- $userId = $this->auth->id;
- $scene = !empty($id) ? 'edit' : 'add';
- $validate = validate('PreOrder');
- if(!$validate->check($this->request->param(),[],$scene)){
- throw new Exception($validate->getError());
- }
- $time = time();
- $data = [
- 'company_id' => $this->request->param('company_id', 0),
- 'name' => $this->request->param('name', ''),
- 'mobile' => $this->request->param('mobile', ''),
- 'remark' => $this->request->param('remark', ''),
- 'car_id' => $carId,
- 'car_number' => $this->request->param('car_model', ''),
- 'servicetype_id' => $this->request->param('servicetype_id', ''),
- 'pre_time' => $this->request->param('pre_time', ''),
- ];
- if (empty($id)) {
- $data['user_id'] = $userId;
- $data['create'] = $time;
- $res = $this->model->insertGetId($data);
- } else {
- $data['updatetime'] = $time;
- $where['id'] = $id;
- $where['user_id'] = $userId;
- $res = $this->model->where($where)->update($data);
- }
- if (!$res) {
- throw new Exception('操作失败');
- }
- $this->success('操作成功');
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- }
- }
|