|
- package zyos_go_coupon
-
- import (
- "code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git/db"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git/md"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git/utils"
- "strings"
- "xorm.io/xorm"
- )
-
- func CommCheck(eg *xorm.Engine, req md.CouponCheckRequest) map[string]string {
- var r = map[string]string{
- "user_coupon_amount": "0",
- "is_show_coupon_list": "0",
- "is_can_buy": "1",
- "base_coupon_time": "1440",
- }
- //查查剩余额度
- userCouponAmount, err := db.GetCouponUserTotalByLeaveSumWithType(eg, utils.StrToInt(req.Uid), req.PvdType, "leave_coupon_amount_value")
- if err != nil {
- return r
- }
- //查出基本配置
- baseList, err := db.CommCouponBaseList(eg)
- if err != nil || baseList == nil {
- return r
- }
- if baseList.Id == 0 {
- return r
- }
- isCanBuy := 1
- isShowCouponList := 1
- //判断额度够不够 并且有没有开启
- if utils.StrToFloat64(req.CouponAmount) > userCouponAmount {
- isCanBuy = 0
- }
- if utils.StrToFloat64(req.CouponAmount) == 0 {
- if utils.StrToInt(req.CheckAmount) == 1 {
- isCanBuy = 1
- isShowCouponList = 0
- }
- if utils.StrToInt(req.CheckAmount) == 0 && userCouponAmount == 0 {
- isCanBuy = 0
- isShowCouponList = 1
- }
- }
-
- //判断有没有开启
- if baseList.IsUse == 0 {
- isCanBuy = 1
- isShowCouponList = 0
- }
- //判断有没有这个渠道
- if strings.Contains(baseList.BonusType, req.PvdType) == false {
- isCanBuy = 1
- isShowCouponList = 0
- }
-
- r = map[string]string{
- "user_coupon_amount": utils.Float64ToStr(userCouponAmount),
- "is_show_coupon_list": utils.IntToStr(isShowCouponList),
- "is_can_buy": utils.IntToStr(isCanBuy),
- "base_coupon_time": utils.IntToStr(baseList.RefundTime),
- }
- if utils.IntToStr(baseList.RefundTime) == "0" {
- r["base_coupon_time"] = "1440"
- }
- return r
- }
|