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