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.
62 lines
1.3 KiB
62 lines
1.3 KiB
package order
|
|
|
|
import (
|
|
"git.oa00.com/go/mysql"
|
|
"github.com/gin-gonic/gin"
|
|
"recook/internal/back"
|
|
"recook/internal/model/order"
|
|
"recook/tools"
|
|
)
|
|
|
|
type deleteOrderParam struct {
|
|
UserID uint `json:"userId"`
|
|
OrderID uint `json:"orderId"`
|
|
}
|
|
|
|
func DeleteOrder(c *gin.Context) {
|
|
var p deleteOrderParam
|
|
err := tools.ParseParams(&p, c)
|
|
if err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
var orderInfo order.Information
|
|
mysql.Db.First(&orderInfo, p.OrderID)
|
|
//dbc.DB.First(&orderInfo, p.OrderID)
|
|
|
|
if orderInfo.Status != 2 && orderInfo.Status != 3 && orderInfo.Status != 5 {
|
|
back.Fail(c, "订单不可删除")
|
|
return
|
|
}
|
|
|
|
tx := mysql.Db.Begin()
|
|
{
|
|
if err = tx.Delete(&orderInfo).Error; err != nil {
|
|
back.Err(c, err.Error())
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
|
|
if err = tx.Where("order_id = ?", orderInfo.ID).Delete(&order.Addr{}).Error; err != nil {
|
|
back.Err(c, err.Error())
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
|
|
if err = tx.Where("order_id = ?", orderInfo.ID).Delete(&order.CouponDetail{}).Error; err != nil {
|
|
back.Err(c, err.Error())
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
|
|
if err = tx.Where("order_id = ?", orderInfo.ID).Delete(&order.GoodsDetail{}).Error; err != nil {
|
|
back.Err(c, err.Error())
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
}
|
|
tx.Commit()
|
|
|
|
back.Suc(c, "", nil)
|
|
}
|