307 lines
6.7 KiB
Go
307 lines
6.7 KiB
Go
package orders
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
|
|
"com.snow.auto_monitor/app/constants/errorcode"
|
|
common "com.snow.auto_monitor/app/http/controllers"
|
|
orderEnt "com.snow.auto_monitor/app/http/entities/orders"
|
|
orderMod "com.snow.auto_monitor/app/models/orders"
|
|
orderServ "com.snow.auto_monitor/app/services/orders"
|
|
transServ "com.snow.auto_monitor/app/services/transfersys"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func GetById(c *gin.Context) {
|
|
request := new(orderEnt.GetListByIdReq)
|
|
err := common.GenRequest(c, request)
|
|
if err != nil {
|
|
common.Error(c, errorcode.ParamError)
|
|
return
|
|
}
|
|
|
|
item, err := orderServ.GetById(request.Id)
|
|
if err != nil {
|
|
common.Error500(c)
|
|
return
|
|
}
|
|
|
|
var response *orderEnt.GetListByIdResp = nil
|
|
|
|
if item != nil {
|
|
response = &orderEnt.GetListByIdResp{
|
|
Id: item.Id,
|
|
OrderNo: item.OrderNo,
|
|
MerchantId: item.MerchantId,
|
|
ProductId: item.ProductId,
|
|
DeviceNo: item.DeviceNo,
|
|
OutTradeNo: item.OutTradeNo,
|
|
RechargeAccount: item.RechargeAccount,
|
|
AccountType: item.AccountType,
|
|
Number: item.Number,
|
|
NotifyUrl: item.NotifyUrl,
|
|
ExtendParameter: item.ExtendParameter,
|
|
Status: item.Status,
|
|
TransferStatus: item.TransferStatus,
|
|
FailReason: item.FailReason,
|
|
CreatedAt: item.CreatedAt.Format(time.RFC3339),
|
|
}
|
|
}
|
|
|
|
common.Success(c, response)
|
|
}
|
|
|
|
func Search(c *gin.Context) {
|
|
request := new(orderEnt.SearchReq)
|
|
err := common.GenRequest(c, request)
|
|
if err != nil {
|
|
common.Error(c, errorcode.ParamError)
|
|
return
|
|
}
|
|
start, end := "", ""
|
|
if len(request.CreatedAt) > 1 {
|
|
start = request.CreatedAt[0]
|
|
end = request.CreatedAt[1]
|
|
}
|
|
res, err := orderServ.Search(
|
|
request.Id,
|
|
request.OrderNo,
|
|
request.MerchantId,
|
|
request.ProductId,
|
|
request.DeviceNo,
|
|
request.OutTradeNo,
|
|
request.RechargeAccount,
|
|
request.AccountType,
|
|
request.Status,
|
|
request.TransferStatus,
|
|
start,
|
|
end,
|
|
request.PageSize,
|
|
request.PageNum,
|
|
)
|
|
if err != nil {
|
|
common.Error500(c)
|
|
return
|
|
}
|
|
|
|
var response []*orderEnt.SearchResp = nil
|
|
|
|
if len(res) > 0 {
|
|
for _, item := range res {
|
|
response = append(response, &orderEnt.SearchResp{
|
|
Id: item.Id,
|
|
OrderNo: item.OrderNo,
|
|
MerchantId: item.MerchantId,
|
|
ProductId: item.ProductId,
|
|
DeviceNo: item.DeviceNo,
|
|
OutTradeNo: item.OutTradeNo,
|
|
RechargeAccount: item.RechargeAccount,
|
|
AccountType: item.AccountType,
|
|
Number: item.Number,
|
|
NotifyUrl: item.NotifyUrl,
|
|
ExtendParameter: item.ExtendParameter,
|
|
Status: item.Status,
|
|
TransferStatus: item.TransferStatus,
|
|
FailReason: item.FailReason,
|
|
CreatedAt: item.CreatedAt.Format(time.RFC3339),
|
|
})
|
|
}
|
|
}
|
|
|
|
total, err := orderServ.CountAll(
|
|
request.Id,
|
|
request.OrderNo,
|
|
request.MerchantId,
|
|
request.ProductId,
|
|
request.DeviceNo,
|
|
request.OutTradeNo,
|
|
request.RechargeAccount,
|
|
request.AccountType,
|
|
request.Status,
|
|
request.TransferStatus,
|
|
start,
|
|
end,
|
|
)
|
|
if err != nil {
|
|
common.Error500(c)
|
|
return
|
|
}
|
|
|
|
common.SuccessWithList(c, response, total)
|
|
}
|
|
|
|
func Create(c *gin.Context) {
|
|
request := new(orderEnt.CreateReq)
|
|
err := common.GenRequest(c, request)
|
|
if err != nil {
|
|
common.Error(c, errorcode.ParamError)
|
|
return
|
|
}
|
|
|
|
orders := &orderMod.Orders{
|
|
OrderNo: "12321",
|
|
MerchantId: request.MerchantId,
|
|
ProductId: request.ProductId,
|
|
OutTradeNo: request.OutTradeNo,
|
|
RechargeAccount: request.RechargeAccount,
|
|
AccountType: request.AccountType,
|
|
Number: request.Number,
|
|
NotifyUrl: request.NotifyUrl,
|
|
ExtendParameter: request.ExtendParameter,
|
|
Status: request.Status,
|
|
TransferStatus: request.TransferStatus,
|
|
FailReason: request.FailReason,
|
|
}
|
|
|
|
affected, err := orderServ.Create(orders)
|
|
if err != nil && affected > 0 {
|
|
common.Error500(c)
|
|
return
|
|
}
|
|
|
|
response := &orderEnt.CreateResp{
|
|
Id: orders.Id,
|
|
}
|
|
|
|
common.Success(c, response)
|
|
}
|
|
|
|
func Update(c *gin.Context) {
|
|
request := new(orderEnt.UpdateReq)
|
|
err := common.GenRequest(c, request)
|
|
if err != nil {
|
|
common.Error(c, errorcode.ParamError)
|
|
return
|
|
}
|
|
|
|
orders := &orderMod.Orders{
|
|
Id: request.Id,
|
|
MerchantId: request.MerchantId,
|
|
ProductId: request.ProductId,
|
|
OutTradeNo: request.OutTradeNo,
|
|
RechargeAccount: request.RechargeAccount,
|
|
AccountType: request.AccountType,
|
|
Number: request.Number,
|
|
NotifyUrl: request.NotifyUrl,
|
|
ExtendParameter: request.ExtendParameter,
|
|
Status: request.Status,
|
|
TransferStatus: request.TransferStatus,
|
|
FailReason: request.FailReason,
|
|
}
|
|
|
|
affected, err := orderServ.Update(orders)
|
|
if err != nil && affected > 0 {
|
|
common.Error500(c)
|
|
return
|
|
}
|
|
|
|
response := &orderEnt.UpdateResp{
|
|
Id: orders.Id,
|
|
}
|
|
|
|
common.Success(c, response)
|
|
}
|
|
|
|
func Cancel(c *gin.Context) {
|
|
request := new(orderEnt.CancelReq)
|
|
err := common.GenRequest(c, request)
|
|
if err != nil {
|
|
common.Error(c, errorcode.ParamError)
|
|
return
|
|
}
|
|
|
|
affected, err := orderServ.Cancel(request.Id)
|
|
if err != nil || affected == 0 {
|
|
common.Error(c, 400, err.Error())
|
|
return
|
|
}
|
|
|
|
err = transServ.AddCallback(strconv.Itoa(int(request.Id)))
|
|
if err != nil {
|
|
common.Error(c, 400, "添加回调失败")
|
|
return
|
|
}
|
|
|
|
response := &orderEnt.CancelResp{
|
|
Id: request.Id,
|
|
}
|
|
|
|
common.Success(c, response)
|
|
}
|
|
|
|
func DangerousConfirm(c *gin.Context) {
|
|
request := new(orderEnt.CancelReq)
|
|
err := common.GenRequest(c, request)
|
|
if err != nil {
|
|
common.Error(c, errorcode.ParamError)
|
|
return
|
|
}
|
|
|
|
affected, err := orderServ.DangerousConfirm(request.Id)
|
|
if err != nil || affected == 0 {
|
|
common.Error(c, 400, err.Error())
|
|
return
|
|
}
|
|
|
|
err = transServ.AddCallback(strconv.Itoa(int(request.Id)))
|
|
if err != nil {
|
|
common.Error(c, 400, "添加回调失败")
|
|
return
|
|
}
|
|
|
|
response := &orderEnt.CancelResp{
|
|
Id: request.Id,
|
|
}
|
|
|
|
common.Success(c, response)
|
|
}
|
|
|
|
func DangerousCancel(c *gin.Context) {
|
|
request := new(orderEnt.CancelReq)
|
|
err := common.GenRequest(c, request)
|
|
if err != nil {
|
|
common.Error(c, errorcode.ParamError)
|
|
return
|
|
}
|
|
|
|
affected, err := orderServ.DangerousCancel(request.Id)
|
|
if err != nil || affected == 0 {
|
|
common.Error(c, 400, err.Error())
|
|
return
|
|
}
|
|
|
|
err = transServ.AddCallback(strconv.Itoa(int(request.Id)))
|
|
if err != nil {
|
|
common.Error(c, 400, "添加回调失败")
|
|
return
|
|
}
|
|
|
|
response := &orderEnt.CancelResp{
|
|
Id: request.Id,
|
|
}
|
|
|
|
common.Success(c, response)
|
|
}
|
|
|
|
func Delete(c *gin.Context) {
|
|
request := new(orderEnt.DeleteReq)
|
|
err := common.GenRequest(c, request)
|
|
if err != nil {
|
|
common.Error(c, errorcode.ParamError)
|
|
return
|
|
}
|
|
|
|
affected, err := orderServ.Delete(request.Id)
|
|
if err != nil && affected > 0 {
|
|
common.Error500(c)
|
|
return
|
|
}
|
|
|
|
response := &orderEnt.DeleteResp{
|
|
Id: request.Id,
|
|
}
|
|
|
|
common.Success(c, response)
|
|
}
|