invoiceAdd.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package controller
  2. //
  3. //type (
  4. // addInvoiceAddParam struct {
  5. // OrderCode string `json:"Swno"` //orderCode订单号
  6. // CustType string `json:"custType"` //购货方企业类型 01:企业 02:机关执业单位 03:个人 04:其他
  7. // CustTaxNo string `json:"custTaxNo"` //纳税人税号
  8. // Phone string `json:"phone"` //手机号
  9. // BillDate string `json:"billDate"` //单据日期 格式:yyyy-MM-dd HH:mm:ss
  10. // CustName string `json:"custName"` //购方名称
  11. // Orders []*orders `json:"orders"` //发票内容
  12. // }
  13. //
  14. // orders struct {
  15. // BillNo string `json:"billNo"` //订单号
  16. // Items []*items `json:"items"`
  17. // }
  18. //
  19. // items struct {
  20. // Name string `json:"name"` //商品名称
  21. // Code string `json:"code"` //商品编号(税收分类编码)
  22. // Yhzcbs string `json:"yhzcbs"` //享受税收优惠政策内容
  23. // LineType string `json:"lineType"` //发票行性质 0:正常行1:折扣行2:被折扣行
  24. // TaxRate string `json:"taxRate"` //税率
  25. // TaxPrice string `json:"taxPrice"` //单价
  26. // TotalAmount string `json:"totalAmount"` //含税金额
  27. // Quantity string `json:"quantity"` //数量
  28. // }
  29. //
  30. // addInvoiceAddResp struct {
  31. // Code int `json:"code"` //0 开票成功;2 开票中 ;其他开票失败
  32. // Msg interface{} `json:"msg,omitempty"`
  33. // Data addInvoiceAddData `json:"data,omitempty"` //异步开票,通过回调通知
  34. // }
  35. // addInvoiceAddData struct {
  36. // Swno string `json:"swno"` //流水号 invoice_serialnum
  37. // Fpdm string `json:"fpdm"` //发票代码 invoice_code
  38. // Fphm string `json:"fphm"` //发票号码 invoice_number
  39. // Path string `json:"path"` //pdf地址 url
  40. // }
  41. //)
  42. //
  43. //// InvoiceAdd 开票
  44. //func InvoiceAdd(r *ghttp.Request) {
  45. // err := func() error {
  46. // haLogin, sessVal := service.GetJySessionVal(r)
  47. // if !haLogin {
  48. // return gerror.New("未登录")
  49. // }
  50. // var (
  51. // orderCode = r.Get("order_code").String()
  52. // invoiceType = r.Get("invoice_type").String() //个人 or 企业
  53. // mail = r.Get("email").String()
  54. // phoneNum = r.Get("phone_num").String()
  55. // companyName = r.Get("company").String() //公司名字
  56. // companyTaxNo = r.Get("id_num").String() //企业税号
  57. // userId = gconv.String(sessVal["userId"])
  58. // )
  59. // if (mail != "" || phoneNum != "" || orderCode != "") || (invoiceType == "企业" && (companyName == "" || companyTaxNo == "")) {
  60. // return gerror.New("缺少参数")
  61. // }
  62. // 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)
  63. // if err != nil || orderRes.IsEmpty() {
  64. // g.Log().Errorf(r.Context(), "查询%d订单异常 err:%v", orderCode, err)
  65. // return gerror.New("未知订单")
  66. // }
  67. // if !(gconv.Int(orderRes["billingMode"]) == 1 && (gconv.Int(orderRes["is_backstage_order"]) != 1 || gconv.String(orderRes["order_channel"]) == "xdqd04")) {
  68. // return gerror.New("改订单不支持线上开票")
  69. // }
  70. // var (
  71. // prices float64
  72. // price = strconv.FormatFloat(prices, 'f', -1, 64)
  73. // product_name = gconv.String(orderRes["product_type"])
  74. // dataexport_data = map[string]interface{}{}
  75. // data = map[string]interface{}{}
  76. // )
  77. // //公对公转账 账单金额可以修改 开发票应取实付金额 pay_money
  78. // //微信支付宝支付 pay_money为订单金额减去微信or支付包红包
  79. // if gconv.String(orderRes["pay_way"]) == "transferAccounts" {
  80. // prices = gconv.Float64(orderRes["pay_money"]) / float64(100)
  81. // } else {
  82. // prices = gconv.Float64(orderRes["order_money"]) / float64(100)
  83. // }
  84. // dataexport_data["applyBill_status"] = 1
  85. // if invoiceType == "个人" {
  86. // dataexport_data["applyBill_type"] = 0
  87. // data["taxpayer_identnum"] = ""
  88. // data["company_name"] = ""
  89. // dataexport_data["applyBill_taxnum"] = ""
  90. // dataexport_data["applybill_company"] = ""
  91. // } else {
  92. // data["taxpayer_identnum"] = companyTaxNo
  93. // data["company_name"] = companyName
  94. // dataexport_data["applyBill_taxnum"] = companyTaxNo
  95. // dataexport_data["applybill_company"] = companyName
  96. // dataexport_data["applyBill_type"] = 1
  97. // }
  98. // dataexport_data["user_mail"] = mail
  99. //
  100. // data["product_type"] = product_name
  101. // data["order_code"] = orderCode
  102. // data["mail"] = mail
  103. // data["phone"] = phoneNum
  104. // data["invoice_type"] = invoiceType
  105. // data["invoice_changed"] = 0
  106. // data["create_time"] = time.Now().Unix()
  107. // data["user_id"] = userId
  108. // data["invoice_status"] = 0
  109. //
  110. // //g.DB().GetCount(r.Context(),"SELECT count(*) FROM invoice WHERE order_code=? and user_id=?",orderCode,userId)
  111. // //
  112. // //status := g.DB().(dbname, map[string]interface{}{"order_code": order_code, "user_id": userId}, "", "create_time", 0, 0)
  113. // //if len(*status) > 0 {
  114. // // return nil
  115. // //}
  116. // //util.Mysql.Insert(dbname, data)
  117. // //if !util.Mysql.Update("dataexport_order", map[string]interface{}{"order_code": order_code, "user_id": userId}, dataexport_data) {
  118. // // invoice_status = -1
  119. // //}
  120. // g.Dump(price)
  121. //
  122. // return nil
  123. // }()
  124. // if err != nil {
  125. //
  126. // }
  127. //
  128. //}
  129. //
  130. //func InvoiceAdd222(r *ghttp.Request) {
  131. // var param *addInvoiceAddParam
  132. // err := func() error {
  133. // err := gconv.Struct(r.GetBody(), param)
  134. // if err != nil {
  135. // return gerror.Wrap(err, "获取参数异常")
  136. // }
  137. // // 存入开票记录表
  138. //
  139. // // 调用第三方开票接口
  140. // if err := tripartite.MakeSingleInvoice(tripartite.MakeInvoiceData{
  141. // Type: "2",
  142. // Gmfmc: param.CustName,
  143. // Gmfnsrsbh: param.CustTaxNo,
  144. // Id: param.OrderCode,
  145. // //Gmfdz: "北京市朝阳区安定路5号院13号楼B座12层1201室",
  146. // Lxdh: param.Phone,
  147. // //Yhyywdmc: "郑州交通银行总行",
  148. // //Yhzh: "6320123123000121",
  149. // InvoiceArr: []tripartite.MakeInvoiceItems{{
  150. // Xmmc: "0fccdac71c36a8552ba662e7a2f42726",
  151. // WhStatus: 1,
  152. // Je: param.Orders[0].Items[0].TaxPrice,
  153. // Sl: "1",
  154. // }},
  155. // }); err != nil {
  156. // return gerror.Wrapf(err, "调用开票接口异常%v", err)
  157. // }
  158. // return nil
  159. // }()
  160. // if err != nil {
  161. // g.Log().Errorf(r.Context(), "处理开票业务异常")
  162. // r.Response.Write(addInvoiceAddResp{
  163. // Code: -1,
  164. // Msg: err.Error(),
  165. // })
  166. // return
  167. // }
  168. // r.Response.Write(addInvoiceAddResp{
  169. // Code: 0,
  170. // Msg: "开票中",
  171. // })
  172. //}