| 
					
				 | 
			
			
				@@ -8,7 +8,10 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package dao 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"errors" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"fmt" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"strconv" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"time" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"github.com/go-xorm/xorm" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"go.mod/comm" 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -30,7 +33,7 @@ func NewApproverDao(engine *xorm.Engine) *ApproverDao { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 // 批量插入数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-func (d *ApproverDao) InsertData(times int, bid int, pid int, dataType int, dataId int, auditors []int, reAuditors []int) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+func (d *ApproverDao) InsertData(bid int, pid int, dataType int, dataId int, auditors []int, reAuditors []int) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	data := make([]models.CmApprover, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	for i, item := range auditors { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		approverVM := models.CmApprover{} 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -42,7 +45,6 @@ func (d *ApproverDao) InsertData(times int, bid int, pid int, dataType int, data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		approverVM.DataType = dataType 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		approverVM.DataId = dataId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		approverVM.Status = 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		approverVM.Times = times 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if i == 0 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			approverVM.Status = 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -55,7 +57,6 @@ func (d *ApproverDao) InsertData(times int, bid int, pid int, dataType int, data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	checkVM.ProjectId = pid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	checkVM.DataType = dataType 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	checkVM.DataId = dataId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	checkVM.Times = times 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	data = append(data, checkVM) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	for i, item := range reAuditors { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		approverVM := models.CmApprover{} 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -66,7 +67,6 @@ func (d *ApproverDao) InsertData(times int, bid int, pid int, dataType int, data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		approverVM.ProjectId = pid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		approverVM.DataType = dataType 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		approverVM.DataId = dataId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		approverVM.Times = times 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		data = append(data, approverVM) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	_, err := d.engine.Insert(data) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -91,14 +91,15 @@ func (d *ApproverDao) ChangeAuditId(bid int, dataType int, dataId int, auditOrde 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func (d *ApproverDao) ChangeNextStatus(id int, status int) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	data := &models.CmApprover{Id: id} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	_, err := d.engine.Get(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	_, err = d.engine.Where("bidsection_id = ? and data_type = ? and data_id = ? and audit_order = ?", data.BidsectionId, data.DataType, data.DataId, data.AuditOrder+1).Cols("status").Update(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	newData := &models.CmApprover{Status: status} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	_, err = d.engine.Where("bidsection_id = ? and data_type = ? and data_id = ? and audit_order = ?", data.BidsectionId, data.DataType, data.DataId, data.AuditOrder+1).Cols("status").Update(newData) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 // 根据当前times,获取审批流程(包括原报) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-func (d *ApproverDao) GetAuditorsWithOwner(bid int, dataType int, dataId int, times int, cur_uid int) []viewmodels.Auditors { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+func (d *ApproverDao) GetAuditorsWithOwner(bid int, dataType int, dataId int, cur_uid int) []viewmodels.Auditors { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	auditors := make([]viewmodels.Auditors, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	auditor := viewmodels.Auditors{Progress: "", Id: ""} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	auditor := viewmodels.Auditors{Progress: "", Id: "", Status: 2} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	_, err := d.engine.Sql("select name, company, position, mobile, id as `audit_id` from `cm_project_account` where id = ?", cur_uid).Get(&auditor) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -107,7 +108,7 @@ func (d *ApproverDao) GetAuditorsWithOwner(bid int, dataType int, dataId int, ti 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	auditors = append(auditors, auditor) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	d.engine.Sql("select pa.`company`, pa.`name`, pa.`account_group`,pa.`mobile`, pa.`position`,ca.`audit_id` as `audit_id`, ca.`id`, ca.`status`, ca.`audit_order`, ca.`progress` from `cm_project_account` as pa, `cm_approver` as ca where ca.`bidsection_id` = ? and ca.`data_type` = ? and ca.`data_id` = ? and ca.`times` = ? and ca.audit_id = pa.id order by `audit_order`", bid, dataType, dataId, times).Find(&auditors) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	d.engine.Sql("select pa.`company`, pa.`name`, pa.`account_group`,pa.`mobile`, pa.`position`,ca.`audit_id` as `audit_id`, ca.`id`, ca.`status`, ca.`audit_order`, ca.`progress` from `cm_project_account` as pa, `cm_approver` as ca where ca.`bidsection_id` = ? and ca.`data_type` = ? and ca.`data_id` = ? and ca.audit_id = pa.id order by `audit_order`", bid, dataType, dataId).Find(&auditors) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 原报 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	return auditors 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -120,21 +121,26 @@ func (d *ApproverDao) FindApproverById(id int) (*models.CmApprover, error) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 // 获取最新的审核人 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func (d *ApproverDao) GetLastedAuditor(bid int, dataType int, dataId int) *viewmodels.Approver { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	data := &viewmodels.Approver{BidsectionId: string(bid), DataType: dataType, DataId: string(dataId), Status: 1} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	data := &models.CmApprover{BidsectionId: bid, DataType: dataType, DataId: dataId, Status: 1} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	has, _ := d.engine.Get(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	approverVM := &viewmodels.Approver{} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if has == true { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		id, _ := comm.AesEncrypt(data.Id, conf.SignSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		data.Id = id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		pid, _ := comm.AesEncrypt(data.ProjectId, conf.SignSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		data.Id = pid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		bid, _ := comm.AesEncrypt(data.BidsectionId, conf.SignSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		data.Id = bid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		dataId, _ := comm.AesEncrypt(data.DataId, conf.SignSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		data.DataId = dataId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		auditId, _ := comm.AesEncrypt(data.AuditId, conf.SignSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		data.AuditId = auditId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		id, _ := comm.AesEncrypt(strconv.Itoa(data.Id), conf.SignSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		approverVM.Id = id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		pid, _ := comm.AesEncrypt(strconv.Itoa(data.ProjectId), conf.SignSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		approverVM.ProjectId = pid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		bid, _ := comm.AesEncrypt(strconv.Itoa(data.BidsectionId), conf.SignSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		approverVM.BidsectionId = bid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		dataId, _ := comm.AesEncrypt(strconv.Itoa(data.DataId), conf.SignSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		approverVM.DataId = dataId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		auditId, _ := comm.AesEncrypt(strconv.Itoa(data.AuditId), conf.SignSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		approverVM.AuditId = auditId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		approverVM.AuditOrder = data.AuditOrder 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		approverVM.DataType = data.DataType 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		approverVM.Progress = strconv.Itoa(data.Progress) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		approverVM.Status = data.Status 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	return data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	return approverVM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 // 获取最后一个审批人 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -145,21 +151,67 @@ func (d *ApproverDao) GetLastAuditor(bid int, dataType int, dataId int) (*models 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 // 初始化审批流程状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-func (d *ApproverDao) InitStatus(bid int, dataType int, dataId int) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+func (d *ApproverDao) InitStatus(bid int, dataType int, dataId int, auditId int, times int, progress int, opinion string) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	session := d.engine.NewSession() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	defer session.Close() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	err := session.Begin() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return errors.New("操作失败-db") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	data := &models.CmApprover{Status: 0} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	_, err := d.engine.Where("bidsection_id = ? and data_type = ? and data_id = ?").Cols("status").Update(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	_, err = session.Where("bidsection_id = ? and data_type = ? and data_id = ?", bid, dataType, dataId).Cols("status").Update(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		session.Rollback() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	_, err = session.Exec("update cm_safe set status = ? where id = ?", 0, dataId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		session.Rollback() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 增加审批日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	safeAudit := &models.CmSafeAudit{BidsectionId: bid, SafeId: dataId, Times: times, AuditId: auditId, Status: 1, Progress: progress, CreateTime: time.Now(), Opinion: opinion} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	_, err = session.Insert(safeAudit) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		session.Rollback() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	err = session.Commit() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 // 审批流程-退回 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-func (d *ApproverDao) BackHandlerWithId(id int) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+func (d *ApproverDao) BackHandlerWithId(id int, cur_audit int, times int, progress int, opinion string) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	session := d.engine.NewSession() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	defer session.Close() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// add Begin() before any action 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	err := session.Begin() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	auditor, err := d.FindApproverById(id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	data := &models.CmApprover{Status: 0} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 将往后的所有记录的status改为0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	_, err = d.engine.Where("bidsection_id = ? and data_type = ? and data_id = ? and audit_order > ?", auditor.BidsectionId, auditor.DataType, auditor.DataId, auditor.AuditOrder).Cols("status").Update(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	_, err = session.Where("bidsection_id = ? and data_type = ? and data_id = ? and audit_order > ?", auditor.BidsectionId, auditor.DataType, auditor.DataId, auditor.AuditOrder).Cols("status").Update(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		session.Rollback() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 将当前的记录改为1-待审批 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	data.Status = 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	_, err = d.engine.ID(id).Cols("status").Update(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	_, err = session.ID(id).Cols("status").Update(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		session.Rollback() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 增加审批日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	safeAudit := &models.CmSafeAudit{BidsectionId: auditor.BidsectionId, SafeId: auditor.DataId, Times: times, AuditId: cur_audit, Status: 1, Progress: progress, CreateTime: time.Now(), Opinion: opinion} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	_, err = session.Insert(safeAudit) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		session.Rollback() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |