CustomerController.php 2.98 KB
<?php

namespace app\wx\modules\order\controllers;

use Yii;


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';
        $orderUUId = $this->request->post('id');
        $md5Mobile = $this->request->post('sn');

        $orderModel = RepairOrderRepository::findOne(['uuid' => $orderUUId]);
        if (empty($orderModel)) {
            $e->message = '找不到该订单';
            return $this->renderJson($e);
        }
        $brokenImageModels = RepairOrderRepository::findOrderImageAll(['repair_order_id' => $orderModel->id]);
        $brokenImages = [];
        $baseURL = Yii::$app->request->getHostInfo();
        foreach($brokenImageModels as $k => $v) {
            $brokenImages[] = $baseURL.'/'.$v->image_path;
        }
        $totalPrice = $orderModel->order_price;
        $rPlans = RepairOrderRepository::findOrderPlansAll(['repair_order_id' => $orderModel->id]);
        $repairPlans = [];
        foreach($rPlans as $k => $plan) {
            $repairPlans[] = ['plan' => $plan['repair_plan'] ,'price' => $plan['price']];
        }
        $fImages = RepairOrderRepository::findOrderFinishImageAll(['repair_order_id' => $orderModel->id]);
        $finishImages = [];
        foreach($fImages as $k => $image) {
            $finishImages[] = $baseURL.'/'.$image['image_path'];
        }
        $hasComment = false;

        $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' => $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),
            'hasComment'    => $hasComment,
            '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';
        $star = $this->request->post('star');
        $comment = $this->request->post('comment');

        //echo $star.'_'.$comment;
        $e->success = true;
        return $this->renderJson($e);
    }

}