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.

261 rinda
9.5KB

  1. <?php
  2. /*
  3. file: Allpay_invoice.php 歐付寶電子發票
  4. */
  5. if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  6. // ----- 定義常數(路徑, cache秒數) -----
  7. define('APP_VERSION', '100'); // 版本號
  8. define('MAX_AGE', 604800); // cache秒數, 此定義1個月
  9. define('APP_NAME', 'allpay_invoice'); // 應用系統名稱
  10. define('PAGE_PATH', APP_BASE.'ci_application/views/'.APP_NAME.'/'); // path of views
  11. define('SERVER_URL', 'http://'.$_SERVER['HTTP_HOST'].'/'); // URL
  12. define('WEB_SERVICE', 'http://'.$_SERVER['SERVER_NAME'].':60133/?'); // web service port:60133
  13. define('WEB_LIB', SERVER_URL.'libs/'); // 網頁lib
  14. define('BOOTSTRAPS', WEB_LIB.'bootstrap_sb/'); // bootstrap lib
  15. define('APP_URL', SERVER_URL.APP_NAME.'.html/'); // controller路徑
  16. define('WEB_URL', SERVER_URL.APP_NAME.'/'); // 網頁路徑
  17. define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path
  18. class Allpay_invoice 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->load->model('allpay_invoice_model');
  34. }
  35. // 發生錯誤時集中在此處理
  36. public function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
  37. {
  38. // ex: car_err://message....
  39. $log_msg = explode('://', $errstr);
  40. if (count($log_msg) > 1)
  41. {
  42. $log_file = LOG_PATH.$log_msg[0];
  43. $str = date('H:i:s')."|{$log_msg[1]}|{$errfile}|{$errline}|{$errno}\n";
  44. }
  45. else
  46. {
  47. $log_file = LOG_PATH.APP_NAME;
  48. $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  49. }
  50. $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  51. error_log($str, 3, $log_file . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  52. }
  53. // 顯示靜態網頁(html檔)
  54. protected function show_page($page_name, &$data = null)
  55. {
  56. $page_file = PAGE_PATH.$page_name.'.php';
  57. $last_modified_time = filemtime($page_file);
  58. /*
  59. // Cross-Origin Resource Sharing Header(允許跨網域連線)
  60. header('Access-Control-Allow-Origin: ' . SERVER_URL);
  61. header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
  62. header('Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept');
  63. */
  64. // 若檔案修改時間沒有異動, 或版本無異動, 通知瀏覽器使用cache, 不再下傳網頁
  65. // header('Cache-Control:max-age='.MAX_AGE); // cache 1個月
  66. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_modified_time).' GMT');
  67. header('Etag: '. APP_VERSION);
  68. header('Cache-Control: public');
  69. if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == APP_VERSION && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time)
  70. {
  71. header('HTTP/1.1 304 Not Modified');
  72. }
  73. else
  74. {
  75. $this->load->view(APP_NAME.'/'.$page_name, $data);
  76. }
  77. }
  78. public function index()
  79. {
  80. $this->show_page('main_page');
  81. }
  82. /*
  83. // step 1: 建立待開記錄
  84. public function test_step1()
  85. {
  86. $station_no = 54321;
  87. $tx_bill_no = 12;
  88. $amt = 1600;
  89. $data = $this->allpay_invoice_model->test_step1_init_bill($station_no, $tx_bill_no, $amt);
  90. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  91. }
  92. // step 2: 開立發票參數
  93. public function test_step2()
  94. {
  95. $order_no = '14906858560000000012';
  96. $company_no = 0;
  97. $email = 'saylxxx@gmail.com';
  98. $mobile = '0953034986';
  99. $invoice_receiver = 0;
  100. $data = $this->allpay_invoice_model->test_step2_submit_purchase($order_no, $company_no, $email, $mobile, $invoice_receiver);
  101. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  102. }
  103. // step 1: 建立待開記錄與參數
  104. public function test_step1_step2_submit()
  105. {
  106. $station_no = 54321;
  107. $tx_bill_no = 12;
  108. $amt = 1600;
  109. $company_no = 0;
  110. $email = 'saylxxx@gmail.com';
  111. $mobile = '0953034986';
  112. $invoice_receiver = 0;
  113. $data = $this->allpay_invoice_model->test_step1_step2_submit(
  114. $station_no, $tx_bill_no, $amt,
  115. $company_no, $email, $mobile, $invoice_receiver);
  116. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  117. }
  118. // step 3: 開立發票
  119. public function test_step3()
  120. {
  121. $order_no = '14906866680000000012';
  122. $amt = 1600;
  123. $data = $this->allpay_invoice_model->invoice_issue_for_tx_bill_ats($order_no, $amt);
  124. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  125. }
  126. // 測試:M.1 建立月租系統發票待開記錄
  127. public function test_create_member_tx_bill_record()
  128. {
  129. $station_no = 54321;
  130. $tx_bill_no = 12;
  131. $amt = 1600;
  132. $company_no = 0;
  133. $email = 'saylxxx@gmail.com';
  134. $mobile = '0953034986';
  135. $data = $this->allpay_invoice_model->create_member_tx_bill_record($station_no, $tx_bill_no, $amt, $company_no, $email, $mobile);
  136. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  137. // 回傳, 要記下 order_no
  138. // {"invoice_remark":"停車費用帳單","order_no":"14906884740000000012","station_no":54321,"amt":1600,"email":"saylxxx@gmail.com","mobile":"0953034986","status":1,"tx_time":"2017\/03\/28 16:07:54","tx_type":100}
  139. }
  140. // 測試:M.2 開立月租系統待開發票
  141. public function test_create_member_tx_bill_invoice()
  142. {
  143. $order_no = '14906884740000000012';
  144. $amt = 1600;
  145. $data = $this->allpay_invoice_model->create_member_tx_bill_invoice($order_no, $amt);
  146. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  147. // 回傳
  148. // {"invoice_no":"TM00012802","result_code":"OK","result_msg":"成功"}
  149. }
  150. // 測試:作廢發票
  151. public function test_invoice_void()
  152. {
  153. $invoice_no = 'TM00012665';
  154. $reason_str = 'test';
  155. $data = $this->allpay_invoice_model->invoice_void($invoice_no, $reason_str);
  156. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  157. }
  158. // 測試:作廢月租系統發票
  159. public function test_void_member_tx_bill_invoice()
  160. {
  161. $station_no = "54321";
  162. $order_no = "14906958880000000025";
  163. $invoice_no = "TM00012805";
  164. $data = $this->allpay_invoice_model->void_member_tx_bill_invoice($station_no, $order_no, $invoice_no);
  165. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  166. }
  167. // 測試:開立折讓
  168. public function test_invoice_allowance()
  169. {
  170. $invoice_no = 'TM00012665';
  171. $allowance_amt = 1600;
  172. $data = $this->allpay_invoice_model->invoice_allowance($invoice_no, $allowance_amt);
  173. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  174. }
  175. */
  176. public function test_curl()
  177. {
  178. $station_no = 54321;
  179. $tx_bill_no = 25;
  180. $amt = 2640;
  181. $company_no = 0;
  182. $email = 'saylxxx@gmail.com';
  183. $mobile = '0953034986';
  184. $data = $this->allpay_invoice_model->test_curl($station_no, $tx_bill_no, $amt, $company_no, $email, $mobile);
  185. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  186. }
  187. // 開立月租系統發票
  188. public function create_member_tx_bill_invoice()
  189. {
  190. $station_no = $this->input->post('station_no', true); // 場站編號
  191. $tx_bill_no = $this->input->post('tx_bill_no', true); // 會員交易帳單代號
  192. $amt = $this->input->post('amt', true); // 金額
  193. $member_company_no = $this->input->post('member_company_no', true); // 買方統編
  194. $company_no = $this->input->post('company_no', true); // 賣方統編
  195. $email = $this->input->post('email', true); // 通知信箱
  196. $mobile = $this->input->post('mobile', true); // 通知簡訊
  197. $lpr = $this->input->post('lpr', true); // 車牌號碼
  198. $data = $this->allpay_invoice_model->create_member_tx_bill_invoice($station_no, $tx_bill_no, $amt, $member_company_no, $company_no, $email, $mobile, $lpr);
  199. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  200. }
  201. // 作廢月租系統發票
  202. public function void_member_tx_bill_invoice()
  203. {
  204. $station_no = $this->input->post('station_no', true); // 場站編號
  205. $order_no = $this->input->post('order_no', true); // 訂單編號
  206. $invoice_no = $this->input->post('invoice_no', true); // 發票號碼
  207. $data = $this->allpay_invoice_model->void_member_tx_bill_invoice($station_no, $order_no, $invoice_no);
  208. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  209. }
  210. // 折讓月租系統發票
  211. public function allowance_member_tx_bill_invoice()
  212. {
  213. $station_no = $this->input->post('station_no', true); // 場站編號
  214. $invoice_no = $this->input->post('invoice_no', true); // 發票號碼
  215. $allowance_amt = $this->input->post('allowance_amt', true); // 折讓金額
  216. $data = $this->allpay_invoice_model->allowance_member_tx_bill_invoice($station_no, $invoice_no, $allowance_amt);
  217. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  218. }
  219. // 測試:作廢折讓
  220. public function test_allowance_void()
  221. {
  222. $invoice_no = 'TM00012665';
  223. $allowance_no = '2017032814257398';
  224. $reason_str = 'test';
  225. $data = $this->allpay_invoice_model->allowance_void($invoice_no, $allowance_no, $reason_str);
  226. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  227. }
  228. }