refactor all service dependency injection
This commit is contained in:
@@ -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"
|
||||
@@ -22,7 +24,7 @@ func Create(ctx context.Context, in *pb.CartAddRequest) (reply *pb.OrderStatusRe
|
||||
}
|
||||
var cart *models.OrderCart
|
||||
|
||||
err = models.DBService.Where("cart_identity=? and product_identity=? and spec_id = ? ", in.CartIdentity, in.ProductIdentity, in.SpecId).First(&cart).Error
|
||||
err = impl.DBService.Where("cart_identity=? and product_identity=? and spec_id = ? ", in.CartIdentity, in.ProductIdentity, in.SpecId).First(&cart).Error
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
printer.Error(err.Error())
|
||||
@@ -41,10 +43,10 @@ func Create(ctx context.Context, in *pb.CartAddRequest) (reply *pb.OrderStatusRe
|
||||
data.PassportIdentity = auth.Identity
|
||||
data.Identity = utils.UUID()
|
||||
if cart.ID == 0 {
|
||||
err = models.DBService.Create(&data).Error
|
||||
err = impl.DBService.Create(&data).Error
|
||||
} else {
|
||||
data.Number += cart.Number
|
||||
err = models.DBService.Where("cart_identity=? and product_identity=? and spec_id = ? ", in.CartIdentity, in.ProductIdentity, in.SpecId).Updates(&data).Error
|
||||
err = impl.DBService.Where("cart_identity=? and product_identity=? and spec_id = ? ", in.CartIdentity, in.ProductIdentity, in.SpecId).Updates(&data).Error
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -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/service"
|
||||
)
|
||||
|
||||
@@ -17,7 +19,7 @@ func Delete(ctx context.Context, in *pb.CartDelRequest) (reply *pb.OrderStatusRe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.DBService.Where("id in ?", in.Id).Delete(&models.OrderCart{}).Error
|
||||
err = impl.DBService.Where("id in ?", in.Id).Delete(&models.OrderCart{}).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package cart
|
||||
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"
|
||||
@@ -26,7 +28,7 @@ func Fetch(ctx context.Context, in *pb.CartGetRequest) (reply *pb.CartGetReply,
|
||||
}
|
||||
}
|
||||
// 查询购物车数据
|
||||
err = models.DBService.Where("cart_identity=? or passport_identity=?", in.GetCarIdentity(), auth.Identity).Find(&cart).Error
|
||||
err = impl.DBService.Where("cart_identity=? or passport_identity=?", in.GetCarIdentity(), auth.Identity).Find(&cart).Error
|
||||
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
@@ -35,7 +37,7 @@ func Fetch(ctx context.Context, in *pb.CartGetRequest) (reply *pb.CartGetReply,
|
||||
|
||||
for _, item := range cart {
|
||||
product := models.Product{}
|
||||
err := models.DBService.Raw(`
|
||||
err := impl.DBService.Raw(`
|
||||
SELECT
|
||||
p.id, p.identity, p.title, p.cover_image, p.args, p.cost_price,
|
||||
( SELECT MIN(mps.price)
|
||||
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/order/internal/models"
|
||||
"bsm/full/module/ec/order/internal/impl"
|
||||
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 +21,7 @@ func Modify(ctx context.Context, in *pb.CartSetRequest) (reply *pb.OrderStatusRe
|
||||
return nil, err
|
||||
}
|
||||
if len(in.GetUpdates()) > 0 {
|
||||
err = models.DBService.Transaction(func(tx *gorm.DB) error {
|
||||
err = impl.DBService.Transaction(func(tx *gorm.DB) error {
|
||||
for _, update := range in.Updates {
|
||||
err := tx.Table("order_cart").Where("id = ?", update.Id).Update("number", update.Number).Error
|
||||
if err != nil {
|
||||
@@ -36,7 +37,7 @@ func Modify(ctx context.Context, in *pb.CartSetRequest) (reply *pb.OrderStatusRe
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = models.DBService.Table("order_cart").Where("id = ?", in.Id).Update("number", in.Number).Error
|
||||
err = impl.DBService.Table("order_cart").Where("id = ?", in.Id).Update("number", in.Number).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
Reference in New Issue
Block a user