From 57d94f82ed62db07e6f1d95a823cf58a7a6e88ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 24 Nov 2022 13:48:52 +0800 Subject: [PATCH] 1 --- business/jxstore/cms/order.go | 68 +++++++++++++-- business/jxstore/cms/recharge_server.go | 50 +++++++++++ business/jxstore/financial/financial.go | 24 ++---- business/jxstore/financial/pay.go | 46 +++++++++-- business/model/dao/dao_order.go | 61 ++++++++++++++ business/model/order.go | 45 ++++++---- conf/app.conf | 19 ++++- controllers/order_controller.go | 8 +- controllers/recharge_callback.go | 69 ++++++++++++++++ controllers/recharge_controller.go | 105 ++++++++++++++++++++++++ globals/api/api.go | 6 +- routers/commentsRouter_controllers.go | 41 +++++++++ routers/router.go | 8 ++ 13 files changed, 493 insertions(+), 57 deletions(-) create mode 100644 business/jxstore/cms/recharge_server.go create mode 100644 controllers/recharge_callback.go create mode 100644 controllers/recharge_controller.go diff --git a/business/jxstore/cms/order.go b/business/jxstore/cms/order.go index a4b54e2da..596e044a6 100644 --- a/business/jxstore/cms/order.go +++ b/business/jxstore/cms/order.go @@ -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 } diff --git a/business/jxstore/cms/recharge_server.go b/business/jxstore/cms/recharge_server.go new file mode 100644 index 000000000..8e8dd6ca5 --- /dev/null +++ b/business/jxstore/cms/recharge_server.go @@ -0,0 +1,50 @@ +package cms + +import ( + "errors" + "git.rosy.net.cn/baseapi/platformapi/recharge_phone_bill" + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/model" + "git.rosy.net.cn/jx-callback/business/model/dao" + "git.rosy.net.cn/jx-callback/globals/api" + "time" +) + +// QueryUserRecharge 用户查询充值列表 +func QueryUserRecharge(userId []string, mobile, orderId string, page, pageSize int, startTime, endTime string, rechargeStatus int) ([]*model.RechargeUserModelData, int, error) { + if page == 0 { + page = 1 + } + if pageSize == 0 { + pageSize = 10 + } + var start time.Time + var end time.Time + if startTime != "" { + start = utils.Str2Time(startTime) + } + if endTime != "" { + end = utils.Str2Time(endTime) + } + + return dao.QueryRechargeRecommend(userId, mobile, orderId, page, pageSize, start, end, rechargeStatus) +} + +// QueryUserOrderDetail 用户查询订单详情 +func QueryUserOrderDetail(orderId, mobile string) ([]recharge_phone_bill.QueryOrderDetailResList, error) { + data, err := api.TelephoneAPI.QueryOrderDetail("", orderId) + if err != nil { + return nil, err + } + have := false + for _, v := range data { + if v.Mobile == mobile { + have = true + } + } + + if have { + return data, err + } + return nil, errors.New("参数电话号码异常") +} diff --git a/business/jxstore/financial/financial.go b/business/jxstore/financial/financial.go index 079600a90..1ff5a63de 100644 --- a/business/jxstore/financial/financial.go +++ b/business/jxstore/financial/financial.go @@ -271,38 +271,30 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) { //充值会员 增加微信支付处理业务 if (order.OrderType == 2 || order.OrderType == 5) && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { - if err := OnWXPayFinished(order); err != nil { - return err - } return OnWXPayFinished(order) } + // 充值话费 + if order.OrderType == 7 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { + return OnWxPayTelephone(order) + } if order.OrderType == 3 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { - globals.SugarLogger.Debug("得到微信回调结果,快递流程开始") txdb, _ := dao.Begin(db) defer func() { if r := recover(); r != nil { panic(r) } }() - globals.SugarLogger.Debug("更新order") order.TransactionID = call.TrxID order.Status = 110 //支付成功状态 - globals.SugarLogger.Debug("输出赋值后的order.TransactionID", order.TransactionID) - if _, err := dao.UpdateEntityTx(txdb, order, "TransactionID"); err != nil { + if _, err := dao.UpdateEntityTx(txdb, order, "TransactionID", "Status"); err != nil { dao.Rollback(db, txdb) return err } - if _, err := dao.UpdateEntityTx(txdb, order, "Status"); err != nil { - dao.Rollback(db, txdb) - return err - } - globals.SugarLogger.Debug("获取UserVendorOrder") userOrder := model.UserVendorOrder{LocalWayBill: order.OrderID} if err := dao.GetEntity(db, &userOrder, "LocalWayBill"); err != nil { dao.Rollback(db, txdb) return err } - globals.SugarLogger.Debug("更新UserVendorOrder") userOrder.OrderStatus = payStatus if _, err := dao.UpdateEntityTx(txdb, &userOrder, "OrderStatus"); err != nil { dao.Rollback(db, txdb) @@ -310,24 +302,18 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) { } //1-余额,2-微信,5-混合 if order.PayMethod == 5 { - globals.SugarLogger.Debug("进入混合支付回调流程") userBill, err := dao.GetUserBill(db, order.UserID, "") if err != nil { return err } //创建混合支付账单 totalPrice := order.PayPrice + userBill.AccountBalance - globals.SugarLogger.Debug("totalPrice=================", totalPrice) - globals.SugarLogger.Debug("进入增加mixpay账单") if err := AddMixPay(txdb, order.OrderID, userBill.AccountBalance, totalPrice, 1); err != nil { - globals.SugarLogger.Debug("增加mixpay账单失败") dao.Rollback(db, txdb) return err } //余额清空 - globals.SugarLogger.Debug("开始清空余额") if err := dao.UpdateUserBill(order.UserID, 0); err != nil { - globals.SugarLogger.Debug("修改余额失败") dao.Rollback(db, txdb) return err } diff --git a/business/jxstore/financial/pay.go b/business/jxstore/financial/pay.go index a34da77ff..803130d3e 100644 --- a/business/jxstore/financial/pay.go +++ b/business/jxstore/financial/pay.go @@ -2,13 +2,13 @@ package financial import ( "fmt" + "git.rosy.net.cn/baseapi/platformapi/recharge_phone_bill" "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/globals" - "github.com/astaxie/beego/client/orm" - "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/globals" + "git.rosy.net.cn/jx-callback/globals/api" ) type PayHandler struct { @@ -106,11 +106,17 @@ func OnCashFinished(order *model.Order) (err error) { //微信支付充值会员 func OnWXPayFinished(order *model.Order) (err error) { var ( - db = dao.GetDB() - ctx *jxcontext.Context - txDB orm.TxOrmer + db = dao.GetDB() + ctx *jxcontext.Context + txDB, _ = dao.Begin(db) ) - globals.SugarLogger.Debugf("OnWXPayFinished begin modify account order: %v", utils.Format4Output(order, false)) + defer func() { + if r := recover(); r != nil { + dao.Rollback(db, txDB) + panic(r) + } + }() + //判断是新会员充值还是老会员续费 userMembers, err := dao.GetUserMember(db, order.UserID, model.MemberTypeNormal) if err != nil { @@ -131,12 +137,34 @@ func OnWXPayFinished(order *model.Order) (err error) { order.Status = model.OrderStatusFinished //更新order状态 if _, err := dao.UpdateEntityTx(txDB, &order, "Status"); err != nil { + dao.Rollback(db, txDB) return err } } else { - globals.SugarLogger.Debugf("OnWXPayFinished 暂不支持此订单类型 order: %v", utils.Format4Output(order, false)) return fmt.Errorf("暂不支持此订单类型!") } - globals.SugarLogger.Debug("OnWXPayFinished end modify account ...", err) return err } + +// OnWxPayTelephone 微信充值话费 +func OnWxPayTelephone(order *model.Order) error { + orderNumber, err := api.TelephoneAPI.RechargePhoneBill(&recharge_phone_bill.RechargePhoneBillBase{ + FlowCode: order.FlowCode, + Mobile: order.Mobile, + OrderNumber: order.OrderID, + CallbackURL: "http://callback.rsm.jxc4.com/recharge/msg", + ChargeType: "1", + }) + if err != nil { + order.Comment = err.Error() + order.RechargeStatus = -1 // 充值失败 + } + order.RechargeStatus = 1 // 充值中 + order.Comment = orderNumber + //更新order状态 + order.Status = model.OrderStatusFinished + if _, err := dao.UpdateEntity(dao.GetDB(), &order, "Status", "RechargeStatus", "Comment"); err != nil { + return err + } + return nil +} diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index f974b8de4..53fad7902 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -686,3 +686,64 @@ func SetOrderStatus(tx orm.TxOrmer, payPrice, payMethod, status int, orderID str } 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) + sql := `SELECT SQL_CALC_FOUND_ROWS o.*,u.name FROM order o ` + sqlParams := make([]interface{}, 0, 0) + + sql += ` JOIN user u ON o.user_id = u.user_id WHERE 1=1 ` + + if orderId != "" { + sql += ` AND o.order_id = ? ` + sqlParams = append(sqlParams, orderId) + if err := GetRows(GetDB(), &result, sql, sqlParams...); err != nil { + return nil, 0, err + } + return result, 1, nil + } + + if userId != nil { + sql += ` AND o.user_id IN (` + GenQuestionMarks(len(userId)) + `)` + sqlParams = append(sqlParams, userId) + } + + if !utils.IsTimeZero(start) { + sql += ` AND o.created_at > ?` + sqlParams = append(sqlParams, start) + } + if !utils.IsTimeZero(end) { + sql += ` AND o.created_at < ?` + sqlParams = append(sqlParams, end) + } + + if mobile != "" { + sql += ` AND o.mobile = ? ` + sqlParams = append(sqlParams, mobile) + } + + if rechargeStatus != 0 { + sql += ` AND o.recharge_status = ? ` + sqlParams = append(sqlParams, rechargeStatus) + } + + sql += " ORDER BY o.created_at DESC LIMIT ? OFFSET ?" + sqlParams = append(sqlParams, jxutils.FormalizePageSize(pageSize), (page-1)*pageSize) + + db := GetDB() + tx, _ := Begin(db) + defer func() { + if r := recover(); r != nil { + Rollback(db, tx) + } + }() + + if err := GetRowsTx(tx, &result, sql, sqlParams...); err != nil { + Rollback(db, tx) + return nil, 0, err + } + + count := GetLastTotalRowCountTx(tx) + return result, count, nil +} diff --git a/business/model/order.go b/business/model/order.go index 1033b2788..ca9a96f7e 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -67,24 +67,27 @@ var ( type Order struct { ModelIDCUL - OrderID string `orm:"column(order_id)" json:"orderID"` // 订单号 - UserID string `orm:"column(user_id);size(48)" json:"userID"` // 用户ID - Type int `json:"type"` // 支付还是提现 1-支付,2-提现 - OrderType int `json:"orderType"` // 订单类型,1-发任务,2-会员月卡,3-发快递,4-提现,5-会员年卡,6-使用充值到余额方式的订单 - Way string `json:"way"` // weixinapp ,weixinmini - Status int `json:"status"` // 订单状态,待支付2,已支付5,支付成功110,支付失败115,150取消 - PayPrice int `json:"payPrice"` // 支付金额 - TransactionID string `orm:"column(transaction_id);size(48)" json:"transactionID"` // 支付成功后,支付方生成的事务ID - PayFinishedAt time.Time `orm:"type(datetime);null" json:"payFinishedAt"` // 支付完成时间 - PrepayID string `orm:"column(prepay_id);size(48)" json:"prepayID"` // 下单后,支付前,支付方生成的事务ID - OriginalData string `orm:"type(text)" json:"-"` // - Comment string `orm:"size(255)" json:"comment"` // 备注 - Lng float64 `json:"lng"` // 坐标 - Lat float64 `json:"lat"` // 坐标 - CityCode int `orm:"default(0)" json:"cityCode"` // 提交订单时用户所在城市 - DistrictCode int `orm:"default(0)" json:"districtCode"` // 城市code - Address string `orm:"size(255)" json:"address"` // 地址 - PayMethod int `orm:"size(255)" json:"address"` // 支付方式1-余额支付,2-微信支付,3-微信提现,4-支付宝提现 5-余额+微信混合支付 + OrderID string `orm:"column(order_id)" json:"orderID"` // 订单号 + UserID string `orm:"column(user_id);size(48)" json:"userID"` // 用户ID + Type int `json:"type"` // 支付还是提现 1-支付,2-提现 + OrderType int `json:"orderType"` // 订单类型,1-发任务,2-会员月卡,3-发快递,4-提现,5-会员年卡,6-使用充值到余额方式的订单,7-话费 + Way string `json:"way"` // weixinapp ,weixinmini + Status int `json:"status"` // 订单状态,待支付2,已支付5,支付成功110,支付失败115,150取消 + PayPrice int `json:"payPrice"` // 支付金额 + TransactionID string `orm:"column(transaction_id);size(48)" json:"transactionID"` // 支付成功后,支付方生成的事务ID + PayFinishedAt time.Time `orm:"type(datetime);null" json:"payFinishedAt"` // 支付完成时间 + PrepayID string `orm:"column(prepay_id);size(48)" json:"prepayID"` // 下单后,支付前,支付方生成的事务ID + OriginalData string `orm:"type(text)" json:"-"` // + Comment string `orm:"size(255)" json:"comment"` // 备注 + Lng float64 `json:"lng"` // 坐标 + Lat float64 `json:"lat"` // 坐标 + CityCode int `orm:"default(0)" json:"cityCode"` // 提交订单时用户所在城市 + DistrictCode int `orm:"default(0)" json:"districtCode"` // 城市code + Address string `orm:"size(255)" json:"address"` // 地址 + PayMethod int `orm:"size(255)" json:"payMethod"` // 支付方式1-余额支付,2-微信支付,3-微信提现,4-支付宝提现 5-余额+微信混合支付 + Mobile string `orm:"size(15)" json:"mobile"` // 电话话费充值时使用 + FlowCode string `orm:"size(15)" json:"flowCode"` // 电话话费充值时使用 + RechargeStatus int `orm:"size(2)" json:"rechargeStatus"` // 充值状态 0-未提交,3-等待待充值(本地) 1:充值中(三方),2:已充值,-1:失败(三方) } func (v *Order) TableUnique() [][]string { @@ -200,3 +203,9 @@ type UnionOrderStatus struct { OrderStatusAt time.Time `json:"orderStatusAt"` //更新时间 Comment string `orm:"size(255)" json:"comment"` //备注 } + +// RechargeUserModelData 充值列表 +type RechargeUserModelData struct { + Order + Name string `json:"name" db:"name"` +} diff --git a/conf/app.conf b/conf/app.conf index 36b38a8da..6feb8843d 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -92,6 +92,10 @@ dbConnectStr = "root:WebServer@1@tcp(127.0.0.1:3306)/jxd_dev_0?charset=utf8mb4&l QBiDaAccess = "18048531223" QBiDaPassword = "18080188338" +#话费充值平台 账号 +AccountNo = "cdrxqgmc" +PasswordNo = "cdrxqgmc1234" +PhoneScenery = "cdrxqgmc123456" [beta] enableStoreWrite = true enableJdStoreWrite = false @@ -175,6 +179,10 @@ aliUpcAppCode = "00a6eefba0204d3fa310ac0ee7a6fc54" QBiDaAccess = "18048531223" QBiDaPassword = "18080188338" +#话费充值平台 账号 +AccountNo = "cdrxqgmc" +PasswordNo = "cdrxqgmc1234" +PhoneScenery = "cdrxqgmc123456" [rsm] EnableDocs = true @@ -283,6 +291,10 @@ pddAppSecret = "fa40c1fe356eebc1376ace1d2380ed44e553c602" QBiDaAccess = "18048531223" QBiDaPassword = "18080188338" +#话费充值平台 账号 +AccountNo = "cdrxqgmc" +PasswordNo = "cdrxqgmc1234" +PhoneScenery = "cdrxqgmc123456" [print] httpport = 8088 EnableDocs = false @@ -298,4 +310,9 @@ enableYbStoreWrite = true enableJdShopWrite = true #QBIDA 账号 QBiDaAccess = "18048531223" -QBiDaPassword = "18080188338" \ No newline at end of file +QBiDaPassword = "18080188338" + +#话费充值平台 账号 +AccountNo = "cdrxqgmc" +PasswordNo = "cdrxqgmc1234" +PhoneScenery = "cdrxqgmc123456" \ No newline at end of file diff --git a/controllers/order_controller.go b/controllers/order_controller.go index c418d8f32..d9c5f1986 100644 --- a/controllers/order_controller.go +++ b/controllers/order_controller.go @@ -18,7 +18,7 @@ type OrderController struct { // @Param orderID formData string true "订单号" // @Param payType formData int true "支付平台类型" // @Param vendorPayType formData string true "平台支付类型" -// @Param orderType formData string true "订单类型member(会员),express快递,recharge充值" +// @Param orderType formData string true "订单类型member(会员),express快递,recharge充值,telephoneBill充话费" // @Param appId formData string true "appId" // @Param isChoose formData int true "-1:未选中余额抵消 1:余额抵消" // @Success 200 {object} controllers.CallResult @@ -70,17 +70,19 @@ func (c *OrderController) Cash() { // @Description 创建订单 // @Param token header string true "认证token" // @Param type formData int true "支付类型/账单类型" -// @Param orderType formData int true "订单类型,1为发任务,2为冲会员,3为发快递,6-需要充值到余额购买的方式" +// @Param orderType formData int true "订单类型,1为发任务,2为冲会员,3为发快递,6-需要充值到余额购买的方式,7-话费充值" // @Param way formData string true "认证方式" // @Param price formData int true "支付金额" // @Param lng formData float64 true "经纬度" // @Param lat formData float64 true "经纬度" +// @Param mobile formData string false "充值电话" +// @Param flowCode formData string false "业务代码" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /CreateOrder [post] func (c *OrderController) CreateOrder() { c.callCreateOrder(func(params *tOrderCreateOrderParams) (retVal interface{}, errCode string, err error) { - retVal, errCode, err = cms.CreateOrder(params.Ctx, params.Type, params.OrderType, params.Way, params.Price, params.Lng, params.Lat) + retVal, errCode, err = cms.CreateOrder(params.Ctx, params.Type, params.OrderType, params.Way, params.Price, params.Lng, params.Lat, params.Mobile, params.FlowCode) return retVal, errCode, err }) } diff --git a/controllers/recharge_callback.go b/controllers/recharge_callback.go new file mode 100644 index 000000000..797856d16 --- /dev/null +++ b/controllers/recharge_callback.go @@ -0,0 +1,69 @@ +package controllers + +import ( + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/model" + "git.rosy.net.cn/jx-callback/business/model/dao" + "git.rosy.net.cn/jx-callback/globals" + beego "github.com/astaxie/beego/adapter" + "io/ioutil" + "net/http" +) + +type RechargeController struct { + beego.Controller +} + +type CallBackMsg struct { + Sign string `json:"sign"` // 签名:大写( md5( md5(密码)+ 平台订单号+秘钥 ) ) + Msg string `json:"msg"` // 响应结果描述 + OrderNumber string `json:"order_number "` // 平台订单号 + UserOrdernum string `json:"user_ordernum"` // 商户订单号 + OrderStatus string `json:"order_status"` // 状态:0:未提交,1:充值中,2:已充值,-1:失败 + Mobile string `json:"mobile"` // 电话 + Ctime string `json:"ctime"` // ctime + Voucher string `json:"voucher"` // 透传流水号 +} + +func (c *RechargeController) Msg() { + if c.Ctx.Input.Method() == http.MethodPost { + data, err := ioutil.ReadAll(getUsefulRequest2(c.Ctx).Body) + if err != nil { + c.Abort("404") + return + } + values, err := utils.HTTPBody2Values(data, false) + if err != nil { + c.Abort("404") + return + } + mapData := utils.URLValues2Map(values) + resultData := CallBackMsg{} + if err := utils.Map2StructByJson(mapData, &resultData, false); err != nil { + c.Abort("404") + return + } + + if resultData.OrderStatus == "0" || resultData.OrderStatus == "1" { + c.Data["json"] = "success" + c.ServeJSON() + return + } + // 获取平台订单 + order := &model.Order{ + OrderID: resultData.UserOrdernum, + } + if err = dao.GetEntity(dao.GetDB(), order, "OrderID"); err != nil { + globals.SugarLogger.Debugf("本地加载订单错误,请查询:%s", err) + c.Abort("404") + return + } + order.RechargeStatus = utils.Str2Int(resultData.OrderStatus) + + dao.UpdateEntity(dao.GetDB(), order, "RechargeStatus") + c.Data["json"] = "success" + c.ServeJSON() + } else { + c.Abort("404") + } +} diff --git a/controllers/recharge_controller.go b/controllers/recharge_controller.go new file mode 100644 index 000000000..a45b334dd --- /dev/null +++ b/controllers/recharge_controller.go @@ -0,0 +1,105 @@ +package controllers + +import ( + "errors" + "fmt" + "git.rosy.net.cn/jx-callback/business/jxstore/cms" + "git.rosy.net.cn/jx-callback/business/model/dao" + "git.rosy.net.cn/jx-callback/globals/api" + beego "github.com/astaxie/beego/adapter" +) + +type RechargeManagerController struct { + beego.Controller +} + +// GetUserRecharge 用户查询充值记录 +// @Title 分页查询用户充值列表 +// @Description 分页查询用户充值列表 +// @Param token header string true "认证token" +// @Param page formData int true "页码" +// @Param pageSize formData int true "页数" +// @Param mobile formData string false "电话" +// @Param orderId formData string false "订单号" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetUserRecharge [post] +func (c *RechargeManagerController) GetUserRecharge() { + c.callGetUserRecharge(func(params *tRechargeGetUserRechargeParams) (interface{}, string, error) { + result, count, err := cms.QueryUserRecharge([]string{params.Ctx.GetUserID()}, params.Mobile, params.OrderId, params.Page, params.PageSize, "", "", 0) + userRecharge := make(map[string]interface{}, 2) + userRecharge["data"] = result + userRecharge["count"] = count + return userRecharge, "", err + }) +} + +// GetRechargeOrderDetail 订单详情查询 +// @Title 订单详情查询 +// @Description 订单详情查询 +// @Param token header string true "认证token" +// @Param orderId formData string true "订单号" +// @Param mobile formData string true "手机号" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetRechargeOrderDetail [get] +func (c *RechargeManagerController) GetRechargeOrderDetail() { + c.callGetRechargeOrderDetail(func(params *tRechargeGetRechargeOrderDetailParams) (interface{}, string, error) { + result, err := cms.QueryUserOrderDetail(params.OrderId, params.Mobile) + return result, "", err + }) +} + +// SystemQueryRechargeList 管理系统获取订单详情 +// @Title 管理系统获取订单详情 +// @Description 管理系统获取订单详情 +// @Param token header string true "认证token" +// @Param orderId formData string false "订单号" +// @Param mobile formData string false "手机号" +// @Param rechargeStatus formData int false "充值状态 0-未提交,3-等待待充值(本地) 1:充值中(三方),2:已充值,-1:失败(三方)" +// @Param page formData int true "页码" +// @Param pageSize formData int true "页数" +// @Param startTime formData string true "开始时间" +// @Param endTime formData string true "结束时间" +// @Param userName formData string false "用户名" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /SystemQueryRechargeList [post] +func (c *RechargeManagerController) SystemQueryRechargeList() { + c.callSystemQueryRechargeList(func(params *tRechargeSystemQueryRechargeListParams) (interface{}, string, error) { + userIdList := make([]string, 0, 0) + // 根据用户获取用户id + if params.UserName != "" { + userList, _, err := dao.GetUsers(dao.GetDB(), 0, params.UserName, "", nil, nil, nil, 0, 0) + if err != nil { + return nil, "", err + } + if len(userList) == 0 { + return nil, "", errors.New(fmt.Sprintf("未查询到此用户:[%s]", params.UserName)) + } + for _, v := range userList { + userIdList = append(userIdList, v.UserID) + } + } + + result, count, err := cms.QueryUserRecharge(userIdList, params.Mobile, params.OrderId, params.Page, params.PageSize, params.StartTime, params.EndTime, params.RechargeStatus) + userRecharge := make(map[string]interface{}, 2) + userRecharge["data"] = result + userRecharge["count"] = count + return userRecharge, "", err + }) +} + +// QueryAccountBill 查询当前账号余额 +// @Title 查询当前账号余额 +// @Description 查询当前账号余额 +// @Param token header string true "认证token" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /QueryAccountBill [get] +func (c *RechargeManagerController) QueryAccountBill() { + c.callQueryAccountBill(func(params *tRechargeQueryAccountBillParams) (interface{}, string, error) { + balance, err := api.TelephoneAPI.QueryAccountBill() + return balance, "", err + }) +} diff --git a/globals/api/api.go b/globals/api/api.go index 00aa1efd9..935b4d806 100644 --- a/globals/api/api.go +++ b/globals/api/api.go @@ -4,6 +4,7 @@ import ( "git.rosy.net.cn/baseapi/platformapi/jdunionapi" "git.rosy.net.cn/baseapi/platformapi/pddapi" "git.rosy.net.cn/baseapi/platformapi/q_bida" + "git.rosy.net.cn/baseapi/platformapi/recharge_phone_bill" "git.rosy.net.cn/baseapi/platformapi/tbunionapi" "io/ioutil" @@ -86,7 +87,8 @@ var ( Cacher cache.ICacher SMSClient *aliyunsmsclient.SmsClient - QBiDaAPI *q_bida.Api // QBiDaApi + QBiDaAPI *q_bida.Api // QBiDaApi + TelephoneAPI *recharge_phone_bill.API // 话费充值 ) func init() { @@ -167,4 +169,6 @@ func Init() { // 初始化QBIDA QBiDaAPI = q_bida.NewQBiDa(beego.AppConfig.DefaultString("QBiDaAccess", ""), beego.AppConfig.DefaultString("QBiDaPassword", "")) + // 话费充值 + TelephoneAPI = recharge_phone_bill.New(beego.AppConfig.DefaultString("PasswordNo", ""), beego.AppConfig.DefaultString("AccountNo", ""), beego.AppConfig.DefaultString("PhoneScenery", "")) } diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index a84ae38c2..ba3eea9a0 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1152,4 +1152,45 @@ func init() { MethodParams: param.Make(), Filters: nil, Params: nil}) + + // 用户查询充值列表 + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:RechargeManagerController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:RechargeManagerController"], + beego.ControllerComments{ + Method: "GetUserRecharge", + Router: "/GetUserRecharge", + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + + // 用户查询平台订单详情 + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:RechargeManagerController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:RechargeManagerController"], + beego.ControllerComments{ + Method: "GetRechargeOrderDetail", + Router: "/GetRechargeOrderDetail", + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + + // 管理系统查询平台订单 + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:RechargeManagerController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:RechargeManagerController"], + beego.ControllerComments{ + Method: "SystemQueryRechargeList", + Router: "/SystemQueryRechargeList", + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + + // 查询当前账号余额 + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:RechargeManagerController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:RechargeManagerController"], + beego.ControllerComments{ + Method: "QueryAccountBill", + Router: "/QueryAccountBill", + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + } diff --git a/routers/router.go b/routers/router.go index 185886370..11ef05eb7 100644 --- a/routers/router.go +++ b/routers/router.go @@ -79,11 +79,19 @@ func init() { &controllers.WithdrawalRecordController{}, ), ), + + // 话费充值 + web.NSNamespace("/recharge", + web.NSInclude( + &controllers.RechargeManagerController{}, + ), + ), ) web.AddNamespace(ns) web.AutoRouter(&controllers.WXPayController{}) web.AutoRouter(&controllers.TongLianController{}) + web.AutoRouter(&controllers.RechargeController{}) // 充值话费回调 web.AutoRouter(&controllers.MTWMController{}) web.AutoRouter(&controllers.PrintController{}) //web.AutoRouter(&controllers.QBiDaExpressController{})