Blame view

app-wx/modules/order/controllers/CustomerController.php 4.82 KB
3a892ee0   xu   app-wx(v0.1.0 bui...
1
2
3
4
<?php

namespace app\wx\modules\order\controllers;

1de3211f   xu   app-wx(v0.1.0 bui...
5
use common\helpers\Utils;
bb9baa4c   xu   app-wx v0.1.0 bui...
6
use domain\order\RepairOrderRate;
1de3211f   xu   app-wx(v0.1.0 bui...
7
use domain\order\RepairOrderRateRepository;
f3ed8f51   xu   app-wx(v0.1.0 bui...
8
9
10
use Yii;


3a892ee0   xu   app-wx(v0.1.0 bui...
11
12
13
14
15
use domain\order\RepairOrderRepository;
use domain\order\RepairOrderStatus;

use stdClass;

bb9baa4c   xu   app-wx v0.1.0 bui...
16
/**
3a892ee0   xu   app-wx(v0.1.0 bui...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 * 控制器
 */
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 = [];
6bece648   xu   app-wx(v0.1.0 bui...
38
        $orderUUId = $this->request->post('id');
3a892ee0   xu   app-wx(v0.1.0 bui...
39
40
41
        $md5Mobile = $this->request->post('sn');

        $orderModel = RepairOrderRepository::findOne(['short_uuid' => $orderUUId]);
f3ed8f51   xu   app-wx(v0.1.0 bui...
42
        if (empty($orderModel)) {
3a892ee0   xu   app-wx(v0.1.0 bui...
43
44
45
46
            $e->message = '找不到该订单';
            return $this->renderJson($e);
        }
        $orderId = $orderModel->id;
f3ed8f51   xu   app-wx(v0.1.0 bui...
47
48
        $brokenImageModels = RepairOrderRepository::findOrderImageAll(['repair_order_id' => $orderId]);
        $brokenImages = [];
3a892ee0   xu   app-wx(v0.1.0 bui...
49
50
51
        $baseURL = Yii::$app->request->getHostInfo();
        foreach($brokenImageModels as $k => $v) {
            $brokenImages[] = $baseURL.'/'.$v->image_path;
1de3211f   xu   app-wx(v0.1.0 bui...
52
53
54
55
        }
        $totalPrice = $orderModel->order_price;
        $rPlans = RepairOrderRepository::findOrderPlansAll(['repair_order_id' => $orderId]);
        $repairPlans = [];
3a892ee0   xu   app-wx(v0.1.0 bui...
56
57
        foreach($rPlans as $k => $plan) {
            $repairPlans[] = ['plan' => $plan['repair_plan'] ,'price' => $plan['price']];
f3ed8f51   xu   app-wx(v0.1.0 bui...
58
        }
3a892ee0   xu   app-wx(v0.1.0 bui...
59
60
61
62
        $fImages = RepairOrderRepository::findOrderFinishImageAll(['repair_order_id' => $orderId]);
        $finishImages = [];
        foreach($fImages as $k => $image) {
            $finishImages[] = $baseURL.'/'.$image['image_path'];
f3ed8f51   xu   app-wx(v0.1.0 bui...
63
        }
3a892ee0   xu   app-wx(v0.1.0 bui...
64
65
        $comments = [];
        $hasComment = false;
1de3211f   xu   app-wx(v0.1.0 bui...
66
67
68
69
        $rateModel = RepairOrderRateRepository::findOne(['repair_order_id' => $orderId]);
        if ($rateModel) {
            $hasComment = true;
            $comments = ['starTxt' => RepairOrderRate::starLabel($rateModel->star_count), 'comment' => $rateModel->comment];
3a892ee0   xu   app-wx(v0.1.0 bui...
70
        }
f3ed8f51   xu   app-wx(v0.1.0 bui...
71

3a892ee0   xu   app-wx(v0.1.0 bui...
72
        $e->success = true;
f3ed8f51   xu   app-wx(v0.1.0 bui...
73
74
75
        $e->item = [
            'carNo'     => $orderModel->car_no,
            'carModel'  => $orderModel->car_model,
afd2f743   xu   app-ht(v0.0.1 bui...
76
77
78
79
80
81
82
            'customer'  => $orderModel->customer,
            'mobile'    => '1*****'.substr($orderModel->contact_mobile,7,4),
            'preRepair' => $orderModel->predict_fault,
            'repairPrice'   => $orderModel->predict_price.'元',
            'preFinishDate' => date('Y-m-d H:00', $orderModel->predict_finish_time),
            'orderDateTime' => date('Y-m-d H:00', $orderModel->created_at),
            'status'        => RepairOrderStatus::getEnLabel($orderModel->status),
f3ed8f51   xu   app-wx(v0.1.0 bui...
83
            'hasComment'    => $hasComment,
32926e46   xu   app-wx(v0.1.0 bui...
84
85
86
87
88
89
90
91
            'comments'      => $comments,
            'brokenImages'  => $brokenImages,
            'repairPlans'   => $repairPlans,
            'totalPrice'    => $totalPrice,
            'finishImages'  => $finishImages
        ];

        return $this->renderJson($e);
3a892ee0   xu   app-wx(v0.1.0 bui...
92
93
94
95
96
97
    }

    /**
     * @return string
     */
    public function actionSubmitRate()
32926e46   xu   app-wx(v0.1.0 bui...
98
99
100
    {
        $e = new stdClass();
        $e->success = false;
3a892ee0   xu   app-wx(v0.1.0 bui...
101
102
103
        $e->message = 'ok';
        $star = $this->request->post('star');
        $orderUUId = $this->request->post('id');
f3ed8f51   xu   app-wx(v0.1.0 bui...
104
        $comment = $this->request->post('comment');
3a892ee0   xu   app-wx(v0.1.0 bui...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
        $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) {
afd2f743   xu   app-ht(v0.0.1 bui...
122
123
124
125
            $e->message = '已经评价过了';
            return $this->renderJson($e);
        }
        if ($userId > 0) {
f3ed8f51   xu   app-wx(v0.1.0 bui...
126
            $e->message = '维修厂人员不能评论';
3a892ee0   xu   app-wx(v0.1.0 bui...
127
            //return $this->renderJson($e);
bb9baa4c   xu   app-wx v0.1.0 bui...
128
        }
afd2f743   xu   app-ht(v0.0.1 bui...
129
        $items = [
f3ed8f51   xu   app-wx(v0.1.0 bui...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
            'ip_address'    => Utils::clientIp(),
            'customer_id'   => 0,
            'star_count'    => $star,
            'repair_order_id'   => $orderModel->id,
            'comment'           => $comment,
        ];
        $rateModel = RepairOrderRate::create($items);
        if($rateModel) {
            $e->success = true;
            $e->message = '提交成功';
        } else {
            $e->message = '提交评论失败';
        }

        return $this->renderJson($e);
    }

} 
d11ff394   xu   app-ht(v0.0.1 bui...

f3ed8f51   xu   app-wx(v0.1.0 bui...

d11ff394   xu   app-ht(v0.0.1 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

f3ed8f51   xu   app-wx(v0.1.0 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

f3ed8f51   xu   app-wx(v0.1.0 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

c6779489   xu   app-wx(v0.1.0 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

c6779489   xu   app-wx(v0.1.0 bui...

6bece648   xu   app-wx(v0.1.0 bui...

f3ed8f51   xu   app-wx(v0.1.0 bui...

3a892ee0   xu   app-wx(v0.1.0 bui...

3a892ee0   xu   app-wx(v0.1.0 bui...