VM暫存
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Carpayment_model.php 27KB

il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 7 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 7 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 7 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 7 ans
il y a 8 ans
il y a 7 ans
il y a 8 ans
il y a 7 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. <?php
  2. /*
  3. file: carpayment_model.php
  4. */
  5. require_once(ALTOB_SYNC_FILE) ;
  6. class Carpayment_model extends CI_Model
  7. {
  8. var $vars = array();
  9. var $io_name = array('I' => '車入', 'O' => '車出', 'MI' => '機入', 'MO' => '機出', 'FI' => '樓入', 'FO' => '樓出');
  10. var $now_str;
  11. function __construct()
  12. {
  13. parent::__construct();
  14. $this->load->database();
  15. $this->now_str = date('Y-m-d H:i:s');
  16. }
  17. public function init($vars)
  18. {
  19. $this->vars = $vars;
  20. }
  21. ////////////////////////////////////////
  22. //
  23. // 付款後, 付款資訊建檔
  24. //
  25. ////////////////////////////////////////
  26. // [付款完成] 付款後續流程
  27. function payed_finished($cario_no, $lpr, $etag, $in_time)
  28. {
  29. $LOG_TAG = 'set_payed://';
  30. $LOG_TAG_FATAL = 'set_payed_fatal://';
  31. trigger_error(__FUNCTION__ . "|$cario_no 付款完成|$lpr, $etag, $in_time|");
  32. $trim_finished_cario_no_arr = array(); // 需處理的進場索引
  33. $in_time_value = strtotime($in_time);
  34. $in_time_1 = date('Y-m-d H:i:s', $in_time_value + 1); // +1 sec
  35. $in_time_2 = date('Y-m-d H:i:s', $in_time_value - 1); // -1 sec
  36. $in_time_3 = date('Y-m-d H:i:s', $in_time_value + 2); // +2 sec
  37. $in_time_4 = date('Y-m-d H:i:s', $in_time_value - 2); // -2 sec
  38. // 挑出已付款入場記錄, 入場時間附近 2 秒內, 但尚未結清之入場記錄
  39. $sql = "SELECT cario_no, obj_id as lpr, etag, in_time
  40. FROM cario
  41. WHERE in_time in ('$in_time', '$in_time_1', '$in_time_2', '$in_time_3', '$in_time_4')
  42. AND cario_no != $cario_no
  43. AND finished = 0
  44. AND payed = 0
  45. AND err = 0
  46. ";
  47. $in_time_retults = $this->db->query($sql)->result_array();
  48. if(!empty($in_time_retults) && count($in_time_retults) > 0)
  49. {
  50. $data = array();
  51. foreach ($in_time_retults as $idx => $rows)
  52. {
  53. $result_cario_no = $rows['cario_no'];
  54. $result_lpr = $rows['lpr'];
  55. $result_etag = $rows['etag'];
  56. $result_in_time = $rows['in_time'];
  57. if(empty($result_lpr) || $result_lpr == 'NONE')
  58. {
  59. if(strlen($result_etag) > 20 && $result_etag == $etag)
  60. {
  61. trigger_error($LOG_TAG . "$cario_no, $lpr, $etag, $in_time|無車牌|ETAG吻合|$result_cario_no, $result_lpr, $result_etag, $result_in_time|待註銷|skip");
  62. //array_push($trim_finished_cario_no_arr, $result_cario_no);
  63. }
  64. }
  65. else
  66. {
  67. $levenshtein_value = levenshtein($result_lpr, $lpr);
  68. if( $levenshtein_value == 0 || $levenshtein_value == 1)
  69. {
  70. trigger_error($LOG_TAG . "$cario_no, $lpr, $etag, $in_time|車牌 差0-1碼|$result_cario_no, $result_lpr, $result_etag, $result_in_time|待註銷");
  71. array_push($trim_finished_cario_no_arr, $result_cario_no);
  72. }
  73. else if($levenshtein_value == 2)
  74. {
  75. if(strlen($result_etag) > 20 && $result_etag == $etag)
  76. {
  77. trigger_error($LOG_TAG . "$cario_no, $lpr, $etag, $in_time|車牌 差2碼|ETAG吻合|$result_cario_no, $result_lpr, $result_etag, $result_in_time|待註銷|skip");
  78. //array_push($trim_finished_cario_no_arr, $result_cario_no);
  79. }
  80. }
  81. else
  82. {
  83. if(strlen($result_etag) > 20 && $result_etag == $etag)
  84. {
  85. trigger_error($LOG_TAG . "$cario_no, $lpr, $etag, $in_time|車牌不合|ETAG吻合|$result_cario_no, $result_lpr, $result_etag, $result_in_time|??");
  86. trigger_error($LOG_TAG_FATAL . "$cario_no, $lpr, $etag, $in_time|車牌不合|ETAG吻合|$result_cario_no, $result_lpr, $result_etag, $result_in_time|??");
  87. }
  88. }
  89. }
  90. }
  91. }
  92. // 執行註銷
  93. if(!empty($trim_finished_cario_no_arr))
  94. {
  95. $this->db->where_in('cario_no', $trim_finished_cario_no_arr)->update('cario', array('err' => 2))->limit(5);
  96. if (!$this->db->affected_rows())
  97. {
  98. trigger_error($LOG_TAG . "註銷失敗|" . $this->db->last_query());
  99. return 'fail';
  100. }
  101. trigger_error($LOG_TAG . "註銷成功|" . $this->db->last_query());
  102. trigger_error(__FUNCTION__ . '..trim_finished_cario_no_arr..' . print_r($trim_finished_cario_no_arr, true));
  103. }
  104. return 'ok';
  105. }
  106. // 通知付款完成
  107. public function p2payed($parms, $opay=false, $finished=false)
  108. {
  109. $result = $this->db->select("in_time, cario_no, station_no, etag")
  110. ->from('cario')
  111. ->where(array('obj_type' => 1, 'obj_id' => $parms['lpr'], 'finished' => 0, 'err' => 0))
  112. ->order_by('cario_no', 'desc')
  113. ->limit(1)
  114. ->get()
  115. ->row_array();
  116. // 找不到記錄
  117. if(!isset($result['cario_no']))
  118. {
  119. trigger_error(__FUNCTION__ . '..not found..' . print_r($parms, true));
  120. return false;
  121. }
  122. if($opay)
  123. {
  124. $pay_time = $this->now_str;
  125. $out_before_time = date('Y-m-d H:i:s', strtotime(" + 15 minutes"));
  126. $pay_type = 4;
  127. $data = array
  128. (
  129. 'out_before_time' => $out_before_time,
  130. 'pay_time' => $pay_time,
  131. 'pay_type' => 4, // 歐付寶行動支付
  132. 'payed' => 1
  133. );
  134. // 是否註記完結
  135. if($finished)
  136. $data['finished'] = 1;
  137. $this->db->where(array('cario_no' => $result['cario_no']))->update('cario', $data);
  138. if (!$this->db->affected_rows())
  139. {
  140. trigger_error("歐付寶行動支付失敗,{$parms['lpr']}金額:{$parms['amt']},序號:{$parms['seqno']}");
  141. return 'fail';
  142. }
  143. trigger_error("歐付寶行動支付成功,{$parms['lpr']}金額:{$parms['amt']},序號:{$parms['seqno']}");
  144. }
  145. else
  146. {
  147. // 若間隔小於 15 分鐘, 拿現在時間來當付款時間
  148. $pay_time = ((strtotime($parms['pay_time']) - strtotime($result['in_time'])) / 60 < 15) ? $this->now_str : $parms['pay_time'];
  149. // 限時離場時間
  150. $out_before_time = date('Y-m-d H:i:s', strtotime("{$pay_time} + 15 minutes"));
  151. // 付款方式
  152. $pay_type = $parms['pay_type'];
  153. // B. 一般繳費機
  154. $data = array
  155. (
  156. 'out_before_time' => $out_before_time,
  157. 'pay_time' => $pay_time,
  158. 'pay_type' => $pay_type,
  159. 'payed' => 1
  160. );
  161. // 是否註記完結
  162. if($finished)
  163. $data['finished'] = 1;
  164. $this->db->where(array('cario_no' => $result['cario_no']))->update('cario', $data);
  165. if (!$this->db->affected_rows())
  166. {
  167. trigger_error("付款失敗:{$parms['lpr']}|{$data['out_before_time']}");
  168. return 'fail';
  169. }
  170. trigger_error("付款後更新時間:{$parms['lpr']}|{$data['out_before_time']}|". print_r($data, true));
  171. }
  172. // 付款後續流程
  173. $this->payed_finished($result['cario_no'], $parms['lpr'], $result['etag'], $result['in_time']);
  174. // 傳送付款更新記錄
  175. $sync_agent = new AltobSyncAgent();
  176. $sync_agent->init($result['station_no'], $result['in_time']);
  177. $sync_agent->cario_no = $result['cario_no']; // 進出編號
  178. $sync_result = $sync_agent->sync_st_pay($parms['lpr'], $pay_time, $pay_type, $out_before_time, $finished);
  179. trigger_error( "..sync_st_pay.." . $sync_result);
  180. return 'ok';
  181. }
  182. // 行動支付, 手機告知已付款
  183. // http://203.75.167.89/carpayment.html/m2payed/ABC1234/120/12112/12345/1f3870be274f6c49b3e31a0c6728957f
  184. // http://203.75.167.89/carpayment.html/m2payed/車牌/金額/場站編號/序號/MD5
  185. // md5(車牌.金額.場站編號.序號)
  186. public function m2payed($parms, $finished=false)
  187. {
  188. $data = array
  189. (
  190. 'out_before_time' => date('Y-m-d H:i:s', strtotime(" + 15 minutes")),
  191. 'pay_time' => date('Y-m-d H:i:s'),
  192. 'pay_type' => 4, // 歐付寶行動支付
  193. 'payed' => 1
  194. );
  195. // 是否註記完結
  196. if($finished)
  197. $data['finished'] = 1;
  198. $this->db->where(array('cario_no' => $parms['seqno']))->update('cario', $data);
  199. if ($this->db->affected_rows())
  200. {
  201. trigger_error("歐付寶行動支付成功,{$parms['lpr']}金額:{$parms['amt']},序號:{$parms['seqno']}");
  202. return 'ok';
  203. }
  204. else
  205. {
  206. trigger_error("歐付寶行動支付失敗,{$parms['lpr']}金額:{$parms['amt']},序號:{$parms['seqno']}");
  207. return 'fail';
  208. }
  209. }
  210. ////////////////////////////////////////
  211. //
  212. // 付款前, 入場資訊查找
  213. //
  214. ////////////////////////////////////////
  215. // 模糊比對
  216. function getLevenshteinSQLStatement($word, $target)
  217. {
  218. $words = array();
  219. if(strlen($word) >= 5)
  220. {
  221. for ($i = 0; $i < strlen($word); $i++) {
  222. // insertions
  223. $words[] = substr($word, 0, $i) . '_' . substr($word, $i);
  224. // deletions
  225. $words[] = substr($word, 0, $i) . substr($word, $i + 1);
  226. // substitutions
  227. //$words[] = substr($word, 0, $i) . '_' . substr($word, $i + 1);
  228. }
  229. }
  230. else
  231. {
  232. for ($i = 0; $i < strlen($word); $i++) {
  233. // insertions
  234. $words[] = substr($word, 0, $i) . '_' . substr($word, $i);
  235. }
  236. }
  237. // last insertion
  238. $words[] = $word . '_';
  239. //return $words;
  240. $fuzzy_statement = ' (';
  241. foreach ($words as $idx => $word)
  242. {
  243. $fuzzy_statement .= " {$target} LIKE '%{$word}%' OR ";
  244. }
  245. $last_or_pos = strrpos($fuzzy_statement, 'OR');
  246. if($last_or_pos !== false)
  247. {
  248. $fuzzy_statement = substr_replace($fuzzy_statement, ')', $last_or_pos, strlen('OR'));
  249. }
  250. return $fuzzy_statement;
  251. }
  252. // 取得進場資訊 (模糊比對)
  253. function q_fuzzy_pks($word)
  254. {
  255. if(empty($word) || strlen($word) < 4 || strlen($word) > 10)
  256. {
  257. return null;
  258. }
  259. /*
  260. // 備援數字使用
  261. else if(is_numeric($word) && strlen($word) == 6)
  262. {
  263. trigger_error(__FUNCTION__ . '..備援查詢: ' . $word);
  264. $sql = "SELECT obj_id as lpr, ticket_no
  265. FROM cario
  266. WHERE finished = 0 AND err = 0
  267. AND out_before_time > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 5 DAY)
  268. AND ticket_no = {$word}
  269. ORDER BY out_before_time DESC";
  270. $retults = $this->db->query($sql)->result_array();
  271. return $retults;
  272. }
  273. */
  274. $fuzzy_statement = $this->getLevenshteinSQLStatement($word, 'obj_id');
  275. //trigger_error("模糊比對 {$word} where: {$fuzzy_statement}");
  276. $sql = "SELECT obj_id as lpr, ticket_no
  277. FROM cario
  278. WHERE {$fuzzy_statement} AND finished = 0 AND err = 0
  279. AND out_before_time > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 5 DAY)
  280. GROUP BY obj_id
  281. ORDER BY out_before_time DESC";
  282. $retults = $this->db->query($sql)->result_array();
  283. return $retults;
  284. }
  285. // 建立博辰查詢入場時間資料 (by ticket_no)
  286. function gen_query_data_type4($ticket_no)
  287. {
  288. $data = array();
  289. // s2. 完整車牌號碼: 右邊補空格補滿7碼
  290. $data['lpr'] = $ticket_no;
  291. // s3. 塔號_車格號碼: 該車牌相關車輛所停車的停車塔號或樓層號碼,
  292. // 地下室部分為負值例如B1為-1,平面停車場為1,二樓為2 (左邊補 ‘0’ 補滿2碼),
  293. // 停車格號4碼(左邊補 ‘0’ 補滿4碼),
  294. // 樓層和停車格號中間以 ‘_’ 分隔,例如:”01_0101”
  295. $data['seat_no'] = 'XX_XXXX';
  296. $data['ticket'] = 0;
  297. $data['start_date'] = '2000/01/01';
  298. $data['end_date'] = '2000/01/01';
  299. $data['start_time'] = '00:00';
  300. $data['end_time'] = '00:00';
  301. $result = $this->db->select("in_time, date_format(pay_time, '%Y/%m/%d %T') as pay_time, in_pic_name, member_no, in_lane, in_out, station_no")
  302. ->from('cario')
  303. ->where(array('obj_type' => 1, 'ticket_no' => $ticket_no, 'finished' => 0, 'err' => 0))
  304. ->order_by('cario_no', 'desc')
  305. ->limit(1)
  306. ->get()
  307. ->row_array();
  308. if (!empty($result['in_time']))
  309. {
  310. // s5. 入場時間: 格式為"yyyy/MM/dd HH:mm:ss",時間為24小時制,若無紀錄秒數秒數部分可填”00”
  311. $data['in_time'] = $result['in_time'];
  312. // s6. 入場車牌圖片路徑: 貴公司的絕對路徑,我方使用網路芳鄰或FTP下載
  313. $data['in_pic_name'] = $this->gen_in_pic_path($result);
  314. // s7. 繳費時間: 無繳費時間時為"2000/01/01 00:00:00",格式為"yyyy/MM/dd HH:mm:ss",時間為24小時制,若無紀錄秒數秒數部分可填”00”
  315. $data['pay_time'] = !empty($result['pay_time']) ? $result['pay_time'] : '2000/01/01 00:00:00';
  316. // s12. 停車位置區域代碼: 從 1 開始
  317. $data['area_code'] = $this->gen_area_code($result);
  318. }
  319. else
  320. {
  321. $data['in_time'] = '';
  322. $data['in_pic_name'] = '';
  323. $data['pay_time'] = '2000/01/01 00:00:00';
  324. $data['area_code'] = 1;
  325. }
  326. return $data;
  327. }
  328. // 取得圖檔路徑
  329. function gen_in_pic_path($cario)
  330. {
  331. // 北車西上特例
  332. $station_local_ip = ($cario['station_no'] == 12304)? '192.168.10.203' : STATION_LOCAL_IP;
  333. if(!empty($cario['in_pic_name']))
  334. {
  335. $pic_name_arr = explode('-', $cario['in_pic_name']);
  336. $date_num = substr($pic_name_arr[7], 0, 8);
  337. return "\\\\" . $station_local_ip . "\\pics\\{$date_num}\\{$cario['in_pic_name']}";
  338. }
  339. else if(file_exists(CAR_PIC . 'lpr-404.jpg'))
  340. {
  341. return "\\\\" . $station_local_ip . "\\pics\\lpr-404.jpg"; // 預設圖片
  342. }
  343. return '';
  344. }
  345. // 產生區域代碼 (判斷 in_out, in_lane, station_no)
  346. function gen_area_code($cario)
  347. {
  348. // 1: 北車西上 (一般車)
  349. // 2: 北車西上 (機車)
  350. // 3: 北車西下 (一般車)
  351. // 4: 北車西下 (計程車)
  352. // 北車西下
  353. if($cario['station_no'] == 12303)
  354. {
  355. if($cario['in_lane'] == 0)
  356. {
  357. return 4; // 4: 北車西下 (計程車)
  358. }
  359. else
  360. {
  361. return 3; // 3: 北車西下 (一般車)
  362. }
  363. }
  364. // 北車西上
  365. else if($cario['station_no'] == 12304)
  366. {
  367. if(substr($cario['in_out'], 0, 1) === 'C')
  368. {
  369. return 1; // 1: 北車西上 (一般車)
  370. }
  371. else
  372. {
  373. return 2; // 2: 北車西上 (機車)
  374. }
  375. }
  376. return 1; // 預設值
  377. }
  378. // 建立博辰查詢入場時間資料
  379. function gen_query_data($lpr)
  380. {
  381. $data = array();
  382. // s2. 完整車牌號碼: 右邊補空格補滿7碼
  383. $data['lpr'] = $lpr; //str_pad($lpr, 7, ' ', STR_PAD_RIGHT);
  384. // s3. 塔號_車格號碼: 該車牌相關車輛所停車的停車塔號或樓層號碼,
  385. // 地下室部分為負值例如B1為-1,平面停車場為1,二樓為2 (左邊補 ‘0’ 補滿2碼),
  386. // 停車格號4碼(左邊補 ‘0’ 補滿4碼),
  387. // 樓層和停車格號中間以 ‘_’ 分隔,例如:”01_0101”
  388. $sql = "select p.pksno, m.group_id
  389. from pks p, pks_group_member m, pks_groups g
  390. where p.pksno = m.pksno
  391. and m.group_id = g.group_id
  392. and g.group_type = 1
  393. and p.lpr = '{$lpr}'
  394. limit 1";
  395. $rows = $this->db->query($sql)->row_array();
  396. if (!empty($rows['pksno']))
  397. {
  398. //$data['seat_no'] = ($rows['group_id'] == 'B1' ? '-1' : '0' . substr($rows['group_id'], -1)) . '_0' . substr($rows['pksno'], -3);
  399. $group_floor_type = preg_replace( '/[^A-Z]/', '', $rows['group_id']);
  400. $group_floor_num = preg_replace( '/[^1-9]/', '', $rows['group_id']);
  401. if($group_floor_type == 'B')
  402. {
  403. $data['seat_no'] = '-' . $group_floor_num . '_0' . substr($rows['pksno'], -3);
  404. }
  405. else
  406. {
  407. $group_floor_num = str_pad($group_floor_num, 2, '0', STR_PAD_LEFT);
  408. $data['seat_no'] = $group_floor_num . '_0' . substr($rows['pksno'], -3);
  409. }
  410. }
  411. else
  412. {
  413. $data['seat_no'] = 'XX_XXXX'; // '-1_0028';
  414. }
  415. // 查詢是否月租會員
  416. $result = $this->db->select("date_format(start_date, '%Y/%m/%d') as start_date, date_format(end_date,'%Y/%m/%d') as end_date")
  417. ->from('members')
  418. ->where(array(
  419. 'lpr' => $lpr,
  420. 'start_date <' => $this->vars['date_time'],
  421. 'end_date >=' => $this->vars['date_time'])
  422. , false)
  423. ->limit(1)
  424. ->get()
  425. ->row_array();
  426. if (!empty($result['start_date'])) // 月租會員
  427. {
  428. $data['ticket'] = 1; // s4. 是否為月票: 0:非月票, 1:月票
  429. $data['start_date'] = $result['start_date'];// s8. 有效起始時間: 非月票時為"2000/01/01", 格式為"yyyy/MM/dd"
  430. $data['end_date'] = $result['end_date']; // s9. 有效截止日期: 非月票時為"2000/01/01", 格式為"yyyy/MM/dd"
  431. $data['start_time'] = '00:00'; // s10. 使用起始時段: 非月票時為"00:00", 格式為"HH:mm"
  432. $data['end_time'] = '23:59'; // s11. 使用結束時段: 非月票時為"00:00", 格式為"HH:mm"
  433. }
  434. else // 臨停車
  435. {
  436. $data['ticket'] = 0;
  437. $data['start_date'] = '2000/01/01';
  438. $data['end_date'] = '2000/01/01';
  439. $data['start_time'] = '00:00';
  440. $data['end_time'] = '00:00';
  441. }
  442. $result = $this->db->select("in_time, date_format(pay_time, '%Y/%m/%d %T') as pay_time, in_pic_name, member_no, in_lane, in_out, station_no")
  443. ->from('cario')
  444. //->where(array('obj_type' => 1, 'obj_id' => $lpr, 'finished' => 0, 'err' => 0))
  445. ->where(array('obj_type' => 1, 'obj_id' => $lpr, 'finished' => 0, 'err' => 0, 'ticket_type' => 0)) // 20180130 刷卡進的跳過
  446. ->order_by('cario_no', 'desc')
  447. ->limit(1)
  448. ->get()
  449. ->row_array();
  450. if (!empty($result['in_time']))
  451. {
  452. // s5. 入場時間: 格式為"yyyy/MM/dd HH:mm:ss",時間為24小時制,若無紀錄秒數秒數部分可填”00”
  453. $data['in_time'] = $result['in_time'];
  454. // s6. 入場車牌圖片路徑: 貴公司的絕對路徑,我方使用網路芳鄰或FTP下載
  455. $data['in_pic_name'] = $this->gen_in_pic_path($result);
  456. // s7. 繳費時間: 無繳費時間時為"2000/01/01 00:00:00",格式為"yyyy/MM/dd HH:mm:ss",時間為24小時制,若無紀錄秒數秒數部分可填”00”
  457. $data['pay_time'] = !empty($result['pay_time']) ? $result['pay_time'] : '2000/01/01 00:00:00';
  458. // s12. 停車位置區域代碼: 從 1 開始
  459. $data['area_code'] = $this->gen_area_code($result);
  460. }
  461. else
  462. {
  463. $data['in_time'] = '';
  464. $data['in_pic_name'] = '';
  465. $data['pay_time'] = '2000/01/01 00:00:00';
  466. $data['area_code'] = 1;
  467. }
  468. return $data;
  469. }
  470. // 博辰查詢入場時間 (fuzzy)
  471. public function query_in_fuzzy($lpr)
  472. {
  473. $fuzzy_result = $this->q_fuzzy_pks($lpr);
  474. $data_count = 0;
  475. if(!empty($fuzzy_result) && count($fuzzy_result) > 0)
  476. {
  477. $data = array();
  478. // s2 ~ s11 的資料會因模糊比對筆數增加或減少而增減
  479. foreach ($fuzzy_result as $idx => $rows)
  480. {
  481. $result_lpr = $rows['lpr'];
  482. $ticket_no = $rows['ticket_no'];
  483. if($result_lpr == 'NONE')
  484. {
  485. $tmp_data = $this->gen_query_data_type4($ticket_no); // 備緩搜尋
  486. }
  487. else
  488. {
  489. $tmp_data = $this->gen_query_data($result_lpr); // 模糊搜尋
  490. }
  491. if($tmp_data['ticket'] == 1)
  492. {
  493. trigger_error("月租車, 直接乎略這筆[{$result_lpr}]:".print_r($rows, true));
  494. }
  495. else if($tmp_data['in_time'] == '')
  496. {
  497. // 若查無入場時間, 直接乎略這筆
  498. trigger_error("查無入場時間, 直接乎略這筆[{$result_lpr}]:".print_r($rows, true));
  499. }
  500. else
  501. {
  502. $data['results'][$idx] = $tmp_data;
  503. $data_count++;
  504. }
  505. }
  506. $data['count'] = $data_count;
  507. }
  508. // 查無資料
  509. if($data_count == 0)
  510. {
  511. $data_0 = array();
  512. $data_0['lpr'] = str_pad($lpr, 7, ' ', STR_PAD_RIGHT);
  513. $data_0['seat_no'] = 'XX_XXXX';
  514. $data_0['ticket'] = 0;
  515. $data_0['start_date'] = '2000/01/01';
  516. $data_0['end_date'] = '2000/01/01';
  517. $data_0['start_time'] = '00:00';
  518. $data_0['end_time'] = '00:00';
  519. $data_0['in_time'] = '';
  520. $data_0['pay_time'] = '2000/01/01 00:00:00';
  521. $data_0['in_pic_name'] = '';
  522. $data_0['area_code'] = 1;
  523. $data = array();
  524. $data['results'][0] = $data_0;
  525. $data['count'] = 0;
  526. }
  527. trigger_error("fuzzy aps查詢入場時間[{$lpr}]:".print_r($data, true));
  528. return $data;
  529. }
  530. // 博辰查詢入場時間
  531. public function query_in($lpr)
  532. {
  533. $data = array();
  534. // 讀取樓層數, group_type = 2為樓層
  535. $sql = "select p.pksno, m.group_id
  536. from pks p, pks_group_member m, pks_groups g
  537. where p.pksno = m.pksno
  538. and m.group_id = g.group_id
  539. and g.group_type = 1
  540. and p.lpr = '{$lpr}'
  541. limit 1";
  542. $rows = $this->db->query($sql)->row_array();
  543. if (!empty($rows['pksno']))
  544. {
  545. //$data['seat_no'] = ($rows['group_id'] == 'B1' ? '-1' : '0' . substr($rows['group_id'], -1)) . '_' . substr($rows['pksno'], -3);
  546. $group_floor_type = preg_replace( '/[^A-Z]/', '', $rows['group_id']);
  547. $group_floor_num = preg_replace( '/[^1-9]/', '', $rows['group_id']);
  548. if($group_floor_type == 'B')
  549. {
  550. $data['seat_no'] = '-' . $group_floor_num . '_0' . substr($rows['pksno'], -3);
  551. }
  552. else
  553. {
  554. $group_floor_num = str_pad($group_floor_num, 2, '0', STR_PAD_LEFT);
  555. $data['seat_no'] = $group_floor_num . '_0' . substr($rows['pksno'], -3);
  556. }
  557. }
  558. else
  559. {
  560. $data['seat_no'] = 'XX_XXXX';
  561. }
  562. // 查詢是否月租會員
  563. $result = $this->db->select("date_format(start_date, '%Y/%m/%d') as start_date, date_format(end_date,'%Y/%m/%d') as end_date")
  564. ->from('members')
  565. ->where(array('lpr' => $lpr, 'end_date >=' => $this->vars['date_time']), false)
  566. ->limit(1)
  567. ->get()
  568. ->row_array();
  569. if (!empty($result['start_date'])) // 月租會員
  570. {
  571. $data['ticket'] = 1;
  572. $data['start_date'] = $result['start_date'];
  573. $data['end_date'] = $result['end_date'];
  574. $data['start_time'] = '00:00';
  575. $data['end_time'] = '23:59';
  576. }
  577. else // 臨停車
  578. {
  579. $data['ticket'] = 0;
  580. $data['start_date'] = '2000/01/01';
  581. $data['end_date'] = '2000/01/01';
  582. $data['start_time'] = '00:00';
  583. $data['end_time'] = '00:00';
  584. }
  585. $result = $this->db->select("in_time, date_format(pay_time, '%Y/%m/%d %T') as pay_time, in_pic_name, member_no, station_no")
  586. ->from('cario')
  587. ->where(array('obj_type' => 1, 'obj_id' => $lpr, 'finished' => 0, 'err' => 0))
  588. ->order_by('cario_no', 'desc')
  589. ->limit(1)
  590. ->get()
  591. ->row_array();
  592. if (!empty($result['in_time']))
  593. {
  594. trigger_error("aps查詢入場時間|{$lpr}|{$result['in_time']}|{$result['in_pic_name']}");
  595. $data['in_time'] = $result['in_time'];
  596. $data['pay_time'] = !empty($result['pay_time']) ? $result['pay_time'] : '2000/01/01 00:00:00';
  597. $data['in_pic_name'] = $this->gen_in_pic_path($result);
  598. $data['records'] = 1;
  599. }
  600. else
  601. {
  602. $data['in_time'] = '';
  603. $data['pay_time'] = '2000/01/01 00:00:00';
  604. $data['in_pic_name'] = '';
  605. $data['records'] = 0;
  606. }
  607. trigger_error("aps查詢入場時間[{$lpr}]:".print_r($data, true));
  608. // return array('in_time' => '', 'in_pic_name' => '', 'records' => 0, 'ticket' => 0, 'seat_no' => 'XX_XXXX');
  609. return $data;
  610. }
  611. // 行動設備查詢入場時間
  612. // http://203.75.167.89/carpayment.html/m2query_in/ABC1234/12112/1f3870be274f6c49b3e31a0c6728957f
  613. // http://203.75.167.89/carpayment.html/m2query_in/車牌/場站編號/MD5
  614. // 回傳0: 失敗, 成功: 12345,60(第一欄位非0數字代表成功, 第二欄位為金額), 此值在付款時必需傳回, 否則視為非法
  615. public function m2query_in($parms)
  616. {
  617. $result = $this->db->select('cario_no, out_before_time')
  618. ->from('cario')
  619. ->where(array('obj_type' => 1, 'obj_id' => $parms['lpr'], 'station_no' => $parms['station_no'], 'finished' => 0, 'err' => 0))
  620. ->order_by('cario_no', 'desc')
  621. ->limit(1)
  622. ->get()
  623. ->row_array();
  624. if (!empty($result['cario_no']))
  625. {
  626. trigger_error("行動設備查詢入場時間成功|{$lpr}|{$result['cario_no']}|{$result['in_time']}");
  627. // call計費模組
  628. $amt = 10;
  629. }
  630. else
  631. {
  632. $result['cario_no'] = 0;
  633. $amt = 0;
  634. trigger_error('行動設備查詢入場時間失敗'.print_r($parms, true));
  635. }
  636. return "{$result['cario_no']},{$amt}";
  637. }
  638. // 臨停未結清單
  639. public function cario_temp_not_finished_query_all($station_no, $q_item, $q_str)
  640. {
  641. $where_station = $station_no == 0 ? '' : " station_no = {$station_no} and "; // 如為0, 則全部場站讀取
  642. switch($q_item)
  643. {
  644. case 'in_time':
  645. $items = "{$q_item} >=";
  646. $q_str .= ' 23:59:59';
  647. break;
  648. case 'lpr':
  649. $items = "{$q_item} like ";
  650. $q_str = strtoupper($q_str).'%';
  651. break;
  652. default:
  653. $items = "{$q_item} like ";
  654. $q_str .= '%';
  655. break;
  656. }
  657. $sql = "
  658. SELECT
  659. cario_no,
  660. station_no,
  661. obj_id as lpr,
  662. in_time,
  663. out_before_time,
  664. pay_time
  665. FROM cario
  666. WHERE
  667. {$where_station} {$items} '{$q_str}'
  668. and obj_type = 1 and finished = 0 and err = 0 and confirms = 0
  669. and member_no = 0
  670. and out_time is null
  671. ORDER BY cario.cario_no asc
  672. ";
  673. //trigger_error(__FUNCTION__ . "test sql: {$sql}");
  674. $results = $this->db->query($sql)->result_array();
  675. return $results;
  676. }
  677. }