Index.php 7.8 KB

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