80 lines
2.4 KiB
Go
80 lines
2.4 KiB
Go
|
package logic
|
||
|
|
||
|
import (
|
||
|
"fusenapi/model/gmodel"
|
||
|
"fusenapi/utils/auth"
|
||
|
"fusenapi/utils/basic"
|
||
|
|
||
|
"context"
|
||
|
|
||
|
"fusenapi/server/home-user-auth/internal/svc"
|
||
|
"fusenapi/server/home-user-auth/internal/types"
|
||
|
|
||
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
)
|
||
|
|
||
|
type UserOderDeleteLogic struct {
|
||
|
logx.Logger
|
||
|
ctx context.Context
|
||
|
svcCtx *svc.ServiceContext
|
||
|
}
|
||
|
|
||
|
func NewUserOderDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserOderDeleteLogic {
|
||
|
return &UserOderDeleteLogic{
|
||
|
Logger: logx.WithContext(ctx),
|
||
|
ctx: ctx,
|
||
|
svcCtx: svcCtx,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (l *UserOderDeleteLogic) UserOderDelete(req *types.RequestOrderId, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||
|
// userinfo 传入值时, 一定不为null
|
||
|
if !userinfo.IsUser() {
|
||
|
return resp.SetStatus(basic.CodeUnAuth) // 如果不是用户信息, 返回未授权错误
|
||
|
}
|
||
|
|
||
|
//订单id
|
||
|
orderId := req.OrderId
|
||
|
if orderId < 0 {
|
||
|
return resp.SetStatus(basic.CodeRequestParamsErr)
|
||
|
}
|
||
|
|
||
|
return resp.SetStatus(basic.CodeOK)
|
||
|
}
|
||
|
|
||
|
func (l *OrderLogic) CancelOrder(req *types.RequestCancelOrder, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||
|
// userinfo 传入值时, 一定不为null
|
||
|
if !userinfo.IsUser() {
|
||
|
return resp.SetStatus(basic.CodeUnAuth) // 如果不是用户信息, 返回未授权错误
|
||
|
}
|
||
|
//订单id
|
||
|
id := req.ReqParam.Get("id")
|
||
|
if id == "" {
|
||
|
return resp.SetStatus(basic.CodeParamErr)
|
||
|
}
|
||
|
//验证当前订单是否可以取消
|
||
|
order, err := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn).GetOne(l.ctx, map[string]interface{}{"user_id": userinfo.UserId, "id": id})
|
||
|
if err != nil {
|
||
|
return resp.SetStatus(basic.CodeDbQueryErr)
|
||
|
}
|
||
|
if order == nil {
|
||
|
return resp.SetStatus(basic.CodeNotFound)
|
||
|
}
|
||
|
//那些状态下是不能关闭的? (订单完成,退款完成,关闭订单)
|
||
|
if order.Status == gconst.OrderStatusComplete ||
|
||
|
order.Status == gconst.OrderStatusRefund ||
|
||
|
order.Status == gconst.OrderStatusClose {
|
||
|
return resp.SetStatus(basic.CodeCannotOperate)
|
||
|
}
|
||
|
//订单状态修改
|
||
|
order.Status = gconst.OrderStatusDelete
|
||
|
order.IsDeleted = 1
|
||
|
result, err := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn).UpdateOne(l.ctx, order)
|
||
|
if err != nil {
|
||
|
return resp.SetStatus(basic.CodeDbUpdateErr)
|
||
|
}
|
||
|
return resp.SetStatus(basic.CodeOK, result)
|
||
|
}
|