wd 4 lat temu
rodzic
commit
47df173923

+ 30 - 24
src/dashoo.cn/backend/api/business/invoiceinfo/invoiceinfoService.go

@@ -27,34 +27,34 @@ type InvoiceService struct {
 }
 
 type InvoiceJson struct {
-	Status   		string `json:"status"`
-	Message  		string `json:"message"`
-	Fpqqlsh  		string `json:"fpqqlsh"`
+	Status  string `json:"status"`
+	Message string `json:"message"`
+	Fpqqlsh string `json:"fpqqlsh"`
 }
 
 type InvoiceNumberJson struct {
-	Result   		string `json:"result"`
-	ErrorMsg 		string `json:"errorMsg"`
-	InvoiceList 	[]ListJson `json:"list"`
+	Result      string     `json:"result"`
+	ErrorMsg    string     `json:"errorMsg"`
+	InvoiceList []ListJson `json:"list"`
 }
 
 type ListJson struct {
-	Status   		string `json:"c_status"`
-	Fpdm 		 	string `json:"c_fpdm"`
-	Kprq 	 		string `json:"c_kprq"`
-	Bhsje   		string `json:"c_bhsje"`
-	Orderno 		string `json:"c_orderno"`
-	Invoiceid 	 	string `json:"c_invoiceid"`
-	Msg   		 	string `json:"c_msg"`
-	Fpqqlsh 		string `json:"c_fpqqlsh"`
-	Fphm 	 		string `json:"c_fphm"`
-	Resultmsg		string `json:"c_resultmsg"`
-	Url 	 		string `json:"c_url"`
-	Jym 	 		string `json:"c_jym"`
-	Jepurl   		string `json:"c_jpg_url"`
-	Hjse 		 	string `json:"c_hjse"`
-	Buyername 	 	string `json:"c_buyername"`
-	Taxnum 		 	string `json:"c_taxnum"`
+	Status    string `json:"c_status"`
+	Fpdm      string `json:"c_fpdm"`
+	Kprq      string `json:"c_kprq"`
+	Bhsje     string `json:"c_bhsje"`
+	Orderno   string `json:"c_orderno"`
+	Invoiceid string `json:"c_invoiceid"`
+	Msg       string `json:"c_msg"`
+	Fpqqlsh   string `json:"c_fpqqlsh"`
+	Fphm      string `json:"c_fphm"`
+	Resultmsg string `json:"c_resultmsg"`
+	Url       string `json:"c_url"`
+	Jym       string `json:"c_jym"`
+	Jepurl    string `json:"c_jpg_url"`
+	Hjse      string `json:"c_hjse"`
+	Buyername string `json:"c_buyername"`
+	Taxnum    string `json:"c_taxnum"`
 }
 
 func GetInvoiceService(xormEngine *xorm.Engine) *InvoiceService {
@@ -110,7 +110,10 @@ func (s *InvoiceService) Post(urls string, params string, key64 string) InvoiceJ
 	params1 := encrypt(params, key64)
 	urlValues := url.Values{}
 	urlValues.Add("order", params1)
-	resp, _ := http.PostForm(urls, urlValues)
+	resp, err := http.PostForm(urls, urlValues)
+	if err != nil {
+		log.Println("err= ", err)
+	}
 	body, _ := ioutil.ReadAll(resp.Body)
 	var invoiceJson InvoiceJson
 	json.Unmarshal(body, &invoiceJson)
@@ -134,8 +137,11 @@ func (s *InvoiceService) SerialNumberPost(urls string, params string, key64 stri
 	params1 := encrypt(params, key64)
 	urlValues := url.Values{}
 	urlValues.Add("order", params1)
-	resp, _ := http.PostForm(urls, urlValues)
+	resp, err := http.PostForm(urls, urlValues)
 	body, _ := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		log.Println("err= ", err)
+	}
 	var invoiceJson InvoiceNumberJson
 	//var listJson ListJson
 	//json.Unmarshal(body, &listJson)

+ 76 - 64
src/dashoo.cn/backend/api/controllers/invoice/invoice.go

@@ -12,6 +12,7 @@ import (
 	"dashoo.cn/utils"
 	"encoding/json"
 	"fmt"
+	"log"
 	"strconv"
 	"time"
 )
@@ -21,68 +22,68 @@ type OilInvoiceController struct {
 }
 
 type InvoiceJson struct {
-	Identity               string  	`json:"identity"`
-	Order           InvoiceOrderJson `json:"order"`
+	Identity string           `json:"identity"`
+	Order    InvoiceOrderJson `json:"order"`
 }
 
 type InvoiceId struct {
-	Id               string  	`json:"Id"`
-	SrcIds           string `json:"SrcIds"`
+	Id     string `json:"Id"`
+	SrcIds string `json:"SrcIds"`
 }
 
 type SelectInvoiceJson struct {
-	Identity               string  	`json:"identity"`
-	Fpqqlsh           string `json:"fpqqlsh"`
+	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"`
+	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"`
+	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 开票
@@ -102,7 +103,7 @@ func (this *OilInvoiceController) OpenInvoice() {
 	Url := utils.Cfg.MustValue("Invoice", "invoiceUrl")
 	userToken, _ := models.CreateToken(this.User.Username)
 	//云平台链接23,然后请求诺诺
-	go func () {
+	go func() {
 		invoice.Post2(Url, string(selS), userToken.Token)
 	}()
 	var errinfo ErrorInfo
@@ -117,7 +118,12 @@ func (this *OilInvoiceController) OpenInvoice() {
 // @Success	200	{object} controllers.Request
 // @router /updateisinvoice [post]
 func (this *OilInvoiceController) UpdateIsInvoice() {
-
+	defer func() {
+		err := recover()
+		if err != nil {
+			log.Println("updateisinvoice发票错误= ", err)
+		}
+	}()
 	var invoiceId InvoiceId
 	var jsonBlob = this.Ctx.Input.RequestBody
 	json.Unmarshal(jsonBlob, &invoiceId)
@@ -159,7 +165,7 @@ func (this *OilInvoiceController) UpdateIsInvoice() {
 			// 测试环境
 			pay.OilPaymentInfo.Amount = "500.00"
 		}
-		amount,_ = strconv.ParseFloat(pay.OilPaymentInfo.Amount, 64)
+		amount, _ = strconv.ParseFloat(pay.OilPaymentInfo.Amount, 64)
 		rate := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceRate")
 		//含税
 		israte := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "IsInvoiceRate")
@@ -168,30 +174,30 @@ func (this *OilInvoiceController) UpdateIsInvoice() {
 		//"yhzcbs":"0","zzstsgl":"","lslbs":3        -------零税率
 		if israte == "" {
 			zzstsgl = ""
-			rate1,_ = strconv.ParseFloat(rate, 64)
+			rate1, _ = strconv.ParseFloat(rate, 64)
 			aq := rate1 + 1
-			tax = fmt.Sprintf("%.2f", amount * rate1 / aq)
+			tax = fmt.Sprintf("%.2f", amount*rate1/aq)
 			//tax := math.Trunc(amount * 0.06 / 1.06)
-			a,_ = strconv.ParseFloat(tax, 64)
+			a, _ = strconv.ParseFloat(tax, 64)
 		} else if israte == "1" {
 			//免税
 			yhzcbs = "1"
 			tax = "0.00"
-			a,_ = strconv.ParseFloat(tax, 64)
+			a, _ = strconv.ParseFloat(tax, 64)
 			zzstsgl = "免税"
 			rate = "0.00"
-		}  else if israte == "2" {
+		} else if israte == "2" {
 			//不征税
 			yhzcbs = "1"
 			zzstsgl = "不征税"
 			tax = "0.00"
-			a,_ = strconv.ParseFloat(tax, 64)
+			a, _ = strconv.ParseFloat(tax, 64)
 			rate = "0.00"
-		}  else if israte == "3" {
+		} else if israte == "3" {
 			//普通0税率
 			zzstsgl = ""
 			tax = "0.00"
-			a,_ = strconv.ParseFloat(tax, 64)
+			a, _ = strconv.ParseFloat(tax, 64)
 			rate = "0.00"
 		}
 		//typeString := ""
@@ -247,7 +253,7 @@ func (this *OilInvoiceController) UpdateIsInvoice() {
 		paramsOrder.Tsfs = "2" //-1,不推送;0,邮箱;1,手机(默认);2,邮箱、手机
 	} else {
 		var corporateInfo register.OilCorporateInfo
-		sup.GetEntity(&corporateInfo, "CheckStatus = 11 and CommercialNo = '" + entity.CommercialNo + "'")
+		sup.GetEntity(&corporateInfo, "CheckStatus = 11 and CommercialNo = '"+entity.CommercialNo+"'")
 		if corporateInfo.EMail != "" {
 			paramsOrder.Email = corporateInfo.EMail
 			paramsOrder.Tsfs = "2" //-1,不推送;0,邮箱;1,手机(默认);2,邮箱、手机
@@ -278,7 +284,7 @@ func (this *OilInvoiceController) UpdateIsInvoice() {
 	fmt.Println(string(paramsStr), "诺诺参数")
 	invoiceJson := invoice.Post(url, string(paramsStr), key)
 	fmt.Println(invoiceJson, "诺诺接口返回")
-	if invoiceJson.Status != "0000"{
+	if invoiceJson.Status != "0000" {
 		//session.Rollback()
 		errinfo.Code = -1
 		errinfo.Message = "开票失败!" + invoiceJson.Message
@@ -326,6 +332,12 @@ func (this *OilInvoiceController) UpdateIsInvoice() {
 // @Success	200	{object} controllers.Request
 // @router /selectInvoice [get]
 func (this *OilInvoiceController) SelectInvoice(Fpqqlsh string, Id int) invoiceinfo.InvoiceNumberJson {
+	defer func() {
+		err := recover()
+		if err != nil {
+			log.Println("SelectInvoice发票错误= ", err)
+		}
+	}()
 	paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
 	var sel SelectInvoiceJson
 	key := paramSvc.GetBaseparameterMessage("INVOICE", "paramset", "InvoiceKey64")
@@ -364,7 +376,7 @@ func (this *OilInvoiceController) SelectInvoiceStatus() {
 	var invoiceList []invoiceinfo.OilInvoiceInfo
 	svc := invoiceinfo.GetInvoiceService(utils.DBE)
 
-	svc.GetEntitysByWhere("OilInvoiceInfo","NuNuSerialNum != '' and (Url = '' or Url is null)", &invoiceList)
+	svc.GetEntitysByWhere("OilInvoiceInfo", "NuNuSerialNum != '' and (Url = '' or Url is null)", &invoiceList)
 	for _, invoice := range invoiceList {
 		this.SelectInvoice(invoice.NuNuSerialNum, invoice.Id)
 	}