fix
This commit is contained in:
parent
73a3f0616d
commit
22c164c780
|
@ -41,61 +41,62 @@ func GetById(c *gin.Context) {
|
||||||
common.Success(c, response)
|
common.Success(c, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
// func Search(c *gin.Context) {
|
func Search(c *gin.Context) {
|
||||||
// request := new(proEnt.SearcgReq)
|
request := new(proEnt.SearcgReq)
|
||||||
// err := common.GenRequest(c, request)
|
err := common.GenRequest(c, request)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// common.Error(c, errorcode.ParamError)
|
common.Error(c, errorcode.ParamError)
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
// start, end := "", ""
|
start, end := "", ""
|
||||||
// if len(request.CreatedAt) > 1 {
|
if len(request.CreatedAt) > 1 {
|
||||||
// start = request.CreatedAt[0]
|
start = request.CreatedAt[0]
|
||||||
// end = request.CreatedAt[1]
|
end = request.CreatedAt[1]
|
||||||
// }
|
}
|
||||||
// res, err := proServ.Search(
|
res, err := proServ.Search(
|
||||||
// request.Id,
|
request.Id,
|
||||||
// request.Name,
|
request.DeviceNo,
|
||||||
// start,
|
request.Phone,
|
||||||
// end,
|
request.Code,
|
||||||
// request.PageSize,
|
start,
|
||||||
// request.PageNum,
|
end,
|
||||||
// )
|
request.PageSize,
|
||||||
// if err != nil {
|
request.PageNum,
|
||||||
// common.Error500(c)
|
)
|
||||||
// return
|
if err != nil {
|
||||||
// }
|
common.Error500(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// var response []*proEnt.SearchResp = nil
|
var response []*proEnt.SearchResp = nil
|
||||||
|
|
||||||
// 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,
|
DeviceNo: item.DeviceNo,
|
||||||
// Price: item.Price,
|
Phone: item.Phone,
|
||||||
// DeviceUrl: item.DeviceUrl,
|
Code: item.Code,
|
||||||
// Status: item.Status,
|
CreatedAt: item.CreatedAt.Format(time.RFC3339),
|
||||||
// CreatedAt: item.CreatedAt.Format(time.RFC3339),
|
})
|
||||||
// Type: item.Type,
|
}
|
||||||
// ExtendParameter: item.ExtendParameter,
|
}
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// total, err := proServ.CountAll(
|
total, err := proServ.CountAll(
|
||||||
// request.Id,
|
request.Id,
|
||||||
// request.Name,
|
request.DeviceNo,
|
||||||
// start,
|
request.Phone,
|
||||||
// end,
|
request.Code,
|
||||||
// )
|
start,
|
||||||
// if err != nil {
|
end,
|
||||||
// common.Error500(c)
|
)
|
||||||
// return
|
if err != nil {
|
||||||
// }
|
common.Error500(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// common.SuccessWithList(c, response, total)
|
common.SuccessWithList(c, response, total)
|
||||||
// }
|
}
|
||||||
|
|
||||||
func Create(c *gin.Context) {
|
func Create(c *gin.Context) {
|
||||||
request := new(proEnt.CreateReq)
|
request := new(proEnt.CreateReq)
|
||||||
|
|
|
@ -12,24 +12,23 @@ type GetListByIdResp struct {
|
||||||
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 {
|
||||||
// Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
// Name string `json:"name"`
|
DeviceNo string `json:"device_no" form:"device_no"`
|
||||||
// CreatedAt []string `json:"created_at" form:"created_at"`
|
Phone string `json:"phone" form:"phone"`
|
||||||
// PageNum int `json:"page_num" form:"page" validate:"required"`
|
Code int64 `json:"code" form:"code"`
|
||||||
// PageSize int `json:"page_size" form:"page_size" validate:"required"`
|
CreatedAt []string `json:"created_at" form:"created_at"`
|
||||||
// }
|
PageNum int `json:"page_num" form:"page" validate:"required"`
|
||||||
|
PageSize int `json:"page_size" form:"page_size" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
// type SearchResp struct {
|
type SearchResp struct {
|
||||||
// Id int64 `json:"id" example:"1"`
|
Id int64 `json:"id" validate:"required"`
|
||||||
// Name string `json:"name" example:"snow"`
|
DeviceNo string `json:"device_no" example:"123456"`
|
||||||
// Price int64 `json:"price" example:"100"`
|
Phone string `json:"phone" example:"123456"`
|
||||||
// ProductUrl string `json:"product_url" example:"http://www.baidu.com"`
|
Code int64 `json:"code" example:"123456"`
|
||||||
// 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 int64 `json:"type" example:"1"`
|
|
||||||
// ExtendParameter string `json:"extend_parameter" example:"{}"`
|
|
||||||
// }
|
|
||||||
|
|
||||||
type CreateReq struct {
|
type CreateReq struct {
|
||||||
DeviceNo string `json:"device_no" example:"123456"`
|
DeviceNo string `json:"device_no" example:"123456"`
|
||||||
|
|
|
@ -94,7 +94,7 @@ func RegisterRoute(router *gin.Engine) {
|
||||||
// product.Use(middlewares.VerifyHtmlIp())
|
// product.Use(middlewares.VerifyHtmlIp())
|
||||||
{
|
{
|
||||||
device.POST("/get_by_id", devCon.GetById)
|
device.POST("/get_by_id", devCon.GetById)
|
||||||
// device.POST("/search", devCon.Search)
|
device.POST("/search", devCon.Search)
|
||||||
device.POST("/create", devCon.Create)
|
device.POST("/create", devCon.Create)
|
||||||
device.POST("/update", devCon.Update)
|
device.POST("/update", devCon.Update)
|
||||||
device.POST("/delete", devCon.Delete)
|
device.POST("/delete", devCon.Delete)
|
||||||
|
|
|
@ -63,44 +63,60 @@ func (m *deviceModel) GetById(id int64) (device *Device, has bool, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (m *deviceModel) Search(id int64, name string, startTime string, endTime string, limit int, page int) (device []*Device, err error) {
|
func (m *deviceModel) Search(id int64, device_no string, phone string, code int64, startTime string, endTime string, limit int, page int) (device []*Device, err error) {
|
||||||
// device = make([]*Device, 0)
|
device = make([]*Device, 0)
|
||||||
// sql := "1=1"
|
sql := "1=1"
|
||||||
// var args []interface{}
|
var args []interface{}
|
||||||
// if id != 0 {
|
if id != 0 {
|
||||||
// sql += " and id = ?"
|
sql += " and id = ?"
|
||||||
// args = append(args, id)
|
args = append(args, id)
|
||||||
// }
|
}
|
||||||
// if name != "" {
|
if device_no != "" {
|
||||||
// sql += " and name = ?"
|
sql += " and device_no = ?"
|
||||||
// args = append(args, name)
|
args = append(args, device_no)
|
||||||
// }
|
}
|
||||||
// if startTime != "" && endTime != "" {
|
if phone != "" {
|
||||||
// sql += " and created_at >= ? and created_at <= ?"
|
sql += " and phone = ?"
|
||||||
// args = append(args, startTime, endTime)
|
args = append(args, phone)
|
||||||
// }
|
}
|
||||||
// err = m.GetDb().Where(sql, args...).OrderBy("created_at desc").Limit(limit, page).Find(&device)
|
if code != 0 {
|
||||||
// return
|
sql += " and code = ?"
|
||||||
// }
|
args = append(args, code)
|
||||||
|
}
|
||||||
|
if startTime != "" && endTime != "" {
|
||||||
|
sql += " and created_at >= ? and created_at <= ?"
|
||||||
|
args = append(args, startTime, endTime)
|
||||||
|
}
|
||||||
|
err = m.GetDb().Where(sql, args...).OrderBy("created_at desc").Limit(limit, page).Find(&device)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// func (m *deviceModel) CountAll(id int64, name string, startTime string, endTime string) (res int64, err error) {
|
func (m *deviceModel) CountAll(id int64, device_no string, phone string, code int64, startTime string, endTime string) (res int64, err error) {
|
||||||
// sql := "1=1"
|
sql := "1=1"
|
||||||
// var args []interface{}
|
var args []interface{}
|
||||||
// if id != 0 {
|
if id != 0 {
|
||||||
// sql += " and id = ?"
|
sql += " and id = ?"
|
||||||
// args = append(args, id)
|
args = append(args, id)
|
||||||
// }
|
}
|
||||||
// if name != "" {
|
if device_no != "" {
|
||||||
// sql += " and name = ?"
|
sql += " and device_no = ?"
|
||||||
// args = append(args, name)
|
args = append(args, device_no)
|
||||||
// }
|
}
|
||||||
// if startTime != "" && endTime != "" {
|
if phone != "" {
|
||||||
// sql += " and created_at >= ? and created_at <= ?"
|
sql += " and phone = ?"
|
||||||
// args = append(args, startTime, endTime)
|
args = append(args, phone)
|
||||||
// }
|
}
|
||||||
// res, err = m.GetDb().Table("device").Where(sql, args...).Count()
|
if code != 0 {
|
||||||
// return
|
sql += " and code = ?"
|
||||||
// }
|
args = append(args, code)
|
||||||
|
}
|
||||||
|
if startTime != "" && endTime != "" {
|
||||||
|
sql += " and created_at >= ? and created_at <= ?"
|
||||||
|
args = append(args, startTime, endTime)
|
||||||
|
}
|
||||||
|
res, err = m.GetDb().Table("device").Where(sql, args...).Count()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (m *deviceModel) Create(device *Device) (affected int64, err error) {
|
func (m *deviceModel) Create(device *Device) (affected int64, err error) {
|
||||||
device.CreatedAt = time.Now()
|
device.CreatedAt = time.Now()
|
||||||
|
|
|
@ -22,7 +22,6 @@ type Orders struct {
|
||||||
OrderNo string
|
OrderNo string
|
||||||
MerchantId int64
|
MerchantId int64
|
||||||
ProductId int64
|
ProductId int64
|
||||||
DeviceNo string
|
|
||||||
|
|
||||||
OutTradeNo string
|
OutTradeNo string
|
||||||
RechargeAccount string
|
RechargeAccount string
|
||||||
|
@ -34,6 +33,7 @@ type Orders struct {
|
||||||
Status int64
|
Status int64
|
||||||
TransferStatus int64
|
TransferStatus int64
|
||||||
FailReason string
|
FailReason string
|
||||||
|
DeviceNo string
|
||||||
CreatedAt time.Time `xorm:"created"`
|
CreatedAt time.Time `xorm:"created"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,16 +21,16 @@ func GetById(id int64) (res *models.Device, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// func Search(id int64, name string, startTime string, endTime string, limit int, page int) (res []*models.Device, err error) {
|
func Search(id int64, device_no string,phone string,code int64, startTime string, endTime string, limit int, page int) (res []*models.Device, err error) {
|
||||||
// limit, page = GetLimitStart(limit, page)
|
limit, page = GetLimitStart(limit, page)
|
||||||
// res, err = models.GetInstance().Search(id, name, startTime, endTime, limit, page)
|
res, err = models.GetInstance().Search(id, device_no,phone,code, startTime, endTime, limit, page)
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func CountAll(id int64, name string, startTime string, endTime string) (res int64, err error) {
|
func CountAll(id int64, device_no string,phone string,code int64, startTime string, endTime string) (res int64, err error) {
|
||||||
// res, err = models.GetInstance().CountAll(id, name, startTime, endTime)
|
res, err = models.GetInstance().CountAll(id, device_no,phone,code, startTime, endTime)
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
|
|
||||||
func Create(device *models.Device) (affected int64, err error) {
|
func Create(device *models.Device) (affected int64, err error) {
|
||||||
affected, err = models.GetInstance().Create(device)
|
affected, err = models.GetInstance().Create(device)
|
||||||
|
|
Loading…
Reference in New Issue