pay.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/interface/main/videoup/model/archive"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. "go-common/library/queue/databus/report"
  8. "time"
  9. )
  10. // dealAddPay fn
  11. func (s *Service) dealAddPay(c context.Context, pay *archive.Pay, aid, mid int64, ip string) (err error) {
  12. // step 1: call API
  13. if err = s.pay.AssReg(c, mid, aid, pay.Price, ip); err != nil {
  14. log.Error("s.pay.AssReg mid(%d)|aid(%d)|pay(%+v) error(%v)", mid, aid, pay, err)
  15. return
  16. }
  17. // step 2: add protocol user log
  18. var index = []interface{}{mid, pay.ProtocolID}
  19. uInfo := &report.UserInfo{
  20. Mid: mid,
  21. Business: archive.UgcpayAddarcProtocol,
  22. Type: 1,
  23. Oid: aid,
  24. Action: "add",
  25. Ctime: time.Now(),
  26. IP: ip,
  27. Index: index,
  28. }
  29. uInfo.Content = map[string]interface{}{
  30. "content": pay,
  31. "protocol_id": pay.ProtocolID,
  32. "mid": mid,
  33. }
  34. report.User(uInfo)
  35. log.Warn("sendLog dealAddPay protocol info (%+v)", uInfo)
  36. return
  37. }
  38. // dealAdjustPay fn
  39. func (s *Service) dealAdjustPay(c context.Context, pay *archive.Pay, aid, mid int64, ip string) (err error) {
  40. // step 1: call API
  41. if err = s.pay.AssReg(c, mid, aid, pay.Price, ip); err != nil {
  42. log.Error("s.pay.AssReg mid(%d)|aid(%d)|pay(%+v) error(%v)", mid, aid, pay, err)
  43. return
  44. }
  45. // step 2: add protocol user log
  46. var index = []interface{}{mid, pay.ProtocolID}
  47. uInfo := &report.UserInfo{
  48. Mid: mid,
  49. Business: archive.UgcpayAddarcProtocol,
  50. Type: 1,
  51. Oid: aid,
  52. Action: "edit",
  53. Ctime: time.Now(),
  54. IP: ip,
  55. Index: index,
  56. }
  57. uInfo.Content = map[string]interface{}{
  58. "content": pay,
  59. "protocol_id": pay.ProtocolID,
  60. "mid": mid,
  61. }
  62. report.User(uInfo)
  63. log.Warn("sendLog dealAdjustPay protocol info (%+v)", uInfo)
  64. return
  65. }
  66. // 参与UGC付费之前必须接受当前最新的投稿协议
  67. func (s *Service) checkPayProtocol(c context.Context, pay *archive.Pay, mid int64) (err error) {
  68. if pay != nil {
  69. accept, _ := s.pay.UserAcceptProtocol(c, pay.ProtocolID, mid)
  70. if accept {
  71. return
  72. }
  73. if !accept && pay.ProtocolAccept == 0 {
  74. log.Error("s.rejectUgcProtocolBefore (%+v),(%+v)", pay, err)
  75. err = ecode.VideoupPayProtocolLimit
  76. return
  77. }
  78. }
  79. return
  80. }
  81. // 付费提交校验
  82. func (s *Service) checkPayLimit(c context.Context, ap *archive.ArcParam) (err error) {
  83. pay := ap.Pay
  84. if pay != nil {
  85. if _, ok := s.exemptUgcPayUps[ap.Mid]; !ok { // 用户灰度
  86. log.Error("s.checkAddPayLimit VideoupPayUserNotAllow (%d),(%+v)", ap.Mid, err)
  87. err = ecode.VideoupPayUserNotAllow
  88. return
  89. }
  90. if pay.Open == 1 {
  91. if ap.Copyright != archive.CopyrightOriginal { // 创作类型
  92. log.Error("s.checkAddPayLimit VideoupPayCopyrightErr (%+v),(%+v)", ap, err)
  93. err = ecode.VideoupPayCopyrightErr
  94. return
  95. }
  96. if pay.Price > 1000 || pay.Price < 1 { //开启之后的定价必须合理有效
  97. log.Error("s.checkAddPayLimit VideoupPayPriceErr (%+v),(%+v)", ap, err)
  98. err = ecode.VideoupPayPriceErr
  99. return
  100. }
  101. ap.UgcPay = 1
  102. } else {
  103. ap.UgcPay = 0
  104. }
  105. }
  106. return
  107. }
  108. // 一起检测是否和商单以及私单冲突,只能三选一
  109. func (s *Service) checkPayWithOrder(c context.Context, porder *archive.Porder, pay *archive.Pay, orderID, mid int64) (err error) {
  110. joinPorder := porder != nil && porder.FlowID > 0
  111. joinPay := pay != nil && pay.Open == 1
  112. if joinPay && (joinPorder || orderID > 0) {
  113. log.Error("s.checkAddPayWithOrder VideoupPayCommericalLimit (%d)|(%+v)|(%+v)|(%+v),(%+v)", mid, porder, pay, orderID, err)
  114. err = ecode.VideoupPayCommericalLimit
  115. return
  116. }
  117. return
  118. }