This commit is contained in:
孙肖扬 2025-06-19 16:16:23 +08:00
parent 734c0b2c1f
commit bdc9706125
3 changed files with 92 additions and 91 deletions

View File

@ -44,7 +44,7 @@ func (b *BundleProvider) BatchGetValueAddServiceLang(ctx context.Context, req *b
return logic.BatchGetValueAddServiceLang(req) return logic.BatchGetValueAddServiceLang(req)
} }
// 增加h5套餐列表 // // 增加h5套餐列表
func (b *BundleProvider) BundleListH5V2(_ context.Context, req *bundle.BundleListRequest) (res *bundle.BundleListResponse, err error) { // func (b *BundleProvider) BundleListH5V2(_ context.Context, req *bundle.BundleListRequest) (res *bundle.BundleListResponse, err error) {
return logic.BundleListH5V2(req) // return logic.BundleListH5V2(req)
} // }

View File

@ -343,94 +343,95 @@ func GetBundleDetailByUuid(uuid string) (*model.BundleProfile, error) {
func CreateBunldeHistory(tx *gorm.DB, req *model.BundleProfileHistory) error { func CreateBunldeHistory(tx *gorm.DB, req *model.BundleProfileHistory) error {
return tx.Model(&model.BundleProfileHistory{}).Create(req).Error return tx.Model(&model.BundleProfileHistory{}).Create(req).Error
} }
func BundleListH5V2(req *bundle.BundleListRequest) (res *bundle.BundleListResponse, err error) {
res = new(bundle.BundleListResponse)
res.Bundles = make([]*bundle.BundleProfile, 0)
bundles := make([]*model.BundleProfile, 0)
query := app.ModuleClients.BundleDB.Model(&model.BundleProfile{}).Where("shelf_status = ?", 1).Preload("BundleProfileLang") // func BundleListH5V2(req *bundle.BundleListRequest) (res *bundle.BundleListResponse, err error) {
//query = query.Where("shelf_status = ?", 1) //上架的 // res = new(bundle.BundleListResponse)
// res.Bundles = make([]*bundle.BundleProfile, 0)
// bundles := make([]*model.BundleProfile, 0)
if req.Name != "" { // query := app.ModuleClients.BundleDB.Model(&model.BundleProfile{}).Where("shelf_status = ?", 1).Preload("BundleProfileLang")
query = query.Where("name like ?", "%"+req.Name+"%") // //query = query.Where("shelf_status = ?", 1) //上架的
}
if req.Content != "" { // if req.Name != "" {
query = query.Where("content like ?", "%"+req.Content+"%") // query = query.Where("name like ?", "%"+req.Name+"%")
} // }
if req.Language != "" { // if req.Content != "" {
query = query.Where("language like ?", req.Language) // query = query.Where("content like ?", "%"+req.Content+"%")
} // }
count := *query // if req.Language != "" {
// query = query.Where("language like ?", req.Language)
// }
// 排序sort 升序,相同 sort 按 created_at 倒序 // count := *query
query = query.Order("sort ASC").Order("created_at DESC")
if req.PageSize != 0 && req.Page != 0 {
query = query.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize))
}
if err = query.Preload("BundleToValueAddService").Find(&bundles).Error; err != nil { // // 排序sort 升序,相同 sort 按 created_at 倒序
return res, commonErr.ReturnError(err, msg.ErrorGetBundleList, "获取套餐列表失败: ") // query = query.Order("sort ASC").Order("created_at DESC")
} // if req.PageSize != 0 && req.Page != 0 {
if bundles != nil && len(bundles) > 0 { // query = query.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize))
for _, bundleProfile := range bundles { // }
selectValueAddService := make([]*bundle.SelectValueAddService, 0)
if bundleProfile.BundleToValueAddService != nil {
for _, v := range bundleProfile.BundleToValueAddService {
selectValueAddService = append(selectValueAddService, &bundle.SelectValueAddService{
ValueAddUuid: v.ValueUid,
IsDisplay: v.IsDisplay,
})
}
}
bundleProfileLang := []*bundle.BundleProfileLang{}
if bundleProfile.BundleProfileLang != nil && len(bundleProfile.BundleProfileLang) > 0 {
for _, lang := range bundleProfile.BundleProfileLang {
bpl := &bundle.BundleProfileLang{
Uuid: lang.UUID,
Name: lang.Name,
Price: lang.Price,
PriceType: lang.PriceType,
Content: lang.Content,
Language: lang.Language,
CreatedAt: time.Unix(lang.CreatedAt, 0).Format("2006-01-02 15:04:05"),
UpdatedAt: time.Unix(int64(lang.UpdatedAt), 0).Format("2006-01-02 15:04:05"),
}
bundleProfileLang = append(bundleProfileLang, bpl)
}
}
res.Bundles = append(res.Bundles, &bundle.BundleProfile{
Uuid: bundleProfile.UUID,
Name: bundleProfile.Name,
Content: bundleProfile.Content,
Price: bundleProfile.Price,
PriceType: bundleProfile.PriceType,
Contract: bundleProfile.Contract,
Language: bundleProfile.Language,
CreatedAt: bundleProfile.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: bundleProfile.UpdatedAt.Format("2006-01-02 15:04:05"),
CompanySign: bundleProfile.CompanySign,
ContractDuration: int64(bundleProfile.ContractDuration),
Sort: bundleProfile.Sort,
ImgOption: int32(bundleProfile.ImgOption),
BgImg1: bundleProfile.BgImg1,
BgImg2: bundleProfile.BgImg2,
SelectValueAddService: selectValueAddService,
BundleProfileLang: bundleProfileLang,
ShelfStatus: int64(bundleProfile.ShelfStatus),
FontColor: bundleProfile.FontColor,
})
}
}
var total int64 // if err = query.Preload("BundleToValueAddService").Find(&bundles).Error; err != nil {
// return res, commonErr.ReturnError(err, msg.ErrorGetBundleList, "获取套餐列表失败: ")
// }
// if bundles != nil && len(bundles) > 0 {
// for _, bundleProfile := range bundles {
// selectValueAddService := make([]*bundle.SelectValueAddService, 0)
// if bundleProfile.BundleToValueAddService != nil {
// for _, v := range bundleProfile.BundleToValueAddService {
// selectValueAddService = append(selectValueAddService, &bundle.SelectValueAddService{
// ValueAddUuid: v.ValueUid,
// IsDisplay: v.IsDisplay,
// })
// }
// }
// bundleProfileLang := []*bundle.BundleProfileLang{}
// if bundleProfile.BundleProfileLang != nil && len(bundleProfile.BundleProfileLang) > 0 {
// for _, lang := range bundleProfile.BundleProfileLang {
// bpl := &bundle.BundleProfileLang{
// Uuid: lang.UUID,
// Name: lang.Name,
// Price: lang.Price,
// PriceType: lang.PriceType,
// Content: lang.Content,
// Language: lang.Language,
// CreatedAt: time.Unix(lang.CreatedAt, 0).Format("2006-01-02 15:04:05"),
// UpdatedAt: time.Unix(int64(lang.UpdatedAt), 0).Format("2006-01-02 15:04:05"),
// }
// bundleProfileLang = append(bundleProfileLang, bpl)
// }
// }
// res.Bundles = append(res.Bundles, &bundle.BundleProfile{
// Uuid: bundleProfile.UUID,
// Name: bundleProfile.Name,
// Content: bundleProfile.Content,
// Price: bundleProfile.Price,
// PriceType: bundleProfile.PriceType,
// Contract: bundleProfile.Contract,
// Language: bundleProfile.Language,
// CreatedAt: bundleProfile.CreatedAt.Format("2006-01-02 15:04:05"),
// UpdatedAt: bundleProfile.UpdatedAt.Format("2006-01-02 15:04:05"),
// CompanySign: bundleProfile.CompanySign,
// ContractDuration: int64(bundleProfile.ContractDuration),
// Sort: bundleProfile.Sort,
// ImgOption: int32(bundleProfile.ImgOption),
// BgImg1: bundleProfile.BgImg1,
// BgImg2: bundleProfile.BgImg2,
// SelectValueAddService: selectValueAddService,
// BundleProfileLang: bundleProfileLang,
// ShelfStatus: int64(bundleProfile.ShelfStatus),
// FontColor: bundleProfile.FontColor,
// })
// }
// }
count.Count(&total) // var total int64
res.Total = int32(total) // count.Count(&total)
return // res.Total = int32(total)
} // return
// }

View File

@ -528,11 +528,11 @@ func saveBundleHistory(tx *gorm.DB, bundleUuid string, operator string, operator
} }
// 增加h5套餐列表 // 增加h5套餐列表
func BundleListH5V2(req *bundle.BundleListRequest) (res *bundle.BundleListResponse, err error) { // func BundleListH5V2(req *bundle.BundleListRequest) (res *bundle.BundleListResponse, err error) {
res = new(bundle.BundleListResponse) // res = new(bundle.BundleListResponse)
res, err = dao.BundleListH5V2(req) // res, err = dao.BundleListH5V2(req)
if err != nil { // if err != nil {
return res, errors.New("获取套餐列表失败") // return res, errors.New("获取套餐列表失败")
} // }
return res, nil // return res, nil
} // }