1
This commit is contained in:
@@ -182,18 +182,18 @@ func Init() {
|
||||
delivery.GetOrderRiderInfoToPlatform("", 0)
|
||||
}, 10*time.Second, 4*time.Minute)
|
||||
|
||||
//每天晚上23:00更新抖店 审核状态
|
||||
ScheduleTimerFunc("UpdateStorePoiStatus", func() {
|
||||
cms.UpdateStorePoiStatus(jxcontext.AdminCtx)
|
||||
}, []string{
|
||||
"22:00:00",
|
||||
})
|
||||
//每天晚上23:00获取门店 电子围栏、仓库、限售模板、运费模板ID同步进数据库
|
||||
ScheduleTimerFunc("UpdateStoreRelInformation", func() {
|
||||
cms.UpdateStoreRelInformation(jxcontext.AdminCtx)
|
||||
}, []string{
|
||||
"22:00:00",
|
||||
})
|
||||
//每天晚上23:00更新抖店 审核状态(收费注释)
|
||||
//ScheduleTimerFunc("UpdateStorePoiStatus", func() {
|
||||
// cms.UpdateStorePoiStatus(jxcontext.AdminCtx)
|
||||
//}, []string{
|
||||
// "22:00:00",
|
||||
//})
|
||||
//每天晚上23:00获取门店 电子围栏、仓库、限售模板、运费模板ID同步进数据库(收费注释)
|
||||
//ScheduleTimerFunc("UpdateStoreRelInformation", func() {
|
||||
// cms.UpdateStoreRelInformation(jxcontext.AdminCtx)
|
||||
//}, []string{
|
||||
// "22:00:00",
|
||||
//})
|
||||
// 更新抖店订单的结算信息
|
||||
ScheduleTimerFunc("UpdateTiktokShopTotalMoney", func() {
|
||||
orderman.UpdateTiktokShopTotalMoney()
|
||||
@@ -264,7 +264,7 @@ func Init() {
|
||||
if beego.BConfig.RunMode != "jxgy" {
|
||||
ScheduleTimerFuncByInterval(func() {
|
||||
cms.RefreshTiktokShopToken(jxcontext.AdminCtx)
|
||||
}, 60*time.Second, 30*time.Minute)
|
||||
}, 60*time.Second, 60*time.Minute)
|
||||
}
|
||||
|
||||
// 定时任务刷新当前订单的物流信息
|
||||
@@ -368,10 +368,10 @@ func Init() {
|
||||
ScheduleTimerFunc("GetNewVendorPopActs", func() {
|
||||
act.GetNewVendorPopActs(jxcontext.AdminCtx)
|
||||
}, dailyHeartbeat)
|
||||
//企业微信群人数通告
|
||||
ScheduleTimerFunc("SendQywxPeopleCount", func() {
|
||||
cms.SendQywxPeopleCount(jxcontext.AdminCtx)
|
||||
}, dailyHeartbeat)
|
||||
//企业微信群人数通告(暂时取消)
|
||||
//ScheduleTimerFunc("SendQywxPeopleCount", func() {
|
||||
// cms.SendQywxPeopleCount(jxcontext.AdminCtx)
|
||||
//}, dailyHeartbeat)
|
||||
ScheduleTimerFunc("doDailyWork1", func() {
|
||||
//同步商品额外前缀和水印图(打标记)
|
||||
cms.SyncSkuExperfixAndWatermark(jxcontext.AdminCtx)
|
||||
|
||||
@@ -22,7 +22,8 @@ const (
|
||||
VendorGoMei = 12 // 国美
|
||||
VendorIDTT = 13 // 抖音平台小程序
|
||||
VendorIDDD = 14 // 抖店
|
||||
VendorIDPurchaseEnd = 15
|
||||
VendorIDKS = 15 // 快手小程序
|
||||
VendorIDPurchaseEnd = 20
|
||||
|
||||
VendorIDWXPay = 51 // 微信支付
|
||||
|
||||
|
||||
@@ -11,9 +11,10 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
PayTypeWX = 1 // 微信支付
|
||||
PayTypeTL = 2 // 通联宝支付
|
||||
PayTypeTicTok = 3 // 抖音支付
|
||||
PayTypeWX = 1 // 微信支付
|
||||
PayTypeTL = 2 // 通联宝支付
|
||||
PayTypeTicTok = 3 // 抖音支付
|
||||
PayTypeKuaiShou = 4 // 快手支付
|
||||
|
||||
PayTypeTL_DiscountCard = 3 // 通联宝支付(会员折扣卡)
|
||||
PayTypeTL_StoreAcctPay = 4 // 通联宝支付(门店账户充值)
|
||||
|
||||
@@ -515,6 +515,9 @@ func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo, isCreate, isE
|
||||
if storeSku.MinOrderCount > 0 {
|
||||
params["minimum"] = utils.Int2Float64(storeSku.MinOrderCount)
|
||||
}
|
||||
if storeSku.MinOrderCount == 0 {
|
||||
params["minimum"] = utils.Int2Float64(1)
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
|
||||
191
business/partner/purchase/jx/localjx/kuaishou_pay.go
Normal file
191
business/partner/purchase/jx/localjx/kuaishou_pay.go
Normal file
@@ -0,0 +1,191 @@
|
||||
package localjx
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/kuaishou_mini"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/kuaishou"
|
||||
"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"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func getOrderBriefKs(order *model.GoodsOrder) string {
|
||||
sku := make([]string, len(order.Skus))
|
||||
for _, v := range order.Skus {
|
||||
sku = append(sku, fmt.Sprintf("%s x %d件商品", v.SkuName, v.Count))
|
||||
}
|
||||
return strings.Join(sku, ",")
|
||||
}
|
||||
|
||||
func pay4OrderByKs(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayType, subAppID string) (orderPay *model.OrderPay, err error) {
|
||||
// 获取用户快手OpenId
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
authBindList, err := dao.GetUserBindAuthInfo(db, ctx.GetUserID(), model.AuthBindTypeAuth, []string{kuaishou.AuthTypeKuaiShouMini}, "", "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(authBindList) == model.NO {
|
||||
return nil, errors.New("用户未绑定快手,无法快手支付")
|
||||
}
|
||||
|
||||
param := &kuaishou_mini.PreCreateOrderReq{
|
||||
OutOrderNo: utils.Int64ToStr(GenPayOrderID(order)),
|
||||
OpenId: authBindList[0].AuthID,
|
||||
TotalAmount: order.ActualPayPrice,
|
||||
Subject: "蔬菜水果日用品",
|
||||
Detail: getOrderBriefKs(order),
|
||||
TypeDetail: 1832, // 蔬菜:费率2%,水果:1833%2
|
||||
ExpireTime: 60 * 10,
|
||||
Sign: "",
|
||||
Attach: "",
|
||||
NotifyUrl: "http://callback.jxc4.com/kuaishou/KuaiShouCallback",
|
||||
GoodsId: "",
|
||||
GoodsDetailUrl: "",
|
||||
MultiCopiesGoodsInfo: "",
|
||||
CancelOrder: 0,
|
||||
}
|
||||
|
||||
// 预下单
|
||||
prePayInfo, err := api.KuaiShouApi.PreCreateOrder(param)
|
||||
if err == nil {
|
||||
orderPay = &model.OrderPay{
|
||||
PayOrderID: order.VendorOrderID, // 抖音订单id
|
||||
PayType: model.PayTypeKuaiShou,
|
||||
VendorPayType: vendorPayType,
|
||||
VendorOrderID: order.VendorOrderID,
|
||||
VendorID: order.VendorID,
|
||||
Status: 0,
|
||||
PayCreatedAt: time.Now(),
|
||||
PrepayID: "",
|
||||
CodeURL: prePayInfo, // 抖音支付token
|
||||
TotalFee: int(order.ActualPayPrice),
|
||||
}
|
||||
}
|
||||
return orderPay, err
|
||||
}
|
||||
|
||||
func OnKSPayCallback(msg *kuaishou_mini.CallBackDetail, refund *kuaishou_mini.RefundCallBack, payType string) (err error) {
|
||||
switch payType {
|
||||
case kuaishou_mini.CallbackTypePay: // 支付回调
|
||||
err = onKSPayFinished(msg)
|
||||
case kuaishou_mini.CallbackTypeRefund: // 退款回调
|
||||
err = onKSPayRefund(refund)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func onKSPayFinished(msg *kuaishou_mini.CallBackDetail) (err error) {
|
||||
orderPay := &model.OrderPay{
|
||||
PayOrderID: msg.OutOrderNo,
|
||||
PayType: model.PayTypeTicTok,
|
||||
}
|
||||
orderPay.DeletedAt = utils.DefaultTimeValue
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetEntity(db, orderPay, "PayOrderID", "PayType", "DeletedAt"); err == nil {
|
||||
orderPay.PayFinishedAt = utils.Time2Pointer(time.Now())
|
||||
orderPay.TransactionID = msg.TradeNo
|
||||
orderPay.OriginalData = utils.Format4Output(msg, true)
|
||||
switch msg.Status {
|
||||
case kuaishou_mini.OrderPayStatusHandleing:
|
||||
orderPay.Status = model.PayStatusNo
|
||||
case kuaishou_mini.OrderPayStatusSuccess:
|
||||
orderPay.Status = model.PayStatusYes
|
||||
case kuaishou_mini.OrderPayStatusFailed:
|
||||
orderPay.Status = model.PayStatusFailed
|
||||
}
|
||||
dao.UpdateEntity(db, orderPay)
|
||||
|
||||
if msg.Status == kuaishou_mini.OrderPayStatusSuccess {
|
||||
err = OnPayFinished(orderPay)
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("onKSPayFinished msg:%s, err:%v", utils.Format4Output(msg, true), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func onKSPayRefund(msg *kuaishou_mini.RefundCallBack) (err error) {
|
||||
orderPayRefund := &model.OrderPayRefund{
|
||||
RefundID: msg.OutRefundNo,
|
||||
}
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetEntity(db, orderPayRefund, "RefundID"); err == nil {
|
||||
switch msg.Status {
|
||||
case kuaishou_mini.OrderPayStatusHandleing:
|
||||
orderPayRefund.Status = model.PayStatusNo
|
||||
case kuaishou_mini.OrderPayStatusSuccess:
|
||||
orderPayRefund.Status = model.PayStatusYes
|
||||
case kuaishou_mini.OrderPayStatusFailed:
|
||||
orderPayRefund.Status = model.PayStatusFailed
|
||||
}
|
||||
|
||||
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.PayTypeKuaiShou,
|
||||
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
|
||||
}
|
||||
|
||||
// RefundOrderByKS 申请退款
|
||||
func RefundOrderByKS(ctx *jxcontext.Context, orderPay *model.OrderPay, refundID string, refundFee int, refundDesc string) (orderPayRefund *model.OrderPayRefund, err error) {
|
||||
|
||||
param := kuaishou_mini.RefundParam{
|
||||
OutOrderNo: orderPay.VendorOrderID,
|
||||
OutRefundNo: refundID,
|
||||
Reason: refundDesc,
|
||||
Attach: "",
|
||||
NotifyUrl: "http://callback.jxc4.com/kuaishou/kuaiShouCallback",
|
||||
RefundAmount: int64(orderPay.TotalFee),
|
||||
Sign: "",
|
||||
MultiCopiesGoodsInfo: "",
|
||||
}
|
||||
result, err := api.KuaiShouApi.RefundOrder(¶m)
|
||||
if err == nil {
|
||||
orderPayRefund = &model.OrderPayRefund{
|
||||
RefundID: refundID,
|
||||
VendorRefundID: result,
|
||||
VendorOrderID: orderPay.VendorOrderID,
|
||||
VendorID: orderPay.VendorID,
|
||||
Status: model.RefundStatusNo,
|
||||
TransactionID: orderPay.TransactionID,
|
||||
RefundFee: refundFee,
|
||||
RefundCreatedAt: time.Now(),
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName())
|
||||
db := dao.GetDB()
|
||||
if result != "" {
|
||||
orderPayRefund.Status = model.RefundStatusYes
|
||||
} else {
|
||||
orderPayRefund.Status = model.RefundStatusFailed
|
||||
}
|
||||
orderPayRefund.OriginalData = utils.Format4Output(result, true)
|
||||
dao.CreateEntity(db, orderPayRefund)
|
||||
|
||||
orderPay.Status = model.PayStatusRefund
|
||||
dao.UpdateEntity(db, orderPay)
|
||||
}
|
||||
return orderPayRefund, err
|
||||
}
|
||||
@@ -335,6 +335,11 @@ func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType
|
||||
dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName())
|
||||
err = dao.CreateEntity(dao.GetDB(), orderPay)
|
||||
}
|
||||
case model.PayTypeKuaiShou:
|
||||
if orderPay, err = pay4OrderByKs(ctx, order, vendorPayType, subAppID); err == nil && orderPay != nil {
|
||||
dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName())
|
||||
err = dao.CreateEntity(dao.GetDB(), orderPay)
|
||||
}
|
||||
default:
|
||||
err = fmt.Errorf("支付方式:%d当前不支持", payType)
|
||||
}
|
||||
@@ -1393,7 +1398,8 @@ func CancelOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string)
|
||||
// refundID := utils.Int64ToStr(GenRefundID(order))
|
||||
refundID := order.VendorOrderID
|
||||
var orderPayRefund *model.OrderPayRefund
|
||||
if orderPay.PayType == model.PayTypeWX {
|
||||
switch orderPay.PayType {
|
||||
case model.PayTypeWX:
|
||||
orderPayRefund, err = refundOrderByWX(ctx, orderPay, refundID, orderPay.TotalFee, reason)
|
||||
if err == nil {
|
||||
dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName())
|
||||
@@ -1401,17 +1407,23 @@ func CancelOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string)
|
||||
} else {
|
||||
errList.AddErr(err)
|
||||
}
|
||||
} else if orderPay.PayType == model.PayTypeTL {
|
||||
case model.PayTypeTL:
|
||||
orderPayRefund, err = RefundOrderByTL(ctx, orderPay, refundID, orderPay.TotalFee, reason)
|
||||
if err != nil {
|
||||
errList.AddErr(err)
|
||||
}
|
||||
} else if orderPay.PayType == model.PayTypeTicTok {
|
||||
case model.PayTypeTicTok:
|
||||
orderPayRefund, err = RefundOrderByTT(ctx, orderPay, refundID, orderPay.TotalFee, reason)
|
||||
if err != nil {
|
||||
errList.AddErr(err)
|
||||
}
|
||||
case model.PayTypeKuaiShou:
|
||||
orderPayRefund, err = RefundOrderByKS(ctx, orderPay, refundID, orderPay.TotalFee, reason)
|
||||
if err != nil {
|
||||
errList.AddErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
//如果用了优惠券,状态要刷回去
|
||||
if order.CouponIDs != "" {
|
||||
|
||||
@@ -58,6 +58,7 @@ func getTikTok(appID string) (TikTokMini *tiktok.API) {
|
||||
}
|
||||
return TikTokMini
|
||||
}
|
||||
|
||||
func OnTTPayCallback(msg *tiktok.DetailCallBackMessage, refund *tiktok.DetailCallBackMessage2Refund, payType string) (err error) {
|
||||
switch payType {
|
||||
case tiktok.PayStatus: // 支付回调
|
||||
|
||||
Reference in New Issue
Block a user