0
0

Index.php 8.0 KB

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