2
3
Prechádzať zdrojové kódy

前后:发票改成开放接口

dubch 5 rokov pred
rodič
commit
b1b03324c7

+ 16 - 0
src/dashoo.cn/backend/api/business/invoiceinfo/invoiceinfoService.go

@@ -10,7 +10,10 @@ import (
 	"encoding/json"
 	"github.com/go-xorm/xorm"
 	"io/ioutil"
+	"log"
 	"net/url"
+	"strings"
+
 	//"time"
 
 	//"github.com/rs/zerolog"
@@ -114,6 +117,19 @@ func (s *InvoiceService) Post(urls string, params string, key64 string) InvoiceJ
 	return invoiceJson
 }
 
+func (s *InvoiceService) Post2(url string, params string, token string) *http.Response {
+	client := &http.Client{}
+	req, err := http.NewRequest("POST", url, strings.NewReader(params))
+	req.Header.Add("Content-Type", "application/json")
+	req.Header.Add("Authorization", "Bearer "+token)
+	resp, err := client.Do(req)
+	if err != nil {
+		log.Println("err= ", err)
+	}
+	log.Println("resp= ", resp)
+	return resp
+}
+
 func (s *InvoiceService) SerialNumberPost(urls string, params string, key64 string) InvoiceNumberJson {
 	params1 := encrypt(params, key64)
 	urlValues := url.Values{}

+ 4 - 1
src/dashoo.cn/backend/api/conf/app.conf

@@ -92,4 +92,7 @@ msgUrl=http://api.dgyt.petrochina/jcfw/duanxin/v1.0/sendmsg
 ptrUrl=http://api.dgyt.petrochina/jcfw/ptr/v1.0/ptr
 
 [Iam]
-iamUrl=http://iam.api.dgyt.petrochina/api/iam/loginex
+iamUrl=http://iam.api.dgyt.petrochina/api/iam/loginex
+
+[Invoice]
+invoiceUrl=http://localhost:10091/api/invoice/updateisinvoice

+ 348 - 0
src/dashoo.cn/backend/api/controllers/invoice/invoice.go

@@ -0,0 +1,348 @@
+package invoice
+
+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/workflow"
+	. "dashoo.cn/backend/api/controllers"
+	"dashoo.cn/backend/api/models"
+	baseparameter "dashoo.cn/business2/parameter"
+	"dashoo.cn/utils"
+	"encoding/json"
+	"fmt"
+	"strconv"
+	"time"
+)
+
+type OilInvoiceController struct {
+	BaseController
+}
+
+type InvoiceJson struct {
+	Identity               string  	`json:"identity"`
+	Order           InvoiceOrderJson `json:"order"`
+}
+
+type InvoiceId struct {
+	Id               string  	`json:"Id"`
+	SrcIds           string `json:"SrcIds"`
+}
+
+type SelectInvoiceJson struct {
+	Identity               string  	`json:"identity"`
+	Fpqqlsh           string `json:"fpqqlsh"`
+}
+
+type InvoiceOrderJson struct {
+	Buyername     string    `json:"buyername"`
+	Phone     string    `json:"phone"`
+	Taxnum     string    `json:"taxnum"`
+	Address     string    `json:"address"`
+	Account     string    `json:"account"`
+	Telephone     string    `json:"telephone"`
+	Orderno     string    `json:"orderno"`
+	Invoicedate     string    `json:"invoicedate"`
+	Clerk     string    `json:"clerk"`
+	Saleaccount     string    `json:"saleaccount"`
+	Salephone     string    `json:"salephone"`
+	Saleaddress     string    `json:"saleaddress"`
+	Saletaxnum     string    `json:"saletaxnum"`
+	Kptype     string    `json:"kptype"`
+	Message     string    `json:"message"`
+	Payee     string    `json:"payee"`
+	Checker     string    `json:"checker"`
+	Tsfs     string    `json:"tsfs"`
+	Email     string    `json:"email"`
+	Qdbz     string    `json:"qdbz"`
+	Qdxmmc     string    `json:"qdxmmc"`
+	Dkbz     string    `json:"dkbz"`
+	Deptid     string    `json:"deptid"`
+	Clerkid     string    `json:"clerkid"`
+	InvoiceLine     string    `json:"invoiceLine"`
+	Cpybz     string    `json:"cpybz"`
+	Detail     []InvoiceDetailJson `json:"detail"`
+}
+
+type InvoiceDetailJson struct {
+	Goodsname     string    `json:"goodsname"`
+	Num     string    `json:"num"`
+	Price     string    `json:"price"`
+	Hsbz     string    `json:"hsbz"`
+	Taxrate     string    `json:"taxrate"`
+	Spec     string    `json:"spec"`
+	Unit     string    `json:"unit"`
+	Spbm     string    `json:"spbm"`
+	Zsbm     string    `json:"zsbm"`
+	Fphxz     string    `json:"fphxz"`
+	Yhzcbs     string    `json:"yhzcbs"`
+	Zzstsgl     string    `json:"zzstsgl"`
+	Lslbs     string    `json:"lslbs"`
+	Kce     string    `json:"kce"`
+	Taxfreeamt     string    `json:"taxfreeamt"`
+	Tax     string    `json:"tax"`
+	Taxamt     string    `json:"taxamt"`
+}
+
+// @Title 开票
+// @Description 开票
+// @Success	200	{object} controllers.Request
+// @router /openInvoice [get]
+func (this *OilInvoiceController) OpenInvoice() {
+	var invoiceId InvoiceId
+	id := this.GetString("Id")
+	srcIds := this.GetString("SrcIds")
+	invoiceId.Id = id
+	invoiceId.SrcIds = srcIds
+	selS, _ := json.Marshal(invoiceId)
+
+	invoice := invoiceinfo.GetInvoiceService(utils.DBE)
+
+	Url := utils.Cfg.MustValue("Invoice", "invoiceUrl")
+	userToken, _ := models.CreateToken(this.User.Username)
+	//云平台链接23,然后请求诺诺
+	go func () {
+		invoice.Post2(Url, string(selS), userToken.Token)
+	}()
+	var errinfo ErrorInfo
+	errinfo.Code = -1
+	errinfo.Message = "开票中,请勿重复开票!"
+	this.Data["json"] = &errinfo
+	this.ServeJSON()
+}
+
+// @Title 开票and更新发票状态
+// @Description 更新发票状态
+// @Success	200	{object} controllers.Request
+// @router /updateisinvoice [post]
+func (this *OilInvoiceController) UpdateIsInvoice() {
+
+	var invoiceId InvoiceId
+	var jsonBlob = this.Ctx.Input.RequestBody
+	json.Unmarshal(jsonBlob, &invoiceId)
+
+	session := utils.DBE.NewSession()
+	defer session.Close()
+	err := session.Begin()
+	paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
+	key := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceKey64")
+
+	// 诺诺网发票接口
+	invoice := invoiceinfo.GetInvoiceService(utils.DBE)
+	url := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceUrl")
+	var entity invoiceinfo.OilInvoiceInfo
+	where := "Id=" + invoiceId.Id
+	invoice.GetEntity(&entity, where)
+
+	sup := supplier.GetOilSupplierService(utils.DBE)
+	var supplierEntity supplier.OilSupplier
+	whereS := "Id=" + strconv.Itoa(entity.SupplierId)
+	sup.GetEntity(&supplierEntity, whereS)
+
+	var paylist []paymentinfo.PaymentinfoList
+	svcp := paymentinfo.GetPaymentService(utils.DBE)
+	where = "p.Id in (" + entity.SrcIds + ")"
+	svcp.GetPaymentinfoList1(where, &paylist)
+	//paramsString := ""
+	var paramsDetail []InvoiceDetailJson
+	for _, pay := range paylist {
+		var detail InvoiceDetailJson
+		var amount float64
+		var rate1 float64
+		var a float64
+		var tax string
+		yhzcbs := "0"
+		environment := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "isDev")
+		zzstsgl := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceZzstsgl")
+		if environment == "1" {
+			// 测试环境
+			pay.OilPaymentInfo.Amount = "500.00"
+		}
+		amount,_ = strconv.ParseFloat(pay.OilPaymentInfo.Amount, 64)
+		rate := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceRate")
+		//含税
+		israte := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "IsInvoiceRate")
+		//"yhzcbs":"1","zzstsgl":"免税","lslbs":"1"  ----免税
+		//"yhzcbs":1,"zzstsgl":"不征税", "lslbs":2   ----不征税
+		//"yhzcbs":"0","zzstsgl":"","lslbs":3        -------零税率
+		if israte == "" {
+			zzstsgl = ""
+			rate1,_ = strconv.ParseFloat(rate, 64)
+			aq := rate1 + 1
+			tax = fmt.Sprintf("%.2f", amount * rate1 / aq)
+			//tax := math.Trunc(amount * 0.06 / 1.06)
+			a,_ = strconv.ParseFloat(tax, 64)
+		} else if israte == "1" {
+			//免税
+			yhzcbs = "1"
+			tax = "0.00"
+			a,_ = strconv.ParseFloat(tax, 64)
+			zzstsgl = "免税"
+			rate = "0.00"
+		}  else if israte == "2" {
+			//不征税
+			yhzcbs = "1"
+			zzstsgl = "不征税"
+			tax = "0.00"
+			a,_ = strconv.ParseFloat(tax, 64)
+			rate = "0.00"
+		}  else if israte == "3" {
+			//普通0税率
+			zzstsgl = ""
+			tax = "0.00"
+			a,_ = strconv.ParseFloat(tax, 64)
+			rate = "0.00"
+		}
+		//typeString := ""
+		//if pay.OilPaymentInfo.PayType == "1" {
+		//	typeString = "准入交费"
+		//} else if pay.OilPaymentInfo.PayType == "2" {
+		//	typeString = "年审交费"
+		//} else if pay.OilPaymentInfo.PayType == "3" {
+		//	typeString = "增项交费"
+		//} else if pay.OilPaymentInfo.PayType == "7" {
+		//	typeString = "信息变更交费"
+		//}
+		//paramsString += "{'goodsname':'" + pay.SupplierTypeName + " " + typeString + "','num':'','price':'','hsbz':'1','taxrate':'" + rate + "','spec':'','unit':'','spbm':'10101150101','zsbm':'','fphxz':'0','yhzcbs':'" + yhzcbs + "','zzstsgl':'" + zzstsgl + "','lslbs':'" + israte + "','kce':'','taxfreeamt':" + fmt.Sprintf("%.2f", amount-a) + ",'tax':" + tax + ",'taxamt':" + strconv.Itoa(int(amount)) + "}"
+		//detail.Goodsname = pay.SupplierTypeName + " " + typeString
+		detail.Goodsname = "资质认证服务费"
+		detail.Hsbz = "1"
+		detail.Taxrate = rate
+		detail.Fphxz = "0"
+		detail.Yhzcbs = yhzcbs
+		detail.Zzstsgl = zzstsgl
+		detail.Lslbs = israte
+		detail.Tax = tax
+		detail.Spbm = "3040101"
+		detail.Taxamt = strconv.Itoa(int(amount))
+		detail.Taxfreeamt = fmt.Sprintf("%.2f", amount-a)
+		paramsDetail = append(paramsDetail, detail)
+	}
+
+	// 身份认证,在诺诺网备案后,由诺诺网提供,每个企业一个
+	identity := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceIdentity")
+	var params InvoiceJson
+	var paramsOrder InvoiceOrderJson
+	params.Identity = identity
+	paramsOrder.Detail = paramsDetail
+	paramsOrder.Buyername = entity.SupplierName
+	paramsOrder.Taxnum = entity.CommercialNo
+	paramsOrder.Phone = supplierEntity.Mobile
+	paramsOrder.Address = entity.Address
+	paramsOrder.Account = entity.DepositBank + " " + entity.BankAccount
+	paramsOrder.Telephone = supplierEntity.Telphone
+	paramsOrder.Orderno = "dg" + entity.BankSerialNum
+	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")
+	paramsOrder.Salephone = paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePhone")
+	paramsOrder.Saleaddress = paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceAddress")
+	paramsOrder.Saletaxnum = paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceSaletaxnum")
+	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
+	paramsOrder.Qdbz = "0"
+	paramsOrder.Dkbz = "0"
+	paramsOrder.InvoiceLine = "p"
+	params.Order = paramsOrder
+	var errinfo ErrorInfo
+	paramsStr, err := json.Marshal(params)
+	if err != nil {
+		errinfo.Code = -1
+		errinfo.Message = "转json失败!"
+		this.Data["json"] = &errinfo
+		this.ServeJSON()
+	}
+	//param1 := "{'identity':'" + identity + "','order':{'buyername':'" + entity.SupplierName + "','taxnum':'" + entity.CommercialNo + "','phone':'" + supplierEntity.Mobile +
+	//	"','address':'" + entity.Address + "','account':'" + entity.DepositBank + " " + entity.BankAccount + "','telephone':'" + supplierEntity.Telphone + "','orderno':'dg123" +
+	//	entity.BankSerialNum + "','invoicedate':'" + time.Now().Format("2006-01-02 15:04:05") + "','clerk':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePeople3") +
+	//	"','saleaccount':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceSaleaccount") + "','salephone':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePhone") +
+	//	"','saleaddress':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceAddress") + "','saletaxnum':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceSaletaxnum") +
+	//	"','kptype':'1','message':'','payee':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePeople1") + "','checker':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePeople2") +
+	//	"','tsfs':'1','email':'" + entity.Email + "','qdbz':'0','qdxmmc':'','dkbz':'0','deptid':'','clerkid':'','invoiceLine':'p','cpybz':'','detail':["+paramsString+"]}}"
+
+	fmt.Println(string(paramsStr), "参数")
+	invoiceJson := invoice.Post(url, string(paramsStr), key)
+	fmt.Println(invoiceJson, "诺诺接口返回")
+	if invoiceJson.Status != "0000"{
+		//session.Rollback()
+		errinfo.Code = -1
+		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)
+
+					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"
+
+					receiveVal := svcActiviti.TaskComplete(ActiComplete)
+					fmt.Println("receiveVal:" + receiveVal)
+					if receiveVal == "true" && err != nil {
+						session.Commit()
+					} else {
+						session.Rollback()
+					}
+					break
+				}
+			}
+			fmt.Print("状态i++" + string(i))
+		}
+		invoiceStr, _ := json.Marshal(result)
+		fmt.Print("获取正确开票状态" + string(invoiceStr))
+	}
+	errinfo.Code = 0
+	errinfo.Message = "开票中,请等待!"
+	this.Data["json"] = &errinfo
+	this.ServeJSON()
+}
+
+// @Title 获取开票状态
+// @Description 获取开票状态
+// @Success	200	{object} controllers.Request
+// @router /selectInvoice [get]
+func (this *OilInvoiceController) SelectInvoice(Fpqqlsh string) 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")
+	sel.Fpqqlsh = Fpqqlsh
+	selS, _ := json.Marshal(sel)
+	invoice := invoiceinfo.GetInvoiceService(utils.DBE)
+	url1 := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceLiuShuiUrl")
+	//params := "{'identity':'" + identity + "','fpqqlsh':['" + invoiceJson.Fpqqlsh + "']}"
+	invoiceJson1 := invoice.SerialNumberPost(url1, string(selS), key)
+	// 根据流水号查询结果
+	//params := "{'identity':'" + identity + "','fpqqlsh':['" + invoiceJson.Fpqqlsh + "']}"
+	//invoiceJson1 := invoice.SerialNumberPost(url, params, key)
+	return invoiceJson1
+}
+
+

+ 0 - 318
src/dashoo.cn/backend/api/controllers/oilsupplier/invoiceinfo.go

@@ -2,82 +2,15 @@ package oilsupplier
 
 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/workflow"
 	. "dashoo.cn/backend/api/controllers"
-	baseparameter "dashoo.cn/business2/parameter"
 	"dashoo.cn/utils"
-	"encoding/json"
-	"fmt"
-	"strconv"
-	"time"
 )
 
 type OilInvoiceController struct {
 	BaseController
 }
 
-type InvoiceJson struct {
-	Identity               string  	`json:"identity"`
-	Order           InvoiceOrderJson `json:"order"`
-}
-
-type SelectInvoiceJson struct {
-	Identity               string  	`json:"identity"`
-	Fpqqlsh           string `json:"fpqqlsh"`
-}
-
-type InvoiceOrderJson struct {
-	Buyername     string    `json:"buyername"`
-	Phone     string    `json:"phone"`
-	Taxnum     string    `json:"taxnum"`
-	Address     string    `json:"address"`
-	Account     string    `json:"account"`
-	Telephone     string    `json:"telephone"`
-	Orderno     string    `json:"orderno"`
-	Invoicedate     string    `json:"invoicedate"`
-	Clerk     string    `json:"clerk"`
-	Saleaccount     string    `json:"saleaccount"`
-	Salephone     string    `json:"salephone"`
-	Saleaddress     string    `json:"saleaddress"`
-	Saletaxnum     string    `json:"saletaxnum"`
-	Kptype     string    `json:"kptype"`
-	Message     string    `json:"message"`
-	Payee     string    `json:"payee"`
-	Checker     string    `json:"checker"`
-	Tsfs     string    `json:"tsfs"`
-	Email     string    `json:"email"`
-	Qdbz     string    `json:"qdbz"`
-	Qdxmmc     string    `json:"qdxmmc"`
-	Dkbz     string    `json:"dkbz"`
-	Deptid     string    `json:"deptid"`
-	Clerkid     string    `json:"clerkid"`
-	InvoiceLine     string    `json:"invoiceLine"`
-	Cpybz     string    `json:"cpybz"`
-	Detail     []InvoiceDetailJson `json:"detail"`
-}
-
-type InvoiceDetailJson struct {
-	Goodsname     string    `json:"goodsname"`
-	Num     string    `json:"num"`
-	Price     string    `json:"price"`
-	Hsbz     string    `json:"hsbz"`
-	Taxrate     string    `json:"taxrate"`
-	Spec     string    `json:"spec"`
-	Unit     string    `json:"unit"`
-	Spbm     string    `json:"spbm"`
-	Zsbm     string    `json:"zsbm"`
-	Fphxz     string    `json:"fphxz"`
-	Yhzcbs     string    `json:"yhzcbs"`
-	Zzstsgl     string    `json:"zzstsgl"`
-	Lslbs     string    `json:"lslbs"`
-	Kce     string    `json:"kce"`
-	Taxfreeamt     string    `json:"taxfreeamt"`
-	Tax     string    `json:"tax"`
-	Taxamt     string    `json:"taxamt"`
-}
-
 // @Title 获取信息
 // @Description get user by token
 // @Success 200 {object} map[string]interface{}
@@ -107,255 +40,4 @@ func (this *OilInvoiceController) GetInvoiceData() {
 
 }
 
-// @Title 更新发票状态
-// @Description 更新发票状态
-// @Success	200	{object} controllers.Request
-// @router /updateisinvoice [get]
-func (this *OilInvoiceController) UpdateIsInvoice() string {
-
-	id := this.GetString("Id")
-	srcIds := this.GetString("SrcIds")
-	session := utils.DBE.NewSession()
-	defer session.Close()
-	err := session.Begin()
-	paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
-	key := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceKey64")
-
-	// 诺诺网发票接口
-	invoice := invoiceinfo.GetInvoiceService(utils.DBE)
-	url := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceUrl")
-	var entity invoiceinfo.OilInvoiceInfo
-	where := "Id=" + id
-	invoice.GetEntity(&entity, where)
-
-	sup := supplier.GetOilSupplierService(utils.DBE)
-	var supplierEntity supplier.OilSupplier
-	whereS := "Id=" + strconv.Itoa(entity.SupplierId)
-	sup.GetEntity(&supplierEntity, whereS)
-
-	var paylist []paymentinfo.PaymentinfoList
-	svcp := paymentinfo.GetPaymentService(utils.DBE)
-	where = "p.Id in (" + entity.SrcIds + ")"
-	svcp.GetPaymentinfoList1(where, &paylist)
-	//paramsString := ""
-	var paramsDetail []InvoiceDetailJson
-	for _, pay := range paylist {
-		var detail InvoiceDetailJson
-		var amount float64
-		var rate1 float64
-		var a float64
-		var tax string
-		yhzcbs := "0"
-		environment := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "isDev")
-		zzstsgl := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceZzstsgl")
-		if environment == "1" {
-			// 测试环境
-			pay.OilPaymentInfo.Amount = "500.00"
-		}
-		amount,_ = strconv.ParseFloat(pay.OilPaymentInfo.Amount, 64)
-		rate := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceRate")
-		//含税
-		israte := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "IsInvoiceRate")
-		//"yhzcbs":"1","zzstsgl":"免税","lslbs":"1"  ----免税
-		//"yhzcbs":1,"zzstsgl":"不征税", "lslbs":2   ----不征税
-		//"yhzcbs":"0","zzstsgl":"","lslbs":3        -------零税率
-		if israte == "" {
-			zzstsgl = ""
-			rate1,_ = strconv.ParseFloat(rate, 64)
-			aq := rate1 + 1
-			tax = fmt.Sprintf("%.2f", amount * rate1 / aq)
-			//tax := math.Trunc(amount * 0.06 / 1.06)
-			a,_ = strconv.ParseFloat(tax, 64)
-		} else if israte == "1" {
-			//免税
-			yhzcbs = "1"
-			tax = "0.00"
-			a,_ = strconv.ParseFloat(tax, 64)
-			zzstsgl = "免税"
-			rate = "0.00"
-		}  else if israte == "2" {
-			//不征税
-			yhzcbs = "1"
-			zzstsgl = "不征税"
-			tax = "0.00"
-			a,_ = strconv.ParseFloat(tax, 64)
-			rate = "0.00"
-		}  else if israte == "3" {
-			//普通0税率
-			zzstsgl = ""
-			tax = "0.00"
-			a,_ = strconv.ParseFloat(tax, 64)
-			rate = "0.00"
-		}
-		//typeString := ""
-		//if pay.OilPaymentInfo.PayType == "1" {
-		//	typeString = "准入交费"
-		//} else if pay.OilPaymentInfo.PayType == "2" {
-		//	typeString = "年审交费"
-		//} else if pay.OilPaymentInfo.PayType == "3" {
-		//	typeString = "增项交费"
-		//} else if pay.OilPaymentInfo.PayType == "7" {
-		//	typeString = "信息变更交费"
-		//}
-		//paramsString += "{'goodsname':'" + pay.SupplierTypeName + " " + typeString + "','num':'','price':'','hsbz':'1','taxrate':'" + rate + "','spec':'','unit':'','spbm':'10101150101','zsbm':'','fphxz':'0','yhzcbs':'" + yhzcbs + "','zzstsgl':'" + zzstsgl + "','lslbs':'" + israte + "','kce':'','taxfreeamt':" + fmt.Sprintf("%.2f", amount-a) + ",'tax':" + tax + ",'taxamt':" + strconv.Itoa(int(amount)) + "}"
-		//detail.Goodsname = pay.SupplierTypeName + " " + typeString
-		detail.Goodsname = "资质认证服务费"
-		detail.Hsbz = "1"
-		detail.Taxrate = rate
-		detail.Fphxz = "0"
-		detail.Yhzcbs = yhzcbs
-		detail.Zzstsgl = zzstsgl
-		detail.Lslbs = israte
-		detail.Tax = tax
-		detail.Spbm = "3040101"
-		detail.Taxamt = strconv.Itoa(int(amount))
-		detail.Taxfreeamt = fmt.Sprintf("%.2f", amount-a)
-		paramsDetail = append(paramsDetail, detail)
-	}
-
-	// 身份认证,在诺诺网备案后,由诺诺网提供,每个企业一个
-	identity := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceIdentity")
-	var params InvoiceJson
-	var paramsOrder InvoiceOrderJson
-	params.Identity = identity
-	paramsOrder.Detail = paramsDetail
-	paramsOrder.Buyername = entity.SupplierName
-	paramsOrder.Taxnum = entity.CommercialNo
-	paramsOrder.Phone = supplierEntity.Mobile
-	paramsOrder.Address = entity.Address
-	paramsOrder.Account = entity.DepositBank + " " + entity.BankAccount
-	paramsOrder.Telephone = supplierEntity.Telphone
-	paramsOrder.Orderno = "dg" + entity.BankSerialNum
-	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")
-	paramsOrder.Salephone = paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePhone")
-	paramsOrder.Saleaddress = paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceAddress")
-	paramsOrder.Saletaxnum = paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceSaletaxnum")
-	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
-	paramsOrder.Qdbz = "0"
-	paramsOrder.Dkbz = "0"
-	paramsOrder.InvoiceLine = "p"
-	params.Order = paramsOrder
-	var errinfo ErrorInfo
-	paramsStr, err := json.Marshal(params)
-	if err != nil {
-		errinfo.Code = -1
-		errinfo.Message = "转json失败!"
-		this.Data["json"] = &errinfo
-		this.ServeJSON()
-	}
-	//param1 := "{'identity':'" + identity + "','order':{'buyername':'" + entity.SupplierName + "','taxnum':'" + entity.CommercialNo + "','phone':'" + supplierEntity.Mobile +
-	//	"','address':'" + entity.Address + "','account':'" + entity.DepositBank + " " + entity.BankAccount + "','telephone':'" + supplierEntity.Telphone + "','orderno':'dg123" +
-	//	entity.BankSerialNum + "','invoicedate':'" + time.Now().Format("2006-01-02 15:04:05") + "','clerk':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePeople3") +
-	//	"','saleaccount':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceSaleaccount") + "','salephone':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePhone") +
-	//	"','saleaddress':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceAddress") + "','saletaxnum':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceSaletaxnum") +
-	//	"','kptype':'1','message':'','payee':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePeople1") + "','checker':'" + paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoicePeople2") +
-	//	"','tsfs':'1','email':'" + entity.Email + "','qdbz':'0','qdxmmc':'','dkbz':'0','deptid':'','clerkid':'','invoiceLine':'p','cpybz':'','detail':["+paramsString+"]}}"
-
-	fmt.Println(string(paramsStr), "参数")
-	invoiceJson := invoice.Post(url, string(paramsStr), key)
-	fmt.Println(invoiceJson, "诺诺接口返回")
-	if invoiceJson.Status != "0000"{
-		//session.Rollback()
-		errinfo.Code = -1
-		errinfo.Message = "操作失败!" + invoiceJson.Message
-		this.Data["json"] = &errinfo
-		this.ServeJSON()
-	} else if invoiceJson.Status == "0000" && invoiceJson.Fpqqlsh != "" {
-		time.Sleep(time.Second * 10)
-		var sel SelectInvoiceJson
-		key := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceKey64")
-		sel.Identity = paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceIdentity")
-		sel.Fpqqlsh = invoiceJson.Fpqqlsh
-		selS, err := json.Marshal(sel)
-		invoice := invoiceinfo.GetInvoiceService(utils.DBE)
-		url1 := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceLiuShuiUrl")
-		//params := "{'identity':'" + identity + "','fpqqlsh':['" + invoiceJson.Fpqqlsh + "']}"
-		invoiceJson1 := invoice.SerialNumberPost(url1, string(selS), key)
-		fmt.Print(invoiceJson1)
-		// 根据流水号查询结果
-		//params := "{'identity':'" + identity + "','fpqqlsh':['" + invoiceJson.Fpqqlsh + "']}"
-		//invoiceJson1 := invoice.SerialNumberPost(url, params, key)
-		if invoiceJson1.Result != "success"{
-			//session.Rollback()
-			errinfo.Code = -1
-			errinfo.Message = "开票查询失败!" + invoiceJson1.ErrorMsg
-			this.Data["json"] = &errinfo
-			this.ServeJSON()
-		} else if invoiceJson1.Result == "success" && len(invoiceJson1.InvoiceList) > 0{
-			results := invoiceJson1.InvoiceList[0]
-			if results.Status != "2"{
-				errinfo.Code = -1
-				errinfo.Message = "操作失败!" + results.Resultmsg
-				this.Data["json"] = &errinfo
-				this.ServeJSON()
-				return ""
-			}
-			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(id, &info, cols)
-
-
-			if err != nil {
-				session.Rollback()
-				errinfo.Code = -1
-				errinfo.Message = "操作失败!"
-				this.Data["json"] = &errinfo
-				this.ServeJSON()
-				return ""
-			}
-
-			var payinfo paymentinfo.OilPaymentInfo
-			payinfo.IsInvoice = "1"
-			paycols := []string{"IsInvoice"}
-			where := "Id in (" + srcIds + ")"
-			err = svc.UpdateEntityBywheretbl(OilPaymentInfoName, &payinfo, paycols, where)
-
-			if err != nil {
-				session.Rollback()
-				errinfo.Code = -1
-				errinfo.Message = "操作失败!"
-				this.Data["json"] = &errinfo
-				this.ServeJSON()
-				return ""
-			}
-
-			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)
-			if receiveVal == "true" {
-				session.Commit()
-				errinfo.Code = 0
-				errinfo.Message = "操作成功!"
-				this.Data["json"] = &errinfo
-				this.ServeJSON()
-			} else {
-				session.Rollback()
-				errinfo.Code = -1
-				errinfo.Message = "操作失败!"
-				this.Data["json"] = &errinfo
-				this.ServeJSON()
-			}
-		}
-	}
-	return ""
-}
-
 

+ 7 - 0
src/dashoo.cn/backend/api/routers/router.go

@@ -9,6 +9,7 @@ import (
 	"dashoo.cn/backend/api/controllers/casbin"
 	"dashoo.cn/backend/api/controllers/document"
 	"dashoo.cn/backend/api/controllers/iamlogin"
+	"dashoo.cn/backend/api/controllers/invoice"
 	"dashoo.cn/backend/api/controllers/oilcontract"
 	"dashoo.cn/backend/api/controllers/oilsupplier"
 	"dashoo.cn/backend/api/controllers/register"
@@ -521,6 +522,12 @@ func init() {
 				&iamlogin.IamLoginController{},
 			),
 		),
+		//发票对外
+		beego.NSNamespace("/invoice",
+			beego.NSInclude(
+				&invoice.OilInvoiceController{},
+			),
+		),
 	)
 	beego.AddNamespace(ns)
 }

+ 1 - 1
src/dashoo.cn/frontend_web/src/api/oilsupplier/supplier.js

@@ -183,7 +183,7 @@ export default {
   },
   updateIsInvoice (params, myAxios) {
     return myAxios({
-      url: '/invoiceinfo/updateisinvoice',
+      url: '/invoice/openInvoice',
       method: 'get',
       params: params
     })