feat(app): update
This commit is contained in:
131
pkg/dto/request/DispatchOrderRequest.go
Normal file
131
pkg/dto/request/DispatchOrderRequest.go
Normal file
@ -0,0 +1,131 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"gitea.ddegame.cn/open/servicebase/pkg/common/HyTools"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// 派单请求
|
||||
type DispatchOrderRequest struct {
|
||||
BaseRequest
|
||||
GuildId string // 公会ID
|
||||
ChatroomId string // 聊天室ID
|
||||
SkillId string // 技能ID
|
||||
SkillMode string // 玩法
|
||||
SkillLevel string // 等级
|
||||
SkillService string // 单子类型
|
||||
Gender string // 性别
|
||||
Hours string // 时长
|
||||
ConfigId string // 配置ID
|
||||
CustomerRequirement string // 用户需求
|
||||
}
|
||||
|
||||
// 判断decimal是否是0.5的倍数
|
||||
func isHalfMultiple(d decimal.Decimal) bool {
|
||||
// 乘以2后检查是否为整数
|
||||
multiplied := d.Mul(decimal.NewFromInt(2))
|
||||
// 将整数部分转换为decimal类型后再比较
|
||||
intPart := decimal.NewFromInt(multiplied.IntPart())
|
||||
return multiplied.Equal(intPart)
|
||||
}
|
||||
|
||||
// 签名验证
|
||||
func (request *DispatchOrderRequest) CheckParameter() (err error) {
|
||||
if len(request.AccessToken) == 0 {
|
||||
err = errors.New("AccessToken不能为空")
|
||||
return
|
||||
}
|
||||
if len(request.SkillId) == 0 {
|
||||
err = errors.New("SkillId不能为空")
|
||||
return
|
||||
}
|
||||
if len(request.ChatroomId) == 0 {
|
||||
err = errors.New("ChatroomId不能为空")
|
||||
return
|
||||
}
|
||||
if HyTools.StringToInt(request.Hours) <= 0 || HyTools.StringToInt(request.Hours) > 999 {
|
||||
err = errors.New("时长不合法")
|
||||
return
|
||||
}
|
||||
//var hours decimal.Decimal
|
||||
//hours, err = decimal.NewFromString(request.Hours)
|
||||
//if err != nil {
|
||||
// err = errors.New("时长不正确")
|
||||
// return
|
||||
//}
|
||||
//if !isHalfMultiple(hours) {
|
||||
// err = errors.New("时长必须为0.5的倍数")
|
||||
// return
|
||||
//}
|
||||
return
|
||||
}
|
||||
|
||||
// 派单请求
|
||||
type DispatchOrderCommonRequest struct {
|
||||
BaseRequest
|
||||
GuildId string // 公会ID
|
||||
ChatroomId string // 房间ID(客服下单)
|
||||
HostUserId string // 派单用户ID(客服下单)
|
||||
BuyerId string // 买家ID(用户自己下单)
|
||||
SkillId string // 技能ID
|
||||
Hours string // 时长
|
||||
Comment string // 备注
|
||||
NeedsAudition string // 是否试音 T=是 F=否
|
||||
OrderList string
|
||||
Orders []DispatchOrderCommonItemRequest
|
||||
CompanionType string // 陪玩类型 single double
|
||||
}
|
||||
|
||||
type DispatchOrderCommonItemRequest struct {
|
||||
ConfigId string // 价格配置ID
|
||||
Mode string //
|
||||
Level string //
|
||||
Service string //
|
||||
Gender string //
|
||||
Price string //
|
||||
}
|
||||
|
||||
// 签名验证
|
||||
func (request *DispatchOrderCommonRequest) CheckParameter() (err error) {
|
||||
if len(request.AccessToken) == 0 {
|
||||
err = errors.New("AccessToken不能为空")
|
||||
return
|
||||
}
|
||||
if len(request.SkillId) == 0 {
|
||||
err = errors.New("SkillId不能为空")
|
||||
return
|
||||
}
|
||||
if e := json.Unmarshal([]byte(request.OrderList), &request.Orders); e != nil {
|
||||
err = errors.New("数据格式错误")
|
||||
return
|
||||
}
|
||||
if len(request.Orders) == 0 {
|
||||
err = errors.New("至少要选择一个陪玩")
|
||||
return
|
||||
}
|
||||
if HyTools.StringToInt(request.Hours) <= 0 || HyTools.StringToInt(request.Hours) > 999 {
|
||||
err = errors.New("时长不合法")
|
||||
return
|
||||
}
|
||||
//var hours decimal.Decimal
|
||||
//hours, err = decimal.NewFromString(request.Hours)
|
||||
//if err != nil {
|
||||
// err = errors.New("时长不正确")
|
||||
// return
|
||||
//}
|
||||
//if !isHalfMultiple(hours) {
|
||||
// err = errors.New("时长必须为0.5的倍数")
|
||||
// return
|
||||
//}
|
||||
for _, item := range request.Orders {
|
||||
if len(item.Gender) > 0 && (HyTools.StringToInt(item.Price) <= 0 || HyTools.StringToInt(item.Price) > 99999) {
|
||||
err = errors.New("价格不合法")
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user