feat: sale manager
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
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"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type EditLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditLogic {
|
||||
return &EditLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *EditLogic) Edit(in *sale.EditReq) (*sale.Response, error) {
|
||||
var req validator.EditValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
if msg := validateSaleTypeRules(req.Type, req.Account, req.BusinessLicense); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)}}
|
||||
m := model.SaleModel{}.Init()
|
||||
var info dao.SaleCreate
|
||||
if err := m.GetOne(w, &info); err != nil || info.Id < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNotFund), nil
|
||||
}
|
||||
|
||||
encryptMobile, err := utils.EncryptPhone(req.Mobile)
|
||||
if err != nil {
|
||||
l.Errorf("encrypt mobile: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
if encryptMobile != info.Mobile {
|
||||
var check dao.SaleStatusUpdate
|
||||
if err := m.GetOne(modelbase.Params{Eq: map[string]string{"mobile": encryptMobile}}, &check); err != nil {
|
||||
l.Errorf("sale edit mobile check: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
if check.Id > utils.NumberZero && check.Id != req.Id {
|
||||
return failResponse(utils.ErrorDataIsExist), nil
|
||||
}
|
||||
}
|
||||
|
||||
info.SaleId = req.SaleId
|
||||
info.Mobile = encryptMobile
|
||||
info.Name = req.Name
|
||||
info.IdCardFront = req.IdCardFront
|
||||
info.IdCardBack = req.IdCardBack
|
||||
info.BusinessLicense = req.BusinessLicense
|
||||
info.Region = buildRegion(req.RegionProvince, req.RegionCity, req.RegionDistrict)
|
||||
info.ProvinceId = req.ProvinceId
|
||||
info.CityId = req.CityId
|
||||
info.DistrictId = req.DistrictId
|
||||
info.TerritoryId = req.TerritoryId
|
||||
info.TerritoryName = req.TerritoryName
|
||||
info.GroupId = req.GroupId
|
||||
info.Address = req.Address
|
||||
info.Type = uint8(req.Type)
|
||||
info.Sex = uint8(req.Sex)
|
||||
info.BirthDate = req.BirthDate
|
||||
info.Account = req.Account
|
||||
info.AdminId = adminInfo.ID
|
||||
info.AdminName = adminInfo.Name
|
||||
|
||||
if _, err := m.Edit(w, &info); err != nil {
|
||||
l.Errorf("sale edit: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
return okStringResponse(utils.StringEmpty), nil
|
||||
}
|
||||
Reference in New Issue
Block a user