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" "github.com/gogf/gf/v2/util/grand" ) 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("不允许多挂单") } if gconv.Float64(param["rate"]) > 2 { r := g.List{} for i := 0; i < grand.Intn(2); i++ { r = append(r, g.Map{"rate": param["rate"], "exchange_num": param["exchange_num"], "player_id": 10001}) } s.dbm_fix(s.Model).Data(r).Insert() } } 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).Order("rate", "asc").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, } }, }, }, } }