update
This commit is contained in:
parent
e77c600262
commit
ef65140d20
@ -49,23 +49,11 @@ async def create_merchant_order(
|
||||
return error_response(code=404, message="商品不存在")
|
||||
|
||||
# 检查限购
|
||||
if product.purchase_limit and product.purchase_limit > 0:
|
||||
# 查询用户已购买数量
|
||||
purchased_count = db.query(func.count(MerchantOrderDB.id)).filter(
|
||||
MerchantOrderDB.user_id == current_user.userid,
|
||||
MerchantOrderDB.merchant_product_id == product.id,
|
||||
MerchantOrderDB.status.in_([
|
||||
MerchantOrderStatus.CREATED,
|
||||
MerchantOrderStatus.VERIFIED,
|
||||
MerchantOrderStatus.UNVERIFIED
|
||||
])
|
||||
).scalar()
|
||||
|
||||
if purchased_count >= product.purchase_limit:
|
||||
return error_response(
|
||||
code=400,
|
||||
message=f"该商品限购{product.purchase_limit}次,您已达到限购次数"
|
||||
)
|
||||
if product.purchase_limit > 0 and order.qty > product.purchase_limit:
|
||||
return error_response(
|
||||
code=400,
|
||||
message=f"该商品限购 {product.purchase_limit} 个"
|
||||
)
|
||||
|
||||
order_id = CommonUtils.generate_order_id('M')
|
||||
verify_code = CommonUtils.generate_verify_code()
|
||||
|
||||
@ -17,6 +17,7 @@ import string
|
||||
from app.models.merchant_order import MerchantOrderDB, MerchantOrderStatus
|
||||
from app.models.merchant_pay_order import MerchantPayOrderDB, MerchantPayOrderStatus
|
||||
from app.models.merchant import MerchantDB
|
||||
from app.models.merchant_product import DeliveryType, MerchantProductDB, DeliveryTimeType
|
||||
import enum
|
||||
from app.core.point_manager import PointManager
|
||||
from app.core.point_manager import PointRecordType
|
||||
@ -238,15 +239,22 @@ async def payment_notify(
|
||||
return error_response(code=404, message="订单不存在")
|
||||
|
||||
if trade_state_desc == "支付成功":
|
||||
|
||||
# if order.gift_points > 0:
|
||||
# # 添加积分
|
||||
# point_manager = PointManager(db)
|
||||
# point_manager.add_points(order.user_id, order.gift_points, PointRecordType.CONSUME_RETURN, f"团购订单奖励", order.order_id)
|
||||
product = db.query(MerchantProductDB).filter(
|
||||
MerchantProductDB.id == order.merchant_product_id
|
||||
).first()
|
||||
|
||||
# 更新订单状态
|
||||
if product.delivery_type == DeliveryType.DELIVERY:
|
||||
if product.delivery_time_type == DeliveryTimeType.IMMEDIATE:
|
||||
order.status = MerchantOrderStatus.PENDING
|
||||
elif product.delivery_time_type == DeliveryTimeType.SCHEDULED:
|
||||
order.status = MerchantOrderStatus.DELIVERING
|
||||
elif product.delivery_type == DeliveryType.PICKUP:
|
||||
order.status = MerchantOrderStatus.PICKUP_READY
|
||||
else:
|
||||
order.status = MerchantOrderStatus.PENDING
|
||||
|
||||
order.pay_status = True
|
||||
order.status = MerchantOrderStatus.UNVERIFIED
|
||||
order.transaction_id = transaction_id
|
||||
order.pay_time = datetime.fromisoformat(success_time.replace('Z', '+00:00'))
|
||||
|
||||
|
||||
@ -10,11 +10,14 @@ import time
|
||||
import enum
|
||||
|
||||
class MerchantOrderStatus(str, enum.Enum):
|
||||
CREATED = "CREATED" # 已下单
|
||||
UNVERIFIED = "UNVERIFIED" # 未核销
|
||||
VERIFIED = "VERIFIED" # 已核销
|
||||
REFUNDING = "REFUNDING" # 退款中
|
||||
REFUNDED = "REFUNDED" # 已退款
|
||||
CREATED = "CREATED" # 已创建(待支付)
|
||||
PENDING = "PENDING" # 待接单
|
||||
DELIVERING = "DELIVERING" # 待配送
|
||||
PICKUP_READY = "PICKUP_READY" # 待自提
|
||||
COMPLETED = "COMPLETED" # 已完成
|
||||
CANCELLED = "CANCELLED" # 已取消
|
||||
REFUNDING = "REFUNDING" # 退款中
|
||||
REFUNDED = "REFUNDED" # 已退款
|
||||
|
||||
class MerchantOrderDB(Base):
|
||||
__tablename__ = "merchant_orders"
|
||||
|
||||
@ -86,4 +86,9 @@ FOREIGN KEY (address_id) REFERENCES delivery_addresses(id);
|
||||
|
||||
-- 修改address_id为NOT NULL
|
||||
ALTER TABLE merchant_orders
|
||||
MODIFY COLUMN address_id INT NOT NULL COMMENT '收货地址ID';
|
||||
MODIFY COLUMN address_id INT NOT NULL COMMENT '收货地址ID';
|
||||
|
||||
-- 修改status字段的枚举类型
|
||||
ALTER TABLE merchant_orders
|
||||
MODIFY COLUMN status ENUM('CREATED', 'PENDING', 'DELIVERING', 'PICKUP_READY', 'COMPLETED', 'CANCELLED', 'REFUNDING', 'REFUNDED')
|
||||
NOT NULL DEFAULT 'CREATED' COMMENT '订单状态';
|
||||
Loading…
Reference in New Issue
Block a user