|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- 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_tools.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, zhios_tool_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 zhios_tool_utils.StrToFloat64(req.CouponAmount) > userCouponAmount {
- isCanBuy = 0
- }
- if zhios_tool_utils.StrToFloat64(req.CouponAmount) == 0 {
- if zhios_tool_utils.StrToInt(req.CheckAmount) == 1 {
- isCanBuy = 1
- isShowCouponList = 0
- }
- if zhios_tool_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": zhios_tool_utils.Float64ToStr(userCouponAmount),
- "is_show_coupon_list": zhios_tool_utils.IntToStr(isShowCouponList),
- "is_can_buy": zhios_tool_utils.IntToStr(isCanBuy),
- "base_coupon_time": zhios_tool_utils.IntToStr(baseList.RefundTime),
- }
- if zhios_tool_utils.IntToStr(baseList.RefundTime) == "0" {
- r["base_coupon_time"] = "1440"
- }
- return r
- }
|