VM暫存
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Cars_model.php 55KB

před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 7 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 7 roky
před 8 roky
před 7 roky
před 8 roky
před 7 roky
před 8 roky
před 7 roky
před 8 roky
před 7 roky
před 8 roky
před 7 roky
před 8 roky
před 7 roky
před 8 roky
před 7 roky
před 8 roky
před 7 roky
před 8 roky
před 7 roky
před 8 roky
před 7 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
před 8 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680
  1. <?php
  2. /*
  3. file: cars_model.php
  4. */
  5. require_once(ALTOB_SYNC_FILE) ;
  6. define('CARS_TMP_LOG', 'cars_tmp_log'); // 暫存進出車號
  7. class Cars_model extends CI_Model
  8. {
  9. var $vars = array();
  10. var $io_name = array('I' => '車入', 'O' => '車出', 'MI' => '機入', 'MO' => '機出', 'FI' => '樓入', 'FO' => '樓出');
  11. var $now_str;
  12. function __construct()
  13. {
  14. parent::__construct();
  15. $this->load->database();
  16. $this->now_str = date('Y-m-d H:i:s');
  17. }
  18. public function init($vars)
  19. {
  20. $this->vars = $vars;
  21. }
  22. // 產生回傳訊息
  23. function gen_return_msg($msg_id, $open_or_not=false)
  24. {
  25. $open_id = $open_or_not ? 1 : 0;
  26. return $open_id . ',' . str_pad($msg_id, 5, '0', STR_PAD_LEFT);
  27. }
  28. // 修改車辨記錄
  29. public function upd_cario($parms)
  30. {
  31. trigger_error(__FUNCTION__ . '|修改車辨記錄:' . print_r($parms, true));
  32. // 更新入場記錄
  33. $data = array('obj_id' => $parms['lpr']);
  34. $this->db->update('cario', $data, array('station_no' => $parms['sno'], 'cario_no' => $parms['cno'], 'obj_id' => $parms['old_lpr'], 'err' => 0, 'finished' => 0));
  35. if ($this->db->affected_rows() <= 0)
  36. {
  37. trigger_error(__FUNCTION__ . '|fail|' . $this->db->last_query());
  38. return 'fail';
  39. }
  40. /* 20171226 車辨失敗暫不同步
  41. // 傳送更新記錄
  42. $sync_agent = new AltobSyncAgent();
  43. $sync_agent->init($parms['sno'], $this->now_str);
  44. $sync_agent->cario_no = $parms['cno']; // 進出編號
  45. $sync_result = $sync_agent->sync_st_io_meta($data);
  46. trigger_error( __FUNCTION__ . "..sync_st_io_meta|{$sync_agent->cario_no}|$sync_result|..". print_r($data, true));
  47. */
  48. return 'ok';
  49. }
  50. // 特殊方式進出註記
  51. public function ipcam_meta($parms)
  52. {
  53. trigger_error(__FUNCTION__ . '|特殊註記:' . print_r($parms, true));
  54. if($parms['token'] != 1)
  55. {
  56. trigger_error(__FUNCTION__ . '|未定義|' . print_r($parms, true));
  57. return false;
  58. }
  59. // 讀取最近一筆入場資料
  60. $rows_cario = $this->db->select('cario_no, obj_id, in_time, out_before_time')
  61. ->from('cario')
  62. ->where(array(
  63. 'station_no' => $parms['sno'],
  64. 'obj_id' => $parms['lpr'],
  65. 'err' => 0
  66. ))
  67. ->order_by('cario_no', 'desc')
  68. ->limit(1)
  69. ->get()
  70. ->row_array();
  71. if (!isset($rows_cario['cario_no']))
  72. {
  73. trigger_error(__FUNCTION__ . '|查無入場記錄|' . print_r($parms, true));
  74. return false;
  75. }
  76. // 更新入場記錄
  77. if(strtotime($rows_cario['out_before_time']) - strtotime($rows_cario['in_time']) > 600)
  78. $data = array('ticket_type' => 3, 'out_before_time' => $rows_cario['in_time']); // 刷進刷出需過卡
  79. else
  80. $data = array('ticket_type' => 3);
  81. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no']));
  82. trigger_error(__FUNCTION__ . '|悠遊卡,更新入場記錄|');
  83. $affect_rows = $this->db->affected_rows();
  84. if ($affect_rows > 0)
  85. {
  86. // 傳送更新記錄
  87. $sync_agent = new AltobSyncAgent();
  88. $sync_agent->init($parms['sno'], $this->now_str);
  89. $sync_agent->cario_no = $rows_cario['cario_no']; // 進出編號
  90. $sync_result = $sync_agent->sync_st_io_meta($data);
  91. trigger_error( __FUNCTION__ . "..sync_st_io_meta|{$sync_agent->cario_no}|$sync_result|..". print_r($data, true));
  92. }
  93. }
  94. // 車輛進出傳入車牌號碼 (2016/07/27)
  95. public function opendoor_lprio($parms)
  96. {
  97. $parms['lpr'] = urldecode($parms['lpr']);
  98. $rows = array();
  99. // $parms['ts'] = date('Y-m-d H:i:s', $parms['ts']);
  100. trigger_error(__FUNCTION__ . '|車牌傳入:' . print_r($parms, true));
  101. if ($parms['etag'] != 'NONE')
  102. {
  103. if ($parms['lpr'] != 'NONE')
  104. {
  105. // do nothing
  106. }
  107. else // 車辨失敗但有eTag, 查詢是否有車號
  108. {
  109. //$parms['lpr'] = $this->etag2lpr_2($parms['etag']); // 2017/01/10 預設都不用 ETAG 找車牌
  110. }
  111. }
  112. $rows = $this->get_member($parms['lpr'],$parms['sno']);
  113. return $this->save_db_io($parms, $rows, true);
  114. }
  115. // 車輛進出傳入車牌號碼
  116. public function lprio($parms)
  117. {
  118. //$parms['lpr'] = urldecode($parms['lpr']);
  119. $rows = array();
  120. // $parms['ts'] = date('Y-m-d H:i:s', $parms['ts']);
  121. trigger_error('車牌傳入:' . print_r($parms, true));
  122. if ($parms['etag'] != 'NONE')
  123. {
  124. if ($parms['lpr'] != 'NONE')
  125. {
  126. // 有車牌有eTag, 檢查資料庫是否double驗證
  127. //get_headers("http://192.168.10.201/cars.html/check_lpr_etag/{$parms['lpr']}/{$parms['etag']}");
  128. get_headers("http://localhost/cars.html/check_lpr_etag/{$parms['lpr']}/{$parms['etag']}"); // update 2016/07/26
  129. }
  130. else // 車辨失敗但有eTag, 查詢是否有車號
  131. {
  132. // $parms['lpr'] = $this->etag2lpr_2($parms['etag']); // 2017/01/10 預設都不用 ETAG 找車牌
  133. }
  134. }
  135. $rows = $this->get_member($parms['lpr'],$parms['sno']);
  136. return $this->save_db_io($parms, $rows);
  137. }
  138. // 入出口異動cario
  139. public function save_db_io($parms, $rows, $opendoor=false)
  140. {
  141. $msg_id = 0; // 訊息代碼
  142. if (!empty($rows['lpr_correct'])) $parms['lpr'] = $rows['lpr_correct'];
  143. // [START] 擋重覆
  144. $skip_or_not = false;
  145. $new_cars_tmp = array
  146. (
  147. 'timestamp' => time(),
  148. 'sno_io' => $parms['sno'] . $parms['io'],
  149. 'lpr' => $parms['lpr'],
  150. 'opendoor' => $opendoor // 20180118 開門與否訊號都過濾
  151. );
  152. $cars_tmp_arr = array();
  153. $cars_tmp_log_arr = $this->vars['mcache']->get(CARS_TMP_LOG);
  154. if(!empty($cars_tmp_log_arr))
  155. {
  156. foreach($cars_tmp_log_arr as $tmp)
  157. {
  158. if(isset($tmp['timestamp']) && $tmp['timestamp'] > time() - 3) // 時限內才判斷 (3 sec)
  159. {
  160. array_push($cars_tmp_arr, $tmp);
  161. }
  162. }
  163. }
  164. // 判斷是否繼續
  165. foreach($cars_tmp_arr as $tmp)
  166. {
  167. if( $new_cars_tmp['lpr'] == $tmp['lpr'] &&
  168. $new_cars_tmp['sno_io'] == $tmp['sno_io'] &&
  169. $new_cars_tmp['opendoor'] == $tmp['opendoor'] // 20180118 開門與否訊號都過濾
  170. )
  171. {
  172. $skip_or_not = true;
  173. }
  174. }
  175. // 更新 CARS_TMP_LOG
  176. array_push($cars_tmp_arr, $new_cars_tmp);
  177. $this->vars['mcache']->set(CARS_TMP_LOG, $cars_tmp_arr);
  178. trigger_error(__FUNCTION__ . '..new ' . CARS_TMP_LOG . " |s:{$skip_or_not}|" . print_r($cars_tmp_arr, true));
  179. // 跳過
  180. if($skip_or_not)
  181. {
  182. trigger_error(__FUNCTION__ . '..skip..');
  183. // [msg] 0: 不處理
  184. $msg_id = 0;
  185. return $this->gen_return_msg($msg_id);
  186. }
  187. // [END] 擋重覆
  188. // 車辨失敗, 結束
  189. if ($parms['lpr'] == 'NONE')
  190. {
  191. if($opendoor)
  192. {
  193. // [msg] 1: 車辨失敗
  194. $msg_id = 1;
  195. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']}".MQ_ALTOB_MSG_END_TAG);
  196. return $this->gen_return_msg($msg_id);
  197. }
  198. else
  199. {
  200. if(substr($parms['io'], -strlen('I')) === 'I')
  201. {
  202. $data = array
  203. (
  204. 'station_no' => $parms['sno'],
  205. 'obj_type' => 1,
  206. 'obj_id' => $parms['lpr'],
  207. 'etag' => $parms['etag'] == 'NONE' ? '' : $parms['etag'],
  208. 'in_out' => $parms['io'],
  209. 'member_no' => 0,
  210. 'finished' => 0,
  211. 'in_time' => $this->now_str,
  212. 'in_lane' => $parms['ivsno'],
  213. 'in_pic_name' => empty($parms['pic_name']) ? '' : $parms['pic_name'],
  214. 'out_before_time' => date("Y-m-d H:i:s"),
  215. 'ticket_no' => $this->gen_pass_code()
  216. );
  217. $this->db->insert('cario', $data);
  218. trigger_error("[車辨失敗] 新增入場資料:".print_r($parms, true));
  219. }
  220. }
  221. return false;
  222. }
  223. $msg = $rows['member_no'] != 0 ? "{$parms['lpr']}." : $parms['lpr']; // 月租車號加.符號
  224. // 月租鎖車, 結束
  225. if ((substr($parms['io'], -strlen('O')) === 'O') && $rows['member_no'] != 0 && !empty($rows['locked']) && $rows['locked'] == 1)
  226. {
  227. if($opendoor)
  228. {
  229. // [msg] 2: 已鎖車
  230. $msg_id = 2;
  231. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  232. return $this->gen_return_msg($msg_id);
  233. }
  234. return false;
  235. }
  236. // 取得會員資訊
  237. $parms['member_no'] = $rows['member_no'];
  238. switch($parms['io'])
  239. {
  240. case 'CI':
  241. case 'MI':
  242. if($opendoor)
  243. {
  244. // 空車位導引
  245. $pks_arr = $this->get_valid_seat();
  246. if ($pks_arr['result']['location_no'] != 0)
  247. {
  248. $pks_loc_name = $pks_arr['loc_name'];
  249. $pks_loc_no = $pks_arr['result']['location_no'];
  250. $pks_floors = $pks_arr['floors'];
  251. }
  252. else
  253. {
  254. $pks_loc_name = 0;
  255. $pks_loc_no = 0;
  256. $pks_floors = 0;
  257. }
  258. // 訊息
  259. // 訊息
  260. if ($rows['member_no'] > 0)
  261. {
  262. // [msg] 4: 會員, 開門
  263. $msg_id = 4;
  264. // 會員開門
  265. $this->member_opendoors($parms);
  266. }
  267. else
  268. {
  269. /*$ck = md5($parms['lpr']);
  270. $jdata = file_get_contents("http://localhost/allpa_service.html/get_allpa_valid_user/{$parms['lpr']}/{$ck}");
  271. $results = json_decode($jdata, true);
  272. if($results['result_code'] == 0)
  273. {
  274. // [msg] 3: 歐pa卡, 開門
  275. $msg_id = 3;
  276. // 會員開門
  277. $this->member_opendoors($parms);
  278. }
  279. else
  280. {*/
  281. // [msg] 11: 臨停車, 開門
  282. $msg_id = 11;
  283. // 臨停開門
  284. $this->temp_opendoors($parms);
  285. //}
  286. }
  287. // 字幕
  288. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']},{$pks_floors},{$pks_loc_no}".MQ_ALTOB_MSG_END_TAG);
  289. // 產生回傳
  290. return $this->gen_return_msg($msg_id, true);
  291. }
  292. else
  293. // 資料流
  294. {
  295. if ($parms['lpr'] != 'NONE')
  296. {
  297. $data = array
  298. (
  299. 'err' => 1,
  300. 'finished' => 1
  301. );
  302. // 原有歷史記錄, 設定錯誤碼為1(入場不應該有歷史記錄)
  303. $this->db->update('cario', $data, array('obj_id' => $parms['lpr'], 'finished' => 0, 'err' => 0, 'obj_type' => 1));
  304. $affect_rows = $this->db->affected_rows();
  305. if ($affect_rows > 0)
  306. {
  307. trigger_error("err://入場郤已有歷史進場記錄[{$affect_rows}]筆,已設成錯誤並結清記錄".print_r($parms, true));
  308. }
  309. }
  310. //20190113新增手動入場
  311. // 15分鐘內, 可直接離場 (刷進刷出需過卡修正)
  312. //if(isset($parms['free_time']) && $parms['free_time'] > 0)
  313. // $out_before_time_value = date('Y-m-d H:i:s', strtotime(" + {$parms['free_time']} minutes"));
  314. //else
  315. // $out_before_time_value = date("Y-m-d H:i:s");
  316. $data = array
  317. (
  318. 'station_no' => $parms['sno'],
  319. 'obj_type' => 1,
  320. 'obj_id' => $parms['lpr'],
  321. 'etag' => $parms['etag'] == 'NONE' ? '' : $parms['etag'],
  322. 'in_out' => $parms['io'],
  323. 'member_no' => $rows['member_no'],
  324. 'finished' => 0,
  325. 'in_time' => $this->now_str,
  326. 'in_lane' => $parms['ivsno'],
  327. 'in_pic_name' => empty($parms['pic_name']) ? '' : $parms['pic_name'],
  328. 'out_before_time' => $this->now_str,
  329. 'ticket_no' => $this->gen_pass_code()
  330. );
  331. $data['in_time'] = isset($parms['in_time']) ? $parms['in_time'] : $this->now_str;
  332. if(isset($parms['free_time']) && $parms['free_time'] > 0)
  333. {
  334. $data['out_before_time'] = date('Y-m-d H:i:s', strtotime(" + {$parms['free_time']} minutes",strtotime($parms['in_time'])));
  335. if($data['out_before_time'] < $data['in_time'])
  336. {
  337. $data['out_before_time']=$data['in_time'];
  338. }
  339. }
  340. else
  341. {
  342. $data['out_before_time'] = $data['in_time'];
  343. }
  344. $this->db->insert('cario', $data);
  345. trigger_error("新增入場資料:".print_r($parms, true));
  346. // 傳送進場記錄
  347. $sync_agent = new AltobSyncAgent();
  348. $sync_agent->init($parms['sno'], $this->now_str);
  349. $sync_agent->cario_no = $this->db->insert_id(); // 進出編號
  350. $sync_agent->member_no = $rows['member_no']; // 會員編號
  351. $sync_result = $sync_agent->sync_st_in($parms);
  352. trigger_error( "..sync_st_in.." . $sync_result);
  353. }
  354. return true;
  355. break;
  356. // 出場
  357. case 'CO':
  358. case 'MO':
  359. // 讀取最近一筆入場資料
  360. $rows_cario = $this->db
  361. ->select('cario_no, payed, in_time, pay_time, out_before_time')
  362. ->from('cario')
  363. //->where(array('in_out' => 'CI', 'obj_id' => $parms['lpr'], 'finished' => 0, 'err' => 0))
  364. ->where(array('obj_id' => $parms['lpr'], 'finished' => 0, 'err' => 0))
  365. ->order_by('cario_no', 'desc')
  366. ->limit(1)
  367. ->get()
  368. ->row_array();
  369. trigger_error("opendoor={$opendoor}| 出場讀到資料:{$rows['member_no']}|".time().'|'.print_r($rows_cario, true));
  370. if (!empty($rows_cario['cario_no'])) // 在限時內可出場
  371. {
  372. $co_time_minutes = floor((strtotime($this->now_str) - strtotime($rows_cario['in_time'])) / 60); // 停車時數 (分鐘)
  373. // 合規定者開門放行
  374. switch(true)
  375. {
  376. case $rows['member_no'] != 0:
  377. // CO.A.1 會員車
  378. // 判斷時段租是否超時 (超過 12 小時)
  379. if($rows['park_time'] != 'RE' && $co_time_minutes > 720)
  380. {
  381. if($opendoor)
  382. {
  383. // [msg] 16: 時段租超時字幕
  384. $msg_id = 16;
  385. // 字幕
  386. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  387. // 產生回傳
  388. return $this->gen_return_msg($msg_id);
  389. }
  390. else
  391. {
  392. $data = array
  393. (
  394. 'out_time' => $this->now_str,
  395. 'out_lane' => $parms['ivsno'],
  396. 'minutes' => $co_time_minutes,
  397. 'out_pic_name' => $parms['pic_name']
  398. );
  399. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no'])); // 記錄出場
  400. trigger_error("{$parms['lpr']}|時段租超時" . print_r($rows_cario, true));
  401. // 傳送離場記錄
  402. $sync_agent = new AltobSyncAgent();
  403. $sync_agent->init($parms['sno'], $this->now_str);
  404. $sync_agent->cario_no = $rows_cario['cario_no']; // 進出編號
  405. $sync_agent->member_no = $rows['member_no']; // 會員編號
  406. $sync_agent->in_time = $rows_cario['in_time']; // 入場時間
  407. $sync_result = $sync_agent->sync_st_out($parms);
  408. trigger_error( "..sync_st_out.." . $sync_result);
  409. }
  410. return true;
  411. }
  412. if($opendoor)
  413. {
  414. // [msg] 5: 會員離場開門
  415. $msg_id = 5;
  416. // 會員開門
  417. $this->member_opendoors($parms);
  418. // 字幕
  419. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  420. // 產生回傳
  421. return $this->gen_return_msg($msg_id, true);
  422. }
  423. else
  424. {
  425. $data = array
  426. (
  427. 'in_out' => $parms['io'],
  428. 'finished' => 1,
  429. 'out_time' => $this->now_str,
  430. 'out_lane' => $parms['ivsno'],
  431. 'minutes' => $co_time_minutes,
  432. 'out_pic_name' => $parms['pic_name']
  433. );
  434. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no']));
  435. trigger_error('會員車離場:' . print_r($rows, true));
  436. // 傳送離場記錄
  437. $sync_agent = new AltobSyncAgent();
  438. $sync_agent->init($parms['sno'], $this->now_str);
  439. $sync_agent->cario_no = $rows_cario['cario_no']; // 進出編號
  440. $sync_agent->member_no = $rows['member_no']; // 會員編號
  441. $sync_agent->in_time = $rows_cario['in_time']; // 入場時間
  442. $sync_agent->finished = 1; // 已離場
  443. $sync_result = $sync_agent->sync_st_out($parms);
  444. trigger_error( "..sync_st_out.." . $sync_result);
  445. }
  446. return true;
  447. break;
  448. case strtotime($rows_cario['out_before_time']) >= time():
  449. if ($rows_cario['payed'])
  450. {
  451. // CO.B.1 臨停車已付款
  452. if($opendoor)
  453. {
  454. // [msg] 6: 臨停車已付款
  455. $msg_id = 6;
  456. // 臨停開門
  457. $this->temp_opendoors($parms);
  458. // 字幕
  459. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  460. // 產生回傳
  461. return $this->gen_return_msg($msg_id, true);
  462. }
  463. else
  464. {
  465. $data = array
  466. (
  467. 'in_out' => $parms['io'],
  468. 'finished' => 1,
  469. 'out_time' => $this->now_str,
  470. 'out_lane' => $parms['ivsno'],
  471. 'minutes' => $co_time_minutes,
  472. 'out_pic_name' => $parms['pic_name']
  473. );
  474. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no']));
  475. trigger_error('臨停車已付款:' . print_r($rows, true));
  476. // 傳送離場記錄
  477. $sync_agent = new AltobSyncAgent();
  478. $sync_agent->init($parms['sno'], $this->now_str);
  479. $sync_agent->cario_no = $rows_cario['cario_no']; // 進出編號
  480. $sync_agent->in_time = $rows_cario['in_time']; // 入場時間
  481. $sync_agent->finished = 1; // 已離場
  482. $sync_result = $sync_agent->sync_st_out($parms);
  483. trigger_error( "..sync_st_out.." . $sync_result);
  484. }
  485. return true;
  486. }
  487. else
  488. {
  489. // CO.B.2 臨停車未付款
  490. if($opendoor)
  491. {
  492. // [msg] 8: 臨停車未付款
  493. $msg_id = 8;
  494. // 字幕
  495. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  496. // 產生回傳
  497. return $this->gen_return_msg($msg_id);
  498. }
  499. else
  500. {
  501. // TODO: 歐pa卡離場記錄和臨停未付款一樣, 待更正
  502. $data = array
  503. (
  504. 'out_time' => $this->now_str,
  505. 'out_lane' => $parms['ivsno'],
  506. 'minutes' => $co_time_minutes,
  507. 'out_pic_name' => $parms['pic_name']
  508. );
  509. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no'])); // 記錄出場
  510. trigger_error('臨停未付款:' . print_r($rows, true));
  511. // 傳送離場記錄
  512. $sync_agent = new AltobSyncAgent();
  513. $sync_agent->init($parms['sno'], $this->now_str);
  514. $sync_agent->cario_no = $rows_cario['cario_no']; // 進出編號
  515. $sync_agent->in_time = $rows_cario['in_time']; // 入場時間
  516. $sync_result = $sync_agent->sync_st_out($parms);
  517. trigger_error( "..sync_st_out.." . $sync_result);
  518. // [mitac] 要求 mitac 扣款 START
  519. $this->call_mitac_pay($parms['lpr'], $parms['ivsno'], $rows_cario);
  520. // [mitac] 要求 mitac 扣款 END
  521. }
  522. return true;
  523. }
  524. break;
  525. default:
  526. // CO.C.1 其它付款方式
  527. if($opendoor)
  528. {
  529. $in_time = strtotime($rows_cario['out_before_time']);
  530. $ck = md5($in_time. $parms['lpr'] . $parms['sno']);
  531. //$jdata = file_get_contents("http://localhost/allpa_service.html/allpa_go/{$in_time}/{$parms['lpr']}/{$parms['sno']}/{$ck}");
  532. $jdata = file_get_contents("http://localhost/allpa_service.html/allpa_go_remote/{$in_time}/{$parms['lpr']}/{$parms['sno']}/{$ck}");
  533. trigger_error("allpa回傳:{$jdata}|{$in_time}/{$parms['lpr']}/{$parms['sno']}/{$ck}");
  534. $results = json_decode($jdata, true);
  535. if (isset($results['result_code'])) // 歐pa卡, 點數足夠扣
  536. {
  537. if($results['result_code'] == 0)
  538. {
  539. // [msg] 7: 歐pa卡付款
  540. $msg_id = 7;
  541. // 臨停開門
  542. $this->temp_opendoors($parms);
  543. // 歐pa卡, 字幕
  544. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']},{$results['amt']}".MQ_ALTOB_MSG_END_TAG);
  545. $data = array(
  546. 'out_before_time' => date('Y-m-d H:i:s', strtotime(" + 15 minutes")),
  547. 'pay_time' => $this->now_str,
  548. 'pay_type' => 9, // 歐pa卡
  549. 'payed' => 1
  550. );
  551. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no'])); // 記錄出場
  552. // 產生回傳
  553. return $this->gen_return_msg($msg_id, true);
  554. }
  555. else if ($results['result_code'] == 12) // 歐pa卡, 餘額不足
  556. {
  557. // [msg] 12: 歐pa卡, 餘額不足
  558. $msg_id = 12;
  559. }
  560. else if ($results['result_code'] == 11) // 歐pa卡, 查無會員
  561. {
  562. // [msg] 9: 其它付款方式
  563. $msg_id = 9;
  564. }
  565. else
  566. {
  567. // [msg] 9: 其它付款方式
  568. $msg_id = 9;
  569. }
  570. }
  571. else
  572. {
  573. // [msg] 9: 其它付款方式
  574. $msg_id = 9;
  575. }
  576. // 字幕
  577. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  578. // 產生回傳
  579. return $this->gen_return_msg($msg_id);
  580. }
  581. else
  582. {
  583. $data = array
  584. (
  585. 'out_time' => $this->now_str,
  586. 'out_lane' => $parms['ivsno'],
  587. 'minutes' => $co_time_minutes,
  588. 'out_pic_name' => $parms['pic_name']
  589. );
  590. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no'])); // 記錄出場
  591. trigger_error("{$parms['lpr']}|其它付款方式:" . print_r($rows_cario, true));
  592. // 傳送離場記錄
  593. $sync_agent = new AltobSyncAgent();
  594. $sync_agent->init($parms['sno'], $this->now_str);
  595. $sync_agent->cario_no = $rows_cario['cario_no']; // 進出編號
  596. $sync_agent->in_time = $rows_cario['in_time']; // 入場時間
  597. $sync_result = $sync_agent->sync_st_out($parms);
  598. trigger_error( "..sync_st_out.." . $sync_result);
  599. // [mitac] 要求 mitac 扣款 START
  600. $this->call_mitac_pay($parms['lpr'], $parms['ivsno'], $rows_cario);
  601. // [mitac] 要求 mitac 扣款 END
  602. }
  603. return true;
  604. break;
  605. }
  606. }
  607. else if ($rows['member_no'] != 0)
  608. {
  609. // CO.Z.1 月租車無入場資料
  610. if($opendoor)
  611. {
  612. // [msg] 10: 月租車無入場資料
  613. $msg_id = 10;
  614. // 會員開門
  615. $this->member_opendoors($parms);
  616. // 會員字幕
  617. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  618. // 產生回傳
  619. return $this->gen_return_msg($msg_id, true);
  620. }
  621. else
  622. {
  623. trigger_error('月租車無入場資料:' . print_r($rows, true));
  624. // 傳送離場記錄
  625. $sync_agent = new AltobSyncAgent();
  626. $sync_agent->init($parms['sno'], $this->now_str);
  627. $sync_agent->member_no = $rows['member_no']; // 會員編號
  628. $sync_agent->finished = 1; // 已離場
  629. $sync_result = $sync_agent->sync_st_out($parms);
  630. trigger_error( "..sync_st_out.." . $sync_result);
  631. }
  632. return true;
  633. }
  634. else
  635. {
  636. // CO.Z.Z 無入場資料
  637. if($opendoor)
  638. {
  639. // [msg] 13: 無入場資料
  640. $msg_id = 13;
  641. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  642. // 產生回傳
  643. return $this->gen_return_msg($msg_id);
  644. }
  645. else
  646. {
  647. trigger_error('無入場資料:' . print_r($rows, true));
  648. // 傳送離場記錄
  649. $sync_agent = new AltobSyncAgent();
  650. $sync_agent->init($parms['sno'], $this->now_str);
  651. $sync_result = $sync_agent->sync_st_out($parms);
  652. trigger_error( "..sync_st_out.." . $sync_result);
  653. }
  654. return true;
  655. }
  656. break;
  657. }
  658. }
  659. // 檢查是否合法會員或VIP資料
  660. public function get_member($lpr,$sno)
  661. {
  662. $where_arr = array
  663. (
  664. 'c.lpr' => $lpr,
  665. 'c.start_time <=' => $this->now_str,
  666. 'c.end_time >=' => $this->now_str
  667. );
  668. $sql = "select
  669. c.lpr_correct,
  670. c.member_no,
  671. m.member_name,
  672. m.member_type,
  673. m.locked,
  674. m.remarks,
  675. m.park_time,
  676. m.suspended,
  677. m.valid_time,
  678. c.etag,
  679. c.start_time,
  680. c.end_time
  681. from member_car c, members m
  682. where c.member_no = m.member_no
  683. and c.start_time <= '{$this->now_str}'
  684. and c.end_time >= '{$this->now_str}'
  685. and c.lpr = '{$lpr}' ";
  686. if(!empty($sno) && $sno > 0)
  687. {
  688. $sql = "{$sql}and c.station_no = {$sno} ";
  689. }
  690. $sql = "{$sql}limit 1";
  691. $rows = $this->db->query($sql)->row_array();
  692. // 新增 park_time_check 2016/11/11
  693. $park_time_check = 0;
  694. if (!empty($rows['lpr_correct']))
  695. {
  696. $park_time = $rows['park_time'];
  697. $pt_arr = $this->vars['mcache']->get('pt');
  698. if(empty($pt_arr) || empty($park_time))
  699. {
  700. // ERROR: 無法驗証時段, 跳過時段限制判斷
  701. trigger_error("[ERROR] mcache.pt is empty !!");
  702. $park_time_check = 1;
  703. }
  704. else
  705. {
  706. $now_time = substr($this->now_str, 11); // 日期字串只取最後時間字串(13:25:32)
  707. $week_no = date('w',strtotime($this->now_str)); // 取星期幾
  708. $park_time_array = explode(',', $park_time); // 用 , 格開
  709. foreach($park_time_array as $idx => $park_time_value)
  710. {
  711. foreach($pt_arr[$park_time_value]['timex'] as $idx => $pt_rows)
  712. {
  713. if ($week_no >= $pt_rows['w_start'] &&
  714. $week_no <= $pt_rows['w_end'] &&
  715. $now_time >= $pt_rows['time_start'] &&
  716. $now_time <= $pt_rows['time_end'])
  717. {
  718. $park_time_check = 2;
  719. trigger_error("時段代碼:{$park_time_value} 星期:{$week_no}");
  720. break;
  721. }
  722. }
  723. }
  724. }
  725. }
  726. if (empty($rows['lpr_correct'])) // A. 非月租車
  727. {
  728. $rows = array
  729. (
  730. 'lpr_correct' => '',
  731. 'member_no' => 0,
  732. 'member_name' => '',
  733. 'member_type' => 9,
  734. 'etag' => '',
  735. 'start_time' => '',
  736. 'end_time' => '',
  737. );
  738. }
  739. else if(empty($park_time_check)) // B. 月租車, 時段無效
  740. {
  741. trigger_error("無效的時段!! " . print_r($rows, true));
  742. $rows = array
  743. (
  744. 'lpr_correct' => '',
  745. 'member_no' => 0,
  746. 'member_name' => '',
  747. 'member_type' => 9,
  748. 'etag' => '',
  749. 'start_time' => '',
  750. 'end_time' => '',
  751. );
  752. }
  753. else if(!empty($rows['suspended'])) // C. 月租車, 停權中
  754. {
  755. trigger_error("停權中!! " . print_r($rows, true));
  756. $rows = array
  757. (
  758. 'lpr_correct' => '',
  759. 'member_no' => 0,
  760. 'member_name' => '',
  761. 'member_type' => 9,
  762. 'etag' => '',
  763. 'start_time' => '',
  764. 'end_time' => '',
  765. );
  766. }
  767. else if(!empty($rows['valid_time']) && $rows['valid_time'] < $this->now_str) // D. 月租車, 已無效 (審核未通過)
  768. {
  769. trigger_error("已無效!! " . print_r($rows, true));
  770. $rows = array
  771. (
  772. 'lpr_correct' => '',
  773. 'member_no' => 0,
  774. 'member_name' => '',
  775. 'member_type' => 9,
  776. 'etag' => '',
  777. 'start_time' => '',
  778. 'end_time' => '',
  779. );
  780. }
  781. trigger_error('讀取會員:' . print_r($rows, true) . ", park_time_check: {$park_time_check}");
  782. /*
  783. // 20171025 強制先不導入會員
  784. $rows = array
  785. (
  786. 'lpr_correct' => '',
  787. 'member_no' => 0,
  788. 'member_name' => '',
  789. 'member_type' => 9,
  790. 'etag' => '',
  791. 'start_time' => '',
  792. 'end_time' => '',
  793. );
  794. trigger_error(__FUNCTION__ . '..force not found..');
  795. */
  796. return $rows;
  797. }
  798. /*
  799. // 開門 (月租)
  800. public function member_opendoors($parms)
  801. {
  802. $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}");
  803. return true;
  804. }
  805. // 開門 (臨停)
  806. public function temp_opendoors($parms)
  807. {
  808. $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}");
  809. return true;
  810. }
  811. */
  812. // 用eTag讀出車號
  813. public function etag2lpr_2($etag)
  814. {
  815. // 用讀取eTag記錄(有double驗證過)
  816. $rows = $this->db->select('lpr')
  817. ->from('etag_lpr')
  818. ->where(array('etag' => $etag, 'confirms >' => 0))
  819. ->limit(1)
  820. ->get()
  821. ->row_array();
  822. // 讀出eTag資料
  823. if (!empty($rows['lpr']))
  824. {
  825. trigger_error("+++車牌NONE,以eTag讀入車牌:{$etag}|{$rows['lpr']}");
  826. return $rows['lpr'];
  827. }
  828. return 'NONE';
  829. }
  830. // 有車牌與eTag, 檢查資料庫 (2017/03/22 new)
  831. public function check_lpr_etag($lpr, $etag)
  832. {
  833. $ETAG_LOG_TITLE = 'etag://';
  834. $ETAG_WARMIN_TITLE = 'etag-warning://';
  835. trigger_error($ETAG_LOG_TITLE. "輸入: {$lpr},{$etag}");
  836. // 手動值上下限
  837. $max_admin_confirms_value = 99;
  838. $min_admin_confirms_value = 50;
  839. // 自動值上下限
  840. $max_system_confirms_value = 33;
  841. $min_system_confirms_value = 0;
  842. // 判斷對應加權
  843. $etag_confirms_bias_plus = 11; // etag 找 車牌, 對上一次可扺 11次
  844. $etag_confirms_bias_minus = -1;
  845. $lpr_confirms_bias_plus = 3; // 車牌 找 etag, 對上一次可扺 3次
  846. $lpr_confirms_bias_minus = -1;
  847. // eTag 找 車牌
  848. $lpr_info_from_etag = $this->db->select('lpr, confirms')
  849. ->from('etag_lpr')
  850. ->where(array('etag' => $etag))
  851. ->limit(1)
  852. ->get()
  853. ->row_array();
  854. if (!empty($lpr_info_from_etag['lpr']))
  855. {
  856. // B. etag 有找到 車牌
  857. if ($lpr_info_from_etag['lpr'] == $lpr)
  858. {
  859. // B.1. etag 有找到 車牌, 且 車牌 相符, confirms 上升
  860. $confirms_bias = $etag_confirms_bias_plus;
  861. }
  862. else
  863. {
  864. // B.2. etag 有找到 車牌, 但 車牌 不符, confirms 下降
  865. $confirms_bias = $etag_confirms_bias_minus;
  866. trigger_error($ETAG_WARMIN_TITLE . "etag 找 lpr | lpr error : {$lpr},{$etag} | query:" . print_r($lpr_info_from_etag, true));
  867. }
  868. $next_confirms_value = $lpr_info_from_etag['confirms'] + $confirms_bias;
  869. trigger_error($ETAG_LOG_TITLE . "etag 找 lpr | {$lpr},{$etag}, next_confirms: {$next_confirms_value}, bias:{$confirms_bias}");
  870. // 更新 confirms 資訊
  871. if($next_confirms_value > $max_admin_confirms_value)
  872. {
  873. // B.3.0 confirms 超過 max_admin_confirms_value, skip
  874. //trigger_error($ETAG_LOG_TITLE . "etag 找 lpr | {$lpr},{$etag} next_confirms_value > max_admin_confirms_value : {$max_admin_confirms_value}");
  875. }
  876. else if ($next_confirms_value >= $min_admin_confirms_value)
  877. {
  878. // B.3.1 人工確認過的記錄, 誤判多次後會停留在 min_admin_confirms_value, 或加到 max_admin_confirms_value
  879. $this->db->where('etag', $etag)->update('etag_lpr', array('confirms' => $next_confirms_value));
  880. }
  881. else if ($next_confirms_value > $max_system_confirms_value)
  882. {
  883. // B.3.2 confirms 超過 max_system_confirms_value, skip
  884. //trigger_error($ETAG_LOG_TITLE . "etag 找 lpr | {$lpr},{$etag} next_confirms_value > max_system_confirms_value : {$max_system_confirms_value}");
  885. }
  886. else if ($next_confirms_value <= $max_system_confirms_value && $next_confirms_value >= $min_system_confirms_value)
  887. {
  888. // B.3.3 confirms 不到 max_system_confirms_value 為系統生成記錄, 誤判多次後 confirms 會扣到 min_system_confirms_value
  889. $this->db->where('etag', $etag)->update('etag_lpr', array('confirms' => $next_confirms_value));
  890. }
  891. else
  892. {
  893. // B.3.4 若低於 min_system_confirms_value,刪除
  894. $this->db->delete('etag_lpr', array('etag' => $etag));
  895. trigger_error($ETAG_LOG_TITLE . "etag 找 lpr | etag confirms fail and removed : {$lpr_info_from_etag['lpr']}, {$etag}");
  896. trigger_error($ETAG_WARMIN_TITLE . "etag 找 lpr | etag confirms fail and removed : {$lpr_info_from_etag['lpr']}, {$etag}");
  897. }
  898. }
  899. else
  900. {
  901. // 車牌 找 etag
  902. $etag_info_form_lpr = $this->db->select('etag, confirms, member_no')
  903. ->from('etag_lpr')
  904. ->where(array('lpr' => $lpr))
  905. ->limit(1)
  906. ->get()
  907. ->row_array();
  908. if (!empty($etag_info_form_lpr['etag']))
  909. {
  910. // A. 車牌 有找到 etag
  911. if ($etag_info_form_lpr['etag'] == $etag)
  912. {
  913. // A.1. 車牌 有找到 etag, 且 etag 相符, confirms 上升
  914. $confirms_bias = $lpr_confirms_bias_plus;
  915. // 若尚未登記為會員
  916. if(empty($etag_info_form_lpr['member_no']))
  917. {
  918. // 檢查是否會員
  919. $member_info_from_lpr = $this->db->select('member_no, member_name')
  920. ->from('members')
  921. ->where(array('lpr' => $lpr))
  922. ->limit(1)
  923. ->get()
  924. ->row_array();
  925. // 確認為會員, 建立 eTag 資訊
  926. if (!empty($member_info_from_lpr['member_no']))
  927. {
  928. $data['member_no'] = $member_info_from_lpr['member_no'];
  929. $data['member_name'] = $member_info_from_lpr['member_name'];
  930. $this->db->where('member_no', $member_info_from_lpr['member_no'])->update('member_car', array('etag' => $etag));
  931. $this->db->where('member_no', $member_info_from_lpr['member_no'])->update('members', array('etag' => $etag));
  932. // 更新 etag_lpr
  933. $this->db->where('etag', $etag)->update('etag_lpr', $data);
  934. }
  935. }
  936. }
  937. else
  938. {
  939. // A.2. 車牌 有找到 etag, 但 etag 不符, confirms 下降
  940. $confirms_bias = $lpr_confirms_bias_minus;
  941. trigger_error($ETAG_WARMIN_TITLE . "lpr 找 etag | etag error : {$lpr},{$etag} | query:" . print_r($etag_info_form_lpr, true));
  942. }
  943. $next_confirms_value = $lpr_info_from_etag['confirms'] + $confirms_bias;
  944. trigger_error($ETAG_LOG_TITLE . "lpr 找 etag | {$lpr},{$etag}, next_confirms: {$next_confirms_value}, bias:{$confirms_bias}");
  945. // 更新 confirms 資訊
  946. if($next_confirms_value > $max_admin_confirms_value)
  947. {
  948. // A.3.0 confirms 超過 max_admin_confirms_value, skip
  949. //trigger_error($ETAG_LOG_TITLE . "lpr 找 etag | {$lpr},{$etag} next_confirms_value > max_admin_confirms_value : {$max_admin_confirms_value}");
  950. }
  951. else if ($next_confirms_value >= $min_admin_confirms_value)
  952. {
  953. // A.3.1 人工確認過的記錄, 誤判多次後會停留在 min_admin_confirms_value, 或加到 max_admin_confirms_value
  954. $this->db->where('lpr', $lpr)->update('etag_lpr', array('confirms' => $next_confirms_value));
  955. }
  956. else if ($next_confirms_value > $max_system_confirms_value)
  957. {
  958. // A.3.2 confirms 超過 max_system_confirms_value, skip
  959. //trigger_error($ETAG_LOG_TITLE . "lpr 找 etag | {$lpr},{$etag} next_confirms_value > max_system_confirms_value : {$max_system_confirms_value}");
  960. }
  961. else if ($next_confirms_value <= $max_system_confirms_value && $next_confirms_value >= $min_system_confirms_value)
  962. {
  963. // A.3.3 confirms 不到 max_system_confirms_value 為系統生成記錄, 誤判多次後 confirms 會扣到 min_system_confirms_value
  964. $this->db->where('lpr', $lpr)->update('etag_lpr', array('confirms' => $next_confirms_value));
  965. }
  966. else
  967. {
  968. // A.3.4 若低於 min_system_confirms_value,刪除
  969. $this->db->delete('etag_lpr', array('lpr' => $lpr));
  970. trigger_error($ETAG_LOG_TITLE . "lpr 找 etag | lpr confirms fail and removed : {$lpr}, {$etag_info_form_lpr['etag']}");
  971. trigger_error($ETAG_WARMIN_TITLE . "lpr 找 etag | lpr confirms fail and removed : {$lpr}, {$etag_info_form_lpr['etag']}");
  972. }
  973. }
  974. else
  975. {
  976. // C. 車牌 與 etag 都找不到記錄
  977. $data = array
  978. (
  979. 'lpr' => $lpr,
  980. 'lpr_correct' => $lpr,
  981. 'etag' => $etag
  982. );
  983. // 檢查是否會員
  984. $member_info_from_lpr = $this->db->select('member_no, member_name')
  985. ->from('members')
  986. ->where(array('lpr' => $lpr))
  987. ->limit(1)
  988. ->get()
  989. ->row_array();
  990. // 會員者, 將eTag update回去
  991. if (!empty($member_info_from_lpr['member_no']))
  992. {
  993. $data['member_no'] = $member_info_from_lpr['member_no'];
  994. $data['member_name'] = $member_info_from_lpr['member_name'];
  995. $this->db->where('member_no', $member_info_from_lpr['member_no'])->update('member_car', array('etag' => $etag));
  996. $this->db->where('member_no', $member_info_from_lpr['member_no'])->update('members', array('etag' => $etag));
  997. }
  998. // 建立第一筆記錄
  999. $this->db->insert('etag_lpr', $data);
  1000. $etag_lpr_seqno = $this->db->insert_id();
  1001. trigger_error($ETAG_LOG_TITLE . "create | insert seqno = {$etag_lpr_seqno}". print_r($data, true));
  1002. }
  1003. }
  1004. }
  1005. /*
  1006. // 有車牌與eTag, 檢查資料庫
  1007. public function check_lpr_etag($lpr, $etag)
  1008. {
  1009. // 用讀取eTag記錄(有double驗證過)
  1010. $rows = $this->db->select('etag, confirms')
  1011. ->from('etag_lpr')
  1012. ->where(array('lpr' => $lpr))
  1013. ->limit(1)
  1014. ->get()
  1015. ->row_array();
  1016. // 讀出eTag資料
  1017. if (!empty($rows['etag']))
  1018. {
  1019. // 車牌與eTag皆相符, 檢查是否confirms欄位若為0, 設成1(double驗證)
  1020. if ($rows['etag'] == $etag)
  1021. {
  1022. if ($rows['confirms'] == 0) $this->db->where('lpr', $lpr)->update('etag_lpr', array('confirms' => 1));
  1023. }
  1024. else // eTag不相符
  1025. {
  1026. if ($rows['confirms'] == 1)
  1027. {
  1028. $this->db->where('lpr', $lpr)->update('etag_lpr', array('confirms' => 0));
  1029. }
  1030. else // 原confirms為0者, 刪除之
  1031. {
  1032. $this->db->delete('etag_lpr', array('lpr' => $lpr));
  1033. }
  1034. }
  1035. }
  1036. else // 無資料, 新增一筆
  1037. {
  1038. // 再檢查一次是否有eTag ?
  1039. $rows_etag = $this->db->select('lpr, confirms')
  1040. ->from('etag_lpr')
  1041. ->where(array('etag' => $etag))
  1042. ->limit(1)
  1043. ->get()
  1044. ->row_array();
  1045. if (empty($rows_etag['lpr'])) // 無資料
  1046. {
  1047. $data = array
  1048. (
  1049. 'lpr' => $lpr,
  1050. 'lpr_correct' => $lpr,
  1051. 'etag' => $etag
  1052. );
  1053. // 檢查是否會員
  1054. $rows_members = $this->db->select('member_no, member_name')
  1055. ->from('members')
  1056. ->where(array('lpr' => $lpr))
  1057. ->limit(1)
  1058. ->get()
  1059. ->row_array();
  1060. // 會員者, 將eTag update回去
  1061. if (!empty($rows_members['member_no']))
  1062. {
  1063. $data['member_no'] = $rows_members['member_no'];
  1064. $data['member_name'] = $rows_members['member_name'];
  1065. $this->db->where('member_no', $rows_members['member_no'])->update('member_car', array('etag' => $etag));
  1066. $this->db->where('member_no', $rows_members['member_no'])->update('members', array('etag' => $etag));
  1067. }
  1068. $this->db->insert('etag_lpr', $data);
  1069. }
  1070. else
  1071. {
  1072. if ($rows_etag['confirms'] == 1)
  1073. {
  1074. $this->db->where('etag', $etag)->update('etag_lpr', array('confirms' => 0));
  1075. }
  1076. else // 原confirms為0者, 刪除之
  1077. {
  1078. $this->db->delete('etag_lpr', array('etag' => $etag));
  1079. }
  1080. }
  1081. }
  1082. }
  1083. */
  1084. // 送出至message queue(目前用mqtt)
  1085. public function mq_send($topic, $msg)
  1086. {
  1087. $this->vars['mqtt']->publish($topic, $msg, 0);
  1088. trigger_error("mqtt:{$topic}|{$msg}");
  1089. usleep(100000); // delay 0.1 sec (避免漏訊號)
  1090. }
  1091. // 產生 CK
  1092. public function gen_opendoor_ck($parms, $function_name)
  1093. {
  1094. return md5($parms['ivsno']. 'alt' . date('dmh') . 'o' . $parms['lpr'] . 'b' . $function_name);
  1095. }
  1096. // 開門 (月租)
  1097. public function member_opendoors($parms)
  1098. {
  1099. //$this->mq_send_opendoor(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}");
  1100. $ck = $this->gen_opendoor_ck($parms, __FUNCTION__);
  1101. get_headers("http://localhost/cars.html/" . __FUNCTION__ . "/{$parms['ivsno']}/{$parms['lpr']}/{$ck}");
  1102. return true;
  1103. }
  1104. // 開門 (臨停)
  1105. public function temp_opendoors($parms)
  1106. {
  1107. //$this->mq_send_opendoor(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}");
  1108. $ck = $this->gen_opendoor_ck($parms, __FUNCTION__);
  1109. get_headers("http://localhost/cars.html/" . __FUNCTION__ ."/{$parms['ivsno']}/{$parms['lpr']}/{$ck}");
  1110. return true;
  1111. }
  1112. // 開門 (月租)
  1113. public function do_member_opendoor($parms)
  1114. {
  1115. if($parms['ck'] != $this->gen_opendoor_ck($parms, 'member_opendoors'))
  1116. {
  1117. return 'ck_error'; // 中斷
  1118. }
  1119. $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}");
  1120. return 'ok';
  1121. }
  1122. // 開門 (臨停)
  1123. public function do_temp_opendoor($parms)
  1124. {
  1125. if($parms['ck'] != $this->gen_opendoor_ck($parms, 'temp_opendoors'))
  1126. {
  1127. return 'ck_error'; // 中斷
  1128. }
  1129. $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}");
  1130. return 'ok';
  1131. }
  1132. // 指派車位
  1133. // http://203.75.167.89/parkingquery.html/get_valid_seat
  1134. // 註記現在時間, 並保留10分鐘
  1135. public function get_valid_seat()
  1136. {
  1137. $data = array();
  1138. //$data['result']['location_no'] = '0';
  1139. //$data['result_code'] = 'FAIL';
  1140. //return $data;
  1141. // 撈 roger db
  1142. /*
  1143. $sql = "
  1144. SELECT ParkingNum AS pksno FROM table_carpark
  1145. WHERE LPR = '' AND DisableSeat = 0 AND
  1146. (SELECT COUNT(*) FROM table_carpark WHERE LPR = '' AND DisableSeat = 0) <= 10
  1147. ORDER BY RAND() LIMIT 1 FOR UPDATE;
  1148. ";
  1149. $dsn_old_db = $this->load->database('old_db', true);
  1150. // 2016/12/14 roger_db 掛了的可能
  1151. if ($dsn_old_db->initialize())
  1152. {
  1153. $retults = $dsn_old_db->query($sql)->result_array();
  1154. }
  1155. if(!empty($retults[0]))
  1156. {
  1157. $data['result']['location_no'] = substr($retults[0]['pksno'], 1);
  1158. $data['result_code'] = 'OK';
  1159. $data['loc_name'] = 'B'.substr($retults[0]['pksno'], 0, 1);
  1160. $data['floors'] = 'B'.substr($retults[0]['pksno'], 0, 1);
  1161. }
  1162. else
  1163. {
  1164. $data['result']['location_no'] = '0';
  1165. $data['result_code'] = 'FAIL';
  1166. }
  1167. */
  1168. $this->db->trans_start();
  1169. $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;";
  1170. $rows = $this->db->query($sql)->row_array();
  1171. if (!empty($rows['pksno']))
  1172. {
  1173. $data['result']['location_no'] = substr($rows['pksno'], -3);
  1174. $data['result_code'] = 'OK';
  1175. $sql = "update pks set book_time = addtime(now(), '00:10:00') where pksno = {$rows['pksno']};";
  1176. $this->db->query($sql);
  1177. $sql = "select g.group_name, g.floors from pks_groups g, pks_group_member m where m.pksno = {$rows['pksno']} and g.group_id = m.group_id and g.group_type = 1 limit 1";
  1178. $rows = $this->db->query($sql)->row_array();
  1179. $data['loc_name'] = $rows['group_name'];
  1180. $data['floors'] = $rows['floors'];
  1181. }
  1182. else
  1183. {
  1184. $data['result']['location_no'] = '0';
  1185. $data['result_code'] = 'FAIL';
  1186. }
  1187. $this->db->trans_complete();
  1188. return $data;
  1189. }
  1190. // 取得出入口 888 資訊
  1191. public function get_888_info($parms)
  1192. {
  1193. $data = array();
  1194. $sql = "select availables as availables, tot as tot from pks_groups where group_id = 'C888' and station_no = {$parms['sno']}";
  1195. $rows = $this->db->query($sql)->row_array();
  1196. if (!empty($rows) && array_key_exists('availables', $rows))
  1197. {
  1198. $data['result_code'] = 'OK';
  1199. $data['availables'] = $rows['availables'];
  1200. $data['tot'] = $rows['tot'];
  1201. }
  1202. else
  1203. {
  1204. trigger_error(__FUNCTION__ . "..not found..".print_r($parms, true));
  1205. $data['result_code'] = 'FAIL';
  1206. $data['availables'] = 9999; // 如果拿不到就忽略這個流程
  1207. $data['tot'] = 0;
  1208. }
  1209. return $data;
  1210. }
  1211. // ===============================================
  1212. // acer cmd
  1213. // ===============================================
  1214. // 產生通行碼
  1215. function gen_pass_code()
  1216. {
  1217. return rand(100000,999999);
  1218. }
  1219. // 呼叫acer
  1220. function call_acer($cmd, $parms)
  1221. {
  1222. return false; // 尚未啟用
  1223. try{
  1224. $ch = curl_init();
  1225. curl_setopt($ch, CURLOPT_URL, 'http://localhost/acer_service.html/cmd_'. $cmd);
  1226. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  1227. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  1228. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1229. curl_setopt($ch, CURLOPT_POST, TRUE);
  1230. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,3);
  1231. curl_setopt($ch, CURLOPT_TIMEOUT, 3); //timeout in seconds
  1232. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parms));
  1233. $data = curl_exec($ch);
  1234. if(curl_errno($ch))
  1235. {
  1236. trigger_error(__FUNCTION__ . ', curl error: '. curl_error($ch));
  1237. }
  1238. curl_close($ch);
  1239. trigger_error(__FUNCTION__ . '..'. $data);
  1240. }catch (Exception $e){
  1241. trigger_error(__FUNCTION__ . 'error:'.$e->getMessage());
  1242. }
  1243. }
  1244. // ===============================================
  1245. // mitac cmd
  1246. // ===============================================
  1247. // 檢查指定時間是否介於停車時段區間
  1248. function check_park_time($park_time, $target_time)
  1249. {
  1250. $pt_arr = $this->vars['mcache']->get('pt');
  1251. $now_time = substr($target_time, 11); // 日期字串只取最後時間字串(13:25:32)
  1252. $week_no = date('w',strtotime($target_time)); // 取星期幾
  1253. $park_time_array = explode(',', $park_time); // 用 , 格開
  1254. foreach($park_time_array as $idx => $park_time_value)
  1255. {
  1256. foreach($pt_arr[$park_time_value]['timex'] as $idx => $pt_rows)
  1257. {
  1258. if ($week_no >= $pt_rows['w_start'] &&
  1259. $week_no <= $pt_rows['w_end'] &&
  1260. $now_time >= $pt_rows['time_start'] &&
  1261. $now_time <= $pt_rows['time_end'])
  1262. {
  1263. return true;
  1264. }
  1265. }
  1266. }
  1267. return false;
  1268. }
  1269. // 取得會員時段區間起點
  1270. function gen_park_time_first($park_time, $target_time)
  1271. {
  1272. $pt_arr = $this->vars['mcache']->get('pt');
  1273. $now_time = substr($target_time, 11); // 日期字串只取最後時間字串(13:25:32)
  1274. $week_no = date('w',strtotime($target_time)); // 取星期幾
  1275. $park_time_array = explode(',', $park_time); // 用 , 格開
  1276. $week_no_first = 0;
  1277. $time_end_first = '';
  1278. foreach($park_time_array as $idx => $park_time_value)
  1279. {
  1280. foreach($pt_arr[$park_time_value]['timex'] as $idx => $pt_rows)
  1281. {
  1282. if ($week_no >= $pt_rows['w_start'] &&
  1283. $week_no <= $pt_rows['w_end'] &&
  1284. $now_time >= $pt_rows['time_start'] &&
  1285. $now_time <= $pt_rows['time_end'])
  1286. {
  1287. $week_no_first = $pt_rows['w_start'];
  1288. $time_end_first = $pt_rows['time_start'];
  1289. trigger_error(__FUNCTION__ . "|$park_time, $target_time | $week_no_first, $time_end_first");
  1290. break;
  1291. }
  1292. }
  1293. }
  1294. $day_offset = $week_no - $week_no_first;
  1295. if($day_offset < 0)
  1296. {
  1297. trigger_error(__FUNCTION__ . '..error..offset..' . $day_offset);
  1298. $day_offset = 0;
  1299. }
  1300. return date('Y-m-d', strtotime("-$day_offset day", strtotime($target_time))). " $time_end_first";
  1301. }
  1302. // 取得會員時段區間終點
  1303. function gen_park_time_last($park_time, $target_time)
  1304. {
  1305. $pt_arr = $this->vars['mcache']->get('pt');
  1306. $now_time = substr($target_time, 11); // 日期字串只取最後時間字串(13:25:32)
  1307. $week_no = date('w',strtotime($target_time)); // 取星期幾
  1308. $park_time_array = explode(',', $park_time); // 用 , 格開
  1309. $week_no_last = 0;
  1310. $time_end_last = '';
  1311. foreach($park_time_array as $idx => $park_time_value)
  1312. {
  1313. foreach($pt_arr[$park_time_value]['timex'] as $idx => $pt_rows)
  1314. {
  1315. if ($week_no >= $pt_rows['w_start'] &&
  1316. $week_no <= $pt_rows['w_end'] &&
  1317. $now_time >= $pt_rows['time_start'] &&
  1318. $now_time <= $pt_rows['time_end'])
  1319. {
  1320. $week_no_last = $pt_rows['w_end'];
  1321. $time_end_last = $pt_rows['time_end'];
  1322. trigger_error(__FUNCTION__ . "|$park_time, $target_time | $week_no_last, $time_end_last");
  1323. break;
  1324. }
  1325. }
  1326. }
  1327. $day_offset = $week_no_last - $week_no;
  1328. if($day_offset < 0)
  1329. {
  1330. trigger_error(__FUNCTION__ . '..error..offset..' . $day_offset);
  1331. $day_offset = 0;
  1332. }
  1333. return date('Y-m-d', strtotime("+$day_offset day", strtotime($target_time))). " $time_end_last";
  1334. }
  1335. // 取得會員身份減免後的費用起算時間
  1336. function check_member_state($lpr, $in_time, $out_time)
  1337. {
  1338. // 檢查月租身份修正
  1339. $member_info = $this->get_member($lpr, false);
  1340. if ($member_info['member_no'] == 0)
  1341. {
  1342. // 查無會員身份
  1343. $member_state = 0;
  1344. $new_in_time = $in_time;
  1345. $new_out_time = $out_time;
  1346. }
  1347. else
  1348. {
  1349. $park_time = $member_info['park_time'];
  1350. $pt_arr = $this->vars['mcache']->get('pt');
  1351. if(empty($pt_arr) || empty($park_time))
  1352. {
  1353. // ERROR: 無法驗証時段, 跳過時段限制判斷
  1354. $member_state = 1;
  1355. $new_in_time = $in_time;
  1356. $new_out_time = $out_time;
  1357. }
  1358. else
  1359. {
  1360. $in_time_in_park_time = $this->check_park_time($park_time, $in_time);
  1361. $out_time_in_park_time = $this->check_park_time($park_time, $out_time);
  1362. trigger_error(__FUNCTION__ . "|$lpr, $in_time, $out_time|..check_park_time: {$in_time_in_park_time}, {$out_time_in_park_time}..");
  1363. if($in_time_in_park_time && $out_time_in_park_time)
  1364. {
  1365. // 進出時間都在會員區間內: 費用起算時間改為出場時間
  1366. $member_state = 2;
  1367. $new_in_time = $out_time;
  1368. $new_out_time = $out_time;
  1369. }
  1370. else if($in_time_in_park_time)
  1371. {
  1372. // 入場時間在會員區間內: 費用起算時間改為, 會員時段區間終點
  1373. $member_state = 3;
  1374. $new_in_time = $this->gen_park_time_last($park_time, $in_time);
  1375. $new_out_time = $out_time;
  1376. if(strtotime($new_in_time) > strtotime($out_time))
  1377. {
  1378. trigger_error(__FUNCTION__ . "|$lpr, $in_time, $out_time|new_in_time error >> out_time..");
  1379. $new_in_time = $out_time;
  1380. }
  1381. }
  1382. else if($out_time_in_park_time)
  1383. {
  1384. // 出場時間在會員區間內: 費用起算時間改為, 會員時段區間起點
  1385. $member_state = 4;
  1386. $new_in_time = $in_time;
  1387. $new_out_time = $this->gen_park_time_first($park_time, $out_time);
  1388. if(strtotime($in_time) > strtotime($new_out_time))
  1389. {
  1390. trigger_error(__FUNCTION__ . "|$lpr, $in_time, $out_time|new_in_time error >> out_time..");
  1391. $new_out_time = $out_time;
  1392. }
  1393. }
  1394. }
  1395. }
  1396. $member_result = array('state' => $member_state, 'in_time' => $new_in_time, 'out_time' => $new_out_time);
  1397. trigger_error(__FUNCTION__ . "|$lpr, $in_time, $out_time|..". print_r($member_result, true));
  1398. return $member_result;
  1399. }
  1400. // 要求 mitac 扣款
  1401. function call_mitac_pay($lpr, $ivsno, $rows_cario)
  1402. {
  1403. $function_name = 'parking_fee_altob';
  1404. $seqno = $rows_cario['cario_no'];
  1405. $in_time = $rows_cario['out_before_time'];
  1406. $out_time = $this->now_str;
  1407. $gate_id = 1; // 20171124 改為強制 1//$ivsno;
  1408. // 確認會員身份
  1409. $member_result = $this->check_member_state($lpr, $in_time, $out_time);
  1410. switch($member_result['state'])
  1411. {
  1412. case 0:
  1413. trigger_error(__FUNCTION__ . '|非會員|');
  1414. break;
  1415. case 1:
  1416. trigger_error(__FUNCTION__ . '|無法驗証時段|skip MITAC|'. print_r($member_result, true));
  1417. return false; // 跳過 mitac
  1418. break;
  1419. case 2:
  1420. trigger_error(__FUNCTION__ . '|進出時間都在會員區間內|skip MITAC|'. print_r($member_result, true));
  1421. return false; // 跳過 mitac
  1422. break;
  1423. case 3:
  1424. trigger_error(__FUNCTION__ . '|入場時間在會員區間內|'. print_r($member_result, true));
  1425. $in_time = $member_result['in_time'];
  1426. break;
  1427. case 4:
  1428. trigger_error(__FUNCTION__ . '|出場時間在會員區間內|'. print_r($member_result, true));
  1429. $out_time = $member_result['out_time'];
  1430. break;
  1431. default:
  1432. trigger_error(__FUNCTION__ . '|未定義|'. print_r($member_result, true));
  1433. break;
  1434. }
  1435. // 通訊內容
  1436. $parms = array(
  1437. 'seqno' => $seqno,
  1438. 'lpr' => $lpr,
  1439. 'in_time' => $in_time,
  1440. 'out_time' => $out_time,
  1441. 'gate_id' => $gate_id);
  1442. // 超過一天就擋掉
  1443. if(strtotime($parms['out_time']) - strtotime($parms['in_time']) > 86400)
  1444. {
  1445. trigger_error(__FUNCTION__ . '|超過計費時限|skip MITAC|'. print_r($parms, true));
  1446. return false; // 跳過 mitac
  1447. }
  1448. // 驗証碼
  1449. $parms['ck'] = md5($parms['seqno']. 'a' . date('dmh') . 'l' . $parms['lpr'] . 't'. $parms['in_time']. 'o'. $parms['out_time'] . 'b'. $parms['gate_id'] . $function_name);
  1450. // 呼叫
  1451. try{
  1452. $ch = curl_init();
  1453. curl_setopt($ch, CURLOPT_URL, "http://localhost/mitac_service.html/{$function_name}");
  1454. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  1455. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  1456. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1457. curl_setopt($ch, CURLOPT_POST, TRUE);
  1458. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,3);
  1459. curl_setopt($ch, CURLOPT_TIMEOUT, 3); //timeout in seconds
  1460. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parms));
  1461. $data = curl_exec($ch);
  1462. if(curl_errno($ch))
  1463. {
  1464. trigger_error(__FUNCTION__ . ', curl error: '. curl_error($ch));
  1465. }
  1466. curl_close($ch);
  1467. trigger_error(__FUNCTION__ . '..'. $data);
  1468. }catch (Exception $e){
  1469. trigger_error(__FUNCTION__ . 'error:'.$e->getMessage());
  1470. }
  1471. }
  1472. }