- 实现账号增删改查接口和逻辑 - 支持账号状态更新及状态历史记录功能 - 提供账号列表、历史和统计信息查询API - 实现账号轮询机制,支持按使用时间轮询获取账号 - 增加账号登录流程及批量登录功能,集成接码平台和平台API - 管理账号订单容量,支持容量检查与账号登录触发 - 提供账号池状态统计接口 - 账号历史记录查询支持多种变更类型文本展示 - 密码等敏感信息采用脱敏展示 - 完善日志记录和错误处理机制,保证业务稳定运行
224 lines
6.3 KiB
Go
224 lines
6.3 KiB
Go
package camel_oil
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
|
|
v1 "kami/api/camel_oil/v1"
|
|
"kami/internal/consts"
|
|
"kami/internal/dao"
|
|
"kami/internal/model/entity"
|
|
"kami/utility/config"
|
|
)
|
|
|
|
// ====================================================================================
|
|
// 订单查询相关方法
|
|
// ====================================================================================
|
|
|
|
// ListOrder 查询订单列表
|
|
func (s *sCamelOil) ListOrder(ctx context.Context, req *v1.ListOrderReq) (res *v1.ListOrderRes, err error) {
|
|
m := dao.V1CamelOilOrder.Ctx(ctx).DB(config.GetDatabaseV1())
|
|
|
|
// 构建查询条件
|
|
if req.MerchantOrderId != "" {
|
|
m = m.Where(dao.V1CamelOilOrder.Columns().MerchantOrderId, req.MerchantOrderId)
|
|
}
|
|
if req.OrderNo != "" {
|
|
m = m.Where(dao.V1CamelOilOrder.Columns().OrderNo, req.OrderNo)
|
|
}
|
|
if req.AccountId != 0 {
|
|
m = m.Where(dao.V1CamelOilOrder.Columns().AccountId, req.AccountId)
|
|
}
|
|
if req.Status > 0 {
|
|
m = m.Where(dao.V1CamelOilOrder.Columns().Status, int(req.Status))
|
|
}
|
|
if req.PayStatus > 0 {
|
|
m = m.Where(dao.V1CamelOilOrder.Columns().PayStatus, int(req.PayStatus))
|
|
}
|
|
if len(req.DateRange) == 2 && req.DateRange[0] != nil && req.DateRange[1] != nil {
|
|
m = m.WhereBetween(dao.V1CamelOilOrder.Columns().CreatedAt, req.DateRange[0], req.DateRange[1])
|
|
}
|
|
|
|
// 查询总数
|
|
total, err := m.Count()
|
|
if err != nil {
|
|
return nil, gerror.Wrap(err, "查询订单总数失败")
|
|
}
|
|
|
|
// 分页查询
|
|
var orders []*entity.V1CamelOilOrder
|
|
err = m.Page(req.Current, req.PageSize).
|
|
OrderDesc(dao.V1CamelOilOrder.Columns().CreatedAt).
|
|
Scan(&orders)
|
|
if err != nil {
|
|
return nil, gerror.Wrap(err, "查询订单列表失败")
|
|
}
|
|
|
|
// 构造返回结果
|
|
items := make([]v1.OrderListItem, 0, len(orders))
|
|
for _, order := range orders {
|
|
items = append(items, v1.OrderListItem{
|
|
OrderNo: order.OrderNo,
|
|
MerchantOrderId: order.MerchantOrderId,
|
|
AccountId: order.AccountId,
|
|
AccountName: order.AccountName,
|
|
Amount: order.Amount.InexactFloat64(),
|
|
AlipayUrl: order.AlipayUrl,
|
|
Status: consts.CamelOilOrderStatus(order.Status),
|
|
StatusText: getOrderStatusText(order.Status),
|
|
PayStatus: consts.CamelOilPayStatus(order.PayStatus),
|
|
PayStatusText: getPayStatusText(order.PayStatus),
|
|
NotifyStatus: consts.CamelOilNotifyStatus(order.NotifyStatus),
|
|
NotifyStatusText: getNotifyStatusText(order.NotifyStatus),
|
|
NotifyCount: order.NotifyCount,
|
|
PaidAt: order.PaidAt,
|
|
LastCheckAt: order.LastCheckAt,
|
|
FailureReason: order.FailureReason,
|
|
CreatedAt: order.CreatedAt,
|
|
UpdatedAt: order.UpdatedAt,
|
|
})
|
|
}
|
|
|
|
res = &v1.ListOrderRes{}
|
|
res.Total = total
|
|
res.List = items
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// OrderDetail 查询订单详情
|
|
func (s *sCamelOil) OrderDetail(ctx context.Context, req *v1.OrderDetailReq) (res *v1.OrderDetailRes, err error) {
|
|
// 查询订单信息
|
|
var order *entity.V1CamelOilOrder
|
|
err = dao.V1CamelOilOrder.Ctx(ctx).DB(config.GetDatabaseV1()).
|
|
Where(dao.V1CamelOilOrder.Columns().OrderNo, req.OrderNo).
|
|
Scan(&order)
|
|
if err != nil {
|
|
return nil, gerror.Wrap(err, "查询订单失败")
|
|
}
|
|
if order == nil {
|
|
return nil, gerror.New("订单不存在")
|
|
}
|
|
|
|
// 查询账号信息
|
|
var account *entity.V1CamelOilAccount
|
|
if order.AccountId > 0 {
|
|
err = dao.V1CamelOilAccount.Ctx(ctx).DB(config.GetDatabaseV1()).
|
|
Where(dao.V1CamelOilAccount.Columns().Id, order.AccountId).
|
|
Scan(&account)
|
|
if err != nil {
|
|
return nil, gerror.Wrap(err, "查询账号失败")
|
|
}
|
|
}
|
|
|
|
res = &v1.OrderDetailRes{}
|
|
|
|
// 填充订单信息
|
|
res.OrderInfo.OrderNo = order.OrderNo
|
|
res.OrderInfo.MerchantOrderId = order.MerchantOrderId
|
|
res.OrderInfo.AccountId = order.AccountId
|
|
res.OrderInfo.AccountName = order.AccountName
|
|
res.OrderInfo.Amount = order.Amount.InexactFloat64()
|
|
res.OrderInfo.AlipayUrl = order.AlipayUrl
|
|
res.OrderInfo.Status = consts.CamelOilOrderStatus(order.Status)
|
|
res.OrderInfo.StatusText = getOrderStatusText(order.Status)
|
|
res.OrderInfo.PayStatus = consts.CamelOilPayStatus(order.PayStatus)
|
|
res.OrderInfo.PayStatusText = getPayStatusText(order.PayStatus)
|
|
res.OrderInfo.NotifyStatus = consts.CamelOilNotifyStatus(order.NotifyStatus)
|
|
res.OrderInfo.NotifyStatusText = getNotifyStatusText(order.NotifyStatus)
|
|
res.OrderInfo.NotifyCount = order.NotifyCount
|
|
res.OrderInfo.PaidAt = order.PaidAt
|
|
res.OrderInfo.LastCheckAt = order.LastCheckAt
|
|
res.OrderInfo.Attach = order.Attach
|
|
res.OrderInfo.FailureReason = order.FailureReason
|
|
res.OrderInfo.CreatedAt = order.CreatedAt
|
|
res.OrderInfo.UpdatedAt = order.UpdatedAt
|
|
|
|
// 填充账号信息
|
|
if account != nil {
|
|
res.AccountInfo.AccountId = account.Id
|
|
res.AccountInfo.AccountName = account.AccountName
|
|
res.AccountInfo.Phone = maskPhone(account.Phone)
|
|
res.AccountInfo.Status = consts.CamelOilAccountStatus(account.Status)
|
|
res.AccountInfo.StatusText = getAccountStatusText(account.Status)
|
|
res.AccountInfo.LastUsedAt = account.LastUsedAt
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// ====================================================================================
|
|
// 辅助函数
|
|
// ====================================================================================
|
|
|
|
// getOrderStatusText 获取订单状态文本
|
|
func getOrderStatusText(status int) string {
|
|
switch status {
|
|
case 1:
|
|
return "待支付"
|
|
case 2:
|
|
return "已支付"
|
|
case 3:
|
|
return "支付超时"
|
|
case 4:
|
|
return "下单失败"
|
|
default:
|
|
return "未知"
|
|
}
|
|
}
|
|
|
|
// getPayStatusText 获取支付状态文本
|
|
func getPayStatusText(payStatus int) string {
|
|
switch payStatus {
|
|
case 0:
|
|
return "未支付"
|
|
case 1:
|
|
return "已支付"
|
|
case 2:
|
|
return "超时"
|
|
default:
|
|
return "未知"
|
|
}
|
|
}
|
|
|
|
// getNotifyStatusText 获取回调状态文本
|
|
func getNotifyStatusText(notifyStatus int) string {
|
|
switch notifyStatus {
|
|
case 0:
|
|
return "未回调"
|
|
case 1:
|
|
return "已回调"
|
|
case 2:
|
|
return "回调失败"
|
|
default:
|
|
return "未知"
|
|
}
|
|
}
|
|
|
|
// getAccountStatusText 获取账号状态文本
|
|
func getAccountStatusText(status int) string {
|
|
switch status {
|
|
case 1:
|
|
return "待登录"
|
|
case 2:
|
|
return "在线"
|
|
case 3:
|
|
return "暂停"
|
|
case 4:
|
|
return "已失效"
|
|
case 5:
|
|
return "登录失败"
|
|
default:
|
|
return "未知"
|
|
}
|
|
}
|
|
|
|
// maskPhone 手机号脱敏
|
|
func maskPhone(phone string) string {
|
|
if len(phone) < 11 {
|
|
return phone
|
|
}
|
|
return phone[:3] + "****" + phone[7:]
|
|
}
|