integral.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package rpc
  2. import (
  3. "app.yhyue.com/moapp/jyMarketing/rpc/activityclient"
  4. "app.yhyue.com/moapp/jyPoints/rpc/integral"
  5. "app.yhyue.com/moapp/jyPoints/rpc/integralclient"
  6. "app.yhyue.com/moapp/jybase/date"
  7. "app.yhyue.com/moapp/jybase/go-logger/logger"
  8. "context"
  9. "fmt"
  10. "github.com/gogf/gf/v2/os/gcfg"
  11. "github.com/gogf/gf/v2/os/gctx"
  12. "github.com/tal-tech/go-zero/core/discov"
  13. "github.com/tal-tech/go-zero/zrpc"
  14. "log"
  15. "time"
  16. )
  17. var zrpcClient zrpc.Client
  18. var activeLib activityclient.Activity
  19. func init() {
  20. var err error
  21. zrpcClient, err = zrpc.NewClient(zrpc.RpcClientConf{
  22. Etcd: discov.EtcdConf{
  23. Hosts: gcfg.Instance().MustGet(gctx.New(), "etcd.baseserver.integral.address", nil).Strings(),
  24. Key: gcfg.Instance().MustGet(gctx.New(), "etcd.baseserver.integral.key", nil).String(),
  25. },
  26. })
  27. if err != nil {
  28. log.Fatalln(err)
  29. }
  30. client := zrpc.MustNewClient(zrpc.RpcClientConf{
  31. Etcd: discov.EtcdConf{
  32. Hosts: gcfg.Instance().MustGet(gctx.New(), "etcd.activeServer.integral.address", nil).Strings(),
  33. Key: gcfg.Instance().MustGet(gctx.New(), "etcd.activeServer.integral.key", nil).String(),
  34. },
  35. })
  36. // defer client.Conn().Close()
  37. activeLib = activityclient.NewActivity(client)
  38. }
  39. // IntegralHarvest 积分奖励发放
  40. func IntegralHarvest(userId string, pNum, pType, dateStamp int64) error {
  41. t := time.Unix(dateStamp, 0).AddDate(1, 0, 0)
  42. req := &integral.Req{
  43. UserId: userId,
  44. AppId: gcfg.Instance().MustGet(gctx.New(), "docPoints.appId", "10000").String(),
  45. PointType: pType,
  46. Point: pNum,
  47. EndDate: date.FormatDate(&t, date.Date_Full_Layout),
  48. OperationType: false,
  49. }
  50. resp, err := integralclient.NewIntegral(zrpcClient).IntegralHarvest(gctx.New(), req)
  51. if err != nil {
  52. return fmt.Errorf(fmt.Sprintf("%+v", req), "IntegralHarvest Resp error", err)
  53. }
  54. if resp.Code == 1 {
  55. logger.Info(fmt.Sprintf("%+v", req), "已成功增加", pNum, "积分")
  56. return nil
  57. } else {
  58. return fmt.Errorf(fmt.Sprintf("%+v", req), "增加", pNum, "积分失败", "Code", resp.Code, "Message", resp.Message)
  59. }
  60. }
  61. type UserLottery struct{}
  62. var UserHarvest *UserLottery
  63. func (this *UserLottery) HarvestFunc(activeReq activityclient.Request) (resp activityclient.ActivityLotteryResp) {
  64. _resp, err := activeLib.UserLottery(context.Background(), &activeReq)
  65. if err != nil {
  66. log.Println("UserHarvest error:", err)
  67. }
  68. return *_resp
  69. }