123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- package bid
- import (
- "zhiyuan/pkg/app"
- "zhiyuan/pkg/param/material"
- bidParam "zhiyuan/pkg/param/material/bid"
- itemParam "zhiyuan/pkg/param/material/item"
- "zhiyuan/pkg/utils"
- "zhiyuan/services/form"
- "zhiyuan/services/material/bid"
- "zhiyuan/services/material/item"
- "zhiyuan/services/material/pkg"
- "zhiyuan/services/structs"
- "github.com/gin-gonic/gin"
- )
- func BidOutline(c *gin.Context) {
- pkgID := utils.ToInt(c.Query("pkg_id"))
- if pkgID <= 0 {
- app.Error(c, "套餐 id 有误")
- return
- }
- maxRoomNum := 5
- houseStyle := make([]map[string]interface{}, 0)
- roomTypes := make([]map[string]interface{}, 0)
- for _, v := range material.Params.RoomType {
- if v.ID > 0 {
- styleValues := make([]map[string]interface{}, 0)
- for i := 1; i <= maxRoomNum; i++ {
- styleValues = append(styleValues, map[string]interface{}{
- "num": i,
- "type_name": v.Name,
- "room_type": v.ID,
- "name": utils.ToStr(i) + v.ShortName,
- })
- }
- houseStyle = append(houseStyle, map[string]interface{}{
- "values": styleValues,
- "defaultIndex": 0,
- })
- roomTypes = append(roomTypes, map[string]interface{}{
- "id": v.ID,
- "name": v.Name,
- })
- }
- }
- var pkgInfo *structs.MaterialPkgList
- if _, err := pkg.GetPkg(map[string]interface{}{"id": pkgID}, nil, &pkgInfo); err != nil {
- app.Error(c, err.Error())
- return
- }
- utils.JsonDecode(pkgInfo.RoomPics).To(&pkgInfo.RoomPicsDecode)
- data := map[string]interface{}{
- "houseStyle": houseStyle,
- "roomTypes": roomTypes,
- "pkgInfo": pkgInfo,
- }
- app.Success(c, data)
- }
- func BidOutlineCalc(c *gin.Context) {
- var form form.MaterialBidOutlineCalc
- if app.Bind(c, &form) != nil {
- return
- }
- //=(7906.21+B3*2379.24+14691.52+7718.33*C3)
- //+(D3-5.4-C3*3.6)*866.6
- //+5.4*1454.8
- //+C3*3.6*1454.8
- //=(5218.1+L24*1570.3+9696.4+5094.1+(M24-1)*5344.1)+(N24-5.4-M24*3.6)*572+5.4*960.17+M24*3.6*960.17+(P24+Q24)/62%-N24*0.4*490
- //=(7906.21+L24*2379.24+14691.52+7718.33*M24)+(N24-5.4-M24*3.6)*866.6+5.4*1454.8+M24*3.6*1454.8-N24*0.4*490/0.66
- roomNum := float64(0) // 房间数量
- toiletNum := float64(0) // 卫生间数量
- for _, v := range form.HouseStyle {
- if v.Type == 1 {
- roomNum = utils.ToFloat64(v.Num)
- } else if v.Type == 4 {
- toiletNum = utils.ToFloat64(v.Num)
- }
- }
- form.Area = utils.FloatMul(form.Area, 0.7, -1)
- compute1 := utils.FloatAddSlice([]float64{5218.1, utils.FloatMul(roomNum, 1570.3, -1), 9696.4, 5094.1, utils.FloatMul(5344.1, utils.FloatSub(toiletNum, 1, -1), -1)}, -1)
- compute2 := utils.FloatMul(utils.FloatSubSlice([]float64{form.Area, 5.4, utils.FloatMul(toiletNum, 3.6, -1)}, -1), 572, -1)
- compute3 := utils.FloatAdd(utils.FloatMul(5.4, 960.17, -1), utils.FloatMulSlice([]float64{toiletNum, 3.6, 960.17}, -1), -1)
- compute4 := utils.FloatAddSlice([]float64{compute1, compute2, compute3}, -1)
- compute5 := utils.FloatSub(compute4, utils.FloatMulSlice([]float64{form.Area, 0.4, 490}, -1), -1)
- compute5 = utils.FloatDiv(compute5, 0.546, -1)
- money := utils.FloatAdd(compute5, 69923, 0)
- app.Success(c, money)
- }
- func BidDetail(c *gin.Context) {
- //maxRoomNum := 10
- houseStyle := make([]map[string]interface{}, 0)
- for _, v := range material.Params.RoomType {
- if v.ID == 0 {
- continue
- }
- styleValues := make([]map[string]interface{}, 0)
- minNum := 1
- defaultIndex := 0
- if v.ID == 5 {
- minNum = 0
- defaultIndex = 1
- }
- for i := minNum; i <= v.MaxRoomNum; i++ {
- styleValues = append(styleValues, map[string]interface{}{
- "num": i,
- "room_type": v.ID,
- "type_name": v.Name,
- "name": utils.ToStr(i) + v.ShortName,
- })
- }
- houseStyle = append(houseStyle, map[string]interface{}{
- "values": styleValues,
- "defaultIndex": defaultIndex,
- })
- }
- data := map[string]interface{}{
- "houseStyle": houseStyle,
- }
- app.Success(c, data)
- }
- func BidDetailCalc(c *gin.Context) {
- var form form.MaterialBidDetailCalc
- if app.Bind(c, &form) != nil {
- return
- }
- bidList := make([]*structs.MaterialBidList, 0)
- if _, err := bid.GetBidList(map[string]interface{}{"pkg_id": form.PkgID}, nil, app.Page{}, &bidList); err != nil {
- app.Error(c, err.Error())
- }
- bidListMap := make(map[int][]*structs.MaterialBidList)
- type bidGroup struct {
- RoomName string `json:"room_name"`
- BidItem map[int][]*structs.MaterialBidList `json:"bid_item"`
- }
- bidListGroup := make(map[int]bidGroup, 0)
- for _, v := range material.Params.RoomType {
- bidListMap[v.ID] = make([]*structs.MaterialBidList, 0)
- bidListGroup[v.ID] = bidGroup{
- RoomName: v.Name,
- BidItem: map[int][]*structs.MaterialBidList{
- 1: make([]*structs.MaterialBidList, 0),
- 2: make([]*structs.MaterialBidList, 0),
- 12: make([]*structs.MaterialBidList, 0),
- 13: make([]*structs.MaterialBidList, 0),
- 14: make([]*structs.MaterialBidList, 0),
- 15: make([]*structs.MaterialBidList, 0),
- 11: make([]*structs.MaterialBidList, 0),
- },
- }
- }
- typeListMap := item.GetTypeMapByIds(bid.GetTypeIDs(bidList))
- for _, v := range bidList {
- if v.CalcParam != "" {
- utils.JsonDecode(v.CalcParam).To(&v.CalcParamDecode)
- }
- v.TypeNames = bid.GetTypeNames(typeListMap, v.TypeIDs)
- if v.Level == 1 {
- if form.IsInclusive == 1 || v.Category < 10 {
- bidListGroup[v.RoomType].BidItem[v.Category] = append(bidListGroup[v.RoomType].BidItem[v.Category], v)
- }
- }
- }
- res, err := bid.Calc(form)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, gin.H{
- "area": res.HouseArea,
- "money": res.TotalPrice,
- "outline_price": res.OutlinePrice,
- "bidList": bidListGroup,
- })
- }
- func BidDetailCalcToilet(c *gin.Context) {
- var form form.MaterialBidDetailCalc1
- if app.Bind(c, &form) != nil {
- return
- }
- res, err := bid.CalcToilet(form)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, gin.H{
- "area": res.HouseArea,
- "money": res.TotalPrice,
- "outline_price": res.OutlinePrice,
- "param": res.Param,
- "PackagePriceDetail": res.PackagePriceDetail,
- })
- }
- func BidList(c *gin.Context) {
- page := app.HandlePageNum(c)
- pkgID := utils.ToInt(c.Query("pkg_id"))
- if pkgID <= 0 {
- app.Error(c, "套餐id有误")
- return
- }
- where := map[string]interface{}{"pkg_id": pkgID}
- if bidName := c.Query("bid_name"); bidName != "" {
- where["bid_name LIKE"] = "%" + bidName + "%"
- }
- if level := utils.ToInt(c.Query("level")); level > 0 {
- where["level"] = level
- }
- if category := utils.ToInt(c.Query("category")); category > 0 {
- where["category"] = category
- }
- if room_type := utils.ToInt(c.Query("room_type")); room_type >= 0 {
- where["room_type"] = room_type
- }
- bidList := make([]*structs.MaterialBidList, 0)
- if _, err := bid.GetBidList(where, nil, page, &bidList); err != nil {
- app.Error(c, err.Error())
- return
- }
- categoryMap := bidParam.GetCategoryMap()
- roomTypeMap := material.GetRoomTypeMap(false)
- unitMap := itemParam.GetUnitMap()
- for _, v := range bidList {
- v.CategoryName = categoryMap[v.Category].Name
- v.RoomTypeName = roomTypeMap[v.RoomType]
- v.UnitName = unitMap[v.Unit]
- }
- app.Success(c, bidList)
- }
|