diff --git a/platformapi/ebaiapi/im_test.go b/platformapi/ebaiapi/im_test.go index 3c999746..0330d956 100644 --- a/platformapi/ebaiapi/im_test.go +++ b/platformapi/ebaiapi/im_test.go @@ -39,8 +39,10 @@ func TestSendMsg(t *testing.T) { fmt.Println(err) } -func TestNew(t *testing.T) { - a := 1698388286149 - b := int(a / 1000) - fmt.Println(b) +func TestInvoice(t *testing.T) { + api.QueryInvoiceSetting([]string{"1306214718"}) +} + +func TestQueryUnansweredInvoice(t *testing.T) { + api.QueryUnansweredInvoice("1306214718") } diff --git a/platformapi/ebaiapi/invoice.go b/platformapi/ebaiapi/invoice.go index 5c678faf..0110afb4 100644 --- a/platformapi/ebaiapi/invoice.go +++ b/platformapi/ebaiapi/invoice.go @@ -112,3 +112,154 @@ type SellerInfo struct { RegisterPhone string `json:"register_phone"` TaxPayerNum string `json:"tax_payer_num"` } + +// QueryInvoiceSetting 查询门店发票设置 +func (a *API) QueryInvoiceSetting(baiduShopId []string) ([]*SettingList, error) { + parameter := make([]*StoreIdList, 0, len(baiduShopId)) + for _, v := range baiduShopId { + parameter = append(parameter, &StoreIdList{BaiDuShopId: v}) + } + + data, err := a.AccessAPI("invoice.settings.list", map[string]interface{}{"shop_list": parameter}) + if err != nil { + return nil, err + } + if data.ErrNo != 0 { + return nil, fmt.Errorf(data.Error) + } + result := make([]*SettingList, 0, 0) + if err = utils.UnmarshalUseNumber(utils.MustMarshal(data.Data.(map[string]interface{})["settings_list"]), &result); err != nil { + return nil, err + } + return result, nil +} + +type StoreIdList struct { + BaiDuShopId string `json:"baidu_shop_id"` // 平台门店ID + ShopId string `json:"shop_id"` // 合作方门店ID +} + +type SettingList struct { + BaiDuShopId string `json:"baidu_shop_id"` // 平台门店ID + ShopId string `json:"shop_id"` // 合作方门店ID + Settings struct { + InvoiceMode string `json:"invoice_mode"` // 开具方式 SYS_MANUAL 枚举:SYS_MANUAL("人工开具"), OPEN_API("开放平台"), FLASH_INVOICE("闪电开票"), CODE_INVOICE("扫码开票"), H5_REDIRECT("H5植入"),OTHER("其他形式"); + InvoiceMaterial string `json:"invoice_material"` // 发票材质 PAPER 枚举: PAPER("纸质"), ELECTRONIC("电子"); + InvoiceClass string `json:"invoice_class"` // 发票种类 VAT_COMMON 枚举: VAT_COMMON("普通发票"), VAT_SPECIAL("专用发票"), QUOTA("定额发票"); + } `json:"settings"` + InvoiceContact struct { + Person string `json:"person"` // 联系人 + Phone string `json:"phone"` // 电话 + } `json:"invoice_contact"` +} + +// BathUpdateInvoiceSetting 批量更新门店发票设置 +func (a *API) BathUpdateInvoiceSetting(baiDuStoreId string, setting *StoreInvoiceSetting) ([]*ResultList, []*ResultList, error) { + data, err := a.AccessAPI("invoice.settings.batchUpdate", map[string]interface{}{ + "shop_list": append([]*StoreIdList{}, &StoreIdList{BaiDuShopId: baiDuStoreId}), + "settings": &setting, + }) + if err != nil { + return nil, nil, err + } + if data.ErrNo != 0 { + return nil, nil, fmt.Errorf(data.Error) + } + + successList := make([]*ResultList, 0, 0) + failList := make([]*ResultList, 0, 0) + respList := data.Data.(map[string]interface{}) + if respList["success_shop_list"] != nil { + if err = utils.UnmarshalUseNumber(utils.MustMarshal(respList["success_shop_list"]), successList); err != nil { + return nil, nil, err + } + } + if respList["failed_shop_list"] != nil { + if err = utils.UnmarshalUseNumber(utils.MustMarshal(respList["failed_shop_list"]), failList); err != nil { + return nil, nil, err + } + } + + return successList, failList, nil +} + +type StoreInvoiceSetting struct { + InvoiceMaterial string `json:"invoice_material"` // PAPER 枚举: PAPER("纸质"), ELECTRONIC("电子"); + InvoiceClass string `json:"invoice_class"` // VAT_COMMON 枚举: VAT_COMMON("普通发票"), VAT_SPECIAL("专用发票"), QUOTA("定额发票") + InvoiceContact struct { + Person string `json:"person"` // 联系人 + Phone string `json:"phone"` // 电话 + } `json:"invoice_contact"` + InvoiceMode string `json:"invoice_mode"` // 开具方式 SYS_MANUAL 枚举:SYS_MANUAL("人工开具"), OPEN_API("开放平台"), FLASH_INVOICE("闪电开票"), CODE_INVOICE("扫码开票"), H5_REDIRECT("H5植入"),OTHER("其他形式"); +} + +type ResultList struct { + BaiDuShopId string `json:"baidu_shop_id"` // 平台门店ID + ShopId string `json:"shop_id"` // 合作方门店ID + Msg string `json:"msg"` +} + +// QueryUnansweredInvoice 查询门店未回复发票信息 +func (a *API) QueryUnansweredInvoice(baiDuStoreId string) (*QueryUnansweredInvoiceResult, error) { + data, err := a.AccessAPI("invoice.apply.list", map[string]interface{}{ + "baidu_shop_id": baiDuStoreId, + "status": "INIT", + "page_no": 1, + "page_size": 100, + }) + if err != nil { + return nil, err + } + if data.ErrNo != 0 { + return nil, fmt.Errorf(data.Error) + } + result := &QueryUnansweredInvoiceResult{} + if err = utils.UnmarshalUseNumber(utils.MustMarshal(data.Data), result); err != nil { + return nil, err + } + return result, nil +} + +type QueryUnansweredInvoiceResult struct { + PageNo int `json:"page_no"` // 页码 + PageSize int `json:"page_size"` // 每页条数 + TotalCount int `json:"total_count"` // 总条数 + TotalPage int `json:"total_page"` // 总页数 + RecordList []*InvoiceApplyBody `json:"record_list"` // 申请单列表 +} + +// InvoiceApplyBody 用户申请发票body 消息推送接口 +type InvoiceApplyBody struct { + ApplicationNo string `json:"application_no"` // 申请单编号 + BaiduShopId string `json:"baidu_shop_id"` // 平台门店ID,与合作方门店ID至少有一个 + ShopId string `json:"shop_id"` // 合作方门店ID,与平台门店ID 至少有一个 + InvoiceMaterial string `json:"invoice_material"` // 发票材质 + InvoiceClass string `json:"invoice_class"` // 发票种类 + Status string `json:"status"` // 申请状态,目前仅支持 + BuyerTitle struct { + BankAccount string `json:"bank_account"` // 开户行账号 + BankName string `json:"bank_name"` // 开户行名称 + RegisterAddress string `json:"register_address"` // 注册地址 + RegisterPhone string `json:"register_phone"` // 注册地址 + TaxPayerNum string `json:"tax_payer_num"` // 纳税人识别号 + TitleName string `json:"title_name"` // 抬头名称 + TitleType string `json:"title_type"` // 抬头类型 + } `json:"buyer_title"` // 购方信息 + OrderList []struct { + CreateTime int64 `json:"create_time"` + InvoiceAmount float64 `json:"invoice_amount"` + OrderId int64 `json:"order_id"` + } `json:"order_list"` + BuyerContact struct { + Email string `json:"email"` // 邮箱 + } `json:"buyer_contact"` // 购方用户联系信息 + TotalInvoiceAmount float64 `json:"total_invoice_amount"` // 开票总金额,单位元 +} + +// InvoiceEmailPush 邮箱推送 消息推送接口 +type InvoiceEmailPush struct { + ApplicationNo string `json:"application_no"` // 是 申请单编号 + BaiduShopId string `json:"baidu_shop_id"` // 否 平台门店ID,与合作方门店ID至少有一个 + ShopId string `json:"shop_id"` // 否 合作方门店ID,与平台门店ID 至少有一个 + Email string `json:"email"` // 是 邮箱 +} diff --git a/platformapi/ebaiapi/shop_sku_test.go b/platformapi/ebaiapi/shop_sku_test.go index 77229032..6e5594ac 100644 --- a/platformapi/ebaiapi/shop_sku_test.go +++ b/platformapi/ebaiapi/shop_sku_test.go @@ -327,8 +327,9 @@ func TestDeleteStoreSku(t *testing.T) { fmt.Println(101 / 50) } +// TestDeleteSku 删除饿了么商品 func TestDeleteSku(t *testing.T) { - shopId := "667410" + shopId := "805178" param1 := &SkuListParams{ Page: 1, PageSize: 100, @@ -359,13 +360,13 @@ func TestDeleteSku(t *testing.T) { fmt.Println(err) } - categoryList, _ := api.ShopCategoryGet(shopId) - for _, v := range categoryList { - if v.Children != nil { - for _, v2 := range v.Children { - api.ShopCategoryDelete(shopId, v2.CategoryID) - } - } - api.ShopCategoryDelete(shopId, v.CategoryID) - } + //categoryList, _ := api.ShopCategoryGet(shopId) + //for _, v := range categoryList { + // if v.Children != nil { + // for _, v2 := range v.Children { + // api.ShopCategoryDelete(shopId, v2.CategoryID) + // } + // } + // api.ShopCategoryDelete(shopId, v.CategoryID) + //} } diff --git a/platformapi/mtwmapi/mtwmapi.go b/platformapi/mtwmapi/mtwmapi.go index 599cd923..d9c05e20 100644 --- a/platformapi/mtwmapi/mtwmapi.go +++ b/platformapi/mtwmapi/mtwmapi.go @@ -5,6 +5,7 @@ import ( "crypto/md5" "fmt" "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/globals" "mime/multipart" "net/http" "net/url" @@ -149,6 +150,7 @@ func (a *API) AccessAPI2(cmd string, isGet bool, bizParams map[string]interface{ } signURL := a.genURL(cmd) + "?" params[signKey] = a.signParams(signURL, params) + globals.SugarLogger.Debugf("------sing := %s", utils.Format4Output(params[signKey], false)) err = platformapi.AccessPlatformAPIWithRetry(a.client, func() *http.Request { var request *http.Request