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

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