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

1103 lines
41KB

  1. <?php
  2. /*
  3. file: Admins_station.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', 'admins_station'); // 應用系統名稱
  11. define('PAGE_PATH', APP_BASE.'ci_application/views/'.APP_NAME.'/'); // path of views
  12. define('SERVER_URL', 'http://'.$_SERVER['HTTP_HOST'].'/'); // URL
  13. define('WEB_SERVICE', 'http://'.$_SERVER['SERVER_NAME'].':60133/?'); // web service port:60133
  14. define('WEB_LIB', SERVER_URL.'libs/'); // 網頁lib
  15. define('BOOTSTRAPS', WEB_LIB.'bootstrap_sb/'); // bootstrap lib
  16. define('APP_URL', SERVER_URL.APP_NAME.'.html/'); // controller路徑
  17. define('WEB_URL', SERVER_URL.APP_NAME.'/'); // 網頁路徑
  18. define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path
  19. // ----- 共用 header -----
  20. header('Access-Control-Allow-Origin: ' . 'http://'.$_SERVER['SERVER_NAME']); // nginx 80 轉 apache 60123
  21. class Admins_station extends CI_Controller
  22. {
  23. var $vars = array(); // 共用變數
  24. function __construct()
  25. {
  26. parent::__construct();
  27. // ----- 程式開發階段log設定 -----
  28. if (@ENVIRONMENT == 'development')
  29. {
  30. ini_set('display_errors', '1');
  31. //error_reporting(E_ALL ^ E_NOTICE);
  32. error_reporting(E_ALL);
  33. }
  34. set_error_handler(array($this, 'error_handler'), E_ALL); // 資料庫異動需做log
  35. // 共用記憶體
  36. $this->vars['mcache'] = new Memcache;
  37. $this->vars['mcache']->connect(MEMCACHE_HOST, MEMCACHE_PORT) or die ('Could not connect memcache');
  38. // mqtt subscribe
  39. $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_PORT, uniqid());
  40. if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); }
  41. // 中控
  42. $this->load->model('admins_station_model');
  43. $this->admins_station_model->init($this->vars);
  44. // 臨停
  45. $this->load->model('carpayment_model');
  46. $this->carpayment_model->init($this->vars);
  47. // 費率
  48. $this->load->model('txdata_model');
  49. // 報表
  50. $this->load->model('excel_model');
  51. $this->excel_model->init($this->vars);
  52. }
  53. // 發生錯誤時集中在此處理
  54. public function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
  55. {
  56. // ex: car_err://message....
  57. $log_msg = explode('://', $errstr);
  58. if (count($log_msg) > 1)
  59. {
  60. $log_file = LOG_PATH.$log_msg[0];
  61. $str = date('H:i:s')."|{$log_msg[1]}|{$errfile}|{$errline}|{$errno}\n";
  62. }
  63. else
  64. {
  65. $log_file = LOG_PATH.APP_NAME;
  66. $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  67. }
  68. //$str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  69. error_log($str, 3, $log_file . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  70. }
  71. // 顯示靜態網頁(html檔)
  72. protected function show_page($page_name, &$data = null)
  73. {
  74. $page_file = PAGE_PATH.$page_name.'.php';
  75. $last_modified_time = filemtime($page_file);
  76. /*
  77. // Cross-Origin Resource Sharing Header(允許跨網域連線)
  78. header('Access-Control-Allow-Origin: ' . SERVER_URL);
  79. header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
  80. header('Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept');
  81. */
  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. if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == APP_VERSION && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time)
  88. {
  89. header('HTTP/1.1 304 Not Modified');
  90. }
  91. else
  92. {
  93. $this->load->view(APP_NAME.'/'.$page_name, $data);
  94. }
  95. }
  96. public function index()
  97. {
  98. // 20170505 改由遠端中控
  99. echo '已停用';
  100. exit;
  101. $this->show_page('main_page');
  102. }
  103. // 送出html code
  104. public function get_html()
  105. {
  106. $data = array
  107. (
  108. 'company_no' => $this->input->post('company_no', true), // 場站統編
  109. 'hq_company_no' => '80682490'
  110. );
  111. $this->load->view(APP_NAME.'/'.$this->input->post('tag_name', true), $data);
  112. }
  113. // 登入帳密檢查
  114. public function login_verify()
  115. {
  116. $login_name = $this->input->post('login_name', true);
  117. $login_pswd = $this->input->post('login_pswd', true);
  118. $ok = $this->admins_station_model->login_verify($login_name, $login_pswd);
  119. if ($ok) // 帳密正確
  120. {
  121. $_SESSION['login_ck'] = uniqid();
  122. $data = array('rcode' => 'OK', 'ck' => $_SESSION['login_ck']);
  123. }
  124. else
  125. {
  126. $_SESSION['login_ck'] = 'NOLOGIN';
  127. $data = array('rcode' => 'NOLOGIN', 'ck' => $_SESSION['login_ck']);
  128. }
  129. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  130. }
  131. // 設定javascript初始值
  132. public function js_vars()
  133. {
  134. $data = $this->admins_station_model->get_init_vars();
  135. echo $data;
  136. }
  137. // 費率清單
  138. public function price_plan_query_all()
  139. {
  140. $data = $this->txdata_model->get_all_valid_price_plan(STATION_NO);
  141. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  142. }
  143. // 會員清單
  144. public function member_query_all()
  145. {
  146. $data = $this->admins_station_model->member_query_all();
  147. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  148. }
  149. // 待審核清單
  150. public function member_tx_check_query()
  151. {
  152. $data = $this->admins_station_model->member_tx_check_query();
  153. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  154. }
  155. // 已退款清單
  156. public function member_tx_refund_query()
  157. {
  158. $station_no = $this->input->post('station_no', true);
  159. $q_item = $this->input->post('q_item', true);
  160. $q_str = $this->input->post('q_str', true);
  161. $data = $this->admins_station_model->member_tx_refund_query($station_no, $q_item, $q_str);
  162. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  163. }
  164. // 取得轉租資訊
  165. public function member_refund_transfer_data_query()
  166. {
  167. $station_no = $this->input->post('station_no', true);
  168. $member_no = $this->input->post('member_no', true);
  169. $member_refund_id = $this->input->post('member_refund_id', true);
  170. $data = $this->admins_station_model->member_refund_transfer_data_query($station_no, $member_no, $member_refund_id);
  171. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  172. }
  173. // 押金保留,結清其它金額 (退租後)
  174. public function member_refund_keep_deposit()
  175. {
  176. $parms = array();
  177. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  178. $parms['member_refund_id'] = $this->input->post('member_refund_id', true); // 退租編號
  179. if(empty($parms['member_refund_id']) || empty($parms['station_no']))
  180. {
  181. echo '資料異常';
  182. exit;
  183. }
  184. echo $this->admins_station_model->member_refund_keep_deposit($parms);
  185. }
  186. // 結清所有金額 (退租後)
  187. public function member_refund_dismiss_all()
  188. {
  189. $parms = array();
  190. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  191. $parms['member_refund_id'] = $this->input->post('member_refund_id', true); // 退租編號
  192. if(empty($parms['member_refund_id']) || empty($parms['station_no']))
  193. {
  194. echo '資料異常';
  195. exit;
  196. }
  197. echo $this->admins_station_model->member_refund_dismiss_all($parms);
  198. }
  199. // 發票折讓 (退租後)
  200. public function refund_invoice_allowance()
  201. {
  202. $parms = array();
  203. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  204. $parms['member_no'] = $this->input->post('member_no', true); // 會員編號
  205. $parms['tx_bill_no'] = $this->input->post('tx_bill_no', true); // 帳單編號
  206. $parms['refund_amt'] = $this->input->post('refund_amt', true); // 折讓金額
  207. $parms['tx_no'] = $this->input->post('tx_no', true); // 交易編號
  208. $parms['company_no'] = $this->input->post('company_no', true); // 賣方統編
  209. if(empty($parms['member_no']) || empty($parms['station_no']) || empty($parms['tx_bill_no']) || empty($parms['tx_no']))
  210. {
  211. echo '資料異常';
  212. exit;
  213. }
  214. // 若賣方統編未設定, 預設拿場站統編
  215. if(empty($parms['company_no']))
  216. {
  217. $st_info = $this->vars['mcache']->get('st_info');
  218. $parms['company_no'] = $st_info['company_no'];
  219. }
  220. echo $this->admins_station_model->refund_invoice_allowance($parms);
  221. }
  222. // 臨停未結確認完成
  223. public function cario_temp_confirmed()
  224. {
  225. $parms = array();
  226. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  227. $parms['cario_no'] = $this->input->post('cario_no', true); // 進出編號
  228. $parms['remarks'] = $this->input->post('remarks', true); // 備註
  229. echo $this->admins_station_model->cario_temp_confirmed($parms);
  230. }
  231. // 審核完成
  232. public function member_tx_confirmed()
  233. {
  234. $parms = array();
  235. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  236. $parms['tx_no'] = $this->input->post('tx_no', true); // 交易編號
  237. $parms['verify_state'] = $this->input->post('verify_state', true); // 0:未審核, 1:人工審核完成
  238. //$parms['valid_time'] = $this->input->post('valid_time', true); // 有效期限
  239. $parms['remarks'] = $this->input->post('remarks', true); // 備註
  240. echo $this->admins_station_model->member_tx_confirmed($parms);
  241. }
  242. // 交易取消
  243. public function member_tx_cancel()
  244. {
  245. $parms = array();
  246. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  247. $parms['member_no'] = $this->input->post('member_no', true); // 會員編號
  248. $parms['tx_no'] = $this->input->post('tx_no', true); // 交易編號
  249. echo $this->admins_station_model->member_tx_cancel($parms);
  250. }
  251. // 會員查詢
  252. public function member_query()
  253. {
  254. $station_no = $this->input->post('station_no', true);
  255. $q_item = $this->input->post('q_item', true);
  256. $q_str = $this->input->post('q_str', true);
  257. $data = $this->admins_station_model->member_query($station_no, $q_item, $q_str);
  258. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  259. }
  260. // 交易查詢
  261. public function member_tx_query()
  262. {
  263. $station_no = $this->input->post('station_no', true);
  264. $member_no = $this->input->post('member_no', true);
  265. $data = $this->admins_station_model->member_tx_query($station_no, $member_no);
  266. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  267. }
  268. // 發票查詢
  269. public function member_tx_bill_query()
  270. {
  271. $station_no = $this->input->post('station_no', true);
  272. $tx_no = $this->input->post('tx_no', true);
  273. $verify_state_str = $this->input->post('verify_state_str', true);
  274. $invoice_state_str = $this->input->post('invoice_state_str', true);
  275. $tx_state_str = $this->input->post('tx_state_str', true);
  276. $tx_bill_no = $this->input->post('tx_bill_no', true);
  277. $member_refund_id = $this->input->post('member_refund_id', true);
  278. $data = $this->admins_station_model->member_tx_bill_query(
  279. $station_no, $tx_no, $verify_state_str, $invoice_state_str, $tx_state_str, $tx_bill_no, $member_refund_id);
  280. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  281. }
  282. // 退租發票查詢
  283. public function member_refund_bill_query()
  284. {
  285. $station_no = $this->input->post('station_no', true);
  286. $tx_no = $this->input->post('tx_no', true);
  287. $verify_state_str = $this->input->post('verify_state_str', true);
  288. $invoice_state_str = $this->input->post('invoice_state_str', true);
  289. $tx_state_str = $this->input->post('tx_state_str', true);
  290. $tx_bill_no = $this->input->post('tx_bill_no', true);
  291. $member_refund_id = $this->input->post('member_refund_id', true);
  292. $data = $this->admins_station_model->member_refund_bill_query(
  293. $station_no, $tx_no, $verify_state_str, $invoice_state_str, $tx_state_str, $tx_bill_no, $member_refund_id);
  294. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  295. }
  296. // 臨停未結清單
  297. public function cario_temp_not_finished_query_all()
  298. {
  299. $station_no = $this->input->post('station_no', true);
  300. $q_item = $this->input->post('q_item', true);
  301. $q_str = $this->input->post('q_str', true);
  302. $data = $this->carpayment_model->cario_temp_not_finished_query_all($station_no, $q_item, $q_str);
  303. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  304. }
  305. // response http
  306. protected function http_return($return_code, $type)
  307. {
  308. if ($type == 'text') echo $return_code;
  309. else echo json_encode($return_code, JSON_UNESCAPED_UNICODE);
  310. }
  311. // 讀取cookie內容
  312. protected function get_cookie($cookie_name)
  313. {
  314. if (empty($_COOKIE[$cookie_name])) return array();
  315. return(json_decode($_COOKIE[$cookie_name], true));
  316. }
  317. // 儲存cookie內容
  318. protected function save_cookie($cookie_name, $cookie_info)
  319. {
  320. return setcookie($cookie_name, json_encode($cookie_info, JSON_UNESCAPED_UNICODE), 0, '/');
  321. }
  322. // 月租資料同步
  323. /*
  324. public function rent_sync()
  325. {
  326. $station_no = $this->input->post('station_no', true);
  327. $start_date = $this->input->post('start_date', true);
  328. $end_date = $this->input->post('end_date', true);
  329. // $data = $this->admins_station_model->rent_sync($station_no, $start_date, $end_date);
  330. // print_r($data);
  331. }
  332. */
  333. // 顯示logs
  334. public function show_logs()
  335. {
  336. $lines = $this->uri->segment(3); // 顯示行數
  337. if (empty($lines)) $lines = 40; // 無行數參數, 預設為40行
  338. // echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><pre style="white-space: pre-wrap;">';
  339. echo '<html lang="zh-TW"><body><pre style="white-space: pre-wrap;">';
  340. passthru('/usr/bin/tail -n ' . $lines . ' ' . LOG_FILE); // 利用linux指令顯示倒數幾行的logs內容
  341. echo "\n----- " . LOG_FILE . ' -----';
  342. echo '</pre></body></html>';
  343. }
  344. // 將設定檔存入記憶體
  345. public function info2mem()
  346. {
  347. $data = $this->admins_station_model->get_info();
  348. foreach($data as $var => $values)
  349. {
  350. $this->mcache->set('i_'.$var, $values);
  351. }
  352. echo 'OK !';
  353. }
  354. // 將設定檔存入記憶體
  355. public function get_info()
  356. {
  357. echo $this->mcache->get('i_station_no');
  358. }
  359. // 新增月租資料
  360. public function member_add()
  361. {
  362. $start_date = $this->input->post('start_date', true);
  363. if(empty($start_date))
  364. {
  365. $start_date = $this->input->post('start_date_done', true);
  366. }
  367. $end_date = $this->input->post('end_date', true);
  368. if(empty($end_date))
  369. {
  370. $end_date = $this->input->post('end_date_done', true);
  371. }
  372. $demonth_start_date = $this->input->post('demonth_start_date', true);
  373. if(empty($demonth_start_date))
  374. {
  375. $demonth_start_date = $this->input->post('demonth_start_date_done', true);
  376. }
  377. $demonth_end_date = $this->input->post('demonth_end_date', true);
  378. if(empty($demonth_end_date))
  379. {
  380. $demonth_end_date = $this->input->post('demonth_end_date_done', true);
  381. }
  382. $data = array
  383. (
  384. 'member_no' => $this->input->post('member_no', true),
  385. 'station_no' => $this->input->post('station_no', true),
  386. 'lpr' => strtoupper($this->input->post('lpr', true)),
  387. 'old_lpr' => strtoupper($this->input->post('old_lpr', true)),
  388. 'etag' => strtoupper($this->input->post('etag', true)),
  389. 'start_date' => $start_date,
  390. 'end_date' => $end_date,
  391. 'park_time' => $this->input->post('park_time', true),
  392. 'member_name' => $this->input->post('member_name', true),
  393. 'member_nick_name' => $this->input->post('member_name', true),
  394. 'mobile_no' => $this->input->post('mobile_no', true),
  395. 'member_id' => $this->input->post('member_id', true),
  396. 'contract_no' => $this->input->post('contract_no', true), // 總公司 only ??
  397. 'member_company_no' => $this->input->post('member_company_no', true), // 買方統編(會員統編)
  398. 'company_no' => $this->input->post('company_no', true), // 賣方統編
  399. 'amt' => $this->input->post('amt', true),
  400. 'tel_h' => $this->input->post('tel_h', true),
  401. 'tel_o' => $this->input->post('tel_o', true),
  402. 'addr' => $this->input->post('addr', true),
  403. 'demonth_start_date' => $demonth_start_date,
  404. 'demonth_end_date' => $demonth_end_date,
  405. 'member_attr' => $this->input->post('member_attr', true),
  406. 'fee_period1' => $this->input->post('fee_period1', true),
  407. 'fee_period' => $this->input->post('fee_period', true),
  408. 'amt1' => $this->input->post('amt1', true),
  409. 'deposit' => $this->input->post('deposit', true),
  410. 'amt_tot' => $this->input->post('amt_tot', true),
  411. 'amt_accrued' => $this->input->post('amt_accrued', true),
  412. 'refund_transfer_id' => $this->input->post('refund_transfer_id', true), // 轉租來源編號
  413. 'refund_transfer_discount' => $this->input->post('refund_transfer_discount', true) // 轉租折扺金額
  414. );
  415. if( empty($data['station_no']) || empty($data['lpr']))
  416. {
  417. echo '資料異常';
  418. exit;
  419. }
  420. trigger_error("add:".print_r($data, true));
  421. //if ($data['member_no'] == 0 || $data['old_lpr'] != $data['lpr'])
  422. if ($data['member_no'] == 0)
  423. {
  424. // 本次操作為新增車牌, 開始驗証是否能繼續
  425. if( empty($data['start_date']) || empty($data['end_date']) ||
  426. empty($data['demonth_start_date']) || empty($data['demonth_end_date']))
  427. {
  428. echo '日期資料異常';
  429. exit;
  430. }
  431. if (!empty($data['refund_transfer_id']))
  432. {
  433. // 轉租戶 (直接進入新增流程, 新資料蓋掉舊資料)
  434. }
  435. else
  436. {
  437. // 一般戶, 再確認一次退租名單是否重複
  438. if ($this->admins_station_model->check_refund_lpr($data['lpr']) > 0)
  439. {
  440. echo '此車牌尚有押金未轉移,請進行轉租';
  441. exit;
  442. }
  443. // 已退租且互不相欠的一般戶 (直接進入新增流程, 新資料蓋掉舊資料)
  444. }
  445. }
  446. else
  447. {
  448. // 本次操作為修改記錄, 開始驗証是否能繼續
  449. // 一般戶, 確認是否存在未處理的退租金額
  450. if ($this->admins_station_model->check_refund_member_no($data['member_no']) > 0)
  451. {
  452. echo '此會員尚有押金未轉移,請進行轉租';
  453. exit;
  454. }
  455. }
  456. // 取得月租費率設定
  457. $rents_arr = $this->get_rents_arr();
  458. echo json_encode($this->admins_station_model->member_add($data, $rents_arr), JSON_UNESCAPED_UNICODE);
  459. }
  460. // 刪除月租資料
  461. /*
  462. public function member_delete()
  463. {
  464. $member_no = $this->input->post('member_no', true);
  465. $station_no = $this->input->post('station_no', true);
  466. if(empty($member_no) || empty($station_no))
  467. {
  468. echo '資料異常';
  469. exit;
  470. }
  471. echo $this->admins_station_model->member_delete($station_no, $member_no);
  472. }
  473. */
  474. // 顯示圖檔(http://url/carpark.html/pics/lpr_ABY8873_O_0_0_C_20150919210022)
  475. public function pics()
  476. {
  477. // ???
  478. readfile(CAR_PIC.$this->uri->segment(3).'/'.str_replace('/', '', $this->uri->segment(4)).'.jpg');
  479. }
  480. // 說明: 手開發票
  481. public function hand_first_rents_payment()
  482. {
  483. $parms = array();
  484. $parms['tx_no'] = $this->input->post('tx_no', true); // 交易編號
  485. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  486. $parms['member_no'] = $this->input->post('member_no', true); // 會員編號
  487. $parms['member_company_no'] = $this->input->post('member_company_no', true); // 買方統編
  488. $parms['company_no'] = $this->input->post('company_no', true); // 賣方統編
  489. $parms['amt1'] = $this->input->post('amt1', true); // 首期租金
  490. $parms['amt'] = $this->input->post('amt', true); // 本期租金
  491. $parms['invoice_track'] = $this->input->post('invoice_track', true); // * 發票字軌
  492. $parms['invoice_no'] = $this->input->post('invoice_no', true); // * 發票號碼
  493. $parms['invoice_type'] = 1; // 手開發票
  494. $parms['invoice_amt'] = $this->input->post('invoice_amt', true); // * 發票金額
  495. $parms['tx_bill_no'] = $this->input->post('tx_bill_no', true); // 帳單編號
  496. if(empty($parms['tx_bill_no']) || empty($parms['tx_no']) || empty($parms['member_no']) || empty($parms['station_no']) )
  497. {
  498. echo '資料異常';
  499. exit;
  500. }
  501. if(empty($parms['invoice_track']) || empty($parms['invoice_no']))
  502. {
  503. echo '查無發票資訊';
  504. exit;
  505. }
  506. if(empty($parms['invoice_amt']))
  507. {
  508. echo '查無金額資訊';
  509. exit;
  510. }
  511. // 若賣方統編未設定, 預設拿場站統編
  512. if(empty($parms['company_no']))
  513. {
  514. $st_info = $this->vars['mcache']->get('st_info');
  515. $parms['company_no'] = $st_info['company_no'];
  516. }
  517. // 確認是否存在退租記錄
  518. if ($this->admins_station_model->check_refund_member_no_exist($parms['member_no']) > 0)
  519. {
  520. echo '此會員已退租';
  521. exit;
  522. }
  523. echo $this->admins_station_model->first_rents_payment($parms);
  524. }
  525. // 說明: 1.新建立直接列印發票、 2.列印發票 (TODO: 待接上歐付寶)
  526. public function first_rents_payment()
  527. {
  528. $parms = array();
  529. $parms['tx_no'] = $this->input->post('tx_no', true); // 交易編號
  530. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  531. $parms['member_no'] = $this->input->post('member_no', true); // 會員編號
  532. $parms['member_attr'] = $this->input->post('member_attr', true); // 會員身份
  533. $parms['member_company_no'] = $this->input->post('member_company_no', true); // 買方統編
  534. $parms['company_no'] = $this->input->post('company_no', true); // 賣方統編
  535. $parms['amt1'] = $this->input->post('amt1', true); // 首期租金
  536. $parms['amt'] = $this->input->post('amt', true); // 本期租金
  537. $parms['invoice_amt'] = $this->input->post('invoice_amt', true); // * 發票金額
  538. $parms['tx_bill_no'] = $this->input->post('tx_bill_no', true); // 帳單編號
  539. $parms['email'] = $this->input->post('email', true); // 發票通知信箱
  540. $parms['mobile'] = $this->input->post('mobile', true); // 發票通知簡訊
  541. if(empty($parms['tx_bill_no']) || empty($parms['tx_no']) || empty($parms['member_no']) || empty($parms['station_no']))
  542. {
  543. echo '資料異常';
  544. exit;
  545. }
  546. if(empty($parms['invoice_amt']))
  547. {
  548. echo '查無金額資訊';
  549. exit;
  550. }
  551. // 若賣方統編未設定, 預設拿場站統編
  552. if(empty($parms['company_no']))
  553. {
  554. $st_info = $this->vars['mcache']->get('st_info');
  555. $parms['company_no'] = $st_info['company_no'];
  556. }
  557. // 若發票通知信箱未設定
  558. if(empty($parms['email']))
  559. {
  560. $parms['email'] = 'altob.rd@gmail.com'; // 預設信箱
  561. }
  562. // 若發票通知簡訊未設定
  563. if(empty($parms['mobile']))
  564. {
  565. $parms['mobile'] = ''; // 預設手機
  566. }
  567. // 確認是否存在退租記錄
  568. if ($this->admins_station_model->check_refund_member_no_exist($parms['member_no']) > 0)
  569. {
  570. echo '此會員已退租';
  571. exit;
  572. }
  573. echo $this->admins_station_model->first_rents_payment($parms);
  574. }
  575. // 說明: 繳租
  576. public function rents_payment()
  577. {
  578. $parms = array();
  579. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  580. $parms['member_no'] = $this->input->post('member_no', true); // 會員編號
  581. $parms['member_attr'] = $this->input->post('member_attr', true); // 會員身份
  582. $parms['lpr'] = $this->input->post('lpr', true); // 車牌號碼
  583. $parms['member_company_no'] = $this->input->post('member_company_no', true); // 買方統編
  584. $parms['company_no'] = $this->input->post('company_no', true); // 賣方統編
  585. $parms['fee_period'] = $this->input->post('fee_period', true); // 本期繳期
  586. $parms['fee_period_last'] = $this->input->post('fee_period_last', true); // 上期繳期
  587. $parms['amt'] = $this->input->post('amt', true); // 本期租金
  588. $parms['amt_last'] = $this->input->post('amt_last', true); // 上期租金
  589. $parms['end_date'] = $this->input->post('end_date', true); // 本期截止日
  590. $parms['start_date_last'] = $this->input->post('start_date_last', true); // 上期截止日
  591. $parms['end_date_last'] = $this->input->post('end_date_last', true); // 上期截止日
  592. if(empty($parms['member_no']) || empty($parms['station_no']))
  593. {
  594. echo '資料異常';
  595. exit;
  596. }
  597. if(empty($parms['end_date']))
  598. {
  599. echo '截止日異常';
  600. exit;
  601. }
  602. // 若賣方統編未設定, 預設拿場站統編
  603. if(empty($parms['company_no']))
  604. {
  605. $st_info = $this->vars['mcache']->get('st_info');
  606. $parms['company_no'] = $st_info['company_no'];
  607. }
  608. // 確認是否存在退租記錄
  609. if ($this->admins_station_model->check_refund_member_no_exist($parms['member_no']) > 0)
  610. {
  611. echo '此會員已退租';
  612. exit;
  613. }
  614. $rents_arr = $this->get_rents_arr(); // 費率設定
  615. echo $this->admins_station_model->rents_payment($parms, $rents_arr);
  616. }
  617. // 退租
  618. public function stop_rents_payment()
  619. {
  620. $parms = array();
  621. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  622. $parms['member_no'] = $this->input->post('member_no', true); // 會員編號
  623. $parms['stop_date'] = $this->input->post('stop_date', true); // 結束日
  624. $parms['tot_amt'] = $this->input->post('tot_amt', true); // 總金額
  625. if(empty($parms['member_no']) || empty($parms['station_no']) || empty($parms['stop_date']))
  626. {
  627. echo '資料異常';
  628. exit;
  629. }
  630. // 確認是否存在退租記錄
  631. if ($this->admins_station_model->check_refund_member_no_exist($parms['member_no']) > 0)
  632. {
  633. echo '此會員已退租';
  634. exit;
  635. }
  636. $rents_arr = $this->get_rents_arr(); // 費率設定
  637. echo $this->admins_station_model->stop_rents_payment($parms, $rents_arr);
  638. }
  639. // 接續開立發票
  640. public function next_tx_bill()
  641. {
  642. $parms = array();
  643. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  644. $parms['member_no'] = $this->input->post('member_no', true); // 會員編號
  645. $parms['tx_bill_no'] = $this->input->post('tx_bill_no', true); // 帳單編號
  646. $parms['remain_amt'] = $this->input->post('remain_amt', true); // 剩餘金額
  647. $parms['tx_no'] = $this->input->post('tx_no', true); // 交易編號
  648. $parms['company_no'] = $this->input->post('company_no', true); // 賣方統編
  649. if(empty($parms['member_no']) || empty($parms['station_no']) || empty($parms['tx_bill_no']) || empty($parms['tx_no']))
  650. {
  651. echo '資料異常';
  652. exit;
  653. }
  654. // 若賣方統編未設定, 預設拿場站統編
  655. if(empty($parms['company_no']))
  656. {
  657. $st_info = $this->vars['mcache']->get('st_info');
  658. $parms['company_no'] = $st_info['company_no'];
  659. }
  660. // 確認是否存在退租記錄
  661. if ($this->admins_station_model->check_refund_member_no_exist($parms['member_no']) > 0)
  662. {
  663. echo '此會員已退租';
  664. exit;
  665. }
  666. $rents_arr = $this->get_rents_arr(); // 費率設定
  667. echo $this->admins_station_model->next_tx_bill($parms, $rents_arr);
  668. }
  669. // 停權或啟動
  670. public function suspended()
  671. {
  672. $parms = array();
  673. $parms['station_no'] = $this->input->post('station_no', true); // 會員編號
  674. $parms['member_no'] = $this->input->post('member_no', true); // 會員編號
  675. $parms['suspended'] = $this->input->post('suspended', true); // 0:啟用, 1:停權
  676. echo $this->admins_station_model->suspended($parms);
  677. }
  678. // 取得費率設定
  679. public function get_rents_json()
  680. {
  681. echo json_encode($this->get_rents_arr(), JSON_UNESCAPED_UNICODE);
  682. }
  683. // 取得費率設定
  684. function get_rents_arr()
  685. {
  686. $rents_arr = array();
  687. $txdata_result = $this->txdata_model->get_price_plan(STATION_NO, 1);
  688. //trigger_error('tx: '. print_r(json_decode($txdata_result[0]['price_plan'], true), true));
  689. if(!empty($txdata_result[0]['price_plan']))
  690. {
  691. foreach (json_decode($txdata_result[0]['price_plan'], true) as $key => $val)
  692. {
  693. $p_keys = explode('_', $key);
  694. if(!array_key_exists($p_keys[0], $rents_arr))
  695. {
  696. $rents_arr[$p_keys[0]] = array();
  697. }
  698. $rents_arr[$p_keys[0]][$p_keys[1]] = $val;
  699. }
  700. }
  701. return $rents_arr;
  702. }
  703. // 同步場站費率
  704. public function sync_price_plan()
  705. {
  706. echo $this->txdata_model->sync_price_plan();
  707. }
  708. // 計算退租金額
  709. public function calculate_stop_rents_amt()
  710. {
  711. $parms = array();
  712. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  713. $parms['member_no'] = $this->input->post('member_no', true); // 會員編號
  714. $parms['stop_date'] = $this->input->post('stop_date', true); // 結束日
  715. $rents_arr = $this->get_rents_arr(); // 費率設定
  716. // 根據會員現況算出所有可退金額
  717. $data = $this->admins_station_model->calculate_stop_rents_amt($parms, $rents_arr);
  718. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  719. }
  720. // 計算月租金額
  721. public function calculate_rents_amt()
  722. {
  723. $rents_arr = $this->get_rents_arr(); // 費率設定
  724. $station_no = $this->input->post('station_no', true); // 場站編號
  725. $demonth_start_date = $this->input->post('demonth_start_date', true); // 不足月起租日
  726. $member_attr = $this->input->post('member_attr', true); // 會員身份類別
  727. $period_1 = $this->input->post('period_1', true); // 首期繳期
  728. $period_2 = $this->input->post('period_2', true); // 例行繳期
  729. // 當傳入不足月開始日為當月第一天時,視為一個足月 2017-02-15 updated
  730. if(date_parse_from_format("Y-m-d", $demonth_start_date)['day'] == 1)
  731. {
  732. $demonth_end_date = $demonth_start_date; // 不足月結束日 (跳過不足月)
  733. $start_date = $demonth_start_date; // 足月起租日 (跳過不足月)
  734. }
  735. else
  736. {
  737. $demonth_end_date = (new DateTime($demonth_start_date))->format('Y-m-t'); // 不足月結束日
  738. $start_date = date('Y-m-d', strtotime("+1 days", strtotime($demonth_end_date))); // 足月起租日
  739. }
  740. // 第二版: 繳期直接算 2017-04-13 updated
  741. $period_month_bias = ($period_2 < 1) ? 0 : $period_2 - 1;
  742. $end_date = date('Y-m-t', strtotime("+{$period_month_bias} months", strtotime($start_date)));
  743. /*
  744. // 第一版: 根據繳期算出所有參數
  745. $start_date_year = date_parse_from_format("Y-m-d", $start_date)['year'];
  746. $start_date_month = date_parse_from_format("Y-m-d", $start_date)['month'];
  747. for($month = 0 ; $month <= 12 ; $month += $period_2)
  748. {
  749. $end_date = null;
  750. if($month >= $start_date_month)
  751. {
  752. $end_date = (new DateTime($start_date_year.'-'.$month))->format('Y-m-t'); // 足月結束日
  753. break;
  754. }
  755. }
  756. if(empty($end_date))
  757. {
  758. // 若有異常繳期, 拿當月最後一天為終止日
  759. $end_date = (new DateTime($start_date_year.'-' . $start_date_month))->format('Y-m-t');
  760. }
  761. */
  762. if ($member_attr == 250)
  763. {
  764. $amt1 = 0; // 不足月 (VIP)
  765. $amt2 = 0; // 足月 (VIP)
  766. }
  767. else
  768. {
  769. // 不足月計算
  770. $date1 = new DateTime($demonth_start_date);
  771. $date2 = new DateTime($demonth_end_date);
  772. // 當傳入不足月開始日為當月第一天時,視為一個足月 2017-02-15 updated
  773. if(date_parse_from_format("Y-m-d", $demonth_start_date)['day'] == 1)
  774. {
  775. $demonth_days = 0;
  776. }
  777. else
  778. {
  779. $demonth_days = $date2->diff($date1)->format("%a") + 1; // 不足月天數
  780. }
  781. $demonth_amt = $rents_arr[$period_1][$member_attr];
  782. $amt1 = round($demonth_amt * $demonth_days / $rents_arr[$period_1][0]);
  783. $amt1 = ($amt1 > $demonth_amt) ? $demonth_amt : $amt1;
  784. trigger_error("days:{$demonth_days}|de_amt:{$demonth_amt}|amt1:{$amt1}");
  785. // 起始日若為空, 就自動回填
  786. //$demonth_start_date = $date1->format('Y-m-d');
  787. // 足月計算
  788. $date1a = new DateTime($start_date);
  789. $date2a = new DateTime($end_date);
  790. $amonth_days = $date2a->diff($date1a)->format("%a") + 1; // 足月天數
  791. $amonth_amt = $rents_arr[$period_2][$member_attr];
  792. // 第一版: 依天數拆分
  793. //$amt2 = round($amonth_amt * $amonth_days / $rents_arr[$period_2][0]);
  794. //$amt2 = ($amt2 > $amonth_amt) ? $amonth_amt : $amt2;
  795. //$amonth_months = $date2a->diff($date1a)->format("%m"); // 足月月數 (gg: 測試後有問題)
  796. // 第二版: 依月數拆分 2017-02-13 updated
  797. //$date1a_month = $date1a->format("m");
  798. //$date2a_month = $date2a->format("m");
  799. //$amonth_months = $date2a_month - $date1a_month + 1;
  800. // 第三版: 繳期直接算 2017-04-13 updated
  801. $amonth_months = $period_2;
  802. $amt2 = round($amonth_amt * $amonth_months / $period_2);
  803. $amt2 = ($amt2 > $amonth_amt) ? $amonth_amt : $amt2;
  804. trigger_error("days:{$amonth_days}|a_amt:{$amonth_amt}|amt2:{$amt2}");
  805. }
  806. // 回傳參數
  807. $amt_arr['rents_deposit'] = $rents_arr[0][0]; // 押金
  808. $amt_arr['demonth_start_date'] = $demonth_start_date; // 不足月起租日
  809. $amt_arr['demonth_end_date'] = $demonth_end_date; // 不足月結束日
  810. $amt_arr['start_date'] = $start_date; // 足月起租日
  811. $amt_arr['end_date'] = $end_date; // 足月結束日
  812. $amt_arr['rents_amt1'] = $amt1; // 不足月:租金
  813. $amt_arr['demonth_amt'] = $demonth_amt; // 不足月:繳期總額
  814. $amt_arr['demonth_days'] = $demonth_days; // 不足月:天數
  815. $amt_arr['demonth_days_total'] = $rents_arr[$period_1][0]; // 不足月:總天數
  816. $amt_arr['rents_amt2'] = $amt2; // 足月:租金
  817. $amt_arr['amonth_amt'] = $amonth_amt; // 足月:繳期總額
  818. $amt_arr['amonth_days'] = $amonth_days; // 足月:天數
  819. $amt_arr['amonth_days_total'] = $rents_arr[$period_2][0]; // 足月:總天數
  820. $amt_arr['amonth_months'] = $amonth_months; // 足月:月數 2017-02-13 updated
  821. $amt_arr['amonth_months_total'] = $period_2; // 足月:總月數 2017-02-13 updated
  822. echo json_encode($amt_arr, JSON_UNESCAPED_UNICODE);
  823. }
  824. // 設定關帳時間點
  825. public function set_check_point()
  826. {
  827. $parms = array();
  828. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  829. $parms['check_time'] = $this->input->post('check_point_time', true); // 時間
  830. $parms['remarks'] = $this->input->post('remarks', true); // 備註
  831. echo $this->admins_station_model->set_check_point($parms);
  832. }
  833. // 關帳查詢
  834. public function check_point_query()
  835. {
  836. $parms = array();
  837. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  838. $parms['check_point_time_from'] = $this->input->post('check_point_time_from', true); // 開始時間
  839. $parms['check_point_time_to'] = $this->input->post('check_point_time_to', true); // 結束時間
  840. $data = $this->admins_station_model->check_point_query($parms);
  841. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  842. }
  843. // 關帳查詢(明細)
  844. public function check_point_detail_query()
  845. {
  846. $parms = array();
  847. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  848. $parms['check_time_no'] = $this->input->post('check_time_no', true); //
  849. $parms['check_time_last_no'] = $this->input->post('check_time_last_no', true); //
  850. $data = $this->admins_station_model->check_point_detail_query($parms);
  851. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  852. }
  853. // 電子發票查詢
  854. public function member_invoice_query()
  855. {
  856. $parms = array();
  857. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  858. $parms['member_invoice_time_from'] = $this->input->post('member_invoice_time_from', true); // 開始時間
  859. $parms['member_invoice_time_to'] = $this->input->post('member_invoice_time_to', true); // 結束時間
  860. $data = $this->admins_station_model->member_invoice_query($parms);
  861. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  862. }
  863. // 電子發票作廢
  864. public function member_invoice_void()
  865. {
  866. $parms = array();
  867. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  868. $parms['invoice_no'] = $this->input->post('invoice_no', true); // 發票號碼
  869. $parms['order_no'] = $this->input->post('order_no', true); // 訂單編號
  870. echo $this->admins_station_model->member_invoice_void($parms);
  871. }
  872. // 批次延時
  873. public function member_tx_check_list_confirm_batch()
  874. {
  875. $parms = array();
  876. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  877. $parms['tx_no_str'] = $this->input->post('tx_no_str', true); // 交易代號字串
  878. $parms['member_no_str'] = $this->input->post('member_no_str', true); // 會員代號字串
  879. $parms['day'] = $this->input->post('day', true); // 延期天數
  880. echo $this->admins_station_model->member_tx_check_list_confirm_batch($parms);
  881. }
  882. // 切換賣方統編
  883. public function switch_company_no()
  884. {
  885. $parms = array();
  886. $parms['station_no'] = $this->input->post('station_no', true); // 場站編號
  887. $parms['tx_bill_no'] = $this->input->post('tx_bill_no', true); // 帳單編號
  888. $parms['company_no'] = $this->input->post('company_no', true); // 賣方統編
  889. echo $this->admins_station_model->switch_company_no($parms);
  890. }
  891. // 取得停車時段字串
  892. public function get_parktime_str()
  893. {
  894. $data = $this->admins_station_model->get_parktime_str();
  895. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  896. }
  897. // 取得未同步資料筆數
  898. public function get_un_synced_count()
  899. {
  900. $data = $this->admins_station_model->get_un_synced_count(STATION_NO);
  901. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  902. }
  903. public function do_sync_batch_100()
  904. {
  905. $this->admins_station_model->try_sync_batch(STATION_NO, 100);
  906. }
  907. // 手動 sync
  908. public function do_sync_batch()
  909. {
  910. $this->admins_station_model->try_sync_batch(STATION_NO, 1);
  911. echo STATION_NO .'..ok';
  912. }
  913. // 報表:匯出會員資料
  914. public function export_members()
  915. {
  916. $this->excel_model->export_members();
  917. }
  918. public function test()
  919. {
  920. echo 'zzz';
  921. }
  922. public function test_check_refund_lpr()
  923. {
  924. $lpr = $this->uri->segment(3);
  925. echo json_encode($this->admins_station_model->check_refund_lpr($lpr), JSON_UNESCAPED_UNICODE);
  926. }
  927. }