package logic import ( "context" "lone-services/pkg/utils" sale "lone-services/rpc/sale/pb" "lone-services/rpc/store/pb" "lone-services/services/store/internal/dao" "lone-services/services/store/internal/model" "lone-services/services/store/internal/svc" "github.com/zeromicro/go-zero/core/logx" ) type CreateLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger BaseLogic } func NewCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLogic { return &CreateLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func (l *CreateLogic) Create(in *store.CreateRequest) (*store.Response, error) { adminInfo := utils.GetUserFromCtx(l.ctx) if adminInfo.ID < utils.NumberOne { return l.fail(utils.ErrorNoLoginInfo) } //TODO 调用用户接口-判断是否可以注册 encryptMobile, cErr := utils.EncryptPhone(in.UserMobile) if cErr != nil { return l.fail(utils.ErrorEncryptAesError) } encryptData, cErr := utils.Crypto{}.AESEncryptECB(in.BusinessLicense) if cErr != nil { return l.fail(utils.ErrorEncryptAesError) } encryptIdCard, cErr := utils.Crypto{}.AESEncryptECB(in.IdCard) if cErr != nil { return l.fail(utils.ErrorEncryptAesError) } data := dao.StoreCreate{ Name: in.Name, UserName: in.UserName, UserMobile: encryptMobile, BusinessLicense: encryptData, District: in.DistrictIds, Address: in.Address, Status: utils.StatusOk, SaleId: in.SaleId, SourceType: model.StoreTypeAdmin, Images: in.Images, Contact: in.Contact, Content: in.Content, BankInfo: in.BankInfo, OpenTime: in.OpenTime, LongitudeWgs84: in.LongitudeWgs84, LatitudeWgs84: in.LatitudeWgs84, LongitudeGcj02: in.LongitudeGcj02, LatitudeGcj02: in.LatitudeGcj02, AdminId: adminInfo.ID, AdminName: adminInfo.Name, StoreImages: in.StoreImages, IdCard: encryptIdCard, Area: in.Area, Receipt: in.Receipt, Type: in.Type, Province: in.Province, City: in.City, County: in.County, ProvinceName: in.ProvinceName, CityName: in.CityName, CountyName: in.CountyName, } groupId, sErr := l.getSaleInfo(in.SaleId) if sErr != utils.Ok { return l.fail(sErr) } if groupId < utils.NumberOne { return l.fail(utils.ErrorNotFund) } data.GroupId = groupId //TODO 调用用户更新接口-更新手机号 //err = models.StoreModel{}.Init().Create(&data) //if err != nil { // l.Logger.Error(err) // return l.fail(utils.Fail) //} //TODO 发送短信 //result := utils.SendPwdSMS(in.UserMobile, in.Password) //jsonStr, err := json.Marshal(result) //SmsLogService{}.Add(c, in.UserMobile, "您的初始密码为:"+in.Password+",请尽快登录后修改!", string(jsonStr)) //if result.Code != dao.NumberZero { // return check.Id, utils.Fail //} return l.ok(utils.NumberOne) } func (l *CreateLogic) getSaleInfo(id int64) (int64, utils.Status) { cli, err := svc.GetRpcClient(l.svcCtx.SaleName) if err != nil { logx.Errorf("get order err: %v", err) return utils.NumberZero, utils.ErrorInternalServer } client := sale.NewSaleClient(cli.Conn()) w := sale.InfoReq{Id: id} info, err := client.InfoInternal(context.Background(), &w) if err != nil { logx.Errorf("get order err: %v", err) return utils.NumberZero, utils.ErrorInternalServer } return info.GroupId, utils.Ok }