123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- contractReq "hongze/hongze_mobile_admin/models/request/contract"
- contractResp "hongze/hongze_mobile_admin/models/response/contract"
- "hongze/hongze_mobile_admin/models/tables/contract_approval"
- "hongze/hongze_mobile_admin/models/tables/contract_approval_record"
- contractService "hongze/hongze_mobile_admin/services/contract"
- "hongze/hongze_mobile_admin/utils"
- "strconv"
- "strings"
- )
- //合同审批模块
- type ContractApprovalCommon struct {
- BaseAuth
- }
- // List
- // @Title 审批单列表
- // @Description 审批单列表接口
- // @Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
- // @Param Status query string false "合同状态,枚举值:'待审批','已审批','已驳回','已撤回'"
- // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
- // @Param SellerId query string false "选择的销售id"
- // @Param Keyword query string false "搜索关键字"
- // @Param KeywordEq query string false "搜索关键字(全等)"
- // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
- // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
- // @Success 200 {object} contract.ContractApprovalListResp
- // @router /list [get]
- func (c *ContractApprovalCommon) List() {
- sysUser := c.AdminWx
- //合同类型、产品类型、合同状态、更新时间、所选销售
- //关键字:合同编号、客户名称,社会信用码
- contractType := c.GetString("ContractType")
- status := c.GetString("Status")
- productId, _ := c.GetInt("ProductId")
- sellerIds := c.GetString("SellerId")
- keyword := c.GetString("Keyword")
- keywordEq := c.GetString("KeywordEq")
- modifyStartTime := c.GetString("ModifyStartTime")
- modifyEndTime := c.GetString("ModifyEndTime")
- childCondition := ""
- condition := ""
- childPars := make([]interface{}, 0)
- pars := make([]interface{}, 0)
- ////如果不是超管或者合规,那么只能查看自己的合同
- //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //权益管理员
- // condition += ` AND c.product_id = ? `
- // pars = append(pars, 2)
- //} else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN { //ficc管理员
- // condition += ` AND c.product_id = ? `
- // pars = append(pars, 1)
- //} else {
- // if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
- // condition += ` AND c.seller_id = ? `
- // pars = append(pars, sysUser.AdminId)
- // }
- //}
- //join表字段
- joinCondition := " and a.curr_node_id=d.node_id"
- //归属
- if status == "待审批" {
- condition += ` AND ( (((c.seller_id = ? and a.start_node_id = a.curr_node_id) OR (d.approve_user_id = ? and a.curr_node_id=d.node_id)) and d.status="待审批") or (d.approve_user_id = ? and a.curr_node_id > d.node_id and d.node_type="cc") ) `
- joinCondition = ``
- pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId)
- } else if status == "处理中" {
- condition += ` AND ((c.seller_id = ? and a.start_node_id != a.curr_node_id) OR (d.approve_user_id = ? and a.curr_node_id > d.node_id and d.node_type!="cc")) and c.status="待审批" `
- joinCondition = " and a.curr_node_id!=d.node_id"
- pars = append(pars, sysUser.AdminId, sysUser.AdminId)
- } else {
- condition += ` AND (c.seller_id = ? or (d.approve_user_id = ? and d.node_id <= a.curr_node_id))`
- pars = append(pars, sysUser.AdminId, sysUser.AdminId)
- }
- //合同类型、、更新时间、所选销售
- //关键字:合同编号、客户名称,社会信用码
- if contractType != "" {
- condition += ` AND c.contract_type = ? `
- pars = append(pars, contractType)
- }
- //审批状态
- fmt.Println(status)
- if status != "" {
- if status == "已审批" {
- condition += ` AND c.status in ("已审批","已驳回") `
- } else if status == "其它" {
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- condition += ` AND c.status in ("已撤回","已作废","已解约") `
- } else {
- condition += ` AND c.status in ("已作废","已解约") `
- }
- } else {
- condition += ` AND c.status = ? `
- if status == "处理中" {
- pars = append(pars, "待审批")
- } else {
- pars = append(pars, status)
- }
- }
- } else {
- //childCondition += ` AND status != "已撤回" `
- condition += ` AND c.status not in ("已撤回","待提交") `
- }
- //产品类型
- if productId > 0 {
- condition += ` AND c.product_id = ? `
- pars = append(pars, productId)
- }
- //所选销售
- if sellerIds != "" {
- condition += ` AND c.seller_id IN (` + sellerIds + `) `
- }
- //更新开始时间
- //更新开始时间
- if modifyStartTime != "" {
- condition += ` AND a.modify_time >= ? `
- pars = append(pars, modifyStartTime)
- }
- //更新结束时间
- if modifyEndTime != "" {
- condition += ` AND a.modify_time <= ? `
- pars = append(pars, modifyEndTime)
- }
- //关键字
- if keyword != "" {
- condition += ` AND (c.contract_code LIKE '%` + keyword + `%' OR c.company_name LIKE '%` + keyword + `%' OR c.credit_code LIKE '%` + keyword + `%' ) `
- }
- //关键字(全等)
- if keywordEq != "" {
- condition += ` AND c.company_name =? `
- pars = append(pars, keywordEq)
- }
- pageSize, _ := c.GetInt("PageSize")
- currentIndex, _ := c.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var total int
- var list []*contract_approval.ContractApprovalList
- if status != "待审批" && status != "处理中" {
- tmpTotal, err := contract_approval.GetContractApprovalListCountV2(childCondition, condition, childPars, pars)
- if err != nil {
- c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
- return
- }
- orderBy := ` modify_time desc `
- switch status {
- case "已签回":
- orderBy = ` check_back_file_time desc `
- case "已撤回":
- orderBy = ` c.modify_time desc `
- case "已作废":
- orderBy = ` c.invalid_time desc `
- }
- tmpList, err := contract_approval.GetContractApprovalListV2(childCondition, condition, orderBy, childPars, pars, startSize, pageSize)
- if err != nil {
- c.FailWithMessage("获取审批列表失败!", "获取审批列表失败,Err:"+err.Error())
- return
- }
- total = tmpTotal
- list = tmpList
- } else {
- tmpTotal, err := contract_approval.GetContractApprovalListCount(childCondition, condition, joinCondition, childPars, pars)
- if err != nil {
- c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
- return
- }
- tmpList, err := contract_approval.GetContractApprovalList(childCondition, condition, joinCondition, childPars, pars, startSize, pageSize)
- if err != nil {
- c.FailWithMessage("获取审批列表失败!", "获取审批列表失败,Err:"+err.Error())
- return
- }
- total = tmpTotal
- list = tmpList
- }
- if len(list) > 0 {
- contractApprovalIdSlice := make([]string, 0)
- for i := 0; i < len(list); i++ {
- contractApprovalIdSlice = append(contractApprovalIdSlice, strconv.Itoa(list[i].ContractApprovalId))
- }
- contractApprovalIdStr := strings.Join(contractApprovalIdSlice, ",")
- //获取审批流列表数据
- contractApprovalRecordList, err := contract_approval_record.GetContractApprovalRecordList(contractApprovalIdStr, sysUser.AdminId)
- if err != nil {
- c.FailWithMessage("获取审批列表失败!", "获取审批列表失败,Err:"+err.Error())
- return
- }
- contractApprovalRecordMap := make(map[int]*contract_approval_record.ContractApprovalRecord)
- for i := 0; i < len(contractApprovalRecordList); i++ {
- contractApprovalRecordMap[contractApprovalRecordList[i].ContractApprovalId] = contractApprovalRecordList[i]
- }
- for i := 0; i < len(list); i++ {
- item := list[i]
- list[i].StartDateStr = item.StartDate.Format(utils.FormatDate)
- list[i].EndDateStr = item.EndDate.Format(utils.FormatDate)
- list[i].CreateTimeStr = item.CreateTime.Format(utils.FormatDateTime)
- list[i].ModifyTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
- if item.ApproveStatus == "已审批" || item.ApproveStatus == "已驳回" {
- list[i].ApproveTime = item.ModifyTime
- list[i].ApproveTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
- }
- //list[i].ContractInfo = contractDetail
- //校验最新审批流数据
- //if contractApprovalRecord, has := contractApprovalRecordMap[item.ContractApprovalId]; has {
- // //审批流id
- // list[i].ContractApprovalRecordId = contractApprovalRecord.ContractApprovalRecordId
- // //审批时间
- // list[i].ApproveTime = contractApprovalRecord.ApproveTime
- // list[i].ApproveTimeStr = contractApprovalRecord.ApproveTime.Format(utils.FormatDateTime)
- //
- // ////判断是否处于待审批状态
- // //if contractApprovalRecord.Status == "待审批" {
- // // //如果不是审批者,那么不能审批操作
- // // if contractApprovalRecord.NodeType != "check" {
- // // continue
- // // }
- // // //如果没有指定审批人的话
- // // if contractApprovalRecord.ApproveUserId <= 0 {
- // // //判断是否与审批角色一致,如果一致,那么允许操作审批
- // // if contractApprovalRecord.ApproveRoleTypeCode == sysUser.RoleTypeCode {
- // // list[i].CanApprovalButton = true
- // // }
- // // } else if contractApprovalRecord.ApproveUserId == sysUser.AdminId {
- // // //如果指定审批人就是自己的话,那么操作审批
- // // list[i].CanApprovalButton = true
- // // }
- // //}
- //}
- //合同状态(突然说要改成展示合同状态,那就根据业务需求,改成返回:合同状态咯)
- //list[i].Status = item.ContractStatus
- if item.Status == "待审批" && status == "处理中" {
- list[i].Status = "处理中"
- }
- //如果是代付合同,那么就展示代付合同的审核内容
- if item.ContractBusinessType == "代付合同" {
- item.ApplyContent = "代付合同"
- }
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- c.OkDetailed(contractResp.ContractApprovalListResp{
- List: list,
- Paging: page,
- }, "获取成功")
- }
- // @Title 审批单详情
- // @Description 审批单详情接口
- // @Param ContractApprovalId query int false "审批单id"
- // @Param ContractApprovalRecordId query int false "审批流程单id"
- // @Success 200 {object} contract.ContractDetailResp
- // @router /detail [get]
- func (c *ContractApprovalCommon) Detail() {
- //审批流程单id
- contractApprovalRecordId, _ := c.GetInt("ContractApprovalRecordId")
- if contractApprovalRecordId > 0 {
- c.detailByApprovalRecordId(contractApprovalRecordId)
- return
- }
- //审批单id
- contractApprovalId, _ := c.GetInt("ContractApprovalId")
- //审批单详情
- contractApprovalInfo, err := contract_approval.GetContractApprovalById(contractApprovalId)
- if err != nil {
- c.FailWithMessage("获取审批单失败!", "获取审批单失败,Err:"+err.Error())
- return
- }
- //合同详情
- contractInfo, flowNodeListResp, contractOpButton, err := contractService.GetContractDetailByContractId(contractApprovalInfo.ContractId, c.AdminWx)
- if err != nil {
- c.FailWithMessage("获取合同详情失败!", "获取合同详情失败,ERR:"+err.Error())
- return
- }
- resp := contractResp.ContractDetailResp{
- ContractDetail: contractInfo,
- FlowNodeList: flowNodeListResp,
- OpButton: contractOpButton,
- }
- c.OkDetailed(resp, "获取成功")
- }
- func (c *ContractApprovalCommon) detailByApprovalRecordId(approvalRecordId int) {
- approvalRecordInfo, err := contract_approval_record.GetContractApprovalRecordById(approvalRecordId)
- if err != nil {
- c.FailWithMessage("获取审批流程单失败", "获取审批流程单失败,Err:"+err.Error())
- return
- }
- //审批单详情
- contractApprovalInfo, err := contract_approval.GetContractApprovalById(approvalRecordInfo.ContractApprovalId)
- if err != nil {
- c.FailWithMessage("获取审批单失败", "获取审批单失败,Err:"+err.Error())
- return
- }
- //合同详情
- contractInfo, flowNodeListResp, contractOpButton, err := contractService.GetContractDetailByContractId(contractApprovalInfo.ContractId, c.AdminWx)
- if err != nil {
- c.FailWithMessage("获取合同详情失败!", "获取合同详情失败,ERR:"+err.Error())
- return
- }
- resp := contractResp.ContractDetailResp{
- ContractDetail: contractInfo,
- FlowNodeList: flowNodeListResp,
- OpButton: contractOpButton,
- }
- c.OkDetailed(resp, "获取成功")
- return
- }
- // @Title 驳回审批
- // @Description 驳回审批接口
- // @Param request body contract.RejectReq true "type json string"
- // @Success Ret=200 驳回成功
- // @router /reject [post]
- func (c *ContractApprovalCommon) Reject() {
- var req contractReq.RejectReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- //合同id编号
- contractId := req.ContractId
- if contractId <= 0 {
- c.FailWithMessage("请传入合同编号!", "请传入合同编号!")
- return
- }
- //数据校验
- contractInfo, approvalInfo, approvalRecord, err := contractService.CheckApproveAuth(contractId, c.AdminWx)
- if err != nil {
- c.FailWithMessage("驳回审批失败!", "驳回审批失败,Err:"+err.Error())
- return
- }
- err = contractService.Reject(contractInfo, approvalInfo, approvalRecord, c.AdminWx, req.Remark)
- if err != nil {
- c.FailWithMessage("驳回审批失败!", "驳回审批失败,Err:"+err.Error())
- return
- }
- c.OkWithMessage("驳回成功")
- }
- // @Title 处理审批单
- // @Description 处理审批单
- // @Param request body contract.ApprovedReq true "type json string"
- // @Success Ret=200 申请成功
- // @router /approved [post]
- func (c *ContractApprovalCommon) Approved() {
- var req contractReq.ApprovedReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- //合同id编号
- contractId := req.ContractId
- if contractId <= 0 {
- c.FailWithMessage("请传入合同编号!", "请传入合同编号!")
- return
- }
- //数据校验
- contractInfo, approvalInfo, approvalRecord, err := contractService.CheckApproveAuth(contractId, c.AdminWx)
- if err != nil {
- c.FailWithMessage("驳回审批失败!", "驳回审批失败,Err:"+err.Error())
- return
- }
- err = contractService.Approved(contractInfo, approvalInfo, approvalRecord, c.AdminWx, req.Remark)
- if err != nil {
- c.FailWithMessage("审核失败!", "审核失败,Err:"+err.Error())
- return
- }
- c.OkWithMessage("审核通过")
- }
|