|
@@ -91,15 +91,15 @@ func (im *InvoiceManager) simpleMakeInvoice(ctx context.Context) (total, okNum i
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// selfMakeInvoice 联合开票(多个订单开一张发票)
|
|
|
-func (im *InvoiceManager) selfMakeInvoice(ctx context.Context) (total, okNum int, end bool, err error) {
|
|
|
+// multipleOrdersMakeInvoice 联合开票(多个订单开一张发票)
|
|
|
+func (im *InvoiceManager) multipleOrdersMakeInvoice(ctx context.Context) (total, okNum int, end bool, err error) {
|
|
|
var (
|
|
|
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_code like '%,%' AND a.create_time > ? GROUP BY invoice_order_code", consts.InvoiceStartTime.Unix())
|
|
|
if err != nil {
|
|
|
- err = gerror.Wrap(err, "selfMakeInvoice-查询待开票异常")
|
|
|
+ err = gerror.Wrap(err, "multipleOrdersMakeInvoice-查询待开票异常")
|
|
|
return
|
|
|
}
|
|
|
total, okNum = res.Len(), 0
|
|
@@ -107,7 +107,7 @@ func (im *InvoiceManager) selfMakeInvoice(ctx context.Context) (total, okNum int
|
|
|
select {
|
|
|
case im.RunPool <- true:
|
|
|
case <-time.After(time.Minute * 5):
|
|
|
- err = gerror.Wrap(consts.WaitTimeOut, "simpleMakeInvoice-开票等待超时")
|
|
|
+ err = gerror.Wrap(consts.WaitTimeOut, "multipleOrdersMakeInvoice-开票等待超时")
|
|
|
return
|
|
|
}
|
|
|
var (
|
|
@@ -146,11 +146,11 @@ func (im *InvoiceManager) selfMakeInvoice(ctx context.Context) (total, okNum int
|
|
|
if err != nil {
|
|
|
<-im.RunPool
|
|
|
if gerror.Is(err, consts.LoginOutErr) {
|
|
|
- g.Log().Infof(ctx, "selfMakeInvoice-身份过期,需要重新登录")
|
|
|
+ g.Log().Infof(ctx, "multipleOrdersMakeInvoice-身份过期,需要重新登录")
|
|
|
end = true
|
|
|
return
|
|
|
}
|
|
|
- g.Log().Errorf(ctx, "selfMakeInvoice-开票接口调用异常 %v", err)
|
|
|
+ g.Log().Errorf(ctx, "multipleOrdersMakeInvoice-开票接口调用异常 %v", err)
|
|
|
continue
|
|
|
}
|
|
|
okNum++
|
|
@@ -158,15 +158,15 @@ func (im *InvoiceManager) selfMakeInvoice(ctx context.Context) (total, okNum int
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// makeRedInvoice 红冲
|
|
|
+// makeRedInvoice 单票红冲(包含一个订单开多张票)
|
|
|
func (im *InvoiceManager) makeRedInvoice(ctx context.Context) (total, okNum int, end bool, err error) {
|
|
|
var (
|
|
|
res gdb.Result
|
|
|
)
|
|
|
//冲红任务
|
|
|
- res, err = g.DB().Query(ctx, "SELECT invoice_number,billing_time FROM invoice a WHERE a.invoice_variety like '%电子%' AND a.invoice_status=0 AND a.invoice_changed=1 AND a.invoice_order_code is NULL AND a.create_time > ? ", consts.InvoiceStartTime.Unix())
|
|
|
+ res, err = g.DB().Query(ctx, "SELECT invoice_number,billing_time FROM invoice a WHERE a.invoice_variety like '%电子%' AND a.invoice_status=0 AND a.invoice_changed=1 AND (a.invoice_order_code is NULL OR a.invoice_code not like '%,%') AND a.create_time > ? ", consts.InvoiceStartTime.Unix())
|
|
|
if err != nil {
|
|
|
- err = gerror.Wrap(err, "selfMakeChangeInvoice-查询待冲红订单异常")
|
|
|
+ err = gerror.Wrap(err, "makeRedInvoice-查询待冲红订单异常")
|
|
|
return
|
|
|
}
|
|
|
total, okNum = res.Len(), 0
|
|
@@ -174,7 +174,47 @@ func (im *InvoiceManager) makeRedInvoice(ctx context.Context) (total, okNum int,
|
|
|
select {
|
|
|
case im.RunPool <- true:
|
|
|
case <-time.After(time.Minute * 5):
|
|
|
- err = gerror.Wrap(consts.WaitTimeOut, "simpleMakeInvoice-开票等待超时")
|
|
|
+ err = gerror.Wrap(consts.WaitTimeOut, "makeRedInvoice-开票等待超时")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ invoiceNumber = gconv.String(m["invoice_number"])
|
|
|
+ invoiceDate = time.Unix(gconv.Int64(m["billing_time"]), 0)
|
|
|
+ )
|
|
|
+ err = im.Auth.MakeSingleRedInvoice(MakeRedInvoiceData{
|
|
|
+ Num: invoiceNumber,
|
|
|
+ Date: invoiceDate.Format(consts.DateFormat_Short),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ <-im.RunPool
|
|
|
+ if gerror.Is(err, consts.LoginOutErr) {
|
|
|
+ g.Log().Infof(ctx, "makeRedInvoice-身份过期,需要重新登录")
|
|
|
+ end = true
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ okNum++
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// multipleOrdersMakeRedInvoice 联合开票红冲(多个订单开一张发票)
|
|
|
+func (im *InvoiceManager) multipleOrdersMakeRedInvoice(ctx context.Context) (total, okNum int, end bool, err error) {
|
|
|
+ var (
|
|
|
+ res gdb.Result
|
|
|
+ )
|
|
|
+ //冲红任务
|
|
|
+ res, err = g.DB().Query(ctx, "SELECT invoice_number,billing_time FROM invoice a WHERE a.invoice_variety like '%电子%' AND a.invoice_status=0 AND a.invoice_changed=1 AND a.invoice_code like '%,%' AND a.create_time > ? GROUP BY invoice_order_code", consts.InvoiceStartTime.Unix())
|
|
|
+ if err != nil {
|
|
|
+ err = gerror.Wrap(err, "multipleOrdersMakeRedInvoice-查询待冲红订单异常")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ total, okNum = res.Len(), 0
|
|
|
+ for _, m := range res.List() {
|
|
|
+ select {
|
|
|
+ case im.RunPool <- true:
|
|
|
+ case <-time.After(time.Minute * 5):
|
|
|
+ err = gerror.Wrap(consts.WaitTimeOut, "multipleOrdersMakeRedInvoice-开票等待超时")
|
|
|
return
|
|
|
}
|
|
|
var (
|
|
@@ -188,7 +228,7 @@ func (im *InvoiceManager) makeRedInvoice(ctx context.Context) (total, okNum int,
|
|
|
if err != nil {
|
|
|
<-im.RunPool
|
|
|
if gerror.Is(err, consts.LoginOutErr) {
|
|
|
- g.Log().Infof(ctx, "selfMakeInvoice-身份过期,需要重新登录")
|
|
|
+ g.Log().Infof(ctx, "multipleOrdersMakeRedInvoice-身份过期,需要重新登录")
|
|
|
end = true
|
|
|
return
|
|
|
}
|