Explorar o código

git commit -a -m '后:发票'

dubch %!s(int64=5) %!d(string=hai) anos
pai
achega
e820d8780e

+ 88 - 47
src/dashoo.cn/backend/api/controllers/invoice/invoice.go

@@ -4,6 +4,7 @@ import (
 	"dashoo.cn/backend/api/business/invoiceinfo"
 	"dashoo.cn/backend/api/business/oilsupplier/supplier"
 	"dashoo.cn/backend/api/business/paymentinfo"
+	"dashoo.cn/backend/api/business/register"
 	"dashoo.cn/backend/api/business/workflow"
 	. "dashoo.cn/backend/api/controllers"
 	"dashoo.cn/backend/api/models"
@@ -105,8 +106,8 @@ func (this *OilInvoiceController) OpenInvoice() {
 		invoice.Post2(Url, string(selS), userToken.Token)
 	}()
 	var errinfo ErrorInfo
-	errinfo.Code = -1
-	errinfo.Message = "开票中,请勿重复开票!"
+	errinfo.Code = 0
+	errinfo.Message = "开票成功!"
 	this.Data["json"] = &errinfo
 	this.ServeJSON()
 }
@@ -231,7 +232,7 @@ func (this *OilInvoiceController) UpdateIsInvoice() {
 	paramsOrder.Address = entity.Address
 	paramsOrder.Account = entity.DepositBank + " " + entity.BankAccount
 	paramsOrder.Telephone = supplierEntity.Telphone
-	paramsOrder.Orderno = "dg" + entity.BankSerialNum
+	paramsOrder.Orderno = "dg_" + strconv.Itoa(entity.SupplierId) + strconv.Itoa(entity.Id)
 	paramsOrder.Invoicedate = time.Now().Format("2006-01-02 15:04:05")
 	paramsOrder.Clerk = paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePeople3")
 	paramsOrder.Saleaccount = paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceSaleaccount")
@@ -241,8 +242,19 @@ func (this *OilInvoiceController) UpdateIsInvoice() {
 	paramsOrder.Kptype = "1"
 	paramsOrder.Payee = paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePeople1")
 	paramsOrder.Checker = paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePeople2")
-	paramsOrder.Tsfs = "2" //-1,不推送;0,邮箱;1,手机(默认);2,邮箱、手机
 	paramsOrder.Email = entity.Email
+	if entity.Email != "" {
+		paramsOrder.Tsfs = "2" //-1,不推送;0,邮箱;1,手机(默认);2,邮箱、手机
+	} else {
+		var corporateInfo register.OilCorporateInfo
+		sup.GetEntity(&corporateInfo, "CheckStatus = 11 and CommercialNo = '" + entity.CommercialNo + "'")
+		if corporateInfo.EMail != "" {
+			paramsOrder.Email = corporateInfo.EMail
+			paramsOrder.Tsfs = "2" //-1,不推送;0,邮箱;1,手机(默认);2,邮箱、手机
+		} else {
+			paramsOrder.Tsfs = "1" //-1,不推送;0,邮箱;1,手机(默认);2,邮箱、手机
+		}
+	}
 	paramsOrder.Qdbz = "0"
 	paramsOrder.Dkbz = "0"
 	paramsOrder.InvoiceLine = "p"
@@ -269,56 +281,42 @@ func (this *OilInvoiceController) UpdateIsInvoice() {
 	if invoiceJson.Status != "0000"{
 		//session.Rollback()
 		errinfo.Code = -1
-		errinfo.Message = "操作失败!" + invoiceJson.Message
+		errinfo.Message = "开票失败!" + invoiceJson.Message
 		this.Data["json"] = &errinfo
 		this.ServeJSON()
 	} else if invoiceJson.Status == "0000" && invoiceJson.Fpqqlsh != "" {
-		var result invoiceinfo.InvoiceNumberJson
-		for i := 0; i < 5; i++ {
-			result = this.SelectInvoice(invoiceJson.Fpqqlsh)
-			if result.Result == "success" && len(result.InvoiceList) > 0 {
-				results := result.InvoiceList[0]
-				if results.Status == "2"{
-					cols := []string{"IsInvoice", "InvoiceOn", "Url", "NuNuSerialNum"}
-					svc := invoiceinfo.GetOilInvoiceInfoSession(session)
-					var info invoiceinfo.OilInvoiceInfo
-					info.IsInvoice = "1"
-					info.InvoiceOn = time.Now()
-					info.Url = results.Url
-					info.NuNuSerialNum = invoiceJson.Fpqqlsh
-					_, err = svc.UpdateEntityByIdCols(invoiceId.Id, &info, cols)
+		cols := []string{"IsInvoice", "InvoiceOn", "NuNuSerialNum"}
+		svc := invoiceinfo.GetOilInvoiceInfoSession(session)
+		var info invoiceinfo.OilInvoiceInfo
+		info.IsInvoice = "1"
+		info.InvoiceOn = time.Now()
+		info.NuNuSerialNum = invoiceJson.Fpqqlsh
+		_, err = svc.UpdateEntityByIdCols(invoiceId.Id, &info, cols)
 
-					var payinfo paymentinfo.OilPaymentInfo
-					payinfo.IsInvoice = "1"
-					paycols := []string{"IsInvoice"}
-					where := "Id in (" + invoiceId.SrcIds + ")"
-					err = svc.UpdateEntityBywheretbl(OilPaymentInfoName, &payinfo, paycols, where)
+		var payinfo paymentinfo.OilPaymentInfo
+		payinfo.IsInvoice = "1"
+		paycols := []string{"IsInvoice"}
+		where := "Id in (" + invoiceId.SrcIds + ")"
+		err = svc.UpdateEntityBywheretbl(OilPaymentInfoName, &payinfo, paycols, where)
 
-					svcActiviti := workflow.GetActivitiService(utils.DBE)
-					var ActiComplete workflow.ActiCompleteVM
-					ActiComplete.ProcessKey = workflow.OIL_SUPPLIER_VERIFY
-					ActiComplete.BusinessKey = invoiceId.Id
-					ActiComplete.UserId = this.User.Id
-					ActiComplete.Remarks = ""
-					ActiComplete.Result = "1"
+		svcActiviti := workflow.GetActivitiService(utils.DBE)
+		var ActiComplete workflow.ActiCompleteVM
+		ActiComplete.ProcessKey = workflow.OIL_SUPPLIER_VERIFY
+		ActiComplete.BusinessKey = invoiceId.Id
+		ActiComplete.UserId = this.User.Id
+		ActiComplete.Remarks = ""
+		ActiComplete.Result = "1"
 
-					receiveVal := svcActiviti.TaskComplete(ActiComplete)
-					fmt.Println("receiveVal:" + receiveVal)
-					if receiveVal == "true" && err != nil {
-						session.Commit()
-					} else {
-						session.Rollback()
-					}
-					break
-				}
-			}
-			fmt.Print("状态i++" + string(i))
+		receiveVal := svcActiviti.TaskComplete(ActiComplete)
+		fmt.Println("receiveVal:" + receiveVal)
+		if receiveVal == "true" && err == nil {
+			session.Commit()
+		} else {
+			session.Rollback()
 		}
-		invoiceStr, _ := json.Marshal(result)
-		fmt.Print("获取正确开票状态" + string(invoiceStr))
 	}
 	errinfo.Code = 0
-	errinfo.Message = "开票中,请等待!"
+	errinfo.Message = "开票成功!"
 	this.Data["json"] = &errinfo
 	this.ServeJSON()
 }
@@ -327,9 +325,8 @@ func (this *OilInvoiceController) UpdateIsInvoice() {
 // @Description 获取开票状态
 // @Success	200	{object} controllers.Request
 // @router /selectInvoice [get]
-func (this *OilInvoiceController) SelectInvoice(Fpqqlsh string) invoiceinfo.InvoiceNumberJson {
+func (this *OilInvoiceController) SelectInvoice(Fpqqlsh string, Id int) invoiceinfo.InvoiceNumberJson {
 	paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
-	time.Sleep(time.Second * 5)
 	var sel SelectInvoiceJson
 	key := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceKey64")
 	sel.Identity = paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceIdentity")
@@ -342,7 +339,51 @@ func (this *OilInvoiceController) SelectInvoice(Fpqqlsh string) invoiceinfo.Invo
 	// 根据流水号查询结果
 	//params := "{'identity':'" + identity + "','fpqqlsh':['" + invoiceJson.Fpqqlsh + "']}"
 	//invoiceJson1 := invoice.SerialNumberPost(url, params, key)
+	invoiceStr, _ := json.Marshal(invoiceJson1)
+	fmt.Print("获取开票状态" + string(invoiceStr))
+	if invoiceJson1.Result == "success" && len(invoiceJson1.InvoiceList) > 0 {
+		results := invoiceJson1.InvoiceList[0]
+		if results.Status == "2" {
+			cols := []string{"Url"}
+			var info invoiceinfo.OilInvoiceInfo
+			info.Url = results.Url
+			_, err := invoice.UpdateEntityByIdCols(Id, &info, cols)
+			if err != nil {
+				fmt.Print("修改url失败")
+			}
+		}
+	}
 	return invoiceJson1
 }
 
+// @Title 获取已开发票没有url的
+// @Description 获取已开发票没有url的
+// @Success	200	{object} controllers.Request
+// @router /selectInvoiceStatus [get]
+func (this *OilInvoiceController) SelectInvoiceStatus() {
+	var invoiceList []invoiceinfo.OilInvoiceInfo
+	svc := invoiceinfo.GetInvoiceService(utils.DBE)
+
+	svc.GetEntitysByWhere("OilInvoiceInfo","NuNuSerialNum != '' and (Url = '' or Url is null)", &invoiceList)
+	for _, invoice := range invoiceList {
+		this.SelectInvoice(invoice.NuNuSerialNum, invoice.Id)
+	}
+}
 
+// @Title 走工作流
+// @Description 走工作流
+// @Success	200	{object} controllers.Request
+// @router /workflowInvoice/:id [get]
+func (this *OilInvoiceController) WorkflowInvoice() {
+	Id := this.Ctx.Input.Param(":id")
+	svcActiviti := workflow.GetActivitiService(utils.DBE)
+	var ActiComplete workflow.ActiCompleteVM
+	ActiComplete.ProcessKey = workflow.OIL_SUPPLIER_VERIFY
+	ActiComplete.BusinessKey = Id
+	ActiComplete.UserId = this.User.Id
+	ActiComplete.Remarks = ""
+	ActiComplete.Result = "1"
+
+	receiveVal := svcActiviti.TaskComplete(ActiComplete)
+	fmt.Println("receiveVal:" + receiveVal)
+}

+ 13 - 0
src/dashoo.cn/backend/api/controllers/toolbox/toolbox.go

@@ -1,6 +1,7 @@
 package toolbox
 
 import (
+	"dashoo.cn/backend/api/controllers/invoice"
 	"dashoo.cn/backend/api/controllers/oilsupplier"
 	"github.com/astaxie/beego/toolbox"
 )
@@ -11,6 +12,7 @@ import (
 
 func TimingTask(){
 	c := new(oilsupplier.OilSupplierCertController)
+	invoice := new(invoice.OilInvoiceController)
 
 	//tkInFlag := toolbox.NewTask("myTaskInFlag", "0 0 1 * * *", func() error {
 	//	c.UpdataInFlag()
@@ -55,6 +57,17 @@ func TimingTask(){
 	} */
 	toolbox.AddTask("myTaskSupplierStatus", tkSupplierStatus)
 
+	//  每分钟获取诺诺网开票状态
+	tkInvoiceStatus := toolbox.NewTask("myTaskInvoiceStatus", "0/30 * * * * *", func() error {
+		invoice.SelectInvoiceStatus()
+		return nil
+	})
+	/* err = tkSupplierStatus.Run()
+	if err != nil {
+		fmt.Println(err)
+	} */
+	toolbox.AddTask("myTaskInvoiceStatus", tkInvoiceStatus)
+
 
 	toolbox.StartTask()