浏览代码

Merge branch 'cygx_10.9.1' into debug

ziwen 1 年之前
父节点
当前提交
4248e2c10b
共有 2 个文件被更改,包括 57 次插入65 次删除
  1. 17 0
      models/company_activity_trip.go
  2. 40 65
      services/activity_special.go

+ 17 - 0
models/company_activity_trip.go

@@ -124,3 +124,20 @@ func GetCompanyPermissionNameCheck(companyId, productId int, permissionName stri
 	err = o.Raw(sql, companyId, productId, permissionName).QueryRow(&count)
 	return
 }
+
+
+// GetCompanyReportPermissionByCompanyIdAndProductId 获取权限类型
+func GetCompanyReportPermissionByCompanyIdAndProductId(companyId, productId int) (items []*CompanyReportPermission, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	re.*
+FROM
+	company_report_permission  as re 
+	INNER JOIN chart_permission as  c ON c.chart_permission_id = re.chart_permission_id
+WHERE
+	re.company_id = ? 
+	AND re.product_id = ? 
+	AND STATUS = '正式' `
+	_, err = o.Raw(sql, companyId, productId).QueryRows(&items)
+	return
+}

+ 40 - 65
services/activity_special.go

@@ -1257,7 +1257,7 @@ func SendWxMsgActivitySpecialCancel(cont context.Context) (err error) {
 	return
 }
 
-func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tripRemaining int,mapChartName map[string]int, err error) {
+func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tripRemaining int, mapChartName map[string]int, err error) {
 	companyDetail, e := models.GetCompanyDetailByIdGroup(companyId)
 	if e != nil {
 		err = errors.New("GetCompanyDetailByIdGroup, Err: " + e.Error())
@@ -1275,7 +1275,6 @@ func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tri
 	//chartMap := map[int]string{utils.YI_YAO_ID:utils.YI_YAO_NAME, utils.XIAO_FEI_ID:utils.XIAO_FEI_NAME, utils.KE_JI_ID:utils.KE_JI_NAME, utils.ZHI_ZAO_ID:utils.ZHI_ZAO_NAME}
 	//chartNumMap := map[int]int{utils.YI_YAO_ID:0, utils.XIAO_FEI_ID:0, utils.KE_JI_ID:0, utils.ZHI_ZAO_ID:0}
 	chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
-
 	if companyDetail.Status == "正式" {
 		//var packageType int
 		userType, _, _ = GetUserType(companyId)
@@ -1299,92 +1298,61 @@ func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tri
 			err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
 		}
 		if userType == 2 {
-			//airborneList, e := cygx.GetActivitySpecialTripAirborneCountByActivitySpecial(condition, pars)
-			//if e != nil {
-			//	err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
-			//	return
-			//}
-			//ariborneMap := make(map[int]int)
-			//for _, v := range airborneList {
-			//	ariborneMap[v.ChartPermissionId] = v.Count
-			//}
-			//到会空降的也加入流水记录表,这里不在做单独计算 2023-07-10
-			//airborneTotal, e := cygx.GetActivitySpecialTripAirborneCountByActivitySpecial(condition, pars)
-			//if e != nil {
-			//	err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
-			//	return
-			//}
-			//condition += ` AND is_valid = 1 `
-			//TripBillNumMap := make(map[int]int)
-			//for _, v := range listTripBill {
-			//	TripBillNumMap[v.ChartPermissionId] += v.BillDetailed
-			//}
-			var TripBillNum int
+
+			var tripBillNum int
 			for _, v := range listTripBill {
 				//if v.ActivityId == 0 {
 				//	continue
 				//}
-				TripBillNum += v.BillDetailed
+				tripBillNum += v.BillDetailed
+			}
+			if len(inheritList) > 0 {
+				for _, v := range inheritList {
+					if v.ChartPermissionId == 0 {
+						tripBillNum += v.Points
+					}
+				}
 			}
-			// CRM13.2 70w客户有16次专项调研, 45w有10次
-			//packageTypeMap := map[int]int{1: 16, 2: 10}
-			//totalTrip := packageTypeMap[packageType]
 
-			tripRemaining = TripBillNum
+			tripRemaining = tripBillNum
 			if tripRemaining < 0 {
 				tripRemaining = 0
 			}
 
-			//for k, _ := range chartNumMap {
-			//	tripRemaining := totalTrip - ariborneMap[k] + TripBillNumMap[k]
-			//	if tripRemaining < 0 {
-			//		tripRemaining = 0
-			//	}
-			//	specialSurplus += chartMap[k] + strconv.Itoa(tripRemaining) + "次,"
-			//}
-			//specialSurplus = strings.TrimRight(specialSurplus, ",")
-
-			//tripRemaining = 12 - tripTota
 		} else {
-			list, e := models.GetCompanyReportPermissionUpgrade(companyId, 2)
+			list, e := models.GetCompanyReportPermissionByCompanyIdAndProductId(companyId, 2)
 			if e != nil && e.Error() != utils.ErrNoRow() {
 				err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
 			}
-			// 10.9.1本身升级没有也可能通过继承获得
-			//if len(list) == 0 {
-			//	return
-			//}
+			if len(list) == 0 {
+				return
+			}
 			var chartPermissionIdSlice []string
 			mapChartName = make(map[string]int)
-			mapInheritChartName := make(map[string]int)
+			mapUpgradeId := make(map[int]int)
 			mapPermissionNameTrip := make(map[string]int)
-
+			mapInheritChartName := make(map[string]int)
 			//mapPermissionName := make(map[int]string)
 			for _, v := range list {
 				chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
-
+				//是升级套餐才有点数
+				if v.IsUpgrade == 1 {
+					mapUpgradeId[v.ChartPermissionId] = 1
+				}
 			}
-			chartList, e := models.GetChartPermissionByIds(chartPermissionIdSlice)
-			if e != nil {
-				err = errors.New("获取品种信息失败, Err:" + e.Error())
-				return
+			chartList := make([]*models.ChartPermission, 0)
+			if len(chartPermissionIdSlice) > 0 {
+				chartList, e = models.GetChartPermissionByIds(chartPermissionIdSlice)
+				if e != nil {
+					err = errors.New("获取品种信息失败, Err:" + e.Error())
+					return
+				}
 			}
-			// 10.9.1本身升级没有也可能通过继承获得
-			//if len(chartList) == 0 {
-			//	return
-			//}
 
-			//到会空降的也加入流水记录表,这里不在做单独计算 2023-07-10
-			//airborneList, e := cygx.GetCygxActivitySpecialTripAirborneListByComapnyId(companyId)
-			//if e != nil {
-			//	err = errors.New("获取品种信息失败, Err:" + e.Error())
-			//	return
-			//}
-			//for _, v := range airborneList {
-			//	mapPermissionNameTrip[v.ChartPermissionName] += 1
-			//}
+			if len(chartList) == 0 {
+				return
+			}
 
-			//var TripBillNum int
 			for _, v := range listTripBill {
 				if v.ActivityId == 0 {
 					continue
@@ -1392,8 +1360,14 @@ func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tri
 				mapPermissionNameTrip[v.ChartPermissionName] += v.BillDetailed
 			}
 			for _, v := range chartList {
-				mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.PermissionName]
+				//如果是升级则加点
+				if _, ok := mapUpgradeId[v.ChartPermissionId]; ok {
+					mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.PermissionName]
+				} else {
+					mapChartName[v.PermissionName] = mapPermissionNameTrip[v.PermissionName]
+				}
 			}
+			// 通过继承获得的加点
 			for _, v := range inheritList {
 				mapInheritChartName[v.ChartPermissionName] = v.Points
 			}
@@ -1404,6 +1378,7 @@ func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tri
 					}
 				}
 			}
+
 			for k, v := range mapChartName {
 				if v > 0 {
 					specialSurplus += k + strconv.Itoa(v) + "次+"