VM暫存
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

890 rindas
27KB

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