| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- 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{}
- // @router /getinvoicedata [get]
- func (this *OilInvoiceController) GetInvoiceData() {
- id := this.GetString("Id")
- dictList := make(map[string]interface{})
- svc := invoiceinfo.GetInvoiceService(utils.DBE)
- var entity invoiceinfo.OilInvoiceInfo
- where := "Id=" + id
- svc.GetEntity(&entity, where)
- var paylist []paymentinfo.PaymentinfoList
- svcp := paymentinfo.GetPaymentService(utils.DBE)
- where = "p.Id in (" + entity.SrcIds + ")"
- svcp.GetPaymentinfoList1(where, &paylist)
- dictList["invoiceinfo"] = entity
- dictList["paymentinfos"] = paylist
- var datainfo DataInfo
- datainfo.Items = dictList
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @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 * 5)
- 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 ""
- }
|