fix: 获取用户已有订阅,如果有就续费,否则使用新购
All checks were successful
CI / build (20.15.1) (push) Successful in 17m33s
All checks were successful
CI / build (20.15.1) (push) Successful in 17m33s
This commit is contained in:
parent
edf961eb7b
commit
780dbe075b
@ -3,7 +3,8 @@
|
|||||||
import PaymentMethods from '@/components/subscribe/payment-methods';
|
import PaymentMethods from '@/components/subscribe/payment-methods';
|
||||||
import PlanTabs, { TabValueType } from '@/components/SubscribePlan/PlanTabs/PlanTabs';
|
import PlanTabs, { TabValueType } from '@/components/SubscribePlan/PlanTabs/PlanTabs';
|
||||||
import useGlobalStore from '@/config/use-global';
|
import useGlobalStore from '@/config/use-global';
|
||||||
import { preCreateOrder, purchase } from '@/services/user/order';
|
import { preCreateOrder, purchase, renewal } from '@/services/user/order';
|
||||||
|
import { queryUserSubscribe } from '@/services/user/user';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { AiroButton } from '@workspace/airo-ui/components/AiroButton';
|
import { AiroButton } from '@workspace/airo-ui/components/AiroButton';
|
||||||
import {
|
import {
|
||||||
@ -104,7 +105,23 @@ const Purchase = forwardRef<PurchaseDialogRef, PurchaseProps>((props, ref) => {
|
|||||||
const handleSubmit = useCallback(async () => {
|
const handleSubmit = useCallback(async () => {
|
||||||
startTransition(async () => {
|
startTransition(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await purchase(params as API.PurchaseOrderRequest);
|
const { data } = await queryUserSubscribe({ params: { includeExpired: 'all' } });
|
||||||
|
const activeList = data.data?.list || [];
|
||||||
|
const existingUser = activeList.find(
|
||||||
|
(item: any) => item.subscribe_id === params.subscribe_id,
|
||||||
|
);
|
||||||
|
let response;
|
||||||
|
// 3. 根据判断结果调用不同接口
|
||||||
|
if (existingUser) {
|
||||||
|
// 已有记录,走续费逻辑
|
||||||
|
response = await renewal({
|
||||||
|
user_subscribe_id: existingUser.id,
|
||||||
|
...params,
|
||||||
|
} as API.RenewalOrderRequest);
|
||||||
|
} else {
|
||||||
|
// 无记录,走新购逻辑
|
||||||
|
response = await purchase(params as API.PurchaseOrderRequest);
|
||||||
|
}
|
||||||
const orderNo = response.data.data?.order_no;
|
const orderNo = response.data.data?.order_no;
|
||||||
if (orderNo) {
|
if (orderNo) {
|
||||||
await getUserInfo();
|
await getUserInfo();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user