obtainshuntlogic.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package logic
  2. import (
  3. "context"
  4. "math/rand"
  5. "time"
  6. . "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/common"
  7. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/internal/svc"
  8. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/internal/types"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type ObtainShuntLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewObtainShuntLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ObtainShuntLogic {
  17. return &ObtainShuntLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func (l *ObtainShuntLogic) ObtainShunt(req *types.ShuntReq) (*types.CommonRes, error) {
  24. // todo: add your logic here and delete this line
  25. data := map[string]interface{}{}
  26. if C.IsShunt {
  27. data["isShunt"] = C.IsShunt
  28. //计算概率,获取分流途径
  29. shunt := "智齿"
  30. if rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(100) <= C.ShuntProbability {
  31. shunt = "智齿"
  32. } else {
  33. shunt = "剑鱼"
  34. }
  35. if shunt == "智齿" {
  36. if req.Type == "PC" {
  37. data["url"] = C.ZhiCiUrl.Pc
  38. } else if req.Type == "APP" {
  39. data["url"] = C.ZhiCiUrl.App
  40. } else {
  41. data["url"] = C.ZhiCiUrl.Wx
  42. }
  43. } else {
  44. if req.Type == "PC" {
  45. data["url"] = C.MessageUrl.Pc
  46. } else if req.Type == "APP" {
  47. data["url"] = C.MessageUrl.App
  48. } else {
  49. data["url"] = C.MessageUrl.Wx
  50. }
  51. }
  52. } else {
  53. data["isShunt"] = C.IsShunt
  54. if req.Type == "PC" {
  55. data["url"] = C.ZhiCiUrl.Pc
  56. } else if req.Type == "App" {
  57. data["url"] = C.ZhiCiUrl.App
  58. } else {
  59. data["url"] = C.ZhiCiUrl.Wx
  60. }
  61. }
  62. return &types.CommonRes{
  63. Data: data,
  64. }, nil
  65. }