瀏覽代碼

Merge branch 'pool_677'

ziwen 1 年之前
父節點
當前提交
8702522782
共有 2 個文件被更改,包括 32 次插入1 次删除
  1. 26 1
      controller/contract/pre_register.go
  2. 6 0
      models/fms/contract_invoice.go

+ 26 - 1
controller/contract/pre_register.go

@@ -766,7 +766,32 @@ func (rg *PreRegisterController) Del(c *gin.Context) {
 		resp.FailMsg("删除统计记录失败", "Err:"+e.Error(), c)
 		return
 	}
-	//todo 合同看情况要不要删
+	//删除预登记新增的假合同
+	count, e := fms.GetInvoiceCountByRegisterId(req.ContractRegisterId)
+	if e != nil {
+		resp.FailMsg("删除统计记录失败", "Err:"+e.Error(), c)
+		return
+	}
+	if count == 0{
+		ob := new(fms.ContractRegister)
+		item, e := ob.Fetch(req.ContractRegisterId)
+		if e != nil {
+			if e == utils.ErrNoRow {
+				resp.Fail("合同登记不存在或已被删除", c)
+				return
+			}
+			resp.FailMsg("获取合同登记失败", "Err:"+e.Error(), c)
+			return
+		}
+		nowTime := time.Now().Local()
+		item.IsDeleted = 1
+		item.ModifyTime = nowTime
+		updateCols := []string{"IsDeleted", "ModifyTime"}
+		if e = item.Update(updateCols); e != nil {
+			resp.FailMsg("操作失败", "更新合同登记失败, Err:"+e.Error(), c)
+			return
+		}
+	}
 
 	resp.Ok("操作成功", c)
 }

+ 6 - 0
models/fms/contract_invoice.go

@@ -807,3 +807,9 @@ func GetDuplicateContractInvoiceDetailItemListForSupplement(companyName, startDa
 	}
 	return
 }
+
+func GetInvoiceCountByRegisterId(registerId int) (total int64, err error) {
+	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
+		Where("is_deleted = 0 AND contract_register_id = ?", registerId).Count(&total).Error
+	return
+}