收紧数据保存检查
This commit is contained in:
@@ -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