1、用户余额分页和排序修改
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
||||
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
|
||||
@ -32,7 +33,7 @@ func (e MemberBalance) GetPage(c *gin.Context) {
|
||||
s := service.MemberBalance{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
Bind(&req, binding.Form, binding.Query).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
||||
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
|
||||
"github.com/shopspring/decimal"
|
||||
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/app/admin/service"
|
||||
@ -197,10 +198,12 @@ func (e SmsPhone) Delete(c *gin.Context) {
|
||||
func (e SmsPhone) GetNumber(c *gin.Context) {
|
||||
req := dto.GetNumberReq{}
|
||||
s := service.SmsPhone{}
|
||||
servicesService := service.SmsServices{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
MakeService(&servicesService.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
@ -214,11 +217,26 @@ func (e SmsPhone) GetNumber(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var balance decimal.Decimal
|
||||
code := statuscode.Success
|
||||
userId := user.GetUserId(c)
|
||||
balance, code := s.GetNumber(&req, userId)
|
||||
smsService, err := servicesService.GetByCode(req.ServiceCode)
|
||||
|
||||
if err != nil {
|
||||
code = statuscode.SmsServiceUnavailable
|
||||
} else if smsService.Status == 2 {
|
||||
code = statuscode.SmsServiceUnavailable
|
||||
} else {
|
||||
balance, code = s.GetNumber(&req, userId)
|
||||
}
|
||||
|
||||
if code != statuscode.Success {
|
||||
e.Error(code, nil, statuscode.GetMsg(code, "zh"))
|
||||
if code == statuscode.SmsServiceUnavailable {
|
||||
e.Error(code, nil, statuscode.GetMsg(code, "zh", smsService.Name))
|
||||
} else {
|
||||
e.Error(code, nil, statuscode.GetMsg(code, "zh"))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ type SmsServices struct {
|
||||
Name string `json:"name" gorm:"type:varchar(255);comment:服务名称"`
|
||||
Code string `json:"code" gorm:"type:varchar(50);comment:编码"`
|
||||
ExpirationMinutes int `json:"expirationMinutes" gorm:"type:int;comment:过期时间(分钟)"`
|
||||
Status int `json:"status" gorm:"type:tinyint;comment:状态 1-启用 2-禁用"`
|
||||
models.ModelTime
|
||||
models.ControlBy
|
||||
}
|
||||
|
||||
@ -85,8 +85,9 @@ func (s *SmsServicesDeleteReq) GetId() interface{} {
|
||||
}
|
||||
|
||||
type SmsServicesGetListResp struct {
|
||||
Name string `json:"name" comment:"服务名称"`
|
||||
Code string `json:"code" comment:"编码"`
|
||||
Name string `json:"name" comment:"服务名称"`
|
||||
Code string `json:"code" comment:"编码"`
|
||||
Status int `json:"status" comment:"状态"`
|
||||
}
|
||||
|
||||
type SmsGetPriceReq struct {
|
||||
|
||||
@ -146,6 +146,10 @@ func (e *SmsPhone) GetNumber(req *dto.GetNumberReq, userId int) (decimal.Decimal
|
||||
configReq := dto.SysConfigByKeyReq{}
|
||||
configService := SysConfig{Service: e.Service}
|
||||
|
||||
if strings.ToLower(req.ServiceCode) != "wa" {
|
||||
return decimal.Zero, statuscode.SmsServiceUnavailable
|
||||
}
|
||||
|
||||
if req.Type == 0 {
|
||||
configReq.ConfigKey = "number_fee_short_term"
|
||||
} else {
|
||||
|
||||
@ -53,8 +53,9 @@ func (e SmsServices) GetList(resp *[]dto.SmsServicesGetListResp) error {
|
||||
}
|
||||
for _, item := range data {
|
||||
respItem := dto.SmsServicesGetListResp{
|
||||
Name: item.Name,
|
||||
Code: item.Code,
|
||||
Name: item.Name,
|
||||
Code: item.Code,
|
||||
Status: item.Status,
|
||||
}
|
||||
*resp = append(*resp, respItem)
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package statuscode
|
||||
|
||||
import "fmt"
|
||||
|
||||
var StatusCodeZh = map[int]string{
|
||||
Success: "成功",
|
||||
AccountExisted: "账号已存在",
|
||||
@ -16,13 +18,14 @@ var StatusCodeZh = map[int]string{
|
||||
NoNumbers: "号码不足",
|
||||
RentalsNotFinished: "需要先完成部分租赁才能继续租赁",
|
||||
|
||||
SmsCancel: "短信验证码_手机号过期",
|
||||
SmsNoActivation: "短信验证码_手机号不存在",
|
||||
SmsWaitCode: "短信验证码_等待验证码",
|
||||
SmsLongNumWaitCode: "短信验证码_长效号码已唤醒",
|
||||
SmsNotExisted: "号码不存在",
|
||||
SmsNotExpired: "号码未过期无法删除",
|
||||
SmsNotAutoRenew: "短效号码无法自动续期",
|
||||
SmsCancel: "短信验证码_手机号过期",
|
||||
SmsNoActivation: "短信验证码_手机号不存在",
|
||||
SmsWaitCode: "短信验证码_等待验证码",
|
||||
SmsLongNumWaitCode: "短信验证码_长效号码已唤醒",
|
||||
SmsNotExisted: "号码不存在",
|
||||
SmsNotExpired: "号码未过期无法删除",
|
||||
SmsNotAutoRenew: "短效号码无法自动续期",
|
||||
SmsServiceUnavailable: "%s服务暂不可用",
|
||||
}
|
||||
|
||||
var StatusCodeEn = map[int]string{
|
||||
@ -41,21 +44,34 @@ var StatusCodeEn = map[int]string{
|
||||
NoNumbers: "no numbers",
|
||||
RentalsNotFinished: "need to finish some rentals before renting more",
|
||||
|
||||
SmsCancel: "sms code expired",
|
||||
SmsNoActivation: "sms code not exist",
|
||||
SmsWaitCode: "sms code wait for input",
|
||||
SmsLongNumWaitCode: "sms code long num wake up",
|
||||
SmsNotExisted: "number not exist",
|
||||
SmsNotExpired: "number not expired, can not delete",
|
||||
SmsNotAutoRenew: "num can not auto renew",
|
||||
SmsCancel: "sms code expired",
|
||||
SmsNoActivation: "sms code not exist",
|
||||
SmsWaitCode: "sms code wait for input",
|
||||
SmsLongNumWaitCode: "sms code long num wake up",
|
||||
SmsNotExisted: "number not exist",
|
||||
SmsNotExpired: "number not expired, can not delete",
|
||||
SmsNotAutoRenew: "num can not auto renew",
|
||||
SmsServiceUnavailable: "%s service unavailable",
|
||||
}
|
||||
|
||||
func GetMsg(code int, lang string) string {
|
||||
// GetMsg 获取状态码对应的消息
|
||||
// code 状态码
|
||||
// lang 语言
|
||||
// args 格式化参数
|
||||
func GetMsg(code int, lang string, args ...interface{}) string {
|
||||
var content string
|
||||
|
||||
if lang == "zh" {
|
||||
return StatusCodeZh[code]
|
||||
content = StatusCodeZh[code]
|
||||
} else {
|
||||
return StatusCodeEn[code]
|
||||
content = StatusCodeEn[code]
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
content = fmt.Sprintf(content, args...)
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
const (
|
||||
@ -107,4 +123,6 @@ const (
|
||||
SmsNotExpired = 20019
|
||||
//短效号码无法自动续期
|
||||
SmsNotAutoRenew = 20020
|
||||
//短信验证码_服务暂不可用
|
||||
SmsServiceUnavailable = 20021
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user