Merge remote-tracking branch 'origin/mark' into su
This commit is contained in:
@@ -198,7 +198,7 @@ func createSkuAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.
|
||||
if err = err2; err == nil {
|
||||
vendorActID = utils.Int64ToStr(infoID)
|
||||
if err = CreatePromotionRules(act.Type, infoID, "", act.LimitUser, act.LimitUser, act.LimitCount, 1, traceInfo); err == nil {
|
||||
if _, err = CreatePromotionSku(act.Type, infoID, "", storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceInfo); err == nil {
|
||||
if _, err = CreatePromotionSku(act.Type, infoID, utils.Int2Str(act.ID), storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceInfo); err == nil {
|
||||
if err = ConfirmPromotion(act.Type, infoID, "", traceInfo); err == nil {
|
||||
for _, v := range actStoreSku {
|
||||
v.VendorActID = vendorActID
|
||||
|
||||
@@ -8,13 +8,13 @@ import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
"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"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/delivery"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -112,6 +112,7 @@ func CreateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64,
|
||||
outJxOrder.OrderID = GenOrderNo(ctx)
|
||||
order, err2 := jxOrder2GoodsOrder(ctx, outJxOrder, deliveryAddress)
|
||||
if err = err2; err == nil {
|
||||
order.Status = model.OrderStatusCreated
|
||||
partner.CurOrderManager.OnOrderNew(order, model.Order2Status(order))
|
||||
}
|
||||
}
|
||||
@@ -123,9 +124,10 @@ func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType
|
||||
if err == nil {
|
||||
switch payType {
|
||||
case model.PayTypeWX:
|
||||
orderPay, err = pay4OrderByWX(ctx, order, vendorPayType)
|
||||
dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName())
|
||||
err = dao.CreateEntity(dao.GetDB(), orderPay)
|
||||
if orderPay, err = pay4OrderByWX(ctx, order, vendorPayType); err == nil {
|
||||
dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName())
|
||||
err = dao.CreateEntity(dao.GetDB(), orderPay)
|
||||
}
|
||||
default:
|
||||
err = fmt.Errorf("支付方式:%d当前不支持", payType)
|
||||
}
|
||||
@@ -350,6 +352,7 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
|
||||
if outJxOrder.FreightPrice, _, err = delivery.CalculateDeliveryFee(dao.GetDB(), jxOrder.StoreID, "",
|
||||
jxutils.StandardCoordinate2Int(deliveryAddress.Lng), jxutils.StandardCoordinate2Int(deliveryAddress.Lat),
|
||||
model.CoordinateTypeMars, outJxOrder.Weight, checkTime); err == nil {
|
||||
outJxOrder.FreightPrice = 0
|
||||
outJxOrder.TotalPrice = outJxOrder.OrderPrice + outJxOrder.FreightPrice
|
||||
outJxOrder.ActualPayPrice = outJxOrder.TotalPrice
|
||||
}
|
||||
@@ -431,29 +434,26 @@ func SelfDeliverDelivered(order *model.GoodsOrder, userName string) (err error)
|
||||
|
||||
func CancelOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string) (err error) {
|
||||
if order.Status < model.OrderStatusDelivering {
|
||||
orderPay := &model.OrderPay{
|
||||
VendorOrderID: order.VendorOrderID,
|
||||
VendorID: jxutils.GetPossibleVendorIDFromVendorOrderID(order.VendorOrderID),
|
||||
Status: model.PayStatusYes,
|
||||
}
|
||||
orderPay.DeletedAt = utils.DefaultTimeValue
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetEntity(db, orderPay, "VendorOrderID", "VendorID", "Status", "DeletedAt"); err == nil || dao.IsNoRowsError(err) {
|
||||
if err == nil {
|
||||
refundID := utils.Int64ToStr(GenRefundID(order))
|
||||
orderPayRefund, err2 := refundOrderByWX(ctx, orderPay, refundID)
|
||||
if err = err2; err == nil {
|
||||
dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName())
|
||||
err = dao.CreateEntity(dao.GetDB(), orderPay)
|
||||
}
|
||||
} else {
|
||||
if order.Status >= model.OrderStatusNew {
|
||||
globals.SugarLogger.Warnf("订单:%s找不到有效的支付方式", order.VendorOrderID)
|
||||
payList, err2 := dao.GetOrderPayList(db, order.VendorOrderID, jxutils.GetPossibleVendorIDFromVendorOrderID(order.VendorOrderID))
|
||||
if err = err2; err == nil {
|
||||
errList := errlist.New()
|
||||
for _, orderPay := range payList {
|
||||
if orderPay.Status == model.PayStatusYes {
|
||||
refundID := utils.Int64ToStr(GenRefundID(order))
|
||||
orderPayRefund, err2 := refundOrderByWX(ctx, orderPay, refundID)
|
||||
if err = err2; err == nil {
|
||||
dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName())
|
||||
errList.AddErr(dao.CreateEntity(dao.GetDB(), orderPay))
|
||||
}
|
||||
} else {
|
||||
orderPay.Status = model.PayStatusCanceled
|
||||
_, err2 := dao.UpdateEntity(db, orderPay)
|
||||
errList.AddErr(err2)
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
err = changeOrderStatus(order.VendorOrderID, model.OrderStatusCanceled, reason)
|
||||
}
|
||||
errList.AddErr(changeOrderStatus(order.VendorOrderID, model.OrderStatusCanceled, reason))
|
||||
err = errList.GetErrListAsOne()
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf("当前订单状态:%s不允许取消", model.OrderStatusName[order.Status])
|
||||
@@ -475,3 +475,9 @@ func changeOrderStatus(vendorOrderID string, status int, remark string) (err err
|
||||
}
|
||||
return partner.CurOrderManager.OnOrderStatusChanged(orderStatus)
|
||||
}
|
||||
|
||||
func GetOrderPay(ctx *jxcontext.Context, vendorOrderID string) (payList []*model.OrderPay, err error) {
|
||||
db := dao.GetDB()
|
||||
payList, err = dao.GetOrderPayList(db, vendorOrderID, jxutils.GetPossibleVendorIDFromVendorOrderID(vendorOrderID))
|
||||
return payList, err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package localjx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/wxpay"
|
||||
@@ -18,10 +19,14 @@ 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 := &wxpay.CreateOrderParam{
|
||||
Body: "",
|
||||
Body: getOrderBrief(order),
|
||||
NotifyURL: globals.WxpayNotifyURL,
|
||||
OutTradeNo: order.VendorOrderID,
|
||||
SpbillCreateIP: ctx.GetRealRemoteIP(),
|
||||
@@ -94,15 +99,27 @@ func onWxpayRefund(msg *wxpay.RefundResultMsg) (err error) {
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetEntity(db, orderPayRefund, "RefundID"); err == nil {
|
||||
if msg.ResultCode == wxpay.ResponseCodeSuccess {
|
||||
orderPayRefund.Status = model.PayStatusYes
|
||||
orderPayRefund.Status = model.RefundStatusYes
|
||||
} else {
|
||||
orderPayRefund.Status = model.PayStatusFailed
|
||||
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
|
||||
}
|
||||
|
||||
@@ -120,7 +137,7 @@ func refundOrderByWX(ctx *jxcontext.Context, orderPay *model.OrderPay, refundID
|
||||
VendorRefundID: result.RefundID,
|
||||
VendorOrderID: orderPay.VendorOrderID,
|
||||
VendorID: orderPay.VendorID,
|
||||
Status: model.PayStatusNo,
|
||||
Status: model.RefundStatusNo,
|
||||
TransactionID: orderPay.TransactionID,
|
||||
RefundFee: orderPay.TotalFee,
|
||||
RefundCreatedAt: time.Now(),
|
||||
|
||||
Reference in New Issue
Block a user