From 34603a48b8018d66957db2c7046ca9f12814dd3d Mon Sep 17 00:00:00 2001 From: HXY <2479895356@qq.com> Date: Sun, 6 Aug 2023 19:41:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=85=AC=E7=BA=A6=E4=B8=8E?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E5=8F=B7=E7=BB=91=E5=AE=9A=E8=B5=A0=E9=80=81?= =?UTF-8?q?=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/dao/jinzhu/user.go | 50 ++++++++++++++++++++++++++++++++- internal/dao/search/search.go | 2 +- internal/servants/web/pub.go | 5 ---- web/src/components/auth.vue | 3 ++ web/src/components/rightbar.vue | 6 ++++ web/src/router/index.ts | 18 +++++++++++- web/src/views/ShareKey.vue | 13 ++++++++- 7 files changed, 88 insertions(+), 9 deletions(-) diff --git a/internal/dao/jinzhu/user.go b/internal/dao/jinzhu/user.go index 96d09fc1..d7d85e5f 100644 --- a/internal/dao/jinzhu/user.go +++ b/internal/dao/jinzhu/user.go @@ -6,6 +6,7 @@ package jinzhu import ( "strings" + "time" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" @@ -90,5 +91,52 @@ func (s *userManageServant) CreateUser(user *dbr.User) (*core.User, error) { } func (s *userManageServant) UpdateUser(user *core.User) error { - return user.Update(s.db) + return s.db.Transaction(func(tx *gorm.DB) error { + //获取用户的账单,判断是否赠送过 + bills, err := (&dbr.WalletStatement{}).List(tx, &dbr.ConditionsT{ + "user_id = ?": user.ID, + "reason = ?": "手机号绑定赠送", + }, 0, 1) + if err != nil { + return err + } + if len(bills) > 0 { + err = user.Update(s.db) + if err != nil { + return err + } + return nil + } + + //查询当前用户的balance + oldUser, err := s.GetUserByID(user.ID) + if err != nil { + return err + } + if oldUser.Balance == 0 || oldUser.Balance <= time.Now().Unix() { + //更新当前用户的balance时间戳,增加14天 + //获取当前时间戳并加上14天 + user.Balance = time.Now().Unix() + 1209600 + } else { + user.Balance = oldUser.Balance + user.Balance + } + + err = user.Update(s.db) + if err != nil { + return err + } + + // 新增账单 + if err := tx.Create(&dbr.WalletStatement{ + UserID: user.ID, + ChangeAmount: 1400, + BalanceSnapshot: user.Balance, + Reason: "手机号绑定赠送", + }).Error; err != nil { + return err + } + + //返回nil,事务会被提交 + return nil + }) } diff --git a/internal/dao/search/search.go b/internal/dao/search/search.go index 25513e84..ffcbe761 100644 --- a/internal/dao/search/search.go +++ b/internal/dao/search/search.go @@ -29,7 +29,7 @@ func NewMeiliTweetSearchService(ams core.AuthorizationManageService) (core.Tweet }); err == nil { settings := meilisearch.Settings{ SearchableAttributes: []string{"content", "tags"}, - SortableAttributes: []string{"is_top", "latest_replied_on", "upvote_count", "collection_count"}, + SortableAttributes: []string{"is_top", "collection_count", "upvote_count:desc", "collection_count:desc"}, FilterableAttributes: []string{"tags", "visibility", "user_id"}, } if _, err = client.Index(s.Index).UpdateSettings(&settings); err != nil { diff --git a/internal/servants/web/pub.go b/internal/servants/web/pub.go index ff94cfd6..5314b9b0 100644 --- a/internal/servants/web/pub.go +++ b/internal/servants/web/pub.go @@ -11,7 +11,6 @@ import ( "image/color" "image/png" "regexp" - "time" "unicode/utf8" "github.com/afocus/captcha" @@ -133,9 +132,6 @@ func (s *pubSrv) Register(req *web.RegisterReq) (*web.RegisterResp, mir.Error) { } password, salt := encryptPasswordAndSalt(req.Password) //password, salt := encryptPasswordAndSalt(req.Password, req.Username) - //当前时间戳加15天 - balance := time.Now().AddDate(0, 0, 15).Unix() - user := &core.User{ Nickname: req.Username, Username: req.Username, @@ -143,7 +139,6 @@ func (s *pubSrv) Register(req *web.RegisterReq) (*web.RegisterResp, mir.Error) { Avatar: getRandomAvatar(), Salt: salt, Status: core.UserStatusNormal, - Balance: balance, } user, err := s.Ds.CreateUser(user) if err != nil { diff --git a/web/src/components/auth.vue b/web/src/components/auth.vue index 4ea830fa..8850495b 100644 --- a/web/src/components/auth.vue +++ b/web/src/components/auth.vue @@ -136,6 +136,9 @@ /> +

+ 注册完成后请及时进入个人中心绑定手机号,成功绑定手机后,才能进行换头像、发动态、回复等交互,并将赠送14天的Aimo订阅! +

+ + + 功能即将推出,请耐心等待~ + + @@ -192,6 +197,7 @@ onMounted(() => { .hottopic-wrap { margin-bottom: 10px; + margin-top: 10px; } .copyright-wrap { diff --git a/web/src/router/index.ts b/web/src/router/index.ts index a5e1b3a9..b50ffc96 100644 --- a/web/src/router/index.ts +++ b/web/src/router/index.ts @@ -94,7 +94,7 @@ const routes = [ path: '/sharekey', name: 'sharekey', meta: { - title: '密钥', + title: '我的分享码', }, component: () => import('@/views/ShareKey.vue'), }, @@ -106,6 +106,22 @@ const routes = [ }, component: () => import('@/views/404.vue'), }, + { + path: '/community', + name: 'community', + meta: { + title: '社区公约', + }, + component: () => import('@/views/community.vue'), + }, + { + path: '/notification', + name: 'notification', + meta: { + title: 'AiMo协议(草案)', + }, + component: () => import('@/views/notification.vue'), + }, { path: '/:pathMatch(.*)', redirect: '/404', diff --git a/web/src/views/ShareKey.vue b/web/src/views/ShareKey.vue index 3c39cbb6..b023fc33 100644 --- a/web/src/views/ShareKey.vue +++ b/web/src/views/ShareKey.vue @@ -133,9 +133,14 @@ const loadKeys = () => { }) .catch((err) => { loading.value = false; + store.commit('triggerAuth', true); + store.commit('userLogout'); }); + } else { + loading.value = false; + store.commit('triggerAuth', true); + store.commit('userLogout'); } - }; const isDelete = (sharekey: Item.ShareKeyProps) => { selectedShareKey.value = sharekey; @@ -159,7 +164,13 @@ const deleteShareKey = (keyToDelete: string) => { }) .catch((err) => { loading.value = false; + store.commit('triggerAuth', true); + store.commit('userLogout'); }); + } else { + loading.value = false; + store.commit('triggerAuth', true); + store.commit('userLogout'); } showRecharge.value = false; };