CustomerController.php
6.37 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
<?php
namespace app\wx\modules\order\controllers;
use Yii;
use common\helpers\ImageManager;
use common\helpers\Utils;
use domain\order\RepairOrderRate;
use domain\order\RepairOrderRateRepository;
use domain\order\RepairOrderRepository;
use domain\order\RepairOrderStatus;
use stdClass;
/**
* 控制器
*/
class CustomerController extends CustomerBaseController
{
/**
* 首页
*/
public function actionIndex()
{
return $this->render('/default/cindex');
}
/**
* @return string
*/
public function actionOrderDetails()
{
$e = new stdClass();
$e->success = false;
$e->message = 'ok';
$e->item = [];
$orderUUId = $this->request->post('id');
$md5Mobile = $this->request->post('sn');
$orderModel = RepairOrderRepository::findOne(['short_uuid' => $orderUUId]);
if (empty($orderModel)) {
$e->message = '找不到该订单';
return $this->renderJson($e);
}
$orderId = $orderModel->id;
$brokenImageModels = RepairOrderRepository::findOrderImageAll(['repair_order_id' => $orderId]);
$brokenImages = [];
$baseURL = Yii::$app->request->getHostInfo();
foreach($brokenImageModels as $k => $v) {
$brokenImages[] = [
'url' => ImageManager::getUrl($v->image_path),
'thumb' => ImageManager::getUrl($v->image_path, 'min')
];
}
$totalPrice = $orderModel->order_price;
$rPlans = RepairOrderRepository::findOrderPlansAll(['repair_order_id' => $orderId]);
$repairPlans = [];
foreach($rPlans as $k => $plan) {
$repairPlans[] = ['plan' => $plan['repair_plan'] ,'price' => $plan['price']];
}
$fImages = RepairOrderRepository::findOrderFinishImageAll(['repair_order_id' => $orderId]);
$finishImages = [];
foreach($fImages as $k => $image) {
$finishImages[] = [
'url' => ImageManager::getUrl($image['image_path']),
'thumb' => ImageManager::getUrl($image['image_path'], 'min')
];
}
$comments = [];
$hasComment = false;
$rateModel = RepairOrderRateRepository::findOne(['repair_order_id' => $orderId]);
if ($rateModel) {
$hasComment = true;
$comments = [
'starTxt' => RepairOrderRate::starLabel($rateModel->star_count),
'qualityStarTxt' => RepairOrderRate::starLabel($rateModel->quality_star),
'effectStarTxt' => RepairOrderRate::starLabel($rateModel->effect_star),
'serviceStarTxt' => RepairOrderRate::starLabel($rateModel->service_star),
'comment' => $rateModel->comment,
];
}
$preFinishDate = '暂无';
$predictPrice = '暂无';
if($orderModel->predict_finish_time) {
$preFinishDate = date('Y-m-d H:00', $orderModel->predict_finish_time);
}
if($orderModel->predict_price) {
$predictPrice = $orderModel->predict_price.'元';
}
$e->success = true;
$e->item = [
'carNo' => $orderModel->car_no,
'carModel' => $orderModel->car_model,
'customer' => $orderModel->customer,
'mobile' => '1*****'.substr($orderModel->contact_mobile,7,4),
'preRepair' => empty($orderModel->predict_fault)?'暂无':$orderModel->predict_fault,
'repairPrice' => $predictPrice,
'preFinishDate' => $preFinishDate,
'orderDateTime' => date('Y-m-d H:00', $orderModel->created_at),
'status' => RepairOrderStatus::getEnLabel($orderModel->status),
'hasComment' => $hasComment,
'comments' => $comments,
'brokenImages' => $brokenImages,
'repairPlans' => $repairPlans,
'totalPrice' => $totalPrice,
'finishImages' => $finishImages
];
return $this->renderJson($e);
}
/**
* @return string
*/
public function actionSubmitRate()
{
$e = new stdClass();
$e->success = false;
$e->message = 'ok';
$qualityStar = $this->request->post('qualityStar');
$effectStar = $this->request->post('effectStar');
$serviceStar = $this->request->post('serviceStar');
$orderUUId = $this->request->post('id');
$comment = $this->request->post('comment');
$images = $this->request->post('images');
$userId = $this->getUserId();
$orderModel = RepairOrderRepository::findOne(['short_uuid' => $orderUUId]);
if (empty($orderModel)) {
$e->message = '找不到订单';
return $this->renderJson($e);
}
if (RepairOrderStatus::WORKING == $orderModel->status) {
$e->message = '订单还在维修中';
return $this->renderJson($e);
}
if(mb_strlen($comment) > 200) {
$e->message = '评论只能200字内';
return $this->renderJson($e);
}
$rateModel = RepairOrderRateRepository::findOne(['repair_order_id' => $orderModel->id]);
if ($rateModel) {
$e->message = '已经评价过了';
return $this->renderJson($e);
}
if ($userId > 0) {
$e->message = '维修厂人员不能评论';
//return $this->renderJson($e);
}
$items = [
'ip_address' => Utils::clientIp(),
'customer_id' => 0,
'quality_star' => $qualityStar,
'effect_star' => $effectStar,
'service_star' => $serviceStar,
'repair_order_id' => $orderModel->id,
'comment' => $comment,
];
$rateModel = RepairOrderRate::create($items);
$commentImages = RepairOrderRate::mvImages($orderModel->uuid, $images);
$images = [];
if ($commentImages) {
foreach($commentImages as $k => $v) {
$images[] = $v[0].$v[1];
}
}
if ($images) {
$rateModel->images = implode(',', $images);
$rateModel->save();
}
if ($rateModel) {
$e->success = true;
$e->message = '提交成功';
} else {
$e->message = '提交评论失败';
}
return $this->renderJson($e);
}
}