package order import ( "app.yhyue.com/moapp/jybase/common" "context" "errors" "fmt" "github.com/gogf/gf/v2/frame/g" "jyOrderManager/internal/model" "strings" ) func InvoiceOrderQuery(ctx context.Context, param model.OrderDetailParams) (interface{}, error) { orderCodeArr := strings.Split(param.OrderCode, ",") if len(orderCodeArr) == 0 { return map[string]interface{}{}, errors.New("订单编号为空") } //根据订单编号查询订单信息 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, "\",\""))) invoiceArr, _ := g.DB().Query(ctx, querySQL) invoiceVariety := "" if invoiceArr.Len() != len(orderCodeArr) { return map[string]interface{}{}, errors.New("订单编号有误") } for _, v1 := range orderCodeArr { fool := true for _, v2 := range invoiceArr.List() { //判断一下所有订单都有发票信息 orderCode := v2["order_code"] if v1 == orderCode { fool = false //查看发票类型是否是同一个 if invoiceVariety == "" { invoiceVariety = common.InterfaceToStr(v2["invoice_variety"]) } else { if invoiceVariety != common.InterfaceToStr(v2["invoice_variety"]) { fool = true } } } } if fool { return map[string]interface{}{}, errors.New("订单编号有误") } } return map[string]interface{}{ "invoice_variety": invoiceVariety, }, nil }