his_api_controller.go 70KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991
  1. package controllers
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/enums"
  8. "gdyb/models"
  9. "gdyb/service"
  10. "gdyb/utils"
  11. "github.com/astaxie/beego"
  12. "github.com/jinzhu/gorm"
  13. "github.com/shopspring/decimal"
  14. "io"
  15. "io/ioutil"
  16. "math/rand"
  17. "net/http"
  18. "os"
  19. "path/filepath"
  20. "strconv"
  21. "strings"
  22. "syscall"
  23. "time"
  24. "unsafe"
  25. )
  26. type HisApiController struct {
  27. BaseAuthAPIController
  28. }
  29. func HisManagerApiRegistRouters() {
  30. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  31. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  32. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  33. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  34. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  35. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  36. beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  37. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  38. }
  39. func (c *HisApiController) Sscard() {
  40. r := CardInit()
  41. if r == 0 {
  42. GetBaseInfo()
  43. }
  44. c.ServeSuccessJSON(map[string]interface{}{
  45. "list": "11",
  46. })
  47. }
  48. func GetBaseInfo() error {
  49. handle := syscall.MustLoadDLL("SSCard.dll")
  50. ReadCardBas := handle.MustFindProc("ReadCardBas")
  51. str := make([]byte, 256)
  52. str1 := make([]byte, 256)
  53. r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  54. fmt.Println(string(str))
  55. fmt.Println(r)
  56. return nil
  57. }
  58. func CardInit() int {
  59. DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  60. add := DllTestDef.MustFindProc("Init")
  61. ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  62. if err != nil {
  63. fmt.Println("SSCard的运算结果为:", ret)
  64. }
  65. result := int(ret)
  66. return result
  67. }
  68. func IntPtr(n int) uintptr {
  69. return uintptr(n)
  70. }
  71. func StrPtr(s string) uintptr {
  72. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  73. }
  74. type ResultTwo struct {
  75. ErrMsg string `json:"err_msg"`
  76. InfRefmsgid string `json:"inf_refmsgid"`
  77. Infcode int64 `json:"infcode"`
  78. Output struct {
  79. Baseinfo struct {
  80. Age float64 `json:"age"`
  81. Brdy string `json:"brdy"`
  82. Certno string `json:"certno"`
  83. Gend string `json:"gend"`
  84. Naty string `json:"naty"`
  85. PsnCertType string `json:"psn_cert_type"`
  86. PsnName string `json:"psn_name"`
  87. PsnNo string `json:"psn_no"`
  88. } `json:"baseinfo"`
  89. Idetinfo []interface{} `json:"idetinfo"`
  90. Iinfo []struct {
  91. Balc int64 `json:"balc"`
  92. CvlservFlag string `json:"cvlserv_flag"`
  93. EmpName string `json:"emp_name"`
  94. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  95. Insutype string `json:"insutype"`
  96. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  97. PausInsuDate interface{} `json:"paus_insu_date"`
  98. PsnInsuDate string `json:"psn_insu_date"`
  99. PsnInsuStas string `json:"psn_insu_stas"`
  100. PsnType string `json:"psn_type"`
  101. } `json:"insuinfo"`
  102. } `json:"output"`
  103. RefmsgTime string `json:"refmsg_time"`
  104. RespondTime string `json:"respond_time"`
  105. Signtype interface{} `json:"signtype"`
  106. WarnInfo interface{} `json:"warn_info"`
  107. }
  108. type ResultThree struct {
  109. Cainfo interface{} `json:"cainfo"`
  110. ErrMsg string `json:"err_msg"`
  111. InfRefmsgid string `json:"inf_refmsgid"`
  112. Infcode int64 `json:"infcode"`
  113. Output struct {
  114. Data struct {
  115. IptOtpNo string `json:"ipt_otp_no"`
  116. MdtrtID string `json:"mdtrt_id"`
  117. PsnNo string `json:"psn_no"`
  118. } `json:"data"`
  119. } `json:"output"`
  120. RefmsgTime string `json:"refmsg_time"`
  121. RespondTime string `json:"respond_time"`
  122. Signtype interface{} `json:"signtype"`
  123. WarnMsg interface{} `json:"warn_msg"`
  124. }
  125. type ResultFour struct {
  126. Cainfo string `json:"cainfo"`
  127. ErrMsg string `json:"err_msg"`
  128. InfRefmsgid string `json:"inf_refmsgid"`
  129. Infcode int64 `json:"infcode"`
  130. Output struct {
  131. Result []struct {
  132. BasMednFlag string `json:"bas_medn_flag"`
  133. ChldMedcFlag string `json:"chld_medc_flag"`
  134. ChrgitmLv string `json:"chrgitm_lv"`
  135. Cnt float64 `json:"cnt"`
  136. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  137. DrtReimFlag string `json:"drt_reim_flag"`
  138. FeedetlSn string `json:"feedetl_sn"`
  139. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  140. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  141. InscpScpAmt float64 `json:"inscp_scp_amt"`
  142. ListSpItemFlag string `json:"list_sp_item_flag"`
  143. LmtUsedFlag string `json:"lmt_used_flag"`
  144. MedChrgitmType string `json:"med_chrgitm_type"`
  145. Memo string `json:"memo"`
  146. OverlmtAmt float64 `json:"overlmt_amt"`
  147. PreselfpayAmt float64 `json:"preselfpay_amt"`
  148. Pric float64 `json:"pric"`
  149. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  150. SelfpayProp float64 `json:"selfpay_prop"`
  151. } `json:"result"`
  152. } `json:"output"`
  153. RefmsgTime string `json:"refmsg_time"`
  154. RespondTime string `json:"respond_time"`
  155. Signtype string `json:"signtype"`
  156. WarnMsg string `json:"warn_msg"`
  157. }
  158. type ResultFive struct {
  159. Insutype string `json:"insutype"`
  160. }
  161. type ResultSix struct {
  162. Cainfo interface{} `json:"cainfo"`
  163. ErrMsg string `json:"err_msg"`
  164. InfRefmsgid string `json:"inf_refmsgid"`
  165. Infcode int64 `json:"infcode"`
  166. Output struct {
  167. } `json:"output"`
  168. RefmsgTime string `json:"refmsg_time"`
  169. RespondTime string `json:"respond_time"`
  170. Signtype interface{} `json:"signtype"`
  171. WarnMsg interface{} `json:"warn_msg"`
  172. }
  173. type ResultSeven struct {
  174. Cainfo string `json:"cainfo"`
  175. ErrMsg string `json:"err_msg"`
  176. InfRefmsgid string `json:"inf_refmsgid"`
  177. Infcode int64 `json:"infcode"`
  178. Output struct {
  179. Setldetail []interface{} `json:"setldetail"`
  180. Setlinfo struct {
  181. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  182. AcctPay float64 `json:"acct_pay"`
  183. ActPayDedc float64 `json:"act_pay_dedc"`
  184. Age float64 `json:"age"`
  185. Balc float64 `json:"balc"`
  186. Brdy string `json:"brdy"`
  187. Certno string `json:"certno"`
  188. ClrOptins string `json:"clr_optins"`
  189. ClrType string `json:"clr_type"`
  190. ClrWay string `json:"clr_way"`
  191. CvlservFlag string `json:"cvlserv_flag"`
  192. CvlservPay float64 `json:"cvlserv_pay"`
  193. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  194. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  195. Gend string `json:"gend"`
  196. HifesPay float64 `json:"hifes_pay"`
  197. HifmiPay float64 `json:"hifmi_pay"`
  198. HifpPay float64 `json:"hifp_pay"`
  199. HospPartAmt float64 `json:"hosp_part_amt"`
  200. InscpScpAmt float64 `json:"inscp_scp_amt"`
  201. Insutype string `json:"insutype"`
  202. MafPay float64 `json:"maf_pay"`
  203. MdtrtCertType string `json:"mdtrt_cert_type"`
  204. HifobPay float64 `json:"hifob_pay"`
  205. MdtrtID string `json:"mdtrt_id"`
  206. MedType string `json:"med_type"`
  207. MedfeeSumamt float64 `json:"medfee_sumamt"`
  208. MedinsSetlID string `json:"medins_setl_id"`
  209. Naty string `json:"naty"`
  210. OthPay float64 `json:"oth_pay"`
  211. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  212. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  213. PreselfpayAmt float64 `json:"preselfpay_amt"`
  214. PsnCashPay float64 `json:"psn_cash_pay"`
  215. PsnCertType string `json:"psn_cert_type"`
  216. PsnName string `json:"psn_name"`
  217. PsnNo string `json:"psn_no"`
  218. PsnPartAmt float64 `json:"psn_part_amt"`
  219. PsnType string `json:"psn_type"`
  220. SetlID string `json:"setl_id"`
  221. SetlTime string `json:"setl_time"`
  222. } `json:"setlinfo"`
  223. } `json:"output"`
  224. RefmsgTime string `json:"refmsg_time"`
  225. RespondTime string `json:"respond_time"`
  226. Signtype interface{} `json:"signtype"`
  227. WarnMsg interface{} `json:"warn_msg"`
  228. }
  229. type ResultEight struct {
  230. Cainfo string `json:"cainfo"`
  231. ErrMsg string `json:"err_msg"`
  232. InfRefmsgid string `json:"inf_refmsgid"`
  233. Infcode int64 `json:"infcode"`
  234. Output struct {
  235. Stmtinfo struct {
  236. SetlOptins string `json:"setl_optins"`
  237. StmtRslt string `json:"stmt_rslt"`
  238. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  239. } `json:"stmtinfo"`
  240. } `json:"output"`
  241. RefmsgTime string `json:"refmsg_time"`
  242. RespondTime string `json:"respond_time"`
  243. Signtype interface{} `json:"signtype"`
  244. WarnMsg interface{} `json:"warn_msg"`
  245. }
  246. type ResultNine struct {
  247. Cainfo string `json:"cainfo"`
  248. ErrMsg string `json:"err_msg"`
  249. InfRefmsgid string `json:"inf_refmsgid"`
  250. Infcode int64 `json:"infcode"`
  251. Output struct {
  252. FileQuryNo string `json:"file_qury_no"`
  253. } `json:"output"`
  254. RefmsgTime string `json:"refmsg_time"`
  255. RespondTime string `json:"respond_time"`
  256. Signtype interface{} `json:"signtype"`
  257. WarnMsg interface{} `json:"warn_msg"`
  258. }
  259. type ResultTen struct {
  260. Cainfo string `json:"cainfo"`
  261. ErrMsg string `json:"err_msg"`
  262. InfRefmsgid string `json:"inf_refmsgid"`
  263. Infcode int64 `json:"infcode"`
  264. Output struct {
  265. DldEndtime string `json:"dld_endtime"`
  266. FileQuryNo string `json:"file_qury_no"`
  267. Filename string `json:"filename"`
  268. } `json:"output"`
  269. RefmsgTime string `json:"refmsg_time"`
  270. RespondTime string `json:"respond_time"`
  271. Signtype interface{} `json:"signtype"`
  272. WarnMsg interface{} `json:"warn_msg"`
  273. }
  274. type ResultEleven struct {
  275. Cainfo string `json:"cainfo"`
  276. ErrMsg string `json:"err_msg"`
  277. InfRefmsgid string `json:"inf_refmsgid"`
  278. Infcode int64 `json:"infcode"`
  279. Output struct {
  280. Setlinfo struct {
  281. FixmedinsName string `json:"fixmedins_name"`
  282. FixmedinsCode string `json:"fixmedins_code"`
  283. PsnNo string `json:"psn_no"`
  284. PsnName string `json:"psn_name"`
  285. HifobPay float64 `json:"hifob_pay"`
  286. Gend string `json:"gend"`
  287. Brdy string `json:"brdy"`
  288. PsnCertType string `json:"psn_cert_type"`
  289. PsnType string `json:"psn_type"`
  290. EmpName string `json:"emp_name"`
  291. Certno string `json:"certno"`
  292. Insutype string `json:"insutype"`
  293. MedfeeSumamt float64 `json:"medfee_sumamt"`
  294. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  295. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  296. PreselfpayAmt float64 `json:"preselfpay_amt"`
  297. InscpScpAmt float64 `json:"inscp_scp_amt"`
  298. ActPayDedc float64 `json:"act_pay_dedc"`
  299. HifpPay float64 `json:"hifp_pay"`
  300. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  301. CvlservPay float64 `json:"cvlserv_pay"`
  302. HifesPay float64 `json:"hifes_pay"`
  303. HifmiPay float64 `json:"hifmi_pay"`
  304. MafPay float64 `json:"maf_pay"`
  305. OthPay float64 `json:"oth_pay"`
  306. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  307. PsnPay float64 `json:"psn_pay"`
  308. AcctPay float64 `json:"acct_pay"`
  309. CashPayamt float64 `json:"cash_payamt"`
  310. Balc float64 `json:"balc"`
  311. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  312. MedinsSetlId string `json:"medins_setl_id"`
  313. RefdSetlFlag string `json:"refd_setl_flag"`
  314. SetlTime string `json:"setl_time"`
  315. } `json:"setlinfo"`
  316. } `json:"output"`
  317. RefmsgTime string `json:"refmsg_time"`
  318. RespondTime string `json:"respond_time"`
  319. Signtype interface{} `json:"signtype"`
  320. WarnMsg interface{} `json:"warn_msg"`
  321. }
  322. type Custom struct {
  323. DetItemFeeSumamt string
  324. Cut string
  325. FeedetlSn string
  326. Price string
  327. MedListCodg string
  328. Type int64
  329. AdviceId int64
  330. ProjectId int64
  331. ItemId int64
  332. }
  333. //获取个人信息----挂号-----上传就诊信息
  334. func (c *HisApiController) GetRegisterInfo() {
  335. id, _ := c.GetInt64("id")
  336. record_time := c.GetString("record_time")
  337. name := c.GetString("name")
  338. gender, _ := c.GetInt64("gender")
  339. age, _ := c.GetInt64("age")
  340. birthday := c.GetString("birthday")
  341. phone := c.GetString("phone")
  342. medical_care, _ := c.GetInt64("medical_care")
  343. id_card := c.GetString("id_card")
  344. register_type, _ := c.GetInt64("register_type")
  345. registration_fee, _ := c.GetFloat("registration_fee")
  346. medical_expenses, _ := c.GetFloat("medical_expenses")
  347. certificates, _ := c.GetInt64("certificates")
  348. settlementValue, _ := c.GetInt64("settlement_value")
  349. social_type, _ := c.GetInt64("social_type")
  350. medical_insurance_card := c.GetString("medical_insurance_card")
  351. timeLayout := "2006-01-02"
  352. loc, _ := time.LoadLocation("Local")
  353. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  354. birthUnix := birthdays.Unix()
  355. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  356. if err != nil {
  357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  358. return
  359. }
  360. recordDateTime := theTime.Unix()
  361. adminInfo := c.GetAdminUserInfo()
  362. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  363. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  364. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  365. fmt.Println(miConfig.SecretKey)
  366. if patient == nil {
  367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  368. return
  369. }
  370. if len(patient.IdCardNo) == 0 {
  371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  372. return
  373. }
  374. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  375. if config.IsOpen == 1 {
  376. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  377. resp, requestErr := http.Get(api)
  378. if requestErr != nil {
  379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  380. return
  381. }
  382. defer resp.Body.Close()
  383. body, ioErr := ioutil.ReadAll(resp.Body)
  384. if ioErr != nil {
  385. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  387. return
  388. }
  389. var respJSON map[string]interface{}
  390. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  391. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  393. return
  394. }
  395. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  396. userJSONBytes, _ := json.Marshal(userJSON)
  397. var res ResultTwo
  398. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  399. utils.ErrorLog("解析失败:%v", err)
  400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  401. return
  402. }
  403. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  404. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  405. infoStr := string(Iinfos)
  406. idetinfoStr := string(Idetinfos)
  407. if res.Infcode == 0 {
  408. his := models.VMHisPatient{
  409. Name: name,
  410. Gender: gender,
  411. Birthday: birthUnix,
  412. MedicalTreatmentType: medical_care,
  413. IdType: certificates,
  414. IdCardNo: id_card,
  415. BalanceAccountsType: settlementValue,
  416. SocialType: social_type,
  417. MedicalInsuranceNumber: medical_insurance_card,
  418. RegisterType: register_type,
  419. RegisterCost: registration_fee,
  420. TreatmentCost: medical_expenses,
  421. Status: 1,
  422. Ctime: time.Now().Unix(),
  423. Mtime: time.Now().Unix(),
  424. PsnNo: res.Output.Baseinfo.PsnNo,
  425. PsnCertType: res.Output.Baseinfo.PsnCertType,
  426. Certno: res.Output.Baseinfo.Certno,
  427. PsnName: res.Output.Baseinfo.PsnName,
  428. Gend: res.Output.Baseinfo.Gend,
  429. Naty: res.Output.Baseinfo.Naty,
  430. Brdy: res.Output.Baseinfo.Brdy,
  431. Age: res.Output.Baseinfo.Age,
  432. Iinfo: infoStr,
  433. Idetinfo: idetinfoStr,
  434. PatientId: patient.ID,
  435. RecordDate: theTime.Unix(),
  436. UserOrgId: adminInfo.CurrentOrgId,
  437. AdminUserId: adminInfo.AdminUser.Id,
  438. IsReturn: 1,
  439. }
  440. timestamp := time.Now().Unix()
  441. tempTime := time.Unix(timestamp, 0)
  442. timeFormat := tempTime.Format("20060102150405")
  443. chrgBchno := rand.Intn(100000) + 10000
  444. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  445. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  446. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  447. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  448. fmt.Println(miConfig.SecretKey)
  449. if count <= 0 {
  450. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  451. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  452. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  453. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  454. resp, requestErr := http.Get(api)
  455. if requestErr != nil {
  456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  457. return
  458. }
  459. defer resp.Body.Close()
  460. body, ioErr := ioutil.ReadAll(resp.Body)
  461. if ioErr != nil {
  462. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  464. return
  465. }
  466. var respJSON map[string]interface{}
  467. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  468. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  470. return
  471. }
  472. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  473. userJSONBytes, _ := json.Marshal(respJSON)
  474. var res ResultThree
  475. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  476. utils.ErrorLog("解析失败:%v", err)
  477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  478. return
  479. }
  480. if res.Infcode == -1 {
  481. adminUser := c.GetAdminUserInfo()
  482. errlog := &models.HisOrderError{
  483. UserOrgId: adminUser.CurrentOrgId,
  484. Ctime: time.Now().Unix(),
  485. Mtime: time.Now().Unix(),
  486. ErrMsg: res.ErrMsg,
  487. Status: 1,
  488. PatientId: id,
  489. RecordTime: recordDateTime,
  490. Stage: 2,
  491. }
  492. service.CreateErrMsgLog(errlog)
  493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  494. return
  495. }
  496. his.Number = res.Output.Data.MdtrtID
  497. his.PsnNo = res.Output.Data.PsnNo
  498. his.IptOtpNo = res.Output.Data.IptOtpNo
  499. his.IdCardNo = patient.IdCardNo
  500. his.PhoneNumber = patient.Phone
  501. his.UserOrgId = adminInfo.CurrentOrgId
  502. his.Ctime = time.Now().Unix()
  503. his.Mtime = time.Now().Unix()
  504. diagnosisConfig, _ := service.FindDiagnoseById(patientPrescription.Diagnosis)
  505. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  506. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  507. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  508. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  509. resp2, requestErr2 := http.Get(api2)
  510. if requestErr2 != nil {
  511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  512. return
  513. }
  514. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  515. if ioErr2 != nil {
  516. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  518. return
  519. }
  520. var respJSON2 map[string]interface{}
  521. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  522. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  524. return
  525. }
  526. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  527. userJSONBytes2, _ := json.Marshal(respJSON2)
  528. var res2 ResultSix
  529. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  530. utils.ErrorLog("解析失败:%v", err)
  531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  532. return
  533. }
  534. if res2.Infcode == -1 {
  535. adminUser := c.GetAdminUserInfo()
  536. errlog := &models.HisOrderError{
  537. UserOrgId: adminUser.CurrentOrgId,
  538. Ctime: time.Now().Unix(),
  539. Mtime: time.Now().Unix(),
  540. ErrMsg: res2.ErrMsg,
  541. Status: 1,
  542. PatientId: id,
  543. RecordTime: recordDateTime,
  544. Stage: 3,
  545. }
  546. service.CreateErrMsgLog(errlog)
  547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  548. return
  549. }
  550. his.Status = 1
  551. service.CreateHisPatientTwo(&his)
  552. c.ServeSuccessJSON(map[string]interface{}{
  553. "his_info": his,
  554. })
  555. } else {
  556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  557. return
  558. }
  559. } else {
  560. adminUser := c.GetAdminUserInfo()
  561. errlog := &models.HisOrderError{
  562. UserOrgId: adminUser.CurrentOrgId,
  563. Ctime: time.Now().Unix(),
  564. Mtime: time.Now().Unix(),
  565. ErrMsg: res.ErrMsg,
  566. Status: 1,
  567. PatientId: id,
  568. RecordTime: recordDateTime,
  569. Stage: 1,
  570. }
  571. service.CreateErrMsgLog(errlog)
  572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  573. return
  574. }
  575. } else {
  576. timeStr := time.Now().Format("2006-01-02")
  577. timeArr := strings.Split(timeStr, "-")
  578. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  579. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  580. var hisPatient models.XtHisPatient
  581. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  582. hisPatient = models.XtHisPatient{
  583. Name: name,
  584. Age: age,
  585. Gender: gender,
  586. Birthday: birthUnix,
  587. Phone: phone,
  588. MedicalTreatmentType: medical_care,
  589. IdType: certificates,
  590. IdCardNo: id_card,
  591. BalanceAccountsType: settlementValue,
  592. SocialType: social_type,
  593. MedicalInsuranceNumber: medical_insurance_card,
  594. RegisterType: register_type,
  595. RegisterCost: registration_fee,
  596. TreatmentCost: medical_expenses,
  597. AdminUserId: adminInfo.AdminUser.Id,
  598. UserOrgId: adminInfo.CurrentOrgId,
  599. Status: 1,
  600. RecordDate: recordDateTime,
  601. IsReturn: 1,
  602. PatientId: patient.ID,
  603. Ctime: time.Now().Unix(),
  604. Mtime: time.Now().Unix(),
  605. Number: str,
  606. }
  607. service.CreateHisPatient(&hisPatient)
  608. }
  609. c.ServeSuccessJSON(map[string]interface{}{
  610. "his_info": hisPatient,
  611. })
  612. }
  613. }
  614. //上传明细----结算
  615. func (c *HisApiController) GetUploadInfo() {
  616. id, _ := c.GetInt64("id")
  617. record_time := c.GetString("record_time")
  618. pay_way, _ := c.GetInt64("pay_way")
  619. pay_price, _ := c.GetFloat("pay_price")
  620. pay_card_no := c.GetString("pay_card_no")
  621. discount_price, _ := c.GetFloat("discount_price")
  622. preferential_price, _ := c.GetFloat("preferential_price")
  623. reality_price, _ := c.GetFloat("reality_price")
  624. found_price, _ := c.GetFloat("found_price")
  625. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  626. private_price, _ := c.GetFloat("private_price")
  627. //settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  628. timeLayout := "2006-01-02"
  629. loc, _ := time.LoadLocation("Local")
  630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  631. if err != nil {
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. recordDateTime := theTime.Unix()
  636. adminUser := c.GetAdminUserInfo()
  637. var prescriptions []*models.HisPrescription
  638. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  639. //if settle_accounts_type == 1 { //日结
  640. //
  641. //} else { //月结
  642. // start_time := c.GetString("start_time")
  643. // end_time := c.GetString("end_time")
  644. // timeLayout := "2006-01-02"
  645. // loc, _ := time.LoadLocation("Local")
  646. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  647. // if err != nil {
  648. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  649. // return
  650. // }
  651. // recordStartTime := theStartTime.Unix()
  652. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  653. // if err != nil {
  654. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  655. // return
  656. // }
  657. // recordEndTime := theEndTime.Unix()
  658. // monthPrescriptions, _ := service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  659. // var advices []*models.HisDoctorAdviceInfo
  660. // var projects []*models.HisPrescriptionProject
  661. // var additions []*models.HisAdditionalCharge
  662. // var customs []*models.Custom
  663. // for _, item := range monthPrescriptions {
  664. // advices = append(advices, item.HisDoctorAdviceInfo...)
  665. // projects = append(projects, item.HisPrescriptionProject...)
  666. // additions = append(additions, item.HisAdditionalCharge...)
  667. // }
  668. //
  669. // var adviceCodes []string
  670. // var projectCodes []string
  671. // var additionCodes []string
  672. //
  673. //
  674. //
  675. //
  676. // for _, item := range advices {
  677. // adviceCodes = append(adviceCodes, item.MedListCodg)
  678. // }
  679. // for _, item := range projects {
  680. // projectCodes = append(projectCodes, item.MedListCodg)
  681. // }
  682. // for _, item := range additions {
  683. // additionCodes = append(additionCodes, item.XtHisAddtionConfig.Code)
  684. // }
  685. // adviceCodes = RemoveRepeatedCode(adviceCodes)
  686. // projectCodes = RemoveRepeatedCode(projectCodes)
  687. // additionCodes = RemoveRepeatedCode(additionCodes)
  688. //
  689. // for _, item := range adviceCodes{
  690. // var custom models.Custom
  691. // for _,subItem := range advices{
  692. // if item == subItem.MedListCodg{
  693. //
  694. //
  695. //
  696. // }
  697. // }
  698. // }
  699. //
  700. //
  701. //
  702. //
  703. //
  704. //
  705. //
  706. //
  707. //
  708. //
  709. //
  710. //}
  711. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  712. timestamp := time.Now().Unix()
  713. tempTime := time.Unix(timestamp, 0)
  714. timeFormat := tempTime.Format("20060102150405")
  715. chrgBchno := rand.Intn(100000) + 10000
  716. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  717. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  718. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  719. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  720. strconv.FormatInt(his.PatientId, 10)
  721. client := &http.Client{}
  722. data := make(map[string]interface{})
  723. data["psn_no"] = his.PsnNo
  724. data["mdtrt_id"] = his.Number
  725. data["pre"] = prescriptions
  726. data["chrg_bchno"] = chrg_bchno
  727. data["org_name"] = miConfig.OrgName
  728. data["doctor"] = patientPrescription.Doctor
  729. data["doctor_id"] = strconv.FormatInt(patientPrescription.DoctorId, 10)
  730. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  731. data["fixmedins_code"] = miConfig.Code
  732. data["dept_code"] = department.Number
  733. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  734. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  735. data["secret_key"] = miConfig.SecretKey
  736. var ids []int64
  737. for _, item := range prescriptions {
  738. ids = append(ids, item.ID)
  739. }
  740. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  741. if config.IsOpen == 1 { //对接了医保,走医保流程
  742. bytesData, _ := json.Marshal(data)
  743. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  744. resp, _ := client.Do(req)
  745. defer resp.Body.Close()
  746. body, ioErr := ioutil.ReadAll(resp.Body)
  747. if ioErr != nil {
  748. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  750. return
  751. }
  752. var respJSON map[string]interface{}
  753. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  754. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  756. return
  757. }
  758. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  759. userJSONBytes, _ := json.Marshal(respJSON)
  760. var res ResultFour
  761. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  762. utils.ErrorLog("解析失败:%v", err)
  763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  764. return
  765. }
  766. if res.Infcode == 0 {
  767. order := &models.HisOrder{
  768. UserOrgId: adminUser.CurrentOrgId,
  769. HisPatientId: his.ID,
  770. PatientId: his.PatientId,
  771. SettleAccountsDate: recordDateTime,
  772. Ctime: time.Now().Unix(),
  773. Mtime: time.Now().Unix(),
  774. Status: 1,
  775. Number: chrg_bchno,
  776. Infcode: res.Infcode,
  777. WarnMsg: res.WarnMsg,
  778. Cainfo: res.Cainfo,
  779. ErrMsg: res.ErrMsg,
  780. RespondTime: res.RefmsgTime,
  781. InfRefmsgid: res.InfRefmsgid,
  782. OrderStatus: 1,
  783. PayWay: pay_way,
  784. PayPrice: pay_price,
  785. PayCardNo: pay_card_no,
  786. DiscountPrice: discount_price,
  787. PreferentialPrice: preferential_price,
  788. RealityPrice: reality_price,
  789. FoundPrice: found_price,
  790. MedicalInsurancePrice: medical_insurance_price,
  791. PrivatePrice: private_price,
  792. IsMedicineInsurance: 1,
  793. }
  794. err = service.CreateOrder(order)
  795. if err != nil {
  796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  797. return
  798. }
  799. for _, item := range res.Output.Result {
  800. temp := strings.Split(item.FeedetlSn, "-")
  801. var advice_id int64 = 0
  802. var project_id int64 = 0
  803. var types int64 = 0
  804. id, _ := strconv.ParseInt(temp[2], 10, 64)
  805. types, _ = strconv.ParseInt(temp[1], 10, 64)
  806. if temp[1] == "1" {
  807. advice_id = id
  808. project_id = 0
  809. } else if temp[1] == "2" {
  810. advice_id = 0
  811. project_id = id
  812. }
  813. info := &models.HisOrderInfo{
  814. OrderNumber: order.Number,
  815. FeedetlSn: item.FeedetlSn,
  816. UploadDate: time.Now().Unix(),
  817. AdviceId: advice_id,
  818. DetItemFeeSumamt: item.DetItemFeeSumamt,
  819. Cnt: item.Cnt,
  820. Pric: float64(item.Pric),
  821. PatientId: his.PatientId,
  822. PricUplmtAmt: item.PricUplmtAmt,
  823. SelfpayProp: item.SelfpayProp,
  824. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  825. OverlmtAmt: item.OverlmtAmt,
  826. PreselfpayAmt: item.PreselfpayAmt,
  827. BasMednFlag: item.BasMednFlag,
  828. MedChrgitmType: item.MedChrgitmType,
  829. HiNegoDrugFlag: item.HiNegoDrugFlag,
  830. Status: 1,
  831. Memo: item.Memo,
  832. Mtime: time.Now().Unix(),
  833. InscpScpAmt: item.InscpScpAmt,
  834. DrtReimFlag: item.DrtReimFlag,
  835. Ctime: time.Now().Unix(),
  836. ListSpItemFlag: item.ListSpItemFlag,
  837. ChldMedcFlag: item.ChldMedcFlag,
  838. LmtUsedFlag: item.LmtUsedFlag,
  839. ChrgitmLv: item.ChrgitmLv,
  840. UserOrgId: adminUser.CurrentOrgId,
  841. HisPatientId: his.ID,
  842. OrderId: order.ID,
  843. ProjectId: project_id,
  844. Type: types,
  845. }
  846. service.CreateOrderInfo(info)
  847. }
  848. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  849. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  850. var total float64
  851. for _, item := range prescriptions {
  852. if item.Type == 1 { //药品
  853. for _, subItem := range item.HisDoctorAdviceInfo {
  854. total = total + (subItem.Price * subItem.PrescribingNumber)
  855. }
  856. }
  857. if item.Type == 2 { //项目
  858. for _, subItem := range item.HisPrescriptionProject {
  859. total = total + (subItem.Price * float64(subItem.Count))
  860. }
  861. }
  862. }
  863. for _, item := range prescriptions {
  864. for _, subItem := range item.HisAdditionalCharge {
  865. total = total + (subItem.Price * float64(subItem.Count))
  866. }
  867. }
  868. allTotal := fmt.Sprintf("%.2f", total)
  869. if res.Infcode == 0 {
  870. var rf []*ResultFive
  871. json.Unmarshal([]byte(his.Iinfo), &rf)
  872. psn_no := his.PsnNo
  873. mdtrt_id := his.Number
  874. chrg_bchno := chrg_bchno
  875. cert_no := his.Certno
  876. insutype := rf[0].Insutype
  877. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  878. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  879. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  880. resp, requestErr := http.Get(api)
  881. if requestErr != nil {
  882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  883. return
  884. }
  885. defer resp.Body.Close()
  886. body, ioErr := ioutil.ReadAll(resp.Body)
  887. if ioErr != nil {
  888. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  890. return
  891. }
  892. var respJSON map[string]interface{}
  893. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  894. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  896. return
  897. }
  898. fmt.Println(respJSON)
  899. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  900. userJSONBytes, _ := json.Marshal(respJSON)
  901. var res ResultSeven
  902. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  903. utils.ErrorLog("解析失败:%v", err)
  904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  905. return
  906. }
  907. if res.Infcode == -1 {
  908. errlog := &models.HisOrderError{
  909. UserOrgId: adminUser.CurrentOrgId,
  910. Ctime: time.Now().Unix(),
  911. Mtime: time.Now().Unix(),
  912. Number: chrg_bchno,
  913. ErrMsg: res.ErrMsg,
  914. Status: 1,
  915. PatientId: id,
  916. RecordTime: recordDateTime,
  917. Stage: 6,
  918. }
  919. service.CreateErrMsgLog(errlog)
  920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  921. return
  922. } else {
  923. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  924. order.OrderStatus = 2
  925. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  926. order.SetlId = res.Output.Setlinfo.SetlID
  927. order.PsnNo = res.Output.Setlinfo.PsnNo
  928. order.PsnName = res.Output.Setlinfo.PsnName
  929. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  930. order.Certno = res.Output.Setlinfo.Certno
  931. order.Gend = res.Output.Setlinfo.Gend
  932. order.Naty = res.Output.Setlinfo.Naty
  933. order.Age = res.Output.Setlinfo.Age
  934. order.Insutype = res.Output.Setlinfo.Insutype
  935. order.PsnType = res.Output.Setlinfo.PsnType
  936. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  937. order.SetlTime = res.Output.Setlinfo.SetlTime
  938. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  939. order.MedType = res.Output.Setlinfo.MedType
  940. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  941. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  942. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  943. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  944. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  945. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  946. order.HifpPay = res.Output.Setlinfo.HifpPay
  947. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  948. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  949. order.HifesPay = res.Output.Setlinfo.HifesPay
  950. order.HifobPay = res.Output.Setlinfo.HifobPay
  951. order.MafPay = res.Output.Setlinfo.MafPay
  952. order.OthPay = res.Output.Setlinfo.OthPay
  953. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  954. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  955. order.AcctPay = res.Output.Setlinfo.AcctPay
  956. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  957. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  958. order.Balc = res.Output.Setlinfo.Balc
  959. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  960. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  961. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  962. order.ClrWay = res.Output.Setlinfo.ClrWay
  963. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  964. detailStr := string(setlDetail)
  965. order.SetlDetail = detailStr
  966. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  967. err = service.UpDateOrder(order)
  968. if err == nil {
  969. c.ServeSuccessJSON(map[string]interface{}{
  970. "msg": "结算成功",
  971. })
  972. } else {
  973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  974. return
  975. }
  976. }
  977. } else {
  978. adminUser := c.GetAdminUserInfo()
  979. errlog := &models.HisOrderError{
  980. UserOrgId: adminUser.CurrentOrgId,
  981. Ctime: time.Now().Unix(),
  982. Mtime: time.Now().Unix(),
  983. ErrMsg: res.ErrMsg,
  984. Status: 1,
  985. PatientId: id,
  986. RecordTime: recordDateTime,
  987. Stage: 4,
  988. }
  989. service.CreateErrMsgLog(errlog)
  990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  991. return
  992. }
  993. } else {
  994. adminUser := c.GetAdminUserInfo()
  995. errlog := &models.HisOrderError{
  996. UserOrgId: adminUser.CurrentOrgId,
  997. Ctime: time.Now().Unix(),
  998. Mtime: time.Now().Unix(),
  999. ErrMsg: res.ErrMsg,
  1000. Status: 1,
  1001. PatientId: id,
  1002. RecordTime: recordDateTime,
  1003. Stage: 4,
  1004. }
  1005. service.CreateErrMsgLog(errlog)
  1006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1007. return
  1008. }
  1009. } else {
  1010. var total float64
  1011. for _, item := range prescriptions {
  1012. if item.Type == 1 { //药品
  1013. for _, subItem := range item.HisDoctorAdviceInfo {
  1014. total = total + (subItem.Price * subItem.PrescribingNumber)
  1015. }
  1016. }
  1017. if item.Type == 2 { //项目
  1018. for _, subItem := range item.HisPrescriptionProject {
  1019. total = total + (subItem.Price * float64(subItem.Count))
  1020. }
  1021. }
  1022. for _, subItem := range item.HisAdditionalCharge {
  1023. total = total + (subItem.Price * float64(subItem.Count))
  1024. }
  1025. }
  1026. allTotal := fmt.Sprintf("%.2f", total)
  1027. totals, _ := strconv.ParseFloat(allTotal, 64)
  1028. order := &models.HisOrder{
  1029. UserOrgId: adminUser.CurrentOrgId,
  1030. HisPatientId: his.ID,
  1031. PatientId: id,
  1032. SettleAccountsDate: recordDateTime,
  1033. Ctime: time.Now().Unix(),
  1034. Mtime: time.Now().Unix(),
  1035. Status: 1,
  1036. OrderStatus: 2,
  1037. Number: chrg_bchno,
  1038. MedfeeSumamt: totals,
  1039. PayWay: pay_way,
  1040. PayPrice: pay_price,
  1041. PayCardNo: pay_card_no,
  1042. DiscountPrice: discount_price,
  1043. PreferentialPrice: preferential_price,
  1044. RealityPrice: reality_price,
  1045. FoundPrice: found_price,
  1046. MedicalInsurancePrice: medical_insurance_price,
  1047. PrivatePrice: private_price,
  1048. }
  1049. err = service.CreateOrder(order)
  1050. if err != nil {
  1051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1052. return
  1053. }
  1054. var customs []*Custom
  1055. for _, item := range prescriptions {
  1056. if item.Type == 1 { //药品
  1057. for _, subItem := range item.HisDoctorAdviceInfo {
  1058. cus := &Custom{
  1059. AdviceId: subItem.ID,
  1060. ProjectId: 0,
  1061. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1062. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1063. FeedetlSn: subItem.FeedetlSn,
  1064. Price: fmt.Sprintf("%.2f", subItem.Price),
  1065. MedListCodg: subItem.MedListCodg,
  1066. Type: 1,
  1067. }
  1068. customs = append(customs, cus)
  1069. }
  1070. }
  1071. if item.Type == 2 { //项目
  1072. for _, subItem := range item.HisPrescriptionProject {
  1073. cus := &Custom{
  1074. AdviceId: 0,
  1075. ProjectId: subItem.ID,
  1076. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1077. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1078. FeedetlSn: subItem.FeedetlSn,
  1079. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1080. MedListCodg: subItem.MedListCodg,
  1081. Type: 2,
  1082. }
  1083. customs = append(customs, cus)
  1084. }
  1085. }
  1086. for _, item := range item.HisAdditionalCharge {
  1087. cus := &Custom{
  1088. ItemId: item.ID,
  1089. AdviceId: 0,
  1090. ProjectId: 0,
  1091. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1092. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1093. FeedetlSn: item.FeedetlSn,
  1094. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1095. MedListCodg: item.XtHisAddtionConfig.Code,
  1096. Type: 3,
  1097. }
  1098. customs = append(customs, cus)
  1099. }
  1100. }
  1101. for _, item := range customs {
  1102. var advice_id int64 = 0
  1103. var project_id int64 = 0
  1104. var item_id int64 = 0
  1105. var types int64 = 0
  1106. if item.Type == 1 {
  1107. advice_id = item.AdviceId
  1108. project_id = 0
  1109. item_id = 0
  1110. } else if item.Type == 2 {
  1111. advice_id = 0
  1112. item_id = 0
  1113. project_id = item.ProjectId
  1114. } else if item.Type == 3 {
  1115. advice_id = 0
  1116. item_id = item.ItemId
  1117. project_id = 0
  1118. }
  1119. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1120. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1121. pric, _ := strconv.ParseFloat(item.Price, 32)
  1122. info := &models.HisOrderInfo{
  1123. OrderNumber: order.Number,
  1124. UploadDate: time.Now().Unix(),
  1125. AdviceId: advice_id,
  1126. DetItemFeeSumamt: detItemFeeSumamt,
  1127. Cnt: cut,
  1128. Pric: pric,
  1129. PatientId: id,
  1130. Status: 1,
  1131. Mtime: time.Now().Unix(),
  1132. Ctime: time.Now().Unix(),
  1133. UserOrgId: adminUser.CurrentOrgId,
  1134. HisPatientId: his.ID,
  1135. OrderId: order.ID,
  1136. ProjectId: project_id,
  1137. Type: types,
  1138. ItemId: item_id,
  1139. }
  1140. service.CreateOrderInfo(info)
  1141. }
  1142. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1143. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1144. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1145. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1146. if err == nil {
  1147. c.ServeSuccessJSON(map[string]interface{}{
  1148. "msg": "结算成功",
  1149. })
  1150. } else {
  1151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1152. return
  1153. }
  1154. }
  1155. }
  1156. //退款
  1157. func (c *HisApiController) Refund() {
  1158. order_id, _ := c.GetInt64("order_id")
  1159. number := c.GetString("number")
  1160. record_time := c.GetString("record_time")
  1161. patient_id, _ := c.GetInt64("patient_id")
  1162. timeLayout := "2006-01-02"
  1163. loc, _ := time.LoadLocation("Local")
  1164. adminUser := c.GetAdminUserInfo()
  1165. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1166. fmt.Println(err)
  1167. if err != nil {
  1168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1169. return
  1170. }
  1171. recordDateTime := theTime.Unix()
  1172. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1173. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1174. order, _ := service.GetHisOrderByID(order_id)
  1175. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1176. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1177. if config.IsOpen == 1 { //对接了医保,走医保流程
  1178. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  1179. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1180. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1181. resp, requestErr := http.Get(api)
  1182. if requestErr != nil {
  1183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1184. return
  1185. }
  1186. body, ioErr := ioutil.ReadAll(resp.Body)
  1187. if ioErr != nil {
  1188. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1190. return
  1191. }
  1192. var respJSON map[string]interface{}
  1193. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1194. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1196. return
  1197. }
  1198. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1199. userJSONBytes, _ := json.Marshal(respJSON)
  1200. fmt.Println(respJSON)
  1201. fmt.Println(userJSONBytes)
  1202. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1203. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1204. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1205. resp2, requestErr2 := http.Get(api2)
  1206. if requestErr2 != nil {
  1207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1208. return
  1209. }
  1210. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1211. if ioErr2 != nil {
  1212. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1214. return
  1215. }
  1216. var respJSON2 map[string]interface{}
  1217. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1218. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1220. return
  1221. }
  1222. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1223. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1224. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1225. resp3, requestErr3 := http.Get(api3)
  1226. if requestErr3 != nil {
  1227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1228. return
  1229. }
  1230. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1231. if ioErr3 != nil {
  1232. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1234. return
  1235. }
  1236. var respJSON3 map[string]interface{}
  1237. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1238. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1240. return
  1241. }
  1242. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1243. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1244. if err == nil {
  1245. c.ServeSuccessJSON(map[string]interface{}{
  1246. "msg": "退费成功",
  1247. })
  1248. } else {
  1249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1250. return
  1251. }
  1252. } else {
  1253. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1254. if err == nil {
  1255. c.ServeSuccessJSON(map[string]interface{}{
  1256. "msg": "退费成功",
  1257. })
  1258. } else {
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1260. return
  1261. }
  1262. }
  1263. }
  1264. func (c *HisApiController) RefundNumber() {
  1265. record_time := c.GetString("record_time")
  1266. patient_id, _ := c.GetInt64("patient_id")
  1267. timeLayout := "2006-01-02"
  1268. loc, _ := time.LoadLocation("Local")
  1269. adminUser := c.GetAdminUserInfo()
  1270. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1271. fmt.Println(err)
  1272. if err != nil {
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1274. return
  1275. }
  1276. recordDateTime := theTime.Unix()
  1277. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1278. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1279. //order, _ := service.GetHisOrderByID(order_id)
  1280. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1281. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1282. if config.IsOpen == 1 { //对接了医保,走医保流程
  1283. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1284. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1285. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1286. resp3, requestErr3 := http.Get(api3)
  1287. if requestErr3 != nil {
  1288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1289. return
  1290. }
  1291. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1292. if ioErr3 != nil {
  1293. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1295. return
  1296. }
  1297. var respJSON3 map[string]interface{}
  1298. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1299. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1301. return
  1302. }
  1303. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1304. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1305. if err == nil {
  1306. c.ServeSuccessJSON(map[string]interface{}{
  1307. "msg": "退费成功",
  1308. })
  1309. } else {
  1310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1311. return
  1312. }
  1313. } else {
  1314. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1315. //if err == nil {
  1316. // c.ServeSuccessJSON(map[string]interface{}{
  1317. // "msg": "退费成功",
  1318. // })
  1319. //} else {
  1320. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1321. // return
  1322. //}
  1323. }
  1324. }
  1325. //对账
  1326. func (c *HisApiController) GetCheckAccount() {
  1327. start_time := c.GetString("start_time")
  1328. end_time := c.GetString("end_time")
  1329. insutype := c.GetString("insutype")
  1330. clr_type := c.GetString("clr_type")
  1331. adminUser := c.GetAdminUserInfo()
  1332. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1333. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1334. timeLayout := "2006-01-02"
  1335. loc, _ := time.LoadLocation("Local")
  1336. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1337. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1338. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  1339. decimal.DivisionPrecision = 2
  1340. var medfee_sumamt float64
  1341. var acct_pay float64
  1342. var fund_pay_sumamt float64
  1343. fixmedins_setl_cnt := int64(len(orders))
  1344. for _, item := range orders {
  1345. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1346. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  1347. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1348. }
  1349. var user_name string
  1350. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1351. if role.ID == 0 {
  1352. user_name = "xxx"
  1353. } else {
  1354. user_name = role.UserName
  1355. }
  1356. if config.IsOpen == 1 {
  1357. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  1358. "insutype=" + insutype +
  1359. "&clr_type=" + clr_type +
  1360. "&setl_optins=" + miConfig.OrgName +
  1361. "&stmt_begndate=" + start_time +
  1362. "&stm_enddate=" + end_time +
  1363. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1364. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1365. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  1366. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1367. "&fixmedins_code=" + miConfig.Code +
  1368. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1369. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1370. "&secret_key=" + miConfig.SecretKey +
  1371. "&org_name=" + miConfig.OrgName +
  1372. "&doctor=" + user_name
  1373. fmt.Println(api)
  1374. resp, requestErr := http.Get(api)
  1375. if requestErr != nil {
  1376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1377. return
  1378. }
  1379. body, ioErr := ioutil.ReadAll(resp.Body)
  1380. fmt.Println(body)
  1381. if ioErr != nil {
  1382. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1384. return
  1385. }
  1386. var respJSON map[string]interface{}
  1387. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1388. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1390. return
  1391. }
  1392. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1393. userJSONBytes, _ := json.Marshal(respJSON)
  1394. var res ResultEight
  1395. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1396. utils.ErrorLog("解析失败:%v", err)
  1397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1398. return
  1399. }
  1400. if res.Infcode == 0 {
  1401. c.ServeSuccessJSON(map[string]interface{}{
  1402. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  1403. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  1404. })
  1405. } else {
  1406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1407. }
  1408. }
  1409. }
  1410. //对账明细
  1411. func (c *HisApiController) GetCheckDetailAccount() {
  1412. start_time := c.GetString("start_time")
  1413. end_time := c.GetString("end_time")
  1414. adminUser := c.GetAdminUserInfo()
  1415. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1416. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1417. timeLayout := "2006-01-02"
  1418. loc, _ := time.LoadLocation("Local")
  1419. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1420. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1421. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  1422. Mkdir(miConfig.OrgName)
  1423. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  1424. file_name := file + ".txt"
  1425. zip_name := file + ".zip"
  1426. zip_path := miConfig.OrgName + "/" + zip_name
  1427. file_path := miConfig.OrgName + "/" + file_name
  1428. decimal.DivisionPrecision = 2
  1429. var medfee_sumamt float64
  1430. var psn_cash_pay float64
  1431. var fund_pay_sumamt float64
  1432. fixmedins_setl_cnt := int64(len(orders))
  1433. for _, item := range orders {
  1434. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1435. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  1436. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1437. }
  1438. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  1439. defer f.Close()
  1440. if err != nil {
  1441. fmt.Println(err.Error())
  1442. } else {
  1443. for _, item := range orders {
  1444. var refd_setl_flag string
  1445. if item.OrderStatus == 2 {
  1446. refd_setl_flag = "0"
  1447. }
  1448. if item.OrderStatus == 3 {
  1449. refd_setl_flag = "1"
  1450. }
  1451. var str string
  1452. str = item.SetlId + " " +
  1453. item.MdtrtId + " " +
  1454. item.PsnNo + " " +
  1455. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  1456. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  1457. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  1458. _, err = f.Write([]byte(str))
  1459. }
  1460. }
  1461. Zip(file_path, zip_path)
  1462. fmt.Println(ReadFile(zip_path))
  1463. fmt.Println(string(ReadFile(zip_path)))
  1464. if config.IsOpen == 1 {
  1465. var user_name string
  1466. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1467. if role.ID == 0 {
  1468. user_name = "xxx"
  1469. } else {
  1470. user_name = role.UserName
  1471. }
  1472. baseParams := models.BaseParams{
  1473. SecretKey: miConfig.SecretKey,
  1474. FixmedinsCode: miConfig.Code,
  1475. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1476. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1477. OrgName: miConfig.OrgName,
  1478. Doctor: user_name,
  1479. }
  1480. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  1481. var dat map[string]interface{}
  1482. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1483. fmt.Println(dat)
  1484. } else {
  1485. fmt.Println(err)
  1486. }
  1487. userJSONBytes, _ := json.Marshal(dat)
  1488. var res ResultNine
  1489. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1490. utils.ErrorLog("解析失败:%v", err)
  1491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1492. return
  1493. }
  1494. if res.Infcode == 0 {
  1495. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  1496. "file_qury_no=" + res.Output.FileQuryNo +
  1497. "&setl_optins=" + miConfig.OrgName +
  1498. "&stmt_begndate=" + start_time +
  1499. "&stm_enddate=" + end_time +
  1500. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1501. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1502. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  1503. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1504. "&fixmedins_code=" + miConfig.Code +
  1505. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1506. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1507. "&secret_key=" + miConfig.SecretKey +
  1508. "&org_name=" + miConfig.OrgName +
  1509. "&doctor=" + user_name
  1510. resp, requestErr := http.Get(api)
  1511. if requestErr != nil {
  1512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1513. return
  1514. }
  1515. body, ioErr := ioutil.ReadAll(resp.Body)
  1516. if ioErr != nil {
  1517. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1519. return
  1520. }
  1521. var respJSON map[string]interface{}
  1522. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1523. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1525. return
  1526. }
  1527. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1528. userJSONBytes, _ := json.Marshal(respJSON)
  1529. var res ResultTen
  1530. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1531. utils.ErrorLog("解析失败:%v", err)
  1532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1533. return
  1534. }
  1535. if res.Infcode == 0 {
  1536. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  1537. c.ServeSuccessJSON(map[string]interface{}{
  1538. "msg": "明细对账成功",
  1539. })
  1540. }
  1541. } else {
  1542. }
  1543. }
  1544. }
  1545. func (c *HisApiController) GetSettleAccounts() {
  1546. //id, _ := c.GetInt64("id")
  1547. //record_time := c.GetString("record_time")
  1548. order_id, _ := c.GetInt64("order_id")
  1549. //timeLayout := "2006-01-02"
  1550. //loc, _ := time.LoadLocation("Local")
  1551. //
  1552. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1553. //if err != nil {
  1554. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1555. // return
  1556. //}
  1557. //recordDateTime := theTime.Unix()
  1558. adminUser := c.GetAdminUserInfo()
  1559. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1560. order, _ := service.GetHisOrderByID(order_id)
  1561. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  1562. var bedCostTotal float64 = 0 //床位总费
  1563. var bedCostSelfTotal float64 = 0 //床位自费
  1564. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  1565. var operationCostTotal float64 = 0 //手术费
  1566. var operationCostSelfTotal float64 = 0 //手术费
  1567. var operationCostPartSelfTotal float64 = 0 //手术费
  1568. var otherCostTotal float64 = 0 //其他费用
  1569. var otherCostSelfTotal float64 = 0 //其他费用
  1570. var otherCostPartSelfTotal float64 = 0 //其他费用
  1571. var materialCostTotal float64 = 0 //材料费
  1572. var materialCostSelfTotal float64 = 0 //材料费
  1573. var materialCostPartSelfTotal float64 = 0 //材料费
  1574. var westernMedicineCostTotal float64 = 0 //西药费
  1575. var westernMedicineCostSelfTotal float64 = 0 //西药费
  1576. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  1577. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  1578. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  1579. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  1580. var checkCostTotal float64 = 0 //检查费
  1581. var checkCostSelfTotal float64 = 0 //检查费
  1582. var checkCostPartSelfTotal float64 = 0 //检查费
  1583. var laboratoryCostTotal float64 = 0 //化验费
  1584. var laboratoryCostSelfTotal float64 = 0 //化验费
  1585. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  1586. var treatCostTotal float64 = 0 //治疗费用
  1587. var treatCostSelfTotal float64 = 0 //治疗费用
  1588. var treatCostPartSelfTotal float64 = 0 //治疗费用
  1589. decimal.DivisionPrecision = 2
  1590. for _, item := range orderInfos {
  1591. if item.MedChrgitmType == "01" { //床位费
  1592. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1593. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1594. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1595. }
  1596. if item.MedChrgitmType == "03" { //检查费
  1597. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1598. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1599. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1600. }
  1601. if item.MedChrgitmType == "04" { //化验费
  1602. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1603. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1604. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1605. }
  1606. if item.MedChrgitmType == "05" { //治疗费
  1607. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1608. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1609. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1610. }
  1611. if item.MedChrgitmType == "06" { //手术费
  1612. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1613. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1614. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1615. }
  1616. if item.MedChrgitmType == "08" { //材料费
  1617. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1618. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1619. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1620. }
  1621. if item.MedChrgitmType == "09" { //西药费
  1622. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1623. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1624. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1625. }
  1626. if item.MedChrgitmType == "11" { //中成费
  1627. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1628. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1629. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1630. }
  1631. if item.MedChrgitmType == "14" { //其他费
  1632. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1633. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1634. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1635. }
  1636. }
  1637. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1638. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1639. var user_name string
  1640. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1641. if role.ID == 0 {
  1642. user_name = "xxx"
  1643. } else {
  1644. user_name = role.UserName
  1645. }
  1646. baseParams := models.BaseParams{
  1647. SecretKey: miConfig.SecretKey,
  1648. FixmedinsCode: miConfig.Code,
  1649. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1650. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1651. OrgName: miConfig.OrgName,
  1652. Doctor: user_name,
  1653. }
  1654. businessParams := models.BusinessParams{
  1655. PsnNo: order.PsnNo,
  1656. MdtrtId: order.MdtrtId,
  1657. SetlId: order.SetlId,
  1658. }
  1659. if config.IsOpen == 1 {
  1660. result := service.Gdyb5203(baseParams, businessParams)
  1661. var dat map[string]interface{}
  1662. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1663. fmt.Println(dat)
  1664. } else {
  1665. fmt.Println(err)
  1666. }
  1667. userJSONBytes, _ := json.Marshal(dat)
  1668. var res ResultEleven
  1669. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1670. utils.ErrorLog("解析失败:%v", err)
  1671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1672. return
  1673. }
  1674. if res.Infcode == 0 {
  1675. c.ServeSuccessJSON(map[string]interface{}{
  1676. "info": res.Output.Setlinfo,
  1677. "bedCostTotal": bedCostTotal,
  1678. "bedCostSelfTotal": bedCostSelfTotal,
  1679. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1680. "operationCostTotal": operationCostTotal,
  1681. "operationCostSelfTotal": operationCostSelfTotal,
  1682. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1683. "otherCostTotal": otherCostTotal,
  1684. "otherCostSelfTotal": otherCostSelfTotal,
  1685. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1686. "materialCostTotal": materialCostTotal,
  1687. "materialCostSelfTotal": materialCostSelfTotal,
  1688. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1689. "westernMedicineCostTotal": westernMedicineCostTotal,
  1690. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1691. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1692. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1693. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1694. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1695. "checkCostTotal": checkCostTotal,
  1696. "checkCostSelfTotal": checkCostSelfTotal,
  1697. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1698. "laboratoryCostTotal": laboratoryCostTotal,
  1699. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1700. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1701. "treatCostTotal": treatCostTotal,
  1702. "treatCostSelfTotal": treatCostSelfTotal,
  1703. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1704. })
  1705. }
  1706. }
  1707. }
  1708. func PathExists(path string) (bool, error) {
  1709. _, err := os.Stat(path)
  1710. if err == nil {
  1711. return true, nil
  1712. }
  1713. if os.IsNotExist(err) {
  1714. return false, nil
  1715. }
  1716. return false, err
  1717. }
  1718. //创建文件夹
  1719. func Mkdir(dir string) {
  1720. // 创建文件夹
  1721. exist, err := PathExists(dir)
  1722. if err != nil {
  1723. fmt.Println(err.Error())
  1724. } else {
  1725. if exist {
  1726. fmt.Println(dir + "文件夹已存在!")
  1727. } else {
  1728. // 文件夹名称,权限
  1729. err := os.Mkdir(dir, os.ModePerm)
  1730. if err != nil {
  1731. fmt.Println(dir+"文件夹创建失败:", err.Error())
  1732. } else {
  1733. fmt.Println(dir + "文件夹创建成功!")
  1734. }
  1735. }
  1736. }
  1737. }
  1738. //压缩文件
  1739. func Zip(srcFile string, destZip string) error {
  1740. zipfile, err := os.Create(destZip)
  1741. if err != nil {
  1742. return err
  1743. }
  1744. defer zipfile.Close()
  1745. archive := zip.NewWriter(zipfile)
  1746. defer archive.Close()
  1747. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  1748. if err != nil {
  1749. return err
  1750. }
  1751. header, err := zip.FileInfoHeader(info)
  1752. if err != nil {
  1753. return err
  1754. }
  1755. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  1756. // header.Name = path
  1757. if info.IsDir() {
  1758. header.Name += "/"
  1759. } else {
  1760. header.Method = zip.Deflate
  1761. }
  1762. writer, err := archive.CreateHeader(header)
  1763. if err != nil {
  1764. return err
  1765. }
  1766. if !info.IsDir() {
  1767. file, err := os.Open(path)
  1768. if err != nil {
  1769. return err
  1770. }
  1771. defer file.Close()
  1772. _, err = io.Copy(writer, file)
  1773. }
  1774. return err
  1775. })
  1776. return err
  1777. }
  1778. func ReadFile(filePath string) []byte {
  1779. f, err := os.Open(filePath)
  1780. if err != nil {
  1781. fmt.Println("read file fail", err)
  1782. return nil
  1783. }
  1784. defer f.Close()
  1785. fd, err := ioutil.ReadAll(f)
  1786. if err != nil {
  1787. fmt.Println("read to fd fail", err)
  1788. return nil
  1789. }
  1790. return fd
  1791. }
  1792. func RemoveRepeatedCode(arr []string) (newArr []string) {
  1793. newArr = make([]string, 0)
  1794. for i := 0; i < len(arr); i++ {
  1795. repeat := false
  1796. for j := i + 1; j < len(arr); j++ {
  1797. if arr[i] == arr[j] {
  1798. repeat = true
  1799. break
  1800. }
  1801. }
  1802. if !repeat {
  1803. newArr = append(newArr, arr[i])
  1804. }
  1805. }
  1806. return
  1807. }