137 lines
4.7 KiB
Go
137 lines
4.7 KiB
Go
package mt
|
|
|
|
import (
|
|
"git.rosy.net.cn/baseapi/platformapi/mtunionapi"
|
|
"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/model"
|
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
orderStatusMap = map[int]int{
|
|
mtunionapi.MtUnionOrderStatusPay: model.UnionOrderStatusPay,
|
|
mtunionapi.MtUnionOrderStatusFinished: model.UnionOrderStatusFinish,
|
|
mtunionapi.MtUnionOrderStatusCanceled: model.UnionOrderStatusFail,
|
|
}
|
|
)
|
|
|
|
func (s *UnionHandler) ShareUnionLink(ctx *jxcontext.Context, linkType, unionActID int, sID, userID string, resourceType int, goodsID string) (link string, err error) {
|
|
if linkType == partner.LinkTypeWeiXinMini {
|
|
if qrCode, err := api.MtUnionAPI.MiniCode(unionActID, sID); err == nil {
|
|
if qrCode != "" {
|
|
return qrCode, err
|
|
}
|
|
}
|
|
return
|
|
} else {
|
|
return api.MtUnionAPI.GenerateLink(unionActID, linkType, sID)
|
|
}
|
|
return link, err
|
|
}
|
|
|
|
func (s *UnionHandler) GetUnionActList(ctx *jxcontext.Context, actType int) (actList []*partner.ActivityList, err error) {
|
|
if result, err2 := getAPI().ActivityList(actType, 20, 0); err2 == nil {
|
|
for _, v := range result {
|
|
act := &partner.ActivityList{
|
|
ActID: v.ID,
|
|
ActName: v.ActName,
|
|
ActDes: v.ActDes,
|
|
Ratio: v.Ratio,
|
|
ActSrc: v.ActSrc,
|
|
Img: v.URL,
|
|
ActRule: v.ActRule,
|
|
}
|
|
if v.DateBound != "" {
|
|
act.DateBegin = utils.Str2Time(v.DateBound[:strings.LastIndex(v.DateBound, "至")-1])
|
|
act.DateEnd = utils.Str2Time(v.DateBound[strings.LastIndex(v.DateBound, "至")+4:])
|
|
}
|
|
actList = append(actList, act)
|
|
}
|
|
} else {
|
|
err = err2
|
|
}
|
|
return actList, err
|
|
}
|
|
|
|
func (s *UnionHandler) CreateUnionPosition(ctx *jxcontext.Context, userID string) (sID string, err error) {
|
|
return sID, err
|
|
}
|
|
|
|
func (s *UnionHandler) GetUnionMatterList(ctx *jxcontext.Context, vendorCatID, keyword string, page, pageSize, sortType int, listID string) (list *partner.MatterList, err error) {
|
|
return nil, err
|
|
}
|
|
|
|
func (s *UnionHandler) GetUnionMatterDetail(ctx *jxcontext.Context, goodsID string) (result *partner.GoodsDetail, err error) {
|
|
return nil, err
|
|
}
|
|
|
|
func (s *UnionHandler) GetUnionMatterListRcmmd(ctx *jxcontext.Context, goodsID string, rcmmdType, offset, pageSize int) (result *partner.MatterList, err error) {
|
|
return nil, err
|
|
}
|
|
|
|
func OnCallback(call *mtunionapi.CallBackResult) (err error) {
|
|
var (
|
|
db = dao.GetDB()
|
|
)
|
|
if order, err2 := api.MtUnionAPI.Rtnotify(call.Orderid, call.Type); order != nil && err2 == nil {
|
|
unionOrders, err3 := dao.GetUnionOrdersByIDs(db, []string{order.Order.Orderid}, model.VendorIDPDD)
|
|
if err2 != nil {
|
|
return err2
|
|
}
|
|
if err3 != nil {
|
|
return err3
|
|
}
|
|
orderStatus := &model.UnionOrderStatus{
|
|
VendorOrderID: order.Order.Orderid,
|
|
VendorID: model.VendorIDMTWM,
|
|
Status: mtunionOrderStatus2Jx(order.Order.Status),
|
|
VendorStatus: utils.Int2Str(order.Order.Status),
|
|
OrderStatusAt: time.Unix(utils.Str2Int64(order.Order.Modtime), 0),
|
|
}
|
|
if len(order.Refund) > 0 {
|
|
orderStatus.Comment = "售后完成"
|
|
}
|
|
//change
|
|
jxutils.CallMsgHandler(func() {
|
|
if len(unionOrders) > 0 {
|
|
if unionOrders[0].Status != orderStatus.Status {
|
|
cms.ChangeUnionOrder(unionOrders[0], orderStatus)
|
|
}
|
|
} else {
|
|
//new
|
|
unionOrder := &model.UnionOrder{
|
|
VendorOrderID: order.Order.Orderid,
|
|
VendorID: model.VendorIDMTWM,
|
|
Status: mtunionOrderStatus2Jx(order.Order.Status),
|
|
PID: order.Order.Sid,
|
|
PayPrice: int(jxutils.StandardPrice2Int(utils.Str2Float64(order.Order.Direct))),
|
|
//PromotionAmount: int(jxutils.StandardPrice2Int(utils.Str2Float64(order.Coupon[0].Profit))),
|
|
GoodsName: order.Order.Smstitle,
|
|
GoodsID: order.Order.Dealid,
|
|
OrderCreateAt: time.Unix(utils.Str2Int64(order.Order.Paytime), 0),
|
|
OrderPayAt: time.Unix(utils.Str2Int64(order.Order.Paytime), 0),
|
|
OrderReceiveAt: time.Unix(utils.Str2Int64(order.Order.Modtime), 0),
|
|
//OrderSettleAt: time.Unix(utils.Str2Int64(order.Coupon[0].Usetime), 0),
|
|
}
|
|
if len(order.Coupon) > 0 {
|
|
unionOrder.PromotionAmount = int(jxutils.StandardPrice2Int(utils.Str2Float64(order.Coupon[0].Profit)))
|
|
unionOrder.OrderSettleAt = time.Unix(utils.Str2Int64(order.Coupon[0].Usetime), 0)
|
|
}
|
|
cms.NewUnionOrder(unionOrder, orderStatus)
|
|
}
|
|
}, jxutils.ComposeUniversalOrderID(order.Order.Orderid, model.VendorIDMTWM))
|
|
}
|
|
return err
|
|
}
|
|
|
|
func mtunionOrderStatus2Jx(status int) (jxstatus int) {
|
|
return orderStatusMap[status]
|
|
}
|