@@ -18,6 +18,7 @@ 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) | |||
@@ -14,17 +14,18 @@ import ( | |||
// PageId 页数 | |||
// PageSize 每页显示记录数 | |||
type MallGoodsListReq struct { | |||
Title string `json:"title"` | |||
Name string `json:"name"` | |||
CategoryId string `json:"category_id"` | |||
SkuCode string `json:"sku_code"` | |||
SaleState string `json:"sale_state"` | |||
PageId string `json:"pageId"` | |||
PageSize string `json:"pageSize"` | |||
OrderBy string `json:"order_by"` | |||
OrderBySate string `json:"order_by_sate"` | |||
StartPrice string `json:"start_price"` | |||
EndPrice string `json:"end_price"` | |||
Title string `json:"title"` | |||
Name string `json:"name"` | |||
CategoryId string `json:"category_id"` | |||
SkuCode string `json:"sku_code"` | |||
SaleState string `json:"sale_state"` | |||
PageId string `json:"pageId"` | |||
PageSize string `json:"pageSize"` | |||
OrderBy string `json:"order_by"` | |||
OrderBySate string `json:"order_by_sate"` | |||
StartPrice string `json:"start_price"` | |||
EndPrice string `json:"end_price"` | |||
EnterpriseId string `json:"enterprise_id"` | |||
} | |||
type GoodsRangeData struct { | |||
@@ -3,11 +3,30 @@ 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 | |||
@@ -24,7 +43,12 @@ func GetMallGoodsList(c *gin.Context, req *md.MallGoodsListReq) (interface{}, in | |||
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"] | |||
@@ -60,6 +84,11 @@ 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) | |||
} | |||
} | |||
@@ -2,6 +2,7 @@ package order | |||
import ( | |||
"applet/app/admin/md" | |||
"applet/app/admin/svc/goods" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
@@ -96,13 +97,17 @@ func GoodsPayCreate(c *gin.Context) { | |||
func commCalc(c *gin.Context, req md.GoodsPayParam) (float64, map[string]string) { | |||
skuPrice := make(map[string]string, 0) | |||
skuIds := make([]int64, 0) | |||
gids := make([]string, 0) | |||
for _, v := range req.GoodsInfo { | |||
skuIds = append(skuIds, utils.StrToInt64(v.SkuId)) | |||
gids = append(gids, v.GoodsId) | |||
} | |||
if len(skuIds) == 0 { | |||
return 0, skuPrice | |||
} | |||
engine := db.Db | |||
skuSchemeMap := goods.GetSkuScheme(engine, req.EnterpriseId, gids) | |||
skuMap := db.GetSkuMore(engine, skuIds) | |||
//计算价格 TODO 对应方案的价格怎么算 | |||
var amount float64 = 0 | |||
@@ -111,7 +116,13 @@ func commCalc(c *gin.Context, req md.GoodsPayParam) (float64, map[string]string) | |||
if ok == false { | |||
return 0, skuPrice | |||
} | |||
//方案的价格 | |||
skuScheme, ok := skuSchemeMap[sku.SkuId] | |||
if ok { | |||
sku.Price = skuScheme.Price | |||
} | |||
skuPrice[v.SkuId] = sku.Price | |||
amount += utils.StrToFloat64(sku.Price) * utils.StrToFloat64(v.Num) | |||
} | |||
return amount, skuPrice | |||