package front import ( "github.com/ahmetb/go-linq/v3" "github.com/gin-gonic/gin" "qteam/app/constants/common" "qteam/app/constants/errorcode" "qteam/app/http/controllers" "qteam/app/http/entities/front" "qteam/app/models/ordermodel" "qteam/app/services" "qteam/app/third/market" "qteam/app/utils" "qteam/config" "strconv" ) func CreateOrder(c *gin.Context) { var request = controllers.GetRequest(c).(*front.OrderCreateRequest) userId := controllers.GetUserId(c) code, data := services.CreateOrderService(userId, request.ProductId) controllers.HandCodeRes(c, data, code) } func OrderList(c *gin.Context) { var request = controllers.GetRequest(c).(*front.OrderListRequest) userId := controllers.GetUserId(c) code, orderList, count := services.OrderQueryService(userId, request) var rsp []front.OrderQueryResponse if count > 0 { linq.From(orderList).SelectT(func(in ordermodel.Order) (out front.OrderQueryResponse) { out.ResponseFromDb(in) return out }).ToSlice(&rsp) } controllers.HandCodeRes(c, gin.H{"data": rsp, "count": count}, code) } func OrderQuery(c *gin.Context) { var request = controllers.GetRequest(c).(*front.OrderQueryRequest) order := ordermodel.Order{OrderNo: request.OrderNo} has, err := services.OrderDetailService(&order) if err != nil { controllers.Error(c, 500, "订单查询失败") return } if has { var state string if order.State < common.ORDER_STATUS_PAY { _, rsp := services.OrderXyQuery(request.OrderNo) utils.Log(nil, "三方订单查询", rsp) if rsp.OrderInfo.TxnStatus == "00" { client := market.NewMarketClient(config.GetConf().OpenApiMarketConfig) data, err := client.MarketSend(order.OrderNo, strconv.Itoa(order.VoucherId), "", "1") if err != nil { controllers.Error(c, 500, "三方订单查询失败") return } if data.ErrCode == "00" { err := services.OrdersUpdateService(front.OrdersUpdateRequest{Id: order.Id, Status: common.ORDER_STATUS_PAY, VoucherLink: data.Data.ShortUrl}) if err != nil { controllers.Error(c, 500, "订单更新失败") utils.Log(nil, "营销系统下单失败", data) return } } state = strconv.Itoa(common.ORDER_STATUS_PAY) } } state = strconv.Itoa(order.State) controllers.Success(c, gin.H{"state": state}, "请求成功") } else { controllers.HandCodeRes(c, nil, errorcode.NotFound) return } }