审查视图

application/admin/controller/Renwu.php 3.6 KB
王智 authored
1 2 3 4
<?php

namespace app\admin\controller;
王智 authored
5
use think\Db;
王智 authored
6 7 8
use app\common\controller\Backend;

/**
王智 authored
9
 *
王智 authored
10 11 12 13 14
 *
 * @icon fa fa-circle-o
 */
class Renwu extends Backend
{
王智 authored
15
王智 authored
16 17 18 19 20 21 22 23 24 25 26 27 28 29
    /**
     * Renwu模型对象
     * @var \app\admin\model\Renwu
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Renwu;
        $this->view->assign("typeList", $this->model->getTypeList());
        $this->view->assign("xiTypeList", $this->model->getXiTypeList());
        $this->view->assign("zhaoTypeList", $this->model->getZhaoTypeList());
    }
王智 authored
30
王智 authored
31 32 33 34 35
    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */
王智 authored
36
王智 authored
37 38 39 40 41 42 43 44 45 46

    /**
     * 查看
     */
    public function index()
    {
        //当前是否为关联查询
        $this->relationSearch = true;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
王智 authored
47
        if ($this->request->isAjax()) {
王智 authored
48
            //如果发送的来源是Selectpage,则转发到Selectpage
王智 authored
49
            if ($this->request->request('keyField')) {
王智 authored
50
                return $this->selectpage();
王智 authored
51
            }
王智 authored
52
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
王智 authored
53
            $total = $this->model
王智 authored
54
                ->with(['user', 'vip'])
王智 authored
55 56 57
                ->where($where)
                ->order($sort, $order)
                ->count();
王智 authored
58 59

            $list = $this->model
王智 authored
60
                ->with(['user', 'vip'])
王智 authored
61 62 63 64
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();
王智 authored
65 66

            foreach ($list as $row) {
王智 authored
67
王智 authored
68
                $row->getRelation('user')->visible(['nickname', 'mobile', 'address', 'address_con', 'car_num', 'color', 'car_type', 'vip']);
王智 authored
69
                $row->getRelation('vip')->visible(['title']);
王智 authored
70 71 72 73 74 75 76 77 78 79 80
                $OrderInfo = Db::name('renwu')->where('order_sn', $row['order_sn'])->find();
                if ($OrderInfo['xi_id'] == null || $OrderInfo['xi_id'] == '' || $OrderInfo['xi_id'] == "") {
                    $row['xi_id'] = '';
                } else {
                    $row['xi_id'] = Db::name('user')->where('id', $OrderInfo['xi_id'])->value('nickname');
                }
                if ($OrderInfo['zhao_id'] == null || $OrderInfo['zhao_id'] == '' || $OrderInfo['zhao_id'] == "") {
                    $row['zhao_id'] = '';
                } else {
                    $row['zhao_id'] = Db::name('user')->where('id', $OrderInfo['zhao_id'])->value('nickname');
                }
王智 authored
81 82 83 84 85 86 87
            }
            $list = collection($list)->toArray();
            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }
        return $this->view->fetch();
    }
王智 authored
88 89 90 91 92


    public function look()
    {
        $id = input('id');
王智 authored
93 94
        $Arr = Db::name('renwu')->where('id', $id)->find();
        if (empty($Arr['xi_id'])) {
王智 authored
95
            $data['xi'] = '未分配洗车工';
王智 authored
96 97 98 99
        } else {
            $data['xi'] = Db::name('user')->where('id', $Arr['xi_id'])->value('nickname');
        }
        if (empty($Arr['zhao_id'])) {
王智 authored
100
            $data['zhao'] = '未分配找车工';
王智 authored
101 102 103 104 105
        } else {
            $data['zhao'] = Db::name('user')->where('id', $Arr['zhao_id'])->value('nickname');
        }
        $this->assign("data", $data);
        return $this->view->fetch();
王智 authored
106
    }
王智 authored
107
}