pick.go 2.1 KB

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