diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 4145b2b..df8cd49 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -5,24 +5,36 @@ name: ImDada-CI on: push: - branches: [ "main" ] + branches: + - main + - develop + - feature/** + - fix/** pull_request: - branches: [ "main" ] + branches: + - main + - develop + - feature/** + - fix/** jobs: build: runs-on: ubuntu-latest + # strategy set + strategy: + matrix: + go: [ "1.19", "1.20" ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: 1.19 + - name: Set up Go ${{ matrix.go }} + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go }} - - name: Build - run: go build -v ./... + - name: Build + run: go build -v ./... - - name: Test - run: go test -v ./... + - name: Test + run: go test -v ./... diff --git a/.gitignore b/.gitignore index 979dc56..d9054d2 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ # vendor/ *.log -*_test.go \ No newline at end of file +*_test.go +logs \ No newline at end of file diff --git a/constant.go b/constant.go index 660d6a2..8d53e99 100644 --- a/constant.go +++ b/constant.go @@ -114,3 +114,39 @@ const ( // fetchCodeModify 修改取货码 fetchCodeModify = "/api/order/fetchCode/update" ) + +const ( + // rechargeCateH5 H5充值 + rechargeCateH5 = "H5" + // rechargeCatePC PC充值 + rechargeCatePC = "PC" +) + +const ( + foodSnacks = 1 // 食品小吃 + drink = 2 // 饮料 + flowersAndGreenery = 3 // 鲜花绿植 + other = 5 // 其他 + printingTicketing = 8 // 文印票务 + convenienceStores = 9 // 便利店 + freshFruit = 13 // 水果生鲜 + intraCityECommerce = 19 // 同城电商 + medicine = 20 // 医药 + cake = 21 // 蛋糕 + wine = 24 // 酒品 + smallCommodityMarkets = 25 // 小商品市场 + clothing = 26 // 服装 + autoRepairParts = 27 // 汽修零配 + digitalAppliances = 28 // 数码家电 + crayfishBBQ = 29 // 小龙虾/烧烤 + supermarket = 31 // 超市 + chafingDish = 51 // 火锅 + personalCareMakeup = 53 // 个护美妆 + mother = 55 // 母婴 + homeTextiles = 57 // 家居家纺 + cellPhone = 59 // 手机 + home = 61 // 家装 + adultProducts = 63 // 成人用品 + campus = 65 // 校园 + highEndMarket = 66 // 高端市场 +) diff --git a/imdada.go b/imdada.go index a2c93a0..c607107 100644 --- a/imdada.go +++ b/imdada.go @@ -235,14 +235,102 @@ func (c *Client) doRequest(ctx context.Context, method string) error { } // QueryBalance query balance. +// 查询账户余额 url: http://newopen.imdada.cn/#/development/file/balanceQuery func (c *Client) QueryBalance(ctx context.Context, req *domain.QueryBalanceRequest) (resp *domain.QueryBalanceResponse, err error) { if c.request.Body, err = sonic.MarshalString(req); err != nil { return nil, err } + c.log.CtxDebugf(ctx, "QueryBalance request data: %s", c.request.Body) if err = c.doRequest(ctx, queryBalance); err != nil { return nil, err } - c.log.CtxDebugf(ctx, "response data: %s", string(c.response.Body())) + c.log.CtxDebugf(ctx, "QueryBalance response data: %s", string(c.response.Body())) + if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil { + return nil, err + } + return +} + +// Recharge account recharge. +// 获取充值链接 url: http://newopen.imdada.cn/#/development/file/recharge +func (c *Client) Recharge(ctx context.Context, req *domain.RechargeRequest) (resp *domain.RechargeResponse, err error) { + if c.request.Body, err = sonic.MarshalString(req); err != nil { + return nil, err + } + c.log.CtxDebugf(ctx, "Recharge request data: %s", c.request.Body) + if err = c.doRequest(ctx, recharge); err != nil { + return nil, err + } + c.log.CtxDebugf(ctx, "Recharge response data: %s", string(c.response.Body())) + if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil { + return nil, err + } + return +} + +// CreateMerchant create merchant. +// 添加商户 url: http://newopen.imdada.cn/#/development/file/merchantAdd +func (c *Client) CreateMerchant(ctx context.Context, req *domain.MerchantCreateRequest) (resp *domain.MerchantCreateResponse, err error) { + if c.request.Body, err = sonic.MarshalString(req); err != nil { + return nil, err + } + c.request.SourceID = "" + c.log.CtxDebugf(ctx, "CreateMerchant request data: %s", c.request.Body) + if err = c.doRequest(ctx, merchantCreate); err != nil { + return nil, err + } + c.log.CtxDebugf(ctx, "CreateMerchant response data: %s", string(c.response.Body())) + if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil { + return nil, err + } + return +} + +// CreateShop create shop. +// 添加门店 url: http://newopen.imdada.cn/#/development/file/shopAdd +func (c *Client) CreateShop(ctx context.Context, req *domain.ShopCreateRequest) (resp *domain.ShopCreateResponse, err error) { + if c.request.Body, err = sonic.MarshalString(req); err != nil { + return nil, err + } + c.log.CtxDebugf(ctx, "CreateShop request data: %s", c.request.Body) + if err = c.doRequest(ctx, shopCreate); err != nil { + return nil, err + } + c.log.CtxDebugf(ctx, "CreateShop response data: %s", string(c.response.Body())) + if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil { + return nil, err + } + return +} + +// ModifyShop modify shop. +// 编辑门店 url: http://newopen.imdada.cn/#/development/file/shopUpdate +func (c *Client) ModifyShop(ctx context.Context, req *domain.ShopUpdateRequest) (resp *domain.ShopUpdateResponse, err error) { + if c.request.Body, err = sonic.MarshalString(req); err != nil { + return nil, err + } + c.log.CtxDebugf(ctx, "ModifyShop request data: %s", c.request.Body) + if err = c.doRequest(ctx, shopUpdate); err != nil { + return nil, err + } + c.log.CtxDebugf(ctx, "ModifyShop response data: %s", string(c.response.Body())) + if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil { + return nil, err + } + return +} + +// QueryShop query shop. +// 门店详情 url: http://newopen.imdada.cn/#/development/file/shopDetail +func (c *Client) QueryShop(ctx context.Context, req *domain.ShopQueryRequest) (resp *domain.ShopQueryResponse, err error) { + if c.request.Body, err = sonic.MarshalString(req); err != nil { + return nil, err + } + c.log.CtxDebugf(ctx, "QueryShop request data: %s", c.request.Body) + if err = c.doRequest(ctx, shopQuery); err != nil { + return nil, err + } + c.log.CtxDebugf(ctx, "QueryShop response data: %s", string(c.response.Body())) if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil { return nil, err } diff --git a/metada.go b/metada.go new file mode 100644 index 0000000..80c1a0e --- /dev/null +++ b/metada.go @@ -0,0 +1,38 @@ +/* + * Copyright ImDaDa-Go Author(https://houseme.github.io/imdada-go/). All Rights Reserved. + * + * This Source Code Form is subject to the terms of the Apache-2.0 License. + * If a copy of the MIT was not distributed with this file, + * You can obtain one at https://github.com/houseme/imdada-go. + */ + +package dada + +import ( + "context" + + "github.com/bytedance/sonic" + + "github.com/houseme/imdada-go/domain" +) + +// QueryCity query city list +// 获取城市信息列表 http://newopen.imdada.cn/#/development/file/cityList +func (c *Client) QueryCity(ctx context.Context, req *domain.CityListQueryRequest) (resp *domain.CityListQueryResponse, err error) { + if req == nil { + c.request.Body = "" + } else { + if c.request.Body, err = sonic.MarshalString(req); err != nil { + return nil, err + } + } + c.log.CtxDebugf(ctx, "QueryCity request data: %s ", c.request.Body) + if err = c.doRequest(ctx, cityCodeList); err != nil { + return nil, err + } + c.log.CtxDebugf(ctx, "QueryCity response data: %s", string(c.response.Body())) + if err = sonic.Unmarshal(c.response.Body(), &resp); err != nil { + return nil, err + } + return +}