feat(cool): 添加删除和更新操作的数据影响行数检查
- 在Controller的Delete方法中添加RowsAffected检查,当影响行数为0时返回"not found"错误
- 在Controller的Update方法中添加RowsAffected检查,当影响行数为0时返回"not found"错误
- 修改Service接口定义,将ServiceDelete和ServiceUpdate方法的返回值类型从interface{}改为sql
This commit is contained in:
@@ -16,10 +16,11 @@ type GoldListService struct {
|
||||
func (s *GoldListService) ModifyBefore(ctx context.Context, method string, param map[string]interface{}) (err error) {
|
||||
admin := cool.GetAdmin(ctx)
|
||||
userId := admin.UserId
|
||||
s.userid = uint32(userId)
|
||||
param["player_id"] = userId
|
||||
|
||||
g.RequestFromCtx(ctx).SetParam("player_id", userId)
|
||||
if method == "Add" {
|
||||
t, _ := s.dbm_fix(s.Model).Count()
|
||||
|
||||
t, _ := s.dbm_fix(s.Model).Where("player_id", userId).Where("status", 0).Count()
|
||||
if t > 0 {
|
||||
return fmt.Errorf("不允许多挂单")
|
||||
}
|
||||
@@ -27,6 +28,19 @@ func (s *GoldListService) ModifyBefore(ctx context.Context, method string, param
|
||||
|
||||
return
|
||||
}
|
||||
func (s *GoldListService) Done(listid uint32) (*model.GoldBeanOrder, error) {
|
||||
var rr model.GoldBeanOrder
|
||||
s.dbm_fix(s.Model).Where("id", listid).Scan(&rr)
|
||||
r, err := s.dbm_fix(s.Model).Data("status", 1).Where("status", 0).Where("id", listid).Update()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
is, _ := r.RowsAffected()
|
||||
if is == 0 {
|
||||
return nil, fmt.Errorf("重复订单")
|
||||
}
|
||||
return &rr, nil
|
||||
}
|
||||
|
||||
func NewGoldListService(id uint32) *GoldListService {
|
||||
return &GoldListService{
|
||||
@@ -34,6 +48,12 @@ func NewGoldListService(id uint32) *GoldListService {
|
||||
BaseService: BaseService{userid: id,
|
||||
|
||||
Service: &cool.Service{Model: model.NewGoldBeanOrder(),
|
||||
Where: func(ctx context.Context) []g.Array {
|
||||
admin := cool.GetAdmin(ctx)
|
||||
return [][]interface{}{
|
||||
{"player_id", admin.UserId, true},
|
||||
}
|
||||
},
|
||||
ListQueryOp: &cool.QueryOp{
|
||||
AddOrderby: g.MapStrStr{"updateTime": "asc"},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user