订单取消

This commit is contained in:
yan.y 2024-05-12 21:31:37 +08:00
parent 7b753da3d9
commit 19f2cac258
1 changed files with 47 additions and 0 deletions

View File

@ -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"`