Browse Source

no message

zhangchuanxing 3 weeks ago
parent
commit
511ed98d59
2 changed files with 201 additions and 2 deletions
  1. 3 1
      models/activity_special_trip_bill.go
  2. 198 1
      services/activity_points.go

+ 3 - 1
models/activity_special_trip_bill.go

@@ -25,7 +25,9 @@ type CygxActivitySpecialTripBill struct {
 	Way                 int       `description:"1报名,取消报名。2到会取消到会 3转正或清零 4取消活动"`
 	Content             string    `description:"内容"`
 	Total               string    `description:"总和"`
-	TableSource         string    `description:"活动类型来源 活动 :activity 、专项调研活动:activityspecial"`
+	TableSource         string    `description:"活动类型来源 活动 :activity 、专项调研活动:activityspecial、路演:roadshow"`
+	ResearcherId        int       `description:"研究员id"`
+	ResearcherName      string    `description:"研究员名称"`
 }
 
 // 添加

+ 198 - 1
services/activity_points.go

@@ -6,8 +6,10 @@ import (
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/models/company"
+	"hongze/hongze_cygx/models/roadshow"
 	"hongze/hongze_cygx/utils"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -234,6 +236,10 @@ func YanXuanActivityPointsBillReduce() (err error) {
 				go ActivitySpecialPointsBillSubmitMeetingReduce(log)
 				fmt.Println("12,专项调研活动提交到会点数更新。")
 				break
+			case 13:
+				go SpecialActivityPointsBillRoadShowReduce(log)
+				fmt.Println("13,给公司添加路演,对应专项调研扣点处理。")
+				break
 
 			default:
 				fmt.Println(string(b))
@@ -1617,7 +1623,7 @@ func ActivitySpecialCompanyApprovalReduce(log models.YanXuanActivityPointsRedis)
 }
 
 //func init() {
-//	ActivitySpecialPointsBillSubmitMeetingReduce(93)
+//	SpecialActivityPointsBillRoadShowReduce(1882)
 //}
 
 // 12: 专项调活动提交到会扣点处理
@@ -1830,6 +1836,197 @@ func ActivitySpecialPointsBillSubmitMeetingReduce(log models.YanXuanActivityPoin
 	return
 }
 
+// 13: 给公司添加路演,对应专项调研扣点处理
+func SpecialActivityPointsBillRoadShowReduce(log models.YanXuanActivityPointsRedis) (err error) {
+	//func SpecialActivityPointsBillRoadShowReduce(activityId int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			//go utils.SendAlarmMsg("专项调活动提交到会扣点处理,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("ActivityId", log.ActivityId, "adminId", log.AdminId), 2)
+		}
+	}()
+
+	time.Sleep(5 * time.Second) //添加五秒的延迟
+
+	activityId := log.ActivityId
+	rsCalendar, e := roadshow.GetRsCalendarById(activityId)
+	if e != nil {
+		err = errors.New("GetRsCalendarById" + e.Error())
+		return
+	}
+	var companyIds []int
+	mapCompanyPoints := make(map[int]float64) //一组公司的剩余点数
+	var condition string
+	var pars []interface{}
+
+	companyId := rsCalendar.CompanyId
+	companyIds = append(companyIds, companyId)
+	//判断公司是不是满足扣点情况,如果是后台超管手动给试用客户报名,就写入一条点数初始化数据
+	total, e := models.GetCygxActivitySpecialPermissionPointsCountByCompanyId(companyId)
+	if e != nil {
+		err = errors.New("GetCygxActivitySpecialPermissionPointsCountByCompanyId, Err: " + e.Error())
+		return
+	}
+
+	if total == 0 {
+		itemPointsCompany := new(models.CygxActivitySpecialPermissionPoints)
+		itemPointsCompany.CompanyId = companyId
+		itemPointsCompany.CompanyName = rsCalendar.CompanyName
+		itemPointsCompany.CreateTime = time.Now()
+		itemPointsCompany.ModifyTime = time.Now()
+		e = models.AddCygxActivitySpecialPermissionPoints(itemPointsCompany)
+		if e != nil {
+			err = errors.New("AddCygxActivitySpecialPermissionPoints, Err: " + e.Error())
+			return
+		}
+	}
+
+	pars = make([]interface{}, 0)
+	condition = ` AND activity_id = ?  AND  company_id = ?  AND table_source = 'roadshow'  AND researcher_id > 0  ORDER BY  id DESC   `
+	pars = append(pars, activityId, companyId)
+	//获取扣点的流水记录
+	activityPointsBillList, e := models.GetCygxActivitySpecialTripBill(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCygxActivitySpecialTripBill" + e.Error())
+		return
+	}
+	mapActivityPointsBill := make(map[int]*models.CygxActivitySpecialTripBill)
+	var itemsOld []*models.CygxActivitySpecialTripBill // 之前扣过点的流水记录
+	for _, v := range activityPointsBillList {         //获取这场路演,某个研究员最后一次的扣点记录
+		if mapActivityPointsBill[v.ResearcherId] == nil {
+			mapActivityPointsBill[v.ResearcherId] = v
+			if v.BillDetailed < 0 {
+				itemsOld = append(itemsOld, v)
+			}
+		}
+		companyIds = append(companyIds, v.CompanyId)
+	}
+
+	//return
+	pars = make([]interface{}, 0)
+	condition = ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
+	pars = append(pars, companyIds)
+	//获取这些公司剩余的点数
+	conpanyList, e := models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err: " + e.Error())
+		return
+	}
+
+	//return
+	for _, v := range conpanyList {
+		if v.CompanyId != 0 {
+			mapCompanyPoints[v.CompanyId] = v.Points
+		}
+	}
+
+	var billDetailed float64
+	var companyStatus string
+	productDetail, e := company.GetCompanyProductDetailByCompanyId(companyId, 2)
+	if e != nil {
+		err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
+		return
+	}
+	if productDetail.Status == "正式" || mapCompanyPoints[companyId] > 0 {
+		billDetailed = -1
+	}
+	if productDetail.Status != "正式" {
+		companyStatus = "(" + productDetail.Status + ")"
+	}
+
+	//获取研究员信息
+	researcherList, e := roadshow.GetRsCalendarResearcherListByIds([]int{activityId})
+	if e != nil {
+		err = errors.New("GetRsCalendarResearcherListByIds, Err: " + e.Error())
+		return
+	}
+
+	//return
+	var items []*models.CygxActivitySpecialTripBill
+	var itemCompanys []*models.CygxActivitySpecialPermissionPoints
+	mapMeetUserId := make(map[int]bool)
+	for _, user := range researcherList {
+		mapMeetUserId[user.ResearcherId] = true
+		item := new(models.CygxActivitySpecialTripBill)
+		item.ActivityId = activityId
+		item.CreateTime = time.Now()
+
+		item.CompanyId = rsCalendar.CompanyId
+		item.CompanyName = rsCalendar.CompanyName
+		item.ResearcherId = user.ResearcherId
+		item.ResearcherName = user.ResearcherName
+		item.RegisterPlatform = log.RegisterPlatform
+		item.AdminId = log.AdminId
+		item.Source = log.Source
+		item.TableSource = utils.CYGX_OBJ_ROADSHOW
+
+		//如果没有扣点记录就对他们进行扣点处理
+		if mapActivityPointsBill[user.ResearcherId] == nil || mapActivityPointsBill[user.ResearcherId].BillDetailed > 0 {
+			points := mapCompanyPoints[companyId] + billDetailed
+			item.BillDetailed = billDetailed
+			item.DoType = 1
+			item.Content = fmt.Sprint(user.StartDate, " ", user.StartTime, "-", user.EndDate, " ", user.EndTime, " ", user.ResearcherName, "路演", companyStatus)
+			item.Total = fmt.Sprint(points, "次")
+			item.TableSource = utils.CYGX_OBJ_ROADSHOW
+			//item.Points = mapCompanyPoints[user.CompanyId] - activityPointsSetDetail.UserPointsNum
+			items = append(items, item)
+			//更新对应机构的剩余点数
+			itemCompany := new(models.CygxActivitySpecialPermissionPoints)
+			itemCompany.CompanyId = companyId
+			itemCompany.Points = points
+			itemCompany.ModifyTime = time.Now()
+			itemCompanys = append(itemCompanys, itemCompany)
+			mapCompanyPoints[companyId] = points
+		}
+
+	}
+
+	if len(itemsOld) > 0 {
+		for _, user := range itemsOld {
+			if mapMeetUserId[user.UserId] {
+				continue
+			}
+			item := new(models.CygxActivitySpecialTripBill)
+			item.ActivityId = activityId
+			item.CreateTime = time.Now()
+			item.CompanyId = user.CompanyId
+			item.CompanyName = user.CompanyName
+			item.RegisterPlatform = log.RegisterPlatform
+			item.AdminId = log.AdminId
+			item.Source = log.Source
+
+			points := mapCompanyPoints[user.CompanyId] - user.BillDetailed
+			item.BillDetailed = -user.BillDetailed
+			item.DoType = 2
+			item.Content = strings.Replace(user.Content, "路演", "路演--取消", -1)
+			//item.Points =points
+			item.Total = fmt.Sprint(points, "次")
+			item.TableSource = utils.CYGX_OBJ_ROADSHOW
+
+			item.CompanyId = rsCalendar.CompanyId
+			item.CompanyName = rsCalendar.CompanyName
+			item.ResearcherId = user.ResearcherId
+			item.ResearcherName = user.ResearcherName
+			items = append(items, item)
+
+			//更新对应机构的剩余点数
+			itemCompany := new(models.CygxActivitySpecialPermissionPoints)
+			itemCompany.CompanyId = user.CompanyId
+			itemCompany.Points = points
+			itemCompany.ModifyTime = time.Now()
+			itemCompanys = append(itemCompanys, itemCompany)
+			mapCompanyPoints[user.CompanyId] = points
+		}
+	}
+
+	e = models.AddCygxActivitySpecialTripBillMulti(items, itemCompanys)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("AddCygxActivitySpecialTripBillMulti, Err: " + e.Error())
+		return
+	}
+	return
+}
+
 //func init() {
 //	initCygx14_5_01()
 //}