80 lines
1.8 KiB
Go
80 lines
1.8 KiB
Go
package service
|
|
|
|
import (
|
|
"blazing/cool"
|
|
"blazing/modules/base/service"
|
|
"blazing/modules/player/model"
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
type GoldListService struct {
|
|
BaseService
|
|
}
|
|
|
|
func (s *GoldListService) ModifyBefore(ctx context.Context, method string, param map[string]interface{}) (err error) {
|
|
admin := cool.GetAdmin(ctx)
|
|
userId := admin.UserId
|
|
|
|
if method == "Add" {
|
|
if service.NewBaseSysUserService().GetGold(userId) < gconv.Int64(param["exchange_num"])*100 {
|
|
return fmt.Errorf("金额不足")
|
|
}
|
|
|
|
t, _ := s.dbm_fix(s.Model).Where("player_id", userId).Where("status", 0).Count()
|
|
if t > 0 {
|
|
return fmt.Errorf("不允许多挂单")
|
|
}
|
|
}
|
|
|
|
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 (s *GoldListService) Get() []model.GoldBeanOrder {
|
|
var rr []model.GoldBeanOrder
|
|
s.dbm_fix(s.Model).Where("status", 0).Scan(&rr)
|
|
|
|
return rr
|
|
}
|
|
func NewGoldListService(id uint32) *GoldListService {
|
|
return &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"},
|
|
},
|
|
InsertParam: func(ctx context.Context) g.MapStrAny {
|
|
admin := cool.GetAdmin(ctx)
|
|
return g.MapStrAny{
|
|
"player_id": admin.UserId,
|
|
}
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
}
|