ugcpay.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package ugcpay
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/interface/main/app-view/conf"
  6. "go-common/app/interface/main/app-view/model/view"
  7. ugcpayrpc "go-common/app/service/main/ugcpay/api/grpc/v1"
  8. "github.com/pkg/errors"
  9. )
  10. // Dao is ugcpay dao
  11. type Dao struct {
  12. // grpc
  13. ugcpayRPC ugcpayrpc.UGCPayClient
  14. }
  15. // New ugcpay dao
  16. func New(c *conf.Config) (d *Dao) {
  17. d = &Dao{}
  18. var err error
  19. d.ugcpayRPC, err = ugcpayrpc.NewClient(nil)
  20. if err != nil {
  21. panic(fmt.Sprintf("ugcpay NewClient error(%v)", err))
  22. }
  23. return
  24. }
  25. // AssetRelationDetail ugcpay
  26. func (d *Dao) AssetRelationDetail(c context.Context, mid, aid int64, platform string) (res *view.Asset, err error) {
  27. var (
  28. arg = &ugcpayrpc.AssetRelationDetailReq{Mid: mid, Oid: aid, Otype: "archive", Currency: "bp"}
  29. asset *ugcpayrpc.AssetRelationDetailResp
  30. )
  31. if asset, err = d.ugcpayRPC.AssetRelationDetail(c, arg); err != nil {
  32. err = errors.Wrapf(err, "%v", arg)
  33. return
  34. }
  35. res = &view.Asset{}
  36. switch asset.RelationState {
  37. case "paid":
  38. res.Paid = 1
  39. }
  40. if price, ok := asset.AssetPlatformPrice[platform]; ok {
  41. res.Price = price
  42. } else {
  43. res.Price = asset.AssetPrice
  44. }
  45. res.Msg.Desc1 = "本视频为付费内容,支付" + fmt.Sprintf("%0.2f", float64(res.Price)/100) + "币即可观看"
  46. res.Msg.Desc2 = "用一点点奖励来支持UP主们创作吧"
  47. return
  48. }