1
This commit is contained in:
@@ -79,7 +79,7 @@ func CreateOrder(ctx *jxcontext.Context, type1, orderType int, way string, price
|
|||||||
return order.OrderID, errCode, err
|
return order.OrderID, errCode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType string) (result *financial.WxPayParam, err error) {
|
func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, appId string) (result *financial.WxPayParam, err error) {
|
||||||
var (
|
var (
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
order = &model.Order{
|
order = &model.Order{
|
||||||
@@ -109,7 +109,7 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType stri
|
|||||||
if userBill == nil {
|
if userBill == nil {
|
||||||
err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID)
|
err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID)
|
||||||
}
|
}
|
||||||
err = payHandler.CreatePay(txDB)
|
err = payHandler.CreatePay(txDB, appId)
|
||||||
dao.Commit(db, txDB)
|
dao.Commit(db, txDB)
|
||||||
globals.SugarLogger.Debugf("result : %v", utils.Format4Output(payHandler.WxPayParam, false))
|
globals.SugarLogger.Debugf("result : %v", utils.Format4Output(payHandler.WxPayParam, false))
|
||||||
return payHandler.WxPayParam, err
|
return payHandler.WxPayParam, err
|
||||||
|
|||||||
@@ -34,28 +34,71 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *PayHandler) CreatePay(txDB orm.TxOrmer) (err error) {
|
func (p *PayHandler) CreatePay(txDB orm.TxOrmer, subAppID string) (err error) {
|
||||||
switch p.PayType {
|
switch p.PayType {
|
||||||
case model.PayTypeTL:
|
case model.PayTypeTL:
|
||||||
param := &tonglianpayapi.CreateUnitorderOrderParam{
|
param := &tonglianpayapi.CreateUnitorderOrderParam{
|
||||||
Trxamt: int(p.Order.PayPrice),
|
Trxamt: p.Order.PayPrice,
|
||||||
NotifyUrl: globals.TLPayNotifyURL,
|
NotifyUrl: globals.TLPayNotifyURL,
|
||||||
Reqsn: p.Order.OrderID,
|
Reqsn: p.Order.OrderID,
|
||||||
PayType: p.VendorPayType,
|
PayType: p.VendorPayType,
|
||||||
}
|
}
|
||||||
|
//暂时做兼容处理
|
||||||
|
if p.VendorPayType == "JSAPI" {
|
||||||
|
param.PayType = tonglianpayapi.PayTypeWxXcx
|
||||||
|
}
|
||||||
if p.VendorPayType == tonglianpayapi.PayTypeWxXcx {
|
if p.VendorPayType == tonglianpayapi.PayTypeWxXcx {
|
||||||
if authInfo, err := p.Ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeWxApp {
|
param.SubAppID = subAppID
|
||||||
|
authInfo, err := p.Ctx.GetV2AuthInfo()
|
||||||
|
// 微信小程序支付
|
||||||
|
if err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini && authInfo.GetAuthTypeID() == subAppID {
|
||||||
param.Acct = authInfo.GetAuthID()
|
param.Acct = authInfo.GetAuthID()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result, err := api.TLpayAPI.CreateUnitorderOrder(param)
|
if p.VendorPayType == tonglianpayapi.PayTypeZfbJS || p.VendorPayType == tonglianpayapi.PayTypeZfbApp {
|
||||||
if err == nil {
|
if authInfo, err := p.Ctx.GetV2AuthInfo(); err == nil {
|
||||||
var result2 tonglianpayapi.PayInfo
|
param.Acct = authInfo.GetAuthID()
|
||||||
json.Unmarshal([]byte(result.PayInfo), &result2)
|
}
|
||||||
p.Order.PrepayID = result2.Package[strings.LastIndex(result2.Package, "=")+1 : len(result2.Package)]
|
if param.Acct == "" {
|
||||||
p.Order.TransactionID = result.TrxID
|
return fmt.Errorf("未找到用户的认证ID!")
|
||||||
_, err = dao.UpdateEntityTx(txDB, p.Order, "PrepayID", "TransactionID")
|
}
|
||||||
}
|
}
|
||||||
|
if p.VendorPayType == tonglianpayapi.PayTypeH5 {
|
||||||
|
param2 := &tonglianpayapi.CreateH5UnitorderOrderParam{
|
||||||
|
Trxamt: p.Order.PayPrice,
|
||||||
|
NotifyUrl: globals.TLPayNotifyURL,
|
||||||
|
Body: "冲天猴",
|
||||||
|
Charset: "UTF-8",
|
||||||
|
}
|
||||||
|
err = api.TLpayAPI.CreateH5UnitorderOrder(param2)
|
||||||
|
} else {
|
||||||
|
result, err := api.TLpayAPI.CreateUnitorderOrder(param)
|
||||||
|
if err == nil {
|
||||||
|
var result2 tonglianpayapi.PayInfo
|
||||||
|
json.Unmarshal([]byte(result.PayInfo), &result2)
|
||||||
|
p.Order.PrepayID = result2.Package[strings.LastIndex(result2.Package, "=")+1 : len(result2.Package)]
|
||||||
|
p.Order.TransactionID = result.TrxID
|
||||||
|
_, err = dao.UpdateEntityTx(txDB, p.Order, "PrepayID", "TransactionID")
|
||||||
|
}
|
||||||
|
//var result2 tonglianpayapi.PayInfo
|
||||||
|
//json.Unmarshal([]byte(result.PayInfo), &result2)
|
||||||
|
//prePayID := result2.Package[strings.LastIndex(result2.Package, "=")+1 : len(result2.Package)]
|
||||||
|
//orderPay = &model.OrderPay{
|
||||||
|
// PayOrderID: param.Reqsn,
|
||||||
|
// PayType: payType,
|
||||||
|
// VendorPayType: vendorPayType,
|
||||||
|
// TransactionID: result.TrxID,
|
||||||
|
// VendorOrderID: order.VendorOrderID,
|
||||||
|
// VendorID: order.VendorID,
|
||||||
|
// Status: 0,
|
||||||
|
// PayCreatedAt: payCreatedAt,
|
||||||
|
// PrepayID: prePayID,
|
||||||
|
// CodeURL: utils.LimitUTF8StringLen(result.PayInfo, 3200),
|
||||||
|
// TotalFee: int(order.ActualPayPrice),
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 暂时不支持微信直接支付
|
||||||
case model.PayTypeWX:
|
case model.PayTypeWX:
|
||||||
param := &wxpayapi.CreateOrderParam{
|
param := &wxpayapi.CreateOrderParam{
|
||||||
OutTradeNo: p.Order.OrderID,
|
OutTradeNo: p.Order.OrderID,
|
||||||
@@ -213,16 +256,24 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
|||||||
loc, _ := time.LoadLocation("Local")
|
loc, _ := time.LoadLocation("Local")
|
||||||
t1, _ := time.ParseInLocation("20060102150405", call.PayTime, loc)
|
t1, _ := time.ParseInLocation("20060102150405", call.PayTime, loc)
|
||||||
order.PayFinishedAt = t1
|
order.PayFinishedAt = t1
|
||||||
// order.TransactionID = call.ChnlTrxID
|
|
||||||
order.OriginalData = utils.Format4Output(call, true)
|
order.OriginalData = utils.Format4Output(call, true)
|
||||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||||
order.Status = model.OrderStatusFinished
|
order.Status = model.OrderStatusFinished
|
||||||
} else {
|
} else {
|
||||||
order.Status = model.OrderStatusCanceled
|
order.Status = model.OrderStatusCanceled
|
||||||
}
|
}
|
||||||
dao.UpdateEntity(db, order)
|
|
||||||
|
if _, err := dao.UpdateEntity(db, order); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||||
err = OnPayFinished(order)
|
switch order.OrderType {
|
||||||
|
case model.PayType4Express:
|
||||||
|
|
||||||
|
case model.PayType4Member, model.PayType4Recharge:
|
||||||
|
err = OnPayFinished(order)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Debugf("onTLpayFinished msg:%s, err:%v", utils.Format4Output(call, true), err)
|
globals.SugarLogger.Debugf("onTLpayFinished msg:%s, err:%v", utils.Format4Output(call, true), err)
|
||||||
|
|||||||
@@ -36,9 +36,7 @@ type PayHandlerInterface interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func OnPayFinished(order *model.Order) (err error) {
|
func OnPayFinished(order *model.Order) (err error) {
|
||||||
var (
|
var db = dao.GetDB()
|
||||||
db = dao.GetDB()
|
|
||||||
)
|
|
||||||
globals.SugarLogger.Debugf("OnPayFinished begin modify account order: %v", utils.Format4Output(order, false))
|
globals.SugarLogger.Debugf("OnPayFinished begin modify account order: %v", utils.Format4Output(order, false))
|
||||||
txDB, _ := dao.Begin(db)
|
txDB, _ := dao.Begin(db)
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ const (
|
|||||||
|
|
||||||
VendorPayTypeCompanyPay = "companyPay" //企业付款
|
VendorPayTypeCompanyPay = "companyPay" //企业付款
|
||||||
VendorPayTypeTransferAccount = "transferAccount" //手动转账
|
VendorPayTypeTransferAccount = "transferAccount" //手动转账
|
||||||
|
|
||||||
|
PayType4Member = 1 // 购买会员
|
||||||
|
PayType4Recharge = 2 // 充值余额
|
||||||
|
PayType4Express = 3 // 支付快递
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -49,23 +53,23 @@ var (
|
|||||||
type Order struct {
|
type Order struct {
|
||||||
ModelIDCUL
|
ModelIDCUL
|
||||||
|
|
||||||
OrderID string `orm:"column(order_id)" json:"orderID"` //订单号
|
OrderID string `orm:"column(order_id)" json:"orderID"` //订单号
|
||||||
UserID string `orm:"column(user_id);size(48)" json:"userID"` //用户ID
|
UserID string `orm:"column(user_id);size(48)" json:"userID"` //用户ID
|
||||||
Type int `json:"type"`
|
Type int `json:"type"` // 支付还是提现
|
||||||
OrderType int `json:"orderType"` //订单类型
|
OrderType int `json:"orderType"` // 订单类型,1为发任务,2为冲会员,3为发快递
|
||||||
Way string `json:"way"` //weixinapp ,weixinmini
|
Way string `json:"way"` //weixinapp ,weixinmini
|
||||||
Status int `json:"status"` //订单状态,待支付2,已支付5,支付成功110,支付失败115
|
Status int `json:"status"` //订单状态,待支付2,已支付5,支付成功110,支付失败115
|
||||||
PayPrice int `json:"payPrice"` //支付金额
|
PayPrice int `json:"payPrice"` //支付金额
|
||||||
TransactionID string `orm:"column(transaction_id);size(48)" json:"transactionID"` // 支付成功后,支付方生成的事务ID
|
TransactionID string `orm:"column(transaction_id);size(48)" json:"transactionID"` // 支付成功后,支付方生成的事务ID
|
||||||
PayFinishedAt time.Time `orm:"type(datetime);null" json:"payFinishedAt"`
|
PayFinishedAt time.Time `orm:"type(datetime);null" json:"payFinishedAt"` // 支付完成时间
|
||||||
PrepayID string `orm:"column(prepay_id);size(48)" json:"prepayID"` // 下单后,支付前,支付方生成的事务ID
|
PrepayID string `orm:"column(prepay_id);size(48)" json:"prepayID"` // 下单后,支付前,支付方生成的事务ID
|
||||||
OriginalData string `orm:"type(text)" json:"-"`
|
OriginalData string `orm:"type(text)" json:"-"`
|
||||||
Comment string `orm:"size(255)" json:"comment"` //备注
|
Comment string `orm:"size(255)" json:"comment"` //备注
|
||||||
Lng float64 `json:"lng"`
|
Lng float64 `json:"lng"` // 坐标
|
||||||
Lat float64 `json:"lat"`
|
Lat float64 `json:"lat"` // 坐标
|
||||||
CityCode int `orm:"default(0)" json:"cityCode"` //提交订单时用户所在城市
|
CityCode int `orm:"default(0)" json:"cityCode"` //提交订单时用户所在城市
|
||||||
DistrictCode int `orm:"default(0)" json:"districtCode"`
|
DistrictCode int `orm:"default(0)" json:"districtCode"` // 城市code
|
||||||
Address string `orm:"size(255)" json:"address"`
|
Address string `orm:"size(255)" json:"address"` // 地址
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Order) TableUnique() [][]string {
|
func (v *Order) TableUnique() [][]string {
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ type UserVendorOrder struct {
|
|||||||
Bulk float64 `orm:"column(bulk)" json:"bulk"` // 体积抛比系数
|
Bulk float64 `orm:"column(bulk)" json:"bulk"` // 体积抛比系数
|
||||||
Increment float64 `orm:"column(increment)" json:"increment"` // 增值(物流)
|
Increment float64 `orm:"column(increment)" json:"increment"` // 增值(物流)
|
||||||
ChannelType int `orm:"size(8);column(channel_type)" json:"channelType"` // 渠道类型(1-快递,2-物流,3-国际物流,4-整车)
|
ChannelType int `orm:"size(8);column(channel_type)" json:"channelType"` // 渠道类型(1-快递,2-物流,3-国际物流,4-整车)
|
||||||
OrderStatus int `orm:"size(8);column(order_status)" json:"orderType"` // 订单状态(1-待支付,2-支付失败,3-支付成功,4-取件,5-配送,6-,4-取消)
|
OrderStatus int `orm:"size(8);column(order_status)" json:"orderType"` // 订单状态(2-待支付,3-支付失败,4-支付成功,5-取件,6-配送,25-取消)
|
||||||
Img string `orm:"column(img)" json:"img"` // 包裹图片
|
Img string `orm:"column(img)" json:"img"` // 包裹图片
|
||||||
IsForward int `orm:"column(is_forward)" json:"isForward"` // 1否,2是
|
IsForward int `orm:"column(is_forward)" json:"isForward"` // 1否,2是 转寄单
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*UserVendorOrder) TableUnique() [][]string {
|
func (*UserVendorOrder) TableUnique() [][]string {
|
||||||
|
|||||||
@@ -66,16 +66,16 @@ func CreateWayOrder(ctx *jxcontext.Context, param *model.MakeOrderParamReq, user
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建三方订单
|
// 创建三方订单
|
||||||
otherId, err := createOtherOrder(param)
|
//otherId, err := createOtherOrder(param)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
//}
|
||||||
|
|
||||||
// 第三方数据创建成功,则创建本地数据
|
// 第三方数据创建成功,则创建本地数据
|
||||||
vendorOrder := &model.UserVendorOrder{
|
vendorOrder := &model.UserVendorOrder{
|
||||||
UserId: userId,
|
UserId: userId,
|
||||||
LocalWayBill: utils.Int64ToStr(time.Now().Unix()) + userId[:4], // 当前时间秒数加用户ID前四位
|
LocalWayBill: utils.Int64ToStr(time.Now().Unix()) + userId[:4], // 当前时间秒数加用户ID前四位
|
||||||
OtherWayBill: otherId,
|
OtherWayBill: utils.Int64ToStr(time.Now().Unix()) + userId[:4],
|
||||||
PromiseTimeType: param.PromiseTimeType,
|
PromiseTimeType: param.PromiseTimeType,
|
||||||
DeliveryType: param.DeliveryType,
|
DeliveryType: param.DeliveryType,
|
||||||
Goods: param.Goods,
|
Goods: param.Goods,
|
||||||
@@ -99,12 +99,54 @@ func CreateWayOrder(ctx *jxcontext.Context, param *model.MakeOrderParamReq, user
|
|||||||
Bulk: param.Bulk,
|
Bulk: param.Bulk,
|
||||||
Increment: param.Increment,
|
Increment: param.Increment,
|
||||||
ChannelType: param.ChannelType,
|
ChannelType: param.ChannelType,
|
||||||
OrderStatus: model.YES, // 创建
|
OrderStatus: 2, // 创建待支付
|
||||||
Img: param.Images,
|
Img: param.Images,
|
||||||
IsForward: model.YES,
|
IsForward: model.YES, //
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 事务创建待支付运单,和待支付order
|
||||||
|
db := dao.GetDB()
|
||||||
|
tdb, _ := dao.Begin(db)
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
dao.Rollback(db, tdb)
|
||||||
|
panic(r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// 添加运单表
|
||||||
dao.WrapAddIDCULEntity(vendorOrder, ctx.GetUserName())
|
dao.WrapAddIDCULEntity(vendorOrder, ctx.GetUserName())
|
||||||
return dao.CreateEntity(dao.GetDB(), vendorOrder)
|
if err := dao.CreateEntity(db, vendorOrder); err != nil {
|
||||||
|
dao.Rollback(db, tdb)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// 添加待支付订单表
|
||||||
|
orderPayStatus := &model.Order{
|
||||||
|
OrderID: vendorOrder.LocalWayBill,
|
||||||
|
UserID: vendorOrder.UserId,
|
||||||
|
Type: model.OrderTypePay,
|
||||||
|
OrderType: model.PayType4Express,
|
||||||
|
Way: "",
|
||||||
|
Status: model.OrderTypeCash, // 待支付状态
|
||||||
|
PayPrice: int(vendorOrder.ChannelFee * 100),
|
||||||
|
TransactionID: "",
|
||||||
|
PayFinishedAt: time.Time{},
|
||||||
|
PrepayID: "",
|
||||||
|
OriginalData: "",
|
||||||
|
Comment: "",
|
||||||
|
Lng: 0,
|
||||||
|
Lat: 0,
|
||||||
|
CityCode: 0,
|
||||||
|
DistrictCode: 0,
|
||||||
|
Address: "",
|
||||||
|
}
|
||||||
|
if err := dao.CreateEntity(db, orderPayStatus); err != nil {
|
||||||
|
dao.Rollback(db, tdb)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
dao.Commit(db, tdb)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CancelWayOrder 取消运单 todo
|
// CancelWayOrder 取消运单 todo
|
||||||
@@ -175,3 +217,9 @@ func QueryUserOrderList(userId string, expressType, orderStatus int, pageNum, pa
|
|||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateOrder2QBiDa 订单回调成功,且为运费支付时使用该接口
|
||||||
|
func CreateOrder2QBiDa(orderId string) {
|
||||||
|
// 加载订单
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,18 +11,21 @@ type OrderController struct {
|
|||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pay 订单支付
|
||||||
// @Title 支付
|
// @Title 支付
|
||||||
// @Description 支付
|
// @Description 支付
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
// @Param orderID formData string true "订单号"
|
// @Param orderID formData string true "订单号"
|
||||||
// @Param payType formData int true "支付平台类型"
|
// @Param payType formData int true "支付平台类型"
|
||||||
// @Param vendorPayType formData string true "平台支付类型"
|
// @Param vendorPayType formData string true "平台支付类型"
|
||||||
|
// @Param orderType formData string true "订单类型member(会员),express快递,recharge充值"
|
||||||
|
// @Param appId formData string true "appId"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /Pay [post]
|
// @router /Pay [post]
|
||||||
func (c *OrderController) Pay() {
|
func (c *OrderController) Pay() {
|
||||||
c.callPay(func(params *tOrderPayParams) (retVal interface{}, errCode string, err error) {
|
c.callPay(func(params *tOrderPayParams) (retVal interface{}, errCode string, err error) {
|
||||||
retVal, err = cms.Pay(params.Ctx, params.OrderID, params.PayType, params.VendorPayType)
|
retVal, err = cms.Pay(params.Ctx, params.OrderID, params.PayType, params.VendorPayType, params.AppId)
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user