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.
158 lines
3.9 KiB
158 lines
3.9 KiB
package attention
|
|
|
|
import (
|
|
"git.oa00.com/go/mysql"
|
|
"recook/internal/back"
|
|
"recook/internal/dbc"
|
|
"recook/internal/model/attention"
|
|
"recook/internal/model/goods"
|
|
"recook/tools"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/jinzhu/gorm"
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
type queryParam struct {
|
|
UserID uint `json:"userId"`
|
|
Page uint `json:"page"`
|
|
}
|
|
|
|
type queryResp struct {
|
|
goods.MomentsCopy
|
|
IsAttention bool `json:"isAttention"`
|
|
IsOfficial bool `json:"isOfficial"`
|
|
Photos []goods.MomentsCopyPhoto `json:"photos"`
|
|
Goods Goods `json:"goods"`
|
|
}
|
|
|
|
type Goods struct {
|
|
ID uint `json:"id"`
|
|
MainPhotoURL string `json:"mainPhotoURL"`
|
|
Name string `json:"name"`
|
|
Price decimal.Decimal `json:"price"`
|
|
}
|
|
|
|
/*
|
|
关注列表 配套插入官方发布的素材
|
|
*/
|
|
func QueryMomentCopyList(c *gin.Context) {
|
|
var p queryParam
|
|
if err := tools.ParseParams(&p, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
//新增判断是否审核成功reviewing=0
|
|
var copyList []goods.MomentsCopy
|
|
if err := mysql.Db.Limit(20).Offset(int(p.Page*20)).Order("id desc").
|
|
Find(©List, "reviewing=? ", 0).Error; err != nil && gorm.IsRecordNotFoundError(err) == false {
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
//var copyList []goods.MomentsCopy
|
|
//if err := dbc.DB.Limit(20).Offset(p.Page*20).Order("id desc").
|
|
// Find(©List, "user_id IN (?) ", ids).Error; err != nil && gorm.IsRecordNotFoundError(err) == false {
|
|
// back.Err(c, err.Error())
|
|
// return
|
|
//}
|
|
|
|
list := make([]queryResp, 0)
|
|
for i, v := range copyList {
|
|
var photos []goods.MomentsCopyPhoto
|
|
dbc.DB.Find(&photos, "moments_copy_id = ?", copyList[i].ID)
|
|
|
|
var g goods.Information
|
|
dbc.DB.Select("id,goods_name").First(&g, copyList[i].GoodsID)
|
|
|
|
var mainPhoto goods.MainPhoto
|
|
dbc.DB.Select("url").First(&mainPhoto, "goods_id = ? AND is_master = 1", copyList[i].GoodsID)
|
|
|
|
var sku goods.Sku
|
|
dbc.DB.Select("goods_id, MIN(discount_price) AS discount_price").
|
|
Group("goods_id").
|
|
Find(&sku, "goods_id = ?", copyList[i].GoodsID)
|
|
|
|
isOfficial := true
|
|
if v.UserID > 0 {
|
|
isOfficial = false
|
|
}
|
|
|
|
list = append(list, queryResp{
|
|
copyList[i],
|
|
true,
|
|
isOfficial,
|
|
photos,
|
|
Goods{
|
|
ID: copyList[i].GoodsID,
|
|
MainPhotoURL: mainPhoto.URL,
|
|
Name: g.GoodsName,
|
|
Price: sku.DiscountPrice,
|
|
},
|
|
})
|
|
}
|
|
|
|
back.Suc(c, "", list)
|
|
}
|
|
|
|
/*
|
|
找没有关注过的人的id
|
|
*/
|
|
func QueryRecommendMomentCopyList(c *gin.Context) {
|
|
var p queryParam
|
|
if err := tools.ParseParams(&p, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
var atts []attention.Info
|
|
dbc.DB.Select("follow_id").Find(&atts, "user_id = ?", p.UserID)
|
|
|
|
ids := []uint{0}
|
|
for _, v := range atts {
|
|
ids = append(ids, v.FollowId)
|
|
}
|
|
|
|
var copyList []goods.MomentsCopy
|
|
if err := dbc.DB.Limit(20).Offset(p.Page*20).Order("id desc").Not("user_id", ids).
|
|
Find(©List, "reviewing=0").Error; err != nil && gorm.IsRecordNotFoundError(err) == false {
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
|
|
list := make([]queryResp, 0)
|
|
for i, v := range copyList {
|
|
var photos []goods.MomentsCopyPhoto
|
|
dbc.DB.Find(&photos, "moments_copy_id = ?", copyList[i].ID)
|
|
|
|
var g goods.Information
|
|
dbc.DB.Select("goods_name").First(&g, copyList[i].GoodsID)
|
|
|
|
var mainPhoto goods.MainPhoto
|
|
dbc.DB.Select("url").First(&mainPhoto, "goods_id = ? AND is_master = 1", copyList[i].GoodsID)
|
|
|
|
var sku goods.Sku
|
|
dbc.DB.Select("goods_id, MIN(discount_price) AS discount_price").Find(&sku, "goods_id = ?", copyList[i].GoodsID).Group("goods_id")
|
|
|
|
isOfficial := false
|
|
if v.UserID == 0 {
|
|
isOfficial = true
|
|
}
|
|
|
|
list = append(list, queryResp{
|
|
copyList[i],
|
|
false,
|
|
isOfficial,
|
|
photos,
|
|
Goods{
|
|
ID: copyList[i].GoodsID,
|
|
MainPhotoURL: mainPhoto.URL,
|
|
Name: g.GoodsName,
|
|
Price: sku.DiscountPrice,
|
|
},
|
|
})
|
|
}
|
|
|
|
back.Suc(c, "", list)
|
|
}
|