package controllers import ( "encoding/json" "fmt" "github.com/rdlucklib/rdluck_tools/paging" approval2 "hongze/hongze_mobile_admin/models/request/approval" "hongze/hongze_mobile_admin/models/response/approval" "hongze/hongze_mobile_admin/models/tables/admin" "hongze/hongze_mobile_admin/models/tables/company_approval" "hongze/hongze_mobile_admin/models/tables/company_contract" "hongze/hongze_mobile_admin/models/tables/company_delay_permission" "hongze/hongze_mobile_admin/models/tables/company_product" "hongze/hongze_mobile_admin/models/tables/company_product_log" "hongze/hongze_mobile_admin/models/tables/company_report_permission" "hongze/hongze_mobile_admin/models/tables/contract_approval_record" "hongze/hongze_mobile_admin/services" "hongze/hongze_mobile_admin/services/flow" "hongze/hongze_mobile_admin/utils" "strconv" "time" ) // 客户审批列表 type ApprovalCommon struct { BaseAuth } // ListOld // @Title 获取审批列表接口 // @Description 获取审批列表接口 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Param Status query string true "状态:'待审批','已审批','驳回','已撤回'" // @Param KeyWord query string true "搜索关键词" // @Param Keyword query string true "搜索关键词" // @Param KeywordEq query string true "搜索关键词(全等)" // @Success 200 {object} approval.CompanyApprovalListResp // @router /list_old [get] func (c *ApprovalCommon) ListOld() { sysUser := c.AdminWx roleTypeCode := sysUser.RoleTypeCode pageSize, _ := c.GetInt("PageSize") currentIndex, _ := c.GetInt("CurrentIndex") status := c.GetString("Status") keyword := c.GetString("Keyword") keywordEq := c.GetString("KeywordEq") keyWord := c.GetString("KeyWord") if keyword == "" { keyword = keyWord } var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) var condition string var pars []interface{} if status != "" { if status == "已审批" { condition += ` AND c.approve_status IN('已审批','驳回') ` } else { condition += ` AND c.approve_status=? ` pars = append(pars, status) } } if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //审批 condition += ` AND c.approve_role_type_code=? ` pars = append(pars, roleTypeCode) } else if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_COMPLIANCE { //超管或者合规 } else { //销售 condition += ` AND c.apply_user_id=? ` pars = append(pars, sysUser.AdminId) } if keyword != "" { condition += ` AND (a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%') ` } if keywordEq != "" { condition += ` AND a.company_name = ? ` pars = append(pars, keywordEq) } total, err := company_approval.GetApprovalCount(condition, pars) if err != nil { c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error()) return } list, err := company_approval.GetApprovalList(condition, pars, startSize, pageSize) if err != nil { c.FailWithMessage("获取失败", "获取数据失败,Err:"+err.Error()) return } listLen := len(list) for i := 0; i < listLen; i++ { item := list[i] if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE { freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate) if time.Now().Before(freezeEndDate) { expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24 list[i].FreezeExpireDays = int(expireDays) } } if item.StartDate != "" && item.EndDate != "" { endDate, _ := time.Parse(utils.FormatDate, item.EndDate) if time.Now().Before(endDate) { expireDays := endDate.Sub(time.Now()).Hours() / 24 list[i].ExpireDay = int(expireDays) } } switch item.ApplyMethod { case 2: //客户冻结转试用次数 approvalCount, err := company_approval.GetFreezeToTryCompanyApprovalCount(item.CompanyId, item.ProductId, item.ApplyUserId) if err != nil && err.Error() != utils.ErrNoRow() { c.FailWithMessage("获取失败", "获取冻结转试用审批次数失败,Err:"+err.Error()) return } list[i].ApprovalCount = approvalCount case 3: //延迟试用权限列表 delayPermission, err := company_delay_permission.GetApplyDelayPermission(item.CompanyApprovalId) if err != nil && err.Error() != utils.ErrNoRow() { c.FailWithMessage("获取失败", "获取延期审批权限失败,Err:"+err.Error()) return } list[i].DelayPermission = delayPermission //客户审批试用延期次数 approvalCount, err := company_approval.GetCompanyTryDelayApprovalCount(item.CompanyId, item.ProductId) if err != nil && err.Error() != utils.ErrNoRow() { c.FailWithMessage("获取失败", "获取延期审批次数失败,Err:"+err.Error()) return } list[i].ApprovalCount = approvalCount } if item.ApproveRoleTypeCode == roleTypeCode { list[i].OpButton = true } } page := paging.GetPaging(currentIndex, pageSize, total) resp := approval.CompanyApprovalListResp{ Paging: page, List: list, } c.OkDetailed(resp, "获取成功") } // @Title 获取审批单详情接口 // @Description 获取审批单详情接口 // @Param ApprovalId query int true "审批单id" // @Success 200 {object} approval.CompanyApprovalDetailResp // @router /detail_old [get] func (c *ApprovalCommon) DetailOld() { sysUser := c.AdminWx roleTypeCode := sysUser.RoleTypeCode companyApprovalId, _ := c.GetInt("ApprovalId") var condition string var pars []interface{} if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //审批 condition += ` AND c.approve_role_type_code=? ` pars = append(pars, roleTypeCode) } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER { //销售 condition += ` AND c.apply_user_id=? ` pars = append(pars, sysUser.AdminId) } item, err := company_approval.GetApprovalInfoByApprovalId(condition, pars, companyApprovalId) if err != nil { c.FailWithMessage("获取失败", "获取数据失败,Err:"+err.Error()) return } if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE { freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate) if time.Now().Before(freezeEndDate) { expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24 item.FreezeExpireDays = int(expireDays) } } if item.StartDate != "" && item.EndDate != "" { endDate, _ := time.Parse(utils.FormatDate, item.EndDate) if time.Now().Before(endDate) { expireDays := endDate.Sub(time.Now()).Hours() / 24 item.ExpireDay = int(expireDays) } } switch item.ApplyMethod { case 2: //客户冻结转试用次数 approvalCount, err := company_approval.GetFreezeToTryCompanyApprovalCount(item.CompanyId, item.ProductId, item.ApplyUserId) if err != nil && err.Error() != utils.ErrNoRow() { c.FailWithMessage("获取失败", "获取冻结转试用审批次数失败,Err:"+err.Error()) return } item.ApprovalCount = approvalCount case 3: //客户审批试用延期次数 approvalCount, err := company_approval.GetCompanyTryDelayApprovalCount(item.CompanyId, item.ProductId) if err != nil && err.Error() != utils.ErrNoRow() { c.FailWithMessage("获取失败", "获取延期审批次数失败,Err:"+err.Error()) return } item.ApprovalCount = approvalCount } //if item.ApplyMethod == 3 { // delayPermission, err := company_delay_permission.GetApplyDelayPermission(item.CompanyApprovalId) // if err != nil && err.Error() != utils.ErrNoRow() { // c.FailWithMessage("获取失败", "获取延期审批权限失败,Err:"+err.Error()) // return // } // item.DelayPermission = delayPermission //} if item.ApproveRoleTypeCode == roleTypeCode { item.OpButton = true } resp := approval.CompanyApprovalDetailResp{ CompanyApprovalDetail: item, } //获取权限列表 //子权限切片集合 var permissionClassifyArr []string if item.ProductId == 1 { for _, v := range utils.PermissionFiccClassifyArr { permissionClassifyArr = append(permissionClassifyArr, v) } } else { permissionClassifyArr = append(permissionClassifyArr, "权益") } //获取需要审批的权限 delayPermissionList, err := company_delay_permission.GetDelayPermissionItems(item.CompanyId, item.CompanyApprovalId) if err != nil && err.Error() != utils.ErrNoRow() { c.FailWithMessage("获取失败", "获取审批权限失败,Err:"+err.Error()) return } delayPermissionIdMap := make(map[int]int) for _, delayPermission := range delayPermissionList { delayPermissionIdMap[delayPermission.ChartPermissionId] = 0 } //遍历获取 for _, v := range permissionClassifyArr { checkList := make([]int, 0) plist := new(company_report_permission.PermissionLookList) items, err := company_report_permission.GetPermissionLookItems(item.ProductId, v) if err != nil { c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error()) return } for _, n := range items { if _, ok := delayPermissionIdMap[n.ChartPermissionId]; ok { checkList = append(checkList, n.ChartPermissionId) } } plist.Items = items plist.ClassifyName = v plist.CheckList = checkList if item.ProductId == 1 { resp.FiccPermissionList = append(resp.FiccPermissionList, plist) } else { resp.PermissionList = append(resp.PermissionList, plist) } } //审批流 flowId := 1 if item.ProductId == 2 { flowId = 2 } flowItem, err := flow.GetApprovalFlow(flowId) if err != nil { c.FailWithMessage("获取失败", "获取数据失败,Err:"+err.Error()) return } approveTime, err := time.Parse(utils.FormatDateTime, item.ApproveTime) if err != nil { c.FailWithMessage("获取失败", "审批时间转换失败,Err:"+err.Error()) return } approvalTime, err := time.Parse(utils.FormatDateTime, item.ApprovalTime) if err != nil { c.FailWithMessage("获取失败", "发起时间转换失败,Err:"+err.Error()) return } //当前审批流程id flowNodeListResp := make([][]contract_approval_record.ContractApprovalRecord, 0) for _, node := range flowItem.NodeList { flowNodeResp := make([]contract_approval_record.ContractApprovalRecord, 0) for _, user := range node.UserList { approveStatus := item.ApproveStatus if approveStatus == "驳回" { approveStatus = "已驳回" } approvalRecord := contract_approval_record.ContractApprovalRecord{ //ContractApprovalRecordId int `orm:"column(contract_approval_record_id);pk"` //ContractApprovalId int `orm:"column(contract_approval_id)" description:"审批单id"` Status: approveStatus, ApproveRemark: item.ApproveRemark, ApproveRoleTypeCode: user.RoleTypeCode, ApproveUserId: user.AdminId, ApproveUserName: user.Name, NodeId: node.NodeId, NodeType: node.NodeType, //PrevNodeId int `description:"上级节点id"` //NextNodeId int `description:"下级节点id"` AuditType: node.AuditType, ApproveTime: approveTime, //ModifyTime time.Time `description:"发起申请时间"` CreateTime: approvalTime, } flowNodeResp = append(flowNodeResp, approvalRecord) if user.AdminId == item.ApproveUserId { resp.CompanyApprovalDetail.CurrNodeId = node.NodeId } } flowNodeListResp = append(flowNodeListResp, flowNodeResp) } resp.FlowNodeList = flowNodeListResp c.OkDetailed(resp, "获取成功") } // @Title 获取审批单中的权限列表 // @Description 获取审批单中的权限列表接口 // @Param ApprovalId query int true "审批单id" // @Success 200 {object} approval.CompanyPermissionResp // @router /getApprovalPermissionList [get] func (c *ApprovalCommon) GetApprovalPermissionList() { //c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error()) //返回基础参数 resp := new(approval.CompanyPermissionResp) //获取审批单信息 approvalId, _ := c.GetInt("ApprovalId") if approvalId <= 0 { c.FailWithMessage("审批单参数异常", "提交审批单参数异常") return } approvalInfo, err := company_approval.GetCompanyApprovalByApprovalId(approvalId) if err != nil { c.FailWithMessage("获取失败", "获取审批单数据失败,Err:"+err.Error()) return } //子权限切片集合 var permissionClassifyArr []string if approvalInfo.ProductId == 1 { for _, v := range utils.PermissionFiccClassifyArr { permissionClassifyArr = append(permissionClassifyArr, v) } } else { permissionClassifyArr = append(permissionClassifyArr, "权益") } //获取需要审批的权限 delayPermissionList, err := company_delay_permission.GetDelayPermissionItems(approvalInfo.CompanyId, approvalInfo.CompanyApprovalId) if err != nil && err.Error() != utils.ErrNoRow() { c.FailWithMessage("获取失败", "获取审批权限失败,Err:"+err.Error()) return } delayPermissionIdMap := make(map[int]int) for _, delayPermission := range delayPermissionList { delayPermissionIdMap[delayPermission.ChartPermissionId] = 0 } //遍历获取 for _, v := range permissionClassifyArr { checkList := make([]int, 0) plist := new(company_report_permission.PermissionLookList) items, err := company_report_permission.GetPermissionLookItems(approvalInfo.ProductId, v) if err != nil { c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error()) return } for _, n := range items { if _, ok := delayPermissionIdMap[n.ChartPermissionId]; ok { checkList = append(checkList, n.ChartPermissionId) } } plist.Items = items plist.ClassifyName = v plist.CheckList = checkList if approvalInfo.ProductId == 1 { resp.FiccPermissionList = append(resp.FiccPermissionList, plist) } else { resp.PermissionList = append(resp.PermissionList, plist) } } c.OkDetailed(resp, "获取成功") } // @Title 审批 // @Description 审批接口 // @Param request body approval.CompanyApplyApproveReq true "type json string" // @Success Ret=200 审批成功 // @router /approve_old [post] func (c *ApprovalCommon) ApplyApproveOld() { sysUser := c.AdminWx var req approval2.CompanyApplyApproveReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) if err != nil { c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error()) return } roleTypeCode := sysUser.RoleTypeCode productId := services.GetProductId(roleTypeCode) if productId == 0 { c.FailWithMessage("参数错误", "参数解析失败,Err:"+"客户类型为:"+roleTypeCode) return } if req.CompanyId <= 0 { c.FailWithMessage("参数错误", "客户Id小于等于0") return } if req.Status != 1 && req.Status != 2 { c.FailWithMessage("参数错误", "审批状态Id小于等于0") return } companyProduct, err := company_product.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId) if err != nil { c.FailWithMessage("获取信息失败", "获取信息失败,Err:"+err.Error()) return } if companyProduct == nil { c.FailWithMessage("获取审批信息失败", "获取信息失败,Err:"+err.Error()) return } approvalItem, err := company_approval.GetCompanyApprovalByCompanyId(req.CompanyId, productId) if err != nil { if err.Error() == utils.ErrNoRow() { c.FailWithMessage("订单已审批,请刷新页面查看最新状态", "待审批信息不存在,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+strconv.Itoa(productId)) } else { c.FailWithMessage("获取信息失败", "获取信息失败,Err:"+err.Error()) } return } if approvalItem == nil { c.FailWithMessage("订单已审批,请刷新页面查看最新状态", "待审批信息不存在,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+strconv.Itoa(productId)) return } if approvalItem.ApproveRoleTypeCode != roleTypeCode { c.FailWithMessage("您无权审批", "ApproveRoleTypeCode:"+approvalItem.ApproveRoleTypeCode+";roleTypeCode:"+roleTypeCode) return } var approveStatus, approveContent string if req.Status == 1 { //通过 //申请类型:1:试用->正式,2:冻结—>试用,3:试用延期,4:原销售申请领取流失客户,5:正式客户申请服务更新,6:正式客户补充协议 if approvalItem.ApplyMethod == 1 { //试用转正式 //获取合同信息 contract, err := company_contract.GetCompanyContractDetail(req.CompanyId, productId, req.CompanyContractId) if err != nil { c.FailWithMessage("待审批信息不存在", "待审批信息不存在,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+strconv.Itoa(productId)+";Err:"+err.Error()) return } if contract == nil { c.FailWithMessage("待审批信息不存在", "待审批信息不存在,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+strconv.Itoa(productId)) return } //格式化合同开始时间 contractStartDate, err := time.Parse(utils.FormatDate, contract.StartDate) if err != nil { c.FailWithMessage("审批失败", "合同开始时间转换失败,Err:"+err.Error()) return } //格式化合同结束日期 contractEndDate, err := time.Parse(utils.FormatDate, contract.EndDate) if err != nil { c.FailWithMessage("审批失败", "合同结束时间转换失败,Err:"+err.Error()) return } //格式化 产品中 合同结束日期 //productContractEndDate, err := time.Parse(utils.FormatDate, companyProduct.ContractEndDate) //if err != nil { // br.Msg = "审批失败" // br.ErrMsg = "产品中合同结束时间转换失败,Err:" + err.Error() // return //} //如果合同时间小于等于今天,那么立马执行合同内容 if time.Now().After(contractStartDate) { _, err = company_approval.TryOutToFormal(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, contract.CompanyContractId, contract.StartDate, contract.EndDate, sysUser.RealName, companyProduct.ProductName, contract.PackageType, contract.RaiPackageType) if err != nil { c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error()) return } } else { err = company_approval.ApplyApproveContract(req.CompanyId, productId, approvalItem.CompanyApprovalId, contract.CompanyContractId) if err != nil { c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error()) return } } //如果合同中的结束日期大于产品中的合同结束日期,那么就去修改产品中的合同结束日期 if contractEndDate.After(companyProduct.ContractEndDate) { companyProduct.ContractEndDate = contractEndDate cols := make([]string, 0) cols = append(cols, "ContractEndDate") _ = companyProduct.Update(cols) } } else if approvalItem.ApplyMethod == 2 { //冻结->试用 _, _, _, err = company_approval.FreezeToTryOut(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, approvalItem.ApplyUserId, sysUser.RealName, companyProduct.ProductName) if err != nil { c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error()) return } } else if approvalItem.ApplyMethod == 3 { //试用延期 _, _, err = company_approval.TryOutDelay(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, sysUser.RealName, companyProduct.EndDate, companyProduct.ProductName) if err != nil { c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error()) return } } else if approvalItem.ApplyMethod == 4 { //原销售申请领取流失客户 _, _, _, err = company_approval.ApplyReceive(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, approvalItem.ApplyUserId, sysUser.RealName, companyProduct.ProductName) if err != nil { c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error()) return } } else if approvalItem.ApplyMethod == 5 || approvalItem.ApplyMethod == 6 { //正式客户申请服务更新 //获取合同信息 contract, err := company_contract.GetCompanyContractDetail(req.CompanyId, productId, req.CompanyContractId) if err != nil { c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error()) return } if contract == nil { c.FailWithMessage("审批失败", "审批失败") return } //格式化合同开始时间 contractStartDate, err := time.Parse(utils.FormatDate, contract.StartDate) if err != nil { c.FailWithMessage("审批失败", "合同开始时间转换失败,Err:"+err.Error()) return } //格式化合同结束日期 contractEndDate, err := time.Parse(utils.FormatDate, contract.EndDate) if err != nil { c.FailWithMessage("审批失败", "合同结束时间转换失败,Err:"+err.Error()) return } //格式化 产品中 合同结束日期 //productContractEndDate, err := time.Parse(utils.FormatDate, companyProduct.ContractEndDate) //if err != nil { // br.Msg = "审批失败" // br.ErrMsg = "产品中合同结束时间转换失败,Err:" + err.Error() // return //} //如果合同时间小于等于今天,那么立马执行合同内容 if time.Now().After(contractStartDate) { _, err = company_approval.ApplyServiceUpdate(req.CompanyId, productId, sysUser.AdminId, approvalItem.CompanyApprovalId, contract.CompanyContractId, companyProduct.StartDate, contract.EndDate, sysUser.RealName, companyProduct.ProductName, contract.PackageType, contract.RaiPackageType) if err != nil { c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error()) return } } else { err = company_approval.ApplyApproveContract(req.CompanyId, productId, approvalItem.CompanyApprovalId, contract.CompanyContractId) if err != nil { c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error()) return } } //如果合同中的结束日期大于产品中的合同结束日期,那么就去修改产品中的合同结束日期 if contractEndDate.After(companyProduct.ContractEndDate) { companyProduct.ContractEndDate = contractEndDate cols := make([]string, 0) cols = append(cols, "ContractEndDate") _ = companyProduct.Update(cols) } } else { c.FailWithMessage("审批失败", "无效的审批状态,CompanyId:"+strconv.Itoa(req.CompanyId)+";productId:"+ strconv.Itoa(productId)+";ApplyMethod:"+strconv.Itoa(approvalItem.ApplyMethod)+" ApproveStatus;"+approvalItem.ApproveStatus) return } approveContent = "审批通过" } else { //拒绝 if req.Remark == "" { c.FailWithMessage("请填写驳回理由", "请填写驳回理由") return } approveStatus = "驳回" err = company_approval.ApproveRefuse(req.CompanyId, productId, approveStatus, req.Remark) approveContent = "审批驳回" if err != nil { c.FailWithMessage("审批失败", "审批失败,Err:"+err.Error()) return } } //新增客户产品日志 { productLog := new(company_product_log.CompanyProductLog) productLog.CompanyProductId = companyProduct.CompanyProductId productLog.CompanyId = companyProduct.CompanyId productLog.ProductId = companyProduct.ProductId productLog.ProductName = companyProduct.ProductName productLog.CompanyName = companyProduct.CompanyName productLog.CompanyName = companyProduct.CompanyName productLog.Source = companyProduct.Source productLog.Reasons = companyProduct.Reasons productLog.Status = companyProduct.Status productLog.IndustryId = companyProduct.IndustryId productLog.IndustryName = companyProduct.IndustryName productLog.SellerId = companyProduct.SellerId productLog.SellerName = companyProduct.SellerName productLog.GroupId = companyProduct.GroupId productLog.DepartmentId = companyProduct.DepartmentId productLog.IsSuspend = companyProduct.IsSuspend productLog.SuspendTime = companyProduct.SuspendTime productLog.ApproveStatus = companyProduct.ApproveStatus productLog.FreezeTime = companyProduct.FreezeTime productLog.Remark = companyProduct.Remark productLog.StartDate = companyProduct.StartDate productLog.EndDate = companyProduct.EndDate productLog.CreateTime = companyProduct.CreateTime productLog.ModifyTime = companyProduct.ModifyTime productLog.LoseReason = companyProduct.LoseReason productLog.LossTime = companyProduct.LossTime productLog.LogType = "modify" productLog.LogCreateTime = time.Now() productLog.AdminId = c.AdminWx.AdminId go company_product_log.AddCompanyProductLog(productLog) } //新增操作记录 { remark := "审批" operation := "approve" services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, sysUser.AdminId, companyProduct.CompanyName, companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, req.Remark, companyProduct.Status) } //待办通知 { content := companyProduct.CompanyName + " " + approvalItem.ApproveContent + approveContent approvalSysUser, _ := admin.GetAdminById(approvalItem.ApplyUserId) if sysUser != nil { approvalStatus := 1 if req.Status == 1 { approvalStatus = 2 } else { approvalStatus = 3 } go services.AddCompanyApprovalMessage(sysUser.AdminId, approvalItem.ApplyUserId, req.CompanyId, approvalItem.CompanyApprovalId, 2, 1, approvalStatus, companyProduct.CompanyName, content, content, approvalSysUser.Mobile, "") } } c.OkWithMessage("审批操作成功") } // @Title 获取审批流详情接口 // @Description 获取审批流详情接口 // @Param FlowId query int true "审批流程id;1:ficc客户审批;2:权益客户审批;3:ficc合同审批,4:权益合同审批,5:用印审批(合同章),6:用印审批(公章、法人章)" // @Success 200 {object} approval_flow.ApprovalFlowItem // @router /flowDetail [get] func (c *ApprovalCommon) GetFlowDetail() { //sysUser := c.AdminWx flowId, _ := c.GetInt("FlowId", 0) if flowId <= 0 { c.FailWithMessage("参数异常", fmt.Sprint("审批流程id异常,FlowId:", flowId)) return } flowItem, err := flow.GetApprovalFlow(flowId) if err != nil { c.FailWithMessage("获取失败", "获取数据失败,Err:"+err.Error()) return } formatFlowItem, err := flow.FormatApprovalFlow(flowItem) c.OkDetailed(formatFlowItem, "获取成功") } // CompanyList // @Title 根据客户名称获取已存在合同系统中客户名称列表 // @Description 获取合同详情接口 // @Param Keyword query string true "搜索关键字:客户名称、组织社会信用码" // @Success 200 {object} []string // @router /company_list [get] func (c *ApprovalCommon) CompanyList() { keyword := c.GetString("Keyword") //合同id if keyword == "" { c.FailWithMessage("搜索关键字必传!", "搜索关键字必传!") return } companyNameList := make([]string, 0) list, err := company_approval.GetCompanyNameList(c.AdminWx.AdminId, keyword) if err != nil { c.FailWithMessage("获取客户名称列表失败!", "获取客户名称列表失败,ERR:"+err.Error()) return } for _, v := range list { companyNameList = append(companyNameList, v.CompanyName) } c.OkDetailed(companyNameList, "获取成功") } //// @Title 审批列表删除 //// @Description 审批列表删除接口 //// @Param request body company.CompanyApplyDeleteReq true "type json string" //// @Success Ret=200 删除成功 //// @router /approval/delete [post] //func (c *CompanyApprovalController) ApplyDelete() { // br := new(models.BaseResponse).Init() // defer func() { // c.Data["json"] = br // c.ServeJSON() // }() // sysUser := c.SysUser // if sysUser == nil { // br.Msg = "请登录" // br.ErrMsg = "请登录,SysUser Is Empty" // br.Ret = 408 // return // } // var req company.CompanyApplyDeleteReq // err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) // if err != nil { // br.Msg = "参数解析异常!" // br.ErrMsg = "参数解析失败,Err:" + err.Error() // return // } // roleTypeCode := sysUser.RoleTypeCode // productId := services.GetProductId(roleTypeCode) // if productId == 0 { // br.Msg = "参数错误" // br.ErrMsg = "客户类型为:" + roleTypeCode // return // } // if req.CompanyId <= 0 { // br.Msg = "参数错误" // br.ErrMsg = "客户Id小于等于0:" // return // } // companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId) // if err != nil { // br.Msg = "获取信息失败" // br.ErrMsg = "获取信息失败,Err:" + err.Error() // return // } // if companyProduct == nil { // br.Msg = "获取信息失败" // br.ErrMsg = "获取审批信息失败,Err:" + err.Error() // return // } // approvalItem, err := company.GetCompanyApprovalByApprovalId(req.CompanyApprovalId) // if err != nil { // if err.Error() == utils.ErrNoRow() { // br.Msg = "待审批信息不存在" // br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId) // return // } // br.Msg = "获取信息失败" // br.ErrMsg = "获取信息失败,Err:" + err.Error() // return // } // if approvalItem == nil { // br.Msg = "待审批信息不存在" // br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId) // return // } // if approvalItem.ApproveStatus != "待审批" && approvalItem.ApproveStatus != "已撤回" { // br.Msg = "审批状态为:" + approvalItem.ApproveStatus + ";不可删除" // br.ErrMsg = "审批状态为:" + approvalItem.ApproveStatus + ";不可删除" + ";CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId) // return // } // //删除 // err = company.ApplyDelete(req.CompanyId, req.CompanyApprovalId, approvalItem.ProductId) // if err != nil { // br.Msg = "删除失败" // br.ErrMsg = "删除失败,Err:" + err.Error() // return // } // //新增操作记录 // { // remark := "删除审批申请" // operation := "approve_delete" // services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, sysUser.AdminId, companyProduct.CompanyName, // companyProduct.ProductName, sysUser.RealName, remark, operation, remark, sysUser.RealName, "", companyProduct.Status) // } // br.Ret = 200 // br.Success = true // br.Msg = "删除成功" //}