| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- 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/register"
- "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 = 0
- 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_" + 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")
- 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.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"
- 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 != "" {
- 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)
- 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()
- }
- }
- 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, Id int) invoiceinfo.InvoiceNumberJson {
- paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
- 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)
- 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)
- }
|