更新公约与手机号绑定赠送时长

pull/361/head
HXY 2 years ago
parent 3c15d4a3d7
commit 34603a48b8

@ -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
})
}

@ -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 {

@ -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 {

@ -136,6 +136,9 @@
/>
</n-form-item-row>
</n-form>
<p style=" font-size: 12px; color: #ef0808;">
14Aimo
</p>
<n-button
type="primary"
block

@ -78,6 +78,11 @@
</n-space>
</div>
</n-card>
<n-card class="hottopic-wrap" title="排行榜" embedded :bordered="false" size="small">
<n-spin :show="loading">
~
</n-spin>
</n-card>
</div>
</template>
@ -192,6 +197,7 @@ onMounted(() => {
.hottopic-wrap {
margin-bottom: 10px;
margin-top: 10px;
}
.copyright-wrap {

@ -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',

@ -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;
};

Loading…
Cancel
Save