All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
feat(player): 优化金币兑换功能 - 在ServiceUpdate方法中返回更新后的数据而不是nil - 新增DuihuanGold方法用于处理金币兑换逻辑 - 修改黄金列表控制器中的兑换计算逻辑,区分费用和获得金币的计算 - 在添加操作前验证用户金币余额是否充足 - 修正了兑换比例计算和余额检查逻辑 ```
75 lines
1.7 KiB
Go
75 lines
1.7 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 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,
|
|
}
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
}
|