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.

73 lines
1.9 KiB

4 years ago
package jyy
import (
3 years ago
"fmt"
"github.com/shopspring/decimal"
4 years ago
"recook/internal/v2/model/jyy"
3 years ago
goods2 "recook/internal/v2/model/recook/goods"
4 years ago
"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
}
3 years ago
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
}