@@ -42,7 +42,7 @@ func AlipayJsApiCallBack(c *gin.Context) { | |||||
} | } | ||||
func WxJsApiCallBack(c *gin.Context) { | func WxJsApiCallBack(c *gin.Context) { | ||||
var req md.WxPayCallback | |||||
var req md.WxCallback | |||||
err := c.ShouldBindJSON(&req) | err := c.ShouldBindJSON(&req) | ||||
if err != nil { | if err != nil { | ||||
err = validate.HandleValidateErr(err) | err = validate.HandleValidateErr(err) | ||||
@@ -60,8 +60,9 @@ func WxJsApiCallBack(c *gin.Context) { | |||||
e.OutErr(c, e.ERR, "解密失败") | e.OutErr(c, e.ERR, "解密失败") | ||||
return | return | ||||
} | } | ||||
fmt.Println(">>>>>>>>>>", decryptString) | fmt.Println(">>>>>>>>>>", decryptString) | ||||
var resp md.WxPayDecryptAesCallback | |||||
var resp md.WxPayCallback | |||||
err = json.Unmarshal([]byte(decryptString), &resp) | err = json.Unmarshal([]byte(decryptString), &resp) | ||||
if err != nil { | if err != nil { | ||||
e.OutErr(c, e.ERR, err.Error()) | e.OutErr(c, e.ERR, err.Error()) | ||||
@@ -74,4 +75,42 @@ func WxJsApiCallBack(c *gin.Context) { | |||||
return | return | ||||
} | } | ||||
e.OutSuc(c, "success", nil) | 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 | |||||
} | } |
@@ -15,6 +15,7 @@ import ( | |||||
) | ) | ||||
func CentralKitchenForSchoolOrderList(c *gin.Context) { | func CentralKitchenForSchoolOrderList(c *gin.Context) { | ||||
platform := c.DefaultQuery("platform", "alipay") | |||||
var req md.CentralKitchenForSchoolOrderListReq | var req md.CentralKitchenForSchoolOrderListReq | ||||
err := c.ShouldBindJSON(&req) | err := c.ShouldBindJSON(&req) | ||||
if err != nil { | if err != nil { | ||||
@@ -23,12 +24,12 @@ func CentralKitchenForSchoolOrderList(c *gin.Context) { | |||||
e.OutErr(c, err1.Code, err1.Error()) | e.OutErr(c, err1.Code, err1.Error()) | ||||
return | return | ||||
} | } | ||||
list, total, err := svc.OrderList(req) | |||||
list, total, err := svc.OrderList(req, platform) | |||||
if err != nil { | if err != nil { | ||||
e.OutErr(c, e.ERR, err.Error()) | e.OutErr(c, e.ERR, err.Error()) | ||||
return | return | ||||
} | } | ||||
sumTotal, err := svc.OrderStatistic(req) | |||||
sumTotal, err := svc.OrderStatistic(req, platform) | |||||
if err != nil { | if err != nil { | ||||
e.OutErr(c, e.ERR, err.Error()) | e.OutErr(c, e.ERR, err.Error()) | ||||
return | return | ||||
@@ -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 | |||||
} |
@@ -1,7 +1,7 @@ | |||||
package md | package md | ||||
// WxPayCallback 微信回调结构体 | |||||
type WxPayCallback struct { | |||||
// WxCallback 微信回调结构体 | |||||
type WxCallback struct { | |||||
Id string `json:"id"` | Id string `json:"id"` | ||||
CreateTime string `json:"create_time"` | CreateTime string `json:"create_time"` | ||||
ResourceType string `json:"resource_type"` | ResourceType string `json:"resource_type"` | ||||
@@ -16,8 +16,8 @@ type WxPayCallback struct { | |||||
} `json:"resource"` | } `json:"resource"` | ||||
} | } | ||||
// WxPayDecryptAesCallback 微信解密回调结构体 | |||||
type WxPayDecryptAesCallback struct { | |||||
// WxPayCallback 微信支付回调结构体 | |||||
type WxPayCallback struct { | |||||
SpMchid string `json:"sp_mchid"` | SpMchid string `json:"sp_mchid"` | ||||
SubMchid string `json:"sub_mchid"` | SubMchid string `json:"sub_mchid"` | ||||
SpAppid string `json:"sp_appid"` | SpAppid string `json:"sp_appid"` | ||||
@@ -2,6 +2,7 @@ package svc | |||||
import ( | import ( | ||||
"applet/app/admin/svc/enterprise_manage" | "applet/app/admin/svc/enterprise_manage" | ||||
enum2 "applet/app/customer/enum" | |||||
"applet/app/customer/md" | "applet/app/customer/md" | ||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/db/model" | "applet/app/db/model" | ||||
@@ -12,10 +13,16 @@ import ( | |||||
"time" | "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). | 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) | And("create_at >= ? And create_at <= ?", req.StartDate, req.EndDate).Limit(req.Limit, (req.Page-1)*req.Limit) | ||||
sess.And("ord_state = ?", req.OrdState) | 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) | total, err = sess.FindAndCount(&m) | ||||
if err != nil { | if err != nil { | ||||
return | return | ||||
@@ -23,9 +30,17 @@ func OrderList(req md.CentralKitchenForSchoolOrderListReq) (m []model.CentralKit | |||||
return | 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) | mapArr1, err := db.QueryNativeString(db.Db, sql) | ||||
if err != nil { | if err != nil { | ||||
return | return | ||||
@@ -3,6 +3,7 @@ package router | |||||
import ( | import ( | ||||
"applet/app/customer/hdl" | "applet/app/customer/hdl" | ||||
selfSupportForSchoolhdl "applet/app/customer/hdl/self_support_for_school" | selfSupportForSchoolhdl "applet/app/customer/hdl/self_support_for_school" | ||||
"applet/app/customer/hdl/test" | |||||
"applet/app/customer/mw" | "applet/app/customer/mw" | ||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
) | ) | ||||
@@ -14,6 +15,7 @@ func CustomerInit(r *gin.RouterGroup) { | |||||
rSelfSupportForSchoolOrder(r.Group("/order/selfSupportForSchool")) | rSelfSupportForSchoolOrder(r.Group("/order/selfSupportForSchool")) | ||||
rSelfSupportForSchool(r.Group("/selfSupportForSchool")) | rSelfSupportForSchool(r.Group("/selfSupportForSchool")) | ||||
rUserIdentity(r.Group("/userIdentity")) | rUserIdentity(r.Group("/userIdentity")) | ||||
rTest(r.Group("/test")) | |||||
r.GET("/sanHu", hdl.SanHu) | r.GET("/sanHu", hdl.SanHu) | ||||
r.POST("/test", hdl.Demo) | r.POST("/test", hdl.Demo) | ||||
@@ -21,6 +23,7 @@ func CustomerInit(r *gin.RouterGroup) { | |||||
r.POST("/curlAlipayPlanetEcocampusApiRosterSignUpInfoTest", hdl.CurlAlipayPlanetEcocampusApiRosterSignUpInfo) | r.POST("/curlAlipayPlanetEcocampusApiRosterSignUpInfoTest", hdl.CurlAlipayPlanetEcocampusApiRosterSignUpInfo) | ||||
r.POST("/alipayJsApiCallBack", hdl.AlipayJsApiCallBack) | r.POST("/alipayJsApiCallBack", hdl.AlipayJsApiCallBack) | ||||
r.POST("/wxJsApiCallBack", hdl.WxJsApiCallBack) | r.POST("/wxJsApiCallBack", hdl.WxJsApiCallBack) | ||||
r.POST("/wxRefundApiCallBack", hdl.WxRefundApiCallBack) | |||||
r.POST("/login", hdl.Login) | r.POST("/login", hdl.Login) | ||||
r.GET("/wxAppletLogin", hdl.WxAppletLogin) | 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) { | func rPay(r *gin.RouterGroup) { | ||||
r.Use(mw.Auth) //检测登录状态 | r.Use(mw.Auth) //检测登录状态 | ||||
r.POST("/buyPackage", hdl.BuyPackage) // 购买套餐 | r.POST("/buyPackage", hdl.BuyPackage) // 购买套餐 | ||||