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,92 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"associate_test.go",
"business_test.go",
"coupon_old_test.go",
"coupon_test.go",
"dao_test.go",
"http_test.go",
"memcache_test.go",
"mysql_test.go",
"oldvip_test.go",
"order_test.go",
"push_test.go",
"redis_test.go",
"resource_test.go",
"sync_test.go",
"vip_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/job/main/vip/conf:go_default_library",
"//app/job/main/vip/model:go_default_library",
"//library/database/sql:go_default_library",
"//library/time: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 = [
"associate.go",
"business.go",
"coupon.go",
"coupon_old.go",
"dao.go",
"http.go",
"memcache.go",
"mysql.go",
"oldvip.go",
"order.go",
"push.go",
"redis.go",
"resource.go",
"sync.go",
"vip.go",
],
importpath = "go-common/app/job/main/vip/dao",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/job/main/vip/conf:go_default_library",
"//app/job/main/vip/model:go_default_library",
"//library/cache/memcache: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/stat/prom:go_default_library",
"//library/time:go_default_library",
"//library/xstr:go_default_library",
"//vendor/github.com/google/uuid:go_default_library",
"//vendor/github.com/pkg/errors: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,35 @@
package dao
import (
"context"
"go-common/app/job/main/vip/model"
"go-common/library/database/sql"
"github.com/pkg/errors"
)
const (
_notGrantActOrder = "SELECT id,mid,order_no,product_id,months,panel_type,associate_state,ctime,mtime FROM vip_order_activity_record WHERE associate_state = 0 AND panel_type = ? limit ?;"
)
// NotGrantActOrders not grant activity order.
func (d *Dao) NotGrantActOrders(c context.Context, panelType string, limit int) (res []*model.VipOrderActivityRecord, err error) {
var rows *sql.Rows
if rows, err = d.oldDb.Query(c, _notGrantActOrder, panelType, limit); err != nil {
err = errors.Wrapf(err, "dao associate not grants query (%s,%d)", panelType, limit)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipOrderActivityRecord)
if err = rows.Scan(&r.ID, &r.Mid, &r.OrderNo, &r.ProductID, &r.Months, &r.PanelType, &r.AssociateState, &r.Ctime, &r.Mtime); err != nil {
err = errors.Wrapf(err, "dao associate not grants scan (%s,%d)", panelType, limit)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}

View File

@ -0,0 +1,20 @@
package dao
import (
"context"
"fmt"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
// go test -test.v -test.run TestDaoNotGrantActOrders
func TestDaoNotGrantActOrders(t *testing.T) {
Convey("TestDaoNotGrantActOrders salary coupon", t, func() {
res, err := d.NotGrantActOrders(context.Background(), "ele", 100)
for _, v := range res {
fmt.Println("res:", v)
}
So(err, ShouldBeNil)
})
}

View File

@ -0,0 +1,470 @@
package dao
import (
"bytes"
"context"
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"sort"
"strconv"
"strings"
xtime "time"
"go-common/app/job/main/vip/model"
"go-common/library/ecode"
"go-common/library/log"
"go-common/library/time"
"go-common/library/xstr"
"github.com/google/uuid"
"github.com/pkg/errors"
)
const (
_cleanCache = "/notify/cleanCache"
_payOrder = "/payplatform/pay/pay"
_message = "/api/notify/send.user.notify.do"
_addBcoin = "/api/coupon/regular/add"
_sendVipbuyTicket = "/mall-marketing/coupon_code/create"
_sendMedal = "/api/nameplate/get/v2"
_pushData = "/x/internal/push-strategy/task/add"
_retry = 3
_minRead = 1024 * 64
_alreadySend = -804
_alreadyGet = -663
_alreadySendVipbuy = 83110005
_ok = 1
//push
appID = 1
)
//PushData http push data
func (d *Dao) PushData(c context.Context, mids []int64, pushData *model.VipPushData, curtime string) (rel *model.VipPushResq, err error) {
var (
pushTime xtime.Time
expireTime xtime.Time
params = url.Values{}
)
rel = new(model.VipPushResq)
if pushTime, err = xtime.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%v %v", curtime, pushData.PushStartTime), xtime.Local); err != nil {
err = errors.WithStack(err)
return
}
if expireTime, err = xtime.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%v %v", curtime, pushData.PushEndTime), xtime.Local); err != nil {
err = errors.WithStack(err)
return
}
page := len(mids) / d.c.Property.SplitPush
if len(mids)%d.c.Property.SplitPush != 0 {
page++
}
for i := 0; i < page; i++ {
startID := i * d.c.Property.SplitPush
endID := (i + 1) * d.c.Property.SplitPush
if endID > len(mids) {
endID = len(mids)
}
tempMids := mids[startID:endID]
params.Set("app_id", fmt.Sprintf("%v", appID))
params.Set("business_id", fmt.Sprintf("%v", d.c.Property.BusinessID))
params.Set("alert_title", pushData.Title)
params.Set("alert_body", pushData.Content)
params.Set("mids", xstr.JoinInts(tempMids))
params.Set("link_type", fmt.Sprintf("%v", pushData.LinkType))
params.Set("link_value", pushData.LinkURL)
params.Set("builds", pushData.Platform)
params.Set("group", pushData.GroupName)
params.Set("uuid", uuid.New().String())
params.Set("push_time", fmt.Sprintf("%v", pushTime.Unix()))
params.Set("expire_time", fmt.Sprintf("%v", expireTime.Unix()))
header := make(map[string]string)
header["Authorization"] = fmt.Sprintf("token=%v", d.c.Property.PushToken)
header["Content-Type"] = "application/x-www-form-urlencoded"
for i := 0; i < _retry; i++ {
if err = d.doNomalSend(c, d.c.URLConf.APICoURL, _pushData, "127.0.0.1", header, params, rel); err != nil {
log.Error("send error(%v) url(%v)", err, d.c.URLConf.APICoURL+_pushData)
return
}
if rel.Code == int64(ecode.OK.Code()) {
log.Info("send url:%v params:%+v return:%+v error(%+v)", d.c.URLConf.APICoURL+_pushData, params, rel, err)
break
}
}
}
return
}
//SendMedal send medal
func (d *Dao) SendMedal(c context.Context, mid, medalID int64) (status int64) {
var (
err error
)
params := url.Values{}
params.Set("mid", fmt.Sprintf("%v", mid))
params.Set("nid", fmt.Sprintf("%v", medalID))
rel := new(struct {
Code int64 `json:"code"`
Data string `json:"data"`
})
defer func() {
if err == nil {
log.Info("send url:%+v params:%+v return:%+v", d.c.URLConf.AccountURL+_sendMedal, params, rel)
}
}()
for i := 0; i < _retry; i++ {
if err = d.client.Get(c, d.c.URLConf.AccountURL+_sendMedal, "127.0.0.1", params, rel); err != nil {
log.Error("send error(%v) url(%v)", err, d.c.URLConf.AccountURL+_sendMedal)
continue
}
if rel.Code == int64(ecode.OK.Code()) || rel.Code == _alreadyGet {
status = 1
if rel.Code == _alreadyGet {
status = 2
}
return
}
}
return
}
//SendVipBuyTicket send vipbuy ticket
func (d *Dao) SendVipBuyTicket(c context.Context, mid int64, couponID string) (status int64) {
var (
err error
)
header := make(map[string]string)
header["Content-Type"] = "application/json"
params := make(map[string]string)
params["mid"] = fmt.Sprintf("%v", mid)
params["couponId"] = fmt.Sprintf("%v", couponID)
for i := 0; i < _retry; i++ {
repl := new(struct {
Code int64 `json:"code"`
Message string `json:"message"`
})
if err = d.doSend(c, d.c.URLConf.MallURL, _sendVipbuyTicket, "127.0.0.1", header, params, repl); err != nil {
log.Error("send vip buy ticket(%+v) error(%+v)", params, err)
continue
}
if repl.Code == int64(ecode.OK.Code()) || repl.Code == _alreadySendVipbuy {
status = 1
if repl.Code == _alreadySendVipbuy {
status = 2
}
return
}
}
return
}
//SendCleanCache clean cache
func (d *Dao) SendCleanCache(c context.Context, hv *model.HandlerVip) (err error) {
params := url.Values{}
params.Set("mid", strconv.FormatInt(int64(hv.Mid), 10))
if err = d.client.Get(c, d.c.VipURI+_cleanCache, "127.0.0.1", params, nil); err != nil {
log.Error("SendCleanCache error(%v) url(%v)", err, d.c.VipURI+_cleanCache)
return
}
return
}
//SendBcoin send bcoin http
func (d *Dao) SendBcoin(c context.Context, mids []int64, money int32, dueTime time.Time, ip string) (err error) {
if len(mids) <= 0 {
return
}
var midStrs []string
for _, v := range mids {
midStrs = append(midStrs, fmt.Sprintf("%v", v))
}
params := url.Values{}
params.Add("activity_id", fmt.Sprintf("%v", d.c.Property.ActivityID))
params.Add("mids", strings.Join(midStrs, ","))
params.Add("money", fmt.Sprintf("%v", money*100))
params.Add("due_time", dueTime.Time().Format("2006-01-02"))
res := new(struct {
Code int64 `json:"code"`
Message string `json:"message"`
TS int64 `json:"ts"`
Data struct {
CouponMoney int64 `json:"coupon_money"`
Status int8 `json:"status"`
} `json:"data"`
})
if err = d.client.Post(c, d.c.URLConf.PayCoURL+_addBcoin, ip, params, res); err != nil {
err = errors.WithStack(err)
return
}
if res.Code == int64(_alreadySend) {
return
}
if int(res.Code) != ecode.OK.Code() {
err = fmt.Errorf("发放B币失败 message: %s mid: %s resp(%+v)", res.Message, strings.Join(midStrs, ","), res)
return
}
if res.Data.Status != _ok {
err = fmt.Errorf("发放B币失败 message: %s mid: %s resp(%+v)", res.Message, strings.Join(midStrs, ","), res)
return
}
log.Info("发放B币成功 mids %v resp(%+v)", mids, res)
return
}
//SendAppCleanCache notice app clean cache
func (d *Dao) SendAppCleanCache(c context.Context, hv *model.HandlerVip, app *model.VipAppInfo) (err error) {
params := url.Values{}
params.Set("modifiedAttr", "updateVip")
params.Set("mid", fmt.Sprintf("%v", hv.Mid))
params.Set("status", fmt.Sprintf("%v", hv.Type))
params.Set("buyMonths", fmt.Sprintf("%v", hv.Months))
params.Set("days", fmt.Sprintf("%v", hv.Days))
if err = d.client.Get(c, app.PurgeURL, "127.0.0.1", params, nil); err != nil {
log.Error("SendAppCleanCache error(%v) url(%v) params(%v)", err, app.PurgeURL, params)
return
}
return
}
//SendMultipMsg send multip msg
func (d *Dao) SendMultipMsg(c context.Context, mids, content, title, mc string, dataType int) (err error) {
params := url.Values{}
params.Set("mc", mc)
params.Set("title", title)
params.Set("context", content)
params.Set("data_type", strconv.FormatInt(int64(dataType), 10))
params.Set("mid_list", mids)
defer func() {
log.Info("SendMultipMsg(%v) params(%+v) error(%+v)", d.c.URLConf.MsgURL+_message, params, err)
}()
if err = d.client.Post(c, d.c.URLConf.MsgURL+_message, "127.0.0.1", params, nil); err != nil {
log.Error("SendMultipMsg params(%+v) error(%v)", err, params)
return
}
log.Info("cur send mid(%+v)", mids)
return
}
// PayOrder pay order.
func (d *Dao) PayOrder(c context.Context, paramsMap map[string]interface{}) (err error) {
params := make(map[string]string)
for k, v := range paramsMap {
params[k] = fmt.Sprintf("%v", v)
}
header := make(map[string]string)
header["Content-Type"] = "application/json"
success := false
for i := 0; i < 3; i++ {
repl := new(struct {
ErrNo int64 `json:"errno"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
})
if err = d.doPaySend(c, d.c.URLConf.PayURL, _payOrder, "127.0.0.1", header, params, repl); err != nil {
continue
}
if repl.ErrNo == 0 {
success = true
break
}
}
if !success {
err = fmt.Errorf("下单失败")
}
return
}
func (d *Dao) sortParamsKey(v map[string]string) string {
if v == nil {
return ""
}
var buf bytes.Buffer
keys := make([]string, 0, len(v))
for k := range v {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
vs := v[k]
prefix := k + "="
if buf.Len() > 0 {
buf.WriteByte('&')
}
buf.WriteString(prefix)
buf.WriteString(vs)
}
return buf.String()
}
//PaySign pay sign
func (d *Dao) PaySign(params map[string]string, token string) (sign string) {
tmp := d.sortParamsKey(params)
var b bytes.Buffer
b.WriteString(tmp)
b.WriteString(fmt.Sprintf("&token=%s", token))
log.Info("sign params:%v ", b.String())
mh := md5.Sum(b.Bytes())
// query
var qb bytes.Buffer
qb.WriteString(tmp)
qb.WriteString("&sign=")
qb.WriteString(hex.EncodeToString(mh[:]))
sign = hex.EncodeToString(mh[:])
log.Info("sign params(%v) and sign(%v)", b.String(), sign)
return
}
func (d *Dao) doNomalSend(c context.Context, basePath, path, ip string, header map[string]string, params url.Values, data interface{}) (err error) {
var (
req *http.Request
client = new(http.Client)
resp *http.Response
bs []byte
marshal string
)
url := basePath + path
if req, err = d.client.NewRequest(http.MethodPost, url, ip, params); err != nil {
err = errors.WithStack(err)
return
}
for k, v := range header {
req.Header.Add(k, v)
}
if resp, err = client.Do(req); err != nil {
log.Error("call url:%v params:%v", basePath+path, string(marshal))
err = errors.WithStack(err)
return
}
defer resp.Body.Close()
defer func() {
log.Info("call url:%v params:(%v) result:(%+v) header:(%+v)", url, string(marshal), data, header)
}()
if resp.StatusCode >= http.StatusBadRequest {
err = errors.Errorf("incorrect http status:%d host:%s, url:%s", resp.StatusCode, req.URL.Host, req.URL.String())
return
}
if bs, err = readAll(resp.Body, _minRead); err != nil {
err = errors.Wrapf(err, "host:%s, url:%s", req.URL.Host, req.URL.String())
return
}
if err = json.Unmarshal(bs, data); err != nil {
err = errors.WithStack(err)
return
}
return
}
func (d *Dao) doSend(c context.Context, basePath, path, IP string, header map[string]string, params map[string]string, data interface{}) (err error) {
var (
req *http.Request
client = new(http.Client)
resp *http.Response
bs []byte
)
url := basePath + path
marshal, _ := json.Marshal(params)
if req, err = http.NewRequest(http.MethodPost, url, strings.NewReader(string(marshal))); err != nil {
err = errors.WithStack(err)
return
}
for k, v := range header {
req.Header.Add(k, v)
}
if resp, err = client.Do(req); err != nil {
log.Error("call url:%v params:%v", basePath+path, string(marshal))
err = errors.WithStack(err)
return
}
defer resp.Body.Close()
defer func() {
log.Info("call url:%v params:(%v) result:(%+v) header:(%+v)", url, string(marshal), data, header)
}()
if resp.StatusCode >= http.StatusBadRequest {
err = errors.Errorf("incorrect http status:%d host:%s, url:%s", resp.StatusCode, req.URL.Host, req.URL.String())
return
}
if bs, err = readAll(resp.Body, _minRead); err != nil {
err = errors.Wrapf(err, "host:%s, url:%s", req.URL.Host, req.URL.String())
return
}
if err = json.Unmarshal(bs, data); err != nil {
err = errors.WithStack(err)
return
}
return
}
func (d *Dao) doPaySend(c context.Context, basePath, path, IP string, header map[string]string, params map[string]string, data interface{}) (err error) {
sign := d.PaySign(params, d.c.PayConf.Token)
params["sign"] = sign
return d.doSend(c, basePath, path, IP, header, params, data)
}
func readAll(r io.Reader, capacity int64) (b []byte, err error) {
buf := bytes.NewBuffer(make([]byte, 0, capacity))
// If the buffer overflows, we will get bytes.ErrTooLarge.
// Return that as an error. Any other panic remains.
defer func() {
e := recover()
if e == nil {
return
}
if panicErr, ok := e.(error); ok && panicErr == bytes.ErrTooLarge {
err = panicErr
} else {
panic(e)
}
}()
_, err = buf.ReadFrom(r)
return buf.Bytes(), err
}
// SalaryCoupon salary coupon.
func (d *Dao) SalaryCoupon(c context.Context, mid int64, couponType int8, count int64, token string) (err error) {
params := url.Values{}
params.Set("mid", fmt.Sprintf("%d", mid))
params.Set("type", fmt.Sprintf("%d", couponType))
params.Set("count", fmt.Sprintf("%d", count))
params.Set("batch_no", token)
var resp struct {
Code int64 `json:"code"`
}
if err = d.client.Post(c, d.c.Property.SalaryCouponURL, "", params, &resp); err != nil {
log.Error("message url(%s) error(%v)", d.c.Property.SalaryCouponURL+"?"+params.Encode(), err)
return
}
if resp.Code != 0 {
err = fmt.Errorf("POST SalaryCoupon url resp(%v)", resp)
return
}
return
}

View File

@ -0,0 +1,121 @@
package dao
import (
"context"
"testing"
"time"
"go-common/app/job/main/vip/model"
xtime "go-common/library/time"
"github.com/smartystreets/goconvey/convey"
gock "gopkg.in/h2non/gock.v1"
)
// go test -test.v -test.run TestDaoSalaryCoupon
func TestDaoSalaryCoupon(t *testing.T) {
convey.Convey("TestDaoSalaryCoupon salary coupon", t, func() {
var (
c = context.TODO()
mid int64 = 123
ct int8 = 2
count int64 = 2
err error
)
err = d.SalaryCoupon(c, mid, ct, count, "cartoon_1_2018_06")
convey.So(err, convey.ShouldBeNil)
})
}
func TestDao_SendMultipMsg(t *testing.T) {
convey.Convey("send multipmsg", t, func() {
defer gock.OffAll()
httpMock("POST", _message).Reply(200).JSON(`{"code":0,"data":1}`)
err := d.SendMultipMsg(context.TODO(), "27515256", "test", "test", "10_1_2", 4)
convey.So(err, convey.ShouldBeNil)
})
}
func TestDaoPushData(t *testing.T) {
pushData := &model.VipPushData{
Title: "TEST",
PushStartTime: "15:04:05",
PushEndTime: "15:04:05",
}
convey.Convey("PushData", t, func() {
defer gock.OffAll()
httpMock("POST", _pushData).Reply(200).JSON(`{"code":0,"data":1}`)
rel, err := d.PushData(context.TODO(), []int64{7593623}, pushData, "2006-01-02")
convey.So(err, convey.ShouldBeNil)
convey.So(rel, convey.ShouldNotBeNil)
})
}
func TestDaoSendMedal(t *testing.T) {
convey.Convey("SendMedal", t, func() {
defer gock.OffAll()
httpMock("GET", _sendMedal).Reply(200).JSON(`{"code":0,"data":{"status":1}}`)
status := d.SendMedal(context.TODO(), 0, 0)
convey.So(status, convey.ShouldNotBeNil)
})
}
func TestDaoSendCleanCache(t *testing.T) {
hv := &model.HandlerVip{Mid: 7593623}
convey.Convey("SendCleanCache", t, func() {
defer gock.OffAll()
httpMock("GET", _cleanCache).Reply(200).JSON(`{"code":0,"data":{"status":1}}`)
err := d.SendCleanCache(context.TODO(), hv)
convey.So(err, convey.ShouldBeNil)
})
}
func TestDaoSendBcoin(t *testing.T) {
convey.Convey("SendBcoin", t, func() {
defer gock.OffAll()
httpMock("POST", _addBcoin).Reply(200).JSON(`{"code":0,"data":{"status":1}}`)
err := d.SendBcoin(context.TODO(), []int64{7593623}, 0, xtime.Time(time.Now().Unix()), "")
convey.So(err, convey.ShouldBeNil)
})
}
func TestDaoSendAppCleanCache(t *testing.T) {
var (
hv = &model.HandlerVip{Mid: 7593623}
app = &model.VipAppInfo{
PurgeURL: "http://bilibili.com/test",
}
)
convey.Convey("SendAppCleanCache", t, func() {
defer gock.OffAll()
httpMock("GET", app.PurgeURL).Reply(200).JSON(`{"code":0}`)
err := d.SendAppCleanCache(context.TODO(), hv, app)
convey.So(err, convey.ShouldBeNil)
})
}
func TestDaosortParamsKey(t *testing.T) {
var v map[string]string
convey.Convey("sortParamsKey", t, func() {
p1 := d.sortParamsKey(v)
convey.So(p1, convey.ShouldNotBeNil)
})
}
func TestDaoPaySign(t *testing.T) {
var params map[string]string
convey.Convey("PaySign", t, func() {
sign := d.PaySign(params, "test")
convey.So(sign, convey.ShouldNotBeNil)
})
}
func TestDaodoNomalSend(t *testing.T) {
var path = "/x/internal/vip/user/info"
convey.Convey("doNomalSend", t, func() {
defer gock.OffAll()
httpMock("POST", path).Reply(200).JSON(`{"code":0}`)
err := d.doNomalSend(context.TODO(), "http://api.bilibili.com", path, "", nil, nil, new(model.VipPushResq))
convey.So(err, convey.ShouldBeNil)
})
}

View File

@ -0,0 +1,46 @@
package dao
import (
"context"
"fmt"
"go-common/app/job/main/vip/model"
"go-common/library/database/sql"
"github.com/pkg/errors"
)
const (
_SelSalaryVideoCoupon = "SELECT `id`,`mid`,`coupon_count`,`coupon_type`,`state`,`type`,`ver` FROM `vip_view_coupon_salary_log_%s` WHERE `mid` = ?;"
_addSalaryLogSQL = "INSERT INTO `vip_view_coupon_salary_log_%s`(`mid`,`coupon_count`,`coupon_type`,`state`,`type`)VALUES(?,?,?,?,?);"
)
//SalaryVideoCouponList select salary video coupon list.
func (d *Dao) SalaryVideoCouponList(c context.Context, mid int64, dv string) (res []*model.VideoCouponSalaryLog, err error) {
var rows *sql.Rows
if rows, err = d.db.Query(c, fmt.Sprintf(_SelSalaryVideoCoupon, dv), mid); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VideoCouponSalaryLog)
if err = rows.Scan(&r.ID, &r.Mid, &r.CouponCount, &r.CouponType, &r.State, &r.Type, &r.Ver); err != nil {
err = errors.WithStack(err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}
//AddSalaryLog add salary log.
func (d *Dao) AddSalaryLog(c context.Context, l *model.VideoCouponSalaryLog, dv string) (err error) {
if _, err = d.db.Exec(c, fmt.Sprintf(_addSalaryLogSQL, dv), l.Mid, l.CouponCount, l.CouponType, l.State, l.Type); err != nil {
err = errors.WithStack(err)
return
}
return
}

View File

@ -0,0 +1,46 @@
package dao
import (
"context"
"fmt"
"go-common/app/job/main/vip/model"
"go-common/library/database/sql"
"github.com/pkg/errors"
)
const (
_selSalaryMaxID = "SELECT IFNULL(MAX(id),0) id FROM vip_view_coupon_salary_log_%s;"
_selOldSalaryList = "SELECT `mid`,`coupon_count`,`state`,`type` FROM `vip_view_coupon_salary_log_%s` WHERE id>? AND id <=?;"
)
// SalaryLogMaxID select salary log max id.
func (d *Dao) SalaryLogMaxID(c context.Context, dv string) (maxID int, err error) {
var row = d.oldDb.QueryRow(c, fmt.Sprintf(_selSalaryMaxID, dv))
if err = row.Scan(&maxID); err != nil {
err = errors.WithStack(err)
return
}
return
}
//SelOldSalaryList sel old salary list
func (d *Dao) SelOldSalaryList(c context.Context, id, endID int, dv string) (res []*model.OldSalaryLog, err error) {
var rows *sql.Rows
if rows, err = d.oldDb.Query(c, fmt.Sprintf(_selOldSalaryList, dv), id, endID); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.OldSalaryLog)
if err = rows.Scan(&r.Mid, &r.CouponCount, &r.State, &r.Type); err != nil {
err = errors.WithStack(err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}

View File

@ -0,0 +1,41 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoSalaryLogMaxID(t *testing.T) {
convey.Convey("SalaryLogMaxID", t, func(ctx convey.C) {
var (
c = context.Background()
dv = "2018_09"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
maxID, err := d.SalaryLogMaxID(c, dv)
ctx.Convey("Then err should be nil.maxID should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(maxID, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoSelOldSalaryList(t *testing.T) {
convey.Convey("SelOldSalaryList", t, func(ctx convey.C) {
var (
c = context.Background()
id = int(0)
endID = int(0)
dv = "2018_09"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelOldSalaryList(c, id, endID, dv)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@ -0,0 +1,44 @@
package dao
import (
"context"
"go-common/app/job/main/vip/model"
"testing"
"time"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoSalaryVideoCouponList(t *testing.T) {
convey.Convey("SalaryVideoCouponList", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(0)
dv = "2018_09"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SalaryVideoCouponList(c, mid, dv)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoAddSalaryLog(t *testing.T) {
convey.Convey("AddSalaryLog", t, func(ctx convey.C) {
var (
c = context.Background()
l = &model.VideoCouponSalaryLog{
Mid: time.Now().Unix(),
}
dv = "2018_09"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.AddSalaryLog(c, l, dv)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@ -0,0 +1,77 @@
package dao
import (
"context"
"time"
"go-common/app/job/main/vip/conf"
"go-common/library/cache/memcache"
"go-common/library/cache/redis"
"go-common/library/database/sql"
bm "go-common/library/net/http/blademaster"
"go-common/library/stat/prom"
)
// Dao struct info of Dao.
type Dao struct {
// mysql
db *sql.DB
oldDb *sql.DB
// http
client *bm.Client
// conf
c *conf.Config
// memcache
mc *memcache.Pool
mcExpire int32
//redis pool
redis *redis.Pool
redisExpire int32
errProm *prom.Prom
frozenExpire int32
}
// New new a Dao and return.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
// conf
c: c,
// mc
mc: memcache.NewPool(c.Memcache.Config),
mcExpire: int32(time.Duration(c.Memcache.Expire) / time.Second),
// redis
redis: redis.NewPool(c.Redis.Config),
redisExpire: int32(time.Duration(c.Redis.Expire) / time.Second),
// db
db: sql.NewMySQL(c.NewMysql),
oldDb: sql.NewMySQL(c.OldMysql),
// http client
client: bm.NewClient(c.HTTPClient),
errProm: prom.BusinessErrCount,
frozenExpire: int32(time.Duration(c.Property.FrozenExpire) / time.Second),
}
return
}
// Ping ping health of db.
func (d *Dao) Ping(c context.Context) (err error) {
return d.db.Ping(c)
}
// Close close connections of mc, redis, db.
func (d *Dao) Close() {
if d.db != nil {
d.db.Close()
}
if d.redis != nil {
d.redis.Close()
}
}
//StartTx start tx
func (d *Dao) StartTx(c context.Context) (tx *sql.Tx, err error) {
if d.db != nil {
tx, err = d.db.Begin(c)
}
return
}

View File

@ -0,0 +1,45 @@
package dao
import (
"flag"
"os"
"strings"
"testing"
"go-common/app/job/main/vip/conf"
gock "gopkg.in/h2non/gock.v1"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.account.vip-job")
flag.Set("conf_token", "9a445028722910ccf99d501d56c6aea0")
flag.Set("tree_id", "14826")
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/vip-job-test.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
d.client.SetTransport(gock.DefaultTransport)
os.Exit(m.Run())
}
func httpMock(method, url string) *gock.Request {
r := gock.New(url)
r.Method = strings.ToUpper(method)
return r
}

View File

@ -0,0 +1,35 @@
package dao
import (
"context"
"fmt"
"net/url"
"go-common/app/job/main/vip/model"
"go-common/library/log"
"github.com/pkg/errors"
)
const (
_retryAutoRenew = "/x/internal/autorenew/retry"
)
//AutoRenewPay auto renew pay.
func (d *Dao) AutoRenewPay(c context.Context, mid int64) (res *model.CommonResq, err error) {
res = new(model.CommonResq)
val := url.Values{}
val.Add("mid", fmt.Sprintf("%d", mid))
url := d.c.VipURI + _retryAutoRenew
if err = d.client.Post(c, url, "", val, res); err != nil {
log.Error("reques fail url %v params:%+v result:%+v, err:%+v", url, val, res, err)
err = errors.WithStack(err)
return
}
if res.Code != 0 {
log.Error("reques fail url %v params:%+v result:%+v, err:%+v", url, val, res, err)
return
}
log.Info("reques success url %v params:%+v result:%+v", url, val, res)
return
}

View File

@ -0,0 +1,16 @@
package dao
import (
"context"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestDaoAutoRenewPay(t *testing.T) {
Convey("TestDaoAutoRenewPay", t, func() {
res, err := d.AutoRenewPay(context.Background(), 1234)
t.Logf("%+v,%+v", res, err)
So(res, ShouldNotBeNil)
})
}

View File

@ -0,0 +1,213 @@
package dao
import (
"context"
"fmt"
"strconv"
"go-common/app/job/main/vip/model"
"go-common/library/cache/memcache"
"go-common/library/log"
"github.com/pkg/errors"
)
const (
_vipInfo = "vo:%d"
_vipMadel = "madel:%d"
_vipbuy = "vipbuy:%d"
_vipfrozen = "vipfrozen:%d"
madelExpired = 3600 * 24 * 15
vipbuyExpired = 3600 * 24 * 8
vipFrozenExpired = 60 * 30
vipFrozenFlag = 1
_prefixInfo = "i:"
)
func vipfrozen(mid int64) string {
return fmt.Sprintf(_vipfrozen, mid)
}
func vipbuy(mid int64) string {
return fmt.Sprintf(_vipbuy, mid)
}
func vipInfoKey(mid int64) string {
return fmt.Sprintf(_vipInfo, mid)
}
func vipMadel(mid int64) string {
return fmt.Sprintf(_vipMadel, mid)
}
func keyInfo(mid int64) string {
return _prefixInfo + strconv.FormatInt(mid, 10)
}
//SetVipFrozen .
func (d *Dao) SetVipFrozen(c context.Context, mid int64) (err error) {
var (
key = vipfrozen(mid)
)
conn := d.mc.Get(c)
defer conn.Close()
item := &memcache.Item{Key: key, Object: vipFrozenFlag, Expiration: vipFrozenExpired, Flags: memcache.FlagJSON}
if err = conn.Set(item); err != nil {
err = errors.Wrapf(err, "d.setVipFrozen")
d.errProm.Incr("vip frozen_mc")
return
}
return
}
//DelVipFrozen .
func (d *Dao) DelVipFrozen(c context.Context, mid int64) (err error) {
return d.delCache(c, vipfrozen(mid))
}
//SetVipMadelCache set vip madel cache
func (d *Dao) SetVipMadelCache(c context.Context, mid int64, val int64) (err error) {
var (
key = vipMadel(mid)
)
conn := d.mc.Get(c)
defer conn.Close()
item := &memcache.Item{Key: key, Object: val, Expiration: madelExpired, Flags: memcache.FlagJSON}
if err = conn.Set(item); err != nil {
err = errors.Wrap(err, "d.SetVipMadelCache")
d.errProm.Incr("vipmadel_mc")
}
return
}
//GetVipBuyCache get vipbuy cache by key
func (d *Dao) GetVipBuyCache(c context.Context, mid int64) (val int64, err error) {
var (
key = vipbuy(mid)
item *memcache.Item
)
conn := d.mc.Get(c)
defer conn.Close()
if item, err = conn.Get(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
err = errors.Wrapf(err, "conn.Get(%s)", key)
d.errProm.Incr("vipinfo_mc")
return
}
if err = conn.Scan(item, &val); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("vipMadelCache_mc")
}
return
}
//SetVipBuyCache set vipbuy cache
func (d *Dao) SetVipBuyCache(c context.Context, mid int64, val int64) (err error) {
var (
key = vipbuy(mid)
)
conn := d.mc.Get(c)
defer conn.Close()
item := &memcache.Item{Key: key, Object: val, Expiration: vipbuyExpired, Flags: memcache.FlagJSON}
if err = conn.Set(item); err != nil {
err = errors.Wrap(err, "d.SetVipBuyCache")
d.errProm.Incr("vipbuy_mc")
}
return
}
//GetVipMadelCache get madel info by mid
func (d *Dao) GetVipMadelCache(c context.Context, mid int64) (val int64, err error) {
var (
key = vipMadel(mid)
item *memcache.Item
)
conn := d.mc.Get(c)
defer conn.Close()
if item, err = conn.Get(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
err = errors.Wrapf(err, "conn.Get(%s)", key)
d.errProm.Incr("vipinfo_mc")
return
}
if err = conn.Scan(item, &val); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("vipMadelCache_mc")
}
return
}
// SetVipInfoCache set vip info cache.
func (d *Dao) SetVipInfoCache(c context.Context, mid int64, v *model.VipInfo) (err error) {
var (
key = vipInfoKey(mid)
)
conn := d.mc.Get(c)
defer conn.Close()
item := &memcache.Item{Key: key, Object: v, Expiration: d.mcExpire, Flags: memcache.FlagProtobuf}
if err = conn.Set(item); err != nil {
err = errors.Wrap(err, "d.SetVipInfo")
d.errProm.Incr("vipinfo_mc")
}
return
}
// DelVipInfoCache del vip info cache.
func (d *Dao) DelVipInfoCache(c context.Context, mid int64) (err error) {
err = d.delCache(c, vipInfoKey(mid))
return
}
// DelInfoCache del vip info cache.
func (d *Dao) DelInfoCache(c context.Context, mid int64) (err error) {
if err = d.delCache(c, keyInfo(mid)); err != nil {
log.Error("del vipinfo cache(mid:%d) error(%+v)", mid, err)
}
return
}
func (d *Dao) delCache(c context.Context, key string) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
} else {
err = errors.Wrapf(err, "conn.Delete(%s)", key)
d.errProm.Incr("del_mc")
}
}
return
}
// AddTransferLock add lock.
func (d *Dao) AddTransferLock(c context.Context, key string) (succeed bool) {
var (
conn = d.mc.Get(c)
)
defer conn.Close()
item := &memcache.Item{
Key: key,
Value: []byte("0"),
Expiration: 3600,
}
if err := conn.Add(item); err != nil {
if err != memcache.ErrNotStored {
log.Error("conn.Add(%s) error(%v)", key, err)
}
} else {
succeed = true
}
return
}

View File

@ -0,0 +1,74 @@
package dao
import (
"testing"
"context"
"go-common/app/job/main/vip/model"
. "github.com/smartystreets/goconvey/convey"
)
func TestDao_DelVipInfoCache(t *testing.T) {
Convey("should return true where err != nil and res not empty", t, func() {
err := d.DelVipInfoCache(context.TODO(), 1234)
So(err, ShouldBeNil)
})
}
func TestDao_SetVipInfoCache(t *testing.T) {
Convey("set vip info cache", t, func() {
err := d.SetVipInfoCache(context.TODO(), 1234, &model.VipInfo{Mid: 1234, VipType: model.Vip, VipStatus: model.VipStatusNotOverTime})
So(err, ShouldBeNil)
})
}
func TestDao_AddPayOrderLog(t *testing.T) {
Convey("add pay order log", t, func() {
_, err := d.AddPayOrderLog(context.TODO(), &model.VipPayOrderLog{Mid: 1234, Status: 1, OrderNo: "12891723894189"})
So(err, ShouldBeNil)
})
}
func TestDao_GetVipMadelCache(t *testing.T) {
Convey("get vip madel cache ", t, func() {
val, err := d.GetVipMadelCache(context.TODO(), 2089801)
t.Logf("val %v \n", val)
So(err, ShouldBeNil)
})
}
func TestDao_SetVipMadelCache(t *testing.T) {
Convey("set vip madel", t, func() {
err := d.SetVipMadelCache(context.TODO(), 2089801, 1)
So(err, ShouldBeNil)
})
}
func TestDao_SetVipFrozen(t *testing.T) {
Convey("set vip frozen", t, func() {
err := d.SetVipFrozen(context.TODO(), 2089809)
So(err, ShouldBeNil)
})
}
func TestDao_GetVipBuyCache(t *testing.T) {
var val int64 = 1
Convey("SetVipBuyCache", t, func() {
err := d.SetVipBuyCache(context.TODO(), 2089809, val)
So(err, ShouldBeNil)
})
Convey("GetVipBuyCache", t, func() {
res, err := d.GetVipBuyCache(context.TODO(), 2089809)
So(err, ShouldBeNil)
So(val, ShouldEqual, res)
})
}
func TestDao_AddTransferLock(t *testing.T) {
Convey("AddTransferLock", t, func() {
err := d.delCache(context.TODO(), "2089809")
So(err, ShouldBeNil)
bool := d.AddTransferLock(context.TODO(), "2089809")
So(bool, ShouldBeTrue)
})
}

View File

@ -0,0 +1,310 @@
package dao
import (
"context"
"fmt"
"strconv"
"strings"
"go-common/app/job/main/vip/model"
"go-common/library/database/sql"
"go-common/library/log"
"go-common/library/xstr"
"github.com/pkg/errors"
)
const (
_selAppInfo = "SELECT id,name,app_key,purge_url from vip_app_info WHERE `type` = 1"
//bcoin sql
_selBcoinSalarySQL = "SELECT id,mid,status,give_now_status,payday,amount,memo FROM vip_user_bcoin_salary WHERE 1=1"
_selBcoinSalaryDataSQL = "SELECT id,mid,status,give_now_status,payday,amount,memo FROM vip_user_bcoin_salary WHERE id>? AND id<=?"
_selBcoinSalaryByMidSQL = "SELECT id,mid,status,give_now_status,payday,amount,memo FROM vip_user_bcoin_salary WHERE mid IN (%v)"
_selOldBcoinSalaryByMidSQL = "SELECT id,mid,IFNULL(status,0),IFNULL(give_now_status,0),month,IFNULL(amount,0),IFNULL(memo,'') FROM vip_bcoin_salary WHERE mid IN (%v)"
_selOldBcoinSalarySQL = "SELECT id,mid,IFNULL(status,0),IFNULL(give_now_status,0),month,IFNULL(amount,0),IFNULL(memo,'') FROM vip_bcoin_salary WHERE id>? AND id<=?"
_addBcoinSalarySQL = "INSERT INTO vip_user_bcoin_salary(mid,status,give_now_status,payday,amount,memo) VALUES(?,?,?,?,?,?)"
_updateBcoinSalarySQL = "UPDATE vip_user_bcoin_salary set status = ? WHERE mid = ? AND payday = ?"
_updateBcoinSalaryBatchSQL = "UPDATE vip_user_bcoin_salary set status = ? WHERE id in (?)"
_batchAddBcoinSalarySQL = "INSERT INTO vip_user_bcoin_salary(mid,status,give_now_status,payday,amount,memo) VALUES "
_selBcoinMaxIDSQL = "SELECT IFNULL(MAX(id),0) FROM vip_user_bcoin_salary"
_selOldBcoinMaxIDSQL = "SELECT IFNULL(MAX(id),0) FROM vip_bcoin_salary"
_delBcoinSalarySQL = "DELETE FROM vip_user_bcoin_salary WHERE mid = ? AND payday = ?"
_getAbleCodeSQL = "SELECT code FROM vip_resource_code WHERE batch_code_id = ? AND status = 1 AND relation_id = '' LIMIT 1"
_selBatchCodeSQL = "SELECT id,business_id,pool_id,status,type,batch_name,reason,unit,count,surplus_count,price,start_time,end_time FROM vip_resource_batch_code WHERE id = ?"
_updateCodeRelationIDSQL = "UPDATE vip_resource_code SET relation_id=?,bmid=? WHERE code=?"
_selEffectiveVipList = "SELECT id,mid,vip_type,vip_status,vip_overdue_time,annual_vip_overdue_time FROM vip_user_info WHERE id>? AND id <=? "
//push
_selPushDataSQL = "SELECT id,disable_type,group_name,title,content,push_total_count,pushed_count,progress_status,`status`,platform,link_type,link_url,error_code,expired_day_start,expired_day_end,effect_start_date,effect_end_date,push_start_time,push_end_time FROM vip_push_data WHERE effect_start_date <= ? AND effect_end_date >= ? "
_updatePushDataSQL = "UPDATE vip_push_data SET progress_status=?,status=?, pushed_count=?,error_code=?,task_id=? WHERE id=?"
)
//SelOldBcoinMaxID sel oldbcoin maxID
func (d *Dao) SelOldBcoinMaxID(c context.Context) (maxID int64, err error) {
row := d.oldDb.QueryRow(c, _selOldBcoinMaxIDSQL)
if err = row.Scan(&maxID); err != nil {
if err == sql.ErrStmtNil {
err = nil
maxID = 0
return
}
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
}
return
}
//SelBcoinMaxID sel bcoin maxID
func (d *Dao) SelBcoinMaxID(c context.Context) (maxID int64, err error) {
row := d.db.QueryRow(c, _selBcoinMaxIDSQL)
if err = row.Scan(&maxID); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
return
}
return
}
//SelBcoinSalaryData sel bcoinSalary data
func (d *Dao) SelBcoinSalaryData(c context.Context, startID int64, endID int64) (res []*model.VipBcoinSalary, err error) {
var rows *sql.Rows
if rows, err = d.db.Query(c, _selBcoinSalaryDataSQL, startID, endID); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_query")
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipBcoinSalary)
if err = rows.Scan(&r.ID, &r.Mid, &r.Status, &r.GiveNowStatus, &r.Payday, &r.Amount, &r.Memo); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
return
}
res = append(res, r)
}
err = rows.Err()
return
}
//SelBcoinSalaryDataMaps sel bcoin salary data convert map
func (d *Dao) SelBcoinSalaryDataMaps(c context.Context, mids []int64) (res map[int64][]*model.VipBcoinSalary, err error) {
var rows *sql.Rows
if rows, err = d.db.Query(c, fmt.Sprintf(_selBcoinSalaryByMidSQL, xstr.JoinInts(mids))); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_query")
return
}
res = make(map[int64][]*model.VipBcoinSalary)
defer rows.Close()
for rows.Next() {
r := new(model.VipBcoinSalary)
if err = rows.Scan(&r.ID, &r.Mid, &r.Status, &r.GiveNowStatus, &r.Payday, &r.Amount, &r.Memo); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
return
}
salaries := res[r.Mid]
salaries = append(salaries, r)
res[r.Mid] = salaries
}
err = rows.Err()
return
}
//SelOldBcoinSalaryDataMaps sel old bcoin salary data convert map
func (d *Dao) SelOldBcoinSalaryDataMaps(c context.Context, mids []int64) (res map[int64][]*model.VipBcoinSalary, err error) {
var rows *sql.Rows
if rows, err = d.oldDb.Query(c, fmt.Sprintf(_selOldBcoinSalaryByMidSQL, xstr.JoinInts(mids))); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_query")
return
}
res = make(map[int64][]*model.VipBcoinSalary)
defer rows.Close()
for rows.Next() {
r := new(model.VipBcoinSalary)
if err = rows.Scan(&r.ID, &r.Mid, &r.Status, &r.GiveNowStatus, &r.Payday, &r.Amount, &r.Memo); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
return
}
salaries := res[r.Mid]
salaries = append(salaries, r)
res[r.Mid] = salaries
}
err = rows.Err()
return
}
//SelBcoinSalary sel bcoin salary data by query
func (d *Dao) SelBcoinSalary(c context.Context, arg *model.QueryBcoinSalary) (res []*model.VipBcoinSalary, err error) {
var rows *sql.Rows
sqlStr := ""
if arg.StartID >= 0 {
sqlStr += fmt.Sprintf(" AND id > %v ", arg.StartID)
}
if arg.EndID >= 0 {
sqlStr += fmt.Sprintf(" AND id <= %v ", arg.EndID)
}
if arg.StartMonth > 0 {
sqlStr += fmt.Sprintf(" AND payday>= '%v' ", arg.StartMonth.Time().Format("2006-01-02"))
}
if arg.EndMonth > 0 {
sqlStr += fmt.Sprintf(" AND payday <= '%v' ", arg.EndMonth.Time().Format("2006-01-02"))
}
if arg.GiveNowStatus > -1 {
sqlStr += fmt.Sprintf(" AND give_now_status = %v ", arg.GiveNowStatus)
}
if arg.Status > -1 {
sqlStr += fmt.Sprintf(" AND status = %v ", arg.Status)
}
if rows, err = d.db.Query(c, _selBcoinSalarySQL+sqlStr); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_query")
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipBcoinSalary)
if err = rows.Scan(&r.ID, &r.Mid, &r.Status, &r.GiveNowStatus, &r.Payday, &r.Amount, &r.Memo); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
}
res = append(res, r)
}
err = rows.Err()
return
}
//SelOldBcoinSalary sel old bcoin salary
func (d *Dao) SelOldBcoinSalary(c context.Context, startID, endID int64) (res []*model.VipBcoinSalary, err error) {
var rows *sql.Rows
if rows, err = d.oldDb.Query(c, _selOldBcoinSalarySQL, startID, endID); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_query")
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipBcoinSalary)
if err = rows.Scan(&r.ID, &r.Mid, &r.Status, &r.GiveNowStatus, &r.Payday, &r.Amount, &r.Memo); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
}
res = append(res, r)
}
err = rows.Err()
return
}
//AddBcoinSalary add bcoin salary
func (d *Dao) AddBcoinSalary(c context.Context, arg *model.VipBcoinSalaryMsg) (err error) {
if _, err = d.db.Exec(c, _addBcoinSalarySQL, &arg.Mid, &arg.Status, &arg.GiveNowStatus, &arg.Payday, &arg.Amount, &arg.Memo); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_exec")
}
return
}
//UpdateBcoinSalary update bcoin salary
func (d *Dao) UpdateBcoinSalary(c context.Context, payday string, mid int64, status int8) (err error) {
if _, err = d.db.Exec(c, _updateBcoinSalarySQL, status, mid, payday); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_exec")
}
return
}
//DelBcoinSalary del bcoin salary
func (d *Dao) DelBcoinSalary(c context.Context, payday string, mid int64) (err error) {
if _, err = d.db.Exec(c, _delBcoinSalarySQL, mid, payday); err != nil {
err = errors.WithStack(err)
return
}
return
}
//UpdateBcoinSalaryBatch update bcoin salary batch
func (d *Dao) UpdateBcoinSalaryBatch(c context.Context, ids []int64, status int8) (err error) {
if len(ids) <= 0 {
return
}
sqlStr := ""
for _, v := range ids {
sqlStr += "," + strconv.FormatInt(v, 10)
}
if _, err = d.db.Exec(c, _updateBcoinSalaryBatchSQL, status, sqlStr[1:]); err != nil {
err = errors.WithStack(err)
return
}
return
}
//BatchAddBcoinSalary batch add bcoin salary data
func (d *Dao) BatchAddBcoinSalary(bcoins []*model.VipBcoinSalary) (err error) {
var values []string
if len(bcoins) <= 0 {
return
}
for _, v := range bcoins {
str := fmt.Sprintf("('%v','%v','%v','%v','%v','%v')", v.Mid, v.Status, v.GiveNowStatus, v.Payday.Time().Format("2006-01-02"), v.Amount, v.Memo)
values = append(values, str)
}
valueStr := strings.Join(values, ",")
if _, err = d.db.Exec(context.TODO(), _batchAddBcoinSalarySQL+valueStr); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_exec")
return
}
return
}
//SelAppInfo sel vip_app_info data
func (d *Dao) SelAppInfo(c context.Context) (res []*model.VipAppInfo, err error) {
var rows *sql.Rows
if rows, err = d.oldDb.Query(c, _selAppInfo); err != nil {
log.Error("SelAppInfo db.query() error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipAppInfo)
if err = rows.Scan(&r.ID, &r.Name, &r.AppKey, &r.PurgeURL); err != nil {
log.Error("row.scan() error(%v)", err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}
//SelEffectiveVipList sel effective vip data
func (d *Dao) SelEffectiveVipList(c context.Context, id, endID int) (res []*model.VipUserInfo, err error) {
var rows *sql.Rows
if rows, err = d.oldDb.Query(c, _selEffectiveVipList, id, endID); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipUserInfo)
if err = rows.Scan(&r.ID, &r.Mid, &r.Type, &r.Status, &r.OverdueTime, &r.AnnualVipOverdueTime); err != nil {
err = errors.WithStack(err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}

View File

@ -0,0 +1,162 @@
package dao
import (
"context"
"testing"
"time"
"go-common/app/job/main/vip/model"
. "github.com/smartystreets/goconvey/convey"
)
func Test_SelVipList(t *testing.T) {
var (
res []*model.VipUserInfo
err error
id = 0
mID = 10000
ot = time.Now().Format("2006-01-02")
)
Convey("should return true where err != nil and res not empty", t, func() {
res, err = d.SelVipList(context.TODO(), id, mID, ot)
So(err, ShouldBeNil)
So(res, ShouldNotBeEmpty)
})
}
func Test_UpdateVipUserInfo(t *testing.T) {
vuf := new(model.VipUserInfo)
vuf.ID = 1
vuf.Type = 1
vuf.Status = 0
Convey("should return true where err == nil", t, func() {
tx, err := d.StartTx(context.TODO())
So(err, ShouldBeNil)
_, err = d.UpdateVipUserInfo(tx, vuf)
So(err, ShouldBeNil)
})
}
func Test_SelAppInfo(t *testing.T) {
Convey("should return true where err == nil and res not empty", t, func() {
res, err := d.SelAppInfo(context.TODO())
So(err, ShouldBeNil)
So(res, ShouldNotBeEmpty)
})
}
func Test_SelMaxID(t *testing.T) {
Convey("should return true where err == nil ", t, func() {
r, err := d.SelMaxID(context.TODO())
So(r, ShouldBeGreaterThan, 100)
So(err, ShouldBeNil)
})
}
func TestDao_SelOrderMaxID(t *testing.T) {
Convey("sel order max id", t, func() {
_, err := d.SelOrderMaxID(context.TODO())
So(err, ShouldBeNil)
})
}
func TestDao_SelOldBcoinMaxID(t *testing.T) {
Convey("sel old bcoin Max id", t, func() {
_, err := d.SelOldBcoinMaxID(context.TODO())
So(err, ShouldBeNil)
})
}
func TestDao_SelBcoinMaxID(t *testing.T) {
Convey("sel bcoin maxID", t, func() {
_, err := d.SelBcoinMaxID(context.TODO())
So(err, ShouldBeNil)
})
}
func TestDao_SelChangeHistoryMaxID(t *testing.T) {
Convey("sel change hsitory max id", t, func() {
_, err := d.SelChangeHistoryMaxID(context.TODO())
So(err, ShouldBeNil)
})
}
func TestDao_SelOldOrderMaxID(t *testing.T) {
Convey("sel old Order maxID", t, func() {
_, err := d.SelOldOrderMaxID(context.TODO())
So(err, ShouldBeNil)
})
}
func TestDao_VipStatus(t *testing.T) {
Convey("vip status", t, func() {
_, err := d.VipStatus(context.TODO(), 1)
So(err, ShouldBeNil)
})
}
func TestDao_SelOldBcoinSalaryDataMaps(t *testing.T) {
Convey("vip SelOldBcoinSalaryDataMaps", t, func() {
_, err := d.SelOldBcoinSalaryDataMaps(context.TODO(), []int64{7593623})
So(err, ShouldBeNil)
})
}
func TestDao_SelBcoinSalary(t *testing.T) {
arg := &model.QueryBcoinSalary{
StartID: 1,
EndID: 1,
Status: 1,
}
Convey("vip SelBcoinSalary", t, func() {
_, err := d.SelBcoinSalary(context.TODO(), arg)
So(err, ShouldBeNil)
})
}
func TestDao_SelOldBcoinSalary(t *testing.T) {
arg := &model.VipBcoinSalaryMsg{
Mid: 7593623,
Status: 1,
GiveNowStatus: 1,
Payday: "10",
Amount: 1,
Memo: "memo",
}
Convey("vip AddBcoinSalary", t, func() {
err := d.AddBcoinSalary(context.TODO(), arg)
So(err, ShouldBeNil)
})
Convey("vip UpdateBcoinSalary", t, func() {
err := d.UpdateBcoinSalary(context.TODO(), "10", 7593623, 2)
So(err, ShouldBeNil)
})
Convey("del bcoin salary", t, func() {
err := d.DelBcoinSalary(context.TODO(), "10", 7593623)
So(err, ShouldBeNil)
})
Convey("vip SelOldBcoinSalary", t, func() {
_, err := d.SelOldBcoinSalary(context.TODO(), 1, 1)
So(err, ShouldBeNil)
})
}
func TestDao_SelBcoinSalaryData(t *testing.T) {
Convey("SelBcoinSalaryData", t, func() {
_, err := d.SelBcoinSalaryData(context.TODO(), 1, 1)
So(err, ShouldBeNil)
})
}
func TestDao_SelBcoinSalaryDataMaps(t *testing.T) {
Convey("SelBcoinSalaryDataMaps", t, func() {
_, err := d.SelBcoinSalaryDataMaps(context.TODO(), []int64{1})
So(err, ShouldBeNil)
})
}
func TestDao_SelEffectiveVipList(t *testing.T) {
Convey("SelEffectiveVipList", t, func() {
_, err := d.SelEffectiveVipList(context.TODO(), 1, 1)
So(err, ShouldBeNil)
})
}

View File

@ -0,0 +1,37 @@
package dao
import (
"context"
"fmt"
"go-common/library/ecode"
"go-common/library/log"
"net/url"
)
const (
_frozenChange = "/internal/v1/user/frozenChange"
)
// OldFrozenChange .
func (d *Dao) OldFrozenChange(mid, status int64) (err error) {
var (
c = context.Background()
)
params := url.Values{}
params.Set("mid", fmt.Sprintf("%v", mid))
params.Set("status", fmt.Sprintf("%v", status))
rel := new(struct {
Code int64 `json:"code"`
Data string `json:"data"`
})
if err = d.client.Get(c, d.c.URLConf.OldVipCoURL+_frozenChange, "127.0.0.1", params, rel); err != nil {
log.Error("send error(%v) url(%v)", err, d.c.URLConf.OldVipCoURL+_frozenChange)
return
}
if rel != nil && rel.Code == int64(ecode.OK.Code()) {
return
}
err = ecode.VipJavaAPIErr
return
}

View File

@ -0,0 +1,14 @@
package dao
import (
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoOldFrozenChange(t *testing.T) {
convey.Convey("OldFrozenChange", t, func() {
err := d.OldFrozenChange(7593623, 0)
convey.So(err, convey.ShouldBeNil)
})
}

View File

@ -0,0 +1,252 @@
package dao
import (
"context"
"database/sql"
"fmt"
"strings"
"go-common/app/job/main/vip/model"
xsql "go-common/library/database/sql"
"go-common/library/log"
"github.com/pkg/errors"
)
const (
_insertPayOrder = "INSERT IGNORE INTO vip_pay_order(order_no,app_id,platform,order_type,mid,to_mid,buy_months,money,status,pay_type,recharge_bp,third_trade_no,payment_time,ver,app_sub_id,coupon_money) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
_selPayOrder = "SELECT order_no,app_id,platform,order_type,mid,to_mid,buy_months,money,status,pay_type,third_trade_no,payment_time,ver,app_sub_id FROM vip_pay_order WHERE id>? AND id <=?"
_selPayOrderByMidSQL = "SELECT order_no,app_id,platform,order_type,mid,to_mid,buy_months,money,status,pay_type,third_trade_no,payment_time,ver,app_sub_id FROM vip_pay_order WHERE mid=? AND order_type=? AND status=? ORDER BY ID DESC LIMIT 1"
_selOrderByMidSQL = "SELECT order_no,app_id,platform,order_type,mid,to_mid,buy_months,money,status,pay_type,third_trade_no,payment_time,ver,app_sub_id FROM vip_pay_order WHERE order_no=?"
_selPayOrderLogByMidSQL = "SELECT order_no,status,mid FROM vip_pay_order_log WHERE mid=? AND status=? ORDER BY ID DESC LIMIT 1"
_selOldPayOrder = "SELECT order_no,app_id,order_type,mid,IFNULL(buy_months,0),money,IFNULL(pay_type,4),IFNULL(status,1),ver,IFNULL(platform,3),mtime,app_sub_id,bmid,coupon_money from vip_pay_order WHERE id>? AND id<=?"
_selOldRechargeOrder = "SELECT pay_order_no,third_trade_no,recharge_bp FROM vip_recharge_order WHERE pay_order_no IN "
_updatePayOrderStatusSQL = "UPDATE vip_pay_order SET "
_updateRechageOrderSQL = "UPDATE vip_pay_order SET recharge_bp = ?,third_trade_no = ? where order_no = ?"
_insertPayOrderLog = "INSERT INTO vip_pay_order_log(order_no,mid,status) VALUES(?,?,?)"
_batchAddPayOrder = "INSERT INTO vip_pay_order(order_no,app_id,platform,order_type,mid,to_mid,buy_months,money,status,pay_type,recharge_bp,third_trade_no,payment_time,ver,app_sub_id) VALUES"
_selOrderMaxIDSQL = "SELECT IFNULL(MAX(id),0) FROM vip_pay_order"
_selOldOrderMaxIDSQL = "SELECT IFNULL(MAX(id),0) FROM vip_pay_order"
)
//SelPayOrderByMid sel payorder by mid
func (d *Dao) SelPayOrderByMid(c context.Context, mid int64, orderType, status int8) (r *model.VipPayOrder, err error) {
row := d.db.QueryRow(c, _selPayOrderByMidSQL, mid, orderType, status)
r = new(model.VipPayOrder)
if err = row.Scan(&r.OrderNo, &r.AppID, &r.Platform, &r.OrderType, &r.Mid, &r.ToMid, &r.BuyMonths, &r.Money, &r.Status, &r.PayType, &r.ThirdTradeNo, &r.PaymentTime, &r.Ver, &r.AppSubID); err != nil {
if err == sql.ErrNoRows {
err = nil
r = nil
return
}
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
return
}
return
}
//SelOrderByOrderNo sel payorder by orderNo
func (d *Dao) SelOrderByOrderNo(c context.Context, orderNo string) (r *model.VipPayOrder, err error) {
row := d.db.QueryRow(c, _selOrderByMidSQL, orderNo)
r = new(model.VipPayOrder)
if err = row.Scan(&r.OrderNo, &r.AppID, &r.Platform, &r.OrderType, &r.Mid, &r.ToMid, &r.BuyMonths, &r.Money, &r.Status, &r.PayType, &r.ThirdTradeNo, &r.PaymentTime, &r.Ver, &r.AppSubID); err != nil {
if err == sql.ErrNoRows {
err = nil
r = nil
return
}
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
return
}
return
}
//SelPayOrderLog sel pay order log.
func (d *Dao) SelPayOrderLog(c context.Context, mid int64, status int8) (r *model.VipPayOrderLog, err error) {
row := d.db.QueryRow(c, _selPayOrderLogByMidSQL, mid, status)
r = new(model.VipPayOrderLog)
if err = row.Scan(&r.OrderNo, &r.Status, &r.Mid); err != nil {
if err == sql.ErrNoRows {
err = nil
r = nil
return
}
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
return
}
return
}
//AddPayOrder add payorder
func (d *Dao) AddPayOrder(c context.Context, r *model.VipPayOrder) (a int64, err error) {
var result sql.Result
if result, err = d.db.Exec(c, _insertPayOrder, &r.OrderNo, &r.AppID, &r.Platform, &r.OrderType, &r.Mid, &r.ToMid, &r.BuyMonths, &r.Money, &r.Status, &r.PayType, &r.RechargeBp, &r.ThirdTradeNo, &r.PaymentTime, &r.Ver, &r.AppSubID, &r.CouponMoney); err != nil {
log.Error("AddPayOrder d.db.exec(%v) error(%v)", r, err)
return
}
if a, err = result.RowsAffected(); err != nil {
log.Error("AddPayOrder result.RowsAffected() error(%v)", err)
return
}
return
}
//SelOrderMaxID sel order maxID
func (d *Dao) SelOrderMaxID(c context.Context) (maxID int, err error) {
row := d.db.QueryRow(c, _selOrderMaxIDSQL)
if err = row.Scan(&maxID); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
return
}
return
}
//SelOldOrderMaxID sel old order maxID
func (d *Dao) SelOldOrderMaxID(c context.Context) (maxID int, err error) {
row := d.oldDb.QueryRow(c, _selOldOrderMaxIDSQL)
if err = row.Scan(&maxID); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
return
}
return
}
//BatchAddPayOrder batch add pay order
func (d *Dao) BatchAddPayOrder(c context.Context, res []*model.VipPayOrder) (err error) {
var values []string
if len(res) == 0 {
return
}
for _, v := range res {
value := fmt.Sprintf("('%v','%v','%v','%v','%v','%v','%v','%v','%v','%v','%v','%v','%v','%v','%v','%v')", v.OrderNo, v.AppID, v.Platform, v.OrderType, v.Mid, v.ToMid, v.BuyMonths, v.Money, v.Status, v.PayType, v.RechargeBp, v.ThirdTradeNo, v.PaymentTime.Time().Format("2006-01-02 15:04:05"), v.Ver, v.AppSubID, v.CouponMoney)
values = append(values, value)
}
valuesStr := strings.Join(values, ",")
dupStr := " ON DUPLICATE KEY UPDATE app_id = VALUES(app_id),platform=VALUES(platform),order_type=VALUES(order_type)," +
"mid=VALUES(mid),to_mid=VALUES(to_mid),buy_months=VALUES(buy_months),money=VALUES(money),status=VALUES(status),pay_type=VALUES(pay_type),recharge_bp=VALUES(recharge_bp)," +
"third_trade_no=VALUES(third_trade_no) ,payment_time=VALUES(payment_time) ,ver=VALUES(ver),app_sub_id=VALUES(app_sub_id),coupon_money=VALUES(coupon_money) "
if _, err = d.db.Exec(c, _batchAddPayOrder+valuesStr+dupStr); err != nil {
err = errors.WithStack(err)
return
}
return
}
//UpdatePayOrderStatus update payorder status
func (d *Dao) UpdatePayOrderStatus(c context.Context, r *model.VipPayOrder) (a int64, err error) {
var result sql.Result
sqlStr := _updatePayOrderStatusSQL
if r.PayType != 0 {
sqlStr += fmt.Sprintf(" pay_type=%v ,payment_time='%v' ,", r.PayType, r.PaymentTime.Time().Format("2006-01-02 15:04:05"))
}
sqlStr += fmt.Sprintf(" ctime='%v',mtime='%v',ver=%v,status=%v,order_type=%v,coupon_money=%v WHERE order_no='%v' ", r.Ctime.Time().Format("2006-01-02 15:04:05"), r.Mtime.Time().Format("2006-01-02 15:04:05"), r.Ver, r.Status, r.OrderType, r.CouponMoney, r.OrderNo)
if result, err = d.db.Exec(c, sqlStr); err != nil {
err = errors.WithStack(err)
return
}
if a, err = result.RowsAffected(); err != nil {
err = errors.WithStack(err)
return
}
return
}
//UpdateRechargeOrder update recharge order info
func (d *Dao) UpdateRechargeOrder(c context.Context, r *model.VipPayOrder) (a int64, err error) {
var result sql.Result
if result, err = d.db.Exec(c, _updateRechageOrderSQL, &r.RechargeBp, &r.ThirdTradeNo, &r.OrderNo); err != nil {
err = errors.WithStack(err)
return
}
if a, err = result.RowsAffected(); err != nil {
err = errors.WithStack(err)
return
}
return
}
//AddPayOrderLog add payorderlog
func (d *Dao) AddPayOrderLog(c context.Context, r *model.VipPayOrderLog) (a int64, err error) {
var result sql.Result
if result, err = d.db.Exec(c, _insertPayOrderLog, &r.OrderNo, &r.Mid, &r.Status); err != nil {
err = errors.WithStack(err)
return
}
if a, err = result.RowsAffected(); err != nil {
err = errors.WithStack(err)
return
}
return
}
//SelPayOrder sel payorder
func (d *Dao) SelPayOrder(c context.Context, sID, eID int) (res []*model.VipPayOrder, err error) {
var rows *xsql.Rows
if rows, err = d.db.Query(c, _selPayOrder, sID, eID); err != nil {
log.Error("SelPayOrder d.db.query(sID:%v,eID:%v) error(%v)", sID, eID, err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipPayOrder)
if err = rows.Scan(&r.OrderNo, &r.AppID, &r.Platform, &r.OrderType, &r.Mid, &r.ToMid, &r.BuyMonths, &r.Money, &r.Status, &r.PayType, &r.ThirdTradeNo, &r.PaymentTime, &r.Ver, &r.AppSubID); err != nil {
log.Error("SelPayOrder rows.scan() error(%v)", err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}
//SelOldPayOrder sel old payorder
func (d *Dao) SelOldPayOrder(c context.Context, sID, eID int) (res []*model.VipPayOrderOld, err error) {
var rows *xsql.Rows
if rows, err = d.oldDb.Query(c, _selOldPayOrder, sID, eID); err != nil {
log.Error("SelOldPayOrder d.db.query(sID:%v,eID:%v) error(%v)", sID, eID, err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipPayOrderOld)
if err = rows.Scan(&r.OrderNo, &r.AppID, &r.OrderType, &r.Mid, &r.BuyMonths, &r.Money, &r.PayType, &r.Status, &r.Ver, &r.Platform, &r.PaymentTime, &r.AppSubID, &r.Bmid, &r.CouponMoney); err != nil {
log.Error("SelOldPayOrder rows.scan() error(%v)", err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}
//SelOldRechargeOrder sel old rechargeOrder
func (d *Dao) SelOldRechargeOrder(c context.Context, orderNos []string) (res []*model.VipRechargeOrder, err error) {
var inStr = strings.Join(orderNos, "','")
inStr = "('" + inStr + "')"
var rows *xsql.Rows
if rows, err = d.oldDb.Query(c, _selOldRechargeOrder+inStr); err != nil {
log.Error("SelOldRechargeOrder d.db.query(%v) error(%v)", orderNos, err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipRechargeOrder)
if err = rows.Scan(&r.PayOrderNo, &r.ThirdTradeNo, &r.RechargeBp); err != nil {
log.Error("SelOldRechargeOrder rows.scan(%v) error(%v)", orderNos, err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}

View File

@ -0,0 +1,76 @@
package dao
import (
"context"
"testing"
"go-common/app/job/main/vip/model"
xtime "go-common/library/time"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestDao_AddPayOrder(t *testing.T) {
Convey("add pay order", t, func() {
d.AddPayOrder(context.TODO(), &model.VipPayOrder{Mid: 123})
})
}
func TestDao_UpdatePayOrderStatus(t *testing.T) {
Convey("update order", t, func() {
r := new(model.VipPayOrder)
r.OrderType = 1
r.PayType = 6
r.Status = 2
r.Ver = 2
r.OrderNo = "1807021929153562939"
r.Mtime = xtime.Time(time.Now().Unix())
_, err := d.UpdatePayOrderStatus(context.TODO(), r)
So(err, ShouldBeNil)
})
}
func TestDao_SelPayOrderByMid(t *testing.T) {
Convey("SelPayOrderByMid", t, func() {
_, err := d.SelPayOrderByMid(context.TODO(), 7593623, 1, 1)
So(err, ShouldBeNil)
})
}
func TestDao_SSelOrderByOrderNo(t *testing.T) {
Convey("SelOrderByOrderNo", t, func() {
_, err := d.SelOrderByOrderNo(context.TODO(), "7593623")
So(err, ShouldBeNil)
})
}
func TestDao_SelPayOrderLog(t *testing.T) {
Convey("SelPayOrderLog", t, func() {
_, err := d.SelPayOrderLog(context.TODO(), 7593623, 1)
So(err, ShouldBeNil)
})
}
func TestDao_SelPayOrder(t *testing.T) {
Convey("SelPayOrder", t, func() {
_, err := d.SelPayOrder(context.TODO(), 1, 1)
So(err, ShouldBeNil)
})
}
func TestDao_SelOldPayOrder(t *testing.T) {
Convey("SelOldPayOrder", t, func() {
_, err := d.SelOldPayOrder(context.TODO(), 1, 1)
So(err, ShouldBeNil)
})
}
func TestDao_SelOldRechargeOrder(t *testing.T) {
Convey("SelOldRechargeOrder", t, func() {
_, err := d.SelOldRechargeOrder(context.TODO(), []string{"test"})
So(err, ShouldBeNil)
})
}

View File

@ -0,0 +1,39 @@
package dao
import (
"context"
"go-common/app/job/main/vip/model"
"go-common/library/database/sql"
"github.com/pkg/errors"
)
//PushDatas get push datas
func (d *Dao) PushDatas(c context.Context, curtime string) (res []*model.VipPushData, err error) {
var rows *sql.Rows
if rows, err = d.db.Query(c, _selPushDataSQL, curtime, curtime); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipPushData)
if err = rows.Scan(&r.ID, &r.DisableType, &r.GroupName, &r.Title, &r.Content, &r.PushTotalCount, &r.PushedCount, &r.ProgressStatus, &r.Status, &r.Platform, &r.LinkType, &r.LinkURL, &r.ErrorCode, &r.ExpiredDayStart, &r.ExpiredDayEnd, &r.EffectStartDate, &r.EffectEndDate, &r.PushStartTime, &r.PushEndTime); err != nil {
err = errors.WithStack(err)
return
}
res = append(res, r)
}
err = rows.Err()
return
}
//UpdatePushData update push data
func (d *Dao) UpdatePushData(c context.Context, status, progressStatus int8, pushedCount int32, errcode, data, id int64) (err error) {
if _, err = d.db.Exec(c, _updatePushDataSQL, progressStatus, status, pushedCount, errcode, data, id); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("exec_err")
}
return
}

View File

@ -0,0 +1,43 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoPushDatas(t *testing.T) {
convey.Convey("PushDatas", t, func(ctx convey.C) {
var (
c = context.Background()
curtime = ""
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.PushDatas(c, curtime)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoUpdatePushData(t *testing.T) {
convey.Convey("UpdatePushData", t, func(ctx convey.C) {
var (
c = context.Background()
status = int8(0)
progressStatus = int8(0)
pushedCount = int32(0)
errcode = int64(0)
data = int64(0)
id = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.UpdatePushData(c, status, progressStatus, pushedCount, errcode, data, id)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@ -0,0 +1,123 @@
package dao
import (
"context"
"fmt"
"time"
"go-common/library/cache/redis"
"github.com/pkg/errors"
)
const (
_frozenDelayQueue = "fdq"
_accLogin = "al:%d"
)
func accLoginKey(mid int64) string {
return fmt.Sprintf(_accLogin, mid)
}
// Enqueue put frozen user to redis sortset queue
func (d *Dao) Enqueue(c context.Context, mid, score int64) (err error) {
var (
conn = d.redis.Get(c)
)
defer conn.Close()
if err = conn.Send("ZADD", _frozenDelayQueue, score, mid); err != nil {
err = errors.Wrap(err, "redis send zadd err(%+v)")
return
}
if err = conn.Send("EXPIRE", _frozenDelayQueue, d.redisExpire); err != nil {
err = errors.Wrap(err, "redis send expire err(%+v)")
return
}
if err = conn.Flush(); err != nil {
return
}
for i := 0; i < 2; i++ {
if _, err = conn.Receive(); err != nil {
return
}
}
return
}
// Dequeue get a frozen user from redis sortset queue
func (d *Dao) Dequeue(c context.Context) (mid []int64, err error) {
var (
conn = d.redis.Get(c)
from = time.Now().Add(-1 * time.Minute).Unix()
to = time.Now().Unix()
)
defer conn.Close()
if mid, err = redis.Int64s(conn.Do("ZRANGEBYSCORE", _frozenDelayQueue, from, to)); err != nil {
err = errors.Wrap(err, "redis do zrevrangebyscore err")
return
}
return
}
// RemQueue del a frozen user from redis sortset queue
func (d *Dao) RemQueue(c context.Context, mid int64) (err error) {
var (
conn = d.redis.Get(c)
)
defer conn.Close()
if _, err = conn.Do("ZREM", _frozenDelayQueue, mid); err != nil {
err = errors.Wrap(err, "redis do zrem err")
return
}
return
}
// AddLogginIP save user loggin info to sortset
func (d *Dao) AddLogginIP(c context.Context, mid int64, ip uint32) (err error) {
var (
conn = d.redis.Get(c)
key = accLoginKey(mid)
)
defer conn.Close()
if err = conn.Send("SADD", key, ip); err != nil {
err = errors.Wrap(err, "redis do zadd err")
return
}
if err = conn.Send("EXPIRE", key, d.frozenExpire); err != nil {
err = errors.Wrap(err, "redis send expire err(%+v)")
return
}
if err = conn.Flush(); err != nil {
return
}
for i := 0; i < 2; i++ {
if _, err = conn.Receive(); err != nil {
return
}
}
return
}
//DelCache del cache.
func (d *Dao) DelCache(c context.Context, mid int64) (err error) {
var (
conn = d.redis.Get(c)
key = accLoginKey(mid)
)
defer conn.Close()
if _, err = conn.Do("DEL", key); err != nil {
err = errors.WithStack(err)
return
}
return
}
// LoginCount get user recent loggin count
func (d *Dao) LoginCount(c context.Context, mid int64) (count int64, err error) {
var conn = d.redis.Get(c)
defer conn.Close()
if count, err = redis.Int64(conn.Do("SCARD", accLoginKey(mid))); err != nil {
err = errors.Wrap(err, "redis send zcard err(%+v)")
}
return
}

View File

@ -0,0 +1,54 @@
package dao
import (
"context"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
var (
ctx = context.TODO()
mid int64 = 7593623
)
func Test_FrozenQueue(t *testing.T) {
Convey("Test_FrozenQueue", t, func() {
var (
err error
score = time.Now().Add(-50 * time.Second).Unix()
)
err = d.Enqueue(ctx, mid, score)
So(err, ShouldBeNil)
res, err2 := d.Dequeue(ctx)
So(err2, ShouldBeNil)
So(res[0], ShouldEqual, mid)
err3 := d.RemQueue(ctx, mid)
So(err3, ShouldBeNil)
})
}
func TestDao_Enqueue(t *testing.T) {
Convey("test enqueue", t, func() {
duration := time.Duration(d.c.Property.FrozenDate)
t.Logf("duration %+v", duration)
err := d.Enqueue(ctx, mid, time.Now().Add(duration).Unix())
So(err, ShouldBeNil)
})
}
func TestDao_Dequeue(t *testing.T) {
Convey("dequeue", t, func() {
res, err := d.Dequeue(ctx)
t.Logf("%+v", res)
So(err, ShouldBeNil)
})
}
func Test_AddLogginIP(t *testing.T) {
Convey("Test_FrozenQueue", t, func() {
err := d.AddLogginIP(ctx, mid, 234231)
So(err, ShouldBeNil)
})
}

View File

@ -0,0 +1,43 @@
package dao
import (
"go-common/app/job/main/vip/model"
"go-common/library/database/sql"
"github.com/pkg/errors"
)
//GetAbleCode get able code
func (d *Dao) GetAbleCode(tx *sql.Tx, batchCodeID int64) (code string, err error) {
row := tx.QueryRow(_getAbleCodeSQL, batchCodeID)
if err = row.Scan(&code); err != nil {
if err == sql.ErrNoRows {
err = nil
return
}
err = errors.WithStack(err)
}
return
}
//UpdateCodeRelationID update code relationID
func (d *Dao) UpdateCodeRelationID(tx *sql.Tx, code, relationID string, bmid int64) (err error) {
if _, err = tx.Exec(_updateCodeRelationIDSQL, relationID, bmid, code); err != nil {
err = errors.WithStack(err)
}
return
}
//SelBatchCodeByID .
func (d *Dao) SelBatchCodeByID(tx *sql.Tx, batchCodeID int64) (r *model.VipResourceBatchCode, err error) {
row := tx.QueryRow(_selBatchCodeSQL, batchCodeID)
r = new(model.VipResourceBatchCode)
if err = row.Scan(&r.ID, &r.BusinessID, &r.PoolID, &r.Status, &r.Type, &r.BatchName, &r.Reason, &r.Unit, &r.Count, &r.SurplusCount, &r.Price, &r.StartTime, &r.EndTime); err != nil {
if err == sql.ErrNoRows {
err = nil
return
}
err = errors.WithStack(err)
}
return
}

View File

@ -0,0 +1,63 @@
package dao
import (
"context"
"go-common/library/database/sql"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoGetAbleCode(t *testing.T) {
convey.Convey("GetAbleCode", t, func(ctx convey.C) {
var (
tx = &sql.Tx{}
batchCodeID = int64(0)
)
tx, err := d.StartTx(context.Background())
ctx.So(err, convey.ShouldBeNil)
ctx.So(tx, convey.ShouldNotBeNil)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.GetAbleCode(tx, batchCodeID)
ctx.Convey("Then err should be nil.code should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoUpdateCodeRelationID(t *testing.T) {
convey.Convey("UpdateCodeRelationID", t, func(ctx convey.C) {
var (
code = ""
relationID = ""
bmid = int64(0)
)
tx, err := d.StartTx(context.Background())
ctx.So(err, convey.ShouldBeNil)
ctx.So(tx, convey.ShouldNotBeNil)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.UpdateCodeRelationID(tx, code, relationID, bmid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelBatchCodeByID(t *testing.T) {
convey.Convey("SelBatchCodeByID", t, func(ctx convey.C) {
var (
batchCodeID = int64(0)
)
tx, err := d.StartTx(context.Background())
ctx.So(err, convey.ShouldBeNil)
ctx.So(tx, convey.ShouldNotBeNil)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelBatchCodeByID(tx, batchCodeID)
ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@ -0,0 +1,37 @@
package dao
import (
"context"
xsql "database/sql"
"go-common/app/job/main/vip/model"
"github.com/pkg/errors"
)
const (
//sync
_syncAddUser = "INSERT INTO vip_user_info(mid,vip_type,vip_pay_type,vip_status,vip_start_time,vip_overdue_time,annual_vip_overdue_time,vip_recent_time,ios_overdue_time,pay_channel_id,ctime,mtime,ver) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)"
_syncUpdateUser = "UPDATE vip_user_info SET vip_type=?,vip_pay_type=?,vip_status=?,vip_overdue_time=?,annual_vip_overdue_time=?,vip_recent_time=?,ios_overdue_time=?,pay_channel_id=?,ctime=?,mtime=?,ver=? WHERE mid=? AND ver=?"
)
//SyncAddUser insert vipUserInfo
func (d *Dao) SyncAddUser(c context.Context, r *model.VipUserInfo) (err error) {
if _, err = d.db.Exec(c, _syncAddUser, r.Mid, r.Type, r.PayType, r.Status, r.StartTime, r.OverdueTime, r.AnnualVipOverdueTime, r.RecentTime, r.OverdueTime, r.PayChannelID, r.Ctime, r.Mtime, r.Ver); err != nil {
err = errors.WithStack(err)
}
return
}
//SyncUpdateUser insert vipUserInfo
func (d *Dao) SyncUpdateUser(c context.Context, r *model.VipUserInfo, ver int64) (eff int64, err error) {
var res xsql.Result
if res, err = d.db.Exec(c, _syncUpdateUser, r.Type, r.PayType, r.Status, r.OverdueTime, r.AnnualVipOverdueTime, r.RecentTime, r.IosOverdueTime, r.PayChannelID, r.Ctime, r.Mtime, r.Ver, r.Mid, ver); err != nil {
err = errors.WithStack(err)
return
}
if eff, err = res.RowsAffected(); err != nil {
err = errors.WithStack(err)
}
return
}

View File

@ -0,0 +1,29 @@
package dao
import (
"context"
"go-common/app/job/main/vip/model"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoSyncAddUser(t *testing.T) {
var r = &model.VipUserInfo{Mid: 7993}
convey.Convey("clean data before", t, func() {
d.db.Exec(context.Background(), "delete from vip_user_info where mid = ?", r.Mid)
})
convey.Convey("SyncAddUser", t, func() {
err := d.SyncAddUser(context.Background(), r)
convey.So(err, convey.ShouldBeNil)
})
convey.Convey("SyncUpdateUser", t, func() {
r.Status = 2
eff, err := d.SyncUpdateUser(context.Background(), r, r.Ver)
convey.So(err, convey.ShouldBeNil)
convey.So(eff, convey.ShouldNotBeNil)
})
convey.Convey("clean data", t, func() {
d.db.Exec(context.Background(), "delete from vip_user_info where mid = ?", r.Mid)
})
}

522
app/job/main/vip/dao/vip.go Normal file
View File

@ -0,0 +1,522 @@
package dao
import (
"context"
xsql "database/sql"
"fmt"
"strings"
"go-common/app/job/main/vip/model"
"go-common/library/database/sql"
"go-common/library/log"
"go-common/library/time"
"go-common/library/xstr"
"github.com/pkg/errors"
)
const (
_getVipStatus = "SELECT id,mid,vip_status FROM vip_user_info WHERE mid=?"
_dupUserDiscountHistory = "INSERT INTO vip_user_discount_history(mid,discount_id,order_no,status) VALUES(?,?,?,?) ON DUPLICATE KEY UPDATE order_no= VALUES(order_no) ,status = VALUES(status)"
_insertUserInfo = "INSERT ignore INTO vip_user_info(mid,vip_type,vip_pay_type,vip_status,vip_start_time,vip_recent_time,vip_overdue_time,annual_vip_overdue_time,pay_channel_id,ios_overdue_time,ver) VALUES(?,?,?,?,?,?,?,?,?,?,?) "
_updateUserInfo = "UPDATE vip_user_info SET vip_type=?,vip_pay_type=?,vip_status=?,vip_start_time=?,vip_recent_time=?,vip_overdue_time=?,annual_vip_overdue_time=?,pay_channel_id=?,ios_overdue_time=?,ver=? WHERE mid=? AND ver=? "
_SelUserDiscountHistorys = "SELECT mid,discount_id FROM vip_user_discount_history WHERE id>? AND id<=? AND discount_id=?"
_SelVipUserInfos = "SELECT mid,vip_type,vip_pay_type,vip_status,vip_start_time,vip_recent_time,vip_overdue_time,annual_vip_overdue_time FROM vip_user_info WHERE id>? and id<=? "
_SelOldVipUserInfos = "SELECT mid,vip_type,is_auto_renew,auto_renewed,IFNULL(vip_status,0),vip_recent_time,TIMESTAMP(IFNULL(vip_start_time,'2016-01-01 00:00:00')),TIMESTAMP(IFNULL(vip_overdue_time,'2016-01-01 00:00:00')),TIMESTAMP(IFNULL(annual_vip_overdue_time,'2016-01-01 00:00:00')),ver,ios_overdue_time,pay_channel_id,ctime,mtime FROM vip_user_info WHERE id>? and id<=?"
_SelVipList = "SELECT id,mid,vip_type,vip_status,vip_overdue_time,annual_vip_overdue_time,is_auto_renew,pay_channel_id FROM vip_user_info WHERE id>? AND id <=? AND vip_status != 0 AND annual_vip_overdue_time<=?"
_selVipUsersSQL = "SELECT id,mid,vip_type,vip_status,vip_overdue_time,annual_vip_overdue_time FROM vip_user_info WHERE id>? AND id <=? AND vip_pay_type = 1 AND vip_overdue_time>=? AND vip_overdue_time<?"
_selVipUserInfoSQL = "SELECT mid FROM vip_user_info WHERE id>? AND id <=? AND vip_status = ? AND vip_overdue_time>=? AND vip_overdue_time<?"
_UpdateVipUserInfoByID = "UPDATE vip_user_info SET pay_channel_id=?,vip_pay_type=?,vip_recent_time=?,vip_overdue_time=?,annual_vip_overdue_time=?, vip_type=?, vip_status=? WHERE mid=?"
_updateVipStatus = "UPDATE vip_user_info SET vip_status=? WHERE mid=?"
_updateVipUserSQL = "UPDATE vip_user_info SET vip_status=?,vip_type=?,is_auto_renew=? WHERE mid=?"
_SelMaxID = "SELECT IFNULL(MAX(id),0) id FROM vip_user_info"
_SelEffectiveScopeVipList = "SELECT `id`,`mid`,`ver`,`vip_type`,`vip_pay_type`,`pay_channel_id`,`vip_status`,`vip_start_time`,`vip_recent_time`,`vip_overdue_time`,`annual_vip_overdue_time`,`ios_overdue_time`,`ctime` FROM `vip_user_info` WHERE id>? AND id <=?;"
_selDiscountMaxID = "SELECT IFNULL(MAX(id),0) id FROM vip_user_discount_history"
_selUserInfoMaxID = "SELECT IFNULL(MAX(id),0) id FROM vip_user_info"
//Vip change history
_selOldMaxIDSQL = "SELECT IFNULL(MAX(id),0) FROM vip_change_history"
_selMaxIDSQL = "SELECT IFNULL(MAX(id),0) FROM vip_user_change_history"
_selOldChangeHistorySQL = "SELECT id,mid,change_type,change_time,days,month,operator_id,relation_id,batch_id,IFNULL(remark,''),batch_code_id FROM vip_change_history WHERE id>? AND id<=?"
_selOldChangeHistoryByMidsSQL = "SELECT id,mid,change_type,change_time,days,month,operator_id,relation_id,batch_id,IFNULL(remark,''),batch_code_id FROM vip_change_history WHERE mid IN (%v)"
_selChangeHistorySQL = "SELECT id,mid,change_type,change_time,days,operator_id,relation_id,batch_id,remark,batch_code_id FROM vip_user_change_history WHERE id>? AND id<=?"
_selChangeHistoryByMidsSQL = "SELECT id,mid,change_type,change_time,days,operator_id,relation_id,batch_id,remark,batch_code_id FROM vip_user_change_history WHERE mid IN (%v)"
_addChangeHistoryBatchSQL = "INSERT INTO vip_user_change_history(mid,change_type,change_time,days,operator_id,relation_id,batch_id,remark,batch_code_id) VALUES"
// old vip db
_selOldVipUserInfo = "SELECT mid,vip_type,is_auto_renew,auto_renewed,IFNULL(vip_status,0),vip_recent_time,TIMESTAMP(IFNULL(vip_start_time,'2016-01-01 00:00:00')),TIMESTAMP(IFNULL(vip_overdue_time,'2016-01-01 00:00:00')),annual_vip_overdue_time,ios_overdue_time,ver,pay_channel_id FROM vip_user_info WHERE mid=?"
_selVipByMidsSQL = "SELECT id,mid,vip_type,vip_status,vip_recent_time,vip_start_time,vip_overdue_time,annual_vip_overdue_time,vip_pay_type,pay_channel_id,ios_overdue_time,ctime,mtime,ver FROM vip_user_info WHERE mid IN (%s)"
_selVipUserInfoByMid = "SELECT id,mid,ver,vip_type,vip_pay_type,vip_status,vip_start_time,vip_overdue_time,annual_vip_overdue_time,vip_recent_time FROM vip_user_info WHERE mid = ?"
)
//AddChangeHistoryBatch batch add change history
func (d *Dao) AddChangeHistoryBatch(res []*model.VipChangeHistory) (err error) {
var values []string
if len(res) <= 0 {
return
}
for _, v := range res {
value := fmt.Sprintf("('%v','%v','%v','%v','%v','%v','%v','%v','%v')", v.Mid, v.ChangeType, v.ChangeTime.Time().Format("2006-01-02 15:04:05"), v.Days, v.OperatorID, v.RelationID, v.BatchID, v.Remark, v.BatchCodeID)
values = append(values, value)
}
valuesStr := strings.Join(values, ",")
if _, err = d.db.Exec(context.TODO(), _addChangeHistoryBatchSQL+valuesStr); err != nil {
log.Error("AddChangeHistoryBatch d.db.exec(%v),error(%v)", valuesStr, err)
return
}
return
}
//SelChangeHistory .
func (d *Dao) SelChangeHistory(c context.Context, startID, endID int64) (res []*model.VipChangeHistory, err error) {
var rows *sql.Rows
if rows, err = d.db.Query(c, _selChangeHistorySQL, startID, endID); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipChangeHistory)
if err = rows.Scan(&r.ID, &r.Mid, &r.ChangeType, &r.ChangeTime, &r.Days, &r.OperatorID, &r.RelationID, &r.BatchID, &r.Remark, &r.BatchCodeID); err != nil {
err = errors.WithStack(err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}
//SelOldChangeHistory .
func (d *Dao) SelOldChangeHistory(c context.Context, startID, endID int64) (res []*model.VipChangeHistory, err error) {
var rows *sql.Rows
if rows, err = d.oldDb.Query(c, _selOldChangeHistorySQL, startID, endID); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipChangeHistory)
if err = rows.Scan(&r.ID, &r.Mid, &r.ChangeType, &r.ChangeTime, &r.Days, &r.Month, &r.OperatorID, &r.RelationID, &r.BatchID, &r.Remark, &r.BatchCodeID); err != nil {
err = errors.WithStack(err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}
//SelChangeHistoryMaps .
func (d *Dao) SelChangeHistoryMaps(c context.Context, mids []int64) (res map[int64][]*model.VipChangeHistory, err error) {
var rows *sql.Rows
if rows, err = d.db.Query(c, fmt.Sprintf(_selChangeHistoryByMidsSQL, xstr.JoinInts(mids))); err != nil {
err = errors.WithStack(err)
return
}
res = make(map[int64][]*model.VipChangeHistory)
defer rows.Close()
for rows.Next() {
r := new(model.VipChangeHistory)
if err = rows.Scan(&r.ID, &r.Mid, &r.ChangeType, &r.ChangeTime, &r.Days, &r.OperatorID, &r.RelationID, &r.BatchID, &r.Remark, &r.BatchCodeID); err != nil {
err = errors.WithStack(err)
res = nil
return
}
histories := res[r.Mid]
histories = append(histories, r)
res[r.Mid] = histories
}
err = rows.Err()
return
}
//SelOldChangeHistoryMaps .
func (d *Dao) SelOldChangeHistoryMaps(c context.Context, mids []int64) (res map[int64][]*model.VipChangeHistory, err error) {
var rows *sql.Rows
if rows, err = d.oldDb.Query(c, fmt.Sprintf(_selOldChangeHistoryByMidsSQL, xstr.JoinInts(mids))); err != nil {
err = errors.WithStack(err)
return
}
res = make(map[int64][]*model.VipChangeHistory)
defer rows.Close()
for rows.Next() {
r := new(model.VipChangeHistory)
if err = rows.Scan(&r.ID, &r.Mid, &r.ChangeType, &r.ChangeTime, &r.Days, &r.Month, &r.OperatorID, &r.RelationID, &r.BatchID, &r.Remark, &r.BatchCodeID); err != nil {
err = errors.WithStack(err)
res = nil
return
}
histories := res[r.Mid]
histories = append(histories, r)
res[r.Mid] = histories
}
err = rows.Err()
return
}
//SelOldChangeHistoryMaxID .
func (d *Dao) SelOldChangeHistoryMaxID(c context.Context) (id int64, err error) {
var row = d.oldDb.QueryRow(c, _selOldMaxIDSQL)
if err = row.Scan(&id); err != nil {
log.Error("SelMaxID row.Scan() error(%v)", err)
return
}
return
}
//SelChangeHistoryMaxID .
func (d *Dao) SelChangeHistoryMaxID(c context.Context) (id int64, err error) {
var row = d.db.QueryRow(c, _selMaxIDSQL)
if err = row.Scan(&id); err != nil {
log.Error("SelMaxID row.Scan() error(%v)", err)
return
}
return
}
// VipStatus get user vip status.
func (d *Dao) VipStatus(c context.Context, mid int64) (res *model.VipUserInfo, err error) {
row := d.db.QueryRow(c, _getVipStatus, mid)
res = new(model.VipUserInfo)
if err = row.Scan(&res.ID, &res.Mid, &res.Status); err != nil {
if err == sql.ErrNoRows {
err = nil
res = nil
} else {
err = errors.Wrapf(err, "d.VipStatus(%d)", mid)
}
}
return
}
//SelMaxID get max id
func (d *Dao) SelMaxID(c context.Context) (mID int, err error) {
var row = d.db.QueryRow(c, _SelMaxID)
if err = row.Scan(&mID); err != nil {
log.Error("SelMaxID row.Scan() error(%v)", err)
return
}
return
}
//UpdateVipUserInfo update vip user info by id
func (d *Dao) UpdateVipUserInfo(tx *sql.Tx, r *model.VipUserInfo) (a int64, err error) {
var res xsql.Result
if res, err = tx.Exec(_UpdateVipUserInfoByID, r.PayChannelID, r.PayType, r.RecentTime, r.OverdueTime, r.AnnualVipOverdueTime, r.Type, r.Status, r.Mid); err != nil {
log.Error("UpdateVipUserInfo: db.Exec(%v) error(%v)", r, err)
return
}
if a, err = res.RowsAffected(); err != nil {
log.Error("UpdateVipUserInfo: res.RowsAffected error(%v)", err)
}
return
}
// UpdateVipUser update vip user info
func (d *Dao) UpdateVipUser(c context.Context, mid int64, status, vipType int8, payType int8) (eff int64, err error) {
var res xsql.Result
if res, err = d.oldDb.Exec(c, _updateVipUserSQL, status, vipType, payType, mid); err != nil {
err = errors.Wrapf(err, "d.UpdateVipStatus(%d)", mid)
return
}
if eff, err = res.RowsAffected(); err != nil {
err = errors.Wrapf(err, "d.UpdateVipStatus(%d) res.RowsAffected", mid)
}
return
}
//UpdateVipStatus update vip status info by mid
func (d *Dao) UpdateVipStatus(c context.Context, mid int64, status int) (eff int64, err error) {
var res xsql.Result
if res, err = d.db.Exec(c, _updateVipStatus, status, mid); err != nil {
err = errors.Wrapf(err, "d.UpdateVipStatus(%d)", mid)
return
}
if eff, err = res.RowsAffected(); err != nil {
err = errors.Wrapf(err, "d.UpdateVipStatus(%d) res.RowsAffected", mid)
}
return
}
// DupUserDiscountHistory add user discount history.
func (d *Dao) DupUserDiscountHistory(tx *sql.Tx, r *model.VipUserDiscountHistory) (a int64, err error) {
var res xsql.Result
if res, err = tx.Exec(_dupUserDiscountHistory, r.Mid, r.DiscountID, r.OrderNo, r.Status); err != nil {
err = errors.WithStack(err)
return
}
if a, err = res.RowsAffected(); err != nil {
err = errors.WithStack(err)
}
return
}
//AddUserInfo add user info.
func (d *Dao) AddUserInfo(tx *sql.Tx, r *model.VipUserInfo) (eff int64, err error) {
var res xsql.Result
if res, err = tx.Exec(_insertUserInfo, r.Mid, r.Type, r.PayType, r.Status, r.StartTime, r.RecentTime, r.OverdueTime, r.AnnualVipOverdueTime, r.PayChannelID, r.IosOverdueTime, r.Ver); err != nil {
log.Error("AddUserDiscountHistory d.db.exec(%v) error(%v)", r, err)
return
}
if eff, err = res.RowsAffected(); err != nil {
log.Error("AddUserDiscountHistory RowsAffected(%v)", err)
}
return
}
//SelVipUserInfo sel vipuser info
func (d *Dao) SelVipUserInfo(c context.Context, mid int64) (r *model.VipUserInfo, err error) {
var row = d.db.QueryRow(c, _selVipUserInfoByMid, mid)
r = new(model.VipUserInfo)
if err = row.Scan(&r.ID, &r.Mid, &r.Ver, &r.Type, &r.PayType, &r.Status, &r.StartTime, &r.OverdueTime, &r.AnnualVipOverdueTime, &r.RecentTime); err != nil {
if err == sql.ErrNoRows {
r = nil
err = nil
} else {
log.Error("row.Scan() error(%v)", err)
}
}
return
}
//UpdateUserInfo add user info
func (d *Dao) UpdateUserInfo(tx *sql.Tx, r *model.VipUserInfo) (eff int64, err error) {
var res xsql.Result
if res, err = tx.Exec(_updateUserInfo, r.Type, r.PayType, r.Status, r.StartTime, r.RecentTime, r.OverdueTime, r.AnnualVipOverdueTime, r.PayChannelID, r.IosOverdueTime, r.Ver, r.Mid, r.OldVer); err != nil {
err = errors.WithStack(err)
return
}
if eff, err = res.RowsAffected(); err != nil {
err = errors.WithStack(err)
}
return
}
//SelUserDiscountMaxID sel discount maxID
func (d *Dao) SelUserDiscountMaxID(c context.Context) (maxID int, err error) {
var row = d.db.QueryRow(c, _selDiscountMaxID)
if err = row.Scan(&maxID); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
return
}
return
}
//SelUserDiscountHistorys sel user discount hsitorys
func (d *Dao) SelUserDiscountHistorys(c context.Context, sID, eID, discountID int) (res []*model.VipUserDiscountHistory, err error) {
var rows *sql.Rows
if rows, err = d.db.Query(c, _SelUserDiscountHistorys, sID, eID, discountID); err != nil {
log.Error("SelUserDiscountHistorys d.db.query(sID:%d,eID:%d,discountID:%d) error(%+v)", sID, eID, discountID, err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipUserDiscountHistory)
if err = rows.Scan(&r.Mid, &r.DiscountID); err != nil {
log.Error("SelUserDiscountHistorys rows.scan() error(%v)", err)
res = nil
return
}
res = append(res, r)
}
return
}
//SelOldUserInfoMaxID sel old userinfo maxID
func (d *Dao) SelOldUserInfoMaxID(c context.Context) (maxID int, err error) {
var row = d.oldDb.QueryRow(c, _selUserInfoMaxID)
if err = row.Scan(&maxID); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
return
}
return
}
// SelUserInfoMaxID select userinfo maxID.
func (d *Dao) SelUserInfoMaxID(c context.Context) (maxID int, err error) {
var row = d.db.QueryRow(c, _selUserInfoMaxID)
if err = row.Scan(&maxID); err != nil {
err = errors.WithStack(err)
d.errProm.Incr("db_scan")
return
}
return
}
//SelUserInfos sel user infos
func (d *Dao) SelUserInfos(c context.Context, sID, eID int) (res []*model.VipUserInfo, err error) {
var rows *sql.Rows
if rows, err = d.db.Query(c, _SelVipUserInfos, sID, eID); err != nil {
log.Error("SelUserDiscountHistorys d.db.query(sID:%v,eID:%v) error(%v)", sID, eID, err)
return
}
for rows.Next() {
r := new(model.VipUserInfo)
if err = rows.Scan(&r.Mid, &r.Type, &r.PayType, &r.Status, &r.StartTime, &r.RecentTime, &r.OverdueTime, &r.AnnualVipOverdueTime); err != nil {
log.Error("SelUserDiscountHistorys rows.scan() error(%v)", err)
res = nil
return
}
res = append(res, r)
}
return
}
//SelVipList sel vipuserinfo list
func (d *Dao) SelVipList(c context.Context, id, endID int, ot string) (res []*model.VipUserInfo, err error) {
var rows *sql.Rows
if rows, err = d.oldDb.Query(c, _SelVipList, id, endID, ot); err != nil {
log.Error("SelVipList db.query(id:%v,ot:%v,endID:%v) error(%v)", id, ot, endID, err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipUserInfo)
if err = rows.Scan(&r.ID, &r.Mid, &r.Type, &r.Status, &r.OverdueTime, &r.AnnualVipOverdueTime, &r.PayType, &r.PayChannelID); err != nil {
log.Error("row.Scan() error(%v)", err)
res = nil
return
}
res = append(res, r)
}
return
}
//SelVipUsers .
func (d *Dao) SelVipUsers(c context.Context, id, endID int, startTime, endTime time.Time) (res []*model.VipUserInfo, err error) {
var rows *sql.Rows
if rows, err = d.db.Query(c, _selVipUsersSQL, id, endID, startTime, endTime); err != nil {
log.Error("SelVipList db.query(id:%v,endID:%v,st:%v,et:%v) error(%v)", id, endID, startTime, endTime, err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipUserInfo)
if err = rows.Scan(&r.ID, &r.Mid, &r.Type, &r.Status, &r.OverdueTime, &r.AnnualVipOverdueTime); err != nil {
log.Error("row.Scan() error(%v)", err)
res = nil
return
}
res = append(res, r)
}
return
}
//SelVipUserInfos sel vipuser info datas
func (d *Dao) SelVipUserInfos(c context.Context, id, endID int, startTime, endTime time.Time, status int) (res []int64, err error) {
var rows *sql.Rows
if rows, err = d.db.Query(c, _selVipUserInfoSQL, id, endID, status, startTime.Time().Format("2006-01-02"), endTime.Time().Format("2006-01-02")); err != nil {
log.Error("SelVipList db.query(id:%v,endID:%v,st:%v,et:%v) error(%v)", id, endID, startTime, endTime, err)
return
}
defer rows.Close()
for rows.Next() {
var r int64
if err = rows.Scan(&r); err != nil {
log.Error("row.Scan() error(%v)", err)
res = nil
return
}
res = append(res, r)
}
return
}
//OldVipInfo get old user by mid.
func (d *Dao) OldVipInfo(c context.Context, mid int64) (r *model.VipUserInfoOld, err error) {
var row = d.oldDb.QueryRow(c, _selOldVipUserInfo, mid)
r = new(model.VipUserInfoOld)
if err = row.Scan(&r.Mid, &r.Type, &r.IsAutoRenew, &r.AutoRenewed, &r.Status, &r.RecentTime, &r.StartTime, &r.OverdueTime,
&r.AnnualVipOverdueTime, &r.IosOverdueTime, &r.Ver, &r.PayChannelID); err != nil {
if err == sql.ErrNoRows {
r = nil
err = nil
} else {
err = errors.WithStack(err)
d.errProm.Incr("row_scan_db")
}
}
return
}
// SelEffectiveScopeVipList get vip list by id scope.
func (d *Dao) SelEffectiveScopeVipList(c context.Context, id, endID int) (res []*model.VipInfoDB, err error) {
var rows *sql.Rows
if rows, err = d.db.Query(c, _SelEffectiveScopeVipList, id, endID); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipInfoDB)
if err = rows.Scan(&r.ID, &r.Mid, &r.Ver, &r.Type, &r.PayType, &r.PayChannelID, &r.Status, &r.StartTime, &r.RecentTime, &r.OverdueTime, &r.AnnualVipOverdueTime,
&r.IosOverdueTime, &r.Ctime); err != nil {
err = errors.WithStack(err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}
// SelVipByIds select vip by ids .
func (d *Dao) SelVipByIds(c context.Context, ids []int64) (res map[int64]*model.VipUserInfo, err error) {
var (
rows *sql.Rows
idStr = xstr.JoinInts(ids)
)
res = make(map[int64]*model.VipUserInfo, len(ids))
if rows, err = d.db.Query(c, fmt.Sprintf(_selVipByMidsSQL, idStr)); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.VipUserInfo)
if err = rows.Scan(&r.ID, &r.Mid, &r.Type, &r.Status, &r.RecentTime, &r.StartTime, &r.OverdueTime, &r.AnnualVipOverdueTime, &r.PayType, &r.PayChannelID, &r.IosOverdueTime, &r.Ctime, &r.Mtime, &r.Ver); err != nil {
err = errors.WithStack(err)
res = nil
return
}
res[r.Mid] = r
}
return
}
//SelOldUserInfoMaps sel old user info map.
func (d *Dao) SelOldUserInfoMaps(c context.Context, sID, eID int) (res map[int64]*model.VipUserInfoOld, err error) {
var (
rows *sql.Rows
)
res = make(map[int64]*model.VipUserInfoOld, eID-sID)
if rows, err = d.oldDb.Query(c, _SelOldVipUserInfos, sID, eID); err != nil {
err = errors.WithStack(err)
return
}
for rows.Next() {
r := new(model.VipUserInfoOld)
if err = rows.Scan(&r.Mid, &r.Type, &r.IsAutoRenew, &r.AutoRenewed, &r.Status, &r.RecentTime, &r.StartTime, &r.OverdueTime, &r.AnnualVipOverdueTime, &r.Ver, &r.IosOverdueTime, &r.PayChannelID, &r.Ctime, &r.Mtime); err != nil {
err = errors.WithStack(err)
res = nil
return
}
res[r.Mid] = r
}
return
}

View File

@ -0,0 +1,408 @@
package dao
import (
"context"
"go-common/app/job/main/vip/model"
xtime "go-common/library/time"
"testing"
"time"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoAddChangeHistoryBatch(t *testing.T) {
convey.Convey("AddChangeHistoryBatch", t, func(ctx convey.C) {
var (
res = []*model.VipChangeHistory{}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.AddChangeHistoryBatch(res)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelChangeHistory(t *testing.T) {
convey.Convey("SelChangeHistory", t, func(ctx convey.C) {
var (
c = context.Background()
startID = int64(0)
endID = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelChangeHistory(c, startID, endID)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelOldChangeHistory(t *testing.T) {
convey.Convey("SelOldChangeHistory", t, func(ctx convey.C) {
var (
c = context.Background()
startID = int64(0)
endID = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelOldChangeHistory(c, startID, endID)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelOldChangeHistoryMaxID(t *testing.T) {
convey.Convey("SelOldChangeHistoryMaxID", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelOldChangeHistoryMaxID(c)
ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelChangeHistoryMaxID(t *testing.T) {
convey.Convey("SelChangeHistoryMaxID", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelChangeHistoryMaxID(c)
ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoVipStatus(t *testing.T) {
convey.Convey("VipStatus", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.VipStatus(c, mid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelMaxID(t *testing.T) {
convey.Convey("SelMaxID", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelMaxID(c)
ctx.Convey("Then err should be nil.mID should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoUpdateVipUserInfo(t *testing.T) {
convey.Convey("UpdateVipUserInfo", t, func(ctx convey.C) {
var (
r = &model.VipUserInfo{}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
tx, err := d.StartTx(context.Background())
ctx.So(err, convey.ShouldBeNil)
ctx.So(tx, convey.ShouldNotBeNil)
_, err = d.UpdateVipUserInfo(tx, r)
ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoUpdateVipUser(t *testing.T) {
convey.Convey("UpdateVipUser", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(0)
status = int8(0)
vipType = int8(0)
payType = int8(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.UpdateVipUser(c, mid, status, vipType, payType)
ctx.Convey("Then err should be nil.eff should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoDupUserDiscountHistory(t *testing.T) {
convey.Convey("DupUserDiscountHistory", t, func(ctx convey.C) {
var (
r = &model.VipUserDiscountHistory{}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
tx, err := d.StartTx(context.Background())
ctx.So(err, convey.ShouldBeNil)
ctx.So(tx, convey.ShouldNotBeNil)
_, err = d.DupUserDiscountHistory(tx, r)
ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoAddUserInfo(t *testing.T) {
convey.Convey("AddUserInfo", t, func(ctx convey.C) {
var (
r = &model.VipUserInfo{}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
tx, err := d.StartTx(context.Background())
ctx.So(err, convey.ShouldBeNil)
ctx.So(tx, convey.ShouldNotBeNil)
_, err = d.AddUserInfo(tx, r)
ctx.Convey("Then err should be nil.eff should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelVipUserInfo(t *testing.T) {
convey.Convey("SelVipUserInfo", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelVipUserInfo(c, mid)
ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoUpdateUserInfo(t *testing.T) {
convey.Convey("UpdateUserInfo", t, func(ctx convey.C) {
var (
r = &model.VipUserInfo{}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
tx, err := d.StartTx(context.Background())
ctx.So(err, convey.ShouldBeNil)
ctx.So(tx, convey.ShouldNotBeNil)
_, err = d.UpdateUserInfo(tx, r)
ctx.Convey("Then err should be nil.eff should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelUserDiscountMaxID(t *testing.T) {
convey.Convey("SelUserDiscountMaxID", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelUserDiscountMaxID(c)
ctx.Convey("Then err should be nil.maxID should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelUserDiscountHistorys(t *testing.T) {
convey.Convey("SelUserDiscountHistorys", t, func(ctx convey.C) {
var (
c = context.Background()
sID = int(0)
eID = int(0)
discountID = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelUserDiscountHistorys(c, sID, eID, discountID)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelOldUserInfoMaxID(t *testing.T) {
convey.Convey("SelOldUserInfoMaxID", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelOldUserInfoMaxID(c)
ctx.Convey("Then err should be nil.maxID should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelUserInfoMaxID(t *testing.T) {
convey.Convey("SelUserInfoMaxID", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelUserInfoMaxID(c)
ctx.Convey("Then err should be nil.maxID should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelUserInfos(t *testing.T) {
convey.Convey("SelUserInfos", t, func(ctx convey.C) {
var (
c = context.Background()
sID = int(0)
eID = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelUserInfos(c, sID, eID)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelVipList(t *testing.T) {
convey.Convey("SelVipList", t, func(ctx convey.C) {
var (
c = context.Background()
id = int(0)
endID = int(0)
ot = ""
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelVipList(c, id, endID, ot)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelVipUsers(t *testing.T) {
convey.Convey("SelVipUsers", t, func(ctx convey.C) {
var (
c = context.Background()
id = int(0)
endID = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelVipUsers(c, id, endID, xtime.Time(time.Now().Unix()), xtime.Time(time.Now().Unix()))
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelVipUserInfos(t *testing.T) {
convey.Convey("SelVipUserInfos", t, func(ctx convey.C) {
var (
c = context.Background()
id = int(0)
endID = int(0)
status = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelVipUserInfos(c, id, endID, xtime.Time(time.Now().Unix()), xtime.Time(time.Now().Unix()), status)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoOldVipInfo(t *testing.T) {
convey.Convey("OldVipInfo", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.OldVipInfo(c, mid)
ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelEffectiveScopeVipList(t *testing.T) {
convey.Convey("SelEffectiveScopeVipList", t, func(ctx convey.C) {
var (
c = context.Background()
id = int(0)
endID = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelEffectiveScopeVipList(c, id, endID)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSelOldUserInfoMaps(t *testing.T) {
convey.Convey("SelOldUserInfoMaps", t, func(ctx convey.C) {
var (
c = context.Background()
sID = int(0)
eID = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.SelOldUserInfoMaps(c, sID, eID)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func Test_SelChangeHistoryMaps(t *testing.T) {
convey.Convey("SelChangeHistoryMaps", t, func(ctx convey.C) {
_, err := d.SelChangeHistoryMaps(context.Background(), []int64{7593623})
ctx.So(err, convey.ShouldBeNil)
})
}
func Test_SelOldChangeHistoryMaps(t *testing.T) {
convey.Convey("SelOldChangeHistoryMaps", t, func(ctx convey.C) {
_, err := d.SelOldChangeHistoryMaps(context.Background(), []int64{7593623})
ctx.So(err, convey.ShouldBeNil)
})
}
func Test_SelVipByIds(t *testing.T) {
convey.Convey("SelVipByIds", t, func(ctx convey.C) {
_, err := d.SelVipByIds(context.Background(), []int64{7593623})
ctx.So(err, convey.ShouldBeNil)
})
}