51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"go.mongodb.org/mongo-driver/v2/mongo"
|
|
"order/dao"
|
|
"order/model/entity"
|
|
)
|
|
|
|
var (
|
|
orderService *OrderService
|
|
paymentService *PaymentService
|
|
)
|
|
|
|
// InitServices 初始化服务
|
|
func InitServices() error {
|
|
ctx := context.Background()
|
|
|
|
// 创建订单集合映射(模拟数据)
|
|
orderCollections := make(map[entity.OrderStatus]*mongo.Collection)
|
|
|
|
// 创建DAO实例
|
|
orderDao := dao.NewOrderDao(orderCollections)
|
|
paymentConfigDao := dao.NewPaymentConfigDao(nil)
|
|
paymentRecordDao := dao.NewPaymentRecordDao(nil)
|
|
refundRecordDao := dao.NewRefundRecordDao(nil)
|
|
|
|
// 创建服务实例
|
|
orderService = NewOrderService(orderDao)
|
|
paymentService = NewPaymentService(
|
|
orderDao,
|
|
paymentConfigDao,
|
|
paymentRecordDao,
|
|
refundRecordDao,
|
|
)
|
|
|
|
g.Log().Info(ctx, "服务初始化完成")
|
|
return nil
|
|
}
|
|
|
|
// GetOrderService 获取订单服务实例
|
|
func GetOrderService() *OrderService {
|
|
return orderService
|
|
}
|
|
|
|
// GetPaymentService 获取支付服务实例
|
|
func GetPaymentService() *PaymentService {
|
|
return paymentService
|
|
}
|