修复域名续费时购买时长的价格计算漏洞

This commit is contained in:
jingrow 2025-10-02 17:13:19 +08:00
parent 2150575fb3
commit 95611089ed
2 changed files with 38 additions and 34 deletions

View File

@ -17,7 +17,7 @@
<button
v-for="period in renewalPeriods"
:key="period.years"
@click="renewalPeriod = period.years"
@click="onRenewalPeriodChange(period.years)"
:class="[
'px-4 py-2 text-sm font-medium rounded-md border',
renewalPeriod === period.years
@ -32,15 +32,7 @@
</div>
<div class="mb-6 border-t border-gray-200 pt-4">
<div 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 v-if="renewPrice" class="flex justify-between items-center">
<div class="text-sm text-gray-600">续费时长</div>
<div class="font-medium">{{ renewalPeriod }} </div>
</div>
@ -48,12 +40,13 @@
<div class="text-sm text-green-600">折扣</div>
<div class="font-medium text-green-600">-{{ discountPercentage }}%</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>
<span v-if="isPriceLoading" class="text-gray-400">获取中...</span>
<span v-else-if="domainPrice">¥ {{ totalAmount }}</span>
</div>
<div>¥ {{ totalAmount }}</div>
</div>
<div v-else class="flex justify-between items-center mt-2 text-lg font-bold">
<div>总计</div>
<div class="text-gray-400">获取价格中...</div>
</div>
</div>
@ -194,7 +187,7 @@
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"
@click="createRenewalOrder"
:disabled="isLoading || isPriceLoading || !domainPrice"
:disabled="isLoading || isPriceLoading || !renewPrice || !selectedPaymentMethod"
>
{{ isLoading ? '处理中...' : (isPriceLoading ? '获取价格中...' : '确认续费') }}
</button>
@ -254,6 +247,7 @@ export default {
paymentQrCodeImage: null,
checkInterval: null,
domainPrice: null,
renewPrice: null, //
renewalPeriods: [
{ years: 1, name: '1年', discount: 0 },
{ years: 2, name: '2年', discount: 0 },
@ -269,17 +263,15 @@ export default {
return period ? period.discount : 0;
},
totalAmount() {
if (!this.domainPrice) return '';
const basePrice = this.domainPrice * this.renewalPeriod;
const discount = basePrice * (this.discountPercentage / 100);
return (basePrice - discount).toFixed(2);
if (!this.renewPrice) return '0.00';
const discount = this.renewPrice * (this.discountPercentage / 100);
return (this.renewPrice - discount).toFixed(2);
},
isLoading() {
return this.$resources.createRenewalOrder.loading;
},
isPriceLoading() {
return this.$resources.getDomainPrice.loading;
return this.$resources.getRenewPrice.loading;
}
},
resources: {
@ -414,15 +406,16 @@ export default {
}
};
},
getDomainPrice() {
getRenewPrice() {
return {
url: 'jcloud.api.domain_west.get_west_domain_renew_price',
params: {
domain: this.domainDoc?.domain
domain: this.domainDoc?.domain,
year: 1
},
onSuccess(data) {
if (data.data?.price) {
this.domainPrice = data.data.price;
this.renewPrice = data.data.price;
}
},
onError(error) {
@ -432,12 +425,25 @@ export default {
}
},
async mounted() {
//
//
if (this.domainDoc?.domain) {
await this.$resources.getDomainPrice.submit();
await this.$resources.getRenewPrice.submit({
domain: this.domainDoc.domain,
year: this.renewalPeriod
});
}
},
methods: {
async onRenewalPeriodChange(years) {
this.renewalPeriod = years;
//
if (this.domainDoc?.domain) {
await this.$resources.getRenewPrice.submit({
domain: this.domainDoc.domain,
year: years
});
}
},
cancel() {
this.stopPaymentCheck();
this.show = false;

View File

@ -1540,14 +1540,12 @@ def create_domain_renew_order(**kwargs):
# 计算续费金额 - 使用现有的价格获取函数保持统一
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"):
yearly_price = price_data["data"]["price"]
total_amount = price_data["data"]["price"]
else:
yearly_price = domain_pg.price or 0
total_amount = yearly_price * renewal_years
return {"success": False, "message": "获取续费价格失败"}
# 生成唯一订单号
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_name": domain,
"renewal_years": renewal_years,
"yearly_price": yearly_price,
"total_price": total_amount,
"domain_owner": domain_pg.domain_owner,
# 续费域名所需参数
"year": renewal_years,