diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 6183b47ad..52a17219e 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -156,7 +156,7 @@ type DataLock struct { } const ( - maxStoreNameBind = 3000 // 最大门店SkuName bind个数 + maxStoreNameBind = 10000 // 最大门店SkuName bind个数 maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数 AutoSaleAtStr = "22:00:00" diff --git a/business/model/order.go b/business/model/order.go index 98a62b783..e785851b8 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -296,25 +296,26 @@ type OrderComment struct { type OrderPay struct { ModelIDCULD - VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` - VendorID int `orm:"column(vendor_id)" json:"vendorID"` - PayType int `json:"payType"` + PayOrderID string `orm:"column(pay_order_id);size(48)" json:"payOrderID"` // 京西支付定单号 + PayType int `json:"payType"` + VendorPayType string `orm:"size(48)" json:"vendorPayType"` + VendorOrderID string `orm:"column(vendor_order_id);size(48);index" json:"vendorOrderID"` // 支付对应的购物订单号 + VendorID int `orm:"column(vendor_id)" json:"vendorID"` // 购物订单所属厂商代码(当前只有京西) Status int `json:"status"` PayCreatedAt time.Time `orm:"type(datetime);index" json:"payCreatedAt"` PayFinishedAt *time.Time `orm:"type(datetime);null" json:"payFinishedAt"` TotalFee int `json:"totalFee"` - TransactionID string `orm:"column(transaction_id);index;size(48)" json:"transactionID"` - PrepayID string `orm:"column(prepay_id);unique;size(48)" json:"prepayID"` + PrepayID string `orm:"column(prepay_id);index;size(48)" json:"prepayID"` // 下单后,支付前,支付方生成的事务ID + TransactionID string `orm:"column(transaction_id);index;size(48)" json:"transactionID"` // 支付成功后,支付方生成的事务ID CodeURL string `orm:"column(code_url);size(256)" json:"codeURL"` - PayOrderID string `orm:"column(pay_order_id);size(48)" json:"payOrderID"` OriginalData string `orm:"type(text)" json:"-"` } func (v *OrderPay) TableIndex() [][]string { return [][]string{ - []string{"VendorOrderID", "VendorID", "PayType", "DeletedAt"}, + []string{"PayOrderID", "PayType", "DeletedAt"}, } } @@ -322,12 +323,11 @@ type OrderPayRefund struct { ModelIDCULD RefundID string `orm:"column(refund_id);unique;size(48)" json:"refundID"` - VendorRefundID string `orm:"column(vendor_refund_id);unique;size(48)" json:"vendorRefundID"` + VendorRefundID string `orm:"column(vendor_refund_id);unique;size(48)" json:"vendorRefundID"` // 支付方退款成功后生成的退款单号 - AfsOrderID string `orm:"column(afs_order_id);index;size(48)" json:"afsOrderID"` // AfsOrderID与RefundID的区别? VendorOrderID string `orm:"column(vendor_order_id);index;size(48)" json:"vendorOrderID"` VendorID int `orm:"column(vendor_id)" json:"vendorID"` - TransactionID string `orm:"column(transaction_id);index;size(48)" json:"transactionID"` + TransactionID string `orm:"column(transaction_id);index;size(48)" json:"transactionID"` // 支付成功后,支付方生成的事务ID Status int `json:"status"` RefundCreatedAt time.Time `orm:"type(datetime);index" json:"payCreatedAt"` RefundFinishedAt *time.Time `orm:"type(datetime);null" json:"payFinishedAt"` diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index 348c0e548..7d254f68d 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -272,6 +272,10 @@ func GenOrderNo(ctx *jxcontext.Context) (orderNo int64) { return orderNo } +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 @@ -507,6 +511,10 @@ func AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool, userName stri return changeOrderStatus(order.VendorOrderID, status, "") } +func AdjustOrder(ctx *jxcontext.Context, order *model.GoodsOrder, removedSkuList []*model.OrderSku, reason string) (err error) { + return err +} + func PickupGoods(order *model.GoodsOrder, isSelfDelivery bool, userName string) (err error) { return changeOrderStatus(order.VendorOrderID, model.OrderStatusFinishedPickup, "") } @@ -527,8 +535,9 @@ func CancelOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string) errList := errlist.New() for _, orderPay := range payList { if orderPay.Status == model.PayStatusYes { - refundID := utils.Int64ToStr(GenRefundID(order)) - orderPayRefund, err2 := refundOrderByWX(ctx, orderPay, refundID) + // refundID := utils.Int64ToStr(GenRefundID(order)) + refundID := order.VendorOrderID + orderPayRefund, err2 := refundOrderByWX(ctx, orderPay, refundID, orderPay.TotalFee, reason) if err2 == nil { dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName()) errList.AddErr(dao.CreateEntity(dao.GetDB(), orderPayRefund)) diff --git a/business/partner/purchase/jx/localjx/wxpay.go b/business/partner/purchase/jx/localjx/wxpay.go index 62d71fad7..453533def 100644 --- a/business/partner/purchase/jx/localjx/wxpay.go +++ b/business/partner/purchase/jx/localjx/wxpay.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "git.rosy.net.cn/baseapi/platformapi/wxpay" + "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" @@ -25,16 +25,16 @@ func getOrderBrief(order *model.GoodsOrder) string { func pay4OrderByWX(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayType string) (orderPay *model.OrderPay, err error) { payCreatedAt := time.Now() - param := &wxpay.CreateOrderParam{ + param := &wxpayapi.CreateOrderParam{ + OutTradeNo: utils.Int64ToStr(GenPayOrderID(order)), Body: getOrderBrief(order), NotifyURL: globals.WxpayNotifyURL, - OutTradeNo: order.VendorOrderID, SpbillCreateIP: ctx.GetRealRemoteIP(), TradeType: vendorPayType2WxpayType(vendorPayType), TotalFee: int(order.ActualPayPrice), - TimeStart: wxpay.Time2PayTime(payCreatedAt), - // TimeExpire: wxpay.Time2PayTime(payCreatedAt.Add(PayWaitingTime)), + TimeStart: wxpayapi.Time2PayTime(payCreatedAt), + // TimeExpire: wxpayapi.Time2PayTime(payCreatedAt.Add(PayWaitingTime)), } if authInfo, err := ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini { param.OpenID = authInfo.GetAuthID() @@ -42,10 +42,12 @@ func pay4OrderByWX(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp result, err := api.WxpayAPI.CreateUnifiedOrder(param) if err == nil { orderPay = &model.OrderPay{ - VendorOrderID: order.VendorOrderID, - VendorID: order.VendorID, + PayOrderID: param.OutTradeNo, PayType: model.PayTypeWX, VendorPayType: vendorPayType, + + VendorOrderID: order.VendorOrderID, + VendorID: order.VendorID, Status: 0, PayCreatedAt: payCreatedAt, PrepayID: result.PrepayID, @@ -56,37 +58,35 @@ func pay4OrderByWX(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp return orderPay, err } -func OnWxPayCallback(msg *wxpay.CallbackMsg) (err error) { +func OnWxPayCallback(msg *wxpayapi.CallbackMsg) (err error) { globals.SugarLogger.Debugf("OnWxPayCallback msg:%s", utils.Format4Output(msg, true)) switch msg.MsgType { - case wxpay.MsgTypePay: - err = onWxpayFinished(msg.Data.(*wxpay.PayResultMsg)) - case wxpay.MsgTypeRefund: - err = onWxpayRefund(msg.Data.(*wxpay.RefundResultMsg)) + case wxpayapi.MsgTypePay: + err = onWxpayFinished(msg.Data.(*wxpayapi.PayResultMsg)) + case wxpayapi.MsgTypeRefund: + err = onWxpayRefund(msg.Data.(*wxpayapi.RefundResultMsg)) } return err } -func onWxpayFinished(msg *wxpay.PayResultMsg) (err error) { +func onWxpayFinished(msg *wxpayapi.PayResultMsg) (err error) { orderPay := &model.OrderPay{ - VendorOrderID: msg.OutTradeNo, - VendorID: jxutils.GetPossibleVendorIDFromVendorOrderID(msg.OutTradeNo), - PayType: model.PayTypeWX, + PayOrderID: msg.OutTradeNo, + PayType: model.PayTypeWX, } orderPay.DeletedAt = utils.DefaultTimeValue db := dao.GetDB() - if err = dao.GetEntity(db, orderPay, "VendorOrderID", "VendorID", "PayType", "DeletedAt"); err == nil { - orderPay.VendorPayType = msg.TradeType - orderPay.PayFinishedAt = utils.Time2Pointer(wxpay.PayTime2Time(msg.TimeEnd)) + 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 == wxpay.ResponseCodeSuccess { + if msg.ResultCode == wxpayapi.ResponseCodeSuccess { orderPay.Status = model.PayStatusYes } else { orderPay.Status = model.PayStatusFailed } dao.UpdateEntity(db, orderPay) - if msg.ResultCode == wxpay.ResponseCodeSuccess { + if msg.ResultCode == wxpayapi.ResponseCodeSuccess { err = OnPayFinished(orderPay) } } else { @@ -95,13 +95,13 @@ func onWxpayFinished(msg *wxpay.PayResultMsg) (err error) { return err } -func onWxpayRefund(msg *wxpay.RefundResultMsg) (err error) { +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 == wxpay.ResponseCodeSuccess { + if msg.ResultCode == wxpayapi.ResponseCodeSuccess { orderPayRefund.Status = model.RefundStatusYes } else { orderPayRefund.Status = model.RefundStatusFailed @@ -126,13 +126,14 @@ func onWxpayRefund(msg *wxpay.RefundResultMsg) (err error) { return err } -func refundOrderByWX(ctx *jxcontext.Context, orderPay *model.OrderPay, refundID string) (orderPayRefund *model.OrderPayRefund, err error) { - result, err := api.WxpayAPI.PayRefund(&wxpay.PayRefundParam{ +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: orderPay.TotalFee, + RefundFee: refundFee, + RefundDesc: wxpayapi.CData(refundDesc), }) if err == nil { orderPayRefund = &model.OrderPayRefund{ diff --git a/business/partner/purchase/jx/order.go b/business/partner/purchase/jx/order.go index 49a0c62d5..2a8955482 100644 --- a/business/partner/purchase/jx/order.go +++ b/business/partner/purchase/jx/order.go @@ -112,6 +112,10 @@ func (c *PurchaseHandler) CancelOrder(ctx *jxcontext.Context, order *model.Goods } 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 } diff --git a/controllers/wxpay_callback.go b/controllers/wxpay_callback.go index 2d6d89e7d..4da448b20 100644 --- a/controllers/wxpay_callback.go +++ b/controllers/wxpay_callback.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "git.rosy.net.cn/baseapi/platformapi/wxpay" + "git.rosy.net.cn/baseapi/platformapi/wxpayapi" "git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx" "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego" @@ -17,19 +17,19 @@ type WXPayController struct { func (c *WXPayController) Msg() { if c.Ctx.Input.Method() == http.MethodPost { msg, callbackResponse := api.WxpayAPI.GetCallbackMsg(c.Ctx.Request) - // globals.SugarLogger.Debugf("wxpay callback msg:%s, callbackResponse:%s, %t", utils.Format4Output(msg, true), utils.Format4Output(callbackResponse, true), callbackResponse == nil) + // globals.SugarLogger.Debugf("wxpayapi callback msg:%s, callbackResponse:%s, %t", utils.Format4Output(msg, true), utils.Format4Output(callbackResponse, true), callbackResponse == nil) var err error if callbackResponse == nil { - if msg.MsgType == wxpay.MsgTypeUnkown { + if msg.MsgType == wxpayapi.MsgTypeUnkown { err = fmt.Errorf("未知的微信支付回调类型:%d", msg.MsgType) } else { err = localjx.OnWxPayCallback(msg) } } if callbackResponse == nil { - callbackResponse = wxpay.SuccessResponse + callbackResponse = wxpayapi.SuccessResponse } else if err != nil { - callbackResponse = wxpay.Err2CallbackResponse(err, "") + callbackResponse = wxpayapi.Err2CallbackResponse(err, "") } c.Data["xml"] = callbackResponse c.ServeXML() diff --git a/globals/api/api.go b/globals/api/api.go index 9ab7e5b4c..8e180df56 100644 --- a/globals/api/api.go +++ b/globals/api/api.go @@ -19,7 +19,7 @@ import ( "git.rosy.net.cn/baseapi/platformapi/showapi" "git.rosy.net.cn/baseapi/platformapi/weimobapi" "git.rosy.net.cn/baseapi/platformapi/weixinapi" - "git.rosy.net.cn/baseapi/platformapi/wxpay" + "git.rosy.net.cn/baseapi/platformapi/wxpayapi" "git.rosy.net.cn/baseapi/platformapi/xiaowmapi" "git.rosy.net.cn/baseapi/platformapi/yilianyunapi" "git.rosy.net.cn/baseapi/platformapi/zhongwuapi" @@ -46,7 +46,7 @@ var ( WeixinMiniAPI *weixinapi.API // 小程序 WeixinMiniAPI2 *weixinapi.API // 小程序2 WeixinMiniAppID2 string - WxpayAPI *wxpay.API // 微信支付API + WxpayAPI *wxpayapi.API // 微信支付API WeixinPageAPI *weixinapi.API // 用户微信扫码登录 @@ -152,8 +152,8 @@ func Init() { } WeixinPageAPI = weixinapi.New(beego.AppConfig.String("weixinPageAppID"), beego.AppConfig.String("weixinPageSecret")) if globals.WxpayNotifyURL != "" { - // WxpayAPI = wxpay.New(beego.AppConfig.String("wxpayAppID"), beego.AppConfig.String("wxpayAppKey"), beego.AppConfig.String("wxpayAppMchID")) - WxpayAPI = wxpay.NewWithCertificate(beego.AppConfig.String("wxpayAppID"), beego.AppConfig.String("wxpayAppKey"), beego.AppConfig.String("wxpayAppMchID"), + // WxpayAPI = wxpayapi.New(beego.AppConfig.String("wxpayAppID"), beego.AppConfig.String("wxpayAppKey"), beego.AppConfig.String("wxpayAppMchID")) + WxpayAPI = wxpayapi.NewWithCertificate(beego.AppConfig.String("wxpayAppID"), beego.AppConfig.String("wxpayAppKey"), beego.AppConfig.String("wxpayAppMchID"), "conf/apiclient_cert.pem", "conf/apiclient_key.pem") } AutonaviAPI = autonavi.New(beego.AppConfig.String("autonaviKey"))