You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
3.0 KiB
145 lines
3.0 KiB
package live
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
goods2 "recook/internal/api/mobile/goods"
|
|
"recook/internal/back"
|
|
"recook/internal/dbc"
|
|
"recook/internal/model/goods"
|
|
"recook/internal/model/order"
|
|
"recook/internal/service/app/shop"
|
|
"recook/tools"
|
|
"strconv"
|
|
)
|
|
|
|
type ArgsList struct {
|
|
Keyword string `json:"keyword" form:"keyword"`
|
|
BrandId uint `json:"brandId" form:"brandId"`
|
|
Page
|
|
}
|
|
|
|
func Profit(c *gin.Context) {
|
|
orderID := c.Query("id")
|
|
var od order.Information
|
|
dbc.DB.First(&od, "id = ?", orderID)
|
|
tx := dbc.DB.Begin()
|
|
if err := shop.OrderProfit(od, tx); err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
tx.Commit()
|
|
}
|
|
|
|
// List 获取商品列表
|
|
func List(c *gin.Context) {
|
|
id, err := strconv.Atoi(c.Request.Header.Get("X-Recook-ID"))
|
|
if id <= 0 || err != nil {
|
|
back.Fail(c, "游客无法使用该功能,请登录")
|
|
return
|
|
}
|
|
|
|
argsList := ArgsList{}
|
|
if err := tools.ParseParams(&argsList, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
if argsList.Keyword == "" && argsList.BrandId == 0 {
|
|
back.Fail(c, "参数不全")
|
|
return
|
|
}
|
|
|
|
var goodsList []goods.Information
|
|
start := (argsList.GetPage() - 1) * argsList.GetLimit()
|
|
|
|
total := 0
|
|
|
|
whereStr := "publish_status = 1"
|
|
whereValue := []interface{}{}
|
|
if argsList.Keyword != "" {
|
|
whereStr += " and goods_name like ?"
|
|
whereValue = append(whereValue, "%"+argsList.Keyword+"%")
|
|
}
|
|
if argsList.BrandId != 0 {
|
|
whereStr += " and brand_id = ?"
|
|
whereValue = append(whereValue, argsList.BrandId)
|
|
}
|
|
dbc.DB.Model(&goods.Information{}).
|
|
Where(whereStr, whereValue).Count(&total)
|
|
|
|
if total > start {
|
|
dbc.DB.
|
|
Where(whereStr, whereValue).
|
|
Limit(argsList.GetLimit()).
|
|
Offset(start).
|
|
Find(&goodsList)
|
|
}
|
|
|
|
back.Suc(c, "", gin.H{
|
|
"list": goods2.GetListByLive(goodsList, uint(id), false),
|
|
"total": total,
|
|
})
|
|
}
|
|
|
|
type ArgsListIds struct {
|
|
Ids []uint `json:"ids" form:"ids"`
|
|
}
|
|
|
|
// 根据商品id获取列表
|
|
func Infos(c *gin.Context) {
|
|
id, err := strconv.Atoi(c.Request.Header.Get("X-Recook-ID"))
|
|
if id <= 0 || err != nil {
|
|
back.Fail(c, "游客无法使用该功能,请登录")
|
|
return
|
|
}
|
|
|
|
argsListIds := ArgsListIds{}
|
|
if err := tools.ParseParams(&argsListIds, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
if len(argsListIds.Ids) == 0 {
|
|
back.Fail(c, "参数不全")
|
|
return
|
|
}
|
|
|
|
var goodsList []goods.Information
|
|
|
|
dbc.DB.
|
|
Where("id in (?)", argsListIds.Ids).
|
|
Find(&goodsList)
|
|
|
|
back.Suc(c, "", goods2.GetListByLive(goodsList, uint(id), false))
|
|
}
|
|
|
|
type ArgsBrand struct {
|
|
BrandID uint `json:"brandId" from:"brandId"`
|
|
Page
|
|
}
|
|
|
|
// @Style 品牌列表
|
|
func BrandList(c *gin.Context) {
|
|
argsBrand := ArgsBrand{}
|
|
if err := tools.ParseParams(&argsBrand, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
brands := []goods.Brand{}
|
|
start := (argsBrand.GetPage() - 1) * argsBrand.GetLimit()
|
|
|
|
total := 0
|
|
dbc.DB.Model(goods.Brand{}).Count(&total)
|
|
|
|
if total > start {
|
|
dbc.DB.Select("id, name, logo_url").
|
|
Limit(argsBrand.GetLimit()).
|
|
Offset(start).
|
|
Find(&brands)
|
|
}
|
|
|
|
back.Suc(c, "", gin.H{
|
|
"list": brands,
|
|
"total": total,
|
|
})
|
|
}
|