Index.php 2.5 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()
    {
        
        return $this->view->fetch('index');
    }

    //app下载提示页面
    public function down()
    {
        $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);
        }

        $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', '');
            }
        }
    }

}