aa
This commit is contained in:
@@ -3,8 +3,10 @@ package cms
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtunionapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/tbunionapi"
|
||||
"math"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -143,7 +145,7 @@ func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (jobID int, errCod
|
||||
if userBill.AccountBalance < job.TotalPrice {
|
||||
return 0, model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("用户余额不足!")
|
||||
}
|
||||
jobs, _ := dao.GetJobsNoPage(db, []string{job.UserID}, nil, nil, nil, DayTimeBegin, DayTimeEnd, 0, false)
|
||||
jobs, _ := dao.GetJobsNoPage(db, []string{job.UserID}, nil, nil, nil, nil, DayTimeBegin, DayTimeEnd, 0, false)
|
||||
if len(jobs) > 0 {
|
||||
members, err := dao.GetUserMember(db, job.UserID, model.MemberTypeNormal)
|
||||
if err != nil {
|
||||
@@ -904,7 +906,7 @@ func RefreshJobStatus(ctx *jxcontext.Context) (err error) {
|
||||
db = dao.GetDB()
|
||||
)
|
||||
globals.SugarLogger.Debugf("RefreshJobStatus begin...")
|
||||
jobs, err := dao.GetJobsNoPage(db, nil, nil, []int{model.JobStatusDoing}, nil, utils.ZeroTimeValue, utils.ZeroTimeValue, 0, false)
|
||||
jobs, err := dao.GetJobsNoPage(db, nil, nil, nil, []int{model.JobStatusDoing}, nil, utils.ZeroTimeValue, utils.ZeroTimeValue, 0, false)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("RefreshJobStatus err :%v", err)
|
||||
return
|
||||
@@ -1956,6 +1958,7 @@ func TempJob() (err error) {
|
||||
// }, []int{0, 1})
|
||||
//tasksch.HandleTask(task, nil, true).Run()
|
||||
//task.GetID()
|
||||
MtUnionJobAutoUpdate(jxcontext.AdminCtx)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2141,3 +2144,79 @@ func GetVendorMatterRcmmd(ctx *jxcontext.Context, vendorID int, goodsID string,
|
||||
handler := partner.GetHandler(vendorID)
|
||||
return handler.GetUnionMatterListRcmmd(ctx, goodsID, rcmmdType, offset, pageSize)
|
||||
}
|
||||
|
||||
func MtUnionJobAutoUpdate(ctx *jxcontext.Context) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
actMap = make(map[int]*mtunionapi.ActivityListResult)
|
||||
jobMap = make(map[int]*dao.GetJobsResult)
|
||||
addList []*mtunionapi.ActivityListResult
|
||||
now = time.Now()
|
||||
)
|
||||
//先找出美团联盟所有发布任务(此任务只用于显示)
|
||||
jobs, _ := dao.GetJobsNoPage(db, nil, []int{model.VendorIDMTWM}, []int{model.JobCategoryIDUnion}, []int{model.JobStatusDoing}, nil, utils.ZeroTimeValue, utils.ZeroTimeValue, 0, false)
|
||||
//再查美团联盟上的所有活动
|
||||
acts, _ := api.MtUnionAPI.ActivityList(1, 30, 0)
|
||||
for _, v := range acts {
|
||||
if v.DateBound != "" {
|
||||
dateBegin := utils.Str2Time(v.DateBound[:strings.LastIndex(v.DateBound, "至")-1])
|
||||
dateEnd := utils.Str2Time(v.DateBound[strings.LastIndex(v.DateBound, "至")+4:])
|
||||
//在有效期内
|
||||
if now.Sub(dateBegin) > 0 && dateEnd.Sub(now) > 0 {
|
||||
actMap[v.ID] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
//筛一下
|
||||
for _, v := range jobs {
|
||||
jobMap[utils.Str2Int(v.UnionActID)] = v
|
||||
}
|
||||
for k := range actMap {
|
||||
if jobMap[k] == nil {
|
||||
//add
|
||||
addList = append(addList, actMap[k])
|
||||
}
|
||||
}
|
||||
//建任务
|
||||
for _, v := range actMap {
|
||||
//推广规则
|
||||
storeURL := ""
|
||||
percentage := 0
|
||||
dateEnd := v.DateBound[strings.LastIndex(v.DateBound, "至")+4:]
|
||||
if v.ActRule != "" {
|
||||
if storeURLs := regexp.MustCompile(`href=\\\\\\"(.*?)"\\\\\\`).FindStringSubmatch(v.ActRule); len(storeURLs) > 0 {
|
||||
fmt.Println("storeURLs .........................", storeURLs)
|
||||
storeURL = storeURLs[1]
|
||||
}
|
||||
}
|
||||
if v.Ratio != "" {
|
||||
if ratios := regexp.MustCompile(`([0-9])`).FindStringSubmatch(v.Ratio); len(ratios) > 0 {
|
||||
percentage = utils.Str2Int(ratios[1])
|
||||
}
|
||||
}
|
||||
PublishJob(ctx, &model.JobExt{
|
||||
FinishedAtStr: dateEnd,
|
||||
Job: model.Job{
|
||||
VendorID: model.VendorIDMTWM,
|
||||
Title: v.ActName,
|
||||
JobCategoryID: model.JobCategoryIDUnion,
|
||||
Content: `
|
||||
<p class='p'>1.本次活动中红包领取时间截止至2022年6月20日24点;</p><p class='p'>2.订单同步为次日,例如12日下的订单,在13日24:00前可同步到返佣订单;</p><p class='p'>3.红包可在美团或美团外卖最新版客户端、美团外卖小程序下单且选择在线支付时使用;</p><p class='p'>4.红包仅限非到店自取外卖订单,下午茶、夜宵、美食、蛋糕、团餐频道、甜点饮品频道使用;</p><p class='p'>5.外卖新人首单红包限新用户(设备、 手机号、美团账号均未在美团外卖下过单)首次下单使用,且不与其他优惠(首减、满减、满赠、套餐增、折扣菜)同享;</p><p class='p'>6.使用红包时下单手机号码必须与收餐人手机号码、领取红包时输入的手机号码一致;</p><p class='p'>7.此活动为部分区域有效,具体红包使用有效期及红包金额以实际收到为准;</p><p class='p'>8.其余问题详见美团外卖客户端:我的一红包一美团红包、商家代金券使用说明;</p><p class='p'>9.活动过程中,任何活动参与方存在虚假交易、恶意套利、作弊等不诚信行为,美团外卖有权取消活动参与方的活动资格,并保留依法追究法律责任的权利;</p><p class='p'>10.活动期间,如出现不可抗力或情势变更的情况,美团外卖可依相关法律法规的规定主张免责;</p><p class='p'>11.分享赚钱中获取到图片后长按图片分享给好友;</p><p class='p'></p>
|
||||
`,
|
||||
Count: 99999,
|
||||
StoreURL: storeURL,
|
||||
SurplusCount: 99999,
|
||||
JobLimitAt: 99999,
|
||||
LimitCountType: model.JobLimitCountTypeNoLimit,
|
||||
Type: model.JobTypeOther,
|
||||
CashbackType: 1,
|
||||
JobCityCode: 999,
|
||||
UnionImg: v.URL,
|
||||
UnionQrcodePosition: "SouthEast",
|
||||
UnionActID: utils.Int2Str(v.ID),
|
||||
Percentage: percentage,
|
||||
},
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ func doDailyWork() {
|
||||
cms.RefreshDropShippingJob(jxcontext.AdminCtx)
|
||||
//刷新京东快递
|
||||
cms.RefreshJdDelivery(jxcontext.AdminCtx)
|
||||
//美团联盟活动自动创建
|
||||
cms.MtUnionJobAutoUpdate(jxcontext.AdminCtx)
|
||||
}
|
||||
|
||||
// 按时间序列循环
|
||||
|
||||
@@ -161,7 +161,7 @@ func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types
|
||||
}
|
||||
|
||||
func GetJob(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, fromTime, toTime time.Time, includeStep bool) (job *model.Job, err error) {
|
||||
jobs, err := GetJobsNoPage(db, userIDs, categoryIDs, statuss, types, fromTime, toTime, 0, includeStep)
|
||||
jobs, err := GetJobsNoPage(db, userIDs, nil, categoryIDs, statuss, types, fromTime, toTime, 0, includeStep)
|
||||
if err != nil {
|
||||
return job, err
|
||||
}
|
||||
@@ -183,7 +183,7 @@ func GetJobWithTitle(db *DaoDB, title string) (job *model.Job, err error) {
|
||||
return job, err
|
||||
}
|
||||
|
||||
func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, fromTime, toTime time.Time, span int, includeStep bool) (jobs []*GetJobsResult, err error) {
|
||||
func GetJobsNoPage(db *DaoDB, userIDs []string, vendorIDs, categoryIDs, statuss, types []int, fromTime, toTime time.Time, span int, includeStep bool) (jobs []*GetJobsResult, err error) {
|
||||
sql := `
|
||||
SELECT a.*, b.name
|
||||
FROM job a
|
||||
@@ -195,6 +195,10 @@ func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss, types []in
|
||||
sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)`
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += ` AND a.vendor_id IN (` + GenQuestionMarks(len(vendorIDs)) + `)`
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
if len(categoryIDs) > 0 {
|
||||
sql += ` AND a.job_category_id IN (` + GenQuestionMarks(len(categoryIDs)) + `)`
|
||||
sqlParams = append(sqlParams, categoryIDs)
|
||||
|
||||
Reference in New Issue
Block a user