Files
lone-services/services/store/internal/logic/verifyEditLogic.go
T
2026-10-15 09:23:07 +08:00

168 lines
4.2 KiB
Go

package logic
import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
user "lone-services/rpc/user/pb"
"lone-services/services/store/internal/dao"
"lone-services/services/store/internal/model"
"lone-services/services/store/validator"
"strconv"
"strings"
store "lone-services/rpc/store/pb"
"lone-services/services/store/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type VerifyEditLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
BaseLogic
}
func NewVerifyEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VerifyEditLogic {
return &VerifyEditLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *VerifyEditLogic) VerifyEdit(in *store.EditRequest) (*store.Response, error) {
var v validator.StoreCreateValidator
if fail := l.checkParams(in, &v); fail != nil {
return fail, nil
}
adminInfo := utils.GetUserFromCtx(l.ctx)
if adminInfo.ID < utils.NumberOne {
return l.fail(utils.ErrorNoLoginInfo)
}
var info dao.StoreCreate
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
modelObj := model.StoreModel{}.Init()
err := modelObj.GetOne(w, &info)
if err != nil || info.Id < utils.NumberOne {
return l.fail(utils.ErrorNotFund)
}
oldMobile, cErr := utils.DecryptPhone(info.UserMobile)
if cErr != nil {
return l.fail(utils.ErrorEncryptAesError)
}
oldMobile2 := utils.DecryptPhoneReplace(oldMobile)
encryptMobile, cErr := utils.EncryptPhone(in.UserMobile)
if cErr != nil {
return l.fail(utils.ErrorEncryptAesError)
}
if oldMobile != in.UserMobile && oldMobile2 != in.UserName {
var check dao.StoreStatus
ww := modelbase.Params{Eq: map[string]string{"user_mobile": encryptMobile}}
err = modelObj.GetOne(ww, &check)
if err != nil {
l.Logger.Error(err)
return l.fail(utils.Fail)
}
if check.Id > utils.NumberZero && check.Id != info.Id {
return l.fail(utils.ErrorDataIsExist)
}
}
if v.BusinessLicense != info.BusinessLicense {
encryptIdCard, cErr := utils.Crypto{}.AESEncryptECB(v.BusinessLicense)
if cErr != nil {
return l.fail(utils.ErrorEncryptAesError)
}
info.BusinessLicense = encryptIdCard
}
if v.IdCard != info.IdCard {
encryptIdCard, cErr := utils.Crypto{}.AESEncryptECB(v.IdCard)
if cErr != nil {
return l.fail(utils.ErrorEncryptAesError)
}
info.IdCard = encryptIdCard
}
info.SaleId = v.SaleId
info.UserName = v.UserName
info.Name = v.Name
info.District = v.DistrictIds
info.Address = v.Address
info.Images = v.Images
info.Contact = v.Contact
info.Content = v.Content
info.BankInfo = v.BankInfo
info.AdminId = adminInfo.ID
info.AdminName = adminInfo.Name
info.OpenTime = v.OpenTime
info.LongitudeWgs84 = v.LongitudeWgs84
info.LatitudeWgs84 = v.LatitudeWgs84
info.LongitudeGcj02 = v.LongitudeGcj02
info.LatitudeGcj02 = v.LatitudeGcj02
info.StoreImages = v.StoreImages
info.Status = utils.StatusOk
info.Area = v.Area
info.Receipt = v.Receipt
info.Type = v.Type
modelObj.Begin()
if oldMobile != in.UserMobile && encryptMobile != info.UserMobile {
uErr := l.updateUser(info, in.UserMobile)
if uErr != utils.Ok {
modelObj.Rollback()
return l.fail(uErr)
}
info.UserMobile = encryptMobile
_, err = modelObj.Edit(w, &info)
if err != nil {
modelObj.Rollback()
l.Logger.Error(err)
return l.fail(utils.Fail)
}
} else {
_, err = modelObj.Edit(w, &info)
if err != nil {
l.Logger.Error(err)
return l.fail(utils.Fail)
}
}
modelObj.Commit()
return l.ok(utils.NumberOne)
}
func (l *VerifyEditLogic) updateUser(info dao.StoreCreate, mobile string) utils.Status {
cli, err := svc.GetRpcClient(l.svcCtx.OrderName)
if err != nil {
logx.Errorf("get user err: %v", err)
return utils.ErrorInternalServer
}
client := user.NewUserClient(cli.Conn())
data := user.InternalUpdateReq{
BizId: info.Id,
SubjectType: dao.UserTypeName,
Mobile: mobile,
Name: info.UserName,
ClientCode: strings.Split(info.StoreType, utils.DecollatorComma), //哪端
CredentialType: []string{dao.LoginTypePassword, dao.LoginTypeSms},
Identifier: mobile,
}
_, err = client.InternalUpdate(context.Background(), &data)
if err != nil {
logx.Errorf("get order err: %v", err)
return utils.ErrorInternalServer
}
return utils.Ok
}