consts.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package consts
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/gogf/gf/v2/errors/gerror"
  6. "github.com/gogf/gf/v2/frame/g"
  7. "strings"
  8. "time"
  9. )
  10. var (
  11. ServiceAddress = g.Cfg().MustGet(context.Background(), "tripartite.service").String()
  12. )
  13. var (
  14. LoginOutErr = gerror.New("请重新获取授权")
  15. AuthTimeOut = gerror.New("验证超时")
  16. WaitTimeOut = gerror.New("等待超时")
  17. InvoiceStartTime time.Time
  18. taxCodeItem []*TaxCodeItem
  19. )
  20. func init() {
  21. var (
  22. err error
  23. ctx context.Context
  24. )
  25. InvoiceStartTime, err = time.ParseInLocation(DateFormat_Short, g.Cfg().MustGet(ctx, "invoiceStartTime", "2024-04-23").String(), time.Local)
  26. if err != nil {
  27. g.Log().Panic(ctx, "发票开始时间异常")
  28. }
  29. if err := g.Cfg().MustGet(ctx, "taxCodeList").Struct(&taxCodeItem); err != nil {
  30. g.Log().Panic(ctx, "获取维护的开票项异常")
  31. }
  32. fmt.Println(taxCodeItem)
  33. }
  34. const (
  35. DateFormat_Full = "2006-01-02 15:04:05"
  36. DateFormat_Short = "2006-01-02"
  37. )
  38. type TaxCodeItem struct {
  39. Name string
  40. Code string
  41. }
  42. // GetTaxCodeByName 获取开票项
  43. func GetTaxCodeByName(name string) string {
  44. if name == "" {
  45. return taxCodeItem[0].Code
  46. }
  47. if splitArr := strings.SplitN(name, "-", 2); len(splitArr) == 2 {
  48. for _, item := range taxCodeItem {
  49. if item.Name == splitArr[1] {
  50. return item.Code
  51. }
  52. }
  53. }
  54. return taxCodeItem[0].Code
  55. }