pkg.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package pkg
  2. import (
  3. "zhiyuan/pkg/app"
  4. "zhiyuan/pkg/param/material"
  5. "zhiyuan/pkg/utils"
  6. "zhiyuan/services/material/pick"
  7. "zhiyuan/services/material/pkg"
  8. "github.com/gin-gonic/gin"
  9. )
  10. func PkgInfo(c *gin.Context) {
  11. pkgID := utils.StrTo(c.Param("id")).MustInt()
  12. if pkgID <= 0 {
  13. app.Error(c, "套餐 id 有误")
  14. return
  15. }
  16. type PkgSub struct {
  17. ID int `json:"id"`
  18. SubName string `json:"sub_name"`
  19. RoomType int `json:"room_type"`
  20. ItemType int `json:"item_type"`
  21. Level int `json:"level"`
  22. }
  23. type PkgInfo struct {
  24. ID int `json:"id"`
  25. PkgName string `json:"pkg_name"`
  26. PriceRule string `json:"price_rule"`
  27. }
  28. var pkgInfo *PkgInfo
  29. if _, err := pkg.GetPkg(map[string]interface{}{"id": pkgID}, nil, &pkgInfo); err != nil {
  30. app.Error(c, err.Error())
  31. return
  32. }
  33. pkgSubList := make([]PkgSub, 0)
  34. pkgSubListMap := make(map[int][]PkgSub)
  35. if _, err := pick.GetPicks(map[string]interface{}{"pkg_id": pkgID}, nil, app.Page{}, &pkgSubList); err == nil {
  36. for _, v := range pkgSubList {
  37. pkgSubListMap[v.RoomType] = append(pkgSubListMap[v.RoomType], v)
  38. }
  39. }
  40. roomTypes := utils.ParseSliceMap(material.Params.RoomType, "id")
  41. maxRoomNum := 5
  42. houseStyle := make([]map[string]interface{}, 0)
  43. for _, v := range material.Params.RoomType {
  44. if v.ID == 0 {
  45. continue
  46. }
  47. styleValues := make([]map[string]interface{}, 0)
  48. for i := 1; i <= maxRoomNum; i++ {
  49. styleValues = append(styleValues, map[string]interface{}{
  50. "room_type": v,
  51. "id": i,
  52. "name": utils.ToStr(i) + v.ShortName,
  53. })
  54. }
  55. houseStyle = append(houseStyle, map[string]interface{}{
  56. "values": styleValues,
  57. "defaultIndex": 0,
  58. })
  59. }
  60. data := map[string]interface{}{
  61. "pkgInfo": pkgInfo,
  62. "pkgSubs": pkgSubListMap,
  63. "houseStyle": houseStyle,
  64. "roomTypes": roomTypes,
  65. }
  66. app.Success(c, data)
  67. }
  68. func PkgList(c *gin.Context) {
  69. where := map[string]interface{}{"state": 1, "show_home": 1}
  70. type Pkg struct {
  71. ID int `json:"id"`
  72. PkgName string `json:"pkg_name"`
  73. }
  74. pkgList := make([]*Pkg, 0)
  75. if _, err := pkg.GetPkgs(where, []string{"id, pkg_name"}, app.Page{}, &pkgList); err != nil {
  76. app.Error(c, err.Error())
  77. return
  78. }
  79. app.Success(c, pkgList)
  80. }