ziwen 1 year ago
parent
commit
704008a024

+ 18 - 18
controllers/activity_special.go

@@ -246,24 +246,6 @@ func (this *ActivitySpecialCoAntroller) SpecialTripAdd() {
 			itemBill.BillDetailed = -1 // 流水减一
 			itemBill.RegisterPlatform = 1
 			itemBill.ChartPermissionId = activityInfo.ChartPermissionId
-			userType, tripRemaining, mapChartName, err := services.GetChartPermissionSpecialSurplusByCompany(user.CompanyId)
-			if err != nil {
-				br.Msg = "获取专项调研剩余次数失败"
-				br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
-				return
-			}
-			if userType == 2 {
-				tripRemaining -= 1
-				itemBill.Total = strconv.Itoa(tripRemaining) + "次"
-			} else {
-				for k, num := range mapChartName {
-					if activityInfo.ChartPermissionName == k {
-						num -= 1
-					}
-					itemBill.Total += k + strconv.Itoa(num) + "次+"
-				}
-				itemBill.Total = strings.TrimRight(itemBill.Total, "+")
-			}
 
 
 			var itemMeeting = new(models.CygxActivitySpecialMeetingDetail)
@@ -339,6 +321,24 @@ func (this *ActivitySpecialCoAntroller) SpecialTripAdd() {
 					itemBill.BillDetailed = 0 //48小时之内,取消报名之后二次报名,不扣除流水记录
 				}
 			}
+			userType, tripRemaining, mapChartName, err := services.GetChartPermissionSpecialSurplusByCompany(user.CompanyId)
+			if err != nil {
+				br.Msg = "获取专项调研剩余次数失败"
+				br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
+				return
+			}
+			if userType == 2 {
+				tripRemaining = tripRemaining-itemBill.BillDetailed
+				itemBill.Total = strconv.Itoa(tripRemaining) + "次"
+			} else {
+				for k, num := range mapChartName {
+					if activityInfo.ChartPermissionName == k {
+						num = num- itemBill.BillDetailed
+					}
+					itemBill.Total += k + strconv.Itoa(num) + "次+"
+				}
+				itemBill.Total = strings.TrimRight(itemBill.Total, "+")
+			}
 			//添加流水记录
 			err = models.AddCygxActivitySpecialTripBill(itemBill)
 			if err != nil {

+ 39 - 0
models/cygx_activity_special_points_company.go

@@ -0,0 +1,39 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxActivitySpecialInheritPointsCompany struct {
+	Id                  int       `orm:"column(id);pk"`
+	CompanyId           int       // 公司ID
+	CompanyName         string    // 公司名称
+	Points              int   // 公司剩余点数
+	CreateTime          time.Time // 创建时间
+	ModifyTime          time.Time // 更新时间
+	ChartPermissionId   int       // 品种ID
+	ChartPermissionName string    // 品种名称
+}
+
+func AddCygxActivitySpecialPointsCompany(item *CygxActivitySpecialInheritPointsCompany) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	if err != nil {
+		return
+	}
+	return
+}
+
+func AddCygxActivitySpecialInheritPointsCompanyMulti(items []*CygxActivitySpecialInheritPointsCompany) (err error) {
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(1, items)
+	return
+}
+
+func GetCygxActivitySpecialInheritPointsByCompanyId(companyId int) (list []*CygxActivitySpecialInheritPointsCompany, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_activity_special_inherit_points_company WHERE company_id = ?  `
+	_, err = o.Raw(sql,companyId).QueryRows(&list)
+	return
+}

+ 28 - 6
services/activity_special.go

@@ -1277,6 +1277,8 @@ 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)
@@ -1294,6 +1296,11 @@ func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tri
 			err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
 			return
 		}
+		// 获取继承点数
+		inheritList, e := models.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
+		}
 		if userType == 2 {
 			//airborneList, e := cygx.GetActivitySpecialTripAirborneCountByActivitySpecial(condition, pars)
 			//if e != nil {
@@ -1346,12 +1353,15 @@ func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tri
 			if e != nil && e.Error() != utils.ErrNoRow() {
 				err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
 			}
-			if len(list) == 0 {
-				return
-			}
+			// 10.9.1本身升级没有也可能通过继承获得
+			//if len(list) == 0 {
+			//	return
+			//}
 			var chartPermissionIdSlice []string
 			mapChartName = make(map[string]int)
+			mapInheritChartName := make(map[string]int)
 			mapPermissionNameTrip := make(map[string]int)
+
 			//mapPermissionName := make(map[int]string)
 			for _, v := range list {
 				chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
@@ -1362,9 +1372,11 @@ func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tri
 				err = errors.New("获取品种信息失败, Err:" + e.Error())
 				return
 			}
-			if len(chartList) == 0 {
-				return
-			}
+			// 10.9.1本身升级没有也可能通过继承获得
+			//if len(chartList) == 0 {
+			//	return
+			//}
+
 			//到会空降的也加入流水记录表,这里不在做单独计算 2023-07-10
 			//airborneList, e := cygx.GetCygxActivitySpecialTripAirborneListByComapnyId(companyId)
 			//if e != nil {
@@ -1385,6 +1397,16 @@ func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tri
 			for _, v := range chartList {
 				mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.PermissionName]
 			}
+			for _, v := range inheritList {
+				mapInheritChartName[v.ChartPermissionName] = v.Points
+			}
+			for k, _ := range chartNameMap {
+				if _, ok := mapChartName[k]; ok {
+					if inherit, ok2 := mapInheritChartName[k]; ok2 {
+						mapChartName[k] += inherit
+					}
+				}
+			}
 			for k, v := range mapChartName {
 				if v > 0 {
 					specialSurplus += k + strconv.Itoa(v) + "次+"