Browse Source

登记列表-导入

hsun 2 years ago
parent
commit
7155b9f1cc

+ 455 - 143
controller/contract/register.go

@@ -17,6 +17,10 @@ import (
 	fmsService "hongze/fms_api/services/fms"
 	"hongze/fms_api/utils"
 	"net/http"
+	"os"
+	"path"
+	"strconv"
+	"strings"
 	"time"
 )
 
@@ -1336,149 +1340,457 @@ func (rg *RegisterController) InvoiceExport(c *gin.Context) {
 // @Success 200 string "操作成功"
 // @router /contract/register/import [post]
 func (rg *RegisterController) Import(c *gin.Context) {
-	//h, err := c.FormFile("File")
-	//if err != nil {
-	//	resp.FailData("获取文件失败", "Err:"+err.Error(), c)
-	//	return
-	//}
-	//ext := path.Ext(h.Filename)
-	//if ext != ".xlsx" && ext != ".xls" {
-	//	resp.Fail("请上传Excel文件", c)
-	//	return
-	//}
-	//
-	//uploadDir := "static/xls"
-	//err = os.MkdirAll(uploadDir, 766)
-	//if err != nil {
-	//	resp.FailData("存储目录创建失败", "Err:"+err.Error(), c)
-	//	return
-	//}
-	//uploadPath := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
-	//err = c.SaveUploadedFile(h, uploadPath)
-	//if err != nil {
-	//	resp.FailData("保存本地文件失败", "Err:"+err.Error(), c)
-	//	return
-	//}
-	//defer func() {
-	//	_ = os.Remove(uploadPath)
-	//}()
-	//xlFile, err := xlsx.OpenFile(uploadPath)
-	//if err != nil {
-	//	resp.FailData("打开文件失败", "Err:"+err.Error(), c)
-	//	return
-	//}
-	//
-	//// 获取所有已登记,根据合同编号去重
-	//contractCodeArr := make([]string, 0)
-	//registerOB := new(fms.ContractRegister)
-	//registerCond := ``
-	//registerPars := make([]interface{}, 0)
-	//registerList, e := registerOB.List(registerCond, registerPars)
-	//if e != nil {
-	//	resp.FailData("获取合同登记列表失败", "Err:"+e.Error(), c)
-	//	return
-	//}
-	//for i := range registerList {
-	//	contractCodeArr = append(contractCodeArr, registerList[i].ContractCode)
-	//}
-	//
-	//// 获取所有销售名称Map
-	//sellerNameIdMap := make(map[string]int)
-	//sellerCond := ``
-	//sellerPars := make([]interface{}, 0)
-	//sellerList, e := crm.GetCompanySellerByRoleCodes(sellerCond, sellerPars)
-	//if e != nil {
-	//	resp.FailData("获取销售列表失败", "Err:"+e.Error(), c)
-	//	return
-	//}
-	//for i := range sellerList {
-	//	sellerNameIdMap[sellerList[i].RealName] = sellerList[i].AdminId
-	//}
-	//
-	//// 获取品种权限Map
-	//chartPermissionNameIdMap := make(map[string]int)
-	//cpCond := `product_id = ?`
-	//cpPars := make([]interface{}, 0)
-	//cpPars = append(cpPars, crm.CompanyProductFicc)
-	//cp := new(crm.ChartPermission)
-	//permissionList, e := cp.List(cpCond, cpPars)
-	//if e != nil {
-	//	resp.FailData("获取权限列表失败", "Err:"+e.Error(), c)
-	//	return
-	//}
-	//for i := range permissionList {
-	//	chartPermissionNameIdMap[permissionList[i].PermissionName] = permissionList[i].ChartPermissionId
-	//}
-	//
-	//// TODO:获取所有套餐
-	//
-	//titleMap := make(map[int]string)
-	//for _, sheet := range xlFile.Sheets {
-	//	// 遍历行读取
-	//	maxRow := sheet.MaxRow
-	//	for i := 0; i < maxRow; i++ {
-	//		// 第二行开始读取表头
-	//		if i == 1 {
-	//			row := sheet.Row(i)
-	//			cells := row.Cells
-	//			for k, cell := range cells {
-	//				text := cell.String()
-	//				titleMap[k] = text
-	//				// 只检验前面部分表头
-	//				if k == 0 {
-	//					if text != "客户名称" {
-	//						resp.Fail("匹配失败, 请按模板导入", c)
-	//						return
-	//					}
-	//				}
-	//				if k == 1 {
-	//					if !strings.Contains(text, "续约") {
-	//						resp.Fail("匹配失败, 请按模板导入", c)
-	//						return
-	//					}
-	//				}
-	//				if k == 2 {
-	//					if text != "销售" {
-	//						resp.Fail("匹配失败, 请按模板导入", c)
-	//						return
-	//					}
-	//				}
-	//				if k == 3 {
-	//					if text != "FICC大套餐" {
-	//						resp.Fail("匹配失败, 请按模板导入", c)
-	//						return
-	//					}
-	//				}
-	//			}
-	//		}
-	//		// 数据行
-	//		if i >= 2 {
-	//			row := sheet.Row(i)
-	//			cells := row.Cells
-	//			var userName, countryCode, mobile, companyName string
-	//			for k, cell := range cells {
-	//				if k == 0 {
-	//					userName = utils.TrimStr(cell.String())
-	//				}
-	//				if k == 1 {
-	//					countryCode = utils.TrimStr(cell.String())
-	//				}
-	//				if k == 2 {
-	//					mobile = utils.TrimStr(cell.String())
-	//				}
-	//				if k == 3 {
-	//					companyName = utils.TrimStr(cell.String())
-	//				}
-	//			}
-	//
-	//			// TODO:新增登记
-	//
-	//			// TODO:新增套餐
-	//
-	//			// TODO:新增开票/到款信息
-	//		}
-	//	}
-	//}
+	h, err := c.FormFile("File")
+	if err != nil {
+		resp.FailData("获取文件失败", "Err:"+err.Error(), c)
+		return
+	}
+	ext := path.Ext(h.Filename)
+	if ext != ".xlsx" && ext != ".xls" {
+		resp.Fail("请上传Excel文件", c)
+		return
+	}
+
+	uploadDir := "static/xls"
+	err = os.MkdirAll(uploadDir, 766)
+	if err != nil {
+		resp.FailData("存储目录创建失败", "Err:"+err.Error(), c)
+		return
+	}
+	uploadPath := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
+	err = c.SaveUploadedFile(h, uploadPath)
+	if err != nil {
+		resp.FailData("保存本地文件失败", "Err:"+err.Error(), c)
+		return
+	}
+	defer func() {
+		_ = os.Remove(uploadPath)
+	}()
+	xlFile, err := xlsx.OpenFile(uploadPath)
+	if err != nil {
+		resp.FailData("打开文件失败", "Err:"+err.Error(), c)
+		return
+	}
+
+	// 获取所有已登记,根据合同编号去重
+	contractCodeArr := make([]string, 0)
+	registerOB := new(fms.ContractRegister)
+	registerCond := ``
+	registerPars := make([]interface{}, 0)
+	registerList, e := registerOB.List(registerCond, registerPars)
+	if e != nil {
+		resp.FailData("获取合同登记列表失败", "Err:"+e.Error(), c)
+		return
+	}
+	for i := range registerList {
+		contractCodeArr = append(contractCodeArr, registerList[i].ContractCode)
+	}
+
+	// 获取所有销售名称Map
+	sellerNameIdMap := make(map[string]int)
+	sellerCond := ``
+	sellerPars := make([]interface{}, 0)
+	sellerList, e := crm.GetCompanySellerByRoleCodes(sellerCond, sellerPars)
+	if e != nil {
+		resp.FailData("获取销售列表失败", "Err:"+e.Error(), c)
+		return
+	}
+	for i := range sellerList {
+		sellerNameIdMap[sellerList[i].RealName] = sellerList[i].AdminId
+	}
+
+	// 获取品种权限Map
+	chartPermissionNameIdMap := make(map[string]int)
+	cpCond := `product_id = ?`
+	cpPars := make([]interface{}, 0)
+	cpPars = append(cpPars, crm.CompanyProductFicc)
+	cp := new(crm.ChartPermission)
+	permissionList, e := cp.List(cpCond, cpPars)
+	if e != nil {
+		resp.FailData("获取权限列表失败", "Err:"+e.Error(), c)
+		return
+	}
+	for i := range permissionList {
+		chartPermissionNameIdMap[permissionList[i].PermissionName] = permissionList[i].ChartPermissionId
+	}
+
+	// 获取所有套餐模板
+	serviceTempCond := ``
+	serviceTempPars := make([]interface{}, 0)
+	serviceTempOB := new(fms.ContractServiceTemplate)
+	serviceTempList, e := serviceTempOB.List(serviceTempCond, serviceTempPars)
+	if e != nil {
+		resp.FailData("获取套餐模板列表失败", "Err:"+e.Error(), c)
+		return
+	}
+	serviceTempNameMap := make(map[string]*fms.ContractServiceTemplate)
+	for i := range serviceTempList {
+		serviceTempNameMap[serviceTempList[i].Title] = serviceTempList[i]
+	}
+
+	titleMap := make(map[int]string)
+	newIds := make([]int, 0)
+	for _, sheet := range xlFile.Sheets {
+		// 遍历行读取
+		maxRow := sheet.MaxRow
+		for i := 0; i < maxRow; i++ {
+			// 第二行开始读取表头
+			if i == 1 {
+				row := sheet.Row(i)
+				cells := row.Cells
+				for k, cell := range cells {
+					text := cell.String()
+					titleMap[k] = text
+					// 只检验前面部分表头
+					if k == 0 {
+						if text != "客户名称" {
+							resp.Fail("匹配失败, 请按模板导入", c)
+							return
+						}
+					}
+					if k == 1 {
+						if !strings.Contains(text, "续约") {
+							resp.Fail("匹配失败, 请按模板导入", c)
+							return
+						}
+					}
+					if k == 2 {
+						if text != "销售" {
+							resp.Fail("匹配失败, 请按模板导入", c)
+							return
+						}
+					}
+					if k == 3 {
+						if text != "FICC大套餐" {
+							resp.Fail("匹配失败, 请按模板导入", c)
+							return
+						}
+					}
+				}
+			}
+			// 数据行
+			if i >= 2 {
+				row := sheet.Row(i)
+				cells := row.Cells
+
+				// 登记信息
+				rowRegister := new(fms.ContractRegister)
+				// 套餐
+				rowServices := make([]*fms.ContractService, 0)
+				// 开票/到款
+				rowInvoices := make([]*fms.ContractInvoice, 0)
+
+				rowChartPermissionIdArr := make([]string, 0)
+				rowInvoice1 := new(fms.ContractInvoice)
+				rowInvoice2 := new(fms.ContractInvoice)
+				rowInvoice3 := new(fms.ContractInvoice)
+				rowInvoice4 := new(fms.ContractInvoice)
+				rowInvoice5 := new(fms.ContractInvoice)
+				rowInvoice6 := new(fms.ContractInvoice)
+				for k, cell := range cells {
+					// 客户名称
+					if k == 0 {
+						rowRegister.CompanyName = utils.TrimStr(cell.String())
+					}
+					// 续约/新增
+					if k == 1 {
+						if utils.TrimStr(cell.String()) == "0" {
+							rowRegister.ContractType = fms.ContractTypeRenew
+						}
+						if utils.TrimStr(cell.String()) == "1" {
+							rowRegister.ContractType = fms.ContractTypeNew
+						}
+					}
+					// 销售
+					if k == 2 {
+						rowRegister.SellerName = utils.TrimStr(cell.String())
+						rowRegister.SellerId = sellerNameIdMap[rowRegister.SellerName]
+					}
+					// FICC大套餐
+					if k == 3 {
+						if utils.TrimStr(cell.String()) == "是" {
+							tempItem := serviceTempNameMap[titleMap[k]]
+							if tempItem == nil {
+								resp.Fail("套餐名称不匹配, 请按模板导入", c)
+								return
+							}
+							cs := &fms.ContractService{
+								ProductId:         crm.CompanyProductFicc,
+								ServiceTemplateId: tempItem.ServiceTemplateId,
+								Title:             tempItem.Title,
+								Value:             tempItem.Value,
+								TableValue:        tempItem.TableValue,
+								ChartPermissionId: tempItem.ChartPermissionId,
+							}
+							cs.Set()
+							rowServices = append(rowServices, cs)
+						}
+					}
+					// FICC小套餐
+					if k >= 4 && k <= 23 {
+						// 小套餐权限
+						if utils.TrimStr(cell.String()) == "是" {
+							rowChartPermissionIdArr = append(rowChartPermissionIdArr, strconv.Itoa(chartPermissionNameIdMap[titleMap[k]]))
+						}
+					}
+					// 市场策略/财富管理
+					if k == 24 || k == 25 {
+						if utils.TrimStr(cell.String()) == "是" {
+							tempItem := serviceTempNameMap[titleMap[k]]
+							if tempItem == nil {
+								resp.Fail("市场策略/财富管理套餐名称不匹配, 请按模板导入", c)
+								return
+							}
+							cs := &fms.ContractService{
+								ProductId:         crm.CompanyProductFicc,
+								ServiceTemplateId: tempItem.ServiceTemplateId,
+								Title:             tempItem.Title,
+								Value:             tempItem.Value,
+								TableValue:        tempItem.TableValue,
+								ChartPermissionId: tempItem.ChartPermissionId,
+							}
+							cs.Set()
+							rowServices = append(rowServices, cs)
+						}
+					}
+					// 套餐备注
+					if k == 26 {
+						rowRegister.ServiceRemark = utils.TrimStr(cell.String())
+					}
+					// 开始时间/到期时间
+					if k == 27 {
+						startDate, e := time.ParseInLocation("2006/01/02", utils.TrimStr(cell.String()), time.Local)
+						if e != nil {
+							resp.Fail("开始时间格式有误, 请按模板导入", c)
+							return
+						}
+						rowRegister.StartDate = startDate
+					}
+					if k == 28 {
+						endDate, e := time.ParseInLocation("2006/01/02", utils.TrimStr(cell.String()), time.Local)
+						if e != nil {
+							resp.Fail("到期时间格式有误, 请按模板导入", c)
+							return
+						}
+						rowRegister.EndDate = endDate
+					}
+					// 合同金额
+					if k == 29 {
+						amountStr := utils.TrimStr(cell.String())
+						amount, e := strconv.ParseFloat(amountStr, 64)
+						if e != nil {
+							resp.Fail("合同金额有误, 请按模板导入", c)
+							return
+						}
+						rowRegister.ContractAmount = amount
+					}
+					// 约定付款日期
+					if k == 30 {
+						rowRegister.AgreedPayTime = utils.TrimStr(cell.String())
+					}
+					// 签订日
+					// k == 32为签订月,可忽略
+					if k == 31 {
+						signDate, e := time.ParseInLocation("2006/01/02", utils.TrimStr(cell.String()), time.Local)
+						if e != nil {
+							resp.Fail("开始时间格式有误, 请按模板导入", c)
+							return
+						}
+						rowRegister.SignDate = signDate
+					}
+					// 合同状态
+					if k == 33 {
+						rowRegister.ContractStatus = fms.ContractStatusNameKeyMap[utils.TrimStr(cell.String())]
+					}
+					// 合同编号
+					if k == 34 {
+						rowContractCode := utils.TrimStr(cell.String())
+						if utils.InArrayByStr(contractCodeArr, rowContractCode) {
+							// 此合同已登记, 跳过本行的读取
+							break
+						}
+						rowRegister.ContractCode = rowContractCode
+					}
+					// 备注
+					if k == 35 {
+						rowRegister.Remark = utils.TrimStr(cell.String())
+					}
+					// 开票日/开票金额
+					if k == 36 {
+						if utils.TrimStr(cell.String()) != "" {
+							fmt.Println("36", utils.TrimStr(cell.String()))
+							invoiceDate, e := time.ParseInLocation("2006/01/02", utils.TrimStr(cell.String()), time.Local)
+							if e != nil {
+								resp.Fail("开票时间1格式有误, 请按模板导入", c)
+								return
+							}
+							rowInvoice1.InvoiceDate = invoiceDate
+							rowInvoice1.ContractCode = rowRegister.ContractCode
+							rowInvoice1.InvoiceType = fms.ContractInvoiceTypeMake
+						}
+					}
+					if k == 37 && utils.TrimStr(cell.String()) != "" {
+						amountStr := utils.TrimStr(cell.String())
+						amount, e := strconv.ParseFloat(amountStr, 64)
+						if e != nil {
+							resp.Fail("开票金额1有误, 请按模板导入", c)
+							return
+						}
+						rowInvoice1.Amount = amount
+						rowInvoices = append(rowInvoices, rowInvoice1)
+					}
+					if k == 38 {
+						if utils.TrimStr(cell.String()) != "" {
+							invoiceDate, e := time.ParseInLocation("2006/01/02", utils.TrimStr(cell.String()), time.Local)
+							if e != nil {
+								resp.Fail("开票时间2格式有误, 请按模板导入", c)
+								return
+							}
+							rowInvoice2.InvoiceDate = invoiceDate
+							rowInvoice2.ContractCode = rowRegister.ContractCode
+							rowInvoice2.InvoiceType = fms.ContractInvoiceTypeMake
+						}
+					}
+					if k == 39 && utils.TrimStr(cell.String()) != "" {
+						amountStr := utils.TrimStr(cell.String())
+						amount, e := strconv.ParseFloat(amountStr, 64)
+						if e != nil {
+							resp.Fail("开票金额2有误, 请按模板导入", c)
+							return
+						}
+						rowInvoice2.Amount = amount
+						rowInvoices = append(rowInvoices, rowInvoice2)
+					}
+					if k == 40 {
+						if utils.TrimStr(cell.String()) != "" {
+							invoiceDate, e := time.ParseInLocation("2006/01/02", utils.TrimStr(cell.String()), time.Local)
+							if e != nil {
+								resp.Fail("开票时间3格式有误, 请按模板导入", c)
+								return
+							}
+							rowInvoice3.InvoiceDate = invoiceDate
+							rowInvoice3.ContractCode = rowRegister.ContractCode
+							rowInvoice3.InvoiceType = fms.ContractInvoiceTypeMake
+						}
+					}
+					if k == 41 && utils.TrimStr(cell.String()) != "" {
+						amountStr := utils.TrimStr(cell.String())
+						amount, e := strconv.ParseFloat(amountStr, 64)
+						if e != nil {
+							resp.Fail("开票金额3有误, 请按模板导入", c)
+							return
+						}
+						rowInvoice3.Amount = amount
+						rowInvoices = append(rowInvoices, rowInvoice3)
+					}
+					// 收款日/收款金额
+					if k == 42 {
+						if utils.TrimStr(cell.String()) != "" {
+							invoiceDate, e := time.ParseInLocation("2006/01/02", utils.TrimStr(cell.String()), time.Local)
+							if e != nil {
+								resp.Fail("收款时间1格式有误, 请按模板导入", c)
+								return
+							}
+							rowInvoice4.InvoiceDate = invoiceDate
+							rowInvoice4.ContractCode = rowRegister.ContractCode
+							rowInvoice4.InvoiceType = fms.ContractInvoiceTypePay
+						}
+					}
+					if k == 43 && utils.TrimStr(cell.String()) != "" {
+						amountStr := utils.TrimStr(cell.String())
+						amount, e := strconv.ParseFloat(amountStr, 64)
+						if e != nil {
+							resp.Fail("收款金额1有误, 请按模板导入", c)
+							return
+						}
+						rowInvoice4.Amount = amount
+						rowInvoices = append(rowInvoices, rowInvoice4)
+					}
+					if k == 44 {
+						if utils.TrimStr(cell.String()) != "" {
+							invoiceDate, e := time.ParseInLocation("2006/01/02", utils.TrimStr(cell.String()), time.Local)
+							if e != nil {
+								resp.Fail("收款时间2格式有误, 请按模板导入", c)
+								return
+							}
+							rowInvoice5.InvoiceDate = invoiceDate
+							rowInvoice5.ContractCode = rowRegister.ContractCode
+							rowInvoice5.InvoiceType = fms.ContractInvoiceTypePay
+						}
+					}
+					if k == 45 && utils.TrimStr(cell.String()) != "" {
+						amountStr := utils.TrimStr(cell.String())
+						amount, e := strconv.ParseFloat(amountStr, 64)
+						if e != nil {
+							resp.Fail("收款金额2有误, 请按模板导入", c)
+							return
+						}
+						rowInvoice5.Amount = amount
+						rowInvoices = append(rowInvoices, rowInvoice5)
+					}
+					if k == 46 {
+						if utils.TrimStr(cell.String()) != "" {
+							invoiceDate, e := time.ParseInLocation("2006/01/02", utils.TrimStr(cell.String()), time.Local)
+							if e != nil {
+								resp.Fail("收款时间3格式有误, 请按模板导入", c)
+								return
+							}
+							rowInvoice6.InvoiceDate = invoiceDate
+							rowInvoice6.ContractCode = rowRegister.ContractCode
+							rowInvoice6.InvoiceType = fms.ContractInvoiceTypePay
+						}
+					}
+					if k == 47 && utils.TrimStr(cell.String()) != "" {
+						amountStr := utils.TrimStr(cell.String())
+						amount, e := strconv.ParseFloat(amountStr, 64)
+						if e != nil {
+							resp.Fail("收款金额3有误, 请按模板导入", c)
+							return
+						}
+						rowInvoice6.Amount = amount
+						rowInvoices = append(rowInvoices, rowInvoice6)
+					}
+				}
+
+				// 小套餐
+				if len(rowChartPermissionIdArr) > 0 {
+					// 说明有小套餐
+					tempItem := serviceTempNameMap["FICC小套餐"]
+					if tempItem == nil {
+						resp.Fail("小套餐名称不匹配, 请按模板导入", c)
+						return
+					}
+					rowChartPermissionIds := strings.Join(rowChartPermissionIdArr, ",")
+					cs := &fms.ContractService{
+						ProductId:          crm.CompanyProductFicc,
+						ServiceTemplateId:  tempItem.ServiceTemplateId,
+						Title:              tempItem.Title,
+						Value:              tempItem.Value,
+						TableValue:         tempItem.TableValue,
+						ChartPermissionId:  tempItem.ChartPermissionId,
+						ChartPermissionIds: rowChartPermissionIds,
+					}
+					cs.Set()
+					rowServices = append(rowServices, cs)
+				}
+
+				// 新增登记、套餐、开票到款信息
+				newId, e := fms.CreateImportContractRegister(rowRegister, rowServices, rowInvoices)
+				if e != nil {
+					resp.FailData("导入失败", "新增导入登记失败, Err: "+e.Error(), c)
+					return
+				}
+				newIds = append(newIds, newId)
+			}
+		}
+	}
+
+	// 更新登记状态
+	go func() {
+		for i := range newIds {
+			fmsService.CheckContractRegisterAmount(newIds[i])
+		}
+	}()
 
 	resp.Ok("操作成功", c)
 }

+ 6 - 0
models/fms/constants.go

@@ -35,6 +35,12 @@ var ContractStatusKeyNameMap = map[int]string{
 	ContractStatusCheckedBack: "已签回",
 }
 
+var ContractStatusNameKeyMap = map[string]int{
+	"已审批":  ContractStatusApproved,
+	"单章寄出": ContractStatusSendOut,
+	"已签回":  ContractStatusCheckedBack,
+}
+
 var ContractInvoiceKeyNameMap = map[int]string{
 	ContractRegisterOpTypeInvoice: "开票",
 	ContractRegisterOpTypePayment: "到款",

+ 42 - 0
models/fms/contract_register.go

@@ -344,3 +344,45 @@ func formatContractRegister2Item(item *ContractRegister) (formatItem *ContractRe
 	formatItem.CreateTime = utils.TimeTransferString(utils.FormatDateTime, item.CreateTime)
 	return
 }
+
+// CreateImportContractRegister 新增导入的合同登记及套餐、开票到款信息
+func CreateImportContractRegister(item *ContractRegister, serviceList []*ContractService, invoiceList []*ContractInvoice) (newId int, err error) {
+	tx := global.DEFAULT_MYSQL.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	// 新增合同登记
+	if e := tx.Create(item).Error; e != nil {
+		err = e
+		return
+	}
+	newId = item.ContractRegisterId
+
+	// 新增套餐
+	if len(serviceList) > 0 {
+		for i := range serviceList {
+			serviceList[i].ContractRegisterId = newId
+		}
+		if e := tx.CreateInBatches(serviceList, len(serviceList)).Error; e != nil {
+			err = e
+			return
+		}
+	}
+
+	// 新增开票/到款
+	if len(invoiceList) > 0 {
+		for i := range invoiceList {
+			invoiceList[i].ContractRegisterId = newId
+		}
+		if e := tx.CreateInBatches(invoiceList, len(invoiceList)).Error; e != nil {
+			err = e
+			return
+		}
+	}
+	return
+}

+ 9 - 0
models/fms/contract_service_template.go

@@ -26,6 +26,15 @@ func (st *ContractServiceTemplate) TableName() string {
 	return "contract_service_template"
 }
 
+func (st *ContractServiceTemplate) List(condition string, pars []interface{}) (list []*ContractServiceTemplate, err error) {
+	list = make([]*ContractServiceTemplate, 0)
+	err = global.DEFAULT_MYSQL.Model(st).
+		Where("is_delete = 0").
+		Where(condition, pars...).
+		Find(&list).Error
+	return
+}
+
 type ContractServiceTemplateItem struct {
 	ServiceTemplateId int    `json:"service_template_id" description:"套餐模板ID"`
 	ProductId         int    `json:"product_id" description:"产品ID"`

+ 1 - 0
routers/contract.go

@@ -21,6 +21,7 @@ func InitContract(rg *gin.RouterGroup) {
 	crGroup.POST("payment", cr.Invoice) // 与开票登记用同一个func, 路由作区分划分权限
 	crGroup.GET("invoice_list", cr.InvoiceList)
 	crGroup.GET("invoice_export", cr.InvoiceExport)
+	crGroup.POST("import", cr.Import)
 
 	// 合同套餐
 	sr := new(contract.ServiceController)