소스 검색

update

add_mode
DengBiao 1 년 전
부모
커밋
89fc788173
4개의 변경된 파일186개의 추가작업 그리고 0개의 파일을 삭제
  1. +40
    -0
      app/customer/hdl/hdl_call_back.go
  2. +43
    -0
      app/customer/md/wxpay.go
  3. +102
    -0
      app/customer/svc/svc_pay.go
  4. +1
    -0
      app/router/customer_router.go

+ 40
- 0
app/customer/hdl/hdl_call_back.go 파일 보기

@@ -1,11 +1,16 @@
package hdl

import (
"applet/app/admin/lib/validate"
"applet/app/customer/md"
"applet/app/customer/svc"
"applet/app/db"
"applet/app/e"
"applet/app/enum"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/wechatpay-apiv3/wechatpay-go/utils"
)

func AlipayJsApiCallBack(c *gin.Context) {
@@ -35,3 +40,38 @@ func AlipayJsApiCallBack(c *gin.Context) {
//c.Header("Content-Type", "text/html; charset=utf-8")
c.String(200, "success")
}

func WxJsApiCallBack(c *gin.Context) {
var req md.WxPayCallback
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(">>>>>>>>>>", decryptString)
var resp md.WxPayDecryptAesCallback
err = json.Unmarshal([]byte(decryptString), &resp)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}

_, err = svc.DealCentralKitchenForSchoolOrderCallBackForWx(resp.OutTradeNo, resp.TradeState)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
e.OutSuc(c, "success", nil)
}

+ 43
- 0
app/customer/md/wxpay.go 파일 보기

@@ -0,0 +1,43 @@
package md

// WxPayCallback 微信回调结构体
type WxPayCallback struct {
Id string `json:"id"`
CreateTime string `json:"create_time"`
ResourceType string `json:"resource_type"`
EventType string `json:"event_type"`
Summary string `json:"summary"`
Resource struct {
OriginalType string `json:"original_type"`
Algorithm string `json:"algorithm"`
Ciphertext string `json:"ciphertext"`
AssociatedData string `json:"associated_data"`
Nonce string `json:"nonce"`
} `json:"resource"`
}

// WxPayDecryptAesCallback 微信解密回调结构体
type WxPayDecryptAesCallback struct {
SpMchid string `json:"sp_mchid"`
SubMchid string `json:"sub_mchid"`
SpAppid string `json:"sp_appid"`
SubAppid string `json:"sub_appid"`
OutTradeNo string `json:"out_trade_no"`
TransactionId string `json:"transaction_id"`
TradeType string `json:"trade_type"`
TradeState string `json:"trade_state"`
TradeStateDesc string `json:"trade_state_desc"`
BankType string `json:"bank_type"`
Attach string `json:"attach"`
SuccessTime string `json:"success_time"`
Payer struct {
SpOpenid string `json:"sp_openid"`
SubOpenid string `json:"sub_openid"`
} `json:"payer"`
Amount struct {
Total int64 `json:"total"`
PayerTotal int64 `json:"payer_total"`
Currency string `json:"currency"`
PayerCurrency string `json:"payer_currency"`
} `json:"amount"`
}

+ 102
- 0
app/customer/svc/svc_pay.go 파일 보기

@@ -493,6 +493,108 @@ func DealCentralKitchenForSchoolOrderCallBack(outTradeNo, tradeStatus string) (s
return
}

func DealCentralKitchenForSchoolOrderCallBackForWx(outTradeNo, tradeStatus string) (state int, err error) {
centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{}
centralKitchenForSchoolPackageOrd.Set(outTradeNo)
ord, err := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd()
if err != nil {
return
}
if ord == nil {
err = errors.New("未查询到对应订单记录")
return
}

if ord.State == enum2.CentralKitchenForSchoolPackageOrdStateForWait {
if tradeStatus == "CLOSED" || tradeStatus == "PAYERROR" {
ord.State = enum2.CentralKitchenForSchoolPackageOrdStateForFail
}

if tradeStatus == "SUCCESS" {
ord.State = enum2.CentralKitchenForSchoolPackageOrdStateForSuccess
ord.OrdState = enum2.CentralKitchenForSchoolPackageOrdOrdStateForSuccess

//TODO::将预留数据插入到 `central_kitchen_for_school_user_with_day`
var data []*model.CentralKitchenForSchoolUserWithDay
err = json.Unmarshal([]byte(ord.WithDayData), &data)
if err != nil {
return
}

var hasMonths = map[string]map[string]interface{}{}
var hasKinds = map[string]map[string]string{}
var hasTotalPrice = map[string]map[string]float64{}
for _, v := range data {
date, _ := time.ParseInLocation("2006-01-02", v.Date, time.Local)
if hasMonths[utils.TimeParseStd(v.Date).Month().String()] == nil {
hasMonths[utils.TimeParseStd(v.Date).Month().String()] = make(map[string]interface{})
hasMonths[utils.TimeParseStd(v.Date).Month().String()]["meal_time_start"] = date.Format("2006-01-02")
hasMonths[utils.TimeParseStd(v.Date).Month().String()]["meal_time_end"] = date.Format("2006-01-02")
} else {
startTime, _ := time.ParseInLocation("2006-01-02", utils.AnyToString(hasMonths[utils.TimeParseStd(v.Date).Month().String()]["meal_time_start"]), time.Local)
if startTime.After(date) {
hasMonths[utils.TimeParseStd(v.Date).Month().String()]["meal_time_start"] = date.Format("2006-01-02")
}

endTime, _ := time.ParseInLocation("2006-01-02", utils.AnyToString(hasMonths[utils.TimeParseStd(v.Date).Month().String()]["meal_time_end"]), time.Local)
if endTime.Before(date) {
hasMonths[utils.TimeParseStd(v.Date).Month().String()]["meal_time_end"] = date.Format("2006-01-02")
}
}
if hasTotalPrice[utils.TimeParseStd(v.Date).Month().String()] == nil {
hasTotalPrice[utils.TimeParseStd(v.Date).Month().String()] = make(map[string]float64)
}
if hasKinds[utils.TimeParseStd(v.Date).Month().String()] == nil {
hasKinds[utils.TimeParseStd(v.Date).Month().String()] = make(map[string]string)
}

hasMonths[utils.TimeParseStd(v.Date).Month().String()]["month"] = int(utils.TimeParseStd(v.Date).Month())
hasKinds[utils.TimeParseStd(v.Date).Month().String()][utils.IntToStr(v.Kind)] = utils.IntToStr(v.Kind)
hasTotalPrice[utils.TimeParseStd(v.Date).Month().String()][utils.IntToStr(v.Kind)] += utils.StrToFloat64(v.Amount)
v.OrdNo = outTradeNo
}

centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{}
centralKitchenForSchoolUserWithDayDb.Set(0)
_, err = centralKitchenForSchoolUserWithDayDb.BatchAddCentralKitchenForSchoolUserWithDays(data)
if err != nil {
return
}

//TODO::插入数据至 `central_kitchen_for_school_package_ord_for_reserve`
centralKitchenForSchoolPackageOrdForReserve := db.CentralKitchenForSchoolPackageOrdForReserve{}
centralKitchenForSchoolPackageOrdForReserve.Set(outTradeNo)
for k, v := range hasMonths {
for _, v1 := range hasKinds[k] {
_, err = centralKitchenForSchoolPackageOrdForReserve.CentralKitchenForSchoolPackageOrdForReserveInsert(&model.CentralKitchenForSchoolPackageOrdForReserve{
EnterpriseId: ord.EnterpriseId,
Uid: ord.Uid,
UserIdentityName: ord.UserIdentityName,
UserIdentityId: ord.UserIdentityId,
Kind: utils.StrToInt(v1),
OutTradeNo: ord.OutTradeNo,
ReserveMonth: utils.AnyToString(v["month"]),
MealTimeStart: utils.AnyToString(v["meal_time_start"]),
MealTimeEnd: utils.AnyToString(v["meal_time_end"]),
TotalPrice: utils.Float64ToStr(hasTotalPrice[k][v1]),
CreateAt: time.Now().Format("2006-01-02 15:04:05"),
UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
})
if err != nil {
return
}
}
}
}
_, err = centralKitchenForSchoolPackageOrd.CentralKitchenForSchoolPackageOrdUpdate(ord, "state", "ord_state")
if err != nil {
return
}
}
state = ord.State
return
}

func CheckAllCallbackParams(c *gin.Context) interface{} {
body, _ := ioutil.ReadAll(c.Request.Body)
utils.FilePutContents("CheckAllCallbackParams", utils.SerializeStr(string(body)))


+ 1
- 0
app/router/customer_router.go 파일 보기

@@ -20,6 +20,7 @@ func CustomerInit(r *gin.RouterGroup) {
r.POST("/downloadCertificates", hdl.DownloadCertificates) //下载微信支付平台证书
r.POST("/curlAlipayPlanetEcocampusApiRosterSignUpInfoTest", hdl.CurlAlipayPlanetEcocampusApiRosterSignUpInfo)
r.POST("/alipayJsApiCallBack", hdl.AlipayJsApiCallBack)
r.POST("/wxJsApiCallBack", hdl.WxJsApiCallBack)

r.POST("/login", hdl.Login)
r.GET("/wxAppletLogin", hdl.WxAppletLogin)


불러오는 중...
취소
저장