tripartiteTaxCode.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/gogf/gf/v2/errors/gerror"
  6. "github.com/gogf/gf/v2/frame/g"
  7. "github.com/gogf/gf/v2/util/gconv"
  8. )
  9. type Billitem struct {
  10. Name string `json:"name"` //税收分类名称(接口中获取)
  11. Ssflbm string `json:"ssflbm"` //税收分类编码(接口中获取)
  12. Thirdid string `json:"thirdid"` //开票项id 自己定义的唯一id
  13. }
  14. // GetTaxList 返回内容 allTaxCode.json
  15. func (t *TripartiteAuth) GetTaxList() error {
  16. err := CommonDoPost("/index_taxcode/getTaxCodeList",
  17. t.GetFormHeaderWithToken(),
  18. nil,
  19. func(i interface{}) error {
  20. g.Dump(i)
  21. return nil
  22. })
  23. if err != nil {
  24. return gerror.Wrap(err, "Demo")
  25. }
  26. return nil
  27. }
  28. // AddTaxCode 开票项增加
  29. func (t *TripartiteAuth) AddTaxCode(items []Billitem) error {
  30. type AddTaxCodeParam struct {
  31. TaxNum string `json:"taxNum"`
  32. Tel string `json:"tel"`
  33. BillItems []Billitem `json:"billitems"`
  34. }
  35. var (
  36. ctx = context.Background()
  37. param = AddTaxCodeParam{
  38. TaxNum: g.Cfg().MustGet(ctx, "company.taxNum").String(),
  39. Tel: g.Cfg().MustGet(ctx, "company.account").String(),
  40. BillItems: items,
  41. }
  42. )
  43. err := CommonDoPost("/index_taxcode/addTaxCode",
  44. t.GetJsonHeaderWithToken(),
  45. gconv.Map(gconv.String(param)),
  46. nil)
  47. if err != nil {
  48. return gerror.Wrap(err, "Demo")
  49. }
  50. return err
  51. }
  52. // GetSuccessTaxCodeList 查询已维护的开票项
  53. func (t *TripartiteAuth) GetSuccessTaxCodeList() ([]map[string]interface{}, error) {
  54. type (
  55. billItem struct {
  56. Code string `json:"code"`
  57. Name string `json:"name"`
  58. Uuid string `json:"uuid"`
  59. }
  60. )
  61. var (
  62. ctx = context.Background()
  63. billItems []billItem
  64. )
  65. err := CommonDoPost("/index_taxcode/getCompanyTaxCodeList",
  66. t.GetFormHeaderWithToken(),
  67. g.MapStrAny{
  68. "taxNum": g.Cfg().MustGet(ctx, "company.taxNum"),
  69. },
  70. func(i interface{}) error {
  71. return gconv.Struct(i, &billItems)
  72. })
  73. if err != nil {
  74. return nil, gerror.Wrap(err, "查询已维护的开票项异常")
  75. }
  76. return gconv.Maps(billItems), nil
  77. }
  78. // DelTaxCode 删除开票项
  79. func (t *TripartiteAuth) DelTaxCode(uuid string) error {
  80. type (
  81. delItem struct {
  82. UUid string `json:"uuid"`
  83. }
  84. AddTaxCodeParam struct {
  85. TaxNum string `json:"taxNum"`
  86. Tel string `json:"tel"`
  87. BillItems []delItem `json:"billitems"`
  88. }
  89. )
  90. var (
  91. ctx = context.Background()
  92. param = AddTaxCodeParam{
  93. TaxNum: g.Cfg().MustGet(ctx, "company.taxNum").String(),
  94. Tel: g.Cfg().MustGet(ctx, "company.account").String(),
  95. BillItems: []delItem{{UUid: uuid}},
  96. }
  97. )
  98. fmt.Println(gconv.String(param))
  99. err := CommonDoPost("/index_taxcode/delTaxCode",
  100. t.GetJsonHeaderWithToken(),
  101. gconv.Map(gconv.String(param)),
  102. nil)
  103. if err != nil {
  104. return gerror.Wrap(err, "删除开票项异常")
  105. }
  106. return err
  107. }