浏览代码

wip:自测提交

wangkaiyue 1 年之前
父节点
当前提交
0ce0ecd377
共有 4 个文件被更改,包括 26 次插入18 次删除
  1. 21 12
      docs/mockService/main.go
  2. 0 2
      internal/consts/consts.go
  3. 3 2
      internal/service/invoiceCallback_blue.go
  4. 2 2
      internal/service/invoiceMake.go

+ 21 - 12
docs/mockService/main.go

@@ -7,6 +7,7 @@ import (
 	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/net/ghttp"
+	"github.com/gogf/gf/v2/os/gctx"
 	"github.com/gogf/gf/v2/util/gconv"
 	"github.com/gogf/gf/v2/util/grand"
 	"github.com/gogf/gf/v2/util/guid"
@@ -82,10 +83,14 @@ var (
 			Token     string `json:"token"`
 			ExpiresIn int    `json:"expiresIn"` //一天有效期
 		}{
-			Token:     "mockToken",
+			Token:     fmt.Sprintf("MOCKTOKEN_%s", guid.S()),
 			ExpiresIn: 60 * 60 * 24,
 		}
-		r.Response.Write(resp)
+		r.Response.Write(CommonRes{
+			Code: 200,
+			Msg:  "",
+			Data: resp,
+		})
 	}
 
 	makeInvoiceC = func(r *ghttp.Request) {
@@ -102,13 +107,15 @@ var (
 		g.Log().Infof(ctx, "开票任务-接收到开票信息:%s", gconv.String(param))
 		time.Sleep(time.Second * time.Duration(grand.Intn(3))) //模拟处理
 		go func() {
+			goCtx := gctx.New()
 			context, err := util.GetPdfBase64(fmt.Sprintf("./pdfDir/invoice_Blue_%s.pdf", param.Data[0].Type)) //pdf文件
 			if err != nil {
-				g.Log().Errorf(ctx, "读取pdf文件异常%v", err)
+				g.Log().Errorf(goCtx, "读取pdf文件异常%v", err)
 				return
 			}
 			callBackParam := g.Map{
 				"calltype": "Invoicing",
+				"type":     1,
 				"pdf":      context,
 				"num":      fmt.Sprintf("MOCKBLUE_%s", guid.S()),
 				"id":       param.Data[0].Id,
@@ -116,8 +123,8 @@ var (
 			}
 			//TODO 回调开票成功
 			for {
-				if checkCallBackOk(ctx, callBackParam) {
-					g.Log().Infof(ctx, "开票任务-开票成功")
+				if checkCallBackOk(goCtx, callBackParam) {
+					g.Log().Infof(goCtx, "开票任务-开票成功")
 					break
 				}
 				time.Sleep(time.Second * 3)
@@ -125,8 +132,8 @@ var (
 
 			//TODO 任务完成通知
 			for {
-				if checkCallBackOk(ctx, g.Map{"calltype": "quit", "data": g.Map{"taskType": "2"}}) {
-					g.Log().Infof(ctx, "开票任务-通知完成")
+				if checkCallBackOk(goCtx, g.Map{"calltype": "quit", "data": g.Map{"taskType": "2"}}) {
+					g.Log().Infof(goCtx, "开票任务-通知完成")
 					break
 				}
 				time.Sleep(time.Second * 3)
@@ -152,13 +159,15 @@ var (
 		g.Log().Infof(ctx, "红冲任务-接收到红冲信息:%s", gconv.String(param))
 		time.Sleep(time.Second * time.Duration(grand.Intn(3))) //模拟处理
 		go func() {
+			goCtx := gctx.New()
 			context, err := util.GetPdfBase64("./pdfDir/invoice_Red.pdf") //pdf文件
 			if err != nil {
-				g.Log().Errorf(ctx, "读取pdf文件异常%v", err)
+				g.Log().Errorf(goCtx, "读取pdf文件异常%v", err)
 				return
 			}
 			callBackParam := g.Map{
 				"calltype":  "offset",
+				"type":      0,
 				"pdf":       context,
 				"num":       param.Data[0].Num,
 				"offsetNum": fmt.Sprintf("MOCKRED_%s", guid.S()),
@@ -167,8 +176,8 @@ var (
 
 			//TODO 回调红冲成功
 			for {
-				if checkCallBackOk(ctx, callBackParam) {
-					g.Log().Infof(ctx, "红冲任务-红冲成功")
+				if checkCallBackOk(goCtx, callBackParam) {
+					g.Log().Infof(goCtx, "红冲任务-红冲成功")
 					break
 				}
 				time.Sleep(time.Second * 3)
@@ -176,8 +185,8 @@ var (
 
 			//TODO 任务完成通知
 			for {
-				if checkCallBackOk(ctx, g.Map{"calltype": "quit", "data": g.Map{"taskType": "9"}}) {
-					g.Log().Infof(ctx, "红冲任务-通知完成")
+				if checkCallBackOk(goCtx, g.Map{"calltype": "quit", "data": g.Map{"taskType": "9"}}) {
+					g.Log().Infof(goCtx, "红冲任务-通知完成")
 					break
 				}
 				time.Sleep(time.Second * 3)

+ 0 - 2
internal/consts/consts.go

@@ -2,7 +2,6 @@ package consts
 
 import (
 	"context"
-	"fmt"
 	"github.com/gogf/gf/v2/errors/gerror"
 	"github.com/gogf/gf/v2/frame/g"
 	"strings"
@@ -35,7 +34,6 @@ func init() {
 	if err := g.Cfg().MustGet(ctx, "taxCodeList").Struct(&taxCodeItem); err != nil {
 		g.Log().Panic(ctx, "获取维护的开票项异常")
 	}
-	fmt.Println(taxCodeItem)
 }
 
 const (

+ 3 - 2
internal/service/invoiceCallback_blue.go

@@ -79,7 +79,8 @@ func updateOrderInvoiceStatus(ctx context.Context, callBackId, invoiceNum string
 		return err
 	}
 	err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
-		record, sqlErr := tx.GetOne(fmt.Sprintf("SELECT only_Identifying,invoice_changed FROM invoice WHERE %s =? ORDER BY id desc", queryItem), queryValue)
+		//invoice_status: 0新开 2红冲后新开
+		record, sqlErr := tx.GetOne(fmt.Sprintf("SELECT only_Identifying,invoice_changed FROM invoice WHERE %s =? AND invoice_status in(0,2) ORDER BY id desc", queryItem), queryValue)
 		if err != nil {
 			return gerror.Wrap(sqlErr, "查询订单异常")
 		}
@@ -98,7 +99,7 @@ func updateOrderInvoiceStatus(ctx context.Context, callBackId, invoiceNum string
 			"url":            pdfPath,
 			"billing_time":   invoiceTime.Unix(),
 			"invoice_status": 1,
-		}, fmt.Sprintf(" %s = ? ", queryItem), queryValue)
+		}, fmt.Sprintf(" %s = ? AND invoice_status in(0,2) ", queryItem), queryValue)
 		if err != nil {
 			return gerror.Wrap(err, "更新发票状态异常")
 		}

+ 2 - 2
internal/service/invoiceMake.go

@@ -21,7 +21,7 @@ func (im *InvoiceManager) simpleMakeInvoice(ctx context.Context) (total, okNum i
 	//查询需要开票的数据
 	//(新开发票【a.invoice_status=0 AND a.invoice_changed=0】,红冲后新开【a.invoice_status=2 AND a.invoice_changed=1】)
 	//线上申请发票【invoice_order_code is null 】, 管理后台一个订单拆分多个发票【invoice_order_code not like '%,%'】
-	res, err = g.DB().Query(ctx, "SELECT a.invoice_type,a.remark,a.invoice_variety,a.taxpayer_identnum,a.company_name,a.invoice_content,b.pay_way,b.order_money,b.pay_money FROM invoice a INNER JOIN dataexport_order b ON a.order_code=b.order_code WHERE a.invoice_variety like '%电子%' AND ((a.invoice_status=0 AND a.invoice_changed=0) or (a.invoice_status=2 AND a.invoice_changed=1 )) AND  (a.invoice_order_code is NULL OR a.invoice_order_code not like '%,%') AND a.create_time > ? ", consts.InvoiceStartTime.Unix())
+	res, err = g.DB().Query(ctx, "SELECT a.id,a.invoice_type,a.remark,a.invoice_variety,a.taxpayer_identnum,a.company_name,a.invoice_content,b.pay_way,b.order_money,b.pay_money FROM invoice a INNER JOIN dataexport_order b ON a.order_code=b.order_code WHERE a.invoice_variety like '%电子%' AND ((a.invoice_status=0 AND a.invoice_changed=0) or (a.invoice_status=2 AND a.invoice_changed=1 )) AND  (a.invoice_order_code is NULL OR a.invoice_order_code not like '%,%') AND a.create_time > ? ", consts.InvoiceStartTime.Unix())
 	if err != nil {
 		err = gerror.Wrap(err, "simpleMakeInvoice-查询待开票异常")
 		return
@@ -97,7 +97,7 @@ func (im *InvoiceManager) multipleOrdersMakeInvoice(ctx context.Context) (total,
 		res gdb.Result
 	)
 	//(新开发票【a.invoice_status=0 AND a.invoice_changed=0】,红冲后新开【a.invoice_status=2 AND a.invoice_changed=1】)
-	res, err = g.DB().Query(ctx, "SELECT a.invoice_type,a.remark,a.invoice_variety,a.taxpayer_identnum,a.company_name,a.invoice_content,a.invoice_money FROM invoice a WHERE a.invoice_variety like '%电子%' AND ((a.invoice_status=0 AND a.invoice_changed=0) or (a.invoice_status=2 AND a.invoice_changed=1)) AND a.invoice_order_code like '%,%' AND a.create_time > ? GROUP BY invoice_order_code", consts.InvoiceStartTime.Unix())
+	res, err = g.DB().Query(ctx, "SELECT a.only_Identifying,a.invoice_type,a.remark,a.invoice_variety,a.taxpayer_identnum,a.company_name,a.invoice_content,a.invoice_money FROM invoice a WHERE a.invoice_variety like '%电子%' AND ((a.invoice_status=0 AND a.invoice_changed=0) or (a.invoice_status=2 AND a.invoice_changed=1)) AND a.invoice_order_code like '%,%' AND a.create_time > ? GROUP BY invoice_order_code", consts.InvoiceStartTime.Unix())
 	if err != nil {
 		err = gerror.Wrap(err, "multipleOrdersMakeInvoice-查询待开票异常")
 		return