invoiceUpload.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package controller
  2. import (
  3. . "app.yhyue.com/moapp/jybase/api"
  4. "app.yhyue.com/moapp/jybase/common"
  5. "app.yhyue.com/moapp/jypkg/ent/util"
  6. "fmt"
  7. "github.com/gogf/gf/v2/frame/g"
  8. "github.com/gogf/gf/v2/net/ghttp"
  9. "github.com/gogf/gf/v2/util/gconv"
  10. "github.com/pkg/errors"
  11. "jyOrderManager/internal/jyutil"
  12. "jyOrderManager/internal/model"
  13. "log"
  14. "time"
  15. )
  16. // InvoiceQuery 发票查询
  17. func InvoiceUpload(r *ghttp.Request) {
  18. rData, err := func() (interface{}, error) {
  19. var param model.InvoiceUploadParams
  20. err := gconv.Struct(r.GetBody(), &param)
  21. if err != nil {
  22. return nil, errors.Wrap(err, "数据校验异常")
  23. }
  24. data := make(map[string]interface{})
  25. orderInfo, _ := g.DB().GetOne(r.Context(), "SELECT create_time,product_type,user_mail,pay_money,create_time,signing_subject,applybill_status FROM dataexport_order WHERE order_code = ?", param.OrderCode)
  26. if orderInfo.IsEmpty() {
  27. return nil, errors.New("订单不存在")
  28. }
  29. if common.ObjToString(orderInfo.Map()["signing_subject"]) == "h02" {
  30. return nil, errors.New("签约主体为拓普")
  31. }
  32. data["order_code"] = param.OrderCode
  33. data["invoice_order_code"] = param.OrderCode
  34. data["invoice_money"] = param.AllMoney
  35. data["address_url"] = param.AddressUrl
  36. data["invoice_order_money"] = param.Money
  37. data["invoice_number"] = param.InvoiceNumber
  38. data["billing_time"] = param.BillingTime
  39. data["invoicing_entity"] = param.SigningSubject
  40. data["invoice_variety"] = param.InvoiceVariety
  41. data["invoice_content"] = param.InvoiceContent
  42. data["invoice_type"] = param.InvoiceType
  43. data["company_name"] = param.CompanyName
  44. data["taxpayer_identnum"] = param.TaxpayerIdentnum
  45. data["delivery_address"] = param.DeliveryAddress
  46. data["phone"] = param.Phone
  47. data["operator"] = jyutil.GetUserMsgFromCtx(r.Context()).EntUserId
  48. data["source"] = 3
  49. data["invoice_status"] = 1
  50. log.Println("发票上传参数", data, param.Id)
  51. if param.Id == 0 {
  52. onlyIdentifying := fmt.Sprintf("%s%s%s", "aa", time.Now().Format("150405"), common.GetRandom(4))
  53. data["only_Identifying"] = onlyIdentifying
  54. data["user_id"] = orderInfo.Map()["user_id"]
  55. data["product_type"] = orderInfo.Map()["product_type"]
  56. g.DB().Save(r.Context(), "invoice", data)
  57. g.DB().Update(r.Context(), "dataexport_order", map[string]interface{}{
  58. "applybill_status": 2,
  59. }, map[string]interface{}{
  60. "order_code": param.OrderCode,
  61. })
  62. } else {
  63. g.DB().Update(r.Context(), "invoice", data, map[string]interface{}{
  64. "id": param.Id,
  65. })
  66. g.DB().Update(r.Context(), "dataexport_order", map[string]interface{}{
  67. "applybill_status": 2,
  68. }, map[string]interface{}{
  69. "order_code": param.OrderCode,
  70. })
  71. }
  72. return nil, nil
  73. }()
  74. if err != nil {
  75. g.Log().Errorf(r.Context(), "发票查询异常 %v", err)
  76. }
  77. r.Response.WriteJson(NewResult(rData, err))
  78. }
  79. func InvoiceAmount(orderCode string) (invoicedMoney int64) {
  80. invoicedInfo := util.Mysql.SelectBySql(fmt.Sprintf("SELECT invoice_order_money,only_Identifying FROM invoice WHERE order_code = '%s' and invoice_status>=0", orderCode))
  81. if invoicedInfo != nil && len(*invoicedInfo) > 0 {
  82. onlyMap := make(map[string]int64)
  83. for _, m := range *invoicedInfo {
  84. if m["only_Identifying"] != nil { //过滤换票过程中的数据
  85. onlyMap[common.InterfaceToStr(m["only_Identifying"])] = common.Int64All(m["invoice_order_money"])
  86. } else {
  87. invoicedMoney += common.Int64All(m["invoice_order_money"])
  88. }
  89. }
  90. if len(onlyMap) > 0 {
  91. for _, i := range onlyMap {
  92. invoicedMoney += i
  93. }
  94. }
  95. }
  96. return
  97. }