|
|
|
@ -2,21 +2,15 @@ package shopping
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
mysql2 "git.oa00.com/go/mysql"
|
|
|
|
|
"github.com/golangkit/formatime"
|
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
|
"math/rand"
|
|
|
|
|
goods3 "recook/internal/api/mobile/goods"
|
|
|
|
|
"recook/internal/cache"
|
|
|
|
|
"recook/internal/dbc"
|
|
|
|
|
"recook/internal/model/goods"
|
|
|
|
|
"recook/internal/v2/model/keywords"
|
|
|
|
|
goods2 "recook/internal/v2/model/recook/goods"
|
|
|
|
|
"recook/internal/v2/model/recook/user"
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
mysql2 "git.oa00.com/go/mysql"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"github.com/golangkit/formatime"
|
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
|
"gorm.io/gorm/clause"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type logic struct {
|
|
|
|
@ -66,127 +60,128 @@ func (l logic) ViewLike(id uint, userID uint, isSale bool) []goods3.QueryCategor
|
|
|
|
|
}
|
|
|
|
|
var likeList []int
|
|
|
|
|
dbc.DB.Table((&goods2.Associate{}).TableName()).Where("goods_id=?", id).Pluck("other_goods_id", &likeList)
|
|
|
|
|
var newlike []int
|
|
|
|
|
var newLike []int
|
|
|
|
|
num := rand.Perm(len(likeList))
|
|
|
|
|
for _, v := range num {
|
|
|
|
|
newlike = append(newlike, likeList[v])
|
|
|
|
|
if len(newlike) == 10 {
|
|
|
|
|
newLike = append(newLike, likeList[v])
|
|
|
|
|
if len(newLike) == 10 {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var goodsList []goods.Information
|
|
|
|
|
dbc.DB.Table((&goods.Information{}).TableName()).Where("publish_status = 1").Where("id in(?)", newlike).Find(&goodsList)
|
|
|
|
|
dbc.DB.Table((&goods.Information{}).TableName()).Where("publish_status = 1").Where("id in(?)", newLike).Find(&goodsList)
|
|
|
|
|
return goods3.GetGoodsRespByInfoList(goodsList, userID, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//ViewLikeMayBe 可能喜欢的商品
|
|
|
|
|
func (l logic) ViewLikeMayBe(c *gin.Context, userId uint) []goods3.QueryCategoryGoodsListResp {
|
|
|
|
|
func (l logic) ViewLikeMayBe(userId uint, isSale bool) []goods3.QueryCategoryGoodsListResp {
|
|
|
|
|
//浏览过的商品
|
|
|
|
|
var kewords []string
|
|
|
|
|
mysql2.Db.Table((&keywords.RecookUserKeywordsModel{}).TableName()).Where("user_id=?", userId).Limit(10).Pluck("keywords", &kewords)
|
|
|
|
|
var kw []string
|
|
|
|
|
mysql2.Db.Table((&keywords.RecookUserKeywordsModel{}).TableName()).Where("user_id=?", userId).Limit(10).Pluck("keywords", &kw)
|
|
|
|
|
where := mysql2.Db.Where("publish_status = 1")
|
|
|
|
|
for _, v := range kewords {
|
|
|
|
|
if isSale {
|
|
|
|
|
where = mysql2.Db.Where("sale_publish = 1 and is_sale=1")
|
|
|
|
|
}
|
|
|
|
|
for _, v := range kw {
|
|
|
|
|
where = where.Where("goods_name like ?", fmt.Sprintf("%%%v%%", v))
|
|
|
|
|
}
|
|
|
|
|
var goodsList []goods.Information
|
|
|
|
|
if len(kewords) > 0 {
|
|
|
|
|
if len(kw) > 0 {
|
|
|
|
|
mysql2.Db.Table((&goods.Information{}).TableName()).Where(where).Find(&goodsList)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("sql:", len(goodsList))
|
|
|
|
|
var newgoodsList []goods.Information
|
|
|
|
|
var newGoodsList []goods.Information
|
|
|
|
|
if len(goodsList) >= 20 {
|
|
|
|
|
num := rand.Perm(len(goodsList))
|
|
|
|
|
num1 := num[:20]
|
|
|
|
|
for _, v := range num1 {
|
|
|
|
|
newgoodsList = append(newgoodsList, goodsList[v])
|
|
|
|
|
newGoodsList = append(newGoodsList, goodsList[v])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(goodsList) < 20 {
|
|
|
|
|
newgoodsList = getFillList(c, goodsList, "")
|
|
|
|
|
}
|
|
|
|
|
return goods3.GetGoodsRespByInfoList(newgoodsList, userId, false)
|
|
|
|
|
return goods3.GetGoodsRespByInfoList(newGoodsList, userId, isSale)
|
|
|
|
|
}
|
|
|
|
|
func getFillList(c *gin.Context, goodsList []goods.Information, volSort string) []goods.Information {
|
|
|
|
|
// 显示记录太少
|
|
|
|
|
// 1.用浏览历史记录填充
|
|
|
|
|
// 2.用T1 - T4商品记录填充
|
|
|
|
|
|
|
|
|
|
uid, _ := strconv.Atoi(c.Request.Header.Get("X-Recook-ID"))
|
|
|
|
|
deviceType := cache.GetDeviceType(c)
|
|
|
|
|
recookUserLoginModel := user.RecookUserLoginModel{}
|
|
|
|
|
tokenInfo := recookUserLoginModel.FindByIdAndDeviceType(uint(uid), deviceType)
|
|
|
|
|
|
|
|
|
|
// 购买记录
|
|
|
|
|
s11 := mysql2.Db.Select("goods_id").Table("recook_order_goods_detail").
|
|
|
|
|
Where("user_id = ?", tokenInfo.UserId)
|
|
|
|
|
|
|
|
|
|
// 已经存在的数据
|
|
|
|
|
var id []uint
|
|
|
|
|
for _, v := range goodsList {
|
|
|
|
|
id = append(id, v.ID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add := 20 - len(goodsList)
|
|
|
|
|
// 浏览记录
|
|
|
|
|
sh1 := mysql2.Db.Table("recook_app_user_history").Select("MAX(id)").
|
|
|
|
|
Where("user_id = ?", tokenInfo.UserId).
|
|
|
|
|
Where("goods_id not in (?)", s11).
|
|
|
|
|
Group("goods_id")
|
|
|
|
|
|
|
|
|
|
if len(id) != 0 {
|
|
|
|
|
sh1 = sh1.Where("goods_id not in (?)", id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var args []uint
|
|
|
|
|
mysql2.Db.Table("recook_app_user_history").
|
|
|
|
|
Select("goods_id").Where("id in (?)", sh1).Order("id DESC").Pluck("goods_id", &args)
|
|
|
|
|
|
|
|
|
|
var history []goods.Information
|
|
|
|
|
query := mysql2.Db.Table("recook_goods_info").Clauses(clause.OrderBy{
|
|
|
|
|
Expression: clause.Expr{SQL: "FIELD(id,?)", Vars: []interface{}{args}, WithoutParentheses: true}}).
|
|
|
|
|
Where("id in (?) AND publish_status = 1", args)
|
|
|
|
|
|
|
|
|
|
if volSort != "" {
|
|
|
|
|
query = query.Order("sales_volume " + volSort)
|
|
|
|
|
}
|
|
|
|
|
query.Limit(add).Find(&history)
|
|
|
|
|
|
|
|
|
|
goodsList = append(goodsList, history...)
|
|
|
|
|
id = []uint{}
|
|
|
|
|
for _, v := range goodsList {
|
|
|
|
|
id = append(id, v.ID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(goodsList) < 20 {
|
|
|
|
|
// 检索 t1 - t4
|
|
|
|
|
add = 20 - len(goodsList)
|
|
|
|
|
s1 := mysql2.Db.Table("recook_activity_info").Select("MAX(id)").
|
|
|
|
|
Where("is_active = 1 AND type > 0").Group("type")
|
|
|
|
|
|
|
|
|
|
s2 := mysql2.Db.Table("recook_activity_goods").
|
|
|
|
|
Select("goods_id").
|
|
|
|
|
Where("activity_id IN (?)", s1).
|
|
|
|
|
Where("goods_id NOT IN (?)", s11)
|
|
|
|
|
|
|
|
|
|
if len(id) != 0 {
|
|
|
|
|
s2 = s2.Where("goods_id not in (?)", id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var remain []goods.Information
|
|
|
|
|
query = mysql2.Db.Table("recook_goods_info").
|
|
|
|
|
Where("id in (?) AND publish_status = 1", s2)
|
|
|
|
|
|
|
|
|
|
if volSort != "" {
|
|
|
|
|
query = query.Order("sales_volume " + volSort)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
query.Limit(add).Find(&remain)
|
|
|
|
|
|
|
|
|
|
goodsList = append(goodsList, remain...)
|
|
|
|
|
}
|
|
|
|
|
return goodsList
|
|
|
|
|
}
|
|
|
|
|
//func getFillList(c *gin.Context, goodsList []goods.Information, volSort string) []goods.Information {
|
|
|
|
|
// // 显示记录太少
|
|
|
|
|
// // 1.用浏览历史记录填充
|
|
|
|
|
// // 2.用T1 - T4商品记录填充
|
|
|
|
|
//
|
|
|
|
|
// uid, _ := strconv.Atoi(c.Request.Header.Get("X-Recook-ID"))
|
|
|
|
|
// deviceType := cache.GetDeviceType(c)
|
|
|
|
|
// recookUserLoginModel := user.RecookUserLoginModel{}
|
|
|
|
|
// tokenInfo := recookUserLoginModel.FindByIdAndDeviceType(uint(uid), deviceType)
|
|
|
|
|
//
|
|
|
|
|
// // 购买记录
|
|
|
|
|
// s11 := mysql2.Db.Select("goods_id").Table("recook_order_goods_detail").
|
|
|
|
|
// Where("user_id = ?", tokenInfo.UserId)
|
|
|
|
|
//
|
|
|
|
|
// // 已经存在的数据
|
|
|
|
|
// var id []uint
|
|
|
|
|
// for _, v := range goodsList {
|
|
|
|
|
// id = append(id, v.ID)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// add := 20 - len(goodsList)
|
|
|
|
|
// // 浏览记录
|
|
|
|
|
// sh1 := mysql2.Db.Table("recook_app_user_history").Select("MAX(id)").
|
|
|
|
|
// Where("user_id = ?", tokenInfo.UserId).
|
|
|
|
|
// Where("goods_id not in (?)", s11).
|
|
|
|
|
// Group("goods_id")
|
|
|
|
|
//
|
|
|
|
|
// if len(id) != 0 {
|
|
|
|
|
// sh1 = sh1.Where("goods_id not in (?)", id)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// var args []uint
|
|
|
|
|
// mysql2.Db.Table("recook_app_user_history").
|
|
|
|
|
// Select("goods_id").Where("id in (?)", sh1).Order("id DESC").Pluck("goods_id", &args)
|
|
|
|
|
//
|
|
|
|
|
// var history []goods.Information
|
|
|
|
|
// query := mysql2.Db.Table("recook_goods_info").Clauses(clause.OrderBy{
|
|
|
|
|
// Expression: clause.Expr{SQL: "FIELD(id,?)", Vars: []interface{}{args}, WithoutParentheses: true}}).
|
|
|
|
|
// Where("id in (?) AND publish_status = 1", args)
|
|
|
|
|
//
|
|
|
|
|
// if volSort != "" {
|
|
|
|
|
// query = query.Order("sales_volume " + volSort)
|
|
|
|
|
// }
|
|
|
|
|
// query.Limit(add).Find(&history)
|
|
|
|
|
//
|
|
|
|
|
// goodsList = append(goodsList, history...)
|
|
|
|
|
// id = []uint{}
|
|
|
|
|
// for _, v := range goodsList {
|
|
|
|
|
// id = append(id, v.ID)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if len(goodsList) < 20 {
|
|
|
|
|
// // 检索 t1 - t4
|
|
|
|
|
// add = 20 - len(goodsList)
|
|
|
|
|
// s1 := mysql2.Db.Table("recook_activity_info").Select("MAX(id)").
|
|
|
|
|
// Where("is_active = 1 AND type > 0").Group("type")
|
|
|
|
|
//
|
|
|
|
|
// s2 := mysql2.Db.Table("recook_activity_goods").
|
|
|
|
|
// Select("goods_id").
|
|
|
|
|
// Where("activity_id IN (?)", s1).
|
|
|
|
|
// Where("goods_id NOT IN (?)", s11)
|
|
|
|
|
//
|
|
|
|
|
// if len(id) != 0 {
|
|
|
|
|
// s2 = s2.Where("goods_id not in (?)", id)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// var remain []goods.Information
|
|
|
|
|
// query = mysql2.Db.Table("recook_goods_info").
|
|
|
|
|
// Where("id in (?) AND publish_status = 1", s2)
|
|
|
|
|
//
|
|
|
|
|
// if volSort != "" {
|
|
|
|
|
// query = query.Order("sales_volume " + volSort)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// query.Limit(add).Find(&remain)
|
|
|
|
|
//
|
|
|
|
|
// goodsList = append(goodsList, remain...)
|
|
|
|
|
// }
|
|
|
|
|
// return goodsList
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//func getGoodsRespByInfoList(goodsList []goods.Information) []queryCategoryGoodsListResp {
|
|
|
|
|
// list := make([]queryCategoryGoodsListResp, 0, 0)
|
|
|
|
|