invoiceQuery.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package order
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "errors"
  6. "fmt"
  7. "github.com/gogf/gf/v2/frame/g"
  8. "jyOrderManager/internal/model"
  9. "strings"
  10. )
  11. func InvoiceOrderQuery(ctx context.Context, param model.OrderDetailParams) (interface{}, error) {
  12. orderCodeArr := strings.Split(param.OrderCode, ",")
  13. if len(orderCodeArr) == 0 {
  14. return map[string]interface{}{}, errors.New("订单编号为空")
  15. }
  16. //根据订单编号查询订单信息
  17. querySQL := fmt.Sprintf("select order_code ,invoice_variety from invoice where order_code in (%s) and invoice_status=0", fmt.Sprintf("\"%s\"", strings.Join(orderCodeArr, "\",\"")))
  18. invoiceArr, _ := g.DB().Query(ctx, querySQL)
  19. invoiceVariety := ""
  20. if invoiceArr.Len() != len(orderCodeArr) {
  21. return map[string]interface{}{}, errors.New("订单编号有误")
  22. }
  23. for _, v1 := range orderCodeArr {
  24. fool := true
  25. for _, v2 := range invoiceArr.List() {
  26. //判断一下所有订单都有发票信息
  27. orderCode := v2["order_code"]
  28. if v1 == orderCode {
  29. fool = false
  30. //查看发票类型是否是同一个
  31. if invoiceVariety == "" {
  32. invoiceVariety = common.InterfaceToStr(v2["invoice_variety"])
  33. } else {
  34. if invoiceVariety != common.InterfaceToStr(v2["invoice_variety"]) {
  35. fool = true
  36. }
  37. }
  38. }
  39. }
  40. if fool {
  41. return map[string]interface{}{}, errors.New("订单编号有误")
  42. }
  43. }
  44. return map[string]interface{}{
  45. "invoice_variety": invoiceVariety,
  46. }, nil
  47. }