diff --git a/business/jxstore/cms/system_store_sku.go b/business/jxstore/cms/system_store_sku.go index b8d1b2691..54a2f4cf6 100644 --- a/business/jxstore/cms/system_store_sku.go +++ b/business/jxstore/cms/system_store_sku.go @@ -1,6 +1,7 @@ package cms import ( + "encoding/json" "fmt" "git.rosy.net.cn/baseapi/platformapi/ebaiapi" "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" @@ -10,6 +11,7 @@ import ( "git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals/api" beego "github.com/astaxie/beego/server/web" + "strings" "time" "git.rosy.net.cn/baseapi/platformapi/mtwmapi" @@ -381,61 +383,362 @@ func BatchInitSkuMT2MT(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi //#endregion //#region 同步活动 -// -//func CopyMtActToMt(ctx *jxcontext.Context, fromStore, toStore *dao.StoreDetail) { -// var fromApi *mtwmapi.API -// var toApi *mtwmapi.API -// var errData = make([]error, 0, 0) -// -// if fromStore.VendorOrgCode == globals.Mtwm2Code { -// fromApi = mtwmapi.New(beego.AppConfig.DefaultString("mtwmAppID2", ""), beego.AppConfig.DefaultString("mtwmSecret2", ""), beego.AppConfig.DefaultString("mtwmCallbackURL2", ""), "") -// fromApi.SetToken(fromStore.MtwmToken) -// } else { -// fromApi = partner.CurAPIManager.GetAPI(model.VendorIDMTWM, fromStore.VendorOrgCode).(*mtwmapi.API) -// } -// -// if toStore.VendorOrgCode == globals.Mtwm2Code { -// toApi = mtwmapi.New(beego.AppConfig.DefaultString("mtwmAppID2", ""), beego.AppConfig.DefaultString("mtwmSecret2", ""), beego.AppConfig.DefaultString("mtwmCallbackURL2", ""), "") -// toApi.SetToken(toStore.MtwmToken) -// } else { -// toApi = partner.CurAPIManager.GetAPI(model.VendorIDMTWM, toStore.VendorOrgCode).(*mtwmapi.API) -// } -// -// // 买赠活动 -// buyGiftList, err := fromApi.BatchQueryBuyGiftsAll(fromStore.VendorStoreID) -// if err != nil { -// errData = append(errData, fmt.Errorf("买赠活动异常:%v", errData)) -// } -// if len(buyGiftList) == model.NO { -// errData = append(errData, fmt.Errorf("门店暂无买赠活动")) -// } -// -// param := make([]*mtwmapi.BatchCreateBuyGiftsParam, 0, 0) -// for _, v := range buyGiftList { -// buyGift := &mtwmapi.BatchCreateBuyGiftsParam{ -// AppSpuCode: v.AppSpuCode, -// StartTime: v.StartTime, -// EndTime: v.EndTime, -// GiftsType: v.GiftsType, -// GiftsName: v.GiftsName, -// GiftsAppSpuCode: v.GiftsAppSpuCode, -// BuyNum: v.BuyNum, -// GiftsNum: v.GiftsNum, -// GiftsCharge: v.GiftsCharge, -// GiftsDayLimit: v.GiftsDayLimit, -// } -// -// // 赠品成本 -// giftsCharge := &mtwmapi.GiftsChargeObj{} -// if err := json.Unmarshal([]byte(v.Charge), giftsCharge); err != nil { -// return -// } -// -// buyGift.GiftsCharge = utils.Str2Float64(fmt.Sprintf("%.2f", utils.Str2Float64(giftsCharge.GiftsCharge))) -// param = append(param, buyGift) -// } -// toApi.BatchCreateBuyGifts(toStore.VendorStoreID, param) -// -//} + +func CopyMtActToMt(ctx *jxcontext.Context, fromStore, toStore *dao.StoreDetail) { + var fromApi, toApi *mtwmapi.API + var errData = make([]error, 0, 0) + + if fromStore.VendorOrgCode == globals.Mtwm2Code { + fromApi = mtwmapi.New(beego.AppConfig.DefaultString("mtwmAppID2", ""), beego.AppConfig.DefaultString("mtwmSecret2", ""), beego.AppConfig.DefaultString("mtwmCallbackURL2", ""), "") + fromApi.SetToken(fromStore.MtwmToken) + } else { + fromApi = partner.CurAPIManager.GetAPI(model.VendorIDMTWM, fromStore.VendorOrgCode).(*mtwmapi.API) + } + + if toStore.VendorOrgCode == globals.Mtwm2Code { + toApi = mtwmapi.New(beego.AppConfig.DefaultString("mtwmAppID2", ""), beego.AppConfig.DefaultString("mtwmSecret2", ""), beego.AppConfig.DefaultString("mtwmCallbackURL2", ""), "") + toApi.SetToken(toStore.MtwmToken) + } else { + toApi = partner.CurAPIManager.GetAPI(model.VendorIDMTWM, toStore.VendorOrgCode).(*mtwmapi.API) + } + + // 买赠活动 + buyGiftList, err := fromApi.BatchQueryBuyGiftsAll(fromStore.VendorStoreID) + if err != nil { + errData = append(errData, fmt.Errorf("买赠活动异常:%v", errData)) + } + if len(buyGiftList) == model.NO { + errData = append(errData, fmt.Errorf("门店暂无买赠活动")) + } + + param := make([]*mtwmapi.BatchCreateBuyGiftsParam, 0, 0) + for _, v := range buyGiftList { + buyGift := &mtwmapi.BatchCreateBuyGiftsParam{ + AppSpuCode: v.AppSpuCode, + StartTime: v.StartTime, + EndTime: v.EndTime, + GiftsType: v.GiftsType, + GiftsName: v.GiftsName, + GiftsAppSpuCode: v.GiftsAppSpuCode, + BuyNum: v.BuyNum, + GiftsNum: v.GiftsNum, + GiftsCharge: v.GiftsCharge, + GiftsDayLimit: v.GiftsDayLimit, + } + + // 赠品成本 + giftsCharge := &mtwmapi.GiftsChargeObj{} + if err := json.Unmarshal([]byte(v.Charge), giftsCharge); err != nil { + return + } + + buyGift.GiftsCharge = utils.Str2Float64(fmt.Sprintf("%.2f", utils.Str2Float64(giftsCharge.GiftsCharge))) + param = append(param, buyGift) + } + toApi.BatchCreateBuyGifts(toStore.VendorStoreID, param) + +} + +// SyncStoreFullReduction 同步门店满减活动 +func SyncStoreFullReduction(fromStoreApi, toStoreApi *mtwmapi.API, fromStoreId, toStoreId string) error { + data, err := fromStoreApi.BatchGetDiscountList(fromStoreId, 0) + if err != nil { + return err + } + + errList := make([]string, 0.0) + for k, v := range data { + param := &mtwmapi.CreateDiscountList{ + AppPoiCode: toStoreId, + ActInfo: "", + ActDetails: "", + AppFoods: "", + } + actInfo := &mtwmapi.CreateDisCountActInfo{ + StartTime: v.ActInfo.StartTime, + EndTime: v.ActInfo.EndTime, + ActType: 0, // 0 不传app_food + AutoDelay: 1, + } + if v.ActInfo.ActName != "" { + actInfo.ActName = v.ActInfo.ActName + } else { + actInfo.ActName = "全店满减" + utils.Int2Str(k) + } + + actInfoByte, err := json.Marshal(actInfo) + if err != nil { + return err + } + param.ActInfo = string(actInfoByte) + + actDetails := make([]mtwmapi.CreateDiscountActDetails, 0, 0) + for _, ads := range v.ActDetails { + actDetails = append(actDetails, mtwmapi.CreateDiscountActDetails{ + OriginPrice: utils.Float64TwoInt(ads.OriginPrice), + ActPrice: utils.Float64TwoInt(ads.ActPrice), + }) + } + actDetailsByte, err := json.Marshal(actDetails) + if err != nil { + return err + } + param.ActDetails = string(actDetailsByte) + _, err = toStoreApi.BatchCreateDiscountList(param) + if err != nil { + errList = append(errList, actInfo.ActName+":"+err.Error()) + } + } + + return fmt.Errorf(strings.Join(errList, ",")) +} + +// SyncStoreShippingFee 同步门店运费满减活动 +func SyncStoreShippingFee(fromStoreApi, toStoreApi *mtwmapi.API, fromStoreId, toStoreId string) error { + data, err := fromStoreApi.BatchGetShippingFee(fromStoreId) + if err != nil { + return err + } + + if data.SuccessList != nil && len(data.SuccessList) != 0 { + param := make([]*mtwmapi.ShippingFeeBatchCreateActData, 0, 0) + for _, v := range data.SuccessList { + shippingFee := &mtwmapi.ShippingFeeBatchCreateActData{ + StartTime: v.StartTime, + EndTime: v.EndTime, + WeeksTime: v.WeeksTime, + Period: v.Period, + MaxPrice: v.MaxPrice, + } + actDetail := make([]mtwmapi.ShippingFeeBatchCreateActDataActDetail, 0, 0) + for _, ad := range v.ActDetail { + actDetail = append(actDetail, mtwmapi.ShippingFeeBatchCreateActDataActDetail{ + LimitPrice: ad.LimitPrice, + DiscountPrice: ad.DiscountPrice, + }) + } + shippingFee.ActDetail = actDetail + + param = append(param, shippingFee) + } + + resultData, err := toStoreApi.BatchCreateShippingFee(toStoreId, param) + if err != nil { + return err + } + if resultData.Data != "ok" { + return fmt.Errorf(resultData.Msg) + } + } + return nil +} + +// SyncStoreProducts 同步门店折扣爆品活动 +func SyncStoreProducts(fromStoreApi, toStoreApi *mtwmapi.API, fromStoreId, toStoreId string) error { + secKillALL, err := fromStoreApi.QueryProductsAll(fromStoreId, mtwmapi.RetailActTypeSecKill) + if err != nil { + return err + } + + killAct := make([]*mtwmapi.RetailDiscountActData, 0, 0) + for _, v := range secKillALL { + kill := &mtwmapi.RetailDiscountActData{ + AppFoodCode: v.AppFoodCode, + UserType: v.UserType, + StartTime: v.StartTime, + EndTime: v.EndTime, + OrderLimit: v.OrderLimit, + DayLimit: v.DayLimit, + Period: v.Period, + WeeksTime: v.WeeksTime, + SettingType: v.SettingType, + ActPrice: v.ActPrice, + DiscountCoefficient: v.DiscountCoefficient, + Sequence: v.Sequence, + ItemID: v.ItemID, + OriginalPrice: v.OriginalPrice, + Stock: v.Stock, + Status: v.Status, + Name: v.Name, + } + killAct = append(killAct, kill) + } + + //todo 折扣活动查询出来一万多条,暂时工单处理 + directDownALL, err := fromStoreApi.QueryProductsAll(fromStoreId, mtwmapi.RetailActTypeDirectDown) + for _, v := range directDownALL { + kill := &mtwmapi.RetailDiscountActData{ + AppFoodCode: v.AppFoodCode, + UserType: v.UserType, + StartTime: v.StartTime, + EndTime: v.EndTime, + OrderLimit: v.OrderLimit, + DayLimit: v.DayLimit, + Period: v.Period, + WeeksTime: v.WeeksTime, + SettingType: v.SettingType, + ActPrice: v.ActPrice, + DiscountCoefficient: v.DiscountCoefficient, + Sequence: v.Sequence, + ItemID: v.ItemID, + OriginalPrice: v.OriginalPrice, + Stock: v.Stock, + Status: v.Status, + Name: v.Name, + } + killAct = append(killAct, kill) + } + if len(killAct) != 0 { + _, _, err := toStoreApi.CreateProductsAct(toStoreId, mtwmapi.RetailActTypeSecKill, killAct) + if err != nil { + return err + } + } + + return nil +} + +// SyncStoreCoupon 同步门店商家券(单店店内商家券) +func SyncStoreCoupon(fromStoreApi, toStoreApi *mtwmapi.API, fromStoreId, toStoreId string) error { + couponList, err := fromStoreApi.QueryStoreCoupon(fromStoreId) + if err != nil { + return err + } + + errList := make([]string, 0, 0) + if len(couponList) != 0 { + for _, v := range couponList { + couponInfoList := make([]*mtwmapi.CouponInfo, 0, 0) + for _, ad := range v.ActData { + couponInfoList = append(couponInfoList, &mtwmapi.CouponInfo{ + LimitPrice: ad.LimitPrice, + CouponPrice: ad.CouponPrice, + UserType: ad.UserType, + ValidityDays: ad.ValidityDays, + Stock: ad.Stock, + }) + } + + limitTime := &mtwmapi.LimitTime{ + StartTime: v.StartTime, + EndTime: v.EndTime, + } + + if _, err := toStoreApi.CreateStoreCouponBatch(toStoreId, limitTime, couponInfoList); err != nil { + errList = append(errList, err.Error()) + } + } + } + + if len(errList) != 0 { + return fmt.Errorf(strings.Join(errList, ",")) + } + return nil +} + +// SyncStoreXDiscount 同步门店X件优惠活动(x件m元/X件m折/X件减m元)目前只有x件m元,其他两个查询不出来,美团创建成功也查询不出来 +// 暂时不能创建,无法获取商品的活动价格和活动库存 +func SyncStoreXDiscount(fromStoreApi, toStoreApi *mtwmapi.API, fromStoreId, toStoreId string) error { + //result := make([]*mtwmapi.BundlesSuccessListDetail, 0, 0) + //// X件M元 + //bundlesXM, _ := fromStoreApi.QueryBundlesAct(fromStoreId, 0) + //if bundlesXM != nil { + // result = append(result, bundlesXM...) + //} + //// X件Y折 + //bundlesXY, _ := fromStoreApi.QueryBundlesAct(fromStoreId, 2) + //if bundlesXY != nil { + // result = append(result, bundlesXY...) + //} + // + //errList := make([]error, 0, 0) + //for _, v := range result { + // actSku, err := fromStoreApi.QueryBundlesSku(fromStoreId, utils.Int64ToStr(v.ActId)) + // if err != nil { + // errList = append(errList, err) + // continue + // } + // + //} + + return nil +} + +// SyncRepurchaseSku 加价购[无法获取活动商品的价格和库存暂不创建] +func SyncRepurchaseSku() { + return +} + +// SyncStoreCouponAct 门店商品券活动 +func SyncStoreCouponAct(fromStoreApi, toStoreApi *mtwmapi.API, fromStoreId, toStoreId string) error { + couponInfoAll := make([]*mtwmapi.GetStoreCouponActSuccessList, 0, 0) + pageNumber := 1 + pageSize := 100 + for { + param := &mtwmapi.GetStoreCouponActParam{ + AppPoiCode: fromStoreId, + ActStatus: 1, + StartTime: time.Now().AddDate(-1, 0, 0).Unix(), + EndTime: time.Now().AddDate(1, 0, 0).Unix(), + PageNum: pageNumber, + PageSize: pageSize, + } + + couponList, err := fromStoreApi.GetStoreCouponAct(param) + if err != nil { + return err + } + couponInfoAll = append(couponInfoAll, couponList...) + if len(couponList) < pageSize { + break + } + pageNumber++ + } + + for _, v := range couponInfoAll { + couponSkuList, err := fromStoreApi.GetCouponActSkuList(fromStoreId, utils.Int64ToStr(v.ActId)) + if err != nil { + return err + } + + for _, csl := range couponSkuList { + param := &mtwmapi.CreateCouponAct{ + AppPoiCodes: csl.AppPoiCodes, + CouponName: csl.CouponName, + IsSinglePoi: csl.IsSinglePoi, + AppSpuCodes: csl.AppSpuCodes, + TakeCouponStartTime: csl.TakeCouponStartTime, + TakeCouponEndTime: csl.TakeCouponEndTime, + UseCouponStartTime: csl.UseCouponStartTime, + CouponLimitCount: csl.CouponLimitCount, + Type: csl.Type, + } + + if csl.SpuData != nil && len(csl.SpuData) != 0 { + for _, sd := range csl.SpuData { + param.SpuData = append(param.SpuData, mtwmapi.CreateCouponActSpuData{ + AppSpuCode: sd.AppSpuCode, + SkuId: sd.SkuId, + Upc: sd.Upc, + }) + } + } + + if csl.ActPriceCouponInfo != nil && len(csl.ActPriceCouponInfo) != 0 { + param.ActPriceCouponInfo = csl.ActPriceCouponInfo + } + if csl.DiscountCouponInfo != nil && len(csl.DiscountCouponInfo) != 0 { + param.DiscountCouponInfo = csl.DiscountCouponInfo + } + + _, err = toStoreApi.CreateCouponAct(param) + if err != nil { + return err + } + } + } + + return nil +} //#endregion diff --git a/business/partner/purchase/jd/sku2.go b/business/partner/purchase/jd/sku2.go index 9a74f221a..245b0b23a 100644 --- a/business/partner/purchase/jd/sku2.go +++ b/business/partner/purchase/jd/sku2.go @@ -220,7 +220,9 @@ func (p *PurchaseHandler) CreateSku2(ctx *jxcontext.Context, sku *dao.StoreSkuSy func (p *PurchaseHandler) UpdateSku2(ctx *jxcontext.Context, sku *dao.StoreSkuSyncInfo) (err error) { param := skuInfo2Param(ctx, sku) if globals.EnableJdStoreWrite { + globals.SugarLogger.Debugf("============param := %s", utils.Format4Output(param, false)) _, err = getAPI(sku.VendorOrgCode).UpdateSku2(param) + globals.SugarLogger.Debugf("============err := %v", err) } return err }