1
This commit is contained in:
@@ -4,9 +4,9 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/recharge_phone_bill"
|
||||
"git.rosy.net.cn/baseapi/platformapi/tonglianpayapi"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/event"
|
||||
"git.rosy.net.cn/jx-callback/business/q_bida"
|
||||
"github.com/astaxie/beego/client/orm"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -142,53 +142,90 @@ func CheckMobileAndFlowCode(mobile, flowCode string) (bool, error) {
|
||||
return false, errors.New("运营商查询错误/充值编码错误")
|
||||
}
|
||||
|
||||
func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, appId string, payPrice int) (result *financial.WxPayParam, err error) {
|
||||
func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, appId string, isChoose int) (result *financial.WxPayParam, err error) {
|
||||
var (
|
||||
temp_PayPrice int
|
||||
temp_PayMethod int
|
||||
txDB orm.TxOrmer
|
||||
db = dao.GetDB()
|
||||
txdb, _ = dao.Begin(db)
|
||||
)
|
||||
orderInfo, err := dao.GetOrderByID(dao.GetDB(), orderID)
|
||||
orderInfo, err := dao.GetOrderByID(db, orderID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
order = &model.Order{
|
||||
OrderID: orderID,
|
||||
PayPrice: orderInfo.PayPrice,
|
||||
UserID: orderInfo.UserID,
|
||||
}
|
||||
payHandler = &financial.PayHandler{
|
||||
PayType: payType,
|
||||
Ctx: ctx,
|
||||
VendorPayType: vendorPayType,
|
||||
}
|
||||
)
|
||||
//支付金额<原金额
|
||||
if payPrice < order.PayPrice {
|
||||
temp_PayPrice = payPrice
|
||||
temp_PayMethod = model.OrderPayMethodMix
|
||||
} else {
|
||||
if orderInfo.OrderType == 6 {
|
||||
return nil, errors.New("不能余额充值余额")
|
||||
}
|
||||
|
||||
// 用户是否使用余额抵消
|
||||
if isChoose == 1 { // 余额抵消
|
||||
// 查询用户余额
|
||||
userBill, err := dao.GetUserBill(db, ctx.GetUserID(), "")
|
||||
if err != nil || userBill == nil { // 出现错误或异常直接使用金钱支付
|
||||
temp_PayPrice = orderInfo.PayPrice
|
||||
temp_PayMethod = model.OrderPayMethodWX
|
||||
} else {
|
||||
if userBill.AccountBalance-orderInfo.PayPrice >= 0 { // 余额大于支付金额,使用余额支付
|
||||
switch orderInfo.OrderType { // 1-发任务,2-会员月卡,3-发快递,4-提现,5-会员年卡,6-使用充值到余额方式的订单,7-话费
|
||||
case 2, 5:
|
||||
if err := financial.OnWXPayFinished(orderInfo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case 3:
|
||||
call := &tonglianpayapi.CallBackResult{}
|
||||
call.TrxID = "ziDingYi_" + utils.Int64ToStr(time.Now().Unix())
|
||||
call.TrxStatus = tonglianpayapi.TrxStatusSuccess
|
||||
if err := financial.OnWxPaySendPage(dao.GetDB(), orderInfo, call, 4); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case 7:
|
||||
if err := financial.OnWxPayTelephone(orderInfo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, errors.New("其他待处理信息,联系管理员")
|
||||
}
|
||||
//账户支出
|
||||
if err = financial.AddExpendUpdateAccount(txdb, userBill, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 1); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
} else {
|
||||
// 混合支付
|
||||
temp_PayPrice = orderInfo.PayPrice - userBill.AccountBalance
|
||||
temp_PayMethod = model.OrderPayMethodMix
|
||||
//账户支出
|
||||
if err = financial.AddExpendUpdateAccount(txdb, userBill, model.BillTypePayByAccountBalance, userBill.AccountBalance, 1); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else { // 原价给
|
||||
temp_PayPrice = orderInfo.PayPrice
|
||||
temp_PayMethod = model.OrderPayMethodWX
|
||||
}
|
||||
//微信支付实际金额更新到数据库
|
||||
if _, err := dao.SetOrderStatus(txDB, temp_PayPrice, temp_PayMethod, orderInfo.Status, orderID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = dao.GetEntity(db, order, "OrderID")
|
||||
if order.OrderID == "" {
|
||||
return result, fmt.Errorf("未找到此订单!")
|
||||
}
|
||||
payHandler.Order = order
|
||||
|
||||
orderInfo.PayPrice = temp_PayPrice
|
||||
orderInfo.PayMethod = temp_PayMethod
|
||||
dao.UpdateEntity(dao.GetDB(), orderInfo, "PayPrice", "PayMethod")
|
||||
payHandler.Order = orderInfo
|
||||
//如果用户没有对应账单信息就给他生成一条
|
||||
// 给用户创建一个银行卡账户
|
||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||
userBill, err := dao.GetUserBill(db, orderInfo.UserID, "")
|
||||
if userBill == nil {
|
||||
err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID)
|
||||
err = financial.AddUserBill(txdb, jxutils.GenBillID(), orderInfo.UserID)
|
||||
}
|
||||
err = payHandler.CreatePay(txDB, appId)
|
||||
err = payHandler.CreatePay(txdb, appId)
|
||||
return payHandler.WxPayParam, err
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_Set(t *testing.T) {
|
||||
if _, err := dao.SetOrderStatus(110, 5, "165943225529BCVFdaX"); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/jx-callback/business/q_bida"
|
||||
"github.com/astaxie/beego/client/orm"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -277,55 +276,9 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
||||
if order.OrderType == 7 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
return OnWxPayTelephone(order)
|
||||
}
|
||||
// 发快递
|
||||
if order.OrderType == 3 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
txdb, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
order.TransactionID = call.TrxID
|
||||
order.Status = 110 //支付成功状态
|
||||
if _, err := dao.UpdateEntityTx(txdb, order, "TransactionID", "Status"); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
return err
|
||||
}
|
||||
userOrder := model.UserVendorOrder{LocalWayBill: order.OrderID}
|
||||
if err := dao.GetEntity(db, &userOrder, "LocalWayBill"); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
return err
|
||||
}
|
||||
userOrder.OrderStatus = payStatus
|
||||
if _, err := dao.UpdateEntityTx(txdb, &userOrder, "OrderStatus"); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
return err
|
||||
}
|
||||
//1-余额,2-微信,5-混合
|
||||
if order.PayMethod == 5 {
|
||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//创建混合支付账单
|
||||
totalPrice := order.PayPrice + userBill.AccountBalance
|
||||
if err := AddMixPay(txdb, order.OrderID, userBill.AccountBalance, totalPrice, 1); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
return err
|
||||
}
|
||||
//余额清空
|
||||
if err := dao.UpdateUserBill(order.UserID, 0); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
return err
|
||||
}
|
||||
}
|
||||
dao.Commit(db, txdb)
|
||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
switch order.OrderType {
|
||||
case model.PayType4Express:
|
||||
err = q_bida.CreateOrder2QBiDa(&userOrder, order.OrderID)
|
||||
}
|
||||
}
|
||||
return err
|
||||
return OnWxPaySendPage(db, order, call, payStatus)
|
||||
}
|
||||
//需要充值到余额方式 购买的
|
||||
if order.OrderType == 6 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
|
||||
@@ -3,10 +3,12 @@ package financial
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/recharge_phone_bill"
|
||||
"git.rosy.net.cn/baseapi/platformapi/tonglianpayapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"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/q_bida"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
@@ -168,3 +170,55 @@ func OnWxPayTelephone(order *model.Order) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// OnWxPaySendPage 发快递支付方
|
||||
func OnWxPaySendPage(db *dao.DaoDB, order *model.Order, call *tonglianpayapi.CallBackResult, payStatus int) (err error) {
|
||||
txdb, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
order.TransactionID = call.TrxID
|
||||
order.Status = 110 //支付成功状态
|
||||
if _, err := dao.UpdateEntityTx(txdb, order, "TransactionID", "Status"); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
return err
|
||||
}
|
||||
userOrder := model.UserVendorOrder{LocalWayBill: order.OrderID}
|
||||
if err := dao.GetEntity(db, &userOrder, "LocalWayBill"); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
return err
|
||||
}
|
||||
userOrder.OrderStatus = payStatus
|
||||
if _, err := dao.UpdateEntityTx(txdb, &userOrder, "OrderStatus"); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
return err
|
||||
}
|
||||
//1-余额,2-微信,5-混合
|
||||
if order.PayMethod == 5 {
|
||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//创建混合支付账单
|
||||
totalPrice := order.PayPrice + userBill.AccountBalance
|
||||
if err := AddMixPay(txdb, order.OrderID, userBill.AccountBalance, totalPrice, 1); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
return err
|
||||
}
|
||||
//余额清空
|
||||
if err := dao.UpdateUserBill(order.UserID, 0); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
return err
|
||||
}
|
||||
}
|
||||
dao.Commit(db, txdb)
|
||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
switch order.OrderType {
|
||||
case model.PayType4Express:
|
||||
err = q_bida.CreateOrder2QBiDa(&userOrder, order.OrderID)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -26,6 +26,11 @@ func GetUserBill(db *DaoDB, userID, billID string) (userBill *model.UserBill, er
|
||||
return userBill, err
|
||||
}
|
||||
|
||||
// 添加用户支出记录
|
||||
func AddUserExpend() {
|
||||
|
||||
}
|
||||
|
||||
func GetBillExpend(db *DaoDB, userID string, billType int, fromTime, toTime time.Time) (billExpends []*model.BillExpend, err error) {
|
||||
sql := `
|
||||
SELECT b.*
|
||||
|
||||
@@ -678,15 +678,6 @@ func SetUserVendorOrderStatus(tx orm.TxOrmer, localWayBillID string, status int)
|
||||
return "更新UserVendorOrder状态成功", err
|
||||
}
|
||||
|
||||
//更新order 价格和状态
|
||||
func SetOrderStatus(tx orm.TxOrmer, payPrice, payMethod, status int, orderID string) (string, error) {
|
||||
|
||||
if _, err := ExecuteSQL(GetDB(), "UPDATE `order` SET pay_price = ?,pay_method= ?,status=? WHERE order_id = ? ", []interface{}{payPrice, payMethod, status, orderID}...); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "更新Order状态成功", nil
|
||||
}
|
||||
|
||||
// QueryRechargeRecommend 电话充值记录查询
|
||||
func QueryRechargeRecommend(userId []string, mobile, orderId string, page, pageSize int, start, end time.Time, rechargeStatus int) ([]*model.RechargeUserModelData, int, error) {
|
||||
result := make([]*model.RechargeUserModelData, 0, 0)
|
||||
|
||||
@@ -20,7 +20,7 @@ type OrderController struct {
|
||||
// @Param vendorPayType formData string true "平台支付类型"
|
||||
// @Param orderType formData string true "订单类型member(会员),express快递,recharge充值,telephoneBill充话费"
|
||||
// @Param appId formData string true "appId"
|
||||
// @Param isChoose formData int true "-1:未选中余额抵消 1:余额抵消"
|
||||
// @Param isChoose formData int true "-1:未选中余额抵消 1:余额抵消"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /Pay [post]
|
||||
|
||||
Reference in New Issue
Block a user