Browse Source

优化合同登记

xiexiaoyuan 2 years ago
parent
commit
94599e1dc8

+ 102 - 1
controller/contract/register.go

@@ -265,6 +265,17 @@ func (rg *RegisterController) Add(c *gin.Context) {
 			}
 		}
 	}
+	//新老客户判断
+	/*newCompany := req.NewCompany
+	if req.ContractType == 1 {
+		newCompany = 1
+	}else if req.ContractType == 2 || req.ContractType == 3 {
+		newCompany = 0
+	}
+	if newCompany != req.NewCompany {
+		resp.Fail("请输入正确的客户类型", c)
+		return
+	}*/
 	nowTime := time.Now().Local()
 	ob.ContractCode = req.ContractCode
 	ob.RelateContractCode = req.RelateContractCode
@@ -296,7 +307,6 @@ func (rg *RegisterController) Add(c *gin.Context) {
 	if req.HasPayment == 1 || req.ContractStatus == fms.ContractStatusEnd {
 		ob.RegisterStatus = fms.ContractRegisterStatusComplete
 	}
-
 	// 新增套餐金额详情内容
 	serviceAmountMap := make(map[int]float64)
 	serviceAmountList, e := fmsService.HandleContractServiceAmount(req.ServiceAmount, serviceAmountMap, req.CurrencyUnit)
@@ -304,6 +314,17 @@ func (rg *RegisterController) Add(c *gin.Context) {
 		resp.FailMsg("操作失败", "新增合同套餐金额信息失败, Err: "+e.Error(), c)
 		return
 	}
+	//判断产品信息
+	productIds := make(map[int]struct{})
+	productIdsStr := ""
+	for _, v := range serviceAmountList {
+		productIds[v.ProductId] = struct{}{}
+	}
+	for proId, _ := range productIds  {
+		productIdsStr += strconv.Itoa(proId)+","
+	}
+	productIdsStr = strings.Trim(productIdsStr, ",")
+	ob.ProductIds = productIdsStr
 	// 套餐信息
 	serviceList, e := fmsService.HandleContractServiceAndDetail(req.Services, true, serviceAmountMap)
 	if e != nil {
@@ -643,6 +664,18 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 		return
 	}
 
+	//判断产品信息
+	productIds := make(map[int]struct{})
+	productIdsStr := ""
+	for _, v := range serviceAmountList {
+		productIds[v.ProductId] = struct{}{}
+	}
+	for proId, _ := range productIds  {
+		productIdsStr += strconv.Itoa(proId)+","
+	}
+	productIdsStr = strings.Trim(productIdsStr, ",")
+	item.ProductIds = productIdsStr
+
 	// 套餐信息
 	serviceList, e := fmsService.HandleContractServiceAndDetail(req.Services, true, serviceAmountMap)
 	if e != nil {
@@ -2834,3 +2867,71 @@ func (rg *RegisterController) CurrencyList(c *gin.Context) {
 	}
 	resp.OkData("获取成功", list, c)
 }
+
+// CheckContractName
+// @Title 货币单位列表
+// @Description 货币单位列表
+// @Success 200 {object} fms.CheckContractNameResp
+// @router /contract/register/check_contract_code [get]
+func (rg *RegisterController) CheckContractName(c *gin.Context) {
+	var req fms.CheckContractNameReq
+	if e := c.BindQuery(&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 += ` or (start_date =? and end_date=?)`
+		}else{
+			existCond = ` start_date = ? and end_date=?`
+		}
+
+		existPars = append(existPars, startDate, endDate)
+	}
+	if existCond == "" {
+		resp.Fail("请输入合同名称或者合同有效期", c)
+		return
+	}
+
+	// 是否存在相同合同名称的登记
+	ob := new(fms.ContractRegister)
+	data := fms.CheckContractNameResp{
+		Exist: 0,
+	}
+	_, e := ob.FetchByCondition(existCond, existPars)
+	if e != nil {
+		if e == utils.ErrNoRow {
+			resp.OkData("查询成功", data, c)
+			return
+		}
+		resp.FailMsg("查询失败", "查询相同登记号失败, Err: "+e.Error(), c)
+		return
+	}
+	data.Exist = 1
+	resp.OkData("查询成功", data, c)
+	return
+}

+ 1 - 1
models/fms/contract_invoice.go

@@ -155,7 +155,7 @@ type ContractInvoiceSaveReq struct {
 
 // ContractInvoiceSaveItem 合同开票数据
 type ContractInvoiceSaveItem struct {
-	ServiceProductId int     `json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
+	ServiceProductId int     `json:"service_product_id" binding:"oneof=1 2" description:"套餐类型:1ficc套餐,2权益套餐"`
 	InvoiceId        int     `json:"invoice_id" description:"开票ID"`
 	OriginAmount     float64 `json:"origin_amount" description:"开票(到款)金额"`
 	Amount           float64 `json:"amount" description:"换算后的金额"`

+ 11 - 0
models/fms/contract_register.go

@@ -537,3 +537,14 @@ func CreateContractRegisterAndServicesAndPayMent(item *ContractRegister, service
 
 	return
 }
+
+type  CheckContractNameReq 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:"合同结束日期"`
+}
+
+
+type  CheckContractNameResp struct {
+	Exist int 	`json:"exist" description:"是否存在相似的合同:0不存在,1存在"`
+}

+ 1 - 0
routers/contract.go

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

+ 4 - 0
services/fms/contract_register.go

@@ -119,6 +119,10 @@ func HandleContractServiceAmount(serviceAmountList []fms.ContractServiceAmountAd
 	for i := 0; i < len(serviceAmountList); i++ {
 		item := serviceAmountList[i]
 		serviceAmountMap[item.ProductId] = item.ServiceAmount
+		if item.ProductId !=crm.CompanyProductRai && item.ProductId != crm.CompanyProductFicc {
+			err = errors.New("请选择正确和套餐类型")
+			return
+		}
 		serviceDetail := &fms.ContractServiceAmount{
 			ProductId:     item.ProductId,
 			ServiceAmount: item.ServiceAmount,