281 lines
9.5 KiB
Go
281 lines
9.5 KiB
Go
package pdd
|
|
|
|
import (
|
|
"fmt"
|
|
"git.rosy.net.cn/baseapi/platformapi/pddapi"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
|
"git.rosy.net.cn/jx-callback/business/jxstore/partner"
|
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
|
"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/globals"
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
sortTypeMap = map[int]int{
|
|
0: 0, //综合排序
|
|
partner.JxSortTypeYJ: 1, //按佣金比率升序;
|
|
-partner.JxSortTypeYJ: 2, //按佣金比例降序;
|
|
partner.JxSortTypeJG: 3, //按价格升序;
|
|
-partner.JxSortTypeJG: 4, //按价格降序;
|
|
partner.JxSortTypeXL: 5, //按销量升序;
|
|
-partner.JxSortTypeXL: 6, //按销量降序;
|
|
}
|
|
|
|
orderStatusMap = map[int]int{
|
|
pddapi.OrderStatusPay: model.UnionOrderStatusPay,
|
|
pddapi.OrderStatus1: model.UnionOrderStatusPay,
|
|
pddapi.OrderStatusTakeOver: model.UnionOrderStatusTakeOver,
|
|
pddapi.OrderStatusAuditOver: model.UnionOrderStatusAuditOver,
|
|
pddapi.OrderStatusAuditFail: model.UnionOrderStatusFail,
|
|
pddapi.OrderStatusEaring: model.UnionOrderStatusFinish,
|
|
}
|
|
)
|
|
|
|
func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, sID, userID string, resourceType int, goodsID string) (link string, err error) {
|
|
//传了goodsID表示是商品分享
|
|
if goodsID != "" {
|
|
authBindFlag, err := api.PddAPI.MemberAuthorityQuery(sID)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if result, err := api.PddAPI.GoodsPromotionURLGen(sID, goodsID, !authBindFlag); err == nil {
|
|
switch linkType {
|
|
case partner.LinTypeH5:
|
|
return result.MobileURL, err
|
|
case partner.LinTypeWx:
|
|
return result.WeAppInfo.PagePath, err
|
|
default:
|
|
return link, fmt.Errorf("暂不支持此链接类型!")
|
|
}
|
|
}
|
|
} else {
|
|
if result, err := api.PddAPI.ResourceURLGen(sID, resourceType); err == nil {
|
|
switch linkType {
|
|
case partner.LinkTypeWeiXinMini:
|
|
return "", err
|
|
case partner.LinTypeH5:
|
|
return result.SingleURLList.URL, err
|
|
case partner.LinTypeWx:
|
|
return result.WeAppInfo.PagePath, err
|
|
default:
|
|
return link, fmt.Errorf("暂不支持此链接类型!")
|
|
}
|
|
}
|
|
}
|
|
|
|
return link, err
|
|
}
|
|
|
|
func (s *UnionHandler) GetUnionActList(ctx *jxcontext.Context, actType int) (actList []*partner.ActivityList, err error) {
|
|
if result, err2 := getAPI().ActivityOperationList(); err2 == nil {
|
|
for _, v := range result {
|
|
act := &partner.ActivityList{
|
|
ActID: v.ID,
|
|
ActName: v.Name,
|
|
ActDes: v.Description,
|
|
Ratio: "未知",
|
|
ActSrc: v.Fileurl,
|
|
Img: v.Bannerimage,
|
|
DateBegin: utils.Str2Time(v.Starttime),
|
|
DateEnd: utils.Str2Time(v.Endtime),
|
|
}
|
|
actList = append(actList, act)
|
|
}
|
|
}
|
|
return actList, err
|
|
}
|
|
|
|
func (s *UnionHandler) CreateUnionPosition(ctx *jxcontext.Context, userID string) (sID string, err error) {
|
|
if sID, err = api.PddAPI.GoodsOPidGenerate(userID); err != nil {
|
|
return "", err
|
|
}
|
|
return sID, err
|
|
}
|
|
|
|
func jxSortType2PddSortType(jxSortType int) (sortType int) {
|
|
return sortTypeMap[jxSortType]
|
|
}
|
|
|
|
func (s *UnionHandler) GetUnionMatterList(ctx *jxcontext.Context, vendorCatID, keyword string, page, pageSize, sortType int, listID string) (list *partner.MatterList, err error) {
|
|
var (
|
|
goodsList []*partner.GoodsList
|
|
)
|
|
list = &partner.MatterList{}
|
|
params := &pddapi.GoodsSearchParam{
|
|
CatID: utils.Str2Int(vendorCatID),
|
|
Keyword: keyword,
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
SortType: jxSortType2PddSortType(sortType),
|
|
ListID: listID,
|
|
}
|
|
//-1表示是拼多多的精选
|
|
if vendorCatID == "-1" {
|
|
params.ActivityTags = []int{pddapi.GoodsActTagBYBT, pddapi.GoodsActTagJXBK, pddapi.GoodsActTagMS, pddapi.GoodsActTagPPGY, pddapi.GoodsActTagPPHB, pddapi.GoodsActTagQWBT, pddapi.GoodsActTagTZTJ}
|
|
}
|
|
if goods, err2 := api.PddAPI.GoodsSearch(params); err2 != nil {
|
|
return nil, err2
|
|
} else {
|
|
list.ListID = goods.ListID
|
|
list.TotalCount = goods.TotalCount
|
|
list.VendorID = model.VendorIDPDD
|
|
for _, v := range goods.GoodsList {
|
|
good := &partner.GoodsList{
|
|
GoodsID: v.GoodsSign,
|
|
GoodsName: v.GoodsName,
|
|
Img: v.GoodsThumbnailURL,
|
|
CouponDiscount: v.CouponDiscount,
|
|
CouponRemainQuantity: v.CouponRemainQuantity,
|
|
MinNormalPrice: v.MinNormalPrice,
|
|
SalesCount: v.SalesTip,
|
|
PromotionRate: v.PromotionRate,
|
|
}
|
|
goodsList = append(goodsList, good)
|
|
}
|
|
list.GoodsList = goodsList
|
|
}
|
|
return list, err
|
|
}
|
|
|
|
func (s *UnionHandler) GetUnionMatterDetail(ctx *jxcontext.Context, goodsID string) (result *partner.GoodsDetail, err error) {
|
|
result = &partner.GoodsDetail{}
|
|
if goods, err2 := api.PddAPI.GoodsDetail(goodsID); err2 != nil {
|
|
return nil, err2
|
|
} else {
|
|
result.GoodsID = goods.GoodsSign
|
|
result.GoodsName = goods.GoodsName
|
|
result.Img = goods.GoodsThumbnailURL
|
|
result.CouponDiscount = goods.CouponDiscount
|
|
result.MinNormalPrice = goods.MinNormalPrice
|
|
result.CouponRemainQuantity = goods.CouponRemainQuantity
|
|
result.SalesCount = goods.SalesTip
|
|
result.Imgs = strings.Join(goods.GoodsGalleryUrls, ",")
|
|
result.MainImg = goods.GoodsImageURL
|
|
result.StoreImg = goods.MallImgURL
|
|
result.StoreName = goods.MallName
|
|
result.LgstTxt = goods.LgstTxt
|
|
result.DescTxt = goods.DescTxt
|
|
result.ServTxt = goods.ServTxt
|
|
result.PromotionRate = goods.PromotionRate
|
|
}
|
|
return result, err
|
|
}
|
|
|
|
func (s *UnionHandler) GetUnionMatterListRcmmd(ctx *jxcontext.Context, goodsID string, rcmmdType, offset, pageSize int) (list *partner.MatterList, err error) {
|
|
var (
|
|
goodsList []*partner.GoodsList
|
|
)
|
|
list = &partner.MatterList{}
|
|
if goods, err2 := api.PddAPI.GoodsRecommendGet(goodsID, rcmmdType, offset, pageSize); err2 != nil {
|
|
return nil, err2
|
|
} else {
|
|
list.ListID = goods.ListID
|
|
list.TotalCount = goods.Total
|
|
list.VendorID = model.VendorIDPDD
|
|
for _, v := range goods.List {
|
|
good := &partner.GoodsList{
|
|
GoodsID: v.GoodsSign,
|
|
GoodsName: v.GoodsName,
|
|
Img: v.GoodsThumbnailURL,
|
|
CouponDiscount: v.CouponDiscount,
|
|
CouponRemainQuantity: v.CouponRemainQuantity,
|
|
MinNormalPrice: v.MinNormalPrice,
|
|
SalesCount: v.SalesTip,
|
|
PromotionRate: v.PromotionRate,
|
|
}
|
|
goodsList = append(goodsList, good)
|
|
}
|
|
list.GoodsList = goodsList
|
|
}
|
|
return list, err
|
|
}
|
|
|
|
func GetUnionOrders() {
|
|
var (
|
|
page = 1
|
|
pageSize = 50
|
|
db = dao.GetDB()
|
|
orderIDs []string
|
|
unionOrderIDsMap map[string]*model.UnionOrder
|
|
)
|
|
orders, err := api.PddAPI.OrderListIncrementGet(time.Now().Add(-time.Minute*5).Unix(), time.Now().Unix(), page, pageSize)
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, v := range orders {
|
|
orderIDs = append(orderIDs, v.OrderSn)
|
|
}
|
|
unionOrders, err := dao.GetUnionOrdersByIDs(db, orderIDs, model.VendorIDPDD)
|
|
if err != nil {
|
|
return
|
|
}
|
|
unionOrderIDsMap = make(map[string]*model.UnionOrder)
|
|
for _, v := range unionOrders {
|
|
unionOrderIDsMap[v.VendorOrderID] = v
|
|
}
|
|
task := tasksch.NewParallelTask("GetUnionOrders1", tasksch.NewParallelConfig().SetIsContinueWhenError(true), jxcontext.AdminCtx,
|
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
|
order := batchItemList[0].(*pddapi.OrderListIncrementGetResult)
|
|
detail, err := api.PddAPI.OrderDetailGet(order.OrderSn)
|
|
if err != nil {
|
|
return
|
|
}
|
|
orderStatus := &model.UnionOrderStatus{
|
|
VendorOrderID: detail.OrderSn,
|
|
VendorID: model.VendorIDPDD,
|
|
Status: pddOrderStatus2Jx(detail.OrderStatus),
|
|
VendorStatus: utils.Int2Str(detail.OrderStatus),
|
|
OrderStatusAt: time.Unix(int64(detail.OrderModifyAt), 0),
|
|
}
|
|
if detail.ReturnStatus == 1 {
|
|
orderStatus.Comment = "售后中"
|
|
} else if detail.ReturnStatus == 2 {
|
|
orderStatus.Comment = "售后完成"
|
|
orderStatus.Status = model.UnionOrderStatusFail
|
|
}
|
|
//change
|
|
jxutils.CallMsgHandler(func() {
|
|
globals.SugarLogger.Debugf("GetUnionOrders pdd, orderstatus: %v", utils.Format4Output(orderStatus, true))
|
|
if unionOrderIDsMap[order.OrderSn] != nil {
|
|
globals.SugarLogger.Debugf("GetUnionOrders pdd, unionorders: %v", utils.Format4Output(unionOrderIDsMap[order.OrderSn], true))
|
|
if unionOrderIDsMap[order.OrderSn].Status != orderStatus.Status {
|
|
cms.ChangeUnionOrder(unionOrderIDsMap[order.OrderSn], orderStatus)
|
|
}
|
|
} else {
|
|
//new
|
|
unionOrder := &model.UnionOrder{
|
|
VendorOrderID: detail.OrderSn,
|
|
VendorID: model.VendorIDPDD,
|
|
Status: pddOrderStatus2Jx(detail.OrderStatus),
|
|
PID: detail.Pid,
|
|
PayPrice: detail.OrderAmount,
|
|
PromotionAmount: detail.PromotionAmount,
|
|
GoodsName: detail.GoodsName,
|
|
GoodsID: detail.GoodsSign,
|
|
GoodsImg: detail.GoodsThumbnailURL,
|
|
OrderCreateAt: time.Unix(int64(order.OrderCreateTime), 0),
|
|
OrderPayAt: time.Unix(int64(order.OrderPayTime), 0),
|
|
OrderReceiveAt: time.Unix(int64(order.OrderReceiveTime), 0),
|
|
OrderSettleAt: time.Unix(int64(order.OrderSettleTime), 0),
|
|
Comment: order.FailReason,
|
|
}
|
|
cms.NewUnionOrder(unionOrder, orderStatus)
|
|
}
|
|
}, jxutils.ComposeUniversalOrderID(order.OrderSn, model.VendorIDPDD))
|
|
return retVal, err
|
|
}, orders)
|
|
tasksch.HandleTask(task, nil, false).Run()
|
|
task.GetID()
|
|
}
|
|
|
|
func pddOrderStatus2Jx(status int) (jxstatus int) {
|
|
return orderStatusMap[status]
|
|
}
|