ziwen 1 år sedan
förälder
incheckning
c74144c2fe

+ 58 - 34
controllers/cygx/activity_special_trip.go

@@ -127,6 +127,12 @@ func (this *ActivitySpecialTripCoAntroller) AddUser() {
 				return
 			}
 			if total == 0 {
+				totalAll, err := cygx.GetUserActivitySpecialTripCount(uid, activityId)
+				if err != nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
+					return
+				}
 				//流水记录表
 				itemBill := new(cygx.CygxActivitySpecialTripBill)
 				itemBill.UserId = infoUser.UserId
@@ -143,6 +149,56 @@ func (this *ActivitySpecialTripCoAntroller) AddUser() {
 				itemBill.RegisterPlatform = 1
 				itemBill.ChartPermissionId = activityInfo.ChartPermissionId
 				itemBill.AdminId = AdminUser.AdminId
+
+				if totalAll == 0 {
+					item := new(cygx.CygxActivitySpecialTrip)
+					item.UserId = infoUser.UserId
+					item.RealName = infoUser.RealName
+					item.SellerName = infoUser.SellerName
+					item.ActivityId = activityId
+					item.CreateTime = time.Now()
+					item.Mobile = infoUser.Mobile
+					item.Email = infoUser.Email
+					item.Email = infoUser.Email
+					item.CompanyId = infoUser.CompanyId
+					item.CompanyName = infoUser.CompanyName
+					item.AdminId = AdminUser.AdminId
+					item.Source = 2
+					//优先绑定用户修改过的外呼手机号
+					if infoUser.OutboundMobile != "" {
+						item.OutboundMobile = infoUser.OutboundMobile
+						if infoUser.OutboundCountryCode == "" {
+							item.CountryCode = "86"
+						} else {
+							item.CountryCode = infoUser.OutboundCountryCode
+						}
+					} else {
+						item.OutboundMobile = infoUser.Mobile
+						if infoUser.CountryCode == "" {
+							item.CountryCode = "86"
+						} else {
+							item.CountryCode = infoUser.CountryCode
+						}
+					}
+					items = append(items, item)
+				} else {
+					updateParams := make(map[string]interface{})
+					updateParams["IsValid"] = 1
+					updateParams["CreateTime"] = time.Now()
+					updateParams["IsCancel"] = 0
+					whereParam := map[string]interface{}{"user_id": uid, "activity_id": activityId}
+					err = cygx.UpdateByExpr(cygx.CygxActivitySpecialTrip{}, whereParam, updateParams)
+					if err != nil {
+						br.Msg = "报名失败,"
+						br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
+						return
+					}
+					resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
+					//48小时之内的取消也扣除一次参会记录
+					if time.Now().Add(+time.Hour * 48).After(resultTime) {
+						itemBill.BillDetailed = 0 //48小时之内,取消报名之后二次报名,不扣除流水记录
+					}
+				}
 				userType, tripRemaining, mapChartName, err := cygxService.GetChartPermissionSpecialSurplusByCompany(infoUser.CompanyId)
 				if err != nil {
 					br.Msg = "获取专项调研剩余次数失败"
@@ -150,49 +206,17 @@ func (this *ActivitySpecialTripCoAntroller) AddUser() {
 					return
 				}
 				if userType == 2 {
-					tripRemaining = tripRemaining-1-i
+					tripRemaining = tripRemaining-itemBill.BillDetailed-i
 					itemBill.Total = strconv.Itoa(tripRemaining) + "次"
 				} else {
 					for k, num := range mapChartName {
 						if activityInfo.ChartPermissionName == k {
-							num = num- 1 - i
+							num = num- itemBill.BillDetailed - i
 						}
 						itemBill.Total += k + strconv.Itoa(num) + "次+"
 					}
 					itemBill.Total = strings.TrimRight(itemBill.Total, "+")
 				}
-
-
-				item := new(cygx.CygxActivitySpecialTrip)
-				item.UserId = infoUser.UserId
-				item.RealName = infoUser.RealName
-				item.SellerName = infoUser.SellerName
-				item.ActivityId = activityId
-				item.CreateTime = time.Now()
-				item.Mobile = infoUser.Mobile
-				item.Email = infoUser.Email
-				item.Email = infoUser.Email
-				item.CompanyId = infoUser.CompanyId
-				item.CompanyName = infoUser.CompanyName
-				item.AdminId = AdminUser.AdminId
-				item.Source = 2
-				//优先绑定用户修改过的外呼手机号
-				if infoUser.OutboundMobile != "" {
-					item.OutboundMobile = infoUser.OutboundMobile
-					if infoUser.OutboundCountryCode == "" {
-						item.CountryCode = "86"
-					} else {
-						item.CountryCode = infoUser.OutboundCountryCode
-					}
-				} else {
-					item.OutboundMobile = infoUser.Mobile
-					if infoUser.CountryCode == "" {
-						item.CountryCode = "86"
-					} else {
-						item.CountryCode = infoUser.CountryCode
-					}
-				}
-				items = append(items, item)
 				itemsBill = append(itemsBill, itemBill)
 			}
 

+ 19 - 0
models/cygx/activity_special_trip.go

@@ -281,3 +281,22 @@ func GetCygxActivitySpecialTripListCondition(condition string, pars []interface{
 	}
 	return
 }
+
+//获取某一用户的报名的数量
+func GetUserActivitySpecialTripCount(uid, activityId int) (count int, err error) {
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip  WHERE  user_id=?  AND   activity_id =? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
+	return
+}
+
+// 更新
+func UpdateByExpr(ptrStructOrTableName interface{}, where, updateParams map[string]interface{}) error {
+	o := orm.NewOrm()
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range where {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err := qs.Update(updateParams)
+	return err
+}

+ 26 - 6
services/cygx/activity_special.go

@@ -223,8 +223,15 @@ func GetSpecialSurplusByCompany(companyId int) (specialSurplus string, err error
 	if companyDetail.Status == "永续" {
 		specialSurplus = "不限次数"
 	}
+	// 获取继承点数
+	inheritList, e := cygx.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.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}
+	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 == "正式" {
 		userType, _, _, _, _ := GetUserType(companyId)
 		if userType == 2 {
@@ -293,12 +300,14 @@ func GetSpecialSurplusByCompany(companyId int) (specialSurplus string, err error
 			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)
 			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))
@@ -308,9 +317,10 @@ func GetSpecialSurplusByCompany(companyId int) (specialSurplus string, err error
 				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 {
@@ -345,6 +355,16 @@ func GetSpecialSurplusByCompany(companyId int) (specialSurplus string, err error
 			for _, v := range chartList {
 				mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.ChartPermissionName]
 			}
+			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) + "次+"