Browse Source

Merge branch 'small_291'

xiziwen 2 days ago
parent
commit
65aa05e9c4

+ 307 - 7
controllers/seal/seal_approval.go

@@ -2,14 +2,24 @@ package seal
 
 import (
 	"encoding/json"
+	"errors"
+	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"github.com/tealeg/xlsx"
 	"hongze/hz_crm_api/controllers"
 	"hongze/hz_crm_api/models"
+	"hongze/hz_crm_api/models/company"
+	"hongze/hz_crm_api/models/contract"
+	sealModels "hongze/hz_crm_api/models/seal"
 	"hongze/hz_crm_api/models/seal/request"
 	"hongze/hz_crm_api/models/seal/response"
 	"hongze/hz_crm_api/services/seal"
 	"hongze/hz_crm_api/utils"
+	"os"
+	"path/filepath"
+	"strconv"
 	"strings"
+	"time"
 )
 
 // 用印审批管理
@@ -28,6 +38,8 @@ type SealApprovalController struct {
 // @Param   StartTime   	query   string  false	"提交开始时间"
 // @Param   EndTime   		query   string  false	"提交结束时间"
 // @Param   Keyword   		query   string  false	"搜索关键词(客户名称/社会信用码)"
+// @Param   IsExport   		query   bool  	false   "是否导出excel,默认是false"
+// @Param   AffiliatedCompany   query   string  	false   "归属公司"
 // @Success 200 {object} response.SealApprovalListResp
 // @router /getApprovalPageList [get]
 func (this *SealApprovalController) List() {
@@ -55,7 +67,7 @@ func (this *SealApprovalController) List() {
 		currentIndex = 1
 	}
 	startSize = paging.StartIndex(currentIndex, pageSize)
-
+	isExport, _ := this.GetBool("IsExport", false)
 	// 筛选条件
 	condition := ""
 	joinCondition := " AND a.curr_node_id = d.node_id" // contract_approval和contract_approval_record的join条件
@@ -158,6 +170,19 @@ func (this *SealApprovalController) List() {
 		pars = append(pars, keywords, keywords, keywords)
 	}
 
+	// 归属公司
+	affiliatedCompany := this.GetString("AffiliatedCompany")
+	if affiliatedCompany != "" {
+		condition += ` AND c.affiliated_company = ?`
+		pars = append(pars, affiliatedCompany)
+	}
+
+	//导出excel
+	if isExport {
+		ApprovalListExport(this, condition, joinCondition, pars, br)
+		return
+	}
+
 	// 列表
 	listData, listTotal, err := seal.GetSealApprovalPageList(condition, joinCondition, pars, startSize, pageSize, sysUser)
 	if err != nil {
@@ -176,6 +201,242 @@ func (this *SealApprovalController) List() {
 	}
 }
 
+// ApprovalListExport 审批列表导出
+func ApprovalListExport(this *SealApprovalController, condition, joinCondition string, pars []interface{}, br *models.BaseResponse) {
+	list, err := sealModels.GetSealApprovalList(condition, joinCondition, pars)
+	if err != nil {
+		br.Msg = "审批列表获取失败!"
+		br.ErrMsg = "审批列表获取失败!" + err.Error()
+		return
+	}
+	////超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
+	//resp := new(cygx.CanDownload)
+	//adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
+	//if errAdmin != nil {
+	//	br.Msg = "获取失败"
+	//	br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
+	//	return
+	//}
+	//if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
+	//	resp.IsCanDownload = true
+	//}
+
+	if len(list) > 0 {
+		// 取出所有列表的关联合同id
+		contractIdSlice := make([]string, 0)
+		contractApprovalIdSlice := make([]string, 0)
+		for i := 0; i < len(list); i++ {
+			contractIdSlice = append(contractIdSlice, strconv.Itoa(list[i].ContractId))
+			contractApprovalIdSlice = append(contractApprovalIdSlice, strconv.Itoa(list[i].ContractApprovalId))
+		}
+
+		// 获取所有关联的合同列表
+		selfContractMap := make(map[int]*contract.ContractList)
+		{
+			if len(contractIdSlice) > 0 {
+				contractIdStr := strings.Join(contractIdSlice, ",")
+				contractList, tempErr := contract.GetContractListByContractIds(contractIdStr)
+				if tempErr != nil {
+					err = errors.New(fmt.Sprint("获取合同失败,Err:"+tempErr.Error(), err))
+					return
+				}
+				for i := 0; i < len(contractList); i++ {
+					selfContractMap[contractList[i].ContractId] = contractList[i]
+				}
+			}
+		}
+
+		selfContractApprovalRecordMap := make(map[int][]*contract.ContractApprovalRecord)
+		{
+			if len(contractApprovalIdSlice) > 0 {
+				contractApprovalIdStr := strings.Join(contractApprovalIdSlice, ",")
+				contractApprovalList, tempErr := contract.GetContractApprovalRecordListByContractApprovalIds(contractApprovalIdStr)
+				if tempErr != nil {
+					err = errors.New(fmt.Sprint("获取合同审批记录失败,Err:"+tempErr.Error(), err))
+					return
+				}
+				for i := 0; i < len(contractApprovalList); i++ {
+					selfContractApprovalRecordMap[contractApprovalList[i].ContractApprovalId] = append(selfContractApprovalRecordMap[contractApprovalList[i].ContractApprovalId], contractApprovalList[i])
+				}
+			}
+		}
+
+		for i, v := range list {
+			// 合同编码
+			if selfContract, has := selfContractMap[v.ContractId]; has {
+				list[i].ContractCode = selfContract.ContractCode
+			}
+
+			// 审批人和抄送人
+			if recordList, ok := selfContractApprovalRecordMap[v.ContractApprovalId]; ok {
+				keySort := make([]int, 0)
+				flowNodeMap := make(map[int][]contract.ContractApprovalRecord, 0)
+				for _, approvalRecord := range recordList {
+					if tmpFlowNodeList, ok := flowNodeMap[approvalRecord.NodeId]; ok {
+						flowNodeMap[approvalRecord.NodeId] = append(tmpFlowNodeList, *approvalRecord)
+					} else {
+						tmpFlowNodeList := make([]contract.ContractApprovalRecord, 1)
+						tmpFlowNodeList[0] = *approvalRecord
+						flowNodeMap[approvalRecord.NodeId] = tmpFlowNodeList
+
+						keySort = append(keySort, approvalRecord.NodeId)
+					}
+				}
+				approversList := make([][]string, 0)
+				ccList := make([][]string, 0)
+				for _, key := range keySort {
+					approver := make([]string, 0)
+					cc := make([]string, 0)
+					if node, ok := flowNodeMap[key]; ok {
+						for _, vv := range node {
+							if vv.NodeType == "check" {
+								approver = append(approver, vv.ApproveUserName)
+							} else if vv.NodeType == "cc" {
+								cc = append(cc, vv.ApproveUserName)
+							}
+						}
+						if len(approver) > 0 {
+							approversList = append(approversList, approver)
+						}
+						if len(cc) > 0 {
+							ccList = append(ccList, cc)
+						}
+					}
+				}
+				if len(approversList) > 0 {
+					list[i].FirstLevelApprovers = strings.Join(approversList[0], ",")
+				}
+				if len(ccList) > 0 {
+					list[i].FirstLevelCC = strings.Join(ccList[0], ",")
+				}
+				if len(approversList) > 1 {
+					list[i].SecondLevelApprovers = strings.Join(approversList[1], ",")
+				}
+				if len(ccList) > 1 {
+					list[i].SecondLevelCC = strings.Join(ccList[1], ",")
+				}
+				if len(approversList) > 2 {
+					list[i].ThirdLevelApprovers = strings.Join(approversList[2], ",")
+				}
+				if len(ccList) > 2 {
+					list[i].ThirdLevelCC = strings.Join(ccList[2], ",")
+				}
+			}
+		}
+	}
+	//创建excel
+	dir, err := os.Executable()
+	exPath := filepath.Dir(dir)
+	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	xlsxFile := xlsx.NewFile()
+	if err != nil {
+		br.Msg = "生成文件失败"
+		br.ErrMsg = "生成文件失败"
+		return
+	}
+	style := xlsx.NewStyle()
+	alignment := xlsx.Alignment{
+		Horizontal: "center",
+		Vertical:   "center",
+		WrapText:   true,
+	}
+	style.Alignment = alignment
+	style.ApplyAlignment = true
+
+	sheetName := "审批列表"
+	sheet, err := xlsxFile.AddSheet(sheetName)
+	if err != nil {
+		br.Msg = "新增Sheet失败"
+		br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
+		return
+	}
+	//标头
+	rowTitle := sheet.AddRow()
+	cellA := rowTitle.AddCell()
+	cellA.Value = "归属公司"
+	cellB := rowTitle.AddCell()
+	cellB.Value = "客户名称"
+	cellC := rowTitle.AddCell()
+	cellC.Value = "社会信用码"
+	cellD := rowTitle.AddCell()
+	cellD.Value = "用印用途"
+	cellE := rowTitle.AddCell()
+	cellE.Value = "合同编号"
+	cellF := rowTitle.AddCell()
+	cellF.Value = "合同类型"
+	cellG := rowTitle.AddCell()
+	cellG.Value = "加盖印章"
+	cellH := rowTitle.AddCell()
+	cellH.Value = "所属销售"
+	cellI := rowTitle.AddCell()
+	cellI.Value = "提交时间"
+	cellJ := rowTitle.AddCell()
+	cellJ.Value = "用印状态"
+	cellK := rowTitle.AddCell()
+	cellK.Value = "一级审批人"
+	cellL := rowTitle.AddCell()
+	cellL.Value = "一级抄送人"
+	cellM := rowTitle.AddCell()
+	cellM.Value = "二级审批人"
+	cellN := rowTitle.AddCell()
+	cellN.Value = "二级抄送人"
+	cellO := rowTitle.AddCell()
+	cellO.Value = "三级审批人"
+	cellP := rowTitle.AddCell()
+	cellP.Value = "三级抄送人"
+
+	for _, v := range list {
+		row := sheet.AddRow()
+		cellA := row.AddCell()
+		cellA.Value = v.AffiliatedCompany
+		cellB := row.AddCell()
+		cellB.Value = v.CompanyName
+		cellC := row.AddCell()
+		cellC.Value = v.CreditCode
+		cellD := row.AddCell()
+		cellD.Value = v.Use
+		cellE := row.AddCell()
+		cellE.Value = v.ContractCode
+		cellF := row.AddCell()
+		cellF.Value = v.ContractType
+		cellG := row.AddCell()
+		cellG.Value = v.SealType
+		cellH := row.AddCell()
+		cellH.Value = v.ApplyUserName
+		cellI := row.AddCell()
+		cellI.Value = v.CreateTime.Format(utils.FormatDateTime)
+		cellJ := row.AddCell()
+		cellJ.Value = v.Status
+		cellK := row.AddCell()
+		cellK.Value = v.FirstLevelApprovers
+		cellL := row.AddCell()
+		cellL.Value = v.FirstLevelCC
+		cellM := row.AddCell()
+		cellM.Value = v.SecondLevelApprovers
+		cellN := row.AddCell()
+		cellN.Value = v.SecondLevelCC
+		cellO := row.AddCell()
+		cellO.Value = v.ThirdLevelApprovers
+		cellP := row.AddCell()
+		cellP.Value = v.ThirdLevelCC
+	}
+
+	err = xlsxFile.Save(downLoadnFilePath)
+	if err != nil {
+		br.Msg = "保存文件失败"
+		br.ErrMsg = "保存文件失败"
+		return
+	}
+	downloadFileName := "审批列表" + ".xlsx"
+	this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
+	defer func() {
+		os.Remove(downLoadnFilePath)
+	}()
+	br.Success = true
+	br.Ret = 200
+	br.IsAddLog = true
+}
+
 // 用印申请
 // @Title 用印申请
 // @Description 用印申请
@@ -204,12 +465,13 @@ func (this *SealApprovalController) Apply() {
 		return
 	}
 	reqVerify := utils.Rules{
-		"Use":         {utils.NotEmpty()},
-		"CompanyName": {utils.NotEmpty()},
-		"CreditCode":  {utils.NotEmpty()},
-		"ServiceType": {utils.NotEmpty()},
-		"SealType":    {utils.NotEmpty()},
-		"FileUrls":    {utils.NotEmpty()},
+		"Use":               {utils.NotEmpty()},
+		"CompanyName":       {utils.NotEmpty()},
+		"CreditCode":        {utils.NotEmpty()},
+		"ServiceType":       {utils.NotEmpty()},
+		"SealType":          {utils.NotEmpty()},
+		"FileUrls":          {utils.NotEmpty()},
+		"AffiliatedCompany": {utils.NotEmpty()},
 	}
 
 	err = utils.Verify(req, reqVerify, utils.LANG_CN)
@@ -294,6 +556,11 @@ func (this *SealApprovalController) Edit() {
 		br.ErrMsg = "合同附件不能为空"
 		return
 	}
+	if req.AffiliatedCompany == "" {
+		br.Msg = "归属公司不能为空"
+		br.ErrMsg = "归属公司不能为空"
+		return
+	}
 
 	// 编辑用印
 	err = seal.EditApply(this.SysUser, req)
@@ -693,3 +960,36 @@ func (this *SealApprovalController) OperationList() {
 		List: list,
 	}
 }
+
+// 关联公司列表
+// @Title 关联公司列表
+// @Description 关联公司列表
+// @Success 200 {object} response.SealApprovalListResp
+// @router /getAffiliatedCompany [get]
+func (this *SealApprovalController) AffiliatedCompanyList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser is Empty"
+		br.Ret = 408
+		return
+	}
+	crmConfig, err := company.GetConfigDetailByCode("affiliated_company")
+	if err != nil {
+		br.Msg = "获取配置失败"
+		br.ErrMsg = "获取配置失败"
+		br.IsSendEmail = false
+		return
+	}
+	list := strings.Split(crmConfig.ConfigValue, ",")
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = list
+}

+ 31 - 29
models/seal/request/seal_approval.go

@@ -2,56 +2,58 @@ package request
 
 // 用印审批申请请求
 type SealApprovalApplyReq struct {
-	ContractId     int      `description:"系统合同id"`
-	Use            string   `description:"用印用途,枚举值:'销售合同','渠道合同','付款通知函','招投标','战略合作协议','代付合同','总对总协议';默认:销售合同"`
-	CompanyName    string   `description:"客户名称,甲方名称,长度32位"`
-	UseCompanyName string   `description:"实际适用方客户名称,长度32位"`
-	CreditCode     string   `description:"社会统一信用代码,长度64位"`
-	ServiceType    string   `description:"业务类型,枚举值:'新签合同','续约合同','补充协议';默认:新签合同"`
-	SealType       string   `description:"加盖印章类型,多选,逗号拼接,值:'合同章','公章','法人章'"`
-	Remark         string   `description:"备注,长度255位"`
-	FileUrls       []string `description:"多个文件附件地址"`
-	FileNum        int      `description:"文件份数"`
+	ContractId        int      `description:"系统合同id"`
+	Use               string   `description:"用印用途,枚举值:'销售合同','渠道合同','付款通知函','招投标','战略合作协议','代付合同','总对总协议';默认:销售合同"`
+	CompanyName       string   `description:"客户名称,甲方名称,长度32位"`
+	UseCompanyName    string   `description:"实际适用方客户名称,长度32位"`
+	CreditCode        string   `description:"社会统一信用代码,长度64位"`
+	ServiceType       string   `description:"业务类型,枚举值:'新签合同','续约合同','补充协议';默认:新签合同"`
+	SealType          string   `description:"加盖印章类型,多选,逗号拼接,值:'合同章','公章','法人章'"`
+	Remark            string   `description:"备注,长度255位"`
+	FileUrls          []string `description:"多个文件附件地址"`
+	FileNum           int      `description:"文件份数"`
+	AffiliatedCompany string   `description:"归属公司"`
 }
 
 // 用印审批编辑请求
 type SealApprovalEditReq struct {
-	SealId         int      `description:"用印id"`
-	ContractId     int      `description:"系统合同id"`
-	Use            string   `description:"用印用途,枚举值:'销售合同', '渠道合同', '付款通知函', '招投标', '战略合作协议';默认:销售合同"`
-	CompanyName    string   `description:"客户名称,甲方名称,长度32位"`
-	UseCompanyName string   `description:"实际适用方客户名称,长度32位"`
-	CreditCode     string   `description:"社会统一信用代码,长度64位"`
-	ServiceType    string   `description:"业务类型,枚举值:'新签合同','续约合同','补充协议';默认:新签合同"`
-	SealType       string   `description:"加盖印章类型,多选,逗号拼接,值:'合同章','公章','法人章'"`
-	Remark         string   `description:"备注,长度255位"`
-	FileUrls       []string `description:"多个文件附件地址"`
-	FileNum        int      `description:"文件份数"`
+	SealId            int      `description:"用印id"`
+	ContractId        int      `description:"系统合同id"`
+	Use               string   `description:"用印用途,枚举值:'销售合同', '渠道合同', '付款通知函', '招投标', '战略合作协议';默认:销售合同"`
+	CompanyName       string   `description:"客户名称,甲方名称,长度32位"`
+	UseCompanyName    string   `description:"实际适用方客户名称,长度32位"`
+	CreditCode        string   `description:"社会统一信用代码,长度64位"`
+	ServiceType       string   `description:"业务类型,枚举值:'新签合同','续约合同','补充协议';默认:新签合同"`
+	SealType          string   `description:"加盖印章类型,多选,逗号拼接,值:'合同章','公章','法人章'"`
+	Remark            string   `description:"备注,长度255位"`
+	FileUrls          []string `description:"多个文件附件地址"`
+	FileNum           int      `description:"文件份数"`
+	AffiliatedCompany string   `description:"归属公司"`
 }
 
 // 用印审批撤回请求
 type SealApprovalCancelReq struct {
-	SealId		int		`description:"用印ID"`
+	SealId int `description:"用印ID"`
 }
 
 // 用印审批删除请求
 type SealApprovalDelReq struct {
-	SealId		int		`description:"用印ID"`
+	SealId int `description:"用印ID"`
 }
 
 // 用印审批作废请求
 type SealApprovalInvalidReq struct {
-	SealId		int		`description:"用印ID"`
+	SealId int `description:"用印ID"`
 }
 
 // 用印审批通过请求
 type SealApplyApprovedReq struct {
-	SealId	int		`description:"用印id"`
-	Remark	string 	`description:"备注字段"`
+	SealId int    `description:"用印id"`
+	Remark string `description:"备注字段"`
 }
 
 // 用印审批驳回请求
 type SealApplyRejectReq struct {
-	SealId	int		`description:"用印id"`
-	Remark	string 	`description:"驳回理由"`
-}
+	SealId int    `description:"用印id"`
+	Remark string `description:"驳回理由"`
+}

+ 65 - 1
models/seal/seal.go

@@ -33,6 +33,7 @@ type Seal struct {
 	ModifyTime        time.Time `description:"最近一次修改时间"`
 	CreateTime        time.Time `description:"添加时间"`
 	CheckBackFileTime time.Time `description:"签回用印附件时间"`
+	AffiliatedCompany string    `description:"归属公司"`
 }
 
 var EnumUse = []string{"销售合同", "渠道合同", "付款通知函", "招投标", "战略合作协议", "代付合同", "总对总协议"}
@@ -193,13 +194,14 @@ type SealApprovalItem struct {
 	InvalidTimeStr       string    `description:"作废时间(字符串)"`
 	CheckBackFileTimeStr string    `description:"签回用印附件时间(字符串)"`
 	ContractCode         string    `description:"合同编码"`
+	AffiliatedCompany    string    `description:"归属公司"`
 }
 
 // GetSealApprovalListByWhere 获取用印审批列表-分页
 func GetSealApprovalListByWhere(condition, joinCondition string, pars []interface{}, startSize, pageSize int) (list []*SealApprovalItem, total int, err error) {
 	o := orm.NewOrm()
 	fields := `a.contract_approval_id,c.contract_id,a.apply_content,a.approve_remark,a.apply_user_id,a.apply_user_name,a.curr_node_id,a.start_node_id,c.create_time,a.modify_time,a.status approval_status,
-			   c.status,c.seal_id,c.seal_type,c.service_type contract_type,c.use,c.company_name,c.file_url,c.approve_time,c.invalid_time,c.code,c.credit_code,c.check_back_file_time,c.check_back_file_url`
+			   c.status,c.seal_id,c.seal_type,c.service_type contract_type,c.use,c.company_name,c.file_url,c.approve_time,c.invalid_time,c.code,c.credit_code,c.check_back_file_time,c.check_back_file_url,c.affiliated_company `
 	sql := `SELECT ` + fields + ` from contract_approval a JOIN ( SELECT max( contract_approval_id ) max_id,contract_id FROM contract_approval where 1=1 and approval_type = "seal" `
 	sql += ` GROUP BY contract_id ) b on a.contract_approval_id=b.max_id
 	JOIN seal c ON c.seal_id = a.contract_id 
@@ -217,3 +219,65 @@ WHERE c.is_delete = 0 AND a.approval_type="seal" `
 
 	return
 }
+
+type SealApprovaExportlItem struct {
+	ContractApprovalId       int `description:"审批单ID"`
+	ContractId               int `description:"合同ID"`
+	ContractApprovalRecordId int `description:"审批流ID"`
+	//ContractCode             string                  `description:"合同编号"`
+	Use            string                  `description:"用印用途,枚举值:'销售合同','渠道合同','付款通知函','招投标','战略合作协议'"`
+	ContractType   string                  `description:"合同类型,枚举值:'新签合同','续约合同','补充协议','代付合同'"`
+	Status         string                  `description:"合同状态,枚举值:待审批','已审批','已驳回','已撤回','已签回',默认待审批"`
+	ApproveStatus  string                  `json:"-" description:"审批单状态,枚举值:待审批','已审批','已驳回','已撤回',默认待审批"`
+	ApplyContent   string                  `description:"申请内容"`
+	ApplyUserId    int                     `description:"申请人ID"`
+	ApplyUserName  string                  `description:"申请人名称"`
+	ContractDetail string                  `json:"-" description:"提交审批时的合同信息;用印快照"`
+	ContractInfo   contract.ContractDetail `json:"-" description:"提交审批时的合同信息;用印快照"`
+	ApproveRemark  string                  `description:"审核备注"`
+	SealType       string                  `description:"用印类型"`
+	CompanyName    string                  `description:"客户名称"`
+	FileUrl        string                  `description:"合同下载地址"`
+	CurrNodeId     int                     `description:"当前审批节点id"`
+	StartNodeId    int                     `description:"开始审批节点id"`
+	//UserId                   int                     `description:"申请人id"`
+	//UserName                 string                  `description:"申请人名称"`
+	SealId               int       `description:"用印审批ID"`
+	CreateTime           time.Time `description:"发起审批的时间"`
+	ModifyTime           time.Time `description:"最后一次修改的时间"`
+	ApproveTime          time.Time `description:"审批时间"`
+	InvalidTime          time.Time `description:"作废时间"`
+	CheckBackFileUrl     string    `description:"签回附件地址"`
+	CheckBackFileTime    time.Time `description:"签回用印附件时间"`
+	CreditCode           string    `description:"社会信用码"`
+	CreateTimeStr        string    `description:"发起审批的时间(字符串)"`
+	ModifyTimeStr        string    `description:"最后一次修改的时间(字符串)"`
+	ApproveTimeStr       string    `description:"审批时间(字符串)"`
+	InvalidTimeStr       string    `description:"作废时间(字符串)"`
+	CheckBackFileTimeStr string    `description:"签回用印附件时间(字符串)"`
+	ContractCode         string    `description:"合同编码"`
+	AffiliatedCompany    string    `description:"归属公司"`
+	FirstLevelApprovers  string    `description:"一级审批人"`
+	SecondLevelApprovers string    `description:"二级审批人"`
+	ThirdLevelApprovers  string    `description:"三级审批人"`
+	FirstLevelCC         string    `description:"一级抄送人"`
+	SecondLevelCC        string    `description:"二级抄送人"`
+	ThirdLevelCC         string    `description:"三级抄送人"`
+}
+
+// GetSealApprovalList 获取用印审批列表
+func GetSealApprovalList(condition, joinCondition string, pars []interface{}) (list []*SealApprovaExportlItem, err error) {
+	o := orm.NewOrm()
+	fields := `a.contract_approval_id,c.contract_id,a.apply_content,a.approve_remark,a.apply_user_id,a.apply_user_name,a.curr_node_id,a.start_node_id,c.create_time,a.modify_time,a.status approval_status,
+			   c.status,c.seal_id,c.seal_type,c.service_type contract_type,c.use,c.company_name,c.file_url,c.approve_time,c.invalid_time,c.code,c.credit_code,c.check_back_file_time,c.check_back_file_url,c.affiliated_company `
+	sql := `SELECT ` + fields + ` from contract_approval a JOIN ( SELECT max( contract_approval_id ) max_id,contract_id FROM contract_approval where 1=1 and approval_type = "seal" `
+	sql += ` GROUP BY contract_id ) b on a.contract_approval_id=b.max_id
+	JOIN seal c ON c.seal_id = a.contract_id 
+	JOIN contract_approval_record d on a.contract_approval_id=d.contract_approval_id ` + joinCondition + `
+WHERE c.is_delete = 0 AND a.approval_type="seal" `
+	sql += condition
+	sql += ` group by c.seal_id order by c.create_time desc`
+	_, err = o.Raw(sql, pars).QueryRows(&list)
+
+	return
+}

+ 9 - 0
routers/commentsRouter.go

@@ -7900,6 +7900,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/seal:SealApprovalController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/seal:SealApprovalController"],
+        beego.ControllerComments{
+            Method: "AffiliatedCompanyList",
+            Router: `/getAffiliatedCompany`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/seal:SealApprovalController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/seal:SealApprovalController"],
         beego.ControllerComments{
             Method: "List",

+ 7 - 5
services/seal/seal.go

@@ -123,7 +123,7 @@ func ApplySeal(sysUser *system.Admin, req request.SealApprovalApplyReq) (err err
 	}()
 
 	// 添加用印
-	sealInfo, err := addSeal(sysUser.AdminId, req.ContractId, req.FileNum, sysUser.RealName, req.Use, req.CompanyName, req.UseCompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrls)
+	sealInfo, err := addSeal(sysUser.AdminId, req.ContractId, req.FileNum, sysUser.RealName, req.Use, req.CompanyName, req.UseCompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrls, req.AffiliatedCompany)
 	if err != nil {
 		return
 	}
@@ -140,7 +140,7 @@ func ApplySeal(sysUser *system.Admin, req request.SealApprovalApplyReq) (err err
 }
 
 // addSeal 新增用印
-func addSeal(userId, contractId, fileNum int, userName, use, companyName, useCompanyName, creditCode, serviceType, sealType, remark string, fileUrls []string) (sealInfo *seal.Seal, err error) {
+func addSeal(userId, contractId, fileNum int, userName, use, companyName, useCompanyName, creditCode, serviceType, sealType, remark string, fileUrls []string, affiliatedCompany string) (sealInfo *seal.Seal, err error) {
 	if !strings.Contains(strings.Join(seal.EnumUse, ","), use) {
 		err = errors.New("用印用途异常")
 		return
@@ -177,6 +177,7 @@ func addSeal(userId, contractId, fileNum int, userName, use, companyName, useCom
 		ContractId:     contractId,
 		ModifyTime:     now,
 		CreateTime:     now,
+		AffiliatedCompany:  affiliatedCompany,
 	}
 	err = seal.AddSeal(sealInfo)
 	if err != nil {
@@ -213,7 +214,7 @@ func EditApply(sysUser *system.Admin, req request.SealApprovalEditReq) (err erro
 	}()
 
 	// 编辑用印
-	sealInfo, err := editSeal(req.SealId, sysUser.AdminId, req.ContractId, req.FileNum, req.Use, req.CompanyName, req.UseCompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrls)
+	sealInfo, err := editSeal(req.SealId, sysUser.AdminId, req.ContractId, req.FileNum, req.Use, req.CompanyName, req.UseCompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrls, req.AffiliatedCompany)
 	if err != nil {
 		return
 	}
@@ -230,7 +231,7 @@ func EditApply(sysUser *system.Admin, req request.SealApprovalEditReq) (err erro
 }
 
 // editSeal 编辑用印申请
-func editSeal(sealId, userId, contractId, fileNum int, use, companyName, userCompanyName, creditCode, serviceType, sealType, remark string, fileUrls []string) (sealInfo *seal.Seal, err error) {
+func editSeal(sealId, userId, contractId, fileNum int, use, companyName, userCompanyName, creditCode, serviceType, sealType, remark string, fileUrls []string, affiliatedCompany string) (sealInfo *seal.Seal, err error) {
 	if !strings.Contains(strings.Join(seal.EnumUse, ","), use) {
 		err = errors.New("用印用途异常")
 		return
@@ -276,7 +277,8 @@ func editSeal(sealId, userId, contractId, fileNum int, use, companyName, userCom
 	sealInfo.ModifyTime = now
 	sealInfo.CreateTime = now // 更新提交时间
 	sealInfo.Status = "待提交"
-	err = sealInfo.Update([]string{"Use", "CompanyName", "UseCompanyName", "CreditCode", "ServiceType", "SealType", "Remark", "FileUrl", "FileNum", "ContractId", "ModifyTime", "CreateTime", "Status"})
+	sealInfo.AffiliatedCompany = affiliatedCompany
+	err = sealInfo.Update([]string{"Use", "CompanyName", "UseCompanyName", "CreditCode", "ServiceType", "SealType", "Remark", "FileUrl", "FileNum", "ContractId", "ModifyTime", "CreateTime", "Status", "AffiliatedCompany"})
 	if err != nil {
 		return
 	}