123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- var smoney = '';
- var sbookid = commont.getQueryString('book_id', window.location.search, '&') || '';
- var schapterid = commont.getQueryString('chapter_id', window.location.search, '&') || '';
- var float_id = commont.getQueryString('float_id', window.location.search, '&') || '';
- $(function () {
- /* if (typeof cpslog == 'undefined') {
- window.cpslog = function (arr, callback) {
- console.log('cps_log.js 未加载');
- }
- }*/
- /**
- * 头像点击
- */
- var n = 0;
- $('.re_head_box img').click(function () {
- n++;
- if (n > 4) {
- window.location.href = '/index/index/dev';
- }
- });
- /**
- * 选项卡点击
- */
- $('.re_list_ul a').click(function () {
- var $this = $(this),
- goodsId = $this.data('goods-id'),
- goodsCategory = $this.data('goods-category'),
- goodsMoney = $this.data('goods-money'),
- activityId = $this.data('activity-id');
- $this.parent().addClass('hover').siblings('li').removeClass('hover');
- var but = $('#pay_btn');
- but.data('goods-id', goodsId);
- but.data('goods-category', goodsCategory);
- but.data('activity-id', activityId);
- but.data('money', goodsMoney);
- but.text('立即充值:' + goodsMoney);
- });
- /**
- * 充值按钮
- */
- var paystop = true;
- var payurl = '/api/recharge/pay';
- $('.re_but_box a').click(function () {
- if (!paystop) {
- return false;
- }
- paystop = false;
- var $this = $(this),
- goodsId = $this.data('goods-id'),
- goodsCategory = $this.data('goods-category'),
- activity_id = $this.data('activity-id');
- smoney = $this.data('money');
- business_line = parseInt($this.data('business_line'));
- sbookid = commont.getQueryString('book_id', window.location.search, '&') || '';
- schapterid = commont.getQueryString('chapter_id', window.location.search, '&') || '';
- cpslog([702, {
- adid: goodsId,
- map: {
- book_id: sbookid,
- chapter_id: schapterid,
- business:business_line,
- money: smoney
- }
- }, business_line]);
- var data = {
- id: goodsId,
- activity_id: activity_id,
- business_line:business_line,
- category: goodsCategory,
- float_id: float_id,
- money: smoney
- };
- if(sbookid){
- data.book_id = sbookid;
- }
- if(schapterid){
- data.chapter_id = schapterid;
- }
- $('.js_loading').show();
- $.ajax({
- url: payurl,
- data: data,
- type: 'POST',
- timeout: 35000,
- success: function (data) {
- paystop = true;
- if (data.code) {
- switch (business_line) {
- case 0: //微信公众号支付
- if (data.data) {
- var oJsonObj = JSON.parse(data.data.json);
- wechatPay(oJsonObj, goodsId);
- cpslog([703, {
- map: {
- package: oJsonObj.package,
- xdtype: goodsCategory,
- result: 1,
- book_id: sbookid,
- adid: goodsId,
- chapter_id: schapterid,
- business:business_line,
- money: smoney
- }
- }, 'xdjg']);
- } else {
- consoleMain(data.msg);
- }
- break;
- default: //alipay 支付宝 //wechath5 微信H5支付
- break;
- }
- } else {
- consoleMain(data.msg);
- cpslog([703, {
- map: {
- xdtype: goodsCategory,
- result: 2,
- book_id: sbookid,
- adid: goodsId,
- chapter_id: schapterid,
- business:business_line,
- money: smoney
- }
- }, 'xdjg']);
- }
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- consoleMain('异常错误,请刷新页面重试');
- cpslog([703, {
- map: {
- xdtype: goodsCategory,
- result: 4,
- book_id: sbookid,
- adid: goodsId,
- chapter_id: schapterid,
- business:business_line,
- money: smoney,
- XMLHttpRequest: XMLHttpRequest.status,
- textStatus: textStatus,
- errorThrown: errorThrown
- }
- }, 'xdjg']);
- paystop = true;
- },
- complete: function () {
- $('.js_loading').hide();
- }
- });
- });
- /**
- * 处理默认充值商品自动下单
- */
- var check = $('.re_but_box a.check');
- if(check.length){
- check.click();
- }
- });
- /**
- * 微信公众号支付
- * @param json 微信支付相关数据
- * @param goodsId 商品id
- */
- function wechatPay(json, goodsId) {
- if (typeof WeixinJSBridge == "undefined") {
- if (document.addEventListener) {
- document.addEventListener('WeixinJSBridgeReady', function () {
- onBridgeReady(json, goodsId);
- }, false);
- } else if (document.attachEvent) {
- document.attachEvent('WeixinJSBridgeReady', function () {
- onBridgeReady(json, goodsId);
- });
- document.attachEvent('onWeixinJSBridgeReady', function () {
- onBridgeReady(json, goodsId);
- });
- }
- } else {
- onBridgeReady(json, goodsId);
- }
- }
- // 倒计时跳转链接
- function innerJumpTime(redirect){
- var _dialog_html = '<div class="J_dialog_pay_div" style="position:fixed;top:50%;left:50%;margin-left:-1rem;margin-top:-.25rem;width:2rem;height:.5rem;line-height:.5rem;border-radius:.05rem;background:rgba(0,0,0,0.65);text-align:center;color:#fff;font-size:.18rem;">充值成功,3秒后跳转</div>';
- var C_TIME = 3;
- $('body').append(_dialog_html);
- var interval = setInterval(function () {
- console.log(C_TIME);
- var time = --C_TIME;
- $('.J_dialog_pay_div').html('充值成功,'+ time +'秒后跳转');
- if (time <= 0) {
- clearInterval(interval);
- $('.J_dialog_pay_div').remove();
- // 广告需要,非从点击底部tab离开充值页,清除支付状态缓存
- window.localStorage.removeItem('payStatus');
- window.location.href = redirect;
- }
- }, 1000);
- }
- /**
- * 微信内唤起充值窗口
- * @param json
- * @param goodsId
- */
- function onBridgeReady(json, goodsId) {
- WeixinJSBridge.invoke(
- 'getBrandWCPayRequest', json,
- function (res) {
- switch (res.err_msg) {
- case 'get_brand_wcpay_request:ok': //成功
- // consoleMain('充值成功,正在跳转');
- cpslog([703, {
- map: {
- cztype: 'wechat',
- package: json.package,
- result: 1,
- book_id: sbookid,
- chapter_id: schapterid,
- money: smoney,
- res: res
- }
- }, 'czjg']);
- /* if (redirect = commont.getQueryString('redirect')) { //回跳链接
- innerJumpTime(redirect)
- }else{
- // 没有回跳地址,弹窗窗口
- $('.bind_alert_box').show();
- }*/
- // 记录支付成功状态,供广告展示使用
- window.payStatus = '1';
- window.localStorage.setItem('payStatus','true');
- if (redirect = commont.getQueryString('redirect')) { //回跳链接
- $('.js_recent_url').val(redirect);
- }
- if (typeof is_mishu_block != 'undefined' && is_mishu_block == '1') {
- $(".mishu_tips_box").show();
- } else {
- $('.dialoge_bg').show();
- }
- var activeId = $('.js_recent_url').attr('active-id');
- if ( parseInt(activeId) > 0 ){
- $('.dialoge_bg .suc_btn_look').text('回到活动');
- }
- $('.dialoge_bg').show();
- break;
- case 'get_brand_wcpay_request:cancel': //取消
- consoleMain('您已取消充值');
- wechatCancel(goodsId);
- cpslog([703, {
- map: {
- cztype: 'wechat',
- package: json.package,
- result: 2,
- book_id: sbookid,
- chapter_id: schapterid,
- money: smoney,
- res: res
- }
- }, 'czjg']);
- if(window.$isAdPick && window.$isAdPick == '1' && $('.ad-recharge-alert').find('.ad-image').length>0){
- window.simpleAD.showRechargeAlert();
- $('.close').unbind().bind('click',function(){
- $('.ad-recharge-alert').hide();
- });
- }
- break;
- case 'get_brand_wcpay_request:fail': //失败
- consoleMain('充值失败,请尝试重新充值或试试其他充值方式');
- wechatCancel(goodsId);
- cpslog([703, {
- map: {
- cztype: 'wechat',
- package: json.package,
- result: 3,
- book_id: sbookid,
- chapter_id: schapterid,
- money: smoney,
- res: res
- }
- }, 'czjg']);
- break;
- default:
- console.log(res);
- wechatCancel(goodsId);
- if (typeof res.err_msg == 'undefined' && res.errMsg == 'chooseWXPay:fail, the permission value is offline verifying') {
- consoleMain('充值失败,原因:模拟器无法充值');
- } else {
- consoleMain('异常错误,请刷新页面重试');
- cpslog([703, {
- map: {
- cztype: 'wechat',
- package: json.package,
- result: 4,
- book_id: sbookid,
- chapter_id: schapterid,
- money: smoney,
- res: res
- }
- }, 'czjg']);
- }
- break;
- }
- }
- );
- }
- //秘书弹窗
- var mishu_2_num_val = parseInt($.fn.cookie('mishu_2_num')) || 0;
- $(".mishu_tips_box .btn_close_2").click(function () {
- mishu_2_num_val++;
- $.fn.cookie('mishu_2_num',mishu_2_num_val,{expires: 3650, path: '/', domain: document.domain});
- $('.mishu_tips_box').remove();
- var goUrl = $('.js_recent_url').val();
- if (goUrl.length > 0 && goUrl.indexOf("book_id") != -1) {
- // 广告需要,非从点击底部tab离开充值页,清除支付状态缓存
- window.localStorage.removeItem('payStatus');
- window.location.href=goUrl;
- } else {
- window.location.reload();
- }
- });
- $(".suc_close").click(function () {
- $('.dialoge_bg').hide();
- window.location.reload();
- });
- //region 弹框事件
- $('.bind_alert_off').click(function () {
- var search = window.location.search.replace('?', '');
- var aParams = search.split('&');
- var aParamsNoGoods = [];
- for (var i = 0; i < aParams.length; i++) {
- if (aParams[i].indexOf('goods_id=') == -1) {
- aParamsNoGoods.push(aParams[i]);
- }
- }
- var strParams = aParamsNoGoods.join('&');
- // 广告需要,非从点击底部tab离开充值页,清除支付状态缓存
- window.localStorage.removeItem('payStatus');
- var href = window.location.pathname + '?' + strParams;
- window.location.href = href;
- });
- $('.alert_but_1, .suc_btn_look').click(function () {
- // 广告需要,非从点击底部tab离开充值页,清除支付状态缓存
- window.localStorage.removeItem('payStatus');
- window.location.href = $('.js_recent_url').val();
- });
- //endregion
- function wechatCancel(goodsId) {
- if ($('.fans_box').length > 0) {
- $('.fans_box').show();
- cpslog([703, {export_fans_id:$('.fans_box').data('id')}, 'export_fans_show']);
- $(".btn_close_3").click(function () {
- $('.fans_box').hide();
- cpslog([703, {export_fans_id:$('.fans_box').data('id')}, 'export_fans_close']);
- });
- }
- $.ajax({
- url: '/api/recharge/wechatCancel',
- data: {
- url: window.location.href,
- goods_id: goodsId
- },
- type: 'POST',
- timeout: 10000,
- success: function (data) {
- },
- error: function (err) {
- }
- });
- }
|