406 行
14 KiB
JavaScript
可执行文件
406 行
14 KiB
JavaScript
可执行文件
localStorage.marskshow = 0;
|
|
//刷新页面
|
|
var discounts = localStorage.discounts;
|
|
if(discounts==1){
|
|
localStorage.discounts = 0;
|
|
window.location.reload();
|
|
}
|
|
$(document).on('touchstart',function (e) {
|
|
if(e.target.className!="marsk" && !$(e.target).parents('.pay').length){
|
|
$('.pay').hide();
|
|
$('.cursor').hide();
|
|
$('.height').hide();
|
|
}
|
|
})
|
|
|
|
var m = '';//存储上一步输入的金额
|
|
$('.keyico').on('touchstart',function () {
|
|
$(this).css('backgroundColor',"#ececec");
|
|
$('.keyico').on('touchend',function () {
|
|
$(this).css('backgroundColor',"white");
|
|
})
|
|
$('.pay').hide();
|
|
$('.cursor').hide();
|
|
$('.height').hide();
|
|
})
|
|
$('.marsk').on('touchstart',function () {
|
|
$('.pay').show();
|
|
$('.cursor').show();
|
|
$('.height').show();
|
|
})
|
|
|
|
//输入金额
|
|
$(".num").on("touchstart",function(){
|
|
$(this).css('backgroundColor',"#ececec");
|
|
$('.num').on('touchend',function () {
|
|
$(this).css('backgroundColor',"white");
|
|
})
|
|
var n = $(this).html();
|
|
var inputmoney = $("#num").val();
|
|
var dotIndex = inputmoney.indexOf('.');
|
|
if(dotIndex<0 && n=='.' && !inputmoney.length){
|
|
n = '0.';
|
|
}
|
|
if(n!='0' && n!='.' && inputmoney=='0'){
|
|
inputmoney = '';
|
|
}
|
|
if(dotIndex>=0 && n=='.'){
|
|
return;
|
|
}
|
|
var temp = inputmoney+n;
|
|
if(temp.length>1 && parseFloat(temp)==0 && temp!="0." && temp!="0.0" && temp!=".0"){
|
|
return;
|
|
}
|
|
if(dotIndex>=0&&inputmoney.length-dotIndex>=3){
|
|
return;
|
|
}
|
|
inputmoney += n;
|
|
if(parseFloat(inputmoney)>100000){
|
|
//最多付款100000元
|
|
return;
|
|
}
|
|
$("#num").val(inputmoney);
|
|
$('.marsk').html(inputmoney);
|
|
getCoup();
|
|
});
|
|
//删除金额
|
|
$(".del").on("touchstart",function(){
|
|
$(this).css('backgroundColor',"#ececec");
|
|
$('.del').on('touchend',function () {
|
|
$(this).css('backgroundColor',"white");
|
|
})
|
|
var inputmoney = $("#num").val();
|
|
if(inputmoney.length<=1){
|
|
$("#num").val('');
|
|
$('.marsk').html('');
|
|
}else{
|
|
var subtext=inputmoney.substr(0,inputmoney.length-1);
|
|
$("#num").val(subtext);
|
|
$('.marsk').html(subtext);
|
|
}
|
|
getCoup();
|
|
});
|
|
function getCoup() {
|
|
var tempmoney = $('#num').val();
|
|
if(m!=tempmoney){
|
|
m = tempmoney;
|
|
if(m<need){
|
|
$('.selectdetail').html('不使用优惠券');//清空选择优惠券信息
|
|
less = 0;
|
|
}
|
|
$.post("/index.php/Vip/Discounts/getCoupons",{money:m},function (res) {
|
|
$('.couponnum').html(res.num);
|
|
coupons = res.coupons;
|
|
count = res.num;
|
|
})
|
|
}
|
|
}
|
|
|
|
var pwd = '';//输入的支付密码
|
|
|
|
//拦截返回事件
|
|
var state = {
|
|
title:"优惠买单",
|
|
url:location.href
|
|
}
|
|
var isrefrash = localStorage.viprefrash || 0;
|
|
if(isrefrash==0){
|
|
//防止多次存储链接
|
|
localStorage.viprefrash = 1;
|
|
window.history.pushState(state, state.title, state.url);
|
|
}
|
|
ToUrlSelfFn("优惠买单",location.href,function () {
|
|
if(localStorage.marskshow==1){
|
|
$('.couponlist_con').hide();
|
|
$('.pwd_con').hide();
|
|
pwd = '';
|
|
$('.ul>li').html('');
|
|
localStorage.marskshow = 0;
|
|
window.history.pushState(state, state.title, state.url);
|
|
}
|
|
})
|
|
|
|
var less = 0;
|
|
var eid = 0;
|
|
var need = 0;
|
|
var money = 0;
|
|
var balance = parseFloat($('#money').html());//余额
|
|
//输入金额
|
|
var coupons = [];
|
|
var count = 0;
|
|
|
|
//点击选择优惠券
|
|
$('.openCoupon').on('touchstart',function () {
|
|
localStorage.marskshow = 1;
|
|
$('.couponlist_con').show();
|
|
if(money!=parseFloat($('#num').val())){
|
|
money = parseFloat($('#num').val());
|
|
$('.couponlist').html('');
|
|
if(coupons.length){
|
|
$('.notuse').show();
|
|
$('.nocoupon').hide();
|
|
for(let i=0;i<coupons.length;i++){
|
|
var list = $(`
|
|
<div class="card_content">
|
|
<div class="card_content_inner">
|
|
<div class="left_content">
|
|
<div class="card_content_inner01">¥${coupons[i].less}</div>
|
|
<div class="card_content_inner02">满${coupons[i].money}元可用</div>
|
|
</div>
|
|
<div class="right_content">
|
|
<div class="card_content_inner03">${coupons[i].less}元代金券</div>
|
|
<div class="card_content_inner04">消费满${coupons[i].money}元立减${coupons[i].less}元</div>
|
|
<div class="card_content_inner05">到期时间${coupons[i].overtime}</div>
|
|
</div>
|
|
<div class="card_content_inner06 notselect" less="${coupons[i].less}" intg="intg-${coupons[i].id}">使用</div>
|
|
</div>
|
|
</div>`);
|
|
$('.couponlist').append(list);
|
|
}
|
|
$('.card_content_inner06').on('touchstart',function () {
|
|
$('.card_content_inner06').html('使用');
|
|
$('.card_content_inner06').addClass('notselect');
|
|
$('.card_content_inner06').removeClass('select');
|
|
|
|
var index = $('.card_content_inner06').index($(this));
|
|
var text = '满'+coupons[index].money+'减'+coupons[index].less;
|
|
$('.selectdetail').html(text);
|
|
|
|
less = parseFloat($(this).attr('less'));
|
|
eid = $(this).attr('intg');
|
|
eid = eid.split('-')[1];
|
|
need = coupons[index].money;
|
|
$(this).html('');
|
|
$(this).removeClass('notselect');
|
|
$(this).addClass('select');
|
|
localStorage.marskshow = 0;
|
|
setTimeout(()=>{
|
|
$('.couponlist_con').hide();
|
|
},500)
|
|
})
|
|
//点击不使用优惠券
|
|
$('.notuse').off().on('touchstart',function () {
|
|
less = 0;
|
|
eid = 0;
|
|
need = 0;
|
|
$('.selectdetail').html('');
|
|
|
|
$('.card_content_inner06').html('使用');
|
|
$('.card_content_inner06').addClass('notselect');
|
|
$('.card_content_inner06').removeClass('select');
|
|
localStorage.marskshow = 0;
|
|
setTimeout(()=>{
|
|
$('.couponlist_con').hide();
|
|
},500)
|
|
})
|
|
}else {
|
|
$('.notuse').hide();
|
|
$('.nocoupon').show();
|
|
}
|
|
}
|
|
})
|
|
$('.nocoupon').on('touchstart',function () {
|
|
$('.couponlist_con').hide();
|
|
localStorage.marskshow = 0;
|
|
})
|
|
|
|
//点击提交
|
|
function submit(){
|
|
var n = parseFloat($('#num').val());
|
|
if(n<=0){
|
|
alertMsg('请输入大于零的金额',1000);
|
|
return;
|
|
}
|
|
if(less){
|
|
n = n - less;//减掉优惠券的钱
|
|
}
|
|
n = parseFloat(n.toFixed(2));
|
|
|
|
if(n){
|
|
$.post("/index.php/Vip/Discounts/getBalance",function (data) {
|
|
balance = parseFloat(data.balance);
|
|
balance = parseFloat(balance.toFixed(2));
|
|
if(n<=balance){
|
|
//余额支付
|
|
$('.pwd_con').show();
|
|
localStorage.marskshow = 1;
|
|
$('.needpay>span').html(n.toFixed(2));
|
|
$('.ul').show();
|
|
}else {
|
|
//微信支付
|
|
var money = n;
|
|
var payAgent=$("#payagent").val();
|
|
var paymod=$("#paymod").val();
|
|
var all_money = n;
|
|
//获取当前 充值的金额
|
|
var total_fee= money;
|
|
if(total_fee==''||parseFloat(total_fee)<0.01||$(".btn").hasClass("disabled")||payAgent==''||paymod=='') {
|
|
return;
|
|
}
|
|
var total_fee = money;
|
|
if(parseFloat(total_fee)<0.01){
|
|
alertMsg("支付金额不得小于0.01元",1000);
|
|
return;
|
|
}
|
|
var localObj = window.location;
|
|
if(paymod=='ping'){
|
|
var appid=$("#appid").val();
|
|
var api_id=$("#api_id").val();
|
|
var sub_merchant_id=$("#sub_merchant_id").val();
|
|
var notify_url=$("#notify_url").val();
|
|
var body=$("#body").val();
|
|
// var storeid=$("#storeid").val();
|
|
var storeid;
|
|
if(isshow){
|
|
storeid = $('#selstore>option:selected').val();
|
|
}else {
|
|
storeid = $('#storeid').val();
|
|
}
|
|
var external_id=$("#external_id").val();
|
|
var remark=$("#remark").val();
|
|
var submitorderurl= localObj.protocol+"//"+localObj.host+"/index.php/pay/"+paymod+"/SubmitOrder/wxchat/1";
|
|
var payway='WxPay';
|
|
var sub_openid=$("#openid").val();
|
|
var payurl= localObj.protocol+"//"+localObj.host+"/index.php/pay/"+paymod+"/"+payway;
|
|
var sub_appid=$("#wxappid").val();
|
|
//sub_appid='';//推荐关注公众号
|
|
var pay_type=1;
|
|
$.post(submitorderurl,{
|
|
all_money:all_money,
|
|
app:appid,
|
|
api_id:api_id,
|
|
api_id:api_id,
|
|
sub_merchant_id:sub_merchant_id,
|
|
external_id:external_id,
|
|
storeid:storeid,
|
|
pay_type:pay_type,
|
|
trade_amount:total_fee,
|
|
remark:remark,
|
|
eid:eid
|
|
}, function(ret) {
|
|
if (ret.success == true) {
|
|
var notifyurl='';
|
|
var orderid= ret.orderid;
|
|
if(notify_url!=null&¬ify_url!=''){
|
|
notifyurl=localObj.protocol+"//"+localObj.host+"/index.php/pay/"+paymod+"/"+notify_url;
|
|
}
|
|
var out_trade_no=ret.out_trade_no;
|
|
$.post(payurl,{
|
|
appid:appid,
|
|
sub_merchant_id:sub_merchant_id,
|
|
notify_url:notifyurl,
|
|
out_trade_no:out_trade_no,
|
|
sub_openid:sub_openid,
|
|
body:body,
|
|
total_fee:total_fee,
|
|
sub_appid:sub_appid
|
|
}, function(res) {
|
|
|
|
if (res.success == true) {
|
|
var prepay_id=res.return_value.prepay_id;
|
|
//var callbackurl='https://openapi-liquidation-test.51fubei.com/payPage/?prepay_id='+prepay_id;
|
|
var callbackurl=res.temp_callback;
|
|
callbackurl+="&callback_url="+localObj.protocol+"//"+localObj.host+"/index.php/pay/Notify/index/rechargeorder/"+eid+"?orderid="+orderid;
|
|
location.href=callbackurl;
|
|
} else {
|
|
alertMsg(res.error_message,1000);
|
|
}
|
|
},'json');
|
|
}else{
|
|
alertMsg(res.error_message,1000);
|
|
}
|
|
},'json');
|
|
|
|
}else{
|
|
alertMsg('该银行支付接口开发中,敬请期待!',600);
|
|
}
|
|
}
|
|
})
|
|
|
|
}else {
|
|
alertMsg('请输入金额',600);
|
|
}
|
|
}
|
|
|
|
//收起键盘
|
|
$('.back').on('touchstart',function () {
|
|
$(this).css('backgroundColor',"#ececec");
|
|
$('.back').on('touchend',function () {
|
|
$(this).css('backgroundColor',"white");
|
|
})
|
|
$('.pwd_con').hide();
|
|
pwd = '';
|
|
$('.ul>li').html('');
|
|
localStorage.marskshow = 0;
|
|
})
|
|
//删除数字
|
|
$('.delete').on('touchstart',function () {
|
|
$(this).css('backgroundColor',"#ececec");
|
|
$('.delete').on('touchend',function () {
|
|
$(this).css('backgroundColor',"white");
|
|
})
|
|
if(pwd.length){
|
|
$('.ul>li').eq(pwd.length-1).html('');
|
|
pwd = pwd.substr(0,pwd.length-1);
|
|
}
|
|
})
|
|
//输入数字
|
|
$('.pwdnum').on('touchstart',function () {
|
|
$(this).css('backgroundColor',"#ececec");
|
|
$('.pwdnum').on('touchend',function () {
|
|
$(this).css('backgroundColor',"white");
|
|
})
|
|
if(pwd.length<6){
|
|
pwd += $(this).html();
|
|
for(var i=0;i<pwd.length;i++){
|
|
$('.ul>li').eq(i).html('●');
|
|
}
|
|
}
|
|
if(pwd.length==6){
|
|
setTimeout(()=>{
|
|
var mn = parseFloat($('#num').val());
|
|
if(less){
|
|
mn = mn - less;
|
|
}
|
|
$('.ul').hide();
|
|
$('.pwdpay').hide();
|
|
$('.loading').show();
|
|
$('.top').html('支付中...');
|
|
eid = Number(eid);
|
|
|
|
var storeid;
|
|
if(isshow){
|
|
storeid = $('#selstore>option:selected').val();
|
|
}else {
|
|
storeid = $('#storeid').val();
|
|
}
|
|
$.post("/index.php/Vip/Discounts/toDiscount",{
|
|
pwd:pwd,
|
|
money:mn,
|
|
remark:$('textarea').val(),
|
|
eid:eid,
|
|
storeid:storeid
|
|
},function (data) {
|
|
$('.loading').hide();
|
|
pwd = '';
|
|
console.log(data);
|
|
if(data.success){
|
|
$('.needpay').html('支付成功');
|
|
alertMsg(data.msg,600,function () {
|
|
localStorage.discounts=1;
|
|
localStorage.viprefrash = 0;
|
|
window.location.replace("/index.php/q/index/ordersuccess/id/"+data.id);
|
|
});
|
|
}else {
|
|
alertMsg(data.msg+'<br>请重新输入',1000,function () {
|
|
$('.ul>li').html('');
|
|
$('.ul').show();
|
|
pwd = '';
|
|
$('.pwdpay').show();
|
|
$('.top').html('请输入支付密码');
|
|
});
|
|
}
|
|
})
|
|
},100)
|
|
}
|
|
}) |