diff --git a/app/http/controllers/product/product.go b/app/http/controllers/product/product.go index 0a6130a..2a9cb29 100644 --- a/app/http/controllers/product/product.go +++ b/app/http/controllers/product/product.go @@ -30,12 +30,12 @@ func GetById(c *gin.Context) { if res != nil { response = &proEnt.GetListByIdResp{ - Id: res.Id, - Name: res.Name, - Price: res.Price, - PddUrl: res.PddUrl, - Status: res.Status, - CreatedAt: res.CreatedAt.Format(time.RFC3339), + Id: res.Id, + Name: res.Name, + Price: res.Price, + ProductUrl: res.ProductUrl, + Status: res.Status, + CreatedAt: res.CreatedAt.Format(time.RFC3339), } } @@ -72,12 +72,12 @@ func Search(c *gin.Context) { if len(res) > 0 { for _, item := range res { response = append(response, &proEnt.SearchResp{ - Id: item.Id, - Name: item.Name, - Price: item.Price, - PddUrl: item.PddUrl, - Status: item.Status, - CreatedAt: item.CreatedAt.Format(time.RFC3339), + Id: item.Id, + Name: item.Name, + Price: item.Price, + ProductUrl: item.ProductUrl, + Status: item.Status, + CreatedAt: item.CreatedAt.Format(time.RFC3339), }) } } @@ -105,10 +105,10 @@ func Create(c *gin.Context) { } product := &proMod.Product{ - Name: request.Name, - Price: request.Price, - PddUrl: request.PddUrl, - Status: 1, //1.上架 2.下架 + Name: request.Name, + Price: request.Price, + ProductUrl: request.ProductUrl, + Status: 1, //1.上架 2.下架 } affected, err := proServ.Create(product) @@ -133,10 +133,10 @@ func Update(c *gin.Context) { } product := &proMod.Product{ - Id: request.Id, - Name: request.Name, - PddUrl: request.PddUrl, - Price: request.Price, + Id: request.Id, + Name: request.Name, + ProductUrl: request.ProductUrl, + Price: request.Price, } affected, err := proServ.Update(product) diff --git a/app/http/controllers/transfersys/transfersys.go b/app/http/controllers/transfersys/transfersys.go index 2b904c1..10687c0 100644 --- a/app/http/controllers/transfersys/transfersys.go +++ b/app/http/controllers/transfersys/transfersys.go @@ -6,12 +6,13 @@ import ( common "com.snow.auto_monitor/app/http/controllers" transEnt "com.snow.auto_monitor/app/http/entities/transfersys" orderMod "com.snow.auto_monitor/app/models/orders" - ransServ "com.snow.auto_monitor/app/services/transfersys" + proServ "com.snow.auto_monitor/app/services/product" + transServ "com.snow.auto_monitor/app/services/transfersys" "github.com/gin-gonic/gin" ) func GetOrder(c *gin.Context) { - item, err := ransServ.ReadGroup() + item, err := transServ.ReadGroup() if err != nil { common.Error(c, 400, err.Error()) return @@ -19,12 +20,19 @@ func GetOrder(c *gin.Context) { var response *transEnt.GetOrderResp = nil + product, err := proServ.GetById(item.ProductId) + if err != nil { + common.Error(c, 400, "产品不存在") + return + } + if item != nil { response = &transEnt.GetOrderResp{ Id: item.Id, OrderNo: item.OrderNo, MerchantId: item.MerchantId, ProductId: item.ProductId, + ProductUrl: product.ProductUrl, OutTradeNo: item.OutTradeNo, RechargeAccount: item.RechargeAccount, AccountType: item.AccountType, @@ -67,7 +75,7 @@ func FinishOrder(c *gin.Context) { TransferStatus: int64(status), } - affected, err := ransServ.FinishOrder(orders) + affected, err := transServ.FinishOrder(orders) if err != nil || affected == 0 { common.Error(c, 400, "无法修改已完成订单") return diff --git a/app/http/entities/product/product.go b/app/http/entities/product/product.go index 85e80dd..648ed94 100644 --- a/app/http/entities/product/product.go +++ b/app/http/entities/product/product.go @@ -5,12 +5,12 @@ type GetListByIdReq struct { } type GetListByIdResp struct { - Id int64 `json:"id" example:"1"` - Name string `json:"name" example:"snow"` - Price int64 `json:"price" example:"100"` - PddUrl string `json:"pdd_url" example:"http://www.baidu.com"` - Status int64 `json:"status" example:"1"` - CreatedAt string `json:"created_at" example:"2020-01-01 00:00:00"` + Id int64 `json:"id" example:"1"` + Name string `json:"name" example:"snow"` + Price int64 `json:"price" example:"100"` + ProductUrl string `json:"product_url" example:"http://www.baidu.com"` + Status int64 `json:"status" example:"1"` + CreatedAt string `json:"created_at" example:"2020-01-01 00:00:00"` } type SearcgReq struct { @@ -22,18 +22,18 @@ type SearcgReq struct { } type SearchResp struct { - Id int64 `json:"id" example:"1"` - Name string `json:"name" example:"snow"` - Price int64 `json:"price" example:"100"` - PddUrl string `json:"pdd_url" example:"http://www.baidu.com"` - Status int64 `json:"status" example:"1"` - CreatedAt string `json:"created_at" example:"2020-01-01 00:00:00"` + Id int64 `json:"id" example:"1"` + Name string `json:"name" example:"snow"` + Price int64 `json:"price" example:"100"` + ProductUrl string `json:"product_url" example:"http://www.baidu.com"` + Status int64 `json:"status" example:"1"` + CreatedAt string `json:"created_at" example:"2020-01-01 00:00:00"` } type CreateReq struct { - Name string `json:"name" validate:"required"` - Price int64 `json:"price" validate:"required"` - PddUrl string `json:"pdd_url" validate:"required"` + Name string `json:"name" validate:"required"` + Price int64 `json:"price" validate:"required"` + ProductUrl string `json:"product_url" validate:"required"` } type CreateResp struct { @@ -41,10 +41,10 @@ type CreateResp struct { } type UpdateReq struct { - Id int64 `json:"id" validate:"required"` - Name string `json:"name" ` - Price int64 `json:"price" ` - PddUrl string `json:"pdd_url" ` + Id int64 `json:"id" validate:"required"` + Name string `json:"name" ` + Price int64 `json:"price" ` + ProductUrl string `json:"product_url" ` } type UpdateResp struct { diff --git a/app/http/entities/transfersys/transfersys.go b/app/http/entities/transfersys/transfersys.go index 7ed1cff..b70e784 100644 --- a/app/http/entities/transfersys/transfersys.go +++ b/app/http/entities/transfersys/transfersys.go @@ -8,6 +8,7 @@ type GetOrderResp struct { OrderNo string `json:"order_no"` MerchantId int64 `json:"merchant_id"` ProductId int64 `json:"product_id"` + ProductUrl string `json:"product_url"` OutTradeNo string `json:"out_trade_no"` RechargeAccount string `json:"recharge_account"` AccountType int64 `json:"account_type"` diff --git a/app/models/product/product.go b/app/models/product/product.go index 2b0196e..16ffb0e 100644 --- a/app/models/product/product.go +++ b/app/models/product/product.go @@ -16,12 +16,12 @@ var ( * Product */ type Product struct { - Id int64 `xorm:"pk autoincr"` //注:使用getOne 或者ID() 需要设置主键 - Name string - Price int64 - PddUrl string - Status int64 - CreatedAt time.Time `xorm:"created"` + Id int64 `xorm:"pk autoincr"` //注:使用getOne 或者ID() 需要设置主键 + Name string + Price int64 + ProductUrl string + Status int64 + CreatedAt time.Time `xorm:"created"` } /** diff --git a/build/sql/db.sql b/build/sql/db.sql index 2dcb4a7..bbb42ec 100644 --- a/build/sql/db.sql +++ b/build/sql/db.sql @@ -34,7 +34,7 @@ create table product ( id int primary key auto_increment, name varchar(255) not null, price int, - pdd_url varchar(255), + product_url varchar(255), status tinyint, -- 1.上架 2.下架 created_at timestamp default current_timestamp );