Manage.php 4.6 KB
<?php

namespace app\equipment\controller;

use app\common\controller\Frontend;
use think\Db;
class Manage extends Frontend
{

    protected $noNeedLogin = [];
    protected $noNeedRight = '*';
    protected $layout = '';
    
    public function _initialize()
    {
        parent::_initialize();

        $this->hardware = new \app\admin\model\reservoir\hkws\Hardware();
    }
    public function test()
    {
        return $this->view->fetch();
    }
    
    public function type()
    {
        return $this->view->fetch();
    }
    
    public function list()
    {
        if ($this->request->isPost()) {
            $page = $this->request->param('page',1);
            $limit = $this->request->param('limit',1);
            $condtion = [];
            $a = $this->request->param('a');
            if ($a) {
                $condtion['reservoirprovince.id'] = ['=',$a];
            }
            $b = $this->request->param('b');
            if ($b) {
                $condtion['reservoirstate.id'] = ['=',$b];
            }
            $c = $this->request->param('c');
            if ($c) {
                $condtion['reservoircounty.id'] = ['=',$c];
            }
            $d = $this->request->param('d');
            if ($d) {
                $condtion['reservoir_id'] = ['=',$d];
            }
            $e = $this->request->param('e');
            if ($e) {
                $condtion['type_child_name'] = ['=',$e];
            }
            $list = $this->hardware
                ->with(['reservoirprovince','reservoirstate','reservoircounty','reservoirlist'])
                ->where($condtion)
                ->page($page,$limit)
                ->select();
            $total = $this->hardware
                ->with(['reservoirprovince','reservoirstate','reservoircounty','reservoirlist'])
                ->where($condtion)
                ->count();
            return json(['code'=>1,'data'=>$list,'total'=>$total]);
        }
        $this->level();
        return $this->view->fetch();
    }
    public function list2()
    {
        if ($this->request->isPost()) {
            $page = $this->request->param('page',1);
            $limit = $this->request->param('limit',1);
            $condtion = [];
            $a = $this->request->param('a');
            if ($a) {
                $condtion['reservoirprovince.id'] = ['=',$a];
            }
            $b = $this->request->param('b');
            if ($b) {
                $condtion['reservoirstate.id'] = ['=',$b];
            }
            $c = $this->request->param('c');
            if ($c) {
                $condtion['reservoircounty.id'] = ['=',$c];
            }
            $d = $this->request->param('d');
            if ($d) {
                $condtion['reservoir_id'] = ['=',$d];
            }
            $e = $this->request->param('e');
            if ($e) {
                $condtion['type_child_name'] = ['=',$e];
            }
            $list = $this->hardware
                ->with(['reservoirprovince','reservoirstate','reservoircounty','reservoirlist'])
                ->where($condtion)
                ->page($page,$limit)
                ->select();
            $total = $this->hardware
                ->with(['reservoirprovince','reservoirstate','reservoircounty','reservoirlist'])
                ->where($condtion)
                ->count();
            return json(['code'=>1,'data'=>$list,'total'=>$total]);
        }
        $this->level();
        return $this->view->fetch();
    }
    public function add()
    {
        return $this->view->fetch();
    }
    private function level()
    {
        $province = Db::name('reservoir_province')->field('id,name')->select();
        foreach ($province as $key=>$item) {
            $state = Db::name('reservoir_state')->field('id,name')->where('province_id',$item['id'])->select();
            if($state){
               $province[$key]['son'] = $state; 
               foreach($state as $key2=>$item2){
                   $county = Db::name('reservoir_county')->field('id,name')->where('state_id',$item2['id'])->select();
                    if($county){
                         $province[$key]['son'][$key2]['son'] = $county;
                         foreach ($county as $key3=>$item3){
                            $shuiku = Db::name('reservoir_list')->field('id,name')->where('county_id',$item3['id'])->select();
                            if($shuiku){
                                $province[$key]['son'][$key2]['son'][$key3]['son'] = $shuiku;
                            }
                         }
                    }
               }
            }
        }
        $this->view->assign('level',$province);
    }
}