activity_points_set.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_task/models"
  6. "hongze/hongze_task/models/data_manage"
  7. "hongze/hongze_task/services/alarm_msg"
  8. "hongze/hongze_task/utils"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. type YanXuanActivityPointsRedis struct {
  14. UserId int `description:"用户ID"`
  15. ComapnyId int `description:"公司ID"`
  16. ActivityId int `description:"活动ID"`
  17. PublishStatus int `description:"发布状态 1已发布,0未发布"`
  18. SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会、6 研选审批通过的时候研选扣点更新。"`
  19. AdminId int `description:"管理员、销售ID"`
  20. Source int `description:" 来源,1客户端,2后台添加, 3开发人员手动添加、4定时任务"`
  21. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  22. CreateTime time.Time `description:"创建时间"`
  23. }
  24. //func init(){
  25. // log := &YanXuanActivityPointsRedis{ComapnyId: 16, SourceType: 7, Source: 4, CreateTime: time.Now()}
  26. // if utils.Re == nil {
  27. // err := utils.Rc.LPush(utils.CYGX_YANXUAN_POINTS_KEY, log)
  28. // if err != nil {
  29. // fmt.Println("YanXuanActivityPointsRedis LPush Err:" + err.Error())
  30. // }
  31. // }
  32. //}
  33. // 6 研选审批通过的时候研选扣点更新
  34. func YanXuanCompanyApproval(comapnyId int) (err error) {
  35. defer func() {
  36. if err != nil {
  37. fmt.Println(err)
  38. msg := fmt.Sprint("comapnyId:", comapnyId)
  39. go alarm_msg.SendAlarmMsg("研选审批通过的时候研选扣点更新,写入Redis队列消息失败:"+err.Error()+msg, 2)
  40. }
  41. }()
  42. //SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会。6 研选审批通过的时候研选扣点更新。7,正式专试用定时任务更新"`
  43. log := &YanXuanActivityPointsRedis{ComapnyId: comapnyId, SourceType: 6, Source: 2, CreateTime: time.Now()}
  44. if utils.Re == nil {
  45. err := utils.Rc.LPush(utils.CYGX_YANXUAN_POINTS_KEY, log)
  46. if err != nil {
  47. fmt.Println("YanXuanActivityPointsRedis LPush Err:" + err.Error())
  48. }
  49. }
  50. return
  51. }
  52. // 7 正式专试用定时任务更新研选扣点
  53. func YanXuanCompanyCompanyTryOut(comapnyId int) (err error) {
  54. defer func() {
  55. if err != nil {
  56. fmt.Println(err)
  57. msg := fmt.Sprint("comapnyId:", comapnyId)
  58. go alarm_msg.SendAlarmMsg("正式专试用定时任务更新研选扣点,写入Redis队列消息失败:"+err.Error()+msg, 2)
  59. }
  60. }()
  61. //SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会。6 研选审批通过的时候研选扣点更新。7,正式专试用定时任务更新"`
  62. log := &YanXuanActivityPointsRedis{ComapnyId: comapnyId, SourceType: 7, Source: 4, CreateTime: time.Now()}
  63. if utils.Re == nil {
  64. err := utils.Rc.LPush(utils.CYGX_YANXUAN_POINTS_KEY, log)
  65. if err != nil {
  66. fmt.Println("YanXuanActivityPointsRedis LPush Err:" + err.Error())
  67. }
  68. }
  69. return
  70. }
  71. // 审批通过的时候专项调研次数更新
  72. func ActivitySpecialCompanyApproval(companyId int) (err error) {
  73. defer func() {
  74. if err != nil {
  75. fmt.Println(err)
  76. msg := fmt.Sprint("companyId:", companyId)
  77. go alarm_msg.SendAlarmMsg("审批通过试用转正式时专项调研次数更新失败:"+err.Error()+msg, 2)
  78. }
  79. }()
  80. comapny, e := models.GetCompanyById(companyId)
  81. if e != nil {
  82. err = errors.New("GetCompanyById err:" + e.Error())
  83. return
  84. }
  85. // 获取继承点数
  86. inheritList, e := data_manage.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
  87. if e != nil && e.Error() != utils.ErrNoRow() {
  88. err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
  89. }
  90. chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
  91. userType, packageType, _, _, _ := GetUserType(companyId)
  92. itemBill := new(data_manage.CygxActivitySpecialTripBill)
  93. itemBill.CreateTime = time.Now()
  94. itemBill.CompanyId = companyId
  95. itemBill.CompanyName = comapny.CompanyName
  96. itemBill.Source = 2
  97. itemBill.DoType = 2
  98. itemBill.Way = 3
  99. if userType == 2{
  100. packageTypeMap := map[int]int{1: 16, 2: 10}
  101. totalTrip := packageTypeMap[packageType]
  102. if len(inheritList) > 0 {
  103. for _, v := range inheritList {
  104. if v.ChartPermissionId == 0 {
  105. itemBill.BillDetailed = totalTrip + v.Points
  106. } else {
  107. itemBill.BillDetailed = totalTrip
  108. }
  109. }
  110. } else {
  111. itemBill.BillDetailed = totalTrip
  112. }
  113. itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次"
  114. if totalTrip == 10 {
  115. itemBill.Content = "45w大套餐转正"
  116. } else {
  117. itemBill.Content = "70w大套餐转正"
  118. }
  119. } else {
  120. list, e := GetCompanyReportPermission(companyId, 2)
  121. if e != nil && e.Error() != utils.ErrNoRow() {
  122. err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  123. }
  124. if len(list) == 0 {
  125. return
  126. }
  127. var chartPermissionIdSlice []string
  128. mapChartName := make(map[string]int)
  129. mapUpgradeId := make(map[int]int)
  130. mapInheritChartName := make(map[string]int)
  131. mapPermissionNameTrip := make(map[string]int)
  132. //mapPermissionName := make(map[int]string)
  133. for _, v := range list {
  134. chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
  135. //是升级套餐才有点数
  136. if v.IsUpgrade == 1 {
  137. mapUpgradeId[v.ChartPermissionId] = 1
  138. }
  139. }
  140. chartList := make([]*models.ChartPermission, 0)
  141. if len(chartPermissionIdSlice) > 0 {
  142. chartList, e = models.GetChartPermissionByIds(chartPermissionIdSlice)
  143. if e != nil {
  144. err = errors.New("获取品种信息失败, Err:" + e.Error())
  145. return
  146. }
  147. }
  148. if len(chartList) == 0 {
  149. return
  150. }
  151. for _, v := range chartList {
  152. //如果是升级则加点
  153. if _, ok := mapUpgradeId[v.ChartPermissionId]; ok {
  154. mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.ChartPermissionName]
  155. } else {
  156. mapChartName[v.PermissionName] = mapPermissionNameTrip[v.ChartPermissionName]
  157. }
  158. }
  159. // 通过继承获得的加点
  160. for _, v := range inheritList {
  161. mapInheritChartName[v.ChartPermissionName] = v.Points
  162. }
  163. for k, _ := range chartNameMap {
  164. if _, ok := mapChartName[k]; ok {
  165. if inherit, ok2 := mapInheritChartName[k]; ok2 {
  166. mapChartName[k] += inherit
  167. }
  168. }
  169. }
  170. for k, v := range mapChartName {
  171. if v > 0 {
  172. itemBill.BillDetailed += v
  173. itemBill.Total += k + strconv.Itoa(v) + "次+"
  174. }
  175. }
  176. itemBill.Content = "行业升级套餐转正"
  177. itemBill.Total = strings.TrimRight(itemBill.Total, "+")
  178. }
  179. err = data_manage.AddCygxActivitySpecialTripBill(itemBill)
  180. if err != nil {
  181. return
  182. }
  183. return
  184. }