feat: sale manager
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package dao
|
||||
|
||||
type Region struct {
|
||||
Id uint `gorm:"column:id" json:"id"`
|
||||
ParentId *uint `gorm:"column:parent_id" json:"parent_id"`
|
||||
Code string `gorm:"column:code" json:"code"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
Level uint8 `gorm:"column:level" json:"level"`
|
||||
CityCode string `gorm:"column:city_code" json:"city_code"`
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
chore "lone-services/rpc/chore/pb"
|
||||
"lone-services/services/chore/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DecryptMobileLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
type DecryptMobileData struct {
|
||||
Mobile string `json:"mobile"`
|
||||
}
|
||||
|
||||
func NewDecryptMobileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DecryptMobileLogic {
|
||||
return &DecryptMobileLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DecryptMobileLogic) DecryptMobile(in *chore.DecryptMobileReq) (*chore.Response, error) {
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
originMobile := in.GetOriginMobile()
|
||||
if originMobile == utils.StringEmpty {
|
||||
return failResponse(utils.ErrorParams), nil
|
||||
}
|
||||
|
||||
mobile, err := utils.DecryptPhone(originMobile)
|
||||
if err != nil {
|
||||
l.Errorf("decrypt mobile: %v", err)
|
||||
return &chore.Response{
|
||||
Code: int32(utils.ErrorDecryptAesError.GetCode()),
|
||||
Msg: utils.ErrorDecryptAesError.GetMsg(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return okResponse(DecryptMobileData{Mobile: mobile}), nil
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
chore "lone-services/rpc/chore/pb"
|
||||
"lone-services/services/chore/internal/dao"
|
||||
"lone-services/services/chore/internal/model"
|
||||
"lone-services/services/chore/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type RegionsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewRegionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegionsLogic {
|
||||
return &RegionsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *RegionsLogic) Regions(in *chore.RegionsReq) (*chore.Response, error) {
|
||||
params := modelbase.Params{
|
||||
Order: "id ASC",
|
||||
}
|
||||
|
||||
parentID := in.GetParentId()
|
||||
if parentID < utils.NumberOne {
|
||||
params.Eq = map[string]string{"level": strconv.Itoa(int(utils.NumberOne))}
|
||||
} else {
|
||||
params.Eq = map[string]string{"parent_id": strconv.Itoa(int(parentID))}
|
||||
}
|
||||
|
||||
var list []dao.Region
|
||||
if err := (model.RegionModel{}.Init().Items(params, &list)); err != nil {
|
||||
l.Errorf("regions list: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
if list == nil {
|
||||
list = []dao.Region{}
|
||||
}
|
||||
|
||||
return okResponse(list), nil
|
||||
}
|
||||
@@ -2,12 +2,11 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"lone-services/pkg/rpcclient"
|
||||
"lone-services/pkg/utils"
|
||||
chore "lone-services/rpc/chore/pb"
|
||||
product "lone-services/rpc/product/pb"
|
||||
sale "lone-services/rpc/sale/pb"
|
||||
"lone-services/services/chore/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -33,8 +32,10 @@ func NewTestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TestLogic {
|
||||
|
||||
func (l *TestLogic) Test(in *chore.TestReq) (*chore.Response, error) {
|
||||
cli, err := rpcclient.Get(l.svcCtx.ProductSvcName)
|
||||
// cli, err := rpcclient.Get(l.svcCtx.SaleSvcName)
|
||||
|
||||
if err != nil {
|
||||
l.Errorf("get product rpc: %v", err)
|
||||
l.Errorf("get rpc: %v", err)
|
||||
return failResponse(utils.ErrorInternalServer), nil
|
||||
}
|
||||
|
||||
@@ -53,21 +54,40 @@ func (l *TestLogic) Test(in *chore.TestReq) (*chore.Response, error) {
|
||||
// fmt.Println(res.GetName())
|
||||
|
||||
// 获取多个产品详情
|
||||
res, err := product.NewProductClient(cli.Conn()).ItemsByIds(l.ctx, &product.ItemsByIdsReq{
|
||||
Ids: in.GetIds(),
|
||||
// res, err := product.NewProductClient(cli.Conn()).ItemsByIds(l.ctx, &product.ItemsByIdsReq{
|
||||
// Ids: in.GetIds(),
|
||||
// })
|
||||
// for _, item := range res.GetItems() {
|
||||
// fmt.Println(item.GetName())
|
||||
// }
|
||||
|
||||
// 销售 names
|
||||
res, err := sale.NewSaleClient(cli.Conn()).NamesInternal(l.ctx, &sale.NamesReq{
|
||||
Type: in.GetNumber(),
|
||||
Level: uint32(in.GetId()),
|
||||
})
|
||||
for _, item := range res.GetItems() {
|
||||
fmt.Println(item.GetName())
|
||||
}
|
||||
|
||||
// TODO: 批量扣减库存
|
||||
// items := make([]*product.NumberItem, 0, len(in.GetIds()))
|
||||
// for _, id := range in.GetIds() {
|
||||
// items = append(items, &product.NumberItem{
|
||||
// Id: id,
|
||||
// Number: in.GetNumber(),
|
||||
// })
|
||||
// }
|
||||
// _, err = product.NewProductClient(cli.Conn()).NumberItems(l.ctx, &product.NumberItemsReq{
|
||||
// Type: productNumberTypeDecr,
|
||||
// Items: items,
|
||||
// })
|
||||
|
||||
if err != nil {
|
||||
l.Errorf("错误信息: %v", err)
|
||||
l.Errorf("XXXXXXXXXXX: %v", err)
|
||||
return failResponse(utils.ErrorInternalServer), nil
|
||||
}
|
||||
|
||||
if res == nil {
|
||||
l.Errorf("res为空")
|
||||
l.Errorf("XXXXXXXXXXX res为空")
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
return okResponse(res), nil
|
||||
|
||||
return okResponse(nil), nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"lone-services/pkg/modelbase"
|
||||
)
|
||||
|
||||
type RegionModel struct {
|
||||
modelbase.Base
|
||||
}
|
||||
|
||||
func (m RegionModel) TableName() string {
|
||||
return modelbase.Prefix() + "regions"
|
||||
}
|
||||
|
||||
func (m RegionModel) Init() RegionModel {
|
||||
m.Table = m.TableName()
|
||||
return m
|
||||
}
|
||||
@@ -32,3 +32,13 @@ func (s *ChoreServer) Test(ctx context.Context, in *chore.TestReq) (*chore.Respo
|
||||
l := logic.NewTestLogic(ctx, s.svcCtx)
|
||||
return l.Test(in)
|
||||
}
|
||||
|
||||
func (s *ChoreServer) DecryptMobile(ctx context.Context, in *chore.DecryptMobileReq) (*chore.Response, error) {
|
||||
l := logic.NewDecryptMobileLogic(ctx, s.svcCtx)
|
||||
return l.DecryptMobile(in)
|
||||
}
|
||||
|
||||
func (s *ChoreServer) Regions(ctx context.Context, in *chore.RegionsReq) (*chore.Response, error) {
|
||||
l := logic.NewRegionsLogic(ctx, s.svcCtx)
|
||||
return l.Regions(in)
|
||||
}
|
||||
|
||||
@@ -5,21 +5,30 @@ import (
|
||||
"lone-services/services/chore/internal/config"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
DB *gorm.DB
|
||||
ProductSvcName string
|
||||
SaleSvcName string
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
|
||||
productSvc := utils.GetConfigString("services.product")
|
||||
if productSvc == utils.StringEmpty {
|
||||
logx.Error("config services.product empty")
|
||||
}
|
||||
saleSvc := utils.GetConfigString("services.sale")
|
||||
if saleSvc == utils.StringEmpty {
|
||||
logx.Error("config services.sale empty")
|
||||
}
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
DB: db,
|
||||
ProductSvcName: productSvc,
|
||||
SaleSvcName: saleSvc,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user