feat(cool): 添加删除和更新操作的数据影响行数检查
- 在Controller的Delete方法中添加RowsAffected检查,当影响行数为0时返回"not found"错误
- 在Controller的Update方法中添加RowsAffected检查,当影响行数为0时返回"not found"错误
- 修改Service接口定义,将ServiceDelete和ServiceUpdate方法的返回值类型从interface{}改为sql
This commit is contained in:
@@ -2,7 +2,14 @@ package admin
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
base "blazing/modules/base/service"
|
||||
"blazing/modules/player/service"
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
type GoldListController struct {
|
||||
@@ -20,3 +27,33 @@ func init() {
|
||||
// 注册路由
|
||||
cool.RegisterController(task_info_controller)
|
||||
}
|
||||
|
||||
type DuihuanGoldAddReq struct {
|
||||
g.Meta `path:"/duihuan" method:"POST"`
|
||||
Authorization string `json:"Authorization" in:"header"`
|
||||
|
||||
ID uint32 `json:"id"`
|
||||
}
|
||||
|
||||
func (c *GoldListController) DuihuanGold(ctx context.Context, req *DuihuanGoldAddReq) (res *cool.BaseRes, err error) {
|
||||
t := cool.GetAdmin(ctx)
|
||||
|
||||
r, err := service.NewGoldListService(0).Done(req.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
all := r.Rate * float64(r.ExchangeNum) * 100
|
||||
if base.NewBaseSysUserService().GetFreeGold(t.UserId) < int64(all*105) {
|
||||
err = fmt.Errorf("余额不足")
|
||||
return
|
||||
}
|
||||
if !r.UpdateTime.Add(1 * time.Hour).Before(gtime.Now()) {
|
||||
err = fmt.Errorf("未到购买时间")
|
||||
return
|
||||
}
|
||||
base.NewBaseSysUserService().UpdateGold(uint32(r.PlayerID), int64(all*95))
|
||||
base.NewBaseSysUserService().UpdateFreeGold(uint32(t.UserId), -int64(all*105))
|
||||
res = cool.Ok(nil)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user