Merge branch 'jdshop' of https://e.coding.net/rosydev/jx-callback into jdshop
This commit is contained in:
@@ -3,7 +3,11 @@ package delivery
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"math/big"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
|
||||
@@ -322,3 +326,44 @@ func UpdateFakeWayBillToTiktok() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// AutoSettingFakeDelivery 自动设置骑手, 推送假订单
|
||||
func AutoSettingFakeDelivery() {
|
||||
db := dao.GetDB()
|
||||
// 查询需要刷单的门店
|
||||
configList, err := dao.QueryConfigs(db, "storeIdList", "AutoDelivery", "")
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("抖音自动刷单获取刷单门店列表错误:%v", err)
|
||||
return
|
||||
}
|
||||
if len(configList) != model.YES {
|
||||
globals.SugarLogger.Errorf("newConfig 刷单门店设置异常")
|
||||
return
|
||||
}
|
||||
|
||||
// 获取刷单门店订单
|
||||
orderList, err := dao.GetOrderListByStoreList(db, utils.StringSlice2Int64(strings.Split(configList[0].Value, ",")))
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("获取门店刷单记录错误")
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range orderList {
|
||||
jxutils.CallMsgHandler(func() {
|
||||
// 1.根据订单客户地址获取骑手列表
|
||||
randNumber, _ := rand.Int(rand.Reader, big.NewInt(200))
|
||||
randTime := randNumber.Int64()
|
||||
riderInfo, err := dao.GetAddressRiderInfo(db, strings.Split(v.ConsigneeAddress, "市")[0], randTime)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("自动获取骑手信息错误:[%v]", err)
|
||||
return
|
||||
}
|
||||
// 自动发单
|
||||
if err := defsch.FixedScheduler.SelfDeliveringAndUpdateStatus(jxcontext.AdminCtx, v.VendorOrderID, v.VendorID, jxcontext.AdminCtx.GetUserName(), riderInfo.CourierName, riderInfo.CourierMobile); err != nil {
|
||||
globals.SugarLogger.Errorf("自动发货错误:[%v]", err)
|
||||
return
|
||||
}
|
||||
}, jxutils.ComposeUniversalOrderID(v.VendorOrderID, model.VendorIDDD))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -89,6 +89,9 @@ type IPurchasePlatformOrderHandler interface {
|
||||
ComplaintRider(vendorOrderId string, resonID int, resonContent string) (err error)
|
||||
//推送订单骑手信息
|
||||
GetOrderRider(vendorOrgCode, vendorStoreID string, param map[string]interface{}) (err error)
|
||||
|
||||
// 获取各个平台订单的结算信息
|
||||
GetOrderSettleAccounts(order *model.GoodsOrder) (int64, error)
|
||||
}
|
||||
|
||||
type IAddWaybillTip interface {
|
||||
|
||||
@@ -350,7 +350,7 @@ func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store,
|
||||
return
|
||||
}
|
||||
content := ""
|
||||
if store.PrinterFontSize == partner.PrinterFontSizeBig {
|
||||
if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 {
|
||||
content = c.getOrderContentBig(order, store.Tel1, storeDetail)
|
||||
} else {
|
||||
content = c.getOrderContent(order, store.Tel1, storeDetail)
|
||||
|
||||
@@ -786,3 +786,14 @@ func (c *PurchaseHandler) CancelLogisticsByWmOrderId(order *model.GoodsOrder, re
|
||||
func (c *PurchaseHandler) OrderLogisticsStatus(orderId int64) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// GetOrderSettleAccounts 获取订单结算信息
|
||||
func (c *PurchaseHandler) GetOrderSettleAccounts(order *model.GoodsOrder) (int64, error) {
|
||||
orderInfo, err := api.EbaiAPI.OrderGet(order.VendorOrderID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
orderMap := orderInfo["order"].(map[string]interface{})
|
||||
|
||||
return utils.ForceInterface2Int64(orderMap["shop_fee"]), nil
|
||||
}
|
||||
|
||||
@@ -344,3 +344,8 @@ func (c *PurchaseHandler) CancelLogisticsByWmOrderId(order *model.GoodsOrder, re
|
||||
func (c *PurchaseHandler) OrderLogisticsStatus(orderId int64) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// GetOrderSettleAccounts 获取订单结算信息
|
||||
func (c *PurchaseHandler) GetOrderSettleAccounts(order *model.GoodsOrder) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@@ -660,3 +660,12 @@ func (c *PurchaseHandler) CancelLogisticsByWmOrderId(order *model.GoodsOrder, re
|
||||
func (c *PurchaseHandler) OrderLogisticsStatus(orderId int64) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// GetOrderSettleAccounts 获取订单结算信息
|
||||
func (c *PurchaseHandler) GetOrderSettleAccounts(goods *model.GoodsOrder) (int64, error) {
|
||||
settlement, err := getAPI(goods.VendorOrgCode).OrderShoudSettlementService2(goods.VendorOrderID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return settlement.SettlementAmount, nil
|
||||
}
|
||||
|
||||
@@ -328,3 +328,8 @@ func (c *PurchaseHandler) CancelLogisticsByWmOrderId(order *model.GoodsOrder, re
|
||||
func (c *PurchaseHandler) OrderLogisticsStatus(orderId int64) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// GetOrderSettleAccounts 获取订单结算信息
|
||||
func (c *PurchaseHandler) GetOrderSettleAccounts(order *model.GoodsOrder) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@@ -155,3 +155,8 @@ func (c *PurchaseHandler) CancelLogisticsByWmOrderId(order *model.GoodsOrder, re
|
||||
func (c *PurchaseHandler) OrderLogisticsStatus(orderId int64) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// GetOrderSettleAccounts 获取订单结算信息
|
||||
func (c *PurchaseHandler) GetOrderSettleAccounts(order *model.GoodsOrder) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@@ -849,3 +849,20 @@ func (c *PurchaseHandler) CancelLogisticsByWmOrderId(order *model.GoodsOrder, re
|
||||
func (c *PurchaseHandler) OrderLogisticsStatus(orderId int64) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// GetOrderSettleAccounts 获取订单结算信息
|
||||
func (c *PurchaseHandler) GetOrderSettleAccounts(order *model.GoodsOrder) (int64, error) {
|
||||
oderDetail, err := getAPI(order.VendorOrgCode, 0, order.VendorStoreID).OrderGetOrderDetail(utils.Str2Int64(order.VendorOrderID), true)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if poiReceiveDetailStr := utils.Interface2String(oderDetail["poi_receive_detail"]); poiReceiveDetailStr != "" {
|
||||
var poiReceiveDetail *mtwmapi.PoiReceiveDetailInfo
|
||||
utils.UnmarshalUseNumber([]byte(poiReceiveDetailStr), &poiReceiveDetail)
|
||||
if poiReceiveDetail != nil {
|
||||
return poiReceiveDetail.WmPoiReceiveCent, nil
|
||||
}
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@@ -2,9 +2,6 @@ package mtwm
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
@@ -15,6 +12,8 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/putils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -163,30 +162,19 @@ func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID in
|
||||
storeCat.CatSyncStatus |= model.SyncFlagNewMask
|
||||
err = p.CreateStoreCategory(ctx, storeID, vendorStoreID, storeCat)
|
||||
}
|
||||
|
||||
// 门店内存在重复的分类:【柑桔柚类】 【底料】,请先删除重复分类后再操作。
|
||||
if err != nil && strings.Contains(err.Error(), "门店内存在重复的分类:") {
|
||||
globals.SugarLogger.Debugf("==========err %s", err.Error())
|
||||
storeCategoryList, err2 := api.RetailCatList(vendorStoreID)
|
||||
globals.SugarLogger.Debugf("==========err2 %v", err2)
|
||||
globals.SugarLogger.Debugf("==========err %s", utils.Format4Output(storeCategoryList, false))
|
||||
if err2 != nil {
|
||||
err = err2
|
||||
} else {
|
||||
for _, v := range storeCategoryList {
|
||||
globals.SugarLogger.Debugf("storeCategoryList==========err %s", err.Error())
|
||||
if len(v.Children) > 0 {
|
||||
for _, c := range v.Children {
|
||||
if strings.Contains(c.Name, err.Error()) {
|
||||
api.RetailCatDelete(vendorStoreID, "", c.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.Contains(v.Name, err.Error()) {
|
||||
api.RetailCatDelete(vendorStoreID, "", v.Name)
|
||||
for _, v := range deleteRepeatCat(err.Error()) {
|
||||
if len(v) > 0 {
|
||||
if err2 := api.RetailCatDelete(vendorStoreID, "", v, model.YES); err != nil {
|
||||
globals.SugarLogger.Errorf("RetailCatDelete delete err : [%v]", err2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
// storeCat.VendorCatID = utils.FilterEmoji(storeCat.Name)
|
||||
storeCat.VendorCatID = utils.Int2Str(storeCat.ID)
|
||||
@@ -194,6 +182,40 @@ func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID in
|
||||
return err
|
||||
}
|
||||
|
||||
// deleteRepeatCat 门店内存在重复的分类:【柑桔柚类】 【底料】 【火锅】,请先删除重复分类后再操作。
|
||||
func deleteRepeatCat(param string) []string {
|
||||
firstIndex := strings.Index(param, "【")
|
||||
lastIndex := strings.LastIndex(param, "】")
|
||||
newParam := param[firstIndex:lastIndex]
|
||||
deleteCat := make([]string, 0, 0)
|
||||
for _, v := range strings.Split(newParam, "【") {
|
||||
if strings.TrimSpace(v) == "" {
|
||||
continue
|
||||
} else if strings.Contains(v, "【") {
|
||||
for _, v2 := range strings.Split(v, "【") {
|
||||
if strings.TrimSpace(v) == "" {
|
||||
continue
|
||||
}
|
||||
if strings.TrimSpace(v2) != "" {
|
||||
deleteCat = append(deleteCat, v2)
|
||||
}
|
||||
}
|
||||
} else if strings.Contains(v, "】") {
|
||||
for _, v3 := range strings.Split(v, "】") {
|
||||
if strings.TrimSpace(v3) == "" {
|
||||
continue
|
||||
}
|
||||
if strings.TrimSpace(v3) != "" {
|
||||
deleteCat = append(deleteCat, v3)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
deleteCat = append(deleteCat, v)
|
||||
}
|
||||
}
|
||||
return deleteCat
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
||||
return p.CreateStoreCategory(ctx, storeID, vendorStoreID, storeCat)
|
||||
}
|
||||
@@ -201,7 +223,7 @@ func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID in
|
||||
func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (err error) {
|
||||
if false {
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
err = getAPI(getStoreVendorOrgCode(storeID), storeID, vendorStoreID).RetailCatDelete(vendorStoreID, tryCatName2Code(vendorCatID), vendorCatID)
|
||||
err = getAPI(getStoreVendorOrgCode(storeID), storeID, vendorStoreID).RetailCatDelete(vendorStoreID, tryCatName2Code(vendorCatID), vendorCatID, model.NO)
|
||||
}
|
||||
} else {
|
||||
var catCodes []string
|
||||
|
||||
@@ -27,7 +27,6 @@ const (
|
||||
|
||||
// OnOrderMsg 抖音
|
||||
func OnOrderMsg(msgId string, msg interface{}) (response *tiktokShop.CallbackResponse) {
|
||||
globals.SugarLogger.Debugf("guoyuan %s,%s", msgId, utils.Format4Output(msg, false))
|
||||
if CurPurchaseHandler != nil {
|
||||
orderId, shopId, _ := api.TiktokStore.GetCallbackOrderId(msgId, msg)
|
||||
globals.SugarLogger.Debugf("order_id %s,%d", orderId, shopId)
|
||||
|
||||
@@ -87,25 +87,24 @@ func (p *PurchaseHandler) getOrder(vendorOrgCode, vendorOrderID, vendorStoreID s
|
||||
}
|
||||
orderMap = result
|
||||
order = &model.GoodsOrder{
|
||||
VendorOrderID: result.OrderId,
|
||||
VendorID: model.VendorIDDD,
|
||||
VendorStoreID: "",
|
||||
StoreID: 0,
|
||||
CoordinateType: model.CoordinateTypeMars,
|
||||
BuyerComment: result.BuyerWords,
|
||||
ExpectedDeliveredTime: getTimeFromTimestamp(result.EarliestReceiptTime + 30*60), // 预计最晚送达时间
|
||||
PickDeadline: utils.DefaultTimeValue,
|
||||
VendorStatus: utils.Int64ToStr(result.OrderStatus), //1待支付/103部分支付/105已支付/2备货中/101部分发货/3已发货/4取消/完成/21发货前退款完成/22发货后退款/39收货后退款
|
||||
OrderSeq: 0,
|
||||
StatusTime: getTimeFromTimestamp(result.CreateTime),
|
||||
OrderCreatedAt: getTimeFromTimestamp(result.CreateTime),
|
||||
OriginalData: string(utils.MustMarshal(result)),
|
||||
ActualPayPrice: result.PayAmount,
|
||||
BaseFreightMoney: result.PostAmount,
|
||||
InvoiceTitle: "",
|
||||
InvoiceTaxerID: "",
|
||||
InvoiceEmail: "",
|
||||
VendorOrgCode: vendorOrgCode,
|
||||
VendorOrderID: result.OrderId,
|
||||
VendorID: model.VendorIDDD,
|
||||
VendorStoreID: "",
|
||||
StoreID: 0,
|
||||
CoordinateType: model.CoordinateTypeMars,
|
||||
BuyerComment: result.BuyerWords,
|
||||
PickDeadline: utils.DefaultTimeValue,
|
||||
VendorStatus: utils.Int64ToStr(result.OrderStatus), //1待支付/103部分支付/105已支付/2备货中/101部分发货/3已发货/4取消/完成/21发货前退款完成/22发货后退款/39收货后退款
|
||||
OrderSeq: 0,
|
||||
StatusTime: getTimeFromTimestamp(result.CreateTime),
|
||||
OrderCreatedAt: getTimeFromTimestamp(result.CreateTime),
|
||||
OriginalData: string(utils.MustMarshal(result)),
|
||||
ActualPayPrice: result.PayAmount,
|
||||
BaseFreightMoney: result.PostAmount,
|
||||
InvoiceTitle: "",
|
||||
InvoiceTaxerID: "",
|
||||
InvoiceEmail: "",
|
||||
VendorOrgCode: vendorOrgCode,
|
||||
}
|
||||
|
||||
if result.FinishTime != 0 {
|
||||
@@ -195,18 +194,27 @@ func (p *PurchaseHandler) getOrder(vendorOrgCode, vendorOrderID, vendorStoreID s
|
||||
globals.SugarLogger.Debugf("平台门店未绑定到京西系统 %s", err.Error())
|
||||
return nil, nil, err
|
||||
}
|
||||
// 订单不在门店营业时间来的订单,
|
||||
openTime := localStore.OpenTime1 // 门店开始营业时间
|
||||
closeTime := localStore.CloseTime1 // 门店结束营业时间
|
||||
if localStore.CloseTime2 != 0 {
|
||||
closeTime = localStore.CloseTime2
|
||||
}
|
||||
|
||||
h, m, _ := order.ExpectedDeliveredTime.Clock()
|
||||
if order.ExpectedDeliveredTime.Day() == time.Now().Day() && utils.Str2Int16(fmt.Sprintf("%d%d", h, m)) >= openTime && utils.Str2Int16(fmt.Sprintf("%d%d", h, m)) < closeTime && localStore.Status == model.StoreStatusOpened {
|
||||
// 订单不在门店营业时间来的订单,
|
||||
//openTime := localStore.OpenTime1 // 门店开始营业时间
|
||||
//closeTime := localStore.CloseTime1 // 门店结束营业时间
|
||||
//if localStore.CloseTime2 != 0 {
|
||||
// closeTime = localStore.CloseTime2
|
||||
//}
|
||||
//
|
||||
//h, m, _ := order.ExpectedDeliveredTime.Clock()
|
||||
//if order.ExpectedDeliveredTime.Day() == time.Now().Day() && utils.Str2Int16(fmt.Sprintf("%d%d", h, m)) >= openTime && utils.Str2Int16(fmt.Sprintf("%d%d", h, m)) < closeTime && localStore.Status == model.StoreStatusOpened {
|
||||
// order.BusinessType = model.BusinessTypeImmediate
|
||||
//} else {
|
||||
// order.BusinessType = model.BusinessTypeDingshida
|
||||
//}
|
||||
|
||||
if result.EarlyArrival { // 立即达
|
||||
order.BusinessType = model.BusinessTypeImmediate
|
||||
} else {
|
||||
order.ExpectedDeliveredTime = getTimeFromTimestamp(result.TargetArrivalTime + 30*60) // 预计最晚送达时间
|
||||
} else { // 定时达
|
||||
order.BusinessType = model.BusinessTypeDingshida
|
||||
order.ExpectedDeliveredTime = getTimeFromTimestamp(result.EarliestReceiptTime + 30*60) // 预计最晚送达时间
|
||||
}
|
||||
|
||||
// 用户保密信息脱敏
|
||||
@@ -1030,3 +1038,8 @@ func GetOrderTotalShopMoney(appOrgCode string, orderIds string, nextStartIndex s
|
||||
func GetOrderDetail(appOrgCode, vendorOrderID string) (*order_orderDetail_response.ShopOrderDetail, error) {
|
||||
return getAPI(appOrgCode, 0, "").GetTiktokOrderDetail(vendorOrderID)
|
||||
}
|
||||
|
||||
// GetOrderSettleAccounts 获取订单结算信息
|
||||
func (c *PurchaseHandler) GetOrderSettleAccounts(order *model.GoodsOrder) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@@ -152,21 +152,25 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
if len(localThing) == 0 {
|
||||
if err := dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(time.Now().Unix()), storeDetail.VendorOrgCode, "本地不存在,线上也不存在", model.ThingTypeSku, model.ThingTypeSyncing); err != nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
|
||||
continue
|
||||
}
|
||||
param, failedList2 := makeMainProductSku(db, api, storeSku, storeDetail, storeID, vendorStoreID, syncType)
|
||||
if len(failedList2) != 0 {
|
||||
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
|
||||
failedList = append(failedList, failedList2...)
|
||||
continue
|
||||
}
|
||||
tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品,同步主商品
|
||||
if err != nil {
|
||||
dao.UpdateThingMap(db, model.ThingTypeSyncFail, utils.Int64ToStr(time.Now().Unix()), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode)
|
||||
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
continue
|
||||
}
|
||||
|
||||
if err := dao.UpdateThingMap(db, model.ThingTypeSyncSuccess, utils.Int64ToStr(tiktokResult.ProductId), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode); err != nil {
|
||||
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
continue
|
||||
}
|
||||
@@ -190,12 +194,14 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
}
|
||||
tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品,同步主商品
|
||||
if err != nil {
|
||||
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
|
||||
dao.UpdateThingMap(db, model.ThingTypeSyncFail, utils.Int64ToStr(time.Now().Unix()), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode)
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
continue
|
||||
}
|
||||
|
||||
if err := dao.UpdateThingMap(db, model.ThingTypeSyncSuccess, utils.Int64ToStr(tiktokResult.ProductId), storeSku.SkuID, model.VendorIDDD, storeDetail.VendorOrgCode); err != nil {
|
||||
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
continue
|
||||
}
|
||||
@@ -214,6 +220,8 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
if time.Now().Unix()-localThing[0].CreatedAt.Unix() > 300 {
|
||||
dao.DeleteThingToTiktokMapList(model.VendorIDDD, localThing[0].VendorThingID, storeSku.SkuID)
|
||||
}
|
||||
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("商品同步中或同步错误"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
continue
|
||||
} else if localThing[0].SyncStatus == model.ThingTypeSyncSuccess {
|
||||
// 主商品存在,直接同步子商品
|
||||
@@ -249,15 +257,16 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
updateParam.Pic = param.Pic
|
||||
updateParam.Description = param.Description
|
||||
updateParam.WeightUnit = tiktokShop.WeightUint_G
|
||||
updateParam.StandardBrandId, err = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, updateParam.CategoryLeafId)
|
||||
|
||||
updateParam.ProductId = mainOrderDetail.ProductId
|
||||
updateParam.MainProductId = mainProductId
|
||||
updateParam.SpecPrices = param.SpecPrices
|
||||
updateParam.StandardBrandId = param.StandardBrandId
|
||||
if err2 := api.EditStoreCommodity(updateParam); err2 != nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err2, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
|
||||
}
|
||||
storeSku.SkuSyncStatus = model.SyncFlagNewMask // 只创建主品,子品都没做
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("修改主品,主品审核中/失败,子商品未创建"), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
continue
|
||||
}
|
||||
@@ -368,8 +377,8 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
}
|
||||
|
||||
// 获取商品的属性
|
||||
if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" {
|
||||
param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
|
||||
if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" || storeSku.UpcTiktokBrandId == "" {
|
||||
param.ProductFormatNew, param.StandardBrandId, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId)
|
||||
if err != nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
continue
|
||||
@@ -378,7 +387,12 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
param.ProductFormatNew = storeSku.TiktokAttribute
|
||||
}
|
||||
// 获取品牌
|
||||
param.StandardBrandId = 789194134 // 默认品牌京西菜市
|
||||
if param.StandardBrandId == 0 {
|
||||
param.StandardBrandId, _ = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, param.CategoryLeafId)
|
||||
}
|
||||
if param.StandardBrandId == 0 {
|
||||
param.StandardBrandId = 596120136 // 无品牌
|
||||
}
|
||||
|
||||
// 修改商品
|
||||
param.ProductId = mainIdInt
|
||||
@@ -454,22 +468,22 @@ func makeMainProductSku(db *dao.DaoDB, api *tiktokShop.API, storeSku *dao.StoreS
|
||||
// spec_prices
|
||||
param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, 0, storeSku)
|
||||
// 获取商品的属性
|
||||
if storeSku.TiktokAttribute != "" && storeSku.TiktokAttribute != "{}" {
|
||||
param.ProductFormatNew = storeSku.TiktokAttribute
|
||||
} else if storeSku.VendorSkuAttrId != "" && storeSku.VendorSkuAttrId != "{}" {
|
||||
if storeSku.TiktokAttribute != "" && storeSku.TiktokAttribute != "{}" && storeSku.UpcTiktokBrandId != "" {
|
||||
param.ProductFormatNew = storeSku.TiktokAttribute
|
||||
} else {
|
||||
param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
|
||||
param.ProductFormatNew, param.StandardBrandId, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId)
|
||||
//param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
|
||||
if err != nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
param.StandardBrandId, err = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, param.CategoryLeafId)
|
||||
if err != nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
return
|
||||
if param.StandardBrandId == 0 {
|
||||
param.StandardBrandId, _ = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, param.CategoryLeafId)
|
||||
}
|
||||
if param.StandardBrandId == 0 {
|
||||
param.StandardBrandId = 596120136
|
||||
}
|
||||
|
||||
param.FreightId, param.SaleLimitId, err = getFreightIdAndSaleLimitId(api, db, storeDetail, vendorStoreID)
|
||||
@@ -481,12 +495,23 @@ func makeMainProductSku(db *dao.DaoDB, api *tiktokShop.API, storeSku *dao.StoreS
|
||||
}
|
||||
|
||||
func getTiktokBrandId(api *tiktokShop.API, db *dao.DaoDB, upc, upcBrandName, upcTiktokBrandId string, categoryLeafId int64) (int64, error) {
|
||||
globals.SugarLogger.Debugf("upc:%s,upcBrandName:%s,upcTiktokBrandId:%s,categoryLeafId:%d", upc, upcBrandName, upcTiktokBrandId, categoryLeafId)
|
||||
if upc == "" { // 默认品牌京西菜市 596120136
|
||||
return 596120136, nil
|
||||
} else if upc != "" && upcBrandName != "" && upcTiktokBrandId != "" {
|
||||
return utils.Str2Int64(upcTiktokBrandId), nil
|
||||
} else if upc != "" && upcBrandName != "" && upcTiktokBrandId == "" {
|
||||
standardBrandId, err := api.GetSkuBrand(categoryLeafId, upcBrandName)
|
||||
brandName := upcBrandName
|
||||
if strings.Contains(brandName, "/") {
|
||||
brandName = strings.Split(brandName, "/")[0]
|
||||
}
|
||||
if strings.Contains(brandName, "(") {
|
||||
brandName = strings.Split(brandName, "(")[0]
|
||||
}
|
||||
if strings.Contains(brandName, "(") {
|
||||
brandName = strings.Split(brandName, "(")[0]
|
||||
}
|
||||
standardBrandId, err := api.GetSkuBrand(categoryLeafId, brandName)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -497,6 +522,15 @@ func getTiktokBrandId(api *tiktokShop.API, db *dao.DaoDB, upc, upcBrandName, upc
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if strings.Contains(brandName, "/") || strings.Contains(brandName, "(") || strings.Contains(brandName, "(") {
|
||||
brandName = strings.Split(brandName, "/")[0]
|
||||
}
|
||||
if strings.Contains(brandName, "(") {
|
||||
brandName = strings.Split(brandName, "(")[0]
|
||||
}
|
||||
if strings.Contains(brandName, "(") {
|
||||
brandName = strings.Split(brandName, "(")[0]
|
||||
}
|
||||
standardBrandId, err := api.GetSkuBrand(categoryLeafId, brandName)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -907,19 +941,21 @@ func GetTiktokImgList(api *tiktokShop.API, storeId, appOrgCode string, detailImg
|
||||
return strings.Join(tiktokImg, "|"), detailTiktok, nil
|
||||
}
|
||||
|
||||
func MakeProductFormatNew(api *tiktokShop.API, skuNameId int64, categoryLeafId int64) (string, error) {
|
||||
func MakeProductFormatNew(api *tiktokShop.API, skuNameId int64, categoryLeafId int64, upcCode, upcBrandName, upcTiktokBrandId string) (string, int64, error) {
|
||||
db := dao.GetDB()
|
||||
categoryList, err := api.GetCatePropertyV2(categoryLeafId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", 0, err
|
||||
}
|
||||
categoryMap := make(map[string][]map[string]interface{})
|
||||
tiktokBrandId, _ := getTiktokBrandId(api, db, upcCode, upcBrandName, upcTiktokBrandId, categoryLeafId)
|
||||
for _, v := range categoryList.Data.Data {
|
||||
if v.Required != model.YES {
|
||||
continue
|
||||
}
|
||||
options := make([]map[string]interface{}, 0)
|
||||
if v.PropertyName == "品牌" {
|
||||
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 789194134, "diy_type": v.DiyType})
|
||||
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": tiktokBrandId, "diy_type": v.DiyType})
|
||||
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
||||
} else if v.PropertyName == "产地" {
|
||||
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 13850, "diy_type": v.DiyType})
|
||||
@@ -934,7 +970,7 @@ func MakeProductFormatNew(api *tiktokShop.API, skuNameId int64, categoryLeafId i
|
||||
}
|
||||
productFormatNew := utils.Format4Output(categoryMap, false)
|
||||
dao.UpdateSkuNameTiktokAttr(dao.GetDB(), skuNameId, productFormatNew)
|
||||
return utils.Format4Output(categoryMap, false), nil
|
||||
return utils.Format4Output(categoryMap, false), tiktokBrandId, nil
|
||||
}
|
||||
|
||||
// GetSpecPrices 解析属性和规格参数
|
||||
|
||||
@@ -313,3 +313,8 @@ func (c *PurchaseHandler) CancelLogisticsByWmOrderId(order *model.GoodsOrder, re
|
||||
func (c *PurchaseHandler) OrderLogisticsStatus(orderId int64) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// GetOrderSettleAccounts 获取订单结算信息
|
||||
func (c *PurchaseHandler) GetOrderSettleAccounts(order *model.GoodsOrder) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@@ -106,3 +106,8 @@ func (c *PurchaseHandler) CancelLogisticsByWmOrderId(order *model.GoodsOrder, re
|
||||
func (c *PurchaseHandler) OrderLogisticsStatus(orderId int64) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// GetOrderSettleAccounts 获取订单结算信息
|
||||
func (c *PurchaseHandler) GetOrderSettleAccounts(order *model.GoodsOrder) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user