VM暫存
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

940 lines
29KB

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