invoiceUpload.go 3.8 KB

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