123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- package cygx
- import (
- "errors"
- "fmt"
- "hongze/hongze_task/models"
- "hongze/hongze_task/models/cygx"
- "hongze/hongze_task/models/data_manage"
- "hongze/hongze_task/services/alarm_msg"
- "hongze/hongze_task/utils"
- "strconv"
- "strings"
- "time"
- )
- func ActivitySpecialCompanyTryOutReduce(comapnyId int) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg("正式转试用定时任务更新专项调研扣点失败:"+err.Error(), 2)
- }
- }()
- comapny, e := models.GetCompanyById(comapnyId)
- if e != nil {
- err = errors.New("GetCompanyById err:" + e.Error())
- return
- }
- userType, tripRemaining, mapChartName, e := GetChartPermissionSpecialSurplusByCompany(comapnyId)
- if e != nil {
- err = errors.New("GetChartPermissionSpecialSurplusByCompany err:" + e.Error())
- return
- }
-
- itemBill := new(data_manage.CygxActivitySpecialTripBill)
- itemBill.CreateTime = time.Now()
- itemBill.Source = 2
- itemBill.DoType = 1
- itemBill.Way = 3
- itemBill.BillDetailed = -tripRemaining
- itemBill.CompanyId = comapnyId
- itemBill.CompanyName = comapny.CompanyName
- itemBill.Content = "到期清零"
- itemBill.Total = "0"
- err = data_manage.AddCygxActivitySpecialTripBill(itemBill)
- if err != nil {
- return
- }
-
- e = cygx.UpdateCygxActivitySpecialPermissionPointsTryOutReduce(comapnyId)
- if e != nil {
- err = errors.New("GetChartPermissionSpecialSurplusByCompany err:" + e.Error())
- return
- }
-
- err = data_manage.DelCygxActivitySpecialInheritPointsByCompanyId(comapnyId)
- if err != nil {
- return
- }
- chartMap := map[string]int{utils.YI_YAO_NAME: utils.YI_YAO_ID, utils.XIAO_FEI_NAME: utils.XIAO_FEI_ID, utils.KE_JI_NAME: utils.KE_JI_ID, utils.ZHI_ZAO_NAME: utils.ZHI_ZAO_ID}
-
- inheritItems := make([]*data_manage.CygxActivitySpecialInheritPointsCompany, 0)
- if userType == 2 {
- inheritItem := new(data_manage.CygxActivitySpecialInheritPointsCompany)
- inheritItem.CompanyId = comapnyId
- inheritItem.CompanyName = comapny.CompanyName
- inheritItem.CreateTime = time.Now()
- inheritItem.ModifyTime = time.Now()
- inheritItem.Points = tripRemaining
- inheritItems = append(inheritItems, inheritItem)
- } else {
- for k, v := range mapChartName {
- inheritItem := new(data_manage.CygxActivitySpecialInheritPointsCompany)
- inheritItem.CompanyId = comapnyId
- inheritItem.CompanyName = comapny.CompanyName
- inheritItem.CreateTime = time.Now()
- inheritItem.ModifyTime = time.Now()
- inheritItem.Points = v
- inheritItem.ChartPermissionName = k
- if _, ok := chartMap[k]; ok {
- inheritItem.ChartPermissionId = chartMap[k]
- }
- inheritItems = append(inheritItems, inheritItem)
- }
- }
- if len(inheritItems) > 0 {
- err = data_manage.AddCygxActivitySpecialInheritPointsCompanyMulti(inheritItems)
- if err != nil {
- return
- }
- }
- return
- }
- func GetUserType(companyId int) (userType, packageType int, permissionStrnew, companyStatus string, err error) {
- var permissionStr, permissionZhengShiStr string
- if companyId <= 1 {
- userType = 0
- } else {
- total, errs := data_manage.GetCountCompanyDetailByIdGroup(companyId)
- if errs != nil {
- err = errs
- return
- }
- if total == 0 {
- userType = 0
- } else {
- companyDetail, errs := data_manage.GetCompanyDetailByIdGroup(companyId)
- if errs != nil {
- err = errs
- return
- }
- companyStatus = companyDetail.Status
- permissionStr, errs = data_manage.GetCompanyPermission(companyId)
- if errs != nil {
- err = errs
- return
- }
- permissionStrnew = permissionStr
-
- companyUserTypeDetail, errs := data_manage.GetCygxCompanyUserType(companyId)
- if errs != nil && errs.Error() != utils.ErrNoRow() {
- err = errs
- return
- }
- if companyUserTypeDetail != nil {
- packageType = companyUserTypeDetail.PackageType
- if companyUserTypeDetail.CustomerTypeId != 0 {
- userType = companyUserTypeDetail.CustomerTypeId
- return
- }
- }
- permissionZhengShiStr, errs = data_manage.GetCompanyPermissionByUserZhengShi(companyId)
- if errs != nil {
- err = errs
- return
- }
-
-
- if companyDetail.Status == "永续" {
- userType = 1
- } else if companyDetail.Status == "试用" {
- userType = 5
- } else if companyDetail.Status == "冻结" {
- userType = 6
- } else if companyDetail.Status == "流失" {
- userType = 7
- }
-
- if userType == 0 && companyDetail.Status == "正式" {
- var permissionZhegnshiNum int
- if strings.Count(permissionZhengShiStr, "医药") == 2 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "消费") == 2 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "科技") == 2 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "智造") == 2 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "策略") == 1 {
- permissionZhegnshiNum++
- }
- if strings.Count(permissionZhengShiStr, "路演服务") == 1 {
- permissionZhegnshiNum++
- }
-
-
-
-
- if permissionZhegnshiNum >= 4 {
- userType = 10
- } else {
- userType = 3
- }
- }
- }
- }
- permissionStrnew = permissionStr
- return
- }
- func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tripRemaining int, mapChartName map[string]int, err error) {
- companyDetail, e := data_manage.GetCompanyDetailByIdGroup(companyId)
- if e != nil {
- err = errors.New("GetCompanyDetailByIdGroup, Err: " + e.Error())
- }
- if companyDetail == nil {
- return
- }
- if companyDetail.Status != "永续" && companyDetail.Status != "正式" {
- return
- }
-
-
-
-
-
-
-
-
- inheritList, e := data_manage.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
- }
- listPermissionNameRai,e:= models.GetPermissionByProductIdAndClassifyName(2,"权益")
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetPermissionByProductIdAndClassifyName, Err: " + e.Error())
- }
- mapPermissionName := make(map[int]string)
- for _,v:= range listPermissionNameRai{
- mapPermissionName[v.ChartPermissionId] = v.ChartPermissionName
- }
- if companyDetail.Status == "正式" {
- userType, _, _, _, _ = GetUserType(companyId)
- var condition string
- var pars []interface{}
- condition += ` AND company_id = ? `
- pars = append(pars, companyId)
-
- condition += ` AND b.create_time >= ? `
- pars = append(pars, time.Now().Format("2006")+"-01-01")
- listTripBill, e := data_manage.GetCygxActivitySpecialTripBillList(condition, pars)
- if e != nil {
- err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
- return
- }
- for k, v := range listTripBill {
- listTripBill[k].ChartPermissionName = mapPermissionName[v.ChartPermissionId]
- }
- if userType == 2 {
-
-
-
-
-
- var TripBillNum int
- for _, v := range listTripBill {
- TripBillNum += v.BillDetailed
- }
-
-
-
- tripRemaining = TripBillNum
- if tripRemaining < 0 {
- tripRemaining = 0
- }
-
-
-
-
-
-
-
-
-
- } 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)
-
- for _, v := range list {
- chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
-
- if v.IsUpgrade == 1 {
- mapUpgradeId[v.ChartPermissionId] = 1
- }
- }
- chartList, e := models.GetChartPermissionByIds(chartPermissionIdSlice)
- if e != nil {
- err = errors.New("获取品种信息失败, Err:" + e.Error())
- return
- }
- if len(chartList) == 0 {
- return
- }
-
- for _, v := range listTripBill {
- if v.ActivityId == 0 {
- continue
- }
- mapPermissionNameTrip[v.ChartPermissionName] += v.BillDetailed
- }
- 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 _, v := range mapChartName {
- if v > 0 {
- tripRemaining += v
- }
- }
- }
- }
- return
- }
|