Browse Source

wip:提交测试修改

wangkaiyue 1 year ago
parent
commit
51efc0fee3
3 changed files with 54 additions and 11 deletions
  1. 4 0
      internal/consts/consts.go
  2. 34 10
      internal/service/invoiceCallback.go
  3. 16 1
      internal/service/invoiceManager.go

+ 4 - 0
internal/consts/consts.go

@@ -14,3 +14,7 @@ var (
 	LoginOutErr = gerror.New("请重新获取授权")
 	AuthTimeOut = gerror.New("验证超时")
 )
+
+const (
+	DateFormat_Full = "2006-01-02 15:04:05"
+)

+ 34 - 10
internal/service/invoiceCallback.go

@@ -1,6 +1,7 @@
 package service
 
 import (
+	"ElectronicInvoice/internal/consts"
 	"ElectronicInvoice/util"
 	"context"
 	"fmt"
@@ -36,7 +37,7 @@ func InvoicingCallBackLogic(r *ghttp.Request) error {
 			return gerror.New("缺少回调参数")
 		}
 
-		invoiceTime, err = time.ParseInLocation(time.DateTime, kptime, time.Local)
+		invoiceTime, err = time.ParseInLocation(consts.DateFormat_Full, kptime, time.Local)
 		if err != nil {
 			return gerror.Wrap(err, "时间格式化异常")
 		}
@@ -85,9 +86,9 @@ func updateOrderInvoiceStatus(ctx context.Context, orderCode, invoiceNum string,
 	}
 
 	// 王浩说开票成功 订单状态不用更新;以下代码来自王浩
-	//if strings.Contains(orderCode, "xx") {
-	//	selfInvoicing(ctx, orderCode)
-	//}
+	if strings.Contains(orderCode, "xx") {
+		selfInvoicing(ctx, orderCode)
+	}
 
 	if err := SendInvoiceSuccessMail(ctx, orderCode); err != nil {
 		g.Log().Errorf(ctx, "%s 发送邮件失败 err: %v ", orderCode, err)
@@ -109,13 +110,36 @@ func selfInvoicing(ctx context.Context, orderCode string) {
 			continue
 		}
 		updateData := map[string]interface{}{}
-		//if InvoiceStatusHandle(v) {
-		//	updateData["applybill_status"] = 2
-		//} else {
-		//	updateData["applybill_status"] = 3
-		//}
-		g.DB().Update(ctx, "dataexport_order", map[string]interface{}{
+		if InvoiceStatusHandle(ctx, v) {
+			updateData["applybill_status"] = 2
+		} else {
+			updateData["applybill_status"] = 3
+		}
+		_, err := g.DB().Update(ctx, "dataexport_order", map[string]interface{}{
 			"order_code": v,
 		}, updateData)
+		if err != nil {
+			g.Log().Errorf(ctx, "自助开票更新订单异常 orderCode:%v %v", v, err)
+		}
+	}
+}
+
+// InvoiceStatusHandle 判断是全额还是部分回款
+// auth :王浩
+func InvoiceStatusHandle(ctx context.Context, orderCode string) bool {
+	orderData, err := g.DB().GetOne(ctx, "SELECT pay_money FROM dataexport_order WHERE order_code=?", orderCode)
+	if err != nil || orderData.IsEmpty() {
+		return false
+	}
+
+	invoiceData, err := g.DB().GetOne(ctx, "select sum(invoice_order_money) as  money  from  invoice where  order_code=?  and  invoice_status>=0  ", orderCode)
+	if err != nil || invoiceData.IsEmpty() {
+		return false
+	}
+	allMoney := gconv.Int64(invoiceData["money"])
+	pay_money := gconv.Int64(orderData["pay_money"])
+	if pay_money == allMoney {
+		return true
 	}
+	return false
 }

+ 16 - 1
internal/service/invoiceManager.go

@@ -110,6 +110,17 @@ func (im *InvoiceManager) RunJob(ctx context.Context) {
 	} else {
 		g.Log().Infof(ctx, "RunJob-开蓝票任务完成 共%d个 完成%d个", total, okNum)
 	}
+	// TODO 蓝票自助开票(管理后台扫码开票)
+	//total, okNum, err = im.selfMakeInvoice(ctx)
+	//if err != nil {
+	//	if gerror.Is(err, consts.LoginOutErr) {
+	//		g.Log().Infof(ctx, "RunJob-任务中止-身份过期,需要重新登录")
+	//		return
+	//	}
+	//	g.Log().Errorf(ctx, "RunJob-开自助蓝票任务异常 %v", err)
+	//} else {
+	//	g.Log().Infof(ctx, "RunJob-开自助蓝票任务完成 共%d个 完成%d个", total, okNum)
+	//}
 
 	//TODO 红票任务
 
@@ -130,7 +141,6 @@ func (im *InvoiceManager) simpleMakeInvoice(ctx context.Context) (total, okNum i
 	g.Log().Infof(ctx, "RunJob-simpleMakeInvoice-本次共加载%d条开票记录", res.Len())
 	total, okNum = res.Len(), 0
 	for _, m := range res.List() {
-
 		select {
 		case im.runPool <- true:
 		case <-time.After(time.Minute * 5):
@@ -185,3 +195,8 @@ func (im *InvoiceManager) simpleMakeInvoice(ctx context.Context) (total, okNum i
 	}
 	return
 }
+
+// selfMakeInvoice 自助开票
+func (im *InvoiceManager) selfMakeInvoice(ctx context.Context) (total, okNum int, err error) {
+	return
+}