This commit is contained in:
邹宗楠
2022-11-24 13:48:52 +08:00
parent 3200ebd799
commit 57d94f82ed
13 changed files with 493 additions and 57 deletions

View File

@@ -1,10 +1,13 @@
package cms
import (
"errors"
"fmt"
"git.rosy.net.cn/baseapi/platformapi/recharge_phone_bill"
"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"
@@ -24,7 +27,7 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
)
func CreateOrder(ctx *jxcontext.Context, type1, orderType int, way string, price int, lng, lat float64) (orderID, errCode string, err error) {
func CreateOrder(ctx *jxcontext.Context, type1, orderType int, way string, price int, lng, lat float64, mobile, flowCode string) (orderID, errCode string, err error) {
var (
db = dao.GetDB()
order *model.Order
@@ -72,8 +75,23 @@ func CreateOrder(ctx *jxcontext.Context, type1, orderType int, way string, price
Address: address,
DistrictCode: dCode,
CityCode: cCode,
PayMethod: 4,
}
// 话费充值
if order.OrderType == 7 {
// 校验充值编号
have, err := CheckMobileAndFlowCode(mobile, flowCode)
if err != nil {
return "", "", err
}
if !have {
return "", "", errors.New("充值模板错误")
}
order.Mobile = mobile
order.FlowCode = flowCode
order.RechargeStatus = 3 // 当前系统待充值
}
dao.WrapAddIDCULEntity(order, ctx.GetUserName())
if err = dao.CreateEntityTx(txDB, order); err != nil {
dao.Rollback(db, txDB)
@@ -82,6 +100,48 @@ func CreateOrder(ctx *jxcontext.Context, type1, orderType int, way string, price
return order.OrderID, errCode, err
}
func CheckMobileAndFlowCode(mobile, flowCode string) (bool, error) {
// 校验业务电话和充值号码是否正确
if mobile == "" || flowCode == "" {
return false, errors.New("充值电话费用号码/业务代码不能为空")
}
regRuler := "^1[3456789]{1}\\d{9}$"
if !regexp.MustCompile(regRuler).MatchString(mobile) {
return false, errors.New("电话号码格式校验错误")
}
switch mobile[0:4] {
case "1703", "1705", "1706": // 中国移动
if flowCode == recharge_phone_bill.FlowCodeY10Y100 || flowCode == recharge_phone_bill.FlowCodeY10Y200 {
return true, nil
}
case "1704", "1707", "1708", "1709": // 中国联通
if flowCode == recharge_phone_bill.FlowCodeL10Y50 || flowCode == recharge_phone_bill.FlowCodeL10Y100 || flowCode == recharge_phone_bill.FlowCodeL10Y200 {
return true, nil
}
case "1700", "1701", "1702 ": // 中国电信
if flowCode == recharge_phone_bill.FlowCodeD10Y50 || flowCode == recharge_phone_bill.FlowCodeD10Y100 || flowCode == recharge_phone_bill.FlowCodeD10Y200 {
return true, nil
}
}
switch mobile[0:3] {
case "139", "138", "137", "136", "135", "134", "150", "151", "152", "157", "158", "159 182", "183", "184", "187", "188", "147", "198", "178 ", "165": // 中国移动
if flowCode == recharge_phone_bill.FlowCodeY10Y100 || flowCode == recharge_phone_bill.FlowCodeY10Y200 {
return true, nil
}
case "130", "131", "132", "155", "156", "185", "186", "175", "176", "166", "171", "167": // 中国联通
if flowCode == recharge_phone_bill.FlowCodeL10Y50 || flowCode == recharge_phone_bill.FlowCodeL10Y100 || flowCode == recharge_phone_bill.FlowCodeL10Y200 {
return true, nil
}
case "133", "153", "173", "177", "180", "181", "189", "191", "199": // 中国电信
if flowCode == recharge_phone_bill.FlowCodeD10Y50 || flowCode == recharge_phone_bill.FlowCodeD10Y100 || flowCode == recharge_phone_bill.FlowCodeD10Y200 {
return true, nil
}
}
return false, errors.New("运营商查询错误/充值编码错误")
}
func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, appId string, payPrice int) (result *financial.WxPayParam, err error) {
var (
temp_PayPrice int
@@ -117,7 +177,6 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
if _, err := dao.SetOrderStatus(txDB, temp_PayPrice, temp_PayMethod, orderInfo.Status, orderID); err != nil {
return nil, err
}
globals.SugarLogger.Debugf("pay begin……")
err = dao.GetEntity(db, order, "OrderID")
if order.OrderID == "" {
return result, fmt.Errorf("未找到此订单!")
@@ -125,14 +184,11 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
payHandler.Order = order
//如果用户没有对应账单信息就给他生成一条
// 给用户创建一个银行卡账户
globals.SugarLogger.Debug("create bill begin……")
userBill, err := dao.GetUserBill(db, order.UserID, "")
if userBill == nil {
err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID)
}
err = payHandler.CreatePay(txDB, appId)
globals.SugarLogger.Debug("the last step o f this program,return err……", err)
globals.SugarLogger.Debugf("result : %v", utils.Format4Output(payHandler.WxPayParam, false))
return payHandler.WxPayParam, err
}