Browse Source

no message

zhangchuanxing 3 days ago
parent
commit
0f7406960f

+ 1 - 1
controllers/company.go

@@ -3422,7 +3422,7 @@ func (this *CompanyController) Detail() {
 				return
 			}
 			//研选服务点数
-			item.Points = cygxService.GetCygxActivityPointsCompanyByCompanyId(companyId)
+			//item.Points = cygxService.GetCygxActivityPointsCompanyByCompanyId(companyId)
 
 			item.PermissionList = append(item.PermissionList, plist)
 			resp.RaiItem = item

+ 3 - 3
models/cygx/activity_special_permission_points.go

@@ -98,9 +98,9 @@ func UpdateCygxActivitySpecialPermissionPoints(points float64, companyId, chartP
 }
 
 // 获取客户是否有研选扣点点数
-func GetCygxActivitySpecialPermissionPointsCount(companyId int) (count int, err error) {
+func GetCygxActivitySpecialPermissionPointsCount(companyId int) (points float64, err error) {
 	o := orm.NewOrmUsingDB("hz_cygx")
-	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_permission_points  WHERE company_id=?  `
-	err = o.Raw(sqlCount, companyId).QueryRow(&count)
+	sqlCount := `SELECT points FROM cygx_activity_special_permission_points  WHERE company_id=?  LIMIT 	  1 `
+	err = o.Raw(sqlCount, companyId).QueryRow(&points)
 	return
 }

+ 2 - 1
services/company_apply/company_approval.go

@@ -410,7 +410,8 @@ func Approved(approvalRecord *contract.ContractApprovalRecord, opUser *system.Ad
 					return
 				}
 				if time.Now().After(contractStartDate) {
-					cygxService.ActivitySpecialCompanyApproval(recordInfo.CompanyId, recordInfo.CompanyContractId, companyInfo.CompanyName) //审批通过的时候专项调研次数更新
+					//cygxService.ActivitySpecialCompanyApproval(recordInfo.CompanyId, recordInfo.CompanyContractId, companyInfo.CompanyName) //审批通过的时候专项调研次数更新
+					cygxService.ActivitySpecialCompanyApprovalRedis(recordInfo.CompanyId, recordInfo.CompanyContractId) //审批通过的时候专项调研次数更新
 					//cygxService.ActivitySpecialCompanyApproval(recordInfo.CompanyContractId) //审批通过的时候专项调研次数更新
 				}
 				//}

+ 20 - 0
services/cygx/activity_points_set.go

@@ -369,6 +369,26 @@ func ActivityPointsBillSignupCancelSpecial(activityId, uid, adminId int) (err er
 	return
 }
 
+// 11 合同审批通过的时候,专项调研点数更新
+func ActivitySpecialCompanyApprovalRedis(comapnyId, companyContractId int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			msg := fmt.Sprint("comapnyId:", comapnyId)
+			go alarm_msg.SendAlarmMsg("研选审批通过的时候研选扣点更新,写入Redis队列消息失败:"+err.Error()+msg, 2)
+		}
+	}()
+	//SourceType int       `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会。"`
+	log := &cygx.YanXuanActivityPointsRedis{ComapnyId: comapnyId, CompanyContractId: companyContractId, SourceType: 11, Source: 2, CreateTime: time.Now()}
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.CYGX_YANXUAN_POINTS_KEY, log)
+		if err != nil {
+			fmt.Println("YanXuanActivityPointsRedis LPush Err:" + err.Error())
+		}
+	}
+	return
+}
+
 func init0703() {
 	//2023.07.03剩余服务点数初始化
 	path := "0703.xlsx"

+ 130 - 188
services/cygx/activity_special.go

@@ -556,202 +556,146 @@ func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tri
 //}
 
 // 审批通过的时候专项调研次数更新
-func ActivitySpecialCompanyApproval(companyId, companyContractId int, companyName string) (err error) {
-	//userType, packageType, _, _, _ := GetUserType(companyId)
-	// 获取继承点数
-	//inheritList, e := cygx.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
-	//if e != nil && e.Error() != utils.ErrNoRow() {
-	//	err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
-	//}
-	//chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
-
-	// 获取合同信息-套餐信息
-	companyContract, e := company.GetCompanyContractById(companyContractId)
-	if e != nil {
-		err = errors.New("GetCompanyContractById, Err: " + e.Error())
-		return
-	}
-	packageType := companyContract.RaiPackageType
-	var items []*cygx.CygxActivitySpecialPermissionPoints
-
-	itemBill := new(cygx.CygxActivitySpecialTripBill)
-	itemBill.CreateTime = time.Now()
-	itemBill.CompanyId = companyId
-	itemBill.CompanyName = companyName
-	itemBill.Source = 2
-	itemBill.DoType = 2
-	itemBill.Way = 3
-	if packageType > 0 {
-		packageTypeMap := map[int]float64{1: 16, 2: 12}
-		totalTrip := packageTypeMap[packageType]
-		itemBill.BillDetailed = totalTrip
-		itemBill.Total = fmt.Sprint(itemBill.BillDetailed) + "次"
-		if packageType == 2 {
-			itemBill.Content = "45w大套餐转正"
-		} else {
-			itemBill.Content = "70w大套餐转正"
-		}
-
-		//记录公司剩余点数
-		item := new(cygx.CygxActivitySpecialPermissionPoints)
-		item.Points = totalTrip
-		item.CompanyId = companyId
-		item.CompanyName = companyName
-		item.CreateTime = time.Now()
-		item.ModifyTime = time.Now()
-		items = append(items, item)
-
-	} else {
-
-		var condition string
-		var pars []interface{}
-		pars = make([]interface{}, 0)
-		condition = " AND  company_contract_id = ?  AND  is_upgrade = 1  "
-		pars = append(pars, companyContractId)
-		list, e := company.GetCompanyContractPermissionList(condition, pars) // 获取带有升级的权限
-		if e != nil && e.Error() != utils.ErrNoRow() {
-			err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
-			return
-		}
-
-		if len(list) == 0 {
-			return
-		}
-
-		//获取权益主观权限
-		listRaiSubjectivity, e := models.GetChartPermissionListRaiSubjectivity()
-		if e != nil && e.Error() != utils.ErrNoRow() {
-			err = errors.New("GetChartPermissionListRaiSubjectivity, Err: " + e.Error())
-		}
-		mapRaiSubjectivity := make(map[int]bool)
-		mapPermissionName := make(map[int]string)
-		for _, v := range listRaiSubjectivity {
-			mapRaiSubjectivity[v.ChartPermissionId] = true
-			mapPermissionName[v.ChartPermissionId] = v.ChartPermissionName
-		}
-		var points float64
-		for _, v := range list {
-			//如果是升级则加点
-			if v.IsUpgrade == 1 && mapRaiSubjectivity[v.ChartPermissionId] {
-				points += 4
-			}
-		}
-		item := new(cygx.CygxActivitySpecialPermissionPoints)
-		item.Points = points
-		item.CompanyId = companyId
-		item.CompanyName = companyName
-		item.ChartPermissionId = 0
-		item.ChartPermissionName = ""
-		item.CreateTime = time.Now()
-		item.ModifyTime = time.Now()
-		items = append(items, item)
-		itemBill.Content = "行业升级套餐转正"
-	}
+//func ActivitySpecialCompanyApproval(companyId, companyContractId int, companyName string) (err error) {
 
-	e = cygx.MultiAddCygxActivitySpecialPermissionPoints(items)
-	if e != nil {
-		err = errors.New("MultiAddCygxActivitySpecialPermissionPoints, Err:" + e.Error())
-		return
-	}
-	if packageType == 0 && len(items) > 0 {
-		var condition string
-		var pars []interface{}
-		pars = make([]interface{}, 0)
-		condition = " AND  company_id  = ?  AND points  > 0   ORDER BY  chart_permission_id DESC  "
-		pars = append(pars, companyId)
-		activitySpecialPermissionPointsList, e := cygx.GetCygxActivitySpecialPermissionPointsList(condition, pars)
-		if e != nil && e.Error() != utils.ErrNoRow() {
-			err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
-			return
-		}
-		var itemBillTotal []string
-		itemBillTotalMap := make(map[string]string)
-		for _, v := range activitySpecialPermissionPointsList {
-			itemBillTotal = append(itemBillTotal, fmt.Sprint(v.ChartPermissionName, v.Points, "次"))
-			itemBillTotalMap[v.ChartPermissionName] = fmt.Sprint(v.ChartPermissionName, v.Points, "次")
-		}
-		itemBill.BillDetailed = float64(4 * len(items))
-		permissionNameSlice := []string{"医药", "消费", "科技", "智造"}
-		var itemBillTotalNew []string
-		for _, v := range permissionNameSlice {
-			if itemBillTotalMap[v] == "" {
-				itemBillTotalNew = append(itemBillTotalNew, fmt.Sprint(v, "0次"))
-			} else {
-				itemBillTotalNew = append(itemBillTotalNew, itemBillTotalMap[v])
-			}
-		}
-		itemBill.Total = strings.Join(itemBillTotalNew, "+")
-	}
-
-	//如果有升级行业权限,或者大套餐客户就写入流水信息
-	if itemBill.Total != "" {
-		e := cygx.AddCygxActivitySpecialTripBill(itemBill)
-		if e != nil {
-			err = errors.New("AddCygxActivitySpecialTripBill, Err:" + e.Error())
-			return
-		}
-	}
-	return
-}
-
-// 取消专项调研返点
-func ActivitySpecialPublishAndCancel(activityInfo *cygx.ActivitySpecialDetail) (err error) {
-	//userType, tripRemaining, mapChartName, err := GetChartPermissionSpecialSurplusByCompany(companyId)
-	//if err != nil {
-	//	br.Msg = "获取专项调研剩余次数失败"
-	//	br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
-	//	return
-	//}
-	//itemBill := new(cygx.CygxActivitySpecialTripBill)
-	//itemBill.CreateTime = time.Now()
-	//itemBill.ActivityId = activityInfo.ActivityId
-	//itemBill.Content = activityInfo.ResearchTheme + "--活动取消"
-	//itemBill.Source = 2
-	//itemBill.DoType = 2
-	//itemBill.Way = 4
-	//itemBill.BillDetailed = 1
-	//err = cygx.AddCygxActivitySpecialTripBill(itemBill)
-	//if err != nil {
-	//	return
-	//}
-	return
-}
-
-//func init() {
-//	fmt.Println(GetSpecialSurplusByCompanyNew(16))
+// 获取合同信息-套餐信息
+//companyContract, e := company.GetCompanyContractById(companyContractId)
+//if e != nil {
+//	err = errors.New("GetCompanyContractById, Err: " + e.Error())
+//	return
+//}
+//packageType := companyContract.RaiPackageType
+//var items []*cygx.CygxActivitySpecialPermissionPoints
+//
+//itemBill := new(cygx.CygxActivitySpecialTripBill)
+//itemBill.CreateTime = time.Now()
+//itemBill.CompanyId = companyId
+//itemBill.CompanyName = companyName
+//itemBill.Source = 2
+//itemBill.DoType = 2
+//itemBill.Way = 3
+//if packageType > 0 {
+//	packageTypeMap := map[int]float64{1: 16, 2: 12}
+//	totalTrip := packageTypeMap[packageType]
+//	itemBill.BillDetailed = totalTrip
+//	itemBill.Total = fmt.Sprint(itemBill.BillDetailed) + "次"
+//	if packageType == 2 {
+//		itemBill.Content = "45w大套餐转正"
+//	} else {
+//		itemBill.Content = "70w大套餐转正"
+//	}
+//
+//	//记录公司剩余点数
+//	item := new(cygx.CygxActivitySpecialPermissionPoints)
+//	item.Points = totalTrip
+//	item.CompanyId = companyId
+//	item.CompanyName = companyName
+//	item.CreateTime = time.Now()
+//	item.ModifyTime = time.Now()
+//	items = append(items, item)
+//
+//} else {
+//
+//	var condition string
+//	var pars []interface{}
+//	pars = make([]interface{}, 0)
+//	condition = " AND  company_contract_id = ?  AND  is_upgrade = 1  "
+//	pars = append(pars, companyContractId)
+//	list, e := company.GetCompanyContractPermissionList(condition, pars) // 获取带有升级的权限
+//	if e != nil && e.Error() != utils.ErrNoRow() {
+//		err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
+//		return
+//	}
+//
+//	if len(list) == 0 {
+//		return
+//	}
+//
+//	//获取权益主观权限
+//	listRaiSubjectivity, e := models.GetChartPermissionListRaiSubjectivity()
+//	if e != nil && e.Error() != utils.ErrNoRow() {
+//		err = errors.New("GetChartPermissionListRaiSubjectivity, Err: " + e.Error())
+//	}
+//	mapRaiSubjectivity := make(map[int]bool)
+//	mapPermissionName := make(map[int]string)
+//	for _, v := range listRaiSubjectivity {
+//		mapRaiSubjectivity[v.ChartPermissionId] = true
+//		mapPermissionName[v.ChartPermissionId] = v.ChartPermissionName
+//	}
+//	var points float64
+//	for _, v := range list {
+//		//如果是升级则加点
+//		if v.IsUpgrade == 1 && mapRaiSubjectivity[v.ChartPermissionId] {
+//			points += 4
+//		}
+//	}
+//	item := new(cygx.CygxActivitySpecialPermissionPoints)
+//	item.Points = points
+//	item.CompanyId = companyId
+//	item.CompanyName = companyName
+//	item.ChartPermissionId = 0
+//	item.ChartPermissionName = ""
+//	item.CreateTime = time.Now()
+//	item.ModifyTime = time.Now()
+//	items = append(items, item)
+//	itemBill.Content = "行业升级套餐转正"
+//}
+//
+//e = cygx.MultiAddCygxActivitySpecialPermissionPoints(items)
+//if e != nil {
+//	err = errors.New("MultiAddCygxActivitySpecialPermissionPoints, Err:" + e.Error())
+//	return
+//}
+//if packageType == 0 && len(items) > 0 {
+//	var condition string
+//	var pars []interface{}
+//	pars = make([]interface{}, 0)
+//	condition = " AND  company_id  = ?  AND points  > 0   ORDER BY  chart_permission_id DESC  "
+//	pars = append(pars, companyId)
+//	activitySpecialPermissionPointsList, e := cygx.GetCygxActivitySpecialPermissionPointsList(condition, pars)
+//	if e != nil && e.Error() != utils.ErrNoRow() {
+//		err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
+//		return
+//	}
+//	var itemBillTotal []string
+//	itemBillTotalMap := make(map[string]string)
+//	for _, v := range activitySpecialPermissionPointsList {
+//		itemBillTotal = append(itemBillTotal, fmt.Sprint(v.ChartPermissionName, v.Points, "次"))
+//		itemBillTotalMap[v.ChartPermissionName] = fmt.Sprint(v.ChartPermissionName, v.Points, "次")
+//	}
+//	itemBill.BillDetailed = float64(4 * len(items))
+//	permissionNameSlice := []string{"医药", "消费", "科技", "智造"}
+//	var itemBillTotalNew []string
+//	for _, v := range permissionNameSlice {
+//		if itemBillTotalMap[v] == "" {
+//			itemBillTotalNew = append(itemBillTotalNew, fmt.Sprint(v, "0次"))
+//		} else {
+//			itemBillTotalNew = append(itemBillTotalNew, itemBillTotalMap[v])
+//		}
+//	}
+//	itemBill.Total = strings.Join(itemBillTotalNew, "+")
+//}
+//
+////如果有升级行业权限,或者大套餐客户就写入流水信息
+//if itemBill.Total != "" {
+//	e := cygx.AddCygxActivitySpecialTripBill(itemBill)
+//	if e != nil {
+//		err = errors.New("AddCygxActivitySpecialTripBill, Err:" + e.Error())
+//		return
+//	}
+//}
+//	return
 //}
 
 // GetSpecialSurplusByCompanyNew 获取公司专项调研剩余次数-用流水表数据不计算了,计算都丢在流水里
 func GetSpecialSurplusByCompanyNew(companyId int) (specialSurplus string, err error) {
-	companyDetail, e := cygx.GetCompanyDetailByIdGroup(companyId)
-	if e != nil {
-		err = errors.New("GetCompanyDetailByIdGroup, Err: " + e.Error())
-	}
-	if companyDetail == nil {
-		return
-	}
-	//if companyDetail.Status != "永续" && companyDetail.Status != "正式" {
-	//	return
-	//}
-	//if companyDetail.Status == "永续" {
-	//	specialSurplus = "不限次数"
-	//}
-	//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 == "正式" {
-	billItem, e := cygx.GetCygxActivitySpecialTripBillByCompanyId(companyId)
+	points, e := cygx.GetCygxActivitySpecialPermissionPointsCount(companyId)
 	if e != nil && e.Error() != utils.ErrNoRow() {
 		err = e
 		return
 	}
-	if billItem != nil {
-		specialSurplus = billItem.Total
-	} else {
-		specialSurplus = "0次"
-	}
+	specialSurplus = fmt.Sprint(points, "次")
 	return
-	//}
-	//return
 }
 
 // GetSpecialBillMaxChartPermissionId  获取专项调研剩余点数最多的行业
@@ -1007,7 +951,5 @@ func CheckSpecialActivityPointsByUserIds(userIds string, activityLen int) (err e
 			err = errors.New("您的专项调研次数已用完,如仍想参加,请与您的对口销售商议")
 		}
 	}
-
 	return
-
 }