266 lines
10 KiB
Go
266 lines
10 KiB
Go
package ebaiapi
|
||
|
||
import (
|
||
"fmt"
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
)
|
||
|
||
// UploadInvoice 上传发票回复
|
||
func (a *API) UploadInvoice(baiduShopId, applicationNo, fileUrl string) (*UploadInvoiceResult, error) {
|
||
param := &UpdateInvoice{
|
||
BaiduShopId: baiduShopId,
|
||
ShopId: "",
|
||
RequestList: nil,
|
||
}
|
||
requestList := make([]ApplicationList, 0, 0)
|
||
requestList = append(requestList, ApplicationList{
|
||
ApplicationNo: applicationNo,
|
||
Status: "",
|
||
InvoiceList: nil,
|
||
FileUrl: fileUrl,
|
||
InvoiceClass: "",
|
||
InvoiceCode: "",
|
||
InvoiceDate: "",
|
||
InvoiceMaterial: "",
|
||
InvoiceNo: "",
|
||
Memo: "",
|
||
LineList: nil,
|
||
MachineCode: "",
|
||
SellerInfo: SellerInfo{},
|
||
TaxAmount: "",
|
||
ValidationCode: "",
|
||
})
|
||
param.RequestList = requestList
|
||
|
||
data, err := a.AccessAPI("invoice.apply.batchUpdate", utils.Struct2Map(param, "", false))
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
if data.ErrNo != 0 {
|
||
return nil, fmt.Errorf(data.Error)
|
||
}
|
||
result := &UploadInvoiceResult{}
|
||
if err = utils.UnmarshalUseNumber(utils.MustMarshal(data.Data), result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
type UploadInvoiceResult struct {
|
||
SuccessfulApplicationNoList []string `json:"successful_application_no_list"`
|
||
FailedApplicationNoList []string `json:"failed_application_no_list"`
|
||
}
|
||
|
||
// UpdateInvoice 申请
|
||
type UpdateInvoice struct {
|
||
BaiduShopId string `json:"baidu_shop_id"`
|
||
ShopId string `json:"shop_id"`
|
||
RequestList []ApplicationList `json:"request_list"`
|
||
}
|
||
|
||
type ApplicationList struct {
|
||
ApplicationNo string `json:"application_no"`
|
||
Status string `json:"status"`
|
||
InvoiceList []InvoiceList `json:"buyer_title"`
|
||
FileUrl string `json:"file_url"`
|
||
InvoiceClass string `json:"invoice_class"`
|
||
InvoiceCode string `json:"invoice_code"`
|
||
InvoiceDate string `json:"invoice_date"`
|
||
InvoiceMaterial string `json:"invoice_material"`
|
||
InvoiceNo string `json:"invoice_no"`
|
||
Memo string `json:"memo"`
|
||
LineList []LineList `json:"line_list"`
|
||
MachineCode string `json:"machine_code"`
|
||
SellerInfo SellerInfo `json:"seller_info"`
|
||
TaxAmount string `json:"tax_amount"`
|
||
ValidationCode string `json:"validation_code"`
|
||
}
|
||
|
||
type InvoiceList struct {
|
||
AmountWithTax float64 `json:"amount_with_tax"`
|
||
AmountWithoutTax float64 `json:"amount_without_tax"`
|
||
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"`
|
||
}
|
||
}
|
||
|
||
type LineList struct {
|
||
AmountWithoutTax float64 `json:"amount_without_tax"`
|
||
CargoName string `json:"cargo_name"`
|
||
CargoNo string `json:"cargo_no"`
|
||
Quantity int `json:"quantity"`
|
||
Specification string `json:"specification"`
|
||
TaxAmount int `json:"tax_amount"`
|
||
TaxRate float64 `json:"tax_rate"`
|
||
Unit string `json:"unit"`
|
||
UnitPrice float64 `json:"unit_price"`
|
||
}
|
||
type SellerInfo struct {
|
||
BankAccount string `json:"bank_account"`
|
||
BankName string `json:"bank_name"`
|
||
Checker string `json:"checker"`
|
||
Clerk string `json:"clerk"`
|
||
Name string `json:"name"`
|
||
Payee string `json:"payee"`
|
||
RegisterAddress string `json:"register_address"`
|
||
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, ShopId: ""})
|
||
}
|
||
|
||
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("定额发票");
|
||
InvoiceContact struct {
|
||
Person string `json:"person"` // 联系人
|
||
Phone string `json:"phone"` // 电话
|
||
} `json:"invoice_contact"`
|
||
} `json:"settings"`
|
||
}
|
||
|
||
// 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"` // 是 邮箱
|
||
}
|