Member.php
11.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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<?php
namespace app\index\controller;
use app\admin\model\Faq;
use app\admin\model\Feedback;
use app\admin\model\Vipdesc;
use app\common\controller\Frontend;
use app\index\model\Goodscollect;
use app\index\model\OrderInfo;
use app\index\model\Price;
use app\index\model\Store;
use app\index\model\Storecollect;
use think\Db;
use think\Validate;
/**
* 个人中心
* Class Member
* @package app\index\controller
*/
class Member 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', 0);
}
// 基本信息
public function index()
{
$this->view->assign('is_nav', 1);
return $this->view->fetch();
}
// 修改基本信息
public function change_inform()
{
if($this->request->isAjax()) {
$param = $this->request->param();
$validate = new Validate([
'nickname' => 'require',
'mobile' => 'require|regex:^1\d{10}$|unique:user,mobile,'.$this->auth->id,
'work_address' => 'require'
]);
$validate->message([
'nickname.require' => '请填写昵称',
'mobile.require' => '请填写电话',
'mobile.regex' => '电话格式错误',
'mobile.unique' => '电话已存在',
'work_address.require' => '请填写办公地址'
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$user = $this->auth->getUser();
$user->nickname = $param['nickname'];
$user->mobile = $param['mobile'];
$user->work_address = $param['work_address'];
$user->updatetime = time();
$result = $user->save();
if(!$result) {
$this->error('修改失败');
}
$this->success('修改成功');
}
}
// 我的订单
public function order()
{
$this->view->assign('is_nav', 2);
return $this->view->fetch();
}
// 订单列表
public function order_list() {
if($this->request->isAjax()) {
$param = $this->request->param();
$order_detail_model = new \app\index\model\OrderDetail();
$order_info_model = new OrderInfo();
$store_model = new Store();
$where = [
'user_id' => $this->auth->id
];
if($param['status']) {
$where['status'] = $param['status'];
}
$order = $order_detail_model
->where($where)
->order('createtime','DESC')
->paginate($param['pageNum'],false,['page'=>$param['page']]);
$list = $order->items();
$status = [
'1' => '待支付',
'2' => '待发货',
'3' => '待收货',
'4' => '待评价',
'5' => '售后',
'6' => '已完成',
];
foreach ($list as $k=>$v) {
$order[$k]['store_name'] = $store_model->where('id',$v['store_id'])->value('name');
$order[$k]['goods'] = $order_info_model->where('order_id',$v['id'])->select();
$order[$k]['operate'] = $this->get_operate($v['status']);
$order[$k]['status'] = $status[$v['status']];
}
$return = [
'list' => $list,
'totalSize' => $order->total(),
'current_page' => $order->currentPage(),
'totalPage' => $order->lastPage(),
'pageNum' => $param['pageNum'],
];
$this->success('成功','',$return);
}
}
private function get_operate($status) {
$operate = '';
switch ($status) {
case '1':
$operate = '<button type="button" class="btn operateBtn operateBtnGreen topay">付款</button>' .
' <button type="button" class="btn operateBtn operateBtnGrey detail">查看订单</button>' .
' <button type="button" class="btn operateBtn operateBtnGrey cancel" >取消订单</button>';
break;
case '2':
$operate = '<button type="button" class="btn operateBtn operateBtnGreen refund">退款</button>' .
' <button type="button" class="btn operateBtn operateBtnGrey detail">查看订单</button>';
break;
case '3':
$operate = '<button type="button" class="btn operateBtn operateBtnGreen topay">付款</button>' .
' <button type="button" class="btn operateBtn operateBtnGrey detail">查看订单</button>' .
' <button type="button" class="btn operateBtn operateBtnGrey cancel" >取消订单</button>';
break;
case '4':
$operate = '<button type="button" class="btn operateBtn operateBtnGreen confirm">确认收货</button>' .
' <button type="button" class="btn operateBtn operateBtnGreen refund">退款</button>' .
' <button type="button" class="btn operateBtn operateBtnGrey detail" >查看订单</button>';
break;
case '5':
$operate = '<button type="button" class="btn operateBtn operateBtnGreen comment">去评价</button>' .
' <button type="button" class="btn operateBtn operateBtnGrey detail">查看订单</button>';
break;
case '6':
$operate = '<button type="button" class="btn operateBtn operateBtnGrey delete">删除</button>';
break;
case '7':
$operate = '<button type="button" class="btn operateBtn operateBtnGrey detail">查看订单</button>';
break;
case '8':
$operate = '<button type="button" class="btn operateBtn operateBtnGrey detail">查看订单</button>';
break;
}
return $operate;
}
// 我的会员
public function member()
{
$store_model = new Store();
$store = $store_model->where('user_id',$this->auth->id)->find();
$is_vip = 0;
if($store) {
if($store['svip_passtime'] > time()) {
$is_vip = 1;
$passtime = date('Y-m-d');
}
}
$this->view->assign('is_nav', 3);
return $this->view->fetch();
}
public function vip() {
$price_model = new Price();
$vipdesc_model = new Vipdesc();
$price = $price_model->where('id',1)->find();
$vipdesc = $vipdesc_model->where('id',1)->find();
$this->view->assign('price',$price);
$this->view->assign('vipdesc',$vipdesc);
return $this->view->fetch();
}
public function svip() {
$price_model = new Price();
$vipdesc_model = new Vipdesc();
$price = $price_model->where('id',1)->find();
$vipdesc = $vipdesc_model->where('id',1)->find();
$this->view->assign('price',$price);
$this->view->assign('vipdesc',$vipdesc);
return $this->view->fetch();
}
// 我的收藏
public function favorite()
{
$this->view->assign('is_nav', 4);
return $this->view->fetch();
}
// 收藏的商品
public function goodscollect() {
if($this->request->isAjax()) {
$param = $this->request->param();
$goodscollect_model = new Goodscollect();
$store_model = new Store();
$where = [
'goodscollect.user_id' => $this->auth->id,
'goods.status' => '1'
];
$goodscollect = $goodscollect_model
->with(['goods'])
->where($where)
->paginate($param['pageNum'],false,['page'=>$param['page']]);
$collect_list = $goodscollect->items();
$list = [];
foreach ($collect_list as $k=>$v) {
$store = $store_model->field('name,property')->where('id',$v['goods']['store_id'])->find();
$list[] = [
'href' => url('goods/detail',['goods_id'=>$v['goods']['id']]),
'goods_id' => $v['goods']['id'],
'goodsname' => $v['goods']['goodsname'],
'thumbnail' => $v['goods']['thumbnail'],
'store_name' => $store['name'],
'price' => $v['goods']['price'],
'property' => explode(',',$store['property']),
];
}
$return = [
'list' => $list,
'totalSize' => $goodscollect->total(),
'current_page' => $goodscollect->currentPage(),
'totalPage' => $goodscollect->lastPage(),
'pageNum' => $param['pageNum'],
];
$this->success('成功','',$return);
}
}
// 收藏的店铺
public function storecollect() {
if($this->request->isAjax()) {
$param = $this->request->param();
$storecollect_model = new Storecollect();
$where = [
'storecollect.user_id' => $this->auth->id
];
$storecollect = $storecollect_model
->with(['store'])
->where($where)
->paginate($param['pageNum'],false,['page'=>$param['page']]);
$collect_list = $storecollect->items();
$list = [];
foreach ($collect_list as $k=>$v) {
$list[] = [
'href' => url('store/detail',['store_id'=>$v['store']['id']]),
'store_id' => $v['goods']['id'],
'name' => $v['store']['name']
];
}
$return = [
'list' => $list,
'totalSize' => $storecollect->total(),
'current_page' => $storecollect->currentPage(),
'totalPage' => $storecollect->lastPage(),
'pageNum' => $param['pageNum'],
];
$this->success('成功','',$return);
}
}
// 常见问题
public function question()
{
$faq_model = new Faq();
$faq = $faq_model->where('id',1)->find();
$this->view->assign('faq',$faq);
$this->view->assign('is_nav', 5);
return $this->view->fetch();
}
// 问题反馈
public function feedback()
{
$this->view->assign('is_nav', 6);
return $this->view->fetch();
}
// 问题反馈提交
public function feedback_submit()
{
if($this->request->isAjax()) {
$param = $this->request->param();
$validate = new Validate([
'name' => 'require',
'content' => 'require',
'phone' => 'require|regex:^1\d{10}$'
]);
$validate->message([
'nickname.require' => '请填写昵称',
'content.require' => '请填写留言内容',
'phone.require' => '请填写手机',
'phone.regex' => '手机格式错误'
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$feedback_model = new Feedback();
$param['user_id'] = $this->auth->id;
$result = $feedback_model->save($param);
if(!$result) {
$this->error('反馈提交失败');
}
$this->success('反馈提交成功');
}
}
}