package pkg import ( "zhiyuan/pkg/app" "zhiyuan/pkg/param/material" "zhiyuan/pkg/utils" "zhiyuan/services/material/pick" "zhiyuan/services/material/pkg" "github.com/gin-gonic/gin" ) func PkgInfo(c *gin.Context) { pkgID := utils.StrTo(c.Param("id")).MustInt() if pkgID <= 0 { app.Error(c, "套餐 id 有误") return } type PkgSub struct { ID int `json:"id"` SubName string `json:"sub_name"` RoomType int `json:"room_type"` ItemType int `json:"item_type"` Level int `json:"level"` } type PkgInfo struct { ID int `json:"id"` PkgName string `json:"pkg_name"` PriceRule string `json:"price_rule"` } var pkgInfo *PkgInfo if _, err := pkg.GetPkg(map[string]interface{}{"id": pkgID}, nil, &pkgInfo); err != nil { app.Error(c, err.Error()) return } pkgSubList := make([]PkgSub, 0) pkgSubListMap := make(map[int][]PkgSub) if _, err := pick.GetPicks(map[string]interface{}{"pkg_id": pkgID}, nil, app.Page{}, &pkgSubList); err == nil { for _, v := range pkgSubList { pkgSubListMap[v.RoomType] = append(pkgSubListMap[v.RoomType], v) } } roomTypes := utils.ParseSliceMap(material.Params.RoomType, "id") maxRoomNum := 5 houseStyle := make([]map[string]interface{}, 0) for _, v := range material.Params.RoomType { if v.ID == 0 { continue } styleValues := make([]map[string]interface{}, 0) for i := 1; i <= maxRoomNum; i++ { styleValues = append(styleValues, map[string]interface{}{ "room_type": v, "id": i, "name": utils.ToStr(i) + v.ShortName, }) } houseStyle = append(houseStyle, map[string]interface{}{ "values": styleValues, "defaultIndex": 0, }) } data := map[string]interface{}{ "pkgInfo": pkgInfo, "pkgSubs": pkgSubListMap, "houseStyle": houseStyle, "roomTypes": roomTypes, } app.Success(c, data) } func PkgList(c *gin.Context) { where := map[string]interface{}{"state": 1, "show_home": 1} type Pkg struct { ID int `json:"id"` PkgName string `json:"pkg_name"` } pkgList := make([]*Pkg, 0) if _, err := pkg.GetPkgs(where, []string{"id, pkg_name"}, app.Page{}, &pkgList); err != nil { app.Error(c, err.Error()) return } app.Success(c, pkgList) }