From eb6f21487a700c29eaa35b3ab18f6d40c4fd2621 Mon Sep 17 00:00:00 2001 From: duyu Date: Wed, 17 Jul 2024 16:53:26 +0800 Subject: [PATCH] product --- app/http/controllers/product/product.go | 17 ++++++++++++----- app/http/entities/product/product.go | 16 +++++++++++----- app/models/product/product.go | 2 ++ build/sql/db.sql | 6 ++++-- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/http/controllers/product/product.go b/app/http/controllers/product/product.go index b4cdac8..0a6130a 100644 --- a/app/http/controllers/product/product.go +++ b/app/http/controllers/product/product.go @@ -33,6 +33,8 @@ func GetById(c *gin.Context) { Id: res.Id, Name: res.Name, Price: res.Price, + PddUrl: res.PddUrl, + Status: res.Status, CreatedAt: res.CreatedAt.Format(time.RFC3339), } } @@ -73,6 +75,8 @@ func Search(c *gin.Context) { Id: item.Id, Name: item.Name, Price: item.Price, + PddUrl: item.PddUrl, + Status: item.Status, CreatedAt: item.CreatedAt.Format(time.RFC3339), }) } @@ -101,8 +105,10 @@ func Create(c *gin.Context) { } product := &proMod.Product{ - Name: request.Name, - Price: request.Price, + Name: request.Name, + Price: request.Price, + PddUrl: request.PddUrl, + Status: 1, //1.上架 2.下架 } affected, err := proServ.Create(product) @@ -127,9 +133,10 @@ func Update(c *gin.Context) { } product := &proMod.Product{ - Id: request.Id, - Name: request.Name, - Price: request.Price, + Id: request.Id, + Name: request.Name, + PddUrl: request.PddUrl, + Price: request.Price, } affected, err := proServ.Update(product) diff --git a/app/http/entities/product/product.go b/app/http/entities/product/product.go index b22caeb..85e80dd 100644 --- a/app/http/entities/product/product.go +++ b/app/http/entities/product/product.go @@ -8,6 +8,8 @@ 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"` } @@ -23,12 +25,15 @@ 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"` } type CreateReq struct { - Name string `json:"name" validate:"required"` - Price int64 `json:"price" validate:"required"` + Name string `json:"name" validate:"required"` + Price int64 `json:"price" validate:"required"` + PddUrl string `json:"pdd_url" validate:"required"` } type CreateResp struct { @@ -36,9 +41,10 @@ type CreateResp struct { } type UpdateReq struct { - Id int64 `json:"id" validate:"required"` - Name string `json:"name" validate:"required"` - Price int64 `json:"price" validate:"required"` + Id int64 `json:"id" validate:"required"` + Name string `json:"name" ` + Price int64 `json:"price" ` + PddUrl string `json:"pdd_url" ` } type UpdateResp struct { diff --git a/app/models/product/product.go b/app/models/product/product.go index a058255..2b0196e 100644 --- a/app/models/product/product.go +++ b/app/models/product/product.go @@ -19,6 +19,8 @@ type Product struct { Id int64 `xorm:"pk autoincr"` //注:使用getOne 或者ID() 需要设置主键 Name string Price int64 + PddUrl string + Status int64 CreatedAt time.Time `xorm:"created"` } diff --git a/build/sql/db.sql b/build/sql/db.sql index d8f0c82..2dcb4a7 100644 --- a/build/sql/db.sql +++ b/build/sql/db.sql @@ -18,8 +18,8 @@ create table orders ( notify_url varchar(255), extend_parameter varchar(1024), - status tinyint, - transfer_status tinyint, + status tinyint,-- 1.成功 2.充值中 3.充值失败 4.异常需要人工处理 + transfer_status tinyint,-- 1.成功 2.充值中 3. 等待充值 4.充值失败 5.异常需要人工处理 created_at timestamp default current_timestamp ); @@ -34,5 +34,7 @@ create table product ( id int primary key auto_increment, name varchar(255) not null, price int, + pdd_url varchar(255), + status tinyint, -- 1.上架 2.下架 created_at timestamp default current_timestamp );