VM暫存
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

350 Zeilen
10KB

  1. <?php
  2. /*
  3. file: Qcar_model.php 停車管理系統
  4. */
  5. class Qcar_model extends CI_Model
  6. {
  7. function __construct()
  8. {
  9. parent::__construct();
  10. $this->load->database();
  11. }
  12. // 查車
  13. public function q_pks($lpr)
  14. {
  15. $sql = "select p.pksno, p.pic_name, p.update_time, p.in_time, p.posx, p.posy, m.group_id, g.group_name, g.floors
  16. from pks p, pks_group_member m, pks_groups g
  17. where p.pksno = m.pksno
  18. and m.group_id = g.group_id
  19. and g.group_type = 1
  20. and p.lpr = '{$lpr}'
  21. limit 1";
  22. $rows = $this->db->query($sql)->row_array();
  23. /*555
  24. if (!empty($rows['pic_name']))
  25. {
  26. // $rows['pic_name'] = str_replace('.jpg', '', $rows['pic_name']);
  27. $rows['pic_name'] = $rows['pic_name'];
  28. } 666
  29. else // 查無資料, 啟用模糊比對
  30. { 777
  31. $len = strlen($lpr);
  32. if ($len >= 5) // 檢查車牌號碼長度
  33. {
  34. $arr = explode(';', file_get_contents("http://192.168.11.253:8090/cgi-bin/parking_status.cgi?CMD=QUERY_SEAT&LPR={$lpr}"));
  35. $pksno = $arr[0];
  36. }
  37. else
  38. {
  39. $pksno = 0; // 車牌號碼長度錯誤
  40. }
  41. trigger_error("電腦查詢模糊比對:[{$lpr}]:" . print_r($arr, true));
  42. if ($pksno != 0) // 模糊比對成功
  43. {
  44. $sql = "select p.pic_name, p.update_time, p.in_time, p.posx, p.posy, m.group_id, g.group_name, g.floors
  45. from pks p, pks_group_member m, pks_groups g
  46. where p.pksno = m.pksno
  47. and m.group_id = g.group_id
  48. and g.group_type = 1
  49. and p.pksno = {$pksno}
  50. limit 1";
  51. $rows_pks = $this->db->query($sql)->row_array();
  52. $rows['pksno'] = $pksno;
  53. // $rows['pic_name'] = str_replace('.jpg', '', $rows_pks['pic_name']);
  54. $rows['pic_name'] = $rows_pks['pic_name'];
  55. $rows['update_time'] = $rows_pks['update_time'];
  56. $rows['in_time'] = $rows_pks['in_time'];
  57. $rows['floors'] = $rows_pks['floors'];
  58. $rows['posx'] = $rows_pks['posx'];
  59. $rows['posy'] = $rows_pks['posy'];
  60. $rows['group_id'] = $rows_pks['group_id'];
  61. $rows['group_name'] = $rows_pks['group_name'];
  62. }
  63. else // 模糊比對仍是失敗
  64. {
  65. $rows['pksno'] = '0'; // 無該筆資料
  66. }
  67. }
  68. */
  69. return $rows;
  70. }
  71. // 月租會員加入
  72. public function q_rents($lpr)
  73. {
  74. $rows = $this->db->select("station_no, member_no, member_name, date_format(end_date, '%Y-%m-%d') as end_date, amt , date_add(date_format(end_date, '%Y-%m-%d'), INTERVAL 1 day) as next_start, date_add(date_format(end_date, '%Y-%m-%d'), INTERVAL 1 MONTH) as next_end", false)
  75. ->from('members')
  76. ->where('lpr', $lpr)
  77. ->get()
  78. ->row_array();
  79. if (empty($rows['member_no'])) $rows['member_no'] = 0; // 無此資料
  80. return $rows;
  81. }
  82. // 新增月租轉帳資料
  83. public function transfer_money_create($data)
  84. {
  85. $this->db->insert('tx_money', $data);
  86. }
  87. // 更新月租轉帳資料 (已結帳)
  88. public function transfer_money_done($order_no)
  89. {
  90. $data = array();
  91. $data['status'] = 1; //狀態,0:剛建立, 1:已結帳, 2:錢沒對上
  92. $this->db->update('tx_money', $data, array('order_no' => $order_no));
  93. return true;
  94. }
  95. // 更新發票號碼
  96. public function transfer_money_set_invoice($order_no, $invoice_no)
  97. {
  98. $data = array();
  99. $data['invoice_no'] = $invoice_no;
  100. $this->db->update('tx_money', $data, array('order_no' => $order_no));
  101. return true;
  102. }
  103. // 找不到POS機
  104. public function transfer_money_done_with_error_10($order_no)
  105. {
  106. $data = array();
  107. $data['status'] = 10; //狀態,0:剛建立, 1:已結帳, 2:錢沒對上, 3:發票沒拿到, 4:手動調整, 10:找不到POS機
  108. $this->db->update('tx_money', $data, array('order_no' => $order_no));
  109. return true;
  110. }
  111. // 更新發票號碼失敗
  112. public function transfer_money_set_invoice_error_4($order_no)
  113. {
  114. $data = array();
  115. $data['status'] = 3; //狀態,0:剛建立, 1:已結帳, 2:錢沒對上, 3:發票沒拿到
  116. $this->db->update('tx_money', $data, array('order_no' => $order_no));
  117. return true;
  118. }
  119. // 更新月租轉帳資料 (錢沒對上)
  120. public function transfer_money_done_with_error_2($order_no)
  121. {
  122. $data = array();
  123. $data['status'] = 2; //狀態,0:剛建立, 1:已結帳, 2:錢沒對上
  124. $this->db->update('tx_money', $data, array('order_no' => $order_no));
  125. return true;
  126. }
  127. // 取得月租轉帳資料
  128. public function get_tx_money($order_no)
  129. {
  130. $result = $this->db
  131. ->from('tx_money')
  132. ->where(array('order_no' => $order_no))
  133. ->get()
  134. ->result_array();
  135. return $result;
  136. }
  137. // 歐付寶記錄
  138. public function create_allpay_feedback_log($data)
  139. {
  140. $this->db->insert('allpay_feedback_log', $data);
  141. return true;
  142. }
  143. // 將發票號碼加入資料庫
  144. public function update_invoice_no($order_no, $invoice_no)
  145. {
  146. $this->db->where(array('order_no' => $order_no))
  147. ->update('tx_money', array('invoice_no' => $invoice_no));
  148. }
  149. // 新增發票記錄
  150. public function invoice_log_create($data)
  151. {
  152. $this->db->insert('tx_invoice_log', $data);
  153. }
  154. // 新增發票記錄回傳
  155. public function invoice_log_set_response($response_code, $invoice_no, $seqno)
  156. {
  157. $data = array();
  158. $data['response_code'] = $response_code;
  159. $this->db->update('tx_invoice_log', $data, array('invoice_no' => $invoice_no, 'seqno' => $seqno));
  160. return true;
  161. }
  162. // 取得POS機資訊
  163. public function get_tx_pos($pos_id)
  164. {
  165. $result = $this->db
  166. ->from('tx_pos')
  167. ->where(array('pos_id' => $pos_id))
  168. ->get()
  169. ->result_array();
  170. return $result;
  171. }
  172. // 取得POS機資訊 by lan_ip
  173. public function get_tx_pos_by_lan_ip($lan_ip)
  174. {
  175. $result = $this->db
  176. ->from('tx_pos')
  177. ->where(array('lan_ip' => $lan_ip))
  178. ->get()
  179. ->result_array();
  180. return $result;
  181. }
  182. // 模糊比對
  183. function getLevenshteinSQLStatement($word, $target)
  184. {
  185. $words = array();
  186. if(strlen($word) >= 5)
  187. {
  188. for ($i = 0; $i < strlen($word); $i++) {
  189. // insertions
  190. $words[] = substr($word, 0, $i) . '_' . substr($word, $i);
  191. // deletions
  192. $words[] = substr($word, 0, $i) . substr($word, $i + 1);
  193. // substitutions
  194. //$words[] = substr($word, 0, $i) . '_' . substr($word, $i + 1);
  195. }
  196. }
  197. else
  198. {
  199. for ($i = 0; $i < strlen($word); $i++) {
  200. // insertions
  201. $words[] = substr($word, 0, $i) . '_' . substr($word, $i);
  202. }
  203. }
  204. // last insertion
  205. $words[] = $word . '_';
  206. //return $words;
  207. $fuzzy_statement = ' (';
  208. foreach ($words as $idx => $word)
  209. {
  210. $fuzzy_statement .= " {$target} LIKE '%{$word}%' OR ";
  211. }
  212. $last_or_pos = strrpos($fuzzy_statement, 'OR');
  213. if($last_or_pos !== false)
  214. {
  215. $fuzzy_statement = substr_replace($fuzzy_statement, ')', $last_or_pos, strlen('OR'));
  216. }
  217. return $fuzzy_statement;
  218. }
  219. // 取得進場資訊 (模糊比對)
  220. public function q_fuzzy_pks($word)
  221. {
  222. if(empty($word) || strlen($word) <= 0 || strlen($word) > 10)
  223. {
  224. return null;
  225. }
  226. $sql = "SELECT station_no, lpr, in_time, pic_name as pks_pic_name
  227. FROM pks
  228. WHERE {$this->getLevenshteinSQLStatement($word, 'lpr')}
  229. ORDER BY lpr ASC";
  230. $retults = $this->db->query($sql)->result_array();
  231. if(count($retults) > 0)
  232. {
  233. foreach ($retults as $idx => $rows)
  234. {
  235. $pks_pic_path = '';
  236. if(!empty($rows['pks_pic_name']))
  237. {
  238. //$pks_pic_path = APP_URL.'pks_pics/'.str_replace('.jpg', '', $rows['pks_pic_name']);
  239. $pks_pic_path = SERVER_URL.'pkspic/'.$rows['pks_pic_name'];
  240. }
  241. $data['result'][$idx] = array
  242. (
  243. 'lpr'=> $rows['lpr'],
  244. 'pks_pic_path' => $pks_pic_path,
  245. 'station_no' => $rows['station_no'],
  246. 'in_time' => $rows['in_time']
  247. );
  248. }
  249. }
  250. else
  251. {
  252. // 讀取入場資料
  253. $sql = "SELECT cario.station_no as station_no, cario.obj_id as lpr, cario.in_time as in_time, cario.in_pic_name as pks_pic_name
  254. FROM cario
  255. WHERE {$this->getLevenshteinSQLStatement($word, 'obj_id')}
  256. AND in_out = 'CI' AND finished = 0 AND err = 0 AND out_time IS NULL
  257. ORDER BY lpr ASC";
  258. // AND in_time > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 5 DAY)
  259. $retults = $this->db->query($sql)->result_array();
  260. if(count($retults) > 0)
  261. {
  262. foreach ($retults as $idx => $rows)
  263. {
  264. $pks_pic_path = '';
  265. if(!empty($rows['pks_pic_name']))
  266. {
  267. $pic_name = str_replace('.jpg', '', $rows['pks_pic_name']);
  268. $arr = explode('-', $pic_name);
  269. $pks_pic_path = SERVER_URL.'carspic/'.substr($arr[7], 0, 8).'/'.$pic_name.'.jpg';
  270. }
  271. $data['result'][$idx] = array
  272. (
  273. 'lpr'=> $rows['lpr'],
  274. 'pks_pic_path' => $pks_pic_path,
  275. 'station_no' => $rows['station_no'],
  276. 'in_time' => $rows['in_time']
  277. );
  278. }
  279. }
  280. }
  281. return $data;
  282. /*
  283. foreach ($retults as $idx => $rows)
  284. {
  285. $pks_pic_path = '';
  286. if(!empty($rows['pks_pic_name']))
  287. {
  288. //$pks_pic_path = APP_URL.'pks_pics/'.str_replace('.jpg', '', $rows['pks_pic_name']);
  289. $pks_pic_path = SERVER_URL.'pkspic/'.$rows['pks_pic_name'];
  290. }
  291. $data['result'][$idx] = array
  292. (
  293. 'lpr'=> $rows['lpr'],
  294. 'pks_pic_path' => $pks_pic_path,
  295. 'station_no' => $rows['station_no'],
  296. 'in_time' => $rows['in_time']
  297. );
  298. }
  299. */
  300. }
  301. }