相关条件的统计
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

svc_reward.go 5.9 KiB

3 månader sedan
3 månader sedan
1 månad sedan
3 månader sedan
1 månad sedan
3 månader sedan
1 månad sedan
3 månader sedan
1 månad sedan
3 månader sedan
3 månader sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package svc
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db"
  4. "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model"
  5. zhios_condition_statistics_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils"
  6. "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/service_award_dividend"
  7. "code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement"
  8. "code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/models"
  9. "errors"
  10. "fmt"
  11. "time"
  12. "xorm.io/xorm"
  13. )
  14. func AddCouponRecord(eg *xorm.Engine, user *model.User, pvdType, coupon string) bool {
  15. changeUid := user.Uid
  16. //接收的用户
  17. transformUserTotal, err := db.GetCouponUserTotalByOneEg(eg, changeUid, pvdType)
  18. if err != nil {
  19. return false
  20. }
  21. if transformUserTotal == nil {
  22. transformUserTotal = &model.CommCouponUserTotal{
  23. Uid: changeUid,
  24. UsePvd: "",
  25. CouponAmountValue: "",
  26. CreateAt: time.Now(),
  27. UpdateAt: time.Now(),
  28. LeaveCouponAmountValue: "",
  29. PvdType: pvdType,
  30. }
  31. has, err := eg.InsertOne(transformUserTotal)
  32. if has == 0 || err != nil {
  33. fmt.Println("优惠券错误:", err)
  34. return false
  35. }
  36. }
  37. leaveAmount := zhios_condition_statistics_utils.StrToFloat64(coupon)
  38. beforeTotal := zhios_condition_statistics_utils.StrToFloat64(transformUserTotal.LeaveCouponAmountValue)
  39. transformUserTotal.CouponAmountValue = zhios_condition_statistics_utils.Float64ToStrByPrec(zhios_condition_statistics_utils.StrToFloat64(transformUserTotal.CouponAmountValue)+leaveAmount, 9)
  40. transformUserTotal.LeaveCouponAmountValue = zhios_condition_statistics_utils.Float64ToStrByPrec(zhios_condition_statistics_utils.StrToFloat64(transformUserTotal.LeaveCouponAmountValue)+leaveAmount, 9)
  41. eg.Where("id=?", transformUserTotal.Id).Update(transformUserTotal)
  42. //写入明细
  43. var ord1 = &model.CommCouponUserOrd{
  44. Uid: user.Uid,
  45. OrdType: 50,
  46. PackageId: 0,
  47. CouponAmountValue: zhios_condition_statistics_utils.Float64ToStr(leaveAmount),
  48. CreateAt: time.Now(),
  49. UpdateAt: time.Now(),
  50. PvdType: pvdType,
  51. UsePvd: "[\"GUIDE\",\"SELF_MALL\"]",
  52. GoodsTitle: "升级赠送",
  53. BeforeAmout: zhios_condition_statistics_utils.Float64ToStrByPrec(beforeTotal, 9),
  54. AfterAmout: transformUserTotal.LeaveCouponAmountValue,
  55. }
  56. eg.Insert(ord1)
  57. return true
  58. }
  59. func AddCoin(eg *xorm.Engine, money float64, Title, ordId string, types, transferType, uid, coinId int, amount string) (int64, error) {
  60. //定制客户存入购物金分期
  61. req := map[string]string{
  62. "coin_id": zhios_condition_statistics_utils.IntToStr(coinId),
  63. "pvd": "2",
  64. "uid": zhios_condition_statistics_utils.IntToStr(uid),
  65. "oid": ordId,
  66. "amount": zhios_condition_statistics_utils.Float64ToStr(money),
  67. "price": amount,
  68. }
  69. NewServiceAwardReturnBaseDb := implement.NewServiceAwardReturnBaseDb(eg)
  70. base, _ := NewServiceAwardReturnBaseDb.GetServiceAwardReturnBase()
  71. if base != nil && base.CoinId == zhios_condition_statistics_utils.StrToInt(req["coin_id"]) {
  72. date := service_award_dividend.GetCycle(eg)
  73. data := models.ServiceAwardReturnFlowSale{
  74. Uid: zhios_condition_statistics_utils.StrToInt(req["uid"]),
  75. Time: time.Now(),
  76. UpdateTime: time.Now(),
  77. Type: 1,
  78. Pvd: zhios_condition_statistics_utils.StrToInt(req["pvd"]),
  79. CoinId: base.CoinId,
  80. Date: zhios_condition_statistics_utils.StrToInt(date["now"]),
  81. LastDate: zhios_condition_statistics_utils.StrToInt(date["last"]),
  82. Price: amount,
  83. }
  84. eg.Insert(&data)
  85. }
  86. state := service_award_dividend.AddPeriodEg(eg, req)
  87. if state == 3 {
  88. return 0, errors.New("失败")
  89. }
  90. if state == 1 {
  91. return 1, nil
  92. }
  93. UserVirtualAmount, err := db.UserVirtualAmountFindById(eg, uid, coinId)
  94. if err != nil || UserVirtualAmount == nil {
  95. if err == nil {
  96. err = errors.New("获取用户余额信息失败")
  97. }
  98. return 0, err
  99. }
  100. beforeAmount := UserVirtualAmount.Amount
  101. afterAmount := ""
  102. if types == 1 {
  103. afterAmount = zhios_condition_statistics_utils.Float64ToStrByPrec(zhios_condition_statistics_utils.AnyToFloat64(UserVirtualAmount.Amount)+money, 6)
  104. UserVirtualAmount.Amount = zhios_condition_statistics_utils.Truncate(zhios_condition_statistics_utils.Float64ToStrByPrec(zhios_condition_statistics_utils.AnyToFloat64(UserVirtualAmount.Amount)+money, 5), 4)
  105. } else if types == 2 {
  106. afterAmount = zhios_condition_statistics_utils.Float64ToStrByPrec(zhios_condition_statistics_utils.AnyToFloat64(UserVirtualAmount.Amount)-money, 6)
  107. UserVirtualAmount.Amount = zhios_condition_statistics_utils.Truncate(zhios_condition_statistics_utils.Float64ToStrByPrec(zhios_condition_statistics_utils.AnyToFloat64(UserVirtualAmount.Amount)-money, 5), 4)
  108. if zhios_condition_statistics_utils.StrToInt64(UserVirtualAmount.Amount) < 0 {
  109. err = errors.New("余额不足")
  110. return 0, err
  111. }
  112. }
  113. affected, err := db.UserVirtualAmountUpdate(eg, uid, coinId, UserVirtualAmount, "amount")
  114. if err != nil || affected == 0 {
  115. if err == nil {
  116. err = errors.New("更新用户余额信息失败")
  117. }
  118. return 0, err
  119. }
  120. id, err := virtualCoinFlowInsert(eg, uid, coinId, zhios_condition_statistics_utils.Float64ToStrByPrec(money, 8), ordId, Title, types, transferType, beforeAmount, afterAmount)
  121. if err != nil {
  122. return 0, err
  123. }
  124. return id, nil
  125. }
  126. func virtualCoinFlowInsert(eg *xorm.Engine, uid, coinId int, money string, ordId string, ItemTitle string, types, transferType int, beforeAmount string, afterAmount string) (int64, error) {
  127. now := time.Now()
  128. data := &model.UserVirtualCoinFlow{
  129. Uid: uid,
  130. OrdId: ordId,
  131. CoinId: coinId,
  132. Direction: types,
  133. Title: ItemTitle,
  134. Amout: money,
  135. BeforeAmout: beforeAmount,
  136. AfterAmout: afterAmount,
  137. CreateTime: now,
  138. TransferType: transferType,
  139. Date: now.Format("2006-01"),
  140. }
  141. eg.Insert(data)
  142. return data.Id, nil
  143. }