Evaluate.php
16.9 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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
/**
* Created by PhpStorm.
* User: wxd1061
* Date: 2017-05-02
* Time: 11:31
*/
namespace app\mobile\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\response\Json;
use think\Session;
use think\Cookie;
class Evaluate extends MobileBase
{
//MobileBase Controller
public $user_id = 0;
//19534
public $user = array();
/**
* 析构流函数
*/
public function __construct()
{
parent::__construct();
if (session('?user')) {
$user = session('user');
$user = M('users')->where("user_id", $user['user_id'])->find();
session('user', $user); //覆盖session 中的 user
$this->user = $user;
$this->user_id = $user['user_id'];
$this->assign('user', $user); //存储用户信息
} else {
$uid = Cookie::get('user_id');
if ($uid) {
$user = M('users')->where("user_id", $uid)->where("store_id", getMobileStoId())->find();
session('user', $user); //覆盖session 中的 user
$this->user = $user;
$this->user_id = $user['user_id'];
$this->assign('user', $user); //存储用户信息
}
}
$nologin = array(
'getNum',
);
if ($this->user_id == 0) {
$this->error('请先登录', U('Mobile/User/login', array('stoid' => getMobileStoId())));
}
if (!in_array(ACTION_NAME, $nologin)) {
if (($this->pm_erpid && (!$user || !$user['erpvipid'])) || (empty($this->pm_erpid) && !$user || !$user['mobile'])) {
$this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId())));
exit;
}
}
}
/**推送打开评论页面**/
public function first()
{
$state = I('state');
$POSNo = I('POSNo');
$user_info = M('users')->alias('a')
->join('store b', 'a.store_id=b.store_id', 'left')
->field('a.*,b.api_token,b.store_logo,b.store_name')
->where("a.user_id", $this->user_id)->find();//调取api_token,商家LOGO,商家名称
if ($user_info) {
if (empty($user_info['erpvipno'])) {
$sto_erpid = $user_info['ERPId'];
if ($user_info['erpvipid']) {
$whereId['VIPId'] = $user_info['erpvipid'];
$rs_one = getApiData_java_p("/api/erp/vip/info/page", $sto_erpid, $whereId, 1, 10, null, "GET");
if ($rs_one) {
$rs_one_data = json_decode($rs_one, true);
if ($rs_one_data['code'] == 0) {
$rs_one1datainfo = $rs_one_data['data']['pageData'][0];
if ($rs_one1datainfo) {
$user_info['erpvipno'] = $rs_one1datainfo['VIPNo'];
M('users')->where(array('store_id' => $user_info['store_id'], 'user_id' => $user_info['user_id']))->save(array('erpvipno' => $rs_one1datainfo['VIPNo']));
}
}
}
}
}
$mapuser['VIPNo'] = $user_info['erpvipno'];//token验证
//第一次进入
mlog("第一次进入:" . json_encode($state), "evaluate_state/" . getMobileStoId());
if ($state == 'STATE' || $state == '') {
$where = array(
'IsEvaluate' => 0,
'vipno' => $user_info['erpvipno'],
'posno' => ''
);
} else if ($state == 'add') {
//列表add进入
$where = array(
'vipno' => '',
'posno' => $POSNo,
);
}
mlog("搜索条件:" . json_encode($where), "evaluate_state/" . getMobileStoId());
$user_rs = getApiData('wxd.pos.prc.posevaluate.list', $user_info['api_token'], null, $where, '', '1', 'BillDate desc');
mlog("接口返回:" . $user_rs, "evaluate_state/" . getMobileStoId());
$user_rs = json_decode($user_rs, 'true');
if ($user_rs && $user_rs['code'] == 1 && $user_rs['data'][0]['POSNo']) {
//还有订单未评价,调取最新未评价订单
$order_info = $user_rs['data'][0];
$other = $user_rs['data'][0]['StarLabelname'];
$order_info['StarLabelname'] = json_decode($other, 'true');
$order_info['store_logo'] = $user_info['store_logo'];
return json(["code" => 1, "msg" => "还有多条订单", "data" => $order_info]);
} else {
//所有订单已经评价跳转至列表页
$this->redirect(U('Mobile/Evaluate/evaluate_list', array('stoid' => getMobileStoId())));
}
}
}
/** 评论页面状态**/
public function evaluate()
{
//是否关闭免费使用优惠券
$switch = tpCache('shopping.switch_list', getMobileStoId());//获取开关json
$switch = json_decode($switch, true);
$is_closecoupon = $switch['is_closecoupon'];
$this->assign('is_closecoupon', $is_closecoupon);
mlog("取会员Id:" . $this->user_id, "evaluate/" . getMobileStoId());
$state = I('state');
$POSNo = I('POSNo');
$user_info = M('users')->alias('a')
->join('store b', 'a.store_id=b.store_id', 'left')
->field('a.*,b.api_token,b.store_logo,b.store_name,b.ERPId')
->where("a.user_id", $this->user_id)->find();//调取api_token,商家LOGO,商家名称
if ($user_info) {
if (empty($user_info['erpvipno']) && $user_info['erpvipid']) {
$sto_erpid = $user_info['ERPId'];
$whereId['VIPId'] = $user_info['erpvipid'];
$rs_one = getApiData_java_p("/api/erp/vip/info/page", $sto_erpid, $whereId, 1, 10, null, "GET");
if ($rs_one) {
$rs_one_data = json_decode($rs_one, true);
if ($rs_one_data['code'] == 0 ) {
$rs_one1datainfo = $rs_one_data['data']['pageData'][0];
$user_info['erpvipno'] = $rs_one1datainfo['VIPNo'];
M('users')->where(array('store_id' => $user_info['store_id'], 'user_id' => $user_info['user_id']))->save(array('erpvipno' => $rs_one1datainfo['VIPNo']));
}
}
}
$mapuser['VIPNo'] = $user_info['erpvipno'];//token验证
if ($state == 'edit' && !empty($POSNo)) {
//列表点击进入,根据订单号查询
if ($state == 'add' || $state == 'edit') {
$where = array(
'vipno' => '',
'posno' => $POSNo,
);
$order_info = getApiData('wxd.pos.prc.posevaluate.list', $user_info['api_token'], null, $where);//内含主表星级以及自定义评价
$order_info = json_decode($order_info, 'true');
if ($order_info && $order_info['code'] == 1) {
$other = $order_info['data'][0]['StarLabelname'];
$other = json_decode($other, 'true');
$order_info = $order_info['data'][0];
$goods_info = $other['goodinfo'];
$star_bs = $other['data2'];
$star_bs = json_encode($star_bs);
//所有星级的评价
$star = $other['data'];
}
//查询状态调取对应的星级
$where = array(
'POSNo' => $POSNo,
);
$fixpro = getApiData('wxd.pos.evaluatelist.list', $user_info['api_token'], null, $where);//查询从表固定评价
$fixpro = json_decode($fixpro, 'true');
$fixpro = $fixpro['data'];
// $onlyorder = I('onlyorder'); //(只有一条订单时,提交评价后判断)且不显示按钮(评价其他订单)
// if (!empty($onlyorder)) {
// $this->assign('onlyorder', $onlyorder);//判断按钮显示
// };
if ($order_info['$order_info'] == '0' || $order_info['$order_info'] == '') {
$onlyorder = '2';
$this->assign('onlyorder', $onlyorder);//判断按钮显示
};
$this->assign('fixpro', $fixpro);//渲染该单固定评价
}
}
$this->assign('star_edit', json_encode($star));//所有星级评价信息
$this->assign('star_bs', $star_bs);//所有星级标识
$this->assign('goods_info', $goods_info);//所有商品信息
$this->assign('order_info', $order_info);//渲染订单信息
$this->assign('store_logo', $user_info['store_logo']);//渲染店铺头像
$this->assign('state', $state);//传递状态add||edit
$this->assign('POSNo', $POSNo);//传订单编号
}
return $this->fetch();
}
/**提交评价内容**/
public function refer_eva()
{
$data = I('post.');
$data['EvaluateDatetime'] = $time = date("Y-m-d H:i:s", time());//添加评价时间
$user_info = M('users')->alias('a')
->join('store b', 'a.store_id=b.store_id', 'left')
->field('a.*,b.api_token,b.store_logo,b.store_name')
->where("a.user_id", $this->user_id)->find();//调取api_token,商家LOGO,商家名称
if ($user_info) {
//添加评价
$data['LabelName'] = explode(',', $data['LabelName']);
$data['LabelName1'] = '';
foreach ($data['LabelName'] as $k => $vo) {
$data['LabelName1'][$k] = array(
'LabelName' => $data['LabelName'][$k],
'POSNo' => $data['POSNo']
);
}
$data['LabelName'] = $data['LabelName1'];
unset($data['LabelName1']);
$data_main = $data;
mlog("0条件:" . json_encode($data_main), "refer_eva/" . getMobileStoId());
$main_table = getApiData('wxd.pos.evaluateparaformlist.add', $user_info['api_token'], $data_main);//插入主表
mlog("1条件:" . $main_table, "refer_eva/" . getMobileStoId());
$main_table = json_decode($main_table, 'true');
if (isset($main_table['code'])) {
if ($main_table && $main_table['code'] == '1') {//插入成功后判断该VIPNo是否存在其他订单,是:返回列表,否:跳转该订单详情页
$where = array(
'VIPNo' => $user_info['erpvipno'],
'IsEvaluate' => 0
);
mlog("4条件:" . json_encode($where), "refer_eva/" . getMobileStoId());
$sur_order = getApiData('wxd.pos.vealuateform.list', $user_info['api_token'], null, $where);//查询是否还有订单未评价
mlog("5条件:" . json_encode($sur_order), "refer_eva/" . getMobileStoId());
$sur_order = json_decode($sur_order, 'true');
if ($sur_order && $sur_order['code'] == 1 && $sur_order['count'] && $sur_order['count'] == 1) {
return json(["code" => 1, "msg" => "评价成功", "count" => 1]);//评价插入成功(订单条数=1)
} else {
return json(["code" => 1, "msg" => "评价成功", "count" => 2]);//评价插入成功(订单条数>1)
}
} else {
return json(["code" => -1, "msg" => "系统繁忙,请稍后"]);//(从)未成功添加信息
}
// if ($main_table && $main_table['code'] == '1' ) {
// //从表
// $slave_main = $data;
// unset($slave_main['Remark']);
// unset($slave_main['Star']);
// unset($slave_main['EvaluateDatetime']);
// mlog("2条件:".json_encode($slave_main),"refer_eva/".getMobileStoId());
// $slave_table = getApiData('wxd.pos.evaluatelist.add', $user_info['api_token'], array($slave_main));
// mlog("3条件:".json_encode($slave_table),"refer_eva/".getMobileStoId());
// $slave_table = json_decode($slave_table, 'true');
//
//
// } else {
// return json(["code" => -1, "msg" => "系统繁忙,请稍后"]);//(主)未成功添加信息
// }
}
}
return $this->fetch();
}
/** 评论列表**/
public
function evaluate_list()
{
$IsEvaluate = I('IsEvaluate');
$user_info = M('users')->alias('a')
->join('store b', 'a.store_id=b.store_id', 'left')
->field('a.*,b.api_token,b.store_logo,b.store_name')
->where("a.user_id", $this->user_id)->find();//调取api_token,商家LOGO,商家名称
if ($user_info) {
$mapuser['VIPNo'] = $user_info['erpvipno'];//token验证
//加载订单信息
if ($IsEvaluate != '') {
$where = array(
'VIPNo' => $user_info['erpvipno'],
'IsEvaluate' => $IsEvaluate
);
} else {
$where = array(
'VIPNo' => $user_info['erpvipno'],
);
}
mlog("1条件:" . json_encode($where), "evaluate_list/" . getMobileStoId());
//查询用户历史订单
$user_rs = getApiData('wxd.pos.vealuateform.list', $user_info['api_token'], null, $where, '', '', 'BillDate desc ,IsEvaluate asc');
mlog("2返回:" . $user_rs, "evaluate_list/" . getMobileStoId());
$user_rs = json_decode($user_rs, 'true');
if ($user_rs && $user_rs['code'] == 1 && $user_rs['count'] && $user_rs['count'] = 1) {
$order_num = $user_rs['data'];
$order_info = $user_rs['data'];
$this->assign('order_info', $order_info);//渲染订单信息
$this->assign('store_logo', $user_info['store_logo']);//渲染店铺头像
// $this->assign('goods_name', $goods_name);//渲染商品名称以及数量
} else {
$order_null = '1';
$this->assign('order_null', $order_null);//暂无订单
}
}
return $this->fetch();
}
/** 评论列表调取商品信息**/
public
function goods_list()
{
$POSNo = I('POSNo');
$user_info = M('users')->alias('a')
->join('store b', 'a.store_id=b.store_id', 'left')
->field('a.*,b.api_token,b.store_logo,b.store_name')
->where("a.user_id", $this->user_id)->find();//调取api_token,商家LOGO,商家名称
if ($user_info) {
//调取一条订单的所有商品信息
$where = array(
'POSNo' => $POSNo,
);
$goods_info = getApiData('wxd.pos.vposdetail.list', $user_info['api_token'], null, $where);
$goods_info = json_decode($goods_info, 'true');
if ($goods_info && $goods_info['code'] == 1 && $goods_info['count'] && $goods_info['count'] > 0) {
// $goods_info = $goods_info['data'];
return json($goods_info);
}
}
return $this->fetch();
}
/**评价其他订单**/
public
function backlist()
{
$user_info = M('users')->alias('a')
->join('store b', 'a.store_id=b.store_id', 'left')
->field('a.*,b.api_token,b.store_logo,b.store_name')
->where("a.user_id", $this->user_id)->find();//调取api_token,商家LOGO,商家名称
if ($user_info) {
$mapuser['VIPNo'] = $user_info['erpvipno'];//token验证
$where = array(
'VIPNo' => $user_info['erpvipno'],
'IsEvaluate' => 0
);
$user_rs = getApiData('wxd.pos.vealuateform.list', $user_info['api_token'], null, $where, '', '', 'BillDate desc ,IsEvaluate asc');
$user_rs = json_decode($user_rs, 'true');
if ($user_rs && $user_rs['code'] == 1 && $user_rs['count'] && $user_rs['count'] == 1) {
$only_order = $user_rs['data']['0']['POSNo'];
return json(["code" => 1, "msg" => "只剩下一条订单", 'data' => $only_order]);
} else if ($user_rs && $user_rs['code'] == 1 && $user_rs['count'] && $user_rs['count'] > 1) {
return json(["code" => 2, "msg" => "还有多条订单"]);
} else {
$order_null = 1;
return json(["code" => 3, "msg" => "没有订单"]);
}
}
}
}