his_api_controller.go 86KB

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