123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- <?php
- namespace app\h5\controller;
- use app\hander\HelpHander;
- use EasyWeChat\Factory;
- use think\Controller;
- use think\Db;
- class Index extends Controller
- {
- public function sysarticle($name){
- $info = Db::name('sys_article')->where('name',$name)->find();
- $this->assign('info',$info);
- return $this->fetch();
- }
- public function newDetail($id){
- $info = Db::name('news')->where('id',$id)->find();
- $this->assign('info',$info);
- return $this->fetch();
- }
- public function errorPage(){
- return $this->fetch('index/error');
- }
- public function article(){
- $token = input('token');
- $id = input('id');
- $info = Db::name('article')
- ->where('id', $id)
- ->field('id,path,view,video,audio,content,type')
- ->find();
- if(!$info){
- return $this->fetch('error');
- }else{
- if($info['type'] == 1){
- $this->assign('path',$info);
- $this->assign('url',$info['path']);
- $this->assign('token',$token);
- return $this->fetch('article');
- }else{
- $this->assign('path',$info);
- $this->assign('token',$token);
- $this->assign('info',$info);
- return $this->fetch('article2');
- }
- }
- }
- // 下载页
- public function download(){
- $ios = "https://apps.apple.com/cn/app/id1587280817";
- // $ios = '#';
- $android = '';
- $app = Db::name('app_mgr')
- ->where('del',0)
- ->where('enable',1)
- ->order('ver desc, id desc')
- ->find();
- if($app){
- $android = $app['path'];
- }
- if(!$android){
- $android = '#';
- }
- if(!$ios){
- $ios = '#';
- }
- $iswx = 0;
- if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
- $iswx = 1;
- }
- $this->assign('iswx',$iswx);
- $this->assign('ios',$ios);
- $this->assign('android',$android);
- return $this->fetch();
- }
- //温控统计
- public function TemperatureTj(){
- $type = input('TjType/d',0);
- $id = input('id','','trim');
- if(empty($id)){
- exit('参数错误');
- }
- switch ($type){
- case 0:
- $html = $this->tj1($id);
- break;
- case 2:
- $html = $this->tj2($id);
- break;
- case 3:
- $html = $this->tj3($id);
- break;
- }
- return $html;
- }
- public function check($id){
- $res = Db::name('temperature_device')
- ->where('id',$id)
- ->where('del',0)
- ->where('enable',1)
- ->find();
- if(!$res) exit('设备不存在');
- return $res;
- }
- /**
- * 24小时温度图
- *
- * @author wst
- * @date 2021/6/9 10:59
- */
- public function tj1() {
- $id = input('id','','trim');
- if(empty($id)){
- exit('参数错误');
- }
- $res = $this->check($id);
- $time = time();
- $timeData = [];
- for ($i = 0; $i <= 23; $i++) {
- if (strlen($i) <= 1) {
- $i = '0' . $i;
- }
- $timeData[] = date('Ymd', $time) . $i;
- }
- $data = [];
- foreach ($timeData as $k => $v) {
- $info = Db::name('temperature_device_data')
- ->where('snaddr', $res['snaddr'])
- ->where('create_ymdh', $v)
- ->where('abnormal', 0)
- ->avg('temp');
- $a = [
- 'name' => substr($v, -2) . ':00',
- 'value' => round($info,2)
- ];
- $data[] = $a;
- }
- $this->assign('key', array_column($data, 'name'));
- $this->assign('value', array_column($data, 'value'));
- $i = array_chunk($data,6);
- $this->assign('data', $i);
- return $this->fetch();
- }
- /**
- * 最近七日温度显示
- *
- * @author wst
- * @date 2021/6/9 14:16
- */
- public function tj2() {
- $id = input('id','','trim');
- if(empty($id)){
- exit('参数错误');
- }
- $res = $this->check($id);
- $time = time();
- $timeData = [];
- for ($i = 6; $i >= 0; $i--) {
- $timeData[] =date('Ymd',$time-($i*86400));
- }
- $data = [];
- foreach ($timeData as $k => $v) {
- $info = Db::name('temperature_device_data')
- ->where('snaddr', $res['snaddr'])
- ->where('create_ymd', $v)
- ->where('abnormal', 0)
- ->avg('temp');
- $a = [
- 'name' => substr($v, 0,4).'-'.substr($v, 4,2).'-'.substr($v, -2),
- 'value' => round($info,2)
- ];
- $data[] = $a;
- }
- $this->assign('key', array_column($data, 'name'));
- $this->assign('value', array_column($data, 'value'));
- $i = array_chunk($data,4);
- $this->assign('data', $i);
- return $this->fetch();
- }
- /**
- * 最近30日温度显示
- *
- * @author wst
- * @date 2021/6/9 14:16
- */
- public function tj3() {
- $id = input('id','','trim');
- if(empty($id)){
- exit('参数错误');
- }
- $res = $this->check($id);
- $time = time();
- $timeData = [];
- for ($i = 29; $i >= 0; $i--) {
- $timeData[] =date('Ymd',$time-($i*86400));
- }
- $data = [];
- foreach ($timeData as $k => $v) {
- $info = Db::name('temperature_device_data')
- ->where('snaddr', $res['snaddr'])
- ->where('create_ymd', $v)
- ->where('abnormal', 0)
- ->avg('temp');
- $a = [
- 'name' => substr($v, 0,4).'-'.substr($v, 4,2).'-'.substr($v, -2),
- 'value' => round($info,2)
- ];
- $data[] = $a;
- }
- $this->assign('key', array_column($data, 'name'));
- $this->assign('value', array_column($data, 'value'));
- $i = array_chunk($data,5);
- $this->assign('data', $i);
- return $this->fetch();
- }
- // 运送收费页
- public function pay(){
- $id = input('id/d',0);
- // $id = 1;
- $info = Db::name('order_convey_pay')->where('id',$id)->where('status',0)->find();
- $error = '';
- if($info){
- $config = config('app.wx_config');
- $notify = config("app.app_host").'/h5/notify/pay';
- $info['url'] = '';
- try{
- $app = Factory::payment($config);
- $result = $app->order->unify([
- 'body' => '运送收费',
- 'out_trade_no' => $info['sn'],
- 'total_fee' => $info['money']*100,
- 'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
- 'trade_type' => 'NATIVE', // 请对应换成你的支付方式对应的值类型
- 'product_id' => $info['order_id'],
- ]);
- if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
- $info['url'] = think_encrypt($result['code_url']);
- }
- }catch (\Exception $e){
- trace($e->getMessage());
- }
- }else{
- $error = "记录不存在或已支付";
- }
- if(!$info['url']){
- $error = "支付二维码生成失败,请重试";
- }
- $this->assign('info',$info);
- $this->assign('error',$error);
- return $this->fetch();
- }
- public function checkPay(){
- $id = input('id/d',0);
- $info = Db::name('order_convey_pay')->where('id',$id)->where('status',1)->find();
- if($info){
- $this->success('已支付');
- }else{
- $this->error('未支付');
- }
- }
- public function errortxt(){
- return $this->fetch('repair/errortxt');
- }
- }
|