1
This commit is contained in:
@@ -144,10 +144,10 @@ func CheckMobileAndFlowCode(mobile, flowCode string) (bool, error) {
|
|||||||
|
|
||||||
func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, appId string, isChoose 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 (
|
var (
|
||||||
temp_PayPrice int
|
tempPayprice int
|
||||||
temp_PayMethod int
|
tempPaymethod int
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
txdb, _ = dao.Begin(db)
|
tdb, _ = dao.Begin(db)
|
||||||
)
|
)
|
||||||
orderInfo, err := dao.GetOrderByID(db, orderID)
|
orderInfo, err := dao.GetOrderByID(db, orderID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -169,23 +169,23 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
|
|||||||
// 查询用户余额
|
// 查询用户余额
|
||||||
userBill, err := dao.GetUserBill(db, ctx.GetUserID(), "")
|
userBill, err := dao.GetUserBill(db, ctx.GetUserID(), "")
|
||||||
if err != nil || userBill == nil { // 出现错误或异常直接使用金钱支付
|
if err != nil || userBill == nil { // 出现错误或异常直接使用金钱支付
|
||||||
temp_PayPrice = orderInfo.PayPrice
|
tempPayprice = orderInfo.PayPrice
|
||||||
temp_PayMethod = model.OrderPayMethodWX
|
tempPaymethod = model.OrderPayMethodWX
|
||||||
} else {
|
} else {
|
||||||
if userBill.AccountBalance-orderInfo.PayPrice >= 0 { // 余额大于支付金额,使用余额支付
|
if userBill.AccountBalance-orderInfo.PayPrice >= 0 { // 余额大于支付金额,使用余额支付
|
||||||
switch orderInfo.OrderType { // 1-发任务,2-会员月卡,3-发快递,4-提现,5-会员年卡,6-使用充值到余额方式的订单,7-话费
|
switch orderInfo.OrderType { // 1-发任务,2-会员月卡,3-发快递,4-提现,5-会员年卡,6-使用充值到余额方式的订单,7-话费
|
||||||
case 2, 5:
|
case model.OrderTypeMember, model.OrderTypeMemberYear:
|
||||||
if err := financial.OnWXPayFinished(orderInfo); err != nil {
|
if err := financial.OnWXPayFinished(orderInfo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case 3:
|
case model.OrderTypeDelivery:
|
||||||
call := &tonglianpayapi.CallBackResult{}
|
call := &tonglianpayapi.CallBackResult{}
|
||||||
call.TrxID = "ziDingYi_" + utils.Int64ToStr(time.Now().Unix())
|
call.TrxID = "ziDingYi_" + utils.Int64ToStr(time.Now().Unix())
|
||||||
call.TrxStatus = tonglianpayapi.TrxStatusSuccess
|
call.TrxStatus = tonglianpayapi.TrxStatusSuccess
|
||||||
if err := financial.OnWxPaySendPage(dao.GetDB(), orderInfo, call, 4); err != nil {
|
if err := financial.OnWxPaySendPage(dao.GetDB(), orderInfo, call, 4); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case 7:
|
case model.OrderTypeMobile:
|
||||||
if err := financial.OnWxPayTelephone(orderInfo); err != nil {
|
if err := financial.OnWxPayTelephone(orderInfo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -193,39 +193,39 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
|
|||||||
return nil, errors.New("其他待处理信息,联系管理员")
|
return nil, errors.New("其他待处理信息,联系管理员")
|
||||||
}
|
}
|
||||||
//账户支出
|
//账户支出
|
||||||
if err = financial.AddExpendUpdateAccount(txdb, userBill, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 1); err != nil {
|
if err = financial.AddExpendUpdateAccount(tdb, userBill, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 1); err != nil {
|
||||||
dao.Rollback(db, txdb)
|
dao.Rollback(db, tdb)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
} else {
|
} else {
|
||||||
// 混合支付
|
// 混合支付
|
||||||
temp_PayPrice = orderInfo.PayPrice - userBill.AccountBalance
|
tempPayprice = orderInfo.PayPrice - userBill.AccountBalance
|
||||||
temp_PayMethod = model.OrderPayMethodMix
|
tempPaymethod = model.OrderPayMethodMix
|
||||||
//账户支出
|
//账户支出
|
||||||
if err = financial.AddExpendUpdateAccount(txdb, userBill, model.BillTypePayByAccountBalance, userBill.AccountBalance, 1); err != nil {
|
if err = financial.AddExpendUpdateAccount(tdb, userBill, model.BillTypePayByAccountBalance, userBill.AccountBalance, 1); err != nil {
|
||||||
dao.Rollback(db, txdb)
|
dao.Rollback(db, tdb)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else { // 原价给
|
} else { // 原价给
|
||||||
temp_PayPrice = orderInfo.PayPrice
|
tempPayprice = orderInfo.PayPrice
|
||||||
temp_PayMethod = model.OrderPayMethodWX
|
tempPaymethod = model.OrderPayMethodWX
|
||||||
}
|
}
|
||||||
|
|
||||||
orderInfo.PayPrice = temp_PayPrice
|
orderInfo.PayPrice = tempPayprice
|
||||||
orderInfo.PayMethod = temp_PayMethod
|
orderInfo.PayMethod = tempPaymethod
|
||||||
dao.UpdateEntity(dao.GetDB(), orderInfo, "PayPrice", "PayMethod")
|
dao.UpdateEntity(dao.GetDB(), orderInfo, "PayPrice", "PayMethod")
|
||||||
payHandler.Order = orderInfo
|
payHandler.Order = orderInfo
|
||||||
//如果用户没有对应账单信息就给他生成一条
|
//如果用户没有对应账单信息就给他生成一条
|
||||||
// 给用户创建一个银行卡账户
|
// 给用户创建一个银行卡账户
|
||||||
userBill, err := dao.GetUserBill(db, orderInfo.UserID, "")
|
userBill, err := dao.GetUserBill(db, orderInfo.UserID, "")
|
||||||
if userBill == nil {
|
if userBill == nil {
|
||||||
err = financial.AddUserBill(txdb, jxutils.GenBillID(), orderInfo.UserID)
|
err = financial.AddUserBill(tdb, jxutils.GenBillID(), orderInfo.UserID)
|
||||||
}
|
}
|
||||||
err = payHandler.CreatePay(txdb, appId)
|
err = payHandler.CreatePay(tdb, appId)
|
||||||
return payHandler.WxPayParam, err
|
return payHandler.WxPayParam, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,12 +235,10 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
|||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
)
|
)
|
||||||
//获取订单信息
|
//获取订单信息
|
||||||
globals.SugarLogger.Debug("begin get pay_by_balance")
|
|
||||||
orderInfo, err := dao.GetOrderByID(db, orderID)
|
orderInfo, err := dao.GetOrderByID(db, orderID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "获取订单信息失败", err
|
return nil, "获取订单信息失败", err
|
||||||
}
|
}
|
||||||
globals.SugarLogger.Debug("orderInfo.OrderType===============", orderInfo.OrderType)
|
|
||||||
//获取用户 会员账户信息
|
//获取用户 会员账户信息
|
||||||
userBill, err := dao.GetUserBill(db, orderInfo.UserID, "")
|
userBill, err := dao.GetUserBill(db, orderInfo.UserID, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -320,7 +318,6 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
|||||||
//(2)用户使用余额,剩余微信支付
|
//(2)用户使用余额,剩余微信支付
|
||||||
totalPrice := orderInfo.PayPrice //订单原价
|
totalPrice := orderInfo.PayPrice //订单原价
|
||||||
needPay := totalPrice - userBill.AccountBalance //需支付金额
|
needPay := totalPrice - userBill.AccountBalance //需支付金额
|
||||||
globals.SugarLogger.Debug("totalprice=====,needpay=====", totalPrice, needPay)
|
|
||||||
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, needPay)
|
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, needPay)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "微信支付失败:", err
|
return nil, "微信支付失败:", err
|
||||||
@@ -331,7 +328,6 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
|||||||
}
|
}
|
||||||
if isChoose == model.PayNotChooseBalance {
|
if isChoose == model.PayNotChooseBalance {
|
||||||
//(3)不选中余额支付 即直接微信支付
|
//(3)不选中余额支付 即直接微信支付
|
||||||
globals.SugarLogger.Debug("进入PayNotChooseBalance==================")
|
|
||||||
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
|
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "微信支付失败:", err
|
return nil, "微信支付失败:", err
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
|||||||
t1, _ := time.ParseInLocation("20060102150405", call.PayTime, loc)
|
t1, _ := time.ParseInLocation("20060102150405", call.PayTime, loc)
|
||||||
order.PayFinishedAt = t1
|
order.PayFinishedAt = t1
|
||||||
order.OriginalData = utils.Format4Output(call, true)
|
order.OriginalData = utils.Format4Output(call, true)
|
||||||
payStatus := 0
|
payStatus := model.PayStatusNo
|
||||||
//order.PayMethod = 2 // 通联微信支付
|
//order.PayMethod = 2 // 通联微信支付
|
||||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||||
order.Status = model.OrderStatusFinished
|
order.Status = model.OrderStatusFinished
|
||||||
@@ -269,19 +269,19 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//充值会员 增加微信支付处理业务
|
//充值会员 增加微信支付处理业务
|
||||||
if (order.OrderType == 2 || order.OrderType == 5) && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
if (order.OrderType == model.OrderTypeMember || order.OrderType == model.OrderTypeMemberYear) && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||||
return OnWXPayFinished(order)
|
return OnWXPayFinished(order)
|
||||||
}
|
}
|
||||||
// 充值话费
|
// 充值话费
|
||||||
if order.OrderType == 7 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
if order.OrderType == model.OrderTypeMobile && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||||
return OnWxPayTelephone(order)
|
return OnWxPayTelephone(order)
|
||||||
}
|
}
|
||||||
// 发快递
|
// 发快递
|
||||||
if order.OrderType == 3 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
if order.OrderType == model.OrderTypeDelivery && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||||
return OnWxPaySendPage(db, order, call, payStatus)
|
return OnWxPaySendPage(db, order, call, payStatus)
|
||||||
}
|
}
|
||||||
//需要充值到余额方式 购买的
|
//需要充值到余额方式 购买的
|
||||||
if order.OrderType == 6 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
if order.OrderType == model.OrderTypeBalance && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||||
if err := dao.UpdateUserBill(order.UserID, order.PayPrice); err != nil {
|
if err := dao.UpdateUserBill(order.UserID, order.PayPrice); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ func OnWxPaySendPage(db *dao.DaoDB, order *model.Order, call *tonglianpayapi.Cal
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//1-余额,2-微信,5-混合
|
//1-余额,2-微信,5-混合
|
||||||
if order.PayMethod == 5 {
|
if order.PayMethod == model.OrderPayMethodMix {
|
||||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -681,7 +681,7 @@ func SetUserVendorOrderStatus(tx orm.TxOrmer, localWayBillID string, status int)
|
|||||||
// QueryRechargeRecommend 电话充值记录查询
|
// QueryRechargeRecommend 电话充值记录查询
|
||||||
func QueryRechargeRecommend(userId []string, mobile, orderId string, page, pageSize int, start, end time.Time, rechargeStatus int) ([]*model.RechargeUserModelData, int, error) {
|
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)
|
result := make([]*model.RechargeUserModelData, 0, 0)
|
||||||
sql := `SELECT SQL_CALC_FOUND_ROWS o.*,u.name FROM order o `
|
sql := `SELECT SQL_CALC_FOUND_ROWS o.*,u.name FROM ` + "`order`" + ` o`
|
||||||
sqlParams := make([]interface{}, 0, 0)
|
sqlParams := make([]interface{}, 0, 0)
|
||||||
|
|
||||||
sql += ` JOIN user u ON o.user_id = u.user_id WHERE 1=1 `
|
sql += ` JOIN user u ON o.user_id = u.user_id WHERE 1=1 `
|
||||||
@@ -701,11 +701,11 @@ func QueryRechargeRecommend(userId []string, mobile, orderId string, page, pageS
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !utils.IsTimeZero(start) {
|
if !utils.IsTimeZero(start) {
|
||||||
sql += ` AND o.created_at > ?`
|
sql += ` AND o.created_at > ? `
|
||||||
sqlParams = append(sqlParams, start)
|
sqlParams = append(sqlParams, start)
|
||||||
}
|
}
|
||||||
if !utils.IsTimeZero(end) {
|
if !utils.IsTimeZero(end) {
|
||||||
sql += ` AND o.created_at < ?`
|
sql += ` AND o.created_at < ? `
|
||||||
sqlParams = append(sqlParams, end)
|
sqlParams = append(sqlParams, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ const (
|
|||||||
OrderTypeMemberYear = 5 //充值会员年卡
|
OrderTypeMemberYear = 5 //充值会员年卡
|
||||||
OrderTypeDelivery = 3 //发快递
|
OrderTypeDelivery = 3 //发快递
|
||||||
OrderTypeDropShipping = 4 //一件代发交钱
|
OrderTypeDropShipping = 4 //一件代发交钱
|
||||||
|
OrderTypeMobile = 7 //充话费
|
||||||
|
OrderTypeBalance = 6 //余额充值
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
Reference in New Issue
Block a user