12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package pick
- import (
- "github.com/gin-gonic/gin"
- "zhiyuan/pkg/app"
- "zhiyuan/pkg/param/material"
- "zhiyuan/pkg/utils"
- "zhiyuan/services/material/pick"
- "zhiyuan/services/material/pkg"
- )
- func PickInfo(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.Error(c, "类型id有误")
- return
- }
- info, _ := pick.GetPick(map[string]interface{}{"id": id}, nil, nil)
- app.Success(c, info)
- }
- func PickList(c *gin.Context) {
- pkgID := utils.StrTo(c.Query("pkg_id")).MustInt()
- if pkgID <= 0 {
- app.Error(c, "套餐 id 有误")
- return
- }
- type Pick struct {
- ID int `json:"id"`
- PickName string `json:"pick_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
- }
- pickList := make([]Pick, 0)
- pickListMap := make(map[int][]Pick)
- if _, err := pick.GetPicks(map[string]interface{}{"pkg_id": pkgID}, nil, app.Page{}, &pickList); err == nil {
- for _, v := range pickList {
- pickListMap[v.RoomType] = append(pickListMap[v.RoomType], v)
- }
- }
- roomTypes := make(map[int]string)
- maxRoomNum := 5
- houseStyle := make([]map[string]interface{}, 0)
- for _, v := range material.Params.RoomType {
- roomTypes[v.ID] = v.Name
- if v.ID == 0 {
- continue
- }
- styleValues := make([]map[string]interface{}, 0)
- unique := 0
- for i := 1; i <= maxRoomNum; i++ {
- styleValues = append(styleValues, map[string]interface{}{
- "room_type": v.ID,
- "unique": unique,
- "id": i,
- "name": utils.ToStr(i) + v.ShortName,
- })
- }
- houseStyle = append(houseStyle, map[string]interface{}{
- "values": styleValues,
- "defaultIndex": 0,
- })
- }
- data := map[string]interface{}{
- "pkgInfo": pkgInfo,
- "pickList": pickListMap,
- "houseStyle": houseStyle,
- "roomTypes": roomTypes,
- }
- app.Success(c, data)
- }
|