Merge remote-tracking branch 'origin/mark' into don
This commit is contained in:
@@ -236,7 +236,7 @@ func (c *OrderManager) SaveOrder(order *model.GoodsOrder, isAdjust bool, db *dao
|
||||
return isDuplicated, err
|
||||
}
|
||||
|
||||
func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.DaoDB) (err error) {
|
||||
func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.DaoDB, storePayPercentage int) (err error) {
|
||||
globals.SugarLogger.Debugf("updateOrderSkuOtherInfo orderID:%s, VendorStoreID:%s", order.VendorOrderID, order.VendorStoreID)
|
||||
jxStoreID := jxutils.GetShowStoreIDFromOrder(order)
|
||||
var opNumStr string
|
||||
@@ -316,10 +316,10 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
|
||||
v.JxSkuID = skuBindInfo.SkuID
|
||||
v.ShopPrice = int64(skuBindInfo.Price)
|
||||
v.Weight = skuBindInfo.Weight // 以本地信息中的WEIGHT为准
|
||||
order.ShopPrice += v.ShopPrice * int64(v.Count)
|
||||
if skuBindInfo.Price == 0 {
|
||||
globals.SugarLogger.Infof("updateOrderSkuOtherInfo [运营%s]%s订单sku门店价格为零(一般原因为没有门店价格信息),orderID:%s, StoreID:%d, SkuID:%d, sku:%v", opNumStr, model.VendorChineseNames[order.VendorID], order.VendorOrderID, jxStoreID, v.JxSkuID, v)
|
||||
}
|
||||
v.EarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
|
||||
if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 {
|
||||
if actStoreSku := actStoreSkuMap.GetActStoreSku(jxStoreID, skuID, order.VendorID); actStoreSku != nil {
|
||||
v.EarningPrice = actStoreSku.EarningPrice
|
||||
if v.StoreSubName != "" {
|
||||
if true { //v.StoreSubName != "" { // 之前这里为什么要加判断?
|
||||
v.StoreSubID = actStoreSku.ActID
|
||||
}
|
||||
}
|
||||
@@ -361,24 +361,24 @@ func (c *OrderManager) updateOrderOtherInfo(order *model.GoodsOrder, db *dao.Dao
|
||||
order.JxStoreID = storeDetail.Store.ID
|
||||
payPercentage = storeDetail.PayPercentage
|
||||
}
|
||||
if err = c.updateOrderSkuOtherInfo(order, db); err == nil {
|
||||
if err = c.updateOrderSkuOtherInfo(order, db, payPercentage); err == nil {
|
||||
jxutils.RefreshOrderSkuRelated(order)
|
||||
caculateOrderEarningPrice(order, payPercentage)
|
||||
// caculateOrderEarningPrice(order, payPercentage)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// 计算结算给门店的金额
|
||||
func caculateOrderEarningPrice(order *model.GoodsOrder, storePayPercentage int) {
|
||||
order.EarningPrice = 0
|
||||
for _, v := range order.Skus {
|
||||
skuEarningPrice := v.EarningPrice
|
||||
if skuEarningPrice == 0 {
|
||||
skuEarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage)
|
||||
}
|
||||
order.EarningPrice += skuEarningPrice * int64(v.Count)
|
||||
}
|
||||
}
|
||||
// func caculateOrderEarningPrice(order *model.GoodsOrder, storePayPercentage int) {
|
||||
// order.EarningPrice = 0
|
||||
// for _, v := range order.Skus {
|
||||
// skuEarningPrice := v.EarningPrice
|
||||
// if skuEarningPrice == 0 {
|
||||
// skuEarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage)
|
||||
// }
|
||||
// order.EarningPrice += skuEarningPrice * int64(v.Count)
|
||||
// }
|
||||
// }
|
||||
|
||||
func (c *OrderManager) addOrderStatus(orderStatus *model.OrderStatus, db *dao.DaoDB) (isDuplicated bool, order *model.GoodsOrder, err error) {
|
||||
globals.SugarLogger.Debugf("addOrderStatus refOrderID:%s, orderID:%s", orderStatus.RefVendorOrderID, orderStatus.VendorOrderID)
|
||||
|
||||
@@ -382,8 +382,7 @@ func (c *OrderManager) getOrders(ctx *jxcontext.Context, isIncludeSku bool, from
|
||||
return nil, 0, err
|
||||
}
|
||||
if len(cities) > 0 {
|
||||
sql += " JOIN store st ON t1.store_id = st.id"
|
||||
sqlWhere += " AND st.city_code IN (" + dao.GenQuestionMarks(len(cities)) + ")"
|
||||
sqlWhere += " AND t5.city_code IN (" + dao.GenQuestionMarks(len(cities)) + ") AND t5.id IS NOT NULL"
|
||||
sqlParams = append(sqlParams, cities)
|
||||
}
|
||||
}
|
||||
@@ -907,7 +906,7 @@ func (c *OrderManager) getAfsOrderSkuInfo4ExportOrders(ctx *jxcontext.Context, f
|
||||
SELECT t2.*
|
||||
FROM afs_order t1
|
||||
JOIN order_sku_financial t2 ON t2.vendor_order_id = t1.vendor_order_id AND t2.vendor_id = t1.vendor_id AND t2.is_afs_order = 1
|
||||
WHERE t1.afs_created_at >= ? AND t1.afs_created_at <= ? AND t1.status = ?
|
||||
WHERE t1.afs_finished_at >= ? AND t1.afs_finished_at <= ? AND t1.status = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
fromDate,
|
||||
|
||||
@@ -1707,3 +1707,35 @@ func SaveAndSendAlarmVendorSnapshot(ctx *jxcontext.Context, vendorIDs, storeIDs
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func SyncStoresQualify(ctx *jxcontext.Context, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
if len(storeIDs) > 0 {
|
||||
db := dao.GetDB()
|
||||
task := tasksch.NewParallelTask("上传门店资质", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorID := model.VendorIDJD
|
||||
if handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IStoreSyncQualifyHandler); handler != nil {
|
||||
storeID := batchItemList[0].(int)
|
||||
storeDetail, err2 := dao.GetStoreDetail(db, storeID, vendorID)
|
||||
if err = err2; err == nil {
|
||||
if err = handler.SyncQualify(ctx, storeDetail); err == nil {
|
||||
retVal = []int{1}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf("平台%s不支持此操作", model.VendorChineseNames[vendorID])
|
||||
}
|
||||
return retVal, err
|
||||
}, storeIDs)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
if isAsync {
|
||||
hint = task.GetID()
|
||||
} else {
|
||||
resultList, err2 := task.GetResult(0)
|
||||
if err = err2; err == nil {
|
||||
hint = utils.Int2Str(len(resultList))
|
||||
}
|
||||
}
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
@@ -163,6 +163,8 @@ type tGetStoresSkusInfo struct {
|
||||
const (
|
||||
maxStoreNameBind = 3000 // 最大门店SkuName bind个数
|
||||
maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数
|
||||
|
||||
AutoSaleAtStr = "20:25:00"
|
||||
)
|
||||
|
||||
func GetStoreSkus(ctx *jxcontext.Context, storeID int, skuIDs []int, isFocus bool, keyword string, isBySku bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) {
|
||||
@@ -1307,6 +1309,15 @@ func getSkuSaleStatus(inSkuBind *StoreSkuBindSkuInfo, skuBindInfo *StoreSkuBindI
|
||||
return model.StoreSkuBindStatusNA
|
||||
}
|
||||
|
||||
func formatAutoSaleTime(autoSaleTime time.Time) (outAutoSaleTime time.Time) {
|
||||
if utils.IsTimeZero(autoSaleTime) {
|
||||
outAutoSaleTime = utils.DefaultTimeValue
|
||||
} else {
|
||||
outAutoSaleTime = jxutils.GetNextTimeFromList(time.Now(), []string{AutoSaleAtStr})
|
||||
}
|
||||
return outAutoSaleTime
|
||||
}
|
||||
|
||||
// todo 应该用updateStoresSkusWithoutSync实现
|
||||
func updateStoreSkusSaleWithoutSync(ctx *jxcontext.Context, storeID int, skuBindSkuInfos []*StoreSkuBindSkuInfo, autoSaleTime time.Time, userName string) (needSyncSkus []int, err error) {
|
||||
var num int64
|
||||
@@ -1331,6 +1342,7 @@ func updateStoreSkusSaleWithoutSync(ctx *jxcontext.Context, storeID int, skuBind
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
autoSaleTime = formatAutoSaleTime(autoSaleTime)
|
||||
for _, skuBind := range storeSkuList {
|
||||
if v := skuBindSkuInfosMap[skuBind.SkuID]; v != nil && v.IsSale != 0 {
|
||||
if v.IsSale == 1 {
|
||||
|
||||
@@ -52,7 +52,7 @@ var (
|
||||
}
|
||||
|
||||
autoSaleStoreSkuTimeList = []string{
|
||||
"20:20:00",
|
||||
cms.AutoSaleAtStr,
|
||||
}
|
||||
|
||||
importantTaskMap = &sync.Map{}
|
||||
|
||||
@@ -479,6 +479,7 @@ func RefreshOrderSkuRelated(order *model.GoodsOrder) *model.GoodsOrder {
|
||||
order.GoodsCount = 0
|
||||
order.SalePrice = 0
|
||||
order.VendorPrice = 0
|
||||
order.ShopPrice = 0
|
||||
order.Weight = 0
|
||||
for _, sku := range order.Skus {
|
||||
if sku.SkuID > math.MaxInt32 {
|
||||
@@ -489,6 +490,7 @@ func RefreshOrderSkuRelated(order *model.GoodsOrder) *model.GoodsOrder {
|
||||
order.GoodsCount += sku.Count
|
||||
order.SalePrice += sku.SalePrice * int64(sku.Count)
|
||||
order.VendorPrice += sku.VendorPrice * int64(sku.Count)
|
||||
order.ShopPrice += sku.ShopPrice * int64(sku.Count)
|
||||
order.Weight += sku.Weight * sku.Count
|
||||
}
|
||||
return order
|
||||
|
||||
@@ -3,9 +3,9 @@ package model
|
||||
type AppKeyConfig struct {
|
||||
ModelIDCULD
|
||||
VendorID int
|
||||
AppKey string // 同一平台下不同的Key
|
||||
AppCode string // 同一平台下不同的商户代码
|
||||
|
||||
Name string
|
||||
AppName string
|
||||
AppType int
|
||||
Value1 string
|
||||
Value2 string
|
||||
|
||||
@@ -8,6 +8,10 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
const (
|
||||
AfsOrderStatus = -1
|
||||
)
|
||||
|
||||
type StoresOrderSaleInfo struct {
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
@@ -122,6 +126,7 @@ func GetAfsOrders(db *DaoDB, vendorID int, vendorOrderID, afsOrderID string) (af
|
||||
return afsOrderList, err
|
||||
}
|
||||
|
||||
// 时间范围是订单完成时间
|
||||
func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, toTime time.Time, statusList []int) (saleInfoList []*StoresOrderSaleInfo, err error) {
|
||||
if utils.IsTimeZero(fromTime) {
|
||||
return nil, fmt.Errorf("查询订单信息必须指定起始时间")
|
||||
@@ -135,13 +140,13 @@ func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, to
|
||||
|
||||
// 用int64类型去取float型的数据库返回值,会取不到
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT IF(t1.jx_store_id > 0, t1.jx_store_id, t1.store_id) store_id, t1.vendor_id, IF(t1.status < ?, 0, t1.status) status,
|
||||
COUNT(*) count, SUM(t1.shop_price) shop_price, SUM(t1.vendor_price) vendor_price, SUM(t1.sale_price) sale_price, SUM(t1.actual_pay_price) actual_pay_price,
|
||||
CAST(SUM(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, %d) / 100)) AS SIGNED) earning_price
|
||||
FROM goods_order t1
|
||||
LEFT JOIN store t5 ON t5.id = IF(t1.jx_store_id <> 0, t1.jx_store_id, t1.store_id)
|
||||
WHERE t1.order_finished_at >= ? AND t1.order_finished_at <= ?
|
||||
`, model.DefaultEarningPricePercentage)
|
||||
SELECT IF(t1.jx_store_id > 0, t1.jx_store_id, t1.store_id) store_id, t1.vendor_id, IF(t1.status < ?, 0, t1.status) status,
|
||||
COUNT(*) count, SUM(t1.shop_price) shop_price, SUM(t1.vendor_price) vendor_price, SUM(t1.sale_price) sale_price, SUM(t1.actual_pay_price) actual_pay_price,
|
||||
CAST(SUM(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, %d) / 100)) AS SIGNED) earning_price
|
||||
FROM goods_order t1
|
||||
LEFT JOIN store t5 ON t5.id = IF(t1.jx_store_id <> 0, t1.jx_store_id, t1.store_id)
|
||||
WHERE t1.order_finished_at >= ? AND t1.order_finished_at <= ?
|
||||
`, model.DefaultEarningPricePercentage)
|
||||
sqlParams := []interface{}{
|
||||
model.OrderStatusEndBegin,
|
||||
fromTime,
|
||||
@@ -156,8 +161,29 @@ func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, to
|
||||
sqlParams = append(sqlParams, statusList)
|
||||
}
|
||||
sql += `
|
||||
GROUP BY 1,2,3
|
||||
ORDER BY 1,2,3`
|
||||
GROUP BY 1,2,3`
|
||||
sql += fmt.Sprintf(`
|
||||
UNION
|
||||
SELECT IF(t0.jx_store_id > 0, t0.jx_store_id, t0.store_id) store_id, t0.vendor_id, -1 status,
|
||||
COUNT(*) count, SUM(t1.shop_price) shop_price, SUM(t1.vendor_price) vendor_price, SUM(t1.sale_price) sale_price, 0 actual_pay_price,
|
||||
CAST(SUM(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, %d) / 100)) AS SIGNED) earning_price
|
||||
FROM afs_order t0
|
||||
JOIN order_sku_financial t2 ON t2.afs_order_id = t0.afs_order_id AND t2.vendor_id = t0.vendor_id AND t2.is_afs_order = 1
|
||||
JOIN order_sku t1 ON t1.vendor_order_id = t2.vendor_order_id AND t1.vendor_id = t2.vendor_id AND t1.sku_id = t2.sku_id
|
||||
LEFT JOIN store t5 ON t5.id = IF(t0.jx_store_id <> 0, t0.jx_store_id, t0.store_id)
|
||||
WHERE t0.afs_finished_at >= ? AND t0.afs_finished_at <= ?`, model.DefaultEarningPricePercentage)
|
||||
sqlParams = append(sqlParams, []interface{}{
|
||||
fromTime,
|
||||
toTime,
|
||||
})
|
||||
if len(storeIDList) > 0 {
|
||||
sql += " AND IF(t0.jx_store_id > 0, t0.jx_store_id, t0.store_id) IN (" + GenQuestionMarks(len(storeIDList)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDList)
|
||||
}
|
||||
sql += `
|
||||
GROUP BY 1,2,3`
|
||||
|
||||
sql += " ORDER BY 1,2,3"
|
||||
err = GetRows(db, &saleInfoList, sql, sqlParams...)
|
||||
return saleInfoList, err
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ type OrderSku struct {
|
||||
ID int64 `orm:"column(id)" json:"-"`
|
||||
VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // 当前这个字段被当成活动ID用
|
||||
StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // 当前这个字段被当成结算活动ID用
|
||||
StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType
|
||||
Count int `json:"count"`
|
||||
VendorSkuID string `orm:"column(vendor_sku_id);size(48)" json:"vendorSkuID"`
|
||||
@@ -94,7 +94,7 @@ type OrderSku struct {
|
||||
ShopPrice int64 `json:"shopPrice"` // 京西价
|
||||
VendorPrice int64 `json:"vendorPrice"` // 平台价
|
||||
SalePrice int64 `json:"salePrice"` // 售卖价
|
||||
EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱
|
||||
EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱,如果结算活动ID为0,是按结算比例算的,否则就是结算表中的值
|
||||
Weight int `json:"weight"` // 单位为克
|
||||
SkuType int `json:"skuType"` // 当前如果为gift就为1,否则缺省为0
|
||||
PromotionType int `json:"promotionType"` // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换
|
||||
|
||||
@@ -155,6 +155,13 @@ type OrderSkuFinancial struct {
|
||||
StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType
|
||||
}
|
||||
|
||||
// todo
|
||||
// func (o *OrderSkuFinancial) TableUnique() [][]string {
|
||||
// return [][]string{
|
||||
// []string{"AfsOrderID", "VendorSkuID", "VendorID", "IsAfsOrder"},
|
||||
// }
|
||||
// }
|
||||
|
||||
func (o *OrderSkuFinancial) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"VendorOrderID", "VendorSkuID"},
|
||||
|
||||
@@ -53,7 +53,7 @@ func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
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), ctx,
|
||||
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)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package partner
|
||||
|
||||
import "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
type IStoreHandler interface {
|
||||
GetAllStoresVendorID(ctx *jxcontext.Context) (vendorStoreIDs []string, err error)
|
||||
@@ -9,3 +12,8 @@ type IStoreHandler interface {
|
||||
// opTime格式为整数1130代表11:30
|
||||
UpdateStoreOpTime(ctx *jxcontext.Context, storeID int, vendorStoreID string, opTimeList []int16) (err error)
|
||||
}
|
||||
|
||||
// 同步资质信息至平台
|
||||
type IStoreSyncQualifyHandler interface {
|
||||
SyncQualify(ctx *jxcontext.Context, storeDetail *dao.StoreDetail) (err error)
|
||||
}
|
||||
|
||||
@@ -12,8 +12,9 @@ import (
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) GetStoreIDListByCoordinates(ctx *jxcontext.Context, coord *ditu.Coordinate) (storeIDList []string, err error) {
|
||||
shopListInfo, err := api.JdAPI.GetStoreList(fmt.Sprintf("%.6f", coord.Lng), fmt.Sprintf("%.6f", coord.Lat))
|
||||
shopListInfo, err := api.JdPageAPI.GetStoreList(fmt.Sprintf("%.6f", coord.Lng), fmt.Sprintf("%.6f", coord.Lat))
|
||||
if err != nil {
|
||||
// time.Sleep(5 * time.Second)
|
||||
return nil, err
|
||||
}
|
||||
if shopListInfo != nil {
|
||||
@@ -27,7 +28,7 @@ func (c *PurchaseHandler) GetStoreIDListByCoordinates(ctx *jxcontext.Context, co
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetStorePageInfo(ctx *jxcontext.Context, cityInfo, storeID string) (storePageInfo *model.PageShop, err error) {
|
||||
shopInfo, err2 := api.JdAPI.GetStoreInfo2(storeID)
|
||||
shopInfo, err2 := api.JdPageAPI.GetStoreInfo2(storeID)
|
||||
if err = err2; err == nil && shopInfo != nil {
|
||||
var lng, lat float64
|
||||
districtCode := 0
|
||||
|
||||
@@ -357,3 +357,95 @@ func (c *PurchaseHandler) GetAllStoresVendorID(ctx *jxcontext.Context) (vendorSt
|
||||
vendorStoreIDs, err = api.JdAPI.GetStationsByVenderId()
|
||||
return vendorStoreIDs, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) storeUploadImgByURL(inImgURL string) (imgURL string, err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
imgURL, err = api.JdPageAPI.StoreUploadImgByURL(inImgURL)
|
||||
} else {
|
||||
imgURL = utils.GetUUID()
|
||||
}
|
||||
return imgURL, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.StoreDetail) (err error) {
|
||||
if storeDetail.LicenceCode == "" || storeDetail.Licence == "" {
|
||||
return fmt.Errorf("营业执照信息不全")
|
||||
}
|
||||
if storeDetail.IDCode == "" || storeDetail.IDCardFront == "" || storeDetail.IDCardBack == "" || storeDetail.IDValid == "" {
|
||||
return fmt.Errorf("个人信息不全")
|
||||
}
|
||||
var qualifyList []*jdapi.QualifyItem
|
||||
licenceDetail, err := api.JdPageAPI.GetCorporationInfo(storeDetail.VendorStoreID, storeDetail.LicenceCode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
licenceURL, err := c.storeUploadImgByURL(storeDetail.Licence)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qualifyList = append(qualifyList, &jdapi.QualifyItem{
|
||||
QualifyType: jdapi.QualifyTypeCompany,
|
||||
QualifyURL: licenceURL,
|
||||
QualifyExpireStart: utils.Time2Str(utils.Str2Time(licenceDetail.StartDate)),
|
||||
QualifyExpireForever: 0,
|
||||
QualifyName: licenceDetail.OperName,
|
||||
LicenceType: "-1",
|
||||
QualifyNumber: storeDetail.LicenceCode,
|
||||
QualifyAddress: licenceDetail.Address,
|
||||
LicenceName: licenceDetail.Name,
|
||||
EconKind: licenceDetail.EconKind,
|
||||
Scope: licenceDetail.Scope,
|
||||
})
|
||||
|
||||
idFrondURL, err := c.storeUploadImgByURL(storeDetail.IDCardFront)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 个体经营,个体工商户
|
||||
if storeDetail.LicenceType == 0 { // 个人
|
||||
personQualify := &jdapi.QualifyItem{
|
||||
QualifyType: jdapi.QualifyTypePerson,
|
||||
QualifyURL: idFrondURL,
|
||||
QualifyExpireStart: utils.Time2Str(utils.Str2Time(storeDetail.IDValid)),
|
||||
QualifyExpireForever: 0,
|
||||
|
||||
QualifyNumber: storeDetail.IDCode,
|
||||
QualifyOwner: storeDetail.LicenceOwnerName,
|
||||
}
|
||||
if storeDetail.IDExpire != "" {
|
||||
personQualify.QualifyExpireForever = 1
|
||||
personQualify.QualifyExpireEnd = utils.Time2Str(utils.Str2Time(storeDetail.IDExpire))
|
||||
}
|
||||
qualifyList = append(qualifyList, personQualify)
|
||||
} else {
|
||||
addInfo := &jdapi.QualifyItem{
|
||||
QualifyType: jdapi.QualifyTypeAddInfo,
|
||||
QualifyURL: idFrondURL,
|
||||
QualifyExpireStart: utils.Time2Str(utils.Str2Time(storeDetail.IDValid)),
|
||||
QualifyExpireForever: 0,
|
||||
}
|
||||
if storeDetail.IDExpire != "" {
|
||||
addInfo.QualifyExpireForever = 1
|
||||
addInfo.QualifyExpireEnd = utils.Time2Str(utils.Str2Time(storeDetail.IDExpire))
|
||||
}
|
||||
qualifyList = append(qualifyList, addInfo)
|
||||
}
|
||||
if storeDetail.IDExpire == "" {
|
||||
idBackURL, err := c.storeUploadImgByURL(storeDetail.IDCardBack)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qualifyList = append(qualifyList, &jdapi.QualifyItem{
|
||||
QualifyType: jdapi.QualifyTypeAddInfo,
|
||||
QualifyURL: idBackURL,
|
||||
QualifyExpireStart: utils.Time2Str(utils.Str2Time(storeDetail.IDValid)),
|
||||
QualifyExpireForever: 0,
|
||||
})
|
||||
}
|
||||
globals.SugarLogger.Debug(utils.Format4Output(qualifyList, false))
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = api.JdPageAPI.SaveQualify(storeDetail.VendorStoreID, jdapi.SaveQualifyActionTypeCommit, qualifyList)
|
||||
// err = api.JdPageAPI.SaveQualify(storeDetail.VendorStoreID, jdapi.SaveQualifyActionTypeSave, qualifyList)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
@@ -81,3 +82,14 @@ func TestUpdateStore2(t *testing.T) {
|
||||
// t.Fatal("result doesn't match")
|
||||
// }
|
||||
// }
|
||||
|
||||
func TestSyncQualify(t *testing.T) {
|
||||
storeDetail, err := dao.GetStoreDetail(dao.GetDB(), 102610, model.VendorIDJD)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
err = curPurchaseHandler.SyncQualify(jxcontext.AdminCtx, storeDetail)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ httpport = 8088
|
||||
jdToken = "df97f334-f7d8-4b36-9664-5784d8ae0baf"
|
||||
jdAppKey = "06692746f7224695ad4788ce340bc854"
|
||||
jdSecret = "d6b42a35a7414a5490d811654d745c84"
|
||||
|
||||
jdStorePageCookie = "5EOCZRXVCRXBTYD5EPV6FOXRCQWFFQO75FRMJ3BAKZ5JXY6XTJECMWXK5OZIPLZTUWZKZKXHXA6I7G3WMIKSWOHZIHRLNE5FZY3NBD6G5IMBOYHMJSJR3RF4TMZB2JEW2DF755YPFUSA6BMWI3KNLT3I4EAP2Z4JA6ZWAA34MNQX5P6LOI4EGG76QJU3G3VW7QFE6BAVAONMKBEHKNXNZGX3RQF7PHXDXSPJSY5XQEGM7IV2L7LKIG3M2D6QVSPEGQW4NV7SZ4TX32D2XQA7PIX46M"
|
||||
disableElm = true
|
||||
|
||||
ebaiSource = "62289"
|
||||
|
||||
@@ -400,3 +400,23 @@ func (c *StoreController) BindPrinter() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 同步门店资质信息至平台(当前只支持京东)
|
||||
// @Description 同步门店资质信息至平台(当前只支持京东)
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeIDs formData string true "京西门店ID列表,必须非空值"
|
||||
// @Param isAsync formData bool true "是否异步操作"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /SyncStoresQualify [post]
|
||||
func (c *StoreController) SyncStoresQualify() {
|
||||
c.callSyncStoresQualify(func(params *tStoreSyncStoresQualifyParams) (retVal interface{}, errCode string, err error) {
|
||||
var storeIDs []int
|
||||
err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs)
|
||||
if err == nil {
|
||||
retVal, err = cms.SyncStoresQualify(params.Ctx, storeIDs, params.IsAsync, params.IsContinueWhenError)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
|
||||
var (
|
||||
JdAPI *jdapi.API
|
||||
JdPageAPI *jdapi.API
|
||||
ElmAPI *elmapi.API
|
||||
EbaiAPI *ebaiapi.API
|
||||
MtpsAPI *mtpsapi.API
|
||||
@@ -67,6 +68,10 @@ func Init() {
|
||||
cookieValue := beego.AppConfig.DefaultString("jdStorePageCookie", "")
|
||||
JdAPI.SetCookie("shop.o2o.jd.com1", cookieValue)
|
||||
JdAPI.SetCookie("lsp-store1.jddj.com", cookieValue)
|
||||
|
||||
conf := platformapi.NewDefAPIConfig()
|
||||
conf.MaxSleepSecondWhenExceedLimit = 60 * 30 // 最大重试间隙30分钟
|
||||
JdPageAPI = jdapi.NewPageOnly(cookieValue, conf)
|
||||
} else {
|
||||
JdAPI = nil
|
||||
}
|
||||
|
||||
@@ -1258,6 +1258,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "SyncStoresQualify",
|
||||
Router: `/SyncStoresQualify`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpGetJxBadComments",
|
||||
|
||||
Reference in New Issue
Block a user