VM暫存
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

651 line
24KB

  1. <?php
  2. /*
  3. file: carpark_model.php 停車管理系統
  4. */
  5. class Carpark_model extends CI_Model
  6. {
  7. var $vars = array();
  8. function __construct()
  9. {
  10. parent::__construct();
  11. $this->load->database();
  12. }
  13. public function init($vars)
  14. {
  15. $this->vars = $vars;
  16. }
  17. // 月租會員加入
  18. public function member_add($data)
  19. {
  20. // 會員車輛基本資料檔
  21. // $data['start_date'] = "{$data['start_date']} 00:00:00";
  22. // $data['end_date'] = "{$data['end_date']} 23:59:59";
  23. $old_lpr = $data['old_lpr'];
  24. unset($data['old_lpr']);
  25. $data_car = array
  26. (
  27. 'lpr' => $data['lpr'],
  28. 'lpr_correct' => $data['lpr'],
  29. 'etag' => $data['etag'],
  30. 'station_no' => $data['station_no'],
  31. 'start_time' => $data['start_date'],
  32. 'end_time' => $data['end_date']
  33. );
  34. $check_member_no = $data['member_no'];
  35. unset($data['member_no']);
  36. trigger_error("members:".print_r($data, true)."car:".print_r($data_car, true));
  37. if ($check_member_no == 0) // 新增一筆會員資料
  38. {
  39. $this->db->insert('members', $data);
  40. $data_car['member_no'] = $this->db->insert_id();
  41. $this->db->insert('member_car', $data_car);
  42. }
  43. else // update會員資料
  44. {
  45. $this->db->update('members', $data, array('member_no' => $check_member_no));
  46. if ($old_lpr == $data['lpr']) // 沒有異動到車牌, 使用update, 否則重建一筆
  47. {
  48. unset($data_car['lpr']);
  49. unset($data_car['lpr_correct']);
  50. $this->db->update('member_car', $data_car, array('member_no' => $check_member_no));
  51. }
  52. else
  53. {
  54. $this->db->delete('member_car', array('member_no' => $check_member_no));
  55. $data_car['member_no'] = $check_member_no;
  56. $this->db->insert('member_car', $data_car);
  57. }
  58. }
  59. return true;
  60. }
  61. // 查詢車牌是否重複
  62. public function check_lpr($lpr)
  63. {
  64. $rows = $this->db->select('count(*) as counts')
  65. ->from('members')
  66. ->where(array('lpr' => $lpr))
  67. ->get()
  68. ->row_array();
  69. return $rows['counts'];
  70. }
  71. // 月租會員查詢
  72. public function member_query()
  73. {
  74. $results = $this->db->select('member_no, lpr, etag, member_name, mobile_no, start_date, end_date, update_time,
  75. contract_no, amt, member_id, tel_h, tel_o, addr, valid_time, station_no')
  76. ->from('members')
  77. ->order_by('station_no, lpr', 'asc')
  78. ->get()
  79. ->result_array();
  80. return $results;
  81. }
  82. // 刪除月租會員
  83. public function member_delete($member_no)
  84. {
  85. $this->db->delete('members', array('member_no' => $member_no));
  86. $this->db->delete('member_car', array('member_no' => $member_no));
  87. return true;
  88. }
  89. // 進出場現況表
  90. public function cario_list()
  91. {
  92. /*
  93. $data_cario = $this->db
  94. ->select('c.cario_no, c.in_out, in_lane, out_lane, c.in_time, c.out_time, c.minutes, c.obj_id as lpr, c.etag, c.in_pic_name, c.out_pic_name, m.member_name as owner')
  95. ->from('cario c')
  96. ->join('members m', 'c.member_no = m.member_no', 'left')
  97. ->where(array('c.err' => 0))
  98. ->order_by('c.update_time', 'desc')
  99. ->limit(10)
  100. ->get()
  101. ->result_array();
  102. */
  103. $sql = '(select c.cario_no, c.in_out, in_lane, out_lane, c.in_time, c.out_time, c.minutes, c.obj_id as lpr, c.etag, c.in_pic_name, c.out_pic_name, m.member_name as owner, c.in_time as time_order
  104. from cario c left join members m on c.obj_id = m.lpr
  105. where c.err = 0 and c.out_time is null)
  106. union
  107. (select c.cario_no, c.in_out, in_lane, out_lane, c.in_time, c.out_time, c.minutes, c.obj_id as lpr, c.etag, c.in_pic_name, c.out_pic_name, m.member_name as owner, c.out_time as time_order
  108. from cario c left join members m on c.obj_id = m.lpr
  109. where c.err = 0 and c.out_time is not null)
  110. order by time_order desc limit 10;';
  111. $data_cario = $this->db->query($sql)->result_array();
  112. // $lane_arr = array(0 => '入1', 1 => '入2', 3 => '出3', 3 => '出4');
  113. $idx = 0;
  114. foreach($data_cario as $rows)
  115. {
  116. ++$rows['in_lane'];
  117. ++$rows['out_lane'];
  118. //$lane_no = $rows['in_out'] == 'CI' ? "入{$rows['in_lane']}" : "入{$rows['in_lane']} -> 出{$rows['out_lane']}";
  119. $lane_no = empty($rows['out_time']) ? "入{$rows['in_lane']}" : "入{$rows['in_lane']} -> 出{$rows['out_lane']}"; // 2016/08/22 有離場時間就顯示
  120. $pic_name = str_replace('.jpg', '', empty($rows['out_pic_name']) ? $rows['in_pic_name'] : $rows['out_pic_name']);
  121. $arr = explode('-', $pic_name);
  122. $pic_path = isset($arr[7]) ? APP_URL.'pics/'.substr($arr[7], 0, 8).'/'.$pic_name : '';
  123. $data[$idx] = array
  124. (
  125. // 'io_name' => $io_name[$rows['in_out']],
  126. 'cario_no' => $rows['cario_no'],
  127. 'io_name' => $lane_no,
  128. 'lpr' => $rows['lpr'],
  129. // 'etag' => $rows['etag'],
  130. 'etag' => $rows['etag'],
  131. 'owner' => $rows['owner'],
  132. 'io_time' => empty($rows['out_time']) ? $rows['in_time'] : "{$rows['in_time']}(入)<br>{$rows['out_time']}(出)<br>{$rows['minutes']}分(停留時間)",
  133. 'pic_name' => $pic_path
  134. );
  135. ++$idx;
  136. }
  137. return $data;
  138. }
  139. // 模糊比對
  140. function getLevenshteinSQLStatement($word, $target)
  141. {
  142. $words = array();
  143. if(strlen($word) >= 5)
  144. {
  145. for ($i = 0; $i < strlen($word); $i++) {
  146. // insertions
  147. $words[] = substr($word, 0, $i) . '_' . substr($word, $i);
  148. // deletions
  149. $words[] = substr($word, 0, $i) . substr($word, $i + 1);
  150. // substitutions
  151. //$words[] = substr($word, 0, $i) . '_' . substr($word, $i + 1);
  152. }
  153. }
  154. else
  155. {
  156. for ($i = 0; $i < strlen($word); $i++) {
  157. // insertions
  158. $words[] = substr($word, 0, $i) . '_' . substr($word, $i);
  159. }
  160. }
  161. // last insertion
  162. $words[] = $word . '_';
  163. //return $words;
  164. $fuzzy_statement = ' (';
  165. foreach ($words as $idx => $word)
  166. {
  167. $fuzzy_statement .= " {$target} LIKE '%{$word}%' OR ";
  168. }
  169. $last_or_pos = strrpos($fuzzy_statement, 'OR');
  170. if($last_or_pos !== false)
  171. {
  172. $fuzzy_statement = substr_replace($fuzzy_statement, ')', $last_or_pos, strlen('OR'));
  173. }
  174. return $fuzzy_statement;
  175. }
  176. // 車號入場查詢
  177. public function carin_lpr_query($word)
  178. {
  179. // updated 2016/09/09 fuzzy search
  180. if(empty($word) || strlen($word) < 4 || strlen($word) > 10)
  181. {
  182. return array();
  183. }
  184. $fuzzy_statement = $this->getLevenshteinSQLStatement($word, 'c.obj_id');
  185. trigger_error("模糊比對 {$word} where: {$fuzzy_statement}");
  186. $sql = "SELECT c.cario_no, c.in_out, in_lane, out_lane, c.in_time, c.out_time, c.minutes, c.obj_id as lpr, c.etag, c.in_pic_name, c.out_pic_name, m.member_name as owner
  187. FROM cario c
  188. LEFT JOIN members m ON c.obj_id = m.lpr
  189. WHERE {$fuzzy_statement} AND c.err = 0 AND c.obj_type = 1
  190. ORDER BY c.update_time DESC
  191. LIMIT 50";
  192. $data_cario = $this->db->query($sql)->result_array();
  193. /*
  194. $data_cario = $this->db
  195. ->select('c.cario_no, c.in_out, in_lane, out_lane, c.in_time, c.out_time, c.minutes, c.obj_id as lpr, c.etag, c.in_pic_name, c.out_pic_name, m.member_name as owner')
  196. ->from('cario c')
  197. ->join('members m', 'c.member_no = m.member_no', 'left')
  198. ->where(array('c.obj_type' => 1, 'obj_id' => $lpr))
  199. ->order_by('c.update_time', 'desc')
  200. ->get()
  201. ->result_array();
  202. */
  203. $data = array();
  204. $idx = 0;
  205. foreach($data_cario as $rows)
  206. {
  207. ++$rows['in_lane'];
  208. ++$rows['out_lane'];
  209. $lane_no = empty($rows['out_time']) ? "入{$rows['in_lane']}" : "入{$rows['in_lane']} -> 出{$rows['out_lane']}";
  210. $io_time = empty($rows['out_time']) ? $rows['in_time'] : "{$rows['in_time']}(入)<br>{$rows['out_time']}(出)<br>{$rows['minutes']}分(停留時間)";
  211. $pic_name = str_replace('.jpg', '', empty($rows['out_pic_name']) ? $rows['in_pic_name'] : $rows['out_pic_name']);
  212. $arr = explode('-', $pic_name);
  213. $pic_path = APP_URL.'pics/'.substr($arr[7], 0, 8).'/'.$pic_name;
  214. $data[$idx++] = array
  215. (
  216. 'io_name' => $lane_no,
  217. 'lpr' => $rows['lpr'],
  218. 'etag' => $rows['etag'],
  219. 'owner' => empty($rows['owner']) ? '' : $rows['owner'],
  220. 'io_time' => $io_time,
  221. 'pic_name' => $pic_path
  222. );
  223. }
  224. return $data;
  225. }
  226. // 車號入場查詢
  227. public function carin_time_query($time_query, $minutes_range)
  228. {
  229. $curr_time = date('Y-m-d H:i:s');
  230. $start_time = date('Y-m-d H:i:s', strtotime("{$time_query} - {$minutes_range} minutes"));
  231. $end_time = date('Y-m-d H:i:s', strtotime("{$time_query} + {$minutes_range} minutes"));
  232. $data_cario = $this->db
  233. ->select('c.cario_no, c.in_out, in_lane, out_lane, c.in_time, c.out_time, c.minutes, c.obj_id as lpr, c.etag, c.in_pic_name, c.out_pic_name, m.member_name as owner')
  234. ->from('cario c')
  235. ->join('members m', 'c.obj_id = m.lpr', 'left')
  236. ->where(array('c.obj_type' => 1, 'c.in_time >=' => $start_time, 'c.in_time <=' => $end_time))
  237. ->order_by('c.update_time', 'desc')
  238. ->get()
  239. ->result_array();
  240. $data = array();
  241. $idx = 0;
  242. foreach($data_cario as $rows)
  243. {
  244. ++$rows['in_lane'];
  245. ++$rows['out_lane'];
  246. $lane_no = empty($rows['out_time']) ? "入{$rows['in_lane']}" : "入{$rows['in_lane']} -> 出{$rows['out_lane']}";
  247. $io_time = empty($rows['out_time']) ? $rows['in_time'] : "{$rows['in_time']}(入)<br>{$rows['out_time']}(出)<br>{$rows['minutes']}分(停留時間)";
  248. $pic_name = str_replace('.jpg', '', empty($rows['out_pic_name']) ? $rows['in_pic_name'] : $rows['out_pic_name']);
  249. $arr = explode('-', $pic_name);
  250. $pic_path = APP_URL.'pics/'.substr($arr[7], 0, 8).'/'.$pic_name;
  251. $data[$idx++] = array
  252. (
  253. 'io_name' => $lane_no,
  254. 'lpr' => $rows['lpr'],
  255. 'etag' => $rows['etag'],
  256. 'owner' => empty($rows['owner']) ? '' : $rows['owner'],
  257. 'io_time' => $io_time,
  258. 'pic_name' => $pic_path
  259. );
  260. }
  261. return $data;
  262. }
  263. // 車辨失敗查詢
  264. public function carin_none_query($time_query, $hours_range)
  265. {
  266. $curr_time = date('Y-m-d H:i:s');
  267. $start_time = date('Y-m-d H:i:s', strtotime("{$time_query} - {$hours_range} hours"));
  268. $end_time = date('Y-m-d H:i:s', strtotime("{$time_query} + {$hours_range} hours"));
  269. $data_cario = $this->db
  270. ->select('c.cario_no, c.in_out, in_lane, out_lane, c.in_time, c.out_time, c.minutes, c.obj_id as lpr, c.etag, c.in_pic_name, c.out_pic_name')
  271. ->from('cario c')
  272. ->where(array( 'c.in_time >=' => $start_time,
  273. 'c.in_time <=' => $end_time,
  274. 'c.obj_id' => 'NONE',
  275. 'c.err' => 0,
  276. 'c.finished' => 0
  277. ))
  278. ->order_by('c.in_time', 'desc')
  279. ->get()
  280. ->result_array();
  281. $data = array();
  282. $idx = 0;
  283. foreach($data_cario as $rows)
  284. {
  285. ++$rows['in_lane'];
  286. ++$rows['out_lane'];
  287. $lane_no = empty($rows['out_time']) ? "入{$rows['in_lane']}" : "入{$rows['in_lane']} -> 出{$rows['out_lane']}";
  288. $io_time = empty($rows['out_time']) ? $rows['in_time'] : "{$rows['in_time']}(入)<br>{$rows['out_time']}(出)<br>{$rows['minutes']}分(停留時間)";
  289. $pic_name = str_replace('.jpg', '', empty($rows['out_pic_name']) ? $rows['in_pic_name'] : $rows['out_pic_name']);
  290. $arr = explode('-', $pic_name);
  291. $pic_path = APP_URL.'pics/'.substr($arr[7], 0, 8).'/'.$pic_name;
  292. $data[$idx++] = array
  293. (
  294. 'cario_no' => $rows['cario_no'],
  295. 'io_name' => $lane_no,
  296. 'lpr' => $rows['lpr'],
  297. 'etag' => $rows['etag'],
  298. 'owner' => '',
  299. 'io_time' => $io_time,
  300. 'pic_name' => $pic_path
  301. );
  302. }
  303. return $data;
  304. }
  305. // 時間長度轉成日時分秒
  306. public function time2str($d1, $d2)
  307. {
  308. $time = strtotime($d2) - strtotime($d1);
  309. $day_str = floor($time/3600/24);
  310. $day_str = $day_str ? $day_str .= '天 ' : '';
  311. $hour_str = floor($time%(24*3600)/3600);
  312. $hour_str = $hour_str ? $hour_str .= '小時 ' : '';
  313. $minute_str = floor($time%3600/60);
  314. $minute_str = $minute_str ? $minute_str .= '分' : '';
  315. /*
  316. $second_str = $time%3600%60;
  317. $second_str = $second_str ? $second_str .= ' seconds ' : '';
  318. $n_time = floor($time/3600/24)."days".floor($time%(24*3600)/3600)."Hour".floor($time%3600/60)."Minute".($time%3600%60)."Second";
  319. */
  320. $n_time = $day_str . $hour_str . $minute_str;
  321. return $n_time;
  322. }
  323. // 在席車位檢查未有入場資料清單
  324. public function pks_check_list($max_rows)
  325. {
  326. $data = array();
  327. $data = $this->db
  328. ->select('pksno, lpr, in_time, pic_name')
  329. ->from('pks')
  330. ->where(array('status' => 'LR', 'cario_no' => 0, 'confirms' => 0, 'station_no' => STATION_NO))
  331. ->order_by('in_time', 'desc')
  332. ->limit($max_rows)
  333. ->get()
  334. ->result_array();
  335. return $data;
  336. }
  337. // 重設在席查核
  338. public function reset_pks_check()
  339. {
  340. // 讀出未查核過的資料
  341. $data_pks = $this->db
  342. ->select('pksno, lpr, in_time')
  343. ->from('pks')
  344. ->where(array('status' => 'LR', 'cario_no' => 0, 'station_no' => STATION_NO))
  345. ->get()
  346. ->result_array();
  347. // $tot = $this->db->num_rows(); // 總筆數
  348. $tot = count($data_pks); // 總筆數
  349. $num_cario = 0; // 入場資料筆數
  350. foreach($data_pks as $rows)
  351. {
  352. $lpr = $rows['lpr'];
  353. if ($lpr == 'NONE') continue; // 車辨失敗者不處理
  354. $pksno = $rows['pksno'];
  355. $pks_in_time = $rows['in_time'];
  356. // 讀取進場時間, 如讀不到資料, 以目前時間取代(add by TZUSS 2016-02-23)
  357. $rows_cario = $this->db
  358. ->select('cario_no, in_time')
  359. ->from('cario')
  360. ->where(array('in_out' => 'CI', 'obj_id' => $lpr, 'finished' => 0, 'err' => 0, 'station_no' => STATION_NO))
  361. ->order_by('cario_no', 'desc')
  362. ->limit(1)
  363. ->get()
  364. ->row_array();
  365. // if ($this->db->num_rows() == 1) // 有入場資料
  366. if (!empty($rows_cario['cario_no'])) // 有入cario_no場資料
  367. {
  368. $cario_no = $rows_cario['cario_no']; // 入場序號
  369. $in_time = $rows_cario['in_time'];
  370. // 在席與入場資料相符, 分別在cario與pks記錄之
  371. $data = array
  372. (
  373. 'pksno' => $pksno,
  374. 'pks_time' => $pks_in_time
  375. );
  376. $this->db->update('cario', $data, array('cario_no' => $cario_no, 'station_no' => STATION_NO));
  377. $data = array
  378. (
  379. 'cario_no' => $cario_no,
  380. 'in_time' => $in_time
  381. );
  382. // 車號及照片檔名填入資料庫內
  383. $this->db->update('pks', $data, array('pksno' => $pksno, 'station_no' => STATION_NO));
  384. ++$num_cario;
  385. }
  386. }
  387. return array('tot' => $tot, 'tot_correct' => $num_cario);
  388. }
  389. // 更正在席車號
  390. public function correct_pks_lpr($pksno, $lpr)
  391. {
  392. // 讀取進場時間, 如讀不到資料, 以目前時間取代(add by TZUSS 2016-02-23)
  393. $rows_cario = $this->db
  394. ->select('cario_no, in_time')
  395. ->from('cario')
  396. ->where(array('in_out' => 'CI', 'obj_id' => $lpr, 'finished' => 0, 'err' => 0, 'station_no' => STATION_NO))
  397. ->order_by('cario_no', 'desc')
  398. ->limit(1)
  399. ->get()
  400. ->row_array();
  401. if (!empty($rows_cario['cario_no'])) // 有cario_no入場資料
  402. {
  403. $cario_no = $rows_cario['cario_no']; // 入場序號
  404. $in_time = $rows_cario['in_time'];
  405. // 在席與入場資料相符, 分別在cario與pks記錄之
  406. $data = array
  407. (
  408. 'pksno' => $pksno,
  409. 'pks_time' => $in_time
  410. );
  411. $this->db->update('cario', $data, array('cario_no' => $cario_no, 'station_no' => STATION_NO));
  412. $data = array
  413. (
  414. 'confirms' => 1,
  415. 'cario_no' => $cario_no,
  416. 'lpr' => $lpr,
  417. 'in_time' => $in_time
  418. );
  419. // 車號及照片檔名填入資料庫內
  420. $this->db->update('pks', $data, array('pksno' => $pksno, 'station_no' => STATION_NO));
  421. $results = array
  422. (
  423. 'err' => 0,
  424. 'cario_no' => $cario_no
  425. );
  426. }
  427. else // 無入場資料
  428. {
  429. $data = array
  430. (
  431. 'confirms' => 1,
  432. 'lpr' => $lpr
  433. );
  434. $this->db->update('pks', $data, array('pksno' => $pksno, 'station_no' => STATION_NO));
  435. $results = array
  436. (
  437. 'err' => 0,
  438. 'cario_no' => 0 // 車號查無入場資料
  439. );
  440. }
  441. return $results;
  442. }
  443. // 入場車號查核在席無資料清單
  444. public function carin_check_list($max_rows)
  445. {
  446. $data = array();
  447. $rows_cario = $this->db
  448. ->select('cario_no, obj_id as lpr, in_time, member_no, in_pic_name')
  449. ->from('cario')
  450. ->where('in_out', 'CI')
  451. ->where(array('pksno' => 0, 'finished' => 0, 'err' => 0, 'confirms' => 0, 'station_no' => STATION_NO, 'in_time <=' => 'date_sub(now(), interval 20 minute)'), null, false)
  452. ->order_by('cario_no', 'desc')
  453. ->limit($max_rows)
  454. ->get()
  455. ->result_array();
  456. $idx = 0;
  457. foreach($rows_cario as $rows)
  458. {
  459. $data[$idx++] = array
  460. (
  461. 'cario_no' => $rows['cario_no'],
  462. 'lpr' => $rows['lpr'],
  463. 'in_time' => $rows['in_time'],
  464. 'type' => $rows['member_no'] == 0 ? '' : '月租',
  465. 'pic_name' => str_replace('-', '', substr($rows['in_time'], 0, 10)) . '/' . $rows['in_pic_name']
  466. );
  467. }
  468. return $data;
  469. }
  470. // 更正入場車號
  471. public function correct_carin_lpr($cario_no, $lpr, $in_time)
  472. {
  473. $rows = $this->db
  474. ->select('pksno, cario_no, in_time')
  475. ->from('pks')
  476. ->where(array('status' => 'LR', 'lpr' => $lpr, 'confirms' => 0, 'station_no' => STATION_NO))
  477. ->limit(1)
  478. ->get()
  479. ->row_array();
  480. // 如果在席資料相符
  481. if (!empty($rows['pksno']))
  482. {
  483. $pksno = $rows['pksno'];
  484. $data = array
  485. (
  486. 'cario_no' => $cario_no,
  487. 'in_time' => $in_time
  488. );
  489. $this->db->update('pks', $data, array('pksno' => $pksno, 'station_no' => STATION_NO));
  490. $data_cario = array
  491. (
  492. 'obj_id' => $lpr,
  493. 'pksno' => $pksno,
  494. 'pks_time' => $in_time,
  495. 'confirms' => 1
  496. );
  497. }
  498. else // 無在席資料
  499. {
  500. $data_cario = array
  501. (
  502. 'obj_id' => $lpr,
  503. 'pksno' => 0,
  504. 'confirms' => 1
  505. );
  506. }
  507. $this->db->update('cario', $data_cario, array('cario_no' => $cario_no, 'station_no' => STATION_NO));
  508. return(array('pksno' => $data_cario['pksno']));
  509. }
  510. // 查詢行動支付記錄
  511. public function tx_bill_query()
  512. {
  513. $sql = "SELECT
  514. tx_bill.order_no as order_no, tx_bill.lpr as lpr, tx_bill.invoice_no as invoice_no, tx_bill.in_time as in_time, tx_bill.balance_time as balance_time, tx_bill.company_no as company_no, tx_bill.email as email, tx_bill.mobile as mobile, tx_bill.amt as amt, tx_bill.tx_time as tx_time,
  515. allpay_feedback_log.rtn_msg as rtn_msg, allpay_feedback_log.payment_type as payment_type,
  516. cario.out_before_time as out_before_time
  517. FROM tx_bill
  518. LEFT JOIN cario ON tx_bill.cario_no = cario.cario_no
  519. LEFT JOIN allpay_feedback_log ON tx_bill.order_no = allpay_feedback_log.merchant_trade_no
  520. WHERE tx_bill.status = 111
  521. ORDER BY tx_bill.tx_time DESC";
  522. return $this->db->query($sql)->result_array();
  523. }
  524. // 查詢月租繳款機記錄
  525. public function tx_bill_ats_query()
  526. {
  527. $sql = "SELECT
  528. tx_bill_ats.order_no as order_no, tx_bill_ats.lpr as lpr, tx_bill_ats.invoice_no as invoice_no,
  529. tx_bill_ats.end_time as end_time, tx_bill_ats.next_start_time as next_start_time, tx_bill_ats.next_end_time as next_end_time,
  530. tx_bill_ats.company_no as company_no, tx_bill_ats.email as email, tx_bill_ats.mobile as mobile, tx_bill_ats.amt as amt,
  531. tx_bill_ats.remarks as remarks, tx_bill_ats.member_name as member_name, tx_bill_ats.tx_time as tx_time,
  532. allpay_feedback_log.rtn_msg as rtn_msg, allpay_feedback_log.payment_type as payment_type
  533. FROM tx_bill_ats
  534. LEFT JOIN allpay_feedback_log ON tx_bill_ats.order_no = allpay_feedback_log.merchant_trade_no
  535. WHERE tx_bill_ats.status = 111
  536. ORDER BY tx_bill_ats.tx_time DESC";
  537. return $this->db->query($sql)->result_array();
  538. }
  539. // 查詢樓層在席群組
  540. public function pks_group_query()
  541. {
  542. $sql = "SELECT
  543. pks_groups.station_no, pks_groups.group_name as group_name, pks_groups.tot as tot, pks_groups.parked as parked, pks_groups.availables as availables, pks_groups.group_id as group_id, pks_groups.renum as renum
  544. FROM pks_groups
  545. ORDER BY pks_groups.group_name * 1 DESC";
  546. return $this->db->query($sql)->result_array();
  547. }
  548. // 送出至message queue(目前用mqtt)
  549. public function mq_send($topic, $msg)
  550. {
  551. $this->vars['mqtt']->publish($topic, $msg, 0);
  552. trigger_error("mqtt:{$topic}|{$msg}");
  553. }
  554. }