his_api_controller.go 86KB

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