fapiao_controller.go 53KB

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