This commit is contained in:
duyu 2024-07-17 17:04:25 +08:00
parent eb6f21487a
commit 81d3966130
6 changed files with 58 additions and 49 deletions

View File

@ -30,12 +30,12 @@ func GetById(c *gin.Context) {
if res != nil { if res != nil {
response = &proEnt.GetListByIdResp{ response = &proEnt.GetListByIdResp{
Id: res.Id, Id: res.Id,
Name: res.Name, Name: res.Name,
Price: res.Price, Price: res.Price,
PddUrl: res.PddUrl, ProductUrl: res.ProductUrl,
Status: res.Status, Status: res.Status,
CreatedAt: res.CreatedAt.Format(time.RFC3339), CreatedAt: res.CreatedAt.Format(time.RFC3339),
} }
} }
@ -72,12 +72,12 @@ func Search(c *gin.Context) {
if len(res) > 0 { if len(res) > 0 {
for _, item := range res { for _, item := range res {
response = append(response, &proEnt.SearchResp{ response = append(response, &proEnt.SearchResp{
Id: item.Id, Id: item.Id,
Name: item.Name, Name: item.Name,
Price: item.Price, Price: item.Price,
PddUrl: item.PddUrl, ProductUrl: item.ProductUrl,
Status: item.Status, Status: item.Status,
CreatedAt: item.CreatedAt.Format(time.RFC3339), CreatedAt: item.CreatedAt.Format(time.RFC3339),
}) })
} }
} }
@ -105,10 +105,10 @@ func Create(c *gin.Context) {
} }
product := &proMod.Product{ product := &proMod.Product{
Name: request.Name, Name: request.Name,
Price: request.Price, Price: request.Price,
PddUrl: request.PddUrl, ProductUrl: request.ProductUrl,
Status: 1, //1.上架 2.下架 Status: 1, //1.上架 2.下架
} }
affected, err := proServ.Create(product) affected, err := proServ.Create(product)
@ -133,10 +133,10 @@ func Update(c *gin.Context) {
} }
product := &proMod.Product{ product := &proMod.Product{
Id: request.Id, Id: request.Id,
Name: request.Name, Name: request.Name,
PddUrl: request.PddUrl, ProductUrl: request.ProductUrl,
Price: request.Price, Price: request.Price,
} }
affected, err := proServ.Update(product) affected, err := proServ.Update(product)

View File

@ -6,12 +6,13 @@ import (
common "com.snow.auto_monitor/app/http/controllers" common "com.snow.auto_monitor/app/http/controllers"
transEnt "com.snow.auto_monitor/app/http/entities/transfersys" transEnt "com.snow.auto_monitor/app/http/entities/transfersys"
orderMod "com.snow.auto_monitor/app/models/orders" 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" "github.com/gin-gonic/gin"
) )
func GetOrder(c *gin.Context) { func GetOrder(c *gin.Context) {
item, err := ransServ.ReadGroup() item, err := transServ.ReadGroup()
if err != nil { if err != nil {
common.Error(c, 400, err.Error()) common.Error(c, 400, err.Error())
return return
@ -19,12 +20,19 @@ func GetOrder(c *gin.Context) {
var response *transEnt.GetOrderResp = nil var response *transEnt.GetOrderResp = nil
product, err := proServ.GetById(item.ProductId)
if err != nil {
common.Error(c, 400, "产品不存在")
return
}
if item != nil { if item != nil {
response = &transEnt.GetOrderResp{ response = &transEnt.GetOrderResp{
Id: item.Id, Id: item.Id,
OrderNo: item.OrderNo, OrderNo: item.OrderNo,
MerchantId: item.MerchantId, MerchantId: item.MerchantId,
ProductId: item.ProductId, ProductId: item.ProductId,
ProductUrl: product.ProductUrl,
OutTradeNo: item.OutTradeNo, OutTradeNo: item.OutTradeNo,
RechargeAccount: item.RechargeAccount, RechargeAccount: item.RechargeAccount,
AccountType: item.AccountType, AccountType: item.AccountType,
@ -67,7 +75,7 @@ func FinishOrder(c *gin.Context) {
TransferStatus: int64(status), TransferStatus: int64(status),
} }
affected, err := ransServ.FinishOrder(orders) affected, err := transServ.FinishOrder(orders)
if err != nil || affected == 0 { if err != nil || affected == 0 {
common.Error(c, 400, "无法修改已完成订单") common.Error(c, 400, "无法修改已完成订单")
return return

View File

@ -5,12 +5,12 @@ type GetListByIdReq struct {
} }
type GetListByIdResp struct { type GetListByIdResp struct {
Id int64 `json:"id" example:"1"` Id int64 `json:"id" example:"1"`
Name string `json:"name" example:"snow"` Name string `json:"name" example:"snow"`
Price int64 `json:"price" example:"100"` Price int64 `json:"price" example:"100"`
PddUrl string `json:"pdd_url" example:"http://www.baidu.com"` ProductUrl string `json:"product_url" example:"http://www.baidu.com"`
Status int64 `json:"status" example:"1"` Status int64 `json:"status" example:"1"`
CreatedAt string `json:"created_at" example:"2020-01-01 00:00:00"` CreatedAt string `json:"created_at" example:"2020-01-01 00:00:00"`
} }
type SearcgReq struct { type SearcgReq struct {
@ -22,18 +22,18 @@ type SearcgReq struct {
} }
type SearchResp struct { type SearchResp struct {
Id int64 `json:"id" example:"1"` Id int64 `json:"id" example:"1"`
Name string `json:"name" example:"snow"` Name string `json:"name" example:"snow"`
Price int64 `json:"price" example:"100"` Price int64 `json:"price" example:"100"`
PddUrl string `json:"pdd_url" example:"http://www.baidu.com"` ProductUrl string `json:"product_url" example:"http://www.baidu.com"`
Status int64 `json:"status" example:"1"` Status int64 `json:"status" example:"1"`
CreatedAt string `json:"created_at" example:"2020-01-01 00:00:00"` CreatedAt string `json:"created_at" example:"2020-01-01 00:00:00"`
} }
type CreateReq struct { type CreateReq struct {
Name string `json:"name" validate:"required"` Name string `json:"name" validate:"required"`
Price int64 `json:"price" validate:"required"` Price int64 `json:"price" validate:"required"`
PddUrl string `json:"pdd_url" validate:"required"` ProductUrl string `json:"product_url" validate:"required"`
} }
type CreateResp struct { type CreateResp struct {
@ -41,10 +41,10 @@ type CreateResp struct {
} }
type UpdateReq struct { type UpdateReq struct {
Id int64 `json:"id" validate:"required"` Id int64 `json:"id" validate:"required"`
Name string `json:"name" ` Name string `json:"name" `
Price int64 `json:"price" ` Price int64 `json:"price" `
PddUrl string `json:"pdd_url" ` ProductUrl string `json:"product_url" `
} }
type UpdateResp struct { type UpdateResp struct {

View File

@ -8,6 +8,7 @@ type GetOrderResp struct {
OrderNo string `json:"order_no"` OrderNo string `json:"order_no"`
MerchantId int64 `json:"merchant_id"` MerchantId int64 `json:"merchant_id"`
ProductId int64 `json:"product_id"` ProductId int64 `json:"product_id"`
ProductUrl string `json:"product_url"`
OutTradeNo string `json:"out_trade_no"` OutTradeNo string `json:"out_trade_no"`
RechargeAccount string `json:"recharge_account"` RechargeAccount string `json:"recharge_account"`
AccountType int64 `json:"account_type"` AccountType int64 `json:"account_type"`

View File

@ -16,12 +16,12 @@ var (
* Product * Product
*/ */
type Product struct { type Product struct {
Id int64 `xorm:"pk autoincr"` //注使用getOne 或者ID() 需要设置主键 Id int64 `xorm:"pk autoincr"` //注使用getOne 或者ID() 需要设置主键
Name string Name string
Price int64 Price int64
PddUrl string ProductUrl string
Status int64 Status int64
CreatedAt time.Time `xorm:"created"` CreatedAt time.Time `xorm:"created"`
} }
/** /**

View File

@ -34,7 +34,7 @@ create table product (
id int primary key auto_increment, id int primary key auto_increment,
name varchar(255) not null, name varchar(255) not null,
price int, price int,
pdd_url varchar(255), product_url varchar(255),
status tinyint, -- 1.上架 2.下架 status tinyint, -- 1.上架 2.下架
created_at timestamp default current_timestamp created_at timestamp default current_timestamp
); );