feature/order_service #1

Merged
daniel.w merged 8 commits from feature/order_service into main 2024-10-27 17:28:27 +00:00
57 changed files with 2031 additions and 0 deletions
Showing only changes of commit 69746285ae - Show all commits

64
Makefile Normal file
View File

@ -0,0 +1,64 @@
GO_CTL_NAME=goctl
# go-zero 生成風格
GO_ZERO_STYLE=go_zero
GO ?= go
GOFMT ?= gofmt "-s"
GOFILES := $(shell find . -name "*.go")
LDFLAGS := -s -w
VERSION="v1.0.1"
DOCKER_REPO="igs170911/feed"
.PHONY: test
test: # 進行測試
go test -v --cover ./...
.PHONY: fmt
fmt: # 格式優化
$(GOFMT) -w $(GOFILES)
goimports -w ./
golangci-lint run
.PHONY: gen-rpc
gen-rpc: # 建立 rpc code
$(GO_CTL_NAME) rpc protoc ./generate/protobuf/trade.proto -m --style=$(GO_ZERO_STYLE) --go_out=./gen_result/pb --go-grpc_out=./gen_result/pb --zrpc_out=.
go mod tidy
@echo "Generate core-api files successfully"
.PHONY: gen-clean
gen-clean: # 建立 rpc code
rm -rf ./client
rm -rf ./etc
rm -rf ./gen_result
rm -rf ./internal
rm -rf go.mod
rm -rf go.sum
rm -rf order.go
@echo "Generate core-api files successfully"
.PHONY: run-docker
run-docker: # 建立 rpc code
docker run --platform=linux/arm64/v8 -p 8080:8080 $(DOCKER_REPO):$(VERSION)
.PHONY: build-docker
build-docker:
cp ./build/Dockerfile Dockerfile
docker buildx build -t $(DOCKER_REPO):$(VERSION) --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/ed_25519)" .
rm -rf Dockerfile
@echo "Generate core-api files successfully"
gen-mongo-model: # 建立 rpc 資料庫
# 只產生 Model 剩下的要自己撰寫,連欄位名稱也是
goctl model mongo -t order --dir ./internal/model/mongo --style $(GO_ZERO_STYLE)
@echo "Generate mongo model files successfully"
.PHONY: mock-gen
mock-gen: # 建立 mock 資料
mockgen -source=./internal/model/mongo/order_model_gen.go -destination=./internal/mock/model/order_model_gen.go -package=mock
mockgen -source=./internal/model/mongo/order_model.go -destination=./internal/mock/model/order_model.go -package=mock
@echo "Generate mock files successfully"
.PHONY: migrate-database
migrate-database:
migrate -source file://generate/database/mongodb -database 'mongodb://127.0.0.1:27017/digimon_order' up

6
etc/trade.yaml Normal file
View File

@ -0,0 +1,6 @@
Name: trade.rpc
ListenOn: 0.0.0.0:8080
Etcd:
Hosts:
- 127.0.0.1:2379
Key: trade.rpc

89
go.mod Normal file
View File

@ -0,0 +1,89 @@
module app-cloudep-trade-service
go 1.22.3
require (
github.com/zeromicro/go-zero v1.7.3
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.35.1
)
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/redis/go-redis/v9 v9.7.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.15 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.15 // indirect
go.etcd.io/etcd/client/v3 v3.5.15 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.7.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.3 // indirect
k8s.io/apimachinery v0.29.4 // indirect
k8s.io/client-go v0.29.3 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

7
internal/config/config.go Executable file
View File

@ -0,0 +1,7 @@
package config
import "github.com/zeromicro/go-zero/zrpc"
type Config struct {
zrpc.RpcServerConf
}

View File

@ -0,0 +1,31 @@
package couponservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateCouponLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateCouponLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateCouponLogic {
return &CreateCouponLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CreateCoupon 創建優惠券
func (l *CreateCouponLogic) CreateCoupon(in *trade.CreateCouponReq) (*trade.CouponResp, error) {
// todo: add your logic here and delete this line
return &trade.CouponResp{}, nil
}

View File

@ -0,0 +1,31 @@
package couponservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteCouponLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDeleteCouponLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteCouponLogic {
return &DeleteCouponLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// DeleteCoupon 刪除優惠券
func (l *DeleteCouponLogic) DeleteCoupon(in *trade.CouponQueryReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package couponservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ListCouponsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewListCouponsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListCouponsLogic {
return &ListCouponsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// ListCoupons列出所有優惠券
func (l *ListCouponsLogic) ListCoupons(in *trade.CouponListReq) (*trade.CouponListResp, error) {
// todo: add your logic here and delete this line
return &trade.CouponListResp{}, nil
}

View File

@ -0,0 +1,31 @@
package couponservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type QueryCouponLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewQueryCouponLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryCouponLogic {
return &QueryCouponLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// QueryCoupon查詢優惠券
func (l *QueryCouponLogic) QueryCoupon(in *trade.CouponQueryReq) (*trade.CouponResp, error) {
// todo: add your logic here and delete this line
return &trade.CouponResp{}, nil
}

View File

@ -0,0 +1,31 @@
package couponservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateCouponLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateCouponLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCouponLogic {
return &UpdateCouponLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// UpdateCoupon更新優惠券
func (l *UpdateCouponLogic) UpdateCoupon(in *trade.UpdateCouponReq) (*trade.CouponResp, error) {
// todo: add your logic here and delete this line
return &trade.CouponResp{}, nil
}

View File

@ -0,0 +1,31 @@
package couponservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ValidateCouponLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewValidateCouponLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ValidateCouponLogic {
return &ValidateCouponLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// ValidateCoupon 驗證優惠券 (在下單或支付時使用)
func (l *ValidateCouponLogic) ValidateCoupon(in *trade.ValidateCouponReq) (*trade.CouponValidationResp, error) {
// todo: add your logic here and delete this line
return &trade.CouponValidationResp{}, nil
}

View File

@ -0,0 +1,31 @@
package inventoryservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type AddStockLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddStockLogic {
return &AddStockLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// AddStock 增加庫存
func (l *AddStockLogic) AddStock(in *trade.StockAdjustmentReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package inventoryservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type AdjustStockLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAdjustStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdjustStockLogic {
return &AdjustStockLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// AdjustStock 調整庫存 (批量修改庫存,用於大批商品更新)
func (l *AdjustStockLogic) AdjustStock(in *trade.BatchStockAdjustmentReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package inventoryservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateStockLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateStockLogic {
return &CreateStockLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CreateStock 建立庫存品項
func (l *CreateStockLogic) CreateStock(in *trade.StockAdjustmentReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package inventoryservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ListAllStockLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewListAllStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListAllStockLogic {
return &ListAllStockLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// ListAllStock 查詢所有商品的庫存狀況
func (l *ListAllStockLogic) ListAllStock(in *trade.StockListReq) (*trade.StockListResp, error) {
// todo: add your logic here and delete this line
return &trade.StockListResp{}, nil
}

View File

@ -0,0 +1,31 @@
package inventoryservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type QueryStockLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewQueryStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryStockLogic {
return &QueryStockLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// QueryStock 查詢單一商品的庫存
func (l *QueryStockLogic) QueryStock(in *trade.StockQueryReq) (*trade.StockResp, error) {
// todo: add your logic here and delete this line
return &trade.StockResp{}, nil
}

View File

@ -0,0 +1,31 @@
package inventoryservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ReduceStockLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewReduceStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReduceStockLogic {
return &ReduceStockLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// ReduceStock 減少庫存
func (l *ReduceStockLogic) ReduceStock(in *trade.StockAdjustmentReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package inventoryservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ReleaseReservedStockLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewReleaseReservedStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReleaseReservedStockLogic {
return &ReleaseReservedStockLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// ReleaseReservedStock 釋放預留庫存 (取消或失效的訂單)
func (l *ReleaseReservedStockLogic) ReleaseReservedStock(in *trade.StockReservationReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package inventoryservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ReserveStockLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewReserveStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReserveStockLogic {
return &ReserveStockLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// ReserveStock 預留庫存 (用於未完成的訂單)
func (l *ReserveStockLogic) ReserveStock(in *trade.StockReservationReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package orderservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CancelOrderLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCancelOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelOrderLogic {
return &CancelOrderLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CancelOrder 取消訂單
func (l *CancelOrderLogic) CancelOrder(in *trade.CancelOrderReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package orderservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateOrderLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrderLogic {
return &CreateOrderLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CreateOrder 建立訂單
func (l *CreateOrderLogic) CreateOrder(in *trade.CreateOrderReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package orderservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteOrderLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDeleteOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteOrderLogic {
return &DeleteOrderLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// DeleteOrder 刪除訂單(軟刪除)
func (l *DeleteOrderLogic) DeleteOrder(in *trade.DeleteOrderReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package orderservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type GetOrderLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderLogic {
return &GetOrderLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetOrder 取得訂單詳情
func (l *GetOrderLogic) GetOrder(in *trade.GetOrderReq) (*trade.GetOrderResp, error) {
// todo: add your logic here and delete this line
return &trade.GetOrderResp{}, nil
}

View File

@ -0,0 +1,31 @@
package orderservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ListOrderLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewListOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListOrderLogic {
return &ListOrderLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// ListOrder 取得訂單列表
func (l *ListOrderLogic) ListOrder(in *trade.ListOrderReq) (*trade.ListOrderResp, error) {
// todo: add your logic here and delete this line
return &trade.ListOrderResp{}, nil
}

View File

@ -0,0 +1,31 @@
package orderservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ModifyOrderStatusLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewModifyOrderStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ModifyOrderStatusLogic {
return &ModifyOrderStatusLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// ModifyOrderStatus 修改訂單狀態
func (l *ModifyOrderStatusLogic) ModifyOrderStatus(in *trade.ModifyOrderStatusReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package orderservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type OrderStatusTimeoutLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewOrderStatusTimeoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderStatusTimeoutLogic {
return &OrderStatusTimeoutLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// OrderStatusTimeout 訂單超時任務/cron/order-status/timeout
func (l *OrderStatusTimeoutLogic) OrderStatusTimeout(in *trade.OrderStatusTimeoutReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package productservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateProductLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateProductLogic {
return &CreateProductLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CreateProduct 新增商品
func (l *CreateProductLogic) CreateProduct(in *trade.ProductCreateReq) (*trade.ProductResp, error) {
// todo: add your logic here and delete this line
return &trade.ProductResp{}, nil
}

View File

@ -0,0 +1,31 @@
package productservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteProductLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDeleteProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteProductLogic {
return &DeleteProductLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// DeleteProduct 刪除商品
func (l *DeleteProductLogic) DeleteProduct(in *trade.ProductDeleteReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package productservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ListAllProductsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewListAllProductsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListAllProductsLogic {
return &ListAllProductsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// ListAllProducts 查詢所有商品資訊
func (l *ListAllProductsLogic) ListAllProducts(in *trade.ProductListReq) (*trade.ProductListResp, error) {
// todo: add your logic here and delete this line
return &trade.ProductListResp{}, nil
}

View File

@ -0,0 +1,31 @@
package productservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type QueryProductLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewQueryProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryProductLogic {
return &QueryProductLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// QueryProduct 查詢單一商品資訊
func (l *QueryProductLogic) QueryProduct(in *trade.ProductQueryReq) (*trade.ProductResp, error) {
// todo: add your logic here and delete this line
return &trade.ProductResp{}, nil
}

View File

@ -0,0 +1,31 @@
package productservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateProductLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateProductLogic {
return &UpdateProductLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// UpdateProduct 更新商品資訊
func (l *UpdateProductLogic) UpdateProduct(in *trade.ProductUpdateReq) (*trade.ProductResp, error) {
// todo: add your logic here and delete this line
return &trade.ProductResp{}, nil
}

View File

@ -0,0 +1,31 @@
package subscriptionservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CancelSubscriptionLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCancelSubscriptionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelSubscriptionLogic {
return &CancelSubscriptionLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CancelSubscription 取消訂閱
func (l *CancelSubscriptionLogic) CancelSubscription(in *trade.SubscriptionCancelReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package subscriptionservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CheckSubscriptionStatusLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCheckSubscriptionStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckSubscriptionStatusLogic {
return &CheckSubscriptionStatusLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CheckSubscriptionStatus 查詢訂閱狀態 (啟用/過期/取消)
func (l *CheckSubscriptionStatusLogic) CheckSubscriptionStatus(in *trade.SubscriptionStatusQueryReq) (*trade.SubscriptionStatusResp, error) {
// todo: add your logic here and delete this line
return &trade.SubscriptionStatusResp{}, nil
}

View File

@ -0,0 +1,31 @@
package subscriptionservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateSubscriptionLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateSubscriptionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSubscriptionLogic {
return &CreateSubscriptionLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CreateSubscription 建立訂閱
func (l *CreateSubscriptionLogic) CreateSubscription(in *trade.SubscriptionCreateReq) (*trade.SubscriptionResp, error) {
// todo: add your logic here and delete this line
return &trade.SubscriptionResp{}, nil
}

View File

@ -0,0 +1,31 @@
package subscriptionservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ListSubscriptionsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewListSubscriptionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListSubscriptionsLogic {
return &ListSubscriptionsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// ListSubscriptions 查詢所有訂閱 (用於管理和監控)
func (l *ListSubscriptionsLogic) ListSubscriptions(in *trade.ListSubscriptionsReq) (*trade.SubscriptionListResp, error) {
// todo: add your logic here and delete this line
return &trade.SubscriptionListResp{}, nil
}

View File

@ -0,0 +1,31 @@
package subscriptionservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type QuerySubscriptionLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewQuerySubscriptionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QuerySubscriptionLogic {
return &QuerySubscriptionLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// QuerySubscription 查詢單一訂閱資訊
func (l *QuerySubscriptionLogic) QuerySubscription(in *trade.SubscriptionQueryReq) (*trade.SubscriptionResp, error) {
// todo: add your logic here and delete this line
return &trade.SubscriptionResp{}, nil
}

View File

@ -0,0 +1,31 @@
package subscriptionservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type RefreshSubscriptionStatusLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewRefreshSubscriptionStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RefreshSubscriptionStatusLogic {
return &RefreshSubscriptionStatusLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// RefreshSubscriptionStatus cron 改變訂閱的狀態(時間到了要過期,需要續約自動續約),每 5 分鐘執行一次
func (l *RefreshSubscriptionStatusLogic) RefreshSubscriptionStatus(in *trade.NoneReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package subscriptionservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type RenewSubscriptionLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewRenewSubscriptionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RenewSubscriptionLogic {
return &RenewSubscriptionLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// RenewSubscription 續訂訂閱
func (l *RenewSubscriptionLogic) RenewSubscription(in *trade.SubscriptionRenewReq) (*trade.SubscriptionResp, error) {
// todo: add your logic here and delete this line
return &trade.SubscriptionResp{}, nil
}

View File

@ -0,0 +1,31 @@
package subscriptionservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateSubscriptionLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateSubscriptionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateSubscriptionLogic {
return &UpdateSubscriptionLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// UpdateSubscription 更新訂閱設定
func (l *UpdateSubscriptionLogic) UpdateSubscription(in *trade.SubscriptionUpdateReq) (*trade.SubscriptionResp, error) {
// todo: add your logic here and delete this line
return &trade.SubscriptionResp{}, nil
}

View File

@ -0,0 +1,31 @@
package walletservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type AppendToFreezeLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAppendToFreezeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppendToFreezeLogic {
return &AppendToFreezeLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// AppendToFreeze 追加凍結 - 減少可用餘額,追加到現有的 [凍結餘額] (基於原order_id)
func (l *AppendToFreezeLogic) AppendToFreeze(in *trade.WalletTransactionReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package walletservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CancelFreezeLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCancelFreezeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelFreezeLogic {
return &CancelFreezeLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CancelFreeze 取消凍結 - 減少 [凍結餘額],加回 [可用餘額],可指定金額
func (l *CancelFreezeLogic) CancelFreeze(in *trade.WalletTransactionReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package walletservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateWalletLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateWalletLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateWalletLogic {
return &CreateWalletLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CreateWallet 建立錢包
func (l *CreateWalletLogic) CreateWallet(in *trade.CreateWalletReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package walletservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type DepositFundsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDepositFundsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DepositFundsLogic {
return &DepositFundsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// DepositFunds 充值 - 增加 [可用餘額] 或 [限制餘額]
func (l *DepositFundsLogic) DepositFunds(in *trade.WalletTransactionReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package walletservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type FreezeFundsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewFreezeFundsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FreezeFundsLogic {
return &FreezeFundsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// FreezeFunds 凍結 - 將 [可用餘額] 減少,加到 [凍結餘額]
func (l *FreezeFundsLogic) FreezeFunds(in *trade.WalletTransactionReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package walletservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type QueryBalanceLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewQueryBalanceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryBalanceLogic {
return &QueryBalanceLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// QueryBalance 餘額查詢 -> 依照日期查詢
func (l *QueryBalanceLogic) QueryBalance(in *trade.QueryBalanceByDateReq) (*trade.QueryBalanceByDateResp, error) {
// todo: add your logic here and delete this line
return &trade.QueryBalanceByDateResp{}, nil
}

View File

@ -0,0 +1,31 @@
package walletservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type RollbackFreezeLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewRollbackFreezeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RollbackFreezeLogic {
return &RollbackFreezeLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// RollbackFreeze 凍結回滾 - 減少 [凍結餘額],加回 [可用餘額],不可指定金額,整筆訂單的凍結金額加回 [可用餘額]
func (l *RollbackFreezeLogic) RollbackFreeze(in *trade.WalletTransactionReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package walletservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type SettleRestrictedFundsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSettleRestrictedFundsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SettleRestrictedFundsLogic {
return &SettleRestrictedFundsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// SettleRestrictedFunds 結算限制餘額 - 限制餘額在 T+N 天後自動失效,每日只能執行一次
func (l *SettleRestrictedFundsLogic) SettleRestrictedFunds(in *trade.NoneReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package walletservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type TransferToRestrictedFundsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewTransferToRestrictedFundsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TransferToRestrictedFundsLogic {
return &TransferToRestrictedFundsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// TransferToRestrictedFunds 限制 - 減少 [凍結餘額],轉移到另一個使用者的 [限制餘額]
func (l *TransferToRestrictedFundsLogic) TransferToRestrictedFunds(in *trade.WalletTransactionReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package walletservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type UnfreezeFundsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUnfreezeFundsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnfreezeFundsLogic {
return &UnfreezeFundsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// UnfreezeFunds 解凍 - 減少 [凍結餘額]
func (l *UnfreezeFundsLogic) UnfreezeFunds(in *trade.WalletTransactionReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package walletservicelogic
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type WithdrawFundsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewWithdrawFundsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WithdrawFundsLogic {
return &WithdrawFundsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// WithdrawFunds 提現 - 減少 [可用餘額]
func (l *WithdrawFundsLogic) WithdrawFunds(in *trade.WalletTransactionReq) (*trade.OKResp, error) {
// todo: add your logic here and delete this line
return &trade.OKResp{}, nil
}

View File

@ -0,0 +1,59 @@
// Code generated by goctl. DO NOT EDIT.
// Source: trade.proto
package server
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/logic/couponservice"
"app-cloudep-trade-service/internal/svc"
)
type CouponServiceServer struct {
svcCtx *svc.ServiceContext
trade.UnimplementedCouponServiceServer
}
func NewCouponServiceServer(svcCtx *svc.ServiceContext) *CouponServiceServer {
return &CouponServiceServer{
svcCtx: svcCtx,
}
}
// CreateCoupon 創建優惠券
func (s *CouponServiceServer) CreateCoupon(ctx context.Context, in *trade.CreateCouponReq) (*trade.CouponResp, error) {
l := couponservicelogic.NewCreateCouponLogic(ctx, s.svcCtx)
return l.CreateCoupon(in)
}
// UpdateCoupon更新優惠券
func (s *CouponServiceServer) UpdateCoupon(ctx context.Context, in *trade.UpdateCouponReq) (*trade.CouponResp, error) {
l := couponservicelogic.NewUpdateCouponLogic(ctx, s.svcCtx)
return l.UpdateCoupon(in)
}
// QueryCoupon查詢優惠券
func (s *CouponServiceServer) QueryCoupon(ctx context.Context, in *trade.CouponQueryReq) (*trade.CouponResp, error) {
l := couponservicelogic.NewQueryCouponLogic(ctx, s.svcCtx)
return l.QueryCoupon(in)
}
// DeleteCoupon 刪除優惠券
func (s *CouponServiceServer) DeleteCoupon(ctx context.Context, in *trade.CouponQueryReq) (*trade.OKResp, error) {
l := couponservicelogic.NewDeleteCouponLogic(ctx, s.svcCtx)
return l.DeleteCoupon(in)
}
// ListCoupons列出所有優惠券
func (s *CouponServiceServer) ListCoupons(ctx context.Context, in *trade.CouponListReq) (*trade.CouponListResp, error) {
l := couponservicelogic.NewListCouponsLogic(ctx, s.svcCtx)
return l.ListCoupons(in)
}
// ValidateCoupon 驗證優惠券 (在下單或支付時使用)
func (s *CouponServiceServer) ValidateCoupon(ctx context.Context, in *trade.ValidateCouponReq) (*trade.CouponValidationResp, error) {
l := couponservicelogic.NewValidateCouponLogic(ctx, s.svcCtx)
return l.ValidateCoupon(in)
}

View File

@ -0,0 +1,71 @@
// Code generated by goctl. DO NOT EDIT.
// Source: trade.proto
package server
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/logic/inventoryservice"
"app-cloudep-trade-service/internal/svc"
)
type InventoryServiceServer struct {
svcCtx *svc.ServiceContext
trade.UnimplementedInventoryServiceServer
}
func NewInventoryServiceServer(svcCtx *svc.ServiceContext) *InventoryServiceServer {
return &InventoryServiceServer{
svcCtx: svcCtx,
}
}
// CreateStock 建立庫存品項
func (s *InventoryServiceServer) CreateStock(ctx context.Context, in *trade.StockAdjustmentReq) (*trade.OKResp, error) {
l := inventoryservicelogic.NewCreateStockLogic(ctx, s.svcCtx)
return l.CreateStock(in)
}
// AddStock 增加庫存
func (s *InventoryServiceServer) AddStock(ctx context.Context, in *trade.StockAdjustmentReq) (*trade.OKResp, error) {
l := inventoryservicelogic.NewAddStockLogic(ctx, s.svcCtx)
return l.AddStock(in)
}
// ReduceStock 減少庫存
func (s *InventoryServiceServer) ReduceStock(ctx context.Context, in *trade.StockAdjustmentReq) (*trade.OKResp, error) {
l := inventoryservicelogic.NewReduceStockLogic(ctx, s.svcCtx)
return l.ReduceStock(in)
}
// QueryStock 查詢單一商品的庫存
func (s *InventoryServiceServer) QueryStock(ctx context.Context, in *trade.StockQueryReq) (*trade.StockResp, error) {
l := inventoryservicelogic.NewQueryStockLogic(ctx, s.svcCtx)
return l.QueryStock(in)
}
// ListAllStock 查詢所有商品的庫存狀況
func (s *InventoryServiceServer) ListAllStock(ctx context.Context, in *trade.StockListReq) (*trade.StockListResp, error) {
l := inventoryservicelogic.NewListAllStockLogic(ctx, s.svcCtx)
return l.ListAllStock(in)
}
// ReserveStock 預留庫存 (用於未完成的訂單)
func (s *InventoryServiceServer) ReserveStock(ctx context.Context, in *trade.StockReservationReq) (*trade.OKResp, error) {
l := inventoryservicelogic.NewReserveStockLogic(ctx, s.svcCtx)
return l.ReserveStock(in)
}
// ReleaseReservedStock 釋放預留庫存 (取消或失效的訂單)
func (s *InventoryServiceServer) ReleaseReservedStock(ctx context.Context, in *trade.StockReservationReq) (*trade.OKResp, error) {
l := inventoryservicelogic.NewReleaseReservedStockLogic(ctx, s.svcCtx)
return l.ReleaseReservedStock(in)
}
// AdjustStock 調整庫存 (批量修改庫存,用於大批商品更新)
func (s *InventoryServiceServer) AdjustStock(ctx context.Context, in *trade.BatchStockAdjustmentReq) (*trade.OKResp, error) {
l := inventoryservicelogic.NewAdjustStockLogic(ctx, s.svcCtx)
return l.AdjustStock(in)
}

View File

@ -0,0 +1,65 @@
// Code generated by goctl. DO NOT EDIT.
// Source: trade.proto
package server
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/logic/orderservice"
"app-cloudep-trade-service/internal/svc"
)
type OrderServiceServer struct {
svcCtx *svc.ServiceContext
trade.UnimplementedOrderServiceServer
}
func NewOrderServiceServer(svcCtx *svc.ServiceContext) *OrderServiceServer {
return &OrderServiceServer{
svcCtx: svcCtx,
}
}
// CreateOrder 建立訂單
func (s *OrderServiceServer) CreateOrder(ctx context.Context, in *trade.CreateOrderReq) (*trade.OKResp, error) {
l := orderservicelogic.NewCreateOrderLogic(ctx, s.svcCtx)
return l.CreateOrder(in)
}
// CancelOrder 取消訂單
func (s *OrderServiceServer) CancelOrder(ctx context.Context, in *trade.CancelOrderReq) (*trade.OKResp, error) {
l := orderservicelogic.NewCancelOrderLogic(ctx, s.svcCtx)
return l.CancelOrder(in)
}
// ModifyOrderStatus 修改訂單狀態
func (s *OrderServiceServer) ModifyOrderStatus(ctx context.Context, in *trade.ModifyOrderStatusReq) (*trade.OKResp, error) {
l := orderservicelogic.NewModifyOrderStatusLogic(ctx, s.svcCtx)
return l.ModifyOrderStatus(in)
}
// DeleteOrder 刪除訂單(軟刪除)
func (s *OrderServiceServer) DeleteOrder(ctx context.Context, in *trade.DeleteOrderReq) (*trade.OKResp, error) {
l := orderservicelogic.NewDeleteOrderLogic(ctx, s.svcCtx)
return l.DeleteOrder(in)
}
// GetOrder 取得訂單詳情
func (s *OrderServiceServer) GetOrder(ctx context.Context, in *trade.GetOrderReq) (*trade.GetOrderResp, error) {
l := orderservicelogic.NewGetOrderLogic(ctx, s.svcCtx)
return l.GetOrder(in)
}
// ListOrder 取得訂單列表
func (s *OrderServiceServer) ListOrder(ctx context.Context, in *trade.ListOrderReq) (*trade.ListOrderResp, error) {
l := orderservicelogic.NewListOrderLogic(ctx, s.svcCtx)
return l.ListOrder(in)
}
// OrderStatusTimeout 訂單超時任務/cron/order-status/timeout
func (s *OrderServiceServer) OrderStatusTimeout(ctx context.Context, in *trade.OrderStatusTimeoutReq) (*trade.OKResp, error) {
l := orderservicelogic.NewOrderStatusTimeoutLogic(ctx, s.svcCtx)
return l.OrderStatusTimeout(in)
}

View File

@ -0,0 +1,53 @@
// Code generated by goctl. DO NOT EDIT.
// Source: trade.proto
package server
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/logic/productservice"
"app-cloudep-trade-service/internal/svc"
)
type ProductServiceServer struct {
svcCtx *svc.ServiceContext
trade.UnimplementedProductServiceServer
}
func NewProductServiceServer(svcCtx *svc.ServiceContext) *ProductServiceServer {
return &ProductServiceServer{
svcCtx: svcCtx,
}
}
// CreateProduct 新增商品
func (s *ProductServiceServer) CreateProduct(ctx context.Context, in *trade.ProductCreateReq) (*trade.ProductResp, error) {
l := productservicelogic.NewCreateProductLogic(ctx, s.svcCtx)
return l.CreateProduct(in)
}
// UpdateProduct 更新商品資訊
func (s *ProductServiceServer) UpdateProduct(ctx context.Context, in *trade.ProductUpdateReq) (*trade.ProductResp, error) {
l := productservicelogic.NewUpdateProductLogic(ctx, s.svcCtx)
return l.UpdateProduct(in)
}
// DeleteProduct 刪除商品
func (s *ProductServiceServer) DeleteProduct(ctx context.Context, in *trade.ProductDeleteReq) (*trade.OKResp, error) {
l := productservicelogic.NewDeleteProductLogic(ctx, s.svcCtx)
return l.DeleteProduct(in)
}
// QueryProduct 查詢單一商品資訊
func (s *ProductServiceServer) QueryProduct(ctx context.Context, in *trade.ProductQueryReq) (*trade.ProductResp, error) {
l := productservicelogic.NewQueryProductLogic(ctx, s.svcCtx)
return l.QueryProduct(in)
}
// ListAllProducts 查詢所有商品資訊
func (s *ProductServiceServer) ListAllProducts(ctx context.Context, in *trade.ProductListReq) (*trade.ProductListResp, error) {
l := productservicelogic.NewListAllProductsLogic(ctx, s.svcCtx)
return l.ListAllProducts(in)
}

View File

@ -0,0 +1,71 @@
// Code generated by goctl. DO NOT EDIT.
// Source: trade.proto
package server
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/logic/subscriptionservice"
"app-cloudep-trade-service/internal/svc"
)
type SubscriptionServiceServer struct {
svcCtx *svc.ServiceContext
trade.UnimplementedSubscriptionServiceServer
}
func NewSubscriptionServiceServer(svcCtx *svc.ServiceContext) *SubscriptionServiceServer {
return &SubscriptionServiceServer{
svcCtx: svcCtx,
}
}
// CreateSubscription 建立訂閱
func (s *SubscriptionServiceServer) CreateSubscription(ctx context.Context, in *trade.SubscriptionCreateReq) (*trade.SubscriptionResp, error) {
l := subscriptionservicelogic.NewCreateSubscriptionLogic(ctx, s.svcCtx)
return l.CreateSubscription(in)
}
// UpdateSubscription 更新訂閱設定
func (s *SubscriptionServiceServer) UpdateSubscription(ctx context.Context, in *trade.SubscriptionUpdateReq) (*trade.SubscriptionResp, error) {
l := subscriptionservicelogic.NewUpdateSubscriptionLogic(ctx, s.svcCtx)
return l.UpdateSubscription(in)
}
// CancelSubscription 取消訂閱
func (s *SubscriptionServiceServer) CancelSubscription(ctx context.Context, in *trade.SubscriptionCancelReq) (*trade.OKResp, error) {
l := subscriptionservicelogic.NewCancelSubscriptionLogic(ctx, s.svcCtx)
return l.CancelSubscription(in)
}
// QuerySubscription 查詢單一訂閱資訊
func (s *SubscriptionServiceServer) QuerySubscription(ctx context.Context, in *trade.SubscriptionQueryReq) (*trade.SubscriptionResp, error) {
l := subscriptionservicelogic.NewQuerySubscriptionLogic(ctx, s.svcCtx)
return l.QuerySubscription(in)
}
// ListSubscriptions 查詢所有訂閱 (用於管理和監控)
func (s *SubscriptionServiceServer) ListSubscriptions(ctx context.Context, in *trade.ListSubscriptionsReq) (*trade.SubscriptionListResp, error) {
l := subscriptionservicelogic.NewListSubscriptionsLogic(ctx, s.svcCtx)
return l.ListSubscriptions(in)
}
// RenewSubscription 續訂訂閱
func (s *SubscriptionServiceServer) RenewSubscription(ctx context.Context, in *trade.SubscriptionRenewReq) (*trade.SubscriptionResp, error) {
l := subscriptionservicelogic.NewRenewSubscriptionLogic(ctx, s.svcCtx)
return l.RenewSubscription(in)
}
// CheckSubscriptionStatus 查詢訂閱狀態 (啟用/過期/取消)
func (s *SubscriptionServiceServer) CheckSubscriptionStatus(ctx context.Context, in *trade.SubscriptionStatusQueryReq) (*trade.SubscriptionStatusResp, error) {
l := subscriptionservicelogic.NewCheckSubscriptionStatusLogic(ctx, s.svcCtx)
return l.CheckSubscriptionStatus(in)
}
// RefreshSubscriptionStatus cron 改變訂閱的狀態(時間到了要過期,需要續約自動續約),每 5 分鐘執行一次
func (s *SubscriptionServiceServer) RefreshSubscriptionStatus(ctx context.Context, in *trade.NoneReq) (*trade.OKResp, error) {
l := subscriptionservicelogic.NewRefreshSubscriptionStatusLogic(ctx, s.svcCtx)
return l.RefreshSubscriptionStatus(in)
}

View File

@ -0,0 +1,89 @@
// Code generated by goctl. DO NOT EDIT.
// Source: trade.proto
package server
import (
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/logic/walletservice"
"app-cloudep-trade-service/internal/svc"
)
type WalletServiceServer struct {
svcCtx *svc.ServiceContext
trade.UnimplementedWalletServiceServer
}
func NewWalletServiceServer(svcCtx *svc.ServiceContext) *WalletServiceServer {
return &WalletServiceServer{
svcCtx: svcCtx,
}
}
// CreateWallet 建立錢包
func (s *WalletServiceServer) CreateWallet(ctx context.Context, in *trade.CreateWalletReq) (*trade.OKResp, error) {
l := walletservicelogic.NewCreateWalletLogic(ctx, s.svcCtx)
return l.CreateWallet(in)
}
// DepositFunds 充值 - 增加 [可用餘額] 或 [限制餘額]
func (s *WalletServiceServer) DepositFunds(ctx context.Context, in *trade.WalletTransactionReq) (*trade.OKResp, error) {
l := walletservicelogic.NewDepositFundsLogic(ctx, s.svcCtx)
return l.DepositFunds(in)
}
// WithdrawFunds 提現 - 減少 [可用餘額]
func (s *WalletServiceServer) WithdrawFunds(ctx context.Context, in *trade.WalletTransactionReq) (*trade.OKResp, error) {
l := walletservicelogic.NewWithdrawFundsLogic(ctx, s.svcCtx)
return l.WithdrawFunds(in)
}
// FreezeFunds 凍結 - 將 [可用餘額] 減少,加到 [凍結餘額]
func (s *WalletServiceServer) FreezeFunds(ctx context.Context, in *trade.WalletTransactionReq) (*trade.OKResp, error) {
l := walletservicelogic.NewFreezeFundsLogic(ctx, s.svcCtx)
return l.FreezeFunds(in)
}
// UnfreezeFunds 解凍 - 減少 [凍結餘額]
func (s *WalletServiceServer) UnfreezeFunds(ctx context.Context, in *trade.WalletTransactionReq) (*trade.OKResp, error) {
l := walletservicelogic.NewUnfreezeFundsLogic(ctx, s.svcCtx)
return l.UnfreezeFunds(in)
}
// AppendToFreeze 追加凍結 - 減少可用餘額,追加到現有的 [凍結餘額] (基於原order_id)
func (s *WalletServiceServer) AppendToFreeze(ctx context.Context, in *trade.WalletTransactionReq) (*trade.OKResp, error) {
l := walletservicelogic.NewAppendToFreezeLogic(ctx, s.svcCtx)
return l.AppendToFreeze(in)
}
// RollbackFreeze 凍結回滾 - 減少 [凍結餘額],加回 [可用餘額],不可指定金額,整筆訂單的凍結金額加回 [可用餘額]
func (s *WalletServiceServer) RollbackFreeze(ctx context.Context, in *trade.WalletTransactionReq) (*trade.OKResp, error) {
l := walletservicelogic.NewRollbackFreezeLogic(ctx, s.svcCtx)
return l.RollbackFreeze(in)
}
// CancelFreeze 取消凍結 - 減少 [凍結餘額],加回 [可用餘額],可指定金額
func (s *WalletServiceServer) CancelFreeze(ctx context.Context, in *trade.WalletTransactionReq) (*trade.OKResp, error) {
l := walletservicelogic.NewCancelFreezeLogic(ctx, s.svcCtx)
return l.CancelFreeze(in)
}
// TransferToRestrictedFunds 限制 - 減少 [凍結餘額],轉移到另一個使用者的 [限制餘額]
func (s *WalletServiceServer) TransferToRestrictedFunds(ctx context.Context, in *trade.WalletTransactionReq) (*trade.OKResp, error) {
l := walletservicelogic.NewTransferToRestrictedFundsLogic(ctx, s.svcCtx)
return l.TransferToRestrictedFunds(in)
}
// SettleRestrictedFunds 結算限制餘額 - 限制餘額在 T+N 天後自動失效,每日只能執行一次
func (s *WalletServiceServer) SettleRestrictedFunds(ctx context.Context, in *trade.NoneReq) (*trade.OKResp, error) {
l := walletservicelogic.NewSettleRestrictedFundsLogic(ctx, s.svcCtx)
return l.SettleRestrictedFunds(in)
}
// QueryBalance 餘額查詢 -> 依照日期查詢
func (s *WalletServiceServer) QueryBalance(ctx context.Context, in *trade.QueryBalanceByDateReq) (*trade.QueryBalanceByDateResp, error) {
l := walletservicelogic.NewQueryBalanceLogic(ctx, s.svcCtx)
return l.QueryBalance(in)
}

View File

@ -0,0 +1,13 @@
package svc
import "app-cloudep-trade-service/internal/config"
type ServiceContext struct {
Config config.Config
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
}
}

49
trade.go Normal file
View File

@ -0,0 +1,49 @@
package main
import (
"flag"
"fmt"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/config"
couponserviceServer "app-cloudep-trade-service/internal/server/couponservice"
inventoryserviceServer "app-cloudep-trade-service/internal/server/inventoryservice"
orderserviceServer "app-cloudep-trade-service/internal/server/orderservice"
productserviceServer "app-cloudep-trade-service/internal/server/productservice"
subscriptionserviceServer "app-cloudep-trade-service/internal/server/subscriptionservice"
walletserviceServer "app-cloudep-trade-service/internal/server/walletservice"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/trade.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
trade.RegisterOrderServiceServer(grpcServer, orderserviceServer.NewOrderServiceServer(ctx))
trade.RegisterWalletServiceServer(grpcServer, walletserviceServer.NewWalletServiceServer(ctx))
trade.RegisterInventoryServiceServer(grpcServer, inventoryserviceServer.NewInventoryServiceServer(ctx))
trade.RegisterProductServiceServer(grpcServer, productserviceServer.NewProductServiceServer(ctx))
trade.RegisterSubscriptionServiceServer(grpcServer, subscriptionserviceServer.NewSubscriptionServiceServer(ctx))
trade.RegisterCouponServiceServer(grpcServer, couponserviceServer.NewCouponServiceServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}