2b19937065
CI / changes (push) Successful in 39s
CI / ad (push) Successful in 1s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 25s
CI / chore (push) Successful in 24s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 1s
CI / factory (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / product (push) Successful in 1s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 24s
CI / task (push) Successful in 0s
CI / user (push) Successful in 0s
CI / wecom (push) Successful in 0s
172 lines
4.3 KiB
Go
172 lines
4.3 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"
|
|
|
|
"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)
|
|
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) 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())
|
|
|
|
mobile, sErr := utils.EncryptPhone(info.UserMobile)
|
|
if sErr != nil {
|
|
return utils.ErrorEncryptAesError
|
|
}
|
|
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
|
|
}
|