VM暫存
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

186 行
6.0KB

  1. <?php
  2. /*
  3. file: Payment_model.php 付費系統 (臨停)
  4. */
  5. class Payment_model extends CI_Model
  6. {
  7. function __construct()
  8. {
  9. parent::__construct();
  10. $this->load->database();
  11. define("PAYMENT_INVOICE_REMARK", "臨停繳交帳單");
  12. }
  13. // 狀態: 結帳完成
  14. public function transfer_money_done($order_no)
  15. {
  16. $data = array();
  17. $data['status'] = TX_BILL_STATUS_PAID;
  18. $this->db->update('tx_bill', $data, array('order_no' => $order_no));
  19. return true;
  20. }
  21. // 狀態: 錢沒對上
  22. public function transfer_money_done_with_amt_error($order_no)
  23. {
  24. $data = array();
  25. $data['status'] = TX_BILL_STATUS_ERROR_AMT;
  26. $this->db->update('tx_bill', $data, array('order_no' => $order_no));
  27. return true;
  28. }
  29. // 狀態: 發票沒建立
  30. public function transfer_money_set_invoice_error($order_no)
  31. {
  32. $data = array();
  33. $data['status'] = TX_BILL_STATUS_ERROR_INVOICE;
  34. $this->db->update('tx_bill', $data, array('order_no' => $order_no));
  35. return true;
  36. }
  37. // 狀態: 訂單逾期作廢
  38. public function transfer_money_timeout($order_no)
  39. {
  40. $data = array();
  41. $data['status'] = TX_BILL_STATUS_TIME_OUT;
  42. $this->db->update('tx_bill', $data, array('order_no' => $order_no));
  43. return true;
  44. }
  45. // 狀態: 交易失敗
  46. public function transfer_money_done_with_tx_error($order_no)
  47. {
  48. $data = array();
  49. $data['status'] = TX_BILL_STATUS_FAIL;
  50. $this->db->update('tx_bill', $data, array('order_no' => $order_no));
  51. return true;
  52. }
  53. // 狀態: 產品已領取
  54. public function transfer_money_done_and_finished($order_no)
  55. {
  56. $data = array();
  57. $data['status'] = TX_BILL_STATUS_DONE;
  58. $this->db->update('tx_bill', $data, array('order_no' => $order_no));
  59. return true;
  60. }
  61. // 建立帳單 (臨停)
  62. public function create_cario_bill($lpr)
  63. {
  64. $result = $this->db->select('station_no, cario_no, in_time, pay_time, out_time, out_before_time, member_no')
  65. ->from('cario')
  66. ->where(array('obj_type' => 1, 'obj_id' => $lpr, 'finished' => 0, 'err' => 0))
  67. ->order_by('cario_no', 'desc')
  68. ->limit(1)
  69. ->get()
  70. ->row_array();
  71. if(!empty($result['member_no'])){
  72. // 會員不算臨停帳單
  73. $data = array();
  74. $data['member_no'] = $result['member_no'];
  75. return $data;
  76. }
  77. else if (!empty($result['out_before_time']))
  78. {
  79. $inTime = $result['out_before_time']; // 進場時間認這個欄位
  80. $balanceTime = date('Y-m-d H:i:s');
  81. $stationNo = $result['station_no'];
  82. require_once(ALTOB_BILL_FILE); // 臨停費率
  83. $oPayment = new AltobPayment();
  84. $oPayment->ServiceURL = ALTOB_PAYMENT_TXDATA_URL;
  85. $bill = $oPayment->getBill($inTime, $balanceTime, $stationNo);
  86. // create tx_bill
  87. $data = array();
  88. $data['invoice_remark'] = PAYMENT_INVOICE_REMARK;
  89. $data['order_no'] = $result['cario_no'].time(); // 交易序號
  90. $data['cario_no'] = $result['cario_no']; // 進出場序號 (金流結束後開門使用)
  91. //$data['amt'] = ($bill[BillResultKey::price] > 0) ? 10 : 0; // 測試用
  92. $data['amt'] = $bill[BillResultKey::price];
  93. $data['balance_time_limit'] = date("Y-m-d H:i:s", strtotime('+ 15 minutes')); // 15 min
  94. $data['balance_time'] = $balanceTime;
  95. $data['in_time'] = $inTime;
  96. $data['lpr'] = strtoupper($lpr);
  97. $data['station_no'] = $stationNo;
  98. if($bill[BillResultKey::price] > 0){
  99. // 有費用才建立到tx_bill
  100. $this->db->insert('tx_bill', $data);
  101. }else{
  102. trigger_error(APP_NAME.', '.__FUNCTION__.', order_no=>' . $order_no."|{$lpr}|尚未產生款項");
  103. }
  104. // return data
  105. $data['bill_days'] = $bill[BillResultKey::days];
  106. $data['bill_hours'] = $bill[BillResultKey::hours];
  107. $data['bill_mins'] = $bill[BillResultKey::mins];
  108. $data['price_detail'] = $bill[BillResultKey::price_detail];
  109. return $data;
  110. }
  111. trigger_error(APP_NAME.', '.__FUNCTION__.', order_no=>' . $order_no."|{$lpr}|無車牌帳單資料");
  112. }
  113. // 繳交帳單 (帳單)
  114. public function pay_bill($order_no, $invoice_receiver, $company_no, $email, $mobile, $clientBackUrl, $orderResultUrl, $serviceUrl, $tx_type=0)
  115. {
  116. $data = $this->get_tx_bill($order_no);
  117. if (!empty($data))
  118. {
  119. if($data['status'] != 0){
  120. trigger_error(APP_NAME.', '.__FUNCTION__.', order_no=>' . $order_no."|error status: ". $data['status']);
  121. return null;
  122. }
  123. if(strlen($invoice_receiver) >= 7){ // 手機載具編號
  124. $data['invoice_receiver'] = '/'.$invoice_receiver;
  125. }
  126. if(strlen($company_no) >= 8){ // 公司統編
  127. $data['company_no'] = $company_no;
  128. $data['company_receiver'] = "公司名稱";
  129. $data['company_address'] = "公司地址";
  130. }
  131. if(strlen($email) >= 5){ // a@b.c
  132. $data['email'] = $email;
  133. }
  134. if(strlen($mobile) >= 10){ // 手機
  135. $data['mobile'] = $mobile;
  136. }
  137. $txTime = time(); // 產生交易時間
  138. if(strtotime($data['balance_time_limit']) - $txTime > 0){
  139. $data['status'] = TX_BILL_STATUS_PROCESSING;
  140. $data['tx_time'] = date('Y/m/d H:i:s', $txTime);
  141. $data['tx_type'] = $tx_type; // 交易種類: 0:未定義, 1:現金, 40:博辰人工模組, 41:博辰自動繳費機, 50:歐付寶轉址刷卡, 51:歐付寶APP, 52:歐付寶轉址WebATM, 60:中國信託刷卡轉址
  142. $data['client_back_url'] = $clientBackUrl;
  143. $data['order_result_url'] = $orderResultUrl;
  144. $data['service_url'] = $serviceUrl;
  145. $this->db->update('tx_bill', $data, array('order_no' => $order_no));
  146. return $data;
  147. }
  148. $this->transfer_money_timeout($order_no); // 訂單逾期作廢
  149. return null;
  150. }
  151. trigger_error(APP_NAME.', '.__FUNCTION__.', order_no=>' . $order_no."|無帳單資料");
  152. }
  153. // 取得臨停帳單資料
  154. public function get_tx_bill($order_no)
  155. {
  156. $result = $this->db
  157. ->from('tx_bill')
  158. ->where(array('order_no' => $order_no))
  159. ->limit(1)
  160. ->get()
  161. ->row_array();
  162. return $result;
  163. }
  164. }