| @@ -9,17 +9,27 @@ class Shop extends CC_Controller | |||||
| parent::__construct('shop'); | parent::__construct('shop'); | ||||
| } | } | ||||
| // 共用首頁 | |||||
| function show_main_page($data=null) | |||||
| { | |||||
| if(empty($data)) | |||||
| $data = array(); | |||||
| $data['ALTOB_SHOP_UUID'] = md5(uniqid() . time()); | |||||
| $this->show_page('main_page', $data); | |||||
| } | |||||
| // 首頁 | // 首頁 | ||||
| public function index() | public function index() | ||||
| { | { | ||||
| $this->show_page('main_page'); | |||||
| $this->show_main_page(); | |||||
| } | } | ||||
| // 付款流程頁面 (返回) | // 付款流程頁面 (返回) | ||||
| public function client_back() | public function client_back() | ||||
| { | { | ||||
| trigger_error(__FUNCTION__ . '..'. print_r($_POST, true)); | trigger_error(__FUNCTION__ . '..'. print_r($_POST, true)); | ||||
| $this->show_page('main_page'); | |||||
| $this->show_main_page(); | |||||
| } | } | ||||
| // 付款流程頁面 (完成, 返回) | // 付款流程頁面 (完成, 返回) | ||||
| @@ -39,12 +49,24 @@ class Shop extends CC_Controller | |||||
| if($ck = md5($order_no.'alt'.$product_plan.'ob'.$invoice_no)) | if($ck = md5($order_no.'alt'.$product_plan.'ob'.$invoice_no)) | ||||
| { | { | ||||
| $this->app_model()->reload_product_bill($order_no, $invoice_no, $product_plan); | $this->app_model()->reload_product_bill($order_no, $invoice_no, $product_plan); | ||||
| // 取得發票待兌換訂單 | |||||
| //$data['invoice_ready_bill'] = $this->app_model()->q_invoice_ready_bill($invoice_no); | |||||
| } | } | ||||
| $this->show_page('main_page', $data); | |||||
| $this->show_main_page($data); | |||||
| } | |||||
| // 取得用戶兌換單 | |||||
| public function query_uuid_bill() | |||||
| { | |||||
| $uuid = $this->input->post('uuid', true); | |||||
| $data = $this->app_model()->q_uuid_ready_bill($uuid); | |||||
| echo json_encode($data, JSON_UNESCAPED_UNICODE); | |||||
| } | |||||
| // 領取 | |||||
| public function redeem_order() | |||||
| { | |||||
| $order_no = $this->input->post('order_no', true); | |||||
| echo $this->app_model()->redeem_order($order_no); | |||||
| } | } | ||||
| // 咖啡包預覽頁 | // 咖啡包預覽頁 | ||||
| @@ -53,7 +75,7 @@ class Shop extends CC_Controller | |||||
| $product_id = $this->uri->segment(3); // 商品代碼 | $product_id = $this->uri->segment(3); // 商品代碼 | ||||
| $data = $this->app_model()->q_product($product_id); | $data = $this->app_model()->q_product($product_id); | ||||
| unset($data['product_plan']); | unset($data['product_plan']); | ||||
| $this->show_page('main_page', $data); | |||||
| $this->show_main_page($data); | |||||
| } | } | ||||
| // 付款 | // 付款 | ||||
| @@ -65,6 +87,7 @@ class Shop extends CC_Controller | |||||
| $company_no = $this->input->post('company_no', true); | $company_no = $this->input->post('company_no', true); | ||||
| $email = $this->input->post('email', true); | $email = $this->input->post('email', true); | ||||
| $mobile = $this->input->post('mobile', true); | $mobile = $this->input->post('mobile', true); | ||||
| $uuid = $this->input->post('uuid', true); | |||||
| // 建立訂單 | // 建立訂單 | ||||
| $new_bill = $this->app_model()->create_product_bill($product_id, $product_code); | $new_bill = $this->app_model()->create_product_bill($product_id, $product_code); | ||||
| @@ -80,7 +103,8 @@ class Shop extends CC_Controller | |||||
| 'invoice_receiver' => $invoice_receiver, | 'invoice_receiver' => $invoice_receiver, | ||||
| 'company_no' => $company_no, | 'company_no' => $company_no, | ||||
| 'email' => $email, | 'email' => $email, | ||||
| 'mobile' => $mobile | |||||
| 'mobile' => $mobile, | |||||
| 'uuid' => $uuid | |||||
| ); | ); | ||||
| // 處理產品訂單 | // 處理產品訂單 | ||||
| @@ -22,16 +22,29 @@ class Shop_model extends CI_Model | |||||
| $this->vars = $vars; | $this->vars = $vars; | ||||
| } | } | ||||
| // 取得發票待兌換訂單 | |||||
| // 取得待兌換訂單 (用戶代號) | |||||
| public function q_uuid_ready_bill($uuid) | |||||
| { | |||||
| $where_arr['uuid'] = $uuid; | |||||
| $where_arr['status'] = 1; | |||||
| $result = $this->db->select('order_no, invoice_remark, product_plan, tx_time') | |||||
| ->from('product_bill') | |||||
| ->where($where_arr)->order_by("tx_time", "desc") | |||||
| ->get() | |||||
| ->result_array(); | |||||
| return $result; | |||||
| } | |||||
| // 取得待兌換訂單 (發票) | |||||
| public function q_invoice_ready_bill($invoice_no) | public function q_invoice_ready_bill($invoice_no) | ||||
| { | { | ||||
| $where_arr['invoice_no'] = $invoice_no; | $where_arr['invoice_no'] = $invoice_no; | ||||
| $where_arr['status'] = 1; | $where_arr['status'] = 1; | ||||
| $data = array(); | |||||
| $result = $this->db->select('product_id, product_code, product_name, invoice_remark, product_plan') | |||||
| $result = $this->db->select('order_no, invoice_remark, product_plan, tx_time') | |||||
| ->from('product_bill') | ->from('product_bill') | ||||
| ->where($where_arr)->order_by("create_time", "desc") | |||||
| ->where($where_arr)->order_by("tx_time", "desc") | |||||
| ->get() | ->get() | ||||
| ->row_array(); | ->row_array(); | ||||
| return $result; | return $result; | ||||
| @@ -104,6 +117,7 @@ class Shop_model extends CI_Model | |||||
| $company_no = $parms['company_no']; | $company_no = $parms['company_no']; | ||||
| $email = $parms['email']; | $email = $parms['email']; | ||||
| $mobile = $parms['mobile']; | $mobile = $parms['mobile']; | ||||
| $uuid = $parms['uuid']; | |||||
| $product_info = $this->db->select('valid_time, product_plan') | $product_info = $this->db->select('valid_time, product_plan') | ||||
| ->from('product_bill') | ->from('product_bill') | ||||
| @@ -126,6 +140,7 @@ class Shop_model extends CI_Model | |||||
| $data = array(); | $data = array(); | ||||
| $data['tx_type'] = $tx_type; // 交易種類: 0:未定義, 1:現金, 40:博辰人工模組, 41:博辰自動繳費機, 50:歐付寶轉址刷卡, 51:歐付寶APP, 52:歐付寶轉址WebATM, 60:中國信託刷卡轉址 | $data['tx_type'] = $tx_type; // 交易種類: 0:未定義, 1:現金, 40:博辰人工模組, 41:博辰自動繳費機, 50:歐付寶轉址刷卡, 51:歐付寶APP, 52:歐付寶轉址WebATM, 60:中國信託刷卡轉址 | ||||
| $data['uuid'] = $uuid; // 客戶代號 | |||||
| if(strlen($company_no) >= 8) | if(strlen($company_no) >= 8) | ||||
| { | { | ||||
| @@ -185,15 +200,16 @@ class Shop_model extends CI_Model | |||||
| // S.4. 兌換訂單商品 | // S.4. 兌換訂單商品 | ||||
| public function redeem_product_bill($order_no) | public function redeem_product_bill($order_no) | ||||
| { | { | ||||
| $product_info = $this->db->select('invoice_no, product_plan') | |||||
| $product_info = $this->db->select('invoice_no, product_plan, uuid') | |||||
| ->from('product_bill') | ->from('product_bill') | ||||
| ->where(array('order_no' => $order_no)) | |||||
| ->where(array('order_no' => $order_no, 'status' => 1)) | |||||
| ->limit(1) | ->limit(1) | ||||
| ->get() | ->get() | ||||
| ->row_array(); | ->row_array(); | ||||
| $invoice_no = $product_info['invoice_no']; | $invoice_no = $product_info['invoice_no']; | ||||
| $product_plan = $product_info['product_plan']; | $product_plan = $product_info['product_plan']; | ||||
| $uuid = $product_info['uuid']; | |||||
| // 取得訂單內容 | // 取得訂單內容 | ||||
| $data = json_decode($product_plan, true); | $data = json_decode($product_plan, true); | ||||
| @@ -224,7 +240,7 @@ class Shop_model extends CI_Model | |||||
| trigger_error(__FUNCTION__ . "|$order_no|$station_no, $product_code, $amount, $memo|兌換|" . print_r($product, true)); | trigger_error(__FUNCTION__ . "|$order_no|$station_no, $product_code, $amount, $memo|兌換|" . print_r($product, true)); | ||||
| // 兌換產品 | // 兌換產品 | ||||
| return $this->redeem_product($order_no, $invoice_no, $product, $amount); | |||||
| return $this->redeem_product($order_no, $invoice_no, $product, $uuid, $amount); | |||||
| } | } | ||||
| trigger_error(__FUNCTION__ . "|$order_no|undefined_product|" . print_r($data, true)); | trigger_error(__FUNCTION__ . "|$order_no|undefined_product|" . print_r($data, true)); | ||||
| @@ -232,7 +248,7 @@ class Shop_model extends CI_Model | |||||
| } | } | ||||
| // 兌換產品 | // 兌換產品 | ||||
| function redeem_product($order_no, $invoice_no, $product, $amount=1) | |||||
| private function redeem_product($order_no, $invoice_no, $product, $uuid, $amount=1) | |||||
| { | { | ||||
| // [A.開始] | // [A.開始] | ||||
| $this->db->trans_start(); | $this->db->trans_start(); | ||||
| @@ -243,6 +259,7 @@ class Shop_model extends CI_Model | |||||
| for($i = 0; $i < $amount; $i++) | for($i = 0; $i < $amount; $i++) | ||||
| { | { | ||||
| $item = array(); | $item = array(); | ||||
| $item['uuid'] = $uuid; // 用戶代號 | |||||
| $item['order_no'] = $this->gen_trx_no(); | $item['order_no'] = $this->gen_trx_no(); | ||||
| $item['tx_time'] = $tx_time; | $item['tx_time'] = $tx_time; | ||||
| $item['invoice_no'] = $invoice_no; | $item['invoice_no'] = $invoice_no; | ||||
| @@ -269,4 +286,54 @@ class Shop_model extends CI_Model | |||||
| return 'ok'; | return 'ok'; | ||||
| } | } | ||||
| // S.5. 兌換 (兌換 商品包 或 商品) | |||||
| public function redeem_order($order_no) | |||||
| { | |||||
| $product_info = $this->db->select('order_no, product_code, product_plan') | |||||
| ->from('product_bill') | |||||
| ->where(array('order_no' => $order_no, 'status' => 1)) | |||||
| ->limit(1) | |||||
| ->get() | |||||
| ->row_array(); | |||||
| if(!isset($product_info['product_code'])) | |||||
| { | |||||
| trigger_error(__FUNCTION__ . "|$order_no|not_found"); | |||||
| return 'not_found'; | |||||
| } | |||||
| $bill_product_code = $product_info['product_code']; | |||||
| // 兌換產品包 | |||||
| if($bill_product_code == PRODUCT_CODE_COFFEE_SHOP) | |||||
| { | |||||
| return $this->redeem_product_bill($order_no); | |||||
| } | |||||
| // 兌換咖啡 | |||||
| else if($bill_product_code == PRODUCT_CODE_COFFEE) | |||||
| { | |||||
| // [A.開始] | |||||
| $this->db->trans_start(); | |||||
| // 兌換時間 | |||||
| $tx_time = date('Y/m/d H:i:s'); | |||||
| // 更新為已領取 | |||||
| $this->db->update('product_bill', array('status' => 111, 'tx_time' => $tx_time), array('status' => 1, 'order_no' => $order_no)); | |||||
| // [C.完成] | |||||
| $this->db->trans_complete(); | |||||
| if ($this->db->trans_status() === FALSE) | |||||
| { | |||||
| trigger_error(__FUNCTION__ . "..$order_no..trans error..". '| last_query: ' . $this->db->last_query()); | |||||
| return 'fail'; // 中斷 | |||||
| } | |||||
| trigger_error(__FUNCTION__ . "|$order_no|已領取|" . print_r($product_info, true)); | |||||
| return 'ok'; | |||||
| } | |||||
| return 'gg'; | |||||
| } | |||||
| } | } | ||||
| @@ -118,6 +118,7 @@ | |||||
| <div class="form-group"> | <div class="form-group"> | ||||
| <input id="product_id" type="hidden" name="product_id" value="0" /> | <input id="product_id" type="hidden" name="product_id" value="0" /> | ||||
| <input id="product_code" type="hidden" name="product_code" value="" /> | <input id="product_code" type="hidden" name="product_code" value="" /> | ||||
| <input id="product_uuid" type="hidden" name="uuid" value="" /> | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| @@ -149,6 +150,7 @@ function load_item_page() | |||||
| $("#checkout_image").attr("src", "<?=SERVER_URL?>i3/pics/coffee.jpg"); | $("#checkout_image").attr("src", "<?=SERVER_URL?>i3/pics/coffee.jpg"); | ||||
| $("#product_id").val(PRODUCT_RESULT.product_id); | $("#product_id").val(PRODUCT_RESULT.product_id); | ||||
| $("#product_code").val(PRODUCT_RESULT.product_code); | $("#product_code").val(PRODUCT_RESULT.product_code); | ||||
| $("#product_uuid").val(get_altob_shop_uuid()); | |||||
| } | } | ||||
| // 開啟轉帳畫面 | // 開啟轉帳畫面 | ||||
| @@ -54,7 +54,7 @@ | |||||
| <div class="pss-choose-box"> | <div class="pss-choose-box"> | ||||
| <h4 class="spacing-title">兌換快捷鍵</h4> | <h4 class="spacing-title">兌換快捷鍵</h4> | ||||
| <div class="parkinsys-search-wrap"> | <div class="parkinsys-search-wrap"> | ||||
| <ul id="order_history_list" class="psw-choose-num"> | |||||
| <ul id="product_bill_list" class="psw-choose-num"> | |||||
| <!--li><a href="javascript:void(0)">ABC-1234</a></li> | <!--li><a href="javascript:void(0)">ABC-1234</a></li> | ||||
| <li><a href="javascript:void(0)">HT-114</a></li> | <li><a href="javascript:void(0)">HT-114</a></li> | ||||
| <li><a href="javascript:void(0)">YA-520</a></li> | <li><a href="javascript:void(0)">YA-520</a></li> | ||||
| @@ -183,103 +183,101 @@ var current_altob_check_list; // 目前待結清單 | |||||
| var current_altob_checkout_bill; // 目前待繳帳單 | var current_altob_checkout_bill; // 目前待繳帳單 | ||||
| var AltobCookies = Cookies.noConflict(); | var AltobCookies = Cookies.noConflict(); | ||||
| // 用戶代號 | |||||
| function get_altob_shop_uuid() | |||||
| { | |||||
| if(AltobCookies.get('ALTOB_SHOP_UUID') !== undefined) | |||||
| { | |||||
| return AltobCookies.get('ALTOB_SHOP_UUID'); | |||||
| } | |||||
| set_cookie('ALTOB_SHOP_UUID', '<?= $ALTOB_SHOP_UUID; ?>'); | |||||
| return AltobCookies.get('ALTOB_SHOP_UUID'); | |||||
| } | |||||
| // 設定 cookie | // 設定 cookie | ||||
| function set_cookie(key, value) | function set_cookie(key, value) | ||||
| { | { | ||||
| AltobCookies.set(key, value, { expires: 30 }); | |||||
| AltobCookies.set(key, value, { expires: 365 }); | |||||
| } | } | ||||
| $(document).ready(function() | |||||
| { | |||||
| <?php /* validate 設定start */ ?> | |||||
| $.validate( | |||||
| { | |||||
| modules : 'security', | |||||
| } | |||||
| ); | |||||
| <?php /* validate 設定end */ ?> | |||||
| // 若有帶產品编號, 前往展示頁 | |||||
| if(PRODUCT_RESULT.product_id != '') | |||||
| { | |||||
| show_item('item_page', 'item_page'); | |||||
| } | |||||
| else | |||||
| { | |||||
| show_item('home_page', 'home_page'); | |||||
| } | |||||
| }); | |||||
| // 載入兌換資訊 | // 載入兌換資訊 | ||||
| function reload_order_list() | function reload_order_list() | ||||
| { | { | ||||
| $("#order_history_list").html(''); | |||||
| if(AltobCookies.get('order_history') !== undefined) // 清除 Cookies.expire('order_history') | |||||
| { | |||||
| var query_list = []; | |||||
| var order_history_arr = AltobCookies.get('order_history').split(';'); | |||||
| for(key in order_history_arr) | |||||
| var altob_shop_uuid = get_altob_shop_uuid(); | |||||
| // 取得兌換資訊 | |||||
| $.ajax | |||||
| ({ | |||||
| url: "<?=APP_URL?>query_uuid_bill", | |||||
| type: "post", | |||||
| dataType: "json", | |||||
| data: {"uuid":altob_shop_uuid}, | |||||
| success:function(jdata) | |||||
| { | { | ||||
| if(order_history_arr[key] != '') | |||||
| { | |||||
| console.log('+' + order_history_arr[key]); | |||||
| } | |||||
| var query_list = []; | |||||
| /* | |||||
| query_list = query_list.concat(['<li><a href="javascript:void(0)" onclick="get_item(', key ,');">', | |||||
| order_history_arr[key] ,'</a></li>']); | |||||
| */ | |||||
| } | |||||
| $("#order_history_list").append(query_list.join('')); | |||||
| } | |||||
| else | |||||
| { | |||||
| // 重新下載兌換卷 | |||||
| } | |||||
| } | |||||
| // 新增兌換記錄 | |||||
| function new_order_list(order_key) | |||||
| { | |||||
| var isNewLpr = true; | |||||
| var order_history_arr = []; | |||||
| if(AltobCookies.get('order_history') !== undefined) // 清除 Cookies.expire('order_history') | |||||
| { | |||||
| order_history_arr = AltobCookies.get('order_history').split(';'); | |||||
| for(key in order_history_arr) | |||||
| { | |||||
| if(order_history_arr[key] == order_key) | |||||
| { | |||||
| isNewLpr = false; | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| if(isNewLpr && order_key != '-') | |||||
| { | |||||
| // 最多記錄 5 筆, 新的被清掉 | |||||
| if(order_history_arr.length >= 5) | |||||
| order_history_arr.shift(); | |||||
| for(idx in jdata) | |||||
| { | |||||
| var invoice_remark = jdata[idx]['invoice_remark']; | |||||
| var product_plan = JSON.parse(jdata[idx]['product_plan']); | |||||
| var order_no = jdata[idx]['order_no']; | |||||
| var item_msg = ''; | |||||
| order_history_arr.push(order_key); | |||||
| set_cookie('order_history', order_history_arr.join(';')) | |||||
| // 重建兌換記錄 | |||||
| reload_order_list(); | |||||
| } | |||||
| // 分析產品內容 | |||||
| if(product_plan.amount > 0) | |||||
| item_msg = '領取 ' + invoice_remark + ' 兌換卷'; | |||||
| else | |||||
| item_msg = '兌換 ' + product_plan.memo + ' x 1'; | |||||
| query_list = query_list.concat(['<li><a href="javascript:void(0)" onclick="get_item(', order_no ,',\'', item_msg, '\');">', item_msg ,'</a></li>']); | |||||
| } | |||||
| $("#product_bill_list").html('').append(query_list.join('')); | |||||
| } | |||||
| }) | |||||
| } | } | ||||
| // 設定車號 | |||||
| function set_lpr(key) | |||||
| // 兌換 | |||||
| function get_item(order_no, item_msg) | |||||
| { | { | ||||
| var order_history_arr = AltobCookies.get('order_history').split(';'); | |||||
| var order_front_tail = String(order_history_arr[key]).split('-'); | |||||
| $("#order_front").val('').val(order_front_tail[0]); | |||||
| $("#order_tail").val('').val(order_front_tail[1]); | |||||
| alertify.set({ | |||||
| buttonFocus: "cancel", | |||||
| labels: { | |||||
| ok : "兌換", | |||||
| cancel : "取消" | |||||
| } | |||||
| }); | |||||
| alertify.confirm( | |||||
| item_msg | |||||
| , function (e){ | |||||
| if (e) { | |||||
| $.ajax | |||||
| ({ | |||||
| url: "<?=APP_URL?>redeem_order", | |||||
| dataType:"text", | |||||
| type:"post", | |||||
| data: {"order_no":order_no}, | |||||
| success:function(redeem_order_result) | |||||
| { | |||||
| if(redeem_order_result == 'ok') | |||||
| { | |||||
| alertify_success('操作完成'); | |||||
| // 重新載入 | |||||
| reload_order_list(); | |||||
| } | |||||
| else if(redeem_order_result == 'not_found') | |||||
| { | |||||
| alertify_error('查無訂單..'); | |||||
| } | |||||
| else | |||||
| { | |||||
| alertify_error('發生異常..' . redeem_order_result); | |||||
| } | |||||
| } | |||||
| }) | |||||
| }}) | |||||
| } | } | ||||
| // 回上頁 | // 回上頁 | ||||
| @@ -292,4 +290,25 @@ function back_page(event) | |||||
| show_item('home_page', 'home_page'); | show_item('home_page', 'home_page'); | ||||
| } | } | ||||
| $(document).ready(function() | |||||
| { | |||||
| <?php /* validate 設定start */ ?> | |||||
| $.validate( | |||||
| { | |||||
| modules : 'security', | |||||
| } | |||||
| ); | |||||
| <?php /* validate 設定end */ ?> | |||||
| // 若有帶產品编號, 前往展示頁 | |||||
| if(PRODUCT_RESULT.product_id != '') | |||||
| { | |||||
| show_item('item_page', 'item_page'); | |||||
| } | |||||
| else | |||||
| { | |||||
| show_item('home_page', 'home_page'); | |||||
| } | |||||
| }); | |||||
| </script> | </script> | ||||