coordinate_controller.go 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "io/ioutil"
  11. "math/rand"
  12. "os"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type CoordinateController struct {
  18. BaseAPIController
  19. }
  20. type ResultReg struct {
  21. ResultCode string `json:"resultCode"`
  22. ResultDesc string `json:"resultDesc"`
  23. InfoSeq string `json:"infoSeq"`
  24. }
  25. type ResultSettle struct {
  26. ResultCode string `json:"resultCode"`
  27. ResultDesc string `json:"resultDesc"`
  28. }
  29. type ResultCancelSettle struct {
  30. ResultCode string `json:"resultCode"`
  31. ResultDesc string `json:"resultDesc"`
  32. }
  33. type Settle struct {
  34. PatientId string `json:"resultCode"`
  35. DocId string `json:"docId"`
  36. InfoSeq string `json:"infoSeq"`
  37. }
  38. type Refund struct {
  39. PatientId string `json:"resultCode"`
  40. DocId string `json:"docId"`
  41. InfoSeq string `json:"infoSeq"`
  42. }
  43. type RefundDetail struct {
  44. Msg string `json:"msg"`
  45. Result []struct {
  46. ResultMsg string `json:"resultMsg"`
  47. Code string `json:"code"`
  48. Records int `json:"records"`
  49. TotalPage int `json:"totalPage"`
  50. List []struct {
  51. Zae01 int64 `json:"ZAE01"`
  52. } `json:"list"`
  53. RecordsTotal int `json:"recordsTotal"`
  54. Pagenumber int `json:"pagenumber"`
  55. Result string `json:"result"`
  56. Total int `json:"total"`
  57. RecordsFtered int `json:"recordsFtered"`
  58. Page int `json:"page"`
  59. } `json:"result"`
  60. Code string `json:"code"`
  61. }
  62. func CoordinateRcegistRouters() {
  63. beego.Router("/coordinate/check", &CoordinateController{}, "get:SavePatientMessageInfo")
  64. //坐标挂号
  65. beego.Router("/coordinate/register", &CoordinateController{}, "get:Register")
  66. //坐标记账
  67. beego.Router("/coordinate/opKeepAccounts", &CoordinateController{}, "get:OpKeepAccounts")
  68. //坐标撤销记账
  69. beego.Router("/coordinate/opCancelKeepAccounts", &CoordinateController{}, "get:OpCancelKeepAccounts")
  70. //坐标结算回调
  71. beego.Router("/coordinate/settle", &CoordinateController{}, "post:Settle")
  72. //坐标退费回调
  73. beego.Router("/coordinate/refund", &CoordinateController{}, "post:Refund")
  74. }
  75. func (c *CoordinateController) Settle() {
  76. //参数1 patient_id
  77. //参数2 就诊号
  78. //参数3 单据id
  79. fmt.Println(c.Ctx.Request.Body)
  80. body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
  81. fmt.Println(string(body))
  82. var respJSON map[string]interface{}
  83. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  84. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  85. return
  86. }
  87. patien_id := respJSON["patientid"].(string)
  88. infoSeq := respJSON["infoseq"].(string)
  89. docId := respJSON["docid"].(string)
  90. fmt.Println(patien_id)
  91. fmt.Println(infoSeq)
  92. fmt.Println(docId)
  93. order, _ := service.GetHisOrderFour(patien_id, infoSeq, "")
  94. order.SetlId = docId
  95. if order.ID == 0 {
  96. json := make(map[string]interface{})
  97. json["msg"] = "结算记录不存在,请检查参数是否正确"
  98. json["code"] = "-1"
  99. c.Data["json"] = json
  100. c.ServeJSON()
  101. return
  102. }
  103. order.OrderStatus = 2
  104. service.UpDateOrder(order)
  105. service.UpdataOrderStatusTwo(order.Number, order.UserOrgId)
  106. json := make(map[string]interface{})
  107. json["msg"] = "结算成功"
  108. json["code"] = "0"
  109. c.Data["json"] = json
  110. c.ServeJSON()
  111. return
  112. }
  113. func (c *CoordinateController) Refund() {
  114. //参数1 patient_id
  115. //参数2 就诊号
  116. //参数3 单据id
  117. body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
  118. var respJSON map[string]interface{}
  119. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  120. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  121. return
  122. }
  123. patien_id := respJSON["patientid"].(string)
  124. infoSeq := respJSON["infoseq"].(string)
  125. docId := respJSON["docid"].(string)
  126. order, _ := service.GetHisOrderFour(patien_id, infoSeq, docId)
  127. if order.ID == 0 {
  128. json := make(map[string]interface{})
  129. json["msg"] = "结算记录不存在,请检查参数是否正确"
  130. json["code"] = "-1"
  131. c.Data["json"] = json
  132. c.ServeJSON()
  133. return
  134. }
  135. service.UpdataOrderStatus(order.ID, order.Number, order.UserOrgId)
  136. json := make(map[string]interface{})
  137. json["msg"] = "退费成功"
  138. json["code"] = "0"
  139. c.Data["json"] = json
  140. c.ServeJSON()
  141. return
  142. }
  143. func (c *CoordinateController) SavePatientMessageInfo() {
  144. result, request_log := service.SavePatientMessageInfo()
  145. fmt.Println(result)
  146. fmt.Println(request_log)
  147. }
  148. func (c *CoordinateController) Register() {
  149. patient_id, _ := c.GetInt64("patient_id")
  150. diagnosis_time := c.GetString("diagnosis_time")
  151. record_date := c.GetString("record_date")
  152. admin_user_id, _ := c.GetInt64("admin_user_id")
  153. org_id, _ := c.GetInt64("org_id")
  154. patient, _ := service.GetPatientByID(org_id, patient_id)
  155. org, _ := service.GetOrgById(org_id)
  156. timeLayout := "2006-01-02"
  157. loc, _ := time.LoadLocation("Local")
  158. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  159. if err != nil {
  160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  161. return
  162. }
  163. if len(patient.ZbPatientId) == 0 {
  164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnNoEmpty)
  165. return
  166. }
  167. recordDateTime := theTime.Unix()
  168. patientPrescription, _ := service.FindPatientPrescriptionInfoTwo(org_id, patient.ID, recordDateTime, 2)
  169. if patientPrescription.ID == 0 {
  170. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(org_id, patient.ID, recordDateTime)
  171. }
  172. doctor_info, _ := service.GetAdminUserInfoByID(org_id, patientPrescription.DoctorId)
  173. admin_user_info, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
  174. reg := models.Reg{
  175. DeptId: "0112",
  176. PatientId: patient.ZbPatientId,
  177. PatientName: patient.Name,
  178. DoctorId: doctor_info.DoctorNumber,
  179. RegDate: strings.Split(diagnosis_time, " ")[0],
  180. RegFee: "0",
  181. TreatFee: "0",
  182. OperatorId: admin_user_info.UserName,
  183. IdCardNo: patient.IdCardNo,
  184. }
  185. result, request_log := service.SaveReg(reg)
  186. fmt.Println(result)
  187. fmt.Println(request_log)
  188. saveLog(result, request_log, "登记", "登记", org.OrgName)
  189. var res ResultReg
  190. if err := json.Unmarshal([]byte(result), &res); err != nil {
  191. utils.ErrorLog("解析失败:%v", err)
  192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  193. return
  194. }
  195. if res.ResultCode == "0" {
  196. timestamp := time.Now().Unix()
  197. tempTime := time.Unix(timestamp, 0)
  198. timeFormat := tempTime.Format("20060102150405")
  199. chrgBchno := rand.Intn(100000) + 10000
  200. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
  201. his := models.VMHisPatient{
  202. Name: patient.Name,
  203. Gender: patient.Gender,
  204. Birthday: patient.Birthday,
  205. MedicalTreatmentType: 0,
  206. IdType: 1,
  207. IdCardNo: patient.IdCardNo,
  208. BalanceAccountsType: 1,
  209. MedicalInsuranceNumber: "",
  210. RegisterType: 0,
  211. RegisterCost: 0,
  212. TreatmentCost: 0,
  213. Status: 1,
  214. Ctime: time.Now().Unix(),
  215. Mtime: time.Now().Unix(),
  216. PsnNo: patient.ZbPatientId,
  217. PsnCertType: "",
  218. Certno: patient.IdCardNo,
  219. PsnName: patient.Name,
  220. Gend: "",
  221. Naty: "",
  222. Brdy: "",
  223. Age: 0,
  224. Iinfo: "",
  225. Idetinfo: "",
  226. PatientId: patient.ID,
  227. RecordDate: theTime.Unix(),
  228. UserOrgId: org_id,
  229. AdminUserId: admin_user_id,
  230. IsReturn: 1,
  231. Doctor: patientPrescription.DoctorId,
  232. Departments: patientPrescription.Departments,
  233. IptOtpNo: ipt_otp_no,
  234. Number: res.InfoSeq,
  235. PhoneNumber: patient.Phone,
  236. }
  237. service.UpdateHisPatientStatus(&his)
  238. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, org_id)
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "his_info": his,
  241. })
  242. } else {
  243. c.ServeSuccessJSON(map[string]interface{}{
  244. "failed_code": -10,
  245. "msg": res.ResultDesc,
  246. })
  247. }
  248. }
  249. //func (c *CoordinateController) GetWaitPayDetail() {
  250. // result, request_log := service.GetWaitPayDetail()
  251. // fmt.Println(result)
  252. // fmt.Println(request_log)
  253. //
  254. //}
  255. func (c *CoordinateController) OpKeepAccounts() {
  256. id, _ := c.GetInt64("id")
  257. record_time := c.GetString("record_time")
  258. his_patient_id, _ := c.GetInt64("his_patient_id")
  259. timeLayout := "2006-01-02"
  260. loc, _ := time.LoadLocation("Local")
  261. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  262. fapiao_code := c.GetString("fapiao_code")
  263. fapiao_number := c.GetString("fapiao_number")
  264. diagnosis_id := c.GetString("diagnosis")
  265. sick_type, _ := c.GetInt64("sick_type")
  266. reg_type, _ := c.GetInt64("p_type")
  267. org_id, _ := c.GetInt64("org_id")
  268. org, _ := service.GetOrgById(org_id)
  269. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  270. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  271. if err != nil {
  272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  273. return
  274. }
  275. recordDateTime := theTime.Unix()
  276. //adminUser := c.GetAdminUserInfo()
  277. var prescriptions []*models.HisPrescription
  278. var start_time int64
  279. var end_time int64
  280. //ids_str := c.GetString("ids")
  281. //ids_arr := strings.Split(ids_str, ",")
  282. if settle_accounts_type == 1 { //日结
  283. //fmt.Println(reg_type)
  284. prescriptions, _ = service.GetUnSettleHisPrescriptionFive(org_id, id, recordDateTime, 2)
  285. } else { //月结
  286. start_time_str := c.GetString("start_time")
  287. end_time_str := c.GetString("end_time")
  288. timeLayout := "2006-01-02"
  289. loc, _ := time.LoadLocation("Local")
  290. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  291. if err != nil {
  292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  293. return
  294. }
  295. recordStartTime := theStartTime.Unix()
  296. start_time = recordStartTime
  297. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  298. if err != nil {
  299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  300. return
  301. }
  302. recordEndTime := theEndTime.Unix()
  303. end_time = recordEndTime
  304. prescriptions, _ = service.GetUnSettleMonthHisPrescription(org_id, id, recordStartTime, recordEndTime)
  305. }
  306. timestamp := time.Now().Unix()
  307. tempTime := time.Unix(timestamp, 0)
  308. timeFormat := tempTime.Format("20060102150405")
  309. chrgBchno := rand.Intn(100000) + 10000
  310. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  311. strconv.FormatInt(his.PatientId, 10)
  312. var ids []int64
  313. for _, item := range prescriptions {
  314. ids = append(ids, item.ID)
  315. }
  316. var total float64
  317. for _, item := range prescriptions {
  318. fmt.Println(item)
  319. if item.Type == 1 { //药品
  320. for _, subItem := range item.HisDoctorAdviceInfo {
  321. total = total + (subItem.Price * subItem.PrescribingNumber)
  322. }
  323. }
  324. if item.Type == 2 { //项目
  325. for _, subItem := range item.HisPrescriptionProject {
  326. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  327. total = total + (subItem.Price * cnt)
  328. }
  329. }
  330. for _, subItem := range item.HisAdditionalCharge {
  331. total = total + (subItem.Price * float64(subItem.Count))
  332. }
  333. }
  334. tm := time.Unix(time.Now().Unix(), 0)
  335. var customs []*models.NewCustomTwo
  336. for _, item := range prescriptions {
  337. if item.Type == 1 { //药品
  338. for _, subItem := range item.HisDoctorAdviceInfo {
  339. cus := &models.NewCustomTwo{
  340. AdviceId: subItem.ID,
  341. ProjectId: 0,
  342. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  343. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  344. FeedetlSn: subItem.FeedetlSn,
  345. Price: fmt.Sprintf("%.2f", subItem.Price),
  346. MedListCodg: subItem.Drug.MedicalInsuranceNumber,
  347. Type: 1,
  348. }
  349. customs = append(customs, cus)
  350. }
  351. }
  352. if item.Type == 2 { //项目
  353. for _, subItem := range item.HisPrescriptionProject {
  354. if subItem.Type == 2 {
  355. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  356. cus := &models.NewCustomTwo{
  357. AdviceId: 0,
  358. ProjectId: subItem.ID,
  359. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  360. Cut: fmt.Sprintf("%.4f", cnt),
  361. FeedetlSn: subItem.FeedetlSn,
  362. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  363. MedListCodg: subItem.HisProject.MedicalCode,
  364. Type: 2,
  365. }
  366. customs = append(customs, cus)
  367. } else {
  368. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  369. cus := &models.NewCustomTwo{
  370. AdviceId: 0,
  371. ProjectId: subItem.ID,
  372. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  373. Cut: fmt.Sprintf("%.4f", cnt),
  374. FeedetlSn: subItem.FeedetlSn,
  375. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  376. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  377. Type: 3,
  378. }
  379. customs = append(customs, cus)
  380. }
  381. }
  382. }
  383. for _, item := range item.HisAdditionalCharge {
  384. cus := &models.NewCustomTwo{
  385. ItemId: item.ID,
  386. AdviceId: 0,
  387. ProjectId: 0,
  388. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  389. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  390. FeedetlSn: item.FeedetlSn,
  391. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  392. MedListCodg: item.XtHisAddtionConfig.Code,
  393. Type: 3,
  394. }
  395. customs = append(customs, cus)
  396. }
  397. }
  398. result, request_log := service.OpKeepAccounts(his.Number, customs)
  399. saveLog(result, request_log, "记账", "记账", org.OrgName)
  400. var res ResultSettle
  401. if err := json.Unmarshal([]byte(result), &res); err != nil {
  402. utils.ErrorLog("解析失败:%v", err)
  403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  404. return
  405. }
  406. if res.ResultCode == "0" {
  407. //totals, _ := strconv.ParseFloat(total, 64)
  408. order := &models.HisOrder{
  409. PsnNo: his.PsnNo,
  410. UserOrgId: org_id,
  411. HisPatientId: his.ID,
  412. PatientId: id,
  413. SettleAccountsDate: recordDateTime,
  414. Ctime: time.Now().Unix(),
  415. Mtime: time.Now().Unix(),
  416. Status: 1,
  417. OrderStatus: 1,
  418. MdtrtId: his.Number,
  419. Number: chrg_bchno,
  420. SetlId: "",
  421. MedfeeSumamt: total,
  422. MedType: strconv.Itoa(int(reg_type)),
  423. SettleEndTime: end_time,
  424. SettleStartTime: start_time,
  425. SettleType: settle_accounts_type,
  426. FaPiaoCode: fapiao_code,
  427. FaPiaoNumber: fapiao_number,
  428. Diagnosis: diagnosis_id,
  429. PType: 2,
  430. SetlTime: tm.Format("2006-01-02 15:04:05"),
  431. }
  432. err = service.CreateOrder(order)
  433. if err != nil {
  434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  435. return
  436. }
  437. for _, item := range customs {
  438. var advice_id int64 = 0
  439. var project_id int64 = 0
  440. var item_id int64 = 0
  441. var types int64 = 0
  442. if item.Type == 1 {
  443. advice_id = item.AdviceId
  444. project_id = 0
  445. item_id = 0
  446. } else if item.Type == 2 {
  447. advice_id = 0
  448. item_id = 0
  449. project_id = item.ProjectId
  450. } else if item.Type == 3 {
  451. advice_id = 0
  452. item_id = item.ItemId
  453. project_id = 0
  454. }
  455. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  456. cut, _ := strconv.ParseFloat(item.Cut, 32)
  457. pric, _ := strconv.ParseFloat(item.Price, 32)
  458. info := &models.HisOrderInfo{
  459. OrderNumber: order.Number,
  460. UploadDate: time.Now().Unix(),
  461. AdviceId: advice_id,
  462. DetItemFeeSumamt: detItemFeeSumamt,
  463. Cnt: cut,
  464. Pric: pric,
  465. PatientId: id,
  466. Status: 1,
  467. Mtime: time.Now().Unix(),
  468. Ctime: time.Now().Unix(),
  469. UserOrgId: org_id,
  470. HisPatientId: his.ID,
  471. OrderId: order.ID,
  472. ProjectId: project_id,
  473. Type: types,
  474. ItemId: item_id,
  475. }
  476. service.CreateOrderInfo(info)
  477. }
  478. his.Diagnosis = diagnosis_id
  479. his.SickType = sick_type
  480. his.RegisterType = reg_type
  481. his.MedicalTreatmentType = reg_type
  482. service.UpdataHisPateint(&his)
  483. err = service.UpDatePrescriptionNumber(org_id, ids, chrg_bchno)
  484. err = service.UpDateHisPrescriptionInfoNumber(org_id, id, chrg_bchno, recordDateTime, his_patient_id)
  485. err = service.UpdataOrderStatusThree(chrg_bchno, org_id)
  486. if err == nil {
  487. c.ServeSuccessJSON(map[string]interface{}{
  488. "msg": "记账成功",
  489. })
  490. }
  491. } else {
  492. c.ServeSuccessJSON(map[string]interface{}{
  493. "failed_code": -10,
  494. "msg": res.ResultDesc,
  495. })
  496. }
  497. }
  498. func (c *CoordinateController) OpCancelKeepAccounts() {
  499. order_id, _ := c.GetInt64("order_id")
  500. admin_user_id, _ := c.GetInt64("admin_user_id")
  501. org_id, _ := c.GetInt64("org_id")
  502. org, _ := service.GetOrgById(org_id)
  503. order, _ := service.GetHisOrderByID(order_id)
  504. if order.ID == 0 {
  505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  506. return
  507. }
  508. role, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
  509. result, request_log := service.OpCancelKeepAccounts(order.SetlId, role.UserName, role.DoctorNumber)
  510. saveLog(result, request_log, "撤销记账", "撤销记账", org.OrgName)
  511. var res RefundDetail
  512. if err := json.Unmarshal([]byte(result), &res); err != nil {
  513. utils.ErrorLog("解析失败:%v", err)
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  515. return
  516. }
  517. fmt.Println(result)
  518. fmt.Println(request_log)
  519. fmt.Println(res)
  520. flag := 0
  521. isSuccess := false
  522. for _, item := range res.Result {
  523. if item.Code == "200" {
  524. flag = flag + 1
  525. }
  526. }
  527. if len(res.Result) == flag {
  528. isSuccess = true
  529. }
  530. var errMsg string
  531. for _, item := range res.Result {
  532. errMsg = errMsg + "\n" + item.ResultMsg
  533. }
  534. if isSuccess {
  535. err := service.UpdataOrderStatus(order_id, order.Number, org_id)
  536. if err == nil {
  537. c.ServeSuccessJSON(map[string]interface{}{
  538. "msg": "撤销记账成功",
  539. })
  540. } else {
  541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  542. return
  543. }
  544. } else {
  545. c.ServeSuccessJSON(map[string]interface{}{
  546. "failed_code": -10,
  547. "msg": errMsg,
  548. })
  549. }
  550. }
  551. //func saveLog(result string, request string, infno string, desc string) {
  552. //
  553. // org_id, _ := beego.AppConfig.Int64("org_id")
  554. // miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  555. // dir := miConfig.OrgName + "日志"
  556. // utils.Mkdir(dir)
  557. // month := time.Unix(1557042972, 0).Format("1")
  558. // year := time.Now().Format("2006")
  559. // month = time.Now().Format("01")
  560. // day := time.Now().Format("02")
  561. // hour := time.Now().Format("15")
  562. // min := time.Now().Format("04")
  563. // sec := time.Now().Format("05")
  564. //
  565. // result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  566. //
  567. // file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  568. // file_name := file + ".txt"
  569. // file_path := miConfig.OrgName + "日志" + "/" + file_name
  570. // exist, _ := utils.PathExists(file_path)
  571. // if exist { //存在
  572. // fmt.Println("存在")
  573. // f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  574. // if err != nil {
  575. // fmt.Println("read fail")
  576. // }
  577. // content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  578. // n, _ := f.Seek(0, 2)
  579. // _, err = f.WriteAt([]byte(content), n)
  580. //
  581. // } else { //不存在
  582. // fmt.Println("文件不存在,创建文件")
  583. // f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  584. // defer f.Close()
  585. // if err != nil {
  586. // } else {
  587. // _, err = f.Write([]byte("记录日志"))
  588. // }
  589. // }
  590. //
  591. //}
  592. type Charset string
  593. const (
  594. UTF8 = Charset("UTF-8")
  595. GB18030 = Charset("GB18030")
  596. )
  597. func saveLog(result string, request string, infno string, desc string, org_name string) {
  598. //org_id, _ := beego.AppConfig.Int64("org_id")
  599. //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  600. dir := org_name + "日志"
  601. utils.Mkdir(dir)
  602. month := time.Unix(1557042972, 0).Format("1")
  603. year := time.Now().Format("2006")
  604. month = time.Now().Format("01")
  605. day := time.Now().Format("02")
  606. hour := time.Now().Format("15")
  607. min := time.Now().Format("04")
  608. sec := time.Now().Format("05")
  609. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  610. file := org_name + "_" + year + month + day + "_log"
  611. file_name := file + ".txt"
  612. file_path := org_name + "日志" + "/" + file_name
  613. exist, _ := utils.PathExists(file_path)
  614. if exist { //存在
  615. fmt.Println("存在")
  616. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  617. if err != nil {
  618. fmt.Println("read fail")
  619. }
  620. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  621. n, _ := f.Seek(0, 2)
  622. _, err = f.WriteAt([]byte(content), n)
  623. } else { //不存在
  624. fmt.Println("文件不存在,创建文件")
  625. f, err := os.Create(org_name + "日志" + "/" + file_name)
  626. defer f.Close()
  627. if err != nil {
  628. } else {
  629. _, err = f.Write([]byte("记录日志"))
  630. }
  631. }
  632. }