@@ -18,7 +18,6 @@ func GetMallGoodsList(c *gin.Context) { | |||
args.PageId = c.Query("page") | |||
args.PageSize = c.Query("limit") | |||
args.SkuCode = c.Query("sku_code") | |||
args.EnterpriseId = c.Query("enterprise_id") | |||
tree, err := svc.GetAllCategory(c) | |||
data, total, err := goods.GetMallGoodsList(c, &args) | |||
@@ -0,0 +1,49 @@ | |||
package goods | |||
import ( | |||
"applet/app/admin/md" | |||
svc "applet/app/admin/svc/category" | |||
"applet/app/admin/svc/goods" | |||
"applet/app/e" | |||
"github.com/gin-gonic/gin" | |||
) | |||
// 商品列表接口 | |||
func GetMallGoodsListByPay(c *gin.Context) { | |||
var args md.MallGoodsListReq | |||
args.Title = c.Query("title") | |||
args.Name = c.Query("name") | |||
args.CategoryId = c.Query("category_id") | |||
args.SaleState = c.Query("sale_state") | |||
args.PageId = c.Query("page") | |||
args.PageSize = c.Query("limit") | |||
args.SkuCode = c.Query("sku_code") | |||
args.EnterpriseId = c.Query("enterprise_id") | |||
tree, err := svc.GetAllCategory(c) | |||
data, total, err := goods.GetMallGoodsListByPay(c, &args) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_NO_DATA, err) | |||
return | |||
} | |||
var returnData = map[string]interface{}{ | |||
"total": total, | |||
"cateList": tree, | |||
// "dataList": data, | |||
//-1审核拒绝 0审核中 1销售中 2已售罄 3放入仓库 4下架 | |||
"stateList": []map[string]interface{}{ | |||
{"name": "全部", "value": 99}, | |||
{"name": "销售中", "value": 1}, | |||
{"name": "已下架", "value": 2}, | |||
}, | |||
} | |||
if data == nil { | |||
returnData["dataList"] = []string{} | |||
} else { | |||
returnData["dataList"] = data | |||
} | |||
e.OutSuc(c, returnData, nil) | |||
return | |||
} |
@@ -3,30 +3,11 @@ package goods | |||
import ( | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/svc" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
"xorm.io/xorm" | |||
) | |||
func GetSkuScheme(engine *xorm.Engine, EnterpriseId string, gids []string) map[int64]model.SchemeWithSku { | |||
var skuSchemeMap = make(map[int64]model.SchemeWithSku) | |||
if utils.StrToInt64(EnterpriseId) > 0 { | |||
var enterpriseScheme model.SchemeWithEnterprise | |||
engine.Where("enterprise_id=?", EnterpriseId).Get(&enterpriseScheme) | |||
if enterpriseScheme.SchemeId > 0 { | |||
var skuScheme []model.SchemeWithSku | |||
engine.In("goods_id", gids).And("scheme_id=?", enterpriseScheme.SchemeId).Find(&skuScheme) | |||
for _, v := range skuScheme { | |||
skuSchemeMap[v.SkuId] = v | |||
} | |||
} | |||
} | |||
return skuSchemeMap | |||
} | |||
// 获取列表数据 | |||
func GetMallGoodsList(c *gin.Context, req *md.MallGoodsListReq) (interface{}, int64, error) { | |||
var goodsListResp []md.MallGoodListResp | |||
@@ -48,7 +29,6 @@ func GetMallGoodsList(c *gin.Context, req *md.MallGoodsListReq) (interface{}, in | |||
for _, item := range mallGoodsList { | |||
gids = append(gids, item["goods_id"]) | |||
} | |||
skuSchemeMap := GetSkuScheme(engine, req.EnterpriseId, gids) | |||
for _, item := range mallGoodsList { | |||
var goods md.MallGoodListResp | |||
goods.GoodsId = item["goods_id"] | |||
@@ -84,11 +64,6 @@ func GetMallGoodsList(c *gin.Context, req *md.MallGoodsListReq) (interface{}, in | |||
// sku | |||
for _, skuItem := range skus { | |||
if skuItem.GoodsId == utils.StrToInt64(item["goods_id"]) { | |||
//方案的价格 | |||
skuScheme, ok := skuSchemeMap[skuItem.SkuId] | |||
if ok { | |||
skuItem.Price = skuScheme.Price | |||
} | |||
goods.SkuList = append(goods.SkuList, skuItem) | |||
} | |||
} | |||
@@ -0,0 +1,124 @@ | |||
package goods | |||
import ( | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/svc" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
"xorm.io/xorm" | |||
) | |||
func GetSkuScheme(engine *xorm.Engine, EnterpriseId string, gids []string) map[int64]model.SchemeWithSku { | |||
var skuSchemeMap = make(map[int64]model.SchemeWithSku) | |||
if utils.StrToInt64(EnterpriseId) > 0 { | |||
var enterpriseScheme model.SchemeWithEnterprise | |||
engine.Where("enterprise_id=?", EnterpriseId).Get(&enterpriseScheme) | |||
if enterpriseScheme.SchemeId > 0 { | |||
var skuScheme []model.SchemeWithSku | |||
engine.In("goods_id", gids).And("scheme_id=?", enterpriseScheme.SchemeId).Find(&skuScheme) | |||
for _, v := range skuScheme { | |||
skuSchemeMap[v.SkuId] = v | |||
} | |||
} | |||
} | |||
return skuSchemeMap | |||
} | |||
// 获取列表数据 | |||
func GetMallGoodsListByPay(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 | |||
} | |||
//判断是不是学校下单时的商品列表 计算对应的价格 | |||
gids := make([]string, 0) | |||
for _, item := range mallGoodsList { | |||
gids = append(gids, item["goods_id"]) | |||
} | |||
skuSchemeMap := GetSkuScheme(engine, req.EnterpriseId, gids) | |||
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 | |||
var minPrice float64 = utils.StrToFloat64(item["price"]) | |||
for _, skuItem := range skus { | |||
if skuItem.GoodsId == utils.StrToInt64(item["goods_id"]) { | |||
//方案的价格 | |||
skuScheme, ok := skuSchemeMap[skuItem.SkuId] | |||
if ok { | |||
skuItem.Price = skuScheme.Price | |||
} | |||
if minPrice > utils.StrToFloat64(skuItem.Price) { | |||
minPrice = utils.StrToFloat64(skuItem.Price) | |||
} | |||
goods.SkuList = append(goods.SkuList, skuItem) | |||
} | |||
} | |||
// 获取价格、库存、重量范围、利润空间 | |||
goods.Price = utils.Float64ToStr(minPrice) | |||
// spe | |||
var spe []map[string]interface{} | |||
var speTmp []map[string]interface{} | |||
utils.Unserialize([]byte(item["spe"]), &spe) | |||
for _, itemSpe := range spe { | |||
tmp := make(map[string]interface{}) | |||
tmp["type"] = "text" | |||
tmp["name"] = itemSpe["name"] | |||
subTmp := make([]map[string]interface{}, 0) | |||
for i, v := range itemSpe["values"].([]interface{}) { | |||
subTmp = append(subTmp, map[string]interface{}{ | |||
"key": i, | |||
"name": v, | |||
}) | |||
} | |||
tmp["values"] = subTmp | |||
speTmp = append(speTmp, tmp) | |||
} | |||
goods.Spe = speTmp | |||
goodsListResp = append(goodsListResp, goods) | |||
} | |||
return goodsListResp, total, err | |||
} |
@@ -130,10 +130,10 @@ func rRole(r *gin.RouterGroup) { | |||
r.POST("/bindAdminRole", hdl.BindAdminRole) //绑定角色 | |||
} | |||
func rGoodsPay(r *gin.RouterGroup) { | |||
r.POST("/enterpriseList", hdl.EnterpriseList) //校企列表 | |||
r.GET("/goodsList", goodsHdl.GetMallGoodsList) //商品列表 | |||
r.POST("/calcAmount", orderHdl.GoodsPayCalcAmount) //商品下单计算价格 | |||
r.POST("/create", orderHdl.GoodsPayCreate) //商品下单 | |||
r.POST("/enterpriseList", hdl.EnterpriseList) //校企列表 | |||
r.GET("/goodsList", goodsHdl.GetMallGoodsListByPay) //商品列表 | |||
r.POST("/calcAmount", orderHdl.GoodsPayCalcAmount) //商品下单计算价格 | |||
r.POST("/create", orderHdl.GoodsPayCreate) //商品下单 | |||
} | |||
func rOrder(r *gin.RouterGroup) { | |||
r.POST("/list", orderHdl.OrderList) //用户订单 | |||