consts.go 1.3 KB

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