This commit is contained in:
邹宗楠
2024-04-03 16:39:33 +08:00
parent 62827f0826
commit 09cb41ce78
4 changed files with 62 additions and 48 deletions

View File

@@ -6685,6 +6685,6 @@ func BatchSetRestockingPrice(ctx *jxcontext.Context, preData map[string][]mtwmap
}
// BatchSetMTBoxPrice 批量修改美团包装费为0
func BatchSetMTBoxPrice(ctx *jxcontext.Context, skuList []*mtwm.SetBoxPrice) error {
return mtwm.UpdateBoxPrice(ctx, dao.GetDB(), skuList)
func BatchSetMTBoxPrice(ctx *jxcontext.Context, storeList []int) error {
return mtwm.UpdateBoxPrice(ctx, dao.GetDB(), storeList)
}

View File

@@ -1699,18 +1699,19 @@ func GetDeletedStoreSkuBind(db *DaoDB, storeID, skuID int) (storeSkuBind *model.
return storeSkuBind
}
func GetStoreSkuBindList(db *DaoDB, storeId int64) []string {
func GetStoreSkuBindList(db *DaoDB, storeId int) ([]*model.StoreSkuBind, error) {
storeSkuBind := make([]*model.StoreSkuBind, 0, 0)
sql := `SELECT * FROM store_sku_bind WHERE store_id = ` + fmt.Sprintf("%d", storeId) + ` AND status = 1 `
GetRows(db, &storeSkuBind, sql)
sql := `SELECT * FROM store_sku_bind WHERE store_id = ? AND deleted_at = ? `
data := make([]string, 0)
for _, v := range storeSkuBind {
if v.TaoID != 0 {
data = append(data, utils.Int64ToStr(v.TaoID))
}
sqlParams := []interface{}{
storeId,
utils.DefaultTimeValue,
}
return data
err := GetRows(db, &storeSkuBind, sql, sqlParams...)
if err != nil {
return nil, err
}
return storeSkuBind, nil
}
func GetStoreSkuBindByNameID(db *DaoDB, storeID, nameID, status int) (storeSkuBind []*model.StoreSkuBind, err error) {

View File

@@ -906,39 +906,54 @@ type SetBoxPrice struct {
BoxPrice float64 `json:"box_price"` // 打包价格
}
func UpdateBoxPrice(ctx *jxcontext.Context, db *dao.DaoDB, list []*SetBoxPrice) error {
storeDetail, err := dao.GetStoreDetail(db, list[0].StoreId, model.VendorIDMTWM, "")
if err != nil {
return err
}
//storeSkuList, err := dao.GetStoresSkusInfo(db, []int{list[0].StoreId}, nil)
//if err != nil {
// return err
//}
api := getAPI(storeDetail.VendorOrgCode, list[0].StoreId, storeDetail.VendorStoreID)
foodDataList := make([]map[string]interface{}, 0)
func UpdateBoxPrice(ctx *jxcontext.Context, db *dao.DaoDB, list []int) error {
for _, v := range list {
storeDetail, err := dao.GetStoreDetail(db, v, model.VendorIDMTWM, "")
if err != nil {
return err
}
foodDataList = append(foodDataList, map[string]interface{}{
"app_spu_code": utils.Int2Str(v.SkuId),
"skus": []map[string]interface{}{
{
"sku_id": utils.Int2Str(v.SkuId),
"ladder_box_num": "1",
"ladder_box_price": utils.Float64ToStr(v.BoxPrice),
skuList, err := dao.GetStoreSkuBindList(db, v)
if err != nil {
return err
}
if len(skuList) == model.NO {
continue
}
foodDataList := make([]map[string]interface{}, 0)
for _, sl := range skuList {
foodDataList = append(foodDataList, map[string]interface{}{
"app_spu_code": utils.Int2Str(sl.SkuID),
"skus": []map[string]interface{}{
{
"sku_id": utils.Int2Str(sl.SkuID),
"ladder_box_num": "0",
"ladder_box_price": "0",
},
},
},
})
}
count := utils.Float64TwoInt(math.Ceil(float64(len(foodDataList)) / float64(50)))
for i := 1; i <= count; i++ {
if i == count {
_, _ = api.RetailBatchInitData(ctx.GetTrackInfo(), storeDetail.VendorStoreID, foodDataList[(i-1)*50:])
} else {
_, _ = api.RetailBatchInitData(ctx.GetTrackInfo(), storeDetail.VendorStoreID, foodDataList[(i-1)*50:i*50])
})
}
count := utils.Float64TwoInt(math.Ceil(float64(len(foodDataList)) / float64(200)))
api := getAPI(storeDetail.VendorOrgCode, v, storeDetail.VendorStoreID)
for i := 1; i <= count; i++ {
if i == count {
result, err := api.RetailBatchInitData(ctx.GetTrackInfo(), storeDetail.VendorStoreID, foodDataList[(i-1)*200:])
if err != nil {
globals.SugarLogger.Debugf("RetailBatchInitData1 err := %v", err)
}
if result != nil {
globals.SugarLogger.Debugf("RetailBatchInitData1 result := %s", utils.Format4Output(result, false))
}
} else {
result, err := api.RetailBatchInitData(ctx.GetTrackInfo(), storeDetail.VendorStoreID, foodDataList[(i-1)*200:i*200])
if err != nil {
globals.SugarLogger.Debugf("RetailBatchInitData2 err := %v", err)
}
if result != nil {
globals.SugarLogger.Debugf("RetailBatchInitData1 result := %s", utils.Format4Output(result, false))
}
}
}
}

View File

@@ -902,18 +902,16 @@ func (c *SkuController) BatchSetRestockingPrice() {
// @Title 批量设置美团商品打包费为零
// @Description 批量设置美团商品打包费为零
// @Param token header string true "认证token"
// @Param payload formData string true "json数据SpuData对象()"
// @Param storeIDs query string false "门店ID列表"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /BatchSetBoxPrice [post]
func (c *SkuController) BatchSetBoxPrice() {
c.callBatchSetBoxPrice(func(params *tSkuBatchSetBoxPriceParams) (retVal interface{}, errCode string, err error) {
payload := make([]*mtwm.SetBoxPrice, 0, 0)
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &payload); err != nil {
return nil, "", err
}
err = cms.BatchSetMTBoxPrice(params.Ctx, payload)
var storeIDs []int
err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs)
err = cms.BatchSetMTBoxPrice(params.Ctx, storeIDs)
return retVal, "", err
})
}