Browse Source

开票登记销售数据修复脚本、导入导出模板套餐调整

hsun 2 years ago
parent
commit
95342198d2

+ 63 - 32
controller/contract/register.go

@@ -911,11 +911,19 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	}
 
 	// 获取套餐服务
-	//serviceList, e := fms.GetContractServiceTemplateMapByProductId(crm.CompanyProductFicc)
-	//if e != nil {
-	//	resp.FailData("获取套餐服务失败", "Err:"+e.Error(), c)
-	//	return
-	//}
+	serviceList, e := fms.GetContractServiceTemplateMapByProductId(crm.CompanyProductFicc)
+	if e != nil {
+		resp.FailData("获取套餐服务失败", "Err:"+e.Error(), c)
+		return
+	}
+	// 除大小套餐外的其他套餐(下面的导出需要以此动态处理)
+	otherService := make([]*fms.ContractServiceTemplateItem, 0)
+	for i := range serviceList {
+		if serviceList[i].Title != "FICC大套餐" && serviceList[i].Title != "FICC小套餐" {
+			otherService = append(otherService, serviceList[i])
+		}
+	}
+	otherServiceLen := len(otherService)
 
 	// 套餐/开票/到款列表
 	serviceMap := make(map[int][]*fms.ContractService)
@@ -1056,8 +1064,15 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	for i := range permissionList {
 		row2Title = append(row2Title, permissionList[i].PermissionName)
 	}
-	row2Title = append(row2Title, "市场策略", "财富管理", "套餐备注", "开始时间", "到期时间", "2022年合同金额", "约定付款时间", "签订日",
-		"签订月", "合同状态", "合同编号", "备注")
+
+	// 其他套餐
+	for i := range otherService {
+		row2Title = append(row2Title, otherService[i].Title)
+	}
+	row2Title = append(row2Title, "套餐备注", "开始时间", "到期时间", "2022年合同金额", "约定付款时间", "签订日", "签订月",
+		"合同状态", "合同编号", "备注")
+
+	// 设置表头
 	for i := range row2Title {
 		v := titleRow2.AddCell()
 		v.SetValue(row2Title[i])
@@ -1138,7 +1153,23 @@ func (rg *RegisterController) Export(c *gin.Context) {
 			}
 		}
 
-		// 财富管理/市场策略(处理方式其实跟上面的大套餐一样, 只是中间隔了小套餐按照顺序要这么处理=_=!)
+		// 除大小套餐外的其他套餐(处理方式其实跟上面的大套餐一样, 只是中间隔了小套餐按照顺序要这么处理=_=!)
+		for i := 0; i < otherServiceLen; i++ {
+			k += 1
+			otherColName := row2Title[k]
+			otherCol := ""
+			if svList != nil && len(svList) > 0 {
+				for isv := range svList {
+					if svList[isv].Title == otherColName {
+						otherCol = "是"
+						break
+					}
+				}
+			}
+			dataRow.AddCell().SetString(otherCol)
+		}
+
+		// 财富管理/市场策略
 		k += 1
 		col5Name := row2Title[k]
 		col5 := ""
@@ -1632,12 +1663,12 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						continue
 					}
-					// 市场策略/财富管理
-					if k == 24 || k == 25 {
+					// 其他类型套餐
+					if k >= 24 && k <= 30 {
 						if v == "是" {
 							tempItem := serviceTempNameMap[titleMap[k]]
 							if tempItem == nil {
-								resp.Fail(fmt.Sprintf("第%d行市场策略/财富管理套餐名称不匹配, 请按模板导入", i+1), c)
+								resp.Fail(fmt.Sprintf("第%d行套餐名称不匹配, 请按模板导入", i+1), c)
 								return
 							}
 							cs := &fms.ContractService{
@@ -1654,12 +1685,12 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 套餐备注
-					if k == 26 {
+					if k == 31 {
 						rowRegister.ServiceRemark = v
 						continue
 					}
 					// 开始时间/到期时间
-					if k == 27 {
+					if k == 32 {
 						// 转换失败可能是因为格式为Excel日期格式, 读取出来会是一串数字, 将其转换成日期字符串再处理
 						va := cell.Value
 						if va == "" {
@@ -1683,7 +1714,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						rowRegister.StartDate = startDate
 						continue
 					}
-					if k == 28 {
+					if k == 33 {
 						va := cell.Value
 						if va == "" {
 							resp.Fail(fmt.Sprintf("第%d行到期时间不可为空, 请按模板导入", i+1), c)
@@ -1706,7 +1737,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合同金额
-					if k == 29 {
+					if k == 34 {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
@@ -1717,13 +1748,13 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 约定付款日期
-					if k == 30 {
+					if k == 35 {
 						rowRegister.AgreedPayTime = v
 						continue
 					}
 					// 签订日
 					// k == 32为签订月,可忽略
-					if k == 31 {
+					if k == 36 {
 						va := cell.Value
 						if va == "" {
 							continue
@@ -1745,7 +1776,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合同状态
-					if k == 33 {
+					if k == 38 {
 						rowRegister.ContractStatus = fms.ContractStatusNameKeyMap[v]
 						if rowRegister.ContractStatus == 0 {
 							resp.Fail(fmt.Sprintf("第%d行合同状态不匹配, 请按模板导入", i+1), c)
@@ -1754,7 +1785,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合同编号
-					if k == 34 {
+					if k == 39 {
 						rowContractCode := v
 						if rowContractCode == "" {
 							resp.Fail(fmt.Sprintf("第%d行合同编号不可为空, 请按模板导入", i+1), c)
@@ -1769,12 +1800,12 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 备注
-					if k == 35 {
+					if k == 40 {
 						rowRegister.Remark = v
 						continue
 					}
 					// 开票日/开票金额
-					if k == 36 {
+					if k == 41 {
 						if v != "" {
 							va := cell.Value
 							invoiceDate, e := time.ParseInLocation("2006/01/02", va, time.Local)
@@ -1796,7 +1827,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						continue
 					}
-					if k == 37 && v != "" {
+					if k == 42 && v != "" {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
@@ -1807,7 +1838,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						rowInvoices = append(rowInvoices, rowInvoice1)
 						continue
 					}
-					if k == 38 {
+					if k == 43 {
 						if v != "" {
 							va := cell.Value
 							invoiceDate, e := time.ParseInLocation("2006/01/02", va, time.Local)
@@ -1829,7 +1860,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						continue
 					}
-					if k == 39 && v != "" {
+					if k == 44 && v != "" {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
@@ -1840,7 +1871,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						rowInvoices = append(rowInvoices, rowInvoice2)
 						continue
 					}
-					if k == 40 {
+					if k == 45 {
 						if v != "" {
 							va := cell.Value
 							invoiceDate, e := time.ParseInLocation("2006/01/02", va, time.Local)
@@ -1862,7 +1893,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						continue
 					}
-					if k == 41 && v != "" {
+					if k == 46 && v != "" {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
@@ -1874,7 +1905,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 收款日/收款金额
-					if k == 42 {
+					if k == 47 {
 						if v != "" {
 							va := cell.Value
 							invoiceDate, e := time.ParseInLocation("2006/01/02", va, time.Local)
@@ -1896,7 +1927,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						continue
 					}
-					if k == 43 && v != "" {
+					if k == 48 && v != "" {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
@@ -1907,7 +1938,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						rowInvoices = append(rowInvoices, rowInvoice4)
 						continue
 					}
-					if k == 44 {
+					if k == 49 {
 						if v != "" {
 							va := cell.Value
 							invoiceDate, e := time.ParseInLocation("2006/01/02", va, time.Local)
@@ -1929,7 +1960,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						continue
 					}
-					if k == 45 && v != "" {
+					if k == 50 && v != "" {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
@@ -1940,7 +1971,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						rowInvoices = append(rowInvoices, rowInvoice5)
 						continue
 					}
-					if k == 46 {
+					if k == 51 {
 						if v != "" {
 							va := cell.Value
 							invoiceDate, e := time.ParseInLocation("2006/01/02", va, time.Local)
@@ -1962,7 +1993,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						continue
 					}
-					if k == 47 && v != "" {
+					if k == 52 && v != "" {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {

+ 8 - 1
init_serve/task.go

@@ -1,5 +1,12 @@
 package init_serve
 
-func InitTask() {
+import (
+	"fmt"
+)
 
+func InitTask() {
+	// TODO:执行一次
+	fmt.Println("task start")
+	//fmsService.FixContractInvoiceSellerInfo()
+	fmt.Println("task end")
 }

+ 1 - 0
models/fms/contract_service_template.go

@@ -74,6 +74,7 @@ func GetContractServiceTemplateMapByProductId(productId int) (items []*ContractS
 	items = make([]*ContractServiceTemplateItem, 0)
 	err = global.DEFAULT_MYSQL.Table("contract_service_template").
 		Where("product_id = ? AND pid = 0 AND is_delete = 0", productId).
+		Order("service_template_id ASC").
 		Find(&items).Error
 	return
 }

+ 58 - 0
services/fms/contract_register.go

@@ -4,8 +4,10 @@ import (
 	"errors"
 	"fmt"
 	"github.com/shopspring/decimal"
+	"hongze/fms_api/models/crm"
 	"hongze/fms_api/models/fms"
 	"hongze/fms_api/services/alarm_msg"
+	crmService "hongze/fms_api/services/crm"
 	"hongze/fms_api/services/resource"
 	"hongze/fms_api/utils"
 	"os"
@@ -258,3 +260,59 @@ func UploadImageBase64(base64Str string) (resourceUrl string, err error) {
 	resourceUrl = utils.OssHost + savePath
 	return
 }
+
+// FixContractInvoiceSellerInfo 修复开票登记销售相关信息(一次性)
+func FixContractInvoiceSellerInfo() {
+	sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
+	if e != nil {
+		fmt.Println("获取销售列表失败, Err: " + e.Error())
+		return
+	}
+	sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
+	for i := range sellerList {
+		sellerMap[sellerList[i].SellerId] = sellerList[i]
+	}
+
+	registerCond := ``
+	registerPars := make([]interface{}, 0)
+	registerOB := new(fms.ContractRegister)
+	registerList, e := registerOB.List(registerCond, registerPars)
+	if e != nil {
+		fmt.Println("获取合同登记列表失败, Err: " + e.Error())
+		return
+	}
+	invUpCols := []string{"SellerId", "SellerName", "SellerGroupId", "SellerTeamId"}
+	fmt.Println("start 修复")
+	for i := range registerList {
+		registerId := registerList[i].ContractRegisterId
+		sellerId := registerList[i].SellerId
+		sellerItem := sellerMap[sellerId]
+		if sellerItem == nil {
+			fmt.Printf("ID-%d 无销售信息\n", registerId)
+			continue
+		}
+
+		invOB := new(fms.ContractInvoice)
+		invCond := `invoice_type = 1 AND contract_register_id = ?`
+		invPars := make([]interface{}, 0)
+		invPars = append(invPars, registerId)
+		invList, e := invOB.List(invCond, invPars, "")
+		if e != nil {
+			fmt.Println("获取开票登记列表失败, Err: " + e.Error())
+			return
+		}
+		for _, v := range invList {
+			v.SellerId = sellerItem.SellerId
+			v.SellerName = sellerItem.SellerName
+			v.SellerGroupId = sellerItem.GroupId
+			v.SellerTeamId = sellerItem.TeamId
+			if e = v.Update(invUpCols); e != nil {
+				fmt.Println("更新开票登记失败, Err: " + e.Error())
+				return
+			}
+			fmt.Printf("ID-%d 修复成功\n", v.ContractInvoiceId)
+		}
+	}
+	fmt.Println("end 修复")
+	return
+}