|
...
|
...
|
@@ -29,22 +29,37 @@ Page({ |
|
|
|
noConfiguration: '', //配置消费金 0未配置 1已配置
|
|
|
|
returnData: '', //赠送消费金配置
|
|
|
|
isReturn: '', //赠送消费金的开关
|
|
|
|
giveConsumePrice: '', //新老用户赠送消费金额
|
|
|
|
isNewUser: '',//新用户1 老用户2
|
|
|
|
recharge_data: [], //所有满赠充值活动
|
|
|
|
payType: '2', //1余额支付 2微信支付
|
|
|
|
multiple: '', //充值几倍当餐免费
|
|
|
|
rechargeList:{},
|
|
|
|
myBalance: '', //店铺总余额
|
|
|
|
balancePay: '', //余额支付金额
|
|
|
|
soothPrice: '', //实付价格-余额的价格
|
|
|
|
countDown: '5', //5秒后自动关闭弹框
|
|
|
|
timer: null,
|
|
|
|
},
|
|
|
|
sid: '', //扫码进入带的参数商家id
|
|
|
|
couponModal: '',
|
|
|
|
giveCouponModal: '',
|
|
|
|
consumeModal: '',
|
|
|
|
giveConsume: '',
|
|
|
|
myToast:'',
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad(options) {
|
|
|
|
console.log('options----', options);
|
|
|
|
this.couponModal = this.selectComponent("#couponModal");
|
|
|
|
this.giveCouponModal = this.selectComponent("#giveCouponModal");
|
|
|
|
this.consumeModal = this.selectComponent("#consumeModal");
|
|
|
|
this.giveConsume = this.selectComponent("#giveConsume");
|
|
|
|
if (options.sid) {
|
|
|
|
this.sid = options.sid
|
|
|
|
this.getSellerDetailFun(options.sid)
|
|
|
|
this.getRechargeDetail(options.sid)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 检测用户是否绑定手机号
|
|
...
|
...
|
@@ -59,7 +74,9 @@ Page({ |
|
|
|
purePhoneNumber: data.phone,
|
|
|
|
})
|
|
|
|
this.getUserInfo()
|
|
|
|
this.getUserRechargeInfo(data.phone, '0')
|
|
|
|
} else {
|
|
|
|
this.getUserInfo()
|
|
|
|
this.setData({
|
|
|
|
purePhoneNumber: '',
|
|
|
|
})
|
|
...
|
...
|
@@ -67,6 +84,113 @@ Page({ |
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 切换支付方式
|
|
|
|
checkPay(e) {
|
|
|
|
let type = e.currentTarget.dataset['type'];
|
|
|
|
let actualPrice = this.data.actualPrice;
|
|
|
|
if (type == '1') {
|
|
|
|
let myBalance = this.data.myBalance * 1;
|
|
|
|
if (actualPrice && actualPrice > 0) {
|
|
|
|
let balancePay = actualPrice > myBalance ? myBalance : actualPrice;
|
|
|
|
let soothPrice = (actualPrice - balancePay).toFixed(2)
|
|
|
|
this.setData({
|
|
|
|
balancePay,
|
|
|
|
soothPrice,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
balancePay: '0.00',
|
|
|
|
soothPrice: actualPrice,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.setData({
|
|
|
|
payType: type,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 根据充值ID获取充值详情
|
|
|
|
getRechargeDetail(sellerid) {
|
|
|
|
App.Activity.GetNewRechargeList({
|
|
|
|
sellerid,
|
|
|
|
}).then(res => {
|
|
|
|
if (res.data) {
|
|
|
|
let arr = []
|
|
|
|
res.data.forEach(i => {
|
|
|
|
if (i.status != '1') {
|
|
|
|
arr.push(i)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
let recharge_data = arr;
|
|
|
|
recharge_data.forEach(item => {
|
|
|
|
item.recharge_list = item.recharge_list ? JSON.parse(item.recharge_list) : '';
|
|
|
|
let recharge_list = item.recharge_list;
|
|
|
|
item.timeStr = util.unixtoTime(item.stime, 'YYYY-MM-DD') + ' - ' + util.unixtoTime(item.etime, 'YYYY-MM-DD')
|
|
|
|
})
|
|
|
|
// 筛选出 未过期的 && 开启状态的充值活动
|
|
|
|
recharge_data = recharge_data.filter(item => {
|
|
|
|
return this.data.dataStr < (item.etime * 1) && item.is_open == '1'
|
|
|
|
})
|
|
|
|
console.log('所有充值活动--------------', recharge_data);
|
|
|
|
this.setData({
|
|
|
|
recharge_data,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
recharge_data: [],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取用户在商家的账户余额
|
|
|
|
getUserRechargeInfo(phone, type) {
|
|
|
|
App.Activity.GetRechargeBalanceByOpenid({
|
|
|
|
openid: getApp().openid,
|
|
|
|
phone,
|
|
|
|
sellerid: this.sid,
|
|
|
|
}).then((json) => {
|
|
|
|
if (json.ret == 200) {
|
|
|
|
let data = json.data;
|
|
|
|
if (data) {
|
|
|
|
console.log('获取用户在商家的余额----', data.recharge_balance);
|
|
|
|
this.setData({
|
|
|
|
myBalance: data.recharge_balance ? (data.recharge_balance * 1).toFixed(2) : '0.00',
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
if (type == '1') this.createInfoFun(phone)
|
|
|
|
console.log('用户在商家没有账号');
|
|
|
|
this.setData({
|
|
|
|
myBalance: null,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 用户绑定手机号
|
|
|
|
bindUserPhoneFun(phone) {
|
|
|
|
console.log('用户绑定手机号');
|
|
|
|
let params = {
|
|
|
|
phone,
|
|
|
|
openid: getApp().openid,
|
|
|
|
}
|
|
|
|
App.Wechat.BindUserPhone(params).then(res => {
|
|
|
|
if (res.ret == 200) {
|
|
|
|
console.log(res, '用户绑定手机号');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 如果该用户不存在账户 新增用户在商家的账户信息
|
|
|
|
createInfoFun(phone) {
|
|
|
|
let params = {
|
|
|
|
openid: getApp().openid,
|
|
|
|
sellerid: this.data.seller.sid,
|
|
|
|
phone
|
|
|
|
}
|
|
|
|
App.Activity.CreateCustomerConsumeSeller(params).then(res => {
|
|
|
|
if (res.ret == 200) {
|
|
|
|
console.log('新增用户在商家的账户信息----', res);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取用户在商家&所有消费金
|
|
|
|
getUserInfo() {
|
|
|
|
App.Activity.GetConsumeBySeller({
|
|
...
|
...
|
@@ -90,11 +214,55 @@ Page({ |
|
|
|
consumeDiscount: '0.00', //消费金抵扣金额
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.getIdentityFun()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取当餐免费的配置信息
|
|
|
|
getFreeMealConfigFun() {
|
|
|
|
App.Activity.GetFreeMealConfigBySeller({
|
|
|
|
sellerid: this.sid,
|
|
|
|
}).then(res => {
|
|
|
|
if (res && res.data && res.data.length > 0 && res.data[0].is_open == '1') {
|
|
|
|
let data = res.data[0];
|
|
|
|
let list = data.recharge_list ? JSON.parse(data.recharge_list) : {}
|
|
|
|
list.priceInfo = '';
|
|
|
|
list.scoreInfo = '';
|
|
|
|
list.certificate = '';
|
|
|
|
if (list.is_price == '1') list.priceInfo = '赠' + list.price + '元余额';
|
|
|
|
if (list.is_score == '1') list.scoreInfo = '赠' + list.score + '积分';
|
|
|
|
if (list.is_coupons == '1' && list.coupons_names.length > 0) list.certificate = '赠' + list.coupons_names.join('、') + '券';;
|
|
|
|
this.setData({
|
|
|
|
multiple: data.multiple,
|
|
|
|
rechargeList: list
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
multiple: '',
|
|
|
|
rechargeList: {}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取用户在当前商家身份及是否领取过消费金
|
|
|
|
getIdentityFun(){
|
|
|
|
App.Activity.GetIdentityBySeller({
|
|
|
|
sellerid: this.sid,
|
|
|
|
openid: getApp().openid,
|
|
|
|
phone: this.data.purePhoneNumber,
|
|
|
|
}).then(res => {
|
|
|
|
let is_get_consume = '1'
|
|
|
|
if (res && res.data) {
|
|
|
|
is_get_consume = res.data.is_get_consume
|
|
|
|
this.setData({
|
|
|
|
isNewUser:res.data.identity,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.getConsumeConfigFun(is_get_consume)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取商家消费金规则
|
|
|
|
getConsumeConfigFun() {
|
|
|
|
getConsumeConfigFun(isConsume) {
|
|
|
|
App.Activity.GetConsumeConfig({
|
|
|
|
sellerid: this.sid,
|
|
|
|
}).then(res => {
|
|
...
|
...
|
@@ -102,17 +270,42 @@ Page({ |
|
|
|
let data = res.data;
|
|
|
|
let together = util.determine(data.together_json);
|
|
|
|
let returnData = util.determine(data.return_json);
|
|
|
|
returnData.ladder_data = returnData.ladder_data ? util.determine(returnData.ladder_data) : {};
|
|
|
|
let beforePay = util.determine(data.before_pay_json);
|
|
|
|
if(beforePay && beforePay.new) beforePay.new = util.determine(beforePay.new);
|
|
|
|
if(beforePay && beforePay.old) beforePay.old = util.determine(beforePay.old);
|
|
|
|
console.log('returnData---',returnData);
|
|
|
|
if(returnData && returnData.ladder_data) returnData.ladder_data = util.determine(returnData.ladder_data);
|
|
|
|
console.log('111配置---',together);
|
|
|
|
console.log('222顾客支付后返消费金---',returnData);
|
|
|
|
console.log('3333新老用户领取消费金---',beforePay);
|
|
|
|
let time = Math.floor(Date.now() / 1000)
|
|
|
|
let giveConsumePrice = '';
|
|
|
|
if(beforePay){
|
|
|
|
// 新用户 && 没有领取过 && 开启新用户领取
|
|
|
|
if(this.data.isNewUser == 'new' && isConsume == '0' && beforePay.new && beforePay.is_new == '1'){
|
|
|
|
let newData = beforePay.new;
|
|
|
|
if((time > newData.stime) && (time < newData.etime)){
|
|
|
|
giveConsumePrice = newData.is_fix == '1'?newData.fix_price :this.getRandomInt(newData.random_min, newData.random_max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 老用户 && 个人消费金大于0 && 开启老用户领取
|
|
|
|
if(this.data.isNewUser == 'old' && this.data.consumePrice == '0.00' && beforePay.old && beforePay.is_old == '1'){
|
|
|
|
let oldData = beforePay.old;
|
|
|
|
if((time > oldData.stime) && (time < oldData.etime)){
|
|
|
|
giveConsumePrice = oldData.is_fix == '1'?oldData.fix_price :this.getRandomInt(oldData.random_min, oldData.random_max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log('giveConsumePrice-------',giveConsumePrice);
|
|
|
|
}
|
|
|
|
this.setData({
|
|
|
|
noConfiguration: '1', //配置为1 未配置为0
|
|
|
|
coexist: together.is_coexist,
|
|
|
|
ratio: together.ratio_data ? together.ratio_data : '100',
|
|
|
|
coexist: together?together.is_coexist:'',
|
|
|
|
ratio: together && together.ratio_data ? together.ratio_data : '100',
|
|
|
|
couponSwitch: true,
|
|
|
|
consumeSwitch: together.is_coexist == '1' ? true : false,
|
|
|
|
consumeSwitch: together && together.is_coexist == '1' ? true : false,
|
|
|
|
returnData,
|
|
|
|
isReturn: data.is_return,
|
|
|
|
giveConsumePrice,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
...
|
...
|
@@ -121,6 +314,7 @@ Page({ |
|
|
|
consumeSwitch: false,
|
|
|
|
returnData: null,
|
|
|
|
isReturn: '0',
|
|
|
|
giveConsumePrice:'',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
...
|
...
|
@@ -155,11 +349,18 @@ Page({ |
|
|
|
if (!this.data.couponSwitch) {
|
|
|
|
this.getCoupon()
|
|
|
|
let val = parseFloat(this.data.inputValue);
|
|
|
|
if (!val) return
|
|
|
|
let discountPrice = 0;
|
|
|
|
let actualPrice = (val - this.data.consumeDiscount - discountPrice).toFixed(2)
|
|
|
|
console.log('actualPrice----', actualPrice);
|
|
|
|
let myBalance = this.data.myBalance * 1;
|
|
|
|
let balancePay = (this.data.payType == '1' && actualPrice > myBalance) ? myBalance : actualPrice;
|
|
|
|
let soothPrice = this.data.payType == '1' ? (actualPrice - balancePay).toFixed(2) : actualPrice;
|
|
|
|
this.setData({
|
|
|
|
discountPrice: 0,
|
|
|
|
actualPrice: actualPrice > 0 ? actualPrice : '0.01'
|
|
|
|
actualPrice,
|
|
|
|
balancePay,
|
|
|
|
soothPrice,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// 开或者关闭使用消费金
|
|
...
|
...
|
@@ -170,10 +371,15 @@ Page({ |
|
|
|
let discountPrice = this.data.couponSwitch ? this.data.discountPrice : 0
|
|
|
|
let actualPrice = (val - consumeDiscount - discountPrice).toFixed(2)
|
|
|
|
let remainingConsume = (this.data.consumePrice * 1 - consumeDiscount).toFixed(2)
|
|
|
|
let myBalance = this.data.myBalance * 1;
|
|
|
|
let balancePay = (this.data.payType == '1' && actualPrice > myBalance) ? myBalance : actualPrice;
|
|
|
|
let soothPrice = this.data.payType == '1' ? (actualPrice - balancePay).toFixed(2) : actualPrice;
|
|
|
|
this.setData({
|
|
|
|
consumeDiscount,
|
|
|
|
actualPrice: actualPrice > 0 ? actualPrice : '0.01',
|
|
|
|
remainingConsume: remainingConsume
|
|
|
|
actualPrice,
|
|
|
|
remainingConsume: remainingConsume,
|
|
|
|
balancePay,
|
|
|
|
soothPrice,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (!this.data.consumeSwitch) {
|
|
...
|
...
|
@@ -182,10 +388,15 @@ Page({ |
|
|
|
let discountPrice = this.data.couponSwitch ? this.data.discountPrice : 0
|
|
|
|
let consumeDiscount = this.data.consumeSwitch ? this.data.consumeDiscount : 0
|
|
|
|
let actualPrice = (val - consumeDiscount - discountPrice).toFixed(2)
|
|
|
|
let myBalance = this.data.myBalance * 1;
|
|
|
|
let balancePay = (this.data.payType == '1' && actualPrice > myBalance) ? myBalance : actualPrice;
|
|
|
|
let soothPrice = this.data.payType == '1' ? (actualPrice - balancePay).toFixed(2) : actualPrice;
|
|
|
|
this.setData({
|
|
|
|
consumeDiscount: '0.00',
|
|
|
|
actualPrice: actualPrice > 0 ? actualPrice : '0.01',
|
|
|
|
actualPrice,
|
|
|
|
remainingConsume: this.data.consumePrice,
|
|
|
|
balancePay,
|
|
|
|
soothPrice,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
...
|
...
|
@@ -218,18 +429,119 @@ Page({ |
|
|
|
closeConsumeModal() {
|
|
|
|
this.consumeModal.closeModal()
|
|
|
|
},
|
|
|
|
// 打开赠送消费金弹框
|
|
|
|
showGiveConsumeModal() {
|
|
|
|
let num = this.data.giveConsumePrice;
|
|
|
|
this.setData({
|
|
|
|
giveConsumePrice: num
|
|
|
|
})
|
|
|
|
this.giveConsume.showModal()
|
|
|
|
this.setData({
|
|
|
|
countDown: 5,
|
|
|
|
})
|
|
|
|
if (this.data.timer) {
|
|
|
|
clearInterval(this.data.timer);
|
|
|
|
}
|
|
|
|
this.startCountDown();
|
|
|
|
console.log('送消费金----',num);
|
|
|
|
},
|
|
|
|
// 开始倒计时
|
|
|
|
startCountDown() {
|
|
|
|
let that = this;
|
|
|
|
const timer = setInterval(() => {
|
|
|
|
if (that.data.countDown <= 1) {
|
|
|
|
that.closeGiveConsumeModal()
|
|
|
|
clearInterval(timer);
|
|
|
|
that.setData({
|
|
|
|
timer: null
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
that.setData({
|
|
|
|
countDown: that.data.countDown - 1
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
this.setData({
|
|
|
|
timer
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// 关闭消费金弹框
|
|
|
|
closeGiveConsumeModal() {
|
|
|
|
this.giveConsume.closeModal()
|
|
|
|
this.getConsumeFun(this.data.giveConsumePrice,'1')
|
|
|
|
},
|
|
|
|
// 选择充值活动
|
|
|
|
checkRechargeData(e) {
|
|
|
|
let id = e.currentTarget.dataset['id'];
|
|
|
|
console.log('id', id);
|
|
|
|
if (!id) {
|
|
|
|
let price = this.data.actualPrice * 1 * this.data.multiple
|
|
|
|
if (!price) return false
|
|
|
|
let str = this.data.finalList.map(item => item.activity_id).join(',');
|
|
|
|
console.log('核销所勾选的券传参', str);
|
|
|
|
let params = {
|
|
|
|
type: '2',
|
|
|
|
types: '4', // 1邀请函 2提前点餐 3商家端app分享 4支付页充值 5我的页面余额充值
|
|
|
|
sid: this.sid,
|
|
|
|
totalize: price.toFixed(2), //充值几倍金额
|
|
|
|
name: this.data.seller.sellername,
|
|
|
|
isFree: '1',
|
|
|
|
multiple: this.data.multiple,
|
|
|
|
inputValue: this.data.inputValue, //订单实际应该支付金额(扣除消费金、券之前)
|
|
|
|
}
|
|
|
|
// 消费金开关开启 && 消费金抵扣金额大于0
|
|
|
|
if (this.data.consumeDiscount * 1 > 0 && this.data.consumeSwitch) {
|
|
|
|
params.consume = this.data.consumeDiscount;
|
|
|
|
}
|
|
|
|
if (str) {
|
|
|
|
params.activity_id = str;
|
|
|
|
}
|
|
|
|
if (this.data.givePrice) {
|
|
|
|
params.givePrice = this.data.givePrice; //当餐免费送的余额
|
|
|
|
}
|
|
|
|
let url = util.http_build_query({
|
|
|
|
...params
|
|
|
|
}, '/pack-activity/pack/vipRecharge')
|
|
|
|
return wx.navigateTo({
|
|
|
|
url
|
|
|
|
})
|
|
|
|
}
|
|
|
|
wx.navigateTo({
|
|
|
|
url: util.http_build_query({
|
|
|
|
id,
|
|
|
|
name: this.data.seller.sellername,
|
|
|
|
sid: this.sid,
|
|
|
|
types: '4',
|
|
|
|
isFree: '0',
|
|
|
|
}, '/pack-activity/pack/vipRecharge')
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 关闭优惠券弹框
|
|
|
|
closegiveCouponModal() {
|
|
|
|
this.giveCouponModal.closeModal()
|
|
|
|
this.getUserInfo()
|
|
|
|
},
|
|
|
|
// 跳转登录页
|
|
|
|
gotoLogin(event) {
|
|
|
|
wx.navigateTo({
|
|
|
|
url: util.http_build_query({
|
|
|
|
types: event.currentTarget.dataset.types
|
|
|
|
}, '/pages/customer/login')
|
|
|
|
})
|
|
|
|
// 获取code、手机号
|
|
|
|
getPhoneNumberFun(e) {
|
|
|
|
console.log('eeeeeeeeee', e.detail);
|
|
|
|
if (e.detail && e.detail.code) {
|
|
|
|
App.Wechat.GetUserPhoneNumber({
|
|
|
|
code: e.detail.code,
|
|
|
|
}).then(res => {
|
|
|
|
console.log('resresres----', res);
|
|
|
|
if (res.ret == 200 && res.data && res.data.phone_info && res.data.phone_info.purePhoneNumber) {
|
|
|
|
this.setData({
|
|
|
|
purePhoneNumber: res.data.phone_info.purePhoneNumber,
|
|
|
|
})
|
|
|
|
this.getUserInfo()
|
|
|
|
this.bindUserPhoneFun(res.data.phone_info.purePhoneNumber)
|
|
|
|
this.getUserRechargeInfo(res.data.phone_info.purePhoneNumber, '1')
|
|
|
|
} else {
|
|
|
|
this.getUserInfo()
|
|
|
|
util.toast('手机号获取失败!', 'none')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 获取店铺名称
|
|
|
|
getSellerDetailFun(sid) {
|
|
...
|
...
|
@@ -266,9 +578,9 @@ Page({ |
|
|
|
if (now >= parseInt(fullData.stime) && now <= parseInt(fullData.etime)) {
|
|
|
|
// rule 1每满门槛均发放(满50送一张券,金额是100送2张)
|
|
|
|
// rule 0仅发放一次(每次满足金额一个券只发一张)
|
|
|
|
const price = parseFloat(fullData.price)
|
|
|
|
const amount = parseInt(priceSum / price)
|
|
|
|
if (fullData.rule == '1') {
|
|
|
|
const price = parseFloat(fullData.price)
|
|
|
|
const amount = parseInt(priceSum / price)
|
|
|
|
if (coupons.length > 0 && amount > 0) this.getCouponFun(coupons, '1', amount,orderid)
|
|
|
|
} else {
|
|
|
|
if (coupons.length > 0 && amount > 0) this.getCouponFun(coupons, '1', 1,orderid)
|
|
...
|
...
|
@@ -367,8 +679,6 @@ Page({ |
|
|
|
}).then(res => {
|
|
|
|
if (res.ret == 200 && res.data && res.data.length > 0) {
|
|
|
|
let list = res.data
|
|
|
|
// console.log('listlistlist',JSON.stringify(list));
|
|
|
|
// list= list.concat(monidata)
|
|
|
|
list.forEach(detail => {
|
|
|
|
detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
|
|
|
|
detail.arule = detail.arule ? util.determine(detail.arule) : '';
|
|
...
|
...
|
@@ -520,7 +830,10 @@ Page({ |
|
|
|
discountPrice: '',
|
|
|
|
actualPrice: '',
|
|
|
|
consumeDiscount: '',
|
|
|
|
remainingConsume: this.data.consumePrice
|
|
|
|
remainingConsume: this.data.consumePrice,
|
|
|
|
soothPrice: '',
|
|
|
|
balancePay: '',
|
|
|
|
payType: '2',
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
if (this.data.couponSwitch) {
|
|
...
|
...
|
@@ -531,17 +844,24 @@ Page({ |
|
|
|
let consumeDiscount = this.calculateConsumeGold(val);
|
|
|
|
let actualPrice = (val - consumeDiscount - this.data.discountPrice).toFixed(2)
|
|
|
|
let remainingConsume = (this.data.consumePrice * 1 - consumeDiscount).toFixed(2)
|
|
|
|
let myBalance = this.data.myBalance * 1;
|
|
|
|
let balancePay = (this.data.payType == '1' && actualPrice > myBalance) ? myBalance : actualPrice;
|
|
|
|
let soothPrice = this.data.payType == '1' ? (actualPrice - balancePay).toFixed(2) : actualPrice;
|
|
|
|
this.setData({
|
|
|
|
consumeDiscount,
|
|
|
|
actualPrice: actualPrice > 0 ? actualPrice : '0.01',
|
|
|
|
remainingConsume: remainingConsume
|
|
|
|
actualPrice: actualPrice,
|
|
|
|
remainingConsume: remainingConsume,
|
|
|
|
balancePay,
|
|
|
|
soothPrice
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 点确认选择
|
|
|
|
checkCertificate() {
|
|
|
|
let inputValue = parseFloat(this.data.inputValue);
|
|
|
|
this.closeCouponModal()
|
|
|
|
if (!inputValue) return
|
|
|
|
let list = this.data.couponArr;
|
|
|
|
list = list.filter(i => {
|
|
|
|
return i.checked
|
|
...
|
...
|
@@ -554,9 +874,14 @@ Page({ |
|
|
|
let val = parseFloat(this.data.inputValue);
|
|
|
|
let actualPrice = (val - price - this.data.consumeDiscount).toFixed(2)
|
|
|
|
price = price.toFixed(2)
|
|
|
|
let myBalance = this.data.myBalance * 1;
|
|
|
|
let balancePay = (this.data.payType == '1' && actualPrice > myBalance) ? myBalance : actualPrice;
|
|
|
|
let soothPrice = this.data.payType == '1' ? (actualPrice - balancePay).toFixed(2) : actualPrice;
|
|
|
|
this.setData({
|
|
|
|
discountPrice: price,
|
|
|
|
actualPrice: actualPrice > 0 ? actualPrice : 0.01,
|
|
|
|
actualPrice,
|
|
|
|
balancePay,
|
|
|
|
soothPrice,
|
|
|
|
})
|
|
|
|
console.log('点确认选择后', list);
|
|
|
|
},
|
|
...
|
...
|
@@ -569,20 +894,28 @@ Page({ |
|
|
|
console.log('处理过后的券数据', list);
|
|
|
|
list.sort((a, b) => b.canCheck - a.canCheck);
|
|
|
|
list.sort((a, b) => b.showCpupon - a.showCpupon);
|
|
|
|
let consumeDiscount = '';
|
|
|
|
let amount = parseFloat(this.data.inputValue);
|
|
|
|
if (this.data.consumeSwitch) {
|
|
|
|
let amount = parseFloat(this.data.inputValue);
|
|
|
|
let num = (amount - this.data.discountPrice).toFixed(2);
|
|
|
|
let val = parseFloat(num);
|
|
|
|
let consumeDiscount = this.calculateConsumeGold(val);
|
|
|
|
let actualPrice = (amount - consumeDiscount - this.data.discountPrice).toFixed(2)
|
|
|
|
let remainingConsume = (this.data.consumePrice * 1 - consumeDiscount).toFixed(2)
|
|
|
|
consumeDiscount = this.calculateConsumeGold(val);
|
|
|
|
this.setData({
|
|
|
|
consumeDiscount,
|
|
|
|
actualPrice: actualPrice > 0 ? actualPrice : '0.01',
|
|
|
|
remainingConsume: remainingConsume
|
|
|
|
})
|
|
|
|
}
|
|
|
|
let actualPrice = (amount - consumeDiscount - this.data.discountPrice).toFixed(2)
|
|
|
|
let remainingConsume = (this.data.consumePrice * 1 - consumeDiscount).toFixed(2)
|
|
|
|
let myBalance = this.data.myBalance * 1;
|
|
|
|
let balancePay = (this.data.payType == '1' && actualPrice > myBalance) ? myBalance : actualPrice;
|
|
|
|
let soothPrice = this.data.payType == '1'?(actualPrice - balancePay).toFixed(2):actualPrice
|
|
|
|
console.log('实际支付金额:', actualPrice);
|
|
|
|
this.setData({
|
|
|
|
consumeDiscount,
|
|
|
|
actualPrice,
|
|
|
|
remainingConsume: remainingConsume,
|
|
|
|
soothPrice,
|
|
|
|
balancePay,
|
|
|
|
couponArr: list,
|
|
|
|
finalList: obj.finalList
|
|
|
|
})
|
|
...
|
...
|
@@ -591,9 +924,9 @@ Page({ |
|
|
|
confirmPayment: util.throttle(function () {
|
|
|
|
let that = this;
|
|
|
|
let actualPrice = this.data.actualPrice
|
|
|
|
if (actualPrice <= 0) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
wx.showLoading({
|
|
|
|
title: '支付中',
|
|
|
|
})
|
|
|
|
let str = this.data.finalList.map(item => item.activity_id).join(',');
|
|
|
|
console.log('核销所勾选的券传参', str);
|
|
|
|
let params = {
|
|
...
|
...
|
@@ -607,9 +940,46 @@ Page({ |
|
|
|
if (str) {
|
|
|
|
params.activity_id = str;
|
|
|
|
}
|
|
|
|
// 用余额支付 || 支付金额为0
|
|
|
|
if (this.data.soothPrice == '0.00') {
|
|
|
|
let obj = {
|
|
|
|
openid: getApp().openid,
|
|
|
|
sellerid: this.data.seller.sid,
|
|
|
|
price: this.data.inputValue,
|
|
|
|
phone: this.data.purePhoneNumber,
|
|
|
|
recharge_balance: this.data.balancePay * 1,
|
|
|
|
}
|
|
|
|
if (str) {
|
|
|
|
obj.activity_id = str;
|
|
|
|
}
|
|
|
|
let consumeDiscount = this.data.consumeDiscount * 1
|
|
|
|
if (consumeDiscount > 0) {
|
|
|
|
obj.consume = this.data.consumeDiscount;
|
|
|
|
}
|
|
|
|
console.log('用余额支付objobj----', obj);
|
|
|
|
App.Activity.CreateRechargeBalanceOrder({
|
|
|
|
...obj
|
|
|
|
}).then(res => {
|
|
|
|
console.log('付款信息', res.data);
|
|
|
|
if (res.ret != '200') {
|
|
|
|
wx.hideLoading()
|
|
|
|
return wx.showToast({
|
|
|
|
title: res.msg,
|
|
|
|
duration: 1000,
|
|
|
|
icon: 'none',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (res.ret == '200') {
|
|
|
|
that.deductBalance(actualPrice, res.data.id)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// 微信支付
|
|
|
|
App.PayOnline.CombineTransactionsByNewActivity(params).then(res => {
|
|
|
|
console.log('付款信息', res.data);
|
|
|
|
if (res.ret != '200') {
|
|
|
|
wx.hideLoading()
|
|
|
|
wx.showToast({
|
|
|
|
title: res.msg,
|
|
|
|
duration: 1000,
|
|
...
|
...
|
@@ -624,20 +994,19 @@ Page({ |
|
|
|
signType: res.data.signType,
|
|
|
|
paySign: res.data.paySign,
|
|
|
|
success(ress) {
|
|
|
|
wx.hideLoading()
|
|
|
|
if (ress.errMsg == 'requestPayment:ok') {
|
|
|
|
that.giftCouponsFun(actualPrice,res.data.orderid) //送券
|
|
|
|
that.giftConsumeFun(actualPrice, res.data.orderid) //送消费金
|
|
|
|
setTimeout(() => {
|
|
|
|
console.log('送券金额----', that.data.totalPrice);
|
|
|
|
console.log('送消费金----', that.data.totalConsumePrice);
|
|
|
|
if (that.data.totalPrice > 0 || that.data.totalConsumePrice > 0) {
|
|
|
|
wx.reLaunch({
|
|
|
|
url: util.http_build_query({
|
|
|
|
totalPrice: that.data.totalPrice,
|
|
|
|
totalConsumePrice: that.data.totalConsumePrice,
|
|
|
|
}, '/pack-activity/pack/paySuccess')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
console.log('2送券金额----', that.data.totalPrice);
|
|
|
|
console.log('2送消费金----', that.data.totalConsumePrice);
|
|
|
|
wx.reLaunch({
|
|
|
|
url: util.http_build_query({
|
|
|
|
totalPrice: that.data.totalPrice,
|
|
|
|
totalConsumePrice: that.data.totalConsumePrice,
|
|
|
|
}, '/pack-activity/pack/paySuccess')
|
|
|
|
})
|
|
|
|
}, 1000);
|
|
|
|
console.log('支付成功', ress);
|
|
|
|
return
|
|
...
|
...
|
@@ -647,6 +1016,7 @@ Page({ |
|
|
|
return that.myToast.showToast('支付失败,请重新下单', 2000)
|
|
|
|
},
|
|
|
|
fail(ress) {
|
|
|
|
wx.hideLoading()
|
|
|
|
that.payFail()
|
|
|
|
console.log('支付失败22', ress);
|
|
|
|
return that.myToast.showToast('支付失败,请重新下单', 2000)
|
|
...
|
...
|
@@ -655,6 +1025,37 @@ Page({ |
|
|
|
}
|
|
|
|
})
|
|
|
|
},3000),
|
|
|
|
// 扣除支付的余额
|
|
|
|
deductBalance(actualPrice, id) {
|
|
|
|
let that = this;
|
|
|
|
let recharge_balance = this.data.balancePay * 1
|
|
|
|
App.Activity.SetRechargeBalanceByOpenid({
|
|
|
|
openid: getApp().openid,
|
|
|
|
recharge_balance,
|
|
|
|
sellerid: this.data.seller.sid,
|
|
|
|
type: '2',
|
|
|
|
}).then(res => {
|
|
|
|
if (res.ret == 200) {
|
|
|
|
wx.hideLoading()
|
|
|
|
console.log('扣除余额成功');
|
|
|
|
that.giftCouponsFun(actualPrice, id) //送券
|
|
|
|
that.giftConsumeFun(actualPrice, id) //送消费金
|
|
|
|
setTimeout(() => {
|
|
|
|
console.log('1送券金额----', that.data.totalPrice);
|
|
|
|
console.log('1送消费金----', that.data.totalConsumePrice);
|
|
|
|
wx.reLaunch({
|
|
|
|
url: util.http_build_query({
|
|
|
|
totalPrice: that.data.totalPrice,
|
|
|
|
totalConsumePrice: that.data.totalConsumePrice,
|
|
|
|
}, '/pack-activity/pack/paySuccess')
|
|
|
|
})
|
|
|
|
}, 1000);
|
|
|
|
} else {
|
|
|
|
wx.hideLoading()
|
|
|
|
that.myToast.showToast('支付失败,请重新下单', 2000)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
payFail() {
|
|
|
|
this.setData({
|
|
|
|
inputValue: '',
|
|
...
|
...
|
@@ -663,6 +1064,9 @@ Page({ |
|
|
|
discountPrice: '0.00',
|
|
|
|
actualPrice: '',
|
|
|
|
consumeDiscount: '0.00', //消费金抵扣金额
|
|
|
|
balancePay:'',
|
|
|
|
payType:'2',
|
|
|
|
soothPrice: '',
|
|
|
|
})
|
|
|
|
this.getCoupon()
|
|
|
|
this.getUserInfo()
|
|
...
|
...
|
@@ -691,20 +1095,15 @@ Page({ |
|
|
|
}
|
|
|
|
},
|
|
|
|
// 为用户增加消费金
|
|
|
|
getConsumeFun(amount) {
|
|
|
|
getConsumeFun(amount,type) {
|
|
|
|
App.Activity.SetConsumeByOpenid({
|
|
|
|
phone: this.data.purePhoneNumber,
|
|
|
|
openid: getApp().openid,
|
|
|
|
amount,
|
|
|
|
sellerid: this.data.seller.sid
|
|
|
|
}).then(res => {
|
|
|
|
if (res.data == '0') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '消费金领取失败!',
|
|
|
|
duration: 1000,
|
|
|
|
icon: 'none',
|
|
|
|
mask: true
|
|
|
|
});
|
|
|
|
if(type == '1'){
|
|
|
|
this.getUserInfo()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
...
|
...
|
@@ -922,14 +1321,13 @@ Page({ |
|
|
|
});
|
|
|
|
discountPrice = discountPrice.toFixed(2)
|
|
|
|
console.log('总优惠金额:', discountPrice);
|
|
|
|
let actualPrice = (amount - discountPrice).toFixed(2);
|
|
|
|
console.log('实际支付金额:', actualPrice);
|
|
|
|
console.log('消费金抵扣:',this.data.consumeDiscount);
|
|
|
|
this.setData({
|
|
|
|
discountPrice,
|
|
|
|
actualPrice: actualPrice > 0 ? actualPrice : '0.01', // 确保实际支付金额不小于0.01
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
arr,
|
|
|
|
discountPrice,
|
|
|
|
finalList, // 返回可叠加和不可叠加的优惠券组合
|
|
|
|
};
|
|
|
|
},
|
|
...
|
...
|
@@ -1061,7 +1459,6 @@ Page({ |
|
|
|
var month = curdate.getMonth() + 1;
|
|
|
|
var date = Math.floor((curdate.getTime() % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60 * 24)) + 1; // 计算当前日期
|
|
|
|
var formattedDate = year + "-" + month + "-" + date;
|
|
|
|
obj.isshow = '0'
|
|
|
|
//在节假日数组内
|
|
|
|
if ((holidays.indexOf(formattedDate) >= 0) && nWeekend.indexOf(formattedDate) < 0) {
|
|
|
|
obj.isshow = '1'
|
|
...
|
...
|
@@ -1185,6 +1582,11 @@ Page({ |
|
|
|
url: '/pages/me/consumeAmount'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getRandomInt(min, max) {
|
|
|
|
min = Math.ceil(min);
|
|
|
|
max = Math.floor(max);
|
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
...
|
...
|
@@ -1196,7 +1598,7 @@ Page({ |
|
|
|
*/
|
|
|
|
onShow() {
|
|
|
|
this.getCheckUserHavePhone()
|
|
|
|
this.getConsumeConfigFun()
|
|
|
|
this.getFreeMealConfigFun()
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|