refactor all service dependency injection
This commit is contained in:
@@ -4,8 +4,10 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/order/internal/impl"
|
||||
"bsm/full/module/ec/order/internal/models"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
@@ -23,7 +25,7 @@ func Cancel(ctx context.Context, in *pb.CancelRequest) (reply *pb.OrderStatusRep
|
||||
summary = new(models.OrderSummary)
|
||||
)
|
||||
|
||||
err = models.DBService.Where("order_no = ?", in.OrderNo).First(&summary).Error
|
||||
err = impl.DBService.Where("order_no = ?", in.OrderNo).First(&summary).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
@@ -36,14 +38,14 @@ func Cancel(ctx context.Context, in *pb.CancelRequest) (reply *pb.OrderStatusRep
|
||||
}
|
||||
values.Status = -1
|
||||
|
||||
err := models.DBService.Where("order_no = ?", in.OrderNo).Updates(values).Error
|
||||
err := impl.DBService.Where("order_no = ?", in.OrderNo).Updates(values).Error
|
||||
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
err = models.DBService.Model(&models.OrderCoupon{}).Where("identity=?", summary.CouponIdentity).Update("status", 2).Error
|
||||
err = impl.DBService.Model(&models.OrderCoupon{}).Where("identity=?", summary.CouponIdentity).Update("status", 2).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
@@ -4,8 +4,10 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/order/internal/impl"
|
||||
"bsm/full/module/ec/order/internal/models"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
@@ -21,7 +23,7 @@ func Check(ctx context.Context, in *pb.Empty) (reply *pb.OrderStatusReply, err e
|
||||
var (
|
||||
summary = new(models.OrderSummary)
|
||||
)
|
||||
err = models.DBService.Where("passport_id = ?", auth.ID).First(&summary).Error
|
||||
err = impl.DBService.Where("passport_id = ?", auth.ID).First(&summary).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
@@ -3,8 +3,10 @@ package summary
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bsm/full/module/ec/order/internal/impl"
|
||||
"bsm/full/module/ec/order/internal/models"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
@@ -25,7 +27,7 @@ func Confirm(ctx context.Context, in *pb.ConfirmRequest) (reply *pb.ConfirmReply
|
||||
coupon = new(models.OrderCoupon)
|
||||
)
|
||||
|
||||
err = models.DBService.Where("order_no = ?", in.OrderNo).First(&summary).Error
|
||||
err = impl.DBService.Where("order_no = ?", in.OrderNo).First(&summary).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
@@ -33,7 +35,7 @@ func Confirm(ctx context.Context, in *pb.ConfirmRequest) (reply *pb.ConfirmReply
|
||||
|
||||
if in.AddressIdentity != "" {
|
||||
/*
|
||||
err = models.DBService.Where("id=?", in.AddressId).First(&address).Error
|
||||
err = impl.DBService.Where("id=?", in.AddressId).First(&address).Error
|
||||
if err == nil {
|
||||
summary.Address = address.Detail
|
||||
summary.County = address.Country
|
||||
@@ -51,10 +53,10 @@ func Confirm(ctx context.Context, in *pb.ConfirmRequest) (reply *pb.ConfirmReply
|
||||
}
|
||||
|
||||
if in.CouponIdentity != "" {
|
||||
err = models.DBService.Where("identity=?", in.CouponIdentity).First(&coupon).Error
|
||||
err = impl.DBService.Where("identity=?", in.CouponIdentity).First(&coupon).Error
|
||||
if err == nil {
|
||||
if coupon.Status == 2 {
|
||||
models.DBService.Model(&models.OrderCoupon{}).Where("identity=?", in.CouponIdentity).Update("status", 3)
|
||||
impl.DBService.Model(&models.OrderCoupon{}).Where("identity=?", in.CouponIdentity).Update("status", 3)
|
||||
couponAmount = coupon.Amount
|
||||
} else {
|
||||
printer.Error(err.Error())
|
||||
@@ -72,7 +74,7 @@ func Confirm(ctx context.Context, in *pb.ConfirmRequest) (reply *pb.ConfirmReply
|
||||
|
||||
summary.Status = 1
|
||||
|
||||
err = models.DBService.Where("order_no = ?", in.OrderNo).Updates(summary).Error
|
||||
err = impl.DBService.Where("order_no = ?", in.OrderNo).Updates(summary).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"bsm/full/module/ec/order/internal/logic/common"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
|
||||
@@ -4,9 +4,11 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"bsm/full/module/ec/order/internal/impl"
|
||||
"bsm/full/module/ec/order/internal/logic/common"
|
||||
"bsm/full/module/ec/order/internal/models"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
@@ -43,7 +45,7 @@ func List(ctx context.Context, in *pb.SummaryListRequest) (reply *pb.SummaryList
|
||||
}
|
||||
|
||||
orderList := make([]*models.OrderSummary, 0)
|
||||
tx := models.DBService.Model(&models.OrderSummary{}).Preload("OrderDetails").Where("passport_identity = ?", auth.Identity)
|
||||
tx := impl.DBService.Model(&models.OrderSummary{}).Preload("OrderDetails").Where("passport_identity = ?", auth.Identity)
|
||||
if payType != 0 {
|
||||
tx = tx.Where("pay_type = ?", payType)
|
||||
|
||||
|
||||
@@ -6,9 +6,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/order/internal/impl"
|
||||
"bsm/full/module/ec/order/internal/logic/common"
|
||||
"bsm/full/module/ec/order/internal/models"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
@@ -30,7 +32,7 @@ func QuickCreateByProduct(ctx context.Context, in *pb.QuickCreateByProductReques
|
||||
|
||||
// 查询商店信息以确保其存在且状态为启用。
|
||||
store := map[string]any{}
|
||||
err = models.DBService.Table("mall_store").Take(&store, "identity=?", in.StoreIdentity).Error
|
||||
err = impl.DBService.Table("mall_store").Take(&store, "identity=?", in.StoreIdentity).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
if errors.Is(err, models.ErrNotFound) {
|
||||
@@ -46,9 +48,9 @@ func QuickCreateByProduct(ctx context.Context, in *pb.QuickCreateByProductReques
|
||||
product := map[string]any{}
|
||||
var pi string = strings.ToLower(in.ProductIdentity)
|
||||
if pi == "gas_by_kg" || pi == "gas_by_bottle" {
|
||||
err = models.DBService.Table("mall_product").Take(&product, "store_identity=? and serial_id=?", in.StoreIdentity, pi).Error
|
||||
err = impl.DBService.Table("mall_product").Take(&product, "store_identity=? and serial_id=?", in.StoreIdentity, pi).Error
|
||||
} else {
|
||||
err = models.DBService.Table("mall_product").Take(&product, "identity=?", in.ProductIdentity).Error
|
||||
err = impl.DBService.Table("mall_product").Take(&product, "identity=?", in.ProductIdentity).Error
|
||||
}
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
@@ -63,7 +65,7 @@ func QuickCreateByProduct(ctx context.Context, in *pb.QuickCreateByProductReques
|
||||
|
||||
// 查询产品规格信息
|
||||
spec := map[string]any{}
|
||||
err = models.DBService.Table("mall_product_spec").Take(&spec, "product_identity=?", in.ProductIdentity).Error
|
||||
err = impl.DBService.Table("mall_product_spec").Take(&spec, "product_identity=?", in.ProductIdentity).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
if errors.Is(err, models.ErrNotFound) {
|
||||
@@ -74,7 +76,7 @@ func QuickCreateByProduct(ctx context.Context, in *pb.QuickCreateByProductReques
|
||||
|
||||
// 查询地址信息以确保其存在。
|
||||
address := map[string]any{}
|
||||
err = models.DBService.Table("address_library").Take(&address, "identity=?", in.AddressIdentity).Error
|
||||
err = impl.DBService.Table("address_library").Take(&address, "identity=?", in.AddressIdentity).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
if errors.Is(err, models.ErrNotFound) {
|
||||
@@ -85,7 +87,7 @@ func QuickCreateByProduct(ctx context.Context, in *pb.QuickCreateByProductReques
|
||||
|
||||
// // 查询配送员信息
|
||||
// member := map[string]any{}
|
||||
// err = models.DBService.Table("delivery_member").Take(&member, "identity=?", in.MemberIdentity).Error
|
||||
// err = impl.DBService.Table("delivery_member").Take(&member, "identity=?", in.MemberIdentity).Error
|
||||
// if err != nil {
|
||||
// printer.Error(err.Error())
|
||||
// if errors.Is(err, models.ErrNotFound) {
|
||||
@@ -144,13 +146,13 @@ func QuickCreateByProduct(ctx context.Context, in *pb.QuickCreateByProductReques
|
||||
}
|
||||
|
||||
// 将订单摘要和订单详情记录到数据库。
|
||||
err = models.DBService.Create(summary).Error
|
||||
err = impl.DBService.Create(summary).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
err = models.DBService.Create(details).Error
|
||||
err = impl.DBService.Create(details).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
@@ -5,8 +5,10 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/order/internal/impl"
|
||||
"bsm/full/module/ec/order/internal/models"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
@@ -20,7 +22,7 @@ func SimulatePay(ctx context.Context, in *pb.SimulatePayRequest) (reply *pb.Orde
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.DBService.Model(&models.OrderSummary{}).Where("identity in ?", in.Identity).Updates(models.OrderSummary{Status: 2, PayTime: time.Now(), PayType: 4, PayRemark: "支付备注", PayTradeNo: "Pay12371937812897", PayAmount: 10000000}).Error
|
||||
err = impl.DBService.Model(&models.OrderSummary{}).Where("identity in ?", in.Identity).Updates(models.OrderSummary{Status: 2, PayTime: time.Now(), PayType: 4, PayRemark: "支付备注", PayTradeNo: "Pay12371937812897", PayAmount: 10000000}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
if errors.Is(err, models.ErrNotFound) {
|
||||
|
||||
@@ -5,8 +5,10 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/order/internal/impl"
|
||||
"bsm/full/module/ec/order/internal/models"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
@@ -24,7 +26,7 @@ func SimulateReceiving(ctx context.Context, in *pb.OrderIdentRequest) (reply *pb
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = models.DBService.Model(&models.OrderSummary{}).Where("identity = ?", in.Identity).Update("status", 4).Error
|
||||
err = impl.DBService.Model(&models.OrderSummary{}).Where("identity = ?", in.Identity).Update("status", 4).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
if errors.Is(err, models.ErrNotFound) {
|
||||
|
||||
@@ -5,8 +5,10 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/order/internal/impl"
|
||||
"bsm/full/module/ec/order/internal/models"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
@@ -24,7 +26,7 @@ func SimulateShipments(ctx context.Context, in *pb.SimulateShipmentsRequest) (re
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = models.DBService.Where("identity = ?", in.Identity).Updates(&models.OrderSummary{Status: 3, DeliveryIdentity: in.MemberIdentity}).Error
|
||||
err = impl.DBService.Where("identity = ?", in.Identity).Updates(&models.OrderSummary{Status: 3, DeliveryIdentity: in.MemberIdentity}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
if errors.Is(err, models.ErrNotFound) {
|
||||
|
||||
@@ -7,9 +7,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/order/internal/impl"
|
||||
"bsm/full/module/ec/order/internal/logic/common"
|
||||
"bsm/full/module/ec/order/internal/models"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
@@ -40,7 +42,7 @@ func Submit(ctx context.Context, in *pb.SubmitRequest) (reply *pb.OrderStatusRep
|
||||
)
|
||||
|
||||
// 获取购物车内数据信息
|
||||
err = models.DBService.Where("passport_identity = ?", auth.Identity).Find(&cart).Error
|
||||
err = impl.DBService.Where("passport_identity = ?", auth.Identity).Find(&cart).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
if errors.Is(err, models.ErrNotFound) {
|
||||
@@ -63,7 +65,7 @@ func Submit(ctx context.Context, in *pb.SubmitRequest) (reply *pb.OrderStatusRep
|
||||
ZipCode: in.Address.ZipCode,
|
||||
}
|
||||
} else {
|
||||
err = models.DBService.Table("address_library").Where("identity = ?", in.AddressIdentity).Find(&address).Error
|
||||
err = impl.DBService.Table("address_library").Where("identity = ?", in.AddressIdentity).Find(&address).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
if errors.Is(err, models.ErrNotFound) {
|
||||
@@ -77,7 +79,7 @@ func Submit(ctx context.Context, in *pb.SubmitRequest) (reply *pb.OrderStatusRep
|
||||
storeGroups := make(map[string][]*models.OrderCart)
|
||||
for k, item := range cart {
|
||||
product := models.Product{}
|
||||
err = models.DBService.Select("store_identity").Table("mall_product").Where("id = ?", item.ProductID).First(&product).Error
|
||||
err = impl.DBService.Select("store_identity").Table("mall_product").Where("id = ?", item.ProductID).First(&product).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
if errors.Is(err, models.ErrNotFound) {
|
||||
@@ -107,7 +109,7 @@ func Submit(ctx context.Context, in *pb.SubmitRequest) (reply *pb.OrderStatusRep
|
||||
spec := models.Spec{}
|
||||
|
||||
// 获取产品信息
|
||||
err = models.DBService.Select("title,cover_image,cost_price,supply_id,args,gas_types").Table("mall_product").
|
||||
err = impl.DBService.Select("title,cover_image,cost_price,supply_id,args,gas_types").Table("mall_product").
|
||||
Where("id = ?", item.ProductID).First(&product).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
@@ -118,7 +120,7 @@ func Submit(ctx context.Context, in *pb.SubmitRequest) (reply *pb.OrderStatusRep
|
||||
}
|
||||
|
||||
// 获取规格信息
|
||||
err := models.DBService.Select("title,serial_number,price").Table("mall_product_spec").
|
||||
err := impl.DBService.Select("title,serial_number,price").Table("mall_product_spec").
|
||||
Where("id = ?", item.SpecID).First(&spec).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
@@ -182,7 +184,7 @@ func Submit(ctx context.Context, in *pb.SubmitRequest) (reply *pb.OrderStatusRep
|
||||
keys = append(keys, StoreIdentity)
|
||||
}
|
||||
|
||||
err = models.DBService.Transaction(func(tx *gorm.DB) error {
|
||||
err = impl.DBService.Transaction(func(tx *gorm.DB) error {
|
||||
// 1. 创建订单摘要
|
||||
if err := tx.Create(summary).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
|
||||
Reference in New Issue
Block a user