VM暫存
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

663 行
25KB

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