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.

874 rindas
28KB

  1. <?php
  2. /*
  3. file: carpark.php 停車管理
  4. */
  5. if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  6. require_once(MQ_CLASS_FILE);
  7. // ----- 定義常數(路徑, cache秒數) -----
  8. define('APP_VERSION', '100'); // 版本號
  9. define('MAX_AGE', 604800); // cache秒數, 此定義1個月
  10. define('APP_NAME', 'carpark'); // 應用系統名稱
  11. define('PAGE_PATH', APP_BASE.'ci_application/views/'.APP_NAME.'/'); // path of views
  12. //define('SERVER_URL', 'http://'.(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost').'/'); // URL
  13. define('SERVER_URL', 'http://'.(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost') . ($_SERVER['SERVER_PORT'] != 60123 ? ':' . $_SERVER['SERVER_PORT'] : '') .'/'); // URL
  14. define('APP_URL', SERVER_URL.APP_NAME.'.html/'); // controller路徑
  15. define('WEB_URL', SERVER_URL.APP_NAME.'/'); // 網頁路徑
  16. define('WEB_LIB', SERVER_URL.'libs/'); // 網頁lib
  17. define('BOOTSTRAPS', WEB_LIB.'bootstrap_sb/'); // bootstrap lib
  18. define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path
  19. class Carpark extends CI_Controller
  20. {
  21. var $vars = array(); // 共用變數
  22. function __construct()
  23. {
  24. parent::__construct();
  25. // ----- 程式開發階段log設定 -----
  26. if (@ENVIRONMENT == 'development')
  27. {
  28. ini_set('display_errors', '1');
  29. //error_reporting(E_ALL ^ E_NOTICE);
  30. error_reporting(E_ALL);
  31. }
  32. set_error_handler(array($this, 'error_handler'), E_ALL); // 資料庫異動需做log
  33. // 共用記憶體
  34. $this->vars['mcache'] = new Memcache;
  35. $this->vars['mcache']->connect(MEMCACHE_HOST, MEMCACHE_PORT) or die ('Could not connect memcache');
  36. // mqtt subscribe
  37. $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_PORT, uniqid());
  38. //if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); }
  39. $this->vars['mqtt']->connect();
  40. $this->load->model('carpark_model');
  41. $this->carpark_model->init($this->vars);
  42. // 微調剩餘車位數
  43. $this->load->model('sync_data_model');
  44. $this->sync_data_model->init($this->vars);
  45. // 產生 excel 報表
  46. $this->load->model('excel_model');
  47. $this->excel_model->init($this->vars);
  48. // [START] 2016/06/03 登入
  49. $this->load->model('user_model');
  50. // load library
  51. $this->load->library(array('form_validation','session'));
  52. // load helpers
  53. $this->load->helper(array('form'));
  54. // ajax code
  55. define('RESULT_SUCCESS', 'ok');
  56. define('RESULT_FORM_VALIDATION_FAIL', '-1');
  57. define('RESULE_FAIL', 'gg');
  58. // [START] 2016/06/03 登入
  59. }
  60. // 發生錯誤時集中在此處理
  61. public function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
  62. {
  63. // ex: car_err://message....
  64. $log_msg = explode('://', $errstr);
  65. if (count($log_msg) > 1)
  66. {
  67. $log_file = LOG_PATH.$log_msg[0];
  68. $str = date('H:i:s')."|{$log_msg[1]}|{$errfile}|{$errline}|{$errno}\n";
  69. }
  70. else
  71. {
  72. $log_file = LOG_PATH.APP_NAME;
  73. $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  74. }
  75. //$str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  76. error_log($str, 3, $log_file . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  77. }
  78. // 顯示靜態網頁(html檔)
  79. protected function show_page($page_name, &$data = null)
  80. {
  81. $page_file = PAGE_PATH.$page_name.'.php';
  82. $last_modified_time = filemtime($page_file);
  83. // 若檔案修改時間沒有異動, 或版本無異動, 通知瀏覽器使用cache, 不再下傳網頁
  84. // header('Cache-Control:max-age='.MAX_AGE); // cache 1個月
  85. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_modified_time).' GMT');
  86. header('Etag: '. APP_VERSION);
  87. header('Cache-Control: public');
  88. // 20170921
  89. header("cache-Control: no-store, no-cache, must-revalidate");
  90. header("cache-Control: post-check=0, pre-check=0", false);
  91. header("Pragma: no-cache");
  92. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  93. if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == APP_VERSION && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time)
  94. {
  95. header('HTTP/1.1 304 Not Modified');
  96. }
  97. else
  98. {
  99. $this->load->view(APP_NAME.'/'.$page_name, $data);
  100. }
  101. }
  102. // ------------------------------------------------
  103. //
  104. // 接收端 (START)
  105. //
  106. // ------------------------------------------------
  107. // [設定檔] 取得設定
  108. public function station_setting_query()
  109. {
  110. $reload = $this->input->post('reload', true);
  111. if(isset($reload) && $reload > 0)
  112. {
  113. $station_setting = $this->sync_data_model->station_setting_query(true); // 強制重新載入
  114. trigger_error(__FUNCTION__ . '..station_setting: '. print_r($station_setting, true));
  115. if(!$station_setting)
  116. {
  117. echo json_encode('fail', JSON_UNESCAPED_UNICODE);
  118. exit; // 中斷
  119. }
  120. $info = array('station_no_arr' => $station_setting['station_no']);
  121. usleep(300000); // 0.3 sec delay
  122. // 費率資料同步
  123. $result = $this->sync_data_model->sync_price_plan($info);
  124. trigger_error(__FUNCTION__ . '..sync_price_plan: '. $result);
  125. usleep(300000); // 0.3 sec delay
  126. // 會員資料同步
  127. $result = $this->sync_data_model->sync_members($info);
  128. trigger_error(__FUNCTION__ . '..sync_members: '. $result);
  129. usleep(300000); // 0.3 sec delay
  130. // 在席資料同步
  131. $result = $this->sync_data_model->sync_pks_groups_reload($station_setting);
  132. trigger_error(__FUNCTION__ . '..sync_pks_groups_reload: '. $result);
  133. }
  134. else
  135. {
  136. $station_setting = $this->sync_data_model->station_setting_query(false);
  137. if(!$station_setting)
  138. {
  139. echo json_encode('fail', JSON_UNESCAPED_UNICODE);
  140. exit; // 中斷
  141. }
  142. }
  143. echo json_encode($station_setting, JSON_UNESCAPED_UNICODE);
  144. }
  145. // [排程 or 強制] 同步場站資訊
  146. public function sync_station_data()
  147. {
  148. trigger_error(__FUNCTION__ . '..from..'. $this->my_ip() .'..network..'); // IP 會浮動?
  149. $switch_lpr_arr = array(); // 換車牌
  150. $meta = $this->input->post('meta', true);
  151. if(!empty($meta))
  152. {
  153. trigger_error( __FUNCTION__ . '..meta_arr..' . $meta);
  154. $meta_arr = explode('@@@', $meta);
  155. foreach($meta_arr as $raw)
  156. {
  157. if(empty($raw))
  158. continue;
  159. $data = json_decode($raw, true);
  160. if($data['key'] == 'switch_lpr')
  161. {
  162. array_push($switch_lpr_arr, $data['value']);
  163. }
  164. }
  165. }
  166. // 0. 取得場站設定
  167. $station_setting = $this->sync_data_model->station_setting_query(false);
  168. trigger_error(__FUNCTION__ . '..station_setting: '. print_r($station_setting, true));
  169. $station_no_arr = array('station_no_arr' => $station_setting['station_no']);
  170. // 1. 月租系統
  171. $result = $this->sync_data_model->sync_members($station_no_arr);
  172. trigger_error(__FUNCTION__ . '..sync_members: '. $result);
  173. // 2. 同步車牌更換
  174. if(!empty($switch_lpr_arr))
  175. {
  176. $this->sync_data_model->sync_switch_lpr($switch_lpr_arr);
  177. }
  178. }
  179. // [API] 取得最新未結清
  180. public function get_last_unbalanced_cario()
  181. {
  182. trigger_error(__FUNCTION__ . '..from..'. $this->my_ip() .'..network..'); // IP 會浮動?
  183. $lpr = $this->input->post('lpr', true);
  184. $station_no = $this->input->post('station_no', true);
  185. $c_s = $this->input->post('c_s', true);
  186. // 確認正確性
  187. if(empty($c_s) || $c_s != md5('altob'.$lpr.'botla'.$station_no))
  188. {
  189. trigger_error(__FUNCTION__ . "..{$lpr}|".$station_no."|{$c_s}..check fail..");
  190. echo 'fail';
  191. exit;
  192. }
  193. $data = $this->sync_data_model->get_last_unbalanced_cario($lpr, $station_no);
  194. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  195. }
  196. // [API] 更新未結清 (行動支付)
  197. public function sync_m2payed()
  198. {
  199. trigger_error(__FUNCTION__ . '..from..'. $this->my_ip() .'..network..'); // IP 會浮動?
  200. $lpr = $this->input->post('lpr', true);
  201. $amt = $this->input->post('amt', true);
  202. $station_no = $this->input->post('station_no', true);
  203. $cario_no = $this->input->post('cario_no', true);
  204. $c_s = $this->input->post('c_s', true);
  205. // 確認正確性
  206. if(empty($c_s) || $c_s != md5($lpr.$amt.'altob'.$station_no.'botla'.$cario_no))
  207. {
  208. trigger_error(__FUNCTION__ . "..{$lpr}|{$amt}|{$station_no}|{$cario_no}|{$c_s}..check fail..");
  209. echo 'fail';
  210. exit;
  211. }
  212. // 臨停繳費
  213. $this->load->model('carpayment_model');
  214. echo $this->carpayment_model->p2payed(array('seqno' => $cario_no, 'lpr' => $lpr, 'amt' => $amt), true);
  215. exit;
  216. //echo 'ok';
  217. }
  218. // 驗証 IP
  219. function is_ip_valid()
  220. {
  221. $client_ip = $this->my_ip();
  222. if(!in_array($client_ip, array('61.219.172.11', '61.219.172.82')))
  223. {
  224. trigger_error('..block..from:'.$client_ip.'..unknown network..');
  225. return false;
  226. }
  227. return true;
  228. }
  229. // 取得 IP
  230. function my_ip()
  231. {
  232. if (getenv('HTTP_X_FORWARDED_FOR'))
  233. {
  234. $ip = getenv('HTTP_X_FORWARDED_FOR');
  235. }
  236. elseif (getenv('HTTP_X_REAL_IP'))
  237. {
  238. $ip = getenv('HTTP_X_REAL_IP');
  239. }
  240. else {
  241. $ip = $_SERVER['REMOTE_ADDR'];
  242. }
  243. return $ip;
  244. }
  245. // 同步 (由排程呼叫)
  246. public function sync_minutely()
  247. {
  248. $this->sync_data_model->sync_pks_groups(); // 同步在席現況
  249. }
  250. // 20170816 手動新增入場資料
  251. public function gen_carin()
  252. {
  253. trigger_error(__FUNCTION__ . '..from..'. $this->my_ip() .'..network..'); // IP 會浮動?
  254. $lpr = $this->input->post('lpr', true);
  255. $station_no = $this->input->post('station_no', true);
  256. $c_s = $this->input->post('c_s', true);
  257. // 確認正確性
  258. if(empty($c_s) || $c_s != md5($lpr.'altob'.$station_no.'botla'. __FUNCTION__ ))
  259. {
  260. trigger_error(__FUNCTION__ . "..{$lpr}|{$station_no}|{$c_s}..check fail..");
  261. echo 'fail';
  262. exit;
  263. }
  264. $parms = array(
  265. 'sno' => $station_no,
  266. 'lpr' => $lpr,
  267. 'etag' => 'NONE',
  268. 'io' => 'CI',
  269. 'ivsno' => 0
  270. );
  271. $this->carpark_model->gen_carin($parms);
  272. echo 'ok';
  273. }
  274. // ------------------------------------------------
  275. //
  276. // 接收端 (END)
  277. //
  278. // ------------------------------------------------
  279. // [START] 2016/06/03 登入
  280. public function index()
  281. {
  282. if($this->session->userdata('logged_in'))
  283. {
  284. $session_data = $this->session->userdata('logged_in');
  285. $data['username'] = $session_data['username'];
  286. $data['type'] = $session_data['type'];
  287. if($data['type'] == 'admin')
  288. {
  289. $this->show_page('admin_page', $data); // 進階管理者介面
  290. }
  291. else
  292. {
  293. $this->show_page('main_page', $data); // 一般
  294. }
  295. }
  296. else
  297. {
  298. //If no session, redirect to login page
  299. //redirect('login', 'refresh');
  300. $this->show_page('login_page');
  301. }
  302. }
  303. // 登入
  304. public function user_login()
  305. {
  306. // form_validation
  307. $this->form_validation->set_rules('login_name', 'login_name', 'trim|required');
  308. $this->form_validation->set_rules('pswd', 'pswd', 'trim|required');
  309. if($this->form_validation->run() == FALSE)
  310. {
  311. return RESULT_FORM_VALIDATION_FAIL;
  312. }
  313. // go model
  314. $data = array
  315. (
  316. 'login_name' => $this->input->post('login_name', true),
  317. 'pswd' => $this->input->post('pswd', true)
  318. );
  319. $result = $this->user_model->user_login($data);
  320. if($result)
  321. {
  322. $sess_array = array();
  323. foreach($result as $row)
  324. {
  325. $sess_array = array
  326. (
  327. 'username' => $row->login_name ,
  328. 'type' => $row->user_type
  329. );
  330. $this->session->set_userdata('logged_in', $sess_array);
  331. }
  332. echo RESULT_SUCCESS;
  333. }
  334. else
  335. {
  336. return RESULE_FAIL;
  337. }
  338. }
  339. // 登出
  340. public function user_logout()
  341. {
  342. $this->session->unset_userdata('logged_in');
  343. session_destroy();
  344. return RESULT_SUCCESS;
  345. }
  346. // [END] 2016/06/03 登入
  347. // response http
  348. protected function http_return($return_code, $type)
  349. {
  350. if ($type == 'text') echo $return_code;
  351. else echo json_encode($return_code, JSON_UNESCAPED_UNICODE);
  352. }
  353. // 送出html code
  354. public function get_html()
  355. {
  356. /*
  357. $data = array
  358. (
  359. 'company_no' => $this->input->post('company_no', true), // 場站統編
  360. 'hq_company_no' => '80682490'
  361. );
  362. $this->load->view(APP_NAME.'/'.$this->input->post('tag_name', true), $data);
  363. */
  364. $this->load->view(APP_NAME.'/'.$this->input->post('tag_name', true), array());
  365. }
  366. // 讀取cookie內容
  367. protected function get_cookie($cookie_name)
  368. {
  369. if (empty($_COOKIE[$cookie_name])) return array();
  370. return(json_decode($_COOKIE[$cookie_name], true));
  371. }
  372. // 儲存cookie內容
  373. protected function save_cookie($cookie_name, $cookie_info)
  374. {
  375. return setcookie($cookie_name, json_encode($cookie_info, JSON_UNESCAPED_UNICODE), 0, '/');
  376. }
  377. // 月租資料同步
  378. public function rent_sync()
  379. {
  380. $station_no = $this->input->post('station_no', true);
  381. $start_date = $this->input->post('start_date', true);
  382. $end_date = $this->input->post('end_date', true);
  383. // $data = $this->carpark_model->rent_sync($station_no, $start_date, $end_date);
  384. // print_r($data);
  385. }
  386. // 重設剩餘車位數
  387. public function available_set()
  388. {
  389. $data = $this->carpark_model->available_set();
  390. $this->http_return($data, 'json');
  391. }
  392. // 剩餘車位數更新
  393. public function available_update()
  394. {
  395. $station_no = $this->input->get_post('station_no', true);
  396. $data['name'] = $this->input->get_post('st_name', true);
  397. $data['tot_pkg'] = $this->input->get_post('tot_pkg', true);
  398. $data['ava_pkg'] = $this->input->get_post('ava_pkg', true);
  399. $this->http_return($this->carpark_model->available_update($station_no, $data), 'json');
  400. }
  401. // 剩餘車位數查核
  402. public function available_check()
  403. {
  404. $time_point = $this->input->get_post('time_point', true);
  405. $this->http_return($this->carpark_model->available_check($time_point), 'json');
  406. }
  407. // 顯示logs
  408. public function show_logs()
  409. {
  410. $lines = $this->uri->segment(3); // 顯示行數
  411. if (empty($lines)) $lines = 140; // 無行數參數, 預設為40行
  412. if($lines > 1000) $lines = 1000; // 最多 1000行
  413. // echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><pre style="white-space: pre-wrap;">';
  414. echo '<html lang="zh-TW"><body><pre style="white-space: pre-wrap;">';
  415. passthru('/usr/bin/tail -n ' . $lines . ' ' . LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt'); // 利用linux指令顯示倒數幾行的logs內容
  416. echo "\n----- " . LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt' . ' -----';
  417. echo '</pre></body></html>';
  418. }
  419. // 顯示logs (cars grep 888)
  420. public function show_888_logs()
  421. {
  422. $lines = $this->uri->segment(3); // 顯示行數
  423. if (empty($lines)) $lines = 1000; // 無行數參數, 預設為1000行
  424. if($lines > 20000) $lines = 20000; // 最多 20000行
  425. $grep_str = ' |grep 888';
  426. $target_str = LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt'. $grep_str;
  427. // echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><pre style="white-space: pre-wrap;">';
  428. echo '<html lang="zh-TW"><body><pre style="white-space: pre-wrap;">';
  429. passthru('/usr/bin/tail -n ' . $lines . ' ' . $target_str); // 利用linux指令顯示倒數幾行的logs內容
  430. echo "\n----- " . $target_str . ' -----';
  431. echo '</pre></body></html>';
  432. }
  433. // 新增月租資料
  434. public function member_add()
  435. {
  436. $data = array
  437. (
  438. 'member_no' => $this->input->post('member_no', true),
  439. 'station_no' => $this->input->post('station_no', true),
  440. 'lpr' => strtoupper($this->input->post('lpr', true)),
  441. 'old_lpr' => strtoupper($this->input->post('old_lpr', true)),
  442. 'etag' => strtoupper($this->input->post('etag', true)),
  443. 'start_date' => $this->input->post('start_date', true),
  444. 'end_date' => $this->input->post('end_date', true),
  445. 'member_name' => $this->input->post('member_name', true),
  446. 'member_nick_name' => $this->input->post('member_name', true),
  447. 'mobile_no' => $this->input->post('mobile_no', true),
  448. 'member_id' => $this->input->post('member_id', true),
  449. 'contract_no' => $this->input->post('contract_no', true),
  450. 'amt' => $this->input->post('amt', true),
  451. 'tel_h' => $this->input->post('tel_h', true),
  452. 'tel_o' => $this->input->post('tel_o', true),
  453. 'addr' => $this->input->post('addr', true)
  454. );
  455. trigger_error("add:".print_r($data, true));
  456. if ($data['member_no'] == 0 || $data['old_lpr'] != $data['lpr'])
  457. {
  458. if ($this->carpark_model->check_lpr($data['lpr']) > 0)
  459. {
  460. echo '車牌重複, 請查明再輸入';
  461. exit;
  462. }
  463. }
  464. $this->carpark_model->member_add($data);
  465. echo 'ok';
  466. }
  467. // 查詢月租資料
  468. public function member_query()
  469. {
  470. $data = $this->carpark_model->member_query();
  471. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  472. }
  473. // 刪除月租資料
  474. public function member_delete()
  475. {
  476. $member_no = $this->input->post('member_no', true);
  477. $this->carpark_model->member_delete($member_no);
  478. echo 'ok';
  479. }
  480. // 進出場現況表
  481. public function cario_list()
  482. {
  483. $data = $this->carpark_model->cario_list();
  484. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  485. }
  486. // 進出場事件即時顯示
  487. public function cario_event()
  488. {
  489. set_time_limit(0);
  490. while(true)
  491. {
  492. }
  493. }
  494. // 顯示圖檔(http://url/carpark.html/pics/lpr_ABY8873_O_0_0_C_20150919210022)
  495. public function pics()
  496. {
  497. // ???
  498. readfile(CAR_PIC.$this->uri->segment(3).'/'.str_replace('/', '', $this->uri->segment(4)).'.jpg');
  499. }
  500. // 汽車開門
  501. public function opendoors()
  502. {
  503. $ivsno = $this->uri->segment(3);
  504. $lanes = array
  505. (
  506. 0 => array ('devno' => 0, 'temp' => 0, 'member' => 1), // 1號入口, temp:臨停, member:月租
  507. // 1 => array ('devno' => 0, 'temp' => 2, 'member' => 3), // 2號調撥入口
  508. 1 => array ('devno' => 1, 'temp' => 0, 'member' => 1), // 3號調撥出口
  509. 2 => array ('devno' => 1, 'temp' => 0, 'member' => 1), // 3號調撥出口
  510. 3 => array ('devno' => 1, 'temp' => 2, 'member' => 3) // 4號出口
  511. );
  512. $url = 'http://admin:99999999@192.168.10.53/cgi-bin/basic_setting.cgi?ID=1&';
  513. $member_tag = 'member'; // member:月租會員
  514. // 短路開柵欄
  515. @get_headers("{$url}OUTDEV={$lanes[$ivsno]['devno']}&OUTCH={$lanes[$ivsno][$member_tag]}&OUTSTATUS=1");
  516. usleep(400000); // 暫停0.4秒
  517. // 斷路, 車過關柵欄
  518. @get_headers("{$url}OUTDEV={$lanes[$ivsno]['devno']}&OUTCH={$lanes[$ivsno][$member_tag]}&OUTSTATUS=0");
  519. }
  520. // 調撥車道查詢
  521. public function reversible_lane_query()
  522. {
  523. $max_lane = 4; // 共幾個車道數
  524. for ($idx = 0; $idx < $max_lane; ++$idx)
  525. {
  526. $data[$idx] = file_get_contents("http://192.168.10.51:8090/cgi-bin/switcher.cgi?id={$idx}&action=9");
  527. }
  528. // $data = array(1, 1, 0, 1);
  529. echo json_encode($data);
  530. }
  531. // 車號入場查詢
  532. public function carin_lpr_query()
  533. {
  534. $lpr = $this->uri->segment(3);
  535. $data = $this->carpark_model->carin_lpr_query($lpr);
  536. echo json_encode($data);
  537. }
  538. // 以時間查詢入場資訊
  539. public function carin_time_query()
  540. {
  541. $time_query = $this->input->post('time_query', true);
  542. $minutes_range = $this->input->post('minutes_range', true);
  543. $data = $this->carpark_model->carin_time_query($time_query, $minutes_range);
  544. echo json_encode($data);
  545. }
  546. // 調撥車道設定
  547. public function reversible_lane_set()
  548. {
  549. $lane_no = $this->input->post('lane_no', true);
  550. $actions = $this->input->post('actions', true);
  551. $data = file_get_contents("http://192.168.10.51:8090/cgi-bin/switcher.cgi?id={$lane_no}&action={$actions}");
  552. echo "{$lane_no}|{$actions}|{$data}";
  553. }
  554. // 在席車位檢查未有入場資料清單
  555. public function pks_check_list()
  556. {
  557. $max_rows = $this->uri->segment(3, 100); // 一次讀取筆數, 預設為100筆
  558. $data = $this->carpark_model->pks_check_list($max_rows);
  559. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  560. }
  561. // 重設在席查核
  562. public function reset_pks_check()
  563. {
  564. $data = $this->carpark_model->reset_pks_check();
  565. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  566. }
  567. // 更正在席車號
  568. public function correct_pks_lpr()
  569. {
  570. $pksno = $this->uri->segment(3, 0); // 車格號碼
  571. $lpr = $this->uri->segment(4, 'NONE'); // 車號
  572. if ($pksno == 0 || $lpr == 'NONE')
  573. {
  574. echo json_encode(array('err' => 1, 'cario_no' => 0), JSON_UNESCAPED_UNICODE);
  575. }
  576. else
  577. {
  578. $data = $this->carpark_model->correct_pks_lpr($pksno, $lpr);
  579. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  580. }
  581. }
  582. // 入場車號查核在席無資料清單
  583. public function carin_check_list()
  584. {
  585. $max_rows = $this->uri->segment(3, 20); // 一次讀取筆數, 預設為100筆
  586. $data = $this->carpark_model->carin_check_list($max_rows);
  587. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  588. }
  589. // 更正入場車號
  590. public function correct_carin_lpr()
  591. {
  592. $cario_no = $this->uri->segment(3, 0); // 車格號碼
  593. $lpr = $this->uri->segment(4, 'NONE'); // 車號
  594. $in_time = urldecode($this->uri->segment(5, '')); // 入場時間
  595. $data = $this->carpark_model->correct_carin_lpr($cario_no, $lpr, $in_time);
  596. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  597. }
  598. // 查詢行動支付記錄
  599. public function tx_bill_query()
  600. {
  601. $data = $this->carpark_model->tx_bill_query();
  602. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  603. }
  604. // 查詢月租繳款機記錄
  605. public function tx_bill_ats_query()
  606. {
  607. $data = $this->carpark_model->tx_bill_ats_query();
  608. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  609. }
  610. // 查詢樓層在席群組
  611. public function pks_group_query()
  612. {
  613. $data = $this->carpark_model->pks_group_query();
  614. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  615. }
  616. // 微調剩餘車位數
  617. public function pks_availables_update()
  618. {
  619. $group_id = $this->uri->segment(3); // id
  620. $value = $this->uri->segment(4, 0); // value
  621. $station_no = $this->uri->segment(5); // station_no
  622. $data = $this->sync_data_model->pks_availables_update($group_id, $value, true, $station_no);
  623. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  624. }
  625. // 進出場觸發 888 呼叫
  626. /*
  627. public function sync_888()
  628. {
  629. $io = $this->uri->segment(3); // CI, CO, MI, MO
  630. if(empty($io))
  631. {
  632. echo 'io_not_found';
  633. exit;
  634. }
  635. $parms = array('io' => $io, 'etag' => __FUNCTION__, 'lpr' => __FUNCTION__);
  636. echo $this->sync_data_model->sync_888($parms);
  637. exit;
  638. }
  639. */
  640. public function test()
  641. {
  642. //echo `whoami`;
  643. //echo phpinfo();
  644. }
  645. // 博辰測試用
  646. // http://localhost/carpark.html/test_8068_002/APK7310
  647. public function test_8068_002()
  648. {
  649. $lpr_in = $this->uri->segment(3);
  650. $seqno = '00001';
  651. $cmd = '002';
  652. $token = '000000000';
  653. $lpr = str_pad($lpr_in, 7, '%', STR_PAD_LEFT);
  654. $in_time = '2000/01/01 00:00:00';
  655. $error_str = '';
  656. $service_port = 8068;
  657. $address = "192.168.10.201";
  658. /* Create a TCP/IP socket. */
  659. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  660. if ($socket === false) {
  661. echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
  662. $error_str .= "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
  663. } else {
  664. echo "OK.\n";
  665. }
  666. echo "Attempting to connect to '{$address}' on port '{$service_port}'...";
  667. $result = socket_connect($socket, $address, $service_port);
  668. if ($result === false) {
  669. echo "socket_connect() failed.\nReason: ({$result}) " . socket_strerror(socket_last_error($socket)) . "\n";
  670. $error_str .= "socket_connect() failed: reason: " . socket_strerror(socket_last_error($socket)) . "\n";
  671. } else {
  672. echo "OK.\n";
  673. }
  674. $in = pack('Ca5Ca3Ca9Ca7Ca19', 0x1c, $seqno, 0x1c, $cmd, 0x1c,
  675. $token, 0x1f, $lpr, 0x1f, $in_time
  676. );
  677. $out = '';
  678. echo "socket_write:";
  679. echo "{$in}<br/><br/>";
  680. if(!socket_write($socket, $in, strlen($in)))
  681. {
  682. echo('<p>Write failed</p>');
  683. $error_str .= "socket_write() failed: reason: " . socket_strerror(socket_last_error($socket)) . "\n";
  684. }
  685. echo "socket_write..OK..";
  686. echo "<br/><br/>socket_read:";
  687. $out = socket_read($socket, 2048) or die("Could not read server responsen");
  688. //while ($out = socket_read($socket, 2048)) {
  689. // echo $out;
  690. //}
  691. echo "{$out}<br/><br/>";
  692. echo "Closing socket...";
  693. socket_close($socket);
  694. echo "OK.\n\n";
  695. trigger_error($error_str);
  696. exit;
  697. }
  698. // test
  699. public function test_phpexcel()
  700. {
  701. $query_year = 2017;
  702. $query_month = 3;
  703. //$this->excel_model->export_cario_data($query_year, $query_month);
  704. $this->excel_model->export_members();
  705. }
  706. }