pharmacy_controller.go 43KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  1. package controllers
  2. import (
  3. "fmt"
  4. "math"
  5. "strconv"
  6. "time"
  7. "XT_New/enums"
  8. "XT_New/models"
  9. "XT_New/service"
  10. "XT_New/utils"
  11. "github.com/astaxie/beego"
  12. )
  13. type PharmacyController struct {
  14. BaseAuthAPIController
  15. }
  16. func PharmacyApiRegistRouters() {
  17. beego.Router("/api/pharmacy/ceshili", &PharmacyController{}, "get:Tlili")
  18. beego.Router("/api/pharmacy/todaynumber", &PharmacyController{}, "get:TodayNumber") //查询今天的待发药,已发药人数(
  19. beego.Router("/api/pharmacy/waitingdrug", &PharmacyController{}, "get:WaitingDrug") //获取当天待发药的所有患者(
  20. beego.Router("/api/pharmacy/issueddrugs", &PharmacyController{}, "get:IssuedDrug") //获取当天已发药的所有患者(
  21. beego.Router("/api/pharmacy/getpharmacycontent", &PharmacyController{}, "get:GetPharmacyContent") //获取当天该患者的所有信息(
  22. beego.Router("/api/pharmacy/dispensingmedicine", &PharmacyController{}, "get:DispensingMedicine") //患者发药按钮点击(
  23. beego.Router("/api/pharmacy/drugwithdrawal", &PharmacyController{}, "get:DrugWithdrawal") //退药按钮点击
  24. beego.Router("/api/pharmacy/dispensingdetails", &PharmacyController{}, "get:DispensingDetails") //获取发药明细的患者列表(
  25. beego.Router("/api/pharmacy/prescriptiondetails", &PharmacyController{}, "get:PrescriptionDetails") //发药明细-详情(
  26. beego.Router("/api/pharmacy/dispensemedicine", &PharmacyController{}, "get:DispenseMedicine") //获取当天已发药的药品(
  27. beego.Router("/api/pharmacy/waitingmedicine", &PharmacyController{}, "get:WaitingMedicine") //获取当天待发药的药品(
  28. beego.Router("/api/pharmacy/getpatientswithdrugs", &PharmacyController{}, "get:GetPatientsWithDrugs") //获取当天该药品的所有患者(
  29. beego.Router("/api/pharmacy/medicinedeparture", &PharmacyController{}, "get:MedicineDeparture") //药品发药按钮点击(
  30. beego.Router("/api/pharmacy/getcurrentname", &PharmacyController{}, "get:GetCurrentName") //获取当前登录账号的名字(
  31. beego.Router("/api/pharmacy/getpartitionlist", &PharmacyController{}, "get:GetPartitionList") //获取当前机构的分区列表
  32. beego.Router("/api/pharmacy/routeofadministration", &PharmacyController{}, "get:RouteOfAdministration") //获取当前机构的给药途径
  33. beego.Router("/api/pharmacy/getgoodinventorylist", &PharmacyController{}, "Get:GetGoodInventoryList")
  34. beego.Router("/api/pharmacy/getgoodinventorybygoodid", &PharmacyController{}, "Get:GetGoodInventoryByGoodId")
  35. beego.Router("/api/pharmacy/updateInventoryWarehouseInfo", &PharmacyController{}, "Get:UpdateInventoryWarehouseInfo")
  36. beego.Router("/api/pharmacy/getdrugnewinventoryList", &PharmacyController{}, "Get:GetDrugInventoryList")
  37. beego.Router("/api/pharmacy/getdruginventorybydrugid", &PharmacyController{}, "Get:GetDrugInventoryByDrugId")
  38. beego.Router("/api/pharmacy/updatedruginventorywarehouseinfo", &PharmacyController{}, "Get:UpdateDrugInventoryWarehouseInfo")
  39. beego.Router("/api/pharmacy/changedrugcode", &PharmacyController{}, "Get:ChangeDrugCode")
  40. }
  41. // 测试
  42. func (this *PharmacyController) Tlili() {
  43. var err error
  44. defer func() {
  45. if rec := recover(); rec != nil {
  46. err = fmt.Errorf("程序异常:%v", rec)
  47. }
  48. if err != nil {
  49. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  50. }
  51. }()
  52. var list2 []*models.ReplacementDrugs
  53. list2, err = service.ReplacementDrugs(9675, false)
  54. if err != nil {
  55. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  56. return
  57. }
  58. this.ServeSuccessJSON(map[string]interface{}{
  59. "list": list2,
  60. })
  61. return
  62. }
  63. func (this *PharmacyController) GetCurrentName() {
  64. create := this.GetAdminUserInfo().AdminUser.Id
  65. this.ServeSuccessJSON(map[string]interface{}{
  66. "list": create,
  67. })
  68. return
  69. }
  70. // 查询今天的待发药,已发药人数
  71. func (this *PharmacyController) TodayNumber() {
  72. var err error
  73. defer func() {
  74. if rec := recover(); rec != nil {
  75. err = fmt.Errorf("程序异常:%v", rec)
  76. }
  77. if err != nil {
  78. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  79. }
  80. }()
  81. orgid := this.GetAdminUserInfo().CurrentOrgId
  82. times := this.GetString("time", "")
  83. timeLayout := "2006-01-02"
  84. loc, _ := time.LoadLocation("Local")
  85. var stime, etime int64
  86. if times == "" {
  87. stime, etime = service.GetNowTime()
  88. } else {
  89. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  90. stime = stmp.Unix()
  91. etime = stime + 86399
  92. }
  93. //if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 && orgid != 10480 {
  94. // //查询表里当天的数据
  95. // var wtotal int
  96. // wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
  97. //
  98. // if err != nil {
  99. // utils.ErrorLog(err.Error())
  100. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  101. // return
  102. // }
  103. //
  104. // var itotal int
  105. // itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
  106. //
  107. // drug, _ := service.GetAllBaseDrugList(orgid)
  108. // if err != nil {
  109. // utils.ErrorLog(err.Error())
  110. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  111. // return
  112. // }
  113. // this.ServeSuccessJSON(map[string]interface{}{
  114. // "wtotal": wtotal,
  115. // "itotal": itotal,
  116. // "drug": drug,
  117. // })
  118. // return
  119. //}
  120. var wtotal int
  121. var itotal int
  122. //查找出库数量
  123. wtotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 1)
  124. itotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 0)
  125. drug, _ := service.GetAllBaseDrugList(orgid)
  126. this.ServeSuccessJSON(map[string]interface{}{
  127. "wtotal": wtotal,
  128. "itotal": itotal,
  129. "drug": drug,
  130. })
  131. return
  132. }
  133. func (this *PharmacyController) IssuedDrug() {
  134. var err error
  135. defer func() {
  136. if rec := recover(); rec != nil {
  137. err = fmt.Errorf("程序异常:%v", rec)
  138. }
  139. if err != nil {
  140. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  141. }
  142. }()
  143. keyword := this.GetString("keyword", "")
  144. fmt.Println(keyword)
  145. times := this.GetString("time", "")
  146. orgid := this.GetAdminUserInfo().CurrentOrgId
  147. shift, err := this.GetInt64("shift", 0) //班次
  148. if err != nil {
  149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  150. return
  151. }
  152. partition, err := this.GetInt64("partition", 0) //分区
  153. if err != nil {
  154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  155. return
  156. }
  157. timeLayout := "2006-01-02"
  158. loc, _ := time.LoadLocation("Local")
  159. var stime, etime int64
  160. if times == "" {
  161. stime, etime = service.GetNowTime()
  162. } else {
  163. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  164. stime = stmp.Unix()
  165. etime = stime + 86399
  166. }
  167. //获取排班班次
  168. schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition)
  169. var ids []int64
  170. for _, item := range schedule {
  171. ids = append(ids, item.PatientId)
  172. }
  173. list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 1, ids)
  174. var flist []models.TmpPatientOne
  175. if len(list) > 0 {
  176. for _, item := range list {
  177. patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
  178. flist = append(flist, patientlist)
  179. }
  180. }
  181. this.ServeSuccessJSON(map[string]interface{}{
  182. "list": flist,
  183. })
  184. //if orgid != 10164 && orgid == 3877 && orgid != 10188 && orgid != 10217 && orgid != 9671 && orgid != 10387 && orgid != 10375 && orgid != 10480 && orgid == 10344 {
  185. // //查询表里当天的数据
  186. // var flist []*models.TmpPatient
  187. // flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
  188. // if err != nil {
  189. // utils.ErrorLog(err.Error())
  190. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  191. // return
  192. // }
  193. // listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
  194. // if err != nil {
  195. // utils.ErrorLog(err.Error())
  196. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  197. // return
  198. // }
  199. // this.ServeSuccessJSON(map[string]interface{}{
  200. // "list": listt,
  201. // })
  202. // return
  203. //}
  204. }
  205. func (this *PharmacyController) WaitingDrug() {
  206. var err error
  207. defer func() {
  208. if rec := recover(); rec != nil {
  209. err = fmt.Errorf("程序异常:%v", rec)
  210. }
  211. if err != nil {
  212. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  213. }
  214. }()
  215. keyword := this.GetString("keyword", "")
  216. times := this.GetString("time", "")
  217. shift, err := this.GetInt64("shift", 0) //班次
  218. if err != nil {
  219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  220. return
  221. }
  222. partition, err := this.GetInt64("partition", 0) //分区
  223. if err != nil {
  224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  225. return
  226. }
  227. orgid := this.GetAdminUserInfo().CurrentOrgId
  228. timeLayout := "2006-01-02"
  229. loc, _ := time.LoadLocation("Local")
  230. var stime, etime int64
  231. if times == "" {
  232. stime, etime = service.GetNowTime()
  233. } else {
  234. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  235. stime = stmp.Unix()
  236. etime = stime + 86399
  237. }
  238. //if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 && orgid != 10387 && orgid != 10375 && orgid != 10480 && orgid != 10344 {
  239. // //查询表里当天的数据
  240. // var flist []*models.TmpPatient
  241. // flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
  242. //
  243. // if err != nil {
  244. // utils.ErrorLog(err.Error())
  245. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  246. // return
  247. // }
  248. // listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
  249. //
  250. // if err != nil {
  251. // utils.ErrorLog(err.Error())
  252. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  253. // return
  254. // }
  255. // baseList, _ := service.GetAllBaseDrugListTwo(orgid)
  256. // this.ServeSuccessJSON(map[string]interface{}{
  257. // "list": listt,
  258. // "baseList": baseList,
  259. // })
  260. // return
  261. //}
  262. fmt.Println(keyword)
  263. //当未发药的人数
  264. //获取排班班次
  265. schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition)
  266. var ids []int64
  267. for _, item := range schedule {
  268. ids = append(ids, item.PatientId)
  269. }
  270. list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 0, ids)
  271. var flist []models.TmpPatientOne
  272. if len(list) > 0 {
  273. for _, item := range list {
  274. patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
  275. flist = append(flist, patientlist)
  276. }
  277. }
  278. baseList, _ := service.GetAllBaseDrugListTwo(orgid)
  279. this.ServeSuccessJSON(map[string]interface{}{
  280. "list": flist,
  281. "baseList": baseList,
  282. })
  283. return
  284. }
  285. func (this *PharmacyController) GetPharmacyContent() {
  286. var err error
  287. defer func() {
  288. if rec := recover(); rec != nil {
  289. err = fmt.Errorf("程序异常:%v", rec)
  290. }
  291. if err != nil {
  292. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  293. }
  294. }()
  295. patient_id, _ := this.GetInt64("patient_id", 0)
  296. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  297. times := this.GetString("time", "")
  298. orgid := this.GetAdminUserInfo().CurrentOrgId
  299. timeLayout := "2006-01-02"
  300. loc, _ := time.LoadLocation("Local")
  301. var stime, etime int64
  302. if times == "" {
  303. stime, etime = service.GetNowTime()
  304. } else {
  305. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  306. stime = stmp.Unix()
  307. etime = stime + 86399
  308. }
  309. var list []*models.PharmacyContent
  310. list, err = service.GetPatientMedication(orgid, patient_id, stime, etime, is_medicine)
  311. baseList, _ := service.GetAllBaseDrugListTwo(orgid)
  312. patients, _ := service.GetPatientByIDOne(orgid, patient_id)
  313. order, _ := service.GetMobiledialysiOrder(orgid, patient_id, stime)
  314. numberList, _ := service.GetAllBedNumberList(orgid)
  315. zoneList, _ := service.GetAllZoneByList(orgid)
  316. appId := this.GetAdminUserInfo().CurrentAppId
  317. adminUserES, _ := service.GetAllAdminUserES(orgid, appId)
  318. allDoctor, _ := service.GetAllDoctor(orgid, appId)
  319. prescriptionListByToDay, _ := service.GetPrescriptionListByToDay(orgid, patient_id, stime)
  320. diagnose, _ := service.FindAllDiagnose(orgid)
  321. if err != nil {
  322. utils.ErrorLog(err.Error())
  323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  324. return
  325. }
  326. return_value := make(map[string]interface{})
  327. return_value["list"] = list
  328. return_value["baseList"] = baseList
  329. return_value["patients"] = patients
  330. return_value["order"] = order
  331. return_value["numberList"] = numberList
  332. return_value["zoneList"] = zoneList
  333. return_value["adminUserES"] = adminUserES
  334. return_value["doctors"] = allDoctor
  335. return_value["prescription"] = prescriptionListByToDay
  336. return_value["diagnose"] = diagnose
  337. //if is_medicine == 1{发药时间先不展示
  338. // return_value["time"] = time
  339. //}
  340. this.ServeSuccessJSON(return_value)
  341. return
  342. }
  343. // 发药按钮点击
  344. func (this *PharmacyController) DispensingMedicine() {
  345. var err error
  346. defer func() {
  347. if rec := recover(); rec != nil {
  348. err = fmt.Errorf("程序异常:%v", rec)
  349. }
  350. if err != nil {
  351. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  352. }
  353. }()
  354. patient_id, _ := this.GetInt64("patient_id", 0)
  355. times := this.GetString("time", "")
  356. orgid := this.GetAdminUserInfo().CurrentOrgId
  357. creater := this.GetAdminUserInfo().AdminUser.Id
  358. timeLayout := "2006-01-02"
  359. loc, _ := time.LoadLocation("Local")
  360. var stime, etime int64
  361. if times == "" {
  362. stime, etime = service.GetNowTime()
  363. } else {
  364. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  365. stime = stmp.Unix()
  366. etime = stime + 86399
  367. }
  368. tmp_bool := service.IsPharmacyConfig(orgid)
  369. if tmp_bool == true {
  370. advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
  371. if len(advicelist) > 0 {
  372. var total int64
  373. var prescribing_number_total int64
  374. for _, item := range advicelist {
  375. //查询改药品信息
  376. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  377. //如果是药房发药的方式
  378. if medical.IsPharmacy == 1 {
  379. houseConfig, _ := service.GetAllStoreHouseConfig(orgid)
  380. //查询该药品是否有库存
  381. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  382. //判断单位是否相等
  383. if medical.MaxUnit == item.PrescribingNumberUnit {
  384. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  385. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  386. //转化为最小单位
  387. total = list.Count*medical.MinNumber + list.StockMinNumber
  388. prescribing_number_total = count * medical.MinNumber
  389. }
  390. if medical.MinUnit == item.PrescribingNumberUnit {
  391. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  392. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  393. total = list.Count*medical.MinNumber + list.StockMinNumber
  394. prescribing_number_total = count
  395. }
  396. if medical.IsUse != 1 {
  397. //如果出库数量大于库存数量
  398. if prescribing_number_total > total {
  399. err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "库存不足")
  400. if err != nil {
  401. utils.ErrorLog(err.Error())
  402. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  403. return
  404. }
  405. }
  406. }
  407. }
  408. }
  409. }
  410. }
  411. if orgid != 10480 && orgid != 10188 && orgid != 10217 && orgid != 10164 && orgid != 10666 {
  412. //发药
  413. err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
  414. if err != nil {
  415. utils.ErrorLog(err.Error())
  416. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  417. return
  418. }
  419. this.ServeSuccessJSON(map[string]interface{}{
  420. "list": "操作成功",
  421. })
  422. return
  423. }
  424. if orgid == 10480 || orgid == 10188 || orgid == 10217 || orgid == 10164 || orgid == 10666 {
  425. //发药逻辑
  426. fmt.Println("hhhhhhhhhhhhhhhhhhhhhhhhhhh尽力")
  427. service.DispensingMedicineOne(orgid, patient_id, stime, etime, creater)
  428. //针对桑植盛康
  429. if orgid == 10387 || orgid == 3877 {
  430. advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
  431. if len(advicelist) > 0 {
  432. for _, item := range advicelist {
  433. //查询改药品信息
  434. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  435. if medical.IsPharmacy == 1 {
  436. flow, _ := service.GetFlow(item.DrugId, item.AdviceDate, orgid, item.PatientId)
  437. if len(flow) > 0 {
  438. service.UpdateAdviceFlow(item.ID)
  439. }
  440. }
  441. }
  442. }
  443. }
  444. if err != nil {
  445. utils.ErrorLog(err.Error())
  446. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  447. return
  448. }
  449. this.ServeSuccessJSON(map[string]interface{}{
  450. "list": "操作成功",
  451. })
  452. return
  453. }
  454. }
  455. // 退药按钮点击
  456. func (this *PharmacyController) DrugWithdrawal() {
  457. var err error
  458. defer func() {
  459. if rec := recover(); rec != nil {
  460. err = fmt.Errorf("程序异常:%v", rec)
  461. }
  462. if err != nil {
  463. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  464. }
  465. }()
  466. patient_id, _ := this.GetInt64("patient_id", 0)
  467. times := this.GetString("time", "")
  468. orgid := this.GetAdminUserInfo().CurrentOrgId
  469. creater := this.GetAdminUserInfo().AdminUser.Id
  470. timeLayout := "2006-01-02"
  471. loc, _ := time.LoadLocation("Local")
  472. var stime, etime int64
  473. if times == "" {
  474. stime, etime = service.GetNowTime()
  475. } else {
  476. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  477. stime = stmp.Unix()
  478. etime = stime + 86399
  479. }
  480. err = service.DrugWithdrawal(orgid, patient_id, stime, etime, creater)
  481. if err != nil {
  482. utils.ErrorLog(err.Error())
  483. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  484. return
  485. }
  486. this.ServeSuccessJSON(map[string]interface{}{
  487. "list": "操作成功",
  488. })
  489. return
  490. }
  491. // 发药明细列表
  492. func (this *PharmacyController) DispensingDetails() {
  493. var err error
  494. defer func() {
  495. if rec := recover(); rec != nil {
  496. err = fmt.Errorf("程序异常:%v", rec)
  497. }
  498. if err != nil {
  499. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  500. }
  501. }()
  502. keyword := this.GetString("keyword", "") //患者名称
  503. start_time := this.GetString("start_time", "") //开始时间
  504. end_time := this.GetString("end_time", "") //结束时间
  505. page, _ := this.GetInt64("page", 1) //页码
  506. limit, _ := this.GetInt64("limit", 10) //每一页查出来的条数
  507. orgid := this.GetAdminUserInfo().CurrentOrgId
  508. timeLayout := "2006-01-02"
  509. loc, _ := time.LoadLocation("Local")
  510. var stime, etime int64
  511. if start_time == "" {
  512. stime = 1
  513. } else {
  514. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  515. stime = stmp.Unix()
  516. }
  517. if end_time == "" {
  518. _, etime = service.GetNowTime()
  519. } else {
  520. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  521. etime = etmp.Unix()
  522. }
  523. var dislist []*models.DispensingList
  524. var total int64
  525. dislist, total, err = service.DispensingDetailsList(stime, etime, orgid, page, limit, keyword)
  526. if err != nil {
  527. utils.ErrorLog(err.Error())
  528. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  529. return
  530. }
  531. this.ServeSuccessJSON(map[string]interface{}{
  532. "list": dislist,
  533. "total": total,
  534. })
  535. return
  536. }
  537. // 处方详情
  538. func (this *PharmacyController) PrescriptionDetails() {
  539. var err error
  540. defer func() {
  541. if rec := recover(); rec != nil {
  542. err = fmt.Errorf("程序异常:%v", rec)
  543. }
  544. if err != nil {
  545. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  546. }
  547. }()
  548. //患者姓名
  549. patient_id, _ := this.GetInt64("patient_id", 0)
  550. //发药时间
  551. record_date, _ := this.GetInt64("record_date", 0)
  552. orgid := this.GetAdminUserInfo().CurrentOrgId
  553. if record_date == 0 || patient_id == 0 {
  554. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  555. return
  556. }
  557. var list []*models.PrescripDetails
  558. list, err = service.PrescriptionDetails(patient_id, record_date, orgid)
  559. if err != nil {
  560. utils.ErrorLog(err.Error())
  561. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  562. return
  563. }
  564. this.ServeSuccessJSON(map[string]interface{}{
  565. "list": list,
  566. })
  567. return
  568. }
  569. // 已发药品的信息
  570. func (this *PharmacyController) DispenseMedicine() {
  571. var err error
  572. defer func() {
  573. if rec := recover(); rec != nil {
  574. err = fmt.Errorf("程序异常:%v", rec)
  575. }
  576. if err != nil {
  577. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  578. }
  579. }()
  580. keyword := this.GetString("keyword", "")
  581. times := this.GetString("time", "")
  582. orgid := this.GetAdminUserInfo().CurrentOrgId
  583. timeLayout := "2006-01-02"
  584. loc, _ := time.LoadLocation("Local")
  585. deliveryway := this.GetString("deliveryway", "")
  586. var stime, etime int64
  587. if times == "" {
  588. stime, etime = service.GetNowTime()
  589. } else {
  590. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  591. stime = stmp.Unix()
  592. etime = stime + 86399
  593. }
  594. //查询表里当天的数据
  595. var flist []*models.ListOfDrugs
  596. flist, err = service.GetTodayMedicine(stime, etime, orgid, 1, keyword)
  597. if err != nil {
  598. utils.ErrorLog(err.Error())
  599. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  600. return
  601. }
  602. llist, err := service.Administration(deliveryway, orgid, flist)
  603. if err != nil {
  604. utils.ErrorLog(err.Error())
  605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  606. return
  607. }
  608. this.ServeSuccessJSON(map[string]interface{}{
  609. "list": llist,
  610. })
  611. return
  612. }
  613. // 待发药的药品信息
  614. func (this *PharmacyController) WaitingMedicine() {
  615. var err error
  616. defer func() {
  617. if rec := recover(); rec != nil {
  618. err = fmt.Errorf("程序异常:%v", rec)
  619. }
  620. if err != nil {
  621. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  622. }
  623. }()
  624. keyword := this.GetString("keyword", "")
  625. times := this.GetString("time", "")
  626. orgid := this.GetAdminUserInfo().CurrentOrgId
  627. timeLayout := "2006-01-02"
  628. loc, _ := time.LoadLocation("Local")
  629. deliveryway := this.GetString("deliveryway", "")
  630. var stime, etime int64
  631. if times == "" {
  632. stime, etime = service.GetNowTime()
  633. } else {
  634. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  635. stime = stmp.Unix()
  636. etime = stime + 86399
  637. }
  638. //查询表里当天的数据
  639. var flist []*models.ListOfDrugs
  640. flist, err = service.GetTodayMedicine(stime, etime, orgid, 0, keyword)
  641. if err != nil {
  642. utils.ErrorLog(err.Error())
  643. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  644. return
  645. }
  646. llist, err := service.Administration(deliveryway, orgid, flist)
  647. if err != nil {
  648. utils.ErrorLog(err.Error())
  649. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  650. return
  651. }
  652. this.ServeSuccessJSON(map[string]interface{}{
  653. "list": llist,
  654. })
  655. return
  656. }
  657. // 获取药品的所有患者信息
  658. func (this *PharmacyController) GetPatientsWithDrugs() {
  659. var err error
  660. defer func() {
  661. if rec := recover(); rec != nil {
  662. err = fmt.Errorf("程序异常:%v", rec)
  663. }
  664. if err != nil {
  665. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  666. }
  667. }()
  668. drug_id, _ := this.GetInt64("drug_id", 0)
  669. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  670. times := this.GetString("time", "")
  671. orgid := this.GetAdminUserInfo().CurrentOrgId
  672. deliveryway := this.GetString("deliveryway", "")
  673. if deliveryway == "" {
  674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  675. return
  676. }
  677. shift, err := this.GetInt64("shift", 0) //班次
  678. if err != nil {
  679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  680. return
  681. }
  682. partition, err := this.GetInt64("partition", 0) //分区
  683. if err != nil {
  684. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  685. return
  686. }
  687. timeLayout := "2006-01-02"
  688. loc, _ := time.LoadLocation("Local")
  689. var stime, etime int64
  690. if times == "" {
  691. stime, etime = service.GetNowTime()
  692. } else {
  693. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  694. stime = stmp.Unix()
  695. etime = stime + 86399
  696. }
  697. var list []*models.PatientInformation
  698. list, err = service.FindMedicationList(orgid, drug_id, stime, etime, is_medicine)
  699. if err != nil {
  700. utils.ErrorLog(err.Error())
  701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  702. return
  703. }
  704. listll, err := service.PartitionAndLayoutDrug(deliveryway, stime, etime, orgid, shift, partition, list)
  705. if err != nil {
  706. utils.ErrorLog(err.Error())
  707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  708. return
  709. }
  710. total, err := service.CalculateTheTotalAmount(listll, drug_id)
  711. if err != nil {
  712. utils.ErrorLog(err.Error())
  713. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  714. return
  715. }
  716. this.ServeSuccessJSON(map[string]interface{}{
  717. "list": listll,
  718. "total": total,
  719. })
  720. return
  721. }
  722. // 药品管理发药按钮点击
  723. func (this *PharmacyController) MedicineDeparture() {
  724. var err error
  725. defer func() {
  726. if rec := recover(); rec != nil {
  727. err = fmt.Errorf("程序异常:%v", rec)
  728. }
  729. if err != nil {
  730. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  731. }
  732. }()
  733. creater, _ := this.GetInt64("creater", 0) //领药人
  734. ids := this.GetString("ids", "") //发药的数据
  735. orgid := this.GetAdminUserInfo().CurrentOrgId
  736. if ids == "" {
  737. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  738. return
  739. }
  740. err = service.MedicineDeparture(ids, creater, orgid)
  741. if err != nil {
  742. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  743. return
  744. }
  745. this.ServeSuccessJSON(map[string]interface{}{
  746. "list": "修改成功",
  747. })
  748. return
  749. }
  750. func (this *PharmacyController) GetPartitionList() {
  751. var err error
  752. defer func() {
  753. if rec := recover(); rec != nil {
  754. err = fmt.Errorf("程序异常:%v", rec)
  755. }
  756. if err != nil {
  757. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  758. }
  759. }()
  760. orgid := this.GetAdminUserInfo().CurrentOrgId
  761. tmp := []*models.DeviceZone{{ID: 0, Name: "全部分区"}}
  762. list, err := service.GetAllValidDeviceZones02(orgid)
  763. if err != nil {
  764. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  765. return
  766. }
  767. this.ServeSuccessJSON(map[string]interface{}{
  768. "list": append(tmp, list...),
  769. })
  770. return
  771. }
  772. func (this *PharmacyController) RouteOfAdministration() {
  773. var err error
  774. defer func() {
  775. if rec := recover(); rec != nil {
  776. err = fmt.Errorf("程序异常:%v", rec)
  777. }
  778. if err != nil {
  779. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  780. }
  781. }()
  782. orgid := this.GetAdminUserInfo().CurrentOrgId
  783. tmp := []*models.DrugwayDic{{ID: 0, Name: "全部"}}
  784. list, _, err := service.GetDrugWayDics(orgid)
  785. if err != nil {
  786. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  787. return
  788. }
  789. this.ServeSuccessJSON(map[string]interface{}{
  790. "list": append(tmp, list...),
  791. })
  792. return
  793. }
  794. func (this *PharmacyController) GetGoodInventoryList() {
  795. keyword := this.GetString("keywords")
  796. orgId := this.GetAdminUserInfo().CurrentOrgId
  797. list, _ := service.GetGoodInventoryList(keyword, orgId)
  798. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  799. this.ServeSuccessJSON(map[string]interface{}{
  800. "list": list,
  801. "manufacturerList": manufacturerList,
  802. })
  803. return
  804. }
  805. func (this *PharmacyController) GetGoodInventoryByGoodId() {
  806. id, _ := this.GetInt64("id")
  807. infoList, _ := service.GetGoodInventoryByGoodId(id)
  808. this.ServeSuccessJSON(map[string]interface{}{
  809. "infoList": infoList,
  810. })
  811. }
  812. func (this *PharmacyController) UpdateInventoryWarehouseInfo() {
  813. id, _ := this.GetInt64("id")
  814. stock_count, _ := this.GetInt64("stock_count")
  815. last_stock_count, _ := this.GetInt64("last_stock_count")
  816. good_id, _ := this.GetInt64("good_id")
  817. orgId := this.GetAdminUserInfo().CurrentOrgId
  818. storehouse_id, _ := this.GetInt64("storehouse_id")
  819. is_type, _ := this.GetInt64("is_type")
  820. warehouseInfo, _ := service.GetInventoryWarehouseInfo(id)
  821. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(good_id)
  822. manufacturer, _ := service.GetManufactureById(warehouseInfo.Manufacturer)
  823. //更新库存
  824. service.UpdateWarehouseInfoById(last_stock_count, id)
  825. recordDateStr := time.Now().Format("2006-01-02")
  826. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  827. goodListOne, _ := service.GetSumGoodList(orgId, storehouse_id, good_id)
  828. var flush_count int64
  829. for _, it := range goodListOne {
  830. flush_count += it.StockCount
  831. }
  832. //盘盈
  833. if last_stock_count > stock_count {
  834. var total_count int64
  835. total_count = last_stock_count - stock_count
  836. creater := this.GetAdminUserInfo().AdminUser.Id
  837. inventory := models.XtStockInventory{
  838. GoodName: goodInfo.GoodName,
  839. SpecificationName: goodInfo.SpecificationName,
  840. WarehousingUnit: goodInfo.PackingUnit,
  841. Count: total_count,
  842. BuyPrice: goodInfo.BuyPrice,
  843. PackingPrice: goodInfo.PackingPrice,
  844. NewPrice: 0,
  845. Manufacturer: manufacturer.ManufacturerName,
  846. Dealer: "",
  847. Remark: "",
  848. GoodId: good_id,
  849. UserOrgId: orgId,
  850. Ctime: time.Now().Unix(),
  851. Mtime: 0,
  852. Status: 1,
  853. WarehousingOrder: warehouseInfo.WarehousingOrder,
  854. LicenseNumber: warehouseInfo.LicenseNumber,
  855. StartTime: time.Now().Unix(),
  856. Creater: creater,
  857. Checker: 0,
  858. CheckerStatus: 0,
  859. CheckerTime: 0,
  860. Total: 0,
  861. Number: warehouseInfo.Number,
  862. WarehousingInfoId: id,
  863. ExpireDate: warehouseInfo.ExpiryDate,
  864. ProductDate: warehouseInfo.ProductDate,
  865. GoodOriginPlace: "",
  866. Type: 10,
  867. InventoryType: is_type,
  868. LastStockCount: last_stock_count,
  869. StockCount: stock_count,
  870. StorehouseId: storehouse_id,
  871. RecordDate: recordDate.Unix(),
  872. }
  873. service.CreateInentory(inventory)
  874. stockFlow := models.VmStockFlow{
  875. WarehousingId: 0,
  876. GoodId: good_id,
  877. Number: warehouseInfo.Number,
  878. LicenseNumber: "",
  879. Count: total_count,
  880. UserOrgId: orgId,
  881. PatientId: 0,
  882. SystemTime: recordDate.Unix(),
  883. ConsumableType: 10,
  884. IsSys: 0,
  885. WarehousingOrder: warehouseInfo.WarehousingOrder,
  886. WarehouseOutId: 0,
  887. WarehouseOutOrderNumber: "",
  888. IsEdit: 0,
  889. CancelStockId: 0,
  890. CancelOrderNumber: "",
  891. Manufacturer: warehouseInfo.Manufacturer,
  892. Dealer: 0,
  893. Creator: creater,
  894. UpdateCreator: 0,
  895. Status: 1,
  896. Ctime: time.Now().Unix(),
  897. Mtime: 0,
  898. Price: warehouseInfo.Price,
  899. WarehousingDetailId: 0,
  900. WarehouseOutDetailId: 0,
  901. CancelOutDetailId: 0,
  902. ProductDate: warehouseInfo.ProductDate,
  903. ExpireDate: warehouseInfo.ExpiryDate,
  904. ReturnCount: 0,
  905. StorehouseId: storehouse_id,
  906. OverCount: flush_count,
  907. }
  908. service.CreateStockFlowOne(stockFlow)
  909. service.ReduceSumOutCount(good_id, total_count, storehouse_id, orgId)
  910. }
  911. //盘亏
  912. if last_stock_count < stock_count {
  913. var total_count int64
  914. total_count = stock_count - last_stock_count
  915. creater := this.GetAdminUserInfo().AdminUser.Id
  916. inventory := models.XtStockInventory{
  917. GoodName: goodInfo.GoodName,
  918. SpecificationName: goodInfo.SpecificationName,
  919. WarehousingUnit: goodInfo.PackingUnit,
  920. Count: total_count,
  921. BuyPrice: goodInfo.BuyPrice,
  922. PackingPrice: goodInfo.PackingPrice,
  923. NewPrice: 0,
  924. Manufacturer: manufacturer.ManufacturerName,
  925. Dealer: "",
  926. Remark: "",
  927. GoodId: good_id,
  928. UserOrgId: orgId,
  929. Ctime: time.Now().Unix(),
  930. Mtime: 0,
  931. Status: 1,
  932. WarehousingOrder: warehouseInfo.WarehousingOrder,
  933. LicenseNumber: warehouseInfo.LicenseNumber,
  934. StartTime: time.Now().Unix(),
  935. Creater: creater,
  936. Checker: 0,
  937. CheckerStatus: 0,
  938. CheckerTime: 0,
  939. Total: 0,
  940. Number: warehouseInfo.Number,
  941. WarehousingInfoId: id,
  942. ExpireDate: warehouseInfo.ExpiryDate,
  943. ProductDate: warehouseInfo.ProductDate,
  944. GoodOriginPlace: "",
  945. Type: 10,
  946. InventoryType: is_type,
  947. LastStockCount: last_stock_count,
  948. StockCount: stock_count,
  949. StorehouseId: storehouse_id,
  950. RecordDate: recordDate.Unix(),
  951. }
  952. service.CreateInentory(inventory)
  953. stockFlow := models.VmStockFlow{
  954. WarehousingId: 0,
  955. GoodId: good_id,
  956. Number: warehouseInfo.Number,
  957. LicenseNumber: "",
  958. Count: total_count,
  959. UserOrgId: orgId,
  960. PatientId: 0,
  961. SystemTime: recordDate.Unix(),
  962. ConsumableType: 11,
  963. IsSys: 0,
  964. WarehousingOrder: warehouseInfo.WarehousingOrder,
  965. WarehouseOutId: 0,
  966. WarehouseOutOrderNumber: "",
  967. IsEdit: 0,
  968. CancelStockId: 0,
  969. CancelOrderNumber: "",
  970. Manufacturer: warehouseInfo.Manufacturer,
  971. Dealer: 0,
  972. Creator: creater,
  973. UpdateCreator: 0,
  974. Status: 1,
  975. Ctime: time.Now().Unix(),
  976. Mtime: 0,
  977. Price: warehouseInfo.Price,
  978. WarehousingDetailId: 0,
  979. WarehouseOutDetailId: 0,
  980. CancelOutDetailId: 0,
  981. ProductDate: warehouseInfo.ProductDate,
  982. ExpireDate: warehouseInfo.ExpiryDate,
  983. ReturnCount: 0,
  984. StorehouseId: storehouse_id,
  985. OverCount: flush_count,
  986. }
  987. service.CreateStockFlowOne(stockFlow)
  988. service.ReduceSumInCount(good_id, total_count, storehouse_id, orgId)
  989. }
  990. //查询已审核单据的剩余库存
  991. goodList, _ := service.GetGoodSumCountByStoreId(storehouse_id, good_id, orgId)
  992. var sum_count int64
  993. var sum_in_count int64
  994. for _, item := range goodList {
  995. sum_count += item.StockCount
  996. sum_in_count += item.WarehousingCount
  997. }
  998. service.UpdateGoodByGoodId(good_id, sum_count, sum_in_count, orgId)
  999. service.UpdateSumGood(orgId, storehouse_id, good_id, flush_count)
  1000. this.ServeSuccessJSON(map[string]interface{}{
  1001. "msg": "msg",
  1002. })
  1003. }
  1004. func (this *PharmacyController) GetDrugInventoryList() {
  1005. keywords := this.GetString("keywords")
  1006. orgId := this.GetAdminUserInfo().CurrentOrgId
  1007. drugList, _ := service.GetDrugNewInventoryList(orgId, keywords)
  1008. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1009. this.ServeSuccessJSON(map[string]interface{}{
  1010. "drugList": drugList,
  1011. "manufacturerList": manufacturerList,
  1012. })
  1013. }
  1014. func (this *PharmacyController) GetDrugInventoryByDrugId() {
  1015. orgId := this.GetAdminUserInfo().CurrentOrgId
  1016. id, _ := this.GetInt64("id")
  1017. infoList, _ := service.GetDrugInvetoryByDrugId(orgId, id)
  1018. this.ServeSuccessJSON(map[string]interface{}{
  1019. "infoList": infoList,
  1020. })
  1021. }
  1022. func (this *PharmacyController) UpdateDrugInventoryWarehouseInfo() {
  1023. id, _ := this.GetInt64("id")
  1024. stock_max_number, _ := this.GetInt64("stock_max_number")
  1025. stock_min_number, _ := this.GetInt64("stock_min_number")
  1026. last_stock_max_number, _ := this.GetInt64("last_stock_max_number")
  1027. last_stock_min_number, _ := this.GetInt64("last_stock_min_number")
  1028. drug_id, _ := this.GetInt64("drug_id")
  1029. storehouse_id, _ := this.GetInt64("storehouse_id")
  1030. is_type, _ := this.GetInt64("is_type")
  1031. specification_name := this.GetString("specification_name")
  1032. orgId := this.GetAdminUserInfo().CurrentOrgId
  1033. base, _ := service.GetBasedrugByIdOne(drug_id, orgId)
  1034. var ord_total int64
  1035. var new_total int64
  1036. var consumable_count int64
  1037. ord_total = stock_max_number*base.MinNumber + stock_min_number
  1038. new_total = last_stock_max_number*base.MinNumber + last_stock_min_number
  1039. //更新入库单
  1040. service.UpdateNewDrugWarehouseInfoById(id, last_stock_max_number, last_stock_min_number)
  1041. //查询默认仓库
  1042. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1043. //查询默认仓库剩余多少库存
  1044. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, drug_id)
  1045. var sum_count int64
  1046. for _, it := range list {
  1047. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  1048. if it.MaxUnit == baseDrug.MaxUnit {
  1049. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  1050. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  1051. }
  1052. sum_count += it.StockMaxNumber + it.StockMinNumber
  1053. }
  1054. //更新剩余库存
  1055. service.UpdateMedicalSumCountOne(drug_id, sum_count, orgId)
  1056. //更新剩余库存
  1057. service.UpdateDrugStockCount(drug_id, orgId, houseConfig.DrugStorehouseOut, sum_count)
  1058. drugWarehouseInfoOne, _ := service.GetDrugWarehouseInfoOne(id)
  1059. manufacturer, _ := service.GetManufactureById(drugWarehouseInfoOne.Manufacturer)
  1060. recordDateStr := time.Now().Format("2006-01-02")
  1061. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1062. //盘亏
  1063. if ord_total > new_total {
  1064. consumable_count = ord_total - new_total
  1065. inventory := models.XtDrugInventory{
  1066. DrugName: base.DrugName,
  1067. SpecificationName: specification_name,
  1068. WarehousingUnit: drugWarehouseInfoOne.MaxUnit,
  1069. Count: consumable_count,
  1070. LastPrice: drugWarehouseInfoOne.Price,
  1071. RetailPrice: drugWarehouseInfoOne.RetailPrice,
  1072. NewPrice: 0,
  1073. Manufacturer: manufacturer.ManufacturerName,
  1074. Dealer: "",
  1075. Remark: "",
  1076. DrugId: drug_id,
  1077. UserOrgId: orgId,
  1078. Ctime: time.Now().Unix(),
  1079. Mtime: 0,
  1080. Status: 1,
  1081. WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
  1082. LicenseNumber: "",
  1083. StartTime: recordDate.Unix(),
  1084. Creater: this.GetAdminUserInfo().AdminUser.Id,
  1085. Checker: 0,
  1086. CheckerStatus: 0,
  1087. CheckerTime: 0,
  1088. ExpiryDate: drugWarehouseInfoOne.ExpiryDate,
  1089. ProductDate: drugWarehouseInfoOne.ProductDate,
  1090. Number: "",
  1091. BatchNumber: drugWarehouseInfoOne.BatchNumber,
  1092. Total: "",
  1093. DrugOriginPlace: "",
  1094. WarehouseInfoId: id,
  1095. ProofCount: 0,
  1096. StockMaxNumber: stock_max_number,
  1097. StockMinNumber: stock_min_number,
  1098. MinCount: 0,
  1099. MinUnit: drugWarehouseInfoOne.MinUnit,
  1100. LastStockMaxNumber: last_stock_max_number,
  1101. LastStockMinNumber: last_stock_min_number,
  1102. InventoryType: 11,
  1103. Type: is_type,
  1104. StorehouseId: storehouse_id,
  1105. RecordDate: recordDate.Unix(),
  1106. }
  1107. service.CreateDrugInventory(inventory)
  1108. flow := models.DrugFlow{
  1109. WarehousingId: id,
  1110. DrugId: drug_id,
  1111. Number: "",
  1112. BatchNumber: drugWarehouseInfoOne.BatchNumber,
  1113. Count: consumable_count,
  1114. UserOrgId: orgId,
  1115. PatientId: 0,
  1116. SystemTime: recordDate.Unix(),
  1117. ConsumableType: 11,
  1118. IsSys: 1,
  1119. WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
  1120. WarehouseOutId: 0,
  1121. WarehouseOutOrderNumber: "",
  1122. IsEdit: 0,
  1123. CancelStockId: 0,
  1124. CancelOrderNumber: "",
  1125. Manufacturer: manufacturer.ID,
  1126. Dealer: 0,
  1127. Creator: this.GetAdminUserInfo().AdminUser.Id,
  1128. UpdateCreator: 0,
  1129. Status: 1,
  1130. Ctime: time.Now().Unix(),
  1131. Mtime: 0,
  1132. Price: drugWarehouseInfoOne.Price,
  1133. WarehousingDetailId: id,
  1134. WarehouseOutDetailId: 0,
  1135. CancelOutDetailId: 0,
  1136. ExpireDate: drugWarehouseInfoOne.ExpiryDate,
  1137. ProductDate: 0,
  1138. MaxUnit: drugWarehouseInfoOne.MaxUnit,
  1139. MinUnit: drugWarehouseInfoOne.MinUnit,
  1140. StorehouseId: storehouse_id,
  1141. OverCount: sum_count,
  1142. }
  1143. service.CreateDrugFlowOne(flow)
  1144. //添加出库数据
  1145. service.AddDrugWarehouseOut(drug_id, consumable_count, storehouse_id, orgId)
  1146. }
  1147. //盘盈
  1148. if ord_total < new_total {
  1149. consumable_count = new_total - ord_total
  1150. inventory := models.XtDrugInventory{
  1151. DrugName: base.DrugName,
  1152. SpecificationName: specification_name,
  1153. WarehousingUnit: drugWarehouseInfoOne.MaxUnit,
  1154. Count: consumable_count,
  1155. LastPrice: drugWarehouseInfoOne.Price,
  1156. RetailPrice: drugWarehouseInfoOne.RetailPrice,
  1157. NewPrice: 0,
  1158. Manufacturer: manufacturer.ManufacturerName,
  1159. Dealer: "",
  1160. Remark: "",
  1161. DrugId: drug_id,
  1162. UserOrgId: orgId,
  1163. Ctime: time.Now().Unix(),
  1164. Mtime: 0,
  1165. Status: 1,
  1166. WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
  1167. LicenseNumber: "",
  1168. StartTime: recordDate.Unix(),
  1169. Creater: this.GetAdminUserInfo().AdminUser.Id,
  1170. Checker: 0,
  1171. CheckerStatus: 0,
  1172. CheckerTime: 0,
  1173. ExpiryDate: drugWarehouseInfoOne.ExpiryDate,
  1174. ProductDate: drugWarehouseInfoOne.ProductDate,
  1175. Number: "",
  1176. BatchNumber: drugWarehouseInfoOne.BatchNumber,
  1177. Total: "",
  1178. DrugOriginPlace: "",
  1179. WarehouseInfoId: id,
  1180. ProofCount: 0,
  1181. StockMaxNumber: stock_max_number,
  1182. StockMinNumber: stock_min_number,
  1183. MinCount: 0,
  1184. MinUnit: drugWarehouseInfoOne.MinUnit,
  1185. LastStockMaxNumber: last_stock_max_number,
  1186. LastStockMinNumber: last_stock_min_number,
  1187. InventoryType: 10,
  1188. Type: is_type,
  1189. StorehouseId: storehouse_id,
  1190. RecordDate: recordDate.Unix(),
  1191. }
  1192. service.CreateDrugInventory(inventory)
  1193. flow := models.DrugFlow{
  1194. WarehousingId: id,
  1195. DrugId: drug_id,
  1196. Number: "",
  1197. BatchNumber: drugWarehouseInfoOne.BatchNumber,
  1198. Count: consumable_count,
  1199. UserOrgId: orgId,
  1200. PatientId: 0,
  1201. SystemTime: recordDate.Unix(),
  1202. ConsumableType: 10,
  1203. IsSys: 1,
  1204. WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
  1205. WarehouseOutId: 0,
  1206. WarehouseOutOrderNumber: "",
  1207. IsEdit: 0,
  1208. CancelStockId: 0,
  1209. CancelOrderNumber: "",
  1210. Manufacturer: manufacturer.ID,
  1211. Dealer: 0,
  1212. Creator: this.GetAdminUserInfo().AdminUser.Id,
  1213. UpdateCreator: 0,
  1214. Status: 1,
  1215. Ctime: time.Now().Unix(),
  1216. Mtime: 0,
  1217. Price: drugWarehouseInfoOne.Price,
  1218. WarehousingDetailId: id,
  1219. WarehouseOutDetailId: 0,
  1220. CancelOutDetailId: 0,
  1221. ExpireDate: drugWarehouseInfoOne.ExpiryDate,
  1222. ProductDate: 0,
  1223. MaxUnit: drugWarehouseInfoOne.MaxUnit,
  1224. MinUnit: drugWarehouseInfoOne.MinUnit,
  1225. StorehouseId: storehouse_id,
  1226. OverCount: sum_count,
  1227. }
  1228. service.CreateDrugFlowOne(flow)
  1229. //减少出库数据
  1230. service.ReduceDrugWarehouseOut(drug_id, consumable_count, storehouse_id, orgId)
  1231. }
  1232. this.ServeSuccessJSON(map[string]interface{}{
  1233. "msg": "msg",
  1234. })
  1235. }
  1236. func (this *PharmacyController) ChangeDrugCode() {
  1237. id, _ := this.GetInt64("id")
  1238. orgId := this.GetAdminUserInfo().CurrentOrgId
  1239. data_source, _ := this.GetInt64("data_source")
  1240. drug_code := this.GetString("drug_code")
  1241. fmt.Println("data_source--------------------", data_source)
  1242. if data_source == 1 {
  1243. fmt.Println("HHAHAHAH")
  1244. service.ChangeHisDrugCode(id, drug_code, orgId)
  1245. }
  1246. if data_source == 2 {
  1247. service.ChangeAdivceDrugCode(id, drug_code, orgId)
  1248. }
  1249. this.ServeSuccessJSON(map[string]interface{}{
  1250. "msg": "msg",
  1251. })
  1252. }