优惠券额度包
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.

coupon_comm_check.go 1.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package zyos_go_coupon
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git/db"
  4. "code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git/md"
  5. "code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git/utils"
  6. "strings"
  7. "xorm.io/xorm"
  8. )
  9. func CommCheck(eg *xorm.Engine, req md.CouponCheckRequest) map[string]string {
  10. var r = map[string]string{
  11. "user_coupon_amount": "0",
  12. "is_show_coupon_list": "0",
  13. "is_can_buy": "1",
  14. "base_coupon_time": "1440",
  15. }
  16. //查查剩余额度
  17. userCouponAmount, err := db.GetCouponUserTotalByLeaveSumWithType(eg, utils.StrToInt(req.Uid), req.PvdType, "leave_coupon_amount_value")
  18. if err != nil {
  19. return r
  20. }
  21. //查出基本配置
  22. baseList, err := db.CommCouponBaseList(eg)
  23. if err != nil || baseList == nil {
  24. return r
  25. }
  26. if baseList.Id == 0 {
  27. return r
  28. }
  29. isCanBuy := 1
  30. isShowCouponList := 1
  31. //判断额度够不够 并且有没有开启
  32. if utils.StrToFloat64(req.CouponAmount) > userCouponAmount {
  33. isCanBuy = 0
  34. }
  35. if utils.StrToFloat64(req.CouponAmount) == 0 {
  36. if utils.StrToInt(req.CheckAmount) == 1 {
  37. isCanBuy = 1
  38. isShowCouponList = 0
  39. }
  40. if utils.StrToInt(req.CheckAmount) == 0 && userCouponAmount == 0 {
  41. isCanBuy = 0
  42. isShowCouponList = 1
  43. }
  44. }
  45. //判断有没有开启
  46. if baseList.IsUse == 0 {
  47. isCanBuy = 1
  48. isShowCouponList = 0
  49. }
  50. //判断有没有这个渠道
  51. if strings.Contains(baseList.BonusType, req.PvdType) == false {
  52. isCanBuy = 1
  53. isShowCouponList = 0
  54. }
  55. r = map[string]string{
  56. "user_coupon_amount": utils.Float64ToStr(userCouponAmount),
  57. "is_show_coupon_list": utils.IntToStr(isShowCouponList),
  58. "is_can_buy": utils.IntToStr(isCanBuy),
  59. "base_coupon_time": utils.IntToStr(baseList.RefundTime),
  60. }
  61. if utils.IntToStr(baseList.RefundTime) == "0" {
  62. r["base_coupon_time"] = "1440"
  63. }
  64. return r
  65. }