ziwen 1 year ago
parent
commit
7c8ddae2b0
3 changed files with 50 additions and 48 deletions
  1. 20 5
      controllers/company.go
  2. 1 1
      models/cygx/activity_special_trip_bill.go
  3. 29 42
      services/cygx/activity_special.go

+ 20 - 5
controllers/company.go

@@ -9217,6 +9217,7 @@ func (this *CompanyTodoController) CompanyActivitySpecialPointsBill() {
 	}
 	//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}
 	resp := new(cygx.CygxActivitySpecialPointsBillResp)
+	//lastTripRemaining := 0
 	for i, v := range list {
 		item := cygx.CygxActivitySpecialPointsBillRespItem{
 			Id:                  v.Id,
@@ -9242,20 +9243,34 @@ func (this *CompanyTodoController) CompanyActivitySpecialPointsBill() {
 
 		}
 		if userType == 2 {
-			if i== 0{
+			if i== 0 {
 				item.Total += strconv.Itoa(tripRemaining) + "次"
 			} else {
-				item.Total += strconv.Itoa(tripRemaining-v.BillDetailed) + "次"
+				item.Total += strconv.Itoa(tripRemaining-list[i-1].BillDetailed) + "次"
 			}
+			//if v.BillDetailed < 4 {
+			//	item.Total += strconv.Itoa(lastTripRemaining-list[i-1].BillDetailed) + "次"
+			//} else {
+			//	item.Total += strconv.Itoa(lastTripRemaining) + "次"
+			//}
 		} else {
 			for k, num := range mapChartName {
-				if num > 0 {
-					if i== 0{
+				if i== 0 {
+					item.Total += k + strconv.Itoa(num) + "次"
+				} else {
+					if list[i-1].ActivityId == 0 {
 						item.Total += k + strconv.Itoa(num) + "次+"
 					} else {
-						item.Total += k + strconv.Itoa(num-v.BillDetailed) + "次+"
+						item.Total += k + strconv.Itoa(num-list[i-1].BillDetailed) + "次+"
 					}
 				}
+				//if num > 0 {
+				//	if i== 0{
+				//		item.Total += k + strconv.Itoa(num) + "次+"
+				//	} else {
+				//		item.Total += k + strconv.Itoa(num-v.BillDetailed) + "次+"
+				//	}
+				//}
 			}
 			item.Total = strings.TrimRight(item.Total, "+")
 		}

+ 1 - 1
models/cygx/activity_special_trip_bill.go

@@ -71,7 +71,7 @@ func GetCygxActivitySpecialTripBillList(condition string, pars []interface{}) (i
 			c.chart_permission_name 
 		FROM
 			cygx_activity_special_trip_bill AS b
-			INNER JOIN chart_permission AS c ON c.chart_permission_id = b.chart_permission_id 
+			LEFT JOIN chart_permission AS c ON c.chart_permission_id = b.chart_permission_id 
 		WHERE
 			1 = 1` + condition
 	_, err = o.Raw(sql, pars).QueryRows(&item)

+ 29 - 42
services/cygx/activity_special.go

@@ -226,7 +226,7 @@ func GetSpecialSurplusByCompany(companyId int) (specialSurplus string, err error
 	//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}
 	if companyDetail.Status == "正式" {
-		userType, packageType, _, _, _ := GetUserType(companyId)
+		userType, _, _, _, _ := GetUserType(companyId)
 		if userType == 2 {
 			var condition string
 			var pars []interface{}
@@ -264,16 +264,17 @@ func GetSpecialSurplusByCompany(companyId int) (specialSurplus string, err error
 			//}
 			var TripBillNum int
 			for _, v := range listTripBill {
-				if v.ActivityId == 0 {
-					continue
-				}
+				//if v.ActivityId == 0 {
+				//	continue
+				//}
 				TripBillNum += v.BillDetailed
 			}
 			// CRM13.2 70w客户有16次专项调研, 45w有10次
-			packageTypeMap := map[int]int{1: 16, 2: 10}
-			totalTrip := packageTypeMap[packageType]
+			//packageTypeMap := map[int]int{1: 16, 2: 10}
+			//totalTrip := packageTypeMap[packageType]
 
-			tripRemaining := totalTrip + TripBillNum
+			//tripRemaining := totalTrip + TripBillNum
+			tripRemaining := TripBillNum
 			if tripRemaining < 0 {
 				tripRemaining = 0
 			}
@@ -438,15 +439,23 @@ 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}
 	if companyDetail.Status == "正式" {
-		var packageType int
-		userType, packageType, _, _, _ = GetUserType(companyId)
-		if userType == 2 {
-			var condition string
-			var pars []interface{}
+		//var packageType int
+		userType, _, _, _, _ = GetUserType(companyId)
+		var condition string
+		var pars []interface{}
 
-			condition += ` AND company_id = ? `
-			pars = append(pars, companyId)
+		condition += ` AND company_id = ? `
+		pars = append(pars, companyId)
 
+		//查询当年的数据
+		condition += ` AND b.create_time >= ?  `
+		pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
+		listTripBill, e := cygx.GetCygxActivitySpecialTripBillList(condition, pars)
+		if e != nil {
+			err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
+			return
+		}
+		if userType == 2 {
 			//airborneList, e := cygx.GetActivitySpecialTripAirborneCountByActivitySpecial(condition, pars)
 			//if e != nil {
 			//	err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
@@ -463,30 +472,22 @@ func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tri
 			//	return
 			//}
 			//condition += ` AND is_valid = 1 `
-			//查询当年的数据
-			condition += ` AND create_time >= ?  `
-			pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
-			listTripBill, e := cygx.GetCygxActivitySpecialTripBill(condition, pars)
-			if e != nil {
-				err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
-				return
-			}
 			//TripBillNumMap := make(map[int]int)
 			//for _, v := range listTripBill {
 			//	TripBillNumMap[v.ChartPermissionId] += v.BillDetailed
 			//}
 			var TripBillNum int
 			for _, v := range listTripBill {
-				if v.ActivityId == 0 {
-					continue
-				}
+				//if v.ActivityId == 0 {
+				//	continue
+				//}
 				TripBillNum += v.BillDetailed
 			}
 			// CRM13.2 70w客户有16次专项调研, 45w有10次
-			packageTypeMap := map[int]int{1: 16, 2: 10}
-			totalTrip := packageTypeMap[packageType]
+			//packageTypeMap := map[int]int{1: 16, 2: 10}
+			//totalTrip := packageTypeMap[packageType]
 
-			tripRemaining = totalTrip + TripBillNum
+			tripRemaining = TripBillNum
 			if tripRemaining < 0 {
 				tripRemaining = 0
 			}
@@ -535,20 +536,6 @@ func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tri
 			//	mapPermissionNameTrip[v.ChartPermissionName] += 1
 			//}
 
-			var condition string
-			var pars []interface{}
-
-			condition += ` AND company_id = ? `
-			pars = append(pars, companyId)
-
-			//查询当年的数据
-			condition += ` AND b.create_time >= ?  `
-			pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
-			listTripBill, e := cygx.GetCygxActivitySpecialTripBillList(condition, pars)
-			if e != nil {
-				err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
-				return
-			}
 			//var TripBillNum int
 			for _, v := range listTripBill {
 				if v.ActivityId == 0 {