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.
112 lines
2.7 KiB
112 lines
2.7 KiB
package live
|
|
|
|
import (
|
|
goods2 "recook/internal/api/mobile/goods"
|
|
"recook/internal/back"
|
|
"recook/internal/dbc"
|
|
"recook/internal/model/goods"
|
|
"recook/internal/model/order"
|
|
"recook/internal/model/user"
|
|
"recook/tools"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
type argsList struct {
|
|
Page
|
|
}
|
|
|
|
type Order struct {
|
|
}
|
|
|
|
// 获取商品列表
|
|
func (o *Order) History(c *gin.Context) {
|
|
id, err := strconv.Atoi(c.Request.Header.Get("X-Recook-ID"))
|
|
if id <= 0 || err != nil {
|
|
back.Fail(c, "游客无法使用该功能,请登录")
|
|
return
|
|
}
|
|
userId := getUserId(uint(id))
|
|
var uid uint64
|
|
if userId != "" {
|
|
uid, _ = strconv.ParseUint(userId, 10, 64)
|
|
} else {
|
|
login := &user.Login{}
|
|
dbc.DB.First(login, "id=?", id)
|
|
if login.UserID == 0 {
|
|
back.Fail(c, "游客无法使用该功能,请登录")
|
|
return
|
|
}
|
|
uid = uint64(login.UserID)
|
|
}
|
|
|
|
args := argsList{}
|
|
if err := tools.ParseParams(&args, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
var orderLists []order.GoodsDetail
|
|
start := (args.GetPage() - 1) * args.GetLimit()
|
|
|
|
total := 0
|
|
dbc.DB.Model(&order.GoodsDetail{}).Group("goods_id").Count(&total)
|
|
|
|
var goodsList []goods.Information
|
|
if total > start {
|
|
dbc.DB.Model(&order.GoodsDetail{}).
|
|
Select("max(id) id,goods_id").
|
|
//Where(` user_id = ?`, uid).
|
|
Limit(args.GetLimit()).
|
|
Offset(start).
|
|
Group("goods_id").
|
|
Order("id desc").
|
|
Find(&orderLists)
|
|
var goodsIds []uint
|
|
for _, orderItem := range orderLists {
|
|
goodsIds = append(goodsIds, orderItem.GoodsID)
|
|
}
|
|
dbc.DB.
|
|
Where(` id in (?)`, goodsIds).
|
|
Find(&goodsList)
|
|
}
|
|
back.Suc(c, "", gin.H{
|
|
"list": goods2.GetListByLive(goodsList, uint(id)),
|
|
"total": total,
|
|
})
|
|
}
|
|
|
|
type argsLiveData struct {
|
|
LiveId uint `json:"liveId" form:"liveId"`
|
|
LiveUserId uint `json:"liveUserId" form:"liveUserId"`
|
|
}
|
|
|
|
type replyLiveData struct {
|
|
UserCount uint `gorm:"column:userCount" json:"userCount"`
|
|
CommissionSum decimal.Decimal `gorm:"column:commissionSum" json:"commissionSum"`
|
|
AmountSum decimal.Decimal `gorm:"column:amountSum" json:"amountSum"`
|
|
}
|
|
|
|
// @Style 获取直播订单统计信息
|
|
func (o *Order) LiveOrderData(c *gin.Context) {
|
|
args := argsLiveData{}
|
|
if err := tools.ParseParams(&args, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
if args.LiveId <= 0 || args.LiveUserId <= 0 {
|
|
back.Fail(c, "参数不全")
|
|
return
|
|
}
|
|
goodsDetail := order.GoodsDetail{}
|
|
|
|
result := replyLiveData{}
|
|
dbc.DB.Model(goodsDetail).Select("Sum(total_commission) commissionSum, sum(goods_amount) amountSum,count(distinct user_id) userCount").
|
|
Where("live_id = ? and parent_id = ? and pay_status = ?", args.LiveId, args.LiveUserId, 1).
|
|
Scan(&result)
|
|
|
|
back.Suc(c, "操作成功", result)
|
|
}
|