|
@@ -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
|
|
|
}
|