ziwen 2 years ago
parent
commit
b0193c283a

+ 82 - 60
controller/contract/register.go

@@ -291,13 +291,13 @@ func (rg *RegisterController) Add(c *gin.Context) {
 		return
 	}*/
 	nowTime := time.Now().Local()
+	ob.ContractRegisterId = req.ContractRegisterId
 	ob.ContractCode = req.ContractCode
 	ob.RelateContractCode = req.RelateContractCode
 	ob.RelateContractMainCode = req.RelateContractMainCode
 	ob.CrmContractId = req.CrmContractId
 	ob.ContractSource = req.ContractSource
 	ob.CompanyName = req.CompanyName
-	ob.ActualCompanyName = req.ActualCompanyName
 	ob.ProductIds = req.ProductIds
 	ob.SellerId = sellerId
 	ob.SellerName = sellerName
@@ -316,8 +316,13 @@ func (rg *RegisterController) Add(c *gin.Context) {
 	ob.Remark = req.Remark
 	ob.ServiceRemark = req.ServiceRemark
 	ob.HasPayment = req.HasPayment
-	ob.NewCompany = req.NewCompany
 	ob.Set()
+	updateCols := []string{
+		"ContractCode","RelateContractCode", "RelateContractMainCode","CrmContractId","ContractSource",
+		"ProductIds", "CompanyName", "SellerId", "SellerName", "StartDate", "EndDate",
+		"RaiSellerId", "RaiSellerName", "ModifyTime","ContractType","ContractAmount","CurrencyUnit","RMBRate",
+		"SignDate","AgreedPayTime","ContractStatus","RegisterStatus", "Remark", "HasPayment",
+	}
 	// 存在代付的直接完成登记, 且不允许进行开票/到款登记
 	if req.HasPayment == 1 || req.ContractStatus == fms.ContractStatusEnd {
 		ob.RegisterStatus = fms.ContractRegisterStatusComplete
@@ -355,20 +360,19 @@ func (rg *RegisterController) Add(c *gin.Context) {
 			return
 		}
 
-		//新增合同信息
-		if e = fms.CreateContractRegisterAndServicesAndPayMent(ob, serviceList); e != nil {
-			resp.FailMsg("操作失败", "新增合同及套餐失败, Err: "+e.Error(), c)
+		//修改合同信息-假合同变成真合同
+		if e = ob.Update(updateCols); e != nil {
+			resp.FailMsg("操作失败", "更新合同登记失败, Err:"+e.Error(), c)
 			return
 		}
 
-		prePayOB := new(fms.ContractInvoice)
-		ppItem, e := prePayOB.Fetch(req.ContractInvoiceId)
+		invoiceOB := new(fms.ContractInvoice)
+		invoiceCond := `contract_register_id = ?`
+		invoicePars := make([]interface{}, 0)
+		invoicePars = append(invoicePars, req.ContractRegisterId)
+		invoiceList, e := invoiceOB.List(invoiceCond, invoicePars, "")
 		if e != nil {
-			if e == utils.ErrNoRow {
-				resp.Fail("预到款不存在或已被删除", c)
-				return
-			}
-			resp.FailMsg("获取预到款记录失败", "Err:"+e.Error(), c)
+			resp.FailMsg("操作失败", "获取合同开票到款列表失败, Err: "+e.Error(), c)
 			return
 		}
 		// 合同有效时长(计算付款方式)
@@ -384,56 +388,76 @@ func (rg *RegisterController) Add(c *gin.Context) {
 		for i := range sellerList {
 			sellerMap[sellerList[i].SellerId] = sellerList[i]
 		}
+		logList := make([]*fms.ContractRegisterLog, 0)
+		for _, ppItem := range invoiceList {
+			v := &fms.ContractInvoice{
+				ContractRegisterId: ob.ContractRegisterId,
+				ContractCode:       ob.ContractCode,
+				Amount:             ppItem.Amount,
+				OriginAmount:       ppItem.OriginAmount,
+				CurrencyUnit:       ppItem.CurrencyUnit,
+				InvoiceDate:        ppItem.InvoiceDate,
+				AdminId:            int(adminInfo.AdminId),
+				AdminName:          adminInfo.RealName,
+				Remark:             ppItem.Remark,
+				IsPrePay:           1,
+			}
+			if ppItem.InvoiceType == 3 {
+				v.InvoiceType = 1
+			} else if ppItem.InvoiceType == 4 {
+				v.InvoiceType = 2
+			}
+			v.Set()
+			// 到款登记-付款方式
+			v.PayType = fmsService.CalculateContractPaymentType(ppItem.Amount, ob.ContractAmount, dayDiff)
 
-		v := &fms.ContractInvoice{
-			ContractRegisterId: ob.ContractRegisterId,
-			ContractCode:       ob.ContractCode,
-			Amount:             ppItem.Amount,
-			OriginAmount:       ppItem.OriginAmount,
-			CurrencyUnit:       ppItem.CurrencyUnit,
-			InvoiceType:        fms.ContractInvoiceTypePay,
-			InvoiceDate:        ppItem.InvoiceDate,
-			AdminId:            int(adminInfo.AdminId),
-			AdminName:          adminInfo.RealName,
-			Remark:             ppItem.Remark,
-			IsPrePay:           1,
-		}
-		v.Set()
-		// 到款登记-付款方式
-		v.PayType = fmsService.CalculateContractPaymentType(ppItem.Amount, ob.ContractAmount, dayDiff)
+			// 新增的记录
+			opData := ""
+			opDataByte, e := json.Marshal(req)
+			if e != nil {
+				return
+			}
+			opData = string(opDataByte)
+			opType := fms.ContractRegisterOpTypePreInvoice
+			newAmount := decimal.NewFromFloat(0).Round(2)
+			a := decimal.NewFromFloat(v.Amount).Round(2)
+			newAmount = newAmount.Add(a)
+			ia, _ := newAmount.Round(2).Float64()
+			logList = append(logList, &fms.ContractRegisterLog{
+				ContractRegisterId: ob.ContractRegisterId,
+				AdminId:            int(adminInfo.AdminId),
+				AdminName:          adminInfo.RealName,
+				OpData:             opData,
+				OpType:             opType,
+				CreateTime:         nowTime,
+				AmountRemark:       fmt.Sprint("新增", fms.ContractInvoiceKeyNameMap[opType], "金额", ia, "元"),
+			})
 
-		// 新增的记录
-		logList := make([]*fms.ContractRegisterLog, 0)
-		opData := ""
-		opDataByte, e := json.Marshal(req)
-		if e != nil {
-			return
-		}
-		opData = string(opDataByte)
-		opType := fms.ContractRegisterOpTypePreInvoice
-		newAmount := decimal.NewFromFloat(0).Round(2)
-		a := decimal.NewFromFloat(v.Amount).Round(2)
-		newAmount = newAmount.Add(a)
-		ia, _ := newAmount.Round(2).Float64()
-		logList = append(logList, &fms.ContractRegisterLog{
-			ContractRegisterId: ob.ContractRegisterId,
-			AdminId:            int(adminInfo.AdminId),
-			AdminName:          adminInfo.RealName,
-			OpData:             opData,
-			OpType:             opType,
-			CreateTime:         nowTime,
-			AmountRemark:       fmt.Sprint("新增", fms.ContractInvoiceKeyNameMap[opType], "金额", ia, "元"),
-		})
+			if e := v.Create(); e != nil {
+				resp.FailData("日期格式有误", "Err:"+e.Error(), c)
+				return
+			}
 
-		if e := v.Create(); e != nil {
-			resp.FailData("日期格式有误", "Err:"+e.Error(), c)
+			//最后删除预到款记录
+			e = ppItem.Delete()
+			if e != nil {
+				resp.FailMsg("删除预到款记录失败", "Err:"+e.Error(), c)
+				return
+			}
+		}
+		ppOB := new(fms.ContractPreRegister)
+		item, e := ppOB.FetchByRegisterId(req.ContractRegisterId)
+		if e != nil {
+			if e == utils.ErrNoRow {
+				resp.Fail("预登记记录不存在或已被删除", c)
+				return
+			}
+			resp.FailMsg("获取预登记失败", "Err:"+e.Error(), c)
 			return
 		}
-
-		//最后删除预到款记录
-		e = ppItem.Delete()
+		e  = item.Delete()
 		if e != nil {
-			resp.FailMsg("删除预到款记录失败", "Err:"+e.Error(), c)
+			resp.FailMsg("删除预登记失败", "Err:"+e.Error(), c)
 			return
 		}
 		// 校验金额-是否修改状态
@@ -583,9 +607,9 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	originHasPayment := item.HasPayment
 
 	updateCols := []string{
-		"ProductIds", "ContractCode", "RelateContractCode", "CrmContractId", "ContractSource", "CompanyName", "ActualCompanyName",
+		"ProductIds", "ContractCode", "RelateContractCode", "CrmContractId", "ContractSource", "CompanyName",
 		"SellerId", "SellerName", "ContractType", "ContractAmount", "StartDate", "EndDate", "SignDate", "AgreedPayTime","RaiSellerId","RaiSellerName",
-		"ContractStatus", "RegisterStatus", "Remark", "ServiceRemark", "HasPayment", "NewCompany", "ModifyTime",
+		"ContractStatus", "RegisterStatus", "Remark", "ServiceRemark", "HasPayment", "ModifyTime",
 	}
 	nowTime := time.Now().Local()
 	item.ProductIds = req.ProductIds
@@ -595,7 +619,6 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	item.CrmContractId = req.CrmContractId
 	item.ContractSource = req.ContractSource
 	item.CompanyName = req.CompanyName
-	item.ActualCompanyName = req.ActualCompanyName
 	item.SellerId = sellerId
 	item.SellerName = sellerName
 	item.RaiSellerId = raiSellerId
@@ -611,7 +634,6 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	item.Remark = req.Remark
 	item.ServiceRemark = req.ServiceRemark
 	item.HasPayment = req.HasPayment
-	item.NewCompany = req.NewCompany
 	item.ModifyTime = nowTime
 
 	// 存在代付的直接完成登记, 且不允许进行开票/到款登记

+ 5 - 0
models/fms/contract_pre_register.go

@@ -128,6 +128,11 @@ func (c *ContractPreRegister) Fetch(id int) (item *ContractPreRegister, err erro
 	return
 }
 
+func (c *ContractPreRegister) FetchByRegisterId(id int) (item *ContractPreRegister, err error) {
+	err = global.DEFAULT_MYSQL.Model(c).Where(" contract_register_id = ?", id).First(&item).Error
+	return
+}
+
 // 删除
 func (c *ContractPreRegister) Delete() (err error) {
 	err = global.DEFAULT_MYSQL.Delete(c).Error

+ 1 - 3
models/fms/contract_register.go

@@ -171,7 +171,6 @@ type ContractRegisterAddReq struct {
 	CrmContractId          int                           `json:"crm_contract_id" description:"CRM系统-合同ID"`
 	ContractSource         int                           `json:"contract_source" binding:"oneof=0 1" description:"合同来源: 0-非系统合同导入; 1-CRM合同导入"`
 	CompanyName            string                        `json:"company_name" binding:"required" description:"客户名称"`
-	ActualCompanyName      string                        `json:"actual_company_name" description:"实际使用方"`
 	SellerIds              string                        `json:"seller_ids" binding:"required" description:"CRM系统-销售ID"`
 	ContractType           int                           `json:"contract_type" binding:"oneof=1 2 3 4" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
 	ContractAmount         float64                       `json:"contract_amount" binding:"required" description:"合同金额"`
@@ -185,9 +184,8 @@ type ContractRegisterAddReq struct {
 	ProductIds             string                        `json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
 	ServiceRemark          string                        `json:"service_remark" description:"套餐备注"`
 	HasPayment             int                           `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
-	NewCompany             int                           `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
 	Supplement             int                           `json:"supplement" description:"是否为补录合同: 0-否; 1-是"`
-	ContractInvoiceId               int                           `json:"contract_invoice_id" description:"预到款信息ID"`
+	ContractRegisterId     int                           `json:"contract_register_id" description:"登记ID"`
 	Services               []ContractServiceAddReq       `json:"services" description:"服务套餐内容"`
 	ServiceAmount          []ContractServiceAmountAddReq `json:"service_amount" description:"服务套餐金额"`
 }