fapiao_controller.go 59KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  1. package sg
  2. import (
  3. "gdyb/common"
  4. "gdyb/enums"
  5. "gdyb/utils"
  6. "gdyb/invoice"
  7. "gdyb/models"
  8. "gdyb/service"
  9. "gdyb/service/fapiao"
  10. "encoding/base64"
  11. "encoding/json"
  12. "fmt"
  13. "github.com/astaxie/beego"
  14. "github.com/shopspring/decimal"
  15. "math"
  16. "strconv"
  17. "strings"
  18. "gdyb/controllers"
  19. "time"
  20. )
  21. func FaPiaoApiRegistRouters() {
  22. beego.Router("/api/fapiao/sms/code", &FapiaoApiController{}, "get:GetLoginUploadCode")
  23. beego.Router("/api/fapiao/sms/login", &FapiaoApiController{}, "get:Login")
  24. beego.Router("/api/fapiao/qrcode/get", &FapiaoApiController{}, "get:GetQRCode")
  25. beego.Router("/api/fapiao/blue", &FapiaoApiController{}, "get:OpenFaPiao")
  26. beego.Router("/api/fapiao/red", &FapiaoApiController{}, "get:RedFaPiao")
  27. beego.Router("/api/fapiao/query", &FapiaoApiController{}, "get:QueryFaPiao")
  28. }
  29. func (c *FapiaoApiController) QueryFaPiao() {
  30. id, _ := c.GetInt64("id")
  31. oc, _ := service.GetFaPiaoOrderById(id)
  32. sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "")
  33. var config models.FapiaoConfig
  34. config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
  35. routerAddress2, postData2 := fapiao.Query(config.SellerTaxpayerNum, oc.OrderSn, "")
  36. r3, err2 := sdk.HttpPost("https://apigw.goldentec.com", routerAddress2, postData2)
  37. fmt.Println("query")
  38. fmt.Println(string(r3))
  39. if err2 != nil {
  40. fmt.Println(err2)
  41. } else {
  42. var resp3 QueryFaPiaoResultResponse
  43. // 将 byte 切片转换为结构体
  44. json.Unmarshal(r3, &resp3)
  45. if resp3.Code == 0 {
  46. //var fapiaos models.HisFaPiaoOrder
  47. if resp3.Data.Status == 3 {
  48. // 异步调用查询操作,不阻塞主程序
  49. oc.TicketSn = resp3.Data.TicketSn
  50. oc.TicketDate = resp3.Data.TicketDate
  51. oc.AmountWithTax = resp3.Data.AmountWithoutTax
  52. oc.AmountWithoutTax = resp3.Data.AmountWithoutTax
  53. oc.FapiaoStatus = "2"
  54. oc.TaxAmount = resp3.Data.TaxAmount
  55. oc.IsRedWashed = strconv.FormatInt(int64(resp3.Data.IsRedWashed), 10)
  56. oc.PdfUrl = resp3.Data.PdfUrl
  57. oc.OfdUrl = resp3.Data.OfdUrl
  58. oc.XmlUrl = resp3.Data.XmlUrl
  59. service.SaveFaPiaoOrder(&oc)
  60. ids := strings.Split(oc.OrderIds, ",")
  61. service.UpdateFaPiaoNumber(resp3.Data.TicketSn, ids) //同步发票号码
  62. c.ServeSuccessJSON(map[string]interface{}{
  63. "msg": "同步成功",
  64. })
  65. } else if resp3.Data.Status == 1 {
  66. oc.FapiaoStatus = "1"
  67. oc.TicketSn = ""
  68. service.SaveFaPiaoOrder(&oc)
  69. c.ServeSuccessJSON(map[string]interface{}{
  70. "msg": "同步成功",
  71. })
  72. //service.UpdateFaPiaoNumber(resp3.Data.TicketSn, ids) //同步发票号码
  73. } else if resp3.Data.Status == 2 {
  74. oc.FapiaoStatus = "3"
  75. oc.TicketSn = ""
  76. oc.Message = resp3.Data.Message
  77. service.SaveFaPiaoOrder(&oc)
  78. c.ServeSuccessJSON(map[string]interface{}{
  79. "msg": resp3.Data.Message,
  80. })
  81. } else {
  82. oc.FapiaoStatus = "3"
  83. oc.TicketSn = ""
  84. oc.Message = resp3.Data.Message
  85. service.SaveFaPiaoOrder(&oc)
  86. c.ServeSuccessJSON(map[string]interface{}{
  87. "msg": "同步成功",
  88. })
  89. }
  90. } else {
  91. //错误处理
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "msg": "查询失败" + resp3.Message,
  94. })
  95. }
  96. //if resp3.Code == 0 {
  97. // // 异步调用查询操作,不阻塞主程序
  98. // oc.TicketSn = resp3.Data.TicketSn
  99. // oc.TicketDate = resp3.Data.TicketDate
  100. // oc.AmountWithTax = resp3.Data.AmountWithoutTax
  101. // oc.AmountWithoutTax = resp3.Data.AmountWithoutTax
  102. // oc.FapiaoStatus = "2"
  103. // oc.TaxAmount = resp3.Data.TaxAmount
  104. // oc.IsRedWashed = strconv.FormatInt(int64(resp3.Data.IsRedWashed), 10)
  105. // oc.PdfUrl = resp3.Data.PdfUrl
  106. // oc.OfdUrl = resp3.Data.OfdUrl
  107. // oc.XmlUrl = resp3.Data.XmlUrl
  108. // service.SaveFaPiaoOrder(oc)
  109. // ids := strings.Split(oc.OrderIds, ",")
  110. // service.UpdateFaPiaoNumber(resp3.Data.TicketSn, ids) //同步发票号码
  111. // c.ServeSuccessJSON(map[string]interface{}{
  112. // "msg": "查询成功",
  113. // })
  114. //} else {
  115. // //错误处理
  116. // c.ServeSuccessJSON(map[string]interface{}{
  117. // "msg": "查询失败" + resp3.Message,
  118. // })
  119. //}
  120. }
  121. }
  122. func (c *HisApiController) GetNewFaPiaoData() {
  123. order_ids := c.GetString("order_ids")
  124. patient_id, _ := c.GetInt64("patient_id")
  125. //number := c.GetString("number")
  126. adminUser := c.GetAdminUserInfo()
  127. orders := strings.Split(order_ids, ",")
  128. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  129. var bedCostTotal float64 = 0 //床位总费
  130. var bedCostSelfTotal float64 = 0 //床位自费
  131. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  132. var operationCostTotal float64 = 0 //手术费
  133. var operationCostSelfTotal float64 = 0 //手术费
  134. var operationCostPartSelfTotal float64 = 0 //手术费
  135. var otherCostTotal float64 = 0 //其他费用
  136. var otherCostSelfTotal float64 = 0 //其他费用
  137. var otherCostPartSelfTotal float64 = 0 //其他费用
  138. var materialCostTotal float64 = 0 //材料费
  139. var materialCostSelfTotal float64 = 0 //材料费
  140. var materialCostPartSelfTotal float64 = 0 //材料费
  141. var westernMedicineCostTotal float64 = 0 //西药费
  142. var westernMedicineCostSelfTotal float64 = 0 //西药费
  143. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  144. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  145. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  146. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  147. var checkCostTotal float64 = 0 //检查费
  148. var checkCostSelfTotal float64 = 0 //检查费
  149. var checkCostPartSelfTotal float64 = 0 //检查费
  150. var hiliCostTotal float64 = 0 //护理费
  151. var hiliCostSelfTotal float64 = 0 //护理费
  152. //var hiliCostPartSelfTotal float64 = 0 //护理费
  153. var laboratoryCostTotal float64 = 0 //化验费
  154. var laboratoryCostSelfTotal float64 = 0 //化验费
  155. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  156. var treatCostTotal float64 = 0 //治疗费用
  157. var treatCostSelfTotal float64 = 0 //治疗费用
  158. var treatCostPartSelfTotal float64 = 0 //治疗费用
  159. var zhenChaCostTotal float64 = 0 //其他费用
  160. var zhenChaCostSelfTotal float64 = 0 //其他费用
  161. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  162. decimal.DivisionPrecision = 2
  163. var MedfeeSumamt float64 = 0 //治疗费用
  164. var PsnCashPay float64 = 0 //治疗费用
  165. var FundPaySumamt float64 = 0 //治疗费用
  166. var HifpPay float64 = 0 //治疗费用
  167. var MafPay float64 = 0 //治疗费用
  168. var AcctPay float64 = 0 //治疗费用
  169. for _, item := range orders {
  170. var new_order models.HisOrder
  171. order_id_num, _ := strconv.ParseInt(item, 10, 64)
  172. new_order, _ = service.GetHisOrderByID(order_id_num)
  173. MedfeeSumamt, _ = decimal.NewFromFloat(MedfeeSumamt).Add(decimal.NewFromFloat(new_order.MedfeeSumamt)).Float64()
  174. PsnCashPay, _ = decimal.NewFromFloat(PsnCashPay).Add(decimal.NewFromFloat(new_order.PsnCashPay)).Float64()
  175. FundPaySumamt, _ = decimal.NewFromFloat(FundPaySumamt).Add(decimal.NewFromFloat(new_order.FundPaySumamt)).Float64()
  176. HifpPay, _ = decimal.NewFromFloat(HifpPay).Add(decimal.NewFromFloat(new_order.HifpPay)).Float64()
  177. MafPay, _ = decimal.NewFromFloat(MafPay).Add(decimal.NewFromFloat(new_order.MafPay)).Float64()
  178. AcctPay, _ = decimal.NewFromFloat(AcctPay).Add(decimal.NewFromFloat(new_order.AcctPay)).Float64()
  179. orderInfos_two, _ := service.GetHisOrderDetailByNumber(new_order.Number, adminUser.CurrentOrgId)
  180. var balanceAccountsType int64
  181. if new_order.IsMedicineInsurance == 1 {
  182. balanceAccountsType = 1
  183. } else {
  184. balanceAccountsType = 2
  185. }
  186. if balanceAccountsType == 2 {
  187. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  188. for _, item := range orderInfos_two {
  189. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  190. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  191. item.MedChrgitmType = "09"
  192. }
  193. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  194. if item.HisPrescriptionProject.Type == 2 {
  195. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  196. case 1:
  197. item.MedChrgitmType = "14"
  198. break
  199. case 2:
  200. item.MedChrgitmType = "05"
  201. break
  202. case 3:
  203. item.MedChrgitmType = "04"
  204. break
  205. case 4:
  206. item.MedChrgitmType = "03"
  207. break
  208. case 5:
  209. item.MedChrgitmType = "08"
  210. break
  211. case 6:
  212. item.MedChrgitmType = "14"
  213. break
  214. case 7:
  215. item.MedChrgitmType = "14"
  216. break
  217. case 8:
  218. item.MedChrgitmType = "03"
  219. break
  220. case 9:
  221. item.MedChrgitmType = "14"
  222. break
  223. }
  224. } else if item.HisPrescriptionProject.Type == 3 {
  225. item.MedChrgitmType = "08"
  226. }
  227. }
  228. }
  229. for _, item := range orderInfos_two {
  230. fmt.Println(item.MedChrgitmType)
  231. if item.MedChrgitmType == "07" { //床位费
  232. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  233. hiliCostSelfTotal = hiliCostTotal
  234. }
  235. if item.MedChrgitmType == "01" { //床位费
  236. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  237. bedCostSelfTotal = bedCostTotal
  238. }
  239. if item.MedChrgitmType == "02" { //诊察费
  240. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  241. zhenChaCostSelfTotal = zhenChaCostTotal
  242. }
  243. if item.MedChrgitmType == "03" { //检查费
  244. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  245. checkCostSelfTotal = checkCostTotal
  246. }
  247. if item.MedChrgitmType == "04" { //化验费
  248. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  249. laboratoryCostSelfTotal = laboratoryCostTotal
  250. }
  251. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  252. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  253. treatCostSelfTotal = treatCostTotal
  254. }
  255. if item.MedChrgitmType == "06" { //手术费
  256. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  257. operationCostSelfTotal = treatCostTotal
  258. }
  259. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  260. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  261. materialCostSelfTotal = materialCostTotal
  262. }
  263. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  264. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  265. westernMedicineCostSelfTotal = westernMedicineCostTotal
  266. }
  267. if item.MedChrgitmType == "11" { //中成费
  268. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  269. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  270. }
  271. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  272. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  273. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  274. otherCostSelfTotal = otherCostTotal
  275. }
  276. } else {
  277. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  278. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  279. otherCostSelfTotal = otherCostTotal
  280. }
  281. }
  282. }
  283. } else {
  284. for _, item := range orderInfos_two {
  285. if item.MedChrgitmType == "01" { //床位费
  286. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  287. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  288. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  289. }
  290. if item.MedChrgitmType == "02" { //诊察费
  291. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  292. //zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  293. //zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  294. }
  295. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  296. if item.MedChrgitmType == "03" { //检查费
  297. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  298. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  299. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  300. }
  301. } else {
  302. if item.MedChrgitmType == "03" { //检查费
  303. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  304. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  305. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  306. }
  307. }
  308. if item.MedChrgitmType == "04" { //化验费
  309. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  310. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  311. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  312. }
  313. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  314. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  315. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  316. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  317. }
  318. if item.MedChrgitmType == "06" { //手术费
  319. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  320. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  321. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  322. }
  323. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  324. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  325. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  326. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  327. }
  328. if item.MedChrgitmType == "07" { //护理
  329. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  330. //hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  331. //hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  332. }
  333. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  334. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  335. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  336. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  337. }
  338. if item.MedChrgitmType == "11" { //中成费
  339. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  340. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  341. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  342. }
  343. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  344. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  345. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  346. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  347. }
  348. }
  349. }
  350. }
  351. //pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  352. //sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  353. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  354. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  355. c.ServeSuccessJSON(map[string]interface{}{
  356. "charge_admin_name": charge_admin.UserName,
  357. "patient": patient,
  358. "admin_user_name": admin.UserName, //收款员
  359. "bedCostTotal": bedCostTotal,
  360. "bedCostSelfTotal": bedCostSelfTotal,
  361. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  362. "operationCostTotal": operationCostTotal,
  363. "operationCostSelfTotal": operationCostSelfTotal,
  364. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  365. "otherCostTotal": otherCostTotal,
  366. "otherCostSelfTotal": otherCostSelfTotal,
  367. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  368. "materialCostTotal": materialCostTotal,
  369. "materialCostSelfTotal": materialCostSelfTotal,
  370. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  371. "westernMedicineCostTotal": westernMedicineCostTotal,
  372. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  373. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  374. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  375. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  376. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  377. "checkCostTotal": checkCostTotal,
  378. "checkCostSelfTotal": checkCostSelfTotal,
  379. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  380. "laboratoryCostTotal": laboratoryCostTotal,
  381. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  382. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  383. "treatCostTotal": treatCostTotal,
  384. "treatCostSelfTotal": treatCostSelfTotal,
  385. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  386. "zhenChaCostTotal": zhenChaCostTotal,
  387. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  388. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  389. "hiliCostTotal": hiliCostTotal,
  390. "hiliCostSelfTotal": hiliCostSelfTotal,
  391. "medfee_sumamt": MedfeeSumamt,
  392. "fund_pay_sumamt": FundPaySumamt,
  393. "hifp_pay": HifpPay,
  394. "maf_pay": MafPay,
  395. "acct_pay": AcctPay,
  396. "psn_cash_pay": PsnCashPay,
  397. })
  398. }
  399. type FapiaoApiController struct {
  400. controllers.BaseAuthAPIController
  401. }
  402. type InvoiceRequest struct {
  403. SellerName string `json:"seller_name,omitempty"` // 销方名称
  404. SellerTaxpayerNum string `json:"seller_taxpayer_num"` // 销方纳税人识别号
  405. SellerAddress string `json:"seller_address"` // 销方地址
  406. SellerTel string `json:"seller_tel"` // 销方电话
  407. SellerBankName string `json:"seller_bank_name"` // 销方银行名称
  408. SellerBankAccount string `json:"seller_bank_account"` // 销方银行账号
  409. TitleType int `json:"title_type"` // 抬头类型:1 个人、政府事业单位;2 企业
  410. BuyerTitle string `json:"buyer_title"` // 购方名称
  411. BuyerTaxpayerNum string `json:"buyer_taxpayer_num,omitempty"` // 购方纳税人识别号
  412. BuyerAddress string `json:"buyer_address,omitempty"` // 购方地址
  413. BuyerPhone string `json:"buyer_phone,omitempty"` // 购方电话
  414. BuyerBankName string `json:"buyer_bank_name,omitempty"` // 购方银行名称
  415. BuyerBankAccount string `json:"buyer_bank_account,omitempty"` // 购方银行账号
  416. BuyerEmail string `json:"buyer_email,omitempty"` // 收票人邮箱
  417. OrderID string `json:"order_id"` // 商户订单号
  418. InvoiceTypeCode string `json:"invoice_type_code,omitempty"` // 开具发票类型
  419. CallbackURL string `json:"callback_url"` // 发票结果回传地址
  420. Drawer string `json:"drawer"` // 开票人姓名
  421. Payee string `json:"payee,omitempty"` // 收款人姓名
  422. Checker string `json:"checker,omitempty"` // 复核人姓名
  423. TerminalCode string `json:"terminal_code"` // 税盘号
  424. UserOpenID string `json:"user_openid,omitempty"` // 商家用户标识
  425. SpecialInvoiceKind string `json:"special_invoice_kind,omitempty"` // 特殊票种标识
  426. AmountHasTax string `json:"amount_has_tax"` // 含税总金额
  427. TaxAmount string `json:"tax_amount"` // 总税额
  428. AmountWithoutTax string `json:"amount_without_tax"` // 不含税总金额
  429. Remark string `json:"remark,omitempty"` // 备注
  430. StoreNo string `json:"store_no,omitempty"` // 门店编码
  431. Template int `json:"template"` // 发票模板
  432. Info *InvoiceInfo `json:"info,omitempty"` // 冠名票信息
  433. TaxpayerConfirmation *TaxpayerConfirmation `json:"taxpayer_confirmation,omitempty"` // 纳税人确认信息
  434. SpecificBusinessCode string `json:"specific_business_code,omitempty"` // 特定业务代码
  435. RealStaticRent *RealStaticRent `json:"real_static_rent,omitempty"` // 不动产经营租赁信息
  436. PassengerTransport []PassengerTransport `json:"passenger_transport,omitempty"` // 旅客运输信息
  437. GoodsTransport []GoodsTransport `json:"goods_transport,omitempty"` // 货物运输信息
  438. AgriculturalPurchase *AgriculturalPurchase `json:"agricultural_purchase,omitempty"` // 农产品收购信息
  439. BuildingService *BuildingService `json:"building_service,omitempty"` // 建筑服务信息
  440. RealStaticSales *RealStaticSales `json:"real_static_sales,omitempty"` // 不动产销售信息
  441. TractorCombine *TractorCombine `json:"tractor_combine,omitempty"` // 拖拉机与联合收割机信息
  442. UsedCarService *UsedCarService `json:"used_car_service,omitempty"` // 二手车服务信息
  443. UsedCarSell *UsedCarSell `json:"used_car_sell,omitempty"` // 二手车销售信息
  444. DeductionService *DeductionService `json:"deduction_service,omitempty"` // 差额征税信息
  445. Items []Item `json:"items"` // 项目商品明细
  446. }
  447. type InvoiceInfo struct {
  448. UseDate string `json:"use_date,omitempty"` // 入园日期
  449. TicketName string `json:"ticket_name,omitempty"` // 票据名称
  450. }
  451. type TaxpayerConfirmation struct {
  452. RenewableResourceRecyclingFlag int `json:"renewable_resource_recycling_flag,omitempty"` // 再生资源回收单位标志
  453. DrawWithNoBuyerFlag int `json:"draw_with_nobuyer_flag,omitempty"` // 无购买方纳税人信息继续开票标志
  454. NotDutyFreeReason string `json:"not_dutyfree_reason,omitempty"` // 放弃享受减按1%征收率原因
  455. }
  456. type RealStaticRent struct {
  457. PropertyNum string `json:"property_num"` // 房屋产权证号
  458. Location string `json:"location"` // 不动产地址 (省市区县)
  459. AddressDetail string `json:"address_detail"` // 不动产详细地址
  460. RentBeginDate string `json:"rent_begin_date"` // 租赁期起
  461. RentEndDate string `json:"rent_end_date"` // 租赁期止
  462. IntercityFlag string `json:"intercity_flag"` // 跨地市标志
  463. UnitOfArea int `json:"unit_of_area"` // 面积单位
  464. }
  465. type PassengerTransport struct {
  466. Traveler string `json:"traveler,omitempty"` // 出行人
  467. IDType int `json:"id_type,omitempty"` // 证件类型
  468. IDNumber string `json:"id_number,omitempty"` // 证件号码
  469. TravelDate string `json:"travel_date,omitempty"` // 出行日期
  470. DeparturePlace string `json:"departure_place,omitempty"` // 出发地
  471. DestinationPlace string `json:"destination_palce,omitempty"` // 到达地
  472. VehicleType int `json:"vehicle_type,omitempty"` // 交通工具类型
  473. Level string `json:"level,omitempty"` // 等级
  474. }
  475. type GoodsTransport struct {
  476. TransportNumber string `json:"transport_number,omitempty"` // 运输工具号牌
  477. TransportKind string `json:"transport_kind,omitempty"` // 运输工具种类
  478. GoodsName string `json:"goods_name,omitempty"` // 货物名称
  479. DeparturePlace string `json:"departure_place,omitempty"` // 出发地
  480. DestinationPlace string `json:"destination_place,omitempty"` // 到达地
  481. }
  482. type AgriculturalPurchase struct {
  483. IDType string `json:"id_type,omitempty"` // 证件类型
  484. }
  485. type BuildingService struct {
  486. Site string `json:"site"` // 建筑服务发生地
  487. DetailSite string `json:"detail_site,omitempty"` // 详细地址
  488. BuildingProject string `json:"building_project"` // 建筑项目名称
  489. CrossSign string `json:"cross_sign"` // 跨地市标志
  490. }
  491. type RealStaticSales struct {
  492. PropertyNum string `json:"property_num,omitempty"` // 房屋产权证书号
  493. Location string `json:"location"` // 不动产地址
  494. AddressDetail string `json:"address_detail,omitempty"` // 不动产详细地址
  495. CrossSign string `json:"cross_sign"` // 跨市标志
  496. UnitOfArea int `json:"unit_of_area"` // 面积单位
  497. OnlineContractCode string `json:"online_contract_code,omitempty"` // 不动产单元代码/网签合同编码
  498. }
  499. type TractorCombine struct {
  500. ChassisNumber string `json:"chassis_number,omitempty"` // 底盘号或机架号
  501. EngineNumber string `json:"engine_number"` // 发动机号
  502. IsRegister string `json:"is_register,omitempty"` // 是否用于拖拉机和联合收割机登记
  503. }
  504. type UsedCarService struct {
  505. TicketSN string `json:"ticket_sn"` // 发票号码
  506. PaperTicketCode string `json:"paper_ticket_code"` // 纸票发票代码
  507. PaperTicketSN string `json:"paper_ticket_sn"` // 纸票发票号码
  508. }
  509. type UsedCarSell struct {
  510. FrameNumber string `json:"frame_number"` // 车架号码
  511. LicensePlateNumber string `json:"license_plate_number"` // 车牌号
  512. BrandModel string `json:"brand_model"` // 厂牌型号
  513. RegistrationCertificate string `json:"registration_certificate"` // 登记证号
  514. TransferOfficeName string `json:"transfer_office_name"` // 转入地车辆管理所名称
  515. NatureOfEnterprise string `json:"nature_of_enterprise"` // 企业性质
  516. }
  517. type DeductionService struct {
  518. TaxDiffServiceFlag int `json:"tax_diff_service_flag,omitempty"` // 差额征税标识
  519. TaxableServiceName string `json:"taxable_service_name,omitempty"` // 差额征税项目名称
  520. }
  521. type Item struct {
  522. ItemName string `json:"item_name"` // 商品名称
  523. ItemSpec string `json:"item_spec,omitempty"` // 商品规格
  524. ItemUnit string `json:"item_unit"` // 商品单位
  525. ItemQuantity float64 `json:"item_quantity"` // 商品数量
  526. ItemPrice float64 `json:"item_price"` // 商品单价
  527. ItemAmount float64 `json:"item_amount"` // 商品金额
  528. ItemTaxRate float64 `json:"item_tax_rate"` // 商品税率
  529. ItemTaxAmount float64 `json:"item_tax_amount"` // 商品税额
  530. RowType int `json:"row_type"` // 行性质标志
  531. }
  532. func (c *FapiaoApiController) GetFaPiaoList() {
  533. page, _ := c.GetInt64("page", -1)
  534. limit, _ := c.GetInt64("limit", -1)
  535. start_time := c.GetString("start_time")
  536. end_time := c.GetString("end_time")
  537. timeLayout := "2006-01-02"
  538. loc, _ := time.LoadLocation("Local")
  539. var startTime int64
  540. if len(start_time) > 0 {
  541. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  542. if err != nil {
  543. //fmt.Println(err)
  544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  545. return
  546. }
  547. startTime = theTime.Unix()
  548. }
  549. var endTime int64
  550. if len(end_time) > 0 {
  551. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  552. if err != nil {
  553. utils.ErrorLog(err.Error())
  554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  555. return
  556. }
  557. endTime = theTime.Unix()
  558. }
  559. adminUser := c.GetAdminUserInfo()
  560. org_id := adminUser.CurrentOrgId
  561. order, err, total := service.GetFaPiaoList(org_id, page, limit, startTime, endTime)
  562. if err == nil {
  563. c.ServeSuccessJSON(map[string]interface{}{
  564. "fapiao_record": order,
  565. "total": total,
  566. })
  567. } else {
  568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  569. return
  570. }
  571. }
  572. func (c *FapiaoApiController) GetOrderFaPiaoList() {
  573. page, _ := c.GetInt64("page", -1)
  574. limit, _ := c.GetInt64("limit", -1)
  575. start_time := c.GetString("start_time")
  576. end_time := c.GetString("end_time")
  577. is_open_fapiao, _ := c.GetInt64("is_open_fapiao", 0)
  578. sort_type, _ := c.GetInt64("sort_type", 0)
  579. patient_id, _ := c.GetInt64("patient_id", 0)
  580. timeLayout := "2006-01-02"
  581. loc, _ := time.LoadLocation("Local")
  582. var startTime int64
  583. if len(start_time) > 0 {
  584. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  585. if err != nil {
  586. //fmt.Println(err)
  587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  588. return
  589. }
  590. startTime = theTime.Unix()
  591. }
  592. var endTime int64
  593. if len(end_time) > 0 {
  594. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  595. if err != nil {
  596. utils.ErrorLog(err.Error())
  597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  598. return
  599. }
  600. endTime = theTime.Unix()
  601. }
  602. adminUser := c.GetAdminUserInfo()
  603. org_id := adminUser.CurrentOrgId
  604. order, err, total := service.GetFaPiaoSettleList(org_id, page, limit, startTime, endTime, sort_type, start_time, end_time, is_open_fapiao, patient_id)
  605. if err == nil {
  606. c.ServeSuccessJSON(map[string]interface{}{
  607. "order": order,
  608. "total": total,
  609. })
  610. } else {
  611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  612. return
  613. }
  614. }
  615. func (c *FapiaoApiController) GetLoginUploadCode() {
  616. sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
  617. var config models.FapiaoConfig
  618. config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
  619. routerAddress, postData := fapiao.GetSMSCode(config) //发票开具
  620. fmt.Println(routerAddress)
  621. fmt.Println(postData)
  622. r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
  623. if err != nil {
  624. fmt.Println(err)
  625. } else {
  626. var resp SmsCode
  627. // 将 byte 切片转换为结构体
  628. json.Unmarshal(r, &resp)
  629. if resp.Code == 0 {
  630. c.ServeSuccessJSON(map[string]interface{}{
  631. "msg": resp.Message,
  632. })
  633. }
  634. }
  635. }
  636. type SmsCode struct {
  637. Code int `json:"code"`
  638. Message string `json:"message"`
  639. }
  640. func (c *FapiaoApiController) Login() {
  641. code := c.GetString("code")
  642. var config models.FapiaoConfig
  643. config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
  644. sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
  645. routerAddress, postData := fapiao.Login(code, config) //发票开具
  646. r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
  647. if err != nil {
  648. fmt.Println(err)
  649. } else {
  650. var resp SmsCode
  651. // 将 byte 切片转换为结构体
  652. json.Unmarshal(r, &resp)
  653. if resp.Code == 0 {
  654. c.ServeSuccessJSON(map[string]interface{}{
  655. "msg": resp.Message,
  656. })
  657. }
  658. }
  659. }
  660. func (c *FapiaoApiController) GetQRCode() {
  661. sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
  662. var config models.FapiaoConfig
  663. config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
  664. routerAddress, postData := fapiao.GetQRCode(config) //发票开具
  665. r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
  666. if err != nil {
  667. fmt.Println(err)
  668. } else {
  669. var resp QRAuth
  670. // 将 byte 切片转换为结构体
  671. err := json.Unmarshal(r, &resp)
  672. fmt.Println(resp)
  673. if err != nil {
  674. fmt.Println("Error unmarshalling:", err)
  675. } else {
  676. if resp.Code == 0 {
  677. decodedBytes, _ := base64.StdEncoding.DecodeString(resp.Data.QrCode)
  678. c.ServeSuccessJSON(map[string]interface{}{
  679. "cus_status": 1,
  680. "qr_code": string(decodedBytes),
  681. })
  682. } else {
  683. c.ServeSuccessJSON(map[string]interface{}{
  684. "cus_status": -4,
  685. "msg": resp.Message,
  686. })
  687. }
  688. }
  689. //fmt.Println(string(r))
  690. }
  691. }
  692. func (c *FapiaoApiController) OpenFaPiao() {
  693. //var config models.FapiaoConfig
  694. //config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
  695. //认证接口
  696. sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "")
  697. //status := GetQRStatusTwo(c.GetAdminUserInfo().CurrentOrgId)
  698. //fmt.Println("11112222")
  699. //
  700. //fmt.Println(status)
  701. //if status == 0 {
  702. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAuthWrong)
  703. // return
  704. //}
  705. //查询余量接口
  706. //routerAddress, postData := fapiao.QueryStock(config)
  707. //r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
  708. //fmt.Println(string(r))
  709. //if err != nil {
  710. // fmt.Println(err)
  711. //} else {
  712. // var resp2 FapiaoStock
  713. // // 将 byte 切片转换为结构体
  714. // err2 := json.Unmarshal(r, &resp2)
  715. // if err2 != nil {
  716. // fmt.Println(err2)
  717. //
  718. // } else {
  719. // if resp2.Code == 0 {
  720. // if resp2.Data.LeftQuantity <= 0 {
  721. // c.ServeSuccessJSON(map[string]interface{}{
  722. // "msg": "发票余量不足,请登录高灯平台申领发票",
  723. // "status": -1,
  724. // })
  725. // return
  726. // }
  727. // }
  728. // }
  729. //}
  730. //return
  731. //开蓝票逻辑
  732. order_ids := c.GetString("order_ids")
  733. admin_user_id, _ := c.GetInt64("admin_user_id")
  734. ids := strings.Split(order_ids, ",")
  735. orders, _ := service.GetFaPiaoOrderByIDS(ids)
  736. var MedfeeSumamt float64 = 0 //治疗费用
  737. var PsnCashPay float64 = 0 //治疗费用
  738. var FundPaySumamt float64 = 0 //治疗费用
  739. var HifmiPay float64 = 0 //治疗费用
  740. var MafPay float64 = 0 //治疗费用
  741. var HifpPay float64 = 0 //治疗费用
  742. var AcctPay float64 = 0 //治疗费用
  743. var details []models.HisOrderInfo
  744. var numbers []string
  745. decimal.DivisionPrecision = 2
  746. var remark string
  747. for _, oss := range orders {
  748. MedfeeSumamt, _ = decimal.NewFromFloat(MedfeeSumamt).Add(decimal.NewFromFloat(oss.MedfeeSumamt)).Float64()
  749. PsnCashPay, _ = decimal.NewFromFloat(PsnCashPay).Add(decimal.NewFromFloat(oss.PsnCashPay)).Float64()
  750. FundPaySumamt, _ = decimal.NewFromFloat(FundPaySumamt).Add(decimal.NewFromFloat(oss.FundPaySumamt)).Float64()
  751. HifmiPay, _ = decimal.NewFromFloat(HifmiPay).Add(decimal.NewFromFloat(oss.HifmiPay)).Float64()
  752. MafPay, _ = decimal.NewFromFloat(MafPay).Add(decimal.NewFromFloat(oss.MafPay)).Float64()
  753. HifpPay, _ = decimal.NewFromFloat(HifpPay).Add(decimal.NewFromFloat(oss.HifpPay)).Float64()
  754. AcctPay, _ = decimal.NewFromFloat(AcctPay).Add(decimal.NewFromFloat(oss.AcctPay)).Float64()
  755. numbers = append(numbers, oss.Number)
  756. }
  757. if MedfeeSumamt > 0 {
  758. MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
  759. if len(remark) == 0 {
  760. //MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
  761. remark = "医疗总费用: " + MedfeeSumamt_str
  762. } else {
  763. remark = remark + " 医疗总费用:" + MedfeeSumamt_str
  764. }
  765. }
  766. if FundPaySumamt > 0 {
  767. MedfeeSumamt_str := fmt.Sprintf("%.2f", FundPaySumamt)
  768. if len(remark) == 0 {
  769. //MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
  770. remark = "基金支付总金额: " + MedfeeSumamt_str
  771. } else {
  772. remark = remark + " 基金支付总金额:" + MedfeeSumamt_str
  773. }
  774. }
  775. if PsnCashPay > 0 {
  776. MedfeeSumamt_str := fmt.Sprintf("%.2f", PsnCashPay)
  777. if len(remark) == 0 {
  778. //MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
  779. remark = "个人现金支付: " + MedfeeSumamt_str
  780. } else {
  781. remark = remark + " 个人现金支付:" + MedfeeSumamt_str
  782. }
  783. }
  784. if HifmiPay > 0 {
  785. MedfeeSumamt_str := fmt.Sprintf("%.2f", HifmiPay)
  786. if len(remark) == 0 {
  787. //MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
  788. remark = "大病基金支付: " + MedfeeSumamt_str
  789. } else {
  790. remark = remark + " 大病基金支付:" + MedfeeSumamt_str
  791. }
  792. }
  793. if AcctPay > 0 {
  794. MedfeeSumamt_str := fmt.Sprintf("%.2f", AcctPay)
  795. if len(remark) == 0 {
  796. //MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
  797. remark = "个账支付: " + MedfeeSumamt_str
  798. } else {
  799. remark = remark + " 个账支付:" + MedfeeSumamt_str
  800. }
  801. }
  802. if HifpPay > 0 {
  803. MedfeeSumamt_str := fmt.Sprintf("%.2f", HifpPay)
  804. if len(remark) == 0 {
  805. //MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
  806. remark = "基本统筹基金支付: " + MedfeeSumamt_str
  807. } else {
  808. remark = remark + " 基本统筹基金支付:" + MedfeeSumamt_str
  809. }
  810. }
  811. if MafPay > 0 {
  812. MedfeeSumamt_str := fmt.Sprintf("%.2f", MafPay)
  813. if len(remark) == 0 {
  814. //MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
  815. remark = "医疗救助基金支付: " + MedfeeSumamt_str
  816. } else {
  817. remark = remark + " 医疗救助基金支付:" + MedfeeSumamt_str
  818. }
  819. }
  820. details, _ = service.GetFaPiaoOrderInfoByNumbers(numbers)
  821. role, _ := service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
  822. //role.UserName = ""
  823. type CostType struct {
  824. name string
  825. price float64
  826. }
  827. var cts []CostType
  828. var ct CostType
  829. var bedCostTotal float64 = 0 //床位总费
  830. var operationCostTotal float64 = 0 //手术费
  831. var otherCostTotal float64 = 0 //其他费用
  832. var materialCostTotal float64 = 0 //材料费
  833. var westernMedicineCostTotal float64 = 0 //西药费
  834. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  835. var checkCostTotal float64 = 0 //检查费
  836. var laboratoryCostTotal float64 = 0 //化验费
  837. var treatCostTotal float64 = 0 //治疗费用
  838. var huliCostTotal float64 = 0 //治疗费用
  839. var zhencaCostTotal float64 = 0 //治疗费用
  840. for _, item := range details {
  841. if item.MedChrgitmType == "01" { //床位费
  842. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  843. }
  844. if item.MedChrgitmType == "07" { //护理费
  845. huliCostTotal, _ = decimal.NewFromFloat(huliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  846. }
  847. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  848. if item.MedChrgitmType == "03" { //检查费
  849. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  850. }
  851. } else {
  852. if item.MedChrgitmType == "03" { //检查费
  853. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  854. }
  855. }
  856. if item.MedChrgitmType == "04" { //化验费
  857. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  858. }
  859. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  860. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  861. }
  862. if item.MedChrgitmType == "06" { //手术费
  863. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  864. }
  865. if item.MedChrgitmType == "08" { //材料费
  866. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  867. }
  868. if item.MedChrgitmType == "09" { //西药费
  869. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  870. }
  871. if item.MedChrgitmType == "11" { //中成费
  872. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  873. }
  874. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  875. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  876. }
  877. if item.MedChrgitmType == "02" { //诊察
  878. zhencaCostTotal, _ = decimal.NewFromFloat(zhencaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  879. }
  880. }
  881. if bedCostTotal > 0 {
  882. ct.name = "床位费"
  883. ct.price = bedCostTotal
  884. cts = append(cts, ct)
  885. }
  886. if operationCostTotal > 0 {
  887. ct.name = "手术费"
  888. ct.price = operationCostTotal
  889. cts = append(cts, ct)
  890. }
  891. if otherCostTotal > 0 {
  892. ct.name = "其他费"
  893. ct.price = otherCostTotal
  894. cts = append(cts, ct)
  895. }
  896. if materialCostTotal > 0 {
  897. ct.name = "材料费"
  898. ct.price = materialCostTotal
  899. cts = append(cts, ct)
  900. }
  901. if westernMedicineCostTotal > 0 {
  902. ct.name = "西药费"
  903. ct.price = westernMedicineCostTotal
  904. cts = append(cts, ct)
  905. }
  906. if chineseTraditionalMedicineCostTotal > 0 {
  907. ct.name = "中成药费"
  908. ct.price = chineseTraditionalMedicineCostTotal
  909. cts = append(cts, ct)
  910. }
  911. if checkCostTotal > 0 {
  912. ct.name = "检查费"
  913. ct.price = checkCostTotal
  914. cts = append(cts, ct)
  915. }
  916. if laboratoryCostTotal > 0 {
  917. ct.name = "化验费"
  918. ct.price = laboratoryCostTotal
  919. cts = append(cts, ct)
  920. }
  921. if treatCostTotal > 0 {
  922. ct.name = "治疗费"
  923. ct.price = treatCostTotal
  924. cts = append(cts, ct)
  925. }
  926. if huliCostTotal > 0 {
  927. ct.name = "护理费"
  928. ct.price = huliCostTotal
  929. cts = append(cts, ct)
  930. }
  931. if zhencaCostTotal > 0 {
  932. ct.name = "诊察费"
  933. ct.price = zhencaCostTotal
  934. cts = append(cts, ct)
  935. }
  936. fmt.Println(cts)
  937. org_config, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  938. var config2 models.FapiaoConfig
  939. config2, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
  940. number := strconv.FormatInt(time.Now().Unix(), 10) + "_" + strconv.FormatInt(orders[0].UserOrgId, 10) + "_" + strconv.FormatInt(orders[0].PatientId, 10)
  941. amountWithoutTax, _, taxAmount, amountHasTax := CalculatePriceDetails(MedfeeSumamt, 1, 0.00)
  942. patient, _ := service.GetXTPatientInfo(c.GetAdminUserInfo().CurrentOrgId, orders[0].PatientId)
  943. orders[0].PsnName = patient.Name
  944. postData3 := map[string]interface{}{
  945. "seller_name": org_config.OrgName,
  946. "seller_taxpayer_num": config2.SellerTaxpayerNum,
  947. "seller_address": config2.SellerAddress,
  948. "seller_tel": config2.SellerTel,
  949. "seller_bank_name": config2.SellerBankName,
  950. "seller_bank_account": config2.SellerBankAccount,
  951. "title_type": 1,
  952. "buyer_title": orders[0].PsnName + "(个人)",
  953. "buyer_taxpayer_num": "",
  954. "buyer_address": "",
  955. "buyer_phone": "",
  956. "buyer_bank_name": "",
  957. "buyer_bank_account": "",
  958. "buyer_email": "",
  959. "order_id": number,
  960. "invoice_type_code": "082",
  961. "callback_url": "http://www.goldentec.com/callback",
  962. "drawer": role.UserName,
  963. "payee": "",
  964. "checker": "",
  965. "terminal_code": config2.TerminalCode,
  966. "user_openid": "",
  967. "special_invoice_kind": "",
  968. "zsfs": "",
  969. "deduction": "",
  970. "amount_has_tax": amountHasTax,
  971. "tax_amount": taxAmount,
  972. "amount_without_tax": amountWithoutTax,
  973. "remark": remark,
  974. }
  975. ////项目商品明细
  976. items := make([]map[string]interface{}, 0)
  977. for _, ct := range cts {
  978. item := make(map[string]interface{})
  979. amountWithoutTax, _, taxAmount, _ := CalculatePriceDetails(ct.price, 1, 0.00)
  980. item["name"] = ct.name
  981. item["tax_code"] = "3070202000000000000"
  982. item["models"] = ""
  983. item["unit"] = ""
  984. item["total_price"] = amountWithoutTax
  985. item["total"] = "1"
  986. item["price"] = amountWithoutTax
  987. item["tax_rate"] = "0.00"
  988. item["tax_amount"] = taxAmount
  989. item["discount"] = "0"
  990. item["preferential_policy_flag"] = "1"
  991. item["zero_tax_flag"] = "1"
  992. item["vat_special_management"] = "免税"
  993. items = append(items, item)
  994. }
  995. postData3["items"] = items
  996. routerAddress, postData4 := fapiao.Blue(postData3) //发票开具
  997. fmt.Println(postData4)
  998. r, err4 := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData4)
  999. fmt.Println("blue")
  1000. fmt.Println(err4)
  1001. fmt.Println(string(r))
  1002. if err4 != nil {
  1003. fmt.Println(err4)
  1004. } else {
  1005. var resp OpenFaPiaoResultResponse
  1006. // 将 byte 切片转换为结构体
  1007. err := json.Unmarshal(r, &resp)
  1008. fmt.Println(resp)
  1009. if err != nil {
  1010. fmt.Println("Error unmarshalling:", err)
  1011. } else {
  1012. fmt.Println(resp)
  1013. if resp.Code == 0 {
  1014. var fapiaos models.HisFaPiaoOrder
  1015. fapiaos.InvoiceId = resp.Data.InvoiceId
  1016. fapiaos.OrderSn = resp.Data.OrderSn
  1017. fapiaos.FapiaoStatus = "1"
  1018. fapiaos.OrderIds = order_ids
  1019. fapiaos.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  1020. fapiaos.Status = 1
  1021. fapiaos.PatientId = orders[0].PatientId
  1022. fapiaos.Ctime = time.Now().Unix()
  1023. fapiaos.Mtime = time.Now().Unix()
  1024. fapiaos.Creator = role.UserName
  1025. fapiaos.MedfeeSumamt = MedfeeSumamt
  1026. fapiaos.FundPaySumamt = FundPaySumamt
  1027. fapiaos.PsnCashPay = PsnCashPay
  1028. fmt.Println(ids)
  1029. service.UpdateFaPiaoSN(resp.Data.OrderSn, ids) //同步发票号码
  1030. err5 := service.SaveFaPiaoOrder(&fapiaos)
  1031. // 异步调用查询操作,通过闭包传递参数
  1032. // 异步调用查询操作,通过闭包传递多个参数
  1033. go func(num string, sn string, number string, fapiaos models.HisFaPiaoOrder, ids []string) {
  1034. // 延迟等待一定时间再查询
  1035. time.Sleep(30 * time.Second)
  1036. // 调用查询发票的函数
  1037. //queryInvoice(id, user, retries)
  1038. routerAddress2, postData2 := fapiao.Query(num, sn, number)
  1039. r3, err2 := sdk.HttpPost("https://apigw.goldentec.com", routerAddress2, postData2)
  1040. fmt.Println("query")
  1041. fmt.Println(string(r3))
  1042. if err2 != nil {
  1043. fmt.Println(err2)
  1044. } else {
  1045. var resp3 QueryFaPiaoResultResponse
  1046. // 将 byte 切片转换为结构体
  1047. json.Unmarshal(r3, &resp3)
  1048. if resp3.Code == 0 {
  1049. if resp3.Data.Status == 3 {
  1050. // 异步调用查询操作,不阻塞主程序
  1051. fapiaos.TicketSn = resp3.Data.TicketSn
  1052. fapiaos.TicketDate = resp3.Data.TicketDate
  1053. fapiaos.AmountWithTax = resp3.Data.AmountWithoutTax
  1054. fapiaos.AmountWithoutTax = resp3.Data.AmountWithoutTax
  1055. fapiaos.FapiaoStatus = "2"
  1056. fapiaos.TaxAmount = resp3.Data.TaxAmount
  1057. fapiaos.IsRedWashed = strconv.FormatInt(int64(resp3.Data.IsRedWashed), 10)
  1058. fapiaos.PdfUrl = resp3.Data.PdfUrl
  1059. fapiaos.OfdUrl = resp3.Data.OfdUrl
  1060. fapiaos.XmlUrl = resp3.Data.XmlUrl
  1061. service.SaveFaPiaoOrder(&fapiaos)
  1062. service.UpdateFaPiaoNumber(resp3.Data.TicketSn, ids) //同步发票号码
  1063. } else if resp3.Data.Status == 1 {
  1064. fapiaos.FapiaoStatus = "1"
  1065. fapiaos.TicketSn = ""
  1066. service.SaveFaPiaoOrder(&fapiaos)
  1067. //service.UpdateFaPiaoNumber(resp3.Data.TicketSn, ids) //同步发票号码
  1068. } else if resp3.Data.Status == 2 {
  1069. fapiaos.FapiaoStatus = "3"
  1070. fapiaos.TicketSn = ""
  1071. fapiaos.Message = resp3.Data.Message
  1072. service.SaveFaPiaoOrder(&fapiaos)
  1073. } else {
  1074. fapiaos.FapiaoStatus = "3"
  1075. fapiaos.TicketSn = ""
  1076. fapiaos.Message = resp3.Data.Message
  1077. service.SaveFaPiaoOrder(&fapiaos)
  1078. }
  1079. } else {
  1080. //错误处理
  1081. c.ServeSuccessJSON(map[string]interface{}{
  1082. "msg": "查询失败" + resp3.Message,
  1083. })
  1084. }
  1085. }
  1086. }(config2.SellerTaxpayerNum, resp.Data.OrderSn, number, fapiaos, ids) // 这里将多个参数传递给闭包
  1087. if err5 == nil {
  1088. c.ServeSuccessJSON(map[string]interface{}{
  1089. "msg": "开具成功,审核中。",
  1090. })
  1091. }
  1092. } else {
  1093. //错误处理
  1094. c.ServeSuccessJSON(map[string]interface{}{
  1095. "msg": "开具失败" + resp.Message,
  1096. })
  1097. }
  1098. }
  1099. }
  1100. }
  1101. func (c *FapiaoApiController) RedFaPiao() {
  1102. id, _ := c.GetInt64("id")
  1103. admin_user_id, _ := c.GetInt64("admin_user_id")
  1104. role2, _ := service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
  1105. fapiao_config, _ := service.GetFaPiaoOrderById(id)
  1106. var config models.FapiaoConfig
  1107. config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
  1108. sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
  1109. routerAddress, postData := fapiao.Red(config.SellerTaxpayerNum, "", fapiao_config.OrderSn) //发票开具
  1110. fmt.Println("postData")
  1111. fmt.Println(postData)
  1112. fmt.Println("postData")
  1113. red, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
  1114. fmt.Println("red")
  1115. fmt.Println(red)
  1116. fmt.Println("red")
  1117. if err != nil {
  1118. fmt.Println(err)
  1119. } else {
  1120. var resp RedResult
  1121. // 将 byte 切片转换为结构体
  1122. json.Unmarshal(red, &resp)
  1123. fmt.Println("resp")
  1124. fmt.Println(resp)
  1125. fmt.Println("resp")
  1126. if resp.Code == 0 {
  1127. if resp.Data[0].State == 1 {
  1128. //查询红票开具情况
  1129. routerAddress2, postData2 := fapiao.Query(config.SellerTaxpayerNum, fapiao_config.OrderSn, "")
  1130. r3, _ := sdk.HttpPost("https://apigw.goldentec.com", routerAddress2, postData2)
  1131. var resp3 QueryFaPiaoResultResponse
  1132. // 将 byte 切片转换为结构体
  1133. json.Unmarshal(r3, &resp3)
  1134. fmt.Println("resp")
  1135. fmt.Println(string(r3))
  1136. fmt.Println(resp3)
  1137. fmt.Println("resp")
  1138. if resp3.Code == 0 {
  1139. if resp3.Data.IsRedWashed == 1 {
  1140. fapiao_config.IsRedWashed = "1"
  1141. fapiao_config.Status = 0
  1142. fapiao_config.RedInvoiceId = resp.Data[0].InvoiceId
  1143. fapiao_config.RedInvoiceCreator = role2.UserName
  1144. service.SaveFaPiaoOrder(&fapiao_config)
  1145. //将结算表的发票号码清空
  1146. service.UpdateFaPiaoNumberByNumber(fapiao_config.TicketSn)
  1147. c.ServeSuccessJSON(map[string]interface{}{
  1148. "msg": "红冲成功",
  1149. })
  1150. } else {
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "系统错误,红冲失败",
  1153. })
  1154. }
  1155. } else {
  1156. c.ServeSuccessJSON(map[string]interface{}{
  1157. "msg": resp3.Message,
  1158. })
  1159. }
  1160. } else {
  1161. c.ServeSuccessJSON(map[string]interface{}{
  1162. "msg": resp.Message,
  1163. })
  1164. }
  1165. } else {
  1166. c.ServeSuccessJSON(map[string]interface{}{
  1167. "msg": resp.Message,
  1168. })
  1169. }
  1170. }
  1171. }
  1172. //func GetQRStatusTwo(org_id int64) (status int64) {
  1173. // sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
  1174. // var config models.FapiaoConfig
  1175. // config, _ = service.FindFaPiaoConfigInfo(org_id)
  1176. // routerAddress, postData := fapiao.GetQRCode(config) //发票开具
  1177. // r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
  1178. // if err != nil {
  1179. // fmt.Println(err)
  1180. // } else {
  1181. // var resp QRAuth
  1182. // // 将 byte 切片转换为结构体
  1183. // err := json.Unmarshal(r, &resp)
  1184. // fmt.Println(resp)
  1185. // if err != nil {
  1186. // fmt.Println("Error unmarshalling:", err)
  1187. // } else {
  1188. // if len(resp.Data.AuthId) == 0 { //还没实名认证
  1189. //
  1190. // } else {
  1191. // status = 1
  1192. // status_str := GetQRStatus(org_id, resp.Data.AuthId)
  1193. // if status_str == "UNDEFINE" {
  1194. // status = 0
  1195. // } else if status_str == "UNHANDLED" {
  1196. // status = 0
  1197. // } else if status_str == "REAL_AUTH_SUCCESS" {
  1198. // status = 1
  1199. // } else if status_str == "REFRESH" {
  1200. // status = 0
  1201. // } else if status_str == "NEED_RELOGIN_BUREAU" {
  1202. // status = 0
  1203. //
  1204. // }
  1205. // }
  1206. // }
  1207. // }
  1208. // return
  1209. //}
  1210. type RedResult struct {
  1211. Code int `json:"code"`
  1212. Data []struct {
  1213. State int `json:"state"`
  1214. Message string `json:"message"`
  1215. OrderSn string `json:"order_sn"`
  1216. InvoiceId string `json:"invoice_id"`
  1217. } `json:"data"`
  1218. Message string `json:"message"`
  1219. }
  1220. type QueryFaPiaoResultResponse struct {
  1221. Code int `json:"code"`
  1222. Data struct {
  1223. OrderSn string `json:"order_sn"`
  1224. Status int `json:"status"`
  1225. Message string `json:"message"`
  1226. TicketDate string `json:"ticket_date"`
  1227. TicketSn string `json:"ticket_sn"`
  1228. TicketCode string `json:"ticket_code"`
  1229. CheckCode string `json:"check_code"`
  1230. AmountWithTax string `json:"amount_with_tax"`
  1231. AmountWithoutTax string `json:"amount_without_tax"`
  1232. TaxAmount string `json:"tax_amount"`
  1233. IsRedWashed int `json:"is_red_washed"`
  1234. PdfUrl string `json:"pdf_url"`
  1235. OfdUrl string `json:"ofd_url"`
  1236. XmlUrl string `json:"xml_url"`
  1237. } `json:"data"`
  1238. Message string `json:"message"`
  1239. }
  1240. type OpenFaPiaoResultResponse struct {
  1241. Code int `json:"code"`
  1242. Message string `json:"message"`
  1243. Data struct {
  1244. State int `json:"state"`
  1245. OrderSn string `json:"order_sn"`
  1246. InvoiceId string `json:"invoice_id"`
  1247. } `json:"data"`
  1248. }
  1249. type SurplusStockResponse struct {
  1250. Code int `json:"code"`
  1251. Message string `json:"message"`
  1252. Data struct {
  1253. LeftQuantity int `json:"left_quantity"`
  1254. } `json:"data"`
  1255. }
  1256. func GetFaPiaoStock(org_id int64) (left_quantity int) {
  1257. sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
  1258. var config models.FapiaoConfig
  1259. config, _ = service.FindFaPiaoConfigInfo(org_id)
  1260. routerAddress, postData := fapiao.QueryStock(config)
  1261. r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
  1262. if err != nil {
  1263. fmt.Println(err)
  1264. } else {
  1265. var resp SurplusStockResponse
  1266. // 将 byte 切片转换为结构体
  1267. err := json.Unmarshal(r, &resp)
  1268. if err != nil {
  1269. fmt.Println("Error unmarshalling:", err)
  1270. } else {
  1271. if resp.Code == 0 {
  1272. left_quantity = resp.Data.LeftQuantity
  1273. }
  1274. }
  1275. }
  1276. return
  1277. }
  1278. //func GetQRStatus(org_id int64, auth_id string) (status string) {
  1279. // sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
  1280. // fmt.Println(sdk)
  1281. // var config models.FapiaoConfig
  1282. // config, _ = service.FindFaPiaoConfigInfo(org_id)
  1283. // fmt.Println(config)
  1284. // routerAddress, postData := fapiao.GetQRStatus(auth_id, config) //发票开具
  1285. // fmt.Println(routerAddress)
  1286. // fmt.Println(postData)
  1287. // r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
  1288. // if err != nil {
  1289. // status = "FAILD"
  1290. // fmt.Println(err)
  1291. // } else {
  1292. // fmt.Println(r)
  1293. //
  1294. // var resp Response
  1295. //
  1296. // // 将 byte 切片转换为结构体
  1297. // err := json.Unmarshal(r, &resp)
  1298. // fmt.Println(string(r))
  1299. // if err != nil {
  1300. // status = "FAILD"
  1301. // fmt.Println("Error unmarshalling:", err)
  1302. // } else {
  1303. // status = resp.Data.Status
  1304. // fmt.Printf("Parsed struct: %+v\n", resp)
  1305. // }
  1306. // }
  1307. // return status
  1308. // //return
  1309. //}
  1310. // 计算商品价格、税额等函数
  1311. func CalculatePriceDetails(totalCost float64, itemCount int, taxRate float64) (string, string, string, string) {
  1312. // 商品不含税总金额,保留两位小数
  1313. amountWithoutTax := roundTo(totalCost/(1+taxRate), 2)
  1314. // 商品不含税单价,保留八位小数
  1315. pricePerItem := roundTo(amountWithoutTax/float64(itemCount), 8)
  1316. // 税额,保留两位小数
  1317. taxAmount := roundTo(amountWithoutTax*taxRate, 2)
  1318. // 含税总金额
  1319. amountHasTax := amountWithoutTax + taxAmount
  1320. return fmt.Sprintf("%f", amountWithoutTax), fmt.Sprintf("%f", pricePerItem), fmt.Sprintf("%f", taxAmount), fmt.Sprintf("%f", amountHasTax)
  1321. }
  1322. // 保留指定小数位数的函数
  1323. func roundTo(value float64, places int) float64 {
  1324. scale := math.Pow(10, float64(places))
  1325. return math.Round(value*scale) / scale
  1326. }
  1327. type QRAuth struct {
  1328. Code int `json:"code"`
  1329. Message string `json:"message"`
  1330. Data struct {
  1331. AuthId string `json:"auth_id"`
  1332. QrCode string `json:"qr_code"`
  1333. } `json:"data"`
  1334. }
  1335. type FapiaoStock struct {
  1336. Code int `json:"code"`
  1337. Data struct {
  1338. LeftQuantity int `json:"left_quantity"`
  1339. } `json:"data"`
  1340. Message string `json:"message"`
  1341. }