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