package cygx import ( "errors" "fmt" "hongze/hongze_task/models" "hongze/hongze_task/models/company_contract" "hongze/hongze_task/models/cygx" "hongze/hongze_task/models/data_manage" "hongze/hongze_task/services/alarm_msg" "hongze/hongze_task/utils" "strconv" "strings" "time" ) type YanXuanActivityPointsRedis struct { UserId int `description:"用户ID"` ComapnyId int `description:"公司ID"` ActivityId int `description:"活动ID"` PublishStatus int `description:"发布状态 1已发布,0未发布"` SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会、6 研选审批通过的时候研选扣点更新。"` AdminId int `description:"管理员、销售ID"` Source int `description:" 来源,1客户端,2后台添加, 3开发人员手动添加、4定时任务"` RegisterPlatform int `description:"来源 1小程序,2:网页"` CreateTime time.Time `description:"创建时间"` } //func init(){ // log := &YanXuanActivityPointsRedis{ComapnyId: 16, SourceType: 7, Source: 4, 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()) // } // } //} // 6 研选审批通过的时候研选扣点更新 func YanXuanCompanyApproval(comapnyId 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:活动到会。6 研选审批通过的时候研选扣点更新。7,正式专试用定时任务更新"` log := &YanXuanActivityPointsRedis{ComapnyId: comapnyId, SourceType: 6, 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 } // 7 正式专试用定时任务更新研选扣点 func YanXuanCompanyCompanyTryOut(comapnyId 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:活动到会。6 研选审批通过的时候研选扣点更新。7,正式专试用定时任务更新"` log := &YanXuanActivityPointsRedis{ComapnyId: comapnyId, SourceType: 7, Source: 4, 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 ActivitySpecialCompanyApproval(companyId int) (err error) { // defer func() { // if err != nil { // fmt.Println(err) // msg := fmt.Sprint("companyId:", companyId) // go alarm_msg.SendAlarmMsg("审批通过试用转正式时专项调研次数更新失败:"+err.Error()+msg, 2) // } // }() // comapny, e := models.GetCompanyById(companyId) // if e != nil { // err = errors.New("GetCompanyById err:" + e.Error()) // return // } // // 获取继承点数 // inheritList, e := data_manage.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} // // userType, packageType, _, _, _ := GetUserType(companyId) // itemBill := new(data_manage.CygxActivitySpecialTripBill) // itemBill.CreateTime = time.Now() // itemBill.CompanyId = companyId // itemBill.CompanyName = comapny.CompanyName // itemBill.Source = 2 // itemBill.DoType = 2 // itemBill.Way = 3 // if userType == 2{ // packageTypeMap := map[int]int{1: 16, 2: 10} // totalTrip := packageTypeMap[packageType] // if len(inheritList) > 0 { // for _, v := range inheritList { // if v.ChartPermissionId == 0 { // itemBill.BillDetailed = totalTrip + v.Points // } else { // itemBill.BillDetailed = totalTrip // } // } // } else { // itemBill.BillDetailed = totalTrip // } // // itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次" // if totalTrip == 10 { // itemBill.Content = "45w大套餐转正" // } else { // itemBill.Content = "70w大套餐转正" // } // } else { // list, e := GetCompanyReportPermission(companyId, 2) // if e != nil && e.Error() != utils.ErrNoRow() { // err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error()) // } // if len(list) == 0 { // return // } // var chartPermissionIdSlice []string // mapChartName := make(map[string]int) // mapUpgradeId := make(map[int]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)) // //是升级套餐才有点数 // if v.IsUpgrade == 1 { // mapUpgradeId[v.ChartPermissionId] = 1 // } // } // chartList := make([]*models.ChartPermission, 0) // if len(chartPermissionIdSlice) > 0 { // chartList, e = models.GetChartPermissionByIds(chartPermissionIdSlice) // if e != nil { // err = errors.New("获取品种信息失败, Err:" + e.Error()) // return // } // } // if len(chartList) == 0 { // return // } // for _, v := range chartList { // //如果是升级则加点 // if _, ok := mapUpgradeId[v.ChartPermissionId]; ok { // mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.ChartPermissionName] // } else { // mapChartName[v.PermissionName] = 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 { // itemBill.BillDetailed += v // itemBill.Total += k + strconv.Itoa(v) + "次+" // } // } // itemBill.Content = "行业升级套餐转正" // itemBill.Total = strings.TrimRight(itemBill.Total, "+") // } // err = data_manage.AddCygxActivitySpecialTripBill(itemBill) // if err != nil { // return // } // return //} 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} var items []*cygx.CygxActivitySpecialPermissionPoints itemBill := new(data_manage.CygxActivitySpecialTripBill) itemBill.CreateTime = time.Now() itemBill.CompanyId = companyId itemBill.CompanyName = companyName itemBill.Source = 2 itemBill.DoType = 2 itemBill.Way = 3 if userType == 2 { packageTypeMap := map[int]int{1: 16, 2: 10} totalTrip := packageTypeMap[packageType] itemBill.BillDetailed = totalTrip itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次" if totalTrip == 10 { 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 { //list, e := company.GetCompanyReportPermissionByCompanyIdAndProductId(companyId, 2) //if e != nil && e.Error() != utils.ErrNoRow() { // err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error()) //} //if len(list) == 0 { // return //} 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_contract.GetCompanyContractPermissionList(condition, pars) // 获取带有升级的权限 if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error()) return } if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCygxAllocationCompanyContractPermissionListById, 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 } for _, v := range list { //如果是升级则加点 if v.IsUpgrade == 1 && mapRaiSubjectivity[v.ChartPermissionId] { item := new(cygx.CygxActivitySpecialPermissionPoints) item.Points = 5 item.CompanyId = companyId item.CompanyName = companyName item.ChartPermissionId = v.ChartPermissionId item.ChartPermissionName = mapPermissionName[v.ChartPermissionId] 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 userType != 2 && 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 for _, v := range activitySpecialPermissionPointsList { itemBillTotal = append(itemBillTotal, fmt.Sprint(v.ChartPermissionName, v.Points, "次")) } itemBill.BillDetailed = 5 * len(items) itemBill.Total = strings.Join(itemBillTotal, "+") } //如果有升级行业权限,或者大套餐客户就写入流水信息 if itemBill.Total != "" { e := data_manage.AddCygxActivitySpecialTripBill(itemBill) if e != nil { err = errors.New("AddCygxActivitySpecialTripBill, Err:" + e.Error()) return } } return }