bid.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package bid
  2. import (
  3. "zhiyuan/pkg/app"
  4. "zhiyuan/pkg/param/material"
  5. bidParam "zhiyuan/pkg/param/material/bid"
  6. itemParam "zhiyuan/pkg/param/material/item"
  7. "zhiyuan/pkg/utils"
  8. "zhiyuan/services/form"
  9. "zhiyuan/services/material/bid"
  10. "zhiyuan/services/material/item"
  11. "zhiyuan/services/material/pkg"
  12. "zhiyuan/services/structs"
  13. "github.com/gin-gonic/gin"
  14. )
  15. func BidOutline(c *gin.Context) {
  16. pkgID := utils.ToInt(c.Query("pkg_id"))
  17. if pkgID <= 0 {
  18. app.Error(c, "套餐 id 有误")
  19. return
  20. }
  21. maxRoomNum := 5
  22. houseStyle := make([]map[string]interface{}, 0)
  23. roomTypes := make([]map[string]interface{}, 0)
  24. for _, v := range material.Params.RoomType {
  25. if v.ID > 0 {
  26. styleValues := make([]map[string]interface{}, 0)
  27. for i := 1; i <= maxRoomNum; i++ {
  28. styleValues = append(styleValues, map[string]interface{}{
  29. "num": i,
  30. "type_name": v.Name,
  31. "room_type": v.ID,
  32. "name": utils.ToStr(i) + v.ShortName,
  33. })
  34. }
  35. houseStyle = append(houseStyle, map[string]interface{}{
  36. "values": styleValues,
  37. "defaultIndex": 0,
  38. })
  39. roomTypes = append(roomTypes, map[string]interface{}{
  40. "id": v.ID,
  41. "name": v.Name,
  42. })
  43. }
  44. }
  45. var pkgInfo *structs.MaterialPkgList
  46. if _, err := pkg.GetPkg(map[string]interface{}{"id": pkgID}, nil, &pkgInfo); err != nil {
  47. app.Error(c, err.Error())
  48. return
  49. }
  50. utils.JsonDecode(pkgInfo.RoomPics).To(&pkgInfo.RoomPicsDecode)
  51. data := map[string]interface{}{
  52. "houseStyle": houseStyle,
  53. "roomTypes": roomTypes,
  54. "pkgInfo": pkgInfo,
  55. }
  56. app.Success(c, data)
  57. }
  58. func BidOutlineCalc(c *gin.Context) {
  59. var form form.MaterialBidOutlineCalc
  60. if app.Bind(c, &form) != nil {
  61. return
  62. }
  63. //=(7906.21+B3*2379.24+14691.52+7718.33*C3)
  64. //+(D3-5.4-C3*3.6)*866.6
  65. //+5.4*1454.8
  66. //+C3*3.6*1454.8
  67. //=(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
  68. //=(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
  69. roomNum := float64(0) // 房间数量
  70. toiletNum := float64(0) // 卫生间数量
  71. for _, v := range form.HouseStyle {
  72. if v.Type == 1 {
  73. roomNum = utils.ToFloat64(v.Num)
  74. } else if v.Type == 4 {
  75. toiletNum = utils.ToFloat64(v.Num)
  76. }
  77. }
  78. form.Area = utils.FloatMul(form.Area, 0.7, -1)
  79. 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)
  80. compute2 := utils.FloatMul(utils.FloatSubSlice([]float64{form.Area, 5.4, utils.FloatMul(toiletNum, 3.6, -1)}, -1), 572, -1)
  81. compute3 := utils.FloatAdd(utils.FloatMul(5.4, 960.17, -1), utils.FloatMulSlice([]float64{toiletNum, 3.6, 960.17}, -1), -1)
  82. compute4 := utils.FloatAddSlice([]float64{compute1, compute2, compute3}, -1)
  83. compute5 := utils.FloatSub(compute4, utils.FloatMulSlice([]float64{form.Area, 0.4, 490}, -1), -1)
  84. compute5 = utils.FloatDiv(compute5, 0.546, -1)
  85. money := utils.FloatAdd(compute5, 69923, 0)
  86. app.Success(c, money)
  87. }
  88. func BidDetail(c *gin.Context) {
  89. //maxRoomNum := 10
  90. houseStyle := make([]map[string]interface{}, 0)
  91. for _, v := range material.Params.RoomType {
  92. if v.ID == 0 {
  93. continue
  94. }
  95. styleValues := make([]map[string]interface{}, 0)
  96. minNum := 1
  97. defaultIndex := 0
  98. if v.ID == 5 {
  99. minNum = 0
  100. defaultIndex = 1
  101. }
  102. for i := minNum; i <= v.MaxRoomNum; i++ {
  103. styleValues = append(styleValues, map[string]interface{}{
  104. "num": i,
  105. "room_type": v.ID,
  106. "type_name": v.Name,
  107. "name": utils.ToStr(i) + v.ShortName,
  108. })
  109. }
  110. houseStyle = append(houseStyle, map[string]interface{}{
  111. "values": styleValues,
  112. "defaultIndex": defaultIndex,
  113. })
  114. }
  115. data := map[string]interface{}{
  116. "houseStyle": houseStyle,
  117. }
  118. app.Success(c, data)
  119. }
  120. func BidDetailCalc(c *gin.Context) {
  121. var form form.MaterialBidDetailCalc
  122. if app.Bind(c, &form) != nil {
  123. return
  124. }
  125. bidList := make([]*structs.MaterialBidList, 0)
  126. if _, err := bid.GetBidList(map[string]interface{}{"pkg_id": form.PkgID}, nil, app.Page{}, &bidList); err != nil {
  127. app.Error(c, err.Error())
  128. }
  129. bidListMap := make(map[int][]*structs.MaterialBidList)
  130. type bidGroup struct {
  131. RoomName string `json:"room_name"`
  132. BidItem map[int][]*structs.MaterialBidList `json:"bid_item"`
  133. }
  134. bidListGroup := make(map[int]bidGroup, 0)
  135. for _, v := range material.Params.RoomType {
  136. bidListMap[v.ID] = make([]*structs.MaterialBidList, 0)
  137. bidListGroup[v.ID] = bidGroup{
  138. RoomName: v.Name,
  139. BidItem: map[int][]*structs.MaterialBidList{
  140. 1: make([]*structs.MaterialBidList, 0),
  141. 2: make([]*structs.MaterialBidList, 0),
  142. 12: make([]*structs.MaterialBidList, 0),
  143. 13: make([]*structs.MaterialBidList, 0),
  144. 14: make([]*structs.MaterialBidList, 0),
  145. 15: make([]*structs.MaterialBidList, 0),
  146. 11: make([]*structs.MaterialBidList, 0),
  147. },
  148. }
  149. }
  150. typeListMap := item.GetTypeMapByIds(bid.GetTypeIDs(bidList))
  151. for _, v := range bidList {
  152. if v.CalcParam != "" {
  153. utils.JsonDecode(v.CalcParam).To(&v.CalcParamDecode)
  154. }
  155. v.TypeNames = bid.GetTypeNames(typeListMap, v.TypeIDs)
  156. if v.Level == 1 {
  157. if form.IsInclusive == 1 || v.Category < 10 {
  158. bidListGroup[v.RoomType].BidItem[v.Category] = append(bidListGroup[v.RoomType].BidItem[v.Category], v)
  159. }
  160. }
  161. }
  162. res, err := bid.Calc(form)
  163. if err != nil {
  164. app.Error(c, err.Error())
  165. return
  166. }
  167. app.Success(c, gin.H{
  168. "area": res.HouseArea,
  169. "money": res.TotalPrice,
  170. "outline_price": res.OutlinePrice,
  171. "bidList": bidListGroup,
  172. })
  173. }
  174. func BidDetailCalcToilet(c *gin.Context) {
  175. var form form.MaterialBidDetailCalc1
  176. if app.Bind(c, &form) != nil {
  177. return
  178. }
  179. res, err := bid.CalcToilet(form)
  180. if err != nil {
  181. app.Error(c, err.Error())
  182. return
  183. }
  184. app.Success(c, gin.H{
  185. "area": res.HouseArea,
  186. "money": res.TotalPrice,
  187. "outline_price": res.OutlinePrice,
  188. "param": res.Param,
  189. "PackagePriceDetail": res.PackagePriceDetail,
  190. })
  191. }
  192. func BidList(c *gin.Context) {
  193. page := app.HandlePageNum(c)
  194. pkgID := utils.ToInt(c.Query("pkg_id"))
  195. if pkgID <= 0 {
  196. app.Error(c, "套餐id有误")
  197. return
  198. }
  199. where := map[string]interface{}{"pkg_id": pkgID}
  200. if bidName := c.Query("bid_name"); bidName != "" {
  201. where["bid_name LIKE"] = "%" + bidName + "%"
  202. }
  203. if level := utils.ToInt(c.Query("level")); level > 0 {
  204. where["level"] = level
  205. }
  206. if category := utils.ToInt(c.Query("category")); category > 0 {
  207. where["category"] = category
  208. }
  209. if room_type := utils.ToInt(c.Query("room_type")); room_type >= 0 {
  210. where["room_type"] = room_type
  211. }
  212. bidList := make([]*structs.MaterialBidList, 0)
  213. if _, err := bid.GetBidList(where, nil, page, &bidList); err != nil {
  214. app.Error(c, err.Error())
  215. return
  216. }
  217. categoryMap := bidParam.GetCategoryMap()
  218. roomTypeMap := material.GetRoomTypeMap(false)
  219. unitMap := itemParam.GetUnitMap()
  220. for _, v := range bidList {
  221. v.CategoryName = categoryMap[v.Category].Name
  222. v.RoomTypeName = roomTypeMap[v.RoomType]
  223. v.UnitName = unitMap[v.Unit]
  224. }
  225. app.Success(c, bidList)
  226. }