feat: sale info
This commit is contained in:
@@ -20,6 +20,8 @@ type DecryptMobileData struct {
|
||||
Mobile string `json:"mobile"`
|
||||
}
|
||||
|
||||
const encryptedPhoneLen = 72
|
||||
|
||||
func NewDecryptMobileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DecryptMobileLogic {
|
||||
return &DecryptMobileLogic{
|
||||
ctx: ctx,
|
||||
@@ -38,6 +40,9 @@ func (l *DecryptMobileLogic) DecryptMobile(in *chore.DecryptMobileReq) (*chore.R
|
||||
if originMobile == utils.StringEmpty {
|
||||
return failResponse(utils.ErrorParams), nil
|
||||
}
|
||||
if len(originMobile) < encryptedPhoneLen {
|
||||
return failResponse(utils.ErrorMobileError), nil
|
||||
}
|
||||
|
||||
mobile, err := utils.DecryptPhone(originMobile)
|
||||
if err != nil {
|
||||
|
||||
@@ -31,15 +31,15 @@ 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)
|
||||
// cli, err := rpcclient.Get(l.svcCtx.ProductSvcName)
|
||||
cli, err := rpcclient.Get(l.svcCtx.SaleSvcName)
|
||||
|
||||
if err != nil {
|
||||
l.Errorf("get rpc: %v", err)
|
||||
return failResponse(utils.ErrorInternalServer), nil
|
||||
}
|
||||
|
||||
// 产品库存更变
|
||||
// ——————————————————————————————产品库存更变——————————————————————————————
|
||||
// _, err = product.NewProductClient(cli.Conn()).Number(l.ctx, &product.NumberReq{
|
||||
// Id: in.GetId(),
|
||||
// Type: productNumberTypeDecr,
|
||||
@@ -53,7 +53,7 @@ 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(),
|
||||
// })
|
||||
@@ -61,13 +61,22 @@ func (l *TestLogic) Test(in *chore.TestReq) (*chore.Response, error) {
|
||||
// fmt.Println(item.GetName())
|
||||
// }
|
||||
|
||||
// 销售 names
|
||||
res, err := sale.NewSaleClient(cli.Conn()).NamesInternal(l.ctx, &sale.NamesReq{
|
||||
Type: in.GetNumber(),
|
||||
Level: uint32(in.GetId()),
|
||||
})
|
||||
// ——————————————————————————————销售 names——————————————————————————————
|
||||
// Type:销售类型
|
||||
// 1 销售人员
|
||||
// 2 销售商(法人)
|
||||
// 3 销售商(个人)
|
||||
// 0 或不传:不按类型过滤
|
||||
|
||||
// TODO: 批量扣减库存
|
||||
// Level:层级过滤
|
||||
// 1:只查顶级(sale_id = 0,没有上级)
|
||||
// 0 或不传:不按层级过滤
|
||||
// res, err := sale.NewSaleClient(cli.Conn()).NamesInternal(l.ctx, &sale.NamesReq{
|
||||
// Type: in.GetNumber(),
|
||||
// Level: uint32(in.GetId()),
|
||||
// })
|
||||
|
||||
// ——————————————————————————————批量扣减库存——————————————————————————————
|
||||
// items := make([]*product.NumberItem, 0, len(in.GetIds()))
|
||||
// for _, id := range in.GetIds() {
|
||||
// items = append(items, &product.NumberItem{
|
||||
@@ -75,19 +84,37 @@ func (l *TestLogic) Test(in *chore.TestReq) (*chore.Response, error) {
|
||||
// Number: in.GetNumber(),
|
||||
// })
|
||||
// }
|
||||
// // {
|
||||
// // "items" : [
|
||||
// // {
|
||||
// // "id": 1,
|
||||
// // "number": 10
|
||||
// // }
|
||||
// // {
|
||||
// // "id": 2,
|
||||
// // "number": 20
|
||||
// // }
|
||||
// // ],
|
||||
// // "type": 1
|
||||
// // }
|
||||
// _, err = product.NewProductClient(cli.Conn()).NumberItems(l.ctx, &product.NumberItemsReq{
|
||||
// Type: productNumberTypeDecr,
|
||||
// Items: items,
|
||||
// })
|
||||
|
||||
// ——————————————————————————————销售详情——————————————————————————————
|
||||
res, err := sale.NewSaleClient(cli.Conn()).InfoInternal(l.ctx, &sale.InfoReq{
|
||||
Id: int64(in.GetId()),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
l.Errorf("XXXXXXXXXXX: %v", err)
|
||||
l.Errorf("XXXXXX: %v", err)
|
||||
return failResponse(utils.ErrorInternalServer), nil
|
||||
}
|
||||
if res == nil {
|
||||
l.Errorf("XXXXXXXXXXX res为空")
|
||||
l.Errorf("XXXXXXXXXX res为空")
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
return okResponse(nil), nil
|
||||
return okResponse(res), nil
|
||||
}
|
||||
|
||||
@@ -81,33 +81,34 @@ type SaleCreate struct {
|
||||
}
|
||||
|
||||
type SaleInfo struct {
|
||||
Id int64 `gorm:"column:id" json:"id"`
|
||||
SaleId int64 `gorm:"column:sale_id" json:"sale_id"`
|
||||
Mobile string `gorm:"column:mobile" json:"mobile"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
IdCardFront string `gorm:"column:id_card_front" json:"id_card_front"`
|
||||
IdCardBack string `gorm:"column:id_card_back" json:"id_card_back"`
|
||||
BusinessLicense string `gorm:"column:business_license" json:"business_license"`
|
||||
Region RegionNames `gorm:"column:region;type:json" json:"region"`
|
||||
ProvinceId int64 `gorm:"column:province_id" json:"province_id"`
|
||||
CityId int64 `gorm:"column:city_id" json:"city_id"`
|
||||
DistrictId int64 `gorm:"column:district_id" json:"district_id"`
|
||||
TerritoryId int64 `gorm:"column:territory_id" json:"territory_id"`
|
||||
TerritoryName string `gorm:"column:territory_name" json:"territory_name"`
|
||||
GroupId int64 `gorm:"column:group_id" json:"group_id"`
|
||||
Address string `gorm:"column:address" json:"address"`
|
||||
Status uint8 `gorm:"column:status" json:"status"`
|
||||
Avatar string `gorm:"column:avatar" json:"avatar"`
|
||||
Account string `gorm:"column:account" json:"account"`
|
||||
Type uint8 `gorm:"column:type" json:"type"`
|
||||
Sex uint8 `gorm:"column:sex" json:"sex"`
|
||||
BirthDate string `gorm:"column:birth_date" json:"birth_date"`
|
||||
Reason string `gorm:"column:reason" json:"reason"`
|
||||
AdminId int64 `gorm:"column:admin_id" json:"admin_id"`
|
||||
AdminName string `gorm:"column:admin_name" json:"admin_name"`
|
||||
CreateTime utils.CustomTime `gorm:"column:create_time" json:"create_time"`
|
||||
UpdateTime utils.CustomTime `gorm:"column:update_time" json:"update_time"`
|
||||
OriginMobile string `gorm:"-" json:"origin_mobile"`
|
||||
Id int64 `gorm:"column:id" json:"id"`
|
||||
SaleId int64 `gorm:"column:sale_id" json:"sale_id"`
|
||||
Mobile string `gorm:"column:mobile" json:"mobile"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
IdCardFront string `gorm:"column:id_card_front" json:"id_card_front"`
|
||||
IdCardBack string `gorm:"column:id_card_back" json:"id_card_back"`
|
||||
BusinessLicense string `gorm:"column:business_license" json:"business_license"`
|
||||
Region RegionNames `gorm:"column:region;type:json" json:"region"`
|
||||
ProvinceId int64 `gorm:"column:province_id" json:"province_id"`
|
||||
CityId int64 `gorm:"column:city_id" json:"city_id"`
|
||||
DistrictId int64 `gorm:"column:district_id" json:"district_id"`
|
||||
TerritoryId int64 `gorm:"column:territory_id" json:"territory_id"`
|
||||
TerritoryName string `gorm:"column:territory_name" json:"territory_name"`
|
||||
GroupId int64 `gorm:"column:group_id" json:"group_id"`
|
||||
Address string `gorm:"column:address" json:"address"`
|
||||
Status uint8 `gorm:"column:status" json:"status"`
|
||||
Avatar string `gorm:"column:avatar" json:"avatar"`
|
||||
Account string `gorm:"column:account" json:"account"`
|
||||
Type uint8 `gorm:"column:type" json:"type"`
|
||||
Sex uint8 `gorm:"column:sex" json:"sex"`
|
||||
BirthDate string `gorm:"column:birth_date" json:"birth_date"`
|
||||
Reason string `gorm:"column:reason" json:"reason"`
|
||||
AdminId int64 `gorm:"column:admin_id" json:"admin_id"`
|
||||
AdminName string `gorm:"column:admin_name" json:"admin_name"`
|
||||
CreateTime utils.CustomTime `gorm:"column:create_time" json:"create_time"`
|
||||
UpdateTime utils.CustomTime `gorm:"column:update_time" json:"update_time"`
|
||||
OriginMobile string `gorm:"-" json:"origin_mobile"`
|
||||
Group *SaleGroupNameItem `gorm:"-" json:"group,omitempty"`
|
||||
}
|
||||
|
||||
type SaleStatusUpdate struct {
|
||||
|
||||
@@ -66,6 +66,34 @@ func maskSaleMobile(info *dao.SaleInfo) {
|
||||
info.Mobile = utils.DecryptPhoneReplace(mobile)
|
||||
}
|
||||
|
||||
// querySaleInfo 查询销售详情并附带分组;mobile 脱敏,origin_mobile 为加密串。
|
||||
// 未找到时返回 (nil, nil)。
|
||||
func querySaleInfo(id int64) (*dao.SaleInfo, error) {
|
||||
var info dao.SaleInfo
|
||||
if err := (model.SaleModel{}.Init().GetOne(modelbase.Params{
|
||||
Eq: map[string]string{"id": strconv.FormatInt(id, 10)},
|
||||
}, &info)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return nil, nil
|
||||
}
|
||||
maskSaleMobile(&info)
|
||||
|
||||
if info.GroupId > utils.NumberZero {
|
||||
var group dao.SaleGroupNameItem
|
||||
if err := (model.SaleGroupModel{}.Init().GetOne(modelbase.Params{
|
||||
Eq: map[string]string{"id": strconv.FormatInt(info.GroupId, 10)},
|
||||
}, &group)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if group.Id > utils.NumberZero {
|
||||
info.Group = &group
|
||||
}
|
||||
}
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func maskSaleNameItems(items []dao.SaleNameItem) {
|
||||
for i := range items {
|
||||
mobile, err := utils.DecryptPhone(items[i].Mobile)
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
sale "lone-services/rpc/sale/pb"
|
||||
"lone-services/services/sale/internal/dao"
|
||||
"lone-services/services/sale/internal/svc"
|
||||
"lone-services/services/sale/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type InfoInternalLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewInfoInternalLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoInternalLogic {
|
||||
return &InfoInternalLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *InfoInternalLogic) InfoInternal(in *sale.InfoReq) (*sale.InfoData, error) {
|
||||
var req validator.InfoValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return nil, status.Error(codes.InvalidArgument, msg)
|
||||
}
|
||||
|
||||
info, err := querySaleInfo(req.Id)
|
||||
if err != nil {
|
||||
l.Errorf("sale InfoInternal: %v", err)
|
||||
return nil, status.Error(codes.Internal, utils.Fail.Msg)
|
||||
}
|
||||
if info == nil {
|
||||
return nil, status.Error(codes.NotFound, utils.ErrorNotFund.Msg)
|
||||
}
|
||||
|
||||
return toSaleInfoData(info), nil
|
||||
}
|
||||
|
||||
func toSaleInfoData(info *dao.SaleInfo) *sale.InfoData {
|
||||
data := &sale.InfoData{
|
||||
Id: info.Id,
|
||||
SaleId: info.SaleId,
|
||||
Mobile: info.Mobile,
|
||||
OriginMobile: info.OriginMobile,
|
||||
Name: info.Name,
|
||||
IdCardFront: info.IdCardFront,
|
||||
IdCardBack: info.IdCardBack,
|
||||
BusinessLicense: info.BusinessLicense,
|
||||
Region: &sale.Region{
|
||||
Province: info.Region.Province,
|
||||
City: info.Region.City,
|
||||
District: info.Region.District,
|
||||
},
|
||||
ProvinceId: info.ProvinceId,
|
||||
CityId: info.CityId,
|
||||
DistrictId: info.DistrictId,
|
||||
TerritoryId: info.TerritoryId,
|
||||
TerritoryName: info.TerritoryName,
|
||||
GroupId: info.GroupId,
|
||||
Address: info.Address,
|
||||
Status: uint32(info.Status),
|
||||
Avatar: info.Avatar,
|
||||
Account: info.Account,
|
||||
Type: uint32(info.Type),
|
||||
Sex: uint32(info.Sex),
|
||||
BirthDate: info.BirthDate,
|
||||
Reason: info.Reason,
|
||||
AdminId: info.AdminId,
|
||||
AdminName: info.AdminName,
|
||||
CreateTime: info.CreateTime.String(),
|
||||
UpdateTime: info.UpdateTime.String(),
|
||||
}
|
||||
if info.Group != nil {
|
||||
data.Group = &sale.GroupItem{
|
||||
Id: info.Group.Id,
|
||||
Name: info.Group.Name,
|
||||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
@@ -2,14 +2,10 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
sale "lone-services/rpc/sale/pb"
|
||||
"lone-services/services/sale/internal/dao"
|
||||
"lone-services/services/sale/internal/model"
|
||||
"lone-services/services/sale/internal/svc"
|
||||
"lone-services/services/sale/validator"
|
||||
|
||||
@@ -36,16 +32,13 @@ func (l *InfoLogic) Info(in *sale.InfoReq) (*sale.Response, error) {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
var info dao.SaleInfo
|
||||
if err := (model.SaleModel{}.Init().GetOne(modelbase.Params{
|
||||
Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)},
|
||||
}, &info)); err != nil {
|
||||
info, err := querySaleInfo(req.Id)
|
||||
if err != nil {
|
||||
l.Errorf("sale info: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
if info == nil {
|
||||
return failResponse(utils.ErrorNotFund), nil
|
||||
}
|
||||
maskSaleMobile(&info)
|
||||
return okResponse(info), nil
|
||||
}
|
||||
|
||||
@@ -70,6 +70,12 @@ func (s *SaleServer) Info(ctx context.Context, in *sale.InfoReq) (*sale.Response
|
||||
return l.Info(in)
|
||||
}
|
||||
|
||||
// 服务间调用:销售详情(含分组;mobile 脱敏,origin_mobile 为加密串)
|
||||
func (s *SaleServer) InfoInternal(ctx context.Context, in *sale.InfoReq) (*sale.InfoData, error) {
|
||||
l := logic.NewInfoInternalLogic(ctx, s.svcCtx)
|
||||
return l.InfoInternal(in)
|
||||
}
|
||||
|
||||
func (s *SaleServer) Items(ctx context.Context, in *sale.ItemsReq) (*sale.Response, error) {
|
||||
l := logic.NewItemsLogic(ctx, s.svcCtx)
|
||||
return l.Items(in)
|
||||
|
||||
@@ -18,12 +18,15 @@ type (
|
||||
EditReq = sale.EditReq
|
||||
GroupCreateReq = sale.GroupCreateReq
|
||||
GroupEmptyReq = sale.GroupEmptyReq
|
||||
GroupItem = sale.GroupItem
|
||||
GroupItemsReq = sale.GroupItemsReq
|
||||
InfoData = sale.InfoData
|
||||
InfoReq = sale.InfoReq
|
||||
ItemsReq = sale.ItemsReq
|
||||
NameItem = sale.NameItem
|
||||
NamesData = sale.NamesData
|
||||
NamesReq = sale.NamesReq
|
||||
Region = sale.Region
|
||||
Response = sale.Response
|
||||
StatusReq = sale.StatusReq
|
||||
|
||||
@@ -39,6 +42,8 @@ type (
|
||||
Create(ctx context.Context, in *CreateReq, opts ...grpc.CallOption) (*Response, error)
|
||||
Edit(ctx context.Context, in *EditReq, opts ...grpc.CallOption) (*Response, error)
|
||||
Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*Response, error)
|
||||
// 服务间调用:销售详情(含分组;mobile 脱敏,origin_mobile 为加密串)
|
||||
InfoInternal(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*InfoData, error)
|
||||
Items(ctx context.Context, in *ItemsReq, opts ...grpc.CallOption) (*Response, error)
|
||||
Status(ctx context.Context, in *StatusReq, opts ...grpc.CallOption) (*Response, error)
|
||||
}
|
||||
@@ -101,6 +106,12 @@ func (m *defaultSale) Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOp
|
||||
return client.Info(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 服务间调用:销售详情(含分组;mobile 脱敏,origin_mobile 为加密串)
|
||||
func (m *defaultSale) InfoInternal(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*InfoData, error) {
|
||||
client := sale.NewSaleClient(m.cli.Conn())
|
||||
return client.InfoInternal(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultSale) Items(ctx context.Context, in *ItemsReq, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := sale.NewSaleClient(m.cli.Conn())
|
||||
return client.Items(ctx, in, opts...)
|
||||
|
||||
Reference in New Issue
Block a user