12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 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: "开票中",
- })
- }
|