Video.php 3.4 KB
<?php

namespace app\equipment\controller;

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

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

        $this->model = new \app\admin\model\reservoir\hkws\Hardware;
    }

    public function list()
    {
        $list = $this->model
            ->alias('h')
            ->join('reservoir_list r','r.id=h.reservoir_id','LEFT')
            ->field('h.*,r.name as reservoir')
            ->order('id desc')
            ->paginate(10,'',['query'=>$this->request->param()]);
        
        $this->view->assign([
            'list'=>$list,
            'reservoir_list' => Db::name('reservoir_list')->field('id,name')->where('county_id',1)->select()
        ]);
        return $this->view->fetch();
    }
    public function add()
    {
        if($this->request->isPost()){
            $params = $this->request->post('row/a');
            if($params){
                if (!$params['name']){
                    $this->error('设备名称不能为空');
                }
                if (!$params['rcode']) {
                   $this->error('注册码不能为空');
                }
                if (!$params['vcode']) {
                   $this->error('验证码不能为空');
                }
                if (!$params['scode']) {
                   $this->error('序列号不能为空');
                }
                $params['province_id']  =  $params['state_id'] = $params['county_id'] = 1;
                $params['createtime'] = time();
                $result = $this->model->allowField(true)->save($params);
                if(!$result){
                    $this->error('网络繁忙');
                }
                $this->success('添加成功');
            }
            
        }    
    }
    
    public function edit($ids=null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error('数据不存在');
        }
        if ($this->request->isPost()) {
            $params = $this->request->post('row/a');
            if (!$params['name']){
                $this->error('设备名称不能为空');
            }
            if (!$params['rcode']) {
                $this->error('注册码不能为空');
            }
            if (!$params['vcode']) {
                $this->error('验证码不能为空');
            }
            if (!$params['scode']) {
                $this->error('序列号不能为空');
            }
            $result = $row->allowField(true)->save($params);
            if (!$result) {
                $this->error('网络繁忙,更新失败');
            }
            $this->success('更新成功');
            
        }
        return json(['code'=>1,'data'=>$row]);
    }
    
    public function del($ids=null)
    {
        $m = $this->model->get($ids);
        $res = $m->delete(true);
        if(!$res){
            $this->error('网络繁忙');
        }
        $this->success('删除成功');
    }
    
    public function getinfo()
    {
        $id = input('?post.id');
        $list = $this->model
            ->alias('h')
            ->join('reservoir_list r','r.id=h.reservoir_id')
            ->field('h.*,r.name as reservoir')
            // ->where('h.id',$id)
            ->select();
        var_dump($list);
        
        
    }
}