Browse Source

no message

zhangchuanxing 3 ngày trước cách đây
mục cha
commit
e8697e5d18
2 tập tin đã thay đổi với 36 bổ sung1 xóa
  1. 25 0
      controllers/company_apply_v2.go
  2. 11 1
      models/seal/seal.go

+ 25 - 0
controllers/company_apply_v2.go

@@ -206,6 +206,7 @@ func (this *CompanyApplyController) ApplyServiceUpdate() {
 			br.ErrMsg = "生成合同编码失败,Err:" + err.Error()
 			return
 		}
+		var sealId int
 		if productId == 2 {
 			sealCount, err := seal.GetCountByDateAndCompanyId(req.StartDate, req.EndDate, req.CompanyId)
 			if err != nil {
@@ -286,6 +287,16 @@ func (this *CompanyApplyController) ApplyServiceUpdate() {
 			br.ErrMsg = "新增合同失败,Err:" + err.Error()
 			return
 		}
+		//如果用印ID > 0 建立合同ID,与用印申请表的关系
+		if sealId > 0 {
+			//用印作废
+			err = seal.UpdateSealCompanyContractId(int(newId), sealId)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "添加用印与合同的关系失败,Err:" + err.Error()
+				return
+			}
+		}
 		permissionArr := strings.Split(req.PermissionIds, ",")
 		permissionMap := make(map[int]int) //权限id的map集合,用来避免重复添加权限校验
 
@@ -724,6 +735,8 @@ func (this *CompanyApplyController) ApplyTurnPositive() {
 		//	}
 		//}
 
+		var sealId int
+
 		if productId == 2 {
 			sealCount, err := seal.GetCountByDateAndCompanyId(req.StartDate, req.EndDate, req.CompanyId)
 			if err != nil {
@@ -750,6 +763,7 @@ func (this *CompanyApplyController) ApplyTurnPositive() {
 					return
 				}
 				contractCode = sealInfo.Code
+				sealId = sealInfo.SealId
 			}
 		}
 
@@ -806,6 +820,17 @@ func (this *CompanyApplyController) ApplyTurnPositive() {
 			br.ErrMsg = "新增合同失败,Err:" + err.Error()
 			return
 		}
+
+		//如果用印ID > 0 建立合同ID,与用印申请表的关系
+		if sealId > 0 {
+			//用印作废
+			err = seal.UpdateSealCompanyContractId(int(newId), sealId)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "添加用印与合同的关系失败,Err:" + err.Error()
+				return
+			}
+		}
 		permissionArr := strings.Split(req.PermissionIds, ",")
 		permissionMap := make(map[int]int) //权限id的map集合,用来避免重复添加权限校验
 		permissionItems := make([]*company.CompanyContractPermission, 0)

+ 11 - 1
models/seal/seal.go

@@ -38,6 +38,7 @@ type Seal struct {
 	CompanyId         int       `description:"客户id."`
 	StartDate         string    `description:"开始日期."`
 	EndDate           string    `description:"结束日期。"`
+	CompanyContractId int       `description:"合同id"`
 }
 
 var EnumUse = []string{"销售合同", "渠道合同", "付款通知函", "招投标", "战略合作协议", "代付合同", "总对总协议"}
@@ -74,7 +75,7 @@ func GetSealInfoByDateAndCompanyId(startDate, endDate string, companyId int) (se
 func GetCountByDateAndCompanyId(startDate, endDate string, companyId int) (count int, err error) {
 	o := orm.NewOrm()
 
-	sql := "select count(*) AS COUNT from seal   where start_date = ? and end_date = ? AND company_id =?  AND  product_id = 2   "
+	sql := "select count(*) AS COUNT from seal   where start_date = ? and end_date = ? AND company_id =?  AND  product_id = 2   AND  company_contract_id  = 0    "
 	err = o.Raw(sql, startDate, endDate, companyId).QueryRow(&count)
 	return
 }
@@ -117,6 +118,15 @@ func Invalid(sealInfo *Seal) (err error) {
 	return
 }
 
+// UpdateSealCompanyContractId 添加用印与合同的关系
+func UpdateSealCompanyContractId(companyContractId, sealId int) (err error) {
+	//修改用印数据入库
+	o := orm.NewOrm()
+	msql := " UPDATE seal SET company_contract_id = ? WHERE seal_id = ? "
+	_, err = o.Raw(msql, companyContractId, sealId).Exec()
+	return
+}
+
 // GetSealCode 生成合同编号
 func GetSealCode() (code string, err error) {
 	var num int