Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"api_test.go",
"dao_test.go",
"redis_test.go",
"task_test.go",
],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/interface/main/creative/conf:go_default_library",
"//app/interface/main/creative/model/newcomer:go_default_library",
"//library/ecode:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
"//vendor/gopkg.in/h2non/gock.v1:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"api.go",
"dao.go",
"redis.go",
"task.go",
],
importpath = "go-common/app/interface/main/creative/dao/newcomer",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/creative/conf:go_default_library",
"//app/interface/main/creative/dao/tool:go_default_library",
"//app/interface/main/creative/model/newcomer:go_default_library",
"//library/cache/redis:go_default_library",
"//library/database/sql:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/xstr:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,247 @@
package newcomer
import (
"context"
"encoding/json"
"errors"
"net/http"
"net/url"
"strconv"
"strings"
"time"
"fmt"
"go-common/app/interface/main/creative/conf"
"go-common/app/interface/main/creative/dao/tool"
"go-common/library/ecode"
"go-common/library/log"
"go-common/library/xstr"
"math/rand"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
// Mall receive mall coupon code.
func (d *Dao) Mall(c context.Context, mid int64, couponID, uname string) (err error) {
type params struct {
MID int64 `json:"mid"`
CouponID string `json:"couponId"`
Uname string `json:"uname"`
}
p := params{}
p.MID = mid
p.CouponID = couponID //优惠券id
p.Uname = uname //抱团购类型 uname必传
paramJSON, err := json.Marshal(p)
if err != nil {
log.Error("Mall json.Marshal param(%+v) error(%v)", p, err)
return
}
paramStr := string(paramJSON)
var (
req *http.Request
)
if req, err = http.NewRequest("POST", d.mallURI, strings.NewReader(paramStr)); err != nil {
log.Error("Mall http.NewRequest url(%s) error(%v)", d.mallURI+"?"+paramStr, err)
err = ecode.CreativeNewcomerMallAPIErr
return
}
log.Info("Mall url(%s)", d.mallURI+"?"+paramStr)
req.Header.Set("Content-Type", "application/json")
var res struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
if err = d.client.Do(c, req, &res); err != nil {
log.Error("Mall d.client.Do url(%s) res(%v) err(%v)", d.mallURI+"?"+paramStr, res, err)
err = ecode.CreativeNewcomerMallAPIErr
return
}
if res.Code != 0 {
log.Error("Mall url(%s) res(%v)", d.mallURI+"?"+paramStr, res)
err = ecode.Int(res.Code)
}
return
}
// BCoin receive b coin.
func (d *Dao) BCoin(c context.Context, mid int64, activityID string, money int64) (err error) {
var (
req *http.Request
params = url.Values{}
)
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("activity_id", activityID) //活动券id uat-217 pre-266
params.Set("money", strconv.FormatInt(money, 10)) //decimal 类型 领取的数量,最大保留两位小数
params.Set("appkey", conf.Conf.App.Key)
params.Set("appsecret", conf.Conf.App.Secret)
params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
var (
query, _ = tool.Sign(params)
mallURL = d.bPayURI
)
log.Info("BCoin url(%s)", mallURL+"?"+query)
if req, err = http.NewRequest("POST", mallURL, strings.NewReader(params.Encode())); err != nil {
log.Error("BCoin url(%s) error(%v)", mallURL, err)
err = ecode.CreativeNewcomerBCoinAPIErr
return
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
var res struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
if err = d.client.Do(c, req, &res); err != nil {
log.Error("BCoin d.client.Do url(%s) res(%+v) err(%v)", mallURL, res, err)
err = ecode.CreativeNewcomerBCoinAPIErr
return
}
if res.Code != 0 {
log.Error("BCoin url(%s) res(%+v)", d.bPayURI+"?"+params.Encode(), res)
err = ecode.Int(res.Code)
}
return
}
// Pendant receive pendant.
func (d *Dao) Pendant(c context.Context, mid int64, priceID string, expires int64) (err error) {
var (
req *http.Request
params = url.Values{}
)
pid, err := strconv.ParseInt(priceID, 10, 64)
if err != nil {
return
}
params.Set("mids", strconv.FormatInt(mid, 10))
params.Set("pid", strconv.FormatInt(pid, 10)) //挂件ID
params.Set("expire", strconv.FormatInt(expires, 10)) //有效期(单位:天)
params.Set("appkey", conf.Conf.App.Key)
params.Set("appsecret", conf.Conf.App.Secret)
params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
var (
query, _ = tool.Sign(params)
pendURL = d.pendantURI
)
log.Info("Pendant url(%s)", pendURL+"?"+query)
if req, err = http.NewRequest("POST", pendURL, strings.NewReader(params.Encode())); err != nil {
log.Error("Pendant url(%s) error(%v)", pendURL, err)
err = ecode.CreativeNewcomerPendantAPIErr
return
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
var res struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
if err = d.client.Do(c, req, &res); err != nil {
log.Error("Pendant d.client.Do url(%s) res(%+v) err(%v)", pendURL, res, err)
err = ecode.CreativeNewcomerPendantAPIErr
return
}
if res.Code != 0 {
log.Error("Pendant url(%s) res(%v)", pendURL, res)
err = ecode.Int(res.Code)
}
return
}
// BigMemberCoupon receive Coupon
func (d *Dao) BigMemberCoupon(c context.Context, mid int64, batchToken string) (err error) {
var (
req *http.Request
params = url.Values{}
)
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("batch_token", batchToken) //资源批次需提前申请,金额固定,不允许更改
params.Set("order_no", genOrderNO(mid)) //每次领取的订单号不允许重复同一订单同一业务方AppKey只允许领取一次
params.Set("appkey", conf.Conf.App.Key)
params.Set("appsecret", conf.Conf.App.Secret)
params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
var (
query, _ = tool.Sign(params)
bigMemberURL = d.bigMemberURI
)
log.Info("BigMemberCoupon url(%s)", bigMemberURL+"?"+query)
if req, err = http.NewRequest("POST", bigMemberURL, strings.NewReader(params.Encode())); err != nil {
log.Error("BigMemberCoupon url(%s) error(%v)", bigMemberURL, err)
err = ecode.CreativeNewcomerBigMemberErr
return
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
var res struct {
Code int `json:"code"`
Msg string `json:"message"`
Data string `json:"data"`
}
if err = d.client.Do(c, req, &res); err != nil {
log.Error("BigMemberCoupon d.client.Do url(%s) res(%+v) err(%v)", bigMemberURL, res, err)
err = ecode.CreativeNewcomerBigMemberErr
return
}
if res.Code != 0 {
log.Error("BigMemberCoupon url(%s) res(%v)", bigMemberURL, res)
err = ecode.Int(res.Code)
}
return
}
// generate orderNo
func genOrderNO(mid int64) string {
s := fmt.Sprintf("%v%s", mid, time.Now().Format("20060102150405"))
if len(s) >= 32 {
return s[0:32]
}
size := 32 - len(s)
bys := make([]byte, size)
for i := 0; i < size; i++ {
bys[i] = uint8(48 + rand.Intn(10))
}
return s + string(bys)
}
// SendNotify send msg notify user
func (d *Dao) SendNotify(c context.Context, mids []int64, mc, title, context string) (err error) {
var (
params = url.Values{}
res struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data *struct {
TotalCount int `json:"total_count"`
ErrorCount int `json:"error_count"`
ErrorMidList []int64 `json:"error_mid_list"`
} `json:"data"`
}
)
params.Set("mc", mc) //消息码,用于识别消息类别
params.Set("data_type", "4") //消息类型1、回复我的 2、@我 3、收到的爱 4、业务通知 5、系统公告
params.Set("title", title) //消息标题
params.Set("context", context) //消息实体内容
params.Set("mid_list", xstr.JoinInts(mids)) //用于接收该消息的用户mid列表不超过1000个(半角逗号分割)
log.Info("SendNotify params(%+v)|msgURI(%s)", params.Encode(), d.msgNotifyURI)
if err = d.client.Post(c, d.msgNotifyURI, "", params, &res); err != nil {
log.Error("d.httpClient.Post(%s,%v,%d)", d.msgNotifyURI, params, err)
return
}
if res.Code != 0 {
err = errors.New("code != 0")
log.Error("d.httpClient.Post(%s,%v,%v,%d)", d.msgNotifyURI, params, err, res.Code)
}
if res.Data != nil {
log.Info("SendNotify log total_count(%d) error_count(%d) error_mid_list(%v)", res.Data.TotalCount, res.Data.ErrorCount, res.Data.ErrorMidList)
}
return
}

View File

@@ -0,0 +1,107 @@
package newcomer
import (
"context"
"go-common/library/ecode"
"testing"
"strings"
"github.com/smartystreets/goconvey/convey"
"gopkg.in/h2non/gock.v1"
)
func TestNewcomerMall(t *testing.T) {
var (
c = context.Background()
mid = int64(27515308)
couponID = "ef89b24b3951429b"
uname = "test"
)
convey.Convey("Mall", t, func(ctx convey.C) {
defer gock.OffAll()
httpMock("POST", d.mallURI).Reply(200).JSON(`{"code":20062}`)
err := d.Mall(c, mid, couponID, uname)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
}
func TestNewcomerBCoin(t *testing.T) {
var (
c = context.Background()
mid = int64(27515406)
money = int64(1)
aid = "217"
)
convey.Convey("BCoin", t, func(ctx convey.C) {
defer gock.OffAll()
httpMock("POST", d.bPayURI).Reply(200).JSON(`{"code":20063}`)
err := d.BCoin(c, mid, aid, money)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
}
func TestNewcomerPendant(t *testing.T) {
var (
c = context.Background()
mid = int64(27515406)
PID = "4"
expires = int64(1)
err error
)
convey.Convey("Pendant", t, func(ctx convey.C) {
defer gock.OffAll()
httpMock("POST", d.pendantURI).Reply(200).JSON(`{"code":20064}`)
err = d.Pendant(c, mid, PID, expires)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
ctx.So(err, convey.ShouldEqual, ecode.CreativeNewcomerPendantAPIErr)
})
})
}
func TestNewcomerBigMemberCoupon(t *testing.T) {
var (
c = context.Background()
mid = int64(27515308)
batchToken = "841764801720181030122848"
)
convey.Convey("BigMemberCoupon", t, func(ctx convey.C) {
defer gock.OffAll()
httpMock("POST", d.bigMemberURI).Reply(200).JSON(`{"code":20069}`)
err := d.BigMemberCoupon(c, mid, batchToken)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
}
func httpMock(method, url string) *gock.Request {
r := gock.New(url)
r.Method = strings.ToUpper(method)
d.client.SetTransport(gock.DefaultTransport)
return r
}
func TestNewcomerSendNotify(t *testing.T) {
convey.Convey("SendNotify", t, func(ctx convey.C) {
var (
c = context.Background()
mids = []int64{27515405}
mc = "1_17_4"
title = "creative"
context = "sssss"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.SendNotify(c, mids, mc, title, context)
ctx.Convey("Then err should be nil.msg should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldEqual, err)
})
})
})
}

View File

@@ -0,0 +1,77 @@
package newcomer
import (
"context"
"go-common/app/interface/main/creative/conf"
"go-common/library/cache/redis"
"go-common/library/database/sql"
"go-common/library/log"
httpx "go-common/library/net/http/blademaster"
)
// Dao define
type Dao struct {
c *conf.Config
db *sql.DB
// http
client *httpx.Client
mallURI string
bPayURI string
pendantURI string
bigMemberURI string
msgNotifyURI string
// redis
redis *redis.Pool
}
const (
_mall = "/mall-marketing/coupon_code/create" //会员购
_bpay = "/api/coupon/add" //B币券
_pendant = "/x/internal/pendant/multiGrantByMid" //挂件:批量发放挂件(多个MID对应一个挂件)
_bigmember = "/x/internal/coupon/allowance/receive" //大会员代金券
_notify = "/api/notify/send.user.notify.do" //发送用户通知消息接口
)
// New init dao
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
db: sql.NewMySQL(c.DB.Creative),
client: httpx.NewClient(c.HTTPClient.Slow),
mallURI: c.Host.Mall + _mall,
bPayURI: c.Host.BPay + _bpay,
pendantURI: c.Host.Pendant + _pendant,
bigMemberURI: c.Host.BigMember + _bigmember,
msgNotifyURI: c.Host.Notify + _notify,
redis: redis.NewPool(c.Redis.Cover.Config),
}
return
}
// Ping db
func (d *Dao) Ping(c context.Context) (err error) {
if d.db != nil {
d.db.Ping(c)
}
if d.redis != nil {
conn := d.redis.Get(c)
if _, err = conn.Do("SET", "ping", "pong"); err != nil {
log.Error("conn.Do(SET) error(%v)", err)
}
conn.Close()
}
return
}
// Close db
func (d *Dao) Close() (err error) {
if d.db != nil {
d.db.Close()
}
if d.redis != nil {
d.redis.Close()
}
return
}

View File

@@ -0,0 +1,34 @@
package newcomer
import (
"flag"
"go-common/app/interface/main/creative/conf"
"os"
"testing"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.creative")
flag.Set("conf_token", "96b6a6c10bb311e894c14a552f48fef8")
flag.Set("tree_id", "2305")
flag.Set("conf_version", "docker-1")
flag.Set("deploy_env", "uat")
flag.Set("conf_host", "config.bilibili.co")
flag.Set("conf_path", "/tmp")
flag.Set("region", "sh")
flag.Set("zone", "sh001")
} else {
flag.Set("conf", "../../cmd/creative.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,43 @@
package newcomer
import (
"context"
"fmt"
"go-common/library/log"
)
const (
_preLock = "creative_task_"
)
func lockKey(key string) string {
return fmt.Sprintf("%s%s", _preLock, key)
}
//Lock .
func (d *Dao) Lock(ctx context.Context, key string, ttl int) (gotLock bool, err error) {
var lockValue = "1"
conn := d.redis.Get(ctx)
defer conn.Close()
realKey := lockKey(key)
var res interface{}
//ttl 毫秒(PX) NX 其实就是 SetNX功能
res, err = conn.Do("SET", realKey, lockValue, "PX", ttl, "NX")
if err != nil {
log.Error("receive_lock failed:%s:%s", realKey, err.Error())
return
}
if res != nil {
gotLock = true
}
return
}
//UnLock .
func (d *Dao) UnLock(ctx context.Context, key string) (err error) {
realKey := lockKey(key)
conn := d.redis.Get(ctx)
defer conn.Close()
_, err = conn.Do("DEL", realKey)
return
}

View File

@@ -0,0 +1,36 @@
package newcomer
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestNewcomerLock(t *testing.T) {
var (
c = context.TODO()
key = ""
ttl = int(1)
)
convey.Convey("Lock", t, func(ctx convey.C) {
gotLock, err := d.Lock(c, key, ttl)
ctx.Convey("Then err should be nil.gotLock should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(gotLock, convey.ShouldNotBeNil)
})
})
}
func TestNewcomerUnLock(t *testing.T) {
var (
c = context.TODO()
key = ""
)
convey.Convey("UnLock", t, func(ctx convey.C) {
err := d.UnLock(c, key)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,572 @@
package newcomer
import (
"context"
"fmt"
"database/sql"
"go-common/app/interface/main/creative/model/newcomer"
"go-common/library/log"
"go-common/library/xstr"
"strings"
)
const (
// select
_getUserTaskBindSQL = "SELECT count(id) FROM newcomers_task_user_%s WHERE mid=?"
_getGiftRewardSQL = "SELECT reward_id FROM newcomers_gift_reward WHERE state=0 AND task_type=?"
_getTaskGroupRewardSQL = "SELECT reward_id FROM newcomers_grouptask_reward WHERE state=0 AND task_group_id=?"
_getIsReceivedSQL = "SELECT count(id) FROM newcomers_reward_receive WHERE mid=?"
_getRewardReceiveStateSQL = "SELECT task_group_id FROM newcomers_reward_receive WHERE mid=?"
_getRewardReceiveSQL = "SELECT id, mid, task_gift_id, task_group_id, reward_id, reward_type, state, receive_time, ctime, mtime FROM newcomers_reward_receive WHERE mid=? AND state IN (0,1,2) ORDER BY receive_time ASC"
_getRewardSQL = "SELECT id, parent_id, type, state, is_active, prize_id, prize_unit, expire, name, logo, comment, unlock_logo, name_extra, ctime, mtime FROM newcomers_reward WHERE state=0"
_getUserTaskByMIDSQL = "SELECT id, mid, task_id, task_group_id, task_type, state, task_bind_time, ctime, mtime FROM newcomers_task_user_%s WHERE state=-1 AND mid=?"
_getTaskSQL = "SELECT id, group_id, type, state, target_type, target_value, title, `desc`, comment, ctime, mtime, rank, extra, fan_range, up_time, down_time FROM newcomers_task WHERE state IN (0,1) ORDER BY rank ASC"
_getAllTaskGroupRewardSQL = "SELECT id,task_group_id,reward_id,state,comment,ctime,mtime FROM newcomers_grouptask_reward WHERE state=0"
_getAllGiftRewardSQL = "SELECT id,root_type,task_type,reward_id,state,comment,ctime,mtime FROM newcomers_gift_reward WHERE state=0"
_getUserTaskSQL = "SELECT task_id,state FROM newcomers_task_user_%s WHERE mid=?"
_getRewardReceiveByIDSQL = "SELECT id, mid, task_gift_id, task_group_id, reward_id, reward_type, state, receive_time, ctime, mtime FROM newcomers_reward_receive WHERE mid=? AND id=?"
_getTaskGroupSQL = "SELECT id, rank, state, root_type, type, ctime, mtime FROM newcomers_task_group WHERE state=0"
_getTaskRewardSQL = "SELECT id,task_id,reward_id,state,comment,ctime,mtime FROM newcomers_task_reward WHERE state=0"
_getRewardReceiveByOldInfo = "SELECT id, mid, oid, type, reward_id, reward_type, state, ctime, mtime FROM newcomers_reward_receive_%s WHERE mid=? AND oid=? AND type=? AND reward_id=?"
// insert
// _inRewardReceiveSQL = "INSERT INTO newcomers_reward_receive (mid, task_gift_id, task_group_id, reward_id, reward_type, state, receive_time, ctime, mtime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
// update
_upRewardReceiveSQL = "UPDATE newcomers_reward_receive SET state=? WHERE mid=? AND id=?"
_upRewardReceiveSQL2 = "UPDATE newcomers_reward_receive_%s SET state=? WHERE mid=? AND id=?"
// update
_upUserTaskSQL = "UPDATE newcomers_task_user_%s SET state=? WHERE mid=? AND task_id=?"
)
// getTableName by mid%100
func getTableName(mid int64) string {
return fmt.Sprintf("%02d", mid%100)
}
// UserTaskBind determine if the user has bound the task
func (d *Dao) UserTaskBind(c context.Context, mid int64) (res int64, err error) {
row := d.db.QueryRow(c, fmt.Sprintf(_getUserTaskBindSQL, getTableName(mid)), mid)
if err = row.Scan(&res); err != nil {
log.Error("UserTaskBind d.db.QueryRow error(%v)", err)
return
}
return
}
// IsRewardReceived if the basic reward and the gift award have been received
func (d *Dao) IsRewardReceived(c context.Context, mid int64, rid int64, rewardType int8) (res bool, err error) {
sqlStr := _getIsReceivedSQL
if rewardType == newcomer.RewardGiftType {
sqlStr += fmt.Sprintf(" AND task_gift_id=?")
} else {
sqlStr += fmt.Sprintf(" AND task_group_id=?")
}
row := d.db.QueryRow(c, sqlStr, mid, rid)
count := 0
if err = row.Scan(&count); err != nil {
log.Error("isRewardReceived d.db.Query error(%v)", err)
return
}
if count > 0 {
return true, nil
}
return
}
// RewardReceivedGroup get []task_group_id by []group_id
func (d *Dao) RewardReceivedGroup(c context.Context, mid int64, ids []int64) (res []int, err error) {
if len(ids) == 0 {
return
}
sqlStr := _getRewardReceiveStateSQL
sqlStr += fmt.Sprintf(" AND task_group_id IN (%s)", xstr.JoinInts(ids))
rows, err := d.db.Query(c, sqlStr, mid)
if err != nil {
log.Error("RewardReceivedGroup d.db.Query error(%v)", err)
return
}
defer rows.Close()
res = make([]int, 0)
for rows.Next() {
gid := 0
if err = rows.Scan(&gid); err != nil {
log.Error("RewardReceivedGroup rows.Scan error(%v)", err)
return
}
res = append(res, gid)
}
return
}
// GiftRewards get the rewards of gift by task_type
func (d *Dao) GiftRewards(c context.Context, taskType int8) (res []int64, err error) {
rows, err := d.db.Query(c, _getGiftRewardSQL, taskType)
if err != nil {
log.Error("GiftRewards d.db.Query error(%v)", err)
return
}
defer rows.Close()
res = make([]int64, 0)
for rows.Next() {
var r int64
if err = rows.Scan(&r); err != nil {
log.Error("GiftRewards rows.Scan error(%v)", err)
return
}
res = append(res, r)
}
return
}
// TaskGroupRewards get the rewards of gift by group_id
func (d *Dao) TaskGroupRewards(c context.Context, groupID int64) (res []int64, err error) {
rows, err := d.db.Query(c, _getTaskGroupRewardSQL, groupID)
if err != nil {
log.Error("TaskGroupRewards d.db.Query error(%v)", err)
return
}
defer rows.Close()
res = make([]int64, 0)
for rows.Next() {
var r int64
if err = rows.Scan(&r); err != nil {
log.Error("TaskGroupRewards rows.Scan error(%v)", err)
return
}
res = append(res, r)
}
return
}
// RewardCompleteState judge the completion of the task
func (d *Dao) RewardCompleteState(c context.Context, mid int64, tids []int64) (res int64, err error) {
sqlStr := fmt.Sprintf(_getUserTaskSQL, getTableName(mid))
sqlStr += fmt.Sprintf(" AND task_id IN (%s)", xstr.JoinInts(tids))
rows, err := d.db.Query(c, sqlStr, mid)
if err != nil {
log.Error("RewardCompleteState d.db.Query error(%v)", err)
return
}
defer rows.Close()
res = 0
for rows.Next() {
t := &newcomer.Task{}
if err = rows.Scan(&t.ID, &t.CompleteSate); err != nil {
log.Error("RewardCompleteState rows.Scan error(%v)", err)
return
}
if t.CompleteSate == newcomer.TaskIncomplete {
res++
}
}
return
}
// RewardReceive add reward receive records.
func (d *Dao) RewardReceive(c context.Context, places string, args []interface{}) (int64, error) {
var (
res sql.Result
err error
)
sqlStr := fmt.Sprintf("INSERT INTO newcomers_reward_receive(mid, task_gift_id, task_group_id, reward_id, reward_type, state) VALUES %s", places)
res, err = d.db.Exec(c, sqlStr, args...)
if err != nil {
log.Error("RewardReceive tx.Exec error(%v)", err)
return 0, err
}
return res.LastInsertId()
}
// RewardActivate activate reward.
func (d *Dao) RewardActivate(c context.Context, mid, id int64) (int64, error) {
res, err := d.db.Exec(c, _upRewardReceiveSQL, newcomer.RewardActivatedNotClick, mid, id)
if err != nil {
log.Error("RewardActivate d.db.Exec mid(%d) id(%d) error(%v)", mid, id, err)
return 0, err
}
return res.RowsAffected()
}
//RewardReceives get reward receive by mid.
func (d *Dao) RewardReceives(c context.Context, mid int64) (res map[int8][]*newcomer.RewardReceive, err error) {
rows, err := d.db.Query(c, _getRewardReceiveSQL, mid)
if err != nil {
log.Error("RewardReceives d.db.Query error(%v)", err)
return
}
defer rows.Close()
res = make(map[int8][]*newcomer.RewardReceive)
for rows.Next() {
r := &newcomer.RewardReceive{}
if err = rows.Scan(&r.ID, &r.MID, &r.TaskGiftID, &r.TaskGroupID, &r.RewardID, &r.RewardType, &r.State, &r.ReceiveTime, &r.CTime, &r.MTime); err != nil {
log.Error("RewardReceives rows.Scan error(%v)", err)
return
}
res[r.RewardType] = append(res[r.RewardType], r)
}
return
}
//Rewards get all reward receive.
func (d *Dao) Rewards(c context.Context) (res []*newcomer.Reward, err error) {
rows, err := d.db.Query(c, _getRewardSQL)
if err != nil {
log.Error("Rewards d.db.Query error(%v)", err)
return
}
defer rows.Close()
res = make([]*newcomer.Reward, 0)
for rows.Next() {
r := &newcomer.Reward{}
if err = rows.Scan(&r.ID, &r.ParentID, &r.Type, &r.State, &r.IsActive, &r.PriceID, &r.PrizeUnit, &r.Expire, &r.Name, &r.Logo, &r.Comment, &r.UnlockLogo, &r.NameExtra, &r.CTime, &r.MTime); err != nil {
log.Error("Rewards rows.Scan error(%v)", err)
return
}
res = append(res, r)
}
return
}
// BindTasks user bind tasks
func (d *Dao) BindTasks(c context.Context, mid int64, places string, args []interface{}) (res int64, err error) {
sqlStr := fmt.Sprintf("INSERT INTO newcomers_task_user_%s(mid , task_id , task_group_id , task_type , state) VALUES %s", getTableName(mid), places)
result, err := d.db.Exec(c, sqlStr, args...)
if err != nil {
log.Error("BindTasks d.db.Exec error(%v)", err)
return
}
return result.LastInsertId()
}
// GiftRewardCount get received gift reward count
func (d *Dao) GiftRewardCount(c context.Context, mid int64, ids []int64) (res int64, err error) {
if len(ids) == 0 {
return
}
sqlStr := fmt.Sprintf("SELECT count(DISTINCT task_gift_id) FROM newcomers_reward_receive WHERE mid=? AND task_gift_id IN (%s)", xstr.JoinInts(ids))
row := d.db.QueryRow(c, sqlStr, mid)
err = row.Scan(&res)
if err != nil {
log.Error("GiftRewardCount d.db.QueryRow error(%v)", err)
return
}
return
}
// BaseRewardCount get received base reward count
func (d *Dao) BaseRewardCount(c context.Context, mid int64, ids []int64) (res int64, err error) {
if len(ids) == 0 {
return
}
sqlStr := fmt.Sprintf("SELECT count(DISTINCT task_group_id) FROM newcomers_reward_receive WHERE mid=? AND task_group_id IN (%s)", xstr.JoinInts(ids))
row := d.db.QueryRow(c, sqlStr, mid)
err = row.Scan(&res)
if err != nil {
log.Error("BaseRewardCount d.db.QueryRow error(%v)", err)
return
}
return
}
//Tasks get all task.
func (d *Dao) Tasks(c context.Context) (res []*newcomer.Task, err error) {
rows, err := d.db.Query(c, _getTaskSQL)
if err != nil {
log.Error("Tasks d.db.Query error(%v)", err)
return
}
defer rows.Close()
res = make([]*newcomer.Task, 0)
for rows.Next() {
r := &newcomer.Task{}
if err = rows.Scan(&r.ID, &r.GroupID, &r.Type, &r.State, &r.TargetType, &r.TargetValue, &r.Title, &r.Desc, &r.Comment, &r.CTime, &r.MTime, &r.Rank, &r.Extra, &r.FanRange, &r.UpTime, &r.DownTime); err != nil {
log.Error("Tasks rows.Scan error(%v)", err)
return
}
res = append(res, r)
}
return
}
//UserTasksByMID get user unfinish task by mid.
func (d *Dao) UserTasksByMID(c context.Context, mid int64) (res []*newcomer.UserTask, err error) {
rows, err := d.db.Query(c, fmt.Sprintf(_getUserTaskByMIDSQL, getTableName(mid)), mid)
if err != nil {
log.Error("UserTasksByMID d.db.Query error(%v)", err)
return
}
defer rows.Close()
res = make([]*newcomer.UserTask, 0)
for rows.Next() {
r := &newcomer.UserTask{}
if err = rows.Scan(&r.ID, &r.MID, &r.TaskID, &r.TaskGroupID, &r.TaskType, &r.State, &r.TaskBindTime, &r.CTime, &r.MTime); err != nil {
log.Error("UserTasksByMID rows.Scan error(%v)", err)
return
}
res = append(res, r)
}
return
}
// UpUserTask update user task finish state
func (d *Dao) UpUserTask(c context.Context, mid, tid int64) (int64, error) {
res, err := d.db.Exec(c, fmt.Sprintf(_upUserTaskSQL, getTableName(mid)), 0, mid, tid)
if err != nil {
log.Error("RewardActivate d.db.Exec mid(%d) id(%d) error(%v)", mid, tid, err)
return 0, err
}
return res.RowsAffected()
}
// UserTaskType Determining the type of task that users have
func (d *Dao) UserTaskType(c context.Context, mid int64) (res int8, err error) {
sqlStr := fmt.Sprintf("SELECT count(DISTINCT task_type) FROM newcomers_task_user_%s WHERE mid=?", getTableName(mid))
row := d.db.QueryRow(c, sqlStr, mid)
if err = row.Scan(&res); err != nil {
log.Error("UserTaskType row.Scan(&res) mid(%d)|error(%v)", mid, err)
return
}
return
}
// AllTaskGroupRewards get all TaskGroupRewards for cache
func (d *Dao) AllTaskGroupRewards(c context.Context) (res map[int64][]*newcomer.TaskGroupReward, err error) {
rows, err := d.db.Query(c, _getAllTaskGroupRewardSQL)
if err != nil {
log.Error("AllTaskGroupRewards d.db.Query error(%v)", err)
return
}
defer rows.Close()
res = make(map[int64][]*newcomer.TaskGroupReward)
for rows.Next() {
t := &newcomer.TaskGroupReward{}
if err = rows.Scan(&t.ID, &t.TaskGroupID, &t.RewardID, &t.State, &t.Comment, &t.CTime, &t.MTime); err != nil {
log.Error("AllTaskGroupRewards rows.Scan error(%v)", err)
return
}
res[t.TaskGroupID] = append(res[t.TaskGroupID], t)
}
return
}
// AllGiftRewards get all GiftRewards for cache
func (d *Dao) AllGiftRewards(c context.Context) (res map[int8][]*newcomer.GiftReward, err error) {
rows, err := d.db.Query(c, _getAllGiftRewardSQL)
if err != nil {
log.Error("AllTaskGroupRewards d.db.Query error(%v)", err)
return
}
defer rows.Close()
res = make(map[int8][]*newcomer.GiftReward)
for rows.Next() {
t := &newcomer.GiftReward{}
if err = rows.Scan(&t.ID, &t.RootType, &t.TaskType, &t.RewardID, &t.State, &t.Comment, &t.CTime, &t.MTime); err != nil {
log.Error("AllTaskGroupRewards rows.Scan error(%v)", err)
return
}
res[t.TaskType] = append(res[t.TaskType], t)
}
return
}
// UserTasks get user tasks
func (d *Dao) UserTasks(c context.Context, mid int64) (res []*newcomer.Task, err error) {
sqlStr := fmt.Sprintf(_getUserTaskSQL, getTableName(mid))
rows, err := d.db.Query(c, sqlStr, mid)
if err != nil {
log.Error("UserTasks d.db.Query mid(%d)|error(%v)", mid, err)
return
}
defer rows.Close()
res = make([]*newcomer.Task, 0)
for rows.Next() {
t := &newcomer.Task{}
if err = rows.Scan(&t.ID, &t.CompleteSate); err != nil {
log.Error("UserTasks rows.Scan mid(%d)|error(%v)", mid, err)
return
}
res = append(res, t)
}
return
}
// RewardReceiveByID get rewardReceive by receiveID
func (d *Dao) RewardReceiveByID(c context.Context, mid, receiveID int64) (res *newcomer.RewardReceive, err error) {
row := d.db.QueryRow(c, _getRewardReceiveByIDSQL, mid, receiveID)
res = &newcomer.RewardReceive{}
if err = row.Scan(&res.ID, &res.MID, &res.TaskGiftID, &res.TaskGroupID, &res.RewardID, &res.RewardType, &res.State, &res.ReceiveTime, &res.CTime, &res.MTime); err != nil {
log.Error("RewardIDByReceiveID row.Scan error(%v)", err)
return
}
return
}
// TaskGroups get task-group
func (d *Dao) TaskGroups(c context.Context) (res []*newcomer.TaskGroupEntity, err error) {
rows, err := d.db.Query(c, _getTaskGroupSQL)
if err != nil {
log.Error("TaskGroups d.db.Query error(%v)", err)
return
}
defer rows.Close()
res = make([]*newcomer.TaskGroupEntity, 0)
for rows.Next() {
t := &newcomer.TaskGroupEntity{}
if err = rows.Scan(&t.ID, &t.Rank, &t.State, &t.RootType, &t.Type, &t.CTime, &t.MTime); err != nil {
log.Error("TaskGroups rows.Scan error(%v)", err)
return
}
res = append(res, t)
}
return
}
// TaskRewards get task-rewards
func (d *Dao) TaskRewards(c context.Context) (res map[int64][]*newcomer.TaskRewardEntity, err error) {
rows, err := d.db.Query(c, _getTaskRewardSQL)
if err != nil {
log.Error("TaskRewards d.db.Query error(%v)", err)
return
}
defer rows.Close()
res = make(map[int64][]*newcomer.TaskRewardEntity)
for rows.Next() {
t := &newcomer.TaskRewardEntity{}
if err = rows.Scan(&t.ID, &t.TaskID, &t.RewardID, &t.State, &t.Comment, &t.CTime, &t.MTime); err != nil {
log.Error("TaskRewards rows.Scan error(%v)", err)
return
}
res[t.TaskID] = append(res[t.TaskID], t)
}
return
}
// RewardReceive2 add reward receive records.
func (d *Dao) RewardReceive2(c context.Context, mid int64, rrs []*newcomer.RewardReceive2) (res int64, err error) {
if len(rrs) == 0 {
return 0, nil
}
tx, err := d.db.Begin(c)
if err != nil {
log.Error("RewardReceive2 d.db.Begin mid(%d)|error(%v)", mid, err)
return
}
place := make([]string, 0)
args := make([]interface{}, 0)
for _, v := range rrs {
place = append(place, "(?, ?, ?, ?, ? ,?)")
if v.Type == newcomer.RewardBaseType {
args = append(args, v.MID, 0, v.OID, v.RewardID, v.RewardType, v.State)
} else if v.Type == newcomer.RewardGiftType {
args = append(args, v.MID, v.OID, 0, v.RewardID, v.RewardType, v.State)
}
}
placeStr := strings.Join(place, ",")
sqlStr := fmt.Sprintf("INSERT INTO newcomers_reward_receive(mid, task_gift_id, task_group_id, reward_id, reward_type, state) VALUES %s", placeStr)
_, err = tx.Exec(sqlStr, args...)
if err != nil {
if rollbackErr := tx.Rollback(); rollbackErr != nil {
log.Error("RewardReceive2 tx.Rollback mid(%d)|error(%v)", mid, rollbackErr)
}
log.Error("RewardReceive2 tx.Exec mid(%d)|error(%v)", mid, err)
return
}
// insert to new table
placeNew := make([]string, 0)
argsNew := make([]interface{}, 0)
for _, v := range rrs {
placeNew = append(placeNew, "(?, ?, ?, ?, ? ,?)")
argsNew = append(argsNew, v.MID, v.OID, v.Type, v.RewardID, v.RewardType, v.State)
}
placeStrNew := strings.Join(placeNew, ",")
sqlStrNew := fmt.Sprintf("INSERT INTO newcomers_reward_receive_%s(mid, oid, type, reward_id, reward_type, state) VALUES %s", getTableName(mid), placeStrNew)
result, err := tx.Exec(sqlStrNew, argsNew...)
if err != nil {
if rollbackErr := tx.Rollback(); rollbackErr != nil {
log.Error("RewardReceive2 tx.Rollback mid(%d)|error(%v)", mid, rollbackErr)
}
log.Error("RewardReceive2 tx.Exec mid(%d)|error(%v)", mid, err)
return
}
if err = tx.Commit(); err != nil {
log.Error("RewardReceive2 tx.Commit() mid(%d)|error(%v)", mid, err)
return
}
return result.LastInsertId()
}
// RewardReceiveByOldInfo get rewardReceive2 by old info
func (d *Dao) RewardReceiveByOldInfo(c context.Context, r *newcomer.RewardReceive) (res *newcomer.RewardReceive2, err error) {
sqlStr := fmt.Sprintf(_getRewardReceiveByOldInfo, getTableName(r.MID))
var (
oid int64
ty int8
)
if r.TaskGiftID == 0 && r.TaskGroupID != 0 {
oid = r.TaskGroupID
ty = newcomer.RewardBaseType
} else if r.TaskGroupID == 0 && r.TaskGiftID != 0 {
oid = r.TaskGiftID
ty = newcomer.RewardGiftType
}
row := d.db.QueryRow(c, sqlStr, r.MID, oid, ty, r.RewardID)
res = &newcomer.RewardReceive2{}
if err = row.Scan(&res.ID, &res.MID, &res.OID, &res.Type, &res.RewardID, &res.RewardType, &res.State, &res.CTime, &res.MTime); err != nil {
log.Error("RewardReceiveByOldInfo row.Scan error(%v)", err)
return
}
return
}
// RewardActivate2 activate reward double write
func (d *Dao) RewardActivate2(c context.Context, mid, oid, nid int64) (int64, error) {
tx, err := d.db.Begin(c)
if err != nil {
log.Error("RewardActivate2 d.db.Begin mid(%d)|error(%v)", mid, err)
return 0, err
}
_, err = tx.Exec(_upRewardReceiveSQL, newcomer.RewardActivatedNotClick, mid, oid)
if err != nil {
if rollbackErr := tx.Rollback(); rollbackErr != nil {
log.Error("RewardActivate2 tx.Rollback mid(%d)|error(%v)", mid, rollbackErr)
}
log.Error("RewardActivate2 tx.Exec mid(%d)|error(%v)", mid, err)
return 0, err
}
// update new table
sqlStr := fmt.Sprintf(_upRewardReceiveSQL2, getTableName(mid))
res, err := tx.Exec(sqlStr, newcomer.RewardActivatedNotClick, mid, nid)
if err != nil {
if rollbackErr := tx.Rollback(); rollbackErr != nil {
log.Error("RewardActivate2 tx.Rollback mid(%d)|error(%v)", mid, rollbackErr)
}
log.Error("RewardActivate2 tx.Exec mid(%d)|error(%v)", mid, err)
return 0, err
}
if err = tx.Commit(); err != nil {
log.Error("RewardActivate2 tx.Commit() mid(%d)|error(%v)", mid, err)
return 0, err
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,438 @@
package newcomer
import (
"context"
"testing"
"go-common/app/interface/main/creative/model/newcomer"
"github.com/smartystreets/goconvey/convey"
)
func TestNewcomergetTableName(t *testing.T) {
convey.Convey("getTableName", t, func(ctx convey.C) {
var (
mid = int64(27515308)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := getTableName(mid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerUserTaskBind(t *testing.T) {
convey.Convey("UserTaskBind", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.UserTaskBind(c, mid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerIsRewardReceived(t *testing.T) {
convey.Convey("IsRewardReceived", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
rid = int64(1)
rewardType = int8(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.IsRewardReceived(c, mid, rid, rewardType)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerRewardReceivedGroup(t *testing.T) {
convey.Convey("RewardReceivedGroup", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
ids = []int64{1, 2, 3}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RewardReceivedGroup(c, mid, ids)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerGiftRewards(t *testing.T) {
convey.Convey("GiftRewards", t, func(ctx convey.C) {
var (
c = context.Background()
taskType = int8(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.GiftRewards(c, taskType)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerTaskGroupRewards(t *testing.T) {
convey.Convey("TaskGroupRewards", t, func(ctx convey.C) {
var (
c = context.Background()
groupID = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.TaskGroupRewards(c, groupID)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerRewardCompleteState(t *testing.T) {
convey.Convey("RewardCompleteState", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
tids = []int64{1, 2, 3}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RewardCompleteState(c, mid, tids)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerRewardReceive(t *testing.T) {
convey.Convey("RewardReceive", t, func(ctx convey.C) {
var (
c = context.Background()
places = "(?, ?, ?, ?, ? ,?)"
args = []interface{}{1, 1, 1, 1, 1, 1}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1, err := d.RewardReceive(c, places, args)
ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerRewardActivate(t *testing.T) {
convey.Convey("RewardActivate", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
id = int64(2)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1, err := d.RewardActivate(c, mid, id)
ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerRewardReceives(t *testing.T) {
convey.Convey("RewardReceives", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RewardReceives(c, mid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerRewards(t *testing.T) {
convey.Convey("Rewards", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Rewards(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerGiftRewardCount(t *testing.T) {
convey.Convey("GiftRewardCount", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
ids = []int64{1}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.GiftRewardCount(c, mid, ids)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerBaseRewardCount(t *testing.T) {
convey.Convey("BaseRewardCount", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
ids = []int64{1}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.BaseRewardCount(c, mid, ids)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerTasks(t *testing.T) {
convey.Convey("Tasks", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Tasks(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerUserTasksByMID(t *testing.T) {
convey.Convey("UserTasksByMID", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.UserTasksByMID(c, mid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerUpUserTask(t *testing.T) {
convey.Convey("UpUserTask", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
tid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1, err := d.UpUserTask(c, mid, tid)
ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerUserTaskType(t *testing.T) {
convey.Convey("UserTaskType", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.UserTaskType(c, mid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerAllTaskGroupRewards(t *testing.T) {
convey.Convey("AllTaskGroupRewards", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.AllTaskGroupRewards(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerAllGiftRewards(t *testing.T) {
convey.Convey("AllGiftRewards", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.AllGiftRewards(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerUserTasks(t *testing.T) {
convey.Convey("UserTasks", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.UserTasks(c, mid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerRewardReceiveByID(t *testing.T) {
convey.Convey("RewardReceiveByID", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
rid = int64(2)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RewardReceiveByID(c, mid, rid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerTaskGroups(t *testing.T) {
convey.Convey("TaskGroups", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.TaskGroups(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerTaskRewards(t *testing.T) {
convey.Convey("TaskRewards", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.TaskRewards(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerRewardReceive2(t *testing.T) {
convey.Convey("RewardReceive2", t, func(ctx convey.C) {
var (
c = context.Background()
rrs = make([]*newcomer.RewardReceive2, 0)
mid = int64(27515308)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RewardReceive2(c, mid, rrs)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerRewardReceiveByOldInfo(t *testing.T) {
convey.Convey("RewardReceiveByOldInfo", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
r = &newcomer.RewardReceive{
ID: 2,
MID: mid,
TaskGiftID: 0,
TaskGroupID: 2,
RewardID: 7,
}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RewardReceiveByOldInfo(c, r)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestNewcomerRewardActivate2(t *testing.T) {
convey.Convey("RewardActivate2", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(27515308)
oid = int64(2)
nid = int64(1)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RewardActivate2(c, mid, oid, nid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}