123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package wallet
- import (
- "fmt"
- "github.com/guonaihong/gout"
- "gogs.uu.mdfitnesscao.com/Algor/sdk"
- "gogs.uu.mdfitnesscao.com/Algor/sdk/response"
- )
- const (
- WalletTypeMedicalReport = 1 // 报告解读
- WalletTypeArchives = 2 // 家庭档案
- )
- // 钱包消费
- func Consume(orderSn string, archivesId string, mechanismId string, walletType int64, quantity int64, remark string) (*sdk.BaseResponse[map[string]any], *response.ErrCode) {
- var resp *sdk.BaseResponse[map[string]any]
- resp, err := postReq[*sdk.BaseResponse[map[string]any]]("/walletService/openapi/member/card/balance", gout.H{
- "orderSn": orderSn,
- "archiveSn": archivesId,
- "mechanismId": mechanismId,
- "type": walletType,
- "quantity": quantity,
- "remark": remark,
- })
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- if resp.Code != 200 {
- return nil, &response.ErrCode{
- Code: resp.Code,
- Msg: resp.Message,
- }
- }
- return resp, nil
- }
- // 钱包消费
- func ConsumeRollback(orderSn string, remark string) (*sdk.BaseResponse[map[string]any], *response.ErrCode) {
- var resp *sdk.BaseResponse[map[string]any]
- resp, err := postReq[*sdk.BaseResponse[map[string]any]]("/walletService/openapi/member/card/balance/rollback", gout.H{
- "orderSn": orderSn,
- "remark": remark,
- })
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- if resp.Code != 200 {
- return nil, &response.ErrCode{
- Code: resp.Code,
- Msg: resp.Message,
- }
- }
- return resp, nil
- }
- // 注册钱包
- func Regist(archivesId string) (*sdk.BaseResponse[map[string]any], *response.ErrCode) {
- var resp *sdk.BaseResponse[map[string]any]
- resp, err := postReq[*sdk.BaseResponse[map[string]any]]("/walletService/openapi/event/member/register", gout.H{
- "archiveSn": archivesId,
- })
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- if resp.Code != 200 {
- return nil, &response.ErrCode{
- Code: resp.Code,
- Msg: resp.Message,
- }
- }
- return resp, nil
- }
- // 检查是否已授权钱包
- func CheckMechanismAuthorize(mechanismId string, walletType int64) (*sdk.BaseResponse[bool], *response.ErrCode) {
- var resp *sdk.BaseResponse[bool]
- resp, err := getReq[*sdk.BaseResponse[bool]]("/walletService/openapi/walletType/mechanism", gout.H{
- "mechanismId": mechanismId,
- "walletTypeId": walletType,
- })
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- if resp.Code != 200 {
- return nil, &response.ErrCode{
- Code: resp.Code,
- Msg: resp.Message,
- }
- }
- return resp, nil
- }
- // 钱包消费
- func MemberCardBind(
- cardId int64, archivesId string, channelName string, price int64, payType string, outTradeNo string, remark string, mechanismId string,
- ) (*sdk.BaseResponse[map[string]any], *response.ErrCode) {
- var resp *sdk.BaseResponse[map[string]any]
- resp, err := postReq[*sdk.BaseResponse[map[string]any]]("/walletService/openapi/member/card/bind", gout.H{
- "cardId": cardId,
- "archiveId": archivesId,
- "channelName": channelName,
- "price": price,
- "payType": payType,
- "outTradeNo": outTradeNo,
- "remark": remark,
- "mechanismId": mechanismId,
- })
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- if resp.Code != 200 {
- return nil, &response.ErrCode{
- Code: resp.Code,
- Msg: resp.Message,
- }
- }
- return resp, nil
- }
- // postReq 发送post请求
- func postReq[T any](path string, data gout.H) (T, error) {
- var res T
- fmt.Println(sdk.GetConfig())
- // 检查配置
- if sdk.GetConfig().ApiDomain == "" {
- return res, fmt.Errorf("请先配置API域名")
- }
- url := fmt.Sprintf("%s%s", sdk.GetConfig().ApiDomain, path)
- fmt.Println("请求地址 ===>", url)
- err := gout.POST(url).Debug(sdk.GetConfig().AppDebug).
- SetHeader(gout.H{}).
- SetJSON(data).
- BindJSON(&res).
- Do()
- if err != nil {
- fmt.Println("请求失败: ", err)
- return res, err
- }
- return res, nil
- }
- // postReq 发送post请求
- func getReq[T any](path string, data gout.H) (T, error) {
- var res T
- fmt.Println(sdk.GetConfig())
- // 检查配置
- if sdk.GetConfig().ApiDomain == "" {
- return res, fmt.Errorf("请先配置API域名")
- }
- url := fmt.Sprintf("%s%s", sdk.GetConfig().ApiDomain, path)
- fmt.Println("请求地址 ===>", url)
- err := gout.GET(url).Debug(sdk.GetConfig().AppDebug).
- SetHeader(gout.H{}).
- SetQuery(data).
- BindJSON(&res).
- Do()
- if err != nil {
- fmt.Println("请求失败: ", err)
- return res, err
- }
- return res, nil
- }
|