feat(pay): 增加支付状态paid 已支付
This commit is contained in:
@@ -70,6 +70,7 @@ def upgrade() -> None:
|
|||||||
sa.UniqueConstraint('user_id', name='uniq_user_id'),
|
sa.UniqueConstraint('user_id', name='uniq_user_id'),
|
||||||
comment='用户表'
|
comment='用户表'
|
||||||
)
|
)
|
||||||
|
op.execute("ALTER SEQUENCE system_users RESTART WITH 100000;")
|
||||||
op.create_index('wechat_openid', 'system_users', ['wechat_openid'], unique=False)
|
op.create_index('wechat_openid', 'system_users', ['wechat_openid'], unique=False)
|
||||||
op.create_table('system_user_collections',
|
op.create_table('system_user_collections',
|
||||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ def upgrade() -> None:
|
|||||||
sa.Column('total_fee', sa.Integer(), nullable=True, comment='发起的总金额,单位为分'),
|
sa.Column('total_fee', sa.Integer(), nullable=True, comment='发起的总金额,单位为分'),
|
||||||
sa.Column('notify_total_fee', sa.Integer(), nullable=True, comment='回调成功支付的总金额,单位为分'),
|
sa.Column('notify_total_fee', sa.Integer(), nullable=True, comment='回调成功支付的总金额,单位为分'),
|
||||||
sa.Column('pay_url', sa.String(length=255), nullable=True, comment='支付地址'),
|
sa.Column('pay_url', sa.String(length=255), nullable=True, comment='支付地址'),
|
||||||
sa.Column('status', sa.Enum('INIT', 'FAIL', 'OK', 'WAIT_PAYMENT', 'CANCEL', name='orderstatustype', inherit_schema=True), server_default='init', nullable=False, comment='订单状态,init:初始化 fail:失败 ok:完成 wait payment:待支付 cancel. 取消'),
|
sa.Column('status', sa.Enum('INIT', 'FAIL', 'OK', 'WAIT_PAYMENT', 'PAID', 'CANCEL', name='orderstatustype', inherit_schema=True), server_default='init', nullable=False, comment='订单状态,init:初始化 fail:失败 ok:完成 wait payment:待支付 cancel. 取消'),
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='自增id'),
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='自增id'),
|
||||||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='创建时间'),
|
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='创建时间'),
|
||||||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='更新时间'),
|
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='更新时间'),
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ def downgrade() -> None:
|
|||||||
op.alter_column('system_cards', 'source',
|
op.alter_column('system_cards', 'source',
|
||||||
existing_type=mysql.ENUM('PSA', 'BGS', 'CGC', 'GBTC', 'CCG', 'BCTC', 'OTHER'),
|
existing_type=mysql.ENUM('PSA', 'BGS', 'CGC', 'GBTC', 'CCG', 'BCTC', 'OTHER'),
|
||||||
comment='来源,PSA、BGS、CGC、GBTC、CCG、BCTC :采集 、OTHER:自定义',
|
comment='来源,PSA、BGS、CGC、GBTC、CCG、BCTC :采集 、OTHER:自定义',
|
||||||
existing_comment='来源,PSA、BGS、CGC、GBTC、CCG、BCTC、CIC :采集 、OTHER:自定义',
|
existing_comment='来源,PSA、BGS、CGC、GBTC、CCG、BCTC:采集 、OTHER:自定义',
|
||||||
existing_nullable=False)
|
existing_nullable=False)
|
||||||
op.alter_column('system_cache_cards', 'source',
|
op.alter_column('system_cache_cards', 'source',
|
||||||
existing_type=mysql.ENUM('PSA', 'BGS', 'CGC', 'GBTC', 'CCG', 'BCTC'),
|
existing_type=mysql.ENUM('PSA', 'BGS', 'CGC', 'GBTC', 'CCG', 'BCTC'),
|
||||||
comment='数据来源:PSA、BGS、CGC、GBTC、CCG、BCTC',
|
comment='数据来源:PSA、BGS、CGC、GBTC、CCG、BCTC',
|
||||||
existing_comment='数据来源:PSA、BGS、CGC、GBTC、CCG、BCTC、CIC',
|
existing_comment='数据来源:PSA、BGS、CGC、GBTC、CCG、BCTC',
|
||||||
existing_nullable=False)
|
existing_nullable=False)
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|||||||
@@ -74,4 +74,5 @@ class OrderStatusType(enum.Enum):
|
|||||||
FAIL = 'fail'
|
FAIL = 'fail'
|
||||||
OK = 'ok'
|
OK = 'ok'
|
||||||
WAIT_PAYMENT = 'wait_payment'
|
WAIT_PAYMENT = 'wait_payment'
|
||||||
|
PAID = 'paid'
|
||||||
CANCEL = 'cancel'
|
CANCEL = 'cancel'
|
||||||
|
|||||||
@@ -244,10 +244,10 @@ class Order(BaseModel, DateModel):
|
|||||||
total_fee: Mapped[int] = mapped_column(Integer, nullable=True, comment='发起的总金额,单位为分')
|
total_fee: Mapped[int] = mapped_column(Integer, nullable=True, comment='发起的总金额,单位为分')
|
||||||
notify_total_fee: Mapped[int] = mapped_column(Integer, nullable=True, comment='回调成功支付的总金额,单位为分')
|
notify_total_fee: Mapped[int] = mapped_column(Integer, nullable=True, comment='回调成功支付的总金额,单位为分')
|
||||||
pay_url: Mapped[str] = mapped_column(String(255), nullable=True, comment='支付地址')
|
pay_url: Mapped[str] = mapped_column(String(255), nullable=True, comment='支付地址')
|
||||||
status: Mapped[str] = mapped_column(
|
status: Mapped[base_schema.OrderStatusType] = mapped_column(
|
||||||
Enum(base_schema.OrderStatusType, inherit_schema=True),
|
Enum(base_schema.OrderStatusType, inherit_schema=True),
|
||||||
server_default=base_schema.OrderStatusType.INIT.value,
|
server_default=base_schema.OrderStatusType.INIT.value,
|
||||||
comment='订单状态,init:初始化 fail:失败 ok:完成 wait payment:待支付 cancel. 取消'
|
comment='订单状态,init:初始化 fail:失败 ok:完成 wait payment:待支付 paid:已支付 cancel. 取消'
|
||||||
)
|
)
|
||||||
ip_address: Mapped[str] = mapped_column(String(255), nullable=True, comment='操作ip')
|
ip_address: Mapped[str] = mapped_column(String(255), nullable=True, comment='操作ip')
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ async def get_current_user(
|
|||||||
if user_id is None:
|
if user_id is None:
|
||||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token")
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token")
|
||||||
|
|
||||||
keyname = generate_keyname(f'login_cache', use_today=True)
|
keyname = generate_keyname('login_cache', use_today=True)
|
||||||
user_str = await redis_conn.hget(keyname, user_id)
|
user_str = await redis_conn.hget(keyname, user_id)
|
||||||
if user_str is None:
|
if user_str is None:
|
||||||
user_model = await CRUD(db_session, User).get(filters={'user_id': user_id})
|
user_model = await CRUD(db_session, User).get(filters={'user_id': user_id})
|
||||||
|
|||||||
@@ -7,12 +7,10 @@
|
|||||||
import logging
|
import logging
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta, datetime
|
||||||
|
|
||||||
from fastapi import Depends
|
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from core.base.schema import ProductCategory, ProductAction, OrderStatusType
|
from core.base.schema import ProductCategory, ProductAction, OrderStatusType
|
||||||
from core.db.crud import CRUD
|
from core.db.crud import CRUD
|
||||||
from core.db.engine import get_async_session
|
|
||||||
from core.db.models import User, Order, Product, PointsTransaction
|
from core.db.models import User, Order, Product, PointsTransaction
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -54,6 +52,13 @@ async def actions_after_payment(
|
|||||||
)
|
)
|
||||||
await actions_handler(db_crud, gift_product, user)
|
await actions_handler(db_crud, gift_product, user)
|
||||||
|
|
||||||
|
record = {
|
||||||
|
'order_id': notify_params['out_trade_no'],
|
||||||
|
'transaction_id': notify_params['transaction_id'],
|
||||||
|
'status': OrderStatusType.OK,
|
||||||
|
}
|
||||||
|
await db_crud.update(data=record, filters={'order_id': record['order_id']})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Payment Actions Exception occurred -> {e}')
|
logger.error(f'Payment Actions Exception occurred -> {e}')
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ async def wechat_notify(
|
|||||||
if params['return_code'] == 'SUCCESS' and params['result_code'] == 'SUCCESS':
|
if params['return_code'] == 'SUCCESS' and params['result_code'] == 'SUCCESS':
|
||||||
record.update({
|
record.update({
|
||||||
'notify_total_fee': params['total_fee'],
|
'notify_total_fee': params['total_fee'],
|
||||||
'status': base_schema.OrderStatusType.OK
|
'status': base_schema.OrderStatusType.PAID
|
||||||
})
|
})
|
||||||
result = {'status': 200, 'message': 'OK'}
|
result = {'status': 200, 'message': 'OK'}
|
||||||
background_tasks.add_task(actions_after_payment, notify_params=params, db_session=db_session)
|
background_tasks.add_task(actions_after_payment, notify_params=params, db_session=db_session)
|
||||||
|
|||||||
Reference in New Issue
Block a user