order.go 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. package bid
  2. import (
  3. "net/http"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "zhiyuan/models"
  8. "zhiyuan/pkg/app"
  9. "zhiyuan/pkg/config"
  10. "zhiyuan/pkg/errcode"
  11. adminParam "zhiyuan/pkg/param/admin"
  12. "zhiyuan/pkg/param/material"
  13. bidParam "zhiyuan/pkg/param/material/bid"
  14. "zhiyuan/pkg/param/material/item"
  15. "zhiyuan/pkg/utils"
  16. "zhiyuan/services/admin"
  17. "zhiyuan/services/dept"
  18. "zhiyuan/services/form"
  19. "zhiyuan/services/material/bid"
  20. "zhiyuan/services/material/pkg"
  21. "zhiyuan/services/structs"
  22. "github.com/gin-gonic/gin"
  23. "github.com/tealeg/xlsx/v3"
  24. )
  25. func OrderList(c *gin.Context) {
  26. page := app.HandlePageNum(c)
  27. pkgID := utils.StrTo(c.Query("pkg_id")).MustInt()
  28. if pkgID <= 0 {
  29. app.Error(c, "套餐id有误")
  30. return
  31. }
  32. pkgInfo, _ := pkg.GetPkg(map[string]interface{}{"id": pkgID}, []string{"id", "room_types", "pkg_name"}, nil)
  33. where := map[string]string{
  34. "where": "`zy_mat_bid_order`.`deleted_at`=0",
  35. "_order_by": "`zy_mat_bid_order`.`id` desc",
  36. }
  37. if page.PageSize != 0 {
  38. where["_page_size"] = utils.ToStr(page.PageSize)
  39. where["_page_num"] = utils.ToStr(page.PageNum)
  40. }
  41. param := make(map[string]interface{})
  42. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`pkg_id` = {{pkg_id}}"
  43. param["pkg_id"] = pkgID
  44. if keyword := c.Query("keyword"); keyword != "" {
  45. where["where"] = where["where"] + " AND (`zy_mat_bid_order`.`customer_name` LIKE {{keyword}} OR `zy_mat_bid_order`.`customer_phone` LIKE {{keyword}})"
  46. param["keyword"] = "%" + keyword + "%"
  47. }
  48. if adminId := utils.ToInt(c.Query("admin_id")); adminId > 0 {
  49. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`admin_id` = {{admin_id}}"
  50. param["admin_id"] = adminId
  51. }
  52. if areaMin := utils.ToFloat64(c.Query("area_min")); areaMin > 0 {
  53. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`house_area` >= {{area_min}}"
  54. param["area_min"] = areaMin
  55. }
  56. if areaMax := utils.ToFloat64(c.Query("area_max")); areaMax > 0 {
  57. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`house_area` <= {{area_max}}"
  58. param["area_max"] = areaMax
  59. }
  60. if moneyMin := utils.ToFloat64(c.Query("money_min")); moneyMin > 0 {
  61. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`total_price` >= {{money_min}}"
  62. param["money_min"] = moneyMin
  63. }
  64. if moneyMax := utils.ToFloat64(c.Query("money_max")); moneyMax > 0 {
  65. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`total_price` <= {{money_max}}"
  66. param["money_max"] = moneyMax
  67. }
  68. if address := c.Query("address"); address != "" {
  69. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`house_address` = {{address}}"
  70. param["address"] = "%" + address + "%"
  71. }
  72. if !admin.IsSuperAdmin(c.GetInt("adminID")) {
  73. var adminInfo *models.Admin
  74. admin.GetInfoByID(c.GetInt("adminID"), nil, &adminInfo)
  75. if adminInfo == nil {
  76. app.Response(c, http.StatusUnauthorized, errcode.TokenInvalid, nil)
  77. return
  78. }
  79. adminRole := false
  80. roleSlice := strings.Split(adminInfo.RoleIds, ",")
  81. for _, v := range roleSlice {
  82. if role, err := strconv.Atoi(v); err == nil && (role == adminParam.AdminRoleId || role == adminParam.MaterialAdminRoleId) {
  83. adminRole = true
  84. break
  85. }
  86. }
  87. if !adminRole {
  88. where["where"] = where["where"] + " AND `zy_admin`.`dept_id` IN {{dept_id}}"
  89. param["dept_id"] = dept.GetSubDeptIds(adminInfo.DeptID, []int{adminInfo.DeptID})
  90. }
  91. }
  92. total, err := bid.CountRaw(where["where"], param)
  93. if err != nil {
  94. app.Error(c, err.Error())
  95. return
  96. }
  97. orderList := make([]structs.MaterialBidOrderList, 0)
  98. if err := bid.GetOrdersRaw(where, param, &orderList); err != nil {
  99. app.Error(c, err.Error())
  100. return
  101. }
  102. roomTypeMap := material.GetRoomTypeMap(true)
  103. orderStateMap := bidParam.GetOrderStateMap()
  104. for k, v := range orderList {
  105. v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD HH:mm")
  106. v.UpdatedAt = utils.DateS(v.UpdatedAt, "YYYY-MM-DD HH:mm")
  107. v.StateName = orderStateMap[v.State].Name
  108. v.StateColor = orderStateMap[v.State].Color
  109. styleName := make([]string, 0)
  110. var houseStyle []structs.HouseStyle
  111. utils.JsonDecode(v.HouseStyle).To(&houseStyle)
  112. for _, house := range houseStyle {
  113. styleName = append(styleName, utils.ToStr(house.Num)+roomTypeMap[house.Type])
  114. }
  115. v.HouseStyle = strings.Join(styleName, "")
  116. v.Auth = structs.MaterialBidOrderAuth{
  117. Finish: utils.IsContain(bidParam.OrderAllow.Finish, v.State),
  118. }
  119. orderList[k] = v
  120. }
  121. data := gin.H{
  122. "pkgInfo": pkgInfo,
  123. "list": orderList,
  124. "total": total,
  125. "limit": page.PageSize,
  126. }
  127. app.Success(c, data)
  128. }
  129. func OrderListExport(c *gin.Context) {
  130. pkgID := utils.StrTo(c.Query("pkg_id")).MustInt()
  131. if pkgID <= 0 {
  132. app.Error(c, "套餐id有误")
  133. return
  134. }
  135. where := map[string]interface{}{"pkg_id": pkgID, "_orderby": "id desc"}
  136. orderList := make([]structs.MaterialBidOrderList, 0)
  137. if _, err := bid.GetOrders(where, nil, app.Page{}, &orderList); err != nil {
  138. app.Error(c, err.Error())
  139. return
  140. }
  141. adminIds := make([]int, 0)
  142. for _, v := range orderList {
  143. adminIds = append(adminIds, v.AdminID)
  144. }
  145. adminListMap := make(map[int]string, 0)
  146. if len(adminIds) > 0 {
  147. if adminList, err := admin.GetAdmins(map[string]interface{}{"id in": adminIds}, nil, app.Page{}, nil); err == nil {
  148. for _, v := range adminList {
  149. adminListMap[v.ID] = v.Username
  150. }
  151. }
  152. }
  153. wb := xlsx.NewFile()
  154. time := utils.ToStr(time.Now().UnixNano())
  155. filename := "預算表导出-" + time + ".xlsx"
  156. fullPath := config.Cfg.App.ExportPath + filename
  157. styleBold := utils.GetCommonStyle(utils.StyleCfg{IsBold: true})
  158. styleCommon := utils.GetCommonStyle(utils.StyleCfg{})
  159. sh, err := wb.AddSheet("Sheet1")
  160. if err != nil {
  161. app.Error(c, err.Error())
  162. return
  163. }
  164. sh = utils.SetColWidth(sh, []float64{10, 30, 10, 10, 10, 10})
  165. var row *xlsx.Row
  166. row = utils.AddRow(sh, utils.Row{Height: 60})
  167. utils.AddCell(row, utils.Cell{Value: "客户名", Style: styleBold})
  168. utils.AddCell(row, utils.Cell{Value: "楼盘", Style: styleBold})
  169. utils.AddCell(row, utils.Cell{Value: "设计师", Style: styleBold})
  170. utils.AddCell(row, utils.Cell{Value: "套餐内总价", Style: styleBold})
  171. utils.AddCell(row, utils.Cell{Value: "个性化总报价", Style: styleBold})
  172. utils.AddCell(row, utils.Cell{Value: "设计费", Style: styleBold})
  173. for _, v := range orderList {
  174. v.AdminName = adminListMap[v.AdminID]
  175. v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD HH:mm")
  176. v.UpdatedAt = utils.DateS(v.UpdatedAt, "YYYY-MM-DD HH:mm")
  177. utils.JsonDecode(v.CustomizePriceDetail).To(&v.CustomizePriceDecode)
  178. row = utils.AddRow(sh, utils.Row{Height: 30})
  179. utils.AddCell(row, utils.Cell{Value: v.CustomerName, Style: styleCommon})
  180. utils.AddCell(row, utils.Cell{Value: v.HouseAddress, Style: styleCommon})
  181. utils.AddCell(row, utils.Cell{Value: v.AdminName, Style: styleCommon})
  182. utils.AddCell(row, utils.Cell{Float: v.PackagePrice, Format: "float", Style: styleCommon})
  183. utils.AddCell(row, utils.Cell{Float: v.CustomizePrice, Format: "float", Style: styleCommon})
  184. utils.AddCell(row, utils.Cell{Float: v.CustomizePriceDecode.Design, Format: "float", Style: styleCommon})
  185. }
  186. if err := wb.Save(fullPath); err != nil {
  187. app.Error(c, err.Error())
  188. return
  189. }
  190. app.Success(c, gin.H{"path": "export/" + filename, "filename": filename})
  191. }
  192. func OrderInfo(c *gin.Context) {
  193. id := utils.ToInt(c.Param("id"))
  194. if id <= 0 {
  195. app.Error(c, "工单 id 为空")
  196. }
  197. var orderInfo structs.MaterialBidOrderList
  198. if _, err := bid.GetOrder(map[string]interface{}{"id": id}, nil, &orderInfo); err != nil {
  199. app.Error(c, err.Error())
  200. }
  201. roomTypeMap := material.GetRoomTypeMap(true)
  202. var houseStyle []structs.HouseStyle
  203. utils.JsonDecode(orderInfo.HouseStyle).To(&houseStyle)
  204. styleName := make([]string, 0)
  205. for _, house := range houseStyle {
  206. styleName = append(styleName, utils.ToStr(house.Num)+roomTypeMap[house.Type])
  207. }
  208. orderInfo.HouseStyle = strings.Join(styleName, "")
  209. utils.JsonDecode(orderInfo.Param).To(&orderInfo.ParamDecode)
  210. utils.JsonDecode(orderInfo.Customize).To(&orderInfo.CustomizeDecode)
  211. utils.JsonDecode(orderInfo.CustomizePriceDetail).To(&orderInfo.CustomizePriceDecode)
  212. utils.JsonDecode(orderInfo.PackagePriceDetail).To(&orderInfo.PackagePriceDecode)
  213. utils.JsonDecode(orderInfo.InclusivePriceDetail).To(&orderInfo.InclusivePriceDecode)
  214. utils.JsonDecode(orderInfo.InclusiveCostDetail).To(&orderInfo.InclusiveCostDecode)
  215. utils.JsonDecode(orderInfo.PackagePriceDetail).To(&orderInfo.OutlinePriceDecode)
  216. utils.JsonDecode(orderInfo.ToiletPriceDetail).To(&orderInfo.ToiletPriceDecode)
  217. bidMap := make(map[int]*structs.MaterialBidList)
  218. bidList := make([]*structs.MaterialBidList, 0)
  219. if _, err := bid.GetBidList(map[string]interface{}{"pkg_id": orderInfo.PkgID}, nil, app.Page{}, &bidList); err == nil {
  220. for _, v := range bidList {
  221. bidMap[v.ID] = v
  222. }
  223. }
  224. app.Success(c, gin.H{
  225. "orderInfo": orderInfo,
  226. "bidList": bidMap,
  227. })
  228. }
  229. func OrderExport(c *gin.Context) {
  230. id := utils.ToInt(c.Param("id"))
  231. if id <= 0 {
  232. app.Error(c, "工单 id 为空")
  233. return
  234. }
  235. var orderInfo structs.MaterialBidOrderList
  236. if _, err := bid.GetOrder(map[string]interface{}{"id": id}, nil, &orderInfo); err != nil {
  237. app.Error(c, err.Error())
  238. return
  239. }
  240. roomTypeMap := material.GetRoomTypeMap(true)
  241. var houseStyle []structs.HouseStyle
  242. utils.JsonDecode(orderInfo.HouseStyle).To(&houseStyle)
  243. styleName := make([]string, 0)
  244. for _, house := range houseStyle {
  245. styleName = append(styleName, utils.ToStr(house.Num)+roomTypeMap[house.Type])
  246. }
  247. orderInfo.HouseStyle = strings.Join(styleName, "")
  248. utils.JsonDecode(orderInfo.Param).To(&orderInfo.ParamDecode)
  249. utils.JsonDecode(orderInfo.Customize).To(&orderInfo.CustomizeDecode)
  250. utils.JsonDecode(orderInfo.CustomizePriceDetail).To(&orderInfo.CustomizePriceDecode)
  251. utils.JsonDecode(orderInfo.PackagePriceDetail).To(&orderInfo.PackagePriceDecode)
  252. utils.JsonDecode(orderInfo.InclusivePriceDetail).To(&orderInfo.InclusivePriceDecode)
  253. bidMap := make(map[int]*structs.MaterialBidList)
  254. bidList := make([]*structs.MaterialBidList, 0)
  255. if _, err := bid.GetBidList(map[string]interface{}{"pkg_id": orderInfo.PkgID}, nil, app.Page{}, &bidList); err == nil {
  256. for _, v := range bidList {
  257. bidMap[v.ID] = v
  258. }
  259. }
  260. if adminInfo, err := admin.GetInfoByID(orderInfo.AdminID, nil, nil); err == nil {
  261. orderInfo.AdminName = adminInfo.Username
  262. }
  263. wb := xlsx.NewFile()
  264. time := utils.ToStr(time.Now().UnixNano())
  265. filename := "2021年[志远一户一价产品]工程预算书-" + orderInfo.HouseAddress + "-" + time + ".xlsx"
  266. fullPath := config.Cfg.App.ExportPath + filename
  267. styleBold := utils.GetCommonStyle(utils.StyleCfg{IsBold: true})
  268. styleCommon := utils.GetCommonStyle(utils.StyleCfg{})
  269. styleHeader := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, FontSize: 17, IsBorderRight: true})
  270. styleHeaderFill := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, IsBorderRight: true, Fill: []string{"00D9D9D9", "FF000000"}})
  271. styleFillLeft := utils.GetCommonStyle(utils.StyleCfg{IsBorderRight: true, Fill: []string{"00D9D9D9", "FF000000"}, Horizontal: "general"})
  272. styleFillBorderRight := utils.GetCommonStyle(utils.StyleCfg{IsBorderRight: true, Fill: []string{"00D9D9D9", "FF000000"}})
  273. styleFill := utils.GetCommonStyle(utils.StyleCfg{Fill: []string{"00D9D9D9", "FF000000"}})
  274. styleBlackBorderRight := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, IsBorderRight: true, Fill: []string{"00808080", "FF000000"}, Horizontal: "general"})
  275. styleBlack := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, Fill: []string{"00808080", "FF000000"}})
  276. styleBoldBorderRight := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, IsBorderRight: true})
  277. styleBorderRight := utils.GetCommonStyle(utils.StyleCfg{IsBorderRight: true})
  278. styleBoldLeftBorderRight := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, IsBorderRight: true, Horizontal: "general"})
  279. styleBoldBorderBottom := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, IsBorderBottom: true})
  280. styleBoldBorderBottomRight := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, IsBorderBottom: true, IsBorderRight: true})
  281. sh, err := wb.AddSheet("Sheet1")
  282. if err != nil {
  283. app.Error(c, err.Error())
  284. return
  285. }
  286. sh = utils.SetColWidth(sh, []float64{10, 5, 20, 5, 10, 15, 15, 80})
  287. var row *xlsx.Row
  288. row = utils.AddRow(sh, utils.Row{Height: 60})
  289. utils.AddCell(row, utils.Cell{Value: "2021年[志远一户一价产品]工程预算书", HMerge: 7, Style: styleHeader})
  290. row = utils.AddRow(sh, utils.Row{Height: 30})
  291. utils.AddCell(row, utils.Cell{Value: "工程预(决)算书 日期: 年 月 日", HMerge: 7, Style: styleHeaderFill})
  292. row = utils.AddRow(sh, utils.Row{Height: 30})
  293. utils.AddCell(row, utils.Cell{Value: "客 户:" + orderInfo.CustomerName + " 联系电话:" + orderInfo.CustomerName + " 工程地址:" + orderInfo.HouseAddress, HMerge: 7, Style: styleFillLeft})
  294. row = utils.AddRow(sh, utils.Row{Height: 30})
  295. utils.AddCell(row, utils.Cell{Value: "房 型:" + orderInfo.HouseStyle + " [套内实测面积M2]:" + utils.ToStr(orderInfo.HouseArea) + " 设计师:" + orderInfo.AdminName, HMerge: 7, Style: styleFillLeft})
  296. row = utils.AddRow(sh, utils.Row{Height: 30})
  297. utils.AddCell(row, utils.Cell{Value: "客 户 温 馨 提 示", HMerge: 7, Style: styleFillBorderRight})
  298. row = utils.AddRow(sh, utils.Row{Height: 45})
  299. utils.AddCell(row, utils.Cell{Value: "一", HMerge: 1, Style: styleFill})
  300. utils.AddCell(row, utils.Cell{Value: "施工中如有漏项、增减项目,应将漏项及增减项目列入结算款中,以实际发生工程量和预算单上工程单价为准,并以现场签证单上双方签字认可为依据进行结算。如预算中所指定材料出现市场供应短缺,则可双方协调调换为同等价位材料;", HMerge: 5, Style: styleFillBorderRight})
  301. row = utils.AddRow(sh, utils.Row{Height: 45})
  302. utils.AddCell(row, utils.Cell{Value: "二", HMerge: 1, Style: styleFill})
  303. utils.AddCell(row, utils.Cell{Value: "客户装修房屋的任何构件(非我方施工主体物件)如可能影响我方施工,无论是拆卸、改造或是用其他办法处理,甲方需承担费用;", HMerge: 5, Style: styleFillBorderRight})
  304. row = utils.AddRow(sh, utils.Row{Height: 45})
  305. utils.AddCell(row, utils.Cell{Value: "三", HMerge: 1, Style: styleFill})
  306. utils.AddCell(row, utils.Cell{Value: "此预算不含物业管理处各项收费。如垃圾外运费、公共设施维护费、办理装修许可证费用等,由甲方自行负责。我公司只交纳办理工人出入证费用;", HMerge: 5, Style: styleFillBorderRight})
  307. row = utils.AddRow(sh, utils.Row{Height: 45})
  308. utils.AddCell(row, utils.Cell{Value: "四", HMerge: 1, Style: styleFill})
  309. utils.AddCell(row, utils.Cell{Value: "不含预算单和图纸标明甲方自购的材料;", HMerge: 5, Style: styleFillBorderRight})
  310. row = utils.AddRow(sh, utils.Row{Height: 45})
  311. utils.AddCell(row, utils.Cell{Value: "五", HMerge: 1, Style: styleFill})
  312. utils.AddCell(row, utils.Cell{Value: "公司严格按照国家安全施工规范进行施工,不承接混凝土墙、水泥现浇梁柱等拆除业务;", HMerge: 5, Style: styleFillBorderRight})
  313. row = utils.AddRow(sh, utils.Row{Height: 45})
  314. utils.AddCell(row, utils.Cell{Value: "工种", Style: styleBold})
  315. utils.AddCell(row, utils.Cell{Value: "编号", Style: styleBold})
  316. utils.AddCell(row, utils.Cell{Value: "项目名称", Style: styleBold})
  317. utils.AddCell(row, utils.Cell{Value: "单位", Style: styleBold})
  318. utils.AddCell(row, utils.Cell{Value: "数量", Style: styleBold})
  319. utils.AddCell(row, utils.Cell{Value: "单价(元)", Style: styleBold})
  320. utils.AddCell(row, utils.Cell{Value: "总价(元)", Style: styleBold})
  321. utils.AddCell(row, utils.Cell{Value: "材 料 及 工 艺 说 明", Style: styleBoldBorderRight})
  322. row = utils.AddRow(sh, utils.Row{Height: 45})
  323. utils.AddCell(row, utils.Cell{Value: "一", HMerge: 1, Style: styleBlack})
  324. utils.AddCell(row, utils.Cell{Value: "一户一价产品内容", HMerge: 5, Style: styleBlackBorderRight})
  325. row = utils.AddRow(sh, utils.Row{Height: 45})
  326. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  327. utils.AddCell(row, utils.Cell{Value: "1", Style: styleCommon})
  328. utils.AddCell(row, utils.Cell{Value: "一户一价工程总价", Style: styleCommon})
  329. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  330. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  331. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  332. utils.AddCell(row, utils.Cell{Float: utils.FloatAdd(orderInfo.PackagePrice, orderInfo.InclusivePrice, 0), Format: "float", Style: styleCommon})
  333. utils.AddCell(row, utils.Cell{Value: "详见《2021年一户一价产品说明表》及报价系统详细说明。", Style: styleBorderRight})
  334. row = utils.AddRow(sh, utils.Row{Height: 45})
  335. utils.AddCell(row, utils.Cell{Value: "二", HMerge: 1, Style: styleBlack})
  336. utils.AddCell(row, utils.Cell{Value: "主材增加项", HMerge: 5, Style: styleBlackBorderRight})
  337. for k, v := range orderInfo.CustomizeDecode[4] {
  338. if bidMap[v.ID] == nil {
  339. bidMap[v.ID] = new(structs.MaterialBidList)
  340. }
  341. row = utils.AddRow(sh, utils.Row{Height: 45})
  342. utils.AddCell(row, utils.Cell{Value: v.RoomTypeName, Style: styleBold})
  343. utils.AddCell(row, utils.Cell{Value: utils.ToStr(k + 1), Style: styleCommon})
  344. utils.AddCell(row, utils.Cell{Value: v.BidName, Style: styleCommon})
  345. utils.AddCell(row, utils.Cell{Value: v.UnitName, Style: styleCommon})
  346. utils.AddCell(row, utils.Cell{Float: v.Num, Format: "float", Style: styleCommon})
  347. utils.AddCell(row, utils.Cell{Float: bidMap[v.ID].Price, Format: "float", Style: styleCommon})
  348. utils.AddCell(row, utils.Cell{Float: v.Total, Format: "float", Style: styleCommon})
  349. utils.AddCell(row, utils.Cell{Value: bidMap[v.ID].Description, Style: styleBorderRight})
  350. }
  351. row = utils.AddRow(sh, utils.Row{Height: 45})
  352. utils.AddCell(row, utils.Cell{Value: "三", HMerge: 1, Style: styleBlack})
  353. utils.AddCell(row, utils.Cell{Value: "主材升级项", HMerge: 5, Style: styleBlackBorderRight})
  354. for k, v := range orderInfo.CustomizeDecode[6] {
  355. if bidMap[v.ID] == nil {
  356. bidMap[v.ID] = new(structs.MaterialBidList)
  357. }
  358. row = utils.AddRow(sh, utils.Row{Height: 45})
  359. utils.AddCell(row, utils.Cell{Value: v.RoomTypeName, Style: styleBold})
  360. utils.AddCell(row, utils.Cell{Value: utils.ToStr(k + 1), Style: styleCommon})
  361. utils.AddCell(row, utils.Cell{Value: v.BidName, Style: styleCommon})
  362. utils.AddCell(row, utils.Cell{Value: v.UnitName, Style: styleCommon})
  363. utils.AddCell(row, utils.Cell{Float: v.Num, Format: "float", Style: styleCommon})
  364. utils.AddCell(row, utils.Cell{Float: bidMap[v.ID].Price, Format: "float", Style: styleCommon})
  365. utils.AddCell(row, utils.Cell{Float: v.Total, Format: "float", Style: styleCommon})
  366. utils.AddCell(row, utils.Cell{Value: bidMap[v.ID].Description, Style: styleBorderRight})
  367. }
  368. row = utils.AddRow(sh, utils.Row{Height: 45})
  369. utils.AddCell(row, utils.Cell{Value: "四", HMerge: 1, Style: styleBlack})
  370. utils.AddCell(row, utils.Cell{Value: "主材减项", HMerge: 5, Style: styleBlackBorderRight})
  371. for k, v := range orderInfo.CustomizeDecode[5] {
  372. if bidMap[v.ID] == nil {
  373. bidMap[v.ID] = new(structs.MaterialBidList)
  374. }
  375. row = utils.AddRow(sh, utils.Row{Height: 45})
  376. utils.AddCell(row, utils.Cell{Value: v.RoomTypeName, Style: styleBold})
  377. utils.AddCell(row, utils.Cell{Value: utils.ToStr(k + 1), Style: styleCommon})
  378. utils.AddCell(row, utils.Cell{Value: v.BidName, Style: styleCommon})
  379. utils.AddCell(row, utils.Cell{Value: v.UnitName, Style: styleCommon})
  380. utils.AddCell(row, utils.Cell{Float: v.Num, Format: "float", Style: styleCommon})
  381. utils.AddCell(row, utils.Cell{Float: bidMap[v.ID].Price, Format: "float", Style: styleCommon})
  382. utils.AddCell(row, utils.Cell{Float: v.Total, Format: "float", Style: styleCommon})
  383. utils.AddCell(row, utils.Cell{Value: bidMap[v.ID].Description, Style: styleBorderRight})
  384. }
  385. row = utils.AddRow(sh, utils.Row{Height: 45})
  386. utils.AddCell(row, utils.Cell{Value: "五", HMerge: 1, Style: styleBlack})
  387. utils.AddCell(row, utils.Cell{Value: "施工增加项", HMerge: 5, Style: styleBlackBorderRight})
  388. for k, v := range orderInfo.CustomizeDecode[3] {
  389. if bidMap[v.ID] == nil {
  390. bidMap[v.ID] = new(structs.MaterialBidList)
  391. }
  392. row = utils.AddRow(sh, utils.Row{Height: 45})
  393. utils.AddCell(row, utils.Cell{Value: v.RoomTypeName, Style: styleBold})
  394. utils.AddCell(row, utils.Cell{Value: utils.ToStr(k + 1), Style: styleCommon})
  395. utils.AddCell(row, utils.Cell{Value: v.BidName, Style: styleCommon})
  396. utils.AddCell(row, utils.Cell{Value: v.UnitName, Style: styleCommon})
  397. utils.AddCell(row, utils.Cell{Float: v.Num, Format: "float", Style: styleCommon})
  398. utils.AddCell(row, utils.Cell{Float: bidMap[v.ID].Price, Format: "float", Style: styleCommon})
  399. utils.AddCell(row, utils.Cell{Float: v.Total, Format: "float", Style: styleCommon})
  400. utils.AddCell(row, utils.Cell{Value: bidMap[v.ID].Description, Style: styleBorderRight})
  401. }
  402. row = utils.AddRow(sh, utils.Row{Height: 45})
  403. utils.AddCell(row, utils.Cell{Value: "其 它", Style: styleBold, VMerge: 13})
  404. utils.AddCell(row, utils.Cell{Value: "A", Style: styleBold})
  405. utils.AddCell(row, utils.Cell{Value: "个性化施工直接费", Style: styleBold})
  406. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  407. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  408. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  409. utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.BuildPrice.Direct, Format: "float", Style: styleCommon})
  410. utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight})
  411. row = utils.AddRow(sh, utils.Row{Height: 45})
  412. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  413. utils.AddCell(row, utils.Cell{Value: "B", Style: styleBold})
  414. utils.AddCell(row, utils.Cell{Value: "个性化主材增项", Style: styleBold})
  415. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  416. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  417. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  418. utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.MaterialAdd, Format: "float", Style: styleCommon})
  419. utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight})
  420. row = utils.AddRow(sh, utils.Row{Height: 45})
  421. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  422. utils.AddCell(row, utils.Cell{Value: "C", Style: styleBold})
  423. utils.AddCell(row, utils.Cell{Value: "个性化主材升级", Style: styleBold})
  424. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  425. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  426. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  427. utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.MaterialUpgrade, Format: "float", Style: styleCommon})
  428. utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight})
  429. row = utils.AddRow(sh, utils.Row{Height: 45})
  430. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  431. utils.AddCell(row, utils.Cell{Value: "D", Style: styleBold})
  432. utils.AddCell(row, utils.Cell{Value: "材料搬运费D=(A+B+C)*" + utils.ToStr(orderInfo.TransportRate*100) + "%\n(如实际核算基数发生变化,计费公式必须同步)", Style: styleBold})
  433. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  434. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  435. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  436. utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.Transport, Format: "float", Style: styleCommon})
  437. utils.AddCell(row, utils.Cell{Value: "有电梯按工程直接费2.5%计算;无电梯二楼按2.5%计算,二楼以上以2.5%为基数每上一楼增加0.5%。(复式楼、别墅户内按无电梯计算)", Style: styleBorderRight})
  438. row = utils.AddRow(sh, utils.Row{Height: 45})
  439. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  440. utils.AddCell(row, utils.Cell{Value: "E", Style: styleBold})
  441. utils.AddCell(row, utils.Cell{Value: "垃圾清运费E=(A+B+C)*" + utils.ToStr(orderInfo.TransportRate*100) + "%\n(如实际核算基数发生变化,计费公式必须同步)", Style: styleBold})
  442. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  443. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  444. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  445. utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.Sanitation, Format: "float", Style: styleCommon})
  446. utils.AddCell(row, utils.Cell{Value: "有电梯按工程直接费2.5%(注:我方将施工过程中每天产生的装修垃圾清理到小区指定堆放点,与管理处收取的垃圾清运费无关)计算;无电梯二楼按2.5%计算,二楼以上以2.5%为基数,每上一楼增加0.5%。(复式楼、别墅户内按无电梯计算)", Style: styleBorderRight})
  447. row = utils.AddRow(sh, utils.Row{Height: 45})
  448. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  449. utils.AddCell(row, utils.Cell{Value: "F", Style: styleBold})
  450. utils.AddCell(row, utils.Cell{Value: "工程管理费F=(A+B+C+D+E)*10%", Style: styleBold})
  451. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  452. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  453. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  454. utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.Manage, Format: "float", Style: styleCommon})
  455. utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight})
  456. row = utils.AddRow(sh, utils.Row{Height: 45})
  457. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  458. utils.AddCell(row, utils.Cell{Value: "G", Style: styleBold})
  459. utils.AddCell(row, utils.Cell{Value: "设计费", Style: styleBold})
  460. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  461. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  462. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  463. utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.Design, Format: "float", Style: styleCommon})
  464. utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight})
  465. row = utils.AddRow(sh, utils.Row{Height: 45})
  466. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  467. utils.AddCell(row, utils.Cell{Value: "H", Style: styleBold})
  468. utils.AddCell(row, utils.Cell{Value: "个性化工程总价H=(A+B+C+D+E+F+G)", Style: styleBold})
  469. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  470. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  471. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  472. utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.Total, Format: "float", Style: styleCommon})
  473. utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight})
  474. row = utils.AddRow(sh, utils.Row{Height: 45})
  475. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  476. utils.AddCell(row, utils.Cell{Value: "I", Style: styleBold})
  477. utils.AddCell(row, utils.Cell{Value: "定制品赠送", Style: styleBold})
  478. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  479. utils.AddCell(row, utils.Cell{Value: strconv.Itoa(orderInfo.InclusiveArea), Style: styleCommon})
  480. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  481. utils.AddCell(row, utils.Cell{Float: 0, Format: "float", Style: styleCommon})
  482. utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight})
  483. row = utils.AddRow(sh, utils.Row{Height: 45})
  484. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  485. utils.AddCell(row, utils.Cell{Value: "J", Style: styleBold})
  486. utils.AddCell(row, utils.Cell{Value: "工程总造价I=一户一价工程总价+个性化工程总价+定制品总价", Style: styleBold})
  487. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  488. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  489. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  490. utils.AddCell(row, utils.Cell{Float: orderInfo.TotalPrice, Format: "float", Style: styleCommon})
  491. utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight})
  492. row = utils.AddRow(sh, utils.Row{Height: 45})
  493. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  494. utils.AddCell(row, utils.Cell{Value: "K", Style: styleBold})
  495. utils.AddCell(row, utils.Cell{Value: "稅金K=J*6%", Style: styleBold})
  496. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  497. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  498. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  499. utils.AddCell(row, utils.Cell{Float: 0, Format: "float", Style: styleCommon})
  500. utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight})
  501. row = utils.AddRow(sh, utils.Row{Height: 45})
  502. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  503. utils.AddCell(row, utils.Cell{Value: "L", Style: styleBold})
  504. utils.AddCell(row, utils.Cell{Value: "工程总造价L=J+K", Style: styleBold})
  505. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  506. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  507. utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
  508. utils.AddCell(row, utils.Cell{Float: orderInfo.TotalPrice, Format: "float", Style: styleCommon})
  509. utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight})
  510. row = utils.AddRow(sh, utils.Row{Height: 45})
  511. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  512. utils.AddCell(row, utils.Cell{Value: "制表: 审核: ", HMerge: 6, Style: styleBoldLeftBorderRight})
  513. row = utils.AddRow(sh, utils.Row{Height: 45})
  514. utils.AddCell(row, utils.Cell{Value: "", Style: styleBold})
  515. utils.AddCell(row, utils.Cell{Value: "甲方签字: 乙方签字: ", HMerge: 6, Style: styleBoldLeftBorderRight})
  516. row = utils.AddRow(sh, utils.Row{Height: 45})
  517. utils.AddCell(row, utils.Cell{Value: "", Style: styleBoldBorderBottom})
  518. utils.AddCell(row, utils.Cell{Value: " 年 月 日 年 月 日 ", HMerge: 6, Style: styleBoldBorderBottomRight})
  519. if err := wb.Save(fullPath); err != nil {
  520. app.Error(c, err.Error())
  521. return
  522. }
  523. app.Success(c, gin.H{"path": "export/" + filename, "filename": filename})
  524. }
  525. func OrderUpdate(c *gin.Context) {
  526. id := utils.StrTo(c.Param("id")).MustInt()
  527. if id <= 0 {
  528. app.ErrorMsg(c, "无效的订单ID", nil)
  529. return
  530. }
  531. if _, err := bid.UpdateOrder(id); err != nil {
  532. app.Error(c, err.Error())
  533. return
  534. }
  535. app.Success(c, nil)
  536. }
  537. func OrderRemark(c *gin.Context) {
  538. id := utils.StrTo(c.Param("id")).MustInt()
  539. if id <= 0 {
  540. app.ErrorMsg(c, "无效的订单ID", nil)
  541. return
  542. }
  543. var form form.OrderRemark
  544. if app.Bind(c, &form) != nil {
  545. return
  546. }
  547. if err := bid.RemarkOrder(form, id); err != nil {
  548. app.Error(c, err.Error())
  549. return
  550. }
  551. app.Success(c, nil)
  552. }
  553. func OrderFinish(c *gin.Context) {
  554. id := utils.StrTo(c.Param("id")).MustInt()
  555. if id <= 0 {
  556. app.Error(c, "工单 id 有误")
  557. return
  558. }
  559. err := bid.FinishOrder(id)
  560. if err != nil {
  561. app.Error(c, err.Error())
  562. return
  563. }
  564. app.Success(c, nil)
  565. }
  566. func OrderListApi(c *gin.Context) {
  567. //page := app.HandlePageNum(c)
  568. pkgID := utils.StrTo(c.Query("pkg_id")).MustInt()
  569. if pkgID <= 0 {
  570. app.Error(c, "套餐id有误")
  571. return
  572. }
  573. //pkgInfo, _ := pkg.GetPkg(map[string]interface{}{"id": pkgID}, []string{"id", "room_types", "pkg_name"}, nil)
  574. where := map[string]string{
  575. "where": "`zy_mat_bid_order`.`deleted_at`=0 AND `zy_mat_bid_order`.`type`=0",
  576. "_order_by": "`zy_mat_bid_order`.`id` desc",
  577. }
  578. /*if page.PageSize != 0 {
  579. where["_page_size"] = utils.ToStr(page.PageSize)
  580. where["_page_num"] = utils.ToStr(page.PageNum)
  581. }*/
  582. param := make(map[string]interface{})
  583. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`pkg_id` = {{pkg_id}}"
  584. param["pkg_id"] = pkgID
  585. if keyword := c.Query("keyword"); keyword != "" {
  586. where["where"] = where["where"] + " AND (`zy_mat_bid_order`.`customer_name` LIKE {{keyword}} OR `zy_mat_bid_order`.`customer_phone` LIKE {{keyword}} OR `zy_mat_bid_order`.`house_address` LIKE {{keyword}})"
  587. param["keyword"] = "%" + keyword + "%"
  588. }
  589. if phone := c.Query("phone"); phone != "" {
  590. where["where"] = where["where"] + " AND `zy_admin`.`phone` = {{phone}}"
  591. param["phone"] = phone
  592. } else {
  593. where["where"] = where["where"] + " AND 1=2"
  594. }
  595. /*if adminId := utils.ToInt(c.Query("admin_id")); adminId > 0 {
  596. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`admin_id` = {{admin_id}}"
  597. param["admin_id"] = adminId
  598. }
  599. if areaMin := utils.ToFloat64(c.Query("area_min")); areaMin > 0 {
  600. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`house_area` >= {{area_min}}"
  601. param["area_min"] = areaMin
  602. }
  603. if areaMax := utils.ToFloat64(c.Query("area_max")); areaMax > 0 {
  604. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`house_area` <= {{area_max}}"
  605. param["area_max"] = areaMax
  606. }
  607. if moneyMin := utils.ToFloat64(c.Query("money_min")); moneyMin > 0 {
  608. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`total_price` >= {{money_min}}"
  609. param["money_min"] = moneyMin
  610. }
  611. if moneyMax := utils.ToFloat64(c.Query("money_max")); moneyMax > 0 {
  612. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`total_price` <= {{money_max}}"
  613. param["money_max"] = moneyMax
  614. }
  615. if address := c.Query("address"); address != "" {
  616. where["where"] = where["where"] + " AND `zy_mat_bid_order`.`house_address` = {{address}}"
  617. param["address"] = "%" + address + "%"
  618. }*/
  619. /*if !admin.IsSuperAdmin(c.GetInt("adminID")) {
  620. var adminInfo *models.Admin
  621. admin.GetInfoByID(c.GetInt("adminID"), nil, &adminInfo)
  622. if adminInfo == nil {
  623. app.Response(c, http.StatusUnauthorized, errcode.TokenInvalid, nil)
  624. return
  625. }
  626. adminRole := false
  627. roleSlice := strings.Split(adminInfo.RoleIds, ",")
  628. for _, v := range roleSlice {
  629. if role, err := strconv.Atoi(v); err == nil && (role == adminParam.AdminRoleId || role == adminParam.MaterialAdminRoleId) {
  630. adminRole = true
  631. break
  632. }
  633. }
  634. if !adminRole {
  635. where["where"] = where["where"] + " AND `zy_admin`.`dept_id` IN {{dept_id}}"
  636. param["dept_id"] = dept.GetSubDeptIds(adminInfo.DeptID, []int{adminInfo.DeptID})
  637. }
  638. }*/
  639. total, err := bid.CountRaw(where["where"], param)
  640. if err != nil {
  641. app.Error(c, err.Error())
  642. return
  643. }
  644. orderList := make([]structs.MaterialBidOrderList, 0)
  645. if err := bid.GetOrdersRaw(where, param, &orderList); err != nil {
  646. app.Error(c, err.Error())
  647. return
  648. }
  649. roomTypeMap := material.GetRoomTypeMap(true)
  650. orderStateMap := bidParam.GetOrderStateMap()
  651. for k, v := range orderList {
  652. v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD HH:mm")
  653. v.UpdatedAt = utils.DateS(v.UpdatedAt, "YYYY-MM-DD HH:mm")
  654. v.StateName = orderStateMap[v.State].Name
  655. v.StateColor = orderStateMap[v.State].Color
  656. styleName := make([]string, 0)
  657. var houseStyle []structs.HouseStyle
  658. utils.JsonDecode(v.HouseStyle).To(&houseStyle)
  659. for _, house := range houseStyle {
  660. styleName = append(styleName, utils.ToStr(house.Num)+roomTypeMap[house.Type])
  661. }
  662. v.HouseStyle = strings.Join(styleName, "")
  663. v.Auth = structs.MaterialBidOrderAuth{
  664. Finish: utils.IsContain(bidParam.OrderAllow.Finish, v.State),
  665. }
  666. orderList[k] = v
  667. }
  668. data := gin.H{
  669. //"pkgInfo": pkgInfo,
  670. "list": orderList,
  671. "total": total,
  672. //"limit": page.PageSize,
  673. }
  674. app.Success(c, data)
  675. }
  676. func OrderInfoApi(c *gin.Context) {
  677. id := utils.StrTo(c.Query("id")).MustInt()
  678. if id <= 0 {
  679. app.Error(c, "工单 id 为空")
  680. }
  681. var orderInfo structs.MaterialBidOrderList
  682. if _, err := bid.GetOrder(map[string]interface{}{"id": id}, nil, &orderInfo); err != nil {
  683. app.Error(c, err.Error())
  684. }
  685. roomTypeMap := material.GetRoomTypeMap(true)
  686. var houseStyle []structs.HouseStyle
  687. utils.JsonDecode(orderInfo.HouseStyle).To(&houseStyle)
  688. styleName := make([]string, 0)
  689. for _, house := range houseStyle {
  690. styleName = append(styleName, utils.ToStr(house.Num)+roomTypeMap[house.Type])
  691. }
  692. orderInfo.HouseStyle = strings.Join(styleName, "")
  693. utils.JsonDecode(orderInfo.Param).To(&orderInfo.ParamDecode)
  694. utils.JsonDecode(orderInfo.Customize).To(&orderInfo.CustomizeDecode)
  695. utils.JsonDecode(orderInfo.CustomizePriceDetail).To(&orderInfo.CustomizePriceDecode)
  696. utils.JsonDecode(orderInfo.PackagePriceDetail).To(&orderInfo.PackagePriceDecode)
  697. utils.JsonDecode(orderInfo.InclusivePriceDetail).To(&orderInfo.InclusivePriceDecode)
  698. utils.JsonDecode(orderInfo.InclusiveCostDetail).To(&orderInfo.InclusiveCostDecode)
  699. utils.JsonDecode(orderInfo.PackagePriceDetail).To(&orderInfo.OutlinePriceDecode)
  700. bidMap := make(map[int]*structs.MaterialBidList)
  701. bidList := make([]*structs.MaterialBidList, 0)
  702. if _, err := bid.GetBidList(map[string]interface{}{"pkg_id": orderInfo.PkgID}, nil, app.Page{}, &bidList); err == nil {
  703. for _, v := range bidList {
  704. bidMap[v.ID] = v
  705. }
  706. }
  707. type List struct {
  708. ID int `json:"id"`
  709. Category int `json:"category"`
  710. RoomType int `json:"room_type" label:"房屋类型"`
  711. RoomName string `json:"room_name" label:"房屋"`
  712. BidName string `json:"bid_name"`
  713. Description string `json:"description"`
  714. Price float64 `json:"price"`
  715. Count float64 `json:"count"`
  716. Total float64 `json:"total"`
  717. Unit string `json:"unit"`
  718. }
  719. calcSetting := bid.GetCalcSetting(houseStyle)
  720. list := make([]List, 0)
  721. for _, room := range orderInfo.ParamDecode {
  722. for _, i := range room.Items {
  723. if bid, ok := bidMap[i.ID]; ok && bid.Category <= 2 {
  724. if bid.CalcType == 7 {
  725. utils.JsonDecode(bid.CalcParam).To(&bid.CalcParamDecode)
  726. list = append(list, List{
  727. ID: bid.ID,
  728. Category: bid.Category,
  729. RoomType: room.RoomType,
  730. RoomName: room.RoomName,
  731. BidName: bid.BidName,
  732. Description: bid.Description,
  733. Price: bid.CalcParamDecode.BaseMoney,
  734. Count: 1,
  735. Total: bid.CalcParamDecode.BaseMoney,
  736. Unit: item.GetUnitMap()[bid.Unit],
  737. })
  738. if calcSetting.RoomNum > bid.CalcParamDecode.RoomNum && bid.CalcParamDecode.AddRoomMoney != 0 {
  739. num := utils.ToFloat64(calcSetting.RoomNum - bid.CalcParamDecode.RoomNum)
  740. money := utils.FloatMul(bid.CalcParamDecode.AddRoomMoney, num, -1)
  741. list = append(list, List{
  742. ID: bid.ID,
  743. Category: bid.Category,
  744. RoomType: room.RoomType,
  745. RoomName: room.RoomName,
  746. BidName: bid.BidName + " 增加房间",
  747. Description: bid.Description,
  748. Price: bid.CalcParamDecode.AddRoomMoney,
  749. Count: num,
  750. Total: money,
  751. Unit: item.GetUnitMap()[bid.Unit],
  752. })
  753. }
  754. if calcSetting.ToiletNum > bid.CalcParamDecode.ToiletNum && bid.CalcParamDecode.AddToiletMoney != 0 {
  755. num := utils.ToFloat64(calcSetting.ToiletNum - bid.CalcParamDecode.ToiletNum)
  756. money := utils.FloatMul(bid.CalcParamDecode.AddToiletMoney, num, -1)
  757. list = append(list, List{
  758. ID: bid.ID,
  759. Category: bid.Category,
  760. RoomType: room.RoomType,
  761. RoomName: room.RoomName,
  762. BidName: bid.BidName + " 增加卫生间",
  763. Description: bid.Description,
  764. Price: bid.CalcParamDecode.AddToiletMoney,
  765. Count: num,
  766. Total: money,
  767. Unit: item.GetUnitMap()[bid.Unit],
  768. })
  769. }
  770. if calcSetting.KitchenNum > bid.CalcParamDecode.KitchenNum && bid.CalcParamDecode.AddKitchenMoney != 0 {
  771. num := utils.ToFloat64(calcSetting.KitchenNum - bid.CalcParamDecode.KitchenNum)
  772. money := utils.FloatMul(bid.CalcParamDecode.AddKitchenMoney, num, -1)
  773. list = append(list, List{
  774. ID: bid.ID,
  775. Category: bid.Category,
  776. RoomType: room.RoomType,
  777. RoomName: room.RoomName,
  778. BidName: bid.BidName + " 增加厨房",
  779. Description: bid.Description,
  780. Price: bid.CalcParamDecode.AddToiletMoney,
  781. Count: num,
  782. Total: money,
  783. Unit: item.GetUnitMap()[bid.Unit],
  784. })
  785. }
  786. if calcSetting.RestaurantNum > bid.CalcParamDecode.RestaurantNum && bid.CalcParamDecode.AddRestaurantMoney != 0 {
  787. num := utils.ToFloat64(calcSetting.RestaurantNum - bid.CalcParamDecode.RestaurantNum)
  788. money := utils.FloatMul(bid.CalcParamDecode.AddRestaurantMoney, num, -1)
  789. list = append(list, List{
  790. ID: bid.ID,
  791. Category: bid.Category,
  792. RoomType: room.RoomType,
  793. RoomName: room.RoomName,
  794. BidName: bid.BidName + " 增加客餐厅",
  795. Description: bid.Description,
  796. Price: bid.CalcParamDecode.AddToiletMoney,
  797. Count: num,
  798. Total: money,
  799. Unit: item.GetUnitMap()[bid.Unit],
  800. })
  801. }
  802. } else {
  803. list = append(list, List{
  804. ID: bid.ID,
  805. Category: bid.Category,
  806. RoomType: room.RoomType,
  807. RoomName: room.RoomName,
  808. BidName: bid.BidName,
  809. Description: bid.Description,
  810. Price: bid.Price,
  811. Count: utils.FloatDiv(i.Price, bid.Price, 4),
  812. Total: i.Price,
  813. Unit: item.GetUnitMap()[bid.Unit],
  814. })
  815. }
  816. }
  817. }
  818. }
  819. app.Success(c, gin.H{
  820. "orderInfo": orderInfo,
  821. "bidList": list,
  822. })
  823. }