Index.php 2.8 KB
<?php

namespace app\index\controller;

use addons\qrcode\Qrcode;
use app\common\controller\Frontend;
use think\Db;
use app\api\controller\Excel;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        //header("Location:https://lx.bqh.ynzhsk.cn/app/jg");
        exit();
        $where = [
            "app_type" => "jianguan",
            "status" => "1"
        ];
        $version = Db::name("appversion")
            ->where($where)
            ->order("version desc")
            ->find();

        if (!empty($version['images'])) {
            $imgarr = explode(',', $version['images']);
            $version['images'] = full_image($imgarr);
        }
        //生成二维码
//        $url = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http";
//        $url .= "://" . $_SERVER['HTTP_HOST'];
//        $url .= $_SERVER['REQUEST_URI'];
//
//        $url = $url . '/app/jg/index';
//        $qrcode_img = addon_url('qrcode/index/build', ['text' => $url]);
//        $version['qrcode_img'] = $qrcode_img;

        $this->view->assign("version", $version);

        return $this->view->fetch('indexjg');
    }


    public function test()
    {
        $number = 100000;
        $min = 0;
        $max = 1;
        $total = 0;
        for ($i = 0; $i < $number; $i++) {
            $num = $min + mt_rand() / mt_getrandmax() * ($max - $min);
            $res = sprintf("%.10f", $num);  //控制小数后几位
            if ($res <= 0.0000010207) {
                echo '有' . $res . '</br>';
            } else {
                echo '没有' . $res . '</br>';
            }
            if ($res <= 0.000001) {
                $total++;
            }
        }
        echo $total;
    }

    public function apptoken()
    {
        $appid = 'wx5488f94eb1c0bded';
        $secret = 'db6ac40041ecf6c7447620392ce59357';
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
        $res = json_decode(file_get_contents($url), true);
        Db::name('weixin_apptoken')->where('id', '=', 1)->update(['token' => $res['access_token']]);
    }

    //变更模板消息状态
    public function updateWxtemplate()
    {
        $code = input('get.code');
        $openid = input('get.openid');
        if (!$code || !$openid) {
            $this->error('非法操作', '');
        } else {
            $res = Db::name('inspection_wxtemplatelog')->where('openid', '=', $openid)->where('code', '=', $code)->update(['status' => '1']);
            if ($res) {
                $this->success('告警接收成功', '');
            } else {
                $this->error('非法操作2', '');
            }
        }
    }

}