package admin import ( "fmt" "os" "os/exec" "path" "path/filepath" "strings" "zhiyuan/models/budget" "zhiyuan/models/budget2" "zhiyuan/models/final" "zhiyuan/pkg/app" "zhiyuan/pkg/config" "zhiyuan/pkg/db" "zhiyuan/pkg/logger" "zhiyuan/pkg/utils" budgetService "zhiyuan/services/budget" "github.com/gin-gonic/gin" ) func QuoteInfo(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } quote, _, _, _, _, _, _ := budget.GetQuoteModel(int64(id)) if quote == nil { app.ErrorMsg(c, "报价不存在", nil) return } //order, err := budgetService.CreateOrder(quote.ID) //if err != nil { // app.ErrorMsg(c, "创建失败", nil) // return //} //context := budgetService.NewContext(order, c) //err = context.Eval() //logger.Sugar.Infof("err: %v", err) app.Success(c, gin.H{ "quote": quote, //"result": order.ToMap(false), }) } func QuoteOrderInfo(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } order, err := budgetService.LoadOrder(model) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } context := budgetService.NewContext(order, c) err = context.Eval() logger.Sugar.Infof("err: %v", err) if model.State == 0 { err = order.Save(context) logger.Sugar.Infof("err: %v", err) } model.Content = make([]byte, 0) app.Success(c, gin.H{ "name": order.Models[budgetService.Quote][order.Form.ID].GetName(), "order": model, "result": order.ToMap(false), }) } type QuoteOrderCopyFrom struct { Name string `form:"name" json:"name"` } func QuoteOrderCopy(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var form QuoteOrderCopyFrom if app.Bind(c, &form) != nil { return } var model budget.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } db.InsertModel(db.Type(budget.Order{}), map[string]interface{}{ "name": form.Name, "quoteId": model.QuoteId, "adminId": c.GetInt("adminID"), "customerId": model.CustomerId, "content": model.Content, "layout": model.Layout, "area": model.Area, }) app.Success(c, nil) } /*func QuoteOrderExport(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } order, err := budgetService.LoadOrder(model) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } context := budgetService.NewContext(order, c) err = context.Eval() logger.Sugar.Infof("err: %v", err) err = order.Save(context) logger.Sugar.Infof("err: %v", err) exportFileName := order.GetForm(false, false).Export() if exportFileName == "" { app.ErrorMsg(c, "导出失败", nil) return } app.Success(c, gin.H{"path": "export/" + exportFileName, "filename": exportFileName}) }*/ type QuoteOrderHandleFrom struct { Key uint64 `form:"key" json:"key" binding:"required"` Type string `form:"type" json:"type"` Value interface{} `form:"value" json:"value"` } func QuoteOrderHandle(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var form QuoteOrderHandleFrom if app.Bind(c, &form) != nil { return } var model budget.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State != 0 { app.ErrorMsg(c, "不能修改报价", nil) return } order, err := budgetService.LoadOrder(model) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } context := budgetService.NewContext(order, c) err = context.Handle(form.Key, form.Type, form.Value) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = context.Eval() if err != nil { logger.Sugar.Infof("err: %v", err) app.ErrorMsg(c, err.Error(), nil) return } err = order.Save(context) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } model.Content = make([]byte, 0) app.Success(c, gin.H{ "name": order.Models[budgetService.Quote][order.Form.ID].GetName(), "order": model, "result": order.ToMap(false), }) } type QuoteCustomerOrderFrom struct { OrderId int64 `form:"orderId" json:"orderId" binding:"required"` Contract string `form:"contract" json:"contract" binding:"required"` Pdf string `form:"pdf" json:"pdf" binding:"required"` Receipt string `form:"receipt" json:"receipt" binding:"required"` } func QuoteCustomerOrder(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var form QuoteCustomerOrderFrom if app.Bind(c, &form) != nil { return } var customer budget.Customer db.GetModel(map[string]interface{}{"id": id}, &customer) if customer.ID == 0 { app.ErrorMsg(c, "客户不存在", nil) return } if customer.OrderId != 0 { app.ErrorMsg(c, "已确认合同", nil) return } var order budget.Order db.GetModel(map[string]interface{}{"id": form.OrderId}, &order) if order.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if order.CustomerId != customer.ID { app.ErrorMsg(c, "订单错误", nil) return } err := db.UpdateModel(db.Type(customer), customer.ID, map[string]interface{}{ "order_id": order.ID, "contract": form.Contract, "pdf": form.Pdf, "receipt": form.Receipt, "state": 1, }) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = db.UpdateModel(db.Type(order), order.ID, map[string]interface{}{ "state": 1, }) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } db.InsertModel(db.Type(budget.BudgetCustomerProcess{}), map[string]interface{}{ "customer_id": customer.ID, "order_id": order.ID, "type": 1, "created_id": c.GetInt("adminID"), }) app.Success(c, nil) } type QuoteCustomerSiteFrom struct { ProjectLeaderId int64 `form:"project_leader_id" json:"project_leader_id" binding:"required"` ManagerId int64 `form:"manager_id" json:"manager_id" binding:"required"` TypeId int64 `form:"type_id" json:"type_id" binding:"required"` } func QuoteCustomerSite(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var form QuoteCustomerSiteFrom if app.Bind(c, &form) != nil { return } var customer budget.Customer db.GetModel(map[string]interface{}{"id": id}, &customer) if customer.ID == 0 { app.ErrorMsg(c, "客户不存在", nil) return } if customer.OrderId == 0 { app.ErrorMsg(c, "未确认合同", nil) return } if customer.State != 2 { app.ErrorMsg(c, "状态错误", nil) return } if customer.SiteId != 0 { app.ErrorMsg(c, "已开工", nil) return } var order budget.Order db.GetModel(map[string]interface{}{"id": customer.OrderId}, &order) if order.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if order.CustomerId != customer.ID { app.ErrorMsg(c, "订单错误", nil) return } siteid, err := db.InsertModel(db.Type(final.FinalSite{}), map[string]interface{}{ "type_id": form.TypeId, "username": customer.Username, "phone": customer.Phone, "village": customer.Village, "address": customer.Address, "room_no": customer.RoomNo, "shop_id": customer.ShopId, "area": order.Area, "manager_id": form.ManagerId, "project_leader_id": form.ProjectLeaderId, "designer_id": customer.CreatedId, "created_id": c.GetInt("adminID"), "customer_id": customer.ID, "order_id": order.ID, }) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = db.UpdateModel(db.Type(customer), customer.ID, map[string]interface{}{ "site_id": siteid, "state": 3, }) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } db.InsertModel(db.Type(budget.BudgetCustomerProcess{}), map[string]interface{}{ "customer_id": customer.ID, "order_id": order.ID, "site_id": siteid, "type": 3, "created_id": c.GetInt("adminID"), }) app.Success(c, nil) } func QuoteFile(c *gin.Context) { quoteId := utils.ToInt(c.Param("id")) if quoteId <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var quote *budget.Quote db.GetModel(map[string]interface{}{"id": quoteId}, "e) if quote == nil { app.ErrorMsg(c, "报价不存在", nil) return } file, err := c.FormFile("file") if err != nil { app.Error(c, fmt.Sprintf("get form err: %s", err.Error())) return } fileExt := utils.FileExt(file.Filename) baseName := utils.FileBase(file.Filename) attachKey := utils.RandomStr() + fileExt file.Filename = "uploads/" + attachKey if err := c.SaveUploadedFile(file, file.Filename); err != nil { app.Error(c, fmt.Sprintf("上传文件失败%s", err.Error())) return } id, err := db.InsertModel(db.Type(budget.File{}), map[string]interface{}{ "quoteId": quoteId, "name": baseName, "path": file.Filename, }) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{"id": id}) } func QuoteOrderExport2(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } fid := utils.ToInt(c.Param("fid")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } order, err := budgetService.LoadOrder(model) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } var file budget.File db.GetModel(map[string]interface{}{"id": fid}, &file) if file.ID == 0 { app.ErrorMsg(c, "模板不存在", nil) return } if file.QuoteId != model.QuoteId { app.ErrorMsg(c, "报价不一致", nil) return } filename := order.Export2(file.Path, c) if filename == "" { app.ErrorMsg(c, "导出失败", nil) return } app.Success(c, gin.H{"path": "export/" + filename, "filename": filename}) } func QuoteOrder2Info(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2UpdateData(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "UpdateData") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2UpdateContractData(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "UpdateContractData") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2UpdateRegion(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "UpdateRegion") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2AddBuildAdditionalItem(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "AddBuildAdditionalItem") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2EditBuildAdditionalItem(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "EditBuildAdditionalItem") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2DelBuildAdditionalItem(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "DelBuildAdditionalItem") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2AddMaterialAdditionalItem(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "AddMaterialAdditionalItem") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2EditMaterialAdditionalItem(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "EditMaterialAdditionalItem") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2DelMaterialAdditionalItem(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "DelMaterialAdditionalItem") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2AddDeductionItem(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "AddDeductionItem") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2DelDeductionItem(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "DelDeductionItem") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2AddSpecialProjectItem(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "AddSpecialProjectItem") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2EditSpecialProjectItem(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "EditSpecialProjectItem") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func QuoteOrder2DelSpecialProjectItem(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if model.State == 2 { app.ErrorMsg(c, "合同已锁定", nil) return } site, err := db.GetOneModelMap(db.Type(final.FinalSiteMobile{}), map[string]interface{}{"id": model.SiteId}, nil) if err != nil { app.ErrorMsg(c, "工地不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = order.Form.Handle(c, "DelSpecialProjectItem") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(order) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{ "pkg_id": model.PkgId, "area_id": order.GetAreaId(), "site": site, "result": order.ReturnResult(), }) } func FuncDocs2Pdf(command string, fileSrcPath string, fileOutDir string, converterType string) (fileOutPath string, error error) { //校验fileSrcPath fileSrcPathAbs, err := filepath.Abs(fileSrcPath) if err != nil { logger.Sugar.Infof("%v", err) return "", err } fileOutDirAbs, err := filepath.Abs(fileOutDir) logger.Sugar.Infof("fileOutDirAbs %v", fileOutDirAbs) if err != nil { logger.Sugar.Infof("%v", err) return "", err } srcFile, erByOpenSrcFile := os.Open(fileSrcPathAbs) if erByOpenSrcFile != nil && os.IsNotExist(erByOpenSrcFile) { logger.Sugar.Infof("%v", erByOpenSrcFile) return "", erByOpenSrcFile } //如文件输出目录fileOutDir不存在则自动创建 outFileDir, erByOpenFileOutDir := os.Open(fileOutDir) if erByOpenFileOutDir != nil && os.IsNotExist(erByOpenFileOutDir) { erByCreateFileOutDir := os.MkdirAll(fileOutDir, os.ModePerm) if erByCreateFileOutDir != nil { fmt.Println("File ouput dir create error.....", erByCreateFileOutDir.Error()) logger.Sugar.Infof("%v", erByCreateFileOutDir) return "", erByCreateFileOutDir } } //关闭流 defer func() { _ = srcFile.Close() _ = outFileDir.Close() }() //convert cmd := exec.Command(command, "--invisible", "--language=zh-CN", "--convert-to", converterType, fileSrcPathAbs, "--outdir", fileOutDirAbs) byteByStat, errByCmdStart := cmd.Output() //命令调用转换失败 if errByCmdStart != nil { logger.Sugar.Infof("%v", errByCmdStart) return "", errByCmdStart } //success //fileOutPath = fileOutDir + "/" + strings.Split(path.Base(fileSrcPath), ".")[0] fileOutPath = strings.Split(path.Base(fileSrcPath), ".")[0] if converterType == "html" { fileOutPath += ".html" } else { fileOutPath += ".pdf" } fmt.Println("文件转换成功...", string(byteByStat)) return fileOutPath, nil } func QuoteOrder2Export(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } exportFileName, err := order.Form.Export(order.SiteId) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{"path": "export/" + exportFileName, "filename": exportFileName}) } func QuoteOrder2ExportPdf(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var model budget2.Order db.GetModel(map[string]interface{}{"id": id}, &model) if model.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } order, err := model.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } exportFileName, err := order.Form.Export(order.SiteId) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } pdfFileName, err := FuncDocs2Pdf("libreoffice", config.Cfg.App.ExportPath+exportFileName, config.Cfg.App.ExportPath, "pdf") if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, gin.H{"path": "export/" + pdfFileName, "filename": pdfFileName}) } func Quote2ConfirmOrder(c *gin.Context) { id := utils.ToInt(c.Param("id")) if id <= 0 { app.ErrorMsg(c, "id must be a number", nil) return } var order budget2.Order db.GetModel(map[string]interface{}{"id": id}, &order) if order.ID == 0 { app.ErrorMsg(c, "订单不存在", nil) return } if order.State != 0 { app.ErrorMsg(c, "订单状态有误", nil) return } var site final.FinalSite db.GetModel(map[string]interface{}{"id": order.SiteId}, &site) if site.ID == 0 { app.ErrorMsg(c, "工地不存在", nil) return } if site.State == 1 { app.ErrorMsg(c, "工地已开工", nil) return } if site.OrderId != 0 { app.ErrorMsg(c, "已确认合同", nil) return } err := db.UpdateModel(db.Type(order), order.ID, map[string]interface{}{ "state": 1, }) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = db.UpdateModel(db.Type(site), site.ID, map[string]interface{}{ "order_id": order.ID, }) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } order.State = 1 o, err := order.LoadOrder() if err != nil { app.ErrorMsg(c, err.Error(), nil) return } err = budget2.SaveOrder(o) if err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, nil) }