package logic import ( "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" "log" "time" "context" "fusenapi/server/home-user-auth/internal/svc" "fusenapi/server/home-user-auth/internal/types" "github.com/zeromicro/go-zero/core/logx" "gorm.io/gorm" ) 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 log.Println(req) if !userinfo.IsUser() { return resp.SetStatus(basic.CodeUnAuth) // 如果不是用户信息, 返回未授权错误 } //订单id orderId := req.OrderId if orderId < 1 { return resp.SetStatus(basic.CodeRequestParamsErr) } m := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn) order, err := m.FindOne(l.ctx, userinfo.UserId, orderId) if err != nil { if err == gorm.ErrRecordNotFound { return resp.SetStatus(basic.CodeOrderNotFoundErr) } logx.Error(err) return resp.SetStatus(basic.CodeDbSqlErr) } if auth.CheckValueRange[constants.Order]( constants.Order(*order.Status), constants.STATUS_NEW_NOT_PAY, constants.STATUS_NEW_PAY_COMPLETED, constants.STATUS_NEW_PART_PAY, ) { return resp.SetStatus(basic.CodeOrderNotCancelledErr) } if *order.IsPayCompleted == 1 && time.Now().After(time.Unix(*order.Ctime, 0).Add(48*time.Hour)) { return resp.SetStatus(basic.CodeOrderNotCancelledErr) } 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) // }