53d203ee14
CI / changes (push) Successful in 14s
CI / docker-bff (push) Successful in 3s
CI / docker-product (push) Successful in 24s
CI / docker-admin (push) Has been skipped
CI / docker-user (push) Has been skipped
CI / docker-ad (push) Has been skipped
CI / docker-chore (push) Successful in 25s
CI / docker-express (push) Has been skipped
CI / docker-sale (push) Successful in 26s
119 lines
3.5 KiB
Go
119 lines
3.5 KiB
Go
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
|
|
names, nErr := fetchRegionNames(l.ctx, l.svcCtx.ChoreSvcName, req.TerritoryId, req.ProvinceId, req.CityId, req.DistrictId)
|
|
if nErr != nil {
|
|
l.Errorf("sale regions: %v", nErr)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
territoryName := names[req.TerritoryId]
|
|
if territoryName == utils.StringEmpty {
|
|
return outResponse(utils.ErrorParams, "请选择地域"), nil
|
|
}
|
|
province := names[req.ProvinceId]
|
|
if province == utils.StringEmpty {
|
|
return outResponse(utils.ErrorParams, "请选择省份"), nil
|
|
}
|
|
city := names[req.CityId]
|
|
if city == utils.StringEmpty {
|
|
return outResponse(utils.ErrorParams, "请选择城市"), nil
|
|
}
|
|
district := names[req.DistrictId]
|
|
if district == utils.StringEmpty {
|
|
return outResponse(utils.ErrorParams, "请选择区县"), nil
|
|
}
|
|
info.Region = buildRegion(province, city, district)
|
|
info.ProvinceId = req.ProvinceId
|
|
info.CityId = req.CityId
|
|
info.DistrictId = req.DistrictId
|
|
info.TerritoryId = req.TerritoryId
|
|
info.TerritoryName = 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
|
|
}
|