Compare commits

...

6 Commits

Author SHA1 Message Date
RecordingTheSmile 02f97fb4a4 fix: update OCR server URL retrieval to use gf configuration 2025-11-04 00:51:31 +08:00
RecordingTheSmile ceee685b80 fix: 今日校园任务登录问题 2025-11-04 00:32:22 +08:00
sugarBecomer 132472de12 🐛 修改余额问题 2025-11-03 21:46:01 +08:00
sugarBecomer 7d8c14a045 🐛 尝试增加redis超时时间 2025-11-03 21:23:27 +08:00
sugarBecomer 25d190c498 🐛 定时任务查询 2025-11-03 21:01:06 +08:00
sugarBecomer f1dfa61578 🐛 充值bug 2025-11-03 20:42:45 +08:00
6 changed files with 24 additions and 23 deletions
-1
View File
@@ -22,7 +22,6 @@ require (
github.com/redis/go-redis/v9 v9.11.0
github.com/samber/oops v1.19.0
github.com/shopspring/decimal v1.4.0
github.com/spf13/viper v1.20.1
github.com/tidwall/gjson v1.18.0
github.com/tidwall/match v1.1.1
github.com/wenlng/go-captcha-assets v1.0.7
+5 -4
View File
@@ -2,13 +2,14 @@ package login
import (
"context"
"github.com/samber/oops"
"github.com/spf13/viper"
"github.com/tidwall/gjson"
"io"
"likedream-goframe/internal/application/httpclient"
"likedream-goframe/internal/cst"
"likedream-goframe/internal/utils"
"github.com/gogf/gf/v2/frame/g"
"github.com/samber/oops"
"github.com/tidwall/gjson"
"resty.dev/v3"
)
@@ -28,7 +29,7 @@ func ResolveOcrCaptcha(ctx context.Context, url string, client *resty.Client) st
_ = captchaResponse.Body.Close()
}()
ocrUrl := viper.GetString(cst.ConfigOcrServerUrl)
ocrUrl := g.Cfg().MustGetWithEnv(ctx, cst.ConfigOcrServerUrl).String()
ocrResponse, err := httpclient.Common.R().
SetMultipartFields(&resty.MultipartField{
+4
View File
@@ -4,6 +4,7 @@ import (
"context"
"likedream-goframe/internal/cst"
"likedream-goframe/internal/utils"
"time"
"github.com/gogf/gf/v2/frame/g"
"github.com/redis/go-redis/v9"
@@ -25,6 +26,9 @@ func Init(ctx context.Context) {
redisUrl := g.Cfg().MustGetWithEnv(ctx, cst.ConfigRedisUrl).String()
redisOpts, e := redis.ParseURL(redisUrl)
redisOpts.DialTimeout = 30 * time.Second
redisOpts.ReadTimeout = 30 * time.Second
redisOpts.WriteTimeout = 30 * time.Second
utils.OkOrPanic(e, oops.WithContext(ctx).
With("redisUrl", redisUrl).
Wrap)
+4 -10
View File
@@ -41,7 +41,7 @@ func (c *CpdailyTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task)
// 查询指定的任务和关联今日校园用户
targetTask, e := db.Global.CpTask.Query().Where(cptask.ID(taskPayload.CpTaskID)).
WithCpUser(func(cuq *ent.CpUserQuery) {
cuq.Select(cpuser.FieldSchoolID, cpuser.FieldEmail).
cuq.
WithSysuser(func(suq *ent.SysUserQuery) {
suq.Select(sysuser.FieldID, sysuser.FieldEmail)
})
@@ -91,17 +91,11 @@ func (c *CpdailyTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task)
schoolDetail := school.GetSchoolDetail(ctx, targetTask.Edges.CpUser.SchoolID)
// 执行登录
var loginClient login.CpdailyLogin
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
if schoolDetail.IsIap() {
loginClient = login.NewIap(ctx)
} else {
loginClient = login.NewCas(ctx)
}
loginExecutor.Login(ctx, &schoolDetail, targetTask.Edges.CpUser.Username, targetTask.Edges.CpUser.Password)
loginClient.Login(ctx, &schoolDetail, targetTask.Edges.CpUser.Username, targetTask.Edges.CpUser.Username)
restyClient := loginClient.GetClient()
restyClient := loginExecutor.GetClient()
// 获取任务执行handler
var taskExecutor cpdailyTask.CpdailyTask
+3 -3
View File
@@ -88,8 +88,8 @@ func (ts *TaskScanner) scanCpdailyTask() {
minExecuteTime := currentTime.Add(-30 * time.Minute).Unix()
allTasks := db.Global.CpTask.Query().
Where(cptask.NextExecuteTimeLTE(currentTime.Unix()), cptask.NextExecuteTimeNotNil(), cptask.NextExecuteTimeGT(0)).
Select(cptask.FieldID, cptask.FieldExecuteHour, cptask.FieldExecuteMinute).
Where(cptask.NextExecuteTimeLTE(currentTime.Unix()), cptask.NextExecuteTimeNotNil(), cptask.NextExecuteTimeGT(0), cptask.StepEQ(cptask.StepComplete), cptask.TaskStatusEQ(cptask.TaskStatusNotStart)).
Select(cptask.FieldID, cptask.FieldExecuteHour, cptask.FieldExecuteMinute, cptask.FieldNextExecuteTime).
AllX(ts.ctx)
var failedIDS []int64
@@ -151,7 +151,7 @@ func (ts *TaskScanner) scanCpdailyTask() {
// 重置30分钟之前的任务到下次执行时间
expiredTasks := db.Global.CpTask.Query().
Where(cptask.NextExecuteTimeLT(minExecuteTime), cptask.NextExecuteTimeNotNil()).
Where(cptask.NextExecuteTimeLT(minExecuteTime), cptask.NextExecuteTimeNotNil(), cptask.NextExecuteTimeGT(0)).
Select(cptask.FieldID, cptask.FieldExecuteHour, cptask.FieldExecuteMinute).
AllX(ts.ctx)
+8 -5
View File
@@ -6,24 +6,27 @@ import (
"likedream-goframe/internal/db"
"likedream-goframe/internal/ent/sysuser"
"likedream-goframe/internal/utils"
"sync"
"github.com/samber/oops"
"github.com/shopspring/decimal"
)
var BalanceService = &BalanceServiceV1{}
var BalanceService = &BalanceServiceV1{
lock: sync.Mutex{},
}
type BalanceServiceV1 struct {
lock sync.Mutex
}
func (v *BalanceServiceV1) ChangeUserBalance(ctx context.Context, userId int64, balance decimal.Decimal) {
if utils.IsAdminFromCtx(ctx) {
return
}
v.lock.Lock()
defer v.lock.Unlock()
tx, err := db.Global.Tx(ctx)
utils.OkOrPanic(err, oops.WithContext(ctx).Wrap)
defer tx.Rollback()
user := tx.SysUser.Query().Where(sysuser.ID(userId)).WithRoles().ForUpdate().OnlyX(ctx)
user := tx.SysUser.Query().Where(sysuser.ID(userId)).WithRoles().OnlyX(ctx)
newBalance := user.Balance.Add(balance)
if newBalance.LessThan(decimal.Zero) {
utils.OkOrPanic(errors.NewBusinessError(400, "余额不足"))