|
@@ -16,9 +16,11 @@ type ContractRegister struct {
|
|
|
ContractSource int `gorm:"column:contract_source" json:"contract_source" description:"合同来源: 0-非系统合同导入; 1-CRM合同导入"`
|
|
|
CompanyName string `gorm:"column:company_name" json:"company_name" description:"客户名称"`
|
|
|
ActualCompanyName string `gorm:"column:actual_company_name" json:"actual_company_name" description:"实际使用方"`
|
|
|
- ProductId int `gorm:"column:product_id" json:"product_id" description:"产品ID: 1-FICC; 2-权益"`
|
|
|
+ ProductIds string `gorm:"column:product_ids" json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
|
|
|
SellerId int `gorm:"column:seller_id" json:"seller_id" description:"CRM系统-销售ID"`
|
|
|
SellerName string `gorm:"column:seller_name" json:"seller_name" description:"CRM系统-销售名称"`
|
|
|
+ RaiSellerId int `gorm:"column:rai_seller_id" json:"rai_seller_id" description:"CRM系统-权益销售ID"`
|
|
|
+ RaiSellerName string `gorm:"column:rai_seller_name" json:"rai_seller_name" description:"CRM系统-权益销售名称"`
|
|
|
ContractType int `gorm:"column:contract_type" json:"contract_type" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
|
|
|
ContractAmount float64 `gorm:"column:contract_amount" json:"contract_amount" description:"合同金额"`
|
|
|
InvoicedAmount float64 `gorm:"column:invoiced_amount" json:"invoiced_amount" description:"开票金额"`
|
|
@@ -98,7 +100,7 @@ type ContractRegisterListReq struct {
|
|
|
Keyword string `json:"keyword" form:"keyword" binding:"omitempty" description:"关键词"`
|
|
|
StartDate string `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"合同开始日期"`
|
|
|
EndDate string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"合同结束日期"`
|
|
|
- ServiceType int `json:"service_type" form:"service_type" description:"套餐类型"`
|
|
|
+ ServiceTypes string `json:"service_types" form:"service_types" description:"套餐类型"`
|
|
|
ContractType int `json:"contract_type" form:"contract_type" description:"合同类型"`
|
|
|
RegisterStatus int `json:"register_status" form:"register_status" description:"登记状态"`
|
|
|
base.PageReq
|
|
@@ -113,8 +115,11 @@ type ContractRegisterItem struct {
|
|
|
ContractSource int `json:"contract_source" description:"合同来源: 0-非系统合同导入; 1-CRM合同导入"`
|
|
|
CompanyName string `json:"company_name" description:"客户名称"`
|
|
|
ActualCompanyName string `json:"actual_company_name" description:"实际使用方"`
|
|
|
+ ProductIds string `json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
|
|
|
SellerId int `json:"seller_id" description:"CRM系统-销售ID"`
|
|
|
SellerName string `json:"seller_name" description:"CRM系统-销售名称"`
|
|
|
+ RaiSellerId int `json:"rai_seller_id" description:"CRM系统-权益销售ID"`
|
|
|
+ RaiSellerName string `json:"rai_seller_name" description:"CRM系统-权益销售名称"`
|
|
|
ContractType int `json:"contract_type" description:"合同类型: 1-新签; 2-续约"`
|
|
|
ContractAmount float64 `json:"contract_amount" description:"合同金额"`
|
|
|
InvoicedAmount float64 `json:"invoiced_amount" description:"开票金额"`
|
|
@@ -132,6 +137,7 @@ type ContractRegisterItem struct {
|
|
|
HasPayment int `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
|
|
|
NewCompany int `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
|
|
|
CreateTime string `json:"create_time" description:"登记时间"`
|
|
|
+ SellerIds string `json:"seller_ids"`
|
|
|
}
|
|
|
|
|
|
// ContractRegisterList 合同登记列表
|
|
@@ -155,30 +161,30 @@ type ContractRegisterUpdateStatusReq struct {
|
|
|
|
|
|
// ContractRegisterAddReq 新增合同登记请求体
|
|
|
type ContractRegisterAddReq struct {
|
|
|
- ContractCode string `json:"contract_code" binding:"required" description:"合同编号"`
|
|
|
- RelateContractCode string `json:"relate_contract_code" description:"关联合同编号"`
|
|
|
- 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:"实际使用方"`
|
|
|
- SellerId int `json:"seller_id" binding:"required" description:"CRM系统-销售ID"`
|
|
|
- SellerName string `json:"seller_name" binding:"required" description:"CRM系统-销售名称"`
|
|
|
- ContractType int `json:"contract_type" binding:"oneof=1 2 3 4" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
|
|
|
- ContractAmount float64 `json:"contract_amount" binding:"required" description:"合同金额"`
|
|
|
- CurrencyUnit string `json:"currency_unit" binding:"required" description:"货币单位"`
|
|
|
- StartDate string `json:"start_date" binding:"required" description:"合同开始日期"`
|
|
|
- EndDate string `json:"end_date" binding:"required" description:"合同结束日期"`
|
|
|
- SignDate string `json:"sign_date" description:"合同签订日期"`
|
|
|
- AgreedPayTime string `json:"agreed_pay_time" description:"约定付款时间(如:生效日起10日内)"`
|
|
|
- ContractStatus int `json:"contract_status" binding:"oneof=1 2 3 4 5" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回; 4-已终止; 5-邮件备案"`
|
|
|
- Remark string `json:"remark" description:"备注信息"`
|
|
|
- ProductId int `json:"product_id" binding:"oneof=1 2" description:"产品ID"`
|
|
|
- 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-是"`
|
|
|
- PrePayId int `json:"pre_pay_id" description:"预到款信息ID"`
|
|
|
- Services []ContractServiceAddReq `json:"services" description:"服务套餐内容"`
|
|
|
+ ContractCode string `json:"contract_code" binding:"required" description:"合同编号"`
|
|
|
+ RelateContractCode string `json:"relate_contract_code" description:"关联合同编号"`
|
|
|
+ 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:"合同金额"`
|
|
|
+ CurrencyUnit string `json:"currency_unit" binding:"required" description:"货币单位"`
|
|
|
+ StartDate string `json:"start_date" binding:"required" description:"合同开始日期"`
|
|
|
+ EndDate string `json:"end_date" binding:"required" description:"合同结束日期"`
|
|
|
+ SignDate string `json:"sign_date" description:"合同签订日期"`
|
|
|
+ AgreedPayTime string `json:"agreed_pay_time" description:"约定付款时间(如:生效日起10日内)"`
|
|
|
+ ContractStatus int `json:"contract_status" binding:"oneof=1 2 3 4 5" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回; 4-已终止; 5-邮件备案"`
|
|
|
+ Remark string `json:"remark" description:"备注信息"`
|
|
|
+ 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-是"`
|
|
|
+ PrePayId int `json:"pre_pay_id" description:"预到款信息ID"`
|
|
|
+ Services []ContractServiceAddReq `json:"services" description:"服务套餐内容"`
|
|
|
+ ServiceAmount []ContractServiceAmountAddReq `json:"service_amount" description:"服务套餐金额"`
|
|
|
}
|
|
|
|
|
|
// ContractRegisterEditReq 编辑合同登记请求体
|
|
@@ -188,7 +194,7 @@ type ContractRegisterEditReq struct {
|
|
|
}
|
|
|
|
|
|
// CreateContractRegisterAndServices 新增合同登记及套餐
|
|
|
-func CreateContractRegisterAndServices(item *ContractRegister, serviceDetail []*ContractServiceAndDetail) (err error) {
|
|
|
+func CreateContractRegisterAndServices(item *ContractRegister, serviceDetail []*ContractServiceAndDetail, serviceAmount []*ContractServiceAmount) (err error) {
|
|
|
tx := global.DEFAULT_MYSQL.Begin()
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -207,7 +213,7 @@ func CreateContractRegisterAndServices(item *ContractRegister, serviceDetail []*
|
|
|
t := serviceDetail[i]
|
|
|
contractService := &ContractService{
|
|
|
ContractRegisterId: item.ContractRegisterId,
|
|
|
- ProductId: item.ProductId,
|
|
|
+ ProductId: t.ProductId,
|
|
|
ServiceTemplateId: t.ServiceTemplateId,
|
|
|
Title: t.Title,
|
|
|
Value: t.Value,
|
|
@@ -230,12 +236,24 @@ func CreateContractRegisterAndServices(item *ContractRegister, serviceDetail []*
|
|
|
// t.Detail[j] = contractServiceDetail
|
|
|
//}
|
|
|
}
|
|
|
+
|
|
|
+ for i := 0; i < len(serviceAmount); i++ {
|
|
|
+ // 合同服务
|
|
|
+ t := serviceAmount[i]
|
|
|
+ tmp := &ContractServiceAmount{
|
|
|
+ ContractRegisterId: item.ContractRegisterId,
|
|
|
+ ProductId: t.ProductId,
|
|
|
+ ServiceAmount: t.ServiceAmount,
|
|
|
+ CurrencyUnit: t.CurrencyUnit,
|
|
|
+ }
|
|
|
+ tx.Create(tmp)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// UpdateContractRegister 更新合同登记
|
|
|
func UpdateContractRegister(item *ContractRegister, updateCols []string, serviceDetail []*ContractServiceAndDetail,
|
|
|
- invoiceList []*ContractInvoice, invoiceUpdateCols []string, invoiceHandleType int) (err error) {
|
|
|
+ invoiceList []*ContractInvoice, invoiceUpdateCols []string, invoiceHandleType int, serviceAmount []*ContractServiceAmount) (err error) {
|
|
|
tx := global.DEFAULT_MYSQL.Begin()
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -256,6 +274,9 @@ func UpdateContractRegister(item *ContractRegister, updateCols []string, service
|
|
|
tx.Exec(sql, item.ContractRegisterId)
|
|
|
sql = `DELETE FROM contract_service_detail WHERE contract_register_id = ?`
|
|
|
tx.Exec(sql, item.ContractRegisterId)
|
|
|
+ sql = `DELETE FROM contract_service_amount WHERE contract_register_id = ?`
|
|
|
+ tx.Exec(sql, item.ContractRegisterId)
|
|
|
+
|
|
|
|
|
|
// 新增合同服务
|
|
|
//nowTime := time.Now().Local()
|
|
@@ -264,7 +285,7 @@ func UpdateContractRegister(item *ContractRegister, updateCols []string, service
|
|
|
t := serviceDetail[i]
|
|
|
contractService := &ContractService{
|
|
|
ContractRegisterId: item.ContractRegisterId,
|
|
|
- ProductId: item.ProductId,
|
|
|
+ ProductId: t.ProductId,
|
|
|
ServiceTemplateId: t.ServiceTemplateId,
|
|
|
Title: t.Title,
|
|
|
Value: t.Value,
|
|
@@ -288,6 +309,18 @@ func UpdateContractRegister(item *ContractRegister, updateCols []string, service
|
|
|
//}
|
|
|
}
|
|
|
|
|
|
+ for i := 0; i < len(serviceAmount); i++ {
|
|
|
+ // 合同服务
|
|
|
+ t := serviceAmount[i]
|
|
|
+ tmp := &ContractServiceAmount{
|
|
|
+ ContractRegisterId: item.ContractRegisterId,
|
|
|
+ ProductId: t.ProductId,
|
|
|
+ ServiceAmount: t.ServiceAmount,
|
|
|
+ CurrencyUnit: t.CurrencyUnit,
|
|
|
+ }
|
|
|
+ tx.Create(tmp)
|
|
|
+ }
|
|
|
+
|
|
|
// 开票到款操作类型: 0-无; 1-更新; 2-删除;
|
|
|
if invoiceHandleType == 2 {
|
|
|
sql = `UPDATE contract_invoice SET is_deleted = 1 WHERE contract_register_id = ?`
|
|
@@ -315,10 +348,11 @@ type ContractRegisterDetailReq struct {
|
|
|
// ContractRegisterDetail-合同登记详情
|
|
|
type ContractRegisterDetail struct {
|
|
|
*ContractRegisterItem
|
|
|
- ServiceList []*ContractServiceAndDetail `json:"service_list" description:"合同服务及详情"`
|
|
|
- InvoiceList []*ContractInvoiceItem `json:"invoice_list" description:"开票信息"`
|
|
|
- PaymentList []*ContractInvoiceItem `json:"payment_list" description:"到款信息"`
|
|
|
- Logs []*ContractRegisterLogItem `json:"logs" description:"登记日志"`
|
|
|
+ ServiceList []*ContractServiceAndDetail `json:"service_list" description:"合同服务及详情"`
|
|
|
+ InvoiceList []*ContractInvoiceItem `json:"invoice_list" description:"开票信息"`
|
|
|
+ PaymentList []*ContractInvoiceItem `json:"payment_list" description:"到款信息"`
|
|
|
+ Logs []*ContractRegisterLogItem `json:"logs" description:"登记日志"`
|
|
|
+ ServiceAmountList []*ContractServiceAmountItem `json:"service_amount_list" description:"合同套餐金额"`
|
|
|
}
|
|
|
|
|
|
// GetContractRegisterItemById 获取合同登记信息
|
|
@@ -364,8 +398,11 @@ func formatContractRegister2Item(item *ContractRegister) (formatItem *ContractRe
|
|
|
formatItem.ContractSource = item.ContractSource
|
|
|
formatItem.CompanyName = item.CompanyName
|
|
|
formatItem.ActualCompanyName = item.ActualCompanyName
|
|
|
+ formatItem.ProductIds = item.ProductIds
|
|
|
formatItem.SellerId = item.SellerId
|
|
|
formatItem.SellerName = item.SellerName
|
|
|
+ formatItem.RaiSellerId = item.RaiSellerId
|
|
|
+ formatItem.RaiSellerName = item.RaiSellerName
|
|
|
formatItem.ContractType = item.ContractType
|
|
|
formatItem.ContractAmount = item.ContractAmount
|
|
|
formatItem.InvoicedAmount = item.InvoicedAmount
|
|
@@ -387,7 +424,7 @@ func formatContractRegister2Item(item *ContractRegister) (formatItem *ContractRe
|
|
|
}
|
|
|
|
|
|
// CreateImportContractRegister 新增导入的合同登记及套餐、开票到款信息
|
|
|
-func CreateImportContractRegister(item *ContractRegister, serviceList []*ContractService, invoiceList []*ContractInvoice) (newId int, err error) {
|
|
|
+func CreateImportContractRegister(item *ContractRegister, serviceList []*ContractService, invoiceList []*ContractInvoice, serviceAmountList []*ContractServiceAmount) (newId int, err error) {
|
|
|
tx := global.DEFAULT_MYSQL.Begin()
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -406,10 +443,29 @@ func CreateImportContractRegister(item *ContractRegister, serviceList []*Contrac
|
|
|
|
|
|
// 新增套餐
|
|
|
if len(serviceList) > 0 {
|
|
|
+ // 过滤重复的数组
|
|
|
+ serviceMap := make(map[int]struct{})
|
|
|
+ addServiceList := make([]*ContractService, 0)
|
|
|
for i := range serviceList {
|
|
|
- serviceList[i].ContractRegisterId = newId
|
|
|
+ if _, ok := serviceMap[serviceList[i].ServiceTemplateId]; !ok {
|
|
|
+ serviceList[i].ContractRegisterId = newId
|
|
|
+ addServiceList = append(addServiceList, serviceList[i])
|
|
|
+ serviceMap[serviceList[i].ServiceTemplateId] = struct{}{}
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if e := tx.CreateInBatches(addServiceList, len(addServiceList)).Error; e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增合同套餐金额相关信息
|
|
|
+ if len(serviceAmountList) > 0 {
|
|
|
+ for i := range serviceAmountList {
|
|
|
+ serviceAmountList[i].ContractRegisterId = newId
|
|
|
}
|
|
|
- if e := tx.CreateInBatches(serviceList, len(serviceList)).Error; e != nil {
|
|
|
+ if e := tx.CreateInBatches(serviceAmountList, len(serviceAmountList)).Error; e != nil {
|
|
|
err = e
|
|
|
return
|
|
|
}
|
|
@@ -456,7 +512,7 @@ func CreateContractRegisterAndServicesAndPayMent(item *ContractRegister, service
|
|
|
t := serviceDetail[i]
|
|
|
contractService := &ContractService{
|
|
|
ContractRegisterId: item.ContractRegisterId,
|
|
|
- ProductId: item.ProductId,
|
|
|
+ ProductId: t.ProductId,
|
|
|
ServiceTemplateId: t.ServiceTemplateId,
|
|
|
Title: t.Title,
|
|
|
Value: t.Value,
|
|
@@ -482,3 +538,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存在"`
|
|
|
+}
|