go
package model
import "time"
type ShoppingCart struct{
BaseModel
User int32 `gorm:"type:int;index"`
Goods int32 `gorm:"type:int;index"`
Nums int32 `gorm:"type:int"`
Checked bool
}
func (ShoppingCart) TableName() string {
return "shoppingcart"
}
type OrderInfo struct{
BaseModel
User int32 `gorm:"type:int;index"`
OrderSn string `gorm:"type:varchar(30);index"`
PayType string `gorm:"type:varchar(20) comment 'alipay(支付宝), wechat(微信)'"`
//status大家可以考虑使用iota来做
Status string `gorm:"type:varchar(20) comment 'PAYING(待支付), TRADE_SUCCESS(成功), TRADE_SUCCESS(超时关闭), WAIT_BUYER_PAY(交易创建), TRADE_FINISHED(交易结束)'"`
TradeNo string `gorm:"type:varchar(100) comment '交易号'"`
OrderMount float32
PayTime time.Time
Address string `gorm:"type:varchar(100)"`
SignerName string `gorm:"type:varchar(20)"`
SingerMobile string `gorm:"type:varchar(11)"`
Post string `gorm:"type:varchar(20)"`
}
func (OrderInfo) TableName() string {
return "orderinfo"
}
type OrderGoods struct{
BaseModel
Order int32 `gorm:"type:int;index"`
Goods int32 `gorm:"type:int;index"`
GoodsName string `gorm:"type:varchar(100);index"`
GoodsImage string `gorm:"type:varchar(200)"`
GoodsPrice float32
Nums int32 `gorm:"type:int"`
}
func (OrderGoods) TableName() string {
return "ordergoods"
}proto文件定义
protobuf
syntax = "proto3";
import "google/protobuf/empty.proto";
option go_package = ".;proto";
service Order {
//购物车
rpc CartItemList(UserInfo) returns(CartItemListResponse); //获取用户的购物车信息
rpc CreateCartItem(CartItemRequest) returns(ShopCartInfoResponse); //添加商品到购物车
rpc UpdateCartItem(CartItemRequest) returns(google.protobuf.Empty); //修改购物车记录
//订单
rpc Create(OrderRequest) returns (OrderInfoResponse); //创建订单
rpc OrderList(OrderFilterRequest) returns (OrderListResponse); // 订单列表
rpc OrderDetail(OrderRequest) returns (OrderInfoDetailResponse); // 订单详情
rpc UpdateOrderStatus(OrderStatus) returns (google.protobuf.Empty); // 修改订单状态
}
message UserInfo {
int32 id = 1;
}
message OrderStatus {
int32 id = 1;
string orderSn = 2;
string status = 3;
}
message CartItemRequest {
int32 id = 1;
int32 userId = 2;
int32 goodsId = 3;
string goodsName = 4;
string goodsImage = 5;
float goodsPrice = 6;
int32 nums = 7;
bool checked = 8;
}
message OrderRequest {
int32 id = 1;
int32 userId = 2;
string address = 3;
string name = 4;
string mobile = 5;
string post = 6;
}
message OrderInfoResponse {
int32 id = 1;
int32 userId = 2;
string orderSn = 3;
string payType = 4;
string status = 5;
string post = 6;
float total = 7;
string address = 8;
string name = 9;
string mobile = 10;
}
message ShopCartInfoResponse {
int32 id = 1;
int32 userId = 2;
int32 goodsId = 3;
int32 nums = 4;
bool checked = 5;
}
message OrderItemResponse {
int32 id = 1;
int32 orderId = 2;
int32 goodsId = 3;
string goodsName = 4;
string goodsImage = 5;
float goodsPrice = 6;
int32 nums = 7;
}
message OrderInfoDetailResponse {
OrderInfoResponse orderInfo = 1;
repeated OrderItemResponse goods = 2;
}
message OrderFilterRequest {
int32 userId = 1;
int32 pages = 2;
int32 pagePerNums = 3;
}
message OrderListResponse {
int32 total = 1;
repeated OrderInfoResponse data = 2;
}
message CartItemListResponse {
int32 total = 1;
repeated ShopCartInfoResponse data = 2;
}