收紧数据保存检查
This commit is contained in:
@@ -142,7 +142,7 @@ func IdentifyCallbackNew(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// 更新用户实名认证状态
|
||||
_, err = q.User.
|
||||
r, err := q.User.
|
||||
Where(q.User.ID.Eq(info.Uid)).
|
||||
UpdateSimple(
|
||||
q.User.IDType.Value(info.Type),
|
||||
@@ -153,6 +153,9 @@ func IdentifyCallbackNew(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return renderIdenResult(c, false, "保存实名认证信息失败,请联系客服处理")
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return renderIdenResult(c, false, "用户状态已失效")
|
||||
}
|
||||
|
||||
// 返回结果页面
|
||||
return renderIdenResult(c, true, "实名认证成功,请在扫码页面点击按钮完成认证")
|
||||
@@ -172,7 +175,7 @@ func DebugIdentifyClear(c *fiber.Ctx) error {
|
||||
return core.NewServErr("需要提供手机号")
|
||||
}
|
||||
|
||||
_, err := q.User.
|
||||
r, err := q.User.
|
||||
Where(
|
||||
q.User.Phone.Eq(phone),
|
||||
).
|
||||
@@ -184,6 +187,9 @@ func DebugIdentifyClear(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return core.NewServErr("清除实名认证失败")
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewServErr("用户状态已失效")
|
||||
}
|
||||
|
||||
return c.SendString("实名信息已清除")
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ func BindAdmin(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// 更新用户信息
|
||||
result, err := q.User.Where(
|
||||
r, err := q.User.Where(
|
||||
q.User.ID.Eq(int32(req.UserID)),
|
||||
q.User.AdminID.IsNull(),
|
||||
).UpdateColumnSimple(
|
||||
@@ -283,7 +283,7 @@ func BindAdmin(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result.RowsAffected == 0 {
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("用户已绑定管理员")
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ func UpdateUser(c *fiber.Ctx) error {
|
||||
if req.ContactWechat != nil {
|
||||
do = append(do, q.User.ContactWechat.Value(*req.ContactWechat))
|
||||
}
|
||||
_, err = q.User.
|
||||
r, err := q.User.
|
||||
Where(q.User.ID.Eq(authCtx.User.ID)).
|
||||
UpdateSimple(do...)
|
||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
@@ -332,6 +332,9 @@ func UpdateUser(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("用户状态已过期")
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
@@ -359,7 +362,7 @@ func UpdateAccount(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// 更新用户信息
|
||||
_, err = q.User.
|
||||
r, err := q.User.
|
||||
Where(q.User.ID.Eq(authCtx.User.ID)).
|
||||
Updates(m.User{
|
||||
Username: &req.Username,
|
||||
@@ -368,6 +371,9 @@ func UpdateAccount(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("用户状态已过期")
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
@@ -410,12 +416,15 @@ func UpdatePassword(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = q.User.
|
||||
r, err := q.User.
|
||||
Where(q.User.ID.Eq(authCtx.User.ID)).
|
||||
UpdateColumn(q.User.Password, newHash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("用户状态已过期")
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
|
||||
@@ -156,7 +156,7 @@ func UpdateWhitelist(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// 更新白名单
|
||||
_, err = q.Whitelist.
|
||||
r, err := q.Whitelist.
|
||||
Where(
|
||||
q.Whitelist.ID.Eq(req.ID),
|
||||
q.Whitelist.UserID.Eq(authCtx.User.ID),
|
||||
@@ -168,6 +168,9 @@ func UpdateWhitelist(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("白名单状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -201,7 +204,7 @@ func RemoveWhitelist(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// 删除白名单
|
||||
_, err = q.Whitelist.
|
||||
r, err := q.Whitelist.
|
||||
Where(
|
||||
q.Whitelist.ID.In(ids...),
|
||||
q.Whitelist.UserID.Eq(authCtx.User.ID),
|
||||
@@ -212,6 +215,9 @@ func RemoveWhitelist(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("白名单状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"platform/pkg/env"
|
||||
auth2 "platform/web/auth"
|
||||
"platform/web/core"
|
||||
"platform/web/globals"
|
||||
"platform/web/handlers"
|
||||
"time"
|
||||
|
||||
@@ -37,6 +38,17 @@ func ApplyRouters(app *fiber.App) {
|
||||
debug.Get("/test/err", func(ctx *fiber.Ctx) error {
|
||||
return core.NewBizErr("测试错误")
|
||||
})
|
||||
|
||||
debug.Get("/trade/status/:trade_no", func(ctx *fiber.Ctx) error {
|
||||
tradeNo := ctx.Params("trade_no")
|
||||
resp, err := globals.SFTPay.QueryTrade(&globals.QueryTradeReq{
|
||||
MchOrderNo: &tradeNo,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.JSON(resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ func (s *adminService) Update(update *UpdateAdmin) error {
|
||||
return q.Q.Transaction(func(q *q.Query) error {
|
||||
// 更新管理员基本信息
|
||||
if len(simples) > 0 {
|
||||
_, err := q.Admin.
|
||||
r, err := q.Admin.
|
||||
Where(
|
||||
q.Admin.ID.Eq(update.Id),
|
||||
q.Admin.Lock.Is(false),
|
||||
@@ -119,6 +119,9 @@ func (s *adminService) Update(update *UpdateAdmin) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("管理员状态已过期")
|
||||
}
|
||||
}
|
||||
|
||||
// 更新角色关联
|
||||
@@ -157,11 +160,17 @@ type UpdateAdmin struct {
|
||||
}
|
||||
|
||||
func (s *adminService) Remove(id int32) error {
|
||||
_, err := q.Admin.
|
||||
r, err := q.Admin.
|
||||
Where(
|
||||
q.Admin.ID.Eq(id),
|
||||
q.Admin.Lock.Is(false),
|
||||
).
|
||||
UpdateColumn(q.Admin.DeletedAt, time.Now())
|
||||
return err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("管理员状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -137,8 +137,14 @@ type UpdateAdminRole struct {
|
||||
}
|
||||
|
||||
func (r *adminRoleService) RemoveAdminRole(id int32) error {
|
||||
_, err := q.AdminRole.Where(q.AdminRole.ID.Eq(id)).UpdateColumn(q.AdminRole.DeletedAt, time.Now())
|
||||
return err
|
||||
rs, err := q.AdminRole.Where(q.AdminRole.ID.Eq(id)).UpdateColumn(q.AdminRole.DeletedAt, time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if rs.RowsAffected == 0 {
|
||||
return core.NewBizErr("管理员角色状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var AdminRoleModifyLock = "platform:admin_role_permissions:modify"
|
||||
|
||||
@@ -87,8 +87,14 @@ func (s *couponService) Update(data UpdateCouponData) error {
|
||||
do = append(do, q.Coupon.ExpireType.Value(int(*data.ExpireType)))
|
||||
}
|
||||
|
||||
_, err := q.Coupon.Where(q.Coupon.ID.Eq(data.ID)).UpdateSimple(do...)
|
||||
return err
|
||||
r, err := q.Coupon.Where(q.Coupon.ID.Eq(data.ID)).UpdateSimple(do...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("优惠券状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateCouponData struct {
|
||||
@@ -104,8 +110,14 @@ type UpdateCouponData struct {
|
||||
}
|
||||
|
||||
func (s *couponService) Delete(id int32) error {
|
||||
_, err := q.Coupon.Where(q.Coupon.ID.Eq(id)).UpdateColumn(q.Coupon.DeletedAt, time.Now())
|
||||
return err
|
||||
r, err := q.Coupon.Where(q.Coupon.ID.Eq(id)).UpdateColumn(q.Coupon.DeletedAt, time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("优惠券状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *couponService) Assign(couponID int32, userID int32) error {
|
||||
@@ -140,7 +152,7 @@ func (s *couponService) GetUserCoupon(uid int32, cuid int32, amount decimal.Deci
|
||||
}
|
||||
|
||||
func (s *couponService) UseCoupon(q *q.Query, cuid int32) error {
|
||||
_, err := q.CouponUser.
|
||||
r, err := q.CouponUser.
|
||||
Where(
|
||||
q.CouponUser.ID.Eq(cuid),
|
||||
q.CouponUser.Status.Eq(int(m.CouponUserStatusUnused)),
|
||||
@@ -149,5 +161,11 @@ func (s *couponService) UseCoupon(q *q.Query, cuid int32) error {
|
||||
q.CouponUser.Status.Value(int(m.CouponUserStatusUsed)),
|
||||
q.CouponUser.UsedAt.Value(time.Now()),
|
||||
)
|
||||
return err
|
||||
if err != nil {
|
||||
return core.NewBizErr("使用优惠券失败", err)
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("优惠券状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -117,8 +117,14 @@ func (s *productService) UpdateProduct(update *UpdateProductData) error {
|
||||
if update.Status != nil {
|
||||
do = append(do, q.Product.Status.Value(*update.Status))
|
||||
}
|
||||
_, err := q.Product.Where(q.Product.ID.Eq(update.Id)).UpdateSimple(do...)
|
||||
return err
|
||||
r, err := q.Product.Where(q.Product.ID.Eq(update.Id)).UpdateSimple(do...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("产品状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateProductData struct {
|
||||
@@ -132,6 +138,12 @@ type UpdateProductData struct {
|
||||
|
||||
// 删除产品
|
||||
func (s *productService) DeleteProduct(id int32) error {
|
||||
_, err := q.Product.Where(q.Product.ID.Eq(id)).UpdateColumn(q.Product.DeletedAt, time.Now())
|
||||
return err
|
||||
r, err := q.Product.Where(q.Product.ID.Eq(id)).UpdateColumn(q.Product.DeletedAt, time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("产品状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -43,8 +43,14 @@ func (s *productDiscountService) Update(data UpdateProductDiscountData) (err err
|
||||
do = append(do, q.ProductDiscount.Discount.Value(*data.Discount))
|
||||
}
|
||||
|
||||
_, err = q.ProductDiscount.Where(q.ProductDiscount.ID.Eq(data.ID)).UpdateSimple(do...)
|
||||
return err
|
||||
r, err := q.ProductDiscount.Where(q.ProductDiscount.ID.Eq(data.ID)).UpdateSimple(do...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewServErr("产品折扣状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateProductDiscountData struct {
|
||||
@@ -54,6 +60,12 @@ type UpdateProductDiscountData struct {
|
||||
}
|
||||
|
||||
func (s *productDiscountService) Delete(id int32) (err error) {
|
||||
_, err = q.ProductDiscount.Where(q.ProductDiscount.ID.Eq(id)).UpdateColumn(q.ProductDiscount.DeletedAt, time.Now())
|
||||
return
|
||||
r, err := q.ProductDiscount.Where(q.ProductDiscount.ID.Eq(id)).UpdateColumn(q.ProductDiscount.DeletedAt, time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewServErr("产品折扣状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -111,8 +111,14 @@ func (s *productSkuService) Update(update UpdateProductSkuData) (err error) {
|
||||
do = append(do, q.ProductSku.CountMin.Value(*update.CountMin))
|
||||
}
|
||||
|
||||
_, err = q.ProductSku.Where(q.ProductSku.ID.Eq(update.ID)).UpdateSimple(do...)
|
||||
return err
|
||||
r, err := q.ProductSku.Where(q.ProductSku.ID.Eq(update.ID)).UpdateSimple(do...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewServErr("产品套餐状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateProductSkuData struct {
|
||||
@@ -128,15 +134,27 @@ type UpdateProductSkuData struct {
|
||||
}
|
||||
|
||||
func (s *productSkuService) Delete(id int32) (err error) {
|
||||
_, err = q.ProductSku.Where(q.ProductSku.ID.Eq(id)).UpdateColumn(q.ProductSku.DeletedAt, time.Now())
|
||||
return
|
||||
r, err := q.ProductSku.Where(q.ProductSku.ID.Eq(id)).UpdateColumn(q.ProductSku.DeletedAt, time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewServErr("产品套餐状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *productSkuService) BatchUpdateDiscount(data BatchUpdateSkuDiscountData) (err error) {
|
||||
_, err = q.ProductSku.Where(q.ProductSku.ProductID.Eq(data.ProductID)).UpdateSimple(
|
||||
r, err := q.ProductSku.Where(q.ProductSku.ProductID.Eq(data.ProductID)).UpdateSimple(
|
||||
q.ProductSku.DiscountId.Value(data.DiscountID),
|
||||
)
|
||||
return
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewServErr("产品套餐状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type BatchUpdateSkuDiscountData struct {
|
||||
|
||||
@@ -130,12 +130,15 @@ func (s *resourceService) Update(data *UpdateResourceData) error {
|
||||
do = append(do, q.Resource.CheckIP.Value(*data.CheckIP))
|
||||
}
|
||||
|
||||
_, err := q.Resource.
|
||||
r, err := q.Resource.
|
||||
Where(q.Resource.ID.Eq(data.Id)).
|
||||
UpdateSimple(do...)
|
||||
if err != nil {
|
||||
return core.NewServErr("更新套餐失败", err)
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("套餐状态已过期")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ func (s *tradeService) OnCompleteTrade(user *m.User, interNo string, outerNo str
|
||||
|
||||
err = q.Q.Transaction(func(q *q.Query) error {
|
||||
// 更新交易信息
|
||||
_, err := q.Trade.
|
||||
r, err := q.Trade.
|
||||
Where(
|
||||
q.Trade.InnerNo.Eq(interNo),
|
||||
q.Trade.Status.Eq(int(m.TradeStatusPending)),
|
||||
@@ -299,6 +299,9 @@ func (s *tradeService) OnCompleteTrade(user *m.User, interNo string, outerNo str
|
||||
if err != nil {
|
||||
return core.NewServErr("更新交易信息失败", err)
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("交易状态已过期")
|
||||
}
|
||||
|
||||
switch trade.Type {
|
||||
case m.TradeTypeRecharge:
|
||||
@@ -406,7 +409,7 @@ func (s *tradeService) CancelTrade(ref *TradeRef) error {
|
||||
return nil
|
||||
}
|
||||
func (s *tradeService) OnCancelTrade(tradeNo string, now time.Time) error {
|
||||
_, err := q.Trade.
|
||||
r, err := q.Trade.
|
||||
Where(
|
||||
q.Trade.InnerNo.Eq(tradeNo),
|
||||
q.Trade.Status.Eq(int(m.TradeStatusPending)),
|
||||
@@ -418,6 +421,9 @@ func (s *tradeService) OnCancelTrade(tradeNo string, now time.Time) error {
|
||||
if err != nil {
|
||||
return core.NewServErr("更新交易状态失败", err)
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("交易状态已过期")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func (s *userService) UpdateBalance(q *q.Query, user *m.User, amount decimal.Dec
|
||||
}
|
||||
|
||||
// 更新余额
|
||||
_, err := q.User.
|
||||
r, err := q.User.
|
||||
Where(
|
||||
q.User.ID.Eq(user.ID),
|
||||
q.User.Balance.Eq(user.Balance),
|
||||
@@ -61,6 +61,9 @@ func (s *userService) UpdateBalance(q *q.Query, user *m.User, amount decimal.Dec
|
||||
if err != nil {
|
||||
return core.NewServErr("更新用户余额失败", err)
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("余额状态已过期")
|
||||
}
|
||||
|
||||
// 新增动账记录
|
||||
err = q.BalanceActivity.Create(&m.BalanceActivity{
|
||||
@@ -204,12 +207,18 @@ func (s *userService) UpdateByAdmin(data UpdateUserByAdminData) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := q.User.Where(q.User.ID.Eq(data.ID)).UpdateSimple(do...)
|
||||
r, err := q.User.Where(q.User.ID.Eq(data.ID)).UpdateSimple(do...)
|
||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
return core.NewBizErr("账号已存在,请检查手机号/用户名/邮箱是否重复")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("用户状态已过期")
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateUserByAdminData struct {
|
||||
@@ -231,6 +240,12 @@ type UpdateUserByAdminData struct {
|
||||
}
|
||||
|
||||
func (s *userService) RemoveByAdmin(id int32) error {
|
||||
_, err := q.User.Where(q.User.ID.Eq(id)).UpdateColumn(q.User.DeletedAt, time.Now())
|
||||
return err
|
||||
r, err := q.User.Where(q.User.ID.Eq(id)).UpdateColumn(q.User.DeletedAt, time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RowsAffected == 0 {
|
||||
return core.NewBizErr("用户状态已过期")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user