|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- package hdl
-
- import (
- "applet/app/admin/lib/validate"
- "applet/app/admin/md"
- svc "applet/app/admin/svc/order"
- md2 "applet/app/customer/md"
- svc2 "applet/app/customer/svc"
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/e"
- "applet/app/enum"
- svc3 "applet/app/svc"
- "applet/app/utils"
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/wechatpay-apiv3/wechatpay-go/core"
- "github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
- "math"
- "time"
- )
-
- // Demo 测试
- func Demo(c *gin.Context) {
- eg := db.Db
- var mm []model.CentralKitchenForSchoolPackageOrdForReserve
- if err1 := eg.Asc("id").Find(&mm); err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- for _, v := range mm {
- m := new(model.CentralKitchenForSchoolUserWithDay)
- has, err := db.Db.Where("ord_no =?", v.OutTradeNo).Get(m)
- if err != nil {
- fmt.Println(err)
- return
- }
- if !has {
- utils.FilePutContents("demo_demo", utils.SerializeStr(v))
- }
- if m.IdentityId != v.UserIdentityId {
- utils.FilePutContents("demo", utils.SerializeStr(v))
- }
- if m.EnterpriseId != v.EnterpriseId {
- utils.FilePutContents("demo111", utils.SerializeStr(v))
- }
- }
- return
- var m []model.CentralKitchenForSchoolUserWithDay
- if err1 := eg.Where("state = 3").Asc("id").Find(&m); err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- now := time.Now()
- var records []int
- for _, v := range m {
- mm := new(model.CentralKitchenForSchoolUserRefundDay)
- has, err := db.Db.Where("records_id =? and state = 1", v.Id).Get(mm)
- if err != nil {
- fmt.Println(err)
- return
- }
- if has == false {
- centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{}
- centralKitchenForSchoolUserRefundDayDb.Set(0)
- _, err = centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayInsert(&model.CentralKitchenForSchoolUserRefundDay{
- OutTradeNo: v.OrdNo,
- OutRequestNo: "",
- Uid: v.Uid,
- IdentityId: v.IdentityId,
- RecordsId: v.Id,
- State: enum.CentralKitchenForSchoolUserRefundDayStateForAuditing,
- Amount: v.Amount,
- Memo: "fill",
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- })
- records = append(records, v.Id)
- }
- }
- e.OutSuc(c, records, nil)
- return
-
- var req md.CentralKitchenForSchoolOrderRefundAuditReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- err1 := svc.CentralKitchenForSchoolOrderRefundAudit(c, req)
- if err1 != nil {
- fmt.Println(err1.Error())
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- sysCfg := sysCfgDb.SysCfgFindWithDb(enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey)
-
- //调用支付宝进行退款
- err6, _ := svc2.OldCurlAlipayTradeRefund(md2.OldCurlAlipayTradeRefundReq{
- 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: "800169659125681442",
- RefundAmount: "180.00",
- RefundReason: "央厨订餐退款",
- OutRequestNo: "r_800169659125681442_1705546121",
- AppAuthToken: "202308BB8ef30019cd8d4a40a3853192c397dX35",
- })
- if err6 != nil {
- fmt.Println(err6.Error())
- }
- return
- qrcodeWithBatchRecordsDb := db.AdminDb{}
- qrcodeWithBatchRecordsDb.Set()
- data, _, err := qrcodeWithBatchRecordsDb.GetAdminRolePermission(1001)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, data, nil)
- go GoOnExecuting()
- return
- }
-
- // Demo 测试
- func TempDemo(c *gin.Context) {
- eg := db.Db
- var list []*model.CentralKitchenForSchoolUserWithDay
- err := db.Db.Where("state = 3").Asc("id").Find(&list)
- if err != nil {
- return
- }
- for _, m := range list {
- mm := new(model.CentralKitchenForSchoolUserRefundDay)
- has, err := db.Db.Where("records_id =? and state = 4", m.Id).Get(mm)
- if err != nil {
- fmt.Println(err)
- return
- }
- if has {
- m.State = 4
- updateAffetcd, err := db.Db.Where("id =?", m.Id).Cols("state").Update(m)
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Println(">>>>>>>>>>>", updateAffetcd)
- }
-
- }
- return
- var m []model.CentralKitchenForSchoolUserWithDay
- if err1 := eg.Where("state = 3").Asc("id").Find(&m); err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- now := time.Now()
- var records []int
- for _, v := range m {
- mm := new(model.CentralKitchenForSchoolUserRefundDay)
- has, err := db.Db.Where("records_id =? and state = 1", v.Id).Get(mm)
- if err != nil {
- fmt.Println(err)
- return
- }
- if has == false {
- centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{}
- centralKitchenForSchoolUserRefundDayDb.Set(0)
- _, err = centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayInsert(&model.CentralKitchenForSchoolUserRefundDay{
- OutTradeNo: v.OrdNo,
- OutRequestNo: "",
- Uid: v.Uid,
- IdentityId: v.IdentityId,
- RecordsId: v.Id,
- State: enum.CentralKitchenForSchoolUserRefundDayStateForAuditing,
- Amount: v.Amount,
- Memo: "fill",
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- })
- records = append(records, v.Id)
- }
- }
- e.OutSuc(c, records, nil)
- return
-
- var req md.CentralKitchenForSchoolOrderRefundAuditReq
- err = c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- err1 := svc.CentralKitchenForSchoolOrderRefundAudit(c, req)
- if err1 != nil {
- fmt.Println(err1.Error())
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- sysCfg := sysCfgDb.SysCfgFindWithDb(enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey)
-
- //调用支付宝进行退款
- err6, _ := svc2.OldCurlAlipayTradeRefund(md2.OldCurlAlipayTradeRefundReq{
- 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: "800169659125681442",
- RefundAmount: "180.00",
- RefundReason: "央厨订餐退款",
- OutRequestNo: "r_800169659125681442_1705546121",
- AppAuthToken: "202308BB8ef30019cd8d4a40a3853192c397dX35",
- })
- if err6 != nil {
- fmt.Println(err6.Error())
- }
- return
- qrcodeWithBatchRecordsDb := db.AdminDb{}
- qrcodeWithBatchRecordsDb.Set()
- data, _, err := qrcodeWithBatchRecordsDb.GetAdminRolePermission(1001)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, data, nil)
- go GoOnExecuting()
- return
- }
-
- func DemoV1(c *gin.Context) {
- var outRequestNo = c.Query("out_request_no")
- var outTradeNo = c.Query("out_no")
- centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{}
- centralKitchenForSchoolUserRefundDayDb.Set(0)
- var m []model.CentralKitchenForSchoolUserRefundDay
- if err := centralKitchenForSchoolUserRefundDayDb.Db.Where("out_request_no =?", outRequestNo).Desc("id").Find(&m); err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{}
- centralKitchenForSchoolPackageOrd.Set(outTradeNo)
- ord, _ := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd()
-
- var dealReturnOrdMapForWx = map[string]struct {
- OutRequestNo string `json:"out_request_no"`
- Amount float64 `json:"amount"`
- Total string `json:"total"`
- WxMchId string `json:"wx_mch_id"`
- }{}
- companyWithWxpayInfoDb := db.CompanyWithWxpayInfoDb{}
- companyWithWxpayInfoDb.Set()
- wxMchId, _ := companyWithWxpayInfoDb.GetCompanyWithWxpayInfoByEnterprise(ord.EnterpriseId)
-
- for _, v := range m {
- dealReturnOrdMapForWx[ord.OutTradeNo] = struct {
- OutRequestNo string `json:"out_request_no"`
- Amount float64 `json:"amount"`
- Total string `json:"total"`
- WxMchId string `json:"wx_mch_id"`
- }(struct {
- OutRequestNo string
- Amount float64
- Total string
- WxMchId string
- }{OutRequestNo: outRequestNo, Amount: dealReturnOrdMapForWx[v.OutTradeNo].Amount + utils.StrToFloat64(v.Amount), Total: ord.TotalPrice, WxMchId: wxMchId})
- }
- client, err1 := svc3.NewWxPayClient(c) //初始化微信连接
- if err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
-
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- sysCfg := sysCfgDb.SysCfgFindWithDb(enum.JsapiPayAppAutToken, enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey, enum.WxJsapiRefundPayNotifyUrl)
- wxSvc := refunddomestic.RefundsApiService{Client: client}
- for k, v := range dealReturnOrdMapForWx {
- resp, _, err6 := wxSvc.Create(c,
- refunddomestic.CreateRequest{
- SubMchid: core.String(v.WxMchId),
- OutTradeNo: core.String(k),
- OutRefundNo: core.String(v.OutRequestNo),
- Reason: core.String("央厨订餐退款"),
- NotifyUrl: core.String(sysCfg[enum.WxJsapiRefundPayNotifyUrl]),
- Amount: &refunddomestic.AmountReq{
- Currency: core.String("CNY"),
- Refund: core.Int64(int64(math.Round(v.Amount * 100))),
- Total: core.Int64(int64(math.Round(utils.StrToFloat64(v.Total) * 100))),
- },
- },
- )
- fmt.Println(">>>>wxRefund<<<<", resp)
- if err6 != nil {
- fmt.Println(err6)
- e.OutErr(c, e.ERR, err6.Error())
- return
- }
- }
- e.OutSuc(c, dealReturnOrdMapForWx, nil)
- return
- }
-
- func GoOnExecuting() {
- for i := 0; i < 20; i++ {
- time.Sleep(1 * time.Second)
- fmt.Println(i)
- }
- }
|