修改Order的命名域
This commit is contained in:
@@ -31,27 +31,24 @@ func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, useri
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
return resp.SetStatus(basic.CodeUnAuth) // 如果不是用户信息, 返回未授权错误
|
||||
}
|
||||
|
||||
// 确认这个IsDefault的值范围
|
||||
if !auth.CheckValueRange(req.IsDefault, 0, 1) {
|
||||
return resp.SetStatus(basic.CodeSafeValueRangeErr)
|
||||
return resp.SetStatus(basic.CodeSafeValueRangeErr) // IsDefault值超出范围, 返回安全值范围错误
|
||||
}
|
||||
|
||||
m := gmodel.NewFsAddressModel(l.svcCtx.MysqlConn)
|
||||
var status int64 = 1
|
||||
m := gmodel.NewFsAddressModel(l.svcCtx.MysqlConn) // 创建地址模型
|
||||
var status int64 = 1 // 默认地址状态为1(正常)
|
||||
|
||||
// 如果ID为0, 表示新增地址
|
||||
if req.Id == 0 {
|
||||
// $address->country = 'USA';
|
||||
// $address->status = 1;
|
||||
// $address->user_id = $uid;
|
||||
var (
|
||||
country string = "USA"
|
||||
|
||||
isDefautl int64 = 1
|
||||
country string = "USA" // 国家默认为美国
|
||||
isDefautl int64 = 1 // 默认地址为1
|
||||
)
|
||||
createOne := &gmodel.FsAddress{
|
||||
createOne := &gmodel.FsAddress{ // 构建FsAddress结构体
|
||||
Name: &req.Name,
|
||||
FirstName: &req.FirstName,
|
||||
LastName: &req.LastName,
|
||||
@@ -66,12 +63,12 @@ func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, useri
|
||||
ZipCode: &req.ZipCode,
|
||||
IsDefault: &isDefautl,
|
||||
}
|
||||
_, err := m.CreateOne(l.ctx, createOne)
|
||||
created, err := m.CreateOne(l.ctx, createOne) // 新增地址
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeDbCreateErr)
|
||||
logx.Error(err) // 日志记录错误
|
||||
return resp.SetStatus(basic.CodeDbCreateErr) // 返回数据库创建错误
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK, map[string]int64{"id": createOne.Id})
|
||||
return resp.SetStatus(basic.CodeOK, map[string]int64{"id": created.Id}) // 返回成功并返回地址ID
|
||||
}
|
||||
|
||||
address := &gmodel.FsAddress{
|
||||
@@ -90,6 +87,7 @@ func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, useri
|
||||
IsDefault: &req.IsDefault,
|
||||
}
|
||||
|
||||
// 插入数据库 更新地址
|
||||
err := m.UpdateAddAddress(l.ctx, address)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
|
||||
@@ -28,10 +28,13 @@ func NewUserAddressListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *U
|
||||
|
||||
func (l *UserAddressListLogic) UserAddressList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
m := gmodel.NewFsAddressModel(l.svcCtx.MysqlConn)
|
||||
userinfo.GetIdType()
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
data, err := m.GetUserAllAddress(l.ctx, 22)
|
||||
m := gmodel.NewFsAddressModel(l.svcCtx.MysqlConn)
|
||||
|
||||
data, err := m.GetUserAllAddress(l.ctx, userinfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
|
||||
79
server/home-user-auth/internal/logic/useroderdeletelogic.go
Normal file
79
server/home-user-auth/internal/logic/useroderdeletelogic.go
Normal file
@@ -0,0 +1,79 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user