package controllers import ( "ERP_storage/Nats" "ERP_storage/Nats/NatsServer" "ERP_storage/conf" "ERP_storage/dto" "ERP_storage/logs" "ERP_storage/models/Account" models "ERP_storage/models/ContractReview" "ERP_storage/services" "encoding/json" "fmt" natslibs "gogs.baozhida.cn/zoie/ERP_libs/Nats" userlibs "gogs.baozhida.cn/zoie/ERP_libs/User" "gogs.baozhida.cn/zoie/ERP_libs/lib" beego "github.com/beego/beego/v2/server/web" "github.com/xuri/excelize/v2" "math" "os" "strconv" ) type ContractReviewController struct { beego.Controller User userlibs.User } func (c *ContractReviewController) Prepare() { c.User = *Account.User_r } // 服务类型 func (c *ContractReviewController) ServiceType_List() { s := services.ServiceType{} reqData := dto.ServiceTypePageReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } R_List, R_cnt := s.GetPage(&reqData) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = reqData.Page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(reqData.PageSize))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } func (c *ContractReviewController) ServiceType_Add() { s := services.ServiceType{} reqData := dto.ServiceTypeInsertReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } Id, err := s.Insert(&reqData) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "服务类型", "添加", reqData) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id} c.ServeJSON() return } func (c *ContractReviewController) ServiceType_Edit() { s := services.ServiceType{} reqData := dto.ServiceTypeUpdateReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } if err := s.Update(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "服务类型", "修改", reqData) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } func (c *ContractReviewController) ServiceType_Del() { s := services.ServiceType{} reqData := dto.ServiceTypeDeleteReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } if err := s.Delete(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "服务类型", "删除", strconv.Itoa(reqData.T_id)) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 服务内容 func (c *ContractReviewController) ServiceItem_List() { s := services.ServiceItem{} reqData := dto.ServiceItemPageReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } R_List, R_cnt := s.GetPage(&reqData) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = reqData.Page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(reqData.PageSize))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } func (c *ContractReviewController) ServiceItem_Add() { s := services.ServiceItem{} reqData := dto.ServiceItemInsertReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } Id, err := s.Insert(&reqData) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "服务内容", "添加", reqData) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id} c.ServeJSON() return } func (c *ContractReviewController) ServiceItem_Edit() { s := services.ServiceItem{} reqData := dto.ServiceItemUpdateReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } if err := s.Update(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "服务内容", "修改", reqData) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } func (c *ContractReviewController) ServiceItem_Del() { s := services.ServiceItem{} reqData := dto.ServiceItemDeleteReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } if err := s.Delete(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "服务内容", "删除", strconv.Itoa(reqData.T_id)) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 合同评审-用户 func (c *ContractReviewController) List() { s := services.ContractReview{} reqData := dto.ContractReviewPageReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) reqData.T_submit = c.User.T_uuid R_List, R_cnt := s.GetPage(&reqData) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = reqData.Page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(reqData.PageSize))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } // 合同评审-财务 func (c *ContractReviewController) Finance_List() { s := services.ContractReview{} reqData := dto.ContractReviewPageReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) R_List, R_cnt := s.GetFinancePage(&reqData) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = reqData.Page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(reqData.PageSize))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } // 合同评审-财务 func (c *ContractReviewController) Manager_List() { s := services.ContractReview{} reqData := dto.ContractReviewPageReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) R_List, R_cnt := s.GetManagerPage(&reqData) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = reqData.Page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(reqData.PageSize))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } // 负责人列表 func (c *ContractReviewController) Submit_User_List() { s := services.ContractReview{} reqData := dto.ContractReviewSubmitUserPageReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) R_List, R_cnt := s.GetSubmitUserPage(&reqData) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } func (c *ContractReviewController) Add() { s := services.ContractReview{} reqData := dto.ContractReviewInsertReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := json.Unmarshal([]byte(reqData.ServiceItems), &reqData.ServiceItemList); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "服务内容 参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } reqData.T_submit = c.User.T_uuid Id, err := s.Insert(&reqData) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "合同评审", "添加", reqData) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id} c.ServeJSON() return } func (c *ContractReviewController) Edit() { s := services.ContractReview{} reqData := dto.ContractReviewUpdateReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := json.Unmarshal([]byte(reqData.ServiceItems), &reqData.ServiceItemList); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "服务内容 参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } if err := s.Update(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: err.Error()} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "合同评审", "修改", reqData) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 提交审核 func (c *ContractReviewController) Submit_Audit() { s := services.ContractReview{} reqData := dto.ContractReviewGetReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } if err := s.SubmitAudit(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: err.Error()} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "合同评审", "提交审核", reqData) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 财务审核 func (c *ContractReviewController) Finance_Audit() { s := services.ContractReview{} reqData := dto.ContractReviewAuditReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } if !(reqData.T_audit == 3 || reqData.T_audit == 4) { c.Data["json"] = lib.JSONS{Code: 202, Msg: "状态参数错误"} c.ServeJSON() return } if err := s.FinanceAudit(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: err.Error()} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "合同评审", "财务审核", reqData) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 管理员审核 func (c *ContractReviewController) Manager_Audit() { s := services.ContractReview{} reqData := dto.ContractReviewAuditReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } if !(reqData.T_audit == 5 || reqData.T_audit == 6) { c.Data["json"] = lib.JSONS{Code: 202, Msg: "状态参数错误"} c.ServeJSON() return } if err := s.ManagerAudit(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: err.Error()} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "合同评审", "总经理审核", reqData) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } func (c *ContractReviewController) Del() { s := services.ContractReview{} reqData := dto.ContractReviewDeleteReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } if err := s.Delete(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "合同评审", "删除", strconv.Itoa(reqData.T_id)) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } func (c *ContractReviewController) Stock_Detail_Excel() { s := services.ContractReview{} reqData := dto.ContractReviewPageReq{} if err := c.ParseForm(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"} c.ServeJSON() return } if err := Validate(&reqData); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) reqData.PageSize = 9999 R_List, _ := s.GetFinancePage(&reqData) filename := fmt.Sprintf("合同评审统计表(%s)", lib.GetRandstring(6, "0123456789", 0)) f := excelize.NewFile() // 设置单元格的值 Style1, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"}, Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"}, }) Style2, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"}, Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true}, Border: []excelize.Border{ {Type: "left", Color: "000000", Style: 1}, {Type: "top", Color: "000000", Style: 1}, {Type: "bottom", Color: "000000", Style: 1}, {Type: "right", Color: "000000", Style: 1}, }, }) f.MergeCell("Sheet1", "A1", "I1") f.SetRowStyle("Sheet1", 1, 1, Style1) f.SetCellValue("Sheet1", "A1", fmt.Sprintf("宝智达科技合同评审统计表")) f.SetRowHeight("Sheet1", 1, 30) // 这里设置表头 f.SetCellStyle("Sheet1", "A2", "I2", Style2) f.SetRowHeight("Sheet1", 2, 20) f.SetCellValue("Sheet1", "A2", "序号") f.SetCellValue("Sheet1", "B2", "状态") f.SetCellValue("Sheet1", "C2", "项目名称") f.SetCellValue("Sheet1", "D2", "项目地址") f.SetCellValue("Sheet1", "E2", "项目负责人") f.SetCellValue("Sheet1", "F2", "预计签约时间") f.SetCellValue("Sheet1", "G2", "总金额") f.SetCellValue("Sheet1", "H2", "最终优惠金额") f.SetCellValue("Sheet1", "I2", "是否有居间费") f.SetCellValue("Sheet1", "J2", "居间费金额") // 设置列宽 f.SetColWidth("Sheet1", "A", "A", 10) f.SetColWidth("Sheet1", "B", "B", 10) f.SetColWidth("Sheet1", "C", "D", 15) f.SetColWidth("Sheet1", "D", "D", 20) f.SetColWidth("Sheet1", "E", "E", 12) f.SetColWidth("Sheet1", "F", "F", 12) f.SetColWidth("Sheet1", "G", "H", 10) f.SetColWidth("Sheet1", "I", "I", 12) f.SetColWidth("Sheet1", "J", "J", 10) line := 2 // 循环写入数据 for _, v := range R_List { line++ f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), line-2) f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), models.Get_T_audit_name(v.T_audit)) f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_name) f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_address) f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_submit_name) f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_predict_sign_time) f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_money) f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_discount_money) T_have_brokerage_fee_str := "否" if v.T_have_brokerage_fee == true { T_have_brokerage_fee_str = "是" } f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), T_have_brokerage_fee_str) f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.T_brokerage_fee_money) } Style4, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Size: 10, Family: "宋体"}, Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true}, Border: []excelize.Border{ {Type: "left", Color: "000000", Style: 1}, {Type: "top", Color: "000000", Style: 1}, {Type: "bottom", Color: "000000", Style: 1}, {Type: "right", Color: "000000", Style: 1}, }, }) f.SetCellStyle("Sheet1", "A2", fmt.Sprintf("I%d", line), Style4) // 保存文件 if err := f.SaveAs("ofile/" + filename + ".xlsx"); err != nil { fmt.Println(err) } var url string //// 上传 OSS nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix) url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx") if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"} c.ServeJSON() return } //删除目录 err := os.Remove("ofile/" + filename + ".xlsx") if err != nil { logs.Error(lib.FuncName(), err) } c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url} c.ServeJSON() return }