|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package goods
-
- import (
- "applet/app/admin/md"
- "applet/app/db"
- "applet/app/svc"
- "applet/app/utils"
- "github.com/gin-gonic/gin"
- )
-
- // 获取列表数据
- func GetMallGoodsList(c *gin.Context, req *md.MallGoodsListReq) (interface{}, int64, error) {
- var goodsListResp []md.MallGoodListResp
- // 获取分库链接
- engine := db.Db
- // 查询goods数据表获取数据
- mallGoodsList, skus, total, err := db.GetMallGoodsListLeftOnMallSku(engine, req)
- if err != nil {
- return nil, 0, err
- }
- var tmpMap interface{}
- scheme, host, subDomain, moreSubDomain := svc.ImageBucketNew(c)
-
- if err != nil {
- return nil, 0, err
- }
-
- for _, item := range mallGoodsList {
- var goods md.MallGoodListResp
- goods.GoodsId = item["goods_id"]
- goods.SaleState = utils.StrToInt(item["sale_state"])
- goods.Sales = utils.StrToInt(item["sales"])
- goods.CreateAt = item["create_at"]
-
- // 商品主图
- if item["image_list"] != "" {
- utils.Unserialize([]byte(item["image_list"]), &tmpMap)
- var imageListUrlTmp []string
- for _, v := range tmpMap.([]interface{}) {
- imageListUrlTmp = append(imageListUrlTmp, svc.ImageFormatWithBucketNew(scheme, host, subDomain, moreSubDomain, v.(string)))
- }
- if imageListUrlTmp != nil {
- goods.Image = imageListUrlTmp[0]
- }
- }
-
- goods.UpdateAt = item["update_at"]
- goods.Title = item["title"]
-
- // 状态
- switch utils.StrToInt64(item["sale_state"]) {
- case 1.00:
- goods.SaleStateText = "銷售中"
- break
- case 2.00:
- goods.SaleStateText = "下架"
- break
- }
-
- // sku
- for _, skuItem := range skus {
- if skuItem.GoodsId == utils.StrToInt64(item["goods_id"]) {
- goods.SkuList = append(goods.SkuList, skuItem)
- }
- }
- // 获取价格、库存、重量范围、利润空间
- goods.Price = item["price"]
- goodsListResp = append(goodsListResp, goods)
- }
-
- return goodsListResp, total, err
- }
-
- func CheckSkuCode(c *gin.Context, skuCode, goodsId string) (bool, error) {
- engine := db.Db
- isHas, _, err := db.GetMallSkuBySkuCode(engine, skuCode, goodsId)
- if err != nil {
- return false, err
- }
- return isHas, nil
- }
|