Order订单待测试
This commit is contained in:
		
							parent
							
								
									d4d11db732
								
							
						
					
					
						commit
						e50dac6b1c
					
				
							
								
								
									
										1
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								go.mod
									
									
									
									
									
								
							| @ -16,6 +16,7 @@ require ( | |||||||
| require ( | require ( | ||||||
| 	github.com/google/uuid v1.3.0 // indirect | 	github.com/google/uuid v1.3.0 // indirect | ||||||
| 	github.com/schollz/progressbar v1.0.0 // indirect | 	github.com/schollz/progressbar v1.0.0 // indirect | ||||||
|  | 	github.com/stripe/stripe-go/v74 v74.22.0 // indirect | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| require ( | require ( | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								go.sum
									
									
									
									
									
								
							| @ -229,6 +229,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ | |||||||
| github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= | ||||||
| github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= | github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= | ||||||
| github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= | github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= | ||||||
|  | github.com/stripe/stripe-go/v74 v74.22.0 h1:A6yqbyS61JYWhq6H4b0PFZukM8Ltx1VOXxsLYBNL+wE= | ||||||
|  | github.com/stripe/stripe-go/v74 v74.22.0/go.mod h1:f9L6LvaXa35ja7eyvP6GQswoaIPaBRvGAimAO+udbBw= | ||||||
| github.com/tidwall/gjson v1.12.0 h1:61wEp/qfvFnqKH/WCI3M8HuRut+mHT6Mr82QrFmM2SY= | github.com/tidwall/gjson v1.12.0 h1:61wEp/qfvFnqKH/WCI3M8HuRut+mHT6Mr82QrFmM2SY= | ||||||
| github.com/tidwall/gjson v1.12.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= | github.com/tidwall/gjson v1.12.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= | ||||||
| github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= | github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= | ||||||
| @ -333,6 +335,7 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R | |||||||
| golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= | golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= | ||||||
| golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= | golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= | ||||||
| golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= | golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= | ||||||
|  | golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= | ||||||
| golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= | golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= | ||||||
| golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= | golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= | ||||||
| golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= | ||||||
| @ -376,6 +379,7 @@ golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7w | |||||||
| golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||||
| golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||||
| golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||||
|  | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||||
| golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||||
| golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||||
| golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||||
| @ -388,6 +392,7 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3 | |||||||
| golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | ||||||
| golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||||||
| golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||||||
|  | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||||||
| golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= | golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= | ||||||
| golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= | golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= | ||||||
| golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ func NewServiceContext(c {{.config}}) *ServiceContext { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | ||||||
| 	AuthKey := r.Header.Get("Authorization") | 	AuthKey := r.Header.Get("Authorization") | ||||||
| 	if len(AuthKey) <= 50 { | 	if len(AuthKey) <= 50 { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | ||||||
| @ -37,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err | |||||||
| 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | ||||||
| 		} | 		} | ||||||
| 		// 返回用于验证签名的密钥 | 		// 返回用于验证签名的密钥 | ||||||
| 		return svcCxt.Config.Auth.AccessSecret, nil | 		return svcCtx.Config.Auth.AccessSecret, nil | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ package gmodel | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 
 | ||||||
| 	"gorm.io/gorm" | 	"gorm.io/gorm" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| @ -51,7 +52,7 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res | |||||||
| func (a *FsAddressModel) UpdateAddAddress(ctx context.Context, address *FsAddress) (err error) { | func (a *FsAddressModel) UpdateAddAddress(ctx context.Context, address *FsAddress) (err error) { | ||||||
| 	err = a.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { | 	err = a.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { | ||||||
| 		if *address.IsDefault > 0 { | 		if *address.IsDefault > 0 { | ||||||
| 			err = tx.Where("user_id = ? and is_default = 1", *address.UserId).Update("is_default", 0).Error | 			err = tx.Where("user_id = ? and is_default = 1", address.UserId).Update("is_default", 0).Error | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return err | 				return err | ||||||
| 			} | 			} | ||||||
|  | |||||||
| @ -9,10 +9,8 @@ func (p *FsPayModel) GetListByOrderNumber(ctx context.Context, sn string) (resp | |||||||
| 	} | 	} | ||||||
| 	return resp, nil | 	return resp, nil | ||||||
| } | } | ||||||
|  | 
 | ||||||
| func (p *FsPayModel) GetOrderPayList(ctx context.Context, sn string, payStatus int64, isRefund int64) (resp []FsPay, err error) { | func (p *FsPayModel) GetOrderPayList(ctx context.Context, sn string, payStatus int64, isRefund int64) (resp []FsPay, err error) { | ||||||
| 	err = p.db.WithContext(ctx).Model(&FsPay{}).Where("`order_number` = ? and `pay_status` = ? and `is_refund` = ?", sn, payStatus, isRefund).Find(&resp).Error | 	err = p.db.WithContext(ctx).Model(&FsPay{}).Where("`order_number` = ? and `pay_status` = ? and `is_refund` = ?", sn, payStatus, isRefund).Find(&resp).Error | ||||||
| 	if err != nil { | 	return resp, err | ||||||
| 		return nil, err |  | ||||||
| 	} |  | ||||||
| 	return resp, nil |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,9 +1,24 @@ | |||||||
| package gmodel | package gmodel | ||||||
| 
 | 
 | ||||||
| import "context" | import ( | ||||||
|  | 	"context" | ||||||
|  | 
 | ||||||
|  | 	"gorm.io/gorm" | ||||||
|  | ) | ||||||
| 
 | 
 | ||||||
| // TODO: 使用model的属性做你想做的 | // TODO: 使用model的属性做你想做的 | ||||||
| 
 | 
 | ||||||
| func (fsRefundReason *FsRefundReasonModel) Update(cxt context.Context) { | func (m *FsRefundReasonModel) Create(ctx context.Context, obj *FsRefundReason) error { | ||||||
|  | 	return m.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { | ||||||
| 
 | 
 | ||||||
|  | 		return nil | ||||||
|  | 	}) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (m *FsRefundReasonModel) Update(ctx context.Context, obj *FsRefundReason) error { | ||||||
|  | 	return m.db.WithContext(ctx).Model(obj).Where("`id` = ?", obj.Id).Updates(obj).Error | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (m *FsRefundReasonModel) UpdateByRefundReasonId(ctx context.Context, obj *FsRefundReason) error { | ||||||
|  | 	return m.db.WithContext(ctx).Model(obj).Where("`refund_reason_id` = ?", obj.RefundReasonId).Updates(obj).Error | ||||||
| } | } | ||||||
|  | |||||||
| @ -5,9 +5,10 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"fusenapi/initalize" | 	"fusenapi/initalize" | ||||||
| 	"fusenapi/server/canteen/internal/config" | 	"fusenapi/server/canteen/internal/config" | ||||||
|  | 	"net/http" | ||||||
|  | 
 | ||||||
| 	"github.com/golang-jwt/jwt" | 	"github.com/golang-jwt/jwt" | ||||||
| 	"gorm.io/gorm" | 	"gorm.io/gorm" | ||||||
| 	"net/http" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type ServiceContext struct { | type ServiceContext struct { | ||||||
| @ -24,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | ||||||
| 	AuthKey := r.Header.Get("Authorization") | 	AuthKey := r.Header.Get("Authorization") | ||||||
| 	if len(AuthKey) <= 50 { | 	if len(AuthKey) <= 50 { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | ||||||
| @ -36,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err | |||||||
| 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | ||||||
| 		} | 		} | ||||||
| 		// 返回用于验证签名的密钥 | 		// 返回用于验证签名的密钥 | ||||||
| 		return svcCxt.Config.Auth.AccessSecret, nil | 		return svcCtx.Config.Auth.AccessSecret, nil | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | ||||||
|  | |||||||
| @ -5,9 +5,10 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"fusenapi/initalize" | 	"fusenapi/initalize" | ||||||
| 	"fusenapi/server/data-transfer/internal/config" | 	"fusenapi/server/data-transfer/internal/config" | ||||||
|  | 	"net/http" | ||||||
|  | 
 | ||||||
| 	"github.com/golang-jwt/jwt" | 	"github.com/golang-jwt/jwt" | ||||||
| 	"gorm.io/gorm" | 	"gorm.io/gorm" | ||||||
| 	"net/http" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type ServiceContext struct { | type ServiceContext struct { | ||||||
| @ -24,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | ||||||
| 	AuthKey := r.Header.Get("Authorization") | 	AuthKey := r.Header.Get("Authorization") | ||||||
| 	if len(AuthKey) <= 50 { | 	if len(AuthKey) <= 50 { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | ||||||
| @ -36,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err | |||||||
| 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | ||||||
| 		} | 		} | ||||||
| 		// 返回用于验证签名的密钥 | 		// 返回用于验证签名的密钥 | ||||||
| 		return svcCxt.Config.Auth.AccessSecret, nil | 		return svcCtx.Config.Auth.AccessSecret, nil | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | ||||||
|  | |||||||
| @ -7,3 +7,6 @@ Auth: | |||||||
|   AccessSecret: fusen2023 |   AccessSecret: fusen2023 | ||||||
|   AccessExpire: 60 |   AccessExpire: 60 | ||||||
|   RefreshAfter: 60 |   RefreshAfter: 60 | ||||||
|  |    | ||||||
|  | Stripe: | ||||||
|  |   SK: "123" | ||||||
|  | |||||||
| @ -10,4 +10,8 @@ type Config struct { | |||||||
| 	rest.RestConf | 	rest.RestConf | ||||||
| 	SourceMysql string | 	SourceMysql string | ||||||
| 	Auth        types.Auth | 	Auth        types.Auth | ||||||
|  | 
 | ||||||
|  | 	Stripe struct { | ||||||
|  | 		SK string | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -13,6 +13,9 @@ import ( | |||||||
| 	"fusenapi/server/home-user-auth/internal/svc" | 	"fusenapi/server/home-user-auth/internal/svc" | ||||||
| 	"fusenapi/server/home-user-auth/internal/types" | 	"fusenapi/server/home-user-auth/internal/types" | ||||||
| 
 | 
 | ||||||
|  | 	"github.com/stripe/stripe-go/v74" | ||||||
|  | 	"github.com/stripe/stripe-go/v74/client" | ||||||
|  | 
 | ||||||
| 	"github.com/zeromicro/go-zero/core/logx" | 	"github.com/zeromicro/go-zero/core/logx" | ||||||
| 	"gorm.io/gorm" | 	"gorm.io/gorm" | ||||||
| ) | ) | ||||||
| @ -104,27 +107,40 @@ func (l *UserOderDeleteLogic) UserOderDelete(req *types.RequestOrderId, userinfo | |||||||
| 		CreatedAt:      &CreatedAt, | 		CreatedAt:      &CreatedAt, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	mFsRefund := gmodel.NewFsRefundReasonModel(l.svcCtx.MysqlConn) | 	mFsRefundReason := gmodel.NewFsRefundReasonModel(l.svcCtx.MysqlConn) | ||||||
| 
 | 	err = mFsRefundReason.Create(l.ctx, refund) | ||||||
| 	err = refund.Save() | 	if err != nil { | ||||||
|  | 		logx.Error(err) | ||||||
|  | 		return resp.SetStatus(basic.CodeDbSqlErr) | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	// 退款 | 	// 退款 | ||||||
| 	// 调用第三方接口发起退款 | 	// 调用第三方接口发起退款 | ||||||
| 	config := GetStripeConfig() | 
 | ||||||
|  | 	config := &stripe.BackendConfig{ | ||||||
|  | 		MaxNetworkRetries: stripe.Int64(0), // Zero retries | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	sc := &client.API{} | ||||||
|  | 	sc.Init(l.svcCtx.Config.Stripe.SK, &stripe.Backends{ | ||||||
|  | 		API:     stripe.GetBackendWithConfig(stripe.APIBackend, config), | ||||||
|  | 		Uploads: stripe.GetBackendWithConfig(stripe.UploadsBackend, config), | ||||||
|  | 	}) | ||||||
|  | 	// ['order_number' => $order->sn, 'is_refund' => 0, 'pay_status' => 1] | ||||||
|  | 	pay := gmodel.NewFsPayModel(l.svcCtx.MysqlConn) | ||||||
| 
 | 
 | ||||||
| 	// 查询支付信息 | 	// 查询支付信息 | ||||||
| 	pays, err := Pay.Find(db.Where("order_number = ? AND is_refund = ? AND pay_status = ?", order.SN, 0, 1)) | 	pays, err := pay.GetOrderPayList(l.ctx, *order.Sn, 1, 0) | ||||||
| 	for _, pay := range pays { | 	for _, pay := range pays { | ||||||
| 		stripe := stripe.New(config.SK) | 		sc.Refunds.New(&stripe.RefundParams{ | ||||||
| 		_, err := stripe.Refunds.Create(stripe.RefundParams{ |  | ||||||
| 			PaymentIntent: pay.TradeNo, | 			PaymentIntent: pay.TradeNo, | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if err == nil && err == nil { | 	// if err == nil && err == nil { | ||||||
| 		return ResponseSuccess(200, "Cancel successfully", order) | 	// 	return ResponseSuccess(200, "Cancel successfully", order) | ||||||
| 	} | 	// } | ||||||
| 	return ResponseError(500, "Cancellation failure") | 	// return ResponseError(500, "Cancellation failure") | ||||||
| 
 | 
 | ||||||
| 	return resp.SetStatus(basic.CodeOK) | 	return resp.SetStatus(basic.CodeOK) | ||||||
| } | } | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | ||||||
| 	AuthKey := r.Header.Get("Authorization") | 	AuthKey := r.Header.Get("Authorization") | ||||||
| 	if AuthKey == "" { | 	if AuthKey == "" { | ||||||
| 		return nil, nil | 		return nil, nil | ||||||
| @ -35,7 +35,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err | |||||||
| 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | ||||||
| 		} | 		} | ||||||
| 		// 返回用于验证签名的密钥 | 		// 返回用于验证签名的密钥 | ||||||
| 		return []byte(svcCxt.Config.Auth.AccessSecret), nil | 		return []byte(svcCtx.Config.Auth.AccessSecret), nil | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | ||||||
|  | |||||||
| @ -5,9 +5,10 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"fusenapi/initalize" | 	"fusenapi/initalize" | ||||||
| 	"fusenapi/server/map-library/internal/config" | 	"fusenapi/server/map-library/internal/config" | ||||||
|  | 	"net/http" | ||||||
|  | 
 | ||||||
| 	"github.com/golang-jwt/jwt" | 	"github.com/golang-jwt/jwt" | ||||||
| 	"gorm.io/gorm" | 	"gorm.io/gorm" | ||||||
| 	"net/http" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type ServiceContext struct { | type ServiceContext struct { | ||||||
| @ -24,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | ||||||
| 	AuthKey := r.Header.Get("Authorization") | 	AuthKey := r.Header.Get("Authorization") | ||||||
| 	if len(AuthKey) <= 50 { | 	if len(AuthKey) <= 50 { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | ||||||
| @ -36,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err | |||||||
| 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | ||||||
| 		} | 		} | ||||||
| 		// 返回用于验证签名的密钥 | 		// 返回用于验证签名的密钥 | ||||||
| 		return svcCxt.Config.Auth.AccessSecret, nil | 		return svcCtx.Config.Auth.AccessSecret, nil | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | ||||||
|  | |||||||
| @ -5,9 +5,10 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"fusenapi/initalize" | 	"fusenapi/initalize" | ||||||
| 	"fusenapi/server/orders/internal/config" | 	"fusenapi/server/orders/internal/config" | ||||||
|  | 	"net/http" | ||||||
|  | 
 | ||||||
| 	"github.com/golang-jwt/jwt" | 	"github.com/golang-jwt/jwt" | ||||||
| 	"gorm.io/gorm" | 	"gorm.io/gorm" | ||||||
| 	"net/http" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type ServiceContext struct { | type ServiceContext struct { | ||||||
| @ -24,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | ||||||
| 	AuthKey := r.Header.Get("Authorization") | 	AuthKey := r.Header.Get("Authorization") | ||||||
| 	if len(AuthKey) <= 50 { | 	if len(AuthKey) <= 50 { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | ||||||
| @ -36,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err | |||||||
| 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | ||||||
| 		} | 		} | ||||||
| 		// 返回用于验证签名的密钥 | 		// 返回用于验证签名的密钥 | ||||||
| 		return svcCxt.Config.Auth.AccessSecret, nil | 		return svcCtx.Config.Auth.AccessSecret, nil | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | ||||||
|  | |||||||
| @ -2,11 +2,13 @@ package svc | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
|  | 	"fmt" | ||||||
| 	"fusenapi/initalize" | 	"fusenapi/initalize" | ||||||
| 	"fusenapi/server/product-templatev2/internal/config" | 	"fusenapi/server/product-templatev2/internal/config" | ||||||
|  | 	"net/http" | ||||||
|  | 
 | ||||||
| 	"github.com/golang-jwt/jwt" | 	"github.com/golang-jwt/jwt" | ||||||
| 	"gorm.io/gorm" | 	"gorm.io/gorm" | ||||||
| 	"net/http" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type ServiceContext struct { | type ServiceContext struct { | ||||||
| @ -23,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | ||||||
| 	AuthKey := r.Header.Get("Authorization") | 	AuthKey := r.Header.Get("Authorization") | ||||||
| 	if len(AuthKey) <= 50 { | 	if len(AuthKey) <= 50 { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | ||||||
| @ -35,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err | |||||||
| 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | ||||||
| 		} | 		} | ||||||
| 		// 返回用于验证签名的密钥 | 		// 返回用于验证签名的密钥 | ||||||
| 		return svcCxt.Config.Auth.AccessSecret, nil | 		return svcCtx.Config.Auth.AccessSecret, nil | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | ||||||
| 	AuthKey := r.Header.Get("Authorization") | 	AuthKey := r.Header.Get("Authorization") | ||||||
| 	if len(AuthKey) <= 50 { | 	if len(AuthKey) <= 50 { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | ||||||
| @ -37,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err | |||||||
| 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | ||||||
| 		} | 		} | ||||||
| 		// 返回用于验证签名的密钥 | 		// 返回用于验证签名的密钥 | ||||||
| 		return svcCxt.Config.Auth.AccessSecret, nil | 		return svcCtx.Config.Auth.AccessSecret, nil | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | ||||||
| 	AuthKey := r.Header.Get("Authorization") | 	AuthKey := r.Header.Get("Authorization") | ||||||
| 	if len(AuthKey) <= 50 { | 	if len(AuthKey) <= 50 { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | ||||||
| @ -37,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err | |||||||
| 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | ||||||
| 		} | 		} | ||||||
| 		// 返回用于验证签名的密钥 | 		// 返回用于验证签名的密钥 | ||||||
| 		return svcCxt.Config.Auth.AccessSecret, nil | 		return svcCtx.Config.Auth.AccessSecret, nil | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | ||||||
|  | |||||||
| @ -68,8 +68,17 @@ func (resp *Response) SetStatus(sr *StatusResponse, data ...interface{}) *Respon | |||||||
| 		} else { | 		} else { | ||||||
| 			newResp.Data = data[0] | 			newResp.Data = data[0] | ||||||
| 		} | 		} | ||||||
| 	} else if len(data) > 1 { | 	} else if len(data) == 2 { | ||||||
| 		newResp.Data = data | 		var dataIndex = 0 | ||||||
|  | 		if err, ok := data[dataIndex].(error); ok { | ||||||
|  | 			newResp.Message = err.Error() | ||||||
|  | 			dataIndex++ | ||||||
|  | 		} else { | ||||||
|  | 			panic("data只接收1或2个 data 或 error.Error() 和 data ") | ||||||
|  | 		} | ||||||
|  | 		newResp.Data = data[1] | ||||||
|  | 	} else { | ||||||
|  | 		panic("data只接收1或2个 data, error.Error() 和 data ") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return newResp | 	return newResp | ||||||
| @ -83,6 +92,21 @@ func (resp *Response) SetStatusWithMessage(sr *StatusResponse, msg string, data | |||||||
| 	} | 	} | ||||||
| 	if len(data) == 1 { | 	if len(data) == 1 { | ||||||
| 		newResp.Data = data[0] | 		newResp.Data = data[0] | ||||||
|  | 	} else { | ||||||
|  | 		panic("data只接收一个 data") | ||||||
|  | 	} | ||||||
|  | 	return newResp | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (resp *Response) SetStatusAddMessage(sr *StatusResponse, msg string, data ...interface{}) *Response { | ||||||
|  | 	newResp := &Response{ | ||||||
|  | 		Code:    sr.Code, | ||||||
|  | 		Message: sr.Message + ":" + msg, | ||||||
|  | 	} | ||||||
|  | 	if len(data) == 1 { | ||||||
|  | 		newResp.Data = data[0] | ||||||
|  | 	} else { | ||||||
|  | 		panic("data只接收一个") | ||||||
| 	} | 	} | ||||||
| 	return newResp | 	return newResp | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user