支付
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"git.rosy.net.cn/jx-print/dao"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
putils "git.rosy.net.cn/jx-print/utils"
|
||||
putils "git.rosy.net.cn/jx-print/putils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -2,8 +2,8 @@ package misc
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
putils "git.rosy.net.cn/jx-print/putils"
|
||||
"git.rosy.net.cn/jx-print/services"
|
||||
putils "git.rosy.net.cn/jx-print/utils"
|
||||
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"time"
|
||||
|
||||
@@ -1,7 +1,93 @@
|
||||
package services
|
||||
|
||||
import "git.rosy.net.cn/jx-print/model"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/tonglianpayapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-print/dao"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"git.rosy.net.cn/jx-print/putils"
|
||||
"git.rosy.net.cn/jx-print/services/api"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func CreateOrder(tokenInfo *model.TokenInfo) (err error) {
|
||||
return err
|
||||
var (
|
||||
findOrderPayPriceMap = map[string]func(db *sqlx.DB, typeID string) (int64, error){
|
||||
model.OrderTypeFlow: func(db *sqlx.DB, typeID string) (payPrice int64, err error) {
|
||||
var flowCfg []*model.FlowConfig
|
||||
if config, err2 := dao.GetConfig(db, model.ConfigTypeSys, model.OrderTypeFlow); err2 == nil && config != nil {
|
||||
if err = json.Unmarshal([]byte(config.Value), &flowCfg); err == nil && len(flowCfg) > 0 {
|
||||
for _, v := range flowCfg {
|
||||
if v.ID == utils.Str2Int(typeID) {
|
||||
payPrice = v.Price
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = err2
|
||||
}
|
||||
return payPrice, err
|
||||
},
|
||||
}
|
||||
|
||||
payFunc = map[string]func(db *sqlx.DB, order *model.PayOrder, vendorPayType string) (err error){
|
||||
model.PayTypeTL: func(db *sqlx.DB, order *model.PayOrder, vendorPayType string) (err error) {
|
||||
param := &tonglianpayapi.CreateUnitorderOrderParam{
|
||||
Trxamt: int(order.PayPrice),
|
||||
NotifyUrl: "http://print.jxc4.com/callback/tlPayCallback",
|
||||
Reqsn: order.OrderID,
|
||||
PayType: vendorPayType,
|
||||
}
|
||||
if vendorPayType != tonglianpayapi.PayTypeWxCode {
|
||||
return fmt.Errorf("暂不支持的支付类型!vendorPayType :%s", vendorPayType)
|
||||
}
|
||||
result, err := api.TLpayAPI.CreateUnitorderOrder(param)
|
||||
if err == nil {
|
||||
var result2 tonglianpayapi.PayInfo
|
||||
json.Unmarshal([]byte(result.PayInfo), &result2)
|
||||
order.PrepayID = result2.Package[strings.LastIndex(result2.Package, "=")+1 : len(result2.Package)]
|
||||
order.TransactionID = result.TrxID
|
||||
err = dao.Update(db, order, "prepay_id", "transaction_id")
|
||||
}
|
||||
return err
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func CreateOrder(tokenInfo *model.TokenInfo, orderType, origin, thingID, typeID string) (orderID string, err error) {
|
||||
var (
|
||||
db = globals.GetDB()
|
||||
now = time.Now()
|
||||
payPrice int64
|
||||
)
|
||||
if payPrice, err = findOrderPayPriceMap[orderType](db, typeID); err != nil {
|
||||
return "", err
|
||||
}
|
||||
orderID = utils.Int64ToStr(putils.GenOrderNo())
|
||||
payOrder := &model.PayOrder{
|
||||
CreatedAt: &now,
|
||||
OrderID: orderID,
|
||||
PayPrice: payPrice,
|
||||
UserID: tokenInfo.User.UserID,
|
||||
OrderType: orderType,
|
||||
Origin: origin,
|
||||
ThingID: thingID,
|
||||
TypeID: typeID,
|
||||
}
|
||||
err = dao.Insert(db, payOrder)
|
||||
return orderID, err
|
||||
}
|
||||
|
||||
func Pay(tokenInfo *model.TokenInfo, orderID, payType, vendorPayType string) (order *model.PayOrder, err error) {
|
||||
var (
|
||||
db = globals.GetDB()
|
||||
)
|
||||
order, _ = dao.GetOrder(db, orderID)
|
||||
err = payFunc[payType](db, order, vendorPayType)
|
||||
return order, err
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"git.rosy.net.cn/jx-print/dao"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
putils "git.rosy.net.cn/jx-print/utils"
|
||||
putils "git.rosy.net.cn/jx-print/putils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"git.rosy.net.cn/jx-print/dao"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
putils "git.rosy.net.cn/jx-print/putils"
|
||||
"git.rosy.net.cn/jx-print/services/api"
|
||||
putils "git.rosy.net.cn/jx-print/utils"
|
||||
|
||||
"time"
|
||||
)
|
||||
@@ -68,7 +68,7 @@ func SimFlowDaySettle() (err error) {
|
||||
sumIncome, _ := dao.GetSimFlowIncomeSum(db, v.IccID, monthBegin, monthEnd)
|
||||
sumExpend, _ := dao.GetSimFlowExpendSum(db, v.IccID, monthBegin, monthEnd)
|
||||
if sumIncome != nil && sumExpend != nil {
|
||||
if sumExpend.Flow-sumIncome.Flow <= 0 {
|
||||
if sumIncome.Flow-sumExpend.Flow <= 0 {
|
||||
v.FlowFlag = 1
|
||||
err = dao.Update(db, v, "flow_flag")
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"git.rosy.net.cn/jx-print/dao"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
putils "git.rosy.net.cn/jx-print/utils"
|
||||
putils "git.rosy.net.cn/jx-print/putils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"strings"
|
||||
|
||||
Reference in New Issue
Block a user