DefaultController.php 3.1 KB
<?php

namespace app\wx\modules\order\controllers;

use Yii;
use stdClass;
use yii\helpers\HtmlPurifier;

/**
 * 控制器
 */
class DefaultController extends BaseController
{
    /**
     * 首页
     */
    public function actionIndex()
    {
        return $this->render('index');
    }

    /**
     * @return string
     */
    public function actionSubmit()
    {
        $e = new stdClass();
        $e->success = false;
        $e->message = 'ok';
        $userId = 0;
        $req = Yii::$app->request;
        $carNo =  HtmlPurifier::process($req->post('carNo'), ['HTML.Allowed' => '']);
        $carModel =  HtmlPurifier::process($req->post('carModel'), ['HTML.Allowed' => '']);
        $customer =  HtmlPurifier::process($req->post('customer'), ['HTML.Allowed' => '']);
        $phone =  HtmlPurifier::process($req->post('phone'), ['HTML.Allowed' => '']);
        $preRepair =  HtmlPurifier::process($req->post('preRepair'), ['HTML.Allowed' => '']);
        $repairPrice =  HtmlPurifier::process($req->post('repairPrice'), ['HTML.Allowed' => '']);
        $finishDate =  HtmlPurifier::process($req->post('finishDate'), ['HTML.Allowed' => '']);
        $images =  $req->post('images');

        //echo $carNo.'_'.$carModel.'_'.$customer.'_'.$phone.'_'.$preRepair.'_'.$repairPrice.'_'.$finishDate.'_'.json_encode($images);
        $e->success = true;
        return $this->renderJson($e);
    }

    /**
     * @return string
     */
    public function actionOrderList()
    {
        $e = new stdClass();
        $e->success = false;
        $e->page = null;
        $e->page_count = null;
        $e->items = [];

        $page = $this->request->get('page');
        $status = $this->request->get('status');

        if (empty($page)) {
            $page = 1;
        }
        $allItemList = [0, 0, 0];
        if ('working' == $status || '' == $status) {
            $allItemList = $this->getOrderList($page, 1);
        } else {
            $allItemList = $this->getOrderList($page, 0);
        }

        $e->page_count = $allItemList[1];
        $e->page = $page ;
        $e->items = $allItemList[2];
        $e->success = true;

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

    /**
     * @param $page
     * @param $status
     */
    private function getOrderList($page, $status)
    {
        $pageSize = 5 ;
        $pager_offset = ($page -1) * $pageSize;
        $limitPage = $pageSize;
        $count = 15;
        $items = [];
        $pageCount = ceil(($count*1) / $pageSize);
        $carModelList = ['宝马X3','宝马X4','宝马X5','宝马X6','奔驰c200l','奔驰E260','奔驰E260','奔驰E300'];
        $customerList = ['张先生','李先生','王先生','赵先生','刘先生','宝先生','好先生','费先生'];
        for ($i = $pager_offset; $i < ($pager_offset+$limitPage); $i++ ) {
            $carModel = $carModelList[mt_rand(0,7)];
            $customer = $customerList[mt_rand(0,7)];
            $items[] = ['id'=> $i ,'carNo' => 'XA'.mt_rand(10000,99999), 'carModel' => $carModel, 'status' => $status, 'customer' => $customer ,'createdTime' => date('Y-m-d H:i')];
        }

        return [$count, $pageCount, $items];
    }
}