浏览代码

1

add_mode
DengBiao 1年前
父节点
当前提交
57d3cefff1
共有 6 个文件被更改,包括 142 次插入12 次删除
  1. +41
    -2
      app/customer/hdl/hdl_call_back.go
  2. +3
    -2
      app/customer/hdl/hdl_central_kitchen_for_school_order.go
  3. +68
    -0
      app/customer/hdl/test/hdl_wx.go
  4. +4
    -4
      app/customer/md/wxpay.go
  5. +19
    -4
      app/customer/svc/order/svc_central_kitchen_for_school_order.go
  6. +7
    -0
      app/router/customer_router.go

+ 41
- 2
app/customer/hdl/hdl_call_back.go 查看文件

@@ -42,7 +42,7 @@ func AlipayJsApiCallBack(c *gin.Context) {
}

func WxJsApiCallBack(c *gin.Context) {
var req md.WxPayCallback
var req md.WxCallback
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
@@ -60,8 +60,9 @@ func WxJsApiCallBack(c *gin.Context) {
e.OutErr(c, e.ERR, "解密失败")
return
}

fmt.Println(">>>>>>>>>>", decryptString)
var resp md.WxPayDecryptAesCallback
var resp md.WxPayCallback
err = json.Unmarshal([]byte(decryptString), &resp)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
@@ -74,4 +75,42 @@ func WxJsApiCallBack(c *gin.Context) {
return
}
e.OutSuc(c, "success", nil)
return
}

func WxRefundApiCallBack(c *gin.Context) {
var req md.WxCallback
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
sysCfgDb := db.SysCfgDb{}
sysCfgDb.Set()
sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxSpMchApiV3Key)

//TODO::进行解密
decryptString, err := utils.DecryptAES256GCM(sysCfg[enum.WxSpMchApiV3Key], req.Resource.AssociatedData, req.Resource.Nonce, req.Resource.Ciphertext)
if err != nil {
e.OutErr(c, e.ERR, "解密失败")
return
}

fmt.Println(">>>>>>>>>>WxRefundApiCallBack<<<<<<<<<", decryptString)
//var resp md.WxPayCallback
//err = json.Unmarshal([]byte(decryptString), &resp)
//if err != nil {
// e.OutErr(c, e.ERR, err.Error())
// return
//}
//
//_, err = svc.DealCentralKitchenForSchoolOrderCallBackForWx(resp.OutTradeNo, resp.TransactionId, resp.TradeState)
//if err != nil {
// e.OutErr(c, e.ERR, err.Error())
// return
//}
e.OutSuc(c, "success", nil)
return
}

+ 3
- 2
app/customer/hdl/hdl_central_kitchen_for_school_order.go 查看文件

@@ -15,6 +15,7 @@ import (
)

func CentralKitchenForSchoolOrderList(c *gin.Context) {
platform := c.DefaultQuery("platform", "alipay")
var req md.CentralKitchenForSchoolOrderListReq
err := c.ShouldBindJSON(&req)
if err != nil {
@@ -23,12 +24,12 @@ func CentralKitchenForSchoolOrderList(c *gin.Context) {
e.OutErr(c, err1.Code, err1.Error())
return
}
list, total, err := svc.OrderList(req)
list, total, err := svc.OrderList(req, platform)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
sumTotal, err := svc.OrderStatistic(req)
sumTotal, err := svc.OrderStatistic(req, platform)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return


+ 68
- 0
app/customer/hdl/test/hdl_wx.go 查看文件

@@ -0,0 +1,68 @@
package test

import (
"applet/app/db"
"applet/app/e"
enum2 "applet/app/enum"
svc3 "applet/app/svc"
"applet/app/utils"
"github.com/gin-gonic/gin"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
"math"
"time"
)

func WxRefundsTest(c *gin.Context) {
outTradeNo := c.DefaultQuery("out_trade_no", "")
refund := c.DefaultQuery("refund", "")
centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{}
centralKitchenForSchoolPackageOrd.Set(outTradeNo)
ord, err := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd()
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
if ord == nil {
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应订单记录")
return
}
sysCfgDb := db.SysCfgDb{}
sysCfgDb.Set()
sysCfg := sysCfgDb.SysCfgFindWithDb(enum2.WxSpMchId)
client, err := svc3.NewWxPayClient(c)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
wxSvc := refunddomestic.RefundsApiService{Client: client}
outRequestNoSuffix := "_" + utils.Int64ToStr(time.Now().Unix())
outRequestNo := "r_" + ord.OutTradeNo + outRequestNoSuffix

resp, result, err := wxSvc.Create(c,
refunddomestic.CreateRequest{
SubMchid: core.String(sysCfg[enum2.WxSpMchId]),
OutTradeNo: core.String(ord.OutTradeNo),
OutRefundNo: core.String(outRequestNo),
Reason: core.String("央厨订餐退款"),
NotifyUrl: core.String("https://weixin.qq.com"),
Amount: &refunddomestic.AmountReq{
Currency: core.String("CNY"),
Refund: core.Int64(utils.StrToInt64(refund)),
Total: core.Int64(int64(math.Round(utils.StrToFloat64(ord.TotalPrice) * 100))),
},
},
)
if err != nil {
// 处理错误
println("call Create err:%s", err)
} else {
// 处理返回结果
println("status=%d resp=%s", result.Response.StatusCode, resp)
}
e.OutSuc(c, map[string]interface{}{
"resp": resp,
"result": result,
}, nil)
return
}

+ 4
- 4
app/customer/md/wxpay.go 查看文件

@@ -1,7 +1,7 @@
package md

// WxPayCallback 微信回调结构体
type WxPayCallback struct {
// WxCallback 微信回调结构体
type WxCallback struct {
Id string `json:"id"`
CreateTime string `json:"create_time"`
ResourceType string `json:"resource_type"`
@@ -16,8 +16,8 @@ type WxPayCallback struct {
} `json:"resource"`
}

// WxPayDecryptAesCallback 微信解密回调结构体
type WxPayDecryptAesCallback struct {
// WxPayCallback 微信支付回调结构体
type WxPayCallback struct {
SpMchid string `json:"sp_mchid"`
SubMchid string `json:"sub_mchid"`
SpAppid string `json:"sp_appid"`


+ 19
- 4
app/customer/svc/order/svc_central_kitchen_for_school_order.go 查看文件

@@ -2,6 +2,7 @@ package svc

import (
"applet/app/admin/svc/enterprise_manage"
enum2 "applet/app/customer/enum"
"applet/app/customer/md"
"applet/app/db"
"applet/app/db/model"
@@ -12,10 +13,16 @@ import (
"time"
)

func OrderList(req md.CentralKitchenForSchoolOrderListReq) (m []model.CentralKitchenForSchoolPackageOrd, total int64, err error) {
func OrderList(req md.CentralKitchenForSchoolOrderListReq, platform string) (m []model.CentralKitchenForSchoolPackageOrd, total int64, err error) {
sess := db.Db.Desc("id").Where("user_identity_id =?", req.UserIdentityId).
And("create_at >= ? And create_at <= ?", req.StartDate, req.EndDate).Limit(req.Limit, (req.Page-1)*req.Limit)
sess.And("ord_state = ?", req.OrdState)
if platform == "alipay" {
sess.And("pay_way = ?", enum2.PayWayForAli)
}
if platform == "wx" {
sess.And("pay_way = ?", enum2.PayWayForWx)
}
total, err = sess.FindAndCount(&m)
if err != nil {
return
@@ -23,9 +30,17 @@ func OrderList(req md.CentralKitchenForSchoolOrderListReq) (m []model.CentralKit
return
}

func OrderStatistic(req md.CentralKitchenForSchoolOrderListReq) (total float64, err error) {
var sql = fmt.Sprintf("SELECT SUM(total_price) AS sum_total FROM central_kitchen_for_school_package_ord where "+
"user_identity_id = '%d' and create_at >= '%s' And create_at <= '%s' and ord_state = '%d'", req.UserIdentityId, req.StartDate, req.EndDate, req.OrdState)
func OrderStatistic(req md.CentralKitchenForSchoolOrderListReq, platform string) (total float64, err error) {
var sql string
if platform == "alipay" {
sql = fmt.Sprintf("SELECT SUM(total_price) AS sum_total FROM central_kitchen_for_school_package_ord where "+
"user_identity_id = '%d' and create_at >= '%s' And create_at <= '%s' and ord_state = '%d' and pay_way = '%d'", req.UserIdentityId, req.StartDate, req.EndDate, req.OrdState, enum2.PayWayForAli)
}
if platform == "wx" {
sql = fmt.Sprintf("SELECT SUM(total_price) AS sum_total FROM central_kitchen_for_school_package_ord where "+
"user_identity_id = '%d' and create_at >= '%s' And create_at <= '%s' and ord_state = '%d' and pay_way = '%d'", req.UserIdentityId, req.StartDate, req.EndDate, req.OrdState, enum2.PayWayForWx)
}

mapArr1, err := db.QueryNativeString(db.Db, sql)
if err != nil {
return


+ 7
- 0
app/router/customer_router.go 查看文件

@@ -3,6 +3,7 @@ package router
import (
"applet/app/customer/hdl"
selfSupportForSchoolhdl "applet/app/customer/hdl/self_support_for_school"
"applet/app/customer/hdl/test"
"applet/app/customer/mw"
"github.com/gin-gonic/gin"
)
@@ -14,6 +15,7 @@ func CustomerInit(r *gin.RouterGroup) {
rSelfSupportForSchoolOrder(r.Group("/order/selfSupportForSchool"))
rSelfSupportForSchool(r.Group("/selfSupportForSchool"))
rUserIdentity(r.Group("/userIdentity"))
rTest(r.Group("/test"))

r.GET("/sanHu", hdl.SanHu)
r.POST("/test", hdl.Demo)
@@ -21,6 +23,7 @@ func CustomerInit(r *gin.RouterGroup) {
r.POST("/curlAlipayPlanetEcocampusApiRosterSignUpInfoTest", hdl.CurlAlipayPlanetEcocampusApiRosterSignUpInfo)
r.POST("/alipayJsApiCallBack", hdl.AlipayJsApiCallBack)
r.POST("/wxJsApiCallBack", hdl.WxJsApiCallBack)
r.POST("/wxRefundApiCallBack", hdl.WxRefundApiCallBack)

r.POST("/login", hdl.Login)
r.GET("/wxAppletLogin", hdl.WxAppletLogin)
@@ -64,6 +67,10 @@ func CustomerInit(r *gin.RouterGroup) {
}
}

func rTest(r *gin.RouterGroup) {
r.POST("/wxRefunds", test.WxRefundsTest) // 测试-微信退款
}

func rPay(r *gin.RouterGroup) {
r.Use(mw.Auth) //检测登录状态
r.POST("/buyPackage", hdl.BuyPackage) // 购买套餐


正在加载...
取消
保存