|
@@ -5,9 +5,12 @@ import (
|
|
|
logger "eta/eta_mini_ht_api/common/component/log"
|
|
|
"eta/eta_mini_ht_api/common/exception"
|
|
|
"eta/eta_mini_ht_api/common/utils/page"
|
|
|
+ merchantService "eta/eta_mini_ht_api/domian/merchant"
|
|
|
productService "eta/eta_mini_ht_api/domian/merchant"
|
|
|
orderService "eta/eta_mini_ht_api/domian/order"
|
|
|
userService "eta/eta_mini_ht_api/domian/user"
|
|
|
+ merchantDao "eta/eta_mini_ht_api/models/merchant"
|
|
|
+ orderDao "eta/eta_mini_ht_api/models/order"
|
|
|
"eta/eta_mini_ht_api/service/user"
|
|
|
"fmt"
|
|
|
"gorm.io/gorm"
|
|
@@ -19,6 +22,22 @@ const (
|
|
|
permanentlyValid = "永久有效"
|
|
|
OnSale = "on_sale" //上架
|
|
|
OffSale = "off_sale" //下架
|
|
|
+
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ productOrderStatusMap = map[orderDao.OrderStatus]string{
|
|
|
+ orderDao.OrderStatusPending: "pending",
|
|
|
+ orderDao.OrderStatusPaid: "paid",
|
|
|
+ orderDao.OrderStatusClosed: "closed",
|
|
|
+ orderDao.OrderStatusRefund: "refund",
|
|
|
+ }
|
|
|
+
|
|
|
+ accessStatusMap = map[merchantDao.SubscribeStatus]string{
|
|
|
+ merchantDao.SubscribeValid: "valid",
|
|
|
+ merchantDao.SubscribeExpired: "expired",
|
|
|
+ merchantDao.SubscribeClose: "closed",
|
|
|
+ }
|
|
|
)
|
|
|
|
|
|
type ProductOrderInfo struct {
|
|
@@ -63,6 +82,20 @@ func CreateProductOrder(templateUser user.User, productId int, orderNo string) (
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+ //校验是否有相同待支付的产品订单
|
|
|
+ var exisitOrder orderService.ProductOrderDTO
|
|
|
+ exisitOrder, err = orderService.GetUserOrderByProduct(productId, templateUser.Id)
|
|
|
+ if (err != nil && !errors.Is(err, gorm.ErrRecordNotFound)) || exisitOrder.Status == productOrderStatusMap[orderDao.OrderStatusPending] {
|
|
|
+ err = exception.NewWithException(exception.SubscribeFailed, "当前产品有正在进行中的订单,请勿重复下单")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //是否在有效期的产品
|
|
|
+ var access merchantService.UserAccessDTO
|
|
|
+ access, err = merchantService.GetUserSubscribe(templateUser.Id, productId)
|
|
|
+ if (err != nil && !errors.Is(err, gorm.ErrRecordNotFound)) || access.Status == accessStatusMap[merchantDao.SubscribeValid] {
|
|
|
+ err = exception.NewWithException(exception.SubscribeFailed, "当前产品已订阅,请勿重复下单")
|
|
|
+ return
|
|
|
+ }
|
|
|
orderNo, err = orderService.CreateProductOrder(orderService.ProductOrderDTO{
|
|
|
OrderID: orderNo,
|
|
|
UserID: officialUser.ID,
|