修改积分计算
This commit is contained in:
@@ -204,7 +204,7 @@
|
||||
<view class="">积分抵扣</view>
|
||||
<view class="color-999 u-m-l-10">
|
||||
<text>(</text>
|
||||
<text>{{ pageData.user.accountPoints || "0" }}</text>
|
||||
<text>{{ pageData.user.pointBalance || "0" }}</text>
|
||||
<text>)</text>
|
||||
</view>
|
||||
<!-- <view><text class="color-red font-bold">{{accountPoints.price}}</text>元</view> -->
|
||||
@@ -215,16 +215,15 @@
|
||||
><text>{{ accountPoints.num }}</text></view
|
||||
>
|
||||
<view
|
||||
v-if="accountPoints.calcRes.usable"
|
||||
v-if="pointDeductionRule.enableRewards"
|
||||
@click.stop="refPointsOpen"
|
||||
>
|
||||
<up-icon name="edit-pen" size="16" color="#999"></up-icon>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view
|
||||
class="u-m-l-32 u-relative"
|
||||
v-if="accountPoints.calcRes.usable"
|
||||
v-if="pointDeductionRule.enableRewards"
|
||||
>
|
||||
<view class="u-absolute position-all"></view>
|
||||
<my-radio :modelValue="accountPoints.sel"> </my-radio>
|
||||
@@ -238,15 +237,12 @@
|
||||
</view>
|
||||
<view class="" v-if="accountPoints.calcRes.usable">
|
||||
<text class="color-red">*</text>
|
||||
<text class="" v-if="accountPoints.calcRes.equivalentPoints"
|
||||
>{{
|
||||
accountPoints.calcRes.equivalentPoints
|
||||
}}积分等于1元,</text
|
||||
<text class="" v-if="pointDeductionRule.enableRewards"
|
||||
>「可用积分{{ pageData.user.id?pageData.user.pointBalance:0}},最大可抵扣{{
|
||||
maxPointDiscount
|
||||
}}元」</text
|
||||
>
|
||||
<text>
|
||||
最大抵扣积分{{ accountPoints.calcRes.maxUsablePoints }}
|
||||
</text>
|
||||
<text>, 最小抵扣积分0 </text>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
<view class="u-m-t-60 u-p-b-30">
|
||||
@@ -355,6 +351,7 @@ const cartStore = useCartStore();
|
||||
import { getHistoryOrder } from "@/http/api/order.js";
|
||||
import { getPayTypeList } from "@/http/api/payType.js";
|
||||
import { shopUserDetail } from "@/http/api/shopUser.js";
|
||||
import { pointsConfig } from "@/http/yskApi/market/points.js";
|
||||
import { discountActivity } from "@/http/yskApi/market/discountActivity.js";
|
||||
|
||||
import {
|
||||
@@ -448,11 +445,34 @@ async function getDiscountActivity() {
|
||||
fullReductionActivities.value = res ? [res] : [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function getPointsConfig() {
|
||||
let res = await pointsConfig();
|
||||
if (res) {
|
||||
const {
|
||||
equivalentPoints,
|
||||
maxDeductionAmount,
|
||||
enableRewards,
|
||||
minPaymentAmount,
|
||||
maxDeductionRatio
|
||||
} = res
|
||||
|
||||
pointDeductionRule.pointsPerYuan = equivalentPoints || 0;
|
||||
pointDeductionRule.maxDeductionAmount = maxDeductionAmount || 0;
|
||||
pointDeductionRule.maxDeductionRatio = maxDeductionRatio || 0;
|
||||
pointDeductionRule.enableRewards = enableRewards || 0;
|
||||
pointDeductionRule.minPaymentAmount = minPaymentAmount || 0;
|
||||
console.log('pointDeductionRule',pointDeductionRule);
|
||||
}
|
||||
}
|
||||
onLoad(async (opt) => {
|
||||
Object.assign(order, opt);
|
||||
Object.assign(options, opt);
|
||||
await getPayType();
|
||||
await getDiscountActivity();
|
||||
await getPointsConfig()
|
||||
console.log("pays.payTypes.list");
|
||||
init();
|
||||
});
|
||||
@@ -572,8 +592,11 @@ const merchantReductionConfig = reactive({
|
||||
});
|
||||
//积分规则
|
||||
const pointDeductionRule = reactive({
|
||||
enableRewards: 0, //是否开启
|
||||
pointsPerYuan: 0,
|
||||
maxDeductionAmount: Infinity,
|
||||
maxDeductionRatio: 0, //积分抵扣比例
|
||||
minPaymentAmount: 0, //门槛
|
||||
});
|
||||
//餐费费
|
||||
const seatFeeConfig = reactive({
|
||||
@@ -674,7 +697,7 @@ watch(
|
||||
() => accountPoints.sel,
|
||||
(newval) => {
|
||||
if (newval) {
|
||||
userPoints.value = accountPoints.num;
|
||||
userPoints.value = maxCanUsePoints.value
|
||||
} else {
|
||||
userPoints.value = 0;
|
||||
}
|
||||
@@ -876,6 +899,11 @@ function pointsConfirm(e) {
|
||||
accountPoints.num = e;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const maxPointDiscount=ref(0)
|
||||
const maxCanUsePoints=ref(0)
|
||||
/**
|
||||
* 获取积分信息
|
||||
* @param {Object} orderAmount
|
||||
@@ -884,20 +912,37 @@ async function getCalcUsablePoints() {
|
||||
if (!pageData.user.userId) {
|
||||
return;
|
||||
}
|
||||
const res = await calcUsablePoints({
|
||||
shopUserId: pageData.user.id,
|
||||
orderAmount: pointsCanDicountMaxMoney.value,
|
||||
});
|
||||
console.log("getCalcUsablePoints", res);
|
||||
pointDeductionRule.pointsPerYuan = res.equivalentPoints;
|
||||
pointDeductionRule.maxDeductionAmount = res.maxDeductionAmount;
|
||||
accountPoints.calcRes = res;
|
||||
accountPoints.num = res.maxUsablePoints;
|
||||
return res;
|
||||
|
||||
|
||||
let userAccountPoints = pageData.user ? pageData.user.pointBalance*1 : 0;
|
||||
|
||||
//1积分等于多少钱
|
||||
const onePointsMoney = pointDeductionRule.pointsPerYuan ? ((1 || 0) / pointDeductionRule.pointsPerYuan) : 0
|
||||
|
||||
|
||||
const calcMaxDiscount = Math.floor(pointsCanDicountMaxMoney.value * (pointDeductionRule.maxDeductionRatio / 100))
|
||||
const userMaxDiscount = BigNumber(userAccountPoints).times(onePointsMoney).decimalPlaces(2, BigNumber.ROUND_DOWN)
|
||||
.toNumber()
|
||||
|
||||
maxPointDiscount.value = Math.min(calcMaxDiscount, userMaxDiscount)
|
||||
console.log('积分最大可抵扣金额', maxPointDiscount.value)
|
||||
pointDeductionRule.maxDeductionAmount = maxPointDiscount.value || 0
|
||||
if (accountPoints.sel && pointDeductionRule.enableRewards) {
|
||||
let num = (maxPointDiscount.value || 0) * pointDeductionRule.pointsPerYuan
|
||||
if (num > userAccountPoints) {
|
||||
num = userAccountPoints
|
||||
}
|
||||
maxCanUsePoints.value=num
|
||||
userPoints.value=num
|
||||
}
|
||||
if (!pointDeductionRule.enableRewards) {
|
||||
userPoints.value=0
|
||||
}
|
||||
console.log('maxCanUsePoints.value', maxCanUsePoints.value)
|
||||
}
|
||||
|
||||
function changeAccountPoints() {
|
||||
if (!accountPoints.calcRes.usable) {
|
||||
if (!pointDeductionRule.enableRewards) {
|
||||
return;
|
||||
}
|
||||
accountPoints.sel = !accountPoints.sel;
|
||||
|
||||
Reference in New Issue
Block a user