Maintain.php
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace app\index\controller;
use app\admin\model\Mainlist;
use app\common\controller\Frontend;
use app\index\model\Area;
class Maintain extends Frontend
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->view->assign('is_search', 0);
$this->view->assign('is_active', 4);
$this->view->assign('title', '产品维修');
}
public function index() {
$maintain_model = new \app\index\model\Maintain();
$maintainer_model = new \app\index\model\Maintainer();
$maintain = $maintain_model->where('id',1)->find();
$maintainer = $maintainer_model->select();
//省市区三级联动
$areaModel = new Area();
$province = $areaModel->selectData(['pid'=>0,'level'=>1]);
$province_id = !empty($province[0]['id']) ? $province[0]['id'] : 0;
$city = $areaModel->selectData(['pid'=>$province_id,'level'=>2]);
$city_id = !empty($city[0]['id']) ? $city[0]['id'] : 0;
$county = $areaModel->selectData(['pid'=>$city_id,'level'=>3]);
$this->assign('province',$province);
$this->assign('city',$city);
$this->assign('county',$county);
$this->view->assign('maintain',$maintain);
$this->view->assign('maintainer',$maintainer);
return $this->view->fetch();
}
// 我要维修提交
public function maintain_submit() {
if($this->request->isAjax()) {
$param = $this->request->param();
$validate = new \think\Validate([
'name' => 'require',
'phone' => 'require|regex:^1\d{10}$',
'province' => 'require',
'city' => 'require',
'address' => 'require',
'content' => 'require',
]);
$validate->message([
'name.require' => '请输入姓名!',
'phone.require' => '请输入手机号!',
'phone.regex' => '手机号格式错误!',
'province.require' => '请选择省!',
'city.require' => '请选择市!',
'county.require' => '请选择区/县!',
'address.require' => '请输入详细地址!',
'content.require' => '请输入需求描述!',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$mainlist_model = new Mainlist();
$result = $mainlist_model->save($param);
if(!$result) {
$this->error('提交失败');
}
$this->success('提交成功');
}
}
}