Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d9d6acee5f | |||
| 164d8956de | |||
| 3f1a08374e | |||
| 334d597f9a | |||
| 98eb15f4e4 |
+2
-2
@@ -43,7 +43,7 @@ baseUrl = "http://s3.out"
|
||||
bucket = "likedream"
|
||||
|
||||
[cpdaily]
|
||||
appVersion = "9.7.2"
|
||||
appVersion = "9.8.8"
|
||||
systemVersion = "iOS 17"
|
||||
calVersion = "firstv"
|
||||
sliderIds = ["1018764144934965", "sdhyxy", "hqdx"]
|
||||
@@ -53,6 +53,6 @@ sliderIds = ["1018764144934965", "sdhyxy", "hqdx"]
|
||||
[basePoint]
|
||||
cpdailyTask = "0.5"
|
||||
cpdailyLeave = "4"
|
||||
|
||||
cpdailyPhone = "0.25"
|
||||
[task]
|
||||
concurrency = 20
|
||||
@@ -30,10 +30,13 @@ type LoginGetCode struct {
|
||||
|
||||
type AddByCode struct {
|
||||
g.Meta `path:"/user/addByCode" method:"post" tags:"CpUser" summary:"手机号登录"`
|
||||
Id int64 `json:"id"`
|
||||
CaptchaKey string `json:"captchaKey" v:"required#验证码不能不能为空"`
|
||||
Dots []captcha.ConfirmData `json:"dots" v:"required#验证码不能为空"`
|
||||
Mobile string `json:"mobile" v:"required#手机号不能为空"`
|
||||
SchoolId string `json:"school_id"`
|
||||
Code string `json:"code"`
|
||||
Email string `json:"email" v:"email|regex:^.*@qq\\.com$#邮箱格式不正确|必须是QQ邮箱"`
|
||||
}
|
||||
|
||||
type CpUserConfirmAddReq struct {
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
)
|
||||
|
||||
func TestAesDecrypt(t *testing.T) {
|
||||
str := "6XkC1UAk07fK0uTaGPUu77i/+r7j/o1JQ/XygRxee2LMiX5H+w/BOqOB6e7W o9kHDZMb1pqZNN43k1tjl0ephbPLEi8g9C1EqBw0suzxX74j3dUdCf6dd/0W 8KvntNXwju96Vy5B2oD2ZosLmUdB1m0xX5rxAdLJ//cTft87XDWoLM0fuasu fGvR4XXXYZN071x8F03+qqR52fD1UQGgn0uGkSa/nrUho32Sg7DNJzF/JBCk 6/z0lu0XmIPo1SDIVjOtYAmyUDMZGl/ZvSAu2w=="
|
||||
str := "457xXTd3ZBTY0017ueFiMR0gFff7W2NuXH39lkT/kvTTCKqhXA1vjJwgtmzRgZOC+qEpA3O9GmAroR+A1lORFVqe+q7o3alKOKj4rxPUUSwcyqGUF2LMNbxFXrmWUEPzeedbdUtlI+ufR8SLXNHbZSs0ECPy864bwUAuSDhFcD235c/3AbiTNacXIZZ+paK0T6GWxS291XbffgNCpGFa+5jCaP7/t9erCUjId9Zm4hmoaHkhqGRKAgZrLwuICa4lTFNOQqLA1N/Dljd/ZPVbZGVZaJQ0oV3zEaQQDCWuSTcWF4JVVeaCw9s/8mqkarg+RIz3/OA8dCvc8Wo6auMGzXT6IlisCX+S5TuPlhKKo1ttAW1KrWNg2nkZMxyD+kTKtNijvZRsdQnA8znVp0q2p0byyvzevaB6qSYUM9NBcaxyxkes5Bd1lKCTUHPaG93Jz4SQ+B8MQ1rLm13eWY8uME/WBTOraG7Rgmba32zBccC6BWwV3ncNGhu7hLL0dIhdgIpuxnrFmXDw4HX/IM+cnCxAFo7+EfzKb4l3yDMyr2d+0tDlVl4UbUR2uRTGz5r/7vVI1WtLgM0fiRTk56JU5BwRrutS7KonsLzugbEp/E8="
|
||||
str = strings.ReplaceAll(str, " ", "")
|
||||
decodeString, _ := base64.StdEncoding.DecodeString(str)
|
||||
decrypt := DesDecrypt(decodeString, Cat)
|
||||
decrypt := AesDecryptForCat(decodeString)
|
||||
t.Log(string(decrypt))
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ func (c *CpdailyReportApp) FillReportForm(detail gjson.Result) map[string]*gvar.
|
||||
resultForm := make(map[string]*gvar.Var)
|
||||
resultForm["id"] = gvar.New(detail.Get("detail.id").String())
|
||||
resultForm["needApproval"] = gvar.New(1)
|
||||
resultForm["leaveType"] = gvar.New(detail.Get("leaveType.code").Int())
|
||||
resultForm["leaveType"] = gvar.New(detail.Get("leaveType.code").String())
|
||||
resultForm["reportLocation"] = gvar.New(detail.Get("detail.applyLocation.address").String())
|
||||
resultForm["approverWid"] = gvar.New("")
|
||||
resultForm["reportApplyExplain"] = gvar.New(nil)
|
||||
@@ -141,11 +141,11 @@ func (c *CpdailyReportApp) SubmitReport(ctx context.Context, form map[string]*gv
|
||||
bodyString := taskhelper.GetBodyString(ctx, form)
|
||||
// 构造提交数据
|
||||
submitData := map[string]*gvar.Var{
|
||||
"lon": gvar.New(lon),
|
||||
"version": gvar.New(cryptoutil.EncryptVersion),
|
||||
"calVersion": gvar.New(cpdailyInfo.CalVersion),
|
||||
"deviceId": extensionForm["deviceId"],
|
||||
//"userId": gvar.New(username),
|
||||
"lon": gvar.New(lon),
|
||||
"version": gvar.New(cryptoutil.EncryptVersion),
|
||||
"calVersion": gvar.New(cpdailyInfo.CalVersion),
|
||||
"deviceId": extensionForm["deviceId"],
|
||||
"userId": gvar.New(username),
|
||||
"systemName": gvar.New("android"),
|
||||
"bodyString": gvar.New(bodyString),
|
||||
"lat": gvar.New(lat),
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"likedream-goframe/internal/application/cookiejar"
|
||||
"likedream-goframe/internal/application/httpclient"
|
||||
"likedream-goframe/internal/common/errors"
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/utils"
|
||||
"strings"
|
||||
|
||||
@@ -86,7 +87,7 @@ func ActivateSession(ctx context.Context, host string, client *resty.Client) {
|
||||
client.SetRedirectPolicy(resty.NoRedirectPolicy())
|
||||
}
|
||||
|
||||
func CookieEnabled(ctx context.Context, host string, client *resty.Client) bool {
|
||||
func CookieEnabled(ctx context.Context, host string, client *resty.Client, loginType cpuser.LoginType) bool {
|
||||
client.SetRedirectPolicy(resty.NoRedirectPolicy())
|
||||
host = strings.TrimSuffix(host, "/")
|
||||
sessionResponse, err := client.R().
|
||||
@@ -95,7 +96,11 @@ func CookieEnabled(ctx context.Context, host string, client *resty.Client) bool
|
||||
Post(fmt.Sprintf("%s/wec-counselor-attendance-apps/student/attendance/getStuAttendacesInOneDay", host))
|
||||
|
||||
utils.OkOrPanic(err)
|
||||
return sessionResponse.StatusCode() != 302
|
||||
needLogin := sessionResponse.StatusCode() == 302
|
||||
if needLogin && loginType == cpuser.LoginTypePhone {
|
||||
utils.OkOrPanic(errors.NewBusinessError(500, "登录信息失效,请重新通过短信验证码登录"))
|
||||
}
|
||||
return !needLogin
|
||||
}
|
||||
|
||||
func GetClient(ctx context.Context, cookie string) *resty.Client {
|
||||
|
||||
@@ -75,15 +75,15 @@ func NewSmsWithoutDeviceID() *SmsLoginHandler {
|
||||
|
||||
type SmsLoginHandler struct {
|
||||
deviceID string
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func (s *SmsLoginHandler) SendSms(ctx context.Context, phone string) *CpdailySmsSendSmsData {
|
||||
jar := cookiejar.NewPersistCookieJar()
|
||||
|
||||
phoneEncrypted := base64.StdEncoding.EncodeToString(cryptoutil.AesEncrypt([]byte(phone)))
|
||||
|
||||
req := httpclient.
|
||||
NewCpdailyClient().
|
||||
s.client = httpclient.NewCpdailyClient()
|
||||
req := s.client.
|
||||
SetCookieJar(jar).
|
||||
R().
|
||||
SetContext(utils.NewCpdailySmsContextBuilder().
|
||||
@@ -126,8 +126,9 @@ func (s *SmsLoginHandler) LoginByCode(ctx context.Context, phone, code string, j
|
||||
"a": encodedPayload,
|
||||
"b": cryptoutil.EncryptVersion,
|
||||
}
|
||||
|
||||
req := httpclient.NewCpdailyClient().SetCookieJar(jar).R().
|
||||
s.client = httpclient.NewCpdailyClient()
|
||||
s.client.SetCookieJar(jar)
|
||||
req := s.client.R().
|
||||
SetBody(payload).
|
||||
SetContext(utils.NewCpdailySmsContextBuilder().
|
||||
WithDeviceID(s.deviceID).
|
||||
@@ -198,10 +199,8 @@ func (s *SmsLoginHandler) SetLoginCookie(ctx context.Context, jar http.CookieJar
|
||||
jar.SetCookies(targetSchoolUrl, []*http.Cookie{cookie})
|
||||
jar.SetCookies(targetApiUrl, []*http.Cookie{cookie})
|
||||
}
|
||||
|
||||
req := httpclient.NewCpdailyClient().
|
||||
SetRedirectPolicy(resty.FlexibleRedirectPolicy(50)).
|
||||
SetCookieJar(jar).R().
|
||||
s.client.SetRedirectPolicy(resty.FlexibleRedirectPolicy(50))
|
||||
req := s.client.R().
|
||||
SetHeader("AmpCookies", ampToken).
|
||||
SetContext(ctx)
|
||||
|
||||
@@ -273,3 +272,9 @@ func setSmsRequestHeaders(ctx context.Context, request *resty.Request) {
|
||||
"CpdailyInfo": encodedCpdailyInfo,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SmsLoginHandler) GetCookieString() string {
|
||||
cookieJar := s.client.CookieJar()
|
||||
serializableJar := cookieJar.(*cookiejar.PersistCookieJar)
|
||||
return serializableJar.Serialize()
|
||||
}
|
||||
|
||||
@@ -44,9 +44,16 @@ const (
|
||||
VideoEncKey = "d_yHJ!$pdA~5"
|
||||
)
|
||||
|
||||
// ErrTimeRestriction 时间限制错误,表示当前时间不在允许执行的范围内
|
||||
var ErrTimeRestriction = errors2.NewBusinessError(499, "当前时间不在允许执行的范围内")
|
||||
|
||||
// TimeCheckFunc 时间检查回调函数类型,返回 true 表示可以继续执行
|
||||
type TimeCheckFunc func() bool
|
||||
|
||||
type XuexitongCourse struct {
|
||||
client *resty.Client
|
||||
userID string
|
||||
client *resty.Client
|
||||
userID string
|
||||
timeCheckFunc TimeCheckFunc // 时间检查回调,每个任务点完成后调用
|
||||
}
|
||||
|
||||
func NewXuexitongCourse(client *resty.Client) *XuexitongCourse {
|
||||
@@ -55,6 +62,19 @@ func NewXuexitongCourse(client *resty.Client) *XuexitongCourse {
|
||||
}
|
||||
}
|
||||
|
||||
// SetTimeCheckFunc 设置时间检查回调函数
|
||||
func (c *XuexitongCourse) SetTimeCheckFunc(fn TimeCheckFunc) {
|
||||
c.timeCheckFunc = fn
|
||||
}
|
||||
|
||||
// checkTimeRestriction 检查时间限制,如果设置了回调且返回 false,则返回时间限制错误
|
||||
func (c *XuexitongCourse) checkTimeRestriction() error {
|
||||
if c.timeCheckFunc != nil && !c.timeCheckFunc() {
|
||||
return ErrTimeRestriction
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *XuexitongCourse) SetUserID(userID string) {
|
||||
c.userID = userID
|
||||
}
|
||||
@@ -1149,12 +1169,22 @@ func (c *XuexitongCourse) AutoStudyCourse(ctx context.Context, course entity.Xue
|
||||
|
||||
// 遍历所有章节
|
||||
for i, chapter := range chapters {
|
||||
// 检查时间限制
|
||||
if err := c.checkTimeRestriction(); err != nil {
|
||||
logger.Logger.Info("时间限制,暂停刷课", zap.String("course", course.CourseName))
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Logger.Info(fmt.Sprintf("章节 [%d/%d]: %s (任务点: %d, 已完成: %d)",
|
||||
i+1, len(chapters), chapter.Name, chapter.PointTotal, chapter.PointFinish))
|
||||
|
||||
if chapter.JobCount > 0 || chapter.PointTotal > chapter.PointFinish {
|
||||
err := c.AutoStudyChapter(ctx, course, chapter)
|
||||
if err != nil {
|
||||
// 如果是时间限制错误,向上传递
|
||||
if err == ErrTimeRestriction {
|
||||
return err
|
||||
}
|
||||
logger.Logger.Error(fmt.Sprintf("刷章节失败: %s", chapter.Name), zap.Error(err))
|
||||
continue
|
||||
}
|
||||
@@ -1267,6 +1297,11 @@ func (c *XuexitongCourse) AutoStudyChapter(ctx context.Context, course entity.Xu
|
||||
|
||||
// 刷视频
|
||||
for i, video := range points.Videos {
|
||||
// 检查时间限制
|
||||
if err := c.checkTimeRestriction(); err != nil {
|
||||
logger.Logger.Info("时间限制,暂停刷课", zap.String("chapter", chapter.Name))
|
||||
return err
|
||||
}
|
||||
logger.Logger.Info(fmt.Sprintf(" 视频任务点 [%d/%d]: %s", i+1, len(points.Videos), video.Title))
|
||||
if err := c.AutoPlayVideo(ctx, course, &points.Videos[i]); err != nil {
|
||||
logger.Logger.Error("视频刷课失败", zap.Error(err), zap.String("title", video.Title))
|
||||
@@ -1276,6 +1311,11 @@ func (c *XuexitongCourse) AutoStudyChapter(ctx context.Context, course entity.Xu
|
||||
|
||||
// 刷文档
|
||||
for i, doc := range points.Documents {
|
||||
// 检查时间限制
|
||||
if err := c.checkTimeRestriction(); err != nil {
|
||||
logger.Logger.Info("时间限制,暂停刷课", zap.String("chapter", chapter.Name))
|
||||
return err
|
||||
}
|
||||
logger.Logger.Info(fmt.Sprintf(" 文档任务点 [%d/%d]: %s", i+1, len(points.Documents), doc.Title))
|
||||
if err := c.AutoReadDocument(ctx, course, &points.Documents[i]); err != nil {
|
||||
logger.Logger.Error("文档刷课失败", zap.Error(err), zap.String("title", doc.Title))
|
||||
@@ -1285,6 +1325,11 @@ func (c *XuexitongCourse) AutoStudyChapter(ctx context.Context, course entity.Xu
|
||||
|
||||
// 刷作业
|
||||
for i, work := range points.Works {
|
||||
// 检查时间限制
|
||||
if err := c.checkTimeRestriction(); err != nil {
|
||||
logger.Logger.Info("时间限制,暂停刷课", zap.String("chapter", chapter.Name))
|
||||
return err
|
||||
}
|
||||
logger.Logger.Info(fmt.Sprintf(" 作业任务点 [%d/%d]: %s", i+1, len(points.Works), work.Title))
|
||||
if err := c.AutoCompleteWork(ctx, course, &points.Works[i]); err != nil {
|
||||
logger.Logger.Error("作业刷课失败", zap.Error(err), zap.String("title", work.Title))
|
||||
@@ -1294,6 +1339,11 @@ func (c *XuexitongCourse) AutoStudyChapter(ctx context.Context, course entity.Xu
|
||||
|
||||
// 刷外链
|
||||
for i, link := range points.Hyperlinks {
|
||||
// 检查时间限制
|
||||
if err := c.checkTimeRestriction(); err != nil {
|
||||
logger.Logger.Info("时间限制,暂停刷课", zap.String("chapter", chapter.Name))
|
||||
return err
|
||||
}
|
||||
logger.Logger.Info(fmt.Sprintf(" 外链任务点 [%d/%d]: %s", i+1, len(points.Hyperlinks), link.Title))
|
||||
if err := c.AutoCompleteHyperlink(ctx, course, &points.Hyperlinks[i]); err != nil {
|
||||
logger.Logger.Error("外链刷课失败", zap.Error(err), zap.String("title", link.Title))
|
||||
@@ -1303,6 +1353,11 @@ func (c *XuexitongCourse) AutoStudyChapter(ctx context.Context, course entity.Xu
|
||||
|
||||
// 刷直播
|
||||
for i, live := range points.Lives {
|
||||
// 检查时间限制
|
||||
if err := c.checkTimeRestriction(); err != nil {
|
||||
logger.Logger.Info("时间限制,暂停刷课", zap.String("chapter", chapter.Name))
|
||||
return err
|
||||
}
|
||||
logger.Logger.Info(fmt.Sprintf(" 直播任务点 [%d/%d]: %s", i+1, len(points.Lives), live.Title))
|
||||
if err := c.AutoWatchLive(ctx, course, &points.Lives[i]); err != nil {
|
||||
logger.Logger.Error("直播刷课失败", zap.Error(err), zap.String("title", live.Title))
|
||||
|
||||
@@ -39,6 +39,7 @@ const (
|
||||
// 基础积分配置
|
||||
ConfigBasePointCpdailyTask = "basePoint.cpdailyTask"
|
||||
ConfigBasePointCpdailyLeave = "basePoint.cpdailyLeave"
|
||||
ConfigBasePointCpdailyPhone = "basePoint.cpdailyPhone"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -4,8 +4,12 @@ import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/framework/captcha"
|
||||
"likedream-goframe/internal/framework/redis"
|
||||
"likedream-goframe/internal/service"
|
||||
"likedream-goframe/internal/utils"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
)
|
||||
|
||||
type CpUserCtrlV1 struct {
|
||||
@@ -68,10 +72,32 @@ func (c CpUserCtrlV1) AuthorizeRandom(ctx context.Context, req *v1.CpUserAuthori
|
||||
}
|
||||
func (c CpUserCtrlV1) LoginGetCode(ctx context.Context, req *v1.LoginGetCode) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
client := redis.GetClient()
|
||||
dotsStr := client.GetDel(ctx, req.CaptchaKey).Val()
|
||||
if dotsStr == "" {
|
||||
return utils.Fail(10003, "验证码错误"), nil
|
||||
}
|
||||
var dots captcha.ConfirmData
|
||||
err = sonic.Unmarshal([]byte(dotsStr), &dots)
|
||||
utils.OkOrPanic(err)
|
||||
if !captcha.VerifyCaptcha(dots, req.Dots) {
|
||||
return utils.Fail(10003, "验证码错误"), nil
|
||||
}
|
||||
return service.Global.CpUser.LoginGetCode(ctx, req), nil
|
||||
}
|
||||
|
||||
func (c CpUserCtrlV1) AddByCode(ctx context.Context, req *v1.AddByCode) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
client := redis.GetClient()
|
||||
dotsStr := client.GetDel(ctx, req.CaptchaKey).Val()
|
||||
if dotsStr == "" {
|
||||
return utils.Fail(10003, "验证码错误"), nil
|
||||
}
|
||||
var dots captcha.ConfirmData
|
||||
err = sonic.Unmarshal([]byte(dotsStr), &dots)
|
||||
utils.OkOrPanic(err)
|
||||
if !captcha.VerifyCaptcha(dots, req.Dots) {
|
||||
return utils.Fail(10003, "验证码错误"), nil
|
||||
}
|
||||
return service.Global.CpUser.AddByCode(ctx, req), nil
|
||||
}
|
||||
|
||||
+12
-1
@@ -39,6 +39,8 @@ type CpUser struct {
|
||||
Cookie string `json:"cookie,omitempty"`
|
||||
// MobileType holds the value of the "mobile_type" field.
|
||||
MobileType cpuser.MobileType `json:"mobile_type,omitempty"`
|
||||
// LoginType holds the value of the "login_type" field.
|
||||
LoginType cpuser.LoginType `json:"login_type,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the CpUserQuery when eager-loading is set.
|
||||
Edges CpUserEdges `json:"edges"`
|
||||
@@ -123,7 +125,7 @@ func (*CpUser) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(ent2.CustomTime)
|
||||
case cpuser.FieldID, cpuser.FieldUserID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case cpuser.FieldUsername, cpuser.FieldPassword, cpuser.FieldSchoolID, cpuser.FieldEmail, cpuser.FieldMobileCode, cpuser.FieldCookie, cpuser.FieldMobileType:
|
||||
case cpuser.FieldUsername, cpuser.FieldPassword, cpuser.FieldSchoolID, cpuser.FieldEmail, cpuser.FieldMobileCode, cpuser.FieldCookie, cpuser.FieldMobileType, cpuser.FieldLoginType:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
@@ -206,6 +208,12 @@ func (_m *CpUser) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
_m.MobileType = cpuser.MobileType(value.String)
|
||||
}
|
||||
case cpuser.FieldLoginType:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field login_type", values[i])
|
||||
} else if value.Valid {
|
||||
_m.LoginType = cpuser.LoginType(value.String)
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@@ -296,6 +304,9 @@ func (_m *CpUser) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("mobile_type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.MobileType))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("login_type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.LoginType))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ const (
|
||||
FieldCookie = "cookie"
|
||||
// FieldMobileType holds the string denoting the mobile_type field in the database.
|
||||
FieldMobileType = "mobile_type"
|
||||
// FieldLoginType holds the string denoting the login_type field in the database.
|
||||
FieldLoginType = "login_type"
|
||||
// EdgeCptasks holds the string denoting the cptasks edge name in mutations.
|
||||
EdgeCptasks = "cptasks"
|
||||
// EdgeCpLeave holds the string denoting the cp_leave edge name in mutations.
|
||||
@@ -98,6 +100,7 @@ var Columns = []string{
|
||||
FieldMobileCode,
|
||||
FieldCookie,
|
||||
FieldMobileType,
|
||||
FieldLoginType,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -123,8 +126,6 @@ var (
|
||||
DefaultUpdateTime func() *ent2.CustomTime
|
||||
// UsernameValidator is a validator for the "username" field. It is called by the builders before save.
|
||||
UsernameValidator func(string) error
|
||||
// PasswordValidator is a validator for the "password" field. It is called by the builders before save.
|
||||
PasswordValidator func(string) error
|
||||
// SchoolIDValidator is a validator for the "school_id" field. It is called by the builders before save.
|
||||
SchoolIDValidator func(string) error
|
||||
)
|
||||
@@ -152,6 +153,32 @@ func MobileTypeValidator(mt MobileType) error {
|
||||
}
|
||||
}
|
||||
|
||||
// LoginType defines the type for the "login_type" enum field.
|
||||
type LoginType string
|
||||
|
||||
// LoginTypeAccount is the default value of the LoginType enum.
|
||||
const DefaultLoginType = LoginTypeAccount
|
||||
|
||||
// LoginType values.
|
||||
const (
|
||||
LoginTypeAccount LoginType = "account"
|
||||
LoginTypePhone LoginType = "phone"
|
||||
)
|
||||
|
||||
func (lt LoginType) String() string {
|
||||
return string(lt)
|
||||
}
|
||||
|
||||
// LoginTypeValidator is a validator for the "login_type" field enum values. It is called by the builders before save.
|
||||
func LoginTypeValidator(lt LoginType) error {
|
||||
switch lt {
|
||||
case LoginTypeAccount, LoginTypePhone:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("cpuser: invalid enum value for login_type field: %q", lt)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the CpUser queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
@@ -210,6 +237,11 @@ func ByMobileType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldMobileType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByLoginType orders the results by the login_type field.
|
||||
func ByLoginType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldLoginType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCptasksCount orders the results by cptasks count.
|
||||
func ByCptasksCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
|
||||
@@ -381,6 +381,16 @@ func PasswordHasSuffix(v string) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldHasSuffix(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordIsNil applies the IsNil predicate on the "password" field.
|
||||
func PasswordIsNil() predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldIsNull(FieldPassword))
|
||||
}
|
||||
|
||||
// PasswordNotNil applies the NotNil predicate on the "password" field.
|
||||
func PasswordNotNil() predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldNotNull(FieldPassword))
|
||||
}
|
||||
|
||||
// PasswordEqualFold applies the EqualFold predicate on the "password" field.
|
||||
func PasswordEqualFold(v string) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldEqualFold(FieldPassword, v))
|
||||
@@ -701,6 +711,26 @@ func MobileTypeNotIn(vs ...MobileType) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldNotIn(FieldMobileType, vs...))
|
||||
}
|
||||
|
||||
// LoginTypeEQ applies the EQ predicate on the "login_type" field.
|
||||
func LoginTypeEQ(v LoginType) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldEQ(FieldLoginType, v))
|
||||
}
|
||||
|
||||
// LoginTypeNEQ applies the NEQ predicate on the "login_type" field.
|
||||
func LoginTypeNEQ(v LoginType) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldNEQ(FieldLoginType, v))
|
||||
}
|
||||
|
||||
// LoginTypeIn applies the In predicate on the "login_type" field.
|
||||
func LoginTypeIn(vs ...LoginType) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldIn(FieldLoginType, vs...))
|
||||
}
|
||||
|
||||
// LoginTypeNotIn applies the NotIn predicate on the "login_type" field.
|
||||
func LoginTypeNotIn(vs ...LoginType) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldNotIn(FieldLoginType, vs...))
|
||||
}
|
||||
|
||||
// HasCptasks applies the HasEdge predicate on the "cptasks" edge.
|
||||
func HasCptasks() predicate.CpUser {
|
||||
return predicate.CpUser(func(s *sql.Selector) {
|
||||
|
||||
@@ -57,6 +57,14 @@ func (_c *CpUserCreate) SetPassword(v string) *CpUserCreate {
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillablePassword sets the "password" field if the given value is not nil.
|
||||
func (_c *CpUserCreate) SetNillablePassword(v *string) *CpUserCreate {
|
||||
if v != nil {
|
||||
_c.SetPassword(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
func (_c *CpUserCreate) SetSchoolID(v string) *CpUserCreate {
|
||||
_c.mutation.SetSchoolID(v)
|
||||
@@ -111,6 +119,20 @@ func (_c *CpUserCreate) SetMobileType(v cpuser.MobileType) *CpUserCreate {
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (_c *CpUserCreate) SetLoginType(v cpuser.LoginType) *CpUserCreate {
|
||||
_c.mutation.SetLoginType(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableLoginType sets the "login_type" field if the given value is not nil.
|
||||
func (_c *CpUserCreate) SetNillableLoginType(v *cpuser.LoginType) *CpUserCreate {
|
||||
if v != nil {
|
||||
_c.SetLoginType(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddCptaskIDs adds the "cptasks" edge to the CpTask entity by IDs.
|
||||
func (_c *CpUserCreate) AddCptaskIDs(ids ...int64) *CpUserCreate {
|
||||
_c.mutation.AddCptaskIDs(ids...)
|
||||
@@ -223,6 +245,10 @@ func (_c *CpUserCreate) defaults() error {
|
||||
v := cpuser.DefaultUpdateTime()
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
}
|
||||
if _, ok := _c.mutation.LoginType(); !ok {
|
||||
v := cpuser.DefaultLoginType
|
||||
_c.mutation.SetLoginType(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -245,14 +271,6 @@ func (_c *CpUserCreate) check() error {
|
||||
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "CpUser.username": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Password(); !ok {
|
||||
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "CpUser.password"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Password(); ok {
|
||||
if err := cpuser.PasswordValidator(v); err != nil {
|
||||
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "CpUser.password": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.SchoolID(); !ok {
|
||||
return &ValidationError{Name: "school_id", err: errors.New(`ent: missing required field "CpUser.school_id"`)}
|
||||
}
|
||||
@@ -269,6 +287,14 @@ func (_c *CpUserCreate) check() error {
|
||||
return &ValidationError{Name: "mobile_type", err: fmt.Errorf(`ent: validator failed for field "CpUser.mobile_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.LoginType(); !ok {
|
||||
return &ValidationError{Name: "login_type", err: errors.New(`ent: missing required field "CpUser.login_type"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.LoginType(); ok {
|
||||
if err := cpuser.LoginTypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "login_type", err: fmt.Errorf(`ent: validator failed for field "CpUser.login_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if len(_c.mutation.SysuserIDs()) == 0 {
|
||||
return &ValidationError{Name: "sysuser", err: errors.New(`ent: missing required edge "CpUser.sysuser"`)}
|
||||
}
|
||||
@@ -335,6 +361,10 @@ func (_c *CpUserCreate) createSpec() (*CpUser, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(cpuser.FieldMobileType, field.TypeEnum, value)
|
||||
_node.MobileType = value
|
||||
}
|
||||
if value, ok := _c.mutation.LoginType(); ok {
|
||||
_spec.SetField(cpuser.FieldLoginType, field.TypeEnum, value)
|
||||
_node.LoginType = value
|
||||
}
|
||||
if nodes := _c.mutation.CptasksIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
@@ -522,6 +552,12 @@ func (u *CpUserUpsert) UpdatePassword() *CpUserUpsert {
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearPassword clears the value of the "password" field.
|
||||
func (u *CpUserUpsert) ClearPassword() *CpUserUpsert {
|
||||
u.SetNull(cpuser.FieldPassword)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
func (u *CpUserUpsert) SetSchoolID(v string) *CpUserUpsert {
|
||||
u.Set(cpuser.FieldSchoolID, v)
|
||||
@@ -600,6 +636,18 @@ func (u *CpUserUpsert) UpdateMobileType() *CpUserUpsert {
|
||||
return u
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (u *CpUserUpsert) SetLoginType(v cpuser.LoginType) *CpUserUpsert {
|
||||
u.Set(cpuser.FieldLoginType, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateLoginType sets the "login_type" field to the value that was provided on create.
|
||||
func (u *CpUserUpsert) UpdateLoginType() *CpUserUpsert {
|
||||
u.SetExcluded(cpuser.FieldLoginType)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
@@ -701,6 +749,13 @@ func (u *CpUserUpsertOne) UpdatePassword() *CpUserUpsertOne {
|
||||
})
|
||||
}
|
||||
|
||||
// ClearPassword clears the value of the "password" field.
|
||||
func (u *CpUserUpsertOne) ClearPassword() *CpUserUpsertOne {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
s.ClearPassword()
|
||||
})
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
func (u *CpUserUpsertOne) SetSchoolID(v string) *CpUserUpsertOne {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
@@ -792,6 +847,20 @@ func (u *CpUserUpsertOne) UpdateMobileType() *CpUserUpsertOne {
|
||||
})
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (u *CpUserUpsertOne) SetLoginType(v cpuser.LoginType) *CpUserUpsertOne {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
s.SetLoginType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateLoginType sets the "login_type" field to the value that was provided on create.
|
||||
func (u *CpUserUpsertOne) UpdateLoginType() *CpUserUpsertOne {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
s.UpdateLoginType()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *CpUserUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
@@ -1059,6 +1128,13 @@ func (u *CpUserUpsertBulk) UpdatePassword() *CpUserUpsertBulk {
|
||||
})
|
||||
}
|
||||
|
||||
// ClearPassword clears the value of the "password" field.
|
||||
func (u *CpUserUpsertBulk) ClearPassword() *CpUserUpsertBulk {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
s.ClearPassword()
|
||||
})
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
func (u *CpUserUpsertBulk) SetSchoolID(v string) *CpUserUpsertBulk {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
@@ -1150,6 +1226,20 @@ func (u *CpUserUpsertBulk) UpdateMobileType() *CpUserUpsertBulk {
|
||||
})
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (u *CpUserUpsertBulk) SetLoginType(v cpuser.LoginType) *CpUserUpsertBulk {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
s.SetLoginType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateLoginType sets the "login_type" field to the value that was provided on create.
|
||||
func (u *CpUserUpsertBulk) UpdateLoginType() *CpUserUpsertBulk {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
s.UpdateLoginType()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *CpUserUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
|
||||
@@ -83,6 +83,12 @@ func (_u *CpUserUpdate) SetNillablePassword(v *string) *CpUserUpdate {
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearPassword clears the value of the "password" field.
|
||||
func (_u *CpUserUpdate) ClearPassword() *CpUserUpdate {
|
||||
_u.mutation.ClearPassword()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
func (_u *CpUserUpdate) SetSchoolID(v string) *CpUserUpdate {
|
||||
_u.mutation.SetSchoolID(v)
|
||||
@@ -171,6 +177,20 @@ func (_u *CpUserUpdate) SetNillableMobileType(v *cpuser.MobileType) *CpUserUpdat
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (_u *CpUserUpdate) SetLoginType(v cpuser.LoginType) *CpUserUpdate {
|
||||
_u.mutation.SetLoginType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableLoginType sets the "login_type" field if the given value is not nil.
|
||||
func (_u *CpUserUpdate) SetNillableLoginType(v *cpuser.LoginType) *CpUserUpdate {
|
||||
if v != nil {
|
||||
_u.SetLoginType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddCptaskIDs adds the "cptasks" edge to the CpTask entity by IDs.
|
||||
func (_u *CpUserUpdate) AddCptaskIDs(ids ...int64) *CpUserUpdate {
|
||||
_u.mutation.AddCptaskIDs(ids...)
|
||||
@@ -346,11 +366,6 @@ func (_u *CpUserUpdate) check() error {
|
||||
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "CpUser.username": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Password(); ok {
|
||||
if err := cpuser.PasswordValidator(v); err != nil {
|
||||
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "CpUser.password": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.SchoolID(); ok {
|
||||
if err := cpuser.SchoolIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "school_id", err: fmt.Errorf(`ent: validator failed for field "CpUser.school_id": %w`, err)}
|
||||
@@ -361,6 +376,11 @@ func (_u *CpUserUpdate) check() error {
|
||||
return &ValidationError{Name: "mobile_type", err: fmt.Errorf(`ent: validator failed for field "CpUser.mobile_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.LoginType(); ok {
|
||||
if err := cpuser.LoginTypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "login_type", err: fmt.Errorf(`ent: validator failed for field "CpUser.login_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.SysuserCleared() && len(_u.mutation.SysuserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "CpUser.sysuser"`)
|
||||
}
|
||||
@@ -397,6 +417,9 @@ func (_u *CpUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if value, ok := _u.mutation.Password(); ok {
|
||||
_spec.SetField(cpuser.FieldPassword, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.PasswordCleared() {
|
||||
_spec.ClearField(cpuser.FieldPassword, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Email(); ok {
|
||||
_spec.SetField(cpuser.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
@@ -418,6 +441,9 @@ func (_u *CpUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if value, ok := _u.mutation.MobileType(); ok {
|
||||
_spec.SetField(cpuser.FieldMobileType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.LoginType(); ok {
|
||||
_spec.SetField(cpuser.FieldLoginType, field.TypeEnum, value)
|
||||
}
|
||||
if _u.mutation.CptasksCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
@@ -696,6 +722,12 @@ func (_u *CpUserUpdateOne) SetNillablePassword(v *string) *CpUserUpdateOne {
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearPassword clears the value of the "password" field.
|
||||
func (_u *CpUserUpdateOne) ClearPassword() *CpUserUpdateOne {
|
||||
_u.mutation.ClearPassword()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
func (_u *CpUserUpdateOne) SetSchoolID(v string) *CpUserUpdateOne {
|
||||
_u.mutation.SetSchoolID(v)
|
||||
@@ -784,6 +816,20 @@ func (_u *CpUserUpdateOne) SetNillableMobileType(v *cpuser.MobileType) *CpUserUp
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (_u *CpUserUpdateOne) SetLoginType(v cpuser.LoginType) *CpUserUpdateOne {
|
||||
_u.mutation.SetLoginType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableLoginType sets the "login_type" field if the given value is not nil.
|
||||
func (_u *CpUserUpdateOne) SetNillableLoginType(v *cpuser.LoginType) *CpUserUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetLoginType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddCptaskIDs adds the "cptasks" edge to the CpTask entity by IDs.
|
||||
func (_u *CpUserUpdateOne) AddCptaskIDs(ids ...int64) *CpUserUpdateOne {
|
||||
_u.mutation.AddCptaskIDs(ids...)
|
||||
@@ -972,11 +1018,6 @@ func (_u *CpUserUpdateOne) check() error {
|
||||
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "CpUser.username": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Password(); ok {
|
||||
if err := cpuser.PasswordValidator(v); err != nil {
|
||||
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "CpUser.password": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.SchoolID(); ok {
|
||||
if err := cpuser.SchoolIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "school_id", err: fmt.Errorf(`ent: validator failed for field "CpUser.school_id": %w`, err)}
|
||||
@@ -987,6 +1028,11 @@ func (_u *CpUserUpdateOne) check() error {
|
||||
return &ValidationError{Name: "mobile_type", err: fmt.Errorf(`ent: validator failed for field "CpUser.mobile_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.LoginType(); ok {
|
||||
if err := cpuser.LoginTypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "login_type", err: fmt.Errorf(`ent: validator failed for field "CpUser.login_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.SysuserCleared() && len(_u.mutation.SysuserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "CpUser.sysuser"`)
|
||||
}
|
||||
@@ -1040,6 +1086,9 @@ func (_u *CpUserUpdateOne) sqlSave(ctx context.Context) (_node *CpUser, err erro
|
||||
if value, ok := _u.mutation.Password(); ok {
|
||||
_spec.SetField(cpuser.FieldPassword, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.PasswordCleared() {
|
||||
_spec.ClearField(cpuser.FieldPassword, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Email(); ok {
|
||||
_spec.SetField(cpuser.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
@@ -1061,6 +1110,9 @@ func (_u *CpUserUpdateOne) sqlSave(ctx context.Context) (_node *CpUser, err erro
|
||||
if value, ok := _u.mutation.MobileType(); ok {
|
||||
_spec.SetField(cpuser.FieldMobileType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.LoginType(); ok {
|
||||
_spec.SetField(cpuser.FieldLoginType, field.TypeEnum, value)
|
||||
}
|
||||
if _u.mutation.CptasksCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
|
||||
@@ -190,6 +190,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
cpuser.FieldMobileCode: {Type: field.TypeString, Column: cpuser.FieldMobileCode},
|
||||
cpuser.FieldCookie: {Type: field.TypeString, Column: cpuser.FieldCookie},
|
||||
cpuser.FieldMobileType: {Type: field.TypeEnum, Column: cpuser.FieldMobileType},
|
||||
cpuser.FieldLoginType: {Type: field.TypeEnum, Column: cpuser.FieldLoginType},
|
||||
},
|
||||
}
|
||||
graph.Nodes[7] = &sqlgraph.Node{
|
||||
@@ -1634,6 +1635,11 @@ func (f *CpUserFilter) WhereMobileType(p entql.StringP) {
|
||||
f.Where(p.Field(cpuser.FieldMobileType))
|
||||
}
|
||||
|
||||
// WhereLoginType applies the entql string predicate on the login_type field.
|
||||
func (f *CpUserFilter) WhereLoginType(p entql.StringP) {
|
||||
f.Where(p.Field(cpuser.FieldLoginType))
|
||||
}
|
||||
|
||||
// WhereHasCptasks applies a predicate to check if query has an edge cptasks.
|
||||
func (f *CpUserFilter) WhereHasCptasks() {
|
||||
f.Where(entql.HasEdge("cptasks"))
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -201,11 +201,12 @@ var (
|
||||
{Name: "create_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
|
||||
{Name: "update_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
|
||||
{Name: "username", Type: field.TypeString},
|
||||
{Name: "password", Type: field.TypeString},
|
||||
{Name: "password", Type: field.TypeString, Nullable: true},
|
||||
{Name: "email", Type: field.TypeString, Nullable: true},
|
||||
{Name: "mobile_code", Type: field.TypeString, Nullable: true},
|
||||
{Name: "cookie", Type: field.TypeString, Nullable: true, Size: 2147483647},
|
||||
{Name: "mobile_type", Type: field.TypeEnum, Enums: []string{"random", "authorize"}},
|
||||
{Name: "login_type", Type: field.TypeEnum, Enums: []string{"account", "phone"}, Default: "account"},
|
||||
{Name: "school_id", Type: field.TypeString},
|
||||
{Name: "user_id", Type: field.TypeInt64},
|
||||
}
|
||||
@@ -217,13 +218,13 @@ var (
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "cp_users_cp_schools_cpusers",
|
||||
Columns: []*schema.Column{CpUsersColumns[9]},
|
||||
Columns: []*schema.Column{CpUsersColumns[10]},
|
||||
RefColumns: []*schema.Column{CpSchoolsColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
{
|
||||
Symbol: "cp_users_sys_user_cpuser",
|
||||
Columns: []*schema.Column{CpUsersColumns[10]},
|
||||
Columns: []*schema.Column{CpUsersColumns[11]},
|
||||
RefColumns: []*schema.Column{SysUserColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
|
||||
@@ -6252,6 +6252,7 @@ type CpUserMutation struct {
|
||||
mobile_code *string
|
||||
cookie *string
|
||||
mobile_type *cpuser.MobileType
|
||||
login_type *cpuser.LoginType
|
||||
clearedFields map[string]struct{}
|
||||
cptasks map[int64]struct{}
|
||||
removedcptasks map[int64]struct{}
|
||||
@@ -6544,9 +6545,22 @@ func (m *CpUserMutation) OldPassword(ctx context.Context) (v string, err error)
|
||||
return oldValue.Password, nil
|
||||
}
|
||||
|
||||
// ClearPassword clears the value of the "password" field.
|
||||
func (m *CpUserMutation) ClearPassword() {
|
||||
m.password = nil
|
||||
m.clearedFields[cpuser.FieldPassword] = struct{}{}
|
||||
}
|
||||
|
||||
// PasswordCleared returns if the "password" field was cleared in this mutation.
|
||||
func (m *CpUserMutation) PasswordCleared() bool {
|
||||
_, ok := m.clearedFields[cpuser.FieldPassword]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetPassword resets all changes to the "password" field.
|
||||
func (m *CpUserMutation) ResetPassword() {
|
||||
m.password = nil
|
||||
delete(m.clearedFields, cpuser.FieldPassword)
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
@@ -6768,6 +6782,42 @@ func (m *CpUserMutation) ResetMobileType() {
|
||||
m.mobile_type = nil
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (m *CpUserMutation) SetLoginType(ct cpuser.LoginType) {
|
||||
m.login_type = &ct
|
||||
}
|
||||
|
||||
// LoginType returns the value of the "login_type" field in the mutation.
|
||||
func (m *CpUserMutation) LoginType() (r cpuser.LoginType, exists bool) {
|
||||
v := m.login_type
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldLoginType returns the old "login_type" field's value of the CpUser entity.
|
||||
// If the CpUser object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *CpUserMutation) OldLoginType(ctx context.Context) (v cpuser.LoginType, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldLoginType is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldLoginType requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldLoginType: %w", err)
|
||||
}
|
||||
return oldValue.LoginType, nil
|
||||
}
|
||||
|
||||
// ResetLoginType resets all changes to the "login_type" field.
|
||||
func (m *CpUserMutation) ResetLoginType() {
|
||||
m.login_type = nil
|
||||
}
|
||||
|
||||
// AddCptaskIDs adds the "cptasks" edge to the CpTask entity by ids.
|
||||
func (m *CpUserMutation) AddCptaskIDs(ids ...int64) {
|
||||
if m.cptasks == nil {
|
||||
@@ -7031,7 +7081,7 @@ func (m *CpUserMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *CpUserMutation) Fields() []string {
|
||||
fields := make([]string, 0, 10)
|
||||
fields := make([]string, 0, 11)
|
||||
if m.create_time != nil {
|
||||
fields = append(fields, cpuser.FieldCreateTime)
|
||||
}
|
||||
@@ -7062,6 +7112,9 @@ func (m *CpUserMutation) Fields() []string {
|
||||
if m.mobile_type != nil {
|
||||
fields = append(fields, cpuser.FieldMobileType)
|
||||
}
|
||||
if m.login_type != nil {
|
||||
fields = append(fields, cpuser.FieldLoginType)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -7090,6 +7143,8 @@ func (m *CpUserMutation) Field(name string) (ent.Value, bool) {
|
||||
return m.Cookie()
|
||||
case cpuser.FieldMobileType:
|
||||
return m.MobileType()
|
||||
case cpuser.FieldLoginType:
|
||||
return m.LoginType()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
@@ -7119,6 +7174,8 @@ func (m *CpUserMutation) OldField(ctx context.Context, name string) (ent.Value,
|
||||
return m.OldCookie(ctx)
|
||||
case cpuser.FieldMobileType:
|
||||
return m.OldMobileType(ctx)
|
||||
case cpuser.FieldLoginType:
|
||||
return m.OldLoginType(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown CpUser field %s", name)
|
||||
}
|
||||
@@ -7198,6 +7255,13 @@ func (m *CpUserMutation) SetField(name string, value ent.Value) error {
|
||||
}
|
||||
m.SetMobileType(v)
|
||||
return nil
|
||||
case cpuser.FieldLoginType:
|
||||
v, ok := value.(cpuser.LoginType)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetLoginType(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown CpUser field %s", name)
|
||||
}
|
||||
@@ -7231,6 +7295,9 @@ func (m *CpUserMutation) AddField(name string, value ent.Value) error {
|
||||
// mutation.
|
||||
func (m *CpUserMutation) ClearedFields() []string {
|
||||
var fields []string
|
||||
if m.FieldCleared(cpuser.FieldPassword) {
|
||||
fields = append(fields, cpuser.FieldPassword)
|
||||
}
|
||||
if m.FieldCleared(cpuser.FieldEmail) {
|
||||
fields = append(fields, cpuser.FieldEmail)
|
||||
}
|
||||
@@ -7254,6 +7321,9 @@ func (m *CpUserMutation) FieldCleared(name string) bool {
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *CpUserMutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case cpuser.FieldPassword:
|
||||
m.ClearPassword()
|
||||
return nil
|
||||
case cpuser.FieldEmail:
|
||||
m.ClearEmail()
|
||||
return nil
|
||||
@@ -7301,6 +7371,9 @@ func (m *CpUserMutation) ResetField(name string) error {
|
||||
case cpuser.FieldMobileType:
|
||||
m.ResetMobileType()
|
||||
return nil
|
||||
case cpuser.FieldLoginType:
|
||||
m.ResetLoginType()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown CpUser field %s", name)
|
||||
}
|
||||
|
||||
@@ -185,10 +185,6 @@ func init() {
|
||||
cpuserDescUsername := cpuserFields[1].Descriptor()
|
||||
// cpuser.UsernameValidator is a validator for the "username" field. It is called by the builders before save.
|
||||
cpuser.UsernameValidator = cpuserDescUsername.Validators[0].(func(string) error)
|
||||
// cpuserDescPassword is the schema descriptor for password field.
|
||||
cpuserDescPassword := cpuserFields[2].Descriptor()
|
||||
// cpuser.PasswordValidator is a validator for the "password" field. It is called by the builders before save.
|
||||
cpuser.PasswordValidator = cpuserDescPassword.Validators[0].(func(string) error)
|
||||
// cpuserDescSchoolID is the schema descriptor for school_id field.
|
||||
cpuserDescSchoolID := cpuserFields[3].Descriptor()
|
||||
// cpuser.SchoolIDValidator is a validator for the "school_id" field. It is called by the builders before save.
|
||||
|
||||
@@ -19,12 +19,13 @@ func (CpUser) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("user_id"),
|
||||
field.String("username").NotEmpty(),
|
||||
field.String("password").NotEmpty(),
|
||||
field.String("password").Optional(),
|
||||
field.String("school_id").NotEmpty(),
|
||||
field.String("email").Optional(),
|
||||
field.String("mobile_code").Optional(),
|
||||
field.Text("cookie").Optional(),
|
||||
field.Enum("mobile_type").Values("random", "authorize"),
|
||||
field.Enum("login_type").Values("account", "phone").Default("account"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,32 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
var Logger *zap.Logger
|
||||
|
||||
func init() {
|
||||
logger, err := zap.NewProduction()
|
||||
// Create a production config and customize the time encoder
|
||||
config := zap.NewProductionConfig()
|
||||
config.EncoderConfig.EncodeTime = BeijingTimeEncoder
|
||||
|
||||
// Build the logger with the custom config
|
||||
logger, err := config.Build()
|
||||
if err != nil {
|
||||
log.Fatalf("cannot init zap logger: %+v", err)
|
||||
}
|
||||
|
||||
Logger = logger
|
||||
}
|
||||
|
||||
// BeijingTimeEncoder formats time in Beijing timezone
|
||||
func BeijingTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
|
||||
// Set timezone to Beijing (UTC+8)
|
||||
beijingLoc, _ := time.LoadLocation("Asia/Shanghai")
|
||||
enc.AppendString(t.In(beijingLoc).Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func (c *CpdailyTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task)
|
||||
schoolDetail := school.GetSchoolDetail(ctx, targetTask.Edges.CpUser.SchoolID)
|
||||
cookie := targetTask.Edges.CpUser.Cookie
|
||||
restyClient := login.GetClient(ctx, cookie)
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, restyClient) {
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, restyClient, targetTask.Edges.CpUser.LoginType) {
|
||||
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
|
||||
loginExecutor.Login(ctx, &schoolDetail, targetTask.Edges.CpUser.Username, targetTask.Edges.CpUser.Password)
|
||||
cookie = loginExecutor.GetCookieString()
|
||||
|
||||
@@ -19,11 +19,18 @@ type EmailTaskHandler struct {
|
||||
|
||||
func (h *EmailTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task) (err error) {
|
||||
defer utils.Pass(&err)
|
||||
|
||||
var payload email.SendPayload
|
||||
|
||||
e := gob.NewDecoder(bytes.NewReader(task.Payload())).Decode(&payload)
|
||||
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||
logger.Logger.Info("开始处理邮件发送", zap.String("邮箱", payload.To))
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// 打印日志
|
||||
logger.Logger.Error("邮件发送失败", zap.String("邮箱", payload.To), zap.Error(r.(error)))
|
||||
// 重新抛出相同的 panic
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
|
||||
message := mail.NewMsg()
|
||||
|
||||
|
||||
@@ -97,9 +97,31 @@ func (h *XuexitongTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task
|
||||
// 创建课程服务
|
||||
courseService := xuexitong.NewXuexitongCourse(client)
|
||||
|
||||
// 非暴力模式下,设置时间检查回调,每个任务点完成后都会检查时间
|
||||
if targetCourse.Violence == courseentity.ViolenceNo {
|
||||
courseService.SetTimeCheckFunc(func() bool {
|
||||
currentTime := time.Now()
|
||||
currentHour := currentTime.Hour()
|
||||
currentMinute := currentTime.Minute()
|
||||
|
||||
startTime := 8*60 + 30 // 8:30
|
||||
endTime := 17*60 + 30 // 17:30
|
||||
currentMinutes := currentHour*60 + currentMinute
|
||||
|
||||
return currentMinutes >= startTime && currentMinutes < endTime
|
||||
})
|
||||
}
|
||||
|
||||
// 执行刷课
|
||||
err = courseService.AutoStudyByCourseID(ctx, targetCourse.CourseID)
|
||||
if err != nil {
|
||||
// 如果是时间限制导致的停止,不算失败
|
||||
if err == xuexitong.ErrTimeRestriction {
|
||||
g.Log().Infof(ctx, "课程ID %d 因时间限制暂停刷课,等待下次执行", targetCourse.ID)
|
||||
// 更新状态为等待中,等待下次定时任务
|
||||
db.Global.CourseEntity.UpdateOneID(taskPayload.CourseID).SetStatus(courseentity.StatusWaiting).ExecX(ctx)
|
||||
return nil
|
||||
}
|
||||
utils.OkOrPanic(errors.NewBusinessErrorWithDetail(503, "刷课失败", err))
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ func (v CpLeaveServiceV1) GetLeaveListFromSystem(ctx context.Context, req *v1.Ge
|
||||
client := login.GetClient(ctx, cookie)
|
||||
|
||||
// 检查cookie是否有效
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client) {
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client, cpUser.LoginType) {
|
||||
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
|
||||
loginExecutor.Login(ctx, &schoolDetail, cpUser.Username, cpUser.Password)
|
||||
cookie = loginExecutor.GetCookieString()
|
||||
@@ -110,15 +110,6 @@ func (v CpLeaveServiceV1) Report(ctx context.Context, req *v1.CpLeaveReportReq)
|
||||
utils.OkOrPanic(errors2.NewBusinessError(400, "非法的今日校园账号"))
|
||||
}
|
||||
|
||||
// 检查是否已经存在该销假记录
|
||||
existLeave, _ := db2.Global.CpLeave.Query().
|
||||
Where(cpleave.LeaveIDEQ(req.LeaveId), cpleave.CpUserIDEQ(req.CpUserId)).
|
||||
First(ctx)
|
||||
|
||||
if existLeave != nil {
|
||||
utils.OkOrPanic(errors2.NewBusinessError(400, fmt.Sprintf("该请假记录已处理,状态:%s", existLeave.Status)))
|
||||
}
|
||||
|
||||
// 计算扣款金额
|
||||
basePoint, err := decimal.NewFromString(g.Cfg().MustGet(ctx, cst2.ConfigBasePointCpdailyLeave).String())
|
||||
utils.OkOrPanic(err)
|
||||
@@ -161,7 +152,7 @@ func (v CpLeaveServiceV1) Report(ctx context.Context, req *v1.CpLeaveReportReq)
|
||||
client := login.GetClient(ctx, cookie)
|
||||
|
||||
// 检查cookie是否有效
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client) {
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client, cpUser.LoginType) {
|
||||
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
|
||||
loginExecutor.Login(ctx, &schoolDetail, cpUser.Username, cpUser.Password)
|
||||
cookie = loginExecutor.GetCookieString()
|
||||
|
||||
@@ -43,7 +43,7 @@ func (v CpTaskServiceV1) GetRecentTasks(ctx context.Context, req *v1.GetRecentTa
|
||||
}
|
||||
schoolDetail := school.GetSchoolDetail(ctx, cpUser.SchoolID)
|
||||
client := login.GetClient(ctx, cpUser.Cookie)
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client) {
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client, cpUser.LoginType) {
|
||||
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
|
||||
loginExecutor.Login(ctx, &schoolDetail, cpUser.Username, cpUser.Password)
|
||||
cookie := loginExecutor.GetCookieString()
|
||||
@@ -118,7 +118,7 @@ func (v CpTaskServiceV1) TaskFormData(ctx context.Context, req *v1.GetCpTaskForm
|
||||
schoolDetail := school.GetSchoolDetail(ctx, cpTask.Edges.CpUser.SchoolID)
|
||||
cookie := cpUser.Cookie
|
||||
client := login.GetClient(ctx, cookie)
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client) {
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client, cpUser.LoginType) {
|
||||
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
|
||||
loginExecutor.Login(ctx, &schoolDetail, cpUser.Username, cpUser.Password)
|
||||
cookie = loginExecutor.GetCookieString()
|
||||
|
||||
@@ -3,6 +3,7 @@ package cpdaily
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/application/cookiejar"
|
||||
"likedream-goframe/internal/application/cpdaily/login"
|
||||
"likedream-goframe/internal/application/cpdaily/school"
|
||||
"likedream-goframe/internal/common/cst"
|
||||
@@ -12,12 +13,15 @@ import (
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/redis"
|
||||
"likedream-goframe/internal/service/balance"
|
||||
"likedream-goframe/internal/utils"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/samber/oops"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
type CpUserServiceV1 struct {
|
||||
@@ -66,6 +70,7 @@ func (v CpUserServiceV1) ConfirmAdd(ctx context.Context, req *v1.CpUserConfirmAd
|
||||
SetMobileType(cpuser.MobileTypeRandom).
|
||||
SetSchoolID(sc.Id).
|
||||
SetSysuserID(user.ID).
|
||||
SetLoginType(cpuser.LoginTypeAccount).
|
||||
SaveX(ctx)
|
||||
return utils.SuccessWithMsg("添加成功")
|
||||
}
|
||||
@@ -88,6 +93,7 @@ func (v CpUserServiceV1) List(ctx context.Context, req *v1.CpUserListReq) *utils
|
||||
// 忽略密码
|
||||
for _, v := range data {
|
||||
v.Password = ""
|
||||
v.Cookie = ""
|
||||
}
|
||||
return utils.SuccessWithTotal[[]*ent.CpUser](data, total)
|
||||
}
|
||||
@@ -174,11 +180,53 @@ func (v CpUserServiceV1) AuthorizeRandom(ctx context.Context, req *v1.CpUserAuth
|
||||
}
|
||||
|
||||
func (v CpUserServiceV1) LoginGetCode(ctx context.Context, req *v1.LoginGetCode) *utils.Response[any] {
|
||||
return utils.SuccessWithMsg("")
|
||||
user := utils.GetUserInfoFromCtx(ctx)
|
||||
// 扣费
|
||||
basePoint, err := decimal.NewFromString(g.Cfg().MustGet(ctx, cst.ConfigBasePointCpdailyPhone).String())
|
||||
utils.OkOrPanic(err)
|
||||
if user.Edges.Agent != nil {
|
||||
basePoint = basePoint.Mul(user.Edges.Agent.Rate)
|
||||
}
|
||||
if user.Balance.Sub(basePoint).IsNegative() {
|
||||
return utils.Fail(400, "余额不足")
|
||||
}
|
||||
loginExecutor := login.NewSmsWithoutDeviceID()
|
||||
loginExecutor.SendSms(ctx, req.Mobile)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint.Neg(), "手机号登录 - 验证码")
|
||||
return utils.SuccessWithMsg("发送成功")
|
||||
}
|
||||
|
||||
func (v CpUserServiceV1) AddByCode(ctx context.Context, req *v1.AddByCode) *utils.Response[any] {
|
||||
return utils.SuccessWithMsg("")
|
||||
user := utils.GetUserInfoFromCtx(ctx)
|
||||
jar := cookiejar.NewPersistCookieJar()
|
||||
loginExecutor := login.NewSmsWithoutDeviceID()
|
||||
data := loginExecutor.LoginByCode(context.Background(), req.Mobile, req.Code, jar)
|
||||
loginExecutor.SetLoginCookie(context.Background(), jar, data)
|
||||
// 扣费
|
||||
basePoint, err := decimal.NewFromString(g.Cfg().MustGet(ctx, cst.ConfigBasePointCpdailyPhone).String())
|
||||
utils.OkOrPanic(err)
|
||||
if user.Edges.Agent != nil {
|
||||
basePoint = basePoint.Mul(user.Edges.Agent.Rate)
|
||||
}
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint.Neg(), "手机号登录 - 登录")
|
||||
if req.Id == 0 {
|
||||
db.Global.CpUser.Create().
|
||||
SetUsername(req.Mobile).
|
||||
SetEmail(req.Email).
|
||||
SetSchoolID(req.SchoolId).
|
||||
SetCookie(loginExecutor.GetCookieString()).
|
||||
SetMobileCode(utils.UUID()).
|
||||
SetMobileType(cpuser.MobileTypeRandom).
|
||||
SetSysuserID(user.ID).
|
||||
SetLoginType(cpuser.LoginTypePhone).
|
||||
SaveX(ctx)
|
||||
return utils.SuccessWithMsg("添加成功")
|
||||
} else {
|
||||
db.Global.CpUser.UpdateOneID(req.Id).
|
||||
SetCookie(loginExecutor.GetCookieString()).
|
||||
ExecX(ctx)
|
||||
return utils.SuccessWithMsg("更新成功")
|
||||
}
|
||||
}
|
||||
|
||||
func (v CpUserServiceV1) LoginUrl(ctx context.Context, req *v1.CpUserLoginUrlReq) *utils.Response[any] {
|
||||
|
||||
Reference in New Issue
Block a user