From dee7ba671f2091837dd5d5a4d8c7588d8ce30201 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Sun, 7 Apr 2024 15:36:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/hdl/goods/hdl_goods_list.go | 1 + app/admin/md/md_goods_list.go | 23 ++++++++++---------- app/admin/svc/goods/svc_goods_list.go | 31 ++++++++++++++++++++++++++- app/admin/svc/order/svc_order_pay.go | 11 ++++++++++ 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/app/admin/hdl/goods/hdl_goods_list.go b/app/admin/hdl/goods/hdl_goods_list.go index e101f2a..c829c85 100644 --- a/app/admin/hdl/goods/hdl_goods_list.go +++ b/app/admin/hdl/goods/hdl_goods_list.go @@ -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) diff --git a/app/admin/md/md_goods_list.go b/app/admin/md/md_goods_list.go index 46980f5..6d5c134 100644 --- a/app/admin/md/md_goods_list.go +++ b/app/admin/md/md_goods_list.go @@ -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 { diff --git a/app/admin/svc/goods/svc_goods_list.go b/app/admin/svc/goods/svc_goods_list.go index d47561f..dce8970 100644 --- a/app/admin/svc/goods/svc_goods_list.go +++ b/app/admin/svc/goods/svc_goods_list.go @@ -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) } } diff --git a/app/admin/svc/order/svc_order_pay.go b/app/admin/svc/order/svc_order_pay.go index 546e227..5a10ec1 100644 --- a/app/admin/svc/order/svc_order_pay.go +++ b/app/admin/svc/order/svc_order_pay.go @@ -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