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ů.

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 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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. <?php
  2. /*
  3. file: carpark.php 停車管理
  4. */
  5. class Carpark extends CC_Controller
  6. {
  7. function __construct()
  8. {
  9. parent::__construct('carpark');
  10. // load library
  11. $this->load->library(array('form_validation','session'));
  12. // load helpers
  13. $this->load->helper(array('form'));
  14. // ajax code
  15. define('RESULT_SUCCESS', 'ok');
  16. define('RESULT_FORM_VALIDATION_FAIL', '-1');
  17. define('RESULE_FAIL', 'gg');
  18. }
  19. // ------------------------------------------------
  20. //
  21. // 報表
  22. //
  23. // ------------------------------------------------
  24. // 進出記錄表 (VIP)
  25. public function export_vip_cario_report()
  26. {
  27. // 次月算上月
  28. $last_day_of_previous_month = date("Y-n-j", strtotime("last day of previous month"));
  29. $d = date_parse_from_format("Y-m-d", $last_day_of_previous_month);
  30. $station_name = empty($this->input->post('station_name', true)) ? '場站名稱' : $this->input->post('station_name', true);
  31. $year = empty($this->input->post('year', true)) ? $d['year'] : $this->input->post('year', true);
  32. $month = empty($this->input->post('month', true)) ? $d['month'] : $this->input->post('month', true);
  33. $addr = empty($this->input->post('addr', true)) ? '地址' : $this->input->post('addr', true);
  34. $phone_no = empty($this->input->post('phone_no', true)) ? '電話' : $this->input->post('phone_no', true);
  35. $result = $this->app_model('excel')->export_cario_report($station_name . '(VIP)', $year, $month, $addr, $phone_no, 250);
  36. if(empty($result))
  37. {
  38. echo '無記錄';
  39. exit;
  40. }
  41. }
  42. // 進出記錄表
  43. public function export_cario_report()
  44. {
  45. // 次月算上月
  46. $last_day_of_previous_month = date("Y-n-j", strtotime("last day of previous month"));
  47. $d = date_parse_from_format("Y-m-d", $last_day_of_previous_month);
  48. $station_name = empty($this->input->post('station_name', true)) ? '場站名稱' : $this->input->post('station_name', true);
  49. $year = empty($this->input->post('year', true)) ? $d['year'] : $this->input->post('year', true);
  50. $month = empty($this->input->post('month', true)) ? $d['month'] : $this->input->post('month', true);
  51. $addr = empty($this->input->post('addr', true)) ? '地址' : $this->input->post('addr', true);
  52. $phone_no = empty($this->input->post('phone_no', true)) ? '電話' : $this->input->post('phone_no', true);
  53. $result = $this->app_model('excel')->export_cario_report($station_name, $year, $month, $addr, $phone_no);
  54. if(empty($result))
  55. {
  56. echo '無記錄';
  57. exit;
  58. }
  59. }
  60. // 進出記錄表 (分時統計)
  61. public function export_cario_summery()
  62. {
  63. // 次月算上月
  64. $last_day_of_previous_month = date("Y-n-j", strtotime("last day of previous month"));
  65. $d = date_parse_from_format("Y-m-d", $last_day_of_previous_month);
  66. $station_name = empty($this->input->post('station_name', true)) ? '場站名稱' : $this->input->post('station_name', true);
  67. $year = empty($this->input->post('year', true)) ? $d['year'] : $this->input->post('year', true);
  68. $month = empty($this->input->post('month', true)) ? $d['month'] : $this->input->post('month', true);
  69. $addr = empty($this->input->post('addr', true)) ? '地址' : $this->input->post('addr', true);
  70. $phone_no = empty($this->input->post('phone_no', true)) ? '電話' : $this->input->post('phone_no', true);
  71. $result = $this->app_model('excel')->export_cario_summery($station_name, $year, $month, $addr, $phone_no);
  72. if(empty($result))
  73. {
  74. echo '無記錄';
  75. exit;
  76. }
  77. }
  78. // ------------------------------------------------
  79. //
  80. // 博辰 (START)
  81. //
  82. // ------------------------------------------------
  83. // 同步 博辰 888
  84. function sync_parktron_888()
  85. {
  86. try{
  87. $ch = curl_init();
  88. curl_setopt($ch, CURLOPT_URL, 'http://192.168.10.80:5477/parktron/ipms/services/areaCount/findAll');
  89. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  90. curl_setopt($ch, CURLOPT_POST, TRUE);
  91. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,5);
  92. curl_setopt($ch, CURLOPT_TIMEOUT, 5); //timeout in seconds
  93. curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
  94. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  95. $result = curl_exec($ch);
  96. $parktron_result = json_decode($result);
  97. trigger_error(PARKTRON_LOG_TITLE . '..' . __FUNCTION__ . '..' . print_r($parktron_result, true));
  98. $this->data_model()->sync_parktron_888($parktron_result);
  99. if(curl_errno($ch))
  100. {
  101. trigger_error(PARKTRON_LOG_TITLE . '..' . __FUNCTION__ . '..' . ', curl error: '. curl_error($ch));
  102. }
  103. curl_close($ch);
  104. }catch (Exception $e){
  105. trigger_error(PARKTRON_LOG_TITLE . '..' . __FUNCTION__ . '..' . 'error:'.$e->getMessage());
  106. }
  107. }
  108. // ------------------------------------------------
  109. //
  110. // CRM (START)
  111. //
  112. // ------------------------------------------------
  113. // [test] zzz
  114. public function gen_test_case()
  115. {
  116. $sno = '12302';
  117. $ivsno = 0;
  118. $io = 'CI';
  119. $lpr = 'TEST1109A';
  120. $ts = date('YmdHis');
  121. $parms = array();
  122. $parms['sno'] = $sno;
  123. $parms['ivsno'] = $ivsno;
  124. $parms['io'] = $io;
  125. $parms['lpr'] = $lpr;
  126. $parms['ts'] = $ts;
  127. $function_name = 'remote_lprio';
  128. $ck = $this->gen_cms_ck($parms, $function_name);
  129. echo "http://localhost/carpark.html/{$function_name}/sno/{$sno}/ivsno/{$ivsno}/io/{$io}/type/C/lpr/{$lpr}/color/NONE/sq/0/ts/{$ts}/sq2/0/etag/NONE/ant/1/ck/{$ck}";
  130. echo "\n\n";
  131. $function_name = 'remote_opendoor_lprio';
  132. $ck = $this->gen_cms_ck($parms, $function_name);
  133. echo "http://localhost/carpark.html/{$function_name}/sno/{$sno}/ivsno/{$ivsno}/io/{$io}/type/C/lpr/{$lpr}/color/NONE/sq/0/ts/{$ts}/sq2/0/etag/NONE/ant/1/ck/{$ck}";
  134. echo "\n\n";
  135. $function_name = 'remote_opendoor_anyway';
  136. $ck = $this->gen_cms_ck($parms, $function_name);
  137. echo "http://localhost/carpark.html/{$function_name}/sno/{$sno}/ivsno/{$ivsno}/io/{$io}/lpr/{$lpr}/ts/{$ts}/ck/{$ck}";
  138. echo "\n\n";
  139. exit;
  140. }
  141. // 產生 CK
  142. function gen_cms_ck($parms, $function_name)
  143. {
  144. return md5($parms['sno']. 'a' . date('dmh') . 'l' . $parms['ts'] . 't'. $parms['lpr']. 'o'. $parms['ivsno'] . 'b'. $parms['io'] . $function_name);
  145. }
  146. // [local] 手動車辨記錄
  147. public function local_lprio()
  148. {
  149. $LOG_FLAG = 'local-cms://';
  150. // 判斷 cmd
  151. $cmd = $this->input->post('cmd', true);
  152. // 新增車辨記錄
  153. if($cmd == 1)
  154. {
  155. $sno = $this->input->post('station_no', true);
  156. $ivsno = $this->input->post('ivsno', true);
  157. $io = $this->input->post('io', true);
  158. $ctype = $this->input->post('ctype', true);
  159. $lpr = $this->input->post('lpr', true);
  160. $parms = array();
  161. $parms['sno'] = preg_replace('/[^0-9]/', '', strtoupper(urldecode($sno)));
  162. $parms['ivsno'] = $ivsno;
  163. $parms['io'] = $ctype.$io;
  164. $parms['type'] = 'C';
  165. $parms['lpr'] = strtoupper(urldecode($lpr));
  166. $parms['color'] = 'NONE';
  167. $parms['sq'] = 0;
  168. $parms['ts'] = date('YmdHis');
  169. $parms['sq2'] = 0;
  170. $parms['etag'] = 'NONE';
  171. $parms['ant'] = 1;
  172. // 補充
  173. $parms['obj_type'] = 1;
  174. $parms['curr_time_str'] = date('Y-m-d H:i:s');
  175. $parms['pic_name'] = '';
  176. trigger_error($LOG_FLAG . __FUNCTION__ . '..' . print_r($parms, true));
  177. // 判斷 io 正確性
  178. if(!in_array($parms['io'], array('CI', 'CO', 'MI', 'MO')))
  179. {
  180. echo 'unknown_io';
  181. exit;
  182. }
  183. // 執行
  184. $this->app_model('cars')->lprio($parms);
  185. echo 'ok';
  186. exit;
  187. }
  188. // 修改車辨記錄
  189. else if($cmd == 2)
  190. {
  191. $station_no = $this->input->post('station_no', true);
  192. $cario_no = $this->input->post('cario_no', true);
  193. $old_lpr = $this->input->post('old_lpr', true);
  194. $new_lpr = $this->input->post('new_lpr', true);
  195. $parms = array();
  196. $parms['sno'] = preg_replace('/[^0-9]/', '', strtoupper(urldecode($station_no)));
  197. $parms['cno'] = preg_replace('/[^0-9]/', '', strtoupper(urldecode($cario_no)));
  198. $parms['old_lpr'] = strtoupper(urldecode($old_lpr));
  199. $parms['lpr'] = strtoupper(urldecode($new_lpr));
  200. trigger_error($LOG_FLAG . __FUNCTION__ . '..' . print_r($parms, true));
  201. // 判斷 lpr 正確性
  202. if($parms['new_lpr'] == $parms['old_lpr'])
  203. {
  204. echo 'no_changed';
  205. exit;
  206. }
  207. else if($parms['lpr'] == 'NONE')
  208. {
  209. echo 'lpr_none';
  210. exit;
  211. }
  212. // 執行
  213. echo $this->app_model('cars')->upd_cario($parms);
  214. exit;
  215. }
  216. // 未知
  217. else
  218. {
  219. echo 'unknown_cmd';
  220. exit;
  221. }
  222. }
  223. // [remote] 新增車辨記錄
  224. public function remote_lprio()
  225. {
  226. $LOG_FLAG = 'cms://';
  227. $parms = $this->uri->uri_to_assoc(3);
  228. // ck
  229. if($parms['ck'] != $this->gen_cms_ck($parms, __FUNCTION__))
  230. {
  231. echo 'ck_error'; // 中斷
  232. exit;
  233. }
  234. $parms['lpr'] = urldecode($parms['lpr']);
  235. $parms['obj_type'] = 1;
  236. $parms['curr_time_str'] = date('Y-m-d H:i:s');
  237. $parms['pic_name'] = '';
  238. trigger_error($LOG_FLAG . __FUNCTION__ . '..' . print_r($parms, true));
  239. // 執行
  240. $this->app_model('cars')->lprio($parms);
  241. echo 'ok';
  242. exit;
  243. }
  244. // [remote] 車辨開門
  245. public function remote_opendoor_lprio()
  246. {
  247. $LOG_FLAG = 'cms://';
  248. $parms = $this->uri->uri_to_assoc(3);
  249. // ck
  250. if($parms['ck'] != $this->gen_cms_ck($parms, __FUNCTION__))
  251. {
  252. echo 'ck_error'; // 中斷
  253. exit;
  254. }
  255. $parms['lpr'] = urldecode($parms['lpr']);
  256. trigger_error($LOG_FLAG . __FUNCTION__ . '..' . print_r($parms, true));
  257. // 初始 mqtt
  258. $this->init_mqtt();
  259. // 執行
  260. $this->app_model('cars')->opendoor_lprio($parms);
  261. echo 'ok';
  262. exit;
  263. }
  264. // [remote] 直接開門
  265. public function remote_opendoor_anyway()
  266. {
  267. $LOG_FLAG = 'cms://';
  268. $parms = $this->uri->uri_to_assoc(3);
  269. // ck
  270. if($parms['ck'] != $this->gen_cms_ck($parms, __FUNCTION__))
  271. {
  272. echo 'ck_error'; // 中斷
  273. exit;
  274. }
  275. $parms['lpr'] = urldecode($parms['lpr']);
  276. trigger_error($LOG_FLAG . __FUNCTION__ . '..' . print_r($parms, true));
  277. // 初始 mqtt
  278. $this->init_mqtt();
  279. // 判斷會員身份
  280. $cars_model = $this->app_model('cars');
  281. $rows = $cars_model->get_member($lpr);
  282. if ($rows['member_no'] == 0)
  283. {
  284. $parms['ck'] = $cars_model->gen_opendoor_ck($parms, 'temp_opendoors'); // 臨停訊號
  285. $cars_model->do_temp_opendoor($parms);
  286. }
  287. else
  288. {
  289. $parms['ck'] = $cars_model->gen_opendoor_ck($parms, 'member_opendoors'); // 月租訊號
  290. $cars_model->do_member_opendoor($parms);
  291. }
  292. echo 'ok';
  293. exit;
  294. }
  295. // ------------------------------------------------
  296. //
  297. // 接收端 (START)
  298. //
  299. // ------------------------------------------------
  300. // [mqtt] 接收端
  301. public function mqtt_service()
  302. {
  303. $LOG_FLAG = 'mqtt://';
  304. $topic = $this->input->post('topic', true);
  305. $msg = $this->input->post('msg', true);
  306. $ck = $this->input->post('ck', true);
  307. if(md5($topic.'altob'.$msg) != $ck)
  308. {
  309. echo 'ck_error';
  310. exit;
  311. }
  312. trigger_error($LOG_FLAG . __FUNCTION__ . "|{$topic}|{$msg}");
  313. if($topic == 'altob.888.mqtt')
  314. {
  315. $data_model = $this->data_model();
  316. // 第一個場站編號 先不管場站
  317. $station_setting = $data_model->station_setting_query();
  318. $station_no_arr = explode(SYNC_DELIMITER_ST_NO, $station_setting['station_no']);
  319. $first_station_no = $station_no_arr[0];
  320. $msg_arr = explode(',', $msg);
  321. if(sizeof($msg_arr) != 4)
  322. {
  323. trigger_error($LOG_FLAG . __FUNCTION__ . "..error_size.." . print_r($msg_arr, true));
  324. echo 'error_size';
  325. exit;
  326. }
  327. if($msg_arr[0] != 'N888' || $msg_arr[3] != 'altob')
  328. {
  329. trigger_error($LOG_FLAG . __FUNCTION__ . "..unknown_msg.." . print_r($msg_arr, true));
  330. echo 'unknown_msg';
  331. exit;
  332. }
  333. $msg_arr = explode(',', $msg);
  334. $group_id = isset($msg_arr[1]) && $msg_arr[1] == 2 ? 'M888' : 'C888';
  335. $value = isset($msg_arr[2]) ? $msg_arr[2] : 0;
  336. $result = $data_model->force_sync_888($first_station_no, $group_id, $value);
  337. trigger_error($LOG_FLAG . __FUNCTION__ . "..{$first_station_no}|{$group_id}|{$value}..result..{$result}..");
  338. }
  339. echo 'ok';
  340. exit;
  341. }
  342. // [設定檔] 取得設定
  343. public function station_setting_query()
  344. {
  345. $reload = $this->input->post('reload', true);
  346. $data_model = $this->data_model();
  347. if(isset($reload) && $reload > 0)
  348. {
  349. $station_setting = $data_model->station_setting_query(true); // 強制重新載入
  350. trigger_error(__FUNCTION__ . '..station_setting: '. print_r($station_setting, true));
  351. if(!$station_setting)
  352. {
  353. echo json_encode('fail', JSON_UNESCAPED_UNICODE);
  354. exit; // 中斷
  355. }
  356. usleep(300000); // 0.3 sec delay
  357. // 費率資料同步
  358. $result = $data_model->sync_price_plan(array('station_no_arr' => $station_setting['station_no']));
  359. trigger_error(__FUNCTION__ . '..sync_price_plan: '. $result);
  360. usleep(300000); // 0.3 sec delay
  361. // 會員資料同步
  362. $result = $data_model->sync_members(array('station_no_arr' => $station_setting['station_no_list'],
  363. 'current_station_no_arr' => $station_setting['station_no'])); // 20171211 upd
  364. trigger_error(__FUNCTION__ . '..sync_members: '. $result);
  365. usleep(300000); // 0.3 sec delay
  366. // 歐pa卡同步
  367. $result = $data_model->sync_allpa_user(array('station_no_arr' => $station_setting['station_no']));
  368. trigger_error(__FUNCTION__ . '..sync_allpa_user: '. $result);
  369. usleep(300000); // 0.3 sec delay
  370. // 在席資料同步
  371. $result = $data_model->sync_pks_groups_reload($station_setting);
  372. trigger_error(__FUNCTION__ . '..sync_pks_groups_reload: '. $result);
  373. }
  374. else
  375. {
  376. $station_setting = $data_model->station_setting_query(false);
  377. if(!$station_setting)
  378. {
  379. echo json_encode('fail', JSON_UNESCAPED_UNICODE);
  380. exit; // 中斷
  381. }
  382. }
  383. echo json_encode($station_setting, JSON_UNESCAPED_UNICODE);
  384. }
  385. // [排程 or 強制] 同步場站資訊
  386. public function sync_station_data()
  387. {
  388. trigger_error(__FUNCTION__ . '..from..'. $this->my_ip() .'..network..'); // IP 會浮動?
  389. $switch_lpr_arr = array(); // 換車牌
  390. $meta = $this->input->post('meta', true);
  391. if(!empty($meta))
  392. {
  393. trigger_error( __FUNCTION__ . '..meta_arr..' . $meta);
  394. $meta_arr = explode('@@@', $meta);
  395. foreach($meta_arr as $raw)
  396. {
  397. if(empty($raw))
  398. continue;
  399. $data = json_decode($raw, true);
  400. if($data['key'] == 'switch_lpr')
  401. {
  402. array_push($switch_lpr_arr, $data['value']);
  403. }
  404. }
  405. }
  406. $data_model = $this->data_model();
  407. // 0. 取得場站設定
  408. $station_setting = $data_model->station_setting_query(false);
  409. trigger_error(__FUNCTION__ . '..station_setting: '. print_r($station_setting, true));
  410. $station_no_arr = array('station_no_arr' => $station_setting['station_no']);
  411. // 1. 月租系統
  412. $result = $data_model->sync_members($station_no_arr);
  413. trigger_error(__FUNCTION__ . '..sync_members: '. $result);
  414. // 2. 同步車牌更換
  415. if(!empty($switch_lpr_arr))
  416. {
  417. $data_model->sync_switch_lpr($switch_lpr_arr);
  418. }
  419. // 3. 歐pa卡同步 (TODO: 暫時放在這)
  420. $result = $data_model->sync_allpa_user($station_no_arr);
  421. trigger_error(__FUNCTION__ . '..sync_allpa_user: '. $result);
  422. }
  423. // [API] 取得最新未結清
  424. public function get_last_unbalanced_cario()
  425. {
  426. trigger_error(__FUNCTION__ . '..from..'. $this->my_ip() .'..network..'); // IP 會浮動?
  427. $lpr = $this->input->post('lpr', true);
  428. $station_no = $this->input->post('station_no', true);
  429. $c_s = $this->input->post('c_s', true);
  430. // 確認正確性
  431. if(empty($c_s) || $c_s != md5('altob'.$lpr.'botla'.$station_no))
  432. {
  433. trigger_error(__FUNCTION__ . "..{$lpr}|".$station_no."|{$c_s}..check fail..");
  434. echo 'fail';
  435. exit;
  436. }
  437. $data = $this->data_model()->get_last_unbalanced_cario($lpr, $station_no);
  438. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  439. }
  440. // [API] 更新未結清 (行動支付)
  441. public function sync_m2payed()
  442. {
  443. trigger_error(__FUNCTION__ . '..from..'. $this->my_ip() .'..network..'); // IP 會浮動?
  444. $lpr = $this->input->post('lpr', true);
  445. $amt = $this->input->post('amt', true);
  446. $station_no = $this->input->post('station_no', true);
  447. $cario_no = $this->input->post('cario_no', true);
  448. $c_s = $this->input->post('c_s', true);
  449. // 確認正確性
  450. if(empty($c_s) || $c_s != md5($lpr.$amt.'altob'.$station_no.'botla'.$cario_no))
  451. {
  452. trigger_error(__FUNCTION__ . "..{$lpr}|{$amt}|{$station_no}|{$cario_no}|{$c_s}..check fail..");
  453. echo 'fail';
  454. exit;
  455. }
  456. // 臨停繳費
  457. echo $this->app_model('carpayment')->p2payed(array('seqno' => $cario_no, 'lpr' => $lpr, 'amt' => $amt), true);
  458. exit;
  459. }
  460. // 同步 (由排程呼叫)
  461. public function sync_minutely()
  462. {
  463. $this->sync_parktron_888(); // 同步博辰 888
  464. $this->data_model()->sync_pks_groups(); // 同步在席現況
  465. }
  466. /*
  467. // 20170816 手動新增入場資料
  468. public function gen_carin()
  469. {
  470. trigger_error(__FUNCTION__ . '..from..'. $this->my_ip() .'..network..'); // IP 會浮動?
  471. $lpr = $this->input->post('lpr', true);
  472. $station_no = $this->input->post('station_no', true);
  473. $c_s = $this->input->post('c_s', true);
  474. // 確認正確性
  475. if(empty($c_s) || $c_s != md5($lpr.'altob'.$station_no.'botla'. __FUNCTION__ ))
  476. {
  477. trigger_error(__FUNCTION__ . "..{$lpr}|{$station_no}|{$c_s}..check fail..");
  478. echo 'fail';
  479. exit;
  480. }
  481. $parms = array(
  482. 'sno' => $station_no,
  483. 'lpr' => $lpr,
  484. 'etag' => 'NONE',
  485. 'io' => 'CI',
  486. 'ivsno' => 0
  487. );
  488. $this->carpark_model->gen_carin($parms);
  489. echo 'ok';
  490. }
  491. */
  492. // ------------------------------------------------
  493. //
  494. // 接收端 (END)
  495. //
  496. // ------------------------------------------------
  497. // [START] 2016/06/03 登入
  498. public function index()
  499. {
  500. if($this->session->userdata('logged_in'))
  501. {
  502. $session_data = $this->session->userdata('logged_in');
  503. $data['username'] = $session_data['username'];
  504. $data['type'] = $session_data['type'];
  505. // 取得場站設定
  506. $station_setting = $this->data_model()->station_setting_query();
  507. if(isset($station_setting['station_no']))
  508. {
  509. $data['station_no'] = $station_setting['station_no'];
  510. $data['station_name'] = $station_setting['station_name'];
  511. }
  512. if($data['type'] == 'admin')
  513. {
  514. $this->show_page('admin_page', $data); // 進階管理者介面
  515. }
  516. else
  517. {
  518. $this->show_page('main_page', $data); // 一般
  519. }
  520. }
  521. else
  522. {
  523. //If no session, redirect to login page
  524. //redirect('login', 'refresh');
  525. $this->show_page('login_page');
  526. }
  527. }
  528. // 登入
  529. public function user_login()
  530. {
  531. // form_validation
  532. $this->form_validation->set_rules('login_name', 'login_name', 'trim|required');
  533. $this->form_validation->set_rules('pswd', 'pswd', 'trim|required');
  534. if($this->form_validation->run() == FALSE)
  535. {
  536. return RESULT_FORM_VALIDATION_FAIL;
  537. }
  538. // go model
  539. $data = array
  540. (
  541. 'login_name' => $this->input->post('login_name', true),
  542. 'pswd' => $this->input->post('pswd', true)
  543. );
  544. $result = $this->app_model('user')->user_login($data);
  545. if($result)
  546. {
  547. $sess_array = array();
  548. foreach($result as $row)
  549. {
  550. $sess_array = array
  551. (
  552. 'username' => $row->login_name ,
  553. 'type' => $row->user_type
  554. );
  555. $this->session->set_userdata('logged_in', $sess_array);
  556. }
  557. echo RESULT_SUCCESS;
  558. }
  559. else
  560. {
  561. return RESULE_FAIL;
  562. }
  563. }
  564. // 登出
  565. public function user_logout()
  566. {
  567. $this->session->unset_userdata('logged_in');
  568. session_destroy();
  569. return RESULT_SUCCESS;
  570. }
  571. // [END] 2016/06/03 登入
  572. /*
  573. // response http
  574. protected function http_return($return_code, $type)
  575. {
  576. if ($type == 'text') echo $return_code;
  577. else echo json_encode($return_code, JSON_UNESCAPED_UNICODE);
  578. }
  579. // 讀取cookie內容
  580. protected function get_cookie($cookie_name)
  581. {
  582. if (empty($_COOKIE[$cookie_name])) return array();
  583. return(json_decode($_COOKIE[$cookie_name], true));
  584. }
  585. // 儲存cookie內容
  586. protected function save_cookie($cookie_name, $cookie_info)
  587. {
  588. return setcookie($cookie_name, json_encode($cookie_info, JSON_UNESCAPED_UNICODE), 0, '/');
  589. }
  590. // 月租資料同步
  591. public function rent_sync()
  592. {
  593. $station_no = $this->input->post('station_no', true);
  594. $start_date = $this->input->post('start_date', true);
  595. $end_date = $this->input->post('end_date', true);
  596. // $data = $this->carpark_model->rent_sync($station_no, $start_date, $end_date);
  597. // print_r($data);
  598. }
  599. // 重設剩餘車位數
  600. public function available_set()
  601. {
  602. $data = $this->carpark_model->available_set();
  603. $this->http_return($data, 'json');
  604. }
  605. // 剩餘車位數更新
  606. public function available_update()
  607. {
  608. $station_no = $this->input->get_post('station_no', true);
  609. $data['name'] = $this->input->get_post('st_name', true);
  610. $data['tot_pkg'] = $this->input->get_post('tot_pkg', true);
  611. $data['ava_pkg'] = $this->input->get_post('ava_pkg', true);
  612. $this->http_return($this->carpark_model->available_update($station_no, $data), 'json');
  613. }
  614. // 剩餘車位數查核
  615. public function available_check()
  616. {
  617. $time_point = $this->input->get_post('time_point', true);
  618. $this->http_return($this->carpark_model->available_check($time_point), 'json');
  619. }
  620. // 顯示logs (cars grep 888)
  621. public function show_888_logs()
  622. {
  623. $lines = $this->uri->segment(3); // 顯示行數
  624. if (empty($lines)) $lines = 1000; // 無行數參數, 預設為1000行
  625. if($lines > 20000) $lines = 20000; // 最多 20000行
  626. $grep_str = ' |grep 888';
  627. $target_str = LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt'. $grep_str;
  628. // echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><pre style="white-space: pre-wrap;">';
  629. echo '<html lang="zh-TW"><body><pre style="white-space: pre-wrap;">';
  630. passthru('/usr/bin/tail -n ' . $lines . ' ' . $target_str); // 利用linux指令顯示倒數幾行的logs內容
  631. echo "\n----- " . $target_str . ' -----';
  632. echo '</pre></body></html>';
  633. }
  634. // 新增月租資料
  635. public function member_add()
  636. {
  637. $data = array
  638. (
  639. 'member_no' => $this->input->post('member_no', true),
  640. 'station_no' => $this->input->post('station_no', true),
  641. 'lpr' => strtoupper($this->input->post('lpr', true)),
  642. 'old_lpr' => strtoupper($this->input->post('old_lpr', true)),
  643. 'etag' => strtoupper($this->input->post('etag', true)),
  644. 'start_date' => $this->input->post('start_date', true),
  645. 'end_date' => $this->input->post('end_date', true),
  646. 'member_name' => $this->input->post('member_name', true),
  647. 'member_nick_name' => $this->input->post('member_name', true),
  648. 'mobile_no' => $this->input->post('mobile_no', true),
  649. 'member_id' => $this->input->post('member_id', true),
  650. 'contract_no' => $this->input->post('contract_no', true),
  651. 'amt' => $this->input->post('amt', true),
  652. 'tel_h' => $this->input->post('tel_h', true),
  653. 'tel_o' => $this->input->post('tel_o', true),
  654. 'addr' => $this->input->post('addr', true)
  655. );
  656. trigger_error("add:".print_r($data, true));
  657. if ($data['member_no'] == 0 || $data['old_lpr'] != $data['lpr'])
  658. {
  659. if ($this->carpark_model->check_lpr($data['lpr']) > 0)
  660. {
  661. echo '車牌重複, 請查明再輸入';
  662. exit;
  663. }
  664. }
  665. $this->carpark_model->member_add($data);
  666. echo 'ok';
  667. }
  668. // 刪除月租資料
  669. public function member_delete()
  670. {
  671. $member_no = $this->input->post('member_no', true);
  672. $this->carpark_model->member_delete($member_no);
  673. echo 'ok';
  674. }
  675. // 進出場事件即時顯示
  676. public function cario_event()
  677. {
  678. set_time_limit(0);
  679. while(true)
  680. {
  681. }
  682. }
  683. // 汽車開門
  684. public function opendoors()
  685. {
  686. $ivsno = $this->uri->segment(3);
  687. $lanes = array
  688. (
  689. 0 => array ('devno' => 0, 'temp' => 0, 'member' => 1), // 1號入口, temp:臨停, member:月租
  690. // 1 => array ('devno' => 0, 'temp' => 2, 'member' => 3), // 2號調撥入口
  691. 1 => array ('devno' => 1, 'temp' => 0, 'member' => 1), // 3號調撥出口
  692. 2 => array ('devno' => 1, 'temp' => 0, 'member' => 1), // 3號調撥出口
  693. 3 => array ('devno' => 1, 'temp' => 2, 'member' => 3) // 4號出口
  694. );
  695. $url = 'http://admin:99999999@192.168.10.53/cgi-bin/basic_setting.cgi?ID=1&';
  696. $member_tag = 'member'; // member:月租會員
  697. // 短路開柵欄
  698. @get_headers("{$url}OUTDEV={$lanes[$ivsno]['devno']}&OUTCH={$lanes[$ivsno][$member_tag]}&OUTSTATUS=1");
  699. usleep(400000); // 暫停0.4秒
  700. // 斷路, 車過關柵欄
  701. @get_headers("{$url}OUTDEV={$lanes[$ivsno]['devno']}&OUTCH={$lanes[$ivsno][$member_tag]}&OUTSTATUS=0");
  702. }
  703. // 調撥車道查詢
  704. public function reversible_lane_query()
  705. {
  706. $max_lane = 4; // 共幾個車道數
  707. for ($idx = 0; $idx < $max_lane; ++$idx)
  708. {
  709. $data[$idx] = file_get_contents("http://192.168.10.51:8090/cgi-bin/switcher.cgi?id={$idx}&action=9");
  710. }
  711. // $data = array(1, 1, 0, 1);
  712. echo json_encode($data);
  713. }
  714. // 調撥車道設定
  715. public function reversible_lane_set()
  716. {
  717. $lane_no = $this->input->post('lane_no', true);
  718. $actions = $this->input->post('actions', true);
  719. $data = file_get_contents("http://192.168.10.51:8090/cgi-bin/switcher.cgi?id={$lane_no}&action={$actions}");
  720. echo "{$lane_no}|{$actions}|{$data}";
  721. }
  722. // 在席車位檢查未有入場資料清單
  723. public function pks_check_list()
  724. {
  725. $max_rows = $this->uri->segment(3, 100); // 一次讀取筆數, 預設為100筆
  726. $data = $this->carpark_model->pks_check_list($max_rows);
  727. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  728. }
  729. // 重設在席查核
  730. public function reset_pks_check()
  731. {
  732. $data = $this->carpark_model->reset_pks_check();
  733. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  734. }
  735. // 更正在席車號
  736. public function correct_pks_lpr()
  737. {
  738. $pksno = $this->uri->segment(3, 0); // 車格號碼
  739. $lpr = $this->uri->segment(4, 'NONE'); // 車號
  740. if ($pksno == 0 || $lpr == 'NONE')
  741. {
  742. echo json_encode(array('err' => 1, 'cario_no' => 0), JSON_UNESCAPED_UNICODE);
  743. }
  744. else
  745. {
  746. $data = $this->carpark_model->correct_pks_lpr($pksno, $lpr);
  747. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  748. }
  749. }
  750. // 入場車號查核在席無資料清單
  751. public function carin_check_list()
  752. {
  753. $max_rows = $this->uri->segment(3, 20); // 一次讀取筆數, 預設為100筆
  754. $data = $this->carpark_model->carin_check_list($max_rows);
  755. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  756. }
  757. // 更正入場車號
  758. public function correct_carin_lpr()
  759. {
  760. $cario_no = $this->uri->segment(3, 0); // 車格號碼
  761. $lpr = $this->uri->segment(4, 'NONE'); // 車號
  762. $in_time = urldecode($this->uri->segment(5, '')); // 入場時間
  763. $data = $this->carpark_model->correct_carin_lpr($cario_no, $lpr, $in_time);
  764. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  765. }
  766. */
  767. // 查詢月租資料
  768. public function member_query()
  769. {
  770. $data = $this->app_model()->member_query();
  771. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  772. }
  773. // 進出場現況表
  774. public function cario_list()
  775. {
  776. $data = $this->app_model()->cario_list();
  777. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  778. }
  779. // 顯示圖檔(http://url/carpark.html/pics/lpr_ABY8873_O_0_0_C_20150919210022)
  780. public function pics()
  781. {
  782. readfile(CAR_PIC.$this->uri->segment(3).'/'.str_replace('/', '', $this->uri->segment(4)).'.jpg');
  783. }
  784. // 車號入場查詢
  785. public function carin_lpr_query()
  786. {
  787. $lpr = $this->uri->segment(3);
  788. $data = $this->app_model()->carin_lpr_query($lpr);
  789. echo json_encode($data);
  790. }
  791. // 以時間查詢入場資訊
  792. public function carin_time_query()
  793. {
  794. $time_query = $this->input->post('time_query', true);
  795. $minutes_range = $this->input->post('minutes_range', true);
  796. $data = $this->app_model()->carin_time_query($time_query, $minutes_range);
  797. echo json_encode($data);
  798. }
  799. // 車辨失敗查詢
  800. public function carin_none_query()
  801. {
  802. $time_query = $this->input->post('time_query', true);
  803. $hours_range = $this->input->post('hours_range', true);
  804. $data = $this->app_model()->carin_none_query($time_query, $hours_range);
  805. echo json_encode($data);
  806. }
  807. // 查詢行動支付記錄
  808. public function tx_bill_query()
  809. {
  810. $data = $this->app_model()->tx_bill_query();
  811. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  812. }
  813. // 查詢月租繳款機記錄
  814. public function tx_bill_ats_query()
  815. {
  816. $data = $this->app_model()->tx_bill_ats_query();
  817. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  818. }
  819. // 查詢樓層在席群組
  820. public function pks_group_query()
  821. {
  822. $data = $this->app_model()->pks_group_query();
  823. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  824. }
  825. // 微調剩餘車位數
  826. public function pks_availables_update()
  827. {
  828. $group_id = $this->uri->segment(3); // id
  829. $value = $this->uri->segment(4, 0); // value
  830. $station_no = $this->uri->segment(5); // station_no
  831. // 初始 mqtt
  832. $this->init_mqtt();
  833. $data = $this->data_model()->pks_availables_update($group_id, $value, true, $station_no);
  834. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  835. }
  836. // 進出場觸發 888 呼叫
  837. /*
  838. public function sync_888()
  839. {
  840. $io = $this->uri->segment(3); // CI, CO, MI, MO
  841. if(empty($io))
  842. {
  843. echo 'io_not_found';
  844. exit;
  845. }
  846. $parms = array('io' => $io, 'etag' => __FUNCTION__, 'lpr' => __FUNCTION__);
  847. echo $this->sync_data_model->sync_888($parms);
  848. exit;
  849. }
  850. */
  851. // 博辰測試用
  852. // http://localhost/carpark.html/test_8068_002/APK7310
  853. public function test_8068_002()
  854. {
  855. $lpr_in = $this->uri->segment(3);
  856. $seqno = '00001';
  857. $cmd = '002';
  858. $token = '000000000';
  859. $lpr = str_pad($lpr_in, 7, '%', STR_PAD_LEFT);
  860. $in_time = '2000/01/01 00:00:00';
  861. $error_str = '';
  862. $service_port = 8068;
  863. $address = empty($this->uri->segment(4)) ? "192.168.10.201" : "192.168.10." . $this->uri->segment(4);
  864. /* Create a TCP/IP socket. */
  865. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  866. if ($socket === false) {
  867. echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
  868. $error_str .= "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
  869. } else {
  870. echo "OK.\n";
  871. }
  872. echo "Attempting to connect to '{$address}' on port '{$service_port}'...";
  873. $result = socket_connect($socket, $address, $service_port);
  874. if ($result === false) {
  875. echo "socket_connect() failed.\nReason: ({$result}) " . socket_strerror(socket_last_error($socket)) . "\n";
  876. $error_str .= "socket_connect() failed: reason: " . socket_strerror(socket_last_error($socket)) . "\n";
  877. } else {
  878. echo "OK.\n";
  879. }
  880. $in = pack('Ca5Ca3Ca9Ca7Ca19', 0x1c, $seqno, 0x1c, $cmd, 0x1c,
  881. $token, 0x1f, $lpr, 0x1f, $in_time
  882. );
  883. $out = '';
  884. echo "socket_write:";
  885. echo "{$in}<br/><br/>";
  886. if(!socket_write($socket, $in, strlen($in)))
  887. {
  888. echo('<p>Write failed</p>');
  889. $error_str .= "socket_write() failed: reason: " . socket_strerror(socket_last_error($socket)) . "\n";
  890. }
  891. echo "socket_write..OK..";
  892. echo "<br/><br/>socket_read:";
  893. $out = socket_read($socket, 2048) or die("Could not read server responsen");
  894. //while ($out = socket_read($socket, 2048)) {
  895. // echo $out;
  896. //}
  897. echo "{$out}<br/><br/>";
  898. echo "Closing socket...";
  899. socket_close($socket);
  900. echo "OK.\n\n";
  901. trigger_error($error_str);
  902. exit;
  903. }
  904. }