Browse Source

商城PC端订单结算添加会员积分兑换业务功能

master
dy-hu 1 year ago
parent
commit
e04ffa731f
  1. 8
      src/api/user/order.js
  2. 154
      src/views/placeOrder/index.vue

8
src/api/user/order.js

@ -122,3 +122,11 @@ export function orderPayCode (params) {
params
})
}
export function queryDict (params) {
return request({
url: '/dict/getByName',
method: 'get',
params
})
}

154
src/views/placeOrder/index.vue

@ -64,6 +64,13 @@
/>
</div>
</div>
<div style="display: flex;justify-content: right;align-items: center" v-if="integralShow">
<span style="font-size: 15px;margin-right: 5px">可用{{ integralNum }}积分抵扣{{ integralPrice.toFixed(2) }}</span>
<el-checkbox v-model="selectIntegral"
@change='changeIntegral()'
:true-label='1'
:false-label='0'/>
</div>
<div class="payBox">
<div class="payTit">选择支付方式</div>
<div class="payList">
@ -213,7 +220,8 @@ import {
orderSubmit,
getSettlement,
getGroupSettle,
checkOrderResult
checkOrderResult,
queryDict
} from '@/api/user/order.js'
import {
getCartList,
@ -286,6 +294,12 @@ export default {
couponShopAmount: 0, //
hasCheck: 0, // 1. 2.
disabledButton: false, //
selectIntegral: true,
integralNum: 0,
integralRatio: 0, //
integralPrice: 0, //
orderCreditThreshold: 0, //
integralShow: false, //
}
},
created () {
@ -317,6 +331,7 @@ export default {
mounted () {
//
this.getAddressList()
this.queryDict()
if (this.$route.query.type) {
this.getSetProList()
} else {
@ -858,6 +873,8 @@ export default {
if (this.checkedPlatformCoupon) {
this.totalPrice = shopSumPrice - this.couponAmount
}
//
this.calcCredit()
//
this.settlement.shops.forEach((item) => {
this.totalPrice = this.totalPrice + (item.distribution.distributionPrice || 0)
@ -893,6 +910,120 @@ export default {
}
this.couponAmount = parseFloat(tmpAmount)
},
calcCredit () {
let shopsLen = this.settlement.shops.length
const skuRemainMap = this.calcSkuRemainMap()
const skuCreditMap = this.settlement.skuCreditMap;
if (skuCreditMap && this.integralRatio > 0) {
this.orderCreditThreshold = this.settlement.orderCreditThreshold
let remainUserCredit = this.settlement.userTotalCredit
let remainTotalPrice = Math.round((this.totalPrice + Number.EPSILON) * 100) / 100
let remainDeductLimit = this.settlement.creditDeductLimit
//
if (this.totalPrice >= this.orderCreditThreshold && remainUserCredit > 0 && remainDeductLimit > 0) {
for (let i = 0; i < shopsLen; i++) {
const curShop = this.settlement.shops[i]
let skuLen = curShop.skus.length
for (let j = 0; j < skuLen; j++) {
const curSku = curShop.skus[j]
const skuId = curSku.skuId
if (skuCreditMap[skuId] > 0 && skuRemainMap[skuId] > 0 && remainUserCredit > 0 &&
remainTotalPrice > 0) {
// 0.01
if (remainTotalPrice - skuRemainMap[skuId] < 0.01) {
skuRemainMap[skuId] -= 0.01
}
// ()
let finalSkuCredit = parseInt((skuRemainMap[skuId] / this.integralRatio).toString());
//
if (skuCreditMap[skuId] < finalSkuCredit) {
finalSkuCredit = skuCreditMap[skuId]
}
//
if (remainUserCredit < finalSkuCredit) {
finalSkuCredit = remainUserCredit
}
//
if (remainDeductLimit < finalSkuCredit) {
finalSkuCredit = remainDeductLimit
}
curSku.cachedCredit = finalSkuCredit
this.integralNum += finalSkuCredit
remainUserCredit -= finalSkuCredit
remainDeductLimit -= finalSkuCredit
remainTotalPrice -= finalSkuCredit
}
}
}
}
//
if (this.integralNum !== 0) {
this.integralNum = parseInt(this.integralNum)
this.integralPrice = this.integralNum * this.integralRatio
if (this.integralNum !== 0) {
this.integralShow = true
}
if (this.selectIntegral) {
this.totalPrice = this.totalPrice - this.integralPrice
}
} else {
this.integralShow = false
}
}
},
/**
* 计算sku在整个运单价格中的剩余价值 1元的订单打1折优惠之后剩余价值就是0.1
*/
calcSkuRemainMap () {
let skuRemainMap = {}
let shopsLen = this.settlement.shops.length
const skuCreditMap = this.settlement.skuCreditMap
for (let i = 0; i < shopsLen; i++) {
const curShop = this.settlement.shops[i]
let skuLen = curShop.skus.length
let checkedShopCoupon = undefined
curShop.shopCoupons.forEach((item) => {
if (item.checked) {
checkedShopCoupon = item
}
})
for (let j = 0; j < skuLen; j++) {
const curSku = curShop.skus[j]
const skuId = curSku.skuId
//
if (!curSku.priceId > 0 && skuCreditMap[skuId] > 0) {
let remainSkuMoney = curSku.price * curSku.number
if (checkedShopCoupon) {
let skuShopPercent = remainSkuMoney / curShop.total
let curReduceMoney = 0
if (checkedShopCoupon.couponType === 1) {
curReduceMoney = checkedShopCoupon.reduceMoney * skuShopPercent
} else {
curReduceMoney = remainSkuMoney * (10 - checkedShopCoupon.reduceMoney) / 10
}
remainSkuMoney = remainSkuMoney - curReduceMoney
}
// 使
if (this.checkedPlatformCoupon && remainSkuMoney > 0) {
//
if (this.checkedPlatformCoupon.couponType === 1) {
let skuTotalPercent = remainSkuMoney / this.totalPrice
remainSkuMoney -= this.checkedPlatformCoupon.reduceMoney * skuTotalPercent
}
//
else {
remainSkuMoney = remainSkuMoney * this.checkedPlatformCoupon.reduceMoney / 10
}
}
skuRemainMap[skuId] = remainSkuMoney
}
}
}
return skuRemainMap
},
//
selectPay (payType) {
this.payType = payType
@ -926,7 +1057,9 @@ export default {
sceneId: k.sceneId,
useMember: k.useMember,
buyerCouponId: k.buyerCouponId,
buyerShopCouponId: k.buyerShopCouponId
buyerShopCouponId: k.buyerShopCouponId,
useCredit: this.selectIntegral && k.cachedCredit ? k.cachedCredit : undefined,
useCreditAmount: this.selectIntegral && k.cachedCredit ? (k.cachedCredit * this.integralRatio).toFixed(2) : undefined
})
}
})
@ -1059,6 +1192,23 @@ export default {
},
toOrder () {
this.$router.push({path: '/myOrder'})
},
//
changeIntegral () {
this.selectIntegral = !this.selectIntegral
if (this.selectIntegral) {
this.totalPrice = this.totalPrice - this.integralPrice
} else {
this.totalPrice = this.totalPrice + this.integralPrice
}
},
async queryDict () {
const response = await queryDict({
name: 'credit_exchange_rate'
})
this.integralRatio = parseFloat(response.data.data.dictDescribe)
}
}
}

Loading…
Cancel
Save