VM暫存
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Parkingquery_model.php 6.3KB

8 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /*
  3. file: Parkingquery_model.php 停車管理系統(提供資策會使用)
  4. */
  5. class Parkingquery_model extends CI_Model
  6. {
  7. function __construct()
  8. {
  9. parent::__construct();
  10. $this->load->database();
  11. }
  12. public function init($vars)
  13. {
  14. // do nothing
  15. }
  16. // 查詢各樓層剩餘車位
  17. // http://203.75.167.89/parkingquery.html/check_space/12345
  18. public function check_space($seqno)
  19. {
  20. $data = array();
  21. $results = $this->db->select('group_id, availables, tot')
  22. ->from('pks_groups')
  23. ->where('group_type', 1)
  24. ->get()
  25. ->result_array();
  26. foreach($results as $idx => $rows)
  27. {
  28. $data['result']['floor'][$idx] = array
  29. (
  30. 'floor_name' => $rows['group_id'],
  31. 'valid_count' => $rows['availables'],
  32. 'total_count' => $rows['tot']
  33. );
  34. }
  35. return $data;
  36. }
  37. // 停車位置查詢(板橋好停車)
  38. // http://203.75.167.89/parkingquery.html/check_location/ABC1234
  39. public function check_location($lpr)
  40. {
  41. $lpr = strtoupper($lpr); // 一律轉大寫
  42. $data = array();
  43. $rows = $this->db->select('pksno, pic_name')
  44. ->from('pks')
  45. ->where('lpr', $lpr)
  46. ->limit(1)
  47. ->get()
  48. ->row_array();
  49. if (!empty($rows['pksno']))
  50. {
  51. $data['result']['num'] = $lpr;
  52. $data['result']['location_no'] = "{$rows['pksno']}";
  53. $data['result_code'] = 'OK';
  54. $data['result']['pic_name'] = $rows['pic_name'];
  55. }
  56. else // 查無資料, 啟用模糊比對
  57. {
  58. // 讀取最近一筆入場資料
  59. $rows_cario = $this->db
  60. ->select('cario_no')
  61. ->from('cario')
  62. ->where(array('in_out' => 'CI', 'obj_id' => $lpr, 'finished' => 0, 'err' => 0, 'out_time IS NULL' => null))
  63. ->order_by('cario_no', 'desc')
  64. ->limit(1)
  65. ->get()
  66. ->row_array();
  67. // 有入場記錄, 直接猜在頂樓
  68. if (!empty($rows_cario['cario_no']))
  69. {
  70. $data['result']['num'] = $lpr;
  71. $data['result']['location_no'] = "7000";
  72. $data['result_code'] = 'OK';
  73. }
  74. else
  75. {
  76. $data['result']['num'] = $lpr;
  77. $data['result']['location_no'] = '0';
  78. $data['result_code'] = 'FAIL';
  79. }
  80. }
  81. return $data;
  82. }
  83. // 空車位導引
  84. // http://203.75.167.89/parkingquery.html/get_valid_seat
  85. // 註記現在時間, 並保留10分鐘
  86. public function get_valid_seat($pksno)
  87. {
  88. $data = array();
  89. $this->db->trans_start();
  90. if ($pksno > 0) // 限制從某一個車位開始指派車位
  91. {
  92. $sql = "select pksno from pks where status = 'VA' and pksno >= {$pksno} and prioritys != 0 and (book_time is null or book_time <= now()) order by prioritys asc limit 1 for update;";
  93. }
  94. else
  95. {
  96. $sql = "select pksno from pks where status = 'VA' and prioritys != 0 and (book_time is null or book_time <= now()) order by prioritys asc limit 1 for update;";
  97. }
  98. $rows = $this->db->query($sql)->row_array();
  99. if (!empty($rows['pksno']))
  100. {
  101. $data['result']['location_no'] = "{$rows['pksno']}";
  102. $data['result_code'] = 'OK';
  103. $sql = "update pks set book_time = addtime(now(), '00:10:00') where pksno = {$rows['pksno']};";
  104. $this->db->query($sql);
  105. }
  106. else
  107. {
  108. $data['result']['location_no'] = '0';
  109. $data['result_code'] = 'FAIL';
  110. }
  111. $this->db->trans_complete();
  112. return $data;
  113. }
  114. // 緊急求救
  115. // http://203.75.167.89/parkingquery.html/send_sos/B2/111/123
  116. public function send_sos($floor, $x, $y)
  117. {
  118. $data = array
  119. (
  120. 'result' => array('send_from' => array('floor' => $floor, 'x' => $x, 'y' => $y)),
  121. 'result_code' => 'OK'
  122. );
  123. return $data;
  124. }
  125. // 防盜鎖車
  126. // http://203.75.167.89/parkingquery.html/security_action/ABC1234/pswd/2
  127. public function security_action($lpr, $pswd, $action)
  128. {
  129. $data = array();
  130. /*
  131. $rows = $this->db->select('member_no, passwd, locked')
  132. ->from('members')
  133. ->where(array('lpr' => $lpr, 'passwd' => $pswd))
  134. ->limit(1)
  135. ->get()
  136. ->row_array();
  137. trigger_error('防盜鎖車:'.$this->db->last_query());
  138. // 無資料或密碼錯誤
  139. if (empty($rows['member_no']))
  140. {
  141. $data['result_code'] = 'FAIL';
  142. return($data);
  143. }
  144. */
  145. $rows = $this->db->select('member_no, passwd, locked')
  146. ->from('members')
  147. ->where(array('lpr' => $lpr))
  148. ->limit(1)
  149. ->get()
  150. ->row_array();
  151. trigger_error('防盜鎖車:'.$this->db->last_query());
  152. // 無資料或密碼錯誤
  153. if (empty($rows['member_no']) || md5($rows['passwd']) != $pswd)
  154. {
  155. $data['result_code'] = 'FAIL';
  156. return($data);
  157. }
  158. $data['result_code'] = 'OK';
  159. // 查詢防盜狀態
  160. if ($action == 2)
  161. {
  162. $data['result']['action'] = 'CHECK_SECURITY';
  163. $data['result'][0]['num'] = $lpr;
  164. $data['result'][0]['result'] = $rows['locked'] ? 'ON' : 'OFF';
  165. return $data;
  166. }
  167. $this->db
  168. ->where('member_no', $rows['member_no'])
  169. ->update('members', array('locked' => $action));
  170. $data['result']['action'] = $action == 1 ? 'ON' : 'OFF';
  171. return $data;
  172. }
  173. }