Index.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php
  2. namespace app\h5\controller;
  3. use app\hander\HelpHander;
  4. use EasyWeChat\Factory;
  5. use think\Controller;
  6. use think\Db;
  7. class Index extends Controller
  8. {
  9. public function sysarticle($name){
  10. $info = Db::name('sys_article')->where('name',$name)->find();
  11. $this->assign('info',$info);
  12. return $this->fetch();
  13. }
  14. public function newDetail($id){
  15. $info = Db::name('news')->where('id',$id)->find();
  16. $this->assign('info',$info);
  17. return $this->fetch();
  18. }
  19. public function errorPage(){
  20. return $this->fetch('index/error');
  21. }
  22. public function article(){
  23. $token = input('token');
  24. $id = input('id');
  25. $info = Db::name('article')
  26. ->where('id', $id)
  27. ->field('id,path,view,video,audio,content,type')
  28. ->find();
  29. if(!$info){
  30. return $this->fetch('error');
  31. }else{
  32. if($info['type'] == 1){
  33. $this->assign('path',$info);
  34. $this->assign('url',$info['path']);
  35. $this->assign('token',$token);
  36. return $this->fetch('article');
  37. }else{
  38. $this->assign('path',$info);
  39. $this->assign('token',$token);
  40. $this->assign('info',$info);
  41. return $this->fetch('article2');
  42. }
  43. }
  44. }
  45. // 下载页
  46. public function download(){
  47. $ios = "https://apps.apple.com/cn/app/id6471941487";
  48. // $ios = '#';
  49. $android = '';
  50. $app = Db::name('app_mgr')
  51. ->where('del',0)
  52. ->where('enable',1)
  53. ->order('ver desc, id desc')
  54. ->find();
  55. if($app){
  56. $android = $app['path'];
  57. }
  58. if(!$android){
  59. $android = '#';
  60. }
  61. if(!$ios){
  62. $ios = '#';
  63. }
  64. $iswx = 0;
  65. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
  66. $iswx = 1;
  67. }
  68. $this->assign('iswx',$iswx);
  69. $this->assign('ios',$ios);
  70. $this->assign('android',$android);
  71. return $this->fetch();
  72. }
  73. public function monitor(){
  74. $id = think_decrypt(input('id','','trim'));
  75. $info = Db::name('monitor')->where('id',$id)->where('del',0)->find();
  76. if(!$info){
  77. $this->error("监控设备不存在");
  78. }
  79. $this->assign('info',$info);
  80. return $this->fetch();
  81. }
  82. //温控统计
  83. public function TemperatureTj(){
  84. $type = input('TjType/d',0);
  85. $id = input('id','','trim');
  86. if(empty($id)){
  87. exit('参数错误');
  88. }
  89. switch ($type){
  90. case 0:
  91. $html = $this->tj1($id);
  92. break;
  93. case 2:
  94. $html = $this->tj2($id);
  95. break;
  96. case 3:
  97. $html = $this->tj3($id);
  98. break;
  99. }
  100. return $html;
  101. }
  102. public function check($id){
  103. $res = Db::name('temperature_device')
  104. ->where('id',$id)
  105. ->where('del',0)
  106. ->where('enable',1)
  107. ->find();
  108. if(!$res) exit('设备不存在');
  109. return $res;
  110. }
  111. /**
  112. * 24小时温度图
  113. *
  114. * @author wst
  115. * @date 2021/6/9 10:59
  116. */
  117. public function tj1() {
  118. $id = input('id','','trim');
  119. if(empty($id)){
  120. exit('参数错误');
  121. }
  122. $res = $this->check($id);
  123. $time = time();
  124. $timeData = [];
  125. for ($i = 0; $i <= 23; $i++) {
  126. if (strlen($i) <= 1) {
  127. $i = '0' . $i;
  128. }
  129. $timeData[] = date('Ymd', $time) . $i;
  130. }
  131. $data = [];
  132. foreach ($timeData as $k => $v) {
  133. $info = Db::name('temperature_device_data')
  134. ->where('snaddr', $res['snaddr'])
  135. ->where('create_ymdh', $v)
  136. ->where('abnormal', 0)
  137. ->avg('temp');
  138. $a = [
  139. 'name' => substr($v, -2) . ':00',
  140. 'value' => round($info,2)
  141. ];
  142. $data[] = $a;
  143. }
  144. $this->assign('key', array_column($data, 'name'));
  145. $this->assign('value', array_column($data, 'value'));
  146. $i = array_chunk($data,6);
  147. $this->assign('data', $i);
  148. return $this->fetch();
  149. }
  150. /**
  151. * 最近七日温度显示
  152. *
  153. * @author wst
  154. * @date 2021/6/9 14:16
  155. */
  156. public function tj2() {
  157. $id = input('id','','trim');
  158. if(empty($id)){
  159. exit('参数错误');
  160. }
  161. $res = $this->check($id);
  162. $time = time();
  163. $timeData = [];
  164. for ($i = 6; $i >= 0; $i--) {
  165. $timeData[] =date('Ymd',$time-($i*86400));
  166. }
  167. $data = [];
  168. foreach ($timeData as $k => $v) {
  169. $info = Db::name('temperature_device_data')
  170. ->where('snaddr', $res['snaddr'])
  171. ->where('create_ymd', $v)
  172. ->where('abnormal', 0)
  173. ->avg('temp');
  174. $a = [
  175. 'name' => substr($v, 0,4).'-'.substr($v, 4,2).'-'.substr($v, -2),
  176. 'value' => round($info,2)
  177. ];
  178. $data[] = $a;
  179. }
  180. $this->assign('key', array_column($data, 'name'));
  181. $this->assign('value', array_column($data, 'value'));
  182. $i = array_chunk($data,4);
  183. $this->assign('data', $i);
  184. return $this->fetch();
  185. }
  186. /**
  187. * 最近30日温度显示
  188. *
  189. * @author wst
  190. * @date 2021/6/9 14:16
  191. */
  192. public function tj3() {
  193. $id = input('id','','trim');
  194. if(empty($id)){
  195. exit('参数错误');
  196. }
  197. $res = $this->check($id);
  198. $time = time();
  199. $timeData = [];
  200. for ($i = 29; $i >= 0; $i--) {
  201. $timeData[] =date('Ymd',$time-($i*86400));
  202. }
  203. $data = [];
  204. foreach ($timeData as $k => $v) {
  205. $info = Db::name('temperature_device_data')
  206. ->where('snaddr', $res['snaddr'])
  207. ->where('create_ymd', $v)
  208. ->where('abnormal', 0)
  209. ->avg('temp');
  210. $a = [
  211. 'name' => substr($v, 0,4).'-'.substr($v, 4,2).'-'.substr($v, -2),
  212. 'value' => round($info,2)
  213. ];
  214. $data[] = $a;
  215. }
  216. $this->assign('key', array_column($data, 'name'));
  217. $this->assign('value', array_column($data, 'value'));
  218. $i = array_chunk($data,5);
  219. $this->assign('data', $i);
  220. return $this->fetch();
  221. }
  222. // 运送收费页
  223. public function pay(){
  224. $id = input('id/d',0);
  225. // $id = 1;
  226. $info = Db::name('order_convey_pay')->where('id',$id)->where('status',0)->find();
  227. $error = '';
  228. if($info){
  229. $config = config('app.wx_config');
  230. $notify = request()->domain().'/h5/notify/pay';
  231. $info['url'] = '';
  232. try{
  233. $app = Factory::payment($config);
  234. $result = $app->order->unify([
  235. 'body' => '运送收费',
  236. 'out_trade_no' => $info['sn'],
  237. 'total_fee' => $info['money']*100,
  238. 'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  239. 'trade_type' => 'NATIVE', // 请对应换成你的支付方式对应的值类型
  240. 'product_id' => $info['order_id'],
  241. ]);
  242. if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
  243. $info['url'] = think_encrypt($result['code_url']);
  244. }
  245. }catch (\Exception $e){
  246. trace($e->getMessage());
  247. }
  248. }else{
  249. $error = "记录不存在或已支付";
  250. }
  251. if(!$info['url']){
  252. $error = "支付二维码生成失败,请重试";
  253. }
  254. $this->assign('info',$info);
  255. $this->assign('error',$error);
  256. return $this->fetch();
  257. }
  258. public function checkPay(){
  259. $id = input('id/d',0);
  260. $info = Db::name('order_convey_pay')->where('id',$id)->where('status',1)->find();
  261. if($info){
  262. $this->success('已支付');
  263. }else{
  264. $this->error('未支付');
  265. }
  266. }
  267. public function errortxt(){
  268. return $this->fetch('repair/errortxt');
  269. }
  270. }