From 19f2cac2581004859651efa21af22e8920e9efe1 Mon Sep 17 00:00:00 2001 From: "yan.y" Date: Sun, 12 May 2024 21:31:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=8F=96=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/api/order.go | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/business/api/order.go b/business/api/order.go index 125a5a5..714cf08 100644 --- a/business/api/order.go +++ b/business/api/order.go @@ -326,6 +326,53 @@ func (p DefParty) orderList() web_iris.Party { }} } +type OrderCancelRequest struct { + OrderId string +} + +type OrderCancelResponse struct { + OrderDetail OrderDetail `json:"orderDetail"` +} + +func (p DefParty) orderCancel() web_iris.Party { + return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) { + index.Post(OrderBase+"/orderCancel", func(ctx *context.Context) { + headerBaseInfo := GetHeaderBaseInfo(ctx) + body, _ := io.ReadAll(ctx.Request().Body) + var orderCancelRequest OrderCancelRequest + json.Unmarshal(body, &orderCancelRequest) + var orderMain models.OrderMain + database.Instance().Model(&models.OrderMain{}).Where("order_id = ?", orderCancelRequest.OrderId).Find(&orderMain) + if orderMain.Uid != headerBaseInfo.Uid { + OrderExistError.Fail(ctx, orderCancelRequest) + return + } + if orderMain.OrderStatus != 1 { + OrderError.Fail(ctx, orderCancelRequest) + return + } + if orderMain.PayStatus == 1 { + var userInfo models.User + database.Instance().Model(&models.User{}).Where("id = ?", orderMain.Uid).Find(&userInfo) + userInfo.Amount = userInfo.Amount + orderMain.PayTotalAmount + updateValues := map[string]interface{}{ + "Amount": userInfo.Amount, + } + database.Instance().Model(&userInfo).Updates(&updateValues) + orderMain.PayTotalAmount = 0 + orderMain.PayStatus = 0 + } + orderMain.OrderStatus = 5 + updateValues := map[string]interface{}{ + "OrderStatus": orderMain.OrderStatus, + "PayStatus": orderMain.PayStatus, + "PayTotalAmount": orderMain.PayTotalAmount, + } + database.Instance().Model(&orderMain).Updates(&updateValues) + }) + }} +} + type TimeObject struct { Time string `json:"time"` Y bool `json:"y"`