v1.2.3 template (clean feature not done)
This commit is contained in:
parent
508d03c073
commit
9a31ec15a4
@ -8,14 +8,12 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"math"
|
||||
"qnc-server/app/user/cmd/api/internal/svc"
|
||||
"qnc-server/app/user/cmd/api/internal/types"
|
||||
"qnc-server/app/user/model"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/crypto"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PaymentLogic struct {
|
||||
@ -78,28 +76,10 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "生成订单, 获取用户信息失败: %+v", err)
|
||||
}
|
||||
|
||||
currentTime := time.Now()
|
||||
|
||||
var mhour int
|
||||
if user.Inside == 1 {
|
||||
mhour = 0
|
||||
amount = 0.01
|
||||
} else {
|
||||
mhour = 12
|
||||
}
|
||||
// 设置时间范围:2025年1月1日中午12点到2025年1月2日中午12点
|
||||
startTime := time.Date(2025, 1, 1, mhour, 0, 0, 0, time.Local)
|
||||
endTime := time.Date(2025, 1, 2, 12, 0, 0, 0, time.Local)
|
||||
|
||||
if currentTime.After(startTime) && currentTime.Before(endTime) {
|
||||
// 打两折
|
||||
amount = product.SellPrice * 0.2
|
||||
amount = math.Round(amount*100) / 100
|
||||
} else {
|
||||
if user.Inside == 1 {
|
||||
amount = 0.01
|
||||
} else {
|
||||
amount = product.SellPrice
|
||||
}
|
||||
amount = product.SellPrice
|
||||
}
|
||||
var createOrderErr error
|
||||
if req.PayMethod == "wechatpay" {
|
||||
|
25
app/user/cmd/api/internal/queue/cleanQueryData.go
Normal file
25
app/user/cmd/api/internal/queue/cleanQueryData.go
Normal file
@ -0,0 +1,25 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/hibiken/asynq"
|
||||
"qnc-server/app/user/cmd/api/internal/svc"
|
||||
)
|
||||
|
||||
const TASKTIME = "32 * * * *"
|
||||
|
||||
type CleanQueryDataHandler struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCleanQueryDataHandler(svcCtx *svc.ServiceContext) *CleanQueryDataHandler {
|
||||
return &CleanQueryDataHandler{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CleanQueryDataHandler) ProcessTask(ctx context.Context, t *asynq.Task) error {
|
||||
fmt.Println("企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅-ProcessTask")
|
||||
return nil
|
||||
}
|
@ -2,6 +2,7 @@ package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/hibiken/asynq"
|
||||
"qnc-server/app/user/cmd/api/internal/svc"
|
||||
"qnc-server/app/user/cmd/api/internal/types"
|
||||
@ -20,9 +21,19 @@ func NewCronJob(ctx context.Context, svcCtx *svc.ServiceContext) *CronJob {
|
||||
}
|
||||
|
||||
func (l *CronJob) Register() *asynq.ServeMux {
|
||||
redisClientOpt := asynq.RedisClientOpt{Addr: l.svcCtx.Config.CacheRedis[0].Host, Password: l.svcCtx.Config.CacheRedis[0].Pass}
|
||||
scheduler := asynq.NewScheduler(redisClientOpt, nil)
|
||||
task := asynq.NewTask(types.MsgCleanQueryData, nil, nil)
|
||||
_, err := scheduler.Register(TASKTIME, task)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("定时任务注册失败:%v", err))
|
||||
}
|
||||
scheduler.Start()
|
||||
fmt.Println("定时任务启动!!!")
|
||||
|
||||
mux := asynq.NewServeMux()
|
||||
|
||||
mux.Handle(types.MsgPaySuccessQuery, NewPaySuccessNotifyUserHandler(l.svcCtx))
|
||||
mux.Handle(types.MsgCleanQueryData, NewCleanQueryDataHandler(l.svcCtx))
|
||||
|
||||
return mux
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
package types
|
||||
|
||||
const MsgPaySuccessQuery = "msg:pay_success:query"
|
||||
const MsgCleanQueryData = "msg:clean_query_data"
|
||||
|
@ -50,6 +50,7 @@ func main() {
|
||||
logx.WithContext(ctx).Errorf("异步任务启动失败: %+v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("异步任务启动!!!")
|
||||
}()
|
||||
|
||||
server := rest.MustNewServer(c.RestConf)
|
||||
|
Loading…
Reference in New Issue
Block a user