浏览代码

Merge branch 'fms_2.7' into debug

ziwen 1 年之前
父节点
当前提交
b3ede022cd
共有 4 个文件被更改,包括 99 次插入1 次删除
  1. 75 0
      controller/contract/register.go
  2. 22 0
      models/fms/contract_register.go
  3. 1 1
      models/fms/invoice_payment_summary.go
  4. 1 0
      routers/contract.go

+ 75 - 0
controller/contract/register.go

@@ -3281,3 +3281,78 @@ func (rg *RegisterController) CheckContractName(c *gin.Context) {
 	resp.OkData("查询成功", data, c)
 	return
 }
+
+
+// CheckContract
+// @Title 货币单位列表
+// @Description 货币单位列表
+// @Success 200 {object} fms.CheckContractNameResp
+// @router /contract/register/check_contract_duplicate [post]
+func (rg *RegisterController) CheckContractDuplicate(c *gin.Context) {
+	var req fms.CheckContractDuplicateReq
+	if e := c.ShouldBind(&req); e != nil {
+		err, ok := e.(validator.ValidationErrors)
+		if !ok {
+			resp.FailData("参数解析失败", "Err:"+e.Error(), c)
+			return
+		}
+		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
+		return
+	}
+	existCond := ""
+	existPars := make([]interface{}, 0)
+	if req.CompanyName != "" {
+		// 是否存在相同的合同名称的登记
+		existCond = ` company_name = ?`
+		existPars = append(existPars, req.CompanyName)
+	}
+
+	if req.StartDate != "" && req.EndDate != "" {
+		// 日期校验
+		startDate, e := time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
+		if e != nil {
+			resp.FailMsg("合同开始日期格式有误", "合同开始日期格式有误, Err: "+e.Error(), c)
+			return
+		}
+		endDate, e := time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
+		if e != nil {
+			resp.FailMsg("合同结束日期格式有误", "合同结束日期格式有误, Err: "+e.Error(), c)
+			return
+		}
+		if existCond != "" {
+			existCond += ` AND (start_date =? and end_date=?)`
+		} else {
+			existCond = ` start_date = ? and end_date=?`
+		}
+
+		existPars = append(existPars, startDate, endDate)
+	}
+	if len(req.Services) > 0 {
+		//serviceList, e := fmsService.HandleContractServiceAndDetail(req.Services, true, serviceAmountMap)
+		//if e != nil {
+		//	resp.FailMsg("操作失败", "获取合同套餐详情失败, Err: "+e.Error(), c)
+		//	return
+		//}
+
+	}
+
+	if existCond == "" {
+		resp.Fail("请输入合同名称或者合同有效期", c)
+		return
+	}
+
+	// 是否存在相同合同名称的登记
+	list, e := fms.CheckContractDuplicate(existCond, existPars)
+	if e != nil {
+		resp.FailMsg("操作失败", "查询重复合同失败, Err: "+e.Error(), c)
+		return
+	}
+	data := fms.CheckContractDuplicateResp{
+		Exist: 0,
+	}
+	if len(list) > 0 {
+		data.Exist = 1
+	}
+	resp.OkData("查询成功", data, c)
+	return
+}

+ 22 - 0
models/fms/contract_register.go

@@ -864,3 +864,25 @@ func UpdateSupplementContractPreRegister(item *ContractRegister, serviceAmountLi
 
 	return
 }
+
+type CheckContractDuplicateReq struct {
+	CompanyName string                  `json:"company_name" form:"company_name" description:"客户名称"`
+	StartDate   string                  `json:"start_date" form:"start_date" description:"合同开始日期"`
+	EndDate     string                  `json:"end_date" form:"end_date" description:"合同结束日期"`
+	Services    []ContractServiceAddReq `json:"services" description:"服务套餐内容"`
+}
+
+func CheckContractDuplicate(condition string, pars []interface{}) (list []*ContractRegister,err error) {
+	query := global.DEFAULT_MYSQL.Table("contract_register AS a").
+		Select("a.* ").
+		Joins(" JOIN contract_service AS b ON a.contract_register_id = b.contract_register_id ").
+		Where(condition, pars...).
+		Group("a.contract_register_id")
+	err = query.Find(&list).Error
+	return
+}
+
+
+type CheckContractDuplicateResp struct {
+	Exist int `json:"exist" description:"是否存在重复的合同:0不存在,1存在"`
+}

+ 1 - 1
models/fms/invoice_payment_summary.go

@@ -165,7 +165,7 @@ func DeleteInvoicePaymentSummaryByInvoiceIdAndPaymentId(invoiceId, arriveId, reg
 
 // GetContractSummaryInvoicePaymentAmount 获取汇总金额合计信息
 func GetContractSummaryInvoicePaymentAmount(condition string, pars []interface{}) (amountTotal float64, err error) {
-	joinCond := `a.register_id = b.contract_register_id `
+	joinCond := ` (a.invoice_id = b.contract_invoice_id OR a.payment_id = b.contract_invoice_id) `
 
 	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
 		Select("IFNULL(SUM(b.amount),0)").

+ 1 - 0
routers/contract.go

@@ -23,6 +23,7 @@ func InitContract(rg *gin.RouterGroup) {
 	crGroup.POST("import", cr.Import)
 	crGroup.GET("currency_list", cr.CurrencyList)
 	crGroup.GET("check_contract_code", cr.CheckContractName)
+	crGroup.POST("check_contract_duplicate", cr.CheckContractDuplicate)
 
 	// 合同套餐
 	sr := new(contract.ServiceController)