Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
1442b0cf64
|
@ -62,6 +62,16 @@ func (m *FsUserMaterialModel) FindOne(ctx context.Context, rowBuilder *gorm.DB)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *FsUserMaterialModel) FindOneData(ctx context.Context, rowBuilder *gorm.DB) (*RelaFsUserMaterial, error) {
|
||||||
|
var resp *RelaFsUserMaterial
|
||||||
|
result := rowBuilder.WithContext(ctx).First(&resp)
|
||||||
|
if result.Error != nil {
|
||||||
|
return nil, result.Error
|
||||||
|
} else {
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (m *FsUserMaterialModel) FindList(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string, orderBy string) ([]*RelaFsUserMaterial, error) {
|
func (m *FsUserMaterialModel) FindList(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string, orderBy string) ([]*RelaFsUserMaterial, error) {
|
||||||
var resp []*RelaFsUserMaterial
|
var resp []*RelaFsUserMaterial
|
||||||
// 过滤
|
// 过滤
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"fusenapi/server/home-user-auth/internal/svc"
|
"fusenapi/server/home-user-auth/internal/svc"
|
||||||
"fusenapi/server/home-user-auth/internal/types"
|
"fusenapi/server/home-user-auth/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logc"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
@ -46,19 +47,76 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a
|
||||||
var userId int64
|
var userId int64
|
||||||
var guestId int64
|
var guestId int64
|
||||||
|
|
||||||
|
if userinfo.IsOnlooker() {
|
||||||
|
// 如果是,返回未授权的错误码
|
||||||
|
return resp.SetStatus(basic.CodeUnAuth)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户信息
|
||||||
|
NewFsUserInfoModel := gmodel.NewFsUserInfoModel(l.svcCtx.MysqlConn)
|
||||||
|
userInfoGorm := NewFsUserInfoModel.BuilderDB(l.ctx, nil).Where("module = ?", "profile")
|
||||||
|
userInfo := gmodel.FsUserInfo{}
|
||||||
|
|
||||||
// 检查用户是否是游客
|
// 检查用户是否是游客
|
||||||
if userinfo.IsGuest() {
|
if userinfo.IsGuest() {
|
||||||
// 如果是,使用游客ID和游客键名格式
|
// 如果是,使用游客ID和游客键名格式
|
||||||
guestId = userinfo.GuestId
|
guestId = userinfo.GuestId
|
||||||
|
userInfoGorm.Where("guest_id = ?", guestId)
|
||||||
} else {
|
} else {
|
||||||
// 否则,使用用户ID和用户键名格式
|
// 否则,使用用户ID和用户键名格式
|
||||||
userId = userinfo.UserId
|
userId = userinfo.UserId
|
||||||
|
userInfoGorm.Where("user_id = ?", userId)
|
||||||
|
}
|
||||||
|
var merchantCategoryIds []int64
|
||||||
|
var logoSelectedIdd int64
|
||||||
|
var userMaterialInfo *gmodel.RelaFsUserMaterial
|
||||||
|
userMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
|
||||||
|
resFirst := userInfoGorm.First(&userInfo)
|
||||||
|
err := resFirst.Error
|
||||||
|
if err != nil {
|
||||||
|
if err != gorm.ErrRecordNotFound {
|
||||||
|
logc.Errorf(l.ctx, "FsUserInfo First err:%+v", err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "data not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if userInfo.Id != 0 && userInfo.Metadata != nil {
|
||||||
|
var metadata map[string]interface{}
|
||||||
|
err = json.Unmarshal([]byte(*userInfo.Metadata), &metadata)
|
||||||
|
if err != nil {
|
||||||
|
logc.Errorf(l.ctx, "userInfo.Metadata Unmarshal err:%+v", err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list")
|
||||||
|
}
|
||||||
|
logoSelectedId, isEx := metadata["logo_selected_id"]
|
||||||
|
if isEx {
|
||||||
|
logoSelectedIdd = int64(logoSelectedId.(float64))
|
||||||
|
userMaterialRSB1 := userMaterialModel.RowSelectBuilder(nil).Preload("ResourceInfo", func(dbPreload *gorm.DB) *gorm.DB {
|
||||||
|
return dbPreload.Table(gmodel.NewFsResourceModel(l.svcCtx.MysqlConn).TableName())
|
||||||
|
}).Where("module = ?", "logo").Where("id = ?", logoSelectedIdd)
|
||||||
|
userMaterialInfo, err = userMaterialModel.FindOneData(l.ctx, userMaterialRSB1)
|
||||||
|
if err != nil {
|
||||||
|
if err != gorm.ErrRecordNotFound {
|
||||||
|
logc.Errorf(l.ctx, "FsUserInfo First err:%+v", err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var metadataMapuserMaterialInfo map[string]interface{}
|
||||||
|
if userMaterialInfo.Metadata != nil {
|
||||||
|
json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapuserMaterialInfo)
|
||||||
|
merchantCategoryuserMaterialInfo, merchantCategoryEixuserMaterialInfo := metadataMapuserMaterialInfo["merchant_category"]
|
||||||
|
if merchantCategoryEixuserMaterialInfo {
|
||||||
|
merchantCategoryIduserMaterialInfo := int64(merchantCategoryuserMaterialInfo.(float64))
|
||||||
|
merchantCategoryIds = append(merchantCategoryIds, merchantCategoryIduserMaterialInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
userMaterialInfo.MetaDataMap = metadataMapuserMaterialInfo
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
userMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
|
// 历史列表
|
||||||
|
|
||||||
userMaterialRSB := userMaterialModel.RowSelectBuilder(nil).Preload("ResourceInfo", func(dbPreload *gorm.DB) *gorm.DB {
|
userMaterialRSB := userMaterialModel.RowSelectBuilder(nil).Preload("ResourceInfo", func(dbPreload *gorm.DB) *gorm.DB {
|
||||||
return dbPreload.Table(gmodel.NewFsResourceModel(l.svcCtx.MysqlConn).TableName())
|
return dbPreload.Table(gmodel.NewFsResourceModel(l.svcCtx.MysqlConn).TableName())
|
||||||
}).Where("module = ?", "logo").Order("id desc").Limit(10)
|
}).Where("module = ?", "logo").Order("id desc").Limit(5)
|
||||||
if userId != 0 {
|
if userId != 0 {
|
||||||
userMaterialRSB.Where("user_id = ?", userId)
|
userMaterialRSB.Where("user_id = ?", userId)
|
||||||
} else {
|
} else {
|
||||||
|
@ -72,8 +130,8 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list")
|
||||||
}
|
}
|
||||||
|
var isDefaul bool = false
|
||||||
if len(list) > 0 {
|
if len(list) > 0 {
|
||||||
var merchantCategoryIds []int64
|
|
||||||
for _, v := range list {
|
for _, v := range list {
|
||||||
var metadataMap map[string]interface{}
|
var metadataMap map[string]interface{}
|
||||||
if v.Metadata != nil {
|
if v.Metadata != nil {
|
||||||
|
@ -95,6 +153,10 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a
|
||||||
v.ResourceInfo.MetaDataMap = resourceMetadata
|
v.ResourceInfo.MetaDataMap = resourceMetadata
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if logoSelectedIdd == v.Id {
|
||||||
|
isDefaul = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(merchantCategoryIds) > 0 {
|
if len(merchantCategoryIds) > 0 {
|
||||||
newFsMerchantCategoryModel := gmodel.NewFsMerchantCategoryModel(l.svcCtx.MysqlConn)
|
newFsMerchantCategoryModel := gmodel.NewFsMerchantCategoryModel(l.svcCtx.MysqlConn)
|
||||||
|
@ -111,7 +173,10 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a
|
||||||
merchantCategoryData[v.Id] = v
|
merchantCategoryData[v.Id] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, v := range list {
|
for k, v := range list {
|
||||||
|
if !isDefaul && k == 4 && userMaterialInfo != nil {
|
||||||
|
v = userMaterialInfo
|
||||||
|
}
|
||||||
if v.MetaDataMap != nil {
|
if v.MetaDataMap != nil {
|
||||||
merchantCategory1, merchantCategoryEix1 := v.MetaDataMap["merchant_category"]
|
merchantCategory1, merchantCategoryEix1 := v.MetaDataMap["merchant_category"]
|
||||||
if merchantCategoryEix1 {
|
if merchantCategoryEix1 {
|
||||||
|
@ -121,6 +186,7 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a
|
||||||
v.MetaDataMap["merchant_category_info"] = nil
|
v.MetaDataMap["merchant_category_info"] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
list[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ func (l *LogoResizeLogic) LogoResize(req *types.LogoResizeReq, userinfo *auth.Us
|
||||||
hashKeyDataB, _ := json.Marshal(req)
|
hashKeyDataB, _ := json.Marshal(req)
|
||||||
json.Unmarshal(hashKeyDataB, &hashKeyDataMap)
|
json.Unmarshal(hashKeyDataB, &hashKeyDataMap)
|
||||||
var resourceId string = hash.JsonHashKey(hashKeyDataMap)
|
var resourceId string = hash.JsonHashKey(hashKeyDataMap)
|
||||||
fmt.Println(resourceId)
|
//fmt.Println(resourceId)
|
||||||
|
|
||||||
// 上传文件
|
// 上传文件
|
||||||
var upload = file.Upload{
|
var upload = file.Upload{
|
||||||
|
@ -107,6 +107,7 @@ func (l *LogoResizeLogic) LogoResize(req *types.LogoResizeReq, userinfo *auth.Us
|
||||||
AwsSession: l.svcCtx.AwsSession,
|
AwsSession: l.svcCtx.AwsSession,
|
||||||
}
|
}
|
||||||
uploadRes, err := upload.UploadFileByByte(&file.UploadBaseReq{
|
uploadRes, err := upload.UploadFileByByte(&file.UploadBaseReq{
|
||||||
|
Refresh: 1,
|
||||||
FileHash: resourceId,
|
FileHash: resourceId,
|
||||||
FileByte: emptyBuff.Bytes(),
|
FileByte: emptyBuff.Bytes(),
|
||||||
UploadBucket: 1,
|
UploadBucket: 1,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user