修复域名续费时购买时长的价格计算漏洞
This commit is contained in:
parent
2150575fb3
commit
95611089ed
@ -17,7 +17,7 @@
|
|||||||
<button
|
<button
|
||||||
v-for="period in renewalPeriods"
|
v-for="period in renewalPeriods"
|
||||||
:key="period.years"
|
:key="period.years"
|
||||||
@click="renewalPeriod = period.years"
|
@click="onRenewalPeriodChange(period.years)"
|
||||||
:class="[
|
:class="[
|
||||||
'px-4 py-2 text-sm font-medium rounded-md border',
|
'px-4 py-2 text-sm font-medium rounded-md border',
|
||||||
renewalPeriod === period.years
|
renewalPeriod === period.years
|
||||||
@ -32,15 +32,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-6 border-t border-gray-200 pt-4">
|
<div class="mb-6 border-t border-gray-200 pt-4">
|
||||||
<div class="flex justify-between items-center">
|
<div v-if="renewPrice" class="flex justify-between items-center">
|
||||||
<div class="text-sm text-gray-600">年度费用</div>
|
|
||||||
<div class="font-medium">
|
|
||||||
<span v-if="isPriceLoading" class="text-gray-400">获取中...</span>
|
|
||||||
<span v-else-if="domainPrice">¥ {{ domainPrice }}</span>
|
|
||||||
<span class="text-gray-500 text-sm"> (年付)</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="flex justify-between items-center mt-2">
|
|
||||||
<div class="text-sm text-gray-600">续费时长</div>
|
<div class="text-sm text-gray-600">续费时长</div>
|
||||||
<div class="font-medium">{{ renewalPeriod }} 年</div>
|
<div class="font-medium">{{ renewalPeriod }} 年</div>
|
||||||
</div>
|
</div>
|
||||||
@ -48,12 +40,13 @@
|
|||||||
<div class="text-sm text-green-600">折扣</div>
|
<div class="text-sm text-green-600">折扣</div>
|
||||||
<div class="font-medium text-green-600">-{{ discountPercentage }}%</div>
|
<div class="font-medium text-green-600">-{{ discountPercentage }}%</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-between items-center mt-2 text-lg font-bold">
|
<div v-if="renewPrice" class="flex justify-between items-center mt-2 text-lg font-bold">
|
||||||
<div>总计</div>
|
<div>总计</div>
|
||||||
<div>
|
<div>¥ {{ totalAmount }}</div>
|
||||||
<span v-if="isPriceLoading" class="text-gray-400">获取中...</span>
|
</div>
|
||||||
<span v-else-if="domainPrice">¥ {{ totalAmount }}</span>
|
<div v-else class="flex justify-between items-center mt-2 text-lg font-bold">
|
||||||
</div>
|
<div>总计</div>
|
||||||
|
<div class="text-gray-400">获取价格中...</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -194,7 +187,7 @@
|
|||||||
type="button"
|
type="button"
|
||||||
class="w-full px-4 py-2 bg-[#1fc76f] border border-transparent rounded-md text-sm font-medium text-white hover:bg-[#19b862] focus:outline-none disabled:bg-gray-300 disabled:cursor-not-allowed"
|
class="w-full px-4 py-2 bg-[#1fc76f] border border-transparent rounded-md text-sm font-medium text-white hover:bg-[#19b862] focus:outline-none disabled:bg-gray-300 disabled:cursor-not-allowed"
|
||||||
@click="createRenewalOrder"
|
@click="createRenewalOrder"
|
||||||
:disabled="isLoading || isPriceLoading || !domainPrice"
|
:disabled="isLoading || isPriceLoading || !renewPrice || !selectedPaymentMethod"
|
||||||
>
|
>
|
||||||
{{ isLoading ? '处理中...' : (isPriceLoading ? '获取价格中...' : '确认续费') }}
|
{{ isLoading ? '处理中...' : (isPriceLoading ? '获取价格中...' : '确认续费') }}
|
||||||
</button>
|
</button>
|
||||||
@ -254,6 +247,7 @@ export default {
|
|||||||
paymentQrCodeImage: null,
|
paymentQrCodeImage: null,
|
||||||
checkInterval: null,
|
checkInterval: null,
|
||||||
domainPrice: null,
|
domainPrice: null,
|
||||||
|
renewPrice: null, // 当前选择年限的总价
|
||||||
renewalPeriods: [
|
renewalPeriods: [
|
||||||
{ years: 1, name: '1年', discount: 0 },
|
{ years: 1, name: '1年', discount: 0 },
|
||||||
{ years: 2, name: '2年', discount: 0 },
|
{ years: 2, name: '2年', discount: 0 },
|
||||||
@ -269,17 +263,15 @@ export default {
|
|||||||
return period ? period.discount : 0;
|
return period ? period.discount : 0;
|
||||||
},
|
},
|
||||||
totalAmount() {
|
totalAmount() {
|
||||||
if (!this.domainPrice) return '';
|
if (!this.renewPrice) return '0.00';
|
||||||
|
const discount = this.renewPrice * (this.discountPercentage / 100);
|
||||||
const basePrice = this.domainPrice * this.renewalPeriod;
|
return (this.renewPrice - discount).toFixed(2);
|
||||||
const discount = basePrice * (this.discountPercentage / 100);
|
|
||||||
return (basePrice - discount).toFixed(2);
|
|
||||||
},
|
},
|
||||||
isLoading() {
|
isLoading() {
|
||||||
return this.$resources.createRenewalOrder.loading;
|
return this.$resources.createRenewalOrder.loading;
|
||||||
},
|
},
|
||||||
isPriceLoading() {
|
isPriceLoading() {
|
||||||
return this.$resources.getDomainPrice.loading;
|
return this.$resources.getRenewPrice.loading;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resources: {
|
resources: {
|
||||||
@ -414,15 +406,16 @@ export default {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getDomainPrice() {
|
getRenewPrice() {
|
||||||
return {
|
return {
|
||||||
url: 'jcloud.api.domain_west.get_west_domain_renew_price',
|
url: 'jcloud.api.domain_west.get_west_domain_renew_price',
|
||||||
params: {
|
params: {
|
||||||
domain: this.domainDoc?.domain
|
domain: this.domainDoc?.domain,
|
||||||
|
year: 1
|
||||||
},
|
},
|
||||||
onSuccess(data) {
|
onSuccess(data) {
|
||||||
if (data.data?.price) {
|
if (data.data?.price) {
|
||||||
this.domainPrice = data.data.price;
|
this.renewPrice = data.data.price;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError(error) {
|
onError(error) {
|
||||||
@ -432,12 +425,25 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
// 获取域名续费价格
|
// 获取当前选择年限的续费价格
|
||||||
if (this.domainDoc?.domain) {
|
if (this.domainDoc?.domain) {
|
||||||
await this.$resources.getDomainPrice.submit();
|
await this.$resources.getRenewPrice.submit({
|
||||||
|
domain: this.domainDoc.domain,
|
||||||
|
year: this.renewalPeriod
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async onRenewalPeriodChange(years) {
|
||||||
|
this.renewalPeriod = years;
|
||||||
|
// 立即获取对应年限的价格
|
||||||
|
if (this.domainDoc?.domain) {
|
||||||
|
await this.$resources.getRenewPrice.submit({
|
||||||
|
domain: this.domainDoc.domain,
|
||||||
|
year: years
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
cancel() {
|
cancel() {
|
||||||
this.stopPaymentCheck();
|
this.stopPaymentCheck();
|
||||||
this.show = false;
|
this.show = false;
|
||||||
|
|||||||
@ -1540,14 +1540,12 @@ def create_domain_renew_order(**kwargs):
|
|||||||
# 计算续费金额 - 使用现有的价格获取函数保持统一
|
# 计算续费金额 - 使用现有的价格获取函数保持统一
|
||||||
renewal_years = int(renewal_years)
|
renewal_years = int(renewal_years)
|
||||||
|
|
||||||
# 调用现有的价格获取函数
|
# 根据实际续费年限直接获取价格
|
||||||
price_data = get_west_domain_renew_price(domain_pg.domain, 1)
|
price_data = get_west_domain_renew_price(domain_pg.domain, renewal_years)
|
||||||
if price_data.get("data", {}).get("price"):
|
if price_data.get("data", {}).get("price"):
|
||||||
yearly_price = price_data["data"]["price"]
|
total_amount = price_data["data"]["price"]
|
||||||
else:
|
else:
|
||||||
yearly_price = domain_pg.price or 0
|
return {"success": False, "message": "获取续费价格失败"}
|
||||||
|
|
||||||
total_amount = yearly_price * renewal_years
|
|
||||||
|
|
||||||
# 生成唯一订单号
|
# 生成唯一订单号
|
||||||
order_id = f"{datetime.now().strftime('%Y%m%d%H%M%S%f')[:-3] + ''.join(random.choices('0123456789', k=6))}"
|
order_id = f"{datetime.now().strftime('%Y%m%d%H%M%S%f')[:-3] + ''.join(random.choices('0123456789', k=6))}"
|
||||||
@ -1557,7 +1555,7 @@ def create_domain_renew_order(**kwargs):
|
|||||||
"domain": domain_pg.domain,
|
"domain": domain_pg.domain,
|
||||||
"domain_name": domain,
|
"domain_name": domain,
|
||||||
"renewal_years": renewal_years,
|
"renewal_years": renewal_years,
|
||||||
"yearly_price": yearly_price,
|
"total_price": total_amount,
|
||||||
"domain_owner": domain_pg.domain_owner,
|
"domain_owner": domain_pg.domain_owner,
|
||||||
# 续费域名所需参数
|
# 续费域名所需参数
|
||||||
"year": renewal_years,
|
"year": renewal_years,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user