IndexController.php
6.1 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use think\Db;
use think\Request;
use think\Validate;
class IndexController extends HomeBaseController
{
public function index()
{
echo '<h1>==403Forbidden==</h1>';
}
//step1 在线报名
public function online_baoming()
{
// $re = Db::name('user')->where(['openid'=>session('openid')])->find();
// if($re && $re['student_type'] == '1'){
// $this->success('您已成功报名,无需再次报名',url('user/login/index'));
// }elseif ($re['user_type'] == '3'){
// $this->success('教练无需报名',url('user/login/index'));
// }
$res = Db::name('goods')->where(['delete_time' => '0', 'status' => '1'])->select()->toArray();
$this->assign('data', $res);
return $this->fetch();
}
//step2 在线报名详情
public function baoming_detail(Request $req)
{
$id = $req->param('id');
if (!$id) {
return $this->error('参数错误');
}
$res = Db::name('goods')->where(['id' => $id])->find();
$this->assign('data', $res);
return $this->fetch();
}
//step3 报名信息填写
public function write_info(Request $req)
{
$id = $req->param('gid');
$this->assign('gid', $id);
$resp = Db::name('goods')->where(['id' => $id])->value('hetong');
$this->assign('page', htmlspecialchars_decode($resp));
return $this->fetch();
}
//step4 提交报名信息ajax
public function baoming_do()
{
$re = Db::name('user')->where(['openid'=>session('openid')])->find();
if($re && $re['student_type'] == '1'){
return json(['code' => '0', 'msg' => '您已成功报名,无需再次报名']);
}elseif ($re['user_type'] == '3'){
return json(['code' => '0', 'msg' => '教练无需报名']);
}
$rules = [
'name' => 'require',
'sex' => 'require',
'birthday' => 'require',
'idnumber' => 'require',
'mobile' => 'require',
'sms_code' => 'require',
];
$validate = new Validate($rules);
$validate->message([
'name.require' => '姓名不能为空',
'sex.require' => '性别不能为空',
'birthday.require' => '生日不能为空',
'idnumber.require' => '身份证号不能为空',
'mobile.require' => '手机号不能为空',
'sms_code.require' => '验证码不能为空',
]);
//验证参数
$data = $this->request->post();
if (!$validate->check($data)) {
return json(['code' => '0', 'msg' => $validate->getError()]);
}
//验证验证码
$sres = cmf_check_verification_code($data['mobile'], $data['sms_code']);
if ($sres != '') {
return json(['code' => '0', 'msg' => $sres]);
}
$dataup['user_nickname'] = $data['name'];
$dataup['sex'] = $data['sex'];
$dataup['birthday'] = $data['birthday'];
$dataup['mobile'] = $data['mobile'];
$dataup['idnumber'] = $data['idnumber'];
$dataup['add_type'] = '1';
$w['openid'] = session('openid');
$re = Db::name("user")
->where($w)
->find();
if ($re) {
$dataup['id'] = $re['id'];
session('user.id', $dataup['id']);
$res = Db::name('user')->update($dataup);
if ($res) {
return json(['code' => '1', 'msg' => '保存成功']);
} else {
return json(['code' => '0', 'msg' => '保存失败']);
}
} else {
return json(['code' => '0', 'msg' => '保存失败']);
}
}
public function confirm_order(Request $req)
{
$gid = $req->param('gid');
$id = session('user.id');
$re = Db::name('user')->where(['id' => $id])->find();
$res = Db::name('goods')->where(['id' => $gid])->find();
$this->assign('data', $re);
$this->assign('gdata', $res);
$this->assign('gid', $gid);
return $this->fetch();
}
//订单入库 ajax
public function baoming_dodata(Request $req)
{
$gid = $req->param('gid');
$res = Db::name('goods')->where(['id' => $gid])->find();
$id = session('user.id');
$data['gid'] = $gid;
$data['uid'] = $id;
$data['create_time'] = time();
$data['price'] = $res['price'];
$data['out_trade_no'] = date('YmdHis') . rand(111,999);
$rr = Db::name('order')->insert($data);
if ($rr) {
return json(['code' => '1', 'msg' => '保存成功', 'data' => $data['out_trade_no']]);
} else {
return json(['code' => '0', 'msg' => '保存失败']);
}
}
//学员手册
public function student_shouce()
{
$data = Db::name('portal_post')->select()->toArray();
$this->assign('data', $data);
return $this->fetch();
}
//手册详情
public function shouce_details(Request $req)
{
$id = $req->param('id');
$data = Db::name('portal_post')->where(['id' => $id])->find();
$this->assign('data', $data);
return $this->fetch();
}
//关于我们
public function about()
{
return $this->fetch();
}
}