AdminEquipmentController.php 1.8 KB
<?php
/**
 * Created by PhpStorm.
 * User: ruidiudiu
 * Date: 2018/11/20
 * Time: 16:33
 */

namespace app\portal\controller;


use app\portal\model\EquipmentModel;
use cmf\controller\AdminBaseController;
use QRcode;
use think\Db;

/**
 * Class AdminEquipmentController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'设备管理',
 *     'action' =>'index',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 30,
 *     'icon'   =>'th',
 *     'remark' =>'设备管理'
 * )
 */
class AdminEquipmentController extends AdminBaseController{

    public function index(){
        $Equipment=new EquipmentModel();
        $data=$Equipment->paginate(10);
        $this->assign('data',$data);
        return $this->fetch();
    }

    public function add(){

        return $this->fetch();
    }

    public function addPost(){
        $data=$this->request->post();
        $data['create_time']=strtotime($data['create_time']);
        $Equipment=new EquipmentModel();
        $res=$Equipment->save($data);
        if ($res){
            $this->apiResponse(200,'保存成功');
        }else{
            $this->apiResponse(301,'error');
        }
    }

    //批量导入设备信息
    public function batch_add(){

        return $this->fetch();
    }

    public function batch_addPost(){

    }



    //生成二维码
    public function createQrCode($value){
        import('phpqrcode.qrlib',VENDOR_PATH,'.php');
        $name=date('YmdHis').rand(1000,9999);
        $filename='qrCode/'.$name.'.png';
        $filePath = 'upload/'.$filename; // 生成的文件名
        $errorCorrectionLevel = 'L';//容错级别
        $matrixPointSize = 6;//生成图片大小
        QRcode::png($value,$filePath, $errorCorrectionLevel, $matrixPointSize, 2);
        return $filename;
    }

}