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

177 lines
4.5KB

  1. <?php
  2. /*
  3. file: shop.php 購物
  4. */
  5. class Shop extends CC_Controller
  6. {
  7. function __construct()
  8. {
  9. parent::__construct('shop');
  10. }
  11. // 共用首頁
  12. function show_main_page($data=null)
  13. {
  14. if(empty($data))
  15. $data = array();
  16. $data['ALTOB_SHOP_UUID'] = md5(uniqid() . time());
  17. $this->show_page('main_page', $data);
  18. }
  19. // 首頁
  20. public function index()
  21. {
  22. $this->show_main_page();
  23. }
  24. // 付款流程頁面 (返回)
  25. public function client_back()
  26. {
  27. trigger_error(__FUNCTION__ . '..'. print_r($_POST, true));
  28. $this->show_main_page();
  29. }
  30. // 付款流程頁面 (完成, 返回)
  31. public function order_result()
  32. {
  33. trigger_error(__FUNCTION__ . '..'. print_r($_POST, true));
  34. $order_no = $this->input->post('order_no', true);
  35. $product_plan = $this->input->post('product_plan', true);
  36. $invoice_no = $this->input->post('invoice_no', true);
  37. $ck = $this->input->post('ck', true);
  38. // 建立頁面資料
  39. $data = array();
  40. $data['invoice_no'] = $invoice_no;
  41. // 更新產品訂單
  42. if($ck = md5($order_no.'alt'.$product_plan.'ob'.$invoice_no))
  43. {
  44. $this->app_model()->reload_product_bill($order_no, $invoice_no, $product_plan);
  45. }
  46. $this->show_main_page($data);
  47. }
  48. // 取得用戶兌換單
  49. public function query_uuid_bill()
  50. {
  51. $uuid = $this->input->post('uuid', true);
  52. $data = $this->app_model()->q_uuid_ready_bill($uuid);
  53. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  54. }
  55. // 領取
  56. public function redeem_order()
  57. {
  58. $order_no = $this->input->post('order_no', true);
  59. echo $this->app_model()->redeem_order($order_no);
  60. }
  61. // 咖啡包預覽頁
  62. public function coffee_shop()
  63. {
  64. $product_id = $this->uri->segment(3); // 商品代碼
  65. $data = $this->app_model()->q_product($product_id);
  66. unset($data['product_plan']);
  67. $this->show_main_page($data);
  68. }
  69. // 付款
  70. public function transfer_money()
  71. {
  72. $product_id = $this->input->post('product_id', true);
  73. $product_code = $this->input->post('product_code', true);
  74. $invoice_receiver = $this->input->post('invoice_receiver', true);
  75. $company_no = $this->input->post('company_no', true);
  76. $email = $this->input->post('email', true);
  77. $mobile = $this->input->post('mobile', true);
  78. $uuid = $this->input->post('uuid', true);
  79. // 建立訂單
  80. $new_bill = $this->app_model()->create_product_bill($product_id, $product_code);
  81. if(!isset($new_bill['order_no']))
  82. {
  83. echo 'bill_create_fail';
  84. exit;
  85. }
  86. $parms = array(
  87. 'order_no' => $new_bill['order_no'],
  88. 'invoice_receiver' => $invoice_receiver,
  89. 'company_no' => $company_no,
  90. 'email' => $email,
  91. 'mobile' => $mobile,
  92. 'uuid' => $uuid
  93. );
  94. // 處理產品訂單
  95. $proceed_bill = $this->app_model()->proceed_product_bill($parms, 50); // 50: 歐付寶刷卡
  96. // 開始進行繳交帳單
  97. if(!isset($proceed_bill['status']) || $proceed_bill['status'] != 100)
  98. {
  99. echo 'bill_proceed_fail';
  100. exit;
  101. }
  102. // 串接總公司購物流程
  103. $proceed_bill['station_no'] = $this->get_station_no();
  104. $proceed_bill['product_id'] = $product_id;
  105. $proceed_bill['product_code'] = $product_code;
  106. $proceed_bill['client_back_path'] = 'shop.html/client_back';
  107. $proceed_bill['order_result_path'] = 'shop.html/order_result';
  108. trigger_error(__FUNCTION__ . '..' . print_r($proceed_bill, true));
  109. try{
  110. $ch = curl_init();
  111. curl_setopt($ch, CURLOPT_URL, 'https://parks.altob.com.tw/bill_service.html/proceed_bill'); // 金流
  112. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  113. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  114. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  115. curl_setopt($ch, CURLOPT_POST, TRUE);
  116. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,30);
  117. curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout in seconds
  118. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($proceed_bill));
  119. $result = curl_exec($ch);
  120. if(curl_errno($ch))
  121. {
  122. trigger_error(__FUNCTION__ . ', curl error: '. curl_error($ch));
  123. }
  124. curl_close($ch);
  125. }catch (Exception $e){
  126. trigger_error(__FUNCTION__ . 'error:'.$e->getMessage());
  127. }
  128. echo $result;
  129. }
  130. /*
  131. // 買
  132. public function i_do()
  133. {
  134. $product_id = $this->uri->segment(3); // 商品代碼
  135. $data = $this->app_model()->q_coffee_shop($product_id);
  136. trigger_error(__FUNCTION__ . '..' . print_r($data, true));
  137. echo 'ok';
  138. }
  139. public function test_product_plan()
  140. {
  141. $order_no = '151246880713876';
  142. $this->app_model()->redeem_product_bill($order_no);
  143. echo 'ok';
  144. }
  145. */
  146. }