@@ -1,6 +1,6 @@ | |||
# 多重构建,减少镜像大小 | |||
# 构建:使用golang:1.15版本 | |||
FROM golang:1.15 as build | |||
FROM registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/golang:1.18.4 as build | |||
# 容器环境变量添加,会覆盖默认的变量值 | |||
ENV GO111MODULE=on | |||
@@ -1,6 +1,6 @@ | |||
# 多重构建,减少镜像大小 | |||
# 构建:使用golang:1.15版本 | |||
FROM golang:1.15 as build | |||
FROM registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/golang:1.18.4 as build | |||
# 容器环境变量添加,会覆盖默认的变量值 | |||
ENV GO111MODULE=on | |||
@@ -13,7 +13,7 @@ WORKDIR /go/release | |||
ADD . . | |||
# 编译:把main.go编译成可执行的二进制文件,命名为zyos | |||
RUN GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -tags netgo -ldflags="-s -w" -installsuffix cgo -o zyos_mall_task cmd/task/main.go | |||
RUN GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -tags netgo -ldflags="-s -w" -installsuffix cgo -o zhimeng_task cmd/task/main.go | |||
FROM ubuntu:xenial as prod | |||
LABEL maintainer="wuhanqin" | |||
@@ -25,10 +25,10 @@ RUN rm -f /etc/localtime \ | |||
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ | |||
&& echo "Asia/Shanghai" > /etc/timezone | |||
# 在build阶段复制可执行的go二进制文件app | |||
COPY --from=build /go/release/zyos_mall_task ./zyos_mall_task | |||
COPY --from=build /go/release/zhimeng_task ./zhimeng_task | |||
COPY --from=build /go/release/etc/task.yml /var/zyos/task.yml | |||
# 启动服务 | |||
CMD ["./zyos_mall_task","-c","/var/zyos/task.yml"] | |||
CMD ["./zhimeng_task","-c","/var/zyos/task.yml"] | |||
@@ -10,7 +10,9 @@ type Config struct { | |||
SrvAddr string `yaml:"srv_addr"` | |||
RedisAddr string `yaml:"redis_addr"` | |||
DB DBCfg `yaml:"db"` | |||
ZhimengDB DBCfg `yaml:"zhimeng_db"` | |||
Log LogCfg `yaml:"log"` | |||
ES ESCfg `yaml:"es"` | |||
} | |||
//数据库配置结构体 | |||
@@ -40,3 +42,8 @@ type LogCfg struct { | |||
FileMaxSize int `yaml:"file_max_size"` | |||
FileMaxAge int `yaml:"file_max_age"` | |||
} | |||
type ESCfg struct { | |||
Url string `yaml:"url"` | |||
User string `yaml:"user"` | |||
Pwd string `yaml:"pwd"` | |||
} |
@@ -14,7 +14,9 @@ var ( | |||
SrvAddr string | |||
RedisAddr string | |||
DB *DBCfg | |||
ZhimengDB *DBCfg | |||
Log *LogCfg | |||
ES *ESCfg | |||
) | |||
//初始化配置文件,将cfg.yml读入到内存 | |||
@@ -40,6 +42,8 @@ func InitCfg() { | |||
Prd = conf.Prd | |||
Debug = conf.Debug | |||
DB = &conf.DB | |||
ZhimengDB = &conf.ZhimengDB | |||
ES = &conf.ES | |||
Log = &conf.Log | |||
RedisAddr = conf.RedisAddr | |||
SrvAddr = conf.SrvAddr | |||
@@ -0,0 +1,13 @@ | |||
package cfg | |||
import ( | |||
"applet/app/utils" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" | |||
"encoding/json" | |||
) | |||
func InitEs() { | |||
data, _ := json.Marshal(ES) | |||
utils.FilePutContents("init_es", string(data)) | |||
es.Init(ES.Url, ES.User, ES.Pwd) | |||
} |
@@ -27,8 +27,10 @@ func InitTaskCfg() { | |||
Prd = conf.Prd | |||
Debug = conf.Debug | |||
DB = &conf.DB | |||
ZhimengDB = &conf.ZhimengDB | |||
Log = &conf.Log | |||
RedisAddr = conf.RedisAddr | |||
ES = &conf.ES | |||
} | |||
var MemCache mc.Cache | |||
@@ -1,39 +0,0 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
type AdminDb struct { | |||
Db *xorm.Engine `json:"db"` | |||
} | |||
func (adminDb *AdminDb) Set() { // set方法 | |||
adminDb.Db = Db | |||
} | |||
func (adminDb *AdminDb) GetAdmin(id int) (m *model.Admin, err error) { | |||
m = new(model.Admin) | |||
has, err := adminDb.Db.Where("adm_id =?", id).Get(m) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if has == false { | |||
return nil, nil | |||
} | |||
return m, nil | |||
} | |||
func (adminDb *AdminDb) GetAdminByUserName(userName string) (m *model.Admin, err error) { | |||
m = new(model.Admin) | |||
has, err := adminDb.Db.Where("username =?", userName).Get(m) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if has == false { | |||
return nil, nil | |||
} | |||
return m, nil | |||
} |
@@ -0,0 +1,89 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/md" | |||
"applet/app/utils/cache" | |||
"applet/app/utils/logx" | |||
"fmt" | |||
"xorm.io/xorm" | |||
) | |||
type MasterListCfgDb struct { | |||
Db *xorm.Engine `json:"db"` | |||
} | |||
func (masterListCfgDb *MasterListCfgDb) Set() { // set方法 | |||
masterListCfgDb.Db = ZhimengDb | |||
} | |||
func (masterListCfgDb *MasterListCfgDb) MasterListCfgGetAll() (*[]model.MasterListCfg, error) { | |||
var cfgList []model.MasterListCfg | |||
if err := Db.Cols("k,v,memo").Find(&cfgList); err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
return &cfgList, nil | |||
} | |||
func (masterListCfgDb *MasterListCfgDb) MasterListCfgGetCron() (*[]model.MasterListCfg, error) { | |||
var cfgList []model.MasterListCfg | |||
if err := Db.Where("`k` LIKE 'zhimeng_cron\\_%' AND v != ''").Cols("k,v,memo").Find(&cfgList); err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
return &cfgList, nil | |||
} | |||
func (masterListCfgDb *MasterListCfgDb) MasterListCfgGetOneNoDataNoErr(key string) (*model.MasterListCfg, error) { | |||
var cfgList model.MasterListCfg | |||
has, err := Db.Where("`k`=?", key).Get(&cfgList) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if !has { | |||
return nil, nil | |||
} | |||
return &cfgList, nil | |||
} | |||
func (masterListCfgDb *MasterListCfgDb) MasterListCfgGetOne(uid, key string) (*model.MasterListCfg, error) { | |||
var cfgList model.MasterListCfg | |||
if has, err := Db.Where("`k`=? and uid=?", key, uid).Get(&cfgList); err != nil || has == false { | |||
return nil, logx.Error(err) | |||
} | |||
return &cfgList, nil | |||
} | |||
func (masterListCfgDb *MasterListCfgDb) MasterListCfgGetOneData(uid, key string) string { | |||
var cfgList model.MasterListCfg | |||
if has, err := Db.Where("`k`=? and uid=?", key, uid).Get(&cfgList); err != nil || has == false { | |||
return "" | |||
} | |||
return cfgList.V | |||
} | |||
func (masterListCfgDb *MasterListCfgDb) MasterListCfgInsert(uid, key, val, memo string) bool { | |||
cfg := model.MasterListCfg{Uid: uid, K: key, V: val, Memo: memo} | |||
_, err := Db.InsertOne(&cfg) | |||
if err != nil { | |||
logx.Error(err) | |||
return false | |||
} | |||
return true | |||
} | |||
func (masterListCfgDb *MasterListCfgDb) MasterListCfgUpdate(uid, key, val string) bool { | |||
cfg := model.MasterListCfg{K: key, V: val} | |||
_, err := Db.Where("`k`=? and uid=?", key, uid).Cols("val").Update(&cfg) | |||
if err != nil { | |||
logx.Error(err) | |||
return false | |||
} | |||
masterListCfgDb.MasterListCfgDel(key) | |||
return true | |||
} | |||
func (masterListCfgDb *MasterListCfgDb) MasterListCfgDel(HKey string) error { | |||
cacheKey := fmt.Sprintf(md.AppCfgCacheKey, HKey[0:1]) | |||
_, err := cache.HDel(cacheKey, HKey) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} |
@@ -0,0 +1,70 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"xorm.io/xorm" | |||
) | |||
type PlayletSaleOrderDb struct { | |||
Db *xorm.Engine `json:"db"` | |||
} | |||
func (playletSaleOrderDb *PlayletSaleOrderDb) Set() { // set方法 | |||
playletSaleOrderDb.Db = ZhimengDb | |||
} | |||
func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderByOid(oid, ordType string) *model.PlayletSaleOrder { | |||
var data model.PlayletSaleOrder | |||
get, err := playletSaleOrderDb.Db.Where("oid=? and ord_type=?", oid, ordType).Get(&data) | |||
if get == false || err != nil { | |||
return nil | |||
} | |||
return &data | |||
} | |||
func (playletSaleOrderDb *PlayletSaleOrderDb) PlayletVideoOrderUpdate(id int, data *model.PlayletSaleOrder) bool { | |||
get, err := playletSaleOrderDb.Db.Where("id=?", id).Update(data) | |||
if get == 0 || err != nil { | |||
return false | |||
} | |||
return true | |||
} | |||
func (playletSaleOrderDb *PlayletSaleOrderDb) PlayletVideoOrderInsert(data *model.PlayletSaleOrder) bool { | |||
get, err := playletSaleOrderDb.Db.InsertOne(data) | |||
if get == 0 || err != nil { | |||
return false | |||
} | |||
return true | |||
} | |||
func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderList(args map[string]string) []model.PlayletSaleOrder { | |||
/*** | |||
p 页数 | |||
size 个数 | |||
start_time 开始时间 | |||
end_time 结束时间 | |||
ord_type 订单类型 | |||
video_type 视频类型 | |||
*/ | |||
var data = make([]model.PlayletSaleOrder, 0) | |||
size := utils.StrToInt(args["size"]) | |||
offet := (utils.StrToInt(args["p"]) - 1) * size | |||
sess := playletSaleOrderDb.Db.Where("uid=?", args["mid"]) | |||
if args["start_time"] != "" { | |||
sess = sess.And("update_time>=?", args["start_time"]) | |||
} | |||
if args["end_time"] != "" { | |||
sess = sess.And("update_time>=?", args["end_time"]) | |||
} | |||
if args["ord_type"] != "" { | |||
sess = sess.And("ord_type=?", args["ord_type"]) | |||
} | |||
if args["video_type"] != "" { | |||
sess = sess.And("video_type=?", args["video_type"]) | |||
} | |||
sess.Limit(size, offet).OrderBy("update_time desc,id desc").Find(&data) | |||
return data | |||
} |
@@ -1,63 +0,0 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/enum" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
type QrcodeDb struct { | |||
Db *xorm.Engine `json:"db"` | |||
} | |||
func (qrcodeDb *QrcodeDb) Set() { // set方法 | |||
qrcodeDb.Db = Db | |||
} | |||
func (qrcodeDb *QrcodeDb) GetQrcode(id int) (m *model.Qrcode, err error) { | |||
m = new(model.Qrcode) | |||
has, err := qrcodeDb.Db.Where("id =?", id).Get(m) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if has == false { | |||
return nil, nil | |||
} | |||
return m, nil | |||
} | |||
func (qrcodeDb *QrcodeDb) GetQrcodeForAllowUse() (m *model.Qrcode, err error) { | |||
m = new(model.Qrcode) | |||
has, err := qrcodeDb.Db.Where("state =?", enum.QrcodeSateAllowUse).Get(m) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if has == false { | |||
return nil, nil | |||
} | |||
return m, nil | |||
} | |||
func (qrcodeDb *QrcodeDb) FindQrcodeForAllowUse() (m []*model.Qrcode, total int64, err error) { | |||
total, err = qrcodeDb.Db.Where("state =?", enum.QrcodeSateAllowUse).FindAndCount(&m) | |||
return | |||
} | |||
func (qrcodeDb *QrcodeDb) BatchAddQrcode(data []*model.Qrcode) (int64, error) { | |||
affected, err := qrcodeDb.Db.Insert(data) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
func (qrcodeDb *QrcodeDb) BatchUpdateQrcodeBySession(session *xorm.Session, ids []int, state int32) (int64, error) { | |||
m := new(model.Qrcode) | |||
m.State = state | |||
affected, err := session.In("id", ids).Cols("state").Update(m) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} |
@@ -1,67 +0,0 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
type QrcodeBatchDb struct { | |||
Db *xorm.Engine `json:"db"` | |||
} | |||
func (qrcodeBatchDb *QrcodeBatchDb) Set() { // set方法 | |||
qrcodeBatchDb.Db = Db | |||
} | |||
func (qrcodeBatchDb *QrcodeBatchDb) GetQrcodeBatchById(id int) (m *model.QrcodeBatch, err error) { | |||
m = new(model.QrcodeBatch) | |||
has, err := qrcodeBatchDb.Db.Where("id =?", id).Get(m) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if has == false { | |||
return nil, nil | |||
} | |||
return m, nil | |||
} | |||
func (qrcodeBatchDb *QrcodeBatchDb) DeleteQrcodeBatchBySession(session *xorm.Session, id int) (delResult int64, err error) { | |||
m := new(model.QrcodeBatch) | |||
delResult, err = session.Where("id =?", id).Delete(m) | |||
return | |||
} | |||
func (qrcodeBatchDb *QrcodeBatchDb) GeLastId() (m *model.QrcodeBatch, err error) { | |||
m = new(model.QrcodeBatch) | |||
has, err := qrcodeBatchDb.Db.OrderBy("id Desc").Get(m) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if has == false { | |||
return nil, nil | |||
} | |||
return m, nil | |||
} | |||
func (qrcodeBatchDb *QrcodeBatchDb) GetQrcodeBatchByName(name string) (m *model.QrcodeBatch, err error) { | |||
m = new(model.QrcodeBatch) | |||
has, err := qrcodeBatchDb.Db.Where("name =?", name).Get(m) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if has == false { | |||
return nil, nil | |||
} | |||
return m, nil | |||
} | |||
func (qrcodeBatchDb *QrcodeBatchDb) List(page, limit int) (m []*model.QrcodeBatch, total int64, err error) { | |||
total, err = qrcodeBatchDb.Db.Desc("id").Limit(limit, (page-1)*limit).FindAndCount(&m) | |||
return | |||
} | |||
func (qrcodeBatchDb *QrcodeBatchDb) AddBySession(session *xorm.Session, m *model.QrcodeBatch) (err error) { | |||
_, err = session.InsertOne(m) | |||
return | |||
} |
@@ -1,66 +0,0 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
type QrcodeWithBatchRecordsDb struct { | |||
Db *xorm.Engine `json:"db"` | |||
} | |||
func (qrcodeWithBatchRecordsDb *QrcodeWithBatchRecordsDb) Set() { // set方法 | |||
qrcodeWithBatchRecordsDb.Db = Db | |||
} | |||
func (qrcodeWithBatchRecordsDb *QrcodeWithBatchRecordsDb) GetQrcodeWithBatchRecordsById(id int) (m *model.QrcodeWithBatchRecords, err error) { | |||
m = new(model.QrcodeWithBatchRecords) | |||
has, err := qrcodeWithBatchRecordsDb.Db.Where("id =?", id).Get(m) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if has == false { | |||
return nil, nil | |||
} | |||
return m, nil | |||
} | |||
func (qrcodeWithBatchRecordsDb *QrcodeWithBatchRecordsDb) FindQrcodeWithBatchRecordsByState(state int32) (m []*model.QrcodeWithBatchRecords, err error) { | |||
err = qrcodeWithBatchRecordsDb.Db.Where("state =?", state).Find(&m) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
return m, nil | |||
} | |||
func (qrcodeWithBatchRecordsDb *QrcodeWithBatchRecordsDb) BatchAddQrcodeWithBatchRecordsBySession(session *xorm.Session, data []*model.QrcodeWithBatchRecords) (int64, error) { | |||
affected, err := session.Insert(data) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
func (qrcodeWithBatchRecordsDb *QrcodeWithBatchRecordsDb) FindQrcodeWithBatchRecordsById(batchId int) (m []*model.QrcodeWithBatchRecords, total int64, err error) { | |||
total, err = qrcodeWithBatchRecordsDb.Db.Where("batch_id =?", batchId).FindAndCount(&m) | |||
return | |||
} | |||
func (qrcodeWithBatchRecordsDb *QrcodeWithBatchRecordsDb) DeleteQrcodeWithBatchRecordsBySession(session *xorm.Session, batchId int) (delResult int64, err error) { | |||
m := new(model.QrcodeWithBatchRecords) | |||
delResult, err = session.Where("batch_id =?", batchId).Delete(m) | |||
return | |||
} | |||
type QrcodeWithBatchRecords struct { | |||
model.QrcodeWithBatchRecords `xorm:"extends"` | |||
model.Qrcode `xorm:"extends"` | |||
} | |||
func (qrcodeWithBatchRecordsDb *QrcodeWithBatchRecordsDb) FindQrcodeWithBatchRecordsLeftJoinQrcode(batchId int) (m []*QrcodeWithBatchRecords, total int64, err error) { | |||
total, err = qrcodeWithBatchRecordsDb.Db.Where("batch_id =?", batchId). | |||
Join("LEFT", "qrcode", "qrcode_with_batch_records.qrcode_id = qrcode.id"). | |||
FindAndCount(&m) | |||
return | |||
} |
@@ -14,20 +14,26 @@ type SysCfgDb struct { | |||
} | |||
func (sysCfgDb *SysCfgDb) Set() { // set方法 | |||
sysCfgDb.Db = Db | |||
sysCfgDb.Db = ZhimengDb | |||
} | |||
func (sysCfgDb *SysCfgDb) SysCfgGetAll() (*[]model.SysCfg, error) { | |||
var cfgList []model.SysCfg | |||
if err := Db.Cols("key,val,memo").Find(&cfgList); err != nil { | |||
if err := Db.Cols("k,v,memo").Find(&cfgList); err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
return &cfgList, nil | |||
} | |||
func (sysCfgDb *SysCfgDb) SysCfgGetCron() (*[]model.SysCfg, error) { | |||
var cfgList []model.SysCfg | |||
if err := Db.Where("`k` LIKE 'zhimeng_cron\\_%' AND v != ''").Cols("k,v,memo").Find(&cfgList); err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
return &cfgList, nil | |||
} | |||
func (sysCfgDb *SysCfgDb) SysCfgGetOneNoDataNoErr(key string) (*model.SysCfg, error) { | |||
var cfgList model.SysCfg | |||
has, err := Db.Where("`key`=?", key).Get(&cfgList) | |||
has, err := Db.Where("`k`=?", key).Get(&cfgList) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
@@ -39,14 +45,21 @@ func (sysCfgDb *SysCfgDb) SysCfgGetOneNoDataNoErr(key string) (*model.SysCfg, er | |||
func (sysCfgDb *SysCfgDb) SysCfgGetOne(key string) (*model.SysCfg, error) { | |||
var cfgList model.SysCfg | |||
if has, err := Db.Where("`key`=?", key).Get(&cfgList); err != nil || has == false { | |||
if has, err := Db.Where("`k`=?", key).Get(&cfgList); err != nil || has == false { | |||
return nil, logx.Error(err) | |||
} | |||
return &cfgList, nil | |||
} | |||
func (sysCfgDb *SysCfgDb) SysCfgGetOneData(key string) string { | |||
var cfgList model.SysCfg | |||
if has, err := Db.Where("`k`=?", key).Get(&cfgList); err != nil || has == false { | |||
return "" | |||
} | |||
return cfgList.V | |||
} | |||
func (sysCfgDb *SysCfgDb) SysCfgInsert(key, val, memo string) bool { | |||
cfg := model.SysCfg{Key: key, Val: val, Memo: memo} | |||
cfg := model.SysCfg{K: key, V: val, Memo: memo} | |||
_, err := Db.InsertOne(&cfg) | |||
if err != nil { | |||
logx.Error(err) | |||
@@ -56,7 +69,7 @@ func (sysCfgDb *SysCfgDb) SysCfgInsert(key, val, memo string) bool { | |||
} | |||
func (sysCfgDb *SysCfgDb) SysCfgUpdate(key, val string) bool { | |||
cfg := model.SysCfg{Key: key, Val: val} | |||
cfg := model.SysCfg{K: key, V: val} | |||
_, err := Db.Where("`key`=?", key).Cols("val").Update(&cfg) | |||
if err != nil { | |||
logx.Error(err) | |||
@@ -83,7 +96,7 @@ func (sysCfgDb *SysCfgDb) SysCfgGetWithDb(HKey string) string { | |||
} | |||
// 设置缓存 | |||
_, err = cache.HSet(cacheKey, HKey, cfg.Val) | |||
_, err = cache.HSet(cacheKey, HKey, cfg.V) | |||
if err != nil { | |||
_ = logx.Error(err) | |||
return "" | |||
@@ -95,7 +108,7 @@ func (sysCfgDb *SysCfgDb) SysCfgGetWithDb(HKey string) string { | |||
return "" | |||
} | |||
} | |||
return cfg.Val | |||
return cfg.V | |||
} | |||
return get | |||
} | |||
@@ -1,27 +0,0 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
type UserFollowWxOfficialAccountDb struct { | |||
Db *xorm.Engine `json:"db"` | |||
} | |||
func (userFollowWxOfficialAccountDb *UserFollowWxOfficialAccountDb) Set() { // set方法 | |||
userFollowWxOfficialAccountDb.Db = Db | |||
} | |||
func (userFollowWxOfficialAccountDb *UserFollowWxOfficialAccountDb) GetUserFollowWxOfficialAccountByOpenId(openId string) (m *model.UserFollowWxOfficialAccount, err error) { | |||
m = new(model.UserFollowWxOfficialAccount) | |||
has, err := userFollowWxOfficialAccountDb.Db.Where("user_wx_open_id =?", openId).Get(m) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if has == false { | |||
return nil, nil | |||
} | |||
return m, nil | |||
} |
@@ -1,47 +0,0 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
type UserUseQrcodeRecordsDb struct { | |||
Db *xorm.Engine `json:"db"` | |||
} | |||
func (userUseQrcodeRecordsDb *UserUseQrcodeRecordsDb) Set() { // set方法 | |||
userUseQrcodeRecordsDb.Db = Db | |||
} | |||
func (userUseQrcodeRecordsDb *UserUseQrcodeRecordsDb) GetUserUseQrcodeRecordsById(recordsId int) (m *model.UserUseQrcodeRecords, err error) { | |||
m = new(model.UserUseQrcodeRecords) | |||
has, err := userUseQrcodeRecordsDb.Db.Where("records_id =?", recordsId).Get(m) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if has == false { | |||
return nil, nil | |||
} | |||
return m, nil | |||
} | |||
func (userUseQrcodeRecordsDb *UserUseQrcodeRecordsDb) GetUserUseQrcodeRecordsByOpenId(openId string) (m *model.UserUseQrcodeRecords, err error) { | |||
m = new(model.UserUseQrcodeRecords) | |||
has, err := userUseQrcodeRecordsDb.Db.Where("user_wx_open_id =?", openId).Get(m) | |||
if err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if has == false { | |||
return nil, nil | |||
} | |||
return m, nil | |||
} | |||
func (userUseQrcodeRecordsDb *UserUseQrcodeRecordsDb) InsertUserUseQrcodeRecords(m *model.UserUseQrcodeRecords) (int64, error) { | |||
_, err := userUseQrcodeRecordsDb.Db.InsertOne(m) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return m.Id, nil | |||
} |
@@ -1,10 +0,0 @@ | |||
package model | |||
type Admin struct { | |||
AdmId int `json:"adm_id" xorm:"not null comment('管理员id') INT(11)"` | |||
Username string `json:"username" xorm:"not null default '' comment('用户名') VARCHAR(255)"` | |||
Password string `json:"password" xorm:"not null default '' comment('密码') VARCHAR(255)"` | |||
State int32 `json:"state" xorm:"not null default 1 comment('状态') TINYINT(1)"` | |||
CreateAt string `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
UpdateAt string `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` | |||
} |
@@ -0,0 +1,8 @@ | |||
package model | |||
type MasterListCfg struct { | |||
K string `json:"k" xorm:"not null pk comment('键') VARCHAR(127)"` | |||
V string `json:"v" xorm:"comment('值') TEXT"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(255)"` | |||
Uid string `json:"uid" xorm:"not null default '' comment('') VARCHAR(255)"` | |||
} |
@@ -0,0 +1,32 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type PlayletSaleOrder struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid string `json:"uid" xorm:"default '' comment('用户id') VARCHAR(255)"` | |||
SubUid int `json:"sub_uid" xorm:"default 0 comment('') INT(11)"` | |||
Data string `json:"data" xorm:"comment('第三方返回数据') VARCHAR(5000)"` | |||
Oid string `json:"oid" xorm:"comment('订单号') VARCHAR(255)"` | |||
Amount string `json:"amount" xorm:"default 0.00 comment('金额') DECIMAL(20,2)"` | |||
Commission string `json:"commission" xorm:"default 0.00 comment('佣金') DECIMAL(20,2)"` | |||
PlatformFee string `json:"platform_fee" xorm:"default 0.00 comment('佣金') DECIMAL(20,2)"` | |||
Fee string `json:"fee" xorm:"default 0.00 comment('佣金') DECIMAL(20,2)"` | |||
Status string `json:"status" xorm:"comment('状态') VARCHAR(255)"` | |||
CreateTime time.Time `json:"create_time" xorm:"comment('下单时间') DATETIME"` | |||
RefundTime time.Time `json:"refund_time" xorm:"comment('退款时间') DATETIME"` | |||
UpdateTime time.Time `json:"update_time" xorm:"comment('广告统计更新时间') DATETIME"` | |||
PlatformSettleTime time.Time `json:"platform_settle_time" xorm:"comment('广告统计更新时间') DATETIME"` | |||
Title string `json:"title" xorm:"comment('标题') VARCHAR(255)"` | |||
VideoType string `json:"video_type" xorm:"comment('视频类型') VARCHAR(255)"` | |||
PlatformType string `json:"platform_type" xorm:"comment('平台类型') VARCHAR(255)"` | |||
GoodsType string `json:"goods_type" xorm:"comment('商品数据') VARCHAR(255)"` | |||
SettleTime int `json:"settle_time" xorm:"default 0 INT(11)"` | |||
OrdType string `json:"ord_type" xorm:"VARCHAR(255)"` | |||
TimesNum string `json:"times_num" xorm:"VARCHAR(255)"` | |||
PeopleNum string `json:"people_num" xorm:"VARCHAR(255)"` | |||
CustomOid string `json:"custom_oid" xorm:"VARCHAR(255)"` | |||
ExtendUid string `json:"extend_uid" xorm:"VARCHAR(255)"` | |||
} |
@@ -1,10 +0,0 @@ | |||
package model | |||
type Qrcode struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Url string `json:"url" xorm:"not null default '' comment('url地址') VARCHAR(255)"` | |||
State int32 `json:"state" xorm:"not null default 1 comment('状态(1:可用 2:不可用) ') TINYINT(1)"` | |||
Index string `json:"index" xorm:"not null default '' comment('唯一标识符(随机6位字母+数字)') CHAR(50)"` | |||
CreateAt string `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
UpdateAt string `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` | |||
} |
@@ -1,13 +0,0 @@ | |||
package model | |||
type QrcodeBatch struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Name string `json:"name" xorm:"not null default '' comment('名称') VARCHAR(255)"` | |||
TotalNum int `json:"total_num" xorm:"not null default 0' comment('总数量') INT(11)"` | |||
TotalAmount string `json:"total_amount" xorm:"not null default 0.00 comment('总金额') DECIMAL(6,2)"` | |||
State int32 `json:"state" xorm:"not null default 1 comment('状态(1:使用中 2:使用完 3:已过期 4:已作废)') TINYINT(1)"` | |||
ExpireDate string `json:"expire_date" xorm:"not null default 0000-00-00 comment('截止日期') CHAR(50)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(255)"` | |||
CreateAt string `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
UpdateAt string `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` | |||
} |
@@ -1,11 +0,0 @@ | |||
package model | |||
type QrcodeWithBatchRecords struct { | |||
Id int64 `json:"id" xorm:"not null pk autoincr BIGINT(32)"` | |||
QrcodeId int `json:"qrcode_id" xorm:"not null default 0' comment('二维码id') INT(11)"` | |||
BatchId int `json:"batch_id" xorm:"not null default 0' comment('批次id') INT(11)"` | |||
Amount string `json:"amount" xorm:"not null default 0.00 comment('金额') DECIMAL(6,2)"` | |||
State int32 `json:"state" xorm:"not null default 1 comment('状态(1:待使用 2:已使用 3:已过期 4:已作废)') TINYINT(1)"` | |||
CreateAt string `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
UpdateAt string `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` | |||
} |
@@ -1,7 +1,7 @@ | |||
package model | |||
type SysCfg struct { | |||
Key string `json:"key" xorm:"not null pk comment('键') VARCHAR(127)"` | |||
Val string `json:"val" xorm:"comment('值') TEXT"` | |||
K string `json:"k" xorm:"not null pk comment('键') VARCHAR(127)"` | |||
V string `json:"v" xorm:"comment('值') TEXT"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(255)"` | |||
} |
@@ -1,8 +0,0 @@ | |||
package model | |||
type UserFollowWxOfficialAccount struct { | |||
Id int64 `json:"id" xorm:"not null pk autoincr BIGINT(32)"` | |||
UserWxOpenId string `json:"user_wx_open_id" xorm:"not null default '' comment('用户微信open_id') VARCHAR(255)"` | |||
CreateAt string `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
UpdateAt string `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` | |||
} |
@@ -1,10 +0,0 @@ | |||
package model | |||
type UserUseQrcodeRecords struct { | |||
Id int64 `json:"id" xorm:"not null pk autoincr BIGINT(32)"` | |||
UserWxOpenId string `json:"user_wx_open_id" xorm:"not null default '' comment('用户微信open_id') VARCHAR(255)"` | |||
RecordsId int64 `json:"records_id" xorm:"not null default 0 comment('二维码记录id') BIGINT(32)"` | |||
State int32 `json:"state" xorm:"not null default 1 comment('状态(0:未发送 1:已发送 2:发送失败)') TINYINT(1)"` | |||
CreateAt string `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
UpdateAt string `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` | |||
} |
@@ -0,0 +1,42 @@ | |||
package db | |||
import ( | |||
"fmt" | |||
"os" | |||
_ "github.com/go-sql-driver/mysql" | |||
"xorm.io/xorm" | |||
"xorm.io/xorm/log" | |||
"applet/app/cfg" | |||
) | |||
var ZhimengDb *xorm.Engine | |||
func InitZhimengDB(c *cfg.DBCfg) error { | |||
var err error | |||
if ZhimengDb, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4", c.User, c.Psw, c.Host, c.Name)); err != nil { | |||
return err | |||
} | |||
ZhimengDb.SetConnMaxLifetime(c.MaxLifetime) | |||
ZhimengDb.SetMaxOpenConns(c.MaxOpenConns) | |||
ZhimengDb.SetMaxIdleConns(c.MaxIdleConns) | |||
if err = Db.Ping(); err != nil { | |||
return err | |||
} | |||
if c.ShowLog { | |||
ZhimengDb.ShowSQL(true) | |||
ZhimengDb.Logger().SetLevel(0) | |||
f, err := os.OpenFile(c.Path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777) | |||
if err != nil { | |||
os.RemoveAll(c.Path) | |||
if f, err = os.OpenFile(c.Path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777); err != nil { | |||
return err | |||
} | |||
} | |||
logger := log.NewSimpleLogger(f) | |||
logger.ShowSQL(true) | |||
ZhimengDb.SetLogger(logger) | |||
} | |||
return nil | |||
} |
@@ -0,0 +1,173 @@ | |||
package md | |||
const ZhiosLianlianProductEsIndex = "zhios_lianlian_product" | |||
const ZhiosLianlianProductEsIndexProd = "zhios_lianlian_product_prod" | |||
const ZhiosLianlianProductEsMapping = ` | |||
{ | |||
"settings" : { | |||
"number_of_shards" : 2, | |||
"number_of_replicas" : 1 | |||
}, | |||
"mappings":{ | |||
"properties":{ | |||
"id":{ | |||
"type": "integer" | |||
}, | |||
"locationIds":{ | |||
"type": "keyword" | |||
}, | |||
"shopKey":{ | |||
"type": "keyword" | |||
}, | |||
"locationId":{ | |||
"type": "integer" | |||
}, | |||
"productTitle":{ | |||
"type": "text", | |||
"analyzer": "ik_smart" | |||
}, | |||
"faceImg":{ | |||
"type": "keyword" | |||
}, | |||
"address":{ | |||
"type": "keyword" | |||
}, | |||
"tel":{ | |||
"type": "keyword" | |||
}, | |||
"endTime":{ | |||
"type": "integer" | |||
}, | |||
"beginTime":{ | |||
"type": "integer" | |||
}, | |||
"validEndDate":{ | |||
"type": "integer" | |||
}, | |||
"validBeginDate":{ | |||
"type": "integer" | |||
}, | |||
"singleMin":{ | |||
"type": "integer" | |||
}, | |||
"singleMax":{ | |||
"type": "integer" | |||
}, | |||
"channelStock":{ | |||
"type": "integer" | |||
}, | |||
"stock":{ | |||
"type": "integer" | |||
}, | |||
"saleAmount":{ | |||
"type": "integer" | |||
}, | |||
"itemStock":{ | |||
"type": "integer" | |||
}, | |||
"bookingType":{ | |||
"type": "integer" | |||
}, | |||
"bookingBeginDate":{ | |||
"type": "integer" | |||
}, | |||
"bookingShowAddress":{ | |||
"type": "integer" | |||
}, | |||
"orderShowIdCard":{ | |||
"type": "integer" | |||
}, | |||
"orderShowDate":{ | |||
"type": "integer" | |||
}, | |||
"bookingText":{ | |||
"type": "keyword" | |||
}, | |||
"attention":{ | |||
"type": "keyword" | |||
}, | |||
"soldOutTime":{ | |||
"type": "integer" | |||
}, | |||
"isSoldOut":{ | |||
"type": "integer" | |||
}, | |||
"city":{ | |||
"type": "text", | |||
"analyzer": "ik_smart" | |||
}, | |||
"cityCode":{ | |||
"type": "keyword" | |||
}, | |||
"latitude":{ | |||
"type": "double" | |||
}, | |||
"longitude":{ | |||
"type": "double" | |||
}, | |||
"bookingShowPostTime":{ | |||
"type": "integer" | |||
}, | |||
"posterUrl":{ | |||
"type": "keyword" | |||
}, | |||
"items":{ | |||
"type": "keyword" | |||
}, | |||
"shops":{ | |||
"type": "keyword" | |||
}, | |||
"categoryPath":{ | |||
"type": "keyword" | |||
}, | |||
"categoryName":{ | |||
"type": "keyword" | |||
}, | |||
"productCategoryId":{ | |||
"type": "integer" | |||
}, | |||
"firstCategoryId":{ | |||
"type": "integer" | |||
}, | |||
"isReFund":{ | |||
"type": "integer" | |||
}, | |||
"contractId":{ | |||
"type": "integer" | |||
}, | |||
"qualificationsList":{ | |||
"type": "keyword" | |||
}, | |||
"releaseTime":{ | |||
"type": "integer" | |||
}, | |||
"channelMallPosterImg":{ | |||
"type": "keyword" | |||
}, | |||
"codeDelay":{ | |||
"type": "integer" | |||
}, | |||
"name":{ | |||
"type": "keyword" | |||
}, | |||
"price":{ | |||
"type": "keyword" | |||
}, | |||
"costPrice":{ | |||
"type": "keyword" | |||
}, | |||
"lianlianPrice":{ | |||
"type": "keyword" | |||
}, | |||
"productSequence":{ | |||
"type": "integer" | |||
}, | |||
"ecommerce":{ | |||
"type": "integer" | |||
}, | |||
"location":{ | |||
"type": "geo_point" | |||
} | |||
} | |||
} | |||
}` |
@@ -0,0 +1,71 @@ | |||
package md | |||
const ZhiosTpdarenEsIndex = "zhios_tpdaren" | |||
const ZhiosTpdarenEsMapping = ` | |||
{ | |||
"settings" : { | |||
"number_of_shards" : 2, | |||
"number_of_replicas" : 1 | |||
}, | |||
"mappings":{ | |||
"properties":{ | |||
"id":{ | |||
"type": "integer" | |||
}, | |||
"is_hot":{ | |||
"type": "integer" | |||
}, | |||
"video_type":{ | |||
"type": "keyword" | |||
}, | |||
"appid":{ | |||
"type": "keyword" | |||
}, | |||
"description":{ | |||
"type": "keyword" | |||
}, | |||
"episode":{ | |||
"type": "integer" | |||
}, | |||
"channel_theater_id":{ | |||
"type": "integer" | |||
}, | |||
"douyin_theater_id":{ | |||
"type": "integer" | |||
}, | |||
"kuaishou_theater_id":{ | |||
"type": "integer" | |||
}, | |||
"update_time":{ | |||
"type": "integer" | |||
}, | |||
"image_url":{ | |||
"type": "keyword" | |||
}, | |||
"is_end":{ | |||
"type": "integer" | |||
}, | |||
"pay_episode":{ | |||
"type": "integer" | |||
}, | |||
"material":{ | |||
"type": "keyword" | |||
}, | |||
"online_time":{ | |||
"type": "keyword" | |||
}, | |||
"time":{ | |||
"type": "integer" | |||
}, | |||
"type":{ | |||
"type": "keyword" | |||
}, | |||
"title":{ | |||
"type": "keyword" | |||
}, | |||
"data":{ | |||
"type": "text" | |||
} | |||
} | |||
} | |||
}` |
@@ -1,13 +0,0 @@ | |||
package hdl | |||
import ( | |||
"applet/app/e" | |||
"applet/app/svc" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func UserInfo(c *gin.Context) { | |||
admInfo := svc.GetUser(c) | |||
e.OutSuc(c, admInfo, nil) | |||
return | |||
} |
@@ -1,81 +0,0 @@ | |||
package hdl | |||
import ( | |||
"applet/app/e" | |||
//"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
) | |||
// Demo 测试 | |||
func Demo(c *gin.Context) { | |||
str := `{"appid":"wx598aaef252cd78e4","bank_type":"OTHERS","cash_fee":"1","fee_type":"CNY","is_subscribe":"N","master_id":"22255132","mch_id":"1534243971","nonce_str":"xiUZXdrEkpY9UdfCGEcBSE2jy7yWmQsk","openid":"odmKs6kNQBnujHv_S8YyME8g0-6c","order_type":"mall_goods","out_trade_no":"570761162512383595","pay_method":"wxpay","result_code":"SUCCESS","return_code":"SUCCESS","sign":"A5C7B43A8437E6AD72BB4FDAA8532A59","time_end":"20210701151722","total_fee":"1","trade_type":"APP","transaction_id":"4200001143202107010591333162"}` | |||
c.Set("data", str) | |||
var tmp map[string]interface{} | |||
err := c.ShouldBindJSON(&tmp) | |||
if err != nil { | |||
_ = logx.Error(err) | |||
return | |||
} | |||
fmt.Println(tmp["master_id"]) | |||
e.OutSuc(c, "hello mall", nil) | |||
} | |||
func Demo1(c *gin.Context) { | |||
//eg := commDb.DBs[c.GetString("mid")] | |||
//sess := eg.NewSession() | |||
////r, err := eg.Table("user_profile").Where("uid=21699").Incr("fin_valid", 10).Exec() | |||
//sql := "update user_profile set fin_valid=fin_valid+? WHERE uid=?" | |||
//r, err := sess.Exec(sql, 10, 21699) | |||
//if err != nil { | |||
// return | |||
//} | |||
//sess.Commit() | |||
// | |||
//fmt.Println("res",utils.SerializeStr(r)) | |||
/*engine := commDb.DBs[c.GetString("mid")] | |||
now := time.Now() //获取当前时间 | |||
var startDate = now.Format("2006-01-02 15:00:00") | |||
var endDate = now.Add(time.Hour * 2).Format("2006-01-02 15:00:00") | |||
res := svc2.HandleSecondsKillForDate(engine, c.GetString("mid"), startDate, endDate) | |||
startTime := utils.AnyToString(now.Hour()) | |||
endTime := utils.AnyToString(now.Add(time.Hour * 2).Hour()) | |||
res = svc2.HandleSecondsKillForTime(engine, c.GetString("mid"), startDate, endDate) | |||
res = svc2.HandleSecondsKillForDateTime(engine, c.GetString("mid"), startDate, endDate, startTime, endTime)*/ | |||
//reqList := make([]*md.CommissionReq, 0, 10) | |||
// | |||
//req := md.CommissionReq{ | |||
// CommissionParam: md.CommissionParam{Commission: "10.00"}, | |||
// Uid: "21699", | |||
// IsShare: 0, | |||
// Provider: "mall_goods", | |||
// IsAllLevelReturn: 0, | |||
// GoodsId: "3", | |||
//} | |||
// | |||
//for i := 0; i < 10; i++ { | |||
// req := req | |||
// req.GoodsId = utils.AnyToString(i + 1) | |||
// reqList = append(reqList, &req) | |||
//} | |||
// | |||
//fmt.Println(utils.SerializeStr(reqList)) | |||
// | |||
//api, err := svc.BatchGetCommissionByCommApi("123456", reqList) | |||
//if err != nil { | |||
// _ = logx.Error(err) | |||
// fmt.Println(err) | |||
// e.OutErr(c, e.ERR, err) | |||
// return | |||
//} | |||
//e.OutSuc(c, res, nil) | |||
} |
@@ -1,45 +0,0 @@ | |||
package hdl | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/lib/validate" | |||
"applet/app/md" | |||
"applet/app/svc" | |||
"applet/app/utils" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func Login(c *gin.Context) { | |||
var req md.LoginReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
adminDb := db.AdminDb{} | |||
adminDb.Set() | |||
admin, err := adminDb.GetAdminByUserName(req.UserName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err) | |||
return | |||
} | |||
if utils.Md5(req.PassWord) != admin.Password { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, "密码错误") | |||
return | |||
} | |||
ip := utils.GetIP(c.Request) | |||
key := fmt.Sprintf(md.AdminJwtTokenKey, ip, utils.AnyToString(admin.AdmId)) | |||
token, err := svc.HandleLoginToken(key, admin) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, md.LoginResponse{ | |||
Token: token, | |||
}, nil) | |||
return | |||
} |
@@ -0,0 +1,10 @@ | |||
package hdl | |||
import ( | |||
"applet/app/svc" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func GetPlayletOrder(c *gin.Context) { | |||
svc.GetPlayletOrder(c) | |||
} |
@@ -1,326 +0,0 @@ | |||
package hdl | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"applet/app/lib/validate" | |||
"applet/app/md" | |||
"applet/app/svc" | |||
"applet/app/utils" | |||
"github.com/360EntSecGroup-Skylar/excelize" | |||
"github.com/gin-gonic/gin" | |||
"github.com/shopspring/decimal" | |||
"strconv" | |||
"time" | |||
) | |||
func QrcodeBatchList(c *gin.Context) { | |||
var req md.QrcodeBatchListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
qrcodeBatchDb := db.QrcodeBatchDb{} | |||
qrcodeBatchDb.Set() | |||
list, total, err := qrcodeBatchDb.List(req.Page, req.Limit) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
qrcodeTotalNums, waitUseQrcodeNums, alreadyUseQrcodeNums, allowCreateQrcodeNums, err := svc.StatisticsQrcodeData() | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": list, | |||
"total": total, | |||
"batch_state_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.QrcodeBatchState(enum.QrcodeBatchStateForUseIng).String(), | |||
"value": enum.QrcodeBatchStateForUseIng, | |||
}, | |||
{ | |||
"name": enum.QrcodeBatchState(enum.QrcodeBatchStateForUseAlready).String(), | |||
"value": enum.QrcodeBatchStateForUseAlready, | |||
}, | |||
{ | |||
"name": enum.QrcodeBatchState(enum.QrcodeBatchStateForExpire).String(), | |||
"value": enum.QrcodeBatchStateForExpire, | |||
}, | |||
{ | |||
"name": enum.QrcodeBatchState(enum.QrcodeBatchStateForCancel).String(), | |||
"value": enum.QrcodeBatchStateForCancel, | |||
}, | |||
}, | |||
"statistics_qrcode_data": map[string]interface{}{ | |||
"qrcode_total_nums": qrcodeTotalNums, | |||
"wait_use_qrcode_nums": waitUseQrcodeNums, | |||
"already_use_qrcode_nums": alreadyUseQrcodeNums, | |||
"allow_create_qrcode_nums": allowCreateQrcodeNums, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func QrcodeBatchAdd(c *gin.Context) { | |||
var req md.QrcodeBatchAddReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
var totalNum int | |||
var totalAmount decimal.Decimal | |||
for _, v := range req.List { | |||
totalNum += v.Num | |||
amount, _ := decimal.NewFromString(v.Amount) | |||
num := decimal.NewFromInt(int64(v.Num)) | |||
totalAmount = totalAmount.Add(amount.Mul(num)) | |||
} | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
now := time.Now() | |||
//1、新增批次数据 `qrcode_batch` | |||
var qrcodeBatch = model.QrcodeBatch{ | |||
Name: req.Name, | |||
TotalNum: totalNum, | |||
TotalAmount: totalAmount.String(), | |||
State: enum.QrcodeBatchStateForUseIng, | |||
ExpireDate: req.ExpireDate, | |||
Memo: req.Memo, | |||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||
} | |||
qrcodeBatchDb := db.QrcodeBatchDb{} | |||
err = qrcodeBatchDb.AddBySession(session, &qrcodeBatch) | |||
if err != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
//2、获取 qrcode 表中是否有可用二维码 | |||
qrcodeDb := db.QrcodeDb{} | |||
qrcodeDb.Set() | |||
_, allowUseQrcodeTotal, err := qrcodeDb.FindQrcodeForAllowUse() | |||
if err != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
diffQrcodeNum := totalNum - int(allowUseQrcodeTotal) | |||
if diffQrcodeNum > 0 { | |||
//TODO::为避免频繁请求微信二维码接口 | |||
if diffQrcodeNum > 1000 { | |||
e.OutErr(c, e.ERR, "为保证二维码数据准确性,每批次新增二维码不宜操过1000张") | |||
return | |||
} | |||
//3、不够用,新增二维码 | |||
err := svc.CreateQrcode(diffQrcodeNum) | |||
if err != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
} | |||
//4、生成 "二维码-批次" 记录 | |||
err = svc.OperateQrcode(qrcodeBatch.Id, totalNum, req, session) | |||
if err != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
err = session.Commit() | |||
if err != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func GetBatchAddName(c *gin.Context) { | |||
var name = "第【1】批" | |||
qrcodeBatchDb := db.QrcodeBatchDb{} | |||
qrcodeBatchDb.Set() | |||
qrcodeBatch, err := qrcodeBatchDb.GeLastId() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if qrcodeBatch != nil { | |||
name = "第【" + utils.IntToStr(qrcodeBatch.Id+1) + "】批" | |||
} | |||
e.OutSuc(c, map[string]string{ | |||
"name": name, | |||
}, nil) | |||
return | |||
} | |||
func QrcodeBatchDetail(c *gin.Context) { | |||
batchId := c.DefaultQuery("id", "") | |||
qrcodeBatchDb := db.QrcodeBatchDb{} | |||
qrcodeBatchDb.Set() | |||
qrcodeBatch, err := qrcodeBatchDb.GetQrcodeBatchById(utils.StrToInt(batchId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if qrcodeBatch == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应的批次记录") | |||
return | |||
} | |||
qrcodeWithBatchRecordsDb := db.QrcodeWithBatchRecordsDb{} | |||
qrcodeWithBatchRecordsDb.Set() | |||
data, _, err := qrcodeWithBatchRecordsDb.FindQrcodeWithBatchRecordsById(utils.StrToInt(batchId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var list = map[string]*md.QrcodeBatchAddReqListDetail{} | |||
for _, v := range data { | |||
if list[v.Amount] == nil { | |||
list[v.Amount] = &md.QrcodeBatchAddReqListDetail{} | |||
} | |||
list[v.Amount].Num++ | |||
list[v.Amount].Amount = v.Amount | |||
switch v.State { | |||
case enum.QrcodeWithBatchRecordsStateForWait: | |||
list[v.Amount].WaitUseNum++ | |||
break | |||
case enum.QrcodeWithBatchRecordsStateForAlready: | |||
list[v.Amount].UsedNum++ | |||
break | |||
case enum.QrcodeWithBatchRecordsStateForExpire: | |||
list[v.Amount].ExpiredNum++ | |||
break | |||
case enum.QrcodeWithBatchRecordsStateForCancel: | |||
list[v.Amount].CancelNum++ | |||
break | |||
} | |||
} | |||
var resultList []*md.QrcodeBatchAddReqListDetail | |||
for _, v := range list { | |||
resultList = append(resultList, v) | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"info": qrcodeBatch, | |||
"list": resultList, | |||
}, nil) | |||
return | |||
} | |||
func QrcodeBatchDelete(c *gin.Context) { | |||
batchId := c.Param("id") | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
//1、删除 `qrcode_batch` 记录 | |||
qrcodeBatchDb := db.QrcodeBatchDb{} | |||
qrcodeBatchDb.Set() | |||
_, err := qrcodeBatchDb.DeleteQrcodeBatchBySession(session, utils.StrToInt(batchId)) | |||
if err != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
//2、将所关联的 `qrcode` 状态改为 "可用" | |||
qrcodeWithBatchRecordsDb := db.QrcodeWithBatchRecordsDb{} | |||
qrcodeWithBatchRecordsDb.Set() | |||
data, _, err := qrcodeWithBatchRecordsDb.FindQrcodeWithBatchRecordsById(utils.StrToInt(batchId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var updateQrcodeIds []int | |||
for _, v := range data { | |||
updateQrcodeIds = append(updateQrcodeIds, v.QrcodeId) | |||
} | |||
qrcodeDb := db.QrcodeDb{} | |||
qrcodeDb.Set() | |||
_, err = qrcodeDb.BatchUpdateQrcodeBySession(session, updateQrcodeIds, enum.QrcodeSateAllowUse) | |||
if err != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
//3、删除 `qrcode_with_batch_records` 记录 | |||
_, err = qrcodeWithBatchRecordsDb.DeleteQrcodeWithBatchRecordsBySession(session, utils.StrToInt(batchId)) | |||
if err != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
err = session.Commit() | |||
if err != nil { | |||
_ = session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func QrcodeBatchDownload(c *gin.Context) { | |||
batchId := c.DefaultQuery("id", "") | |||
qrcodeBatchDb := db.QrcodeBatchDb{} | |||
qrcodeBatchDb.Set() | |||
qrcodeBatch, err := qrcodeBatchDb.GetQrcodeBatchById(utils.StrToInt(batchId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if qrcodeBatch == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应的批次记录") | |||
return | |||
} | |||
qrcodeWithBatchRecordsDb := db.QrcodeWithBatchRecordsDb{} | |||
qrcodeWithBatchRecordsDb.Set() | |||
data, _, err := qrcodeWithBatchRecordsDb.FindQrcodeWithBatchRecordsLeftJoinQrcode(utils.StrToInt(batchId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
titleList := []string{"批次", "有效期", "金额", "二维码地址"} | |||
xlsx := excelize.NewFile() | |||
xlsx.SetSheetRow("Sheet1", "A1", &titleList) | |||
//表头被第一行用了,只能从第二行开始 | |||
j := 2 | |||
for _, vv := range data { | |||
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{qrcodeBatch.Name, qrcodeBatch.ExpireDate, vv.Amount, vv.Url}) | |||
j++ | |||
} | |||
//if err := xlsx.SaveAs(qrcodeBatch.Name + ".xlsx"); err != nil { | |||
// e.OutErr(c, e.ERR, err.Error()) | |||
// return | |||
//} | |||
c.Header("Content-Type", "application/octet-stream") | |||
c.Header("Content-Disposition", "attachment; filename="+qrcodeBatch.Name+".xlsx") | |||
c.Header("Content-Transfer-Encoding", "binary") | |||
//回写到web 流媒体 形成下载 | |||
_ = xlsx.Write(c.Writer) | |||
return | |||
} |
@@ -1,39 +0,0 @@ | |||
package hdl | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"applet/app/lib/validate" | |||
"applet/app/md" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func GetSysCfg(c *gin.Context) { | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
res := sysCfgDb.SysCfgFindWithDb(enum.WxMchApiV3Key, enum.WxMchCertificateSerialNumber, enum.WxMchId, enum.WxOfficialAccountAppId, enum.WxOfficialAccountAppSecret) | |||
e.OutSuc(c, res, nil) | |||
return | |||
} | |||
func SetSysCfg(c *gin.Context) { | |||
var req md.SetSysCfgReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
sysCfgDb.SysCfgUpdate(enum.WxMchApiV3Key, req.WxMchApiV3Key) | |||
sysCfgDb.SysCfgUpdate(enum.WxMchCertificateSerialNumber, req.WxMchCertificateSerialNumber) | |||
sysCfgDb.SysCfgUpdate(enum.WxMchId, req.WxMchId) | |||
sysCfgDb.SysCfgUpdate(enum.WxOfficialAccountAppId, req.WxOfficialAccountAppId) | |||
sysCfgDb.SysCfgUpdate(enum.WxOfficialAccountAppSecret, req.WxOfficialAccountAppSecret) | |||
//res := sysCfgDb.SysCfgFindWithDb(enum.WxMchApiV3Key, enum.WxMchCertificateSerialNumber, enum.WxMchId, enum.WxOfficialAccountAppId, enum.WxOfficialAccountAppSecret) | |||
e.OutSuc(c, nil, nil) | |||
return | |||
} |
@@ -1,148 +0,0 @@ | |||
package hdl | |||
import ( | |||
"applet/app/utils" | |||
"encoding/xml" | |||
"fmt" | |||
"log" | |||
"time" | |||
"github.com/gin-gonic/gin" | |||
) | |||
const Token = "temptoken" | |||
// WXCheckSignature 微信接入校验 | |||
func WXCheckSignature(c *gin.Context) { | |||
signature := c.Query("signature") | |||
timestamp := c.Query("timestamp") | |||
nonce := c.Query("nonce") | |||
echostr := c.Query("echostr") | |||
ok := utils.CheckSignature(signature, timestamp, nonce, Token) | |||
if !ok { | |||
log.Println("[微信接入] - 微信公众号接入校验失败!") | |||
return | |||
} | |||
log.Println("[微信接入] - 微信公众号接入校验成功!") | |||
_, _ = c.Writer.WriteString(echostr) | |||
} | |||
// WXMsg 微信消息结构体 | |||
type WXMsg struct { | |||
ToUserName string | |||
FromUserName string | |||
CreateTime int64 | |||
MsgType string | |||
} | |||
// WXTextMsg 微信文本消息结构体 | |||
type WXTextMsg struct { | |||
ToUserName string | |||
FromUserName string | |||
CreateTime int64 | |||
MsgType string | |||
Content string | |||
MsgId int64 | |||
} | |||
// WXEventForSubscribeMsg 扫描带参数二维码事件消息结构体(用户未关注时,进行关注后的事件推送) | |||
type WXEventForSubscribeMsg struct { | |||
ToUserName string //开发者微信号 | |||
FromUserName string //发送方帐号(一个OpenID) | |||
CreateTime int64 //消息创建时间 (整型) | |||
MsgType string //消息类型,event | |||
Event string //事件类型,subscribe | |||
EventKey string //事件KEY值,qrscene_为前缀,后面为二维码的参数值 | |||
Ticket string //二维码的ticket,可用来换取二维码图片 | |||
} | |||
// WXEventForScanMsg 扫描带参数二维码事件消息结构体(用户已关注时的事件推送) | |||
type WXEventForScanMsg struct { | |||
ToUserName string //开发者微信号 | |||
FromUserName string //发送方帐号(一个OpenID) | |||
CreateTime int64 //消息创建时间 (整型) | |||
MsgType string //消息类型,event | |||
Event string //事件类型,subscribe | |||
EventKey string //事件KEY值,是一个32位无符号整数,即创建二维码时的二维码scene_id | |||
Ticket string //二维码的ticket,可用来换取二维码图片 | |||
} | |||
// WXMsgReceive 微信消息接收 | |||
func WXMsgReceive(c *gin.Context) { | |||
var msg WXMsg | |||
err := c.ShouldBindXML(&msg) | |||
if err != nil { | |||
log.Printf("[消息接收] - XML数据包解析失败: %v\n", err) | |||
return | |||
} | |||
log.Printf("[消息接收] - 收到消息, 消息类型为: %s", msg.MsgType) | |||
if msg.MsgType == "event" { | |||
//事件类型消息 | |||
var eventMsg WXEventForSubscribeMsg | |||
err := c.ShouldBindXML(&eventMsg) | |||
if err != nil { | |||
log.Printf("[事件类型-消息接收] - XML数据包解析失败: %v\n", err) | |||
return | |||
} | |||
log.Printf("[事件类型]-收到消息, 事件类型为: %s, 事件KEY值为: %s\n, 二维码的ticket值为: %s\n", eventMsg.Event, eventMsg.EventKey, eventMsg.Ticket) | |||
if eventMsg.Event == "subscribe" { | |||
//用户未关注时,进行关注后的事件推送 | |||
//userUseQrcodeRecordsDb := db.UserUseQrcodeRecordsDb{} | |||
//userUseQrcodeRecordsDb.Set() | |||
//userUseQrcodeRecordsDb.InsertUserUseQrcodeRecords(model.UserUseQrcodeRecords{ | |||
// UserWxOpenId: eventMsg.FromUserName, | |||
// RecordsId: 0, | |||
// State: 0, | |||
// CreateAt: "", | |||
// UpdateAt: "", | |||
//}) | |||
} | |||
if eventMsg.Event == "SCAN" { | |||
//用户已关注时的事件推送 | |||
} | |||
} | |||
if msg.MsgType == "text" { | |||
//事件类型消息 | |||
var textMsg WXTextMsg | |||
err := c.ShouldBindXML(&textMsg) | |||
if err != nil { | |||
log.Printf("[文本消息-消息接收] - XML数据包解析失败: %v\n", err) | |||
return | |||
} | |||
log.Printf("[文本消息]-收到消息, 消息内容为: %s", textMsg.Content) | |||
WXMsgReply(c, textMsg.ToUserName, textMsg.FromUserName) | |||
} | |||
} | |||
// WXRepTextMsg 微信回复文本消息结构体 | |||
type WXRepTextMsg struct { | |||
ToUserName string | |||
FromUserName string | |||
CreateTime int64 | |||
MsgType string | |||
Content string | |||
// 若不标记XMLName, 则解析后的xml名为该结构体的名称 | |||
XMLName xml.Name `xml:"xml"` | |||
} | |||
// WXMsgReply 微信消息回复 | |||
func WXMsgReply(c *gin.Context, fromUser, toUser string) { | |||
repTextMsg := WXRepTextMsg{ | |||
ToUserName: toUser, | |||
FromUserName: fromUser, | |||
CreateTime: time.Now().Unix(), | |||
MsgType: "text", | |||
Content: fmt.Sprintf("[消息回复] - %s\n,hello, world!", time.Now().Format("2006-01-02 15:04:05")), | |||
} | |||
msg, err := xml.Marshal(&repTextMsg) | |||
if err != nil { | |||
log.Printf("[消息回复] - 将对象进行XML编码出错: %v\n", err) | |||
return | |||
} | |||
_, _ = c.Writer.Write(msg) | |||
} |
@@ -1,85 +0,0 @@ | |||
package wx | |||
import ( | |||
"applet/app/db" | |||
"applet/app/enum" | |||
"applet/app/md" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
"encoding/json" | |||
"errors" | |||
) | |||
type OfficialAccount struct { | |||
AccessToken string `json:"access_token"` | |||
Appid string `json:"appid"` | |||
Secret string `json:"secret"` | |||
} | |||
func (officialAccount *OfficialAccount) Set() { // set方法 | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
officialAccount.Appid = sysCfgDb.SysCfgGetWithDb(enum.WxOfficialAccountAppId) | |||
officialAccount.Secret = sysCfgDb.SysCfgGetWithDb(enum.WxOfficialAccountAppSecret) | |||
officialAccount.AccessToken = officialAccount.createToken() | |||
} | |||
func (officialAccount *OfficialAccount) createToken() (accessToken string) { | |||
cacheKey := md.WxOfficialAccountCacheKey | |||
accessToken, _ = cache.GetString(cacheKey) | |||
if accessToken != "" { | |||
return | |||
} | |||
url := md.WxOfficialAccountRequestBaseUrl + enum.GetAccessToken | |||
post, err := utils.CurlPost(url, map[string]string{ | |||
"appid": officialAccount.Appid, | |||
"secret": officialAccount.Secret, | |||
"grant_type": "client_credential", | |||
}, nil) | |||
utils.FilePutContents("wx_official_account_create_token", "resp"+string(post)) | |||
var data md.CreateTokenResp | |||
err = json.Unmarshal(post, &data) | |||
if err != nil { | |||
return | |||
} | |||
if data.AccessToken == "" { | |||
panic(errors.New("获取 access_token 失败")) | |||
} | |||
accessToken = data.AccessToken | |||
cache.SetEx(cacheKey, accessToken, int(data.ExpiresIn-3600)) | |||
return | |||
} | |||
func (officialAccount *OfficialAccount) QrcodeCreate(sceneStr string) (qrcodeUrl string, err error) { | |||
url := md.WxOfficialAccountRequestBaseUrl + enum.QrcodeCreate + "?access_token=" + officialAccount.AccessToken | |||
//post, err := utils.CurlPost(url, map[string]interface{}{ | |||
// "action_name": "QR_LIMIT_STR_SCENE", | |||
// "action_info": map[string]interface{}{ | |||
// "scene": map[string]string{ | |||
// "scene_str": sceneStr, | |||
// }, | |||
// }, | |||
//}, nil) | |||
requestBody, _ := json.Marshal(map[string]interface{}{ | |||
"action_name": "QR_STR_SCENE", | |||
"expire_seconds": "6000", | |||
"action_info": map[string]interface{}{ | |||
"scene": map[string]string{ | |||
"scene_str": sceneStr, | |||
}, | |||
}, | |||
}) | |||
post, err := utils.CurlPost(url, requestBody, nil) | |||
utils.FilePutContents("wx_official_account_qrcode_create", "resp"+string(post)) | |||
var data md.CreateQrcodeResp | |||
err = json.Unmarshal(post, &data) | |||
if err != nil { | |||
return | |||
} | |||
qrcodeUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + data.Ticket | |||
return | |||
} |
@@ -1,27 +1,10 @@ | |||
package mw | |||
import ( | |||
"applet/app/e" | |||
"applet/app/svc" | |||
"github.com/gin-gonic/gin" | |||
) | |||
// 检查权限, 签名等等 | |||
func Auth(c *gin.Context) { | |||
admin, err := svc.CheckUser(c) | |||
if err != nil { | |||
switch err.(type) { | |||
case e.E: | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
default: | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
} | |||
// 将当前请求的username信息保存到请求的上下文c上 | |||
c.Set("admin", admin) | |||
c.Next() | |||
} |
@@ -37,41 +37,22 @@ func Init() *gin.Engine { | |||
c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}}) | |||
}) | |||
r.Use(mw.Cors) | |||
route(r.Group("/api/v1")) | |||
routeInternal(r.Group("/api/v1/internal")) | |||
return r | |||
} | |||
func route(r *gin.RouterGroup) { | |||
r.Any("/demo", hdl.Demo) | |||
r.POST("/login", hdl.Login) | |||
r.Group("/wx") | |||
{ | |||
r.Use(mw.DB) | |||
// 微信公众号消息通知 | |||
r.GET("/msgReceive", hdl.WXCheckSignature) | |||
r.POST("/msgReceive", hdl.WXMsgReceive) | |||
} | |||
func routeInternal(r *gin.RouterGroup) { | |||
r.Use(mw.DB) // 以下接口需要用到数据库 | |||
{ | |||
r.GET("/demo1", hdl.Demo1) | |||
r.POST("/playlet_order", hdl.GetPlayletOrder) | |||
} | |||
r.Use(mw.Checker) // 以下接口需要检查Header: platform | |||
{ | |||
} | |||
r.GET("/qrcodeBatchDownload", hdl.QrcodeBatchDownload) //二维码批次-下载 | |||
r.Use(mw.Auth) // 以下接口需要JWT验证 | |||
r.Use(mw.Auth) // 以下接口需要JWT验证 | |||
{ | |||
r.GET("/userInfo", hdl.UserInfo) //用户信息 | |||
r.GET("/sysCfg", hdl.GetSysCfg) //基础配置-获取 | |||
r.POST("/sysCfg", hdl.SetSysCfg) //基础配置-设置 | |||
r.POST("/qrcodeBatchList", hdl.QrcodeBatchList) //二维码批次-列表 | |||
r.GET("/getBatchAddName", hdl.GetBatchAddName) //二维码批次-自动获取添加时名称 | |||
r.POST("/qrcodeBatchAdd", hdl.QrcodeBatchAdd) //二维码批次-添加 | |||
r.GET("/qrcodeBatchDetail", hdl.QrcodeBatchDetail) //二维码批次-详情 | |||
r.DELETE("/qrcodeBatchDelete/:id", hdl.QrcodeBatchDelete) //二维码批次-删除 | |||
} | |||
} |
@@ -1,51 +0,0 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"errors" | |||
"github.com/gin-gonic/gin" | |||
"strings" | |||
) | |||
func GetUser(c *gin.Context) *model.Admin { | |||
user, _ := c.Get("admin") | |||
if user == nil { | |||
return &model.Admin{ | |||
AdmId: 0, | |||
Username: "", | |||
Password: "", | |||
State: 0, | |||
CreateAt: "", | |||
UpdateAt: "", | |||
} | |||
} | |||
return user.(*model.Admin) | |||
} | |||
func CheckUser(c *gin.Context) (*model.Admin, error) { | |||
token := c.GetHeader("Authorization") | |||
if token == "" { | |||
return nil, errors.New("token not exist") | |||
} | |||
// 按空格分割 | |||
parts := strings.SplitN(token, " ", 2) | |||
if !(len(parts) == 2 && parts[0] == "Bearer") { | |||
return nil, errors.New("token format error") | |||
} | |||
// parts[1]是获取到的tokenString,我们使用之前定义好的解析JWT的函数来解析它 | |||
mc, err := utils.ParseToken(parts[1]) | |||
if err != nil { | |||
return nil, err | |||
} | |||
// 获取admin | |||
adminDb := db.AdminDb{} | |||
adminDb.Set() | |||
admin, err := adminDb.GetAdmin(mc.AdmId) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return admin, nil | |||
} |
@@ -1,33 +0,0 @@ | |||
package svc | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/md" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
"applet/app/utils/logx" | |||
) | |||
func HandleLoginToken(cacheKey string, admin *model.Admin) (string, error) { | |||
// 获取之前生成的token | |||
token, err := cache.GetString(cacheKey) | |||
if err != nil { | |||
_ = logx.Error(err) | |||
} | |||
// 没有获取到 | |||
if err != nil || token == "" { | |||
// 生成token | |||
token, err = utils.GenToken(admin.AdmId, admin.Username) | |||
if err != nil { | |||
return "", err | |||
} | |||
// 缓存token | |||
_, err = cache.SetEx(cacheKey, token, md.JwtTokenCacheTime) | |||
if err != nil { | |||
return "", err | |||
} | |||
return token, nil | |||
} | |||
return token, nil | |||
} |
@@ -0,0 +1,21 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func GetPlayletOrder(c *gin.Context) { | |||
var args map[string]string | |||
if err := c.ShouldBindJSON(&args); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
playletSaleOrderDb := db.PlayletSaleOrderDb{} | |||
playletSaleOrderDb.Set() | |||
args["mid"] = c.GetString("mid") | |||
list := playletSaleOrderDb.GetPlayletVideoOrderList(args) | |||
e.OutSuc(c, list, nil) | |||
return | |||
} |
@@ -1,108 +0,0 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/enum" | |||
"applet/app/lib/wx" | |||
"applet/app/md" | |||
"applet/app/utils" | |||
"errors" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
func StatisticsQrcodeData() (qrcodeTotalNums, waitUseQrcodeNums, alreadyUseQrcodeNums, allowCreateQrcodeNums int64, err error) { | |||
qrcodeTotalNums = md.QrcodeTotalNums //二维码总量 | |||
qrcodeWithBatchRecordsDb := db.QrcodeWithBatchRecordsDb{} | |||
qrcodeWithBatchRecordsDb.Set() | |||
qrcodeWithBatchRecordsForUseWait, err := qrcodeWithBatchRecordsDb.FindQrcodeWithBatchRecordsByState(enum.QrcodeWithBatchRecordsStateForWait) | |||
if err != nil { | |||
return | |||
} | |||
waitUseQrcodeNums = int64(len(qrcodeWithBatchRecordsForUseWait)) //待使用二维码数量 | |||
qrcodeWithBatchRecordsForUseAlready, err := qrcodeWithBatchRecordsDb.FindQrcodeWithBatchRecordsByState(enum.QrcodeWithBatchRecordsStateForAlready) | |||
if err != nil { | |||
return | |||
} | |||
alreadyUseQrcodeNums = int64(len(qrcodeWithBatchRecordsForUseAlready)) //已使用二维码数量 | |||
allowCreateQrcodeNums = qrcodeTotalNums - waitUseQrcodeNums //可生成二维码数量 | |||
return | |||
} | |||
func createQrcodeIndex() string { | |||
date := utils.Int64ToStr(time.Now().UnixMicro()) | |||
sceneStr := date + "_" + utils.RandString(6) //根据当前时间戳(微秒)+ 随机6位字符串 作为唯一标识符 | |||
return sceneStr | |||
} | |||
func CreateQrcode(createNums int) (err error) { | |||
now := time.Now() | |||
var insertData []*model.Qrcode | |||
//1、调用微信 `cgi-bin/qrcode/create` 生成带参的永久二维码 | |||
wxOfficial := wx.OfficialAccount{} | |||
wxOfficial.Set() | |||
for i := 0; i < createNums; i++ { | |||
sceneStr := createQrcodeIndex() | |||
qrcodeUrl, err1 := wxOfficial.QrcodeCreate(sceneStr) | |||
if err1 != nil { | |||
return err1 | |||
} | |||
insertData = append(insertData, &model.Qrcode{ | |||
Url: qrcodeUrl, | |||
State: enum.QrcodeSateAllowUse, | |||
Index: sceneStr, | |||
CreateAt: now.Format("2006-01-02 15:00:00"), | |||
UpdateAt: now.Format("2006-01-02 15:00:00"), | |||
}) | |||
} | |||
//2、批量新增二维码 | |||
qrcodeDb := db.QrcodeDb{} | |||
qrcodeDb.Set() | |||
_, err = qrcodeDb.BatchAddQrcode(insertData) | |||
return | |||
} | |||
func OperateQrcode(batchId, totalNums int, args md.QrcodeBatchAddReq, session *xorm.Session) (err error) { | |||
qrcodeDb := db.QrcodeDb{} | |||
qrcodeDb.Set() | |||
//1、获取当前可用二维码 | |||
allowUseQrcodeList, allowUseQrcodeTotal, err := qrcodeDb.FindQrcodeForAllowUse() | |||
if int(allowUseQrcodeTotal) < totalNums { | |||
err = errors.New("可用二维码不足") | |||
return | |||
} | |||
now := time.Now() | |||
var insertData []*model.QrcodeWithBatchRecords | |||
var updateQrcodeIds []int | |||
var k = 0 | |||
for _, v := range args.List { | |||
for i := 0; i < v.Num; i++ { | |||
insertData = append(insertData, &model.QrcodeWithBatchRecords{ | |||
QrcodeId: allowUseQrcodeList[k].Id, | |||
BatchId: batchId, | |||
Amount: v.Amount, | |||
State: enum.QrcodeWithBatchRecordsStateForWait, | |||
CreateAt: now.Format("2006-01-02 15:00:00"), | |||
UpdateAt: now.Format("2006-01-02 15:00:00"), | |||
}) | |||
updateQrcodeIds = append(updateQrcodeIds, allowUseQrcodeList[k].Id) | |||
k++ | |||
} | |||
} | |||
//2、新增“二维码-批次”记录 | |||
qrcodeWithBatchRecordsDb := db.QrcodeWithBatchRecordsDb{} | |||
qrcodeWithBatchRecordsDb.Set() | |||
if _, err = qrcodeWithBatchRecordsDb.BatchAddQrcodeWithBatchRecordsBySession(session, insertData); err != nil { | |||
return | |||
} | |||
//3、修改"二维码状态"为不可用 | |||
_, err = qrcodeDb.BatchUpdateQrcodeBySession(session, updateQrcodeIds, enum.QrcodeSateAllowNotUse) | |||
return | |||
} |
@@ -1,25 +1,20 @@ | |||
package task | |||
import ( | |||
"applet/app/db" | |||
taskMd "applet/app/task/md" | |||
"time" | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"github.com/robfig/cron/v3" | |||
"xorm.io/xorm" | |||
"time" | |||
) | |||
var ( | |||
timer *cron.Cron | |||
jobs = map[string]func(*xorm.Engine, string){} | |||
baseEntryId cron.EntryID | |||
entryIds []cron.EntryID | |||
taskCfgList map[string]*[]model.SysCfg | |||
ch = make(chan int, 30) | |||
workerNum = 15 // 智盟跟单并发数量 | |||
otherCh = make(chan int, 30) | |||
otherWorkerNum = 18 // 淘宝, 苏宁, 考拉并发量 | |||
timer *cron.Cron | |||
jobs = map[string]func(){} | |||
baseEntryId cron.EntryID | |||
entryIds []cron.EntryID | |||
ch = make(chan int, 30) | |||
workerNum = 15 // 智盟跟单并发数量 | |||
) | |||
func Init() { | |||
@@ -41,8 +36,11 @@ func Run() { | |||
func reload() { | |||
// 重新初始化数据库 | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
cronList, _ := sysCfgDb.SysCfgGetCron() | |||
if len(taskCfgList) > 0 { | |||
if cronList != nil { | |||
// 删除原有所有任务 | |||
if len(entryIds) > 0 { | |||
for _, v := range entryIds { | |||
@@ -56,14 +54,11 @@ func reload() { | |||
entryId cron.EntryID | |||
err error | |||
) | |||
// 添加任务 | |||
for dbName, v := range taskCfgList { | |||
for _, vv := range *v { | |||
if _, ok := jobs[vv.Key]; ok && vv.Val != "" { | |||
// fmt.Println(vv.Val) | |||
if entryId, err = timer.AddFunc(vv.Val, doTask(dbName, vv.Key)); err == nil { | |||
entryIds = append(entryIds, entryId) | |||
} | |||
for _, vv := range *cronList { | |||
if _, ok := jobs[vv.K]; ok && vv.V != "" { | |||
// fmt.Println(vv.Val) | |||
if entryId, err = timer.AddFunc(vv.V, doTask(vv.K)); err == nil { | |||
entryIds = append(entryIds, entryId) | |||
} | |||
} | |||
} | |||
@@ -71,13 +66,12 @@ func reload() { | |||
} | |||
} | |||
func doTask(dbName, fnName string) func() { | |||
func doTask(fnName string) func() { | |||
return func() { | |||
begin := time.Now().Local() | |||
end := time.Now().Local() | |||
logx.Infof( | |||
"[%s] AutoTask <%s> started at <%s>, ended at <%s> duration <%s>", | |||
dbName, | |||
" AutoTask <%s> started at <%s>, ended at <%s> duration <%s>", | |||
fnName, | |||
begin.Format("2006-01-02 15:04:05.000"), | |||
end.Format("2006-01-02 15:04:05.000"), | |||
@@ -88,5 +82,12 @@ func doTask(dbName, fnName string) func() { | |||
// 增加自动任务队列 | |||
func initTasks() { | |||
jobs[taskMd.MallCronOrderCancel] = taskCancelOrder // 取消订单 | |||
jobs[taskMd.ZhimengCronPlayletVideoOrder] = taskPlayletVideoOrder // | |||
jobs[taskMd.ZhimengCronPlayletVideoOrderYesterDay] = taskPlayletVideoOrderYesterday // | |||
jobs[taskMd.ZhimengCronPlayletVideoOrderMonth] = taskPlayletVideoOrderMonth // | |||
jobs[taskMd.ZhimengCronPlayletAdvOrderMonth] = taskPlayletAdvOrderMonth // | |||
jobs[taskMd.ZhimengCronPlayletAdvOrder] = taskPlayletAdvOrder // | |||
jobs[taskMd.ZhimengCronPlayletAdvOrderYesterDay] = taskPlayletAdvOrderYesterday // | |||
jobs[taskMd.ZhimengCronPlayletAdvOrderYesterDayToMoney] = taskPlayletAdvOrderYesterdayToMoney // | |||
jobs[taskMd.ZhimengCronPlayletGoods] = taskPlayletGoods // | |||
} |
@@ -1,5 +1,12 @@ | |||
package md | |||
const ( | |||
MallCronOrderCancel = "mall_cron_order_cancel" // 取消订单任务 | |||
ZhimengCronPlayletVideoOrder = "zhimeng_cron_playlet_video_order" //短剧订单 | |||
ZhimengCronPlayletAdvOrder = "zhimeng_cron_playlet_adv_order" //短剧广告订单 | |||
ZhimengCronPlayletVideoOrderYesterDay = "zhimeng_cron_playlet_video_order_yesterday" | |||
ZhimengCronPlayletVideoOrderMonth = "zhimeng_cron_playlet_video_order_month" | |||
ZhimengCronPlayletAdvOrderYesterDay = "zhimeng_cron_playlet_adv_order_yesterday" | |||
ZhimengCronPlayletAdvOrderMonth = "zhimeng_cron_playlet_adv_order_month" | |||
ZhimengCronPlayletAdvOrderYesterDayToMoney = "zhimeng_cron_playlet_adv_order_yesterday_to_money" | |||
ZhimengCronPlayletGoods = "zhimeng_cron_playlet_goods" | |||
) |
@@ -0,0 +1,37 @@ | |||
package md | |||
type Tpdaren struct { | |||
Id int `json:"id"` | |||
Description string `json:"description"` | |||
Episode int `json:"episode"` | |||
ImageUrl string `json:"image_url"` | |||
IsEnd string `json:"is_end"` | |||
IsHot int `json:"is_hot"` | |||
PayEpisode int `json:"pay_episode"` | |||
Material string `json:"material"` | |||
OnlineTime string `json:"online_time"` | |||
Type string `json:"type"` | |||
Title string `json:"title"` | |||
Data string `json:"data"` | |||
VideoType string `json:"video_type"` | |||
ChannelTheaterId int `json:"channel_theater_id"` | |||
DouyinTheaterId int `json:"douyin_theater_id"` | |||
KuaishouTheaterId int `json:"kuaishou_theater_id"` | |||
UpdateTime int `json:"update_time"` | |||
Time int `json:"time"` | |||
ShareTitle string `json:"share_title"` | |||
Appid string `json:"appid"` | |||
} | |||
type TpdarenList struct { | |||
Title string `json:"title"` | |||
Description string `json:"description"` | |||
ChannelTheaterId int `json:"channel_theater_id"` | |||
DouyinTheaterId int `json:"douyin_theater_id"` | |||
KuaishouTheaterId int `json:"kuaishou_theater_id"` | |||
IsEnd bool `json:"is_end"` | |||
Episode int `json:"episode"` | |||
PayEpisode int `json:"pay_episode"` | |||
Material string `json:"material"` | |||
ImageUrl string `json:"image_url"` | |||
OnlineTime string `json:"online_time"` | |||
} |
@@ -0,0 +1,29 @@ | |||
package md | |||
type PlayletVideoOrder struct { | |||
Appid int `json:"appid"` | |||
Channel string `json:"channel"` | |||
OrderId string `json:"order_id"` | |||
PayDate string `json:"pay_date"` | |||
Price int `json:"price"` | |||
RefundDate string `json:"refund_date"` | |||
SourceId string `json:"source_id"` | |||
Status int `json:"status"` | |||
Title string `json:"title"` | |||
SourceType string `json:"source_type"` | |||
SettleType string `json:"settle_type"` | |||
} | |||
type PlayletAdvOrder struct { | |||
Appid int `json:"appid"` | |||
Channel string `json:"channel"` | |||
CreatedTime string `json:"created_time"` | |||
Price int `json:"price"` | |||
PointPv int `json:"point_pv"` | |||
PointUv int `json:"point_uv"` | |||
FinishPv int `json:"finish_pv"` | |||
FinishUv int `json:"finish_uv"` | |||
SourceId string `json:"source_id"` | |||
Title string `json:"title"` | |||
SourceType string `json:"source_type"` | |||
SettleType string `json:"settle_type"` | |||
} |
@@ -1,64 +0,0 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"errors" | |||
"fmt" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
func CancelOrder(eg *xorm.Engine, dbName string) { | |||
fmt.Println("cancel order...") | |||
defer func() { | |||
if err := recover(); err != nil { | |||
_ = logx.Error(err) | |||
} | |||
}() | |||
timeStr, err := getCancelCfg(eg, dbName) | |||
if err != nil { | |||
fmt.Println(err.Error()) | |||
return | |||
} | |||
now := time.Now() | |||
// x 分钟后取消订单 | |||
expTime := now.Add(-time.Hour * time.Duration(utils.StrToInt64(timeStr))) | |||
expTimeStr := utils.Time2String(expTime, "") | |||
page := 1 | |||
for { | |||
isEmpty, err := handleOnePage(eg, dbName, expTimeStr) | |||
if err != nil { | |||
_ = logx.Error(err) | |||
break | |||
} | |||
if isEmpty { | |||
break | |||
} | |||
if page > 100 { | |||
break | |||
} | |||
page += 1 | |||
} | |||
} | |||
func handleOnePage(eg *xorm.Engine, dbName, expTimeStr string) (isEmpty bool, err error) { | |||
return false, nil | |||
} | |||
func getCancelCfg(eg *xorm.Engine, masterId string) (string, error) { | |||
cfg := db.SysCfgGetWithDb(eg, masterId, "order_expiration_time") | |||
if cfg == "" { | |||
return "", errors.New("order_expiration_time no found") | |||
} | |||
return cfg, nil | |||
} |
@@ -0,0 +1,61 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tpdaren" | |||
"fmt" | |||
"strings" | |||
"time" | |||
) | |||
func GetRunTime(uid, pvdTimeKey, memo string) int64 { | |||
sysCfgDb := db.MasterListCfgDb{} | |||
sysCfgDb.Set() | |||
// 获得最后时间 | |||
latest, err := sysCfgDb.MasterListCfgGetOne(uid, pvdTimeKey) | |||
if err != nil || latest == nil { | |||
sysCfgDb.MasterListCfgInsert(uid, pvdTimeKey, time.Now().String(), memo) | |||
latest, _ = sysCfgDb.MasterListCfgGetOne(uid, pvdTimeKey) | |||
} | |||
// 所有时间都是在操作秒数 | |||
now := time.Now().Unix() | |||
strs := strings.Split(latest.V, ":") | |||
timeStr := latest.V | |||
if len(strs) == 3 { | |||
timeStr = strs[0] + ":" + strs[1] + ":00" | |||
} | |||
fmt.Println(timeStr) | |||
past := utils.TimeParseStd(timeStr).Unix() | |||
if past < now-180*86400 || past > now { | |||
past = now | |||
} | |||
return past | |||
} | |||
func SetRunTime(uid, pvdTimeKey, val string) { | |||
sysCfgDb := db.MasterListCfgDb{} | |||
sysCfgDb.Set() | |||
sysCfgDb.MasterListCfgUpdate(uid, pvdTimeKey, val) | |||
} | |||
func GetTpdarenToken(uid string) string { | |||
syscfgDb := db.MasterListCfgDb{} | |||
syscfgDb.Set() | |||
tpdarenAppidData, _ := syscfgDb.MasterListCfgGetOne(uid, "tpdaren_appid") | |||
tpdarenAppsecretData, _ := syscfgDb.MasterListCfgGetOne(uid, "tpdaren_appsecret") | |||
if tpdarenAppidData == nil || tpdarenAppsecretData == nil { | |||
return "" | |||
} | |||
key := "tpdaren_token_" + tpdarenAppidData.V | |||
getString, err := cache.GetString(key) | |||
if getString == "" || err != nil { | |||
token := tpdaren.TpdarenToken(tpdarenAppidData.V, tpdarenAppsecretData.V) | |||
if token == "" { | |||
return "" | |||
} | |||
getString = token | |||
cache.SetEx(key, token, 7180) | |||
} | |||
return getString | |||
} |
@@ -0,0 +1,297 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/task/md" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tpdaren" | |||
"encoding/json" | |||
"fmt" | |||
"github.com/tidwall/gjson" | |||
"strings" | |||
"time" | |||
) | |||
func PlayletAdvOrder() { | |||
defer func() { | |||
if err := recover(); err != nil { | |||
_ = logx.Error(err) | |||
} | |||
}() | |||
uid := "0" | |||
// 获取上次获取订单时候的时间戳 | |||
pvdTimeKey := "playlet_adv_order_time" | |||
timeRange := utils.GetTimeRange("today") | |||
now := time.Now().Unix() | |||
past := GetRunTime(uid, pvdTimeKey, "广告获取订单时间") | |||
var ( | |||
beginTime int64 = 0 | |||
endTime int64 = 0 | |||
pageNo int = 1 | |||
pageSize int = 200 | |||
) | |||
//怕时间不是走最新的 | |||
leave := now - past | |||
if leave > 500 { | |||
leave = 0 | |||
} | |||
var eveTime int64 = 86400 | |||
past = past + leave | |||
beginTime = past - eveTime | |||
endTime = past | |||
if endTime > now { | |||
endTime = now | |||
} | |||
if endTime > timeRange["start"] { | |||
beginTime = timeRange["start"] | |||
} | |||
for { | |||
// 分配堆内存 | |||
time.Sleep(time.Microsecond * 500) // 等待500毫秒 | |||
//获取订单 | |||
arg := map[string]interface{}{ | |||
"start": time.Unix(beginTime, 0).Format("2006-01-02 15:04:05"), | |||
"end": time.Unix(endTime, 0).Format("2006-01-02 15:04:05"), | |||
"page_size": pageSize, | |||
"page_index": pageNo, | |||
} | |||
count := getAdvOrder(uid, arg) | |||
if count == 0 { | |||
goto ChkArg | |||
} | |||
if count == pageSize { | |||
pageNo++ | |||
continue | |||
} | |||
ChkArg: | |||
// 查询完后重置时间, 最后查询时间 | |||
if endTime < now { | |||
pageNo = 1 | |||
SetRunTime(uid, pvdTimeKey, utils.TimeToStr(endTime)) | |||
beginTime = endTime | |||
endTime = endTime + eveTime | |||
if endTime > now { | |||
endTime = now | |||
} | |||
if endTime > timeRange["start"] { | |||
beginTime = timeRange["start"] | |||
} | |||
continue | |||
} | |||
break | |||
} | |||
// 更新最后供应商执行订单时间 | |||
SetRunTime(uid, pvdTimeKey, utils.TimeToStr(now)) | |||
} | |||
func PlayletAdvOrderYesterday(hours int, runtimeStr string) { | |||
defer func() { | |||
if err := recover(); err != nil { | |||
_ = logx.Error(err) | |||
} | |||
}() | |||
uid := "0" | |||
timeRange := utils.GetTimeRange("today") | |||
hour := time.Now().Hour() | |||
if hour < hours { | |||
return | |||
} | |||
syscfgDb := db.MasterListCfgDb{} | |||
syscfgDb.Set() | |||
playletVideoOrderYesterdayRuntime := syscfgDb.MasterListCfgGetOneData(uid, runtimeStr) | |||
if utils.TimeStdParseUnix(playletVideoOrderYesterdayRuntime) > timeRange["start"] { | |||
return | |||
} | |||
var ( | |||
beginTime int64 = timeRange["start"] - 86400 | |||
endTime int64 = timeRange["start"] | |||
pageNo int = 1 | |||
pageSize int = 200 | |||
) | |||
for { | |||
// 分配堆内存 | |||
time.Sleep(time.Microsecond * 500) // 等待500毫秒 | |||
//获取订单 | |||
arg := map[string]interface{}{ | |||
"start": time.Unix(beginTime, 0).Format("2006-01-02 15:04:05"), | |||
"end": time.Unix(endTime, 0).Format("2006-01-02 15:04:05"), | |||
"page_size": pageSize, | |||
"page_index": pageNo, | |||
} | |||
count := getVideoOrder(uid, arg) | |||
if count == 0 { | |||
break | |||
} | |||
if count == pageSize { | |||
pageNo++ | |||
continue | |||
} | |||
} | |||
syscfgDb.MasterListCfgUpdate(uid, runtimeStr, time.Now().Format("2006-01-02 15:04:05")) | |||
return | |||
} | |||
func PlayletAdvOrderMonth() { | |||
defer func() { | |||
if err := recover(); err != nil { | |||
_ = logx.Error(err) | |||
} | |||
}() | |||
uid := "0" | |||
timeRange := utils.GetTimeRange("last_month") | |||
t := time.Now() | |||
stime := time.Date(t.Year(), t.Month(), 5, 0, 0, 0, 0, t.Location()).Unix() | |||
day := time.Now().Day() | |||
if day < 5 { | |||
return | |||
} | |||
syscfgDb := db.MasterListCfgDb{} | |||
syscfgDb.Set() | |||
//上次开始的时间 | |||
keyStart := "playlet_adv_order_month_starttime" | |||
starttime := syscfgDb.MasterListCfgGetOneData(uid, keyStart) | |||
//运行到哪一天 | |||
key := "playlet_adv_order_month_runtime" | |||
runtime := syscfgDb.MasterListCfgGetOneData(uid, key) | |||
keyIsEnd := "playlet_adv_order_month_is_end" | |||
if utils.TimeStdParseUnix(starttime) < stime { | |||
syscfgDb.MasterListCfgUpdate(uid, key, time.Now().Format("2006-01-02 15:04:05")) | |||
syscfgDb.MasterListCfgUpdate(uid, keyIsEnd, "") | |||
runtime = time.Unix(timeRange["start"], 0).Format("2006-01-02 15:04:05") | |||
} | |||
//当前是否结束了 | |||
isEnd := syscfgDb.MasterListCfgGetOneData(uid, keyIsEnd) | |||
if isEnd == "1" { | |||
return | |||
} | |||
var ( | |||
beginTime int64 = utils.TimeStdParseUnix(runtime) - 86400 | |||
endTime int64 = utils.TimeStdParseUnix(runtime) | |||
pageNo int = 1 | |||
pageSize int = 200 | |||
) | |||
for { | |||
// 分配堆内存 | |||
time.Sleep(time.Microsecond * 500) // 等待500毫秒 | |||
//获取订单 | |||
arg := map[string]interface{}{ | |||
"start": time.Unix(beginTime, 0).Format("2006-01-02 15:04:05"), | |||
"end": time.Unix(endTime, 0).Format("2006-01-02 15:04:05"), | |||
"page_size": pageSize, | |||
"page_index": pageNo, | |||
} | |||
count := getAdvOrder(uid, arg) | |||
if count == 0 { | |||
break | |||
} | |||
if count == pageSize { | |||
pageNo++ | |||
continue | |||
} | |||
} | |||
if endTime > time.Now().Unix() { | |||
syscfgDb.MasterListCfgUpdate(uid, keyIsEnd, "1") | |||
} | |||
syscfgDb.MasterListCfgUpdate(uid, key, time.Unix(endTime, 0).Format("2006-01-02 15:04:05")) | |||
return | |||
} | |||
func getAdvOrder(uids string, arg map[string]interface{}) int { | |||
list := make([]map[string]string, 0) | |||
token := GetTpdarenToken(uids) | |||
paging, err := tpdaren.AdStatisticFindPaging(token, arg) | |||
fmt.Println("playletAdvOrder", paging) | |||
fmt.Println("playletAdvOrder", err) | |||
if paging == "" { | |||
return len(list) | |||
} | |||
data := gjson.Get(paging, "data.data").String() | |||
if data == "" { | |||
return len(list) | |||
} | |||
dataList := make([]md.PlayletAdvOrder, 0) | |||
json.Unmarshal([]byte(data), &dataList) | |||
sysCfgDb := db.MasterListCfgDb{} | |||
sysCfgDb.Set() | |||
playletKuaishouBili := sysCfgDb.MasterListCfgGetOneData(uids, "adv_kuaishou_bili") | |||
playletDouyinBili := sysCfgDb.MasterListCfgGetOneData(uids, "adv_douyin_bili") | |||
playletChannelBili := sysCfgDb.MasterListCfgGetOneData(uids, "adv_channel_bili") | |||
var biliMap = map[string]string{ | |||
"kuaishou": playletKuaishouBili, | |||
"douyin": playletDouyinBili, | |||
"channel": playletChannelBili, | |||
} | |||
zyPlayletKuaishouBili := sysCfgDb.MasterListCfgGetOneData(uids, "zy_adv_kuaishou_bili") | |||
zyPlayletDouyinBili := sysCfgDb.MasterListCfgGetOneData(uids, "zy_adv_douyin_bili") | |||
zyPlayletChannelBili := sysCfgDb.MasterListCfgGetOneData(uids, "zy_adv_channel_bili") | |||
var zyBiliMap = map[string]string{ | |||
"kuaishou": zyPlayletKuaishouBili, | |||
"douyin": zyPlayletDouyinBili, | |||
"channel": zyPlayletChannelBili, | |||
} | |||
for _, v := range dataList { | |||
sourceIdArr := strings.Split(v.SourceId, "_") | |||
mid := "" | |||
uid := "" | |||
if len(sourceIdArr) == 2 { | |||
mid = sourceIdArr[0] | |||
uid = sourceIdArr[1] | |||
} | |||
if mid == "" || uid == "" { | |||
continue | |||
} | |||
money := utils.Float64ToStr(float64(v.Price) / 100) | |||
if v.Channel == "wechat" { | |||
v.Channel = "channel" | |||
} | |||
oid := v.Channel + v.SourceId + v.CreatedTime | |||
oid = strings.ReplaceAll(oid, "_", "") | |||
oid = strings.ReplaceAll(oid, "-", "") | |||
oid = strings.ReplaceAll(oid, " ", "") | |||
oid = strings.ReplaceAll(oid, ":", "") | |||
bili := biliMap[v.Channel] | |||
zyBili := zyBiliMap[v.Channel] | |||
platformFee := utils.Float64ToStr(utils.StrToFloat64(money) * utils.StrToFloat64(bili) / 100) | |||
zyFee := utils.Float64ToStr(utils.StrToFloat64(money) * utils.StrToFloat64(zyBili) / 100) | |||
commission := utils.Float64ToStr(utils.StrToFloat64(money) - utils.StrToFloat64(platformFee) - utils.StrToFloat64(zyFee)) | |||
var tmp = model.PlayletSaleOrder{ | |||
Uid: mid, | |||
SubUid: utils.StrToInt(uid), | |||
Data: utils.SerializeStr(v), | |||
Oid: oid, | |||
Amount: money, | |||
Commission: commission, | |||
CreateTime: utils.TimeParseStd(v.CreatedTime + " 00:00:00"), | |||
UpdateTime: time.Now(), | |||
Title: v.Title, | |||
VideoType: v.Channel, | |||
PlatformType: "tpdaren", | |||
GoodsType: "playlet", | |||
OrdType: "adv", | |||
ExtendUid: uids, | |||
Fee: zyFee, | |||
PlatformFee: platformFee, | |||
} | |||
playletSaleOrderDb := db.PlayletSaleOrderDb{} | |||
playletSaleOrderDb.Set() | |||
ord := playletSaleOrderDb.GetPlayletVideoOrderByOid(tmp.Oid, tmp.OrdType) | |||
tmp.Status = "订单付款" | |||
if v.SettleType == "1" { | |||
tmp.Status = "订单结算" | |||
if ord != nil && ord.PlatformSettleTime.IsZero() { | |||
tmp.PlatformSettleTime = time.Now() | |||
} | |||
} | |||
if ord != nil { | |||
playletSaleOrderDb.PlayletVideoOrderUpdate(ord.Id, &tmp) | |||
} else { | |||
tmp.CustomOid = utils.OrderUUID(tmp.SubUid) | |||
playletSaleOrderDb.PlayletVideoOrderInsert(&tmp) | |||
} | |||
} | |||
return len(list) | |||
} |
@@ -0,0 +1,112 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
md2 "applet/app/es/md" | |||
"applet/app/task/md" | |||
"applet/app/utils" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tpdaren" | |||
"encoding/json" | |||
"fmt" | |||
"github.com/syyongx/php2go" | |||
"github.com/tidwall/gjson" | |||
"time" | |||
) | |||
func PlayletGoods() { | |||
sysCfgDb := db.MasterListCfgDb{} | |||
sysCfgDb.Set() | |||
uid := "0" | |||
tpdarenAppidData, _ := sysCfgDb.MasterListCfgGetOne(uid, "tpdaren_appid") | |||
tpdarenAppsecretData, _ := sysCfgDb.MasterListCfgGetOne(uid, "tpdaren_appsecret") | |||
if tpdarenAppidData == nil || tpdarenAppsecretData == nil { | |||
return | |||
} | |||
token := GetTpdarenToken(uid) | |||
if token == "" { | |||
return | |||
} | |||
i := 1 | |||
size := 200 | |||
for { | |||
param := map[string]interface{}{ | |||
"page_size": size, | |||
"page_index": i, | |||
} | |||
paging, err := tpdaren.TheaterFindPaging(token, param) | |||
if err != nil || paging == "" { | |||
break | |||
} | |||
listMap := gjson.Get(paging, "data.data").String() | |||
var list = make([]md.TpdarenList, 0) | |||
err = json.Unmarshal([]byte(listMap), &list) | |||
if err != nil { | |||
break | |||
} | |||
for _, v := range list { | |||
isEnd := "0" | |||
if v.IsEnd { | |||
isEnd = "1" | |||
} | |||
var tmp = md.Tpdaren{ | |||
Description: v.Description, | |||
Episode: v.Episode, | |||
ImageUrl: v.ImageUrl, | |||
IsEnd: isEnd, | |||
PayEpisode: v.PayEpisode, | |||
Material: v.Material, | |||
OnlineTime: v.OnlineTime, | |||
Type: "tpdaren", | |||
Title: v.Title, | |||
Data: utils.SerializeStr(v), | |||
ChannelTheaterId: v.ChannelTheaterId, | |||
DouyinTheaterId: v.DouyinTheaterId, | |||
KuaishouTheaterId: v.KuaishouTheaterId, | |||
UpdateTime: int(time.Now().Unix()), | |||
Time: int(utils.TimeStdParseUnix(v.OnlineTime + " 00:00:00")), | |||
Appid: tpdarenAppidData.V, | |||
} | |||
var uniqueId = "" | |||
if v.ChannelTheaterId > 0 { | |||
tmp.VideoType = "channel" | |||
uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + utils.IntToStr(v.ChannelTheaterId)) | |||
tmp.Id = v.ChannelTheaterId | |||
commAdd(uniqueId, tmp) | |||
} | |||
if v.DouyinTheaterId > 0 { | |||
tmp.VideoType = "douyin" | |||
uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + utils.IntToStr(v.DouyinTheaterId)) | |||
tmp.Id = v.DouyinTheaterId | |||
commAdd(uniqueId, tmp) | |||
} | |||
if v.KuaishouTheaterId > 0 { | |||
tmp.VideoType = "kuaishou" | |||
uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + utils.IntToStr(v.KuaishouTheaterId)) | |||
tmp.Id = v.KuaishouTheaterId | |||
commAdd(uniqueId, tmp) | |||
} | |||
} | |||
if len(list) < 200 { | |||
break | |||
} | |||
i++ | |||
} | |||
} | |||
func commAdd(uniqueId string, tmp md.Tpdaren) { | |||
doc, _ := es.FirstDoc(md2.ZhiosTpdarenEsIndex, uniqueId) | |||
if doc == nil { | |||
createDocRet, err := es.CreateDoc(md2.ZhiosTpdarenEsIndex, uniqueId, tmp) | |||
if err != nil { | |||
return | |||
} | |||
fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet) | |||
} else { | |||
createDocRet, err := es.UpdateDoc(md2.ZhiosTpdarenEsIndex, uniqueId, tmp) | |||
if err != nil { | |||
return | |||
} | |||
fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet) | |||
} | |||
} |
@@ -0,0 +1,289 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/task/md" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tpdaren" | |||
"encoding/json" | |||
"fmt" | |||
"github.com/tidwall/gjson" | |||
"strings" | |||
"time" | |||
) | |||
func PlayletVideoOrder() { | |||
defer func() { | |||
if err := recover(); err != nil { | |||
_ = logx.Error(err) | |||
} | |||
}() | |||
uid := "0" | |||
// 获取上次获取订单时候的时间戳 | |||
pvdTimeKey := "playlet_video_order_time" | |||
now := time.Now().Unix() | |||
past := GetRunTime(uid, pvdTimeKey, "短剧获取订单时间") | |||
var ( | |||
beginTime int64 = 0 | |||
endTime int64 = 0 | |||
pageNo int = 1 | |||
pageSize int = 200 | |||
) | |||
//怕时间不是走最新的 | |||
leave := now - past | |||
if leave > 500 { | |||
leave = 0 | |||
} | |||
var eveTime int64 = 3600 | |||
past = past + leave | |||
beginTime = past - eveTime | |||
endTime = past | |||
if endTime > now { | |||
endTime = now | |||
} | |||
for { | |||
// 分配堆内存 | |||
time.Sleep(time.Microsecond * 500) // 等待500毫秒 | |||
//获取订单 | |||
arg := map[string]interface{}{ | |||
"start": time.Unix(beginTime, 0).Format("2006-01-02 15:04:05"), | |||
"end": time.Unix(endTime, 0).Format("2006-01-02 15:04:05"), | |||
"page_size": pageSize, | |||
"page_index": pageNo, | |||
} | |||
count := getVideoOrder(uid, arg) | |||
if count == 0 { | |||
goto ChkArg | |||
} | |||
if count == pageSize { | |||
pageNo++ | |||
continue | |||
} | |||
ChkArg: | |||
// 查询完后重置时间, 最后查询时间 | |||
if endTime < now { | |||
pageNo = 1 | |||
SetRunTime(uid, pvdTimeKey, utils.TimeToStr(endTime)) | |||
beginTime = endTime | |||
endTime = endTime + eveTime | |||
if endTime > now { | |||
endTime = now | |||
} | |||
continue | |||
} | |||
break | |||
} | |||
// 更新最后供应商执行订单时间 | |||
SetRunTime(uid, pvdTimeKey, utils.TimeToStr(now)) | |||
} | |||
func PlayletVideoOrderYesterDay() { | |||
defer func() { | |||
if err := recover(); err != nil { | |||
_ = logx.Error(err) | |||
} | |||
}() | |||
uid := "0" | |||
timeRange := utils.GetTimeRange("today") | |||
hour := time.Now().Hour() | |||
if hour < 1 { | |||
return | |||
} | |||
syscfgDb := db.MasterListCfgDb{} | |||
syscfgDb.Set() | |||
playletVideoOrderYesterdayRuntime := syscfgDb.MasterListCfgGetOneData(uid, "playlet_video_order_yesterday_runtime") | |||
if utils.TimeStdParseUnix(playletVideoOrderYesterdayRuntime) > timeRange["start"] { | |||
return | |||
} | |||
var ( | |||
beginTime int64 = timeRange["start"] - 86400 | |||
endTime int64 = timeRange["start"] | |||
pageNo int = 1 | |||
pageSize int = 200 | |||
) | |||
for { | |||
// 分配堆内存 | |||
time.Sleep(time.Microsecond * 500) // 等待500毫秒 | |||
//获取订单 | |||
arg := map[string]interface{}{ | |||
"start": time.Unix(beginTime, 0).Format("2006-01-02 15:04:05"), | |||
"end": time.Unix(endTime, 0).Format("2006-01-02 15:04:05"), | |||
"page_size": pageSize, | |||
"page_index": pageNo, | |||
} | |||
count := getVideoOrder(uid, arg) | |||
if count == 0 { | |||
break | |||
} | |||
if count == pageSize { | |||
pageNo++ | |||
continue | |||
} | |||
} | |||
syscfgDb.MasterListCfgUpdate(uid, "playlet_video_order_yesterday_runtime", time.Now().Format("2006-01-02 15:04:05")) | |||
return | |||
} | |||
func PlayletVideoOrderMonth() { | |||
defer func() { | |||
if err := recover(); err != nil { | |||
_ = logx.Error(err) | |||
} | |||
}() | |||
uid := "0" | |||
timeRange := utils.GetTimeRange("last_month") | |||
t := time.Now() | |||
stime := time.Date(t.Year(), t.Month(), 5, 0, 0, 0, 0, t.Location()).Unix() | |||
day := time.Now().Day() | |||
if day < 5 { | |||
return | |||
} | |||
syscfgDb := db.MasterListCfgDb{} | |||
syscfgDb.Set() | |||
//上次开始的时间 | |||
keyStart := "playlet_video_order_month_starttime" | |||
starttime := syscfgDb.MasterListCfgGetOneData(uid, keyStart) | |||
//运行到哪一天 | |||
key := "playlet_video_order_month_runtime" | |||
runtime := syscfgDb.MasterListCfgGetOneData(uid, key) | |||
keyIsEnd := "playlet_video_order_month_is_end" | |||
if utils.TimeStdParseUnix(starttime) < stime { | |||
syscfgDb.MasterListCfgUpdate(uid, key, time.Now().Format("2006-01-02 15:04:05")) | |||
syscfgDb.MasterListCfgUpdate(uid, keyIsEnd, "") | |||
runtime = time.Unix(timeRange["start"], 0).Format("2006-01-02 15:04:05") | |||
} | |||
//当前是否结束了 | |||
isEnd := syscfgDb.MasterListCfgGetOneData(uid, keyIsEnd) | |||
if isEnd == "1" { | |||
return | |||
} | |||
var ( | |||
beginTime int64 = utils.TimeStdParseUnix(runtime) - 86400 | |||
endTime int64 = utils.TimeStdParseUnix(runtime) | |||
pageNo int = 1 | |||
pageSize int = 200 | |||
) | |||
for { | |||
// 分配堆内存 | |||
time.Sleep(time.Microsecond * 500) // 等待500毫秒 | |||
//获取订单 | |||
arg := map[string]interface{}{ | |||
"start": time.Unix(beginTime, 0).Format("2006-01-02 15:04:05"), | |||
"end": time.Unix(endTime, 0).Format("2006-01-02 15:04:05"), | |||
"page_size": pageSize, | |||
"page_index": pageNo, | |||
} | |||
count := getVideoOrder(uid, arg) | |||
if count == 0 { | |||
break | |||
} | |||
if count == pageSize { | |||
pageNo++ | |||
continue | |||
} | |||
} | |||
if endTime > time.Now().Unix() { | |||
syscfgDb.MasterListCfgUpdate(uid, keyIsEnd, "1") | |||
} | |||
syscfgDb.MasterListCfgUpdate(uid, key, time.Unix(endTime, 0).Format("2006-01-02 15:04:05")) | |||
return | |||
} | |||
func getVideoOrder(uids string, arg map[string]interface{}) int { | |||
list := make([]map[string]string, 0) | |||
token := GetTpdarenToken(uids) | |||
paging, err := tpdaren.OrderFindPaging(token, arg) | |||
fmt.Println("playletVideoOrder", paging) | |||
fmt.Println("playletVideoOrder", err) | |||
if paging == "" { | |||
return len(list) | |||
} | |||
data := gjson.Get(paging, "data.data").String() | |||
if data == "" { | |||
return len(list) | |||
} | |||
dataList := make([]md.PlayletVideoOrder, 0) | |||
json.Unmarshal([]byte(data), &dataList) | |||
sysCfgDb := db.MasterListCfgDb{} | |||
sysCfgDb.Set() | |||
playletKuaishouBili := sysCfgDb.MasterListCfgGetOneData(uids, "playlet_kuaishou_bili") | |||
playletDouyinBili := sysCfgDb.MasterListCfgGetOneData(uids, "playlet_douyin_bili") | |||
playletChannelBili := sysCfgDb.MasterListCfgGetOneData(uids, "playlet_channel_bili") | |||
var biliMap = map[string]string{ | |||
"kuaishou": playletKuaishouBili, | |||
"douyin": playletDouyinBili, | |||
"channel": playletChannelBili, | |||
} | |||
zyPlayletKuaishouBili := sysCfgDb.MasterListCfgGetOneData(uids, "zy_playlet_kuaishou_bili") | |||
zyPlayletDouyinBili := sysCfgDb.MasterListCfgGetOneData(uids, "zy_playlet_douyin_bili") | |||
zyPlayletChannelBili := sysCfgDb.MasterListCfgGetOneData(uids, "zy_playlet_channel_bili") | |||
var zyBiliMap = map[string]string{ | |||
"kuaishou": zyPlayletKuaishouBili, | |||
"douyin": zyPlayletDouyinBili, | |||
"channel": zyPlayletChannelBili, | |||
} | |||
var statusMap = map[int]string{ | |||
2: "订单退款", 4: "订单付款", | |||
} | |||
for _, v := range dataList { | |||
sourceIdArr := strings.Split(v.SourceId, "_") | |||
mid := "" | |||
uid := "" | |||
if len(sourceIdArr) == 2 { | |||
mid = sourceIdArr[0] | |||
uid = sourceIdArr[1] | |||
} | |||
if mid == "" || uid == "" { | |||
continue | |||
} | |||
money := utils.Float64ToStr(float64(v.Price) / 100) | |||
if v.Channel == "wechat" { | |||
v.Channel = "channel" | |||
} | |||
bili := biliMap[v.Channel] | |||
zyBili := zyBiliMap[v.Channel] | |||
platformFee := utils.Float64ToStr(utils.StrToFloat64(money) * utils.StrToFloat64(bili) / 100) | |||
zyFee := utils.Float64ToStr(utils.StrToFloat64(money) * utils.StrToFloat64(zyBili) / 100) | |||
commission := utils.Float64ToStr(utils.StrToFloat64(money) - utils.StrToFloat64(platformFee) - utils.StrToFloat64(zyFee)) | |||
var tmp = model.PlayletSaleOrder{ | |||
Uid: mid, | |||
SubUid: utils.StrToInt(uid), | |||
Data: utils.SerializeStr(v), | |||
Oid: v.OrderId, | |||
Amount: money, | |||
Commission: commission, | |||
CreateTime: utils.TimeParseStd(v.PayDate), | |||
UpdateTime: time.Now(), | |||
Title: v.Title, | |||
VideoType: v.Channel, | |||
PlatformType: "tpdaren", | |||
GoodsType: "playlet", | |||
OrdType: "video", | |||
ExtendUid: uids, | |||
Fee: zyFee, | |||
PlatformFee: platformFee, | |||
} | |||
playletSaleOrderDb := db.PlayletSaleOrderDb{} | |||
playletSaleOrderDb.Set() | |||
ord := playletSaleOrderDb.GetPlayletVideoOrderByOid(v.OrderId, tmp.OrdType) | |||
tmp.Status = statusMap[v.Status] | |||
if v.Status != 2 && v.SettleType == "1" { | |||
tmp.Status = "订单结算" | |||
if ord != nil && ord.PlatformSettleTime.IsZero() { | |||
tmp.PlatformSettleTime = time.Now() | |||
} | |||
} | |||
if v.RefundDate != "" { | |||
tmp.RefundTime = utils.TimeParseStd(v.RefundDate) | |||
} | |||
if ord != nil { | |||
playletSaleOrderDb.PlayletVideoOrderUpdate(ord.Id, &tmp) | |||
} else { | |||
tmp.CustomOid = utils.OrderUUID(tmp.SubUid) | |||
playletSaleOrderDb.PlayletVideoOrderInsert(&tmp) | |||
} | |||
} | |||
return len(list) | |||
} |
@@ -4,11 +4,10 @@ import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
// 取消订单 | |||
func taskCancelOrder(eg *xorm.Engine, dbName string) { | |||
// | |||
func taskPlayletAdvOrder() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
@@ -18,6 +17,6 @@ func taskCancelOrder(eg *xorm.Engine, dbName string) { | |||
} | |||
START: | |||
ch <- 1 | |||
svc.CancelOrder(eg, dbName) | |||
svc.PlayletAdvOrder() | |||
<-ch | |||
} |
@@ -0,0 +1,22 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
) | |||
// | |||
func taskPlayletAdvOrderMonth() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.PlayletAdvOrderMonth() | |||
<-ch | |||
} |
@@ -0,0 +1,22 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
) | |||
// | |||
func taskPlayletAdvOrderYesterday() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.PlayletAdvOrderYesterday(1, "playlet_adv_order_yesterday_runtime") | |||
<-ch | |||
} |
@@ -0,0 +1,22 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
) | |||
// | |||
func taskPlayletAdvOrderYesterdayToMoney() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.PlayletAdvOrderYesterday(12, "playlet_adv_order_yesterday_runtime") | |||
<-ch | |||
} |
@@ -0,0 +1,22 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
) | |||
// | |||
func taskPlayletGoods() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.PlayletGoods() | |||
<-ch | |||
} |
@@ -0,0 +1,22 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
) | |||
// | |||
func taskPlayletVideoOrder() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.PlayletVideoOrder() | |||
<-ch | |||
} |
@@ -0,0 +1,22 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
) | |||
// | |||
func taskPlayletVideoOrderMonth() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.PlayletVideoOrderMonth() | |||
<-ch | |||
} |
@@ -0,0 +1,22 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
) | |||
// | |||
func taskPlayletVideoOrderYesterday() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.PlayletVideoOrderYesterDay() | |||
<-ch | |||
} |
@@ -20,11 +20,16 @@ func init() { | |||
cfg.InitLog() | |||
// 初始化redis | |||
cfg.InitCache() | |||
cfg.InitEs() //ElasticSearch初始化 | |||
baseDb := *cfg.DB | |||
baseDb.Path = fmt.Sprintf(cfg.DB.Path, cfg.DB.Name) | |||
if err := db.InitDB(&baseDb); err != nil { | |||
panic(err) | |||
} | |||
if err := db.InitZhimengDB(cfg.ZhimengDB); err != nil { | |||
panic(err) | |||
} | |||
utils.CurlDebug = true | |||
//cfg.InitMemCache() | |||
} | |||
@@ -17,6 +17,17 @@ db: | |||
max_idle_conns: 100 | |||
path: 'tmp/task_sql_%v.log' | |||
zhimeng_db: | |||
host: '119.23.182.117:3306' | |||
name: 'zhi_meng' | |||
user: 'root' | |||
psw: 'Fnuo123com@' | |||
show_log: true | |||
max_lifetime: 30 | |||
max_open_conns: 100 | |||
max_idle_conns: 100 | |||
path: 'tmp/%s.log' | |||
# 日志 | |||
log: | |||
level: 'debug' # 普通日志级别 #debug, info, warn, fatal, panic | |||
@@ -28,3 +39,9 @@ log: | |||
file_max_size: 256 | |||
file_max_age: 1 | |||
file_name: 'task.log' | |||
# 连接ElasticSearch | |||
es: | |||
url: 'http://120.55.48.175:9200' | |||
user: 'elastic' | |||
pwd: 'fnuo123' |
@@ -3,57 +3,34 @@ module applet | |||
go 1.15 | |||
require ( | |||
github.com/360EntSecGroup-Skylar/excelize v1.4.1 // indirect | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.0 | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20230703061209-fc6ac71cc155 | |||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 | |||
github.com/antchfx/htmlquery v1.3.0 // indirect | |||
github.com/antchfx/xmlquery v1.3.16 // indirect | |||
github.com/boombuler/barcode v1.0.1 | |||
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 | |||
github.com/dgrijalva/jwt-go v3.2.0+incompatible | |||
github.com/forgoer/openssl v0.0.0-20201023062029-c3112b0c8700 | |||
github.com/gin-contrib/sessions v0.0.3 | |||
github.com/gin-gonic/gin v1.6.3 | |||
github.com/go-playground/locales v0.13.0 | |||
github.com/go-playground/universal-translator v0.17.0 | |||
github.com/go-playground/validator/v10 v10.4.2 | |||
github.com/gin-gonic/gin v1.8.0 | |||
github.com/go-playground/locales v0.14.0 | |||
github.com/go-playground/universal-translator v0.18.0 | |||
github.com/go-playground/validator/v10 v10.10.0 | |||
github.com/go-redis/redis v6.15.9+incompatible | |||
github.com/go-sql-driver/mysql v1.6.0 | |||
github.com/gobwas/glob v0.2.3 // indirect | |||
github.com/gocolly/colly v1.2.0 | |||
github.com/golang/protobuf v1.5.2 // indirect | |||
github.com/golang/snappy v0.0.3 // indirect | |||
github.com/gomodule/redigo v2.0.0+incompatible | |||
github.com/gorilla/sessions v1.2.1 // indirect | |||
github.com/json-iterator/go v1.1.10 // indirect | |||
github.com/kennygrant/sanitize v1.2.4 // indirect | |||
github.com/kr/text v0.2.0 // indirect | |||
github.com/leodido/go-urn v1.2.1 // indirect | |||
github.com/makiuchi-d/gozxing v0.0.0-20210324052758-57132e828831 | |||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | |||
github.com/modern-go/reflect2 v1.0.1 // indirect | |||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect | |||
github.com/onsi/ginkgo v1.15.0 // indirect | |||
github.com/onsi/gomega v1.10.5 // indirect | |||
github.com/pkg/errors v0.9.1 // indirect | |||
github.com/robfig/cron/v3 v3.0.1 | |||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect | |||
github.com/shopspring/decimal v1.3.1 | |||
github.com/smartystreets/goconvey v1.6.4 // indirect | |||
github.com/sony/sonyflake v1.0.0 | |||
github.com/stretchr/testify v1.7.0 // indirect | |||
github.com/syyongx/php2go v0.9.4 | |||
github.com/temoto/robotstxt v1.1.2 // indirect | |||
github.com/tidwall/gjson v1.7.4 | |||
github.com/ugorji/go v1.2.5 // indirect | |||
github.com/syyongx/php2go v0.9.7 | |||
github.com/tidwall/gjson v1.14.1 | |||
go.uber.org/multierr v1.6.0 // indirect | |||
go.uber.org/zap v1.16.0 | |||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect | |||
google.golang.org/appengine v1.6.1 // indirect | |||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect | |||
golang.org/x/net v0.7.0 // indirect | |||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 | |||
gopkg.in/yaml.v2 v2.4.0 | |||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect | |||
honnef.co/go/tools v0.0.1-2020.1.4 // indirect | |||
xorm.io/builder v0.3.9 // indirect | |||
xorm.io/xorm v1.0.7 | |||
xorm.io/xorm v1.3.2 | |||
) |
@@ -20,10 +20,14 @@ func init() { | |||
cfg.InitCfg() //配置初始化 | |||
cfg.InitLog() //日志初始化 | |||
cfg.InitCache() //缓存初始化 | |||
cfg.InitEs() //ElasticSearch初始化 | |||
if cfg.Debug { //判断是否是debug | |||
if err := db.InitDB(cfg.DB); err != nil { //主数据库初始化 | |||
panic(err) | |||
} | |||
if err := db.InitZhimengDB(cfg.ZhimengDB); err != nil { | |||
panic(err) | |||
} | |||
} | |||
fmt.Println("init success") | |||