Bläddra i källkod

wip:临时提交

wangkaiyue 1 år sedan
förälder
incheckning
34640454e9

+ 11 - 7
config.yaml

@@ -10,6 +10,11 @@ logger:
   level: "all"
   stdout: true
 
+database:
+  default:
+    link: "mysql:root:=PDT49#80Z!RVv52_z@tcp(192.168.3.14:4000)/jianyu"
+    debug: true
+
 #发票三方系统配置
 # 测试
 tripartite:
@@ -23,10 +28,6 @@ tripartite:
 #  clientId: e061913340b7f236
 #  clientSecret: 048d69910897525f0e0e2855b3b0e94e
 
-# 发票三方系统配置-接口回调
-callBack:
-  #flush: true #是否同步回调地址 默认false
-  action: "https://wky.jydev.jianyu360.com/Invoice/callback"
 
 # 公司税务发表系统账户
 company:
@@ -35,13 +36,16 @@ company:
   tel: "13733157437"
   password: "13733157437Ph"
 
+# 开票任务
+invoiceJob:
+  stop: false # 是否停止任务(临时停止任务)
+  cron: "# */30 9-18 * * *"
+
 # 登录相关配置
 loginType: 0 # 税务系统登录方式【0 短信登录 1 扫码登录】
 qwxRobotUrl: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=e7792e7a-159d-4419-b1ed-27ea19b6ea54" #扫码登录企业微信消息机器人接口
 
-jyPayNotice: "http://192.168.20.241:86/jypay/invoice/callback"
-
-
 pdfFilePathRootDir: "./out"
 pdfFilePathPrefix: "jyInvoice" #即请求路径前缀
 
+

+ 12 - 6
go.mod

@@ -3,31 +3,37 @@ module ElectronicInvoice
 go 1.18
 
 require (
-	github.com/gogf/gf/v2 v2.5.2
+	github.com/gogf/gf/contrib/drivers/mysql/v2 v2.7.0
+	github.com/gogf/gf/contrib/nosql/redis/v2 v2.7.0
+	github.com/gogf/gf/v2 v2.7.0
 	github.com/satori/go.uuid v1.2.0
 	github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
 )
 
 require (
 	github.com/BurntSushi/toml v1.2.0 // indirect
+	github.com/cespare/xxhash/v2 v2.2.0 // indirect
 	github.com/clbanning/mxj/v2 v2.7.0 // indirect
+	github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
 	github.com/fatih/color v1.15.0 // indirect
-	github.com/fsnotify/fsnotify v1.6.0 // indirect
+	github.com/fsnotify/fsnotify v1.7.0 // indirect
 	github.com/go-logr/logr v1.2.4 // indirect
 	github.com/go-logr/stdr v1.2.2 // indirect
+	github.com/go-sql-driver/mysql v1.7.1 // indirect
 	github.com/gorilla/websocket v1.5.0 // indirect
 	github.com/grokify/html-strip-tags-go v0.0.1 // indirect
 	github.com/magiconair/properties v1.8.6 // indirect
 	github.com/mattn/go-colorable v0.1.13 // indirect
-	github.com/mattn/go-isatty v0.0.19 // indirect
+	github.com/mattn/go-isatty v0.0.20 // indirect
 	github.com/mattn/go-runewidth v0.0.15 // indirect
 	github.com/olekukonko/tablewriter v0.0.5 // indirect
+	github.com/redis/go-redis/v9 v9.2.1 // indirect
 	github.com/rivo/uniseg v0.4.4 // indirect
 	go.opentelemetry.io/otel v1.14.0 // indirect
 	go.opentelemetry.io/otel/sdk v1.14.0 // indirect
 	go.opentelemetry.io/otel/trace v1.14.0 // indirect
-	golang.org/x/net v0.12.0 // indirect
-	golang.org/x/sys v0.10.0 // indirect
-	golang.org/x/text v0.11.0 // indirect
+	golang.org/x/net v0.17.0 // indirect
+	golang.org/x/sys v0.13.0 // indirect
+	golang.org/x/text v0.13.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect
 )

+ 26 - 13
go.sum

@@ -1,19 +1,31 @@
 github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
 github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
+github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
+github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
+github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
+github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
 github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
 github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
+github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
 github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
 github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
-github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
-github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
+github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
+github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
 github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
 github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
 github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
 github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
 github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
-github.com/gogf/gf/v2 v2.5.2 h1:fACJE7DJH6iTGHGhgiNY1uuZIZtr2IqQkJ52E+wBnt8=
-github.com/gogf/gf/v2 v2.5.2/go.mod h1:7yf5qp0BznfsYx7Sw49m3mQvBsHpwAjJk3Q9ZnKoUEc=
+github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
+github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
+github.com/gogf/gf/contrib/drivers/mysql/v2 v2.7.0 h1:5Igvtz4gy5UMvH+Ut4kLIpwSzggV9ZgDVBsIiOctH5E=
+github.com/gogf/gf/contrib/drivers/mysql/v2 v2.7.0/go.mod h1:0+flZ0clMKjtH1sTI7YD2KG4FPr8xz0L9h1WMd5M2Z8=
+github.com/gogf/gf/contrib/nosql/redis/v2 v2.7.0 h1:hJxshC0gZyFZaGo2HItXd5XMzIMbCRcgShr1ljMYwUc=
+github.com/gogf/gf/contrib/nosql/redis/v2 v2.7.0/go.mod h1:is3Q3ItZSPMZ1RBJ3xIcEasyGZnOg8eNeG9dubOx/zc=
+github.com/gogf/gf/v2 v2.7.0 h1:CjxhbMiE7oqf6K8ZtGuKt3dQEwK4vL6LhiI+dI7tJGU=
+github.com/gogf/gf/v2 v2.7.0/go.mod h1:Qu8nimKt9aupJQcdUL85tWF4Mfxocz97zUt8UC4abVI=
 github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
 github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
 github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
@@ -24,14 +36,16 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK
 github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
 github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
 github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
-github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
-github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
+github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
 github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
 github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
 github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
 github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
 github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/redis/go-redis/v9 v9.2.1 h1:WlYJg71ODF0dVspZZCpYmoF1+U1Jjk9Rwd7pq6QmlCg=
+github.com/redis/go-redis/v9 v9.2.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
 github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
 github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
 github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
@@ -46,15 +60,14 @@ go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvx
 go.opentelemetry.io/otel/sdk v1.14.0/go.mod h1:bwIC5TjrNG6QDCHNWvW4HLHtUQ4I+VQDsnjhvyZCALM=
 go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M=
 go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8=
-golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
-golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
+golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
+golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
 golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
-golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
-golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
+golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
+golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
+golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

+ 5 - 3
internal/cmd/cmd.go

@@ -18,9 +18,11 @@ var (
 		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
 			s := g.Server()
 			s.Group("/Invoice", func(group *ghttp.RouterGroup) {
-				group.POST("/callback", controller.CallBack)     //开票回调
-				group.GET("/Add", controller.InvoiceAdd)         //开票
-				group.GET("/Replace", controller.InvoiceReplace) //换票(红冲+开票)
+				group.POST("/callback", controller.CallBack) //开票回调
+				group.POST("/control", controller.CallBack)  //控制开票接口 控制开关
+
+				//group.GET("/Add", controller.InvoiceAdd)         //开票
+				//group.GET("/Replace", controller.InvoiceReplace) //换票(红冲+开票)
 			})
 			s.Run()
 			return nil

+ 0 - 2
internal/controller/callback.go

@@ -37,5 +37,3 @@ func CallBack(r *ghttp.Request) {
 	}
 	r.Response.WriteJson(g.MapStrStr{"code": "200"})
 }
-
-//callbak = logging

+ 171 - 92
internal/controller/invoiceAdd.go

@@ -1,94 +1,173 @@
 package controller
 
-import (
-	"ElectronicInvoice/internal/service/tripartite"
-	"github.com/gogf/gf/v2/errors/gerror"
-	"github.com/gogf/gf/v2/frame/g"
-	"github.com/gogf/gf/v2/net/ghttp"
-	"github.com/gogf/gf/v2/util/gconv"
-)
-
-type (
-	addInvoiceAddParam struct {
-		OrderCode string    `json:"Swno"`      //orderCode订单号
-		CustType  string    `json:"custType"`  //购货方企业类型 01:企业 02:机关执业单位 03:个人 04:其他
-		CustTaxNo string    `json:"custTaxNo"` //纳税人税号
-		Phone     string    `json:"phone"`     //手机号
-		BillDate  string    `json:"billDate"`  //单据日期  格式:yyyy-MM-dd HH:mm:ss
-		CustName  string    `json:"custName"`  //购方名称
-		Orders    []*orders `json:"orders"`    //发票内容
-	}
-
-	orders struct {
-		BillNo string   `json:"billNo"` //订单号
-		Items  []*items `json:"items"`
-	}
-
-	items struct {
-		Name        string `json:"name"`        //商品名称
-		Code        string `json:"code"`        //商品编号(税收分类编码)
-		Yhzcbs      string `json:"yhzcbs"`      //享受税收优惠政策内容
-		LineType    string `json:"lineType"`    //发票行性质 0:正常行1:折扣行2:被折扣行
-		TaxRate     string `json:"taxRate"`     //税率
-		TaxPrice    string `json:"taxPrice"`    //单价
-		TotalAmount string `json:"totalAmount"` //含税金额
-		Quantity    string `json:"quantity"`    //数量
-	}
-
-	addInvoiceAddResp struct {
-		Code int               `json:"code"` //0 开票成功;2 开票中 ;其他开票失败
-		Msg  interface{}       `json:"msg,omitempty"`
-		Data addInvoiceAddData `json:"data,omitempty"` //异步开票,通过回调通知
-	}
-	addInvoiceAddData struct {
-		Swno string `json:"swno"` //流水号  invoice_serialnum
-		Fpdm string `json:"fpdm"` //发票代码  invoice_code
-		Fphm string `json:"fphm"` //发票号码  invoice_number
-		Path string `json:"path"` //pdf地址  url
-	}
-)
-
-// InvoiceAdd 开票
-func InvoiceAdd(r *ghttp.Request) {
-	var param *addInvoiceAddParam
-	err := func() error {
-		err := gconv.Struct(r.GetBody(), param)
-		if err != nil {
-			return gerror.Wrap(err, "获取参数异常")
-		}
-		// 存入开票记录表
-
-		// 调用第三方开票接口
-		if err := tripartite.MakeSingleInvoice(tripartite.MakeInvoiceData{
-			Type:      "2",
-			Gmfmc:     param.CustName,
-			Gmfnsrsbh: param.CustTaxNo,
-			Id:        param.OrderCode,
-			//Gmfdz:     "北京市朝阳区安定路5号院13号楼B座12层1201室",
-			Lxdh: param.Phone,
-			//Yhyywdmc:  "郑州交通银行总行",
-			//Yhzh:      "6320123123000121",
-			InvoiceArr: []tripartite.MakeInvoiceItems{{
-				Xmmc:     "0fccdac71c36a8552ba662e7a2f42726",
-				WhStatus: 1,
-				Je:       param.Orders[0].Items[0].TaxPrice,
-				Sl:       "1",
-			}},
-		}); err != nil {
-			return gerror.Wrapf(err, "调用开票接口异常%v", err)
-		}
-		return nil
-	}()
-	if err != nil {
-		g.Log().Errorf(r.Context(), "处理开票业务异常")
-		r.Response.Write(addInvoiceAddResp{
-			Code: -1,
-			Msg:  err.Error(),
-		})
-		return
-	}
-	r.Response.Write(addInvoiceAddResp{
-		Code: 0,
-		Msg:  "开票中",
-	})
-}
+//
+//type (
+//	addInvoiceAddParam struct {
+//		OrderCode string    `json:"Swno"`      //orderCode订单号
+//		CustType  string    `json:"custType"`  //购货方企业类型 01:企业 02:机关执业单位 03:个人 04:其他
+//		CustTaxNo string    `json:"custTaxNo"` //纳税人税号
+//		Phone     string    `json:"phone"`     //手机号
+//		BillDate  string    `json:"billDate"`  //单据日期  格式:yyyy-MM-dd HH:mm:ss
+//		CustName  string    `json:"custName"`  //购方名称
+//		Orders    []*orders `json:"orders"`    //发票内容
+//	}
+//
+//	orders struct {
+//		BillNo string   `json:"billNo"` //订单号
+//		Items  []*items `json:"items"`
+//	}
+//
+//	items struct {
+//		Name        string `json:"name"`        //商品名称
+//		Code        string `json:"code"`        //商品编号(税收分类编码)
+//		Yhzcbs      string `json:"yhzcbs"`      //享受税收优惠政策内容
+//		LineType    string `json:"lineType"`    //发票行性质 0:正常行1:折扣行2:被折扣行
+//		TaxRate     string `json:"taxRate"`     //税率
+//		TaxPrice    string `json:"taxPrice"`    //单价
+//		TotalAmount string `json:"totalAmount"` //含税金额
+//		Quantity    string `json:"quantity"`    //数量
+//	}
+//
+//	addInvoiceAddResp struct {
+//		Code int               `json:"code"` //0 开票成功;2 开票中 ;其他开票失败
+//		Msg  interface{}       `json:"msg,omitempty"`
+//		Data addInvoiceAddData `json:"data,omitempty"` //异步开票,通过回调通知
+//	}
+//	addInvoiceAddData struct {
+//		Swno string `json:"swno"` //流水号  invoice_serialnum
+//		Fpdm string `json:"fpdm"` //发票代码  invoice_code
+//		Fphm string `json:"fphm"` //发票号码  invoice_number
+//		Path string `json:"path"` //pdf地址  url
+//	}
+//)
+//
+//// InvoiceAdd 开票
+//func InvoiceAdd(r *ghttp.Request) {
+//	err := func() error {
+//		haLogin, sessVal := service.GetJySessionVal(r)
+//		if !haLogin {
+//			return gerror.New("未登录")
+//		}
+//		var (
+//			orderCode    = r.Get("order_code").String()
+//			invoiceType  = r.Get("invoice_type").String() //个人 or 企业
+//			mail         = r.Get("email").String()
+//			phoneNum     = r.Get("phone_num").String()
+//			companyName  = r.Get("company").String() //公司名字
+//			companyTaxNo = r.Get("id_num").String()  //企业税号
+//			userId       = gconv.String(sessVal["userId"])
+//		)
+//		if (mail != "" || phoneNum != "" || orderCode != "") || (invoiceType == "企业" && (companyName == "" || companyTaxNo == "")) {
+//			return gerror.New("缺少参数")
+//		}
+//		orderRes, err := g.DB().GetOne(r.Context(), "SELECT order_money,product_type,order_channel,pay_way,pay_money,is_backstage_order,billingMode FROM dataexport_order WHERE order_code=? AND user_id=? AND applyBill_status!=2", orderCode, userId)
+//		if err != nil || orderRes.IsEmpty() {
+//			g.Log().Errorf(r.Context(), "查询%d订单异常 err:%v", orderCode, err)
+//			return gerror.New("未知订单")
+//		}
+//		if !(gconv.Int(orderRes["billingMode"]) == 1 && (gconv.Int(orderRes["is_backstage_order"]) != 1 || gconv.String(orderRes["order_channel"]) == "xdqd04")) {
+//			return gerror.New("改订单不支持线上开票")
+//		}
+//		var (
+//			prices          float64
+//			price           = strconv.FormatFloat(prices, 'f', -1, 64)
+//			product_name    = gconv.String(orderRes["product_type"])
+//			dataexport_data = map[string]interface{}{}
+//			data            = map[string]interface{}{}
+//		)
+//		//公对公转账 账单金额可以修改 开发票应取实付金额 pay_money
+//		//微信支付宝支付 pay_money为订单金额减去微信or支付包红包
+//		if gconv.String(orderRes["pay_way"]) == "transferAccounts" {
+//			prices = gconv.Float64(orderRes["pay_money"]) / float64(100)
+//		} else {
+//			prices = gconv.Float64(orderRes["order_money"]) / float64(100)
+//		}
+//		dataexport_data["applyBill_status"] = 1
+//		if invoiceType == "个人" {
+//			dataexport_data["applyBill_type"] = 0
+//			data["taxpayer_identnum"] = ""
+//			data["company_name"] = ""
+//			dataexport_data["applyBill_taxnum"] = ""
+//			dataexport_data["applybill_company"] = ""
+//		} else {
+//			data["taxpayer_identnum"] = companyTaxNo
+//			data["company_name"] = companyName
+//			dataexport_data["applyBill_taxnum"] = companyTaxNo
+//			dataexport_data["applybill_company"] = companyName
+//			dataexport_data["applyBill_type"] = 1
+//		}
+//		dataexport_data["user_mail"] = mail
+//
+//		data["product_type"] = product_name
+//		data["order_code"] = orderCode
+//		data["mail"] = mail
+//		data["phone"] = phoneNum
+//		data["invoice_type"] = invoiceType
+//		data["invoice_changed"] = 0
+//		data["create_time"] = time.Now().Unix()
+//		data["user_id"] = userId
+//		data["invoice_status"] = 0
+//
+//		//g.DB().GetCount(r.Context(),"SELECT count(*) FROM invoice WHERE order_code=? and user_id=?",orderCode,userId)
+//		//
+//		//status := g.DB().(dbname, map[string]interface{}{"order_code": order_code, "user_id": userId}, "", "create_time", 0, 0)
+//		//if len(*status) > 0 {
+//		//	return nil
+//		//}
+//		//util.Mysql.Insert(dbname, data)
+//		//if !util.Mysql.Update("dataexport_order", map[string]interface{}{"order_code": order_code, "user_id": userId}, dataexport_data) {
+//		//	invoice_status = -1
+//		//}
+//		g.Dump(price)
+//
+//		return nil
+//	}()
+//	if err != nil {
+//
+//	}
+//
+//}
+//
+//func InvoiceAdd222(r *ghttp.Request) {
+//	var param *addInvoiceAddParam
+//	err := func() error {
+//		err := gconv.Struct(r.GetBody(), param)
+//		if err != nil {
+//			return gerror.Wrap(err, "获取参数异常")
+//		}
+//		// 存入开票记录表
+//
+//		// 调用第三方开票接口
+//		if err := tripartite.MakeSingleInvoice(tripartite.MakeInvoiceData{
+//			Type:      "2",
+//			Gmfmc:     param.CustName,
+//			Gmfnsrsbh: param.CustTaxNo,
+//			Id:        param.OrderCode,
+//			//Gmfdz:     "北京市朝阳区安定路5号院13号楼B座12层1201室",
+//			Lxdh: param.Phone,
+//			//Yhyywdmc:  "郑州交通银行总行",
+//			//Yhzh:      "6320123123000121",
+//			InvoiceArr: []tripartite.MakeInvoiceItems{{
+//				Xmmc:     "0fccdac71c36a8552ba662e7a2f42726",
+//				WhStatus: 1,
+//				Je:       param.Orders[0].Items[0].TaxPrice,
+//				Sl:       "1",
+//			}},
+//		}); err != nil {
+//			return gerror.Wrapf(err, "调用开票接口异常%v", err)
+//		}
+//		return nil
+//	}()
+//	if err != nil {
+//		g.Log().Errorf(r.Context(), "处理开票业务异常")
+//		r.Response.Write(addInvoiceAddResp{
+//			Code: -1,
+//			Msg:  err.Error(),
+//		})
+//		return
+//	}
+//	r.Response.Write(addInvoiceAddResp{
+//		Code: 0,
+//		Msg:  "开票中",
+//	})
+//}

+ 0 - 8
internal/controller/invoiceReplace.go

@@ -1,8 +0,0 @@
-package controller
-
-import "github.com/gogf/gf/v2/net/ghttp"
-
-// InvoiceReplace 换票(红冲+开票)
-func InvoiceReplace(r *ghttp.Request) {
-
-}

+ 0 - 1
internal/service/invoiceCallback.go

@@ -46,7 +46,6 @@ func InvoicingCallBackLogic(r *ghttp.Request) error {
 			return gerror.Wrap(err, "pdf文件写入异常")
 		}
 		g.Log().Infof(r.Context(), "pdf保存成功 orderCode:%s filePath:%s ", orderCode, fileFullPath)
-		JyPayNotice()
 		return nil
 	case 3:
 		g.Log().Error(r.Context(), "活体验证已过期,未完成活体验证")

+ 0 - 6
internal/service/invoiceNotice.go

@@ -1,6 +0,0 @@
-package service
-
-// JyPayNotice 发送开发票结果给支付程序
-func JyPayNotice() {
-
-}

+ 123 - 0
internal/service/tripartiteAuth.go

@@ -0,0 +1,123 @@
+package service
+
+import (
+	"ElectronicInvoice/internal/consts"
+	"context"
+	"fmt"
+	"github.com/gogf/gf/v2/errors/gerror"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/net/gclient"
+	"github.com/gogf/gf/v2/util/gconv"
+	"strings"
+	"time"
+)
+
+type (
+	TripartiteAuth struct {
+		token         string
+		effectiveTime time.Time
+	}
+)
+
+func createTripartite() *TripartiteAuth {
+	t := &TripartiteAuth{}
+	_, err := t.GetToken(true)
+	if err != nil {
+		g.Log().Errorf(context.Background(), "刷新token异常%v", err)
+	}
+	return t
+}
+
+// GetToken 获取token
+func (t *TripartiteAuth) GetToken(reload ...bool) (string, error) {
+	var (
+		ctx = context.Background()
+	)
+	type (
+		tokenResData struct {
+			Token     string `json:"token"`
+			ExpiresIn int    `json:"expiresIn"` //一天有效期
+		}
+	)
+	if time.Now().Before(t.effectiveTime) && t.token != "" && len(reload) == 0 {
+		return t.token, nil
+	}
+	err := CommonDoPost("/authority_token/getToken",
+		g.MapStrStr{"Content-Type": "application/x-www-form-urlencoded"},
+		g.MapStrAny{
+			"client_id":     g.Cfg().MustGet(ctx, "TripartiteAuth.clientId"),
+			"client_secret": g.Cfg().MustGet(ctx, "TripartiteAuth.clientSecret"),
+		},
+		func(i interface{}) error {
+			var d tokenResData
+			if err := gconv.Struct(i, &d); err != nil {
+				return err
+			}
+			t.token = d.Token
+			t.effectiveTime = time.Now().Add(time.Second * time.Duration(d.ExpiresIn))
+			return nil
+		})
+	if err != nil {
+		return "", err
+	}
+	return t.token, nil
+}
+
+// GetFormHeaderWithToken 携带token的form请求头
+func (t *TripartiteAuth) GetFormHeaderWithToken() map[string]string {
+	token, err := t.GetToken()
+	if err != nil {
+		g.Log().Panic(context.Background(), gerror.Wrap(err, "GetFormHeaderWithToken 获取token异常"))
+	}
+	return g.MapStrStr{
+		"Content-Type":  "application/x-www-form-urlencoded",
+		"API-AuthToken": token,
+	}
+}
+
+// GetJsonHeaderWithToken 携带token的json请求头
+func (t *TripartiteAuth) GetJsonHeaderWithToken() map[string]string {
+	token, err := t.GetToken()
+	if err != nil {
+		g.Log().Panic(context.Background(), gerror.Wrap(err, "GetJsonHeaderWithToken 获取token异常"))
+	}
+	return g.MapStrStr{
+		"Content-Type":  "application/json",
+		"API-AuthToken": token,
+	}
+}
+
+func CommonDoPost(url string, header map[string]string, param map[string]interface{}, success func(interface{}) error) (err error) {
+	var (
+		res *gclient.Response
+		ctx = context.Background()
+	)
+	type CommonRes struct {
+		Code int         `json:"code"`
+		Msg  string      `json:"msg"`
+		Data interface{} `json:"data"`
+	}
+	res, err = g.Client().Header(header).Post(ctx, fmt.Sprintf("%s%s", consts.ServiceAddress, url), param)
+	if err != nil {
+		return
+	}
+	defer res.Close()
+
+	respByte := res.ReadAll()
+	//打印请求三方开票系统日志
+	if g.Cfg().MustGet(ctx, "reqDebug", false).Bool() {
+		g.Log().Infof(ctx, "%s\nrequest: %s\nheader: %+v\nparam: %+v\nresp: %s", strings.Repeat("=", 50), url, header, param, string(respByte))
+	}
+
+	var commonRes CommonRes
+	if err := gconv.Struct(respByte, &commonRes); err != nil {
+		return err
+	}
+	if commonRes.Code == 200 {
+		if success != nil {
+			return success(commonRes.Data)
+		}
+		return nil
+	}
+	return fmt.Errorf("CommonDoPost:%s \nErrorCode:%d Msg:%s", url, commonRes.Code, commonRes.Msg)
+}

+ 65 - 0
internal/service/tripartiteInvoice.go

@@ -0,0 +1,65 @@
+package service
+
+import (
+	"context"
+	"github.com/gogf/gf/v2/errors/gerror"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/util/gconv"
+)
+
+type (
+	makeInvoiceAllParam struct {
+		TaxNum string            `json:"taxNum"` //企业税号*
+		Tel    string            `json:"tel"`    //登录电子税局手机号或身份证号*
+		Data   []MakeInvoiceData `json:"data"`
+	}
+
+	MakeInvoiceData struct {
+		Type       string             `json:"type"`      //票类* 1 增值税专用发票;2 普通发票
+		Gmfmc      string             `json:"gmfmc"`     //购买方名称* 人名
+		Gmfnsrsbh  string             `json:"gmfnsrsbh"` //购买方纳税人识别号* 身份证号
+		Id         string             `json:"id"`        //发票流水号* 合作商开具的发票流水号,涉及到回调通知
+		Gmfdz      string             `json:"gmfdz"`     //购买方地址
+		Lxdh       string             `json:"lxdh"`      //购买方联系方式
+		Yhyywdmc   string             `json:"yhyywdmc"`  //购买方开户行
+		Yhzh       string             `json:"yhzh"`      //购买方银行账号
+		Notes      string             `json:"notes"`     //发票备注
+		InvoiceArr []MakeInvoiceItems `json:"invoiceArr"`
+	}
+
+	MakeInvoiceItems struct {
+		Xmmc     string `json:"xmmc"`      //项目名称*
+		Je       string `json:"je"`        //开票金额*
+		WhStatus int    `json:"wh_status"` //该开票项是否已调用接口进行维护: 1 已维护;0 未维护
+		Xhgg     string `json:"xhgg"`      //型号规格
+		Dw       string `json:"dw"`        //单位
+		Sl       string `json:"sl"`        //数量
+		Tsaxrate string `json:"taxrate"`   //税率
+	}
+)
+
+// MakeSingleInvoice 开单张发票
+func (t *TripartiteAuth) MakeSingleInvoice(param MakeInvoiceData) (err error) {
+	return t.MakeInvoices([]MakeInvoiceData{param})
+}
+
+// MakeInvoices 开多张发票
+func (t *TripartiteAuth) MakeInvoices(invoices []MakeInvoiceData) (err error) {
+	var (
+		ctx   = context.Background()
+		param = makeInvoiceAllParam{
+			TaxNum: g.Cfg().MustGet(ctx, "company.taxNum").String(),
+			Tel:    g.Cfg().MustGet(ctx, "company.tel").String(),
+			Data:   invoices,
+		}
+	)
+	err = CommonDoPost("/index_index/makeInvoiceC",
+		t.GetJsonHeaderWithToken(),
+		gconv.Map(gconv.String(param)),
+		nil)
+	if err != nil {
+		err = gerror.Wrap(err, "开票接口异常")
+		return
+	}
+	return nil
+}

+ 2 - 0
main.go

@@ -2,6 +2,8 @@ package main
 
 import (
 	"ElectronicInvoice/internal/cmd"
+	_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
+	_ "github.com/gogf/gf/contrib/nosql/redis/v2"
 	"github.com/gogf/gf/v2/os/gctx"
 )