82 lines
1.8 KiB
Go
82 lines
1.8 KiB
Go
package orders
|
|
|
|
import (
|
|
"time"
|
|
|
|
common "com.snow.auto_monitor/app/http/controllers"
|
|
transEnt "com.snow.auto_monitor/app/http/entities/transfersys"
|
|
orderMod "com.snow.auto_monitor/app/models/orders"
|
|
ransServ "com.snow.auto_monitor/app/services/transfersys"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func GetOrder(c *gin.Context) {
|
|
item, err := ransServ.ReadGroup()
|
|
if err != nil {
|
|
common.Error(c, 400, err.Error())
|
|
return
|
|
}
|
|
|
|
var response *transEnt.GetOrderResp = nil
|
|
|
|
if item != nil {
|
|
response = &transEnt.GetOrderResp{
|
|
Id: item.Id,
|
|
OrderNo: item.OrderNo,
|
|
MerchantId: item.MerchantId,
|
|
ProductId: item.ProductId,
|
|
OutTradeNo: item.OutTradeNo,
|
|
RechargeAccount: item.RechargeAccount,
|
|
AccountType: item.AccountType,
|
|
Number: item.Number,
|
|
NotifyUrl: item.NotifyUrl,
|
|
ExtendParameter: item.ExtendParameter,
|
|
Status: item.Status,
|
|
TransferStatus: item.TransferStatus,
|
|
CreatedAt: item.CreatedAt.Format(time.RFC3339),
|
|
}
|
|
} else {
|
|
c.JSON(500, gin.H{
|
|
"code": 500,
|
|
"message": "no data",
|
|
})
|
|
return
|
|
}
|
|
common.Success(c, response)
|
|
}
|
|
|
|
func FinishOrder(c *gin.Context) {
|
|
request := new(transEnt.FinishOrderReq)
|
|
err := common.GenRequest(c, request)
|
|
if err != nil {
|
|
common.Error(c, 400, err.Error())
|
|
return
|
|
}
|
|
|
|
status := 5
|
|
if request.Result == "success" {
|
|
status = 1
|
|
} else if request.Result == "fail" {
|
|
status = 4
|
|
}
|
|
|
|
orders := &orderMod.Orders{
|
|
Id: request.Id,
|
|
ProductId: request.ProductId,
|
|
MerchantId: request.MerchantId,
|
|
TransferStatus: int64(status),
|
|
}
|
|
|
|
affected, err := ransServ.FinishOrder(orders)
|
|
if err != nil || affected == 0 {
|
|
common.Error(c, 400, "无法修改已完成订单")
|
|
return
|
|
}
|
|
|
|
response := &transEnt.FinishOrderResp{
|
|
Id: orders.Id,
|
|
}
|
|
|
|
common.Success(c, response)
|
|
}
|