shan
This commit is contained in:
@@ -1,128 +0,0 @@
|
||||
package cs
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/weimobapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
minCSOrderPayment = 0 // 供货订单的最小金额(单位为元)
|
||||
maxUnitPrice = 3000 // 为防止误填单价,限制单价最高(单位为分)
|
||||
)
|
||||
|
||||
func OnCallbackMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackResponse) {
|
||||
orderID := utils.Int64ToStr(msg.OrderNo)
|
||||
jxutils.CallMsgHandler(func() {
|
||||
response = onOrderMsg(msg)
|
||||
}, jxutils.ComposeUniversalOrderID(orderID, model.VendorIDWSC))
|
||||
return response
|
||||
}
|
||||
|
||||
func onOrderMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackResponse) {
|
||||
globals.SugarLogger.Debugf("onOrderMsg:%s", utils.Format4Output(msg, true))
|
||||
if msg.Event == weimobapi.MsgEventOrderStatusChange {
|
||||
if utils.ForceInterface2Int64(msg.MsgBody["orderStatus"]) == weimobapi.MsgOrderStatusFinished {
|
||||
if orderDetail, err := api.WeimobAPI.QueryOrderDetail2(msg.OrderNo, false); err == nil {
|
||||
if orderDetail.OrderStatus == weimobapi.OrderStatusFinished && orderDetail.PaymentAmount >= minCSOrderPayment {
|
||||
changeStoreSkusByOrder(orderDetail)
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("onOrderMsg order:%s failed with err:%v", msg.OrderNo, err)
|
||||
response = weimobapi.Err2CallbackResponse(err, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
func changeStoreSkusByOrder(order *weimobapi.OrderDetail) {
|
||||
globals.SugarLogger.Debugf("changeStoreSkusByOrder order:%s", utils.Format4Output(order, true))
|
||||
receiverMobile := order.DeliveryDetail.LogisticsDeliveryDetail.ReceiverMobile
|
||||
ctx := jxcontext.NewWithUserName(nil, utils.LimitStringLen(utils.Int64ToStr(order.OrderNo), 32), nil, nil)
|
||||
if storeList, err := GetStoreList4Mobile(dao.GetDB(), []string{receiverMobile}); err == nil {
|
||||
if len(storeList) >= 1 {
|
||||
var skuBindInfos []*cms.StoreSkuBindInfo
|
||||
storeID := storeList[0].ID
|
||||
globals.SugarLogger.Debugf("changeStoreSkusByOrder storeID:%d", storeID)
|
||||
for _, v := range order.ItemList {
|
||||
nameID := int(utils.Str2Int64WithDefault(v.SkuCode, 0))
|
||||
unitPrice := v.CostPrice
|
||||
if nameID > 0 && (unitPrice > 0 && unitPrice < maxUnitPrice) {
|
||||
skuBindInfos = append(skuBindInfos, &cms.StoreSkuBindInfo{
|
||||
StoreID: storeID,
|
||||
NameID: nameID,
|
||||
UnitPrice: int(jxutils.StandardPrice2Int(unitPrice)),
|
||||
IsFocus: 1,
|
||||
IsSale: 1,
|
||||
})
|
||||
} else {
|
||||
globals.SugarLogger.Infof("[运营],微商城订单:%d,商品:%s没有设置正确的SkuName编码或单价,当前商家编码:%s,市场价:%s", order.OrderNo, v.SkuNum, v.SkuCode, jxutils.IntPrice2StandardString(jxutils.StandardPrice2Int(unitPrice)))
|
||||
}
|
||||
}
|
||||
if len(skuBindInfos) > 0 {
|
||||
var nameIDs []int
|
||||
for _, v := range skuBindInfos {
|
||||
nameIDs = append(nameIDs, v.NameID)
|
||||
}
|
||||
if skuNamesInfo, err := cms.GetSkuNames(ctx, "", false, false, map[string]interface{}{
|
||||
"nameIDs": string(utils.MustMarshal(nameIDs)),
|
||||
}, 0, 0); err == nil {
|
||||
for _, skuName := range skuNamesInfo.SkuNames {
|
||||
if skuName.Status != model.SkuStatusNormal {
|
||||
cms.UpdateSkuName(ctx, skuName.ID, map[string]interface{}{
|
||||
"status": model.SkuStatusNormal,
|
||||
}, false)
|
||||
}
|
||||
for _, sku := range skuName.Skus {
|
||||
if sku.Status != model.SkuStatusNormal {
|
||||
cms.UpdateSku(ctx, sku.ID, map[string]interface{}{
|
||||
"status": model.SkuStatusNormal,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cms.UpdateStoreSkus(ctx, 0, storeID, skuBindInfos, true, true)
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("changeStoreSkusByOrder orderID:%d, storeID:%d is empty", order.OrderNo, storeID)
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Infof("[运营],微商城订单:%d,手机:%s找不到唯一一个本地门店%d", order.OrderNo, receiverMobile, len(storeList))
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Warnf("changeStoreSkusByOrder orderNo:%d, receiverMobile:%s failed with err:%v", order.OrderNo, receiverMobile, err)
|
||||
}
|
||||
}
|
||||
|
||||
func GetStoreList4Mobile(db *dao.DaoDB, mobileList []string) (storeList []*model.Store, err error) {
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM store t1
|
||||
WHERE t1.deleted_at = ? /*AND t1.change_price_type = ?*/`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
// model.StoreChangePriceTypeBossDisabled,
|
||||
}
|
||||
if len(mobileList) > 0 {
|
||||
questionMarks := dao.GenQuestionMarks(len(mobileList))
|
||||
sql += " AND (t1.tel1 IN (" + questionMarks + ") OR t1.tel2 IN (" + questionMarks + `)
|
||||
OR (SELECT
|
||||
COUNT(*)
|
||||
FROM casbin_rule t2
|
||||
JOIN user t3 ON t3.user_id = t2.v0 AND t3.mobile IN (` + questionMarks + `)
|
||||
WHERE t2.v1 = CONCAT(?, t1.id)
|
||||
) > 0)
|
||||
`
|
||||
sqlParams = append(sqlParams, mobileList, mobileList, mobileList, autils.NewStoreBossRole(-1).GetFullName())
|
||||
}
|
||||
err = dao.GetRows(db, &storeList, sql, sqlParams...)
|
||||
return storeList, err
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package cs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals/api2"
|
||||
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||
)
|
||||
|
||||
func init() {
|
||||
testinit.Init()
|
||||
api2.Init()
|
||||
}
|
||||
|
||||
func TestGetStoreList4Mobile(t *testing.T) {
|
||||
storeList, err := GetStoreList4Mobile(dao.GetDB(), []string{"18180948107"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(storeList, false))
|
||||
t.Log(len(storeList))
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/globals/api2"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
@@ -82,7 +81,6 @@ func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||||
"storeMsgSendStatusName": model.StoreMsgSendStatusName,
|
||||
"shopChineseNames": model.ShopChineseNames,
|
||||
"printerVendorInfo": model.PrinterVendorInfo,
|
||||
"printerStatusName": partner.PrinterStatusName,
|
||||
"purchaseVendorInfo": model.PurchaseVendorInfo,
|
||||
"afsReasonTypeName": model.AfsReasonTypeName,
|
||||
"afsAppealTypeName": model.AfsAppealTypeName,
|
||||
|
||||
@@ -4,10 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
)
|
||||
|
||||
type SyncErrResult struct {
|
||||
@@ -44,16 +40,6 @@ type SpecSyncError struct {
|
||||
SpecErr error `json:"specErr"`
|
||||
}
|
||||
|
||||
// 对于多门店平台接口的通用处理
|
||||
type MultiStoreHandlerWrapper struct {
|
||||
partner.IMultipleStoresHandler
|
||||
}
|
||||
|
||||
// 对于单门店平台接口的通用处理
|
||||
type SingleStoreHandlerWrapper struct {
|
||||
partner.ISingleStoreHandler
|
||||
}
|
||||
|
||||
var (
|
||||
CurVendorSync VendorSync
|
||||
)
|
||||
@@ -75,38 +61,6 @@ var (
|
||||
syncErrResultLock SyncErrResultLock
|
||||
)
|
||||
|
||||
func buildErrMsg(task tasksch.ITask) (err error) {
|
||||
err = fmt.Errorf(utils.Format4Output(buildErrMsgJson(task), true))
|
||||
return makeSpecSyncError(err)
|
||||
}
|
||||
|
||||
func buildErrMsgJson(task tasksch.ITask) (resultL []*SyncErrResult) {
|
||||
failedList := task.GetFailedList()
|
||||
for _, v := range failedList {
|
||||
for _, vv := range v.([]*partner.StoreSkuInfoWithErr) {
|
||||
result := &SyncErrResult{
|
||||
SkuID: 0,
|
||||
StoreID: vv.StoreID,
|
||||
CategoryName: vv.CategoryName,
|
||||
VendorName: vv.VendoreName,
|
||||
VendorSkuID: "",
|
||||
NameID: 0,
|
||||
VendorPrice: 0,
|
||||
SyncType: vv.SyncType,
|
||||
ErrMsg: vv.ErrMsg,
|
||||
}
|
||||
if vv.StoreSkuInfo != nil {
|
||||
result.SkuID = vv.StoreSkuInfo.SkuID
|
||||
result.VendorSkuID = vv.StoreSkuInfo.VendorSkuID
|
||||
result.NameID = vv.StoreSkuInfo.NameID
|
||||
result.VendorPrice = vv.StoreSkuInfo.VendorPrice
|
||||
}
|
||||
resultL = append(resultL, result)
|
||||
}
|
||||
}
|
||||
return resultL
|
||||
}
|
||||
|
||||
func makeSyncError(err error) (newErr error) {
|
||||
if err != nil {
|
||||
if _, ok := err.(*SyncError); !ok {
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package storeskulock
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
cacheKeyPrefix = "jdpromotion"
|
||||
)
|
||||
|
||||
func LockJdStoreSku(jdStoreID string, jdSkuID int64, expire time.Time) {
|
||||
return
|
||||
globals.SugarLogger.Debug(expire, " ", time.Now())
|
||||
duration := expire.Sub(time.Now())
|
||||
if duration > 0 {
|
||||
api.Cacher.Set(genCacheKey(jdStoreID, jdSkuID), 1, duration)
|
||||
}
|
||||
}
|
||||
|
||||
func UnlockJdStoreSku(jdStoreID string, jdSkuID int64) {
|
||||
api.Cacher.Del(genCacheKey(jdStoreID, jdSkuID))
|
||||
}
|
||||
|
||||
func IsJdStoreSkuLocked(jdStoreID string, jdSkuID int64) bool {
|
||||
return false
|
||||
return api.Cacher.Get(genCacheKey(jdStoreID, jdSkuID)) != nil
|
||||
}
|
||||
|
||||
func ClearJdStoreSkuLock() {
|
||||
api.Cacher.FlushKeys(cacheKeyPrefix)
|
||||
}
|
||||
|
||||
func genCacheKey(jdStoreID string, jdSkuID int64) string {
|
||||
return fmt.Sprintf("%s.%s.%d", cacheKeyPrefix, jdStoreID, jdSkuID)
|
||||
}
|
||||
@@ -1,256 +0,0 @@
|
||||
package netspider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ditu"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
DefRadius = 8000
|
||||
DefGridWith = 2000
|
||||
)
|
||||
|
||||
func GetCityShops(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []int, cityCode, radius, gridWith int) (pageStoreList []*model.PageShop, err error) {
|
||||
coordList := ditu.GetCityCoordinateList(cityCode, radius, gridWith)
|
||||
if len(coordList) > 0 {
|
||||
task := tasksch.NewParallelTask(fmt.Sprintf("GetCityShops:%d", cityCode), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorID := batchItemList[0].(int)
|
||||
storeList, err2 := getStoreListByCoordinates(ctx, task, vendorID, cityCode, coordList)
|
||||
if err = err2; err == nil {
|
||||
retVal = storeList
|
||||
}
|
||||
globals.SugarLogger.Debugf("GetCityShops vendorID:%d, cityCode:%d, len(storeList):%d, err:%v", vendorID, cityCode, len(storeList), err)
|
||||
return retVal, err
|
||||
}, vendorIDs)
|
||||
tasksch.AddChild(parentTask, task).Run()
|
||||
list, err2 := task.GetResult(0)
|
||||
if err = err2; err != nil && len(list) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
err = nil
|
||||
for _, v := range list {
|
||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||
pageStoreList = append(pageStoreList, v.(*model.PageShop))
|
||||
}
|
||||
}
|
||||
return pageStoreList, err
|
||||
}
|
||||
|
||||
func getStorePageInfo(ctx *jxcontext.Context, handler partner.IPurchasePlatformNetSpiderHandler, cityCode int, vendorStoreID string) (storePageInfo *model.PageShop, err error) {
|
||||
storePageInfo, err = handler.GetStorePageInfo(ctx, vendorStoreID)
|
||||
if err == nil && storePageInfo != nil {
|
||||
updatePageShopCityDistrictInfo(ctx, storePageInfo, cityCode)
|
||||
}
|
||||
return storePageInfo, err
|
||||
}
|
||||
|
||||
func updatePageShopCityDistrictInfo(ctx *jxcontext.Context, storePageInfo *model.PageShop, cityCode int) {
|
||||
if !(storePageInfo.Lng != 0 && storePageInfo.Lat != 0) {
|
||||
storePageInfo.Lng, storePageInfo.Lat, storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateFromAddress(storePageInfo.Address, utils.Int2Str(cityCode))
|
||||
if storePageInfo.DistrictCode == 0 && cityCode != 0 {
|
||||
if place, err := dao.GetPlaceByCode(dao.GetDB(), cityCode); err == nil {
|
||||
storePageInfo.Lng, storePageInfo.Lat, storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateFromAddress(storePageInfo.Address, utils.Int2Str(place.ParentCode))
|
||||
}
|
||||
}
|
||||
} else if storePageInfo.DistrictCode == 0 {
|
||||
storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateDistrictCode(storePageInfo.Lng, storePageInfo.Lat)
|
||||
}
|
||||
if storePageInfo.CityCode == 0 {
|
||||
if storePageInfo.DistrictCode != 0 {
|
||||
if place, err := dao.GetPlaceByCode(dao.GetDB(), storePageInfo.DistrictCode); err == nil {
|
||||
storePageInfo.CityCode = place.ParentCode
|
||||
}
|
||||
}
|
||||
if storePageInfo.CityCode == 0 {
|
||||
storePageInfo.CityCode = cityCode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, cityCode int, coordList []*ditu.Coordinate) (storeList []*model.PageShop, err error) {
|
||||
if len(coordList) > 0 {
|
||||
if handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformNetSpiderHandler); handler != nil {
|
||||
mainStoreIDList, _ := handler.GetStoreIDListByCoordinates(ctx, coordList[0])
|
||||
if len(mainStoreIDList) > 0 {
|
||||
task1 := tasksch.NewParallelTask(fmt.Sprintf("GetStoreListByCoordinate[%s] get list", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true).SetParallelCount(1), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
pos := batchItemList[0].(*ditu.Coordinate)
|
||||
storeIDList, err := handler.GetStoreIDListByCoordinates(ctx, pos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storeIDList, nil
|
||||
}, coordList)
|
||||
tasksch.AddChild(parentTask, task1).Run()
|
||||
fullStoreIDs, err2 := task1.GetResult(0)
|
||||
if err = err2; err != nil && len(fullStoreIDs) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
storeIDMap := make(map[string]int)
|
||||
for _, v := range fullStoreIDs {
|
||||
storeIDMap[v.(string)] = 1
|
||||
}
|
||||
var storeIDs []string
|
||||
for storeID := range storeIDMap {
|
||||
storeIDs = append(storeIDs, storeID)
|
||||
}
|
||||
|
||||
task2 := tasksch.NewParallelTask(fmt.Sprintf("GetStoreListByCoordinate[%s] get detail", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeID := batchItemList[0].(string)
|
||||
storePageInfo, err := getStorePageInfo(ctx, handler, cityCode, storeID)
|
||||
if err == nil && storePageInfo != nil {
|
||||
return []interface{}{storePageInfo}, nil
|
||||
}
|
||||
return nil, err
|
||||
}, storeIDs)
|
||||
tasksch.AddChild(parentTask, task2).Run()
|
||||
shopList, err2 := task2.GetResult(0)
|
||||
if err = err2; err != nil && len(shopList) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
err = nil
|
||||
for _, v := range shopList {
|
||||
storeList = append(storeList, v.(*model.PageShop))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return storeList, err
|
||||
}
|
||||
|
||||
func GetAndStoreCitiesShops(ctx *jxcontext.Context, vendorIDs []int, cityCodeList []int, radius, gridWith int, isShuffle, isAsync bool) (hint string, err error) {
|
||||
db := dao.GetDB()
|
||||
if len(cityCodeList) == 0 {
|
||||
placeList, err2 := dao.GetPlacesByCond(db, dao.EnableCondAll)
|
||||
if err = err2; err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, v := range placeList {
|
||||
cityCodeList = append(cityCodeList, v.Code)
|
||||
}
|
||||
}
|
||||
if isShuffle {
|
||||
rand.Shuffle(len(cityCodeList), func(i, j int) {
|
||||
cityCodeList[i], cityCodeList[j] = cityCodeList[j], cityCodeList[i]
|
||||
})
|
||||
} else {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM page_shop t1
|
||||
ORDER BY t1.id DESC
|
||||
LIMIT 1`
|
||||
var lastShop *model.PageShop
|
||||
if err2 := dao.GetRow(db, &lastShop, sql); err2 == nil {
|
||||
index := -1
|
||||
for k, v := range cityCodeList {
|
||||
if v >= lastShop.CityCode {
|
||||
index = k
|
||||
if v == lastShop.CityCode {
|
||||
index++
|
||||
}
|
||||
if index >= len(cityCodeList) {
|
||||
index = -1
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if index > 0 {
|
||||
var cityCodeList2 []int
|
||||
cityCodeList2 = append(cityCodeList2, cityCodeList[index:]...)
|
||||
cityCodeList2 = append(cityCodeList2, cityCodeList[:index]...)
|
||||
cityCodeList = cityCodeList2
|
||||
}
|
||||
globals.SugarLogger.Debugf("GetAndStoreCitiesShops last cityCode:%d, cityCodeList:%v", lastShop.CityCode, cityCodeList)
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("GetAndStoreCitiesShops get lastest city code error:%v", err2)
|
||||
}
|
||||
}
|
||||
if len(vendorIDs) == 0 {
|
||||
vendorIDs = []int{model.VendorIDJD, model.VendorIDEBAI}
|
||||
}
|
||||
if radius <= 0 {
|
||||
radius = DefRadius
|
||||
}
|
||||
if gridWith <= 0 {
|
||||
gridWith = DefGridWith
|
||||
}
|
||||
|
||||
task := tasksch.NewParallelTask(fmt.Sprintf("GetAndStoreCitiesShops:%v", vendorIDs), tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
cityCode := batchItemList[0].(int)
|
||||
globals.SugarLogger.Debugf("process city:%d", cityCode)
|
||||
shopList, err := GetCityShops(ctx, task, vendorIDs, cityCode, radius, gridWith)
|
||||
if err == nil {
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
for _, v := range shopList {
|
||||
globals.SugarLogger.Debugf("GetAndStoreCitiesShops cityCode:%d, 平台:%s, shopID:%s, districtCode:%d", cityCode, model.VendorChineseNames[v.VendorID], v.VendorStoreID, v.DistrictCode)
|
||||
if v.DistrictCode > 0 {
|
||||
tmpShop := *v
|
||||
dao.DeleteEntity(db, &tmpShop, model.FieldVendorStoreID, model.FieldVendorID)
|
||||
}
|
||||
if err = dao.CreateEntity(db, v); err != nil {
|
||||
if dao.IsDuplicateError(err) {
|
||||
err = nil
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
} else {
|
||||
hint = utils.Int2Str(len(shopList))
|
||||
dao.Commit(db)
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debugf("process city:%d, len(shopList):%d, err:%v", cityCode, len(shopList), err)
|
||||
return nil, err
|
||||
}, cityCodeList)
|
||||
tasksch.ManageTask(task).Run()
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
} else {
|
||||
hint = task.GetID()
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func RefreshPageShops(ctx *jxcontext.Context) (err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM page_shop t1
|
||||
WHERE t1.district_code = 0 AND t1.lng != 0 AND t1.lat != 0`
|
||||
db := dao.GetDB()
|
||||
var shopList []*model.PageShop
|
||||
if err = dao.GetRows(db, &shopList, sql); err != nil {
|
||||
return err
|
||||
}
|
||||
task := tasksch.NewParallelTask(fmt.Sprintf("刷新网页门店信息:%d", len(shopList)), nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
pageShop := batchItemList[0].(*model.PageShop)
|
||||
updatePageShopCityDistrictInfo(ctx, pageShop, pageShop.CityCode)
|
||||
_, err = dao.UpdateEntity(db, pageShop, "CityCode", "DistrictCode", "Lng", "Lat")
|
||||
return retVal, err
|
||||
}, shopList)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
return err
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package netspider
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ditu"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||
)
|
||||
|
||||
func init() {
|
||||
testinit.Init()
|
||||
}
|
||||
|
||||
func TestGetStoreListByCoordinate(t *testing.T) {
|
||||
storeList, err := getStoreListByCoordinates(jxcontext.AdminCtx, nil, 3, "成都",
|
||||
[]*ditu.Coordinate{
|
||||
&ditu.Coordinate{
|
||||
Lng: 104.057218,
|
||||
Lat: 30.6949,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(storeList, false))
|
||||
t.Log(len(storeList))
|
||||
}
|
||||
|
||||
func TestGetCityShops(t *testing.T) {
|
||||
shopList, err := GetCityShops(jxcontext.AdminCtx, nil, []int{0, 3}, 510100, 5000, 3000)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(shopList, false))
|
||||
t.Log(len(shopList))
|
||||
}
|
||||
@@ -1,307 +0,0 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
const (
|
||||
StoreNameSeparator = "-"
|
||||
)
|
||||
|
||||
const (
|
||||
CreatedPeration = "create"
|
||||
UpdatedPeration = "update"
|
||||
)
|
||||
|
||||
const (
|
||||
CancelWaybillReasonNotAcceptIntime = 1
|
||||
CancelWaybillReasonSwitch2SelfFailed = 2
|
||||
CancelWaybillReasonOther = 10
|
||||
)
|
||||
|
||||
const (
|
||||
AfsApproveTypeRefund = 1 // 退款
|
||||
AfsApproveTypeReturnGoods = 2 // 退货
|
||||
AfsApproveTypeRefused = 3 // 驳回
|
||||
)
|
||||
|
||||
const (
|
||||
TimerTypeNoOverride = 0 // GetStatusActionConfig 返回表示不修改缺省配置
|
||||
TimerTypeByPass = 1
|
||||
TimerTypeBaseNow = 2
|
||||
TimerTypeBaseStatusTime = 3
|
||||
TimerTypeBaseOrderCreatedAt = 4
|
||||
)
|
||||
|
||||
type StatusActionParams struct {
|
||||
TimerType int // 参见上面的相关常量定义
|
||||
Timeout time.Duration // 超时时间,0在GetStatusActionConfig返回时表示不修改缺省
|
||||
TimeoutGap int // 以秒为单位的随机时间,0在GetStatusActionConfig返回时表示不修改缺省
|
||||
}
|
||||
|
||||
type OrderInFoChange struct {
|
||||
}
|
||||
|
||||
func (s *StatusActionParams) GetRefTimeout(statusTime time.Time, orderCreatedAt time.Time) (timeout time.Duration) {
|
||||
switch s.TimerType {
|
||||
case TimerTypeBaseNow:
|
||||
timeout = s.Timeout
|
||||
case TimerTypeBaseStatusTime:
|
||||
timeout = statusTime.Sub(time.Now()) + s.Timeout
|
||||
case TimerTypeBaseOrderCreatedAt:
|
||||
timeout = orderCreatedAt.Sub(time.Now()) + s.Timeout
|
||||
default:
|
||||
timeout = 0
|
||||
}
|
||||
if timeout < 0 {
|
||||
timeout = 0
|
||||
}
|
||||
return timeout
|
||||
}
|
||||
|
||||
var (
|
||||
CancelWaybillReasonStrNotAcceptIntime = "没有及时抢单"
|
||||
CancelWaybillReasonStrSwitch2SelfFailed = "转自送失败"
|
||||
CancelWaybillReasonStrOrderAlreadyFinished = "订单已经结束"
|
||||
CancelWaybillReasonStrActive = "操作由人员主动发起"
|
||||
CancelWaybillReasonNotInStoreOpenTime = "不在门店的营业时间范围内"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrCanNotFindItem = errors.New("没有找到指定的东西")
|
||||
ErrStoreHaveNoCourier = errors.New("门店没有绑定相应的配送信息")
|
||||
)
|
||||
|
||||
var (
|
||||
CurOrderManager IOrderManager
|
||||
CurStoreManager IStoreManager
|
||||
|
||||
PurchasePlatformHandlers map[int]IPurchasePlatformHandler
|
||||
PurchaseOrderHandlers map[int]IPurchasePlatformOrderHandler
|
||||
)
|
||||
|
||||
type IOrderManager interface {
|
||||
SaveOrder(order *model.GoodsOrder, isAdjust bool, db *dao.DaoDB) (isDuplicated bool, err error)
|
||||
|
||||
OnOrderNew(order *model.GoodsOrder, orderStatus *model.OrderStatus) (err error)
|
||||
OnOrderAdjust(order *model.GoodsOrder, orderStatus *model.OrderStatus) (err error)
|
||||
OnOrderStatusChanged(vendorOrgCode string, orderStatus *model.OrderStatus) (err error)
|
||||
OnOrderMsg(order *model.GoodsOrder, vendorStatus, remark string) (err error)
|
||||
|
||||
OnWaybillStatusChanged(bill *model.Waybill) (err error)
|
||||
|
||||
CreateAfsOrderFromOrder(vendorOrderID string, vendorID int) (afsOrder *model.AfsOrder, err error)
|
||||
LoadOrder(vendorOrderID string, vendorID int) (order *model.GoodsOrder, err error)
|
||||
LoadOrder2(vendorOrderID2 string, vendorID int) (order *model.GoodsOrder, err error)
|
||||
|
||||
LoadOrderFinancial(vendorOrderID string, vendorID int) (order *model.OrderFinancial, err error)
|
||||
LoadOrderFinancial2(vendorOrderID2 string, vendorID int) (order *model.OrderFinancial, err error)
|
||||
|
||||
UpdateOrderStatusAndDeliveryFlag(order *model.GoodsOrder) (err error)
|
||||
UpdateOrderFields(order *model.GoodsOrder, fieldList []string) (err error)
|
||||
// LoadStoreDetail(storeID, vendorID int) (storeDetail *dao.StoreDetail, err error)
|
||||
|
||||
LoadWaybill(vendorWaybillID string, waybillVendorID int) (bill *model.Waybill, err error)
|
||||
OnOrderComments(orderCommentList []*model.OrderComment) (err error)
|
||||
|
||||
SaveOrderFinancialInfo(order *model.OrderFinancial, operation string) (err error)
|
||||
SaveAfsOrderFinancialInfo(afsOrder *model.AfsOrder) (err error)
|
||||
|
||||
GetOrderWaybillInfo(ctx *jxcontext.Context, vendorOrderID string, vendorID int, isNotEnded, isGetPos bool) (bills []*model.WaybillExt, err error)
|
||||
|
||||
ChangeOrderInfo(order *model.GoodsOrder) (err error)
|
||||
// afs order
|
||||
OnAfsOrderAdjust(afsOrder *model.AfsOrder, orderStatus *model.OrderStatus) (err error)
|
||||
OnAfsOrderNew(afsOrder *model.AfsOrder, orderStatus *model.OrderStatus) (err error)
|
||||
OnAfsOrderStatusChanged(orderStatus *model.OrderStatus) (err error)
|
||||
LoadAfsOrder(vendorAfsOrderID string, vendorID int) (afsOrder *model.AfsOrder, err error)
|
||||
UpdateAfsOrderFields(afsOrder *model.AfsOrder, fieldList []string) (err error)
|
||||
|
||||
GetStatusDuplicatedCount(status *model.OrderStatus) (duplicatedCount int)
|
||||
}
|
||||
|
||||
type IStoreManager interface {
|
||||
OnStoreStatusChanged(vendorStoreID string, vendorID int, storeStatus int) (err error)
|
||||
OnCourierStoreStatusChanged(ctx *jxcontext.Context, vendorStoreID string, vendorID int, auditStatus int) (err error)
|
||||
}
|
||||
|
||||
// purchase handler中
|
||||
// 所有Sync,Refresh开头的函数都必须自己清理sync_status标记
|
||||
// 所有非以Sync,Refresh开头的函数不用自己清理sync_status标记(VendorSync统一处理)
|
||||
|
||||
type IPurchasePlatformHandler interface {
|
||||
IPurchasePlatformActHandler
|
||||
IPurchasePlatformOrderHandler
|
||||
|
||||
GetVendorID() int
|
||||
|
||||
// 只与平台相关
|
||||
// GetVendorCategories(ctx *jxcontext.Context) (vendorCats []*model.SkuVendorCategory, err error)
|
||||
|
||||
////////
|
||||
// Store
|
||||
// ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string) (store *dao.StoreDetail, err error)
|
||||
UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error)
|
||||
CreateStore2(db *dao.DaoDB, storeID int, userName string) (vendorStoreID string, err error)
|
||||
DeleteStore(db *dao.DaoDB, storeID int, userName string) (err error)
|
||||
GetStoreStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string) (storeStatus int, err error)
|
||||
UpdateStoreCustomID(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string, storeID int64) (err error)
|
||||
|
||||
RefreshAllStoresID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool) (hint string, err error)
|
||||
|
||||
UploadImg(ctx *jxcontext.Context, vendorOrgCode, imgURL string, imgData []byte, imgName string, imgType int) (imgHint string, err error)
|
||||
}
|
||||
|
||||
// db *dao.DaoDB,
|
||||
type IMultipleStoresHandler interface {
|
||||
IPurchasePlatformHandler
|
||||
GetAllCategories(ctx *jxcontext.Context, vendorOrgCode string) (cats []*BareCategoryInfo, err error)
|
||||
|
||||
// CreateCategory(db *dao.DaoDB, cat *model.SkuCategory, userName string) (err error)
|
||||
// UpdateCategory(db *dao.DaoDB, cat *model.SkuCategory, userName string) error
|
||||
// DeleteCategory(db *dao.DaoDB, cat *model.SkuCategory, userName string) error
|
||||
// ReorderCategories(db *dao.DaoDB, parentCatID int, userName string) (err error)
|
||||
|
||||
// CreateCategory2(ctx *jxcontext.Context, cat *dao.SkuStoreCatInfo) (err error)
|
||||
// UpdateCategory2(ctx *jxcontext.Context, cat *dao.SkuStoreCatInfo) (err error)
|
||||
DeleteCategory2(ctx *jxcontext.Context, vendorOrgCode, vendorCatID string) (err error)
|
||||
ReorderCategories2(ctx *jxcontext.Context, vendorOrgCode, vendorParentCatID string, vendorCatIDList []string) (err error)
|
||||
|
||||
// sku
|
||||
// CreateSku(db *dao.DaoDB, sku *model.Sku, userName string) (err error)
|
||||
// UpdateSku(db *dao.DaoDB, sku *model.Sku, userName string) (err error)
|
||||
// DeleteSku(db *dao.DaoDB, sku *model.Sku, userName string) (err error)
|
||||
|
||||
// ReadSku(ctx *jxcontext.Context, vendorOrgCode, vendorSkuID string) (skuNameExt *model.SkuNameExt, err error)
|
||||
// CreateSku2(ctx *jxcontext.Context, sku *dao.StoreSkuSyncInfo) (err error)
|
||||
// UpdateSku2(ctx *jxcontext.Context, sku *dao.StoreSkuSyncInfo) (err error)
|
||||
DeleteSku2(ctx *jxcontext.Context, vendorOrgCode string, sku *StoreSkuInfo) (err error)
|
||||
|
||||
// RefreshAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool) (hint string, err error)
|
||||
|
||||
GetSkus(ctx *jxcontext.Context, vendorOrgCode string, skuID int, vendorSkuID string) (skuNameList []*SkuNameInfo, err error)
|
||||
}
|
||||
|
||||
type ISingleStoreHandler interface {
|
||||
IPurchasePlatformHandler
|
||||
ISingleStoreStoreSkuHandler
|
||||
// SyncStoreCategory(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync bool) (hint string, err error)
|
||||
|
||||
// RefreshStoresAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool, storeIDs []int) (hint string, err error)
|
||||
}
|
||||
|
||||
type BasePurchasePlatform struct {
|
||||
}
|
||||
|
||||
func (p *BasePurchasePlatform) GetStatusActionTimeout(order *model.GoodsOrder, statusType, status int) (params *StatusActionParams) {
|
||||
return params
|
||||
}
|
||||
|
||||
func (c *BasePurchasePlatform) CanSwitch2SelfDeliver(order *model.GoodsOrder) (isCan bool, err error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
PurchasePlatformHandlers = make(map[int]IPurchasePlatformHandler)
|
||||
PurchaseOrderHandlers = make(map[int]IPurchasePlatformOrderHandler)
|
||||
DeliveryPlatformHandlers = make(map[int]*DeliveryPlatformHandlerInfo)
|
||||
}
|
||||
|
||||
func InitOrderManager(curOrderManager IOrderManager) {
|
||||
CurOrderManager = curOrderManager
|
||||
}
|
||||
|
||||
func InitStoreManager(curStoreManager IStoreManager) {
|
||||
CurStoreManager = curStoreManager
|
||||
}
|
||||
|
||||
func RegisterPurchasePlatform(handler IPurchasePlatformHandler) {
|
||||
vendorID := handler.GetVendorID()
|
||||
if !(model.IsPurchaseVendorExist(vendorID)) {
|
||||
panic(fmt.Sprintf("purchase vendor:%d is illegal", vendorID))
|
||||
}
|
||||
if _, ok := PurchasePlatformHandlers[vendorID]; ok {
|
||||
panic(fmt.Sprintf("purchase vendor:%d, already exists", vendorID))
|
||||
}
|
||||
_, isSingleStore := handler.(ISingleStoreHandler)
|
||||
_, isMultiStore := handler.(IMultipleStoresHandler)
|
||||
if !isSingleStore && !isMultiStore {
|
||||
panic(fmt.Sprintf("platform:%d type is wrong!", vendorID))
|
||||
}
|
||||
PurchasePlatformHandlers[vendorID] = handler
|
||||
}
|
||||
|
||||
func RegisterPurchaseOrderHandler(vendorID int, handler IPurchasePlatformOrderHandler) {
|
||||
PurchaseOrderHandlers[vendorID] = handler
|
||||
}
|
||||
|
||||
func GetPurchasePlatformFromVendorID(vendorID int) IPurchasePlatformHandler {
|
||||
return PurchasePlatformHandlers[vendorID]
|
||||
}
|
||||
|
||||
func GetPurchaseOrderHandlerFromVendorID(vendorID int) (handler IPurchasePlatformOrderHandler) {
|
||||
handler = PurchasePlatformHandlers[vendorID]
|
||||
if handler == nil {
|
||||
handler = PurchaseOrderHandlers[vendorID]
|
||||
}
|
||||
return handler
|
||||
}
|
||||
|
||||
func GetPurchasePlatformVendorIDs() (vendorIDs []int) {
|
||||
for k := range PurchasePlatformHandlers {
|
||||
vendorIDs = append(vendorIDs, k)
|
||||
}
|
||||
return vendorIDs
|
||||
}
|
||||
|
||||
func GetMultiStoreVendorIDs() (vendorIDs []int) {
|
||||
for k, v := range PurchasePlatformHandlers {
|
||||
if _, ok := v.(IMultipleStoresHandler); ok {
|
||||
vendorIDs = append(vendorIDs, k)
|
||||
}
|
||||
}
|
||||
return vendorIDs
|
||||
}
|
||||
|
||||
func GetSingleStoreVendorIDs() (vendorIDs []int) {
|
||||
for k, v := range PurchasePlatformHandlers {
|
||||
if _, ok := v.(ISingleStoreHandler); ok {
|
||||
vendorIDs = append(vendorIDs, k)
|
||||
}
|
||||
}
|
||||
return vendorIDs
|
||||
}
|
||||
|
||||
func IsMultiStore(vendorID int) bool {
|
||||
if _, ok := GetPurchasePlatformFromVendorID(vendorID).(IMultipleStoresHandler); ok {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func GetRidderPositionGetter(vendorID int) (handler IRidderPositionGetter) {
|
||||
if handlerInfo := GetDeliveryPlatformFromVendorID(vendorID); handlerInfo != nil {
|
||||
if handler, _ = handlerInfo.Handler.(IRidderPositionGetter); handler != nil {
|
||||
return handler
|
||||
}
|
||||
}
|
||||
handler, _ = GetPurchasePlatformFromVendorID(vendorID).(IRidderPositionGetter)
|
||||
return handler
|
||||
}
|
||||
|
||||
func GetWaybillTipUpdater(vendorID int) (handler IAddWaybillTip) {
|
||||
if handlerInfo := GetDeliveryPlatformFromVendorID(vendorID); handlerInfo != nil {
|
||||
if handler, _ = handlerInfo.Handler.(IAddWaybillTip); handler != nil {
|
||||
return handler
|
||||
}
|
||||
}
|
||||
handler, _ = GetPurchasePlatformFromVendorID(vendorID).(IAddWaybillTip)
|
||||
return handler
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
type IActManager interface {
|
||||
IsVendorActExist(ctx *jxcontext.Context, vendorActID string, vendorID int) (isExist bool)
|
||||
CreateActFromVendor(ctx *jxcontext.Context, act2 *model.Act2, actStoreSku []*model.ActStoreSku2) (actID int, err error)
|
||||
}
|
||||
|
||||
type IPurchasePlatformActHandler interface {
|
||||
// // 如果是单品级活动,actOrderRules为空
|
||||
// // 如果是订单级活动,actStoreSku可以为空(表示不限制SKU)
|
||||
// CreateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreSku []*model.ActStoreSku2) (err error)
|
||||
// UpdateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreSku []*model.ActStoreSku2) (err error)
|
||||
// // 取消整个京西活动
|
||||
// CancelAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreSku []*model.ActStoreSku2) (err error)
|
||||
|
||||
SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreSkuList []*model.ActStoreSku2) (err error)
|
||||
}
|
||||
|
||||
type IPurchasePlatformPageActHandler interface {
|
||||
GetPageActList(ctx *jxcontext.Context, createdFrom time.Time) (actList []*model.Act2, err error)
|
||||
GetPageActSkuList(ctx *jxcontext.Context, vendorPageActID string) (actStoreSkuList []*model.ActStoreSku2, err error)
|
||||
}
|
||||
|
||||
var (
|
||||
CurActManager IActManager
|
||||
)
|
||||
|
||||
func InitActManager(p IActManager) {
|
||||
CurActManager = p
|
||||
}
|
||||
|
||||
func SplitActStoreSku(actStoreSkuList []*model.ActStoreSku2) (actStoreSkuMap map[int][]*model.ActStoreSku2) {
|
||||
actStoreSkuMap = make(map[int][]*model.ActStoreSku2)
|
||||
for _, v := range actStoreSkuList {
|
||||
actStoreSkuMap[v.StoreID] = append(actStoreSkuMap[v.StoreID], v)
|
||||
}
|
||||
return actStoreSkuMap
|
||||
}
|
||||
|
||||
func SplitActStoreSku2List(actStoreSkuList []*model.ActStoreSku2) (actStoreSkuListList [][]*model.ActStoreSku2) {
|
||||
actStoreSkuMap := SplitActStoreSku(actStoreSkuList)
|
||||
for _, v := range actStoreSkuMap {
|
||||
actStoreSkuListList = append(actStoreSkuListList, v)
|
||||
}
|
||||
return actStoreSkuListList
|
||||
}
|
||||
|
||||
func Act2ActMap(act *model.Act2) (actMap *model.ActMap) {
|
||||
actMap = &model.ActMap{}
|
||||
actMap.ID = act.MapID
|
||||
return actMap
|
||||
}
|
||||
|
||||
func ActStoreSku2ActStoreSkuMap(actStoreSku *model.ActStoreSku2) (actStoreSkuMap *model.ActStoreSkuMap) {
|
||||
actStoreSkuMap = &model.ActStoreSkuMap{
|
||||
ModelIDCULD: actStoreSku.ModelIDCULD,
|
||||
BindID: actStoreSku.MapID,
|
||||
|
||||
ActID: actStoreSku.ActID,
|
||||
StoreID: actStoreSku.StoreID,
|
||||
SkuID: actStoreSku.SkuID,
|
||||
VendorID: actStoreSku.VendorID,
|
||||
VendorActID: actStoreSku.VendorActID,
|
||||
SyncStatus: actStoreSku.SyncStatus,
|
||||
VendorPrice: actStoreSku.VendorPrice,
|
||||
ActualActPrice: actStoreSku.ActualActPrice,
|
||||
|
||||
EarningPrice: actStoreSku.EarningPrice,
|
||||
}
|
||||
actStoreSkuMap.ID = actStoreSku.MapID
|
||||
return actStoreSkuMap
|
||||
}
|
||||
|
||||
func Act2Update(ctx *jxcontext.Context, act *model.Act2, syncStatus int) (item *dao.KVUpdateItem) {
|
||||
kvs := map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldUpdatedAt: time.Now(),
|
||||
model.FieldLastOperator: ctx.GetUserName(),
|
||||
}
|
||||
if syncStatus == model.SyncFlagDeletedMask {
|
||||
kvs[model.FieldDeletedAt] = time.Now()
|
||||
} else if syncStatus == model.SyncFlagNewMask {
|
||||
kvs[model.FieldVendorActID] = act.VendorActID
|
||||
}
|
||||
item = &dao.KVUpdateItem{
|
||||
Item: Act2ActMap(act),
|
||||
KVs: kvs,
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
func ActStoreSku2Update(ctx *jxcontext.Context, actStoreSkuList []*model.ActStoreSku2, syncStatus int) (items []*dao.KVUpdateItem) {
|
||||
for _, v := range actStoreSkuList {
|
||||
v.SyncStatus = 0
|
||||
v.UpdatedAt = time.Now()
|
||||
v.LastOperator = ctx.GetUserName()
|
||||
kvs := map[string]interface{}{
|
||||
model.FieldSyncStatus: v.SyncStatus,
|
||||
model.FieldUpdatedAt: v.UpdatedAt,
|
||||
model.FieldLastOperator: v.LastOperator,
|
||||
}
|
||||
if syncStatus == model.SyncFlagDeletedMask {
|
||||
v.DeletedAt = time.Now()
|
||||
kvs[model.FieldDeletedAt] = v.DeletedAt
|
||||
} else if syncStatus == model.SyncFlagNewMask {
|
||||
kvs[model.FieldVendorActID] = v.VendorActID
|
||||
}
|
||||
items = append(items, &dao.KVUpdateItem{
|
||||
Item: ActStoreSku2ActStoreSkuMap(v),
|
||||
KVs: kvs,
|
||||
})
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func GetVendorIDsFromActMap(actMap map[int]*model.Act2) (vendorIDs []int) {
|
||||
for vendorID := range actMap {
|
||||
vendorIDs = append(vendorIDs, vendorID)
|
||||
}
|
||||
return vendorIDs
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package partner
|
||||
|
||||
type IAPIManager interface {
|
||||
GetAPI(vendorID int, appOrgCode string) interface{}
|
||||
GetAppOrgCodeList(vendorID int) (appOrgCodeList []string)
|
||||
}
|
||||
|
||||
var (
|
||||
CurAPIManager IAPIManager
|
||||
)
|
||||
|
||||
func InitAPIManager(curAPIManager IAPIManager) {
|
||||
CurAPIManager = curAPIManager
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
const (
|
||||
WaybillFeeErrCodeCourierNotOpen = 1 //配送门店没有启用
|
||||
WaybillFeeErrCodeCourierNotSupported = 2 //配送门店不被系统支持
|
||||
WaybillFeeErrCodeCourierForbidden = 3 //配送门店内部禁用
|
||||
WaybillFeeErrCodeCourierOthers = 10 //其它错误
|
||||
)
|
||||
|
||||
type WaybillFeeInfo struct {
|
||||
ErrCode int `json:"errCode"`
|
||||
ErrStr string `json:"errStr"`
|
||||
RefDeliveryFee int64 `json:"refDeliveryFee"` // 无用,待删除
|
||||
RefAddFee int64 `json:"refAddFee"` // 无用,待删除
|
||||
DeliveryFee int64 `json:"deliveryFee"`
|
||||
TimeoutSecond int `json:"timeoutSecond"` // 系统会自动发运单的倒计时
|
||||
Waybill *model.Waybill `json:"waybill"`
|
||||
}
|
||||
|
||||
type CreateWaybillPolicyFunc func(refDeliveryFee, refAddFee, deliveryFee int64) (errStr string)
|
||||
|
||||
type IDeliveryPlatformHandler interface {
|
||||
GetVendorID() int
|
||||
|
||||
// CreateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (vendorStoreID string, status int, err error)
|
||||
// GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error)
|
||||
IsErrStoreNotExist(err error) bool
|
||||
IsErrStoreExist(err error) bool
|
||||
|
||||
CreateWaybill(order *model.GoodsOrder, maxDeliveryFee int64) (bill *model.Waybill, err error)
|
||||
CancelWaybill(bill *model.Waybill, cancelReasonID int, cancelReason string) (err error)
|
||||
GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo *WaybillFeeInfo, err error)
|
||||
//投诉骑手
|
||||
ComplaintRider(bill *model.Waybill, resonID int, resonContent string) (err error)
|
||||
}
|
||||
|
||||
type IDeliveryUpdateStoreHandler interface {
|
||||
// UpdateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (err error)
|
||||
}
|
||||
|
||||
type DeliveryPlatformHandlerInfo struct {
|
||||
Handler IDeliveryPlatformHandler
|
||||
Use4CreateWaybill bool
|
||||
}
|
||||
|
||||
var (
|
||||
DeliveryPlatformHandlers map[int]*DeliveryPlatformHandlerInfo
|
||||
UseableDeliveryVendorIDs []int
|
||||
)
|
||||
|
||||
func init() {
|
||||
DeliveryPlatformHandlers = make(map[int]*DeliveryPlatformHandlerInfo)
|
||||
}
|
||||
|
||||
func RegisterDeliveryPlatform(handler IDeliveryPlatformHandler, isUse4CreateWaybill bool) {
|
||||
vendorID := handler.GetVendorID()
|
||||
if !(model.IsDeliveryVendorExist(vendorID)) {
|
||||
panic(fmt.Sprintf("delivery vendor:%d is illegal", vendorID))
|
||||
}
|
||||
if _, ok := DeliveryPlatformHandlers[vendorID]; ok {
|
||||
panic(fmt.Sprintf("delivery vendor:%d, already exists", vendorID))
|
||||
}
|
||||
DeliveryPlatformHandlers[vendorID] = &DeliveryPlatformHandlerInfo{
|
||||
Handler: handler,
|
||||
Use4CreateWaybill: isUse4CreateWaybill,
|
||||
}
|
||||
UseableDeliveryVendorIDs = append(UseableDeliveryVendorIDs, vendorID)
|
||||
}
|
||||
|
||||
func GetDeliveryPlatformFromVendorID(vendorID int) *DeliveryPlatformHandlerInfo {
|
||||
return DeliveryPlatformHandlers[vendorID]
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrCodeUnknown = 1
|
||||
ErrCodeChangePriceFailed = 100
|
||||
)
|
||||
|
||||
type ErrorWithCode struct {
|
||||
errMsg string
|
||||
intCode int
|
||||
vendorID int
|
||||
storeID int
|
||||
skuID int
|
||||
}
|
||||
|
||||
func NewErrorCode(errMsg string, code, vendorID int) *ErrorWithCode {
|
||||
retVal := &ErrorWithCode{
|
||||
errMsg: errMsg,
|
||||
intCode: code,
|
||||
vendorID: vendorID,
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) SetStoreID(storeID int) {
|
||||
e.storeID = storeID
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) SetSkuID(skuID int) {
|
||||
e.skuID = skuID
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) Error() string {
|
||||
return fmt.Sprintf("平台:%s, code:%d, %s", model.VendorChineseNames[e.VendorID()], e.intCode, e.errMsg)
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) String() string {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) Code() int {
|
||||
return e.intCode
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) ErrMsg() string {
|
||||
return e.errMsg
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) VendorID() int {
|
||||
return e.vendorID
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) StoreID() int {
|
||||
return e.storeID
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) SkuID() int {
|
||||
return e.skuID
|
||||
}
|
||||
|
||||
func IsErrChangePriceFailed(err error) *ErrorWithCode {
|
||||
if vendorErr, ok := err.(*ErrorWithCode); ok && vendorErr.Code() == ErrCodeChangePriceFailed {
|
||||
return vendorErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func IsErrVendorError(err error) *ErrorWithCode {
|
||||
if vendorErr, ok := err.(*ErrorWithCode); ok {
|
||||
return vendorErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func AddVendorInfo2Err(inErr error, vendorID int) (outErr error) {
|
||||
outErr = inErr
|
||||
if inErr != nil {
|
||||
if IsErrVendorError(inErr) == nil {
|
||||
outErr = NewErrorCode(inErr.Error(), ErrCodeUnknown, vendorID)
|
||||
}
|
||||
}
|
||||
return outErr
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type OrderPhoneNumberInfo struct {
|
||||
VendorOrderID string
|
||||
PhoneNumber string
|
||||
}
|
||||
|
||||
type IPurchasePlatformOrderHandler interface {
|
||||
Map2Order(orderData map[string]interface{}) (order *model.GoodsOrder)
|
||||
GetOrder(vendorOrgCode, vendorOrderID string) (order *model.GoodsOrder, err error)
|
||||
GetOrderStatus(vendorOrgCode, vendorOrderID string) (status int, err error)
|
||||
GetStatusActionTimeout(order *model.GoodsOrder, statusType, status int) (params *StatusActionParams)
|
||||
|
||||
AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool, userName string) (err error)
|
||||
PickupGoods(order *model.GoodsOrder, isSelfDelivery bool, userName string) (err error)
|
||||
|
||||
AcceptOrRefuseFailedGetOrder(ctx *jxcontext.Context, order *model.GoodsOrder, isAcceptIt bool) (err error)
|
||||
CallCourier(ctx *jxcontext.Context, order *model.GoodsOrder) (err error) // 取货失败后再次招唤平台配送
|
||||
ConfirmReceiveGoods(ctx *jxcontext.Context, order *model.GoodsOrder) (err error) // 投递失败后确认收到退货
|
||||
|
||||
// 是否可能转商家自送
|
||||
CanSwitch2SelfDeliver(order *model.GoodsOrder) (isCan bool, err error)
|
||||
// 将订单从购物平台配送转为自送
|
||||
Swtich2SelfDeliver(order *model.GoodsOrder, userName string) (err error)
|
||||
|
||||
// 将订单从购物平台配送转为自送后又送达
|
||||
Swtich2SelfDelivered(order *model.GoodsOrder, userName string) (err error)
|
||||
|
||||
// 完全自送的门店表示开始配送
|
||||
SelfDeliverDelivering(order *model.GoodsOrder, userName string) (err error)
|
||||
|
||||
// 完全自送的门店表示配送完成
|
||||
SelfDeliverDelivered(order *model.GoodsOrder, userName string) (err error)
|
||||
|
||||
GetOrderRealMobile(ctx *jxcontext.Context, order *model.GoodsOrder) (mobile string, err error)
|
||||
|
||||
ReplyOrderComment(ctx *jxcontext.Context, vendorOrgCode string, orderComment *model.OrderComment, replyComment string) (err error)
|
||||
|
||||
AgreeOrRefuseCancel(ctx *jxcontext.Context, order *model.GoodsOrder, isAgree bool, reason string) (err error)
|
||||
CancelOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string) (err error)
|
||||
// order.Skus要包含原始订单中的Sku信息,removedSkuList中是要移除的Sku信息
|
||||
AdjustOrder(ctx *jxcontext.Context, order *model.GoodsOrder, removedSkuList []*model.OrderSku, reason string) (err error)
|
||||
|
||||
// 售后
|
||||
// 发起全款退款
|
||||
RefundOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string) (err error)
|
||||
// 发起部分退款
|
||||
PartRefundOrder(ctx *jxcontext.Context, order *model.GoodsOrder, refundSkuList []*model.OrderSku, reason string) (err error)
|
||||
// 审核售后单申请
|
||||
AgreeOrRefuseRefund(ctx *jxcontext.Context, order *model.AfsOrder, approveType int, reason string) (err error)
|
||||
// // 确认收到退货
|
||||
ConfirmReceivedReturnGoods(ctx *jxcontext.Context, order *model.AfsOrder) (err error)
|
||||
}
|
||||
|
||||
type IAddWaybillTip interface {
|
||||
GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error)
|
||||
UpdateWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee int64) (err error)
|
||||
}
|
||||
|
||||
type IRidderPositionGetter interface {
|
||||
GetRidderPosition(ctx *jxcontext.Context, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (lng, lat float64, err error)
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
const (
|
||||
PrinterStatusUnknown = 0
|
||||
PrinterStatusOffline = 1
|
||||
PrinterStatusOnlineOK = 2
|
||||
PrinterStatusOnlineAbnormal = 3
|
||||
)
|
||||
|
||||
const (
|
||||
PrintResultSuccess = 0 // 成功
|
||||
PrintResultNoPrinter = 1 // 没有配置网络打印机
|
||||
)
|
||||
|
||||
const (
|
||||
PrinterFontSizeNormal = int8(0) //正常大小
|
||||
PrinterFontSizeBig = int8(1) //两倍大小
|
||||
)
|
||||
|
||||
var (
|
||||
PrinterStatusName = map[int]string{
|
||||
PrinterStatusUnknown: "未知",
|
||||
PrinterStatusOffline: "离线",
|
||||
PrinterStatusOnlineOK: "正常",
|
||||
PrinterStatusOnlineAbnormal: "异常",
|
||||
}
|
||||
)
|
||||
|
||||
type PrinterStatus struct {
|
||||
PrintResult int `json:"printResult"`
|
||||
PrinterStatus int `json:"printerStatus"`
|
||||
Printed int `json:"printed"` // 已经打印的单数
|
||||
Waiting int `json:"waiting"` // 等待打印的单数,超过1一般不太正常
|
||||
}
|
||||
|
||||
type BindPrinterResult struct {
|
||||
PrinterSN string `json:"printerSN"`
|
||||
PrinterKey string `json:"printerKey"`
|
||||
PrinterKey2 string `json:"printerKey2"`
|
||||
ExpiresAt int64 `json:"expiresAt"`
|
||||
}
|
||||
|
||||
type IPrinterHandler interface {
|
||||
GetVendorID() int
|
||||
PrintMsg(ctx *jxcontext.Context, id1, id2, msgTitle, msgContent string) (printerStatus *PrinterStatus, err error)
|
||||
GetPrinterStatus(ctx *jxcontext.Context, id1, id2 string) (printerStatus *PrinterStatus, err error)
|
||||
|
||||
RegisterPrinter(ctx *jxcontext.Context, id1, id2, printerName string) (newID1, newID2 string, err error)
|
||||
UnregisterPrinter(ctx *jxcontext.Context, id1, id2 string) (err error)
|
||||
|
||||
BindPrinter(ctx *jxcontext.Context, mapData map[string]interface{}) (bindResult *BindPrinterResult, err error)
|
||||
RebindPrinter(ctx *jxcontext.Context, lastBindResult *BindPrinterResult) (bindResult *BindPrinterResult, err error)
|
||||
|
||||
// PrintOrder(ctx *jxcontext.Context, store *model.Store, order *model.GoodsOrder) (printerStatus *PrinterStatus, err error)
|
||||
|
||||
EmptyPrintList(ctx *jxcontext.Context, id1, id2 string) (err error)
|
||||
PlayText(ctx *jxcontext.Context, id1, id2, orderID, text string) (printerStatus *PrinterStatus, err error)
|
||||
SetSound(ctx *jxcontext.Context, id1, id2, sound string) (err error)
|
||||
}
|
||||
|
||||
var (
|
||||
PrinterPlatformHandlers map[int]IPrinterHandler
|
||||
)
|
||||
|
||||
func init() {
|
||||
PrinterPlatformHandlers = make(map[int]IPrinterHandler)
|
||||
}
|
||||
|
||||
func RegisterPrinterPlatform(handler IPrinterHandler) {
|
||||
vendorID := handler.GetVendorID()
|
||||
if !(model.IsPrinterVendorExist(vendorID)) {
|
||||
panic(fmt.Sprintf("printer vendor:%d is illegal", vendorID))
|
||||
}
|
||||
if _, ok := PrinterPlatformHandlers[vendorID]; ok {
|
||||
panic(fmt.Sprintf("printer vendor:%d, already exists", vendorID))
|
||||
}
|
||||
PrinterPlatformHandlers[vendorID] = handler
|
||||
}
|
||||
|
||||
func GetPrinterPlatformFromVendorID(vendorID int) IPrinterHandler {
|
||||
return PrinterPlatformHandlers[vendorID]
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
)
|
||||
|
||||
type IStoreHandler interface {
|
||||
GetAllStoresVendorID(ctx *jxcontext.Context, vendorOrgCode string) (vendorStoreIDs []string, err error)
|
||||
|
||||
EnableAutoAcceptOrder(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, isSetEnable bool) (err error)
|
||||
UpdateStoreStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, status int) (err error)
|
||||
// opTime格式为整数1130代表11:30
|
||||
UpdateStoreOpTime(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, opTimeList []int16) (err error)
|
||||
}
|
||||
|
||||
// 同步资质信息至平台
|
||||
type IStoreSyncQualifyHandler interface {
|
||||
// SyncQualify(ctx *jxcontext.Context, storeDetail *dao.StoreDetail) (err error)
|
||||
}
|
||||
@@ -1,203 +0,0 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"math"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
const (
|
||||
// FuncGetStoreSkusBareInfo = 1 // 此接口要求实现为不限制批处理大小的
|
||||
FuncUpdateStoreSkusStock = 2
|
||||
FuncUpdateStoreSkusStatus = 3
|
||||
FuncUpdateStoreSkusPrice = 4
|
||||
|
||||
FuncGetStoreSkusFullInfo = 6
|
||||
FuncCreateStoreSkus = 7
|
||||
FuncUpdateStoreSkus = 8
|
||||
FuncDeleteStoreSkus = 9
|
||||
|
||||
FuncCreateActs = 10
|
||||
FuncCancelActs = 11
|
||||
)
|
||||
|
||||
const (
|
||||
UnlimitedBatchSize = math.MaxInt32
|
||||
|
||||
// MaxStoreSkuStock = model.MaxStoreSkuStockQty
|
||||
UnlimitedStoreSkuStock = -1
|
||||
)
|
||||
|
||||
type StoreSkuInfo struct {
|
||||
SkuID int `json:"skuID,omitempty"`
|
||||
VendorSkuID string `json:"vendorSkuID,omitempty"`
|
||||
NameID int `json:"nameID,omitempty"`
|
||||
VendorNameID string `json:"vendorNameID,omitempty"`
|
||||
|
||||
Stock int `json:"stock,omitempty"`
|
||||
VendorPrice int64 `json:"price,omitempty"`
|
||||
Status int `json:"status,omitempty"`
|
||||
|
||||
Seq int `json:"seq,omitempty"`
|
||||
|
||||
ActPrice int64 `json:"actPrice,omitempty"`
|
||||
VendorActID string `json:"vendorActID,omitempty"`
|
||||
IsSpecialty int `json:"isSpecialty,omitempty"`
|
||||
JxPrice int64 `json:"jxPrice,omitempty"`
|
||||
JxUnitPrice int64 `json:"jxUnitPrice,omitempty"`
|
||||
VendorSkuID2 string `json:"vendorSkuID2,omitempty"`
|
||||
JdsStockSwitch int `json:"jdsStockSwitch"`
|
||||
IsDeletedBySku bool `json:"isDeletedBySku"`
|
||||
}
|
||||
|
||||
type StoreSkuInfoWithErr struct {
|
||||
StoreSkuInfo *StoreSkuInfo
|
||||
CategoryName string
|
||||
VendoreID int
|
||||
VendoreName string
|
||||
StoreID int
|
||||
SyncType string
|
||||
ErrMsg string
|
||||
}
|
||||
|
||||
type SkuInfo struct {
|
||||
StoreSkuInfo
|
||||
SkuName string
|
||||
Comment string
|
||||
SpecQuality float64
|
||||
SpecUnit string
|
||||
Weight int
|
||||
ActPrice int64
|
||||
}
|
||||
|
||||
type SkuNameInfo struct {
|
||||
NameID int `json:"nameID,omitempty"`
|
||||
VendorNameID string `json:"vendorNameID,omitempty"`
|
||||
|
||||
Prefix string
|
||||
Name string
|
||||
Description string
|
||||
Unit string
|
||||
VendorCatIDList []string
|
||||
PictureList []string
|
||||
Status int `json:"status,omitempty"`
|
||||
YbBarCode string
|
||||
SkuList []*SkuInfo
|
||||
}
|
||||
|
||||
type BareStoreSkuInfoList []*StoreSkuInfo
|
||||
|
||||
func (l BareStoreSkuInfoList) GetVendorSkuIDList() (vendorSkuIDList []string) {
|
||||
for _, v := range l {
|
||||
if !dao.IsVendorThingIDEmpty(v.VendorSkuID) {
|
||||
vendorSkuIDList = append(vendorSkuIDList, v.VendorSkuID)
|
||||
}
|
||||
}
|
||||
return vendorSkuIDList
|
||||
}
|
||||
|
||||
func (l BareStoreSkuInfoList) GetVendorSkuIDIntList() (vendorSkuIDIntList []int64) {
|
||||
for _, v := range l {
|
||||
if !dao.IsVendorThingIDEmpty(v.VendorSkuID) {
|
||||
vendorSkuIDIntList = append(vendorSkuIDIntList, utils.Str2Int64(v.VendorSkuID))
|
||||
}
|
||||
}
|
||||
return vendorSkuIDIntList
|
||||
}
|
||||
|
||||
func (l BareStoreSkuInfoList) GetSkuIDList() (skuIDList []int) {
|
||||
for k, v := range l {
|
||||
if v.SkuID > 0 {
|
||||
skuIDList[k] = v.SkuID
|
||||
}
|
||||
}
|
||||
return skuIDList
|
||||
}
|
||||
|
||||
func (l BareStoreSkuInfoList) Len() int {
|
||||
return len(l)
|
||||
}
|
||||
|
||||
func (l BareStoreSkuInfoList) Less(i, j int) bool {
|
||||
if l[i].Seq != l[j].Seq {
|
||||
return l[i].Seq < l[j].Seq
|
||||
}
|
||||
return l[i].VendorPrice < l[j].VendorPrice
|
||||
}
|
||||
|
||||
func (l BareStoreSkuInfoList) Swap(i, j int) {
|
||||
l[i], l[j] = l[j], l[i]
|
||||
}
|
||||
|
||||
type BareCategoryInfo struct {
|
||||
VendorCatID string `json:"vendorCatID"`
|
||||
|
||||
Level int `json:"level"`
|
||||
Name string `json:"name"`
|
||||
Seq int `json:"seq,omitempty"`
|
||||
Children []*BareCategoryInfo `json:"children,omitempty"`
|
||||
}
|
||||
|
||||
// 批处理函数,如果是部分失败的情况会返回失败,successedList中会返回成功的列表
|
||||
|
||||
type IPurchasePlatformStoreSkuHandler interface {
|
||||
GetStoreSkusBatchSize(funcID int) int
|
||||
|
||||
ListOrders(ctx *jxcontext.Context, vendorOrgCode string, parentTask tasksch.ITask, queryDate time.Time, vendorStoreID string) (vendorOrderIDs []string, err error)
|
||||
|
||||
// 此接口要求实现为不限制批处理大小的
|
||||
GetStoreSkusBareInfo(ctx *jxcontext.Context, vendorOrgCode string, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*StoreSkuInfo) (outStoreSkuList []*StoreSkuInfo, err error)
|
||||
UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (failedList []*StoreSkuInfoWithErr, err error)
|
||||
UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo, status int) (failedList []*StoreSkuInfoWithErr, err error)
|
||||
UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (failedList []*StoreSkuInfoWithErr, err error)
|
||||
|
||||
CreateStoreSkusAct(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (failedList []*StoreSkuInfoWithErr, err error)
|
||||
CancelActs(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (failedList []*StoreSkuInfoWithErr, err error)
|
||||
UpdateStoreSkusSpecTag(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (err error)
|
||||
}
|
||||
|
||||
type ISingleStoreStoreSkuHandler interface {
|
||||
IPurchasePlatformStoreSkuHandler
|
||||
|
||||
GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (outSkuNameList []*SkuNameInfo, err error)
|
||||
// CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*StoreSkuInfoWithErr, err error)
|
||||
// UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*StoreSkuInfoWithErr, err error)
|
||||
DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (failedList []*StoreSkuInfoWithErr, err error)
|
||||
DeleteStoreAllSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, isContinueWhenError bool) (err error)
|
||||
IsErrSkuExist(err error) (isExist bool)
|
||||
IsErrSkuNotExist(err error) (isNotExist bool)
|
||||
|
||||
GetStoreAllCategories(ctx *jxcontext.Context, storeID int, vendorStoreID string) (cats []*BareCategoryInfo, err error)
|
||||
GetStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, catName string) (cat *BareCategoryInfo, err error)
|
||||
// CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error)
|
||||
// UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error)
|
||||
DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (err error)
|
||||
DeleteStoreAllCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, isContinueWhenError bool) (err error)
|
||||
|
||||
IsErrCategoryExist(err error) (isExist bool)
|
||||
IsErrCategoryNotExist(err error) (isNotExist bool)
|
||||
|
||||
GetSensitiveWordRegexp() *regexp.Regexp
|
||||
}
|
||||
|
||||
type IStoreSkuSorter interface {
|
||||
ReorderStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, vendorCatID string, storeSkuList []*StoreSkuInfo) (err error)
|
||||
}
|
||||
|
||||
func BuildSkuName(skuID int, vendorSkuID string) (skuName *SkuNameInfo) {
|
||||
return &SkuNameInfo{
|
||||
SkuList: []*SkuInfo{
|
||||
&SkuInfo{
|
||||
StoreSkuInfo: StoreSkuInfo{
|
||||
SkuID: skuID,
|
||||
VendorSkuID: vendorSkuID,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
)
|
||||
|
||||
type PayOpStatus int
|
||||
|
||||
const (
|
||||
OpStatusFailed PayOpStatus = 0
|
||||
OpStatusSuccessed PayOpStatus = 1
|
||||
)
|
||||
|
||||
type CreatePayParam struct {
|
||||
PayOrderID string
|
||||
VendorPayType string
|
||||
|
||||
VendorOrderID string
|
||||
ProductDesc string
|
||||
ProductDetail string
|
||||
FeeType string
|
||||
TotalFee int
|
||||
TimeStart time.Time
|
||||
TimeExpire time.Time
|
||||
|
||||
UserData string
|
||||
}
|
||||
|
||||
type PayOpResult struct {
|
||||
Status PayOpStatus
|
||||
VendorStatus string
|
||||
ErrMsg string
|
||||
|
||||
ID string
|
||||
VendorID string
|
||||
|
||||
OriginalData string
|
||||
}
|
||||
|
||||
type ResponseHandler interface {
|
||||
OnCreatePay(vendorID int, result *PayOpResult) (err error)
|
||||
OnRefundPay(vendorID int, result *PayOpResult) (err error)
|
||||
}
|
||||
|
||||
type IPayPlatformHandler interface {
|
||||
CreatePay(ctx *jxcontext.Context, param *CreatePayParam, isOffline bool) (prepayID, qrCodeURL string, err error)
|
||||
ClosePay(ctx *jxcontext.Context, payOrderID, vendorPayOrderID string) (err error)
|
||||
RefundPay(ctx *jxcontext.Context, payOrderID, vendorPayOrderID, refundID, reason string, totalFee, refundFee int) (vendorRefundID string, err error)
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package wxpay
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/pay"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
func OnCallback(msg *wxpayapi.CallbackMsg) (err error) {
|
||||
globals.SugarLogger.Debugf("wxpay OnCallback msg:%s", utils.Format4Output(msg, true))
|
||||
switch msg.MsgType {
|
||||
case wxpayapi.MsgTypePay:
|
||||
err = onWxpayFinished(msg.Data.(*wxpayapi.PayResultMsg))
|
||||
case wxpayapi.MsgTypeRefund:
|
||||
err = onWxpayRefund(msg.Data.(*wxpayapi.RefundResultMsg))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func onWxpayFinished(msg *wxpayapi.PayResultMsg) (err error) {
|
||||
opResult := &pay.PayOpResult{
|
||||
OriginalData: string(utils.MustMarshal(msg)),
|
||||
}
|
||||
if msg.ReturnCode == wxpayapi.ResponseCodeSuccess {
|
||||
opResult.Status = pay.OpStatusSuccessed
|
||||
opResult.ID = msg.OutTradeNo
|
||||
if msg.ResultCode == wxpayapi.ResponseCodeSuccess {
|
||||
opResult.VendorID = msg.TransactionID
|
||||
} else {
|
||||
opResult.VendorStatus = msg.ErrCode
|
||||
opResult.ErrMsg = msg.ErrCodeDes
|
||||
}
|
||||
} else {
|
||||
opResult.Status = pay.OpStatusFailed
|
||||
}
|
||||
err = payHandler.responseHandler.OnCreatePay(model.VendorIDWXPay, opResult)
|
||||
return err
|
||||
}
|
||||
|
||||
func onWxpayRefund(msg *wxpayapi.RefundResultMsg) (err error) {
|
||||
opResult := &pay.PayOpResult{
|
||||
OriginalData: string(utils.MustMarshal(msg)),
|
||||
}
|
||||
if msg.ReturnCode == wxpayapi.ResponseCodeSuccess {
|
||||
opResult.Status = pay.OpStatusSuccessed
|
||||
if msg.ResultCode == wxpayapi.ResponseCodeSuccess {
|
||||
opResult.ID = msg.ReqInfoObj.OutRefundNo
|
||||
opResult.VendorID = msg.ReqInfoObj.RefundID
|
||||
} else {
|
||||
opResult.VendorStatus = msg.ErrCode
|
||||
opResult.ErrMsg = msg.ErrCodeDes
|
||||
}
|
||||
} else {
|
||||
opResult.Status = pay.OpStatusFailed
|
||||
}
|
||||
err = payHandler.responseHandler.OnRefundPay(model.VendorIDWXPay, opResult)
|
||||
return err
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package wxpay
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/pay"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
type PayHandler struct {
|
||||
responseHandler pay.ResponseHandler
|
||||
}
|
||||
|
||||
var (
|
||||
payHandler *PayHandler
|
||||
)
|
||||
|
||||
func New(responseHandler pay.ResponseHandler) (handler *PayHandler) {
|
||||
return &PayHandler{
|
||||
responseHandler: responseHandler,
|
||||
}
|
||||
}
|
||||
|
||||
func vendorPayType2WxpayType(vendorPayType string) string {
|
||||
return vendorPayType
|
||||
}
|
||||
|
||||
func (p *PayHandler) CreatePay(ctx *jxcontext.Context, createParam *pay.CreatePayParam, isOffline bool) (prepayID, qrCodeURL string, err error) {
|
||||
param := &wxpayapi.CreateOrderParam{
|
||||
OutTradeNo: createParam.PayOrderID,
|
||||
Body: createParam.ProductDesc,
|
||||
NotifyURL: globals.WxpayNotifyURL,
|
||||
SpbillCreateIP: ctx.GetRealRemoteIP(),
|
||||
TradeType: vendorPayType2WxpayType(createParam.VendorPayType),
|
||||
TotalFee: createParam.TotalFee,
|
||||
|
||||
TimeStart: wxpayapi.Time2PayTime(createParam.TimeStart),
|
||||
TimeExpire: wxpayapi.Time2PayTime(createParam.TimeExpire),
|
||||
ProfitSharing: wxpayapi.OptYes,
|
||||
}
|
||||
if isOffline {
|
||||
param.TradeType = wxpayapi.TradeTypeNative
|
||||
}
|
||||
if authInfo, err := ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini {
|
||||
param.OpenID = authInfo.GetAuthID()
|
||||
}
|
||||
if result, err := api.WxpayAPI.CreateUnifiedOrder(param); err == nil {
|
||||
prepayID = result.PrepayID
|
||||
qrCodeURL = result.CodeURL
|
||||
}
|
||||
return prepayID, qrCodeURL, err
|
||||
}
|
||||
|
||||
func (p *PayHandler) ClosePay(ctx *jxcontext.Context, payOrderID, vendorPayOrderID string) (err error) {
|
||||
return api.WxpayAPI.CloseOrder(payOrderID)
|
||||
}
|
||||
|
||||
func (p *PayHandler) RefundPay(ctx *jxcontext.Context, payOrderID, vendorPayOrderID, refundID, reason string, totalFee, refundFee int) (vendorRefundID string, err error) {
|
||||
param := &wxpayapi.PayRefundParam{
|
||||
OutTradeNo: payOrderID,
|
||||
NotifyURL: globals.WxpayNotifyURL,
|
||||
OutRefundNo: refundID,
|
||||
TotalFee: totalFee,
|
||||
RefundFee: refundFee,
|
||||
RefundDesc: wxpayapi.CData(reason),
|
||||
}
|
||||
retVal, err := api.WxpayAPI.PayRefund(param)
|
||||
if err == nil {
|
||||
vendorRefundID = retVal.RefundID
|
||||
}
|
||||
return vendorRefundID, err
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package jx
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreSkuList []*model.ActStoreSku2) (err error) {
|
||||
return err
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package jx
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
type PurchaseHandler struct {
|
||||
partner.BasePurchasePlatform
|
||||
}
|
||||
|
||||
var (
|
||||
CurPurchaseHandler *PurchaseHandler
|
||||
)
|
||||
|
||||
func init() {
|
||||
globals.SugarLogger.Debug("init jx")
|
||||
if true {
|
||||
CurPurchaseHandler = new(PurchaseHandler)
|
||||
// 不能注册京西
|
||||
// partner.RegisterPurchasePlatform(CurPurchaseHandler)
|
||||
partner.RegisterPurchaseOrderHandler(CurPurchaseHandler.GetVendorID(), CurPurchaseHandler)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetVendorID() int {
|
||||
return model.VendorIDJX
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UploadImg(ctx *jxcontext.Context, vendorOrgCode, imgURL string, imgData []byte, imgName string, imgType int) (imgHint string, err error) {
|
||||
return imgHint, err
|
||||
}
|
||||
@@ -1,708 +0,0 @@
|
||||
package localjx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdshopapi"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
OrderCreateTypePre = 0 // 预创建
|
||||
OrderCreateTypeNormal = 1 // 正常创建
|
||||
|
||||
PayWaitingTime = 10 * time.Minute // 等待支付的最长时间
|
||||
DingShiDaMinTime = 1 * time.Hour
|
||||
|
||||
specialStoreID = 100274
|
||||
specialFreightPrice = 1500
|
||||
|
||||
wxAppID = "wx4b5930c13f8b1170"
|
||||
|
||||
autoCancelOrderReason = "支付超时,系统自动取消!"
|
||||
cancelMatterOrderReason = "失败重发!"
|
||||
settleDiscountActRefundReason = "守价订单生成补退款"
|
||||
|
||||
splitMatterOrderMinWeight = 4500 //物料订单分包最少要4.5kg
|
||||
jxwxfMatterEclpID = "EMG4418113943423" //京西五香粉物料编码
|
||||
)
|
||||
|
||||
type JxSkuInfo struct {
|
||||
SkuID int `json:"skuID"`
|
||||
Count int `json:"count"`
|
||||
|
||||
Price int64 `json:"price,omitempty"` // 原价
|
||||
SalePrice int64 `json:"salePrice,omitempty"` // 售卖价
|
||||
|
||||
Name string `json:"name"`
|
||||
Weight int `json:"weight"`
|
||||
GroupSign bool `json:"groupSign"`
|
||||
|
||||
DefendPrice int64 `json:"defendPrice"` //守价
|
||||
}
|
||||
|
||||
type JxSkuInfo2 struct {
|
||||
SkuID int `json:"skuID"`
|
||||
Count int `json:"count"`
|
||||
|
||||
Price int64 `json:"price,omitempty"` // 原价
|
||||
SalePrice int64 `json:"salePrice,omitempty"` // 售卖价
|
||||
|
||||
Name string `json:"name"`
|
||||
Weight int `json:"weight"`
|
||||
GroupSign bool `json:"groupSign"`
|
||||
}
|
||||
|
||||
type JxSkuInfoList []*JxSkuInfo
|
||||
|
||||
func (l JxSkuInfoList) Len() int {
|
||||
return len(l)
|
||||
}
|
||||
|
||||
func (l JxSkuInfoList) Less(i, j int) bool {
|
||||
if l[i].SkuID == l[j].SkuID {
|
||||
return l[i].SalePrice < l[j].SalePrice
|
||||
}
|
||||
return l[i].SkuID < l[j].SkuID
|
||||
}
|
||||
|
||||
func (l JxSkuInfoList) Swap(i, j int) {
|
||||
l[i], l[j] = l[j], l[i]
|
||||
}
|
||||
|
||||
type JxOrderInfo struct {
|
||||
BuyerComment string `json:"buyerComment"`
|
||||
StoreID int `json:"storeID"`
|
||||
Skus []*JxSkuInfo `json:"skus"`
|
||||
|
||||
ExpectedDeliveredTimestamp int64 `json:"expectedDeliveredTimestamp"` // 预期送达时间
|
||||
|
||||
TotalPrice int64 `json:"totalPrice"` // 单位为分 订单总价
|
||||
FreightPrice int64 `json:"freightPrice"` // 单位为分 订单配送费
|
||||
OrderPrice int64 `json:"orderPrice"` // 单位为分 订单商品价格
|
||||
ActualPayPrice int64 `json:"actualPayPrice"` // 单位为分 顾客实际支付
|
||||
|
||||
OrderID int64 `json:"orderID"`
|
||||
StoreName string `json:"storeName"`
|
||||
Weight int `json:"weight"`
|
||||
FromStoreID int `json:"fromStoreID"`
|
||||
EarningType int `json:"earningType"`
|
||||
OrderType int `json:"orderType"`
|
||||
IsBuyNowPrice int `json:"isBuyNowPrice"`
|
||||
IsPriceDefend int `json:"isPriceDefend"`
|
||||
OrderID2 string `json:"-"`
|
||||
UserID string `json:"userID"`
|
||||
}
|
||||
|
||||
type DeliveryTimeItem struct {
|
||||
ViewTime string `json:"viewTime"`
|
||||
UnixTime int64 `json:"unixTime"`
|
||||
ViewShippingFee string `json:"viewShippingFee"`
|
||||
}
|
||||
|
||||
type DeliveryDayTimeInfo struct {
|
||||
Date string `json:"date"`
|
||||
TimeList []*DeliveryTimeItem `json:"timeList"`
|
||||
}
|
||||
|
||||
type MatterOrderStatus struct {
|
||||
Time time.Time `json:"time"`
|
||||
Status string `json:"status"`
|
||||
Name string `json:"name"`
|
||||
Sign int `sign`
|
||||
}
|
||||
|
||||
var (
|
||||
weekdayMap = map[int]string{
|
||||
1: "一",
|
||||
2: "二",
|
||||
3: "三",
|
||||
4: "四",
|
||||
5: "五",
|
||||
6: "六",
|
||||
0: "日",
|
||||
}
|
||||
dayList = []string{"今天", "明天", "后天"}
|
||||
|
||||
bagMap = map[int]int{
|
||||
6039382: 100,
|
||||
6039383: 200,
|
||||
6039384: 200,
|
||||
6039387: 200,
|
||||
6039390: 200,
|
||||
}
|
||||
|
||||
regexpCnameAndCmobile = regexp.MustCompile(`配送员,(.*),手机号,(.*)`)
|
||||
regexpCnameAndCmobile2 = regexp.MustCompile(`(快递员:(.*),联系电话:(.*))`)
|
||||
|
||||
bagSkuMap = map[int]int{ //京西物料袋子skuid
|
||||
6039382: 6039382,
|
||||
6039383: 6039383,
|
||||
6039384: 6039384,
|
||||
6039387: 6039387,
|
||||
6039390: 6039390,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
func buildDefendPriceOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64) (vendorOrderID string) {
|
||||
var (
|
||||
issue = 0
|
||||
db = dao.GetDB()
|
||||
)
|
||||
issue = jxutils.GetDefendPriceIssue()
|
||||
priceDefendOrder := &model.PriceDefendOrder{
|
||||
VendorOrderID: utils.Int64ToStr(jxutils.GenOrderNo()),
|
||||
StoreID: jxOrder.StoreID,
|
||||
SkuID: jxOrder.Skus[0].SkuID,
|
||||
AddressID: addressID,
|
||||
Count: jxOrder.Skus[0].Count,
|
||||
DefendPrice: jxOrder.Skus[0].DefendPrice,
|
||||
OriginPrice: jxOrder.Skus[0].Price,
|
||||
IsBuyNowPrice: jxOrder.IsBuyNowPrice,
|
||||
Issue: issue,
|
||||
IsSuccess: model.NO, //默认是不成功
|
||||
IsPay: model.NO,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(priceDefendOrder, ctx.GetUserName())
|
||||
priceDefendOrder.ActualPayPrice = int64(priceDefendOrder.Count)*jxOrder.Skus[0].Price + jxOrder.FreightPrice
|
||||
dao.CreateEntity(db, priceDefendOrder)
|
||||
return priceDefendOrder.VendorOrderID
|
||||
}
|
||||
|
||||
// 买家取消(或申请取消)订单
|
||||
func BuyerCancelOrder(ctx *jxcontext.Context, orderID int64, reason string) (canceled bool, err error) {
|
||||
order, err := partner.CurOrderManager.LoadOrder(utils.Int64ToStr(orderID), model.VendorIDJX)
|
||||
if err == nil {
|
||||
if order.Status < model.OrderStatusNew {
|
||||
order.Status = model.OrderStatusCanceled
|
||||
order.VendorStatus = utils.Int2Str(model.OrderStatusCanceled)
|
||||
if err = partner.CurOrderManager.UpdateOrderFields(order, []string{model.FieldStatus, "VendorStatus"}); err == nil {
|
||||
canceled = true
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf("暂不支持自行取消订单,请联系商家取消")
|
||||
// err = changeOrderStatus(utils.Int64ToStr(orderID), model.OrderStatusApplyCancel, fmt.Sprintf("用户%s主动取消", ctx.GetUserName()))
|
||||
}
|
||||
}
|
||||
return canceled, err
|
||||
}
|
||||
|
||||
func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType string) (orderPay *model.OrderPay, err error) {
|
||||
order, err := partner.CurOrderManager.LoadOrder(utils.Int64ToStr(orderID), model.VendorIDJX)
|
||||
if err == nil {
|
||||
switch payType {
|
||||
case model.PayTypeWX:
|
||||
if orderPay, err = pay4OrderByWX(ctx, order, vendorPayType); err == nil {
|
||||
dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName())
|
||||
err = dao.CreateEntity(dao.GetDB(), orderPay)
|
||||
}
|
||||
case model.PayTypeTL:
|
||||
if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType); err == nil && orderPay != nil {
|
||||
dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName())
|
||||
err = dao.CreateEntity(dao.GetDB(), orderPay)
|
||||
}
|
||||
default:
|
||||
err = fmt.Errorf("支付方式:%d当前不支持", payType)
|
||||
}
|
||||
} else {
|
||||
// priceDefendOrders, _ := dao.GetPriceDefendOrder(db, utils.Int64ToStr(orderID), nil, nil, []int{jxutils.GetDefendPriceIssue()}, 0, -1, -1, 0, "", utils.ZeroTimeValue, utils.ZeroTimeValue, false)
|
||||
// if len(priceDefendOrders) == 0 {
|
||||
// err = fmt.Errorf("未查询到待支付订单!order_id: %v", orderID)
|
||||
// }
|
||||
// order2 := &model.GoodsOrder{
|
||||
// VendorOrderID: priceDefendOrders[0].VendorOrderID,
|
||||
// ActualPayPrice: priceDefendOrders[0].ActualPayPrice,
|
||||
// VendorID: model.VendorIDJX,
|
||||
// }
|
||||
// if orderPay, err = pay4OrderByTL(ctx, order2, payType, vendorPayType); err == nil && orderPay != nil {
|
||||
// dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName())
|
||||
// err = dao.CreateEntity(dao.GetDB(), orderPay)
|
||||
// }
|
||||
}
|
||||
return orderPay, err
|
||||
}
|
||||
|
||||
func Pay4User(ctx *jxcontext.Context, thingID, payType int, vendorPayType string) (orderPay *model.OrderPay, err error) {
|
||||
// var (
|
||||
// db = dao.GetDB()
|
||||
// order *model.GoodsOrder
|
||||
// dicountCards []*model.DiscountCard
|
||||
// vendorOrderID string
|
||||
// )
|
||||
// switch payType {
|
||||
// case model.PayTypeTL_DiscountCard:
|
||||
// if configList, err := dao.QueryConfigs(db, "会员折扣卡", model.ConfigTypeDiscountCard, ""); err == nil {
|
||||
// jxutils.Strings2Objs(configList[0].Value, &dicountCards)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// discountCard := findDiscountCard(dicountCards, thingID)
|
||||
// // flag, userMemberOrigin, err := checkMember(db, ctx.GetUserID(), discountCard)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// vendorOrderID = utils.Int64ToStr(jxutils.GenOrderNo())
|
||||
// order = &model.GoodsOrder{
|
||||
// VendorOrderID: vendorOrderID,
|
||||
// ActualPayPrice: int64(discountCard.Price),
|
||||
// VendorID: model.VendorIDJX,
|
||||
// }
|
||||
// if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType); err == nil && orderPay != nil {
|
||||
// dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName())
|
||||
// err = dao.CreateEntity(dao.GetDB(), orderPay)
|
||||
// }
|
||||
// userMember := &model.UserMember{
|
||||
// VendorOrderID: vendorOrderID,
|
||||
// UserID: ctx.GetUserID(),
|
||||
// MemberType: model.MemberTypeDiscountCard,
|
||||
// EndAt: utils.Str2Time(time.Now().AddDate(0, 1, 0).AddDate(0, 0, -1).Format("2006-01-02") + " 23:59:59"),
|
||||
// MemberTypeID: thingID,
|
||||
// IsPay: model.NO,
|
||||
// }
|
||||
// dao.WrapAddIDCULDEntity(userMember, ctx.GetUserName())
|
||||
// if flag == 0 {
|
||||
// dao.CreateEntity(db, userMember)
|
||||
// } else if flag == 1 {
|
||||
// userMemberOrigin.EndAt = userMemberOrigin.EndAt.AddDate(0, 1, 0)
|
||||
// dao.UpdateEntity(db, userMemberOrigin, "EndAt")
|
||||
// }
|
||||
// }
|
||||
// default:
|
||||
// err = fmt.Errorf("支付方式:%d当前不支持", payType)
|
||||
// }
|
||||
return orderPay, err
|
||||
}
|
||||
|
||||
func OnPayFinished(orderPay *model.OrderPay) (err error) {
|
||||
order, err := partner.CurOrderManager.LoadOrder(orderPay.VendorOrderID, orderPay.VendorID)
|
||||
if err == nil {
|
||||
db := dao.GetDB()
|
||||
dao.UpdateEntity(db, orderPay)
|
||||
// if count, err2 := dao.GetJxOrderCount(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorOrderID, order.OrderCreatedAt); err2 == nil {
|
||||
// order.OrderSeq = count + 1
|
||||
// partner.CurOrderManager.UpdateOrderFields(order, []string{"OrderSeq"})
|
||||
// }
|
||||
order.Status = model.OrderStatusNew
|
||||
order.VendorStatus = utils.Int2Str(model.OrderStatusNew)
|
||||
order.StatusTime = *orderPay.PayFinishedAt
|
||||
err = callNewOrder(order)
|
||||
//如果是物料的订单,直接到拣货完成,配送中的状态
|
||||
if order.OrderType != model.OrderTypeNormal {
|
||||
// if order.FromStoreID != 0 {
|
||||
if order.OrderType != model.OrderTypeDefendPrice {
|
||||
// netprinter.PrintOrderByOrder(jxcontext.AdminCtx, order)
|
||||
}
|
||||
// PickupGoods(order, false, "jxadmin")
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
switch orderPay.PayType {
|
||||
// case model.PayTypeTL_DiscountCard:
|
||||
// userMembers, _ := dao.GetUserMember(dao.GetDB(), "", orderPay.VendorOrderID, model.MemberTypeDiscountCard, model.NO)
|
||||
// if len(userMembers) > 0 {
|
||||
// userMembers[0].IsPay = model.YES
|
||||
// dao.UpdateEntity(dao.GetDB(), userMembers[0], "IsPay")
|
||||
// err = nil
|
||||
// }
|
||||
default:
|
||||
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func GenPayOrderID(order *model.GoodsOrder) (payOrderID int64) {
|
||||
return utils.Str2Int64(order.VendorOrderID)
|
||||
}
|
||||
|
||||
func GenRefundID(order *model.GoodsOrder) (refundID int64) {
|
||||
const suffix = 100000
|
||||
refundID = utils.Str2Int64(order.VendorOrderID) * suffix
|
||||
refundID += int64(time.Now().Sub(order.OrderFinishedAt) / time.Minute)
|
||||
return refundID
|
||||
}
|
||||
|
||||
func formalizeSkus(skus []*JxSkuInfo) (outSkus []*JxSkuInfo) {
|
||||
skuMap := make(map[int]int)
|
||||
for _, v := range skus {
|
||||
skuMap[v.SkuID] += v.Count
|
||||
}
|
||||
for skuID, skuCount := range skuMap {
|
||||
outSkus = append(outSkus, &JxSkuInfo{
|
||||
SkuID: skuID,
|
||||
Count: skuCount,
|
||||
})
|
||||
}
|
||||
return outSkus
|
||||
}
|
||||
|
||||
func isTimeInOpTime(openTime1, closeTime1, openTime2, closeTime2 int16, time2Check time.Time) bool {
|
||||
timeStrList := []string{
|
||||
jxutils.OperationTime2StrWithSecond(openTime1),
|
||||
jxutils.OperationTime2StrWithSecond(closeTime1),
|
||||
}
|
||||
if openTime1 > 0 {
|
||||
timeStrList = append(timeStrList,
|
||||
jxutils.OperationTime2StrWithSecond(openTime2),
|
||||
jxutils.OperationTime2StrWithSecond(closeTime2),
|
||||
)
|
||||
}
|
||||
checkTimeStr := utils.Time2TimeStr(time2Check)
|
||||
for i := 0; i < len(timeStrList); i += 2 {
|
||||
if checkTimeStr >= timeStrList[i] && checkTimeStr <= timeStrList[i+1] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
func jxOrder2GoodsOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, deliveryAddress *dao.UserDeliveryAddressEx, userID string, IsDeliverySelf bool) (order *model.GoodsOrder, err error) {
|
||||
order = &model.GoodsOrder{
|
||||
VendorOrderID: utils.Int64ToStr(jxOrder.OrderID),
|
||||
VendorID: model.VendorIDJX,
|
||||
VendorStoreID: utils.Int2Str(jxOrder.StoreID),
|
||||
StoreID: jxOrder.StoreID,
|
||||
StoreName: jxOrder.StoreName,
|
||||
// UserID: ctx.GetUserID(),
|
||||
|
||||
ConsigneeName: deliveryAddress.ConsigneeName,
|
||||
ConsigneeMobile: deliveryAddress.ConsigneeMobile,
|
||||
ConsigneeMobile2: deliveryAddress.ConsigneeMobile,
|
||||
ConsigneeAddress: fmt.Sprintf("%s%s", deliveryAddress.Address, deliveryAddress.DetailAddress),
|
||||
CoordinateType: model.CoordinateTypeMars,
|
||||
ConsigneeLng: jxutils.StandardCoordinate2Int(deliveryAddress.Lng),
|
||||
ConsigneeLat: jxutils.StandardCoordinate2Int(deliveryAddress.Lat),
|
||||
|
||||
Status: model.OrderStatusUnknown,
|
||||
VendorStatus: "realnew",
|
||||
OrderSeq: 0,
|
||||
BuyerComment: jxOrder.BuyerComment,
|
||||
|
||||
DeliveryType: model.OrderDeliveryTypeStoreSelf,
|
||||
StatusTime: time.Now(),
|
||||
EarningType: jxOrder.EarningType,
|
||||
OrderType: jxOrder.OrderType,
|
||||
VendorOrderID2: jxOrder.OrderID2,
|
||||
}
|
||||
if userID == "" {
|
||||
order.UserID = ctx.GetUserID()
|
||||
} else {
|
||||
order.UserID = userID
|
||||
}
|
||||
order.OrderCreatedAt = order.StatusTime
|
||||
order.VendorUserID = order.UserID
|
||||
if order.UserID == "" && order.VendorUserID == "" {
|
||||
if jxOrder.UserID != "" {
|
||||
order.UserID = jxOrder.UserID
|
||||
order.VendorUserID = jxOrder.UserID
|
||||
}
|
||||
}
|
||||
if jxOrder.ExpectedDeliveredTimestamp != 0 {
|
||||
order.ExpectedDeliveredTime = utils.Timestamp2Time(jxOrder.ExpectedDeliveredTimestamp)
|
||||
order.BusinessType = model.BusinessTypeDingshida
|
||||
} else {
|
||||
order.ExpectedDeliveredTime = order.OrderCreatedAt.Add(time.Hour)
|
||||
order.BusinessType = model.BusinessTypeImmediate
|
||||
}
|
||||
for _, sku := range jxOrder.Skus {
|
||||
order.Skus = append(order.Skus, &model.OrderSku{
|
||||
Count: sku.Count,
|
||||
VendorSkuID: utils.Int2Str(sku.SkuID),
|
||||
SkuID: sku.SkuID,
|
||||
SkuName: sku.Name,
|
||||
VendorPrice: sku.Price,
|
||||
SalePrice: sku.SalePrice,
|
||||
})
|
||||
order.TotalShopMoney += int64(sku.Count) * sku.SalePrice
|
||||
}
|
||||
order.TotalShopMoney += jxOrder.FreightPrice
|
||||
order.ActualPayPrice = jxOrder.ActualPayPrice
|
||||
order.TotalShopMoney = utils.Float64TwoInt64(float64(order.TotalShopMoney) * jdshopapi.JdsPayPercentage)
|
||||
if jxOrder.FromStoreID != 0 {
|
||||
order.FromStoreID = jxOrder.FromStoreID
|
||||
order.DeliveryFlag = model.OrderDeliveryFlagMaskScheduleDisabled
|
||||
order.Flag = 1
|
||||
if jxOrder.OrderType == model.OrderTypeMatter {
|
||||
order.WaybillVendorID = model.VendorIDJDWL
|
||||
order.ConsigneeAddress = deliveryAddress.Address
|
||||
}
|
||||
}
|
||||
//如果是自提单就设置
|
||||
if IsDeliverySelf {
|
||||
order.DeliveryType = model.OrderDeliveryTypeSelfTake
|
||||
}
|
||||
return order, err
|
||||
}
|
||||
|
||||
func AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool, userName string) (err error) {
|
||||
var status int
|
||||
if isAcceptIt {
|
||||
status = model.OrderStatusAccepted
|
||||
} else {
|
||||
status = model.OrderStatusCanceled
|
||||
}
|
||||
return changeOrderStatus(order.VendorOrderID, status, "")
|
||||
}
|
||||
|
||||
func AdjustOrder(ctx *jxcontext.Context, order *model.GoodsOrder, removedSkuList []*model.OrderSku, reason string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func MarkArrears(db *dao.DaoDB, order *model.GoodsOrder, orderPay *model.OrderPay) {
|
||||
//退款后,若此订单下单用户有推广人,则需要将分给推广人的金额记录到该推广人的欠款中
|
||||
// orders, _ := dao.QueryOrders(db, order.VendorOrderID, 0, []int{model.VendorIDJX}, 0, utils.DefaultTimeValue, utils.DefaultTimeValue)
|
||||
// if len(orders) > 0 {
|
||||
// user, _ := dao.GetUserByID(db, "user_id", orders[0].UserID)
|
||||
// if user.ParentMobile != "" {
|
||||
// user2, _ := dao.GetUserByID(db, "mobile", user.ParentMobile)
|
||||
// user2.Arrears = user2.Arrears + (orderPay.TotalFee * user2.DividePercentage / 100)
|
||||
// dao.UpdateEntity(db, user2, "Arrears")
|
||||
// if user2.ParentMobile != "" {
|
||||
// user3, _ := dao.GetUserByID(db, "mobile", user2.ParentMobile)
|
||||
// user3.Arrears = user3.Arrears + ((orderPay.TotalFee - user2.Arrears) * user3.DividePercentage / 100)
|
||||
// dao.UpdateEntity(db, user3, "Arrears")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// todo 消息用异步可能导致丢失,单同步又有重入相关的问题
|
||||
func callNewOrder(order *model.GoodsOrder) (err error) {
|
||||
jxutils.CallMsgHandlerAsync(func() {
|
||||
err = partner.CurOrderManager.OnOrderNew(order, model.Order2Status(order))
|
||||
}, jxutils.ComposeUniversalOrderID(order.VendorOrderID, model.VendorIDJX))
|
||||
return err
|
||||
}
|
||||
|
||||
func changeOrderStatus(vendorOrderID string, status int, remark string) (err error) {
|
||||
orderStatus := &model.OrderStatus{
|
||||
VendorOrderID: vendorOrderID,
|
||||
VendorID: model.VendorIDJX,
|
||||
OrderType: model.OrderTypeOrder,
|
||||
RefVendorOrderID: vendorOrderID,
|
||||
RefVendorID: model.VendorIDJX,
|
||||
VendorStatus: utils.Int2Str(status),
|
||||
Status: status,
|
||||
StatusTime: time.Now(),
|
||||
Remark: remark,
|
||||
}
|
||||
jxutils.CallMsgHandlerAsync(func() {
|
||||
err = partner.CurOrderManager.OnOrderStatusChanged("", orderStatus)
|
||||
}, jxutils.ComposeUniversalOrderID(vendorOrderID, model.VendorIDJX))
|
||||
return err
|
||||
}
|
||||
|
||||
func PayForPopluarMan(ctx *jxcontext.Context, vendorOrderID, userID string, price int) (err error) {
|
||||
db := dao.GetDB()
|
||||
user, err := dao.GetUserByID(db, "user_id", userID)
|
||||
if user == nil {
|
||||
return fmt.Errorf("未找到此用户!用户ID:[%v]\n", userID)
|
||||
}
|
||||
auth, err := dao.GetUserBindAuthInfo(db, userID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "", "wx4b5930c13f8b1170")
|
||||
if len(auth) == 0 {
|
||||
return fmt.Errorf("未找到此用户的微信验证方式!用户ID:[%v]\n", userID)
|
||||
}
|
||||
// goods, err := dao.QueryOrders(db, vendorOrderID, 0, []int{model.VendorIDJX}, 0, utils.ZeroTimeValue, utils.ZeroTimeValue)
|
||||
// if len(goods) == 0 {
|
||||
// return fmt.Errorf("未找到此订单!订单ID:[%v]\n", vendorOrderID)
|
||||
// }
|
||||
param := &wxpayapi.TransfersParam{
|
||||
CheckName: wxpayapi.CheckName,
|
||||
PartnerTradeNo: vendorOrderID,
|
||||
Desc: "每日推广人订单分成分到个人",
|
||||
SpbillCreateIP: ctx.GetRealRemoteIP(),
|
||||
OpenID: auth[0].AuthID,
|
||||
Amount: price,
|
||||
}
|
||||
_, err = api.WxpayAPI.Transfers(param)
|
||||
return err
|
||||
}
|
||||
|
||||
//自动打款给市场推广人
|
||||
func AutoPayForPopluarMan(ctx *jxcontext.Context) (err error) {
|
||||
// var (
|
||||
// errMsg string
|
||||
// // errCode string
|
||||
// db = dao.GetDB()
|
||||
// fromDateStr = time.Now().AddDate(0, 0, -1).Format("2006-1-2") + " 00:00:00"
|
||||
// toDateStr = time.Now().AddDate(0, 0, -1).Format("2006-1-2") + " 23:59:59"
|
||||
// mapResult = make(map[string]interface{})
|
||||
// )
|
||||
// result, err := dao.GetOrdersForJxPay(db, utils.Str2Time(fromDateStr), utils.Str2Time(toDateStr))
|
||||
// for _, goods := range result {
|
||||
// var (
|
||||
// param = &wxpayapi.TransfersParam{
|
||||
// CheckName: wxpayapi.CheckName,
|
||||
// Desc: "每日推广人订单分成分到个人",
|
||||
// SpbillCreateIP: ctx.GetRealRemoteIP(),
|
||||
// }
|
||||
// payPrice1 int
|
||||
// payPrice2 int
|
||||
// )
|
||||
// user, err := dao.GetUserByID(db, "user_id", goods.UserID)
|
||||
// if user.ParentMobile == "" {
|
||||
// return err
|
||||
// }
|
||||
// user2, err := dao.GetUserByID(db, "mobile", user.ParentMobile)
|
||||
// auths, err := dao.GetUserBindAuthInfo(db, user2.UserID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "", "wx4b5930c13f8b1170")
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if len(auths) == 0 {
|
||||
// errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user2.UserID)
|
||||
// } else {
|
||||
// var openID string
|
||||
// for _, auth := range auths {
|
||||
// if auth.TypeID == wxAppID {
|
||||
// openID = auth.AuthID
|
||||
// }
|
||||
// }
|
||||
// payPrice1 = int(goods.ActualPayPrice) * user2.DividePercentage / 100
|
||||
// //表示这个人之前有欠款,意思是取消订单退款时,这个推广人的分成收不回来,算作欠款,打钱的时候要扣除
|
||||
// //表示这个人之前有小于3毛钱的款没有打(微信付款api付款最低3毛),记录下来加到以后的款项中
|
||||
// rPrice := payPrice1 - user2.Arrears + user2.Profit
|
||||
// err = updateUserAndTransfers(db, param, user2, openID, rPrice)
|
||||
// if err != nil {
|
||||
// errMsg += err.Error()
|
||||
// }
|
||||
// mapResult["打款人1"] = user2.Name
|
||||
// mapResult["打款人金额1"] = rPrice
|
||||
// mapResult["打款人电话1"] = user2.Mobile
|
||||
// mapResult["打款人1userID"] = user2.UserID
|
||||
// }
|
||||
// if user2.ParentMobile != "" {
|
||||
// user3, err := dao.GetUserByID(db, "mobile", user2.ParentMobile)
|
||||
// auths, err := dao.GetUserBindAuthInfo(db, user3.UserID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "", "wx4b5930c13f8b1170")
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if len(auths) == 0 {
|
||||
// errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user3.UserID)
|
||||
// } else {
|
||||
// var openID string
|
||||
// for _, auth := range auths {
|
||||
// if auth.TypeID == wxAppID {
|
||||
// openID = auth.AuthID
|
||||
// }
|
||||
// }
|
||||
// payPrice2 = (int(goods.ActualPayPrice) - payPrice1) * user3.DividePercentage / 100
|
||||
// rPrice := payPrice2 - user3.Arrears + user3.Profit
|
||||
// err = updateUserAndTransfers(db, param, user3, openID, rPrice)
|
||||
// if err != nil {
|
||||
// errMsg += err.Error()
|
||||
// }
|
||||
// mapResult["打款人2"] = user3.Name
|
||||
// mapResult["打款人金额2"] = rPrice
|
||||
// mapResult["打款人电话2"] = user3.Mobile
|
||||
// mapResult["打款人2userID"] = user3.UserID
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// user, _ := dao.GetUserByID(dao.GetDB(), "mobile", "18160030913")
|
||||
// if user != nil && errMsg != "" {
|
||||
// ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "每日打款错误", errMsg)
|
||||
// }
|
||||
// if err != nil || errMsg != "" {
|
||||
// errMsg += err.Error()
|
||||
// errCode = model.ErrCodeGeneralFailed
|
||||
// } else {
|
||||
// errCode = model.ErrCodeSuccess
|
||||
// }
|
||||
// err = event.AddOperateEvent(ctx, ctx.GetTrackInfo(), cms.BuildDiffData(mapResult), errCode, errMsg, 0, "AutoPayForPopluarMan")
|
||||
// globals.SugarLogger.Debugf("每日订单打款:[%v]", cms.BuildDiffData(mapResult))
|
||||
return err
|
||||
}
|
||||
|
||||
func updateUserAndTransfers(db *dao.DaoDB, param *wxpayapi.TransfersParam, user *model.User, authID string, rPrice int) (err error) {
|
||||
if rPrice >= 30 {
|
||||
param.OpenID = authID
|
||||
param.Amount = rPrice
|
||||
param.PartnerTradeNo = utils.GetUUID()
|
||||
_, err = api.WxpayAPI.Transfers(param)
|
||||
user.ProfitSum = user.ProfitSum + rPrice
|
||||
user.Profit = 0
|
||||
user.Arrears = 0
|
||||
} else if rPrice >= 0 && rPrice < 30 {
|
||||
user.Profit = rPrice
|
||||
user.Arrears = 0
|
||||
} else {
|
||||
user.Profit = 0
|
||||
user.Arrears = int(utils.Float64TwoInt64(math.Abs(utils.Int2Float64(rPrice))))
|
||||
}
|
||||
_, err = dao.UpdateEntity(db, user, "ProfitSum", "Profit", "Arrears")
|
||||
return err
|
||||
}
|
||||
|
||||
func CancelPayTimeOutOrder(ctx *jxcontext.Context) (err error) {
|
||||
db := dao.GetDB()
|
||||
var orders []*model.GoodsOrder
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM goods_order
|
||||
WHERE order_created_at >= ? AND order_created_at <= NOW()
|
||||
AND status = ?
|
||||
AND vendor_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
time.Now().Add(-time.Minute * 30),
|
||||
model.OrderStatusWait4Pay,
|
||||
model.VendorIDJX,
|
||||
}
|
||||
err = dao.GetRows(db, &orders, sql, sqlParams)
|
||||
for _, v := range orders {
|
||||
if v.OrderCreatedAt.Add(PayWaitingTime).Before(time.Now()) {
|
||||
err2 := changeOrderStatus(v.VendorOrderID, model.OrderStatusCanceled, autoCancelOrderReason)
|
||||
err = err2
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func GetHalfHoursList() (strs []string) {
|
||||
for k := 0; k < 3; k++ {
|
||||
for i := 0; i < 10; i++ {
|
||||
for j := 0; j < 4; j += 3 {
|
||||
if k == 2 && i > 3 {
|
||||
break
|
||||
}
|
||||
strs = append(strs, utils.Int2Str(k)+utils.Int2Str(i)+":"+utils.Int2Str(j)+"0"+":00")
|
||||
}
|
||||
}
|
||||
}
|
||||
return strs
|
||||
}
|
||||
|
||||
func GetDiscountActHoursList() (str []string) {
|
||||
for k := 1; k < 3; k++ {
|
||||
for i := 0; i < 10; i++ {
|
||||
for j := 0; j < 6; j++ {
|
||||
if k == 1 && i == 0 && j == 0 {
|
||||
continue
|
||||
}
|
||||
if k == 2 && i > 2 {
|
||||
break
|
||||
}
|
||||
if k == 2 && i == 2 && j > 0 {
|
||||
break
|
||||
}
|
||||
str = append(str, utils.Int2Str(k)+utils.Int2Str(i)+":"+utils.Int2Str(j)+"0"+":00")
|
||||
}
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
package localjx
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/tonglianpayapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, payType int, vendorPayType string) (orderPay *model.OrderPay, err error) {
|
||||
// if order.FromStoreID != 0 {
|
||||
// result, _ := orderman.GetMatterStoreOrderCount(nil, order.FromStoreID)
|
||||
// if !result.Flag {
|
||||
// return nil, fmt.Errorf("该门店[%v]已在一周内申请过物料,请勿重复申请!", order.FromStoreID)
|
||||
// }
|
||||
// }
|
||||
payCreatedAt := time.Now()
|
||||
param := &tonglianpayapi.CreateUnitorderOrderParam{
|
||||
Trxamt: int(order.ActualPayPrice),
|
||||
NotifyUrl: globals.TLPayNotifyURL,
|
||||
Reqsn: order.VendorOrderID,
|
||||
PayType: vendorPayType,
|
||||
}
|
||||
//暂时做兼容处理
|
||||
if vendorPayType == "JSAPI" {
|
||||
param.PayType = tonglianpayapi.PayTypeWxXcx
|
||||
}
|
||||
if vendorPayType == tonglianpayapi.PayTypeWxXcx {
|
||||
if authInfo, err := ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini {
|
||||
param.Acct = authInfo.GetAuthID()
|
||||
}
|
||||
}
|
||||
if vendorPayType == tonglianpayapi.PayTypeH5 {
|
||||
param2 := &tonglianpayapi.CreateH5UnitorderOrderParam{
|
||||
Trxamt: int(order.ActualPayPrice),
|
||||
NotifyUrl: globals.TLPayNotifyURL,
|
||||
Body: "京西菜市",
|
||||
Charset: "UTF-8",
|
||||
}
|
||||
err = api.TLpayAPI.CreateH5UnitorderOrder(param2)
|
||||
} else {
|
||||
result, err := api.TLpayAPI.CreateUnitorderOrder(param)
|
||||
if err == nil {
|
||||
var result2 tonglianpayapi.PayInfo
|
||||
json.Unmarshal([]byte(result.PayInfo), &result2)
|
||||
prePayID := result2.Package[strings.LastIndex(result2.Package, "=")+1 : len(result2.Package)]
|
||||
orderPay = &model.OrderPay{
|
||||
PayOrderID: param.Reqsn,
|
||||
PayType: payType,
|
||||
VendorPayType: vendorPayType,
|
||||
TransactionID: result.TrxID,
|
||||
VendorOrderID: order.VendorOrderID,
|
||||
VendorID: order.VendorID,
|
||||
Status: 0,
|
||||
PayCreatedAt: payCreatedAt,
|
||||
PrepayID: prePayID,
|
||||
CodeURL: utils.LimitUTF8StringLen(result.PayInfo, 3200),
|
||||
TotalFee: int(order.ActualPayPrice),
|
||||
}
|
||||
}
|
||||
}
|
||||
return orderPay, err
|
||||
}
|
||||
|
||||
func OnTLPayCallback(call *tonglianpayapi.CallBackResult) (err error) {
|
||||
globals.SugarLogger.Debugf("OnTLPayCallback msg:%s", utils.Format4Output(call, true))
|
||||
switch call.TrxCode {
|
||||
case tonglianpayapi.MsgTypePay:
|
||||
err = onTLpayFinished(call)
|
||||
case tonglianpayapi.MsgTypeRefund:
|
||||
err = onTLpayRefund(call)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
||||
orderPay := &model.OrderPay{
|
||||
PayOrderID: call.CusorderID,
|
||||
// PayType: model.PayTypeTL,
|
||||
}
|
||||
orderPay.DeletedAt = utils.DefaultTimeValue
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetEntity(db, orderPay, "PayOrderID", "DeletedAt"); err == nil {
|
||||
if orderPay.Status != 0 {
|
||||
globals.SugarLogger.Debugf("already pay msg:%s, err:%v", utils.Format4Output(call, true), err)
|
||||
return err
|
||||
}
|
||||
loc, _ := time.LoadLocation("Local")
|
||||
t1, _ := time.ParseInLocation("20060102150405", call.PayTime, loc)
|
||||
orderPay.PayFinishedAt = utils.Time2Pointer(t1)
|
||||
// orderPay.TransactionID = call.ChnlTrxID
|
||||
orderPay.OriginalData = utils.Format4Output(call, true)
|
||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
orderPay.Status = model.PayStatusYes
|
||||
} else {
|
||||
orderPay.Status = model.PayStatusFailed
|
||||
}
|
||||
dao.UpdateEntity(db, orderPay)
|
||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
err = OnPayFinished(orderPay)
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("onTLpayFinished msg:%s, err:%v", utils.Format4Output(call, true), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func onTLpayRefund(call *tonglianpayapi.CallBackResult) (err error) {
|
||||
orderPayRefund := &model.OrderPayRefund{
|
||||
RefundID: call.CusorderID,
|
||||
}
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetEntity(db, orderPayRefund, "RefundID"); err == nil {
|
||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
orderPayRefund.Status = model.RefundStatusYes
|
||||
} else {
|
||||
orderPayRefund.Status = model.RefundStatusFailed
|
||||
}
|
||||
orderPayRefund.OriginalData = utils.Format4Output(call, true)
|
||||
dao.UpdateEntity(db, orderPayRefund)
|
||||
} else if dao.IsNoRowsError(err) {
|
||||
globals.SugarLogger.Warnf("收到异常的退款事件, call:%s", utils.Format4Output(call, true))
|
||||
}
|
||||
|
||||
orderPay := &model.OrderPay{
|
||||
VendorOrderID: orderPayRefund.VendorOrderID,
|
||||
VendorID: jxutils.GetPossibleVendorIDFromVendorOrderID(orderPayRefund.VendorOrderID),
|
||||
PayType: model.PayTypeWX,
|
||||
Status: model.PayStatusYes,
|
||||
}
|
||||
orderPay.DeletedAt = utils.DefaultTimeValue
|
||||
if err = dao.GetEntity(db, orderPay, "VendorOrderID", "VendorID", "PayType", "Status", "DeletedAt"); err == nil {
|
||||
orderPay.Status = model.PayStatusRefund
|
||||
dao.UpdateEntity(db, orderPay)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func RefundOrderByTL(ctx *jxcontext.Context, orderPay *model.OrderPay, refundID string, refundFee int, refundDesc string) (orderPayRefund *model.OrderPayRefund, err error) {
|
||||
result, err := api.TLpayAPI.PayRefund(&tonglianpayapi.PayRefundParam{
|
||||
Trxamt: refundFee,
|
||||
Reqsn: utils.GetUUID(),
|
||||
Remark: refundDesc,
|
||||
OldTrxID: orderPay.TransactionID,
|
||||
})
|
||||
if err == nil {
|
||||
orderPayRefund = &model.OrderPayRefund{
|
||||
RefundID: refundID,
|
||||
VendorRefundID: result.TrxID,
|
||||
VendorOrderID: orderPay.VendorOrderID,
|
||||
VendorID: orderPay.VendorID,
|
||||
Status: model.RefundStatusNo,
|
||||
TransactionID: orderPay.TransactionID,
|
||||
RefundFee: refundFee,
|
||||
RefundCreatedAt: time.Now(),
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName())
|
||||
db := dao.GetDB()
|
||||
if result.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
orderPayRefund.Status = model.RefundStatusYes
|
||||
} else {
|
||||
orderPayRefund.Status = model.RefundStatusFailed
|
||||
}
|
||||
orderPayRefund.OriginalData = utils.Format4Output(result, true)
|
||||
dao.CreateEntity(db, orderPayRefund)
|
||||
|
||||
orderPay.Status = model.PayStatusRefund
|
||||
dao.UpdateEntity(db, orderPay)
|
||||
}
|
||||
return orderPayRefund, err
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
package localjx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func vendorPayType2WxpayType(vendorPayType string) string {
|
||||
return vendorPayType
|
||||
}
|
||||
|
||||
func getOrderBrief(order *model.GoodsOrder) string {
|
||||
return fmt.Sprintf("%s等共%d件商品", order.Skus[0].SkuName, order.GoodsCount)
|
||||
}
|
||||
|
||||
func pay4OrderByWX(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayType string) (orderPay *model.OrderPay, err error) {
|
||||
payCreatedAt := time.Now()
|
||||
param := &wxpayapi.CreateOrderParam{
|
||||
OutTradeNo: utils.Int64ToStr(GenPayOrderID(order)),
|
||||
Body: getOrderBrief(order),
|
||||
NotifyURL: globals.WxpayNotifyURL,
|
||||
SpbillCreateIP: ctx.GetRealRemoteIP(),
|
||||
TradeType: vendorPayType2WxpayType(vendorPayType),
|
||||
TotalFee: int(order.ActualPayPrice),
|
||||
|
||||
TimeStart: wxpayapi.Time2PayTime(payCreatedAt),
|
||||
// TimeExpire: wxpayapi.Time2PayTime(payCreatedAt.Add(PayWaitingTime)),
|
||||
ProfitSharing: wxpayapi.OptYes,
|
||||
}
|
||||
if authInfo, err := ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini {
|
||||
param.OpenID = authInfo.GetAuthID()
|
||||
}
|
||||
result, err := api.WxpayAPI.CreateUnifiedOrder(param)
|
||||
if err == nil {
|
||||
orderPay = &model.OrderPay{
|
||||
PayOrderID: param.OutTradeNo,
|
||||
PayType: model.PayTypeWX,
|
||||
VendorPayType: vendorPayType,
|
||||
|
||||
VendorOrderID: order.VendorOrderID,
|
||||
VendorID: order.VendorID,
|
||||
Status: 0,
|
||||
PayCreatedAt: payCreatedAt,
|
||||
PrepayID: result.PrepayID,
|
||||
CodeURL: result.CodeURL,
|
||||
TotalFee: int(order.ActualPayPrice),
|
||||
}
|
||||
}
|
||||
return orderPay, err
|
||||
}
|
||||
|
||||
func OnWxPayCallback(msg *wxpayapi.CallbackMsg) (err error) {
|
||||
globals.SugarLogger.Debugf("OnWxPayCallback msg:%s", utils.Format4Output(msg, true))
|
||||
switch msg.MsgType {
|
||||
case wxpayapi.MsgTypePay:
|
||||
err = onWxpayFinished(msg.Data.(*wxpayapi.PayResultMsg))
|
||||
case wxpayapi.MsgTypeRefund:
|
||||
err = onWxpayRefund(msg.Data.(*wxpayapi.RefundResultMsg))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func onWxpayFinished(msg *wxpayapi.PayResultMsg) (err error) {
|
||||
orderPay := &model.OrderPay{
|
||||
PayOrderID: msg.OutTradeNo,
|
||||
PayType: model.PayTypeWX,
|
||||
}
|
||||
orderPay.DeletedAt = utils.DefaultTimeValue
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetEntity(db, orderPay, "PayOrderID", "PayType", "DeletedAt"); err == nil {
|
||||
orderPay.PayFinishedAt = utils.Time2Pointer(wxpayapi.PayTime2Time(msg.TimeEnd))
|
||||
orderPay.TransactionID = msg.TransactionID
|
||||
orderPay.OriginalData = utils.Format4Output(msg, true)
|
||||
if msg.ResultCode == wxpayapi.ResponseCodeSuccess {
|
||||
orderPay.Status = model.PayStatusYes
|
||||
} else {
|
||||
orderPay.Status = model.PayStatusFailed
|
||||
}
|
||||
dao.UpdateEntity(db, orderPay)
|
||||
if msg.ResultCode == wxpayapi.ResponseCodeSuccess {
|
||||
err = OnPayFinished(orderPay)
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("onWxpayFinished msg:%s, err:%v", utils.Format4Output(msg, true), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func onWxpayRefund(msg *wxpayapi.RefundResultMsg) (err error) {
|
||||
orderPayRefund := &model.OrderPayRefund{
|
||||
RefundID: msg.ReqInfoObj.OutRefundNo,
|
||||
}
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetEntity(db, orderPayRefund, "RefundID"); err == nil {
|
||||
if msg.ResultCode == wxpayapi.ResponseCodeSuccess {
|
||||
orderPayRefund.Status = model.RefundStatusYes
|
||||
} else {
|
||||
orderPayRefund.Status = model.RefundStatusFailed
|
||||
}
|
||||
orderPayRefund.OriginalData = utils.Format4Output(msg, true)
|
||||
dao.UpdateEntity(db, orderPayRefund)
|
||||
} else if dao.IsNoRowsError(err) {
|
||||
globals.SugarLogger.Warnf("收到异常的退款事件, msg:%s", utils.Format4Output(msg, true))
|
||||
}
|
||||
|
||||
orderPay := &model.OrderPay{
|
||||
VendorOrderID: orderPayRefund.VendorOrderID,
|
||||
VendorID: jxutils.GetPossibleVendorIDFromVendorOrderID(orderPayRefund.VendorOrderID),
|
||||
PayType: model.PayTypeWX,
|
||||
Status: model.PayStatusYes,
|
||||
}
|
||||
orderPay.DeletedAt = utils.DefaultTimeValue
|
||||
if err = dao.GetEntity(db, orderPay, "VendorOrderID", "VendorID", "PayType", "Status", "DeletedAt"); err == nil {
|
||||
orderPay.Status = model.PayStatusRefund
|
||||
dao.UpdateEntity(db, orderPay)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func refundOrderByWX(ctx *jxcontext.Context, orderPay *model.OrderPay, refundID string, refundFee int, refundDesc string) (orderPayRefund *model.OrderPayRefund, err error) {
|
||||
result, err := api.WxpayAPI.PayRefund(&wxpayapi.PayRefundParam{
|
||||
OutTradeNo: orderPay.VendorOrderID,
|
||||
NotifyURL: globals.WxpayNotifyURL,
|
||||
OutRefundNo: refundID,
|
||||
TotalFee: orderPay.TotalFee,
|
||||
RefundFee: refundFee,
|
||||
RefundDesc: wxpayapi.CData(refundDesc),
|
||||
})
|
||||
if err == nil {
|
||||
orderPayRefund = &model.OrderPayRefund{
|
||||
RefundID: refundID,
|
||||
VendorRefundID: result.RefundID,
|
||||
VendorOrderID: orderPay.VendorOrderID,
|
||||
VendorID: orderPay.VendorID,
|
||||
Status: model.RefundStatusNo,
|
||||
TransactionID: orderPay.TransactionID,
|
||||
RefundFee: orderPay.TotalFee,
|
||||
RefundCreatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
return orderPayRefund, err
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
package jx
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/phpjx"
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *model.GoodsOrder) {
|
||||
return order
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetOrder(vendorOrgCode, orderID string) (order *model.GoodsOrder, err error) {
|
||||
order, err = partner.CurOrderManager.LoadOrder(orderID, model.VendorIDJX)
|
||||
return order, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetOrderStatus(vendorOrgCode, vendorOrderID string) (status int, err error) {
|
||||
order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, model.VendorIDJX)
|
||||
if err == nil {
|
||||
status = order.Status
|
||||
}
|
||||
return status, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool, userName string) (err error) {
|
||||
var status int
|
||||
if isAcceptIt {
|
||||
status = model.OrderStatusAccepted
|
||||
} else {
|
||||
status = model.OrderStatusCanceled
|
||||
}
|
||||
if model.IsOrderJXTemp(order) {
|
||||
err = phpjx.NotifyOrderStatusChanged(order, status)
|
||||
} else {
|
||||
err = localjx.AcceptOrRefuseOrder(order, isAcceptIt, userName)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) PickupGoods(order *model.GoodsOrder, isSelfDelivery bool, userName string) (err error) {
|
||||
if model.IsOrderJXTemp(order) {
|
||||
err = phpjx.NotifyOrderStatusChanged(order, model.OrderStatusFinishedPickup)
|
||||
} else {
|
||||
err = localjx.PickupGoods(order, isSelfDelivery, userName)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) AcceptOrRefuseFailedGetOrder(ctx *jxcontext.Context, order *model.GoodsOrder, isAcceptIt bool) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CallCourier(ctx *jxcontext.Context, order *model.GoodsOrder) (err error) { // 拣货失败后再次招唤平台配送
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) ConfirmReceiveGoods(ctx *jxcontext.Context, order *model.GoodsOrder) (err error) { // 投递失败后确认收到退货
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) Swtich2SelfDeliver(order *model.GoodsOrder, userName string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) Swtich2SelfDelivered(order *model.GoodsOrder, userName string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) SelfDeliverDelivering(order *model.GoodsOrder, userName string) (err error) {
|
||||
if model.IsOrderJXTemp(order) {
|
||||
err = phpjx.NotifyOrderStatusChanged(order, model.OrderStatusDelivering)
|
||||
} else {
|
||||
err = localjx.SelfDeliverDelivering(order, userName)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) SelfDeliverDelivered(order *model.GoodsOrder, userName string) (err error) {
|
||||
if model.IsOrderJXTemp(order) {
|
||||
err = phpjx.NotifyOrderStatusChanged(order, model.OrderStatusFinished)
|
||||
} else {
|
||||
err = localjx.SelfDeliverDelivered(order, userName)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetOrderRealMobile(ctx *jxcontext.Context, order *model.GoodsOrder) (mobile string, err error) {
|
||||
return mobile, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) AgreeOrRefuseCancel(ctx *jxcontext.Context, order *model.GoodsOrder, isAgree bool, reason string) (err error) {
|
||||
if model.IsOrderJXTemp(order) {
|
||||
} else {
|
||||
err = localjx.AgreeOrRefuseCancel(ctx, order, isAgree, reason)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) CancelOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string) (err error) {
|
||||
if model.IsOrderJXTemp(order) {
|
||||
err = phpjx.NotifyOrderStatusChanged(order, model.OrderStatusCanceled)
|
||||
} else {
|
||||
err = localjx.CancelOrder(ctx, order, reason)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) AdjustOrder(ctx *jxcontext.Context, order *model.GoodsOrder, removedSkuList []*model.OrderSku, reason string) (err error) {
|
||||
if model.IsOrderJXTemp(order) {
|
||||
} else {
|
||||
err = localjx.AdjustOrder(ctx, order, removedSkuList, reason)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, vendorOrgCode string, parentTask tasksch.ITask, queryDate time.Time, vendorStoreID string) (vendorOrderIDs []string, err error) {
|
||||
return vendorOrderIDs, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) ConfirmSelfTake(ctx *jxcontext.Context, vendorOrderID, selfTakeCode string) (err error) {
|
||||
order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, model.VendorIDJX)
|
||||
if err == nil {
|
||||
if model.IsOrderJXTemp(order) {
|
||||
err = phpjx.NotifyOrderStatusChanged(order, model.OrderStatusFinished)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
package jx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
)
|
||||
|
||||
// 审核售后单申请
|
||||
func (c *PurchaseHandler) AgreeOrRefuseRefund(ctx *jxcontext.Context, order *model.AfsOrder, approveType int, reason string) (err error) {
|
||||
var status int
|
||||
if approveType == partner.AfsApproveTypeRefused {
|
||||
status = model.AfsOrderStatusFailed
|
||||
} else {
|
||||
status = model.AfsOrderStatusFinished
|
||||
}
|
||||
orderStatus := &model.OrderStatus{
|
||||
VendorOrderID: order.AfsOrderID, // 是售后单ID,不是订单ID,订单ID在RefVendorOrderID中
|
||||
VendorID: order.VendorID,
|
||||
OrderType: model.OrderTypeAfsOrder,
|
||||
RefVendorOrderID: order.VendorOrderID,
|
||||
RefVendorID: order.VendorID,
|
||||
VendorStatus: utils.Int2Str(status),
|
||||
Status: status,
|
||||
StatusTime: time.Now(),
|
||||
Remark: reason,
|
||||
}
|
||||
if status == model.AfsOrderStatusFinished {
|
||||
orderPays, err := dao.GetOrderPayList(dao.GetDB(), order.VendorOrderID, order.VendorID)
|
||||
if err == nil {
|
||||
_, err = localjx.RefundOrderByTL(ctx, orderPays[0], order.VendorOrderID, int(order.SkuUserMoney), reason)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
partner.CurOrderManager.OnAfsOrderStatusChanged(orderStatus)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
partner.CurOrderManager.OnAfsOrderStatusChanged(orderStatus)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// 确认收到退货
|
||||
func (c *PurchaseHandler) ConfirmReceivedReturnGoods(ctx *jxcontext.Context, order *model.AfsOrder) (err error) {
|
||||
err = fmt.Errorf("京西商城当前不支持ConfirmReceivedReturnGoods")
|
||||
return err
|
||||
}
|
||||
|
||||
// 发起全款退款
|
||||
func (c *PurchaseHandler) RefundOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string) (err error) {
|
||||
err = c.PartRefundOrder(ctx, order, order.Skus, reason)
|
||||
return err
|
||||
}
|
||||
|
||||
// 发起部分退款
|
||||
func (c *PurchaseHandler) PartRefundOrder(ctx *jxcontext.Context, order *model.GoodsOrder, refundSkuList []*model.OrderSku, reason string) (err error) {
|
||||
globals.SugarLogger.Debugf("PartRefundOrder jx, orderID :%v", order.VendorOrderID)
|
||||
var (
|
||||
skuMap = make(map[int]*model.OrderSku)
|
||||
appID = ""
|
||||
salePrice int64
|
||||
db = dao.GetDB()
|
||||
)
|
||||
if time.Now().Sub(order.OrderCreatedAt) > 24*time.Hour {
|
||||
return fmt.Errorf("已超过售后申请时间,如有疑问请联系门店!")
|
||||
}
|
||||
referer := ctx.GetRequest().Referer()
|
||||
index := strings.Index(referer, "//")
|
||||
if index > 0 {
|
||||
list := strings.Split(referer[index+2:], "/")
|
||||
if len(list) >= 2 {
|
||||
appID = list[1]
|
||||
}
|
||||
}
|
||||
for _, sku := range order.Skus {
|
||||
skuMap[sku.SkuID] = sku
|
||||
}
|
||||
orderStatus := buildOrderStatus(ctx, order, reason, isJxShop(appID))
|
||||
afsOrder := &model.AfsOrder{
|
||||
VendorID: order.VendorID,
|
||||
AfsOrderID: orderStatus.VendorOrderID,
|
||||
VendorOrderID: orderStatus.RefVendorOrderID,
|
||||
VendorStoreID: order.VendorStoreID,
|
||||
StoreID: order.StoreID,
|
||||
AfsCreatedAt: time.Now(),
|
||||
VendorAppealType: "",
|
||||
AppealType: model.AfsAppealTypeRefund,
|
||||
VendorReasonType: utils.Int2Str(model.AfsReasonNotOthers),
|
||||
ReasonType: model.AfsReasonNotOthers,
|
||||
ReasonDesc: utils.LimitUTF8StringLen(reason, 1024),
|
||||
ReasonImgList: "",
|
||||
RefundType: model.AfsTypePartRefund,
|
||||
|
||||
VendorOrgCode: "",
|
||||
}
|
||||
for _, sku := range refundSkuList {
|
||||
orderSku := &model.OrderSkuFinancial{
|
||||
Count: sku.Count,
|
||||
VendorSkuID: utils.Int2Str(sku.SkuID),
|
||||
SkuID: sku.SkuID,
|
||||
}
|
||||
if skuMap[sku.SkuID] != nil {
|
||||
orderSku.Name = skuMap[sku.SkuID].SkuName
|
||||
orderSku.UserMoney = skuMap[sku.SkuID].SalePrice * int64(sku.Count)
|
||||
salePrice += skuMap[sku.SkuID].SalePrice * int64(sku.Count)
|
||||
}
|
||||
afsOrder.SkuUserMoney += orderSku.UserMoney
|
||||
afsOrder.Skus = append(afsOrder.Skus, orderSku)
|
||||
}
|
||||
|
||||
if !isJxShop(appID) {
|
||||
orderPays, err := dao.GetOrderPayList(db, order.VendorOrderID, order.VendorID)
|
||||
if err == nil {
|
||||
_, err = localjx.RefundOrderByTL(ctx, orderPays[0], order.VendorOrderID, int(salePrice), reason)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
if afsOrder != nil {
|
||||
err = partner.CurOrderManager.OnAfsOrderNew(afsOrder, orderStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = partner.CurOrderManager.OnAfsOrderNew(afsOrder, orderStatus)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func buildOrderStatus(ctx *jxcontext.Context, order *model.GoodsOrder, reason string, isJxShop bool) (orderStatus *model.OrderStatus) {
|
||||
orderStatus = &model.OrderStatus{
|
||||
VendorOrderID: utils.Int64ToStr(jxutils.GenAfsOrderNo()), // 是售后单ID,不是订单ID,订单ID在RefVendorOrderID中
|
||||
VendorID: order.VendorID,
|
||||
OrderType: model.OrderTypeAfsOrder,
|
||||
RefVendorOrderID: order.VendorOrderID,
|
||||
RefVendorID: order.VendorID,
|
||||
VendorStatus: utils.Int2Str(model.AfsOrderStatusWait4Approve),
|
||||
// Status: model.AfsOrderStatusWait4Approve,
|
||||
StatusTime: time.Now(),
|
||||
Remark: reason,
|
||||
}
|
||||
if isJxShop {
|
||||
orderStatus.Status = model.AfsOrderStatusWait4Approve
|
||||
} else {
|
||||
orderStatus.Status = model.AfsOrderStatusFinished
|
||||
}
|
||||
return orderStatus
|
||||
}
|
||||
|
||||
func isJxShop(appID string) bool {
|
||||
if appID == api.WeixinMiniAppID2 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package jx
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) ReplyOrderComment(ctx *jxcontext.Context, vendorOrgCode string, orderComment *model.OrderComment, replyComment string) (err error) {
|
||||
return err
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package phpjx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
appKey = "4A86853D-E4B6-454E-940A-B68ECDA2B73E"
|
||||
|
||||
MsgTypeOrder = "order"
|
||||
MsgTypeAfsOrder = "afsOrder"
|
||||
)
|
||||
|
||||
type CallbackResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
type CallbackMsg struct {
|
||||
AppKey string `json:"appKey"`
|
||||
MsgType string `json:"msgType"`
|
||||
SubMsgType string `json:"subMsgType"`
|
||||
ThingID string `json:"thingID"`
|
||||
ThingID2 string `json:"thingID2"`
|
||||
Data string `json:"data"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
func OnCallbackMsg(msg *CallbackMsg) (retVal, errCode string, err error) {
|
||||
if msg.AppKey != appKey {
|
||||
return retVal, errCode, fmt.Errorf("无效的AppKey:%s", msg.AppKey)
|
||||
}
|
||||
if msg.MsgType == MsgTypeOrder {
|
||||
retVal, errCode, err = OnOrderMsg(msg)
|
||||
} else if msg.MsgType == MsgTypeAfsOrder {
|
||||
err = OnAfsOrderMsg(msg)
|
||||
}
|
||||
return retVal, errCode, err
|
||||
}
|
||||
|
||||
func postFakeMsg(orderNo string, status int) {
|
||||
msg := &CallbackMsg{
|
||||
AppKey: appKey,
|
||||
MsgType: MsgTypeOrder,
|
||||
SubMsgType: utils.Int2Str(status),
|
||||
ThingID: orderNo,
|
||||
Timestamp: time.Now().Unix(),
|
||||
}
|
||||
utils.CallFuncAsync(func() {
|
||||
OnCallbackMsg(msg)
|
||||
})
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package phpjx
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||
)
|
||||
|
||||
func init() {
|
||||
testinit.Init()
|
||||
}
|
||||
|
||||
func TestBuildNewJxOrder(t *testing.T) {
|
||||
order, err := partner.CurOrderManager.LoadOrder("920931913000041", model.VendorIDJD)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
order.VendorID = model.VendorIDJX
|
||||
order.VendorStoreID = utils.Int2Str(order.StoreID)
|
||||
for _, sku := range order.Skus {
|
||||
sku.VendorID = model.VendorIDJX
|
||||
sku.VendorSkuID = utils.Int2Str(sku.SkuID)
|
||||
}
|
||||
order2 := &Data4Neworder{
|
||||
GoodsOrder: *order,
|
||||
Skus: order.Skus,
|
||||
}
|
||||
msg := &CallbackMsg{
|
||||
AppKey: appKey,
|
||||
MsgType: MsgTypeOrder,
|
||||
SubMsgType: utils.Int2Str(model.OrderStatusNew),
|
||||
ThingID: order.VendorOrderID,
|
||||
Data: utils.Format4Output(order2, true),
|
||||
}
|
||||
t.Logf("\n%s", msg.AppKey)
|
||||
t.Logf("\n%s", msg.MsgType)
|
||||
t.Logf("\n%s", msg.SubMsgType)
|
||||
t.Logf("\n%s", msg.ThingID)
|
||||
t.Logf("\n%s", msg.Data)
|
||||
|
||||
var order3 *model.GoodsOrder
|
||||
err = utils.UnmarshalUseNumber([]byte(msg.Data), &order3)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(order3.OrderCreatedAt)
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
package phpjx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
type API struct {
|
||||
token string
|
||||
appKey string
|
||||
appSecret string
|
||||
client *http.Client
|
||||
config *platformapi.APIConfig
|
||||
}
|
||||
|
||||
const (
|
||||
ResponseCodeSuccess = 200
|
||||
)
|
||||
|
||||
const (
|
||||
prodURL = "https://www.jingxicaishi.com/index.php/Weimendian/index"
|
||||
)
|
||||
|
||||
var (
|
||||
exceedLimitCodes = map[int]int{}
|
||||
canRetryCodes = map[int]int{}
|
||||
)
|
||||
|
||||
var (
|
||||
jxAPI *API
|
||||
)
|
||||
|
||||
func NewAPI(token, appKey, appSecret string, config ...*platformapi.APIConfig) *API {
|
||||
curConfig := platformapi.DefAPIConfig
|
||||
if len(config) > 0 {
|
||||
curConfig = *config[0]
|
||||
}
|
||||
return &API{
|
||||
token: token,
|
||||
appKey: appKey,
|
||||
appSecret: appSecret,
|
||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||
config: &curConfig,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
jxAPI = NewAPI("", "", "")
|
||||
}
|
||||
|
||||
func (a *API) AccessAPI(apiStr string, jxParams map[string]interface{}, traceInfo string) (retVal map[string]interface{}, err error) {
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
params := utils.MergeMaps(jxParams, map[string]interface{}{
|
||||
"timestamp": utils.GetCurTimeStr(),
|
||||
})
|
||||
var request *http.Request
|
||||
if false {
|
||||
|
||||
} else {
|
||||
fullURL := prodURL + "/" + apiStr
|
||||
// baseapi.SugarLogger.Debug(utils.Map2URLValues(params).Encode())
|
||||
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
|
||||
request.Header.Set("charset", "UTF-8")
|
||||
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
}
|
||||
if traceInfo != "" {
|
||||
request.Header.Set(platformapi.KeyTrackInfo, traceInfo)
|
||||
}
|
||||
// request.Close = true //todo 为了性能考虑还是不要关闭
|
||||
return request
|
||||
},
|
||||
a.config,
|
||||
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
|
||||
if jsonResult1 == nil {
|
||||
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||
}
|
||||
code := int(utils.Interface2Int64WithDefault(jsonResult1["code"], 0))
|
||||
if code == ResponseCodeSuccess {
|
||||
retVal = jsonResult1
|
||||
return platformapi.ErrLevelSuccess, nil
|
||||
}
|
||||
newErr := utils.NewErrorIntCode(jsonResult1["msg"].(string), code)
|
||||
if _, ok := exceedLimitCodes[code]; ok {
|
||||
return platformapi.ErrLevelExceedLimit, newErr
|
||||
} else if _, ok := canRetryCodes[code]; ok {
|
||||
return platformapi.ErrLevelRecoverableErr, newErr
|
||||
} else {
|
||||
baseapi.SugarLogger.Debugf("jx AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
||||
}
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package phpjx
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
var (
|
||||
orderStatusMap = map[int]int{
|
||||
model.OrderStatusFinishedPickup: 7,
|
||||
model.OrderStatusDelivering: 8,
|
||||
// 4,
|
||||
model.OrderStatusFinished: 3,
|
||||
model.OrderStatusCanceled: 3,
|
||||
}
|
||||
)
|
||||
|
||||
func translateOrderStatus(status int) (outStatus int) {
|
||||
return status //orderStatusMap[status]
|
||||
}
|
||||
|
||||
func (a *API) NotifyOrderStatusChanged(order *model.GoodsOrder) (err error) {
|
||||
status := translateOrderStatus(order.Status)
|
||||
if status > 0 {
|
||||
_, err = a.AccessAPI("orderChangeStatus", map[string]interface{}{
|
||||
"orderid": order.VendorOrderID,
|
||||
"status": status,
|
||||
"data": "", //string(utils.MustMarshal(order)),
|
||||
}, "")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) NotifyAfsOrderStatusChanged(afsOrder *model.AfsOrder) (err error) {
|
||||
status := translateOrderStatus(afsOrder.Status)
|
||||
if status > 0 {
|
||||
_, err = a.AccessAPI("afsOrderChangeStatus", map[string]interface{}{
|
||||
"orderid": afsOrder.VendorOrderID,
|
||||
"afsOrderID": afsOrder.AfsOrderID,
|
||||
"status": status,
|
||||
"data": "", //string(utils.MustMarshal(order)),
|
||||
}, "")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package phpjx
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
)
|
||||
|
||||
func TestNotifyOrderStatusChanged(t *testing.T) {
|
||||
order, err := partner.CurOrderManager.LoadOrder("920931913000041", model.VendorIDJX)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = jxAPI.NotifyOrderStatusChanged(order)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package phpjx
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
func NotifyOrderStatusChanged(order *model.GoodsOrder, status int) (err error) {
|
||||
orderMsg := *order
|
||||
orderMsg.Status = status
|
||||
if err = jxAPI.NotifyOrderStatusChanged(&orderMsg); err == nil {
|
||||
postFakeMsg(orderMsg.VendorOrderID, orderMsg.Status)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
type Data4Neworder struct {
|
||||
model.GoodsOrder
|
||||
Skus []*model.OrderSku `json:"skus"`
|
||||
}
|
||||
|
||||
func OnOrderMsg(msg *CallbackMsg) (retVal, errCode string, err error) {
|
||||
jxutils.CallMsgHandler(func() {
|
||||
retVal, errCode, err = onOrderMsg(msg)
|
||||
}, jxutils.ComposeUniversalOrderID(msg.ThingID, model.VendorIDJX))
|
||||
return retVal, errCode, err
|
||||
}
|
||||
|
||||
func onOrderMsg(msg *CallbackMsg) (retVal, errCode string, err error) {
|
||||
subMsgType := int(utils.Str2Int64WithDefault(msg.SubMsgType, 0))
|
||||
if subMsgType == model.OrderStatusNew || subMsgType == model.OrderStatusAdjust {
|
||||
var order *Data4Neworder
|
||||
if err = utils.UnmarshalUseNumber([]byte(msg.Data), &order); err == nil {
|
||||
if order.VendorStatus == "" {
|
||||
order.VendorStatus = utils.Int2Str(order.Status)
|
||||
}
|
||||
retVal, errCode, err = onOrderNew(msg, subMsgType, order)
|
||||
}
|
||||
} else {
|
||||
status := callbackMsg2Status(msg)
|
||||
err = partner.CurOrderManager.OnOrderStatusChanged("", status)
|
||||
}
|
||||
return retVal, errCode, err
|
||||
}
|
||||
|
||||
func callbackMsg2Status(msg *CallbackMsg) *model.OrderStatus {
|
||||
orderStatus := &model.OrderStatus{
|
||||
VendorOrderID: msg.ThingID,
|
||||
VendorID: model.VendorIDJX,
|
||||
OrderType: model.OrderTypeOrder,
|
||||
RefVendorOrderID: msg.ThingID,
|
||||
RefVendorID: model.VendorIDJX,
|
||||
VendorStatus: msg.SubMsgType,
|
||||
Status: int(utils.Str2Int64WithDefault(msg.SubMsgType, 0)),
|
||||
StatusTime: utils.Timestamp2Time(msg.Timestamp),
|
||||
Remark: "",
|
||||
}
|
||||
return orderStatus
|
||||
}
|
||||
|
||||
func onOrderNew(msg *CallbackMsg, subMsgType int, order *Data4Neworder) (retVal, errCode string, err error) {
|
||||
globals.SugarLogger.Debugf("onOrderNew orderID:%s", msg.ThingID)
|
||||
order.StoreID = int(utils.Str2Int64WithDefault(order.VendorStoreID, 0))
|
||||
if order.DeliveryType == "" {
|
||||
order.DeliveryType = model.OrderDeliveryTypeStoreSelf
|
||||
}
|
||||
order.GoodsOrder.Skus = order.Skus
|
||||
order.VendorID = model.VendorIDJX
|
||||
order.Flag = model.OrderFlagMaskTempJX
|
||||
for _, v := range order.GoodsOrder.Skus {
|
||||
v.SkuID = int(utils.Str2Int64WithDefault(v.VendorSkuID, 0))
|
||||
}
|
||||
jxutils.RefreshOrderSkuRelated(&order.GoodsOrder)
|
||||
orderStatus := model.Order2Status(&order.GoodsOrder)
|
||||
if subMsgType == model.OrderStatusNew {
|
||||
err = partner.CurOrderManager.OnOrderNew(&order.GoodsOrder, orderStatus)
|
||||
} else if subMsgType == model.OrderStatusAdjust {
|
||||
err = partner.CurOrderManager.OnOrderAdjust(&order.GoodsOrder, orderStatus)
|
||||
}
|
||||
return retVal, errCode, err
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
package phpjx
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
)
|
||||
|
||||
type Data4AfsOrderSku struct {
|
||||
VendorSkuID string `orm:"column(vendor_sku_id);size(48)" json:"vendorSkuID"` // 平台skuid
|
||||
PromotionType int `json:"promotionType"` // 商品级别促销类型 (1、无优惠;2、秒杀(已经下线);3、单品直降;4、限时抢购;1202、加价购;1203、满赠(标识商品);6、买赠(买A送B,标识B);9999、表示一个普通商品参与捆绑促销,设置的捆绑类型;9998、表示一个商品参与了捆绑促销,并且还参与了其他促销类型;9997、表示一个商品参与了捆绑促销,但是金额拆分不尽,9996:组合购,8001:轻松购会员价,8:第二件N折,9:拼团促销)
|
||||
Name string `orm:"size(255)" json:"name"` // 商品名
|
||||
SalePrice int64 `json:"salePrice"` // 售卖价
|
||||
Count int `json:"count"` // 订单下单数量
|
||||
}
|
||||
|
||||
type Data4AfsOrder struct {
|
||||
VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` // 关联原始订单ID
|
||||
AfsOrderID string `orm:"column(afs_order_id);size(48)" json:"afsOrderID"` // 售后订单ID
|
||||
AfsCreatedAt time.Time `orm:"type(datetime);null;index" json:"afsCreatedAt"` // 售后单生成时间
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"` // 外部系统里记录的storeid
|
||||
|
||||
VendorStatus string `orm:"size(255)" json:"vendorStatus"`
|
||||
VendorReasonType string `orm:"size(255)" json:"vendorReasonType"` // 原始售后原因
|
||||
ReasonDesc string `orm:"size(1024)" json:"reasonDesc"` // 售后原因描述
|
||||
ReasonImgList string `orm:"size(1024)" json:"reasonImgList"` // 售后描述图片
|
||||
VendorAppealType string `orm:"size(255)" json:"vendorAppealType"` // 原始售后方式
|
||||
Skus []*Data4AfsOrderSku
|
||||
}
|
||||
|
||||
func OnAfsOrderMsg(msg *CallbackMsg) (err error) {
|
||||
jxutils.CallMsgHandlerAsync(func() {
|
||||
err = onAfsOrderMsg(msg)
|
||||
}, jxutils.ComposeUniversalOrderID(msg.ThingID, model.VendorIDJX))
|
||||
return err
|
||||
}
|
||||
|
||||
func buildAfsOrder(msg *CallbackMsg) (outAfsOrder *model.AfsOrder, err error) {
|
||||
var afsOrder *Data4AfsOrder
|
||||
if err = utils.UnmarshalUseNumber([]byte(msg.Data), &afsOrder); err == nil {
|
||||
outAfsOrder = &model.AfsOrder{
|
||||
VendorID: model.VendorIDJX,
|
||||
AfsOrderID: afsOrder.AfsOrderID,
|
||||
VendorOrderID: afsOrder.VendorOrderID,
|
||||
VendorStoreID: afsOrder.VendorStoreID,
|
||||
StoreID: int(utils.Str2Int64WithDefault(afsOrder.VendorStoreID, 0)),
|
||||
AfsCreatedAt: afsOrder.AfsCreatedAt,
|
||||
|
||||
VendorStatus: afsOrder.VendorStatus,
|
||||
VendorReasonType: afsOrder.VendorReasonType,
|
||||
ReasonType: int8(utils.Str2Int64WithDefault(afsOrder.VendorReasonType, 0)),
|
||||
ReasonDesc: utils.LimitUTF8StringLen(afsOrder.ReasonDesc, 1024),
|
||||
ReasonImgList: afsOrder.ReasonImgList,
|
||||
VendorAppealType: afsOrder.VendorAppealType,
|
||||
AppealType: int8(utils.Str2Int64WithDefault(afsOrder.VendorAppealType, 0)),
|
||||
Flag: model.OrderFlagMaskTempJX,
|
||||
}
|
||||
outAfsOrder.Status = int(utils.Str2Int64WithDefault(afsOrder.VendorStatus, 0))
|
||||
|
||||
for _, x := range afsOrder.Skus {
|
||||
orderSku := &model.OrderSkuFinancial{
|
||||
Count: x.Count,
|
||||
VendorSkuID: x.VendorSkuID,
|
||||
SkuID: int(utils.Str2Int64WithDefault(x.VendorSkuID, 0)),
|
||||
Name: x.Name,
|
||||
}
|
||||
if x.PromotionType != 0 && x.PromotionType != jdapi.PromotionTypeNormal {
|
||||
orderSku.StoreSubName = utils.Int2Str(x.PromotionType)
|
||||
}
|
||||
outAfsOrder.Skus = append(outAfsOrder.Skus, orderSku)
|
||||
}
|
||||
}
|
||||
return outAfsOrder, err
|
||||
}
|
||||
|
||||
func callbackAfsMsg2Status(msg *CallbackMsg) *model.OrderStatus {
|
||||
orderStatus := &model.OrderStatus{
|
||||
VendorOrderID: msg.ThingID2, // 是售后单ID,不是订单ID,订单ID在RefVendorOrderID中
|
||||
VendorID: model.VendorIDJX,
|
||||
OrderType: model.OrderTypeAfsOrder,
|
||||
RefVendorOrderID: msg.ThingID,
|
||||
RefVendorID: model.VendorIDJX,
|
||||
VendorStatus: msg.SubMsgType,
|
||||
Status: int(utils.Str2Int64WithDefault(msg.SubMsgType, 0)),
|
||||
StatusTime: utils.Timestamp2Time(msg.Timestamp),
|
||||
Remark: "",
|
||||
}
|
||||
return orderStatus
|
||||
}
|
||||
|
||||
func onAfsOrderMsg(msg *CallbackMsg) (err error) {
|
||||
subMsgType := int(utils.Str2Int64WithDefault(msg.SubMsgType, 0))
|
||||
status := callbackAfsMsg2Status(msg)
|
||||
if subMsgType == model.AfsOrderStatusWait4Approve || subMsgType == model.AfsOrderStatusNew {
|
||||
afsOrder, err2 := buildAfsOrder(msg)
|
||||
if err = err2; err == nil {
|
||||
err = partner.CurOrderManager.OnAfsOrderNew(afsOrder, status)
|
||||
}
|
||||
} else {
|
||||
err = partner.CurOrderManager.OnOrderStatusChanged("", status)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func postFakeAfsMsg(orderNo, afsOrderID string, status int) {
|
||||
msg := &CallbackMsg{
|
||||
AppKey: appKey,
|
||||
MsgType: MsgTypeAfsOrder,
|
||||
SubMsgType: utils.Int2Str(status),
|
||||
ThingID: orderNo,
|
||||
ThingID2: afsOrderID,
|
||||
Timestamp: time.Now().Unix(),
|
||||
}
|
||||
utils.CallFuncAsync(func() {
|
||||
OnCallbackMsg(msg)
|
||||
})
|
||||
}
|
||||
|
||||
func NotifyAfsOrderStatusChanged(order *model.AfsOrder, status int) (err error) {
|
||||
orderMsg := *order
|
||||
orderMsg.Status = status
|
||||
if err = jxAPI.NotifyAfsOrderStatusChanged(&orderMsg); err == nil {
|
||||
postFakeAfsMsg(orderMsg.VendorOrderID, orderMsg.AfsOrderID, orderMsg.Status)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package jx
|
||||
|
||||
// 这里函数取得的信息,除了与自身实体相关的ID(比如PARENT ID),都已经转换成了本地ID了
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"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"
|
||||
)
|
||||
|
||||
// func (p *PurchaseHandler) CreateCategory(db *dao.DaoDB, cat *model.SkuCategory, userName string) (err error) {
|
||||
// return err
|
||||
// }
|
||||
|
||||
func (p *PurchaseHandler) GetAllCategories(ctx *jxcontext.Context, vendorOrgCode string) (cats []*partner.BareCategoryInfo, err error) {
|
||||
return cats, err
|
||||
}
|
||||
|
||||
// func (p *PurchaseHandler) UpdateCategory(db *dao.DaoDB, cat *model.SkuCategory, userName string) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) DeleteCategory(db *dao.DaoDB, cat *model.SkuCategory, userName string) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) ReorderCategories(db *dao.DaoDB, parentCatID int, userName string) (err error) {
|
||||
// return err
|
||||
// }
|
||||
|
||||
func (p *PurchaseHandler) CreateCategory2(ctx *jxcontext.Context, cat *dao.SkuStoreCatInfo) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateCategory2(ctx *jxcontext.Context, cat *dao.SkuStoreCatInfo) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) DeleteCategory2(ctx *jxcontext.Context, vendorOrgCode, vendorCatID string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) ReorderCategories2(ctx *jxcontext.Context, vendorOrgCode, vendorParentCatID string, vendorCatIDList []string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// func (p *PurchaseHandler) CreateSku(db *dao.DaoDB, sku *model.Sku, userName string) (err error) {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) ReadSku(ctx *jxcontext.Context, vendorOrgCode, vendorSkuID string) (skuNameExt *model.SkuNameExt, err error) {
|
||||
// return skuNameExt, err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) UpdateSku(db *dao.DaoDB, sku *model.Sku, userName string) (err error) {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) DeleteSku(db *dao.DaoDB, sku *model.Sku, userName string) (err error) {
|
||||
// return err
|
||||
// }
|
||||
|
||||
func (p *PurchaseHandler) CreateSku2(ctx *jxcontext.Context, sku *dao.StoreSkuSyncInfo) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateSku2(ctx *jxcontext.Context, sku *dao.StoreSkuSyncInfo) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) DeleteSku2(ctx *jxcontext.Context, vendorOrgCode string, sku *partner.StoreSkuInfo) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetVendorCategories(ctx *jxcontext.Context) (vendorCats []*model.SkuVendorCategory, err error) {
|
||||
return vendorCats, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetSkus(ctx *jxcontext.Context, vendorOrgCode string, skuID int, vendorSkuID string) (skuNameList []*partner.SkuNameInfo, err error) {
|
||||
return skuNameList, err
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package jx
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string) (storeDetail *dao.StoreDetail, err error) {
|
||||
return storeDetail, err
|
||||
}
|
||||
|
||||
// stoerIDs为nil表示所有
|
||||
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool) (hint string, err error) {
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string) (storeStatus int, err error) {
|
||||
return storeStatus, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) EnableAutoAcceptOrder(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, isSetEnable bool) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateStoreStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, status int) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateStoreOpTime(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, opTimeList []int16) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetAllStoresVendorID(ctx *jxcontext.Context, vendorOrgCode string) (vendorStoreIDs []string, err error) {
|
||||
return vendorStoreIDs, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateStoreCustomID(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string, storeID int64) (err error) {
|
||||
return err
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package jx
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
)
|
||||
|
||||
func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
|
||||
batchSize = 1
|
||||
return batchSize
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreSkusBareInfo(ctx *jxcontext.Context, vendorOrgCode string, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) {
|
||||
return outStoreSkuList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (successList []*partner.StoreSkuInfo, err error) {
|
||||
return successList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) {
|
||||
return successList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) {
|
||||
return successList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CreateStoreSkusAct(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
return failedList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CancelActs(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
return failedList, err
|
||||
}
|
||||
@@ -1,304 +0,0 @@
|
||||
package putils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
)
|
||||
|
||||
type DefSingleStorePlatform struct {
|
||||
partner.ISingleStoreStoreSkuHandler
|
||||
}
|
||||
|
||||
func (p *DefSingleStorePlatform) DeleteStoreAllSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, isContinueWhenError bool) (err error) {
|
||||
skuNameList, err := p.GetStoreSkusFullInfo(ctx, parentTask, storeID, vendorStoreID, nil)
|
||||
if err != nil || len(skuNameList) == 0 {
|
||||
return err
|
||||
}
|
||||
storeStoreList := make([]*partner.StoreSkuInfo, len(skuNameList))
|
||||
for k, v := range skuNameList {
|
||||
storeStoreList[k] = &partner.StoreSkuInfo{
|
||||
SkuID: v.SkuList[0].SkuID,
|
||||
VendorSkuID: v.SkuList[0].VendorSkuID,
|
||||
}
|
||||
}
|
||||
_, err = FreeBatchStoreSkuInfo("删除门店商品", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
|
||||
_, err = p.DeleteStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList)
|
||||
return nil, 0, err
|
||||
}, ctx, parentTask, storeStoreList, p.GetStoreSkusBatchSize(partner.FuncDeleteStoreSkus), isContinueWhenError)
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *DefSingleStorePlatform) DeleteStoreAllCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, isContinueWhenError bool) (err error) {
|
||||
catList, err := p.GetStoreAllCategories(ctx, storeID, vendorStoreID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
catListMap := make(map[int][]*partner.BareCategoryInfo)
|
||||
flattedCatList := flatCatList(catList)
|
||||
for _, v := range flattedCatList {
|
||||
catListMap[v.Level] = append(catListMap[v.Level], v)
|
||||
}
|
||||
var levelList []int
|
||||
for k := range catListMap {
|
||||
levelList = append(levelList, k)
|
||||
}
|
||||
sort.Sort(sort.Reverse(sort.IntSlice(levelList)))
|
||||
task1 := tasksch.NewSeqTask2(fmt.Sprintf("DeleteStoreAllCategories1, vendorStoreID:%s", vendorStoreID), ctx, true,
|
||||
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
vendorCatIDs := make([]string, len(catListMap[levelList[step]]))
|
||||
for k, v := range catListMap[levelList[step]] {
|
||||
vendorCatIDs[k] = v.VendorCatID
|
||||
}
|
||||
err = FreeBatchCategoryIDOp(func(vendorCatID string) (err error) {
|
||||
err2 := p.DeleteStoreCategory(ctx, storeID, vendorStoreID, vendorCatID, step)
|
||||
return err2
|
||||
}, ctx, task, vendorCatIDs, isContinueWhenError)
|
||||
return nil, err
|
||||
}, len(levelList))
|
||||
tasksch.HandleTask(task1, parentTask, true).Run()
|
||||
_, err = task1.GetResult(0)
|
||||
return err
|
||||
}
|
||||
|
||||
func flatCatList(catList []*partner.BareCategoryInfo) (flattedCatList []*partner.BareCategoryInfo) {
|
||||
flattedCatList = append(flattedCatList, catList...)
|
||||
for _, v := range catList {
|
||||
flattedCatList = append(flattedCatList, flatCatList(v.Children)...)
|
||||
}
|
||||
return flattedCatList
|
||||
}
|
||||
|
||||
func (p *DefSingleStorePlatform) GetStoreSkusBareInfo(ctx *jxcontext.Context, vendorOrgCode string, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) {
|
||||
resultList, err := FreeBatchStoreSkuInfo("获取门店商品信息", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
|
||||
result, err = p.GetStoreSkusFullInfo(ctx, parentTask, storeID, vendorStoreID, batchedStoreSkuList)
|
||||
return result, successCount, err
|
||||
}, ctx, parentTask, inStoreSkuList, p.GetStoreSkusBatchSize(partner.FuncGetStoreSkusFullInfo), true)
|
||||
if err != nil || len(resultList) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
inStoreSkuMap := make(map[string]*partner.StoreSkuInfo)
|
||||
for _, v := range inStoreSkuList {
|
||||
if v.VendorSkuID != "" {
|
||||
inStoreSkuMap[v.VendorNameID] = v
|
||||
}
|
||||
}
|
||||
for _, v := range resultList {
|
||||
skuName := v.(*partner.SkuNameInfo)
|
||||
for _, v2 := range skuName.SkuList {
|
||||
storeSkuBareInfo := &v2.StoreSkuInfo
|
||||
if storeSkuBareInfo.SkuID == 0 && inStoreSkuMap[storeSkuBareInfo.VendorSkuID] != nil {
|
||||
storeSkuBareInfo.SkuID = inStoreSkuMap[storeSkuBareInfo.VendorSkuID].SkuID
|
||||
storeSkuBareInfo.NameID = inStoreSkuMap[storeSkuBareInfo.VendorSkuID].NameID
|
||||
}
|
||||
outStoreSkuList = append(outStoreSkuList, storeSkuBareInfo)
|
||||
}
|
||||
}
|
||||
return outStoreSkuList, err
|
||||
}
|
||||
|
||||
func StoreSkuFullList2Bare(storeSkuFull []*partner.SkuNameInfo) (bareStoreSkuList []*partner.StoreSkuInfo) {
|
||||
for _, v := range storeSkuFull {
|
||||
for _, v2 := range v.SkuList {
|
||||
bareStoreSkuList = append(bareStoreSkuList, &v2.StoreSkuInfo)
|
||||
}
|
||||
}
|
||||
return bareStoreSkuList
|
||||
}
|
||||
|
||||
func findCategoryByName(catList []*partner.BareCategoryInfo, catName string) (cat *partner.BareCategoryInfo) {
|
||||
catName2 := utils.FilterEmoji(catName)
|
||||
for _, v := range catList {
|
||||
if v.Name == catName || v.Name == catName2 {
|
||||
cat = v
|
||||
break
|
||||
}
|
||||
if cat = findCategoryByName(v.Children, catName); cat != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return cat
|
||||
}
|
||||
func (p *DefSingleStorePlatform) GetStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, catName string) (cat *partner.BareCategoryInfo, err error) {
|
||||
catList, err := p.GetStoreAllCategories(ctx, storeID, vendorStoreID)
|
||||
if err == nil {
|
||||
if cat = findCategoryByName(catList, catName); cat == nil {
|
||||
err = fmt.Errorf("门店:%d,%s不能找到商家分类:%s", storeID, vendorStoreID, catName)
|
||||
}
|
||||
}
|
||||
return cat, err
|
||||
}
|
||||
|
||||
func FreeBatchStoreSkuInfo(name string, handler func(tasksch.ITask, []*partner.StoreSkuInfo) (interface{}, int, error), ctx *jxcontext.Context, parentTask tasksch.ITask, storeSkuList []*partner.StoreSkuInfo, batchSize int, isContinueWhenError bool) (resultList []interface{}, err error) {
|
||||
if true { //len(storeSkuList) > batchSize {
|
||||
task := tasksch.NewParallelTask2(fmt.Sprintf("FreeBatchStoreSkuInfo:%s", name), tasksch.NewParallelConfig().SetParallelCount(1).SetBatchSize(batchSize).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, successCount int, err error) {
|
||||
batchStoreSkuList := make([]*partner.StoreSkuInfo, len(batchItemList))
|
||||
for k, v := range batchItemList {
|
||||
batchStoreSkuList[k] = v.(*partner.StoreSkuInfo)
|
||||
}
|
||||
retVal, successCount, err = handler(task, batchStoreSkuList)
|
||||
if err != nil {
|
||||
retVal = nil
|
||||
}
|
||||
return retVal, successCount, err
|
||||
}, storeSkuList)
|
||||
tasksch.HandleTask(task, parentTask, false).Run()
|
||||
resultList, err = task.GetResult(0)
|
||||
} else {
|
||||
result, _, err2 := handler(parentTask, storeSkuList)
|
||||
if err = err2; err == nil {
|
||||
resultList = utils.Interface2Slice(result)
|
||||
}
|
||||
}
|
||||
return resultList, err
|
||||
}
|
||||
|
||||
func FreeBatchCategoryIDOp(handler func(vendorCatID string) (err error), ctx *jxcontext.Context, parentTask tasksch.ITask, vendorCatIDs []string, isContinueWhenError bool) (err error) {
|
||||
if len(vendorCatIDs) > 1 {
|
||||
task := tasksch.NewParallelTask("FreeBatchCategoryIDOp", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
err = handler(batchItemList[0].(string))
|
||||
return nil, err
|
||||
}, vendorCatIDs)
|
||||
tasksch.HandleTask(task, parentTask, false).Run()
|
||||
_, err = task.GetResult(0)
|
||||
} else if len(vendorCatIDs) > 0 {
|
||||
err = handler(vendorCatIDs[0])
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func StoreSkuList2MapByVendorSkuID(storeSkuList []*partner.StoreSkuInfo) (storeSkuMap map[string]*partner.StoreSkuInfo) {
|
||||
storeSkuMap = make(map[string]*partner.StoreSkuInfo)
|
||||
for _, v := range storeSkuList {
|
||||
storeSkuMap[v.VendorSkuID] = v
|
||||
}
|
||||
return storeSkuMap
|
||||
}
|
||||
|
||||
func StoreSkuList2MapBySkuID(storeSkuList []*partner.StoreSkuInfo) (storeSkuMap map[int]*partner.StoreSkuInfo) {
|
||||
storeSkuMap = make(map[int]*partner.StoreSkuInfo)
|
||||
for _, v := range storeSkuList {
|
||||
storeSkuMap[v.SkuID] = v
|
||||
}
|
||||
return storeSkuMap
|
||||
}
|
||||
|
||||
func StoreSkuList2IDs(storeSkuList []*partner.StoreSkuInfo) (ids []int) {
|
||||
ids = make([]int, len(storeSkuList))
|
||||
for k, v := range storeSkuList {
|
||||
ids[k] = v.SkuID
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
func UnselectStoreSkuListByVendorSkuIDs(storeSkuList []*partner.StoreSkuInfo, vendorSkuIDs []string) (selectedStoreSkuList []*partner.StoreSkuInfo) {
|
||||
if len(vendorSkuIDs) > 0 {
|
||||
vendorSkuIDMap := jxutils.StringList2Map(vendorSkuIDs)
|
||||
for _, v := range storeSkuList {
|
||||
if vendorSkuIDMap[v.VendorSkuID] == 0 {
|
||||
selectedStoreSkuList = append(selectedStoreSkuList, v)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
selectedStoreSkuList = storeSkuList
|
||||
}
|
||||
return selectedStoreSkuList
|
||||
}
|
||||
|
||||
func GetErrMsg2FailedSingleList(storeSkuList interface{}, err error, storeID int, vendorName, syncType string) (failedList []*partner.StoreSkuInfoWithErr) {
|
||||
|
||||
return failedList
|
||||
}
|
||||
|
||||
func UnselectStoreSkuListBySkuIDs(storeSkuList []*partner.StoreSkuInfo, skuIDs []int) (selectedStoreSkuList []*partner.StoreSkuInfo) {
|
||||
if len(skuIDs) > 0 {
|
||||
skuIDMap := jxutils.IntList2Map(skuIDs)
|
||||
for _, v := range storeSkuList {
|
||||
if skuIDMap[v.SkuID] == 0 {
|
||||
selectedStoreSkuList = append(selectedStoreSkuList, v)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
selectedStoreSkuList = storeSkuList
|
||||
}
|
||||
return selectedStoreSkuList
|
||||
}
|
||||
|
||||
func GenPartialFailedErr(failedInfo interface{}, failedCount int) (err error) {
|
||||
if failedCount > 0 {
|
||||
err = fmt.Errorf("部分失败了%d个:%s", failedCount, utils.Format4Output(failedInfo, true))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func StoreSku2ActStoreSku(syncStatus int8, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (actStoreSku []*model.ActStoreSku2) {
|
||||
for _, v := range storeSkuList {
|
||||
actStoreSku = append(actStoreSku, &model.ActStoreSku2{
|
||||
ActStoreSku: model.ActStoreSku{
|
||||
SkuID: v.SkuID,
|
||||
Stock: 200,
|
||||
},
|
||||
VendorStoreID: vendorStoreID,
|
||||
VendorSkuID: v.VendorSkuID,
|
||||
VendorActID: v.VendorActID,
|
||||
ActualActPrice: v.ActPrice,
|
||||
SyncStatus: syncStatus,
|
||||
})
|
||||
}
|
||||
return actStoreSku
|
||||
}
|
||||
|
||||
func UpdateStoreSkuByActStoreSku(storeSkuList []*partner.StoreSkuInfo, actStoreSku []*model.ActStoreSku2) []*partner.StoreSkuInfo {
|
||||
storeSkuMap := StoreSkuList2MapBySkuID(storeSkuList)
|
||||
for _, v := range actStoreSku {
|
||||
if storeSku := storeSkuMap[v.SkuID]; storeSku != nil {
|
||||
storeSku.VendorActID = v.VendorActID
|
||||
}
|
||||
}
|
||||
return storeSkuList
|
||||
}
|
||||
|
||||
func GetFixDirectDownAct(vendorOrgCode string, storeID, skuID int) (act *model.Act2) {
|
||||
name := fmt.Sprintf("自动直降活动%d:%d:%d", storeID, skuID, time.Now().Unix())
|
||||
act = &model.Act2{
|
||||
Act: model.Act{
|
||||
Name: name,
|
||||
Advertising: name,
|
||||
Type: model.ActSkuDirectDown,
|
||||
Status: model.ActStatusCreated,
|
||||
LimitUser: 1,
|
||||
LimitCount: 1,
|
||||
BeginAt: utils.Time2Date(time.Now()),
|
||||
EndAt: utils.Time2Date(time.Now().Add(50 * 24 * time.Hour)), // 饿百平台要求只能是2个月长的活动
|
||||
},
|
||||
VendorOrgCode: vendorOrgCode,
|
||||
}
|
||||
return act
|
||||
}
|
||||
|
||||
func StoreSkuInfoWithErrList2SkuIDs(list []*partner.StoreSkuInfoWithErr) (skuIDs []int) {
|
||||
for _, v := range list {
|
||||
if v.StoreSkuInfo != nil && v.StoreSkuInfo.SkuID > 0 {
|
||||
skuIDs = append(skuIDs, v.StoreSkuInfo.SkuID)
|
||||
}
|
||||
}
|
||||
return skuIDs
|
||||
}
|
||||
|
||||
func StoreSkuInfoWithErrList2MapBySku(list []*partner.StoreSkuInfoWithErr) (mapInfo map[int]*partner.StoreSkuInfoWithErr) {
|
||||
mapInfo = make(map[int]*partner.StoreSkuInfoWithErr)
|
||||
for _, v := range list {
|
||||
mapInfo[v.StoreSkuInfo.SkuID] = v
|
||||
}
|
||||
return mapInfo
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
package apimanager
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
FakeJdOrgCode = "fakejd"
|
||||
)
|
||||
|
||||
type VendorOrgCodePair struct {
|
||||
VendorID int
|
||||
AppOrgCode string
|
||||
}
|
||||
|
||||
type APIManager struct {
|
||||
}
|
||||
|
||||
var (
|
||||
CurAPIManager *APIManager
|
||||
)
|
||||
|
||||
func init() {
|
||||
globals.SugarLogger.Debug("init apimanager")
|
||||
CurAPIManager = &APIManager{}
|
||||
partner.InitAPIManager(CurAPIManager)
|
||||
}
|
||||
|
||||
func (a *APIManager) GetAPI(vendorID int, appOrgCode string) (pfAPI interface{}) {
|
||||
switch vendorID {
|
||||
case model.VendorIDJD:
|
||||
pfAPI = api.JdAPI
|
||||
if appOrgCode == FakeJdOrgCode {
|
||||
pfAPI = api.FakeJdAPI
|
||||
} else if appOrgCode != "" && appOrgCode == globals.Jd2OrgCode {
|
||||
pfAPI = api.Jd2API
|
||||
} else if appOrgCode != "" && appOrgCode == globals.Jd3OrgCode {
|
||||
pfAPI = api.Jd3API
|
||||
}
|
||||
case model.VendorIDMTWM:
|
||||
pfAPI = api.MtwmAPI
|
||||
case model.VendorIDEBAI:
|
||||
pfAPI = api.EbaiAPI
|
||||
}
|
||||
return pfAPI
|
||||
}
|
||||
|
||||
// TODO
|
||||
func (a *APIManager) GetAppOrgCodeList(vendorID int) (appOrgCodeList []string) {
|
||||
switch vendorID {
|
||||
case model.VendorIDJD:
|
||||
appOrgCodeList = jxutils.BatchString2Slice(globals.JdOrgCode, globals.Jd2OrgCode, globals.Jd3OrgCode)
|
||||
case model.VendorIDMTWM:
|
||||
appOrgCodeList = []string{api.MtwmAPI.GetAppID()}
|
||||
case model.VendorIDEBAI:
|
||||
appOrgCodeList = []string{api.EbaiAPI.GetSource()}
|
||||
}
|
||||
return appOrgCodeList
|
||||
}
|
||||
|
||||
func (a *APIManager) GetVendorOrgCodeList(vendorIDs []int, appOrgCodes []string) (vendorOrgCodeList []*VendorOrgCodePair) {
|
||||
if len(vendorIDs) == 0 {
|
||||
vendorIDs = partner.GetMultiStoreVendorIDs()
|
||||
}
|
||||
appOrgCodeMap := jxutils.StringList2Map(appOrgCodes)
|
||||
for _, vendorID := range vendorIDs {
|
||||
tmpOrgCodeList := a.GetAppOrgCodeList(vendorID)
|
||||
for _, v := range tmpOrgCodeList {
|
||||
if len(appOrgCodes) == 0 || appOrgCodeMap[v] == 1 {
|
||||
vendorOrgCodeList = append(vendorOrgCodeList, &VendorOrgCodePair{
|
||||
VendorID: vendorID,
|
||||
AppOrgCode: v,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return vendorOrgCodeList
|
||||
}
|
||||
|
||||
func GetVendorOrgCodeMap(ctx *jxcontext.Context) (vendorOrgCodeMap map[int][]string) {
|
||||
vendorOrgCodeMap = make(map[int][]string)
|
||||
for _, vendorID := range partner.GetPurchasePlatformVendorIDs() {
|
||||
vendorOrgCodeMap[vendorID] = CurAPIManager.GetAppOrgCodeList(vendorID)
|
||||
}
|
||||
return vendorOrgCodeMap
|
||||
}
|
||||
Reference in New Issue
Block a user