123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554 |
- package controllers
-
- import (
- "XT_New/common"
- "XT_New/enums"
- "XT_New/invoice"
- "XT_New/models"
- "XT_New/service"
- "XT_New/service/fapiao"
- "XT_New/utils"
- "encoding/base64"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "github.com/shopspring/decimal"
- "math"
- "strconv"
- "strings"
- "time"
- )
-
- func FaPiaoApiRegistRouters() {
- beego.Router("/api/fapiao/sms/code", &FapiaoApiController{}, "get:GetLoginUploadCode")
- beego.Router("/api/fapiao/sms/login", &FapiaoApiController{}, "get:Login")
- beego.Router("/api/fapiao/qrcode/get", &FapiaoApiController{}, "get:GetQRCode")
- beego.Router("/api/fapiao/blue", &FapiaoApiController{}, "get:OpenFaPiao")
- beego.Router("/api/fapiao/red", &FapiaoApiController{}, "get:RedFaPiao")
- beego.Router("/api/order/fapiao/list", &FapiaoApiController{}, "get:GetOrderFaPiaoList")
- beego.Router("/api/gdfapiao/list", &FapiaoApiController{}, "get:GetFaPiaoList")
-
- beego.Router("/api/newfapiao/get", &HisApiController{}, "get:GetNewFaPiaoData")
-
- beego.Router("/api/fapiao/query", &FapiaoApiController{}, "get:QueryFaPiao")
-
- }
-
- func (c *FapiaoApiController) QueryFaPiao() {
- id, _ := c.GetInt64("id")
- oc, _ := service.GetFaPiaoOrderById(id)
- sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "")
- var config models.FapiaoConfig
- config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
- routerAddress2, postData2 := fapiao.Query(config.SellerTaxpayerNum, oc.OrderSn, "")
- r3, err2 := sdk.HttpPost("https://apigw.goldentec.com", routerAddress2, postData2)
- fmt.Println("query")
- fmt.Println(string(r3))
- if err2 != nil {
- fmt.Println(err2)
- } else {
- var resp3 QueryFaPiaoResultResponse
-
- json.Unmarshal(r3, &resp3)
- if resp3.Code == 0 {
-
- if resp3.Data.Status == 3 {
-
- oc.TicketSn = resp3.Data.TicketSn
- oc.TicketDate = resp3.Data.TicketDate
- oc.AmountWithTax = resp3.Data.AmountWithoutTax
- oc.AmountWithoutTax = resp3.Data.AmountWithoutTax
- oc.FapiaoStatus = "2"
- oc.TaxAmount = resp3.Data.TaxAmount
- oc.IsRedWashed = strconv.FormatInt(int64(resp3.Data.IsRedWashed), 10)
- oc.PdfUrl = resp3.Data.PdfUrl
- oc.OfdUrl = resp3.Data.OfdUrl
- oc.XmlUrl = resp3.Data.XmlUrl
- service.SaveFaPiaoOrder(&oc)
- ids := strings.Split(oc.OrderIds, ",")
- service.UpdateFaPiaoNumber(resp3.Data.TicketSn, ids)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "同步成功",
- })
-
- } else if resp3.Data.Status == 1 {
- oc.FapiaoStatus = "1"
- oc.TicketSn = ""
- service.SaveFaPiaoOrder(&oc)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "同步成功",
- })
-
- } else if resp3.Data.Status == 2 {
- oc.FapiaoStatus = "3"
- oc.TicketSn = ""
- oc.Message = resp3.Data.Message
- service.SaveFaPiaoOrder(&oc)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "同步成功",
- })
- } else {
- oc.FapiaoStatus = "3"
- oc.TicketSn = ""
- oc.Message = resp3.Data.Message
- service.SaveFaPiaoOrder(&oc)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "同步成功",
- })
- }
- } else {
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "查询失败" + resp3.Message,
- })
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
- }
-
- func (c *HisApiController) GetNewFaPiaoData() {
- order_ids := c.GetString("order_ids")
- patient_id, _ := c.GetInt64("patient_id")
-
-
- adminUser := c.GetAdminUserInfo()
- orders := strings.Split(order_ids, ",")
- patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
-
- var bedCostTotal float64 = 0
- var bedCostSelfTotal float64 = 0
- var bedCostPartSelfTotal float64 = 0
-
- var operationCostTotal float64 = 0
- var operationCostSelfTotal float64 = 0
- var operationCostPartSelfTotal float64 = 0
-
- var otherCostTotal float64 = 0
- var otherCostSelfTotal float64 = 0
- var otherCostPartSelfTotal float64 = 0
-
- var materialCostTotal float64 = 0
- var materialCostSelfTotal float64 = 0
- var materialCostPartSelfTotal float64 = 0
-
- var westernMedicineCostTotal float64 = 0
- var westernMedicineCostSelfTotal float64 = 0
- var westernMedicineCostPartSelfTotal float64 = 0
-
- var chineseTraditionalMedicineCostTotal float64 = 0
- var chineseTraditionalMedicineCostSelfTotal float64 = 0
- var chineseTraditionalMedicineCostPartSelfTotal float64 = 0
-
- var checkCostTotal float64 = 0
- var checkCostSelfTotal float64 = 0
- var checkCostPartSelfTotal float64 = 0
-
- var hiliCostTotal float64 = 0
- var hiliCostSelfTotal float64 = 0
-
-
- var laboratoryCostTotal float64 = 0
- var laboratoryCostSelfTotal float64 = 0
- var laboratoryCostPartSelfTotal float64 = 0
-
- var treatCostTotal float64 = 0
- var treatCostSelfTotal float64 = 0
- var treatCostPartSelfTotal float64 = 0
-
- var zhenChaCostTotal float64 = 0
- var zhenChaCostSelfTotal float64 = 0
- var zhenChaCostPartSelfTotal float64 = 0
-
- decimal.DivisionPrecision = 2
-
- var MedfeeSumamt float64 = 0
- var PsnCashPay float64 = 0
- var FundPaySumamt float64 = 0
-
- var HifpPay float64 = 0
- var MafPay float64 = 0
- var AcctPay float64 = 0
-
- for _, item := range orders {
- var new_order models.HisOrder
-
- order_id_num, _ := strconv.ParseInt(item, 10, 64)
- new_order, _ = service.GetHisOrderByID(order_id_num)
-
- MedfeeSumamt, _ = decimal.NewFromFloat(MedfeeSumamt).Add(decimal.NewFromFloat(new_order.MedfeeSumamt)).Float64()
- PsnCashPay, _ = decimal.NewFromFloat(PsnCashPay).Add(decimal.NewFromFloat(new_order.PsnCashPay)).Float64()
- FundPaySumamt, _ = decimal.NewFromFloat(FundPaySumamt).Add(decimal.NewFromFloat(new_order.FundPaySumamt)).Float64()
- HifpPay, _ = decimal.NewFromFloat(HifpPay).Add(decimal.NewFromFloat(new_order.HifpPay)).Float64()
- MafPay, _ = decimal.NewFromFloat(MafPay).Add(decimal.NewFromFloat(new_order.MafPay)).Float64()
- AcctPay, _ = decimal.NewFromFloat(AcctPay).Add(decimal.NewFromFloat(new_order.AcctPay)).Float64()
-
- orderInfos_two, _ := service.GetHisOrderDetailByNumber(new_order.Number, adminUser.CurrentOrgId)
- var balanceAccountsType int64
- if new_order.IsMedicineInsurance == 1 {
- balanceAccountsType = 1
- } else {
- balanceAccountsType = 2
- }
-
- if balanceAccountsType == 2 {
-
- for _, item := range orderInfos_two {
- item.FulamtOwnpayAmt = item.DetItemFeeSumamt
- if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 {
- item.MedChrgitmType = "09"
- }
- if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
- if item.HisPrescriptionProject.Type == 2 {
- switch item.HisPrescriptionProject.VMHisProject.CostClassify {
- case 1:
- item.MedChrgitmType = "14"
- break
- case 2:
- item.MedChrgitmType = "05"
-
- break
- case 3:
- item.MedChrgitmType = "04"
-
- break
- case 4:
- item.MedChrgitmType = "03"
-
- break
- case 5:
- item.MedChrgitmType = "08"
-
- break
- case 6:
- item.MedChrgitmType = "14"
-
- break
- case 7:
- item.MedChrgitmType = "14"
-
- break
- case 8:
- item.MedChrgitmType = "03"
- break
- case 9:
- item.MedChrgitmType = "14"
- break
- }
-
- } else if item.HisPrescriptionProject.Type == 3 {
- item.MedChrgitmType = "08"
- }
- }
- }
-
- for _, item := range orderInfos_two {
- fmt.Println(item.MedChrgitmType)
- if item.MedChrgitmType == "07" {
- hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- hiliCostSelfTotal = hiliCostTotal
- }
-
- if item.MedChrgitmType == "01" {
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- bedCostSelfTotal = bedCostTotal
- }
-
- if item.MedChrgitmType == "02" {
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- zhenChaCostSelfTotal = zhenChaCostTotal
- }
-
- if item.MedChrgitmType == "03" {
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- checkCostSelfTotal = checkCostTotal
- }
-
- if item.MedChrgitmType == "04" {
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- laboratoryCostSelfTotal = laboratoryCostTotal
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" {
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- treatCostSelfTotal = treatCostTotal
- }
-
- if item.MedChrgitmType == "06" {
- treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- operationCostSelfTotal = treatCostTotal
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" {
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- materialCostSelfTotal = materialCostTotal
- }
-
- if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" {
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- westernMedicineCostSelfTotal = westernMedicineCostTotal
- }
-
- if item.MedChrgitmType == "11" {
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
- }
-
- if c.GetAdminUserInfo().CurrentOrgId == 10106 {
- if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" {
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- otherCostSelfTotal = otherCostTotal
- }
- } else {
- if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" {
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- otherCostSelfTotal = otherCostTotal
- }
-
- }
-
- }
-
- } else {
- for _, item := range orderInfos_two {
- if item.MedChrgitmType == "01" {
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
-
- }
-
- if item.MedChrgitmType == "02" {
- zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
-
- }
-
- if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
- if item.MedChrgitmType == "03" {
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
-
-
- }
- } else {
- if item.MedChrgitmType == "03" {
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
-
- }
-
- }
-
- if item.MedChrgitmType == "04" {
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
-
-
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" {
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
-
-
- }
-
- if item.MedChrgitmType == "06" {
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
-
- }
-
- if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" {
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
-
- }
-
- if item.MedChrgitmType == "07" {
- hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
-
- }
-
- if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" {
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
-
- }
-
- if item.MedChrgitmType == "11" {
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
-
- }
-
- if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" {
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
-
-
- }
- }
- }
- }
-
-
-
- admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
- charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "charge_admin_name": charge_admin.UserName,
- "patient": patient,
- "admin_user_name": admin.UserName,
- "bedCostTotal": bedCostTotal,
- "bedCostSelfTotal": bedCostSelfTotal,
- "bedCostPartSelfTotal": bedCostPartSelfTotal,
- "operationCostTotal": operationCostTotal,
- "operationCostSelfTotal": operationCostSelfTotal,
- "operationCostPartSelfTotal": operationCostPartSelfTotal,
- "otherCostTotal": otherCostTotal,
- "otherCostSelfTotal": otherCostSelfTotal,
- "otherCostPartSelfTotal": otherCostPartSelfTotal,
- "materialCostTotal": materialCostTotal,
- "materialCostSelfTotal": materialCostSelfTotal,
- "materialCostPartSelfTotal": materialCostPartSelfTotal,
- "westernMedicineCostTotal": westernMedicineCostTotal,
- "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
- "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
- "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
- "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
- "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
- "checkCostTotal": checkCostTotal,
- "checkCostSelfTotal": checkCostSelfTotal,
- "checkCostPartSelfTotal": checkCostPartSelfTotal,
- "laboratoryCostTotal": laboratoryCostTotal,
- "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
- "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
- "treatCostTotal": treatCostTotal,
- "treatCostSelfTotal": treatCostSelfTotal,
- "treatCostPartSelfTotal": treatCostPartSelfTotal,
- "zhenChaCostTotal": zhenChaCostTotal,
- "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
- "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
- "hiliCostTotal": hiliCostTotal,
- "hiliCostSelfTotal": hiliCostSelfTotal,
- "medfee_sumamt": MedfeeSumamt,
- "fund_pay_sumamt": FundPaySumamt,
- "hifp_pay": HifpPay,
- "maf_pay": MafPay,
- "acct_pay": AcctPay,
- "psn_cash_pay": PsnCashPay,
- })
-
- }
-
- type FapiaoApiController struct {
- BaseAuthAPIController
- }
-
- type InvoiceRequest struct {
- SellerName string `json:"seller_name,omitempty"`
- SellerTaxpayerNum string `json:"seller_taxpayer_num"`
- SellerAddress string `json:"seller_address"`
- SellerTel string `json:"seller_tel"`
- SellerBankName string `json:"seller_bank_name"`
- SellerBankAccount string `json:"seller_bank_account"`
- TitleType int `json:"title_type"`
- BuyerTitle string `json:"buyer_title"`
- BuyerTaxpayerNum string `json:"buyer_taxpayer_num,omitempty"`
- BuyerAddress string `json:"buyer_address,omitempty"`
- BuyerPhone string `json:"buyer_phone,omitempty"`
- BuyerBankName string `json:"buyer_bank_name,omitempty"`
- BuyerBankAccount string `json:"buyer_bank_account,omitempty"`
- BuyerEmail string `json:"buyer_email,omitempty"`
- OrderID string `json:"order_id"`
- InvoiceTypeCode string `json:"invoice_type_code,omitempty"`
- CallbackURL string `json:"callback_url"`
- Drawer string `json:"drawer"`
- Payee string `json:"payee,omitempty"`
- Checker string `json:"checker,omitempty"`
- TerminalCode string `json:"terminal_code"`
- UserOpenID string `json:"user_openid,omitempty"`
- SpecialInvoiceKind string `json:"special_invoice_kind,omitempty"`
- AmountHasTax string `json:"amount_has_tax"`
- TaxAmount string `json:"tax_amount"`
- AmountWithoutTax string `json:"amount_without_tax"`
- Remark string `json:"remark,omitempty"`
- StoreNo string `json:"store_no,omitempty"`
- Template int `json:"template"`
- Info *InvoiceInfo `json:"info,omitempty"`
- TaxpayerConfirmation *TaxpayerConfirmation `json:"taxpayer_confirmation,omitempty"`
- SpecificBusinessCode string `json:"specific_business_code,omitempty"`
- RealStaticRent *RealStaticRent `json:"real_static_rent,omitempty"`
- PassengerTransport []PassengerTransport `json:"passenger_transport,omitempty"`
- GoodsTransport []GoodsTransport `json:"goods_transport,omitempty"`
- AgriculturalPurchase *AgriculturalPurchase `json:"agricultural_purchase,omitempty"`
- BuildingService *BuildingService `json:"building_service,omitempty"`
- RealStaticSales *RealStaticSales `json:"real_static_sales,omitempty"`
- TractorCombine *TractorCombine `json:"tractor_combine,omitempty"`
- UsedCarService *UsedCarService `json:"used_car_service,omitempty"`
- UsedCarSell *UsedCarSell `json:"used_car_sell,omitempty"`
- DeductionService *DeductionService `json:"deduction_service,omitempty"`
- Items []Item `json:"items"`
- }
-
- type InvoiceInfo struct {
- UseDate string `json:"use_date,omitempty"`
- TicketName string `json:"ticket_name,omitempty"`
- }
-
- type TaxpayerConfirmation struct {
- RenewableResourceRecyclingFlag int `json:"renewable_resource_recycling_flag,omitempty"`
- DrawWithNoBuyerFlag int `json:"draw_with_nobuyer_flag,omitempty"`
- NotDutyFreeReason string `json:"not_dutyfree_reason,omitempty"`
- }
-
- type RealStaticRent struct {
- PropertyNum string `json:"property_num"`
- Location string `json:"location"`
- AddressDetail string `json:"address_detail"`
- RentBeginDate string `json:"rent_begin_date"`
- RentEndDate string `json:"rent_end_date"`
- IntercityFlag string `json:"intercity_flag"`
- UnitOfArea int `json:"unit_of_area"`
- }
-
- type PassengerTransport struct {
- Traveler string `json:"traveler,omitempty"`
- IDType int `json:"id_type,omitempty"`
- IDNumber string `json:"id_number,omitempty"`
- TravelDate string `json:"travel_date,omitempty"`
- DeparturePlace string `json:"departure_place,omitempty"`
- DestinationPlace string `json:"destination_palce,omitempty"`
- VehicleType int `json:"vehicle_type,omitempty"`
- Level string `json:"level,omitempty"`
- }
-
- type GoodsTransport struct {
- TransportNumber string `json:"transport_number,omitempty"`
- TransportKind string `json:"transport_kind,omitempty"`
- GoodsName string `json:"goods_name,omitempty"`
- DeparturePlace string `json:"departure_place,omitempty"`
- DestinationPlace string `json:"destination_place,omitempty"`
- }
-
- type AgriculturalPurchase struct {
- IDType string `json:"id_type,omitempty"`
- }
-
- type BuildingService struct {
- Site string `json:"site"`
- DetailSite string `json:"detail_site,omitempty"`
- BuildingProject string `json:"building_project"`
- CrossSign string `json:"cross_sign"`
- }
-
- type RealStaticSales struct {
- PropertyNum string `json:"property_num,omitempty"`
- Location string `json:"location"`
- AddressDetail string `json:"address_detail,omitempty"`
- CrossSign string `json:"cross_sign"`
- UnitOfArea int `json:"unit_of_area"`
- OnlineContractCode string `json:"online_contract_code,omitempty"`
- }
-
- type TractorCombine struct {
- ChassisNumber string `json:"chassis_number,omitempty"`
- EngineNumber string `json:"engine_number"`
- IsRegister string `json:"is_register,omitempty"`
- }
-
- type UsedCarService struct {
- TicketSN string `json:"ticket_sn"`
- PaperTicketCode string `json:"paper_ticket_code"`
- PaperTicketSN string `json:"paper_ticket_sn"`
- }
-
- type UsedCarSell struct {
- FrameNumber string `json:"frame_number"`
- LicensePlateNumber string `json:"license_plate_number"`
- BrandModel string `json:"brand_model"`
- RegistrationCertificate string `json:"registration_certificate"`
- TransferOfficeName string `json:"transfer_office_name"`
- NatureOfEnterprise string `json:"nature_of_enterprise"`
- }
-
- type DeductionService struct {
- TaxDiffServiceFlag int `json:"tax_diff_service_flag,omitempty"`
- TaxableServiceName string `json:"taxable_service_name,omitempty"`
- }
-
- type Item struct {
- ItemName string `json:"item_name"`
- ItemSpec string `json:"item_spec,omitempty"`
- ItemUnit string `json:"item_unit"`
- ItemQuantity float64 `json:"item_quantity"`
- ItemPrice float64 `json:"item_price"`
- ItemAmount float64 `json:"item_amount"`
- ItemTaxRate float64 `json:"item_tax_rate"`
- ItemTaxAmount float64 `json:"item_tax_amount"`
- RowType int `json:"row_type"`
- }
-
- func (c *FapiaoApiController) GetFaPiaoList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUser := c.GetAdminUserInfo()
- org_id := adminUser.CurrentOrgId
- order, err, total := service.GetFaPiaoList(org_id, page, limit, startTime, endTime)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "fapiao_record": order,
- "total": total,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- }
- func (c *FapiaoApiController) GetOrderFaPiaoList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- is_open_fapiao, _ := c.GetInt64("is_open_fapiao", 0)
- sort_type, _ := c.GetInt64("sort_type", 0)
-
- patient_id, _ := c.GetInt64("patient_id", 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- adminUser := c.GetAdminUserInfo()
- org_id := adminUser.CurrentOrgId
- order, err, total := service.GetFaPiaoSettleList(org_id, page, limit, startTime, endTime, sort_type, start_time, end_time, is_open_fapiao, patient_id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- "total": total,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- func (c *FapiaoApiController) GetLoginUploadCode() {
- sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
- var config models.FapiaoConfig
- config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
- routerAddress, postData := fapiao.GetSMSCode(config)
- fmt.Println(routerAddress)
- fmt.Println(postData)
- r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
- if err != nil {
- fmt.Println(err)
- } else {
- var resp SmsCode
-
- json.Unmarshal(r, &resp)
- if resp.Code == 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": resp.Message,
- })
- }
- }
- }
-
- type SmsCode struct {
- Code int `json:"code"`
- Message string `json:"message"`
- }
-
- func (c *FapiaoApiController) Login() {
- code := c.GetString("code")
- var config models.FapiaoConfig
- config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
- sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
- routerAddress, postData := fapiao.Login(code, config)
- r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
- if err != nil {
- fmt.Println(err)
- } else {
- var resp SmsCode
-
- json.Unmarshal(r, &resp)
- if resp.Code == 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": resp.Message,
- })
- }
- }
- }
- func (c *FapiaoApiController) GetQRCode() {
- sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
- var config models.FapiaoConfig
- config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
- routerAddress, postData := fapiao.GetQRCode(config)
- r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
- if err != nil {
- fmt.Println(err)
- } else {
- var resp QRAuth
-
- err := json.Unmarshal(r, &resp)
- fmt.Println(resp)
- if err != nil {
- fmt.Println("Error unmarshalling:", err)
- } else {
- if resp.Code == 0 {
- decodedBytes, _ := base64.StdEncoding.DecodeString(resp.Data.QrCode)
- if len(resp.Data.AuthId) == 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "cus_status": 1,
- "qr_code": string(decodedBytes),
- })
-
- } else {
- status := GetQRStatus(c.GetAdminUserInfo().CurrentOrgId, resp.Data.AuthId)
- if status == "UNDEFINE" {
- c.ServeSuccessJSON(map[string]interface{}{
- "cus_status": -1,
- "msg": "未定义",
- })
- } else if status == "UNHANDLED" {
- c.ServeSuccessJSON(map[string]interface{}{
- "cus_status": 1,
- "qr_code": string(decodedBytes),
- })
- } else if status == "REAL_AUTH_SUCCESS" {
- c.ServeSuccessJSON(map[string]interface{}{
- "cus_status": 2,
- "msg": "已经实名认证成功",
- })
- } else if status == "REFRESH" {
- c.ServeSuccessJSON(map[string]interface{}{
- "cus_status": 1,
- "qr_code": string(decodedBytes),
- })
- } else if status == "NEED_RELOGIN_BUREAU" {
- c.ServeSuccessJSON(map[string]interface{}{
- "cus_status": -3,
- "msg": "登录失效,请重新短信登录税局",
- })
-
- }
- }
-
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "cus_status": -4,
- "msg": resp.Message,
- })
- }
-
- }
-
- }
- }
-
- func (c *FapiaoApiController) OpenFaPiao() {
-
-
-
-
- sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "")
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- order_ids := c.GetString("order_ids")
- admin_user_id, _ := c.GetInt64("admin_user_id")
- ids := strings.Split(order_ids, ",")
- orders, _ := service.GetFaPiaoOrderByIDS(ids)
- var MedfeeSumamt float64 = 0
- var PsnCashPay float64 = 0
- var FundPaySumamt float64 = 0
-
- var HifmiPay float64 = 0
- var MafPay float64 = 0
- var HifpPay float64 = 0
- var AcctPay float64 = 0
-
- var details []models.HisOrderInfo
- var numbers []string
- decimal.DivisionPrecision = 2
-
- var remark string
-
- for _, oss := range orders {
- MedfeeSumamt, _ = decimal.NewFromFloat(MedfeeSumamt).Add(decimal.NewFromFloat(oss.MedfeeSumamt)).Float64()
- PsnCashPay, _ = decimal.NewFromFloat(PsnCashPay).Add(decimal.NewFromFloat(oss.PsnCashPay)).Float64()
- FundPaySumamt, _ = decimal.NewFromFloat(FundPaySumamt).Add(decimal.NewFromFloat(oss.FundPaySumamt)).Float64()
-
- HifmiPay, _ = decimal.NewFromFloat(HifmiPay).Add(decimal.NewFromFloat(oss.HifmiPay)).Float64()
- MafPay, _ = decimal.NewFromFloat(MafPay).Add(decimal.NewFromFloat(oss.MafPay)).Float64()
- HifpPay, _ = decimal.NewFromFloat(HifpPay).Add(decimal.NewFromFloat(oss.HifpPay)).Float64()
- AcctPay, _ = decimal.NewFromFloat(AcctPay).Add(decimal.NewFromFloat(oss.AcctPay)).Float64()
-
- numbers = append(numbers, oss.Number)
- }
- if MedfeeSumamt > 0 {
- MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
-
- if len(remark) == 0 {
-
- remark = "医疗总费用: " + MedfeeSumamt_str
- } else {
- remark = remark + " 医疗总费用:" + MedfeeSumamt_str
- }
- }
-
- if FundPaySumamt > 0 {
- MedfeeSumamt_str := fmt.Sprintf("%.2f", FundPaySumamt)
-
- if len(remark) == 0 {
-
- remark = "基金支付总金额: " + MedfeeSumamt_str
- } else {
- remark = remark + " 基金支付总金额:" + MedfeeSumamt_str
- }
- }
-
- if PsnCashPay > 0 {
- MedfeeSumamt_str := fmt.Sprintf("%.2f", PsnCashPay)
-
- if len(remark) == 0 {
-
- remark = "个人现金支付: " + MedfeeSumamt_str
- } else {
- remark = remark + " 个人现金支付:" + MedfeeSumamt_str
- }
- }
-
- if HifmiPay > 0 {
- MedfeeSumamt_str := fmt.Sprintf("%.2f", HifmiPay)
-
- if len(remark) == 0 {
-
- remark = "大病基金支付: " + MedfeeSumamt_str
- } else {
- remark = remark + " 大病基金支付:" + MedfeeSumamt_str
- }
- }
-
- if AcctPay > 0 {
- MedfeeSumamt_str := fmt.Sprintf("%.2f", AcctPay)
-
- if len(remark) == 0 {
-
- remark = "个账支付: " + MedfeeSumamt_str
- } else {
- remark = remark + " 个账支付:" + MedfeeSumamt_str
- }
- }
-
- if HifpPay > 0 {
- MedfeeSumamt_str := fmt.Sprintf("%.2f", HifpPay)
-
- if len(remark) == 0 {
-
- remark = "基本统筹基金支付: " + MedfeeSumamt_str
- } else {
- remark = remark + " 基本统筹基金支付:" + MedfeeSumamt_str
- }
- }
-
- if MafPay > 0 {
- MedfeeSumamt_str := fmt.Sprintf("%.2f", MafPay)
-
- if len(remark) == 0 {
-
- remark = "医疗救助基金支付: " + MedfeeSumamt_str
- } else {
- remark = remark + " 医疗救助基金支付:" + MedfeeSumamt_str
- }
- }
-
- details, _ = service.GetFaPiaoOrderInfoByNumbers(numbers)
- role, _ := service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
-
- type CostType struct {
- name string
- price float64
- }
- var cts []CostType
- var ct CostType
-
- var bedCostTotal float64 = 0
- var operationCostTotal float64 = 0
- var otherCostTotal float64 = 0
- var materialCostTotal float64 = 0
- var westernMedicineCostTotal float64 = 0
- var chineseTraditionalMedicineCostTotal float64 = 0
- var checkCostTotal float64 = 0
- var laboratoryCostTotal float64 = 0
- var treatCostTotal float64 = 0
- var huliCostTotal float64 = 0
- var zhencaCostTotal float64 = 0
-
- for _, item := range details {
- if item.MedChrgitmType == "01" {
- bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- }
- if item.MedChrgitmType == "07" {
- huliCostTotal, _ = decimal.NewFromFloat(huliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- }
- if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
- if item.MedChrgitmType == "03" {
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- }
- } else {
- if item.MedChrgitmType == "03" {
- checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- }
-
- }
- if item.MedChrgitmType == "04" {
- laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- }
-
- if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" {
- treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- }
-
- if item.MedChrgitmType == "06" {
- operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- }
-
- if item.MedChrgitmType == "08" {
- materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- }
-
- if item.MedChrgitmType == "09" {
- westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- }
-
- if item.MedChrgitmType == "11" {
- chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- }
-
- if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" {
- otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- }
-
- if item.MedChrgitmType == "02" {
- zhencaCostTotal, _ = decimal.NewFromFloat(zhencaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
- }
- }
- if bedCostTotal > 0 {
- ct.name = "床位费"
- ct.price = bedCostTotal
- cts = append(cts, ct)
- }
-
- if operationCostTotal > 0 {
- ct.name = "手术费"
- ct.price = operationCostTotal
- cts = append(cts, ct)
-
- }
- if otherCostTotal > 0 {
- ct.name = "其他费"
- ct.price = otherCostTotal
- cts = append(cts, ct)
-
- }
- if materialCostTotal > 0 {
- ct.name = "材料费"
- ct.price = materialCostTotal
- cts = append(cts, ct)
-
- }
- if westernMedicineCostTotal > 0 {
- ct.name = "西药费"
- ct.price = westernMedicineCostTotal
- cts = append(cts, ct)
-
- }
- if chineseTraditionalMedicineCostTotal > 0 {
- ct.name = "中成药费"
- ct.price = chineseTraditionalMedicineCostTotal
- cts = append(cts, ct)
-
- }
- if checkCostTotal > 0 {
- ct.name = "检查费"
- ct.price = checkCostTotal
- cts = append(cts, ct)
-
- }
- if laboratoryCostTotal > 0 {
- ct.name = "化验费"
- ct.price = laboratoryCostTotal
- cts = append(cts, ct)
-
- }
- if treatCostTotal > 0 {
- ct.name = "治疗费"
- ct.price = treatCostTotal
- cts = append(cts, ct)
-
- }
- if huliCostTotal > 0 {
- ct.name = "护理费"
- ct.price = huliCostTotal
- cts = append(cts, ct)
-
- }
-
- if zhencaCostTotal > 0 {
- ct.name = "诊察费"
- ct.price = zhencaCostTotal
- cts = append(cts, ct)
-
- }
- fmt.Println(cts)
- org_config, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
- var config2 models.FapiaoConfig
- config2, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
- number := strconv.FormatInt(time.Now().Unix(), 10) + "_" + strconv.FormatInt(orders[0].UserOrgId, 10) + "_" + strconv.FormatInt(orders[0].PatientId, 10)
- amountWithoutTax, _, taxAmount, amountHasTax := CalculatePriceDetails(MedfeeSumamt, 1, 0.00)
-
- patient, _ := service.GetXTPatientInfo(c.GetAdminUserInfo().CurrentOrgId, orders[0].PatientId)
-
- orders[0].PsnName = patient.Name
- role.UserName = "陈金娣"
- postData3 := map[string]interface{}{
- "seller_name": org_config.OrgName,
- "seller_taxpayer_num": config2.SellerTaxpayerNum,
- "seller_address": config2.SellerAddress,
- "seller_tel": config2.SellerTel,
- "seller_bank_name": config2.SellerBankName,
- "seller_bank_account": config2.SellerBankAccount,
- "title_type": 1,
- "buyer_title": orders[0].PsnName + "(个人)",
- "buyer_taxpayer_num": "",
- "buyer_address": "",
- "buyer_phone": "",
- "buyer_bank_name": "",
- "buyer_bank_account": "",
- "buyer_email": "",
- "order_id": number,
- "invoice_type_code": "082",
- "callback_url": "http://www.goldentec.com/callback",
- "drawer": role.UserName,
- "payee": "",
- "checker": "",
- "terminal_code": config2.TerminalCode,
- "user_openid": "",
- "special_invoice_kind": "",
- "zsfs": "",
- "deduction": "",
- "amount_has_tax": amountHasTax,
- "tax_amount": taxAmount,
- "amount_without_tax": amountWithoutTax,
- "remark": remark,
- }
-
-
- items := make([]map[string]interface{}, 0)
- for _, ct := range cts {
- item := make(map[string]interface{})
- amountWithoutTax, _, taxAmount, _ := CalculatePriceDetails(ct.price, 1, 0.00)
- item["name"] = ct.name
- item["tax_code"] = "3070202000000000000"
- item["models"] = ""
- item["unit"] = ""
- item["total_price"] = amountWithoutTax
- item["total"] = "1"
- item["price"] = amountWithoutTax
- item["tax_rate"] = "0.00"
- item["tax_amount"] = taxAmount
- item["discount"] = "0"
- item["preferential_policy_flag"] = "1"
- item["zero_tax_flag"] = "1"
- item["vat_special_management"] = "免税"
- items = append(items, item)
- }
- postData3["items"] = items
- routerAddress, postData4 := fapiao.Blue(postData3)
- fmt.Println(postData4)
-
- r, err4 := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData4)
- fmt.Println("blue")
- fmt.Println(err4)
- fmt.Println(string(r))
- if err4 != nil {
- fmt.Println(err4)
- } else {
- var resp OpenFaPiaoResultResponse
-
- err := json.Unmarshal(r, &resp)
- fmt.Println(resp)
- if err != nil {
- fmt.Println("Error unmarshalling:", err)
- } else {
- fmt.Println(resp)
-
- if resp.Code == 0 {
- var fapiaos models.HisFaPiaoOrder
- fapiaos.InvoiceId = resp.Data.InvoiceId
- fapiaos.OrderSn = resp.Data.OrderSn
- fapiaos.FapiaoStatus = "1"
- fapiaos.OrderIds = order_ids
- fapiaos.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
- fapiaos.Status = 1
- fapiaos.PatientId = orders[0].PatientId
- fapiaos.Ctime = time.Now().Unix()
- fapiaos.Mtime = time.Now().Unix()
- fapiaos.Creator = role.UserName
- fapiaos.MedfeeSumamt = MedfeeSumamt
- fapiaos.FundPaySumamt = FundPaySumamt
- fapiaos.PsnCashPay = PsnCashPay
- fmt.Println(ids)
- service.UpdateFaPiaoSN(resp.Data.OrderSn, ids)
- err5 := service.SaveFaPiaoOrder(&fapiaos)
-
-
- go func(num string, sn string, number string, fapiaos models.HisFaPiaoOrder, ids []string) {
-
- time.Sleep(30 * time.Second)
-
-
- routerAddress2, postData2 := fapiao.Query(num, sn, number)
- r3, err2 := sdk.HttpPost("https://apigw.goldentec.com", routerAddress2, postData2)
- fmt.Println("query")
- fmt.Println(string(r3))
- if err2 != nil {
- fmt.Println(err2)
- } else {
- var resp3 QueryFaPiaoResultResponse
-
- json.Unmarshal(r3, &resp3)
- if resp3.Code == 0 {
- if resp3.Data.Status == 3 {
-
- fapiaos.TicketSn = resp3.Data.TicketSn
- fapiaos.TicketDate = resp3.Data.TicketDate
- fapiaos.AmountWithTax = resp3.Data.AmountWithoutTax
- fapiaos.AmountWithoutTax = resp3.Data.AmountWithoutTax
- fapiaos.FapiaoStatus = "2"
- fapiaos.TaxAmount = resp3.Data.TaxAmount
- fapiaos.IsRedWashed = strconv.FormatInt(int64(resp3.Data.IsRedWashed), 10)
- fapiaos.PdfUrl = resp3.Data.PdfUrl
- fapiaos.OfdUrl = resp3.Data.OfdUrl
- fapiaos.XmlUrl = resp3.Data.XmlUrl
- service.SaveFaPiaoOrder(&fapiaos)
- service.UpdateFaPiaoNumber(resp3.Data.TicketSn, ids)
-
- } else if resp3.Data.Status == 1 {
- fapiaos.FapiaoStatus = "1"
- fapiaos.TicketSn = ""
- service.SaveFaPiaoOrder(&fapiaos)
-
- } else if resp3.Data.Status == 2 {
- fapiaos.FapiaoStatus = "3"
- fapiaos.TicketSn = ""
- fapiaos.Message = resp3.Data.Message
- service.SaveFaPiaoOrder(&fapiaos)
- } else {
- fapiaos.FapiaoStatus = "3"
- fapiaos.TicketSn = ""
- fapiaos.Message = resp3.Data.Message
- service.SaveFaPiaoOrder(&fapiaos)
- }
- } else {
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "查询失败" + resp3.Message,
- })
- }
- }
- }(config2.SellerTaxpayerNum, resp.Data.OrderSn, number, fapiaos, ids)
-
- if err5 == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "开具成功,审核中。",
- })
- }
-
- } else {
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "开具失败" + resp.Message,
- })
- }
- }
- }
- }
-
- func (c *FapiaoApiController) RedFaPiao() {
-
- id, _ := c.GetInt64("id")
- admin_user_id, _ := c.GetInt64("admin_user_id")
- role2, _ := service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
- fapiao_config, _ := service.GetFaPiaoOrderById(id)
- var config models.FapiaoConfig
- config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
- sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
- routerAddress, postData := fapiao.Red(config.SellerTaxpayerNum, "", fapiao_config.OrderSn)
- fmt.Println("postData")
- fmt.Println(postData)
- fmt.Println("postData")
- red, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
- fmt.Println("red")
- fmt.Println(red)
- fmt.Println("red")
-
- if err != nil {
- fmt.Println(err)
- } else {
- var resp RedResult
-
- json.Unmarshal(red, &resp)
-
- fmt.Println("resp")
- fmt.Println(resp)
- fmt.Println("resp")
-
- if resp.Code == 0 {
- if resp.Data[0].State == 1 {
-
- routerAddress2, postData2 := fapiao.Query(config.SellerTaxpayerNum, fapiao_config.OrderSn, "")
- r3, _ := sdk.HttpPost("https://apigw.goldentec.com", routerAddress2, postData2)
- var resp3 QueryFaPiaoResultResponse
-
- json.Unmarshal(r3, &resp3)
-
- fmt.Println("resp")
- fmt.Println(string(r3))
- fmt.Println(resp3)
- fmt.Println("resp")
- if resp3.Code == 0 {
- if resp3.Data.IsRedWashed == 1 {
- fapiao_config.IsRedWashed = "1"
- fapiao_config.Status = 0
- fapiao_config.RedInvoiceId = resp.Data[0].InvoiceId
- fapiao_config.RedInvoiceCreator = role2.UserName
- service.SaveFaPiaoOrder(&fapiao_config)
-
- service.UpdateFaPiaoNumberByNumber(fapiao_config.TicketSn)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "红冲成功",
- })
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "系统错误,红冲失败",
- })
- }
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": resp3.Message,
- })
- }
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": resp.Message,
- })
- }
- } else {
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": resp.Message,
- })
- }
- }
- }
- func GetQRStatusTwo(org_id int64) (status int64) {
- sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
- var config models.FapiaoConfig
- config, _ = service.FindFaPiaoConfigInfo(org_id)
- routerAddress, postData := fapiao.GetQRCode(config)
- r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
- if err != nil {
- fmt.Println(err)
- } else {
- var resp QRAuth
-
- err := json.Unmarshal(r, &resp)
- fmt.Println(resp)
- if err != nil {
- fmt.Println("Error unmarshalling:", err)
- } else {
- if len(resp.Data.AuthId) == 0 {
-
- } else {
- status = 1
- status_str := GetQRStatus(org_id, resp.Data.AuthId)
- if status_str == "UNDEFINE" {
- status = 0
- } else if status_str == "UNHANDLED" {
- status = 0
- } else if status_str == "REAL_AUTH_SUCCESS" {
- status = 1
- } else if status_str == "REFRESH" {
- status = 0
- } else if status_str == "NEED_RELOGIN_BUREAU" {
- status = 0
-
- }
- }
- }
- }
- return
- }
-
- type RedResult struct {
- Code int `json:"code"`
- Data []struct {
- State int `json:"state"`
- Message string `json:"message"`
- OrderSn string `json:"order_sn"`
- InvoiceId string `json:"invoice_id"`
- } `json:"data"`
- Message string `json:"message"`
- }
- type QueryFaPiaoResultResponse struct {
- Code int `json:"code"`
- Data struct {
- OrderSn string `json:"order_sn"`
- Status int `json:"status"`
- Message string `json:"message"`
- TicketDate string `json:"ticket_date"`
- TicketSn string `json:"ticket_sn"`
- TicketCode string `json:"ticket_code"`
- CheckCode string `json:"check_code"`
- AmountWithTax string `json:"amount_with_tax"`
- AmountWithoutTax string `json:"amount_without_tax"`
- TaxAmount string `json:"tax_amount"`
- IsRedWashed int `json:"is_red_washed"`
- PdfUrl string `json:"pdf_url"`
- OfdUrl string `json:"ofd_url"`
- XmlUrl string `json:"xml_url"`
- } `json:"data"`
- Message string `json:"message"`
- }
- type OpenFaPiaoResultResponse struct {
- Code int `json:"code"`
- Message string `json:"message"`
- Data struct {
- State int `json:"state"`
- OrderSn string `json:"order_sn"`
- InvoiceId string `json:"invoice_id"`
- } `json:"data"`
- }
- type SurplusStockResponse struct {
- Code int `json:"code"`
- Message string `json:"message"`
- Data struct {
- LeftQuantity int `json:"left_quantity"`
- } `json:"data"`
- }
-
- func GetFaPiaoStock(org_id int64) (left_quantity int) {
- sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
- var config models.FapiaoConfig
- config, _ = service.FindFaPiaoConfigInfo(org_id)
- routerAddress, postData := fapiao.QueryStock(config)
- r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
- if err != nil {
- fmt.Println(err)
- } else {
- var resp SurplusStockResponse
-
- err := json.Unmarshal(r, &resp)
- if err != nil {
- fmt.Println("Error unmarshalling:", err)
- } else {
- if resp.Code == 0 {
- left_quantity = resp.Data.LeftQuantity
- }
- }
- }
- return
- }
-
- type Response struct {
- Code int `json:"code"`
- Message string `json:"message"`
- Data struct {
- Status string `json:"status"`
- } `json:"data"`
- }
-
- func GetQRStatus(org_id int64, auth_id string) (status string) {
- sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
- fmt.Println(sdk)
- var config models.FapiaoConfig
- config, _ = service.FindFaPiaoConfigInfo(org_id)
- fmt.Println(config)
- routerAddress, postData := fapiao.GetQRStatus(auth_id, config)
- fmt.Println(routerAddress)
- fmt.Println(postData)
- r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
- if err != nil {
- status = "FAILD"
- fmt.Println(err)
- } else {
- fmt.Println(r)
-
- var resp Response
-
-
- err := json.Unmarshal(r, &resp)
- fmt.Println(string(r))
- if err != nil {
- status = "FAILD"
- fmt.Println("Error unmarshalling:", err)
- } else {
- status = resp.Data.Status
- fmt.Printf("Parsed struct: %+v\n", resp)
- }
- }
- return status
-
- }
-
-
- func CalculatePriceDetails(totalCost float64, itemCount int, taxRate float64) (string, string, string, string) {
-
- amountWithoutTax := roundTo(totalCost/(1+taxRate), 2)
-
-
- pricePerItem := roundTo(amountWithoutTax/float64(itemCount), 8)
-
-
- taxAmount := roundTo(amountWithoutTax*taxRate, 2)
-
-
- amountHasTax := amountWithoutTax + taxAmount
-
- return fmt.Sprintf("%f", amountWithoutTax), fmt.Sprintf("%f", pricePerItem), fmt.Sprintf("%f", taxAmount), fmt.Sprintf("%f", amountHasTax)
- }
-
-
- func roundTo(value float64, places int) float64 {
- scale := math.Pow(10, float64(places))
- return math.Round(value*scale) / scale
- }
-
- type QRAuth struct {
- Code int `json:"code"`
- Message string `json:"message"`
- Data struct {
- AuthId string `json:"auth_id"`
- QrCode string `json:"qr_code"`
- } `json:"data"`
- }
-
- type FapiaoStock struct {
- Code int `json:"code"`
- Data struct {
- LeftQuantity int `json:"left_quantity"`
- } `json:"data"`
- Message string `json:"message"`
- }
|