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

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