golang 的 rabbitmq 消费项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

svc_commission.go 4.6 KiB

6 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/md"
  5. "applet/app/utils"
  6. "applet/app/utils/logx"
  7. "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/lib/comm_plan"
  8. md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md"
  9. "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule"
  10. "errors"
  11. "fmt"
  12. "github.com/gin-gonic/gin"
  13. "github.com/jinzhu/copier"
  14. "xorm.io/xorm"
  15. )
  16. // GetCommissionByCommApi 调用公共接口获取佣金
  17. func GetCommissionByCommApi(eg *xorm.Engine, masterId string, req md.CommissionFirstParam) (*comm_plan.SettleCommissionToGuide, error) {
  18. profit, pvdFee, sysFee, subsidyFee, lvUser, err := SettleComm(eg, masterId, req)
  19. if err != nil {
  20. return nil, err
  21. }
  22. result := &comm_plan.SettleCommissionToGuide{
  23. Profit: profit,
  24. PvdFee: pvdFee,
  25. SysFee: sysFee,
  26. SubsidyFee: subsidyFee,
  27. LvUser: lvUser,
  28. }
  29. return result, nil
  30. }
  31. func GetCommissionByCommApiExtend(eg *xorm.Engine, masterId string, reqs md.CommissionReq) (*comm_plan.LvUser, error) {
  32. var req md2.CommissionFirstParam
  33. copier.Copy(&req, reqs)
  34. _, _, _, _, lvUser, err := rule.SettleCommWithGoodsDetailExtend(eg, masterId, req)
  35. if err != nil {
  36. return nil, errors.New("分佣数据解析错误")
  37. }
  38. return lvUser, nil
  39. }
  40. func SettleComm(eg *xorm.Engine, masterId string, CommissionParam md.CommissionFirstParam) (float64, float64, float64, float64, *comm_plan.LvUser, error) {
  41. var CommissionParam1 = md2.CommissionFirstParam{}
  42. copier.Copy(&CommissionParam1, CommissionParam)
  43. profit, pvdFee, sysFee, subsidyFee, lvUser, err := rule.SettleCommWithOrder(eg, masterId, CommissionParam1)
  44. return profit, pvdFee, sysFee, subsidyFee, lvUser, err
  45. }
  46. // 批量计算分佣
  47. func BatchGetCommissionByGoodsApi(c *gin.Context, eg *xorm.Engine, masterId string, reqs []md.CommissionFirstParam) (map[string]*comm_plan.LvUser, error) {
  48. var req []*md2.CommissionFirstParam
  49. for _, v := range reqs {
  50. var tmp = md2.CommissionFirstParam{}
  51. err2 := copier.Copy(&tmp, v)
  52. if err2 != nil {
  53. utils.FilePutContents(c.GetString("mid")+"_tik_tok_goods", "============"+c.GetString("postDataP")+"======"+utils.SerializeStr(err2))
  54. }
  55. req = append(req, &tmp)
  56. }
  57. utils.FilePutContents(c.GetString("mid")+"_tik_tok_goods", "============"+c.GetString("postDataP")+"======"+utils.SerializeStr(req))
  58. commissionList, err := rule.BatchGetCommissionByGoods(eg, masterId, req)
  59. if err != nil {
  60. return nil, logx.Error(err)
  61. }
  62. return commissionList, nil
  63. }
  64. // 批量计算分佣
  65. func BatchGetCommissionByCommApi(eg *xorm.Engine, masterId string, reqs []md.CommissionFirstParam) (map[string]*comm_plan.SettleCommissionToGuide, error) {
  66. var req = make([]*md2.CommissionFirstParam, 0)
  67. for _, v := range reqs {
  68. var tmp = md2.CommissionFirstParam{}
  69. copier.Copy(&tmp, v)
  70. req = append(req, &tmp)
  71. }
  72. commissionList, err := rule.BatchGetCommissionByOrder(eg, masterId, req)
  73. if err != nil {
  74. return nil, logx.Error(err)
  75. }
  76. return commissionList, nil
  77. }
  78. // 批量计算分佣
  79. func BatchGetCommissionByCommApiSecond(eg *xorm.Engine, masterId string, reqs []*md.CommissionReq) (map[string]*comm_plan.LvUser, error) {
  80. var req []*md2.CommissionFirstParam
  81. for _, v := range reqs {
  82. var tmp = md2.CommissionFirstParam{}
  83. copier.Copy(&tmp, v)
  84. req = append(req, &tmp)
  85. }
  86. commissionList, err := rule.BatchGetCommissionByGoods(eg, masterId, req)
  87. if err != nil {
  88. fmt.Println("=========================", err.Error())
  89. commissionList = map[string]*comm_plan.LvUser{}
  90. }
  91. return commissionList, nil
  92. }
  93. func BatchGetCommissionByCommApiExtend(eg *xorm.Engine, masterId string, reqs []*md.CommissionReq) (map[string]*comm_plan.LvUser, error) {
  94. var req []*md2.CommissionFirstParam
  95. for _, v := range reqs {
  96. var tmp = md2.CommissionFirstParam{}
  97. copier.Copy(&tmp, v)
  98. req = append(req, &tmp)
  99. }
  100. commissionList, err := rule.BatchGetCommissionByGoodsExtend(eg, masterId, req)
  101. if err != nil {
  102. commissionList = map[string]*comm_plan.LvUser{}
  103. }
  104. return commissionList, nil
  105. }
  106. func GetCommission(eg *xorm.Engine, masterId, commission, Uid, Provider string, IsShare int, showLevel string) (respCommission, shareCommission string) {
  107. var t = md.CommissionFirstParam{}
  108. param := md.CommissionParam{Commission: commission}
  109. t.CommissionParam = param
  110. t.Uid = Uid
  111. t.Provider = Provider
  112. t.IsShare = IsShare
  113. t.ShowLevel = showLevel
  114. pvd, err2 := db.DbsPlanCommissionByPvd(eg, Provider)
  115. if err2 != nil || pvd == nil {
  116. return "0", "0"
  117. }
  118. var req = md2.CommissionFirstParam{}
  119. copier.Copy(&req, t)
  120. respCommission1, shareCommission1, _, err := rule.GetRewardCommission(eg, masterId, pvd.Mode, req)
  121. if err != nil {
  122. return "0", "0"
  123. }
  124. return utils.AnyToString(respCommission1), utils.AnyToString(shareCommission1)
  125. }