Merge branch 'jdshop' of https://e.coding.net/rosydev/jx-callback into jdshop

This commit is contained in:
richboo111
2023-09-25 15:08:52 +08:00
18 changed files with 284 additions and 122 deletions

View File

@@ -2701,31 +2701,36 @@ func UpdateTiktokShopTotalMoney() {
// UpdateTaoSettleInfo 定时任务更新淘鲜达结算信息
func UpdateTaoSettleInfo() {
db := dao.GetDB()
var count = 0
globals.SugarLogger.Debugf("======================UpdateTaoSettleInfo")
storeMaps, err := dao.GetStoresMapList(db, []int{model.VendorIDTaoVegetable}, nil, nil, -9, -1, "", "", "")
timeStart := time.Now().Add(-24 * 20 * time.Hour)
startTime := time.Date(timeStart.Year(), timeStart.Month(), timeStart.Day(), 0, 0, 0, 0, timeStart.Location())
timeEnd := time.Now()
endTime := time.Date(timeEnd.Year(), timeEnd.Month(), timeEnd.Day()-1, 23, 59, 59, 0, timeStart.Location())
storeMaps, err := dao.GetTaoOrderVendor(db, startTime, endTime)
if err != nil {
return
}
timeStart := time.Now().Add(-24 * 90 * time.Hour)
startTime := time.Date(timeStart.Year(), timeStart.Month(), timeStart.Day()-4, 0, 0, 0, 0, timeStart.Location())
timeEnd := time.Now()
endTiem := time.Date(timeEnd.Year(), timeEnd.Month(), timeEnd.Day()-1, 23, 59, 59, 0, timeStart.Location())
for _, v := range storeMaps {
settleInfo, err := tao.GetOrderTotalShopMoney(v.VendorOrgCode, v.VendorStoreID, startTime, endTiem)
for k, v := range storeMaps {
count++
globals.SugarLogger.Debugf("========storeID := %s", k)
settleInfo, err := tao.GetOrderTotalShopMoney(v, k, startTime, endTime)
if err != nil {
globals.SugarLogger.Errorf("获取淘鲜达结算信息异常 := %v", err)
continue
}
if len(settleInfo) == model.NO {
globals.SugarLogger.Debugf("门店[%d:%s],暂无结算信息", v.StoreID, v.StoreName)
continue
}
for orderId2, settle := range settleInfo {
goodsOrder, err := partner.CurOrderManager.LoadOrder2(orderId2, model.VendorIDTaoVegetable)
if err != nil || goodsOrder == nil {
globals.SugarLogger.Debugf("门店[%d:%s],订单查询异常[%s:%v]", v.StoreID, v.StoreName, orderId2, err)
globals.SugarLogger.Debugf("门店[%d:%s],订单查询异常[%s:%v]", v, k, orderId2, err)
continue
}
@@ -2749,4 +2754,5 @@ func UpdateTaoSettleInfo() {
}
}
}
globals.SugarLogger.Debug("========count := %d", count)
}

View File

@@ -203,6 +203,7 @@ var (
"deliveryRange": 1,
"status": 1,
"promoteInfo": 1,
"vendorStoreName": 1,
}
storeMapKeyPropertyMap = map[string]int{
@@ -824,7 +825,7 @@ func GetVendorStore(ctx *jxcontext.Context, vendorID int, vendorOrgCode, vendorS
if !jxutils.IsLegalStoreID(retVal.ID) {
retVal.ID = 0
}
if retVal.Status == model.StoreStatusDisabled {
if result.Status <= model.StoreStatusHaveRest {
retVal.BussinessStatus = -1
} else {
retVal.BussinessStatus = 1
@@ -1369,7 +1370,7 @@ func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (i
Status: model.StoreStatusOpened,
PricePercentagePack: "无",
VendorID: model.VendorIDJX,
})
}, false)
//尝试把平台负责人加到他自己的权限里
if store.MarketManPhone != "" {
user, _ := dao.GetUserByID(db, "mobile", store.MarketManPhone)
@@ -1489,7 +1490,7 @@ func CreateStore2JX(ctx *jxcontext.Context, storeExt *StoreExt, userName string)
PricePercentagePack: "无",
CreateDeliveryType: model.YES, // 菜市门店默认门店发单
VendorID: model.VendorIDJX,
})
}, false)
//尝试把平台负责人加到他自己的权限里
if store.MarketManPhone != "" {
user, _ := dao.GetUserByID(db, "mobile", store.MarketManPhone)
@@ -1570,7 +1571,7 @@ func GetStoreVendorMaps(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, vend
}
// todo 需要对字段做有效性检查
func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vendorOrgCode string, storeID int, storeMap *model.StoreMap) (outStoreMap *model.StoreMap, err error) {
func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vendorOrgCode string, storeID int, storeMap *model.StoreMap, isAdd bool) (outStoreMap *model.StoreMap, err error) {
errList := errlist.ErrList{}
if storeID == 0 {
return nil, fmt.Errorf("storeID不能为0")
@@ -1687,7 +1688,7 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
err = AddEventDetail(db, ctx, model.OperateAdd, vendorID, model.ThingTypeStore, storeID, "", `{"VendorID":`+utils.Int2Str(vendorID)+`}`)
}
_, err = CurVendorSync.SyncStore(ctx, db, storeMap.VendorID, storeID, false, userName)
_, err = CurVendorSync.FullSyncStoresSkus(ctx, db, []int{vendorID}, []int{storeID}, true, nil, true, true)
_, err = CurVendorSync.FullSyncStoresSkus(ctx, db, []int{vendorID}, []int{storeID}, true, nil, true, true, isAdd)
if utils.IsNil(errList) && err == nil {
return outStoreMap, nil
} else {
@@ -1862,6 +1863,7 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
}
}()
// 这里面包含address时会报错,所以删除
if address != "" {
delete(valid, "address")
}
@@ -1908,9 +1910,13 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
}
}
dao.Commit(db, txDB)
if address != "" {
valid["address"] = address
}
if isStoreMapNeedSync(vendorID, valid) || address != "" {
if isUpdateStoreNeedSync(valid) { // 同步修改门店已经配送门店
_, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName)
updateCourierStores(ctx, storeID)
}
// 更新商品
@@ -4749,7 +4755,8 @@ func UpdateVendorStoreBussinessStatus(ctx *jxcontext.Context, storeID, vendorID,
if storeMaps, _ := dao.GetStoresMapList(db, []int{vendorID}, []int{storeID}, nil, model.StoreStatusAll,
model.StoreIsSyncAll, "", "", ""); len(storeMaps) > 0 {
storeMaps[0].IsOnline = status
dao.UpdateEntity(db, storeMaps[0], "IsOnline")
storeMaps[0].Status = status
dao.UpdateEntity(db, storeMaps[0], "IsOnline", "Status")
}
}
return err
@@ -5540,7 +5547,7 @@ func AuditStoreMap(ctx *jxcontext.Context, ID int, vendorOrgCode, vendorStoreID
DeliveryCompetition: 1,
PricePercentage: 100,
}
_, err = AddStoreVendorMap(ctx, db, storeMapAudit.VendorID, vendorOrgCode, storeMapAudit.StoreID, storeMap)
_, err = AddStoreVendorMap(ctx, db, storeMapAudit.VendorID, vendorOrgCode, storeMapAudit.StoreID, storeMap, false)
} else {
if comment == "" {
fmt.Errorf("审核不通过请输入原因!")

View File

@@ -555,7 +555,7 @@ func (v *VendorSync) SyncStoresSkus(ctx *jxcontext.Context, parentTask tasksch.I
func (c *ComparePlatform) CompareStoreWithOperator(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled bool, excludeSkuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
return hint, makeSyncError(err)
}
func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled bool, excludeSkuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled bool, excludeSkuIDs []int, isAsync, isContinueWhenError, isAdd bool) (hint string, err error) {
hint, err = v.LoopStoresMap(ctx, db, fmt.Sprintf("初始化门店商品信息:%v", storeIDs), isAsync, true, vendorIDs, storeIDs,
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
@@ -569,7 +569,7 @@ func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, v
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeMap := batchItemList[0].(*model.StoreMap)
if syncDisabled || storeMap.Status > model.StoreStatusDisabled {
if _, err = FullSyncStoreSkuNew(ctx, task, storeMap.VendorID, storeMap.StoreID, storeMap.VendorStoreID, excludeSkuIDs, false, isContinueWhenError); err != nil {
if _, err = FullSyncStoreSkuNew(ctx, task, storeMap.VendorID, storeMap.StoreID, storeMap.VendorStoreID, excludeSkuIDs, false, isContinueWhenError, isAdd); err != nil {
globals.SugarLogger.Debugf("FullSyncStoresSkus failed2 store:%d failed with error:%v", storeMap.StoreID, err)
}
}

View File

@@ -219,7 +219,8 @@ func SyncStoreSkuNew2(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFla
return hint, err
}
func FullSyncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, excludeSkuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
// FullSyncStoreSkuNew isAdd 这个参数是因为在绑定门店映射是会删除门店商品和分类,才使用这个字段限制
func FullSyncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, excludeSkuIDs []int, isAsync, isContinueWhenError, isAdd bool) (hint string, err error) {
singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
task := tasksch.NewParallelTask("FullSyncStoreSkuNew", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
@@ -227,8 +228,10 @@ func FullSyncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
switch step {
case 0:
if singleStoreHandler != nil {
// _, err = ClearRemoteStoreStuffAndSetNew(ctx, task, vendorID, storeID, vendorStoreID, false, isContinueWhenError)
_, err = amendAndPruneStoreStuff(ctx, parentTask, vendorID, storeID, vendorStoreID, false, isContinueWhenError, AmendPruneAll, false)
//_, err = ClearRemoteStoreStuffAndSetNew(ctx, task, vendorID, storeID, vendorStoreID, false, isContinueWhenError)
if !isAdd {
_, err = amendAndPruneStoreStuff(ctx, parentTask, vendorID, storeID, vendorStoreID, false, isContinueWhenError, AmendPruneAll, false)
}
} else {
_, err = dao.SetStoreSkuSyncStatus(dao.GetDB(), vendorID, []int{storeID}, nil, model.SyncFlagStoreSkuOnlyMask)
}
@@ -1010,8 +1013,7 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v
remoteSkuMap := make(map[string]int)
for _, v := range remoteSkuList {
if vendorSkuID := v.SkuList[0].VendorSkuID; vendorSkuID != "" {
if localSkuMap[vendorSkuID] == nil ||
remoteSkuMap[vendorSkuID] == 1 /*skuID在平台重复典型的是美团可能会出现此类情况*/ {
if localSkuMap[vendorSkuID] == nil || remoteSkuMap[vendorSkuID] == 1 /*skuID在平台重复典型的是美团可能会出现此类情况*/ {
sku2Delete = append(sku2Delete, &partner.StoreSkuInfo{
SkuID: v.SkuList[0].SkuID,
VendorSkuID: vendorSkuID,

View File

@@ -1,7 +1,9 @@
package cms
import (
"encoding/json"
"fmt"
"git.rosy.net.cn/jx-callback/globals"
"time"
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
@@ -11,27 +13,28 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
"git.rosy.net.cn/jx-callback/business/partner/putils"
)
// CopyOnStoreSkuToOther 将一个美团门店分类和商品复制到另一个门店
func CopyOnStoreSkuToOther(ctx *jxcontext.Context, fromVendorStoreId, toStoreId int, isAsync bool) (hint string, err error) {
func CopyOnStoreSkuToOther(ctx *jxcontext.Context, fromVendorStoreId, toStoreId int, isAsync bool, offSet int) (hint string, err error) {
var (
db = dao.GetDB()
)
// 门店api加载
// fromStore, err := dao.GetStoreDetail(db, fromStoreId, model.VendorIDMTWM, "")
toStore, err := dao.GetStoreDetailByVendorStoreID(db, utils.Int2Str(toStoreId), model.VendorIDMTWM, "")
if err != nil {
return "", err
}
toStore, err := dao.GetStoreDetail(db, toStoreId, model.VendorIDMTWM, "")
if err != nil {
return "", err
}
//fromApi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, toStore.VendorOrgCode).(*mtwmapi.API)
toApi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, toStore.VendorOrgCode).(*mtwmapi.API)
toApi.SetToken(toStore.MtwmToken)
fromStore, err := dao.GetStoreDetailByVendorStoreID(db, utils.Int2Str(fromVendorStoreId), model.VendorIDMTWM, "")
if err != nil {
return "", err
}
fromApi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, fromStore.VendorOrgCode).(*mtwmapi.API)
fromApi.SetToken(fromStore.MtwmToken)
taskName := fmt.Sprintf("将平台门店[%d],分类和商品复制到[%d]", fromVendorStoreId, toStoreId)
config := tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(false)
@@ -40,46 +43,56 @@ func CopyOnStoreSkuToOther(ctx *jxcontext.Context, fromVendorStoreId, toStoreId
switch step {
case 1:
// 1.加载门店商品,删除商品.当分类下没有商品时.删除分类
errs := LoadingStoreSkuList(ctx, toApi, toStore.VendorStoreID)
if errs != nil && len(errs) > 0 {
return nil, errs[0]
}
//errs := LoadingStoreSkuList(ctx, toApi, toStore.VendorStoreID)
//if errs != nil && len(errs) > 0 {
// return nil, errs[0]
//}
case 2:
// 同步分类
fromCategoryList, err := toApi.RetailCatList(utils.Int2Str(fromVendorStoreId))
if err != nil {
return nil, err
}
for _, v := range fromCategoryList {
if err := toApi.RetailCatUpdate(toStore.VendorStoreID, v.Name, &mtwmapi.Param4UpdateCat{
CategoryCode: v.Code,
Sequence: v.Sequence,
}); err != nil {
return nil, err
}
if v.Children != nil && len(v.Children) != 0 {
for _, c := range v.Children {
if err := toApi.RetailCatUpdate(toStore.VendorStoreID, v.Name, &mtwmapi.Param4UpdateCat{
CategoryCode: v.Code,
SecondaryCategoryCode: c.Code,
SecondaryCategoryName: c.Name,
Sequence: c.Sequence,
}); err != nil {
return nil, err
}
}
}
}
//fromCategoryList, _ := fromApi.RetailCatList(utils.Int2Str(fromVendorStoreId))
//
//for _, v := range fromCategoryList {
// err := toApi.RetailCatUpdate(toStore.VendorStoreID, v.Name, &mtwmapi.Param4UpdateCat{
// CategoryCode: v.Code,
// Sequence: v.Sequence,
// })
// if err != nil {
// globals.SugarLogger.Debugf("err := RetailCatUpdate : %s", utils.Format4Output(err, false))
// }
// if v.Children != nil && len(v.Children) != 0 {
// for _, c := range v.Children {
// if err := toApi.RetailCatUpdate(toStore.VendorStoreID, v.Name, &mtwmapi.Param4UpdateCat{
// CategoryNameOrigin: v.Name,
// //CategoryCodeOrigin: v.Code,
// //CategoryCode: v.Code,
// SecondaryCategoryCode: c.Code,
// SecondaryCategoryName: c.Name,
// Sequence: c.Sequence,
// }); err != nil {
// globals.SugarLogger.Debugf("err := RetailCatUpdate Children : %s", utils.Format4Output(c, false))
// }
// }
// }
//}
case 3:
// 同步商品
fromFoodList, err1 := toApi.RetailListAll(utils.Int2Str(fromVendorStoreId))
if err1 != nil {
return nil, err1
}
if err := BatchInitData(ctx, fromFoodList, toApi, toStore.VendorStoreID); err != nil {
return nil, err
i := offSet
for {
// 同步商品
fromFoodList, err1 := fromApi.RetailListAll(utils.Int2Str(fromVendorStoreId), i)
if len(fromFoodList) == 0 || fromFoodList == nil {
return nil, fmt.Errorf("fromFoodList 为空 %s ,i:= %d", utils.Format4Output(err1, false), i)
}
if err := BatchInitData(ctx, fromFoodList, toApi, toStore.VendorStoreID); err != nil {
globals.SugarLogger.Debugf("BatchInitData : %s", utils.Format4Output(err, false))
}
if len(fromFoodList) < 100 {
break
}
i++
}
}
return
}
@@ -95,7 +108,7 @@ func CopyOnStoreSkuToOther(ctx *jxcontext.Context, fromVendorStoreId, toStoreId
}
func LoadingStoreSkuList(ctx *jxcontext.Context, api *mtwmapi.API, poiCode string) (err []error) {
foodList, err1 := api.RetailListAll(poiCode)
foodList, err1 := api.RetailListAll(poiCode, 0)
if err1 != nil {
return append(err, err1)
}
@@ -115,45 +128,125 @@ func LoadingStoreSkuList(ctx *jxcontext.Context, api *mtwmapi.API, poiCode strin
return
}
type Skus struct {
AvailableTimes struct {
Friday string `json:"friday"`
Monday string `json:"monday"`
Saturday string `json:"saturday"`
Sunday string `json:"sunday"`
Thursday string `json:"thursday"`
Tuesday string `json:"tuesday"`
Wednesday string `json:"wednesday"`
} `json:"available_times"`
BoxNum string `json:"box_num"`
BoxPrice string `json:"box_price"`
IsSellFlag int `json:"isSellFlag"`
LadderBoxNum string `json:"ladder_box_num"`
LadderBoxPrice string `json:"ladder_box_price"`
LimitOpenSyncStockNow bool `json:"limit_open_sync_stock_now"`
LocationCode string `json:"location_code"`
MinOrderCount string `json:"min_order_count"`
Price string `json:"price"`
SkuId string `json:"sku_id"`
Spec string `json:"spec"`
Stock string `json:"stock"`
Unit string `json:"unit"`
Upc string `json:"upc"`
Weight string `json:"weight"`
WeightForUnit string `json:"weight_for_unit"`
WeightUnit string `json:"weight_unit"`
}
// BatchInitData 批量创建商品
func BatchInitData(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi *mtwmapi.API, vendorStoreID string) error {
globals.SugarLogger.Debugf("===========[] %d", len(fromSku))
foodDataList := make([]map[string]interface{}, len(fromSku))
for i, storeSku := range fromSku {
foodData := make(map[string]interface{})
foodDataList[i] = foodData
foodData[mtwmapi.KeyAppFoodCode] = storeSku.AppFoodCode
foodData["skus"] = storeSku.Skus
if storeSku.AppFoodCode != "" {
foodData[mtwmapi.KeyAppFoodCode] = storeSku.AppFoodCode
} else {
foodData[mtwmapi.KeyAppFoodCode] = time.Now().UnixNano() + int64(i*3)
}
skus := []map[string]interface{}{
map[string]interface{}{
"sku_id": foodData[mtwmapi.KeyAppFoodCode],
},
}
foodData["skus"] = skus
foodData["name"] = utils.LimitUTF8StringLen(storeSku.Name, mtwmapi.MaxSkuNameCharCount)
foodData["description"] = storeSku.Description
foodData["price"] = storeSku.Price
if storeSku.MinOrderCount != 0 {
foodData["min_order_count"] = storeSku.MinOrderCount
} else {
foodData["min_order_count"] = 1
}
foodData["min_order_count"] = storeSku.MinOrderCount
foodData["unit"] = storeSku.Unit
attr := mtwm.SwitchAttr(toApi, vendorStoreID, int64(storeSku.TagID), 0, storeSku.Name)
if attr != "" {
foodData["common_attr_value"] = attr
//todo 增加商品必填属性
//attr := mtwm.SwitchAttr(toApi, vendorStoreID, int64(storeSku.TagID), 0, storeSku.Name)
//if attr != "" {
foodData["common_attr_value"] = storeSku.CommonAttrValue
//}
if storeSku.SecondaryCategoryCode != "" {
foodData["category_code"] = storeSku.SecondaryCategoryCode
} else {
foodData["category_name"] = storeSku.SecondaryCategoryName
}
foodData["category_code"] = storeSku.CategoryCode
foodData["category_name"] = storeSku.CategoryName
foodData["is_sold_out"] = storeSku.IsSoldOut
foodData["picture"] = storeSku.Picture
foodData["picture_contents"] = storeSku.PictureContents
foodData["sequence"] = storeSku.Sequence
foodData["tag_id"] = storeSku.TagID
}
failedFoodList, err2 := toApi.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList)
if err := err2; err == nil {
if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil {
skusAttr := make([]*Skus, 0, 0)
if err := json.Unmarshal([]byte(storeSku.Skus), &skusAttr); err != nil {
return err
}
} else if err2 != nil && len(failedFoodList) == 0 {
if errExt, ok := err2.(*utils.ErrorWithCode); ok {
return utils.UnmarshalUseNumber([]byte(errExt.ErrMsg()), &failedFoodList)
//skus2 := make([]*Skus, 0, 0)
for i2 := 0; i2 < len(skusAttr); i2++ {
if skusAttr[i2].Weight != "" && skusAttr[i2].WeightForUnit != "" {
skusAttr[i2].WeightForUnit = ""
}
//skus2 = append(skus2, skusAttr[i2])
skus[0]["spec"] = skusAttr[i2].Spec
skus[0]["price"] = skusAttr[i2].Price
skus[0]["stock"] = skusAttr[i2].Stock
if skusAttr[i2].Upc != "" {
skus[0]["upc"] = skusAttr[i2].Upc
}
skus[0]["ladder_box_num"] = skusAttr[i2].LadderBoxNum
skus[0]["ladder_box_price"] = skusAttr[i2].BoxPrice
if foodData["tag_id"] != nil {
skus[0]["weight"] = skusAttr[i2].Weight // weight字段仅限服饰鞋帽、美妆、日用品、母婴、生鲜果蔬、生活超市下的便利店/超市门店品类的商家使用
}
break
}
foodDataList[i] = foodData
}
count := len(foodDataList) / 10
if len(foodDataList)%10 != 0 {
count += 1
}
globals.SugarLogger.Debugf("===========[count] %d", count)
for i := 0; i < count; i++ {
if i == count-1 {
failedFoodList, err2 := toApi.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList[i*10:])
if err2 != nil {
globals.SugarLogger.Debugf("RetailBatchInitData err3 :%s", utils.Format4Output(err2, false))
}
if len(failedFoodList) != 0 {
globals.SugarLogger.Debugf("RetailBatchInitData err4 :%s", utils.Format4Output(failedFoodList, false))
}
} else {
failedFoodList, err2 := toApi.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList[i*10:(i+1)*10])
if err2 != nil {
globals.SugarLogger.Debugf("RetailBatchInitData err3 :%s", utils.Format4Output(err2, false))
}
if len(failedFoodList) != 0 {
globals.SugarLogger.Debugf("RetailBatchInitData err4 :%s", utils.Format4Output(failedFoodList, false))
}
}
}
return nil
}

View File

@@ -155,7 +155,7 @@ func GetCheckVendorCookie(ctx *jxcontext.Context, vendorIDs []int, isAuto bool)
resultMap, err := api.EbaiAPI.GetStoreOrderInfo(ebaiOrderID)
if len(resultMap) < 1 && err != nil {
if strings.Contains(err.Error(), ebaiErr) || strings.Contains(err.Error(), ebaiErr2) {
errMsg += fmt.Sprintf(" 饿百账号:[%v]的Cookie无效了")
errMsg += fmt.Sprintf(" 饿百账号:[%v]的Cookie无效了", v)
flag = true
}
}
@@ -163,7 +163,7 @@ func GetCheckVendorCookie(ctx *jxcontext.Context, vendorIDs []int, isAuto bool)
_, err := api.MtwmAPI.PackagePriceGet(mtStoreID)
if err != nil {
if strings.Contains(err.Error(), mtErr) {
errMsg += fmt.Sprintf(" 美团账号:[%v]的Cookie无效了")
errMsg += fmt.Sprintf(" 美团账号:[%v]的Cookie无效了", v)
flag = true
}
}
@@ -171,7 +171,7 @@ func GetCheckVendorCookie(ctx *jxcontext.Context, vendorIDs []int, isAuto bool)
result, err := api.JdAPI.GetJdUpcCodeByName("", jdUpcCode, 1, 5)
if len(result) < 1 && err != nil {
if strings.Contains(err.Error(), jdErr) {
errMsg += fmt.Sprintf(" 京东账号:[%v]的Cookie无效了")
errMsg += fmt.Sprintf(" 京东账号:[%v]的Cookie无效了", v)
flag = true
}
}
@@ -179,7 +179,7 @@ func GetCheckVendorCookie(ctx *jxcontext.Context, vendorIDs []int, isAuto bool)
_, err := api.JdShopAPI.OrderDetail("124350112427")
if err != nil {
if strings.Contains(err.Error(), "登录") {
errMsg += fmt.Sprintf("京东商城:[%v]的Cookie无效了")
errMsg += fmt.Sprintf("京东商城:[%v]的Cookie无效了", v)
flag = true
}
}

View File

@@ -200,10 +200,8 @@ func Init() {
ScheduleTimerFunc("UpdateTaoTotalMoney", func() {
orderman.UpdateTaoSettleInfo()
}, []string{
"18:30:00",
"06:30:00",
"00:30:00",
"12:30:00",
"18:07:00",
})
// 每分钟轮询一次,推送骑手信息(假的订单)

View File

@@ -1902,6 +1902,24 @@ func QueryOrdersForManageState(db *DaoDB, storeID, vendorID, status int, fromTim
return userCoupons, err
}
func GetTaoOrderVendor(db *DaoDB, startTime, endTime time.Time) (map[string]string, error) {
sql := ` SELECT * FROM goods_order g WHERE g.order_created_at >= ? AND g.order_created_at <= ? AND g.vendor_id = ? AND g.total_shop_money = ? `
param := []interface{}{startTime, endTime, model.VendorIDTaoVegetable, model.NO}
result := make([]*model.GoodsOrder, 0, 0)
if err := GetRows(db, &result, sql, param); err != nil {
return nil, err
}
data := make(map[string]string, 0)
if len(result) > 0 {
for _, v := range result {
data[v.VendorStoreID] = v.VendorOrgCode
}
}
return data, nil
}
func GetOrderStoreIDs(db *DaoDB, beginAt, endAt time.Time, vendorID int) (storeIDs []int, err error) {
var (
stores []*model.Store

View File

@@ -175,7 +175,19 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
storeParams.StationName = utils.LimitUTF8StringLen(storeParams.StationName, jdapi.MaxStoreNameLen)
}
if store.SyncStatus&(model.SyncFlagNewMask|model.SyncFlagStoreAddress) != 0 {
storeParams.StationAddress = store.Address
storeDetail, _ := dao.GetStoreDetail(db, storeID, model.VendorIDJD, "")
address := ""
if !strings.Contains(store.Address, "省") && model.ZXCityCodeMap[store.CityCode] != "" {
address += storeDetail.ProvinceName
}
if !strings.Contains(storeDetail.Address, "市") {
address += storeDetail.CityName
}
if !strings.Contains(storeDetail.Address, "县") || !strings.Contains(storeDetail.Address, "区") {
address += storeDetail.DistrictName
}
storeParams.StationAddress = address + storeDetail.Address
storeParams.CoordinateType = jdapi.CoordinateTypeAutonavi // 一直用高德
storeParams.Lng = jxutils.IntCoordinate2Standard(store.Lng)
storeParams.Lat = jxutils.IntCoordinate2Standard(store.Lat)
@@ -576,6 +588,18 @@ func (p *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName stri
if createParams.County == 310045 {
createParams.City = 49318
}
address := ""
if !strings.Contains(storeDetail.Address, "省") && model.ZXCityCodeMap[storeDetail.CityCode] != "" {
address += storeDetail.ProvinceName
}
if !strings.Contains(storeDetail.Address, "市") {
address += storeDetail.CityName
}
if !strings.Contains(storeDetail.Address, "县") || !strings.Contains(storeDetail.Address, "区") {
address += storeDetail.DistrictName
}
createParams.StationAddress = address + storeDetail.Address
result, err := getAPI(vendorOrgCode).CreateStore(createParams)
if err != nil {
return "", err

View File

@@ -185,6 +185,10 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
order.BusinessType = model.BusinessTypeDingshida
}
if utils.Interface2Int64WithDefault(result["delivery_time"], 0) == 0 {
order.ExpectedDeliveredTime = getTimeFromTimestamp(utils.Interface2Int64WithDefault(result["estimate_arrival_time"], 0))
}
originalLng := utils.MustInterface2Float64(result["longitude"])
originalLat := utils.MustInterface2Float64(result["latitude"])
order.ConsigneeLng = jxutils.StandardCoordinate2Int(originalLng)

View File

@@ -66,8 +66,6 @@ func (c *PurchaseHandler) OnAfsOrderMsg(msg *mtwmapi.CallbackMsg) (retVal *mtwma
func (c *PurchaseHandler) onAfsOrderMsg(msg *mtwmapi.CallbackMsg) (retVal *mtwmapi.CallbackResponse) {
var err error
orderStatus := c.callbackAfsMsg2Status(msg)
globals.SugarLogger.Debugf("=================msg := %s", utils.Format4Output(msg, false))
globals.SugarLogger.Debugf("=================orderStatus := %s", utils.Format4Output(orderStatus, false))
needCallNew := orderStatus.Status == model.AfsOrderStatusWait4Approve || orderStatus.Status == model.AfsOrderStatusNew
if !needCallNew {
_, err := partner.CurOrderManager.LoadAfsOrder(orderStatus.VendorOrderID, orderStatus.VendorID)
@@ -148,8 +146,6 @@ func (c *PurchaseHandler) onAfsOrderMsg(msg *mtwmapi.CallbackMsg) (retVal *mtwma
if orderStatus.Status == model.AfsOrderStatusFinished {
afsOrder.AfsFinishedAt = afsOrder.AfsCreatedAt
}
globals.SugarLogger.Debugf("afsOrder=============== : %s", utils.Format4Output(afsOrder, false))
globals.SugarLogger.Debugf("orderStatus=============== : %s", utils.Format4Output(orderStatus, false))
err = partner.CurOrderManager.OnAfsOrderNew(afsOrder, orderStatus)
}
} else {

View File

@@ -576,7 +576,6 @@ func SwitchAttr(apiObj *mtwmapi.API, vendorStoreID string, vendorCatID int64, na
}
//更新进数据库
dao.UpdateSkuNameMtAttr(db, int64(nameID), attrs)
globals.SugarLogger.Debugf("SwitchAttr attrs=%s", utils.Format4Output(attrs, false))
return attrs
}

View File

@@ -916,7 +916,10 @@ func GetOrderTotalShopMoney(appOrgCode string, vendorStoreID string, start, end
}
var totalIndex int64 = 0
result, _ := api.QueryBillList(param)
result, err := api.QueryBillList(param)
if err != nil {
return settlement, nil
}
for _, v := range *result.TxdBillDetailBOS {
if *v.OrderType == "positive" {
settlement[*v.BizOrderId] = *v.ReceivableAmount
@@ -931,7 +934,10 @@ func GetOrderTotalShopMoney(appOrgCode string, vendorStoreID string, start, end
for i := 2; i <= int(totalIndex); i++ {
param.TxdBillListGetRequest.PageIndex = utils.Int64ToPointer(int64(i))
result2, _ := api.QueryBillList(param)
result2, err := api.QueryBillList(param)
if err != nil {
return settlement, nil
}
for _, v := range *result2.TxdBillDetailBOS {
if *v.OrderType == "positive" {
settlement[*v.BizOrderId] = *v.ReceivableAmount

View File

@@ -26,8 +26,12 @@ const (
// OnOrderMsg 抖音
func OnOrderMsg(msgId string, msg interface{}) (response *tiktokShop.CallbackResponse) {
globals.SugarLogger.Debugf("GetTiktokApi msg := %s", utils.Format4Output(msg, false))
if CurPurchaseHandler != nil {
orderId, shopId, _ := api.TiktokStore.GetCallbackOrderId(msgId, msg)
if shopId == 53802960 {
return tiktokShop.Err2CallbackResponse(nil, "")
}
orderDetail, err := GetTiktokApi(utils.Int64ToStr(shopId), 0, "").GetTiktokOrderDetail(orderId)
if err != nil {
return tiktokShop.Err2CallbackResponse(err, "")

View File

@@ -239,7 +239,7 @@ func (c *StoreController) AddStoreVendorMap() {
c.callAddStoreVendorMap(func(params *tStoreAddStoreVendorMapParams) (retVal interface{}, errCode string, err error) {
storeMap := &model.StoreMap{}
if err = utils.UnmarshalUseNumber([]byte(params.Payload), storeMap); err == nil {
retVal, err = cms.AddStoreVendorMap(params.Ctx, nil, params.VendorID, params.VendorOrgCode, params.StoreID, storeMap)
retVal, err = cms.AddStoreVendorMap(params.Ctx, nil, params.VendorID, params.VendorOrgCode, params.StoreID, storeMap, true)
}
return retVal, "", err
})

View File

@@ -1051,12 +1051,13 @@ func (c *StoreSkuController) CopyMtToJd() {
// @Param token header string true "认证token"
// @Param fromStoreID formData string true "被复制门店id"
// @Param toStoreID formData string true "复制到门店id"
// @Param offSet formData int true "跳过页码"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CopyMtToMt [post]
func (c *StoreSkuController) CopyMtToMt() {
c.callCopyMtToMt(func(params *tStoreSkuCopyMtToMtParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.CopyOnStoreSkuToOther(params.Ctx, utils.Str2Int(params.FromStoreID), utils.Str2Int(params.ToStoreID), false)
retVal, err = cms.CopyOnStoreSkuToOther(params.Ctx, utils.Str2Int(params.FromStoreID), utils.Str2Int(params.ToStoreID), false, params.OffSet)
return retVal, errCode, err
})
}

View File

@@ -122,7 +122,7 @@ func (c *SyncController) FullSyncStoresSkus() {
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.VendorIDs, &vendorIDs); err != nil {
return retVal, "", err
}
retVal, err = cms.CurVendorSync.FullSyncStoresSkus(params.Ctx, db, vendorIDs, storeIDs, true, nil, params.IsAsync, params.IsContinueWhenError)
retVal, err = cms.CurVendorSync.FullSyncStoresSkus(params.Ctx, db, vendorIDs, storeIDs, true, nil, params.IsAsync, params.IsContinueWhenError, false)
return retVal, "", err
})
}

View File

@@ -68,25 +68,29 @@ func (a *APIManager) GetAPI(vendorID int, appOrgCode string) (pfAPI interface{})
pfAPI = api.Mtwm2API
}
case model.VendorIDTaoVegetable:
api := api.TaoVegetableApi
codes, _ := dao.GetVendorOrgCode(db, vendorID, appOrgCode, "platform")
if len(codes) == 0 {
return nil
}
code := codes[0]
api = tao_vegetable.NewTaoVegetable(code.AppKey, code.AppSecret, beego.AppConfig.DefaultString("taoVegetableServerUrl", ""))
if code.Token != "" {
var tokenInfo *tao_vegetable.StoreTokenInfo
if err := json.Unmarshal([]byte(code.Token), &tokenInfo); err != nil {
api2 := api.TaoVegetableApi
if api2 == nil || api2.GetToken() == "" {
codes, _ := dao.GetVendorOrgCode(db, vendorID, appOrgCode, "platform")
if len(codes) == 0 {
return nil
}
if tokenInfo.AccessToken != "" && tokenInfo.ExpireTime > time.Now().UnixNano()/1e6 {
api.SetToken(tokenInfo.AccessToken)
} else {
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "DDC5657B43EE11E9A9FF525400E86DC0", "淘鲜达token过期", ",请重新授权")
code := codes[0]
api2 = tao_vegetable.NewTaoVegetable(code.AppKey, code.AppSecret, beego.AppConfig.DefaultString("taoVegetableServerUrl", ""))
if code.Token != "" {
var tokenInfo *tao_vegetable.StoreTokenInfo
if err := json.Unmarshal([]byte(code.Token), &tokenInfo); err != nil {
return nil
}
if tokenInfo.AccessToken != "" && tokenInfo.ExpireTime > time.Now().UnixNano()/1e6 {
api2.SetToken(tokenInfo.AccessToken)
} else {
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "2452A93EEB9111EC9B06525400E86DC0", "淘鲜达token过期", ",请重新授权")
}
}
api.TaoVegetableApi = api2
}
pfAPI = api
pfAPI = api2
case model.VendorIDEBAI:
pfAPI = api.EbaiAPI
case model.VendorIDJDShop: