瀏覽代碼

test

tags/v1.0.5
huangjiajun 1 年之前
父節點
當前提交
a61c19fb15
共有 13 個文件被更改,包括 268 次插入1 次删除
  1. +9
    -0
      db/db.go
  2. +58
    -0
      db/db_day_luck_draw_order_jackpot.go
  3. +30
    -0
      db/db_day_luck_draw_period.go
  4. +24
    -0
      db/db_day_luck_draw_period_reward.go
  5. +14
    -1
      db/db_day_luck_draw_setting.go
  6. +1
    -0
      db/model/day_luck_draw_setting.go
  7. +16
    -0
      md/cfg_app.go
  8. +10
    -0
      md/day_luck_draw_order_jackpot.go
  9. +6
    -0
      md/day_luck_draw_period.go
  10. +7
    -0
      md/day_luck_draw_period_reward.go
  11. +7
    -0
      md/day_luck_draw_setting.go
  12. +28
    -0
      svc/svc_day_luck_draw_order_jackpot.go
  13. +58
    -0
      svc/svc_day_luck_draw_reward.go

+ 9
- 0
db/db.go 查看文件

@@ -0,0 +1,9 @@
package db

import "xorm.io/xorm"

// QueryNativeString 查询原生sql
func QueryNativeStringSess(sess *xorm.Session, sql string, args ...interface{}) ([]map[string]string, error) {
results, err := sess.SQL(sql, args...).QueryString()
return results, err
}

+ 58
- 0
db/db_day_luck_draw_order_jackpot.go 查看文件

@@ -0,0 +1,58 @@
package db

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/db/model"
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/md"
zhios_day_luck_draw_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/utils"
"errors"
"time"
"xorm.io/xorm"
)

func AddOrderJackpot(eg *xorm.Engine, req md.DayLuckDrawOrderJackpotReq) error {
count, _ := eg.Where("oid=? and uid=? and pvd=?", req.Oid, req.Uid, req.Pvd).Count(&model.DayLuckDrawOrderJackpot{})
if count > 0 {
return nil
}
var data = &model.DayLuckDrawOrderJackpot{
Oid: req.Oid,
Pvd: req.Pvd,
Amount: req.Amount,
Commission: req.Commission,
Reward: req.Reward,
Uid: zhios_day_luck_draw_utils.StrToInt(req.Uid),
CreateTime: time.Now(),
}
one, err := eg.InsertOne(data)
if one == 0 {
return errors.New("失败")
}
if err != nil {
return err
}
return nil
}

/***
1.创建期数
2.获取还没分配的金额 就是 期数为0的
3.把期数设置到订单
4.查出所有订单号
5.随机出订单号(每个名额随机一次 如果重复再次循环) 先按一等奖分
*/

func GetAllOrderSum(sess *xorm.Session) float64 {
sum, _ := sess.Where("period=0").Sum(&model.DayLuckDrawOrderJackpot{}, "reward")
return sum
}
func GetAllOrderOid(sess *xorm.Session) []string {
sql := `SELECT oid,uid FROM day_luck_draw_order_jackpot where period=0;`
data, _ := QueryNativeStringSess(sess, sql)
var list = make([]string, 0)
if len(data) > 0 {
for _, v := range data {
list = append(list, v["uid"])
}
}
return list
}

+ 30
- 0
db/db_day_luck_draw_period.go 查看文件

@@ -0,0 +1,30 @@
package db

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/db/model"
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/md"
zhios_day_luck_draw_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/utils"
"time"
"xorm.io/xorm"
)

func AddPeriod(sess *xorm.Session, req md.DayLuckDrawPeriodReq) bool {
var data = &model.DayLuckDrawPeriod{
Reward: req.Reward,
CreateTime: time.Now(),
Period: zhios_day_luck_draw_utils.StrToInt(req.Period),
}
insert, err := sess.Insert(data)
if insert == 0 || err != nil {
return false
}
return true
}
func GetPeriodMax(sess *xorm.Session) *model.DayLuckDrawPeriod {
var data model.DayLuckDrawPeriod
get, err := sess.Desc("period").Get(&data)
if get == false || err != nil {
return nil
}
return &data
}

+ 24
- 0
db/db_day_luck_draw_period_reward.go 查看文件

@@ -4,9 +4,33 @@ import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/db/model"
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/md"
zhios_day_luck_draw_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/utils"
"errors"
"time"
"xorm.io/xorm"
)

func AddPeriodReward(eg *xorm.Engine, req md.DayLuckDrawRewardReq) error {
count, _ := eg.Where("uid=? and period=?", req.Uid, req.Period).Count(&model.DayLuckDrawPeriodReward{})
if count > 0 {
return nil
}
var data = &model.DayLuckDrawPeriodReward{
Reward: req.Reward,
Uid: zhios_day_luck_draw_utils.StrToInt(req.Uid),
CreateTime: time.Now(),
Period: zhios_day_luck_draw_utils.StrToInt(req.Period),
Lv: zhios_day_luck_draw_utils.StrToInt(req.Lv),
}
one, err := eg.InsertOne(data)
if one == 0 {
return errors.New("失败")
}
if err != nil {
return err
}
return nil
}

func GetDayLuckDrawPeriodRewardList(Db *xorm.Engine, parameter *md.DayLuckDrawPeriodRewardRequest) ([]*model.DayLuckDrawPeriodReward, int, error) {
var list []*model.DayLuckDrawPeriodReward
count := DayLuckDrawPeriodRewardGetCount(Db, parameter)


+ 14
- 1
db/db_day_luck_draw_setting.go 查看文件

@@ -19,7 +19,20 @@ func GetDayLuckDrawSetting(eg *xorm.Engine) *model.DayLuckDrawSetting {
}
return &data
}

func GetDayLuckDrawSettingSess(sess *xorm.Session) *model.DayLuckDrawSetting {
var data model.DayLuckDrawSetting
get, err := sess.Get(&data)
if err != nil {
return nil
}
if get == false {
one, err := sess.InsertOne(&data)
if one == 0 || err != nil {
return nil
}
}
return &data
}
func InsertDayLuckDrawSetting(eg *xorm.Engine, data *model.DayLuckDrawSetting) bool {
if data.Id == 0 {
one, err := eg.InsertOne(data)


+ 1
- 0
db/model/day_luck_draw_setting.go 查看文件

@@ -16,5 +16,6 @@ type DayLuckDrawSetting struct {
CycleDay int `json:"cycle_day" xorm:"default 0 comment('周期') INT(11)"`
AdvUse int `json:"adv_use" xorm:"INT(11)"`
AdvType string `json:"adv_type" xorm:"VARCHAR(255)"`
Amount string `json:"amount" xorm:"VARCHAR(255)"`
RewardData string `json:"reward_data" xorm:"TEXT"`
}

+ 16
- 0
md/cfg_app.go 查看文件

@@ -0,0 +1,16 @@
package md

import "time"

//数据库配置结构体
type DBCfg struct {
Host string `yaml:"host"` //ip及端口
Name string `yaml:"name"` //库名
User string `yaml:"user"` //用户
Psw string `yaml:"psw"` //密码
ShowLog bool `yaml:"show_log"` //是否显示SQL语句
MaxLifetime time.Duration `yaml:"max_lifetime"`
MaxOpenConns int `yaml:"max_open_conns"`
MaxIdleConns int `yaml:"max_idle_conns"`
Path string `yaml:"path"` //日志文件存放路径
}

+ 10
- 0
md/day_luck_draw_order_jackpot.go 查看文件

@@ -0,0 +1,10 @@
package md

type DayLuckDrawOrderJackpotReq struct {
Uid string `json:"uid"`
Oid string `json:"oid" `
Pvd string `json:"pvd"`
Amount string `json:"amount"`
Commission string `json:"commission" `
Reward string `json:"reward" `
}

+ 6
- 0
md/day_luck_draw_period.go 查看文件

@@ -0,0 +1,6 @@
package md

type DayLuckDrawPeriodReq struct {
Reward string `json:"reward"`
Period string `json:"period" `
}

+ 7
- 0
md/day_luck_draw_period_reward.go 查看文件

@@ -17,3 +17,10 @@ type DayLuckDrawPeriodRewardOrdList struct {
Period string `json:"period"`
CreateTime string `json:"create_time"`
}

type DayLuckDrawRewardReq struct {
Uid string `json:"uid"`
Period string `json:"period"`
Reward string `json:"reward" `
Lv string `json:"lv"`
}

+ 7
- 0
md/day_luck_draw_setting.go 查看文件

@@ -0,0 +1,7 @@
package md

type RewardData struct {
Key string `json:"key"`
Bili string `json:"bili"`
Num string `json:"num"`
}

+ 28
- 0
svc/svc_day_luck_draw_order_jackpot.go 查看文件

@@ -0,0 +1,28 @@
package svc

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/db"
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/md"
zhios_day_luck_draw_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/utils"
"time"
"xorm.io/xorm"
)

func AddOrderJackpot(eg *xorm.Engine, req md.DayLuckDrawOrderJackpotReq) error {
setting := db.GetDayLuckDrawSetting(eg)
if setting == nil {
return nil
}
now := time.Now().Unix()
if setting.IsUse == 0 || setting.StartTime.IsZero() || setting.EndTime.IsZero() || (now > setting.StartTime.Unix() && now < setting.EndTime.Unix()) {
return nil
}
if setting.OrderSoruce == "mall" && zhios_day_luck_draw_utils.InArr(req.Pvd, []string{"mall_goods", "mall_group_buy", "mall_goods_user_lv", "super_group_buy", "mall_supply", "mall_group_own_buy"}) == false {
return nil
}
err := db.AddOrderJackpot(eg, req)
if err != nil {
return err
}
return nil
}

+ 58
- 0
svc/svc_day_luck_draw_reward.go 查看文件

@@ -0,0 +1,58 @@
package svc

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/db"
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/md"
zhios_day_luck_draw_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/utils"
"encoding/json"
"math/rand"
"time"
"xorm.io/xorm"
)

//随机几个用户
func RandUser(sess *xorm.Session) []string {
var newOid = make([]string, 0)

setting := db.GetDayLuckDrawSettingSess(sess)
if setting == nil {
return newOid
}
now := time.Now().Unix()
if setting.IsUse == 0 || setting.StartTime.IsZero() || setting.EndTime.IsZero() || (now > setting.StartTime.Unix() && now < setting.EndTime.Unix()) {
return newOid
}
count := 0
var rewardData = make([]md.RewardData, 0)
err := json.Unmarshal([]byte(setting.RewardData), &rewardData)
if err == nil {
for _, v := range rewardData {
count += zhios_day_luck_draw_utils.StrToInt(v.Num)
}
}
if count > 0 {
oids := db.GetAllOrderOid(sess)
newOid = MicsSlice(oids, count)
return newOid
}
return newOid

}
func MicsSlice(origin []string, count int) []string {
tmpOrigin := make([]string, len(origin))
copy(tmpOrigin, origin)
//一定要seed
rand.Seed(time.Now().Unix())
rand.Shuffle(len(tmpOrigin), func(i int, j int) {
tmpOrigin[i], tmpOrigin[j] = tmpOrigin[j], tmpOrigin[i]
})

result := make([]string, 0, count)
for index, value := range tmpOrigin {
if index == count {
break
}
result = append(result, value)
}
return result
}

Loading…
取消
儲存