ソースを参照

用印申请 允许多附件上传,给销售发送已签回模版消息

xiexiaoyuan 2 年 前
コミット
f31a558747

+ 6 - 6
controllers/seal.go

@@ -55,12 +55,12 @@ func (c *SealCommon) Add() {
 		c.FailWithMessage("印章类型不能为空", "印章类型不能为空")
 		return
 	}
-	if req.FileUrl == "" {
+	if len(req.FileUrls) == 0 {
 		c.FailWithMessage("合同附件不能为空", "合同附件不能为空")
 		return
 	}
 
-	sealInfo, err := sealService.AddSeal(c.AdminWx.AdminId, req.ContractId, req.FileNum, c.AdminWx.RealName, req.Use, req.UseCompanyName, req.CompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrl)
+	sealInfo, err := sealService.AddSeal(c.AdminWx.AdminId, req.ContractId, req.FileNum, c.AdminWx.RealName, req.Use, req.UseCompanyName, req.CompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrls)
 	if err != nil {
 		c.FailWithMessage("用印添加失败", err.Error())
 		return
@@ -115,12 +115,12 @@ func (c *SealCommon) Edit() {
 		c.FailWithMessage("印章类型不能为空", "印章类型不能为空")
 		return
 	}
-	if req.FileUrl == "" {
+	if len(req.FileUrls) == 0 {
 		c.FailWithMessage("合同附件不能为空", "合同附件不能为空")
 		return
 	}
 
-	sealInfo, err := sealService.Edit(req.SealId, c.AdminWx.AdminId, req.ContractId, req.FileNum, req.Use, req.CompanyName, req.UseCompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrl, c.AdminWx.RealName)
+	sealInfo, err := sealService.Edit(req.SealId, c.AdminWx.AdminId, req.ContractId, req.FileNum, req.Use, req.CompanyName, req.UseCompanyName, req.CreditCode, req.ServiceType, req.SealType, req.Remark, req.FileUrls, c.AdminWx.RealName)
 	if err != nil {
 		c.FailWithMessage("修改合同失败!", "修改合同失败,Err:"+err.Error())
 		return
@@ -163,7 +163,7 @@ func (c *SealCommon) CheckEdit() {
 		c.FailWithMessage("印章类型不能为空", "印章类型不能为空")
 		return
 	}
-	if req.FileUrl == "" {
+	if len(req.FileUrls) == 0 {
 		c.FailWithMessage("合同附件不能为空", "合同附件不能为空")
 		return
 	}
@@ -172,7 +172,7 @@ func (c *SealCommon) CheckEdit() {
 	sealInfo, approvalInfo, approvalRecord, err := sealService.CheckApproveAuth(sealId, c.AdminWx)
 
 	//合规修改
-	err = sealService.CheckEdit(sealInfo, approvalInfo, approvalRecord, req.FileNum, req.FileUrl, req.Use, req.SealType, req.Remark, c.AdminWx)
+	err = sealService.CheckEdit(sealInfo, approvalInfo, approvalRecord, req.FileNum, req.FileUrls, req.Use, req.SealType, req.Remark, c.AdminWx)
 	if err != nil {
 		c.FailWithMessage("修改合同失败!", "修改合同失败,Err:"+err.Error())
 		return

+ 1 - 0
models/db_init.go

@@ -87,6 +87,7 @@ func init() {
 		new(wx_user.WxUser),
 		new(seal.Seal),                //用印表
 		new(seal.SealOperationRecord), // 用印操作记录表
+		new(seal.Attachment),         //用印附件
 		new(roadshow.RsCalendar),
 		new(roadshow.RsCalendarResearcher),
 		new(roadshow.RsMatters),

+ 27 - 27
models/request/seal/sale.go

@@ -2,41 +2,41 @@ package seal
 
 //新增用印请求
 type AddReq 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位"`
-	FileUrl        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:"文件份数"`
 }
 
 //编辑用印请求
 type EditReq 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位"`
-	FileUrl        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:"文件份数"`
 }
 
 //审批者编辑用印请求
 type CheckEditReq struct {
-	SealId   int    `description:"用印单id"`
-	Use      string `description:"用印用途,枚举值:'销售合同', '渠道合同', '付款通知函', '招投标', '战略合作协议';默认:销售合同"`
-	SealType string `description:"加盖印章类型,枚举值:'合同章', '公章', '法人章';默认:合同章"`
-	Remark   string `description:"备注,长度255位"`
-	FileUrl  string `description:"文件附件地址"`
-	FileNum  int    `description:"文件份数"`
+	SealId   int      `description:"用印单id"`
+	Use      string   `description:"用印用途,枚举值:'销售合同', '渠道合同', '付款通知函', '招投标', '战略合作协议';默认:销售合同"`
+	SealType string   `description:"加盖印章类型,枚举值:'合同章', '公章', '法人章';默认:合同章"`
+	Remark   string   `description:"备注,长度255位"`
+	FileUrls []string `description:"文件附件地址"`
+	FileNum  int      `description:"文件份数"`
 }
 
 // InvalidReq 作废用印请求

+ 5 - 1
models/response/seal/seal.go

@@ -20,11 +20,15 @@ type SealApprovalListResp struct {
 
 //SealDetailResp 审批列表
 type SealDetailResp struct {
-	SealDetail   *seal.Seal                                          `description:"审批单详情"`
+	SealDetail   *SealMoreResp                                          `description:"审批单详情"`
 	FlowNodeList [][]contract_approval_record.ContractApprovalRecord `description:"审批流"`
 	OpButton     OpButton                                            `description:"操作权限"`
 }
 
+type SealMoreResp struct {
+	*seal.Seal
+	FileUrls []string `description:"多个附件"`
+}
 //OpButton 合同操作按钮
 type OpButton struct {
 	Approval   bool `description:"是否有审批权限"`

+ 41 - 0
models/tables/seal/seal_attachment.go

@@ -0,0 +1,41 @@
+package seal
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+//Attachment 用印附件结构体
+type Attachment struct {
+	Id         int       `orm:"column(id);pk"`
+	SealId     int       `description:"用印ID"`
+	FileUrl    string    `description:"文件附件地址"`
+	ModifyTime time.Time `description:"最近一次修改时间"`
+	CreateTime time.Time `description:"添加时间"`
+}
+
+func (a *Attachment) TableName() string {
+	return "seal_attachment"
+}
+//GetAttachmentBySealId 根据用印id获取合同附件信息
+func GetAttachmentBySealId(sealId int) ( list []*Attachment, err error) {
+	o := orm.NewOrm()
+	sql := `select * from seal_attachment where seal_id = ? `
+	_, err = o.Raw(sql, sealId).QueryRows(&list)
+	return
+}
+
+//DelAttachmentBySealId 删除用印相关的合同附件信息
+func DelAttachmentBySealId(sealId int) (err error) {
+	o := orm.NewOrm()
+	sql := `delete from seal_attachment where seal_id = ? `
+	_, err = o.Raw(sql, sealId).Exec()
+	return
+}
+//AddAttachments 用印附件添加
+func AddAttachments(list []*Attachment) (err error) {
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(1, list)
+	return
+}
+

+ 189 - 19
services/seal/seal.go

@@ -3,6 +3,7 @@ package seal
 import (
 	"errors"
 	"fmt"
+	"github.com/beego/beego/v2/client/orm"
 	"hongze/hongze_mobile_admin/models/custom"
 	sealResp "hongze/hongze_mobile_admin/models/response/seal"
 	"hongze/hongze_mobile_admin/models/tables/admin"
@@ -14,12 +15,25 @@ import (
 	contractService "hongze/hongze_mobile_admin/services/contract"
 	"hongze/hongze_mobile_admin/utils"
 	"mime/multipart"
+	"reflect"
 	"strings"
 	"time"
 )
 
 // AddSeal 添加用印
-func AddSeal(userId, contractId, fileNum int, userName, use, useCompanyName, companyName, creditCode, serviceType, sealType, remark, fileUrl string) (sealInfo *seal.Seal, err error) {
+func AddSeal(userId, contractId, fileNum int, userName, use, useCompanyName, companyName, creditCode, serviceType, sealType, remark string, fileUrls []string) (sealInfo *seal.Seal, err error) {
+	o := orm.NewOrm()
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
 	if !strings.Contains(strings.Join(seal.EnumUse, ","), use) {
 		err = errors.New("用印用途异常")
 		return
@@ -33,6 +47,12 @@ func AddSeal(userId, contractId, fileNum int, userName, use, useCompanyName, com
 	if err != nil {
 		return
 	}
+	fileUrl := ""
+	now := time.Now()
+	attachments := make([]*seal.Attachment,0)
+	if len(fileUrls) == 1 {
+		fileUrl = fileUrls[0]
+	}
 	sealInfo = &seal.Seal{
 		Code:           sealCode,
 		UserId:         userId,
@@ -48,14 +68,30 @@ func AddSeal(userId, contractId, fileNum int, userName, use, useCompanyName, com
 		FileUrl:        fileUrl,
 		FileNum:        fileNum,
 		ContractId:     contractId,
-		ModifyTime:     time.Now(),
-		CreateTime:     time.Now(),
+		ModifyTime:     now,
+		CreateTime:     now,
 	}
 	err = seal.AddSeal(sealInfo)
 	if err != nil {
 		err = errors.New("新增用印失败")
 		return
 	}
+	if len(fileUrls) > 1 {
+		for _, v := range fileUrls {
+			tmp := &seal.Attachment{
+				SealId:     sealInfo.SealId,
+				FileUrl:    v,
+				ModifyTime: now,
+				CreateTime: now,
+			}
+			attachments = append(attachments, tmp)
+		}
+		err = seal.AddAttachments(attachments)
+		if err != nil {
+			err = errors.New("添加用印附件失败")
+			return
+		}
+	}
 
 	// 操作日志
 	err = seal.AddSealOperationRecord(sealInfo.SealId, userId, 0, "apply", userName, "提交审批", "")
@@ -68,7 +104,19 @@ func AddSeal(userId, contractId, fileNum int, userName, use, useCompanyName, com
 }
 
 // Edit 修改用印
-func Edit(sealId, userId, contractId, fileNum int, use, companyName, userCompanyName, creditCode, serviceType, sealType, remark, fileUrl, userName string) (sealInfo *seal.Seal, err error) {
+func Edit(sealId, userId, contractId, fileNum int, use, companyName, userCompanyName, creditCode, serviceType, sealType, remark string, fileUrls []string, userName string) (sealInfo *seal.Seal, err error) {
+	o := orm.NewOrm()
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
 	if !strings.Contains(strings.Join(seal.EnumUse, ","), use) {
 		err = errors.New("用印用途异常")
 		return
@@ -96,6 +144,12 @@ func Edit(sealId, userId, contractId, fileNum int, use, companyName, userCompany
 		return
 	}
 	//sealId,userId int, userName, use, companyName, creditCode, serviceType, sealType, remark, fileUrl string
+	fileUrl := ""
+	now := time.Now()
+	attachments := make([]*seal.Attachment,0)
+	if len(fileUrls) == 1 {
+		fileUrl = fileUrls[0]
+	}
 	sealInfo.Use = use
 	sealInfo.CompanyName = companyName
 	sealInfo.UseCompanyName = userCompanyName
@@ -106,8 +160,8 @@ func Edit(sealId, userId, contractId, fileNum int, use, companyName, userCompany
 	sealInfo.FileUrl = fileUrl
 	sealInfo.FileNum = fileNum
 	sealInfo.ContractId = contractId
-	sealInfo.CreateTime = time.Now()	// 重提更新提交时间
-	sealInfo.ModifyTime = time.Now()
+	sealInfo.CreateTime = now	// 重提更新提交时间
+	sealInfo.ModifyTime = now
 	sealInfo.Status = "待提交" //用印状态
 
 	err = sealInfo.Update([]string{"Use", "CompanyName", "UseCompanyName", "CreditCode", "ServiceType", "SealType", "Remark", "FileUrl", "FileNum", "ContractId", "CreateTime", "ModifyTime", "Status"})
@@ -115,7 +169,22 @@ func Edit(sealId, userId, contractId, fileNum int, use, companyName, userCompany
 		err = errors.New("新增用印日志失败")
 		return
 	}
-
+	if len(fileUrls) > 1 {
+		for _, v := range fileUrls {
+			tmp := &seal.Attachment{
+				SealId:     sealInfo.SealId,
+				FileUrl:    v,
+				ModifyTime: now,
+				CreateTime: now,
+			}
+			attachments = append(attachments, tmp)
+		}
+		err = seal.AddAttachments(attachments)
+		if err != nil {
+			err = errors.New("添加用印附件失败")
+			return
+		}
+	}
 	// 操作日志
 	err = seal.AddSealOperationRecord(sealInfo.SealId, userId, 0, "edit", userName, "重提审批", "")
 	if err != nil {
@@ -127,7 +196,7 @@ func Edit(sealId, userId, contractId, fileNum int, use, companyName, userCompany
 }
 
 // CheckEdit 审批者修改用印
-func CheckEdit(sealInfo *seal.Seal, approvalInfo *contract_approval.ContractApproval, approvalRecord *contract_approval_record.ContractApprovalRecord, fileNum int, fileUrl, use, sealType, remark string, opUser *custom.AdminWx) (err error) {
+func CheckEdit(sealInfo *seal.Seal, approvalInfo *contract_approval.ContractApproval, approvalRecord *contract_approval_record.ContractApprovalRecord, fileNum int, fileUrls []string, use, sealType, remark string, opUser *custom.AdminWx) (err error) {
 	if !strings.Contains(strings.Join(seal.EnumUse, ","), use) {
 		err = errors.New("用印用途异常")
 		return
@@ -164,9 +233,26 @@ func CheckEdit(sealInfo *seal.Seal, approvalInfo *contract_approval.ContractAppr
 		updateCol = append(updateCol, "FileNum")
 		updateContent = append(updateContent, "文件份数")
 	}
-	if sealInfo.FileUrl != fileUrl {
+	//判断附件地址是否相等:
+	sealAttachements, err := seal.GetAttachmentBySealId(sealInfo.SealId)
+	if err != nil {
+		err = errors.New(fmt.Sprint("获取用印附件失败,Err:"+err.Error(), err))
+		return
+	}
+	oldFileUrls := make([]string, 0)
+	if sealInfo.FileUrl != "" {
+		oldFileUrls = append(oldFileUrls, sealInfo.FileUrl)
+	}
+	if len(sealAttachements) > 0 {
+		for _, v := range sealAttachements{
+			oldFileUrls = append(oldFileUrls, v.FileUrl)
+		}
+	}
+	attachmentFlag := false
+	if !reflect.DeepEqual(oldFileUrls, fileUrls) {
 		updateCol = append(updateCol, "FileUrl")
 		updateContent = append(updateContent, "文件附件")
+		attachmentFlag = true
 	}
 	fmt.Println(updateCol)
 
@@ -180,6 +266,10 @@ func CheckEdit(sealInfo *seal.Seal, approvalInfo *contract_approval.ContractAppr
 	originFlowType := GetFlowTypeBySealType(sealInfo.SealType)
 	reqFlowType := GetFlowTypeBySealType(sealType)
 
+	newFileUrl := ""
+	if len(fileUrls) == 1 {
+		newFileUrl = fileUrls[0]
+	}
 	//如果变更了盖章类型(涉及到审批流程变更),那么需要变更审批流
 	//变更审批流:先驳回用印申请,再修改用印,再发消息给申请人,再替申请人重新发起申请,
 	//然后遍历审批流程,当前操作人节点之前的全部审核通过,最后通过当前操作人的节点(改成如果一级审批人如果是自己,那么直接通过这一级审批,否则不通过,让审批单重走流程)
@@ -194,9 +284,9 @@ func CheckEdit(sealInfo *seal.Seal, approvalInfo *contract_approval.ContractAppr
 		sealInfo.SealType = sealType
 		sealInfo.Remark = remark
 		sealInfo.FileNum = fileNum
-		sealInfo.FileUrl = fileUrl
+		sealInfo.FileUrl = newFileUrl
 		sealInfo.ModifyTime = time.Now()
-		checkEdit(sealInfo, updateCol, approvalRecord.ContractApprovalRecordId, content, opUser)
+		checkEdit(sealInfo, updateCol, approvalRecord.ContractApprovalRecordId, content, opUser, attachmentFlag, fileUrls)
 
 		//重新获取最新的用印单
 		sealInfo, tmpErr := seal.GetSealInfoById(sealInfo.SealId)
@@ -217,9 +307,9 @@ func CheckEdit(sealInfo *seal.Seal, approvalInfo *contract_approval.ContractAppr
 		sealInfo.SealType = sealType
 		sealInfo.Remark = remark
 		sealInfo.FileNum = fileNum
-		sealInfo.FileUrl = fileUrl
+		sealInfo.FileUrl = newFileUrl
 		sealInfo.ModifyTime = time.Now()
-		checkEdit(sealInfo, updateCol, approvalRecord.ContractApprovalRecordId, content, opUser)
+		checkEdit(sealInfo, updateCol, approvalRecord.ContractApprovalRecordId, content, opUser, attachmentFlag, fileUrls)
 
 		//审核通过
 		err = Approved(sealInfo, approvalInfo, approvalRecord, opUser, "")
@@ -230,8 +320,13 @@ func CheckEdit(sealInfo *seal.Seal, approvalInfo *contract_approval.ContractAppr
 }
 
 // checkEdit 审批人修改
-func checkEdit(sealInfo *seal.Seal, updateCol []string, approvalRecordId int, content string, opUser *custom.AdminWx) {
-	_ = sealInfo.Update(updateCol)
+func checkEdit(sealInfo *seal.Seal, updateCol []string, approvalRecordId int, content string, opUser *custom.AdminWx, attachmentFlag bool, fileUrls []string) {
+	if attachmentFlag {
+		// 同时更新用印申请和附件
+		_ = updateSealAndAttachment(sealInfo, updateCol, fileUrls)
+	}else{
+		_ = sealInfo.Update(updateCol)
+	}
 
 	// 操作日志
 	_ = seal.AddSealOperationRecord(sealInfo.SealId, opUser.AdminId, approvalRecordId, "edit", opUser.RealName, "审批人修改信息", "")
@@ -364,7 +459,7 @@ func UploadCheckBackFileByFile(sealId int, ext string, fileMulti multipart.File,
 		err = errors.New("文件保存失败,Err:" + err.Error())
 		return
 	}
-
+	oldStatus := sealInfo.Status
 	sealInfo.CheckBackFileUrl = resourceUrl
 	sealInfo.Status = "已签回"
 	sealInfo.ModifyTime = time.Now()
@@ -373,6 +468,16 @@ func UploadCheckBackFileByFile(sealId int, ext string, fileMulti multipart.File,
 	if err != nil {
 		return
 	}
+
+	// TODO 发送模版消息
+	if oldStatus == "已审批" {
+		sellerInfo, tErr := admin.GetAdminById(sealInfo.UserId)
+		if tErr == nil {
+			if sellerInfo.Mobile != "" {
+				go services.SendSealFinishedWxTemplateMsg(sellerInfo.Mobile, sealInfo.CompanyName, sealInfo.SealId)
+			}
+		}
+	}
 	return
 }
 
@@ -389,6 +494,7 @@ func UploadCheckBackFile(sealId int, fileUrl string, opUser *custom.AdminWx) (se
 		err = errors.New("用印状态异常,不允许上传签回用印附件,当前用印状态:" + sealInfo.Status)
 		return
 	}
+	oldStatus := sealInfo.Status
 	sealInfo.CheckBackFileUrl = fileUrl
 	sealInfo.Status = "已签回"
 	sealInfo.ModifyTime = time.Now()
@@ -397,6 +503,15 @@ func UploadCheckBackFile(sealId int, fileUrl string, opUser *custom.AdminWx) (se
 	if err != nil {
 		return
 	}
+	// TODO 发送模版消息
+	if oldStatus == "已审批" {
+		sellerInfo, tErr := admin.GetAdminById(sealInfo.UserId)
+		if tErr == nil {
+			if sellerInfo.Mobile != "" {
+				go services.SendSealFinishedWxTemplateMsg(sellerInfo.Mobile, sealInfo.CompanyName, sealInfo.SealId)
+			}
+		}
+	}
 	return
 }
 
@@ -479,13 +594,28 @@ func GetOpButton(sealInfo *seal.Seal, contractApprovalInfo *contract_approval.Co
 }
 
 //根据用印id获取用印详情
-func GetSealDetailBySealId(sealId int, opUser *custom.AdminWx) (sealInfo *seal.Seal, flowNodeListResp [][]contract_approval_record.ContractApprovalRecord, opButton sealResp.OpButton, err error) {
-	sealInfo, err = seal.GetSealInfoById(sealId)
+func GetSealDetailBySealId(sealId int, opUser *custom.AdminWx) (sealMore *sealResp.SealMoreResp, flowNodeListResp [][]contract_approval_record.ContractApprovalRecord, opButton sealResp.OpButton, err error) {
+	sealInfo, err := seal.GetSealInfoById(sealId)
 	if err != nil {
 		err = errors.New("获取合同详情失败,ERR:" + err.Error())
 		return
 	}
-
+	sealAttachements, err := seal.GetAttachmentBySealId(sealId)
+	if err != nil {
+		err = errors.New(fmt.Sprint("获取用印附件失败,Err:"+err.Error(), err))
+		return
+	}
+	fileUrls := make([]string, 0)
+	if sealInfo.FileUrl != "" {
+		fileUrls = append(fileUrls, sealInfo.FileUrl)
+	}
+	for _, v := range sealAttachements{
+		fileUrls = append(fileUrls, v.FileUrl)
+	}
+	sealMore = &sealResp.SealMoreResp{
+		Seal:     sealInfo,
+		FileUrls: fileUrls,
+	}
 	//查询最近一次审批单信息
 	lastApprovalInfo, err := contract_approval.GetLastContractApprovalByContractId(sealInfo.SealId, "seal")
 	if err != nil {
@@ -507,3 +637,43 @@ func GetSealDetailBySealId(sealId int, opUser *custom.AdminWx) (sealInfo *seal.S
 	}
 	return
 }
+
+// updateSealAndAttachment 更新用印申请,并更新附件
+func updateSealAndAttachment(sealInfo *seal.Seal, updateCol []string, fileUrls []string) (err error){
+	o := orm.NewOrm()
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+	err = sealInfo.Update(updateCol)
+	if err != nil {
+		return
+	}
+	now := time.Now()
+	//删除原有的附件,新增最新的附件
+	err = seal.DelAttachmentBySealId(sealInfo.SealId)
+	if err != nil {
+		return
+	}
+	attachments := make([]*seal.Attachment, 0)
+	if len(fileUrls) > 1 {
+		for _, v := range fileUrls {
+			tmp := &seal.Attachment{
+				SealId:     sealInfo.SealId,
+				FileUrl:    v,
+				ModifyTime: now,
+				CreateTime: now,
+			}
+			attachments = append(attachments, tmp)
+		}
+		err = seal.AddAttachments(attachments)
+	}
+	return
+}

+ 62 - 0
services/wechat_send_msg.go

@@ -393,3 +393,65 @@ func SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppP
 	utils.FileLog.Info("send end")
 	return
 }
+
+// 给销售发送 用印申请已签回的模版消息
+func SendSealFinishedWxTemplateMsg(mobile string, companyName string, sealId int) (err error) {
+	var msg string
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
+			utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
+		}
+		if msg != "" {
+			utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
+		}
+	}()
+	utils.FileLog.Info("%s", "services SendMsg")
+	accessToken, err := WxGetAccessToken()
+	if err != nil {
+		msg = "GetWxAccessToken Err:" + err.Error()
+		return
+	}
+	if accessToken == "" {
+		msg = "accessToken is empty"
+		return
+	}
+	utils.FileLog.Info("mobile:%s", mobile)
+	openIdStr := WxUsersGet()
+	openIdList, err := wx_user.GetOpenIdListByMobile(mobile, openIdStr)
+	if err != nil {
+		msg = "get openIdList err:" + err.Error()
+		return
+	}
+	utils.FileLog.Info("openIdListCount:%s", len(openIdList))
+
+	if len(openIdList) > 0 && utils.WxMsgTemplateIdWithSealApplyFinished != "" {
+		utils.FileLog.Info("start send")
+		sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
+		fmt.Println("send start")
+		utils.FileLog.Info("send start")
+		sendMap := make(map[string]interface{})
+		sendData := make(map[string]interface{})
+		first := "您的用印申请已签回,可前往提交转正/续约申请"
+		keyword1 := companyName
+		keyword2 := "已签回"
+		remark := "点击查看用印详情"
+
+		sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
+		sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
+		sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
+		sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
+
+		sendMap["template_id"] = utils.WxMsgTemplateIdWithSealApplyFinished
+		sendMap["url"] = "" //跳转地址
+		sendMap["data"] = sendData
+
+		// TODO 随手办公小程序的跳转地址
+		wxAppPath := fmt.Sprintf("pages-approve/seal/detail?id=%d", sealId)
+		sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId2, "pagepath": wxAppPath}
+		err = sendTemplateMsg(sendUrl, sendMap, openIdList)
+	}
+	utils.FileLog.Info("send end")
+	return
+}

+ 3 - 0
utils/config.go

@@ -38,6 +38,7 @@ var (
 	WxMsgTemplateIdWithRoadshowPending      string //路演->研究员收到待处理的申请
 	WxMsgTemplateIdWithRoadshowDetailResult string //路演->销售收到处理结果
 	WxMsgTemplateIdWithRoadshowDeleteNotice string //路演->研究员收到活动删除通知
+	WxMsgTemplateIdWithSealApplyFinished      string // 用印申请-已签回通知
 )
 
 var (
@@ -134,6 +135,7 @@ func init() {
 		WxMsgTemplateIdWithRoadshowPending = "PaoDanHGlt1kFw5q-4_ipJSwO3FyZpxSSNg4rwB7YCk"      //路演->研究员收到待处理的申请
 		WxMsgTemplateIdWithRoadshowDetailResult = "dYg6iHooRq74PyCXmw_Ns7qdJZmbtLoKS2p2FKeaXl0" //路演->销售收到处理结果
 		WxMsgTemplateIdWithRoadshowDeleteNotice = "dYg6iHooRq74PyCXmw_Ns7qdJZmbtLoKS2p2FKeaXl0" //路演->研究员收到活动删除通知
+		WxMsgTemplateIdWithSealApplyFinished   = "dYg6iHooRq74PyCXmw_Ns7qdJZmbtLoKS2p2FKeaXl0"   // 用印申请-已签回通知
 	} else {
 		WxAppId = "wx9b5d7291e581233a"
 		WxAppSecret = "f4d52e34021eee262dce9682b31f8861"
@@ -152,6 +154,7 @@ func init() {
 		WxMsgTemplateIdWithRoadshowPending = "qfNuops-sKrfIkbA7U97A7gSrX03mUpoEpJksRUdloo"      //路演->研究员收到待处理的申请
 		WxMsgTemplateIdWithRoadshowDetailResult = "CB7bOl7f3viMG4s1uhRo7WM0Jbx3WvodKuIZ8A_z8fM" //路演->销售收到处理结果
 		WxMsgTemplateIdWithRoadshowDeleteNotice = "CB7bOl7f3viMG4s1uhRo7WM0Jbx3WvodKuIZ8A_z8fM" //路演->研究员收到活动删除通知
+		WxMsgTemplateIdWithSealApplyFinished   = "CB7bOl7f3viMG4s1uhRo7WM0Jbx3WvodKuIZ8A_z8fM"   // 用印申请-已签回通知
 	}
 
 	tmpLibreOfficePath, err := web.AppConfig.String("libreOfficePath")