修改Order的命名域
This commit is contained in:
parent
db954e88d4
commit
58547706c7
|
@ -1,7 +0,0 @@
|
|||
package constants
|
||||
|
||||
// 发货到地址方式
|
||||
const DELIVERY_METHOD_ADDRESS = 1
|
||||
|
||||
// 发货到云仓方式
|
||||
const DELIVERY_METHOD_CLOUD = 2
|
|
@ -2,68 +2,128 @@ package constants
|
|||
|
||||
// 新版订单状态-后台所有
|
||||
// 未支付
|
||||
const STATUS_NEW_NOT_PAY = 0
|
||||
// const STATUS_NEW_NOT_PAY = 0
|
||||
|
||||
// 首款已付,尾款待付
|
||||
const STATUS_NEW_PART_PAY = 1
|
||||
// // 首款已付,尾款待付
|
||||
// const STATUS_NEW_PART_PAY = 1
|
||||
|
||||
// // 全款已付
|
||||
// const STATUS_NEW_PAY_COMPLETED = 2
|
||||
|
||||
// // 订单已确认
|
||||
// const STATUS_NEW_SURE = 3
|
||||
|
||||
// // 订单生产中
|
||||
// const STATUS_NEW_PRODUTING = 4
|
||||
|
||||
// // 订单生产完成
|
||||
// const STATUS_NEW_PRODUT_COMPLETED = 5
|
||||
|
||||
// // 订单已到库
|
||||
// const STATUS_NEW_ARRIVAL = 6
|
||||
|
||||
// // 已发货
|
||||
// const STATUS_NEW_DELIVER = 7
|
||||
|
||||
// // UPS提货
|
||||
// const STATUS_NEW_UPS = 8
|
||||
|
||||
// // 已完成
|
||||
// const STATUS_NEW_COMPLETED = 9
|
||||
|
||||
// // 取消订单
|
||||
// const STATUS_NEW_CANCEL = 10
|
||||
|
||||
// // 退款中
|
||||
// const STATUS_NEW_REFUNDING = 11
|
||||
|
||||
// // 退款完成
|
||||
// const STATUS_NEW_REFUNDED = 12
|
||||
|
||||
// // 订单删除
|
||||
// const STATUS_NEW_DELETE = 13
|
||||
|
||||
// // 订单关闭
|
||||
// const STATUS_NEW_CLOSE = 14
|
||||
|
||||
// // 前台订单
|
||||
// // 已支付
|
||||
// const STATUS_FONT_PAID = 1
|
||||
|
||||
// // 生产中
|
||||
// const STATUS_FONT_PRODUCTION = 2
|
||||
|
||||
// // 运输中
|
||||
// const STATUS_FONT_SHIPPED = 3
|
||||
|
||||
// // 到达云仓
|
||||
// const STATUS_FONT_INVENTORY = 4
|
||||
|
||||
// // 订单完成
|
||||
// const STATUS_FONT_COMPLETED = 5
|
||||
|
||||
// // 订单关闭
|
||||
// const STATUS_FONT_CLOSED = 7
|
||||
|
||||
// // 云仓完成
|
||||
// const STATUS_FONT_COMPLETED_CLOUD = 8
|
||||
|
||||
type Order int
|
||||
|
||||
const (
|
||||
// 配送方式
|
||||
DELIVERY_METHOD_ADDRESS Order = 1 // 直接发货到收获地址
|
||||
DELIVERY_METHOD_CLOUD Order = 2 // 云仓
|
||||
)
|
||||
|
||||
// 订单状态
|
||||
const (
|
||||
// 未支付
|
||||
STATUS_NEW_NOT_PAY Order = 0
|
||||
// 首款已付,尾款待付
|
||||
STATUS_NEW_PART_PAY Order = 1
|
||||
// 全款已付
|
||||
const STATUS_NEW_PAY_COMPLETED = 2
|
||||
|
||||
STATUS_NEW_PAY_COMPLETED Order = 2
|
||||
// 订单已确认
|
||||
const STATUS_NEW_SURE = 3
|
||||
|
||||
STATUS_NEW_SURE Order = 3
|
||||
// 订单生产中
|
||||
const STATUS_NEW_PRODUTING = 4
|
||||
|
||||
STATUS_NEW_PRODUCING Order = 4
|
||||
// 订单生产完成
|
||||
const STATUS_NEW_PRODUT_COMPLETED = 5
|
||||
|
||||
STATUS_NEW_PRODUT_COMPLETED Order = 5
|
||||
// 订单已到库
|
||||
const STATUS_NEW_ARRIVAL = 6
|
||||
|
||||
STATUS_NEW_ARRIVAL Order = 6
|
||||
// 已发货
|
||||
const STATUS_NEW_DELIVER = 7
|
||||
|
||||
STATUS_NEW_DELIVER Order = 7
|
||||
// UPS提货
|
||||
const STATUS_NEW_UPS = 8
|
||||
|
||||
STATUS_NEW_UPS Order = 8
|
||||
// 已完成
|
||||
const STATUS_NEW_COMPLETED = 9
|
||||
|
||||
STATUS_NEW_COMPLETED Order = 9
|
||||
// 取消订单
|
||||
const STATUS_NEW_CANCEL = 10
|
||||
|
||||
STATUS_NEW_CANCEL Order = 10
|
||||
// 退款中
|
||||
const STATUS_NEW_REFUNDING = 11
|
||||
|
||||
STATUS_NEW_REFUNDING Order = 11
|
||||
// 退款完成
|
||||
const STATUS_NEW_REFUNDED = 12
|
||||
|
||||
STATUS_NEW_REFUNDED Order = 12
|
||||
// 订单删除
|
||||
const STATUS_NEW_DELETE = 13
|
||||
|
||||
STATUS_NEW_DELETE Order = 13
|
||||
// 订单关闭
|
||||
const STATUS_NEW_CLOSE = 14
|
||||
STATUS_NEW_CLOSE Order = 14
|
||||
)
|
||||
|
||||
// 前台订单
|
||||
// 前台订单状态
|
||||
const (
|
||||
// 已支付
|
||||
const STATUS_FONT_PAID = 1
|
||||
|
||||
STATUS_FONT_PAID Order = 1
|
||||
// 生产中
|
||||
const STATUS_FONT_PRODUCTION = 2
|
||||
|
||||
STATUS_FONT_PRODUCTION Order = 2
|
||||
// 运输中
|
||||
const STATUS_FONT_SHIPPED = 3
|
||||
|
||||
STATUS_FONT_SHIPPED Order = 3
|
||||
// 到达云仓
|
||||
const STATUS_FONT_INVENTORY = 4
|
||||
|
||||
STATUS_FONT_INVENTORY Order = 4
|
||||
// 订单完成
|
||||
const STATUS_FONT_COMPLETED = 5
|
||||
|
||||
STATUS_FONT_COMPLETED Order = 5
|
||||
// 订单关闭
|
||||
const STATUS_FONT_CLOSED = 7
|
||||
|
||||
STATUS_FONT_CLOSED Order = 7
|
||||
// 云仓完成
|
||||
const STATUS_FONT_COMPLETED_CLOUD = 8
|
||||
STATUS_FONT_COMPLETED_CLOUD Order = 8
|
||||
)
|
||||
|
|
8
go.mod
8
go.mod
|
@ -14,13 +14,12 @@ require (
|
|||
)
|
||||
|
||||
require (
|
||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
||||
github.com/schollz/progressbar v1.0.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/474420502/requests v1.32.1
|
||||
github.com/474420502/requests v1.33.0
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/tidwall/gjson v1.12.0
|
||||
|
@ -38,7 +37,7 @@ require (
|
|||
github.com/go-logr/logr v1.2.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-redis/redis/v8 v8.11.5 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.0
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect
|
||||
|
@ -53,7 +52,6 @@ require (
|
|||
github.com/prometheus/common v0.42.0 // indirect
|
||||
github.com/prometheus/procfs v0.9.0 // indirect
|
||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
github.com/zeromicro/ddl-parser v1.0.4
|
||||
go.opentelemetry.io/otel v1.14.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.14.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect
|
||||
|
|
12
go.sum
12
go.sum
|
@ -32,8 +32,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
|
|||
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
github.com/474420502/random v0.4.1 h1:HUUyLXRWMijVb7CJoEC16f0aFQOW25Lkr80Mut6PoKU=
|
||||
github.com/474420502/requests v1.32.1 h1:ivr9iMXrYqfdKWS0q15HEFlt1Cjeeu75Hjhbmikg9us=
|
||||
github.com/474420502/requests v1.32.1/go.mod h1:rrDBE6AfPr0Cclo1lL4Jgw1mIW6TKSCvFgXDuEqlw70=
|
||||
github.com/474420502/requests v1.33.0 h1:psSTM9WsIDjbjJIXXXhhT52BlpcaNs+gDetQi2wgu1o=
|
||||
github.com/474420502/requests v1.33.0/go.mod h1:5qAlksMg7JIrEXrpkxw1++4Z5W2tUkZbHA6M7oq1r/0=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||
|
@ -43,8 +43,6 @@ github.com/SebastiaanKlippert/go-wkhtmltopdf v1.9.0/go.mod h1:SQq4xfIdvf6WYKSDxA
|
|||
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk=
|
||||
github.com/alicebob/miniredis/v2 v2.30.2 h1:lc1UAUT9ZA7h4srlfBmBt2aorm5Yftk9nBjxz7EyY9I=
|
||||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec h1:EEyRvzmpEUZ+I8WmD5cw/vY8EqhambkOqy5iFr0908A=
|
||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4=
|
||||
|
@ -182,8 +180,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
|||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
|
@ -215,6 +211,8 @@ github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB
|
|||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/schollz/progressbar v1.0.0 h1:gbyFReLHDkZo8mxy/dLWMr+Mpb1MokGJ1FqCiqacjZM=
|
||||
github.com/schollz/progressbar v1.0.0/go.mod h1:/l9I7PC3L3erOuz54ghIRKUEFcosiWfLvJv+Eq26UMs=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
|
@ -241,8 +239,6 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
|
|||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE=
|
||||
github.com/zeromicro/ddl-parser v1.0.4 h1:fzU0ZNfV/a6T/WO8TvZZeJE9hmdt3qHvVUsW1X9SGJQ=
|
||||
github.com/zeromicro/ddl-parser v1.0.4/go.mod h1:ISU/8NuPyEpl9pa17Py9TBPetMjtsiHrb9f5XGiYbo8=
|
||||
github.com/zeromicro/go-zero v1.5.2 h1:vpMlZacCMtgdtYzKI3OMyhS6mZ9UQctiAh0J7gIq31I=
|
||||
github.com/zeromicro/go-zero v1.5.2/go.mod h1:ndCd1nMMAdEMZgPfdm1fpavHUdBW0ykB6ckCRaSG10w=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
|
|
|
@ -23,11 +23,11 @@ func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (r
|
|||
return
|
||||
}
|
||||
|
||||
func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (resp *FsAddress, err error) {
|
||||
func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (result *FsAddress, err error) {
|
||||
|
||||
err = a.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
// now := time.Now().Unix()
|
||||
resp = &FsAddress{
|
||||
result = &FsAddress{
|
||||
UserId: address.UserId,
|
||||
Name: address.Name,
|
||||
FirstName: address.FirstName,
|
||||
|
@ -43,14 +43,14 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res
|
|||
IsDefault: address.IsDefault,
|
||||
}
|
||||
|
||||
return tx.Create(resp).Error
|
||||
return tx.Create(result).Error
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *FsAddressModel) UpdateAddAddress(ctx context.Context, address *FsAddress) (err error) {
|
||||
|
|
|
@ -57,6 +57,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/user/add-address",
|
||||
Handler: UserAddAddressHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/user/order-delete",
|
||||
Handler: UserOderDeleteHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/logic"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
)
|
||||
|
||||
func UserOderDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var (
|
||||
// 定义错误变量
|
||||
err error
|
||||
// 定义用户信息变量
|
||||
userinfo *auth.UserInfo
|
||||
)
|
||||
// 解析JWT token,并对空用户进行判断
|
||||
claims, err := svcCtx.ParseJwtToken(r)
|
||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401, // 返回401状态码,表示未授权
|
||||
Message: "unauthorized", // 返回未授权信息
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||
return
|
||||
}
|
||||
|
||||
if claims != nil {
|
||||
// 从token中获取对应的用户信息
|
||||
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401,
|
||||
Message: "unauthorized",
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// 如果claims为nil,则认为用户身份为白板用户
|
||||
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||
}
|
||||
|
||||
var req types.RequestOrderId
|
||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewUserOderDeleteLogic(r.Context(), svcCtx)
|
||||
resp := l.UserOderDelete(&req, userinfo)
|
||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -43,6 +43,10 @@ type RequestAddAddress struct {
|
|||
State string `json:"state"` //州
|
||||
}
|
||||
|
||||
type RequestOrderId struct {
|
||||
OrderId int64 `json:"id"`
|
||||
}
|
||||
|
||||
type DataUserLogin struct {
|
||||
Token string `json:"token"` // 登录jwt token
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ func TestAcceptCookieLogic(t *testing.T) {
|
|||
ses := GetSesssion(t, gserver)
|
||||
|
||||
// 向服务器发送 GET 请求,获取 cookie 信息
|
||||
resp, err = ses.Post(fmt.Sprintf("http://%s:%d/user/accept-cookie", cnf.Host, cnf.Port)).TestInServer(gserver)
|
||||
resp, err = ses.Post(fmt.Sprintf("http://%s:%d/user/accept-cookie", cnf.Host, cnf.Port)).TestExecute(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func GetSesssionWithUserToken(t *testing.T, server requests.ITestServer) *reques
|
|||
"name": "devenv@sina.cn",
|
||||
"pwd": "$2y$13$6UFDMZQMEfqFYiNLpiUCi.B3fpvGEamPAjIgzUqv/u7jT05nB3pOC",
|
||||
})
|
||||
resp, err := tp.TestInServer(server)
|
||||
resp, err := tp.TestExecute(server)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func GetSesssionWithGuestToken(t *testing.T, server requests.ITestServer) *reque
|
|||
ses := requests.NewSession()
|
||||
tp := ses.Post(fmt.Sprintf("http://%s:%d/accept/cookie", cnf.Host, cnf.Port))
|
||||
|
||||
resp, err := tp.TestInServer(server)
|
||||
resp, err := tp.TestExecute(server)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
127
server/home-user-auth/test/useraddaddresslogic_test.go
Normal file
127
server/home-user-auth/test/useraddaddresslogic_test.go
Normal file
|
@ -0,0 +1,127 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"testing"
|
||||
|
||||
"github.com/474420502/requests"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func TestCaseUserAddAddress(t *testing.T) {
|
||||
var err error
|
||||
var resp *requests.Response
|
||||
var result gjson.Result
|
||||
|
||||
// 获取 session,并携带 JWT token
|
||||
ses := GetSesssionWithUserToken(t, gserver)
|
||||
|
||||
// 构建新增地址请求体
|
||||
addrReq := types.RequestAddAddress{
|
||||
Name: "John Doe",
|
||||
FirstName: "John",
|
||||
LastName: "Doe",
|
||||
Mobile: "123-456-7890",
|
||||
Street: "Main St",
|
||||
Suite: "Apt 123",
|
||||
City: "New York",
|
||||
State: "NY",
|
||||
ZipCode: "10001",
|
||||
}
|
||||
|
||||
// 向服务器发送 POST 请求,新增用户地址
|
||||
tp := ses.Post(fmt.Sprintf("http://%s:%d/user/add-address", cnf.Host, cnf.Port))
|
||||
tp.SetBodyJson(addrReq)
|
||||
resp, err = tp.TestExecute(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 检查返回值中的 code 字段是否存在,并且值是否为 200
|
||||
result = resp.Json().Get("code")
|
||||
if !result.Exists() {
|
||||
t.Error("code is not exists")
|
||||
}
|
||||
if result.Int() != 200 {
|
||||
t.Error("code != 200")
|
||||
}
|
||||
|
||||
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
|
||||
result = resp.Json().Get("msg")
|
||||
if !result.Exists() {
|
||||
t.Error("msg is not exists")
|
||||
}
|
||||
if result.String() != "success" {
|
||||
t.Error(result.String())
|
||||
}
|
||||
|
||||
// 检查返回值中的 data 字段是否存在,并且包含新增地址的 id
|
||||
result = resp.Json().Get("data")
|
||||
if !result.Exists() {
|
||||
t.Error("data is not exists")
|
||||
}
|
||||
if !result.Get("id").Exists() {
|
||||
t.Error("data.id is not exists")
|
||||
}
|
||||
|
||||
addressId := result.Get("id").Int()
|
||||
|
||||
// 测试修改
|
||||
|
||||
addrReq = types.RequestAddAddress{
|
||||
Id: addressId, // 获取新增的id
|
||||
Name: "Jane Smith",
|
||||
FirstName: "Jane",
|
||||
LastName: "Smith",
|
||||
Mobile: "987-654-3210",
|
||||
Street: "First Ave",
|
||||
Suite: "Unit 456",
|
||||
City: "San Francisco",
|
||||
State: "CA",
|
||||
ZipCode: "94122",
|
||||
}
|
||||
|
||||
// 向服务器发送 POST 请求,新增用户地址
|
||||
tp = ses.Post(fmt.Sprintf("http://%s:%d/user/add-address", cnf.Host, cnf.Port))
|
||||
tp.SetBodyJson(addrReq)
|
||||
resp, err = tp.TestExecute(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 检查返回值中的 code 字段是否存在,并且值是否为 200
|
||||
result = resp.Json().Get("code")
|
||||
if !result.Exists() {
|
||||
t.Error("code is not exists")
|
||||
}
|
||||
if result.Int() != 200 {
|
||||
t.Error("code != 200")
|
||||
}
|
||||
|
||||
// 检查返回值中的 msg 字段是否存在,并且值是否为 "success"
|
||||
result = resp.Json().Get("msg")
|
||||
if !result.Exists() {
|
||||
t.Error("msg is not exists")
|
||||
}
|
||||
if result.String() != "success" {
|
||||
t.Error(result.String())
|
||||
}
|
||||
|
||||
// log.Println(resp.Json())
|
||||
// 检查返回值中的 data 字段是否存在,并且包含新增地址的 id
|
||||
result = resp.Json().Get("data")
|
||||
if !result.Exists() {
|
||||
t.Error("data is not exists")
|
||||
}
|
||||
if !result.Get("id").Exists() {
|
||||
t.Error("data.id is not exists")
|
||||
}
|
||||
|
||||
if result.Get("id").Int() != addressId {
|
||||
t.Error("addressId is error")
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,7 @@ func TestCaseAddressList(t *testing.T) {
|
|||
ses := GetSesssionWithUserToken(t, gserver)
|
||||
|
||||
// 向服务器发送 GET 请求,获取用户地址列表
|
||||
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/address-list", cnf.Host, cnf.Port)).TestInServer(gserver)
|
||||
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/address-list", cnf.Host, cnf.Port)).TestExecute(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ func TestCaseBasicInfoLogic(t *testing.T) {
|
|||
ses := GetSesssionWithUserToken(t, gserver)
|
||||
|
||||
// 向服务器发送 GET 请求,获取用户基本信息
|
||||
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/basic-info", cnf.Host, cnf.Port)).TestInServer(gserver)
|
||||
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/basic-info", cnf.Host, cnf.Port)).TestExecute(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ func TestCaseUserFontsLogic(t *testing.T) {
|
|||
ses := GetSesssionWithUserToken(t, gserver)
|
||||
|
||||
// 向服务器发送 GET 请求,获取字体列表
|
||||
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/fonts", cnf.Host, cnf.Port)).TestInServer(gserver)
|
||||
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/fonts", cnf.Host, cnf.Port)).TestExecute(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ func TestCaseGetTypeLogic(t *testing.T) {
|
|||
ses := GetSesssionWithUserToken(t, gserver)
|
||||
|
||||
// 向服务器发送 GET 请求,获取用户类型信息
|
||||
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/get-type", cnf.Host, cnf.Port)).TestInServer(gserver)
|
||||
resp, err = ses.Get(fmt.Sprintf("http://%s:%d/user/get-type", cnf.Host, cnf.Port)).TestExecute(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ func TestCaseUserSaveBasicinfoLogic(t *testing.T) {
|
|||
var tp *requests.Temporary
|
||||
|
||||
tp = ses.Get(fmt.Sprintf("http://%s:%d/user/basic-info", cnf.Host, cnf.Port))
|
||||
resp, err = tp.TestInServer(gserver)
|
||||
resp, err = tp.TestExecute(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -52,7 +52,7 @@ func TestCaseUserSaveBasicinfoLogic(t *testing.T) {
|
|||
|
||||
// 向服务器发送 GET 请求,获取用户类型信息
|
||||
tp = ses.Post(fmt.Sprintf("http://%s:%d/user/basic-info", cnf.Host, cnf.Port)).SetBodyJson(req)
|
||||
resp, err = tp.TestInServer(gserver)
|
||||
resp, err = tp.TestExecute(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -69,7 +69,7 @@ func TestCaseUserSaveBasicinfoLogic(t *testing.T) {
|
|||
}
|
||||
|
||||
tp = ses.Get(fmt.Sprintf("http://%s:%d/user/basic-info", cnf.Host, cnf.Port))
|
||||
resp, err = tp.TestInServer(gserver)
|
||||
resp, err = tp.TestExecute(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
|
|
@ -17,7 +17,7 @@ func TestCaseUserStatusConfigLogic(t *testing.T) {
|
|||
ses := GetSesssionWithUserToken(t, gserver)
|
||||
|
||||
// 向服务器发送 GET 请求,获取用户类型信息
|
||||
resp, err = ses.Post(fmt.Sprintf("http://%s:%d/user/status-config", cnf.Host, cnf.Port)).TestInServer(gserver)
|
||||
resp, err = ses.Post(fmt.Sprintf("http://%s:%d/user/status-config", cnf.Host, cnf.Port)).TestExecute(gserver)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -41,6 +41,9 @@ service home-user-auth {
|
|||
|
||||
@handler UserAddAddressHandler
|
||||
post /user/add-address(RequestAddAddress) returns (response);
|
||||
|
||||
@handler UserOderDeleteHandler
|
||||
post /user/order-delete(RequestOrderId) returns (response);
|
||||
}
|
||||
|
||||
type RequestBasicInfoForm {
|
||||
|
@ -67,6 +70,7 @@ type RequestUserLogin {
|
|||
Password string `json:"pwd"`
|
||||
}
|
||||
|
||||
// RequestAddAddress 增加地址结构
|
||||
type RequestAddAddress {
|
||||
Id int64 `json:"id"` // address_id 地址id
|
||||
IsDefault int64 `json:"is_default"` //是否默认
|
||||
|
@ -81,6 +85,11 @@ type RequestAddAddress {
|
|||
State string `json:"state"` //州
|
||||
}
|
||||
|
||||
// RequestOrderId 传入订单id的结构
|
||||
type RequestOrderId {
|
||||
OrderId int64 `json:"id"`
|
||||
}
|
||||
|
||||
// UserLoginHandler 用户登录请求结构
|
||||
type DataUserLogin {
|
||||
Token string `json:"token"` // 登录jwt token
|
||||
|
|
|
@ -64,7 +64,10 @@ func (resp *Response) SetStatus(sr *StatusResponse, data ...interface{}) *Respon
|
|||
} else {
|
||||
newResp.Data = data[0]
|
||||
}
|
||||
} else if len(data) > 1 {
|
||||
newResp.Data = data
|
||||
}
|
||||
|
||||
return newResp
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user