package bid import ( "net/http" "strconv" "strings" "time" "zhiyuan/models" "zhiyuan/pkg/app" "zhiyuan/pkg/config" "zhiyuan/pkg/errcode" adminParam "zhiyuan/pkg/param/admin" "zhiyuan/pkg/param/material" bidParam "zhiyuan/pkg/param/material/bid" "zhiyuan/pkg/param/material/item" "zhiyuan/pkg/utils" "zhiyuan/services/admin" "zhiyuan/services/dept" "zhiyuan/services/form" "zhiyuan/services/material/bid" "zhiyuan/services/material/pkg" "zhiyuan/services/structs" "github.com/gin-gonic/gin" "github.com/tealeg/xlsx/v3" ) func OrderList(c *gin.Context) { page := app.HandlePageNum(c) pkgID := utils.StrTo(c.Query("pkg_id")).MustInt() if pkgID <= 0 { app.Error(c, "套餐id有误") return } pkgInfo, _ := pkg.GetPkg(map[string]interface{}{"id": pkgID}, []string{"id", "room_types", "pkg_name"}, nil) where := map[string]string{ "where": "`zy_mat_bid_order`.`deleted_at`=0", "_order_by": "`zy_mat_bid_order`.`id` desc", } if page.PageSize != 0 { where["_page_size"] = utils.ToStr(page.PageSize) where["_page_num"] = utils.ToStr(page.PageNum) } param := make(map[string]interface{}) where["where"] = where["where"] + " AND `zy_mat_bid_order`.`pkg_id` = {{pkg_id}}" param["pkg_id"] = pkgID if keyword := c.Query("keyword"); keyword != "" { where["where"] = where["where"] + " AND (`zy_mat_bid_order`.`customer_name` LIKE {{keyword}} OR `zy_mat_bid_order`.`customer_phone` LIKE {{keyword}})" param["keyword"] = "%" + keyword + "%" } if adminId := utils.ToInt(c.Query("admin_id")); adminId > 0 { where["where"] = where["where"] + " AND `zy_mat_bid_order`.`admin_id` = {{admin_id}}" param["admin_id"] = adminId } if areaMin := utils.ToFloat64(c.Query("area_min")); areaMin > 0 { where["where"] = where["where"] + " AND `zy_mat_bid_order`.`house_area` >= {{area_min}}" param["area_min"] = areaMin } if areaMax := utils.ToFloat64(c.Query("area_max")); areaMax > 0 { where["where"] = where["where"] + " AND `zy_mat_bid_order`.`house_area` <= {{area_max}}" param["area_max"] = areaMax } if moneyMin := utils.ToFloat64(c.Query("money_min")); moneyMin > 0 { where["where"] = where["where"] + " AND `zy_mat_bid_order`.`total_price` >= {{money_min}}" param["money_min"] = moneyMin } if moneyMax := utils.ToFloat64(c.Query("money_max")); moneyMax > 0 { where["where"] = where["where"] + " AND `zy_mat_bid_order`.`total_price` <= {{money_max}}" param["money_max"] = moneyMax } if address := c.Query("address"); address != "" { where["where"] = where["where"] + " AND `zy_mat_bid_order`.`house_address` = {{address}}" param["address"] = "%" + address + "%" } if !admin.IsSuperAdmin(c.GetInt("adminID")) { var adminInfo *models.Admin admin.GetInfoByID(c.GetInt("adminID"), nil, &adminInfo) if adminInfo == nil { app.Response(c, http.StatusUnauthorized, errcode.TokenInvalid, nil) return } adminRole := false roleSlice := strings.Split(adminInfo.RoleIds, ",") for _, v := range roleSlice { if role, err := strconv.Atoi(v); err == nil && (role == adminParam.AdminRoleId || role == adminParam.MaterialAdminRoleId) { adminRole = true break } } if !adminRole { where["where"] = where["where"] + " AND `zy_admin`.`dept_id` IN {{dept_id}}" param["dept_id"] = dept.GetSubDeptIds(adminInfo.DeptID, []int{adminInfo.DeptID}) } } total, err := bid.CountRaw(where["where"], param) if err != nil { app.Error(c, err.Error()) return } orderList := make([]structs.MaterialBidOrderList, 0) if err := bid.GetOrdersRaw(where, param, &orderList); err != nil { app.Error(c, err.Error()) return } roomTypeMap := material.GetRoomTypeMap(true) orderStateMap := bidParam.GetOrderStateMap() for k, v := range orderList { v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD HH:mm") v.UpdatedAt = utils.DateS(v.UpdatedAt, "YYYY-MM-DD HH:mm") v.StateName = orderStateMap[v.State].Name v.StateColor = orderStateMap[v.State].Color styleName := make([]string, 0) var houseStyle []structs.HouseStyle utils.JsonDecode(v.HouseStyle).To(&houseStyle) for _, house := range houseStyle { styleName = append(styleName, utils.ToStr(house.Num)+roomTypeMap[house.Type]) } v.HouseStyle = strings.Join(styleName, "") v.Auth = structs.MaterialBidOrderAuth{ Finish: utils.IsContain(bidParam.OrderAllow.Finish, v.State), } orderList[k] = v } data := gin.H{ "pkgInfo": pkgInfo, "list": orderList, "total": total, "limit": page.PageSize, } app.Success(c, data) } func OrderListExport(c *gin.Context) { pkgID := utils.StrTo(c.Query("pkg_id")).MustInt() if pkgID <= 0 { app.Error(c, "套餐id有误") return } where := map[string]interface{}{"pkg_id": pkgID, "_orderby": "id desc"} orderList := make([]structs.MaterialBidOrderList, 0) if _, err := bid.GetOrders(where, nil, app.Page{}, &orderList); err != nil { app.Error(c, err.Error()) return } adminIds := make([]int, 0) for _, v := range orderList { adminIds = append(adminIds, v.AdminID) } adminListMap := make(map[int]string, 0) if len(adminIds) > 0 { if adminList, err := admin.GetAdmins(map[string]interface{}{"id in": adminIds}, nil, app.Page{}, nil); err == nil { for _, v := range adminList { adminListMap[v.ID] = v.Username } } } wb := xlsx.NewFile() time := utils.ToStr(time.Now().UnixNano()) filename := "預算表导出-" + time + ".xlsx" fullPath := config.Cfg.App.ExportPath + filename styleBold := utils.GetCommonStyle(utils.StyleCfg{IsBold: true}) styleCommon := utils.GetCommonStyle(utils.StyleCfg{}) sh, err := wb.AddSheet("Sheet1") if err != nil { app.Error(c, err.Error()) return } sh = utils.SetColWidth(sh, []float64{10, 30, 10, 10, 10, 10}) var row *xlsx.Row row = utils.AddRow(sh, utils.Row{Height: 60}) utils.AddCell(row, utils.Cell{Value: "客户名", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "楼盘", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "设计师", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "套餐内总价", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "个性化总报价", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "设计费", Style: styleBold}) for _, v := range orderList { v.AdminName = adminListMap[v.AdminID] v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD HH:mm") v.UpdatedAt = utils.DateS(v.UpdatedAt, "YYYY-MM-DD HH:mm") utils.JsonDecode(v.CustomizePriceDetail).To(&v.CustomizePriceDecode) row = utils.AddRow(sh, utils.Row{Height: 30}) utils.AddCell(row, utils.Cell{Value: v.CustomerName, Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: v.HouseAddress, Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: v.AdminName, Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: v.PackagePrice, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: v.CustomizePrice, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: v.CustomizePriceDecode.Design, Format: "float", Style: styleCommon}) } if err := wb.Save(fullPath); err != nil { app.Error(c, err.Error()) return } app.Success(c, gin.H{"path": "export/" + filename, "filename": filename}) } func OrderInfo(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.Error(c, "工单 id 为空") } var orderInfo structs.MaterialBidOrderList if _, err := bid.GetOrder(map[string]interface{}{"id": id}, nil, &orderInfo); err != nil { app.Error(c, err.Error()) } roomTypeMap := material.GetRoomTypeMap(true) var houseStyle []structs.HouseStyle utils.JsonDecode(orderInfo.HouseStyle).To(&houseStyle) styleName := make([]string, 0) for _, house := range houseStyle { styleName = append(styleName, utils.ToStr(house.Num)+roomTypeMap[house.Type]) } orderInfo.HouseStyle = strings.Join(styleName, "") utils.JsonDecode(orderInfo.Param).To(&orderInfo.ParamDecode) utils.JsonDecode(orderInfo.Customize).To(&orderInfo.CustomizeDecode) utils.JsonDecode(orderInfo.CustomizePriceDetail).To(&orderInfo.CustomizePriceDecode) utils.JsonDecode(orderInfo.PackagePriceDetail).To(&orderInfo.PackagePriceDecode) utils.JsonDecode(orderInfo.InclusivePriceDetail).To(&orderInfo.InclusivePriceDecode) utils.JsonDecode(orderInfo.InclusiveCostDetail).To(&orderInfo.InclusiveCostDecode) utils.JsonDecode(orderInfo.PackagePriceDetail).To(&orderInfo.OutlinePriceDecode) utils.JsonDecode(orderInfo.ToiletPriceDetail).To(&orderInfo.ToiletPriceDecode) bidMap := make(map[int]*structs.MaterialBidList) bidList := make([]*structs.MaterialBidList, 0) if _, err := bid.GetBidList(map[string]interface{}{"pkg_id": orderInfo.PkgID}, nil, app.Page{}, &bidList); err == nil { for _, v := range bidList { bidMap[v.ID] = v } } app.Success(c, gin.H{ "orderInfo": orderInfo, "bidList": bidMap, }) } func OrderExport(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.Error(c, "工单 id 为空") return } var orderInfo structs.MaterialBidOrderList if _, err := bid.GetOrder(map[string]interface{}{"id": id}, nil, &orderInfo); err != nil { app.Error(c, err.Error()) return } roomTypeMap := material.GetRoomTypeMap(true) var houseStyle []structs.HouseStyle utils.JsonDecode(orderInfo.HouseStyle).To(&houseStyle) styleName := make([]string, 0) for _, house := range houseStyle { styleName = append(styleName, utils.ToStr(house.Num)+roomTypeMap[house.Type]) } orderInfo.HouseStyle = strings.Join(styleName, "") utils.JsonDecode(orderInfo.Param).To(&orderInfo.ParamDecode) utils.JsonDecode(orderInfo.Customize).To(&orderInfo.CustomizeDecode) utils.JsonDecode(orderInfo.CustomizePriceDetail).To(&orderInfo.CustomizePriceDecode) utils.JsonDecode(orderInfo.PackagePriceDetail).To(&orderInfo.PackagePriceDecode) utils.JsonDecode(orderInfo.InclusivePriceDetail).To(&orderInfo.InclusivePriceDecode) bidMap := make(map[int]*structs.MaterialBidList) bidList := make([]*structs.MaterialBidList, 0) if _, err := bid.GetBidList(map[string]interface{}{"pkg_id": orderInfo.PkgID}, nil, app.Page{}, &bidList); err == nil { for _, v := range bidList { bidMap[v.ID] = v } } if adminInfo, err := admin.GetInfoByID(orderInfo.AdminID, nil, nil); err == nil { orderInfo.AdminName = adminInfo.Username } wb := xlsx.NewFile() time := utils.ToStr(time.Now().UnixNano()) filename := "2021年[志远一户一价产品]工程预算书-" + orderInfo.HouseAddress + "-" + time + ".xlsx" fullPath := config.Cfg.App.ExportPath + filename styleBold := utils.GetCommonStyle(utils.StyleCfg{IsBold: true}) styleCommon := utils.GetCommonStyle(utils.StyleCfg{}) styleHeader := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, FontSize: 17, IsBorderRight: true}) styleHeaderFill := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, IsBorderRight: true, Fill: []string{"00D9D9D9", "FF000000"}}) styleFillLeft := utils.GetCommonStyle(utils.StyleCfg{IsBorderRight: true, Fill: []string{"00D9D9D9", "FF000000"}, Horizontal: "general"}) styleFillBorderRight := utils.GetCommonStyle(utils.StyleCfg{IsBorderRight: true, Fill: []string{"00D9D9D9", "FF000000"}}) styleFill := utils.GetCommonStyle(utils.StyleCfg{Fill: []string{"00D9D9D9", "FF000000"}}) styleBlackBorderRight := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, IsBorderRight: true, Fill: []string{"00808080", "FF000000"}, Horizontal: "general"}) styleBlack := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, Fill: []string{"00808080", "FF000000"}}) styleBoldBorderRight := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, IsBorderRight: true}) styleBorderRight := utils.GetCommonStyle(utils.StyleCfg{IsBorderRight: true}) styleBoldLeftBorderRight := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, IsBorderRight: true, Horizontal: "general"}) styleBoldBorderBottom := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, IsBorderBottom: true}) styleBoldBorderBottomRight := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, IsBorderBottom: true, IsBorderRight: true}) sh, err := wb.AddSheet("Sheet1") if err != nil { app.Error(c, err.Error()) return } sh = utils.SetColWidth(sh, []float64{10, 5, 20, 5, 10, 15, 15, 80}) var row *xlsx.Row row = utils.AddRow(sh, utils.Row{Height: 60}) utils.AddCell(row, utils.Cell{Value: "2021年[志远一户一价产品]工程预算书", HMerge: 7, Style: styleHeader}) row = utils.AddRow(sh, utils.Row{Height: 30}) utils.AddCell(row, utils.Cell{Value: "工程预(决)算书 日期: 年 月 日", HMerge: 7, Style: styleHeaderFill}) row = utils.AddRow(sh, utils.Row{Height: 30}) utils.AddCell(row, utils.Cell{Value: "客 户:" + orderInfo.CustomerName + " 联系电话:" + orderInfo.CustomerName + " 工程地址:" + orderInfo.HouseAddress, HMerge: 7, Style: styleFillLeft}) row = utils.AddRow(sh, utils.Row{Height: 30}) utils.AddCell(row, utils.Cell{Value: "房 型:" + orderInfo.HouseStyle + " [套内实测面积M2]:" + utils.ToStr(orderInfo.HouseArea) + " 设计师:" + orderInfo.AdminName, HMerge: 7, Style: styleFillLeft}) row = utils.AddRow(sh, utils.Row{Height: 30}) utils.AddCell(row, utils.Cell{Value: "客 户 温 馨 提 示", HMerge: 7, Style: styleFillBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "一", HMerge: 1, Style: styleFill}) utils.AddCell(row, utils.Cell{Value: "施工中如有漏项、增减项目,应将漏项及增减项目列入结算款中,以实际发生工程量和预算单上工程单价为准,并以现场签证单上双方签字认可为依据进行结算。如预算中所指定材料出现市场供应短缺,则可双方协调调换为同等价位材料;", HMerge: 5, Style: styleFillBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "二", HMerge: 1, Style: styleFill}) utils.AddCell(row, utils.Cell{Value: "客户装修房屋的任何构件(非我方施工主体物件)如可能影响我方施工,无论是拆卸、改造或是用其他办法处理,甲方需承担费用;", HMerge: 5, Style: styleFillBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "三", HMerge: 1, Style: styleFill}) utils.AddCell(row, utils.Cell{Value: "此预算不含物业管理处各项收费。如垃圾外运费、公共设施维护费、办理装修许可证费用等,由甲方自行负责。我公司只交纳办理工人出入证费用;", HMerge: 5, Style: styleFillBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "四", HMerge: 1, Style: styleFill}) utils.AddCell(row, utils.Cell{Value: "不含预算单和图纸标明甲方自购的材料;", HMerge: 5, Style: styleFillBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "五", HMerge: 1, Style: styleFill}) utils.AddCell(row, utils.Cell{Value: "公司严格按照国家安全施工规范进行施工,不承接混凝土墙、水泥现浇梁柱等拆除业务;", HMerge: 5, Style: styleFillBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "工种", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "编号", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "项目名称", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "单位", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "数量", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "单价(元)", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "总价(元)", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "材 料 及 工 艺 说 明", Style: styleBoldBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "一", HMerge: 1, Style: styleBlack}) utils.AddCell(row, utils.Cell{Value: "一户一价产品内容", HMerge: 5, Style: styleBlackBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "1", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "一户一价工程总价", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: utils.FloatAdd(orderInfo.PackagePrice, orderInfo.InclusivePrice, 0), Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "详见《2021年一户一价产品说明表》及报价系统详细说明。", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "二", HMerge: 1, Style: styleBlack}) utils.AddCell(row, utils.Cell{Value: "主材增加项", HMerge: 5, Style: styleBlackBorderRight}) for k, v := range orderInfo.CustomizeDecode[4] { if bidMap[v.ID] == nil { bidMap[v.ID] = new(structs.MaterialBidList) } row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: v.RoomTypeName, Style: styleBold}) utils.AddCell(row, utils.Cell{Value: utils.ToStr(k + 1), Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: v.BidName, Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: v.UnitName, Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: v.Num, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: bidMap[v.ID].Price, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: v.Total, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: bidMap[v.ID].Description, Style: styleBorderRight}) } row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "三", HMerge: 1, Style: styleBlack}) utils.AddCell(row, utils.Cell{Value: "主材升级项", HMerge: 5, Style: styleBlackBorderRight}) for k, v := range orderInfo.CustomizeDecode[6] { if bidMap[v.ID] == nil { bidMap[v.ID] = new(structs.MaterialBidList) } row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: v.RoomTypeName, Style: styleBold}) utils.AddCell(row, utils.Cell{Value: utils.ToStr(k + 1), Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: v.BidName, Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: v.UnitName, Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: v.Num, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: bidMap[v.ID].Price, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: v.Total, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: bidMap[v.ID].Description, Style: styleBorderRight}) } row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "四", HMerge: 1, Style: styleBlack}) utils.AddCell(row, utils.Cell{Value: "主材减项", HMerge: 5, Style: styleBlackBorderRight}) for k, v := range orderInfo.CustomizeDecode[5] { if bidMap[v.ID] == nil { bidMap[v.ID] = new(structs.MaterialBidList) } row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: v.RoomTypeName, Style: styleBold}) utils.AddCell(row, utils.Cell{Value: utils.ToStr(k + 1), Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: v.BidName, Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: v.UnitName, Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: v.Num, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: bidMap[v.ID].Price, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: v.Total, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: bidMap[v.ID].Description, Style: styleBorderRight}) } row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "五", HMerge: 1, Style: styleBlack}) utils.AddCell(row, utils.Cell{Value: "施工增加项", HMerge: 5, Style: styleBlackBorderRight}) for k, v := range orderInfo.CustomizeDecode[3] { if bidMap[v.ID] == nil { bidMap[v.ID] = new(structs.MaterialBidList) } row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: v.RoomTypeName, Style: styleBold}) utils.AddCell(row, utils.Cell{Value: utils.ToStr(k + 1), Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: v.BidName, Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: v.UnitName, Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: v.Num, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: bidMap[v.ID].Price, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: v.Total, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: bidMap[v.ID].Description, Style: styleBorderRight}) } row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "其 它", Style: styleBold, VMerge: 13}) utils.AddCell(row, utils.Cell{Value: "A", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "个性化施工直接费", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.BuildPrice.Direct, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "B", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "个性化主材增项", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.MaterialAdd, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "C", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "个性化主材升级", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.MaterialUpgrade, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "D", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "材料搬运费D=(A+B+C)*" + utils.ToStr(orderInfo.TransportRate*100) + "%\n(如实际核算基数发生变化,计费公式必须同步)", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.Transport, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "有电梯按工程直接费2.5%计算;无电梯二楼按2.5%计算,二楼以上以2.5%为基数每上一楼增加0.5%。(复式楼、别墅户内按无电梯计算)", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "E", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "垃圾清运费E=(A+B+C)*" + utils.ToStr(orderInfo.TransportRate*100) + "%\n(如实际核算基数发生变化,计费公式必须同步)", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.Sanitation, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "有电梯按工程直接费2.5%(注:我方将施工过程中每天产生的装修垃圾清理到小区指定堆放点,与管理处收取的垃圾清运费无关)计算;无电梯二楼按2.5%计算,二楼以上以2.5%为基数,每上一楼增加0.5%。(复式楼、别墅户内按无电梯计算)", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "F", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "工程管理费F=(A+B+C+D+E)*10%", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.Manage, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "G", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "设计费", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.Design, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "H", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "个性化工程总价H=(A+B+C+D+E+F+G)", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: orderInfo.CustomizePriceDecode.Total, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "I", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "定制品赠送", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: strconv.Itoa(orderInfo.InclusiveArea), Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: 0, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "J", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "工程总造价I=一户一价工程总价+个性化工程总价+定制品总价", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: orderInfo.TotalPrice, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "K", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "稅金K=J*6%", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: 0, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "L", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "工程总造价L=J+K", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon}) utils.AddCell(row, utils.Cell{Float: orderInfo.TotalPrice, Format: "float", Style: styleCommon}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "制表: 审核: ", HMerge: 6, Style: styleBoldLeftBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBold}) utils.AddCell(row, utils.Cell{Value: "甲方签字: 乙方签字: ", HMerge: 6, Style: styleBoldLeftBorderRight}) row = utils.AddRow(sh, utils.Row{Height: 45}) utils.AddCell(row, utils.Cell{Value: "", Style: styleBoldBorderBottom}) utils.AddCell(row, utils.Cell{Value: " 年 月 日 年 月 日 ", HMerge: 6, Style: styleBoldBorderBottomRight}) if err := wb.Save(fullPath); err != nil { app.Error(c, err.Error()) return } app.Success(c, gin.H{"path": "export/" + filename, "filename": filename}) } func OrderUpdate(c *gin.Context) { id := utils.StrTo(c.Param("id")).MustInt() if id <= 0 { app.ErrorMsg(c, "无效的订单ID", nil) return } if _, err := bid.UpdateOrder(id); err != nil { app.Error(c, err.Error()) return } app.Success(c, nil) } func OrderRemark(c *gin.Context) { id := utils.StrTo(c.Param("id")).MustInt() if id <= 0 { app.ErrorMsg(c, "无效的订单ID", nil) return } var form form.OrderRemark if app.Bind(c, &form) != nil { return } if err := bid.RemarkOrder(form, id); err != nil { app.Error(c, err.Error()) return } app.Success(c, nil) } func OrderFinish(c *gin.Context) { id := utils.StrTo(c.Param("id")).MustInt() if id <= 0 { app.Error(c, "工单 id 有误") return } err := bid.FinishOrder(id) if err != nil { app.Error(c, err.Error()) return } app.Success(c, nil) } func OrderListApi(c *gin.Context) { //page := app.HandlePageNum(c) pkgID := utils.StrTo(c.Query("pkg_id")).MustInt() if pkgID <= 0 { app.Error(c, "套餐id有误") return } //pkgInfo, _ := pkg.GetPkg(map[string]interface{}{"id": pkgID}, []string{"id", "room_types", "pkg_name"}, nil) where := map[string]string{ "where": "`zy_mat_bid_order`.`deleted_at`=0 AND `zy_mat_bid_order`.`type`=0", "_order_by": "`zy_mat_bid_order`.`id` desc", } /*if page.PageSize != 0 { where["_page_size"] = utils.ToStr(page.PageSize) where["_page_num"] = utils.ToStr(page.PageNum) }*/ param := make(map[string]interface{}) where["where"] = where["where"] + " AND `zy_mat_bid_order`.`pkg_id` = {{pkg_id}}" param["pkg_id"] = pkgID if keyword := c.Query("keyword"); keyword != "" { 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}})" param["keyword"] = "%" + keyword + "%" } if phone := c.Query("phone"); phone != "" { where["where"] = where["where"] + " AND `zy_admin`.`phone` = {{phone}}" param["phone"] = phone } else { where["where"] = where["where"] + " AND 1=2" } /*if adminId := utils.ToInt(c.Query("admin_id")); adminId > 0 { where["where"] = where["where"] + " AND `zy_mat_bid_order`.`admin_id` = {{admin_id}}" param["admin_id"] = adminId } if areaMin := utils.ToFloat64(c.Query("area_min")); areaMin > 0 { where["where"] = where["where"] + " AND `zy_mat_bid_order`.`house_area` >= {{area_min}}" param["area_min"] = areaMin } if areaMax := utils.ToFloat64(c.Query("area_max")); areaMax > 0 { where["where"] = where["where"] + " AND `zy_mat_bid_order`.`house_area` <= {{area_max}}" param["area_max"] = areaMax } if moneyMin := utils.ToFloat64(c.Query("money_min")); moneyMin > 0 { where["where"] = where["where"] + " AND `zy_mat_bid_order`.`total_price` >= {{money_min}}" param["money_min"] = moneyMin } if moneyMax := utils.ToFloat64(c.Query("money_max")); moneyMax > 0 { where["where"] = where["where"] + " AND `zy_mat_bid_order`.`total_price` <= {{money_max}}" param["money_max"] = moneyMax } if address := c.Query("address"); address != "" { where["where"] = where["where"] + " AND `zy_mat_bid_order`.`house_address` = {{address}}" param["address"] = "%" + address + "%" }*/ /*if !admin.IsSuperAdmin(c.GetInt("adminID")) { var adminInfo *models.Admin admin.GetInfoByID(c.GetInt("adminID"), nil, &adminInfo) if adminInfo == nil { app.Response(c, http.StatusUnauthorized, errcode.TokenInvalid, nil) return } adminRole := false roleSlice := strings.Split(adminInfo.RoleIds, ",") for _, v := range roleSlice { if role, err := strconv.Atoi(v); err == nil && (role == adminParam.AdminRoleId || role == adminParam.MaterialAdminRoleId) { adminRole = true break } } if !adminRole { where["where"] = where["where"] + " AND `zy_admin`.`dept_id` IN {{dept_id}}" param["dept_id"] = dept.GetSubDeptIds(adminInfo.DeptID, []int{adminInfo.DeptID}) } }*/ total, err := bid.CountRaw(where["where"], param) if err != nil { app.Error(c, err.Error()) return } orderList := make([]structs.MaterialBidOrderList, 0) if err := bid.GetOrdersRaw(where, param, &orderList); err != nil { app.Error(c, err.Error()) return } roomTypeMap := material.GetRoomTypeMap(true) orderStateMap := bidParam.GetOrderStateMap() for k, v := range orderList { v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD HH:mm") v.UpdatedAt = utils.DateS(v.UpdatedAt, "YYYY-MM-DD HH:mm") v.StateName = orderStateMap[v.State].Name v.StateColor = orderStateMap[v.State].Color styleName := make([]string, 0) var houseStyle []structs.HouseStyle utils.JsonDecode(v.HouseStyle).To(&houseStyle) for _, house := range houseStyle { styleName = append(styleName, utils.ToStr(house.Num)+roomTypeMap[house.Type]) } v.HouseStyle = strings.Join(styleName, "") v.Auth = structs.MaterialBidOrderAuth{ Finish: utils.IsContain(bidParam.OrderAllow.Finish, v.State), } orderList[k] = v } data := gin.H{ //"pkgInfo": pkgInfo, "list": orderList, "total": total, //"limit": page.PageSize, } app.Success(c, data) } func OrderInfoApi(c *gin.Context) { id := utils.StrTo(c.Query("id")).MustInt() if id <= 0 { app.Error(c, "工单 id 为空") } var orderInfo structs.MaterialBidOrderList if _, err := bid.GetOrder(map[string]interface{}{"id": id}, nil, &orderInfo); err != nil { app.Error(c, err.Error()) } roomTypeMap := material.GetRoomTypeMap(true) var houseStyle []structs.HouseStyle utils.JsonDecode(orderInfo.HouseStyle).To(&houseStyle) styleName := make([]string, 0) for _, house := range houseStyle { styleName = append(styleName, utils.ToStr(house.Num)+roomTypeMap[house.Type]) } orderInfo.HouseStyle = strings.Join(styleName, "") utils.JsonDecode(orderInfo.Param).To(&orderInfo.ParamDecode) utils.JsonDecode(orderInfo.Customize).To(&orderInfo.CustomizeDecode) utils.JsonDecode(orderInfo.CustomizePriceDetail).To(&orderInfo.CustomizePriceDecode) utils.JsonDecode(orderInfo.PackagePriceDetail).To(&orderInfo.PackagePriceDecode) utils.JsonDecode(orderInfo.InclusivePriceDetail).To(&orderInfo.InclusivePriceDecode) utils.JsonDecode(orderInfo.InclusiveCostDetail).To(&orderInfo.InclusiveCostDecode) utils.JsonDecode(orderInfo.PackagePriceDetail).To(&orderInfo.OutlinePriceDecode) bidMap := make(map[int]*structs.MaterialBidList) bidList := make([]*structs.MaterialBidList, 0) if _, err := bid.GetBidList(map[string]interface{}{"pkg_id": orderInfo.PkgID}, nil, app.Page{}, &bidList); err == nil { for _, v := range bidList { bidMap[v.ID] = v } } type List struct { ID int `json:"id"` Category int `json:"category"` RoomType int `json:"room_type" label:"房屋类型"` RoomName string `json:"room_name" label:"房屋"` BidName string `json:"bid_name"` Description string `json:"description"` Price float64 `json:"price"` Count float64 `json:"count"` Total float64 `json:"total"` Unit string `json:"unit"` } calcSetting := bid.GetCalcSetting(houseStyle) list := make([]List, 0) for _, room := range orderInfo.ParamDecode { for _, i := range room.Items { if bid, ok := bidMap[i.ID]; ok && bid.Category <= 2 { if bid.CalcType == 7 { utils.JsonDecode(bid.CalcParam).To(&bid.CalcParamDecode) list = append(list, List{ ID: bid.ID, Category: bid.Category, RoomType: room.RoomType, RoomName: room.RoomName, BidName: bid.BidName, Description: bid.Description, Price: bid.CalcParamDecode.BaseMoney, Count: 1, Total: bid.CalcParamDecode.BaseMoney, Unit: item.GetUnitMap()[bid.Unit], }) if calcSetting.RoomNum > bid.CalcParamDecode.RoomNum && bid.CalcParamDecode.AddRoomMoney != 0 { num := utils.ToFloat64(calcSetting.RoomNum - bid.CalcParamDecode.RoomNum) money := utils.FloatMul(bid.CalcParamDecode.AddRoomMoney, num, -1) list = append(list, List{ ID: bid.ID, Category: bid.Category, RoomType: room.RoomType, RoomName: room.RoomName, BidName: bid.BidName + " 增加房间", Description: bid.Description, Price: bid.CalcParamDecode.AddRoomMoney, Count: num, Total: money, Unit: item.GetUnitMap()[bid.Unit], }) } if calcSetting.ToiletNum > bid.CalcParamDecode.ToiletNum && bid.CalcParamDecode.AddToiletMoney != 0 { num := utils.ToFloat64(calcSetting.ToiletNum - bid.CalcParamDecode.ToiletNum) money := utils.FloatMul(bid.CalcParamDecode.AddToiletMoney, num, -1) list = append(list, List{ ID: bid.ID, Category: bid.Category, RoomType: room.RoomType, RoomName: room.RoomName, BidName: bid.BidName + " 增加卫生间", Description: bid.Description, Price: bid.CalcParamDecode.AddToiletMoney, Count: num, Total: money, Unit: item.GetUnitMap()[bid.Unit], }) } if calcSetting.KitchenNum > bid.CalcParamDecode.KitchenNum && bid.CalcParamDecode.AddKitchenMoney != 0 { num := utils.ToFloat64(calcSetting.KitchenNum - bid.CalcParamDecode.KitchenNum) money := utils.FloatMul(bid.CalcParamDecode.AddKitchenMoney, num, -1) list = append(list, List{ ID: bid.ID, Category: bid.Category, RoomType: room.RoomType, RoomName: room.RoomName, BidName: bid.BidName + " 增加厨房", Description: bid.Description, Price: bid.CalcParamDecode.AddToiletMoney, Count: num, Total: money, Unit: item.GetUnitMap()[bid.Unit], }) } if calcSetting.RestaurantNum > bid.CalcParamDecode.RestaurantNum && bid.CalcParamDecode.AddRestaurantMoney != 0 { num := utils.ToFloat64(calcSetting.RestaurantNum - bid.CalcParamDecode.RestaurantNum) money := utils.FloatMul(bid.CalcParamDecode.AddRestaurantMoney, num, -1) list = append(list, List{ ID: bid.ID, Category: bid.Category, RoomType: room.RoomType, RoomName: room.RoomName, BidName: bid.BidName + " 增加客餐厅", Description: bid.Description, Price: bid.CalcParamDecode.AddToiletMoney, Count: num, Total: money, Unit: item.GetUnitMap()[bid.Unit], }) } } else { list = append(list, List{ ID: bid.ID, Category: bid.Category, RoomType: room.RoomType, RoomName: room.RoomName, BidName: bid.BidName, Description: bid.Description, Price: bid.Price, Count: utils.FloatDiv(i.Price, bid.Price, 4), Total: i.Price, Unit: item.GetUnitMap()[bid.Unit], }) } } } } app.Success(c, gin.H{ "orderInfo": orderInfo, "bidList": list, }) }