Browse Source

test

master
huangjiajun 1 year ago
parent
commit
84dd3713c3
26 changed files with 691 additions and 3 deletions
  1. +9
    -0
      app/db/db_master_amount.go
  2. +36
    -0
      app/db/db_master_last_month_amount_list.go
  3. +10
    -0
      app/db/db_playlet_sale_order.go
  4. +1
    -0
      app/db/model/master_amount_flow.go
  5. +19
    -0
      app/db/model/master_last_month_amount_flow.go
  6. +52
    -0
      app/hdl/hdl_file_upload.go
  7. +45
    -0
      app/hdl/hdl_file_upload_callback.go
  8. +16
    -0
      app/lib/qiniu/bucket_create.go
  9. +18
    -0
      app/lib/qiniu/bucket_delete.go
  10. +18
    -0
      app/lib/qiniu/bucket_get_domain.go
  11. +20
    -0
      app/lib/qiniu/init.go
  12. +54
    -0
      app/lib/qiniu/req_img_upload.go
  13. +15
    -0
      app/md/cfg_key.go
  14. +54
    -0
      app/md/file.go
  15. +18
    -0
      app/mw/mw_init_validator.go
  16. +2
    -0
      app/router/router.go
  17. +5
    -0
      app/svc/platform/svc_withdrawal.go
  18. +68
    -0
      app/svc/svc_file_upload.go
  19. +4
    -0
      app/task/init.go
  20. +3
    -0
      app/task/md/cron_key.go
  21. +83
    -0
      app/task/svc/svc_master_month_settle.go
  22. +92
    -0
      app/task/svc/svc_playlet_order_settle.go
  23. +22
    -0
      app/task/task_master_month_settle.go
  24. +22
    -0
      app/task/task_playlet_order_settle.go
  25. +3
    -3
      app/utils/time.go
  26. +2
    -0
      go.mod

+ 9
- 0
app/db/db_master_amount.go View File

@@ -2,6 +2,7 @@ package db

import (
"applet/app/db/model"
"applet/app/utils"
"time"
"xorm.io/xorm"
)
@@ -23,6 +24,14 @@ func (masterAmountDb *MasterAmountDb) GetMasterAmount(id, types string) *model.M
}
return &data
}
func (masterAmountDb *MasterAmountDb) GetMasterAmountList(args map[string]string) *[]model.MasterAmount {
var data = make([]model.MasterAmount, 0)
size := utils.StrToInt(args["size"])
offet := (utils.StrToInt(args["p"]) - 1) * size
sess := masterAmountDb.Db.Where("last_month_amount>0")
sess.Limit(size, offet).OrderBy("id desc").Find(&data)
return &data
}
func (masterAmountDb *MasterAmountDb) GetMasterAmountByListId(id string) *model.MasterAmount {
var data model.MasterAmount
get, err := masterAmountDb.Db.Where("id=?", id).Get(&data)


+ 36
- 0
app/db/db_master_last_month_amount_list.go View File

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

import (
"applet/app/db/model"
"xorm.io/xorm"
)

type MasterLastMonthAmountFlowDb struct {
Db *xorm.Engine `json:"db"`
}

func (masterLastMonthAmountFlowDb *MasterLastMonthAmountFlowDb) Set() { // set方法
masterLastMonthAmountFlowDb.Db = ZhimengDb
}

func (masterLastMonthAmountFlowDb *MasterLastMonthAmountFlowDb) MasterLastMonthAmountListUpdate(id int, data *model.MasterLastMonthAmountFlow) bool {
get, err := masterLastMonthAmountFlowDb.Db.Where("id=?", id).Update(data)
if get == 0 || err != nil {
return false
}
return true
}
func (masterLastMonthAmountFlowDb *MasterLastMonthAmountFlowDb) MasterLastMonthAmountFlowInsert(data *model.MasterLastMonthAmountFlow) bool {
get, err := masterLastMonthAmountFlowDb.Db.InsertOne(data)
if get == 0 || err != nil {
return false
}
return true
}
func MasterLastMonthAmountFlowInsertWithSess(sess *xorm.Session, data *model.MasterLastMonthAmountFlow) bool {
get, err := sess.InsertOne(data)
if get == 0 || err != nil {
return false
}
return true
}

+ 10
- 0
app/db/db_playlet_sale_order.go View File

@@ -3,6 +3,7 @@ package db
import (
"applet/app/db/model"
"applet/app/utils"
"fmt"
"time"
"xorm.io/xorm"
)
@@ -64,6 +65,8 @@ func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderList(args map[
settle_status 结算状态
oid 订单号
sort 排序
is_to_settle 智盟结算
to_settle_time 结算上月时间
*/
var data = make([]model.PlayletSaleOrder, 0)
size := utils.StrToInt(args["size"])
@@ -75,12 +78,19 @@ func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderList(args map[
if args["end_time"] != "" {
sess = sess.And("update_time>=?", args["end_time"])
}
if args["to_settle_time"] != "" {
sess = sess.And("create_time<?", args["to_settle_time"])
}
sess = commWhere(sess, args)
sort := "update_time desc,id desc"
if args["sort"] != "" {
sort = args["sort"]
}
if args["is_to_settle"] == "1" {
sess = sess.And("settle_time=?", 0)
}
sess.Limit(size, offet).OrderBy(sort).Find(&data)
fmt.Println(sess.LastSQL())
return data
}
func (playletSaleOrderDb *PlayletSaleOrderDb) GetPlayletVideoOrderListAndTotal(args map[string]string) (*[]model.PlayletSaleOrder, int64) {


+ 1
- 0
app/db/model/master_amount_flow.go View File

@@ -15,4 +15,5 @@ type MasterAmountFlow struct {
Oid string `json:"oid" xorm:"VARCHAR(255)"`
Title string `json:"title" xorm:"VARCHAR(255)"`
FlowType string `json:"flow_type" xorm:"VARCHAR(255)"`
IncomeType int `json:"income_type" xorm:"default 0 INT(1)"`
}

+ 19
- 0
app/db/model/master_last_month_amount_flow.go View File

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

import (
"time"
)

type MasterLastMonthAmountFlow struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid string `json:"uid" xorm:"VARCHAR(255)"`
Time time.Time `json:"time" xorm:"DATETIME"`
BeforeAmount string `json:"before_amount" xorm:"default 0.00 DECIMAL(20,2)"`
Amount string `json:"amount" xorm:"default 0.00 DECIMAL(20,2)"`
AfterAmount string `json:"after_amount" xorm:"default 0.00 DECIMAL(20,2)"`
Platform string `json:"platform" xorm:"VARCHAR(255)"`
Oid string `json:"oid" xorm:"VARCHAR(255)"`
Title string `json:"title" xorm:"VARCHAR(255)"`
FlowType string `json:"flow_type" xorm:"VARCHAR(255)"`
IncomeType int `json:"income_type" xorm:"default 0 INT(1)"`
}

+ 52
- 0
app/hdl/hdl_file_upload.go View File

@@ -0,0 +1,52 @@
package hdl

import (
"applet/app/db"
"applet/app/e"
"applet/app/lib/validate"
"applet/app/svc"
"applet/app/utils"
"github.com/gin-gonic/gin"
"github.com/mcuadros/go-defaults"
)

func ImgReqUpload(c *gin.Context) {
var args struct {
DirName string `json:"dir_name,omitempty" default:"0"`
FileName string `json:"file_name" binding:"required" label:"文件名"`
FileSize int64 `json:"file_size" binding:"gt=1" label:"文件大小"` // 文件大小, 单位byte
}
defaults.SetDefaults(&args)
err := c.ShouldBindJSON(&args)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}

scheme := "http"
if c.Request.TLS != nil {
scheme = "https"
}
// 拼装回调地址
callbackUrl := scheme + "://" + c.Request.Host + "/api/admin/file/upload/callback"
res, err := svc.ImgReqUpload(c, "", args.DirName, args.FileName, callbackUrl, args.FileSize)
if err != nil {
e.OutErr(c, e.ERR_BAD_REQUEST, err.Error())
return
}
my := utils.SerializeStr(res)
var my1 map[string]interface{}
utils.Unserialize([]byte(my), &my1)
masterListCfgDb := db.MasterListCfgDb{}
masterListCfgDb.Set()
fileBucketRegion := masterListCfgDb.MasterListCfgGetOneData("0", "file_bucket_region")
if err != nil {
e.OutErr(c, e.ERR_BAD_REQUEST, err)
return
}
my1["host"] = fileBucketRegion
e.OutSuc(c, my1, nil)

}

+ 45
- 0
app/hdl/hdl_file_upload_callback.go View File

@@ -0,0 +1,45 @@
package hdl

import (
"applet/app/db"
"applet/app/e"
"applet/app/md"
"applet/app/utils"
"fmt"
"github.com/gin-gonic/gin"
)

func FileImgCallback(c *gin.Context) {
var args md.FileCallback
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, 200, e.ERR_INVALID_ARGS)
return
}
fmt.Println("callback args:", utils.SerializeStr(args))

res := map[string]interface{}{
"name": args.FileName,
"fname": getFileNameURL(c, args.FileName),
"fsize": args.FileSize,
"provider": args.Provider,
"uid": args.Uid,
"dir_id": args.DirId,
"w": args.Width,
"h": args.Height,
}
fmt.Println("callback res:", utils.SerializeStr(res))

e.OutSuc(c, &res, nil)

}

func getFileNameURL(c *gin.Context, filename string) string {
masterListCfgDb := db.MasterListCfgDb{}
masterListCfgDb.Set()
protocol := masterListCfgDb.MasterListCfgGetOneData("0", "file_bucket_scheme")
domain := masterListCfgDb.MasterListCfgGetOneData("0", "file_bucket_host")
if protocol != "" && domain != "" {
return protocol + "://" + domain + "/" + filename
}
return filename
}

+ 16
- 0
app/lib/qiniu/bucket_create.go View File

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

import (
"github.com/qiniu/api.v7/v7/auth"
"github.com/qiniu/api.v7/v7/storage"
)

func BucketCreate() error {
mac := auth.New(AK, SK)
cfg := storage.Config{
// 是否使用https域名进行资源管理
UseHTTPS: false,
}
bucketManager := storage.NewBucketManager(mac, &cfg)
return bucketManager.CreateBucket("", storage.RIDHuanan)
}

+ 18
- 0
app/lib/qiniu/bucket_delete.go View File

@@ -0,0 +1,18 @@
package qiniu

import (
"github.com/qiniu/api.v7/v7/auth"
"github.com/qiniu/api.v7/v7/storage"
)

func BucketDelete(bucketName string) error {
mac := auth.New(AK, SK)

cfg := storage.Config{
// 是否使用https域名进行资源管理
UseHTTPS: false,
}

bucketManager := storage.NewBucketManager(mac, &cfg)
return bucketManager.DropBucket(bucketName)
}

+ 18
- 0
app/lib/qiniu/bucket_get_domain.go View File

@@ -0,0 +1,18 @@
package qiniu

import (
"github.com/qiniu/api.v7/v7/auth"
"github.com/qiniu/api.v7/v7/storage"
)

func BucketGetDomain(bucketName string) (string, error) {
mac := auth.New(AK, SK)

cfg := storage.Config{UseHTTPS: false}
bucketManager := storage.NewBucketManager(mac, &cfg)
b, err := bucketManager.ListBucketDomains(bucketName)
if err != nil {
return "", err
}
return b[0].Domain, nil
}

+ 20
- 0
app/lib/qiniu/init.go View File

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

import "applet/app/utils"

var (
AK = "MmxNdai23egjNUHjdzEVaTPdPCIbWzENz9BQuak3"
SK = "mElaFlM9O16rXp-ihoQdJ9KOH56naKm3MoyQBA59"
BUCKET = "dev-fnuoos" // 桶子名称
BUCKET_SCHEME = "http"
BUCKET_REGION = "up-z2.qiniup.com"
Expires uint64 = 3600
)

func Init(ak, sk, bucket, region, scheme string) {
AK, SK, BUCKET, BUCKET_REGION, BUCKET_SCHEME = ak, sk, bucket, region, scheme
}

func Sign(t string) string {
return utils.Md5(AK + SK + t)
}

+ 54
- 0
app/lib/qiniu/req_img_upload.go View File

@@ -0,0 +1,54 @@
package qiniu

import (
"applet/app/md"
"applet/app/utils"
"time"

"github.com/qiniu/api.v7/v7/auth/qbox"
_ "github.com/qiniu/api.v7/v7/conf"
"github.com/qiniu/api.v7/v7/storage"
)

// 请求图片上传地址信息
func ReqImgUpload(f *md.FileCallback, callbackUrl string) interface{} {
if ext := utils.FileExt(f.FileName); ext == "png" || ext == "jpg" || ext == "jpeg" || ext == "gif" || ext == "bmp" || ext == "webp" {
f.Width = "$(imageInfo.width)"
f.Height = "$(imageInfo.height)"
}
f.Provider = "qiniu"
f.FileSize = "$(fsize)"
f.Hash = "$(etag)"
f.Bucket = "$(bucket)"
f.Mime = "$(mimeType)"
f.Time = utils.Int64ToStr(time.Now().Unix())
f.Sign = Sign(f.Time)
putPolicy := storage.PutPolicy{
Scope: BUCKET + ":" + f.FileName, // 使用覆盖方式时候必须请求里面有key,否则报错
Expires: Expires,
ForceSaveKey: true,
SaveKey: f.FileName,
MimeLimit: "image/*", // 只允许上传图片
CallbackURL: callbackUrl,
CallbackBody: utils.SerializeStr(f),
CallbackBodyType: "application/json",
}
return &struct {
Method string `json:"method"`
Key string `json:"key"`
Host string `json:"host"`
Token string `json:"token"`
}{Key: f.FileName, Method: "POST", Host: BUCKET_SCHEME + "://" + BUCKET_REGION, Token: putPolicy.UploadToken(qbox.NewMac(AK, SK))}
}

/*
form表单上传
地址 : http://upload-z2.qiniup.com
header
- Content-Type : multipart/form-data

body :
- key : 文件名
- token : 生成token
- file : 待上传文件
*/

+ 15
- 0
app/md/cfg_key.go View File

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

const (
// 文件缓存的key
KEY_CFG_FILE_PVD = "file_provider" // 文件供应商
KEY_CFG_FILE_BUCKET = "file_bucket"
KEY_CFG_FILE_REGION = "file_bucket_region"
KEY_CFG_FILE_HOST = "file_bucket_host"
KEY_CFG_FILE_SCHEME = "file_bucket_scheme"
KEY_CFG_FILE_AK = "file_access_key"
KEY_CFG_FILE_SK = "file_secret_key"
KEY_CFG_FILE_MAX_SIZE = "file_user_upload_max_size"
KEY_CFG_FILE_EXT = "file_ext"
KEY_CFG_FILE_AVATAR_THUMBNAIL = "file_avatar_thumbnail" // 默认头像缩略图参数,宽高120px,格式webp.
)

+ 54
- 0
app/md/file.go View File

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

// 用户拥有上传权限的目录, 目录ID

const (
FILE_DIR_FEEDBACK = "feedback"
FILE_DIR_AVATAR = "avatar"
FILE_DIR_QRCODE = "qrcode"
FILE_DIR_STYLE = "style"
)

var (
FileUserDir = map[string]string{
FILE_DIR_FEEDBACK: "4", // 用户反馈
FILE_DIR_AVATAR: "5", // 用户头像
FILE_DIR_QRCODE: "6", // 用户微信二维码
FILE_DIR_STYLE: "7", // 用户样式
}
)

// 文件回调信息
type FileCallback struct {
Uid string `json:"uid"`
DirId string `json:"dir_id"`
Provider string `json:"provider"` // 供应商
FileName string `json:"fname"` // 原文件名
FileSize string `json:"fsize"`
Hash string `json:"hash"`
Bucket string `json:"bucket"`
Mime string `json:"mime"`
Width string `json:"w,omitempty"`
Height string `json:"h,omitempty"`
Time string `json:"time"` // 默认一个小时内要上传完毕,否则超时
Sign string `json:"sign"` // 签名
}

type FileList struct {
Path string `json:"path"`
DirId int `json:"dir_id"`
FileName string `json:"f_name"` // 显示名称
StgName string `json:"stg_name"` // 存储名字
Ext string `json:"ext"` // 后缀名, png,jpg等
FileSize string `json:"f_size"`
Provider string `json:"provider"` // 存储供应商
Hash string `json:"hash"`
Bucket string `json:"bucket"`
Width int `json:"w"`
Height int `json:"h"`
Mime string `json:"mime"`
IsAdm bool `json:"is_adm"` //是否管理后台上传
IsDir bool `json:"is_dir"` //是否文件夹
CreateAt int `json:"create_at"`
Url string `json:"url"`
}

+ 18
- 0
app/mw/mw_init_validator.go View File

@@ -0,0 +1,18 @@
package mw

import (
"applet/app/e"
"applet/app/utils"
"fmt"
"github.com/gin-gonic/gin"
)

func InitReqValidator(c *gin.Context) {
// 初始化翻译器
if err := utils.ValidatorTransInitZh(); err != nil {
e.OutErr(c, e.ERR, fmt.Sprintf("init trans failed, err:%v\n", err))
return
}

c.Next()
}

+ 2
- 0
app/router/router.go View File

@@ -64,6 +64,8 @@ func routeZhimeng(r *gin.RouterGroup) {
r.GET("/authorizationCode", hdl.GetAuthorizationCode)
r.GET("/token", hdl.GetToken)
r.POST("/rToken", hdl.RefreshToken)
r.POST("/file/upload/token", mw.InitReqValidator, hdl.ImgReqUpload) // 文件上传获取七牛云上传token
r.POST("/file/upload/callback", hdl.FileImgCallback) // 文件上传回调

r.Use(mw.AuthJWT, mw.RequestCache) // 以下接口需要JWT验证
{


+ 5
- 0
app/svc/platform/svc_withdrawal.go View File

@@ -107,6 +107,11 @@ func WithdrawalDoing(c *gin.Context) {
masterListCfgDb.Set()
withdrawalBili := masterListCfgDb.MasterListCfgGetOneData("0", "withdrawal_bili")
invoiceBili := masterListCfgDb.MasterListCfgGetOneData("0", "invoice_bili")
withdrawalDay := masterListCfgDb.MasterListCfgGetOneData("0", "withdrawal_day")
if time.Now().Day() != utils.StrToInt(withdrawalDay) && utils.StrToInt(withdrawalDay) > 0 {
e.OutErr(c, 400, e.NewErr(400, "每月"+withdrawalDay+"号提现"))
return
}
var fee float64 = 0
if utils.StrToFloat64(withdrawalBili) > 0 {
bili := utils.StrToFloat64(withdrawalBili) / 100


+ 68
- 0
app/svc/svc_file_upload.go View File

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

import (
"applet/app/db"
"applet/app/e"
"applet/app/lib/qiniu"
"applet/app/md"
"applet/app/utils"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"strings"
"time"
)

// 请求文件上传
func ImgReqUpload(c *gin.Context, uid, dirName, fname, callbackUrl string, fsize int64) (interface{}, error) {
ext := utils.FileExt(fname)
if err := initStg(c, fsize, ext); err != nil {
return nil, err
}
pureFileName := strings.Replace(fname, "."+ext, "", 1)
pureFileName += "-" + utils.RandString(6, utils.AnyToString(time.Now().UnixNano()))
newName := dirName + "/" + pureFileName + "." + ext

f := &md.FileCallback{
Uid: uid,
DirId: dirName,
FileName: newName,
}
return qiniu.ReqImgUpload(f, callbackUrl), nil
}

func initStg(c *gin.Context, fsize int64, ext string) error {
// 获取上传配置
fileCfg := make(map[string]string)
masterListCfgDb := db.MasterListCfgDb{}
masterListCfgDb.Set()
fileCfg[md.KEY_CFG_FILE_BUCKET] = masterListCfgDb.MasterListCfgGetOneData("0", md.KEY_CFG_FILE_BUCKET)
fileCfg[md.KEY_CFG_FILE_HOST] = masterListCfgDb.MasterListCfgGetOneData("0", md.KEY_CFG_FILE_HOST)
fileCfg[md.KEY_CFG_FILE_AK] = masterListCfgDb.MasterListCfgGetOneData("0", md.KEY_CFG_FILE_AK)
fileCfg[md.KEY_CFG_FILE_SK] = masterListCfgDb.MasterListCfgGetOneData("0", md.KEY_CFG_FILE_SK)
fileCfg[md.KEY_CFG_FILE_PVD] = masterListCfgDb.MasterListCfgGetOneData("0", md.KEY_CFG_FILE_PVD)
fileCfg[md.KEY_CFG_FILE_MAX_SIZE] = masterListCfgDb.MasterListCfgGetOneData("0", md.KEY_CFG_FILE_MAX_SIZE)
fileCfg[md.KEY_CFG_FILE_EXT] = masterListCfgDb.MasterListCfgGetOneData("0", md.KEY_CFG_FILE_EXT)
fileCfg[md.KEY_CFG_FILE_SCHEME] = masterListCfgDb.MasterListCfgGetOneData("0", md.KEY_CFG_FILE_SCHEME)
utils.FilePutContents("initStg", fmt.Sprintf("[KEY_CFG_FILE_BUCKET]:%s ; [KEY_CFG_FILE_HOST]:%s ; [KEY_CFG_FILE_AK]::%s;"+
" [KEY_CFG_FILE_SK]::%s, ;[KEY_CFG_FILE_PVD]::%s, ;[KEY_CFG_FILE_REGION]::%s, ;[KEY_CFG_FILE_MAX_SIZE]::%s, ;[KEY_CFG_FILE_EXT]::%s, ;[KEY_CFG_FILE_SCHEME]::%s, "+
">>>>>>>>>>>>>>>>>>>>", fileCfg[md.KEY_CFG_FILE_BUCKET], fileCfg[md.KEY_CFG_FILE_HOST], fileCfg[md.KEY_CFG_FILE_AK], fileCfg[md.KEY_CFG_FILE_SK],
fileCfg[md.KEY_CFG_FILE_PVD], fileCfg[md.KEY_CFG_FILE_REGION], fileCfg[md.KEY_CFG_FILE_MAX_SIZE], fileCfg[md.KEY_CFG_FILE_EXT], fileCfg[md.KEY_CFG_FILE_SCHEME]))
for _, v := range fileCfg {
if v == "" {
return errors.New("上传配置不完整")
}
}

qiniu.Init(fileCfg[md.KEY_CFG_FILE_AK], fileCfg[md.KEY_CFG_FILE_SK], fileCfg[md.KEY_CFG_FILE_BUCKET], fileCfg[md.KEY_CFG_FILE_REGION], fileCfg[md.KEY_CFG_FILE_SCHEME])

// 检查文件大小限制
if utils.StrToInt64(fileCfg[md.KEY_CFG_FILE_MAX_SIZE]) < fsize {
return e.NewErrCode(e.ERR_FILE_MAX_SIZE)
}
// 检查文件后缀
if !strings.Contains(fileCfg[md.KEY_CFG_FILE_EXT], ext) {
return e.NewErrCode(e.ERR_FILE_EXT)
}
return nil
}

+ 4
- 0
app/task/init.go View File

@@ -91,4 +91,8 @@ func initTasks() {
jobs[taskMd.ZhimengCronPlayletAdvOrderYesterDay] = taskPlayletAdvOrderYesterday //
jobs[taskMd.ZhimengCronPlayletAdvOrderYesterDayToMoney] = taskPlayletAdvOrderYesterdayToMoney //
jobs[taskMd.ZhimengCronPlayletGoods] = taskPlayletGoods //

jobs[taskMd.ZhimengCronPlayletOrderSettle] = taskPlayletOrderSettle //
jobs[taskMd.ZhimengCronMasterMonthSettle] = taskMasterMonthSettle //

}

+ 3
- 0
app/task/md/cron_key.go View File

@@ -9,4 +9,7 @@ const (
ZhimengCronPlayletAdvOrderMonth = "zhimeng_cron_playlet_adv_order_month"
ZhimengCronPlayletAdvOrderYesterDayToMoney = "zhimeng_cron_playlet_adv_order_yesterday_to_money"
ZhimengCronPlayletGoods = "zhimeng_cron_playlet_goods"

ZhimengCronPlayletOrderSettle = "zhimeng_cron_playlet_order_settle"
ZhimengCronMasterMonthSettle = "zhimeng_cron_master_month_settle"
)

+ 83
- 0
app/task/svc/svc_master_month_settle.go View File

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

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/utils"
"applet/app/utils/cache"
"fmt"
"time"
)

func MasterMonthSettle() {
day := time.Now().Day()
masterListCfgDb := db.MasterListCfgDb{}
masterListCfgDb.Set()
withdrawalDay := masterListCfgDb.MasterListCfgGetOneData("0", "withdrawal_day")
if day < utils.StrToInt(withdrawalDay) {
return
}
args := map[string]string{
"p": "1",
"size": "100",
}
masterAmountDb := db.MasterAmountDb{}
masterAmountDb.Set()
list := masterAmountDb.GetMasterAmountList(args)
if list == nil {
return
}
for _, v := range *list {
mutexKey := fmt.Sprintf("master_month_settle:%d", v.Id)
withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 1800, "NX")
if err != nil {
continue
}
if withdrawAvailable != "OK" {
continue
}
if utils.StrToFloat64(v.LastMonthAmount) <= 0 {
continue
}
oldAmount := v.Amount
oldLastMonthAmount := v.LastMonthAmount
v.Amount = utils.Float64ToStr(utils.StrToFloat64(v.Amount) + utils.StrToFloat64(v.LastMonthAmount))
v.LastMonthAmount = "0"
update := masterAmountDb.MasterAmountUpdate(v.Id, &v)
if update == false {
continue
}
var tmp = model.MasterAmountFlow{
Uid: v.Uid,
Time: time.Now(),
BeforeAmount: oldAmount,
Amount: oldLastMonthAmount,
AfterAmount: v.Amount,
Platform: "playlet",
Oid: utils.IntToStr(v.Id),
Title: "短剧上月结算佣金到账",
FlowType: "last_month_playlet_settle",
IncomeType: 0,
}
masterAmountFlowDb := db.MasterAmountFlowDb{}
masterAmountFlowDb.Set()
masterAmountFlowDb.MasterAmountFlowInsert(&tmp)

var tmpLastMonth = model.MasterLastMonthAmountFlow{
Uid: v.Uid,
Time: time.Now(),
BeforeAmount: oldLastMonthAmount,
Amount: oldLastMonthAmount,
AfterAmount: v.LastMonthAmount,
Platform: "playlet",
Oid: utils.IntToStr(v.Id),
Title: "短剧上月结算佣金转到余额",
FlowType: "last_month_playlet_settle",
IncomeType: 1,
}
masterLastMonthAmountFlowDb := db.MasterLastMonthAmountFlowDb{}
masterLastMonthAmountFlowDb.Set()
masterLastMonthAmountFlowDb.MasterLastMonthAmountFlowInsert(&tmpLastMonth)

}
}

+ 92
- 0
app/task/svc/svc_playlet_order_settle.go View File

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

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/utils"
"applet/app/utils/cache"
"fmt"
"time"
)

func PlayletOrderSettle() {
day := time.Now().Day()
if day < 5 {
return
}
month := utils.GetTimeRange("current_month")
fmt.Println(month)
arg := map[string]string{
"status": "订单结算",
"sort": "id desc",
"is_to_settle": "1",
"to_settle_time": time.Unix(month["start"], 0).Format("2006-01-02 15:04:05"),
"p": "1",
"size": "100",
}
playletSaleOrderDb := db.PlayletSaleOrderDb{}
playletSaleOrderDb.Set()
order := playletSaleOrderDb.GetPlayletVideoOrderList(arg)
if len(order) == 0 {
return
}

for _, v := range order {
// 加锁 防止并发提取
mutexKey := fmt.Sprintf("playlet_order_settle:%s", v.CustomOid)
withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 1800, "NX")
if err != nil {
continue
}
if withdrawAvailable != "OK" {
continue
}
if v.SettleTime > 0 {
continue
}
//加到上月结算
if v.Uid == "" || v.Uid == "0" {
continue
}
masterDb := db.MasterDb{}
masterDb.Set()
master := masterDb.GetMaster(v.Uid)
if master == nil {
continue
}
masterAmountDb := db.MasterAmountDb{}
masterAmountDb.Set()
amount := masterAmountDb.GetMasterAmount(utils.IntToStr(master.Id), "playlet")
if amount == nil {
continue
}
if utils.StrToFloat64(v.Commission) <= 0 {
v.SettleTime = int(time.Now().Unix())
playletSaleOrderDb.PlayletVideoOrderUpdate(v.Id, &v)
continue
}
oldAmount := amount.LastMonthAmount
amount.LastMonthAmount = utils.Float64ToStr(utils.StrToFloat64(amount.LastMonthAmount) + utils.StrToFloat64(v.Commission))
update := masterAmountDb.MasterAmountUpdate(master.Id, amount)
if update == false {
continue
}
var tmp = model.MasterLastMonthAmountFlow{
Uid: utils.IntToStr(master.Id),
Time: time.Now(),
BeforeAmount: oldAmount,
Amount: v.Commission,
AfterAmount: amount.LastMonthAmount,
Platform: "playlet",
Oid: v.Oid,
Title: "短剧订单结算",
FlowType: "playlet_settle",
}
masterLastMonthAmountFlowDb := db.MasterLastMonthAmountFlowDb{}
masterLastMonthAmountFlowDb.Set()
masterLastMonthAmountFlowDb.MasterLastMonthAmountFlowInsert(&tmp)
v.SettleTime = int(time.Now().Unix())
playletSaleOrderDb.PlayletVideoOrderUpdate(v.Id, &v)
}
return
}

+ 22
- 0
app/task/task_master_month_settle.go View File

@@ -0,0 +1,22 @@
package task

import (
"applet/app/task/svc"
"math/rand"
"time"
)

//
func taskMasterMonthSettle() {
for {
if len(ch) > workerNum {
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000)))
} else {
goto START
}
}
START:
ch <- 1
svc.MasterMonthSettle()
<-ch
}

+ 22
- 0
app/task/task_playlet_order_settle.go View File

@@ -0,0 +1,22 @@
package task

import (
"applet/app/task/svc"
"math/rand"
"time"
)

//
func taskPlayletOrderSettle() {
for {
if len(ch) > workerNum {
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000)))
} else {
goto START
}
}
START:
ch <- 1
svc.PlayletOrderSettle()
<-ch
}

+ 3
- 3
app/utils/time.go View File

@@ -168,11 +168,11 @@ func GetTimeRange(s string) map[string]int64 {
// 明天 0点
etime = time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, t.Location())
case "current_month":
stime = time.Date(t.Year(), t.Month(), 0, 0, 0, 0, 0, t.Location())
stime = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
etime = time.Date(t.Year(), t.Month()+1, 0, 0, 0, 0, 0, t.Location())
case "last_month":
stime = time.Date(t.Year(), t.Month()-1, 0, 0, 0, 0, 0, t.Location())
etime = time.Date(t.Year(), t.Month(), 0, 0, 0, 0, 0, t.Location())
stime = time.Date(t.Year(), t.Month()-1, 1, 0, 0, 0, 0, t.Location())
etime = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
}

return map[string]int64{


+ 2
- 0
go.mod View File

@@ -20,6 +20,8 @@ require (
github.com/go-sql-driver/mysql v1.6.0
github.com/gomodule/redigo v2.0.0+incompatible
github.com/makiuchi-d/gozxing v0.1.1
github.com/mcuadros/go-defaults v1.2.0
github.com/qiniu/api.v7/v7 v7.8.2
github.com/robfig/cron/v3 v3.0.1
github.com/sony/sonyflake v1.1.0
github.com/syyongx/php2go v0.9.7


Loading…
Cancel
Save