factroy store
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/rpc/store/pb"
|
||||
"lone-services/services/store/internal/dao"
|
||||
"lone-services/services/store/internal/model"
|
||||
"lone-services/services/store/internal/svc"
|
||||
"strconv"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type EditLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditLogic {
|
||||
return &EditLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *EditLogic) Edit(in *store.EditRequest) (*store.Response, error) {
|
||||
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.FormatInt(in.Id, utils.NumberTen)}}
|
||||
modelObj := model.StoreModel{}.Init()
|
||||
err := modelObj.GetOne(w, &info)
|
||||
if err != nil || info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
|
||||
action := utils.ActionAdd{
|
||||
OldContent: info,
|
||||
Type: utils.LogActionTypeEdit,
|
||||
ModuleName: utils.LogActionModuleStore,
|
||||
}
|
||||
if info.Status != utils.StatusOk &&
|
||||
info.Status != utils.StatusNotPass &&
|
||||
info.Status != utils.StatusAdminSecondRefuse &&
|
||||
info.Status != utils.StatusForbidden {
|
||||
return l.fail(utils.SetError(utils.Fail, "当前状态不允许修改"))
|
||||
}
|
||||
|
||||
oldMobile, cErr := utils.DecryptPhone(info.UserMobile)
|
||||
if cErr == nil {
|
||||
oldMobile = utils.DecryptPhoneReplace(oldMobile)
|
||||
}
|
||||
encryptMobile, cErr := utils.EncryptPhone(in.UserMobile)
|
||||
if cErr != nil {
|
||||
return l.fail(utils.SetError(utils.Fail, cErr.GetMsg()))
|
||||
}
|
||||
if oldMobile != in.UserMobile {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
//TODO 调用用户接口-判断是否可以修改
|
||||
//TODO 调用用户更新接口-更新手机号
|
||||
|
||||
if in.BusinessLicense != info.BusinessLicense {
|
||||
encryptData, cErr := utils.Crypto{}.AESEncryptECB(in.BusinessLicense)
|
||||
if cErr != nil {
|
||||
return l.fail(utils.SetError(utils.Fail, cErr.GetMsg()))
|
||||
}
|
||||
info.BusinessLicense = encryptData
|
||||
}
|
||||
|
||||
if in.IdCard != info.IdCard {
|
||||
encryptIdCard, cErr := utils.Crypto{}.AESEncryptECB(in.IdCard)
|
||||
if cErr != nil {
|
||||
return l.fail(utils.SetError(utils.Fail, cErr.GetMsg()))
|
||||
}
|
||||
info.IdCard = encryptIdCard
|
||||
}
|
||||
|
||||
info.SaleId = in.SaleId
|
||||
info.UserName = in.UserName
|
||||
info.Name = in.Name
|
||||
info.District = in.DistrictIds
|
||||
info.Address = in.Address
|
||||
info.BankInfo = in.BankInfo
|
||||
info.Images = in.Images
|
||||
info.Content = in.Content
|
||||
info.AdminId = adminInfo.ID
|
||||
info.AdminName = adminInfo.Name
|
||||
info.OpenTime = in.OpenTime
|
||||
info.LongitudeWgs84 = in.LongitudeWgs84
|
||||
info.LatitudeWgs84 = in.LatitudeWgs84
|
||||
info.LongitudeGcj02 = in.LongitudeGcj02
|
||||
info.LatitudeGcj02 = in.LatitudeGcj02
|
||||
info.StoreImages = in.StoreImages
|
||||
info.Area = in.Area
|
||||
info.Receipt = in.Receipt
|
||||
info.Type = in.Type
|
||||
info.Province = in.Province
|
||||
info.ProvinceName = in.ProvinceName
|
||||
info.City = in.City
|
||||
info.CityName = in.CityName
|
||||
info.County = in.County
|
||||
info.CountyName = in.CountyName
|
||||
|
||||
if oldMobile != in.UserMobile && encryptMobile != info.UserMobile {
|
||||
info.UserMobile = encryptMobile
|
||||
}
|
||||
w = modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(in.Id, utils.NumberTen)}}
|
||||
edit := dao.StoreNewContent{
|
||||
NewContent: utils.StructToJson(info),
|
||||
AdminId: adminInfo.ID,
|
||||
AdminName: adminInfo.Name,
|
||||
Status: utils.StatusAdminFirstVerify,
|
||||
}
|
||||
row, err := modelObj.Edit(w, &edit)
|
||||
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = info
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
Reference in New Issue
Block a user