@@ -9,6 +9,7 @@ import ( | |||||
"applet/app/e" | "applet/app/e" | ||||
"applet/app/enum" | "applet/app/enum" | ||||
"applet/app/utils" | "applet/app/utils" | ||||
"applet/app/utils/cache" | |||||
"applet/app/utils/logx" | "applet/app/utils/logx" | ||||
"errors" | "errors" | ||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
@@ -119,7 +120,15 @@ func CentralKitchenForSchoolOrderRefundAudit(c *gin.Context) { | |||||
return | return | ||||
} | } | ||||
//TODO::先将所有申请单改成 审核通过 状态 | |||||
//TODO:: 加锁 Redis 锁,防并发 | |||||
getString, _ := cache.GetString(md.AuditLockKeyForCentralKitchenLockKey) | |||||
if getString != "" { | |||||
e.OutErr(c, e.ERR, "请稍等,存在其他退款处理中!") | |||||
return | |||||
} | |||||
cache.Set(md.AuditLockKeyForCentralKitchenLockKey, "running") | |||||
//先将所有申请单改成 审核通过 状态 | |||||
session := db.Db.NewSession() | session := db.Db.NewSession() | ||||
defer session.Close() | defer session.Close() | ||||
session.Begin() | session.Begin() | ||||
@@ -208,6 +217,7 @@ func CentralKitchenForSchoolOrderRefundAudit(c *gin.Context) { | |||||
logx.Error(err1) | logx.Error(err1) | ||||
println("<<<<CentralKitchenForSchoolOrderRefundAudit>>>>>Error:::", err1.Error()) | println("<<<<CentralKitchenForSchoolOrderRefundAudit>>>>>Error:::", err1.Error()) | ||||
} | } | ||||
cache.Del(md.AuditLockKeyForCentralKitchenLockKey) | |||||
}() | }() | ||||
e.OutSuc(c, "success", nil) | e.OutSuc(c, "success", nil) | ||||
@@ -2,13 +2,14 @@ package md | |||||
// 缓存key统一管理 | // 缓存key统一管理 | ||||
const ( | const ( | ||||
AdminJwtTokenKey = "%s:smart_canteen_admin_jwt_token:%s" // jwt, 占位符:ip, admin:id | |||||
JwtTokenCacheTime = 3600 * 24 | |||||
AdminRolePermissionKey = "%s:smart_canteen_admin_role_permission:%s" // 占位符:ip, admin:id | |||||
AdminRolePermissionCacheTime = 3600 * 24 * 0.5 | |||||
AdminHomePageDataKey = "%s:smart_canteen_admin_home_data:%s" // 占位符:ip, admin:id | |||||
AdminHomePageDataCacheTime = 60 * 10 | |||||
CfgCacheTime = 86400 | |||||
AppCfgCacheKey = "smart_canteen:%s" // 占位符: key的第一个字母 | |||||
WxOfficialAccountCacheKey = "wx_official_account" // 占位符: key的第一个字母 | |||||
AdminJwtTokenKey = "%s:smart_canteen_admin_jwt_token:%s" // jwt, 占位符:ip, admin:id | |||||
JwtTokenCacheTime = 3600 * 24 | |||||
AdminRolePermissionKey = "%s:smart_canteen_admin_role_permission:%s" // 占位符:ip, admin:id | |||||
AdminRolePermissionCacheTime = 3600 * 24 * 0.5 | |||||
AdminHomePageDataKey = "%s:smart_canteen_admin_home_data:%s" // 占位符:ip, admin:id | |||||
AdminHomePageDataCacheTime = 60 * 10 | |||||
CfgCacheTime = 86400 | |||||
AppCfgCacheKey = "smart_canteen:%s" // 占位符: key的第一个字母 | |||||
WxOfficialAccountCacheKey = "wx_official_account" // 占位符: key的第一个字母 | |||||
AuditLockKeyForCentralKitchenLockKey = "audit_lock_key_for_central_kitchen_lock_key" | |||||
) | ) |
@@ -70,6 +70,17 @@ type CurlAlipayTradeRefundReq struct { | |||||
AppAuthToken string `json:"app_auth_token" binding:"required" label:"应用授权token"` | AppAuthToken string `json:"app_auth_token" binding:"required" label:"应用授权token"` | ||||
} | } | ||||
type CurlAlipayTradeRefundQueryReq struct { | |||||
Config struct { | |||||
PayAliAppId string `json:"pay_ali_app_id" label:"支付宝开放平台-第三方应用-appid"` | |||||
PayAliPrivateKey string `json:"pay_ali_private_key" label:"支付宝开放平台-第三方应用-接口加签-应用私钥"` | |||||
PayAliPublicKey string `json:"pay_ali_public_key" label:"支付宝开放平台-第三方应用-接口加签-支付宝公钥"` | |||||
} `json:"config" label:"配置信息"` | |||||
OutTradeNo string `json:"out_trade_no" label:"商户订单号"` | |||||
OutRequestNo string `json:"out_request_no" label:"退款订单号"` | |||||
AppAuthToken string `json:"app_auth_token" binding:"required" label:"应用授权token"` | |||||
} | |||||
type CurlEducateSceneTokenReq struct { | type CurlEducateSceneTokenReq struct { | ||||
Config struct { | Config struct { | ||||
AliAppId string `json:"ali_app_id" label:"支付宝开放平台-小程序-appid"` | AliAppId string `json:"ali_app_id" label:"支付宝开放平台-小程序-appid"` | ||||
@@ -165,6 +165,36 @@ func CurlAlipayTradeRefund(args md.CurlAlipayTradeRefundReq) (err error, resp in | |||||
return nil, result.Data | return nil, result.Data | ||||
} | } | ||||
func CurlAlipayTradeRefundQuery(args md.CurlAlipayTradeRefundQueryReq) (err error, resp interface{}) { | |||||
url := cfg.SmartCanteenPay + "/alipay/pay/tradeRefundQuery" | |||||
utils.FilePutContents("CurlAlipayTradeRefundQuery", utils.SerializeStr(map[string]interface{}{ | |||||
"args": args, | |||||
})) | |||||
bytes, err := utils.CurlPost(url, utils.Serialize(args), nil) | |||||
if err != nil { | |||||
return | |||||
} | |||||
var result struct { | |||||
Code int `json:"code"` | |||||
Msg string `json:"msg"` | |||||
Data interface{} `json:"data"` | |||||
} | |||||
utils.FilePutContents("CurlAlipayTradeRefundQuery", utils.SerializeStr(result)) | |||||
err = json.Unmarshal(bytes, &result) | |||||
if err != nil { | |||||
return | |||||
} | |||||
if result.Code != 0 { | |||||
if result.Msg != "" { | |||||
err = errors.New(result.Msg) | |||||
return | |||||
} | |||||
err = errors.New("请求智慧餐厅支付 异常/失败") | |||||
return | |||||
} | |||||
return nil, result.Data | |||||
} | |||||
func CurlEducateSceneTokenQuery(args md.CurlEducateSceneTokenReq, userIdentity *model.UserIdentity, userToken, schoolName string) (err error, resp interface{}) { | func CurlEducateSceneTokenQuery(args md.CurlEducateSceneTokenReq, userIdentity *model.UserIdentity, userToken, schoolName string) (err error, resp interface{}) { | ||||
utils.FilePutContents("CurlEducateSceneTokenQuery", utils.SerializeStr(map[string]interface{}{ | utils.FilePutContents("CurlEducateSceneTokenQuery", utils.SerializeStr(map[string]interface{}{ | ||||
"args": args, | "args": args, | ||||
@@ -0,0 +1,94 @@ | |||||
package svc | |||||
import ( | |||||
md2 "applet/app/customer/md" | |||||
svc2 "applet/app/customer/svc" | |||||
"applet/app/db" | |||||
"applet/app/db/model" | |||||
"applet/app/enum" | |||||
"applet/app/utils" | |||||
"encoding/json" | |||||
"fmt" | |||||
"xorm.io/xorm" | |||||
) | |||||
func CentralKitchenForSchoolAlipayTradeFastpayRefundQuery(eg *xorm.Engine) { | |||||
var list []model.CentralKitchenForSchoolUserRefundDay | |||||
if err := db.Db.Where("refund_date >= '2024-01-17 12:00:00' AND state = 3").Desc("id").Find(&list); err != nil { | |||||
fmt.Println(err) | |||||
} | |||||
sysCfgDb := db.SysCfgDb{} | |||||
sysCfgDb.Set() | |||||
sysCfg := sysCfgDb.SysCfgFindWithDb(enum.JsapiPayAppAutToken, enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey, enum.WxJsapiRefundPayNotifyUrl) | |||||
for _, v := range list { | |||||
affected1, err := db.Db.Where("id=?", v.RecordsId).Cols("state").Update(&model.CentralKitchenForSchoolUserWithDay{ | |||||
State: 3, | |||||
}) | |||||
if err != nil { | |||||
fmt.Println(err) | |||||
} | |||||
fmt.Println(">>>>>>>>>>>>>>>>>affected1<<<<<<<<<<<<<<<<<<<", affected1) | |||||
continue | |||||
err, data := svc2.CurlAlipayTradeRefundQuery(md2.CurlAlipayTradeRefundQueryReq{ | |||||
Config: struct { | |||||
PayAliAppId string `json:"pay_ali_app_id" label:"支付宝开放平台-第三方应用-appid"` | |||||
PayAliPrivateKey string `json:"pay_ali_private_key" label:"支付宝开放平台-第三方应用-接口加签-应用私钥"` | |||||
PayAliPublicKey string `json:"pay_ali_public_key" label:"支付宝开放平台-第三方应用-接口加签-支付宝公钥"` | |||||
}{ | |||||
PayAliAppId: sysCfg[enum.OpenAlipayAppid], | |||||
PayAliPrivateKey: sysCfg[enum.OpenAlipayAppPrivateKey], | |||||
PayAliPublicKey: sysCfg[enum.OpenAlipayPublicKey], | |||||
}, | |||||
OutTradeNo: v.OutTradeNo, | |||||
OutRequestNo: v.OutRequestNo, | |||||
AppAuthToken: sysCfg[enum.JsapiPayAppAutToken], | |||||
}) | |||||
if err != nil { | |||||
fmt.Println("err:::::", err.Error()) | |||||
} | |||||
var dataMap map[string]string | |||||
err = json.Unmarshal([]byte(utils.SerializeStr(data)), &dataMap) | |||||
if dataMap["out_request_no"] == "" && dataMap["refund_status"] != "REFUND_SUCCESS" { | |||||
var mm []model.CentralKitchenForSchoolUserRefundDay | |||||
if err1 := db.Db.Where("out_request_no = ?", v.OutRequestNo).Desc("id").Find(&mm); err != nil { | |||||
fmt.Println(err1) | |||||
} | |||||
//var amount float64 | |||||
for _, vv := range mm { | |||||
//amount += utils.StrToFloat64(vv.Amount) | |||||
vv.State = 3 | |||||
affected1, err := db.Db.Where("id=?", vv.Id).Cols("state").Update(&vv) | |||||
if err != nil { | |||||
fmt.Println(err) | |||||
} | |||||
fmt.Println(">>>>>>>>>>>>>>>>>affected1<<<<<<<<<<<<<<<<<<<", affected1) | |||||
} | |||||
//err6, _ := svc2.CurlAlipayTradeRefund(md2.CurlAlipayTradeRefundReq{ | |||||
// Config: struct { | |||||
// PayAliAppId string `json:"pay_ali_app_id" label:"支付宝开放平台-第三方应用-appid"` | |||||
// PayAliPrivateKey string `json:"pay_ali_private_key" label:"支付宝开放平台-第三方应用-接口加签-应用私钥"` | |||||
// PayAliPublicKey string `json:"pay_ali_public_key" label:"支付宝开放平台-第三方应用-接口加签-支付宝公钥"` | |||||
// }{ | |||||
// PayAliAppId: sysCfg[enum.OpenAlipayAppid], | |||||
// PayAliPrivateKey: sysCfg[enum.OpenAlipayAppPrivateKey], | |||||
// PayAliPublicKey: sysCfg[enum.OpenAlipayPublicKey], | |||||
// }, | |||||
// OutTradeNo: v.OutTradeNo, | |||||
// RefundAmount: utils.Float64ToStr(amount), | |||||
// RefundReason: "央厨订餐退款", | |||||
// OutRequestNo: v.OutRequestNo, | |||||
// AppAuthToken: sysCfg[enum.JsapiPayAppAutToken], | |||||
//}) | |||||
//if err6 != nil { | |||||
// fmt.Println(err6) | |||||
//} | |||||
} | |||||
fmt.Println(dataMap) | |||||
} | |||||
} |
@@ -0,0 +1,23 @@ | |||||
package task | |||||
import ( | |||||
"applet/app/task/svc" | |||||
"math/rand" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
// 查询支付宝退款 | |||||
func taskCentralKitchenForSchoolAlipayTradeFastpayRefundQuery(eg *xorm.Engine) { | |||||
for { | |||||
if len(ch) > workerNum { | |||||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||||
} else { | |||||
goto START | |||||
} | |||||
} | |||||
START: | |||||
ch <- 1 | |||||
svc.CentralKitchenForSchoolAlipayTradeFastpayRefundQuery(eg) | |||||
<-ch | |||||
} |