You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
3.9 KiB
124 lines
3.9 KiB
|
2 weeks ago
|
package service
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"errors"
|
||
|
|
"log"
|
||
|
|
"strconv"
|
||
|
|
"tyj_admin/api/v1/game"
|
||
|
|
"tyj_admin/internal/harmonyos"
|
||
|
|
)
|
||
|
|
|
||
|
|
func HarmonyOrderLookup(req *game.GetHarmonyOrderReq) (res *game.GetHarmonyOrderRes, err error) {
|
||
|
|
res = new(game.GetHarmonyOrderRes)
|
||
|
|
bodyMap := make(map[string]interface{})
|
||
|
|
bodyMap["orderNo"] = req.Order
|
||
|
|
orderService := &harmonyos.OrderLookup{}
|
||
|
|
orderInfoStr, err := orderService.OrderQuery(bodyMap)
|
||
|
|
if err != nil {
|
||
|
|
log.Printf("HarmonyOrderLookup======>.OrderStatusQuery : %v - err:%s", req.Order, err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
orderInfo := &game.HarmonyLookup{}
|
||
|
|
if err = json.Unmarshal([]byte(orderInfoStr), &orderInfo); err != nil {
|
||
|
|
log.Printf("HarmonyOrderLookup======>.Unmarshal : %v", orderInfoStr)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
res.OrderStatus = orderInfo.OrderStatus
|
||
|
|
if orderInfo.OrderStatus != 1 {
|
||
|
|
err = errors.New("交易号无效")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
jwsChecker := &harmonyos.JWSChecker{}
|
||
|
|
purchaseOrderStr, err := jwsChecker.CheckAndDecodeJWS(orderInfo.JwsPurchaseOrder)
|
||
|
|
if err != nil {
|
||
|
|
log.Printf("HarmonyOrderLookup======>.jwsChecker.CheckAndDecodeJWS : err: %s, %s", err.Error(), purchaseOrderStr)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
purchaseOrder := game.PurchaseOrderPayload{}
|
||
|
|
if err = json.Unmarshal([]byte(purchaseOrderStr), &purchaseOrder); err != nil {
|
||
|
|
log.Printf("HarmonyOrderLookup======>.CheckAndDecodeJWS Unmarshal: %v, Err: %s", purchaseOrderStr, err)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
res.PurchaseOrderInfo = purchaseOrder
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
func HarmonyOrders(req *game.GetHarmonyOrdersReq) (res *game.GetHarmonyOrdersRes, err error) {
|
||
|
|
res = new(game.GetHarmonyOrdersRes)
|
||
|
|
bodyMap := map[string]interface{}{
|
||
|
|
"startTime": req.StartTime,
|
||
|
|
"endTime": req.EndTime,
|
||
|
|
}
|
||
|
|
if len(req.ContinuationToken) > 0 {
|
||
|
|
bodyMap["continuationToken"] = req.ContinuationToken
|
||
|
|
}
|
||
|
|
orderService := &harmonyos.OrderLookup{}
|
||
|
|
orderInfoStr, err := orderService.OrdersQuery(bodyMap)
|
||
|
|
if err != nil {
|
||
|
|
log.Printf("HarmonyOrders======>.StartTime: %d, EndTime : %d - err:%s", req.StartTime, req.EndTime, err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if err = json.Unmarshal([]byte(orderInfoStr), &res); err != nil {
|
||
|
|
log.Printf("HarmonyOrders======>.Unmarshal : %v", orderInfoStr)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
func HarmonyUserOrders(req *game.GetHarmonyUserOrdersReq) (res *game.GetHarmonyUserOrdersRes, err error) {
|
||
|
|
res = new(game.GetHarmonyUserOrdersRes)
|
||
|
|
bodyMap := make(map[string]interface{})
|
||
|
|
bodyMap["purchaseOrderId"] = req.PurchaseOrderId
|
||
|
|
if req.ProductType != "" {
|
||
|
|
bodyMap["productType"], err = strconv.Atoi(req.ProductType)
|
||
|
|
}
|
||
|
|
if req.StartTime != 0 {
|
||
|
|
bodyMap["startTime"] = req.StartTime
|
||
|
|
}
|
||
|
|
if req.EndTime != 0 {
|
||
|
|
bodyMap["endTime"] = req.EndTime
|
||
|
|
}
|
||
|
|
if len(req.ProductIdList) > 0 {
|
||
|
|
bodyMap["productIdList"] = req.ProductIdList
|
||
|
|
}
|
||
|
|
if len(req.ContinuationToken) > 0 {
|
||
|
|
bodyMap["continuationToken"] = req.ContinuationToken
|
||
|
|
}
|
||
|
|
orderService := &harmonyos.OrderLookup{}
|
||
|
|
orderInfoStr, err := orderService.UserOrdersQuery(bodyMap)
|
||
|
|
if err != nil {
|
||
|
|
log.Printf("HarmonyUserOrders======>.purchaseOrderId: %s, - err:%s", req.PurchaseOrderId, err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
orderInfo := game.HarmonyUserOrders{}
|
||
|
|
if err = json.Unmarshal([]byte(orderInfoStr), &orderInfo); err != nil {
|
||
|
|
log.Printf("HarmonyUserOrders======>.Unmarshal : %v", orderInfoStr)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
res.ResponseCode = orderInfo.ResponseCode
|
||
|
|
res.ResponseMessage = orderInfo.ResponseMessage
|
||
|
|
res.ContinuationToken = orderInfo.ContinuationToken
|
||
|
|
for _, v := range orderInfo.JwsPurchaseOrderList {
|
||
|
|
jwsChecker := &harmonyos.JWSChecker{}
|
||
|
|
purchaseOrderStr, err1 := jwsChecker.CheckAndDecodeJWS(v)
|
||
|
|
if err1 != nil {
|
||
|
|
err = err1
|
||
|
|
log.Printf("HarmonyUserOrders======>.jwsChecker.CheckAndDecodeJWS : err: %s, %s", err.Error(), purchaseOrderStr)
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
purchaseOrder := game.PurchaseOrderPayload{}
|
||
|
|
if err = json.Unmarshal([]byte(purchaseOrderStr), &purchaseOrder); err != nil {
|
||
|
|
log.Printf("HarmonyUserOrders======>.CheckAndDecodeJWS Unmarshal: %v, Err: %s", purchaseOrderStr, err)
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
res.OrderInfoList = append(res.OrderInfoList, purchaseOrder)
|
||
|
|
}
|
||
|
|
|
||
|
|
return
|
||
|
|
}
|