|
|
|
package jyy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
"recook/internal/v2/model/jyy"
|
|
|
|
goods2 "recook/internal/v2/model/recook/goods"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.oa00.com/go/mysql"
|
|
|
|
)
|
|
|
|
|
|
|
|
type logic struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
var Logic = logic{}
|
|
|
|
|
|
|
|
func (o logic) Banners() (res jyy.Banner, err error) {
|
|
|
|
now := time.Now()
|
|
|
|
mysql.Db.Where("start < ?", now).Where("end > ?", now).Order("order_sort asc").Order("id desc").Find(&res)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o logic) Activities() (res jyy.Activity, err error) {
|
|
|
|
mysql.Db.Where("status = 1").Order("order_sort asc").Order("id desc").Find(&res)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type ArgsEntryReq struct {
|
|
|
|
UserID uint `json:"user_id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ShopCartSku struct {
|
|
|
|
ID uint `json:"id"`
|
|
|
|
DiscountPrice decimal.Decimal `json:"discount_price"`
|
|
|
|
SalePrice decimal.Decimal `json:"sale_price"`
|
|
|
|
Quantity decimal.Decimal `json:"quantity"`
|
|
|
|
Limit uint `json:"limit"`
|
|
|
|
Min uint `json:"min"`
|
|
|
|
SkuName string `json:"skuName"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ShopCartEntry struct {
|
|
|
|
GoodsID uint `json:"goods_id"`
|
|
|
|
GoodsName string `json:"goods_name"`
|
|
|
|
MainPhoto string `json:"main_photo"`
|
|
|
|
SkuList []ShopCartSku `json:"sku_list"`
|
|
|
|
SalePublish bool `json:"sale_publish"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ShopCartEntries struct {
|
|
|
|
GoodsList []ShopCartEntry `json:"goods_list"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o logic) ShopCartEntries(args ArgsEntryReq) (res ShopCartEntries) {
|
|
|
|
sc := make([]jyy.ShopCartEntry, 0)
|
|
|
|
mysql.Db.Model(&jyy.ShopCartEntry{}).Where("user_id = ?", args.UserID).Find(&sc)
|
|
|
|
ids := make([]uint, 0)
|
|
|
|
idsMap := make(map[uint]uint, 0)
|
|
|
|
for _, v := range sc {
|
|
|
|
ids = append(ids, v.SkuID)
|
|
|
|
idsMap[v.SkuID] = v.Quantity
|
|
|
|
}
|
|
|
|
|
|
|
|
skuList := make([]goods2.RecookGoodsSkuModel, 0)
|
|
|
|
mysql.Db.Preload("GoodsInfo.MainPhoto").Where("id in (?)", ids).Find(&skuList)
|
|
|
|
for _, v := range skuList {
|
|
|
|
// todo
|
|
|
|
fmt.Println(v.GoodsInfo.MainPhoto.Url)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|