huangjiajun há 2 meses
ascendente
cometimento
4ba6c887e6
4 ficheiros alterados com 314 adições e 0 eliminações
  1. +31
    -0
      db/model/mall_coupon_scheme.go
  2. +20
    -0
      db/model/mall_user_coupon.go
  3. +190
    -0
      enum/mall_coupon.go
  4. +73
    -0
      rule/service_award_dividend/return.go

+ 31
- 0
db/model/mall_coupon_scheme.go Ver ficheiro

@@ -0,0 +1,31 @@
package model

import (
"time"
)

type MallCouponScheme struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Name string `json:"name" xorm:"not null default '' comment('名称') VARCHAR(255)"`
LvNum string `json:"lv_num" xorm:"not null default '' comment('名称') VARCHAR(255)"`
Kind int `json:"kind" xorm:"comment('优惠券类型:1立减2满减3折扣') TINYINT(1)"`
Cal string `json:"cal" xorm:"not null default '0.00' comment('折扣算法json:形式:{\"reach\":\"10.00\", \"reduce\":\"1.00\"},无门槛reach为0') VARCHAR(255)"`
SendWay int `json:"send_way" xorm:"comment('发放形式:1主动发放2手动发放') TINYINT(1)"`
SendTimeType int `json:"send_time_type" xorm:"comment('(主动发放时)发放类型:1立即2定时') TINYINT(1)"`
IsSend int `json:"is_send" xorm:"default 0 comment('(定时发放时)是否已发放0:否,1:是') TINYINT(1)"`
SendTime time.Time `json:"send_time" xorm:"comment('定时发放的时间') DATETIME"`
PerUserNum int `json:"per_user_num" xorm:"not null default 1 comment('(手动发放时)每人限制领多少张') INT(11)"`
SendUserType int `json:"send_user_type" xorm:"not null comment('1全部用户 2指定用户') TINYINT(1)"`
SendNum int `json:"send_num" xorm:"not null comment('发放数量') INT(11)"`
LeftNum int `json:"left_num" xorm:"not null comment('剩余数量') INT(11)"`
ValidTimeType int `json:"valid_time_type" xorm:"comment('有效期类型:1固定日期2领取后x天有效') TINYINT(1)"`
ValidTimeStart time.Time `json:"valid_time_start" xorm:"comment('固定日期开始') DATETIME"`
ValidTimeEnd time.Time `json:"valid_time_end" xorm:"comment('固定日期结束') DATETIME"`
ValidDayNum int `json:"valid_day_num" xorm:"comment('领取后有效的天数') INT(11)"`
UseRule int `json:"use_rule" xorm:"comment('1全部商品可用2指定商品3指定活动类型') TINYINT(1)"`
UseActivityType int `json:"use_activity_type" xorm:"comment('可用的活动类型: 1拼团活动 2秒杀活动 3砍价活动') TINYINT(1)"`
IsUse int `json:"is_use" xorm:"not null default 1 comment('是否开启:0否 1是') TINYINT(1)"`
CreateTime time.Time `json:"create_time" xorm:"default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateTime time.Time `json:"update_time" xorm:"default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
DeleteTime time.Time `json:"delete_time" xorm:"comment('删除时间') DATETIME"`
}

+ 20
- 0
db/model/mall_user_coupon.go Ver ficheiro

@@ -0,0 +1,20 @@
package model

import (
"time"
)

type MallUserCoupon struct {
Id int64 `json:"id" xorm:"not null pk autoincr BIGINT(20)"`
Uid int `json:"uid" xorm:"comment('用户id') index INT(11)"`
SchemeId int `json:"scheme_id" xorm:"comment('优惠券方案的id') INT(11)"`
IsUse int `json:"is_use" xorm:"comment('是否已使用:0否1是2失效') TINYINT(1)"`
Kind int `json:"kind" xorm:"comment('优惠券类型:1立减2满减3折扣') TINYINT(1)"`
Cal string `json:"cal" xorm:"not null default '0.00' comment('折扣算法json:形式:{\"reach\":\"10.00\", \"reduce\":\"1.00\"},无门槛reach为0') VARCHAR(255)"`
ValidTimeStart time.Time `json:"valid_time_start" xorm:"comment('有效日期开始') DATETIME"`
ValidTimeEnd time.Time `json:"valid_time_end" xorm:"comment('有效日期结束') DATETIME"`
UseRule int `json:"use_rule" xorm:"comment('1全部商品可用2指定商品3指定活动类型') TINYINT(1)"`
UseActivityType int `json:"use_activity_type" xorm:"comment('可用的活动类型: 1拼团活动 2秒杀活动 3砍价活动') TINYINT(1)"`
CreateTime time.Time `json:"create_time" xorm:"created default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateTime time.Time `json:"update_time" xorm:"updated default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 190
- 0
enum/mall_coupon.go Ver ficheiro

@@ -0,0 +1,190 @@
package enum

// MallCouponType 优惠券类型
type MallCouponType int

const (
MallCouponTypeImmediate MallCouponType = iota + 1 // 立减
MallCouponTypeReachReduce // 满减
MallCouponTypeReachDiscount // 满折
)

func (em MallCouponType) String() string {
switch em {
case MallCouponTypeImmediate:
return "立减券"
case MallCouponTypeReachReduce:
return "满减券"
case MallCouponTypeReachDiscount:
return "折扣券"
default:
return "未知类型"
}
}

// MallCouponSendWay 发放形式
type MallCouponSendWay int

const (
MallCouponSendWayPositive MallCouponSendWay = iota + 1
MallCouponSendWayManual
ActCouponSendWayReg
)

func (em MallCouponSendWay) String() string {
switch em {
case MallCouponSendWayPositive:
return "主动发放"
case MallCouponSendWayManual:
return "手动领取"
case ActCouponSendWayReg:
return "注册发放"
default:
return "未知类型"
}
}

// MallCouponSendTimeType 发放时间类型
type MallCouponSendTimeType int

const (
MallCouponSendTimeTypeImmediate MallCouponSendTimeType = iota + 1
MallCouponSendTimeTypeTiming
)

func (em MallCouponSendTimeType) String() string {
switch em {
case MallCouponSendTimeTypeImmediate:
return "立即发放"
case MallCouponSendTimeTypeTiming:
return "定时"
default:
return "未知类型"
}
}

// MallCouponSendUserType 发放用户
type MallCouponSendUserType int

const (
MallCouponSendUserTypeAll MallCouponSendUserType = iota + 1
MallCouponSendUserTypeSpecify
)

func (em MallCouponSendUserType) String() string {
switch em {
case MallCouponSendUserTypeAll:
return "全部用户"
case MallCouponSendUserTypeSpecify:
return "指定用户"
default:
return "未知类型"
}
}

// MallCouponValidTimeType 有效时间
type MallCouponValidTimeType int

const (
MallCouponValidTimeTypeFix MallCouponValidTimeType = iota + 1 // 固定日期
MallCouponValidTimeTypeXDay // 领取后x天有效
)

func (em MallCouponValidTimeType) String() string {
switch em {
case MallCouponValidTimeTypeFix:
return "固定日期"
case MallCouponValidTimeTypeXDay:
return "领取日起x天内"
default:
return "未知类型"
}
}

// MallCouponUseRule 使用规则
type MallCouponUseRule int

const (
MallCouponUseRuleAll MallCouponUseRule = iota + 1 // 全部商品可用
MallCouponUseRuleSpecifyGoods // 仅可用于指定商品
MallCouponUseRuleSpecifyActivity // 可用于活动类型
ActCouponUsePhone // 可用于权益卡话费
)

func (em MallCouponUseRule) String() string {
switch em {
case MallCouponUseRuleAll:
return "全部商品可用"
case MallCouponUseRuleSpecifyGoods:
return "仅可用于指定商品"
case MallCouponUseRuleSpecifyActivity:
return "可用于活动类型"
case ActCouponUsePhone:
return "可用于权益卡话费"
default:
return "未知类型"
}
}

type MallCouponUseActivityType int

const (
MallCouponUseActivityTypeForGroup MallCouponUseActivityType = iota + 1
MallCouponUseActivityTypeForSecondKill
MallCouponUseActivityTypeForBargain
)

func (em MallCouponUseActivityType) String() string {
switch em {
case MallCouponUseActivityTypeForGroup:
return "拼团活动"
case MallCouponUseActivityTypeForSecondKill:
return "秒杀活动"
case MallCouponUseActivityTypeForBargain:
return "砍价活动"
default:
return "未知类型"
}
}

type MallCouponSendState int

const (
MallCouponSendStateUnProvide MallCouponSendState = iota + 1 // 未发放
MallCouponSendStateProvide // 已发放
MallCouponSendStateProviding // 发放中
)

func (em MallCouponSendState) String() string {
switch em {
case MallCouponSendStateUnProvide:
return "未发放"
case MallCouponSendStateProvide:
return "已发放"
case MallCouponSendStateProviding:
return "发放中"
default:
return "未知类型"
}
}

type MallUserCouponUseState int

const (
MallUserCouponUseStateUnUse MallUserCouponUseState = iota // 未使用
MallUserCouponUseStateUsed // 已使用
MallUserCouponUseStateUnValid // 失效
)

func (em MallUserCouponUseState) String() string {
switch em {
case MallUserCouponUseStateUnUse:
return "未使用"
case MallUserCouponUseStateUsed:
return "已使用"
case MallUserCouponUseStateUnValid:
return "失效"
default:
return "未知类型"
}
}

+ 73
- 0
rule/service_award_dividend/return.go Ver ficheiro

@@ -1,9 +1,13 @@
package service_award_dividend

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/enum"
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/models"
"encoding/json"
"sort"
"strings"
"time"
@@ -210,3 +214,72 @@ func AddPeriodEg(eg *xorm.Engine, req map[string]string) int {
}
return 1
}
func CouponReward(eg *xorm.Engine, uid int) {
var data []model.MallCouponScheme
err2 := eg.Where("send_way=4 and left_num>0").Find(&data)
if len(data) == 0 || err2 != nil {
return
}
for _, v := range data {
BatchInsertMallUserCoupon(eg, v, uid)
}
}
func BatchInsertMallUserCoupon(engine *xorm.Engine, mallCouponScheme model.MallCouponScheme, uid int) error {
user, _ := db.UserFindByID(engine, uid)
var userCoupons []*model.MallUserCoupon
var startTime time.Time
var endTime time.Time
var now = time.Now()
if mallCouponScheme.ValidTimeType == int(enum.MallCouponValidTimeTypeFix) { // 固定日期
startTime = mallCouponScheme.ValidTimeStart
endTime = mallCouponScheme.ValidTimeEnd
} else { // 领取后多少天有效
startTime = now
endTime = now.Add(time.Hour * 24 * time.Duration(mallCouponScheme.ValidDayNum))
}
if mallCouponScheme.LeftNum < 0 {
mallCouponScheme.LeftNum = 0
}
var tmp = make([]map[string]interface{}, 0)
json.Unmarshal([]byte(mallCouponScheme.LvNum), &tmp)
if len(tmp) == 0 {
return nil
}
tmpData := make(map[string]interface{})
for _, v := range tmp {
if zhios_order_relate_utils.AnyToString(v["id"]) == zhios_order_relate_utils.IntToStr(user.Level) {
tmpData = v
}
}
perUserNum := zhios_order_relate_utils.StrToInt(zhios_order_relate_utils.AnyToString(tmpData["count"]))
leftNum := mallCouponScheme.LeftNum - perUserNum
if leftNum < 0 {
perUserNum = mallCouponScheme.LeftNum
}
for i := 0; i < perUserNum; i++ {
var userCoupon = &model.MallUserCoupon{
Uid: uid,
SchemeId: mallCouponScheme.Id,
IsUse: 0,
Kind: zhios_order_relate_utils.StrToInt(zhios_order_relate_utils.AnyToString(tmpData["kind"])),
Cal: zhios_order_relate_utils.SerializeStr(tmpData["cal"]),
ValidTimeStart: startTime,
ValidTimeEnd: endTime,
UseRule: mallCouponScheme.UseRule,
UseActivityType: mallCouponScheme.UseActivityType,
CreateTime: now,
UpdateTime: now,
}
userCoupons = append(userCoupons, userCoupon)
}
if len(userCoupons) == 0 {
return nil
}
_, err := engine.Table("mall_user_coupon").Insert(&userCoupons)
if err != nil {
return err
}
mallCouponScheme.LeftNum = leftNum
engine.Where("id=?", mallCouponScheme.Id).Cols("left_num").Update(&mallCouponScheme)
return nil
}

Carregando…
Cancelar
Guardar