From d65b49002e2a0b2f8efe300868a1cd2584a29ce3 Mon Sep 17 00:00:00 2001 From: gazebo Date: Sun, 16 Jun 2019 15:19:13 +0800 Subject: [PATCH] =?UTF-8?q?-=20updateStoresSkusWithoutSync=E4=B8=AD?= =?UTF-8?q?=EF=BC=8C=E5=85=B3=E6=B3=A8=E4=B8=94=E6=B2=A1=E6=9C=89=E7=BB=99?= =?UTF-8?q?=E4=BB=B7=E6=97=B6=EF=BC=8C=E9=9C=80=E8=A6=81=E5=B0=9D=E8=AF=95?= =?UTF-8?q?=E4=BB=8Estore=5Fsku=5Fbind=E4=B8=AD=E5=BE=97=E5=88=B0=E5=B7=B2?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E5=8D=95=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 32 ++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index f9d837d4d..04e3a82d9 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -707,27 +707,45 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs }() for _, storeID := range storeIDs { for _, skuBindInfo := range skuBindInfos { + // 关注且没有给价时,需要尝试从store_sku_bind中得到已有的单价 + needGetExistingUnitPrice := skuBindInfo.UnitPrice == 0 && skuBindInfo.IsFocus == 1 inSkuBinds := skuBindInfo.Skus var allBinds []*tStoreSkuBindAndSpec sql := ` SELECT t2.*, - t1.id real_sku_id, t1.spec_quality, t1.spec_unit, - t3.price sku_name_price, t3.unit sku_name_unit, t3.name + t1.id real_sku_id, t1.spec_quality, t1.spec_unit,` + if needGetExistingUnitPrice { + sql += " IF(t5.unit_price > 0, t5.unit_price, t3.price) sku_name_price," + } + sql += ` + t3.unit sku_name_unit, t3.name FROM sku t1 JOIN store ts ON ts.id = ? AND ts.deleted_at = ? LEFT JOIN store_sku_bind t2 ON t2.sku_id = t1.id AND t2.store_id = ts.id AND t2.deleted_at = ? - JOIN sku_name t3 ON t1.name_id = t3.id AND t3.deleted_at = ? - WHERE t1.name_id = ? AND t1.deleted_at = ? - FOR UPDATE` + JOIN sku_name t3 ON t1.name_id = t3.id AND t3.deleted_at = ?` sqlParams := []interface{}{ storeID, utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue, - skuBindInfo.NameID, - utils.DefaultTimeValue, } + if needGetExistingUnitPrice { + sql += ` + LEFT JOIN ( + SELECT t7.store_id, t8.name_id, CAST(AVG(t7.unit_price) AS SIGNED) unit_price + FROM store_sku_bind t7 + JOIN sku t8 ON t8.id = t7.sku_id AND t8.name_id = ? + WHERE t7.deleted_at = ? AND t7.store_id = ? + GROUP BY 1,2 + ) t5 ON t5.store_id = ts.id AND t5.name_id = t1.name_id` + sqlParams = append(sqlParams, skuBindInfo.NameID, utils.DefaultTimeValue, storeID) + } + sql += ` + WHERE t1.name_id = ? AND t1.deleted_at = ? + FOR UPDATE` + sqlParams = append(sqlParams, skuBindInfo.NameID, utils.DefaultTimeValue) + // globals.SugarLogger.Debug(sql) if err = dao.GetRows(db, &allBinds, sql, sqlParams...); err == nil { if len(allBinds) > 0 { // globals.SugarLogger.Debug(utils.Format4Output(allBinds, false))