secondary_order_api_contorller.go 67KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020
  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. "github.com/jinzhu/gorm"
  11. "math/rand"
  12. "reflect"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type SecondaryOrderApiController struct {
  18. BaseAuthAPIController
  19. }
  20. func SecondaryOrderApiRegistRouters() {
  21. beego.Router("/api/secondary/getcode", &SecondaryOrderApiController{}, "get:GetStoreCode") //获取仓库编码
  22. beego.Router("/api/secondary/updatestatus", &SecondaryOrderApiController{}, "get:UpdateStatus") //修改仓库状态
  23. beego.Router("/api/secondary/deletestorehouse", &SecondaryOrderApiController{}, "get:DeleteStorehouse") //删除仓库
  24. beego.Router("/api/secondary/isstorehousename", &SecondaryOrderApiController{}, "get:IsStorehouseName") //仓库名称是否重复
  25. beego.Router("/api/secondary/isstorehouseaddress", &SecondaryOrderApiController{}, "get:IsStorehouseAddress") //仓库地址是否重复
  26. beego.Router("/api/secondary/storehouselist", &SecondaryOrderApiController{}, "get:StorehouseList") //分页
  27. beego.Router("/api/secondary/addstorehouse", &SecondaryOrderApiController{}, "post:AddStorehouse") //新增仓库
  28. beego.Router("/api/secondary/updatestorehouse", &SecondaryOrderApiController{}, "post:UpdateStorehouse") //修改
  29. beego.Router("/api/secondary/getonestorehouse", &SecondaryOrderApiController{}, "get:GetOneStorehouse") //查一条仓库的信息
  30. beego.Router("/api/secondary/getallstorehousename", &SecondaryOrderApiController{}, "get:GetAllStorehouseName") //获取当前机构的所有可用仓库名称
  31. beego.Router("/api/secondary/findstorehouseconfig", &SecondaryOrderApiController{}, "get:FindStorehouseConfig") //查询该机构的仓库配置
  32. beego.Router("/api/secondary/updateinfo", &SecondaryOrderApiController{}, "get:UpdateInfo") //更改耗材自动入库仓库
  33. beego.Router("/api/secondary/updateoutinfo", &SecondaryOrderApiController{}, "get:UpdateOutInfo") //更改耗材自动出库仓库
  34. beego.Router("/api/secondary/updatedruginfo", &SecondaryOrderApiController{}, "get:UpdateDrugInfo") //更改药品自动入库仓库
  35. beego.Router("/api/secondary/updatedrugout", &SecondaryOrderApiController{}, "get:UpdateDrugOut") //更改药品自动出库仓库
  36. beego.Router("/api/secondary/getusername", &SecondaryOrderApiController{}, "get:GetuserName") //获取仓库管理员信息
  37. beego.Router("/api/secondary/byliinit", &SecondaryOrderApiController{}, "get:Byliinit") //初始化旧数据
  38. beego.Router("/api/secondary/getcreaterid", &SecondaryOrderApiController{}, "get:GetCreaterId") //获取当前登录的人的id
  39. beego.Router("/api/seconde/getsencondegoodlist", &SecondaryOrderApiController{}, "Get:GetSencondeGoodList")
  40. beego.Router("/api/senconde/savesencondorder", &SecondaryOrderApiController{}, "Post:SaveSencondOrder")
  41. beego.Router("/api/senconde/getallsecondeorderlist", &SecondaryOrderApiController{}, "Get:GetAllSecondeOrderList")
  42. beego.Router("/api/senconde/getsencondorderdetail", &SecondaryOrderApiController{}, "Get:GetSencondOrderDetail")
  43. beego.Router("/api/senconde/updatesencondorder", &SecondaryOrderApiController{}, "Post:UpdateSencondOrder")
  44. beego.Router("/api/sencond/getsecondorderbyid", &SecondaryOrderApiController{}, "Get:GetSecondOrderById")
  45. beego.Router("/api/sencond/checksecondorder", &SecondaryOrderApiController{}, "Get:CheckSecondOrer")
  46. beego.Router("/api/sencond/deletestorehouselist", &SecondaryOrderApiController{}, "Get:DeleteStorehouseList")
  47. beego.Router("/api/sencond/returnchecksecondeorder", &SecondaryOrderApiController{}, "Get:ReturnCheckSecondOrder")
  48. beego.Router("/api/second/getstorehousegoodlist", &SecondaryOrderApiController{}, "Get:GetStoreHouseGoodList")
  49. beego.Router("/api/second/getsumsecondecount", &SecondaryOrderApiController{}, "Get:GetSumSecondCount")
  50. beego.Router("/api/second/deletesecondorderinfo", &SecondaryOrderApiController{}, "Get:DeleteSecondOrderInfo")
  51. }
  52. //获取仓库编码
  53. func (this *SecondaryOrderApiController) GetStoreCode() {
  54. orgId := this.GetAdminUserInfo().CurrentOrgId
  55. var code string
  56. for a := true; a == true; {
  57. code = service.CreateCode()
  58. tmp := service.FindStorehouseCode(orgId, code)
  59. //如果没有重复的编码结束循环
  60. if tmp == false {
  61. a = false
  62. }
  63. }
  64. this.ServeSuccessJSON(map[string]interface{}{
  65. "list": code,
  66. })
  67. return
  68. }
  69. //修改仓库状态
  70. func (this *SecondaryOrderApiController) UpdateStatus() {
  71. orgId := this.GetAdminUserInfo().CurrentOrgId
  72. check := map[string][]string{
  73. "id": {"must", "int", "id"},
  74. }
  75. _, err := checkParams(this, &check)
  76. if err != nil {
  77. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  78. return
  79. }
  80. id, _ := this.GetInt64("id")
  81. //判断该仓库的库存是否为零
  82. boolean := service.IsStorehouseNil(id, orgId)
  83. if boolean == false {
  84. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  85. return
  86. }
  87. //判断该仓库是否在仓库配置表中
  88. boolean = service.IsInConfig(orgId, id)
  89. if boolean == true {
  90. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  91. return
  92. }
  93. //修改仓库状态
  94. err = service.UpdateStorehouseStatus(id)
  95. if err != nil {
  96. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  97. return
  98. }
  99. this.ServeSuccessJSON(map[string]interface{}{
  100. "list": "修改成功",
  101. })
  102. return
  103. }
  104. //删除仓库
  105. func (this *SecondaryOrderApiController) DeleteStorehouse() {
  106. orgId := this.GetAdminUserInfo().CurrentOrgId
  107. check := map[string][]string{
  108. "id": {"must", "int", "id"},
  109. }
  110. _, err := checkParams(this, &check)
  111. if err != nil {
  112. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  113. return
  114. }
  115. id, _ := this.GetInt64("id")
  116. //判断该仓库的库存是否为零
  117. boolean := service.IsStorehouseNil(id, orgId)
  118. if boolean == false {
  119. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  120. return
  121. }
  122. //判断该仓库是否在仓库配置表中
  123. boolean = service.IsInConfig(orgId, id)
  124. if boolean == true {
  125. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  126. return
  127. }
  128. err = service.DeleteStorehouse(id)
  129. if err != nil {
  130. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  131. return
  132. }
  133. this.ServeSuccessJSON(map[string]interface{}{
  134. "list": "删除成功",
  135. })
  136. return
  137. }
  138. //仓库名称是否重复
  139. func (this *SecondaryOrderApiController) IsStorehouseName() {
  140. orgId := this.GetAdminUserInfo().CurrentOrgId
  141. storehouse_name := this.GetString("storehouse_name")
  142. check := map[string][]string{
  143. "storehouse_name": {"must", "string", "storehouse_name"},
  144. }
  145. _, err := checkParams(this, &check)
  146. if err != nil {
  147. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  148. return
  149. }
  150. var bo bool
  151. bo, err = service.IsStorehouseName(orgId, storehouse_name)
  152. if bo == true {
  153. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  154. return
  155. }
  156. this.ServeSuccessJSON(map[string]interface{}{
  157. "list": "ok",
  158. })
  159. return
  160. }
  161. //仓库地址是否重复
  162. func (this *SecondaryOrderApiController) IsStorehouseAddress() {
  163. orgId := this.GetAdminUserInfo().CurrentOrgId
  164. storehouse_address := this.GetString("storehouse_address")
  165. check := map[string][]string{
  166. "storehouse_address": {"must", "string", "storehouse_address"},
  167. }
  168. _, err := checkParams(this, &check)
  169. if err != nil {
  170. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  171. return
  172. }
  173. var bo bool
  174. bo, err = service.IsStorehouseAddress(orgId, storehouse_address)
  175. if bo == true {
  176. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  177. return
  178. }
  179. this.ServeSuccessJSON(map[string]interface{}{
  180. "list": "ok",
  181. })
  182. return
  183. }
  184. //分页
  185. func (this *SecondaryOrderApiController) StorehouseList() {
  186. adminUserInfo := this.GetAdminUserInfo()
  187. page, _ := this.GetInt64("page") //页码
  188. limit, _ := this.GetInt64("limit") //每一页查出来的条数
  189. check := map[string][]string{
  190. "page": {"must", "string", "page"},
  191. "limit": {"must", "string", "limit"},
  192. }
  193. _, err := checkParams(this, &check)
  194. keyword := this.GetString("keyword")
  195. orgId := this.GetAdminUserInfo().CurrentOrgId
  196. if err != nil {
  197. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  198. }
  199. namemap := make(map[int64]string)
  200. //根据管理员id获取管理员
  201. viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  202. for _, v := range viewModels {
  203. namemap[int64(v.AdminUserId)] = v.UserName
  204. }
  205. slicekey := make([]int64, 0)
  206. if len(keyword) > 0 {
  207. for k, v := range namemap {
  208. res := strings.Contains(v, keyword)
  209. if res == true {
  210. slicekey = append(slicekey, k)
  211. }
  212. }
  213. }
  214. //获取分页的数据
  215. list, total, err := service.StorehouseList(page, limit, orgId, keyword, slicekey)
  216. //分页
  217. type Storehouselist struct {
  218. ID int64
  219. StorehouseCode string //仓库编号
  220. StorehouseName string //仓库名称
  221. StorehouseAddress string //仓库地址
  222. StorehouseStatus int64 //仓库状态
  223. Status int64 //数据状态
  224. StorehouseAdminId int64 //仓库管理员id
  225. StorehouseAdminName string //仓库管理员名字
  226. UserOrgId int64
  227. }
  228. //初始化该结构体
  229. tmplist := []*Storehouselist{}
  230. for i := 0; i < len(list); i++ {
  231. tlist := &Storehouselist{
  232. list[i].ID,
  233. list[i].StorehouseCode,
  234. list[i].StorehouseName,
  235. list[i].StorehouseAddress,
  236. list[i].StorehouseStatus,
  237. list[i].Status,
  238. list[i].StorehouseAdminId,
  239. "",
  240. list[i].UserOrgId,
  241. }
  242. tmplist = append(tmplist, tlist)
  243. }
  244. for _, v := range tmplist {
  245. if k, ok := namemap[v.StorehouseAdminId]; ok {
  246. v.StorehouseAdminName = k
  247. } else {
  248. v.StorehouseAdminName = "超级管理员"
  249. }
  250. }
  251. this.ServeSuccessJSON(map[string]interface{}{
  252. "list": tmplist,
  253. "total": total,
  254. })
  255. }
  256. //新增仓库
  257. func (this *SecondaryOrderApiController) AddStorehouse() {
  258. orgId := this.GetAdminUserInfo().CurrentOrgId
  259. dataBody := make(map[string]interface{}, 0)
  260. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  261. if err != nil {
  262. utils.ErrorLog(err.Error())
  263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  264. return
  265. }
  266. var storehouse_status, admin_id int64
  267. tmpstatus := dataBody["storehouse_status"]
  268. tmpid := dataBody["storehouse_admin_id"] //管理员id
  269. if tmpstatus == nil {
  270. storehouse_status = 1
  271. } else {
  272. storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
  273. }
  274. if tmpid == nil {
  275. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
  276. return
  277. } else {
  278. admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
  279. }
  280. switch {
  281. case dataBody["storehouse_code"] == nil:
  282. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库编号不能为空")
  283. return
  284. case dataBody["storehouse_name"] == nil:
  285. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  286. return
  287. case dataBody["storehouse_address"] == nil:
  288. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  289. return
  290. }
  291. code := dataBody["storehouse_code"].(string) //仓库编号
  292. name := dataBody["storehouse_name"].(string) //仓库名称
  293. address := dataBody["storehouse_address"].(string) //地址
  294. switch {
  295. case name == "":
  296. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  297. return
  298. case address == "":
  299. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  300. return
  301. }
  302. //判断仓库名称是否重复
  303. var bo bool
  304. bo, err = service.IsStorehouseName(orgId, name)
  305. if bo == true {
  306. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  307. return
  308. }
  309. //判断仓库地址是否重复
  310. bo, err = service.IsStorehouseAddress(orgId, address)
  311. if bo == true {
  312. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  313. return
  314. }
  315. storehouse := models.Storehouse{
  316. StorehouseCode: code,
  317. StorehouseName: name,
  318. StorehouseAddress: address,
  319. StorehouseStatus: storehouse_status,
  320. UserOrgId: orgId,
  321. Status: 1,
  322. StorehouseAdminId: admin_id,
  323. Ctime: time.Now().Unix(),
  324. }
  325. var shiwu string
  326. shiwu, err = service.AddStroehouse(storehouse)
  327. if err != nil {
  328. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
  329. return
  330. }
  331. this.ServeSuccessJSON(map[string]interface{}{
  332. "list": "保存成功",
  333. "shiwu": shiwu,
  334. })
  335. return
  336. }
  337. //修改仓库
  338. func (this *SecondaryOrderApiController) UpdateStorehouse() {
  339. orgId := this.GetAdminUserInfo().CurrentOrgId
  340. dataBody := make(map[string]interface{}, 0)
  341. //orgId := this.GetAdminUserInfo().CurrentOrgId
  342. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  343. if err != nil {
  344. utils.ErrorLog(err.Error())
  345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  346. return
  347. }
  348. var storehouse_status, admin_id int64
  349. tmpstatus := dataBody["storehouse_status"]
  350. tmpid := dataBody["storehouse_admin_id"]
  351. if tmpstatus == nil {
  352. storehouse_status = 1
  353. } else {
  354. storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
  355. }
  356. if tmpid == nil {
  357. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
  358. return
  359. } else {
  360. admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
  361. }
  362. switch {
  363. case dataBody["id"] == nil:
  364. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库id不能为空")
  365. return
  366. case dataBody["storehouse_name"] == nil:
  367. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  368. return
  369. case dataBody["storehouse_address"] == nil:
  370. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  371. return
  372. }
  373. id := int64(dataBody["id"].(float64))
  374. name := dataBody["storehouse_name"].(string) //仓库名称
  375. address := dataBody["storehouse_address"].(string) //地址
  376. //查询当前仓库状态,根据当前状态判断是否需要更改
  377. list, errs := service.GetOneStorehouse(id, orgId)
  378. if errs != nil {
  379. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  380. return
  381. }
  382. if storehouse_status != list.StorehouseStatus && storehouse_status == 0 {
  383. //判断该仓库的库存是否为零
  384. boolean := service.IsStorehouseNil(id, orgId)
  385. if boolean == false {
  386. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  387. return
  388. }
  389. //判断该仓库是否在仓库配置表中
  390. boolean = service.IsInConfig(orgId, id)
  391. if boolean == true {
  392. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  393. return
  394. }
  395. }
  396. //判断仓库名称是否重复
  397. var bo bool
  398. bo, err = service.IsStorehouseNameUp(orgId, id, name)
  399. if bo == true {
  400. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  401. return
  402. }
  403. //判断仓库地址是否重复
  404. bo, err = service.IsStorehouseAddressUp(orgId, id, address)
  405. if bo == true {
  406. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  407. return
  408. }
  409. storehouse := models.Storehouse{
  410. ID: id,
  411. StorehouseName: name,
  412. StorehouseAddress: address,
  413. StorehouseStatus: storehouse_status,
  414. StorehouseAdminId: admin_id,
  415. Mtime: time.Now().Unix(),
  416. }
  417. err = service.UpdateStroehouse(storehouse)
  418. if err != nil {
  419. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
  420. return
  421. }
  422. this.ServeSuccessJSON(map[string]interface{}{
  423. "list": "保存成功",
  424. })
  425. return
  426. }
  427. func (this *SecondaryOrderApiController) GetSencondeGoodList() {
  428. orgId := this.GetAdminUserInfo().CurrentOrgId
  429. houseList, _ := service.GetAllStoreHouseListThree(orgId)
  430. this.ServeSuccessJSON(map[string]interface{}{
  431. "houseList": houseList,
  432. })
  433. return
  434. }
  435. func (this *SecondaryOrderApiController) SaveSencondOrder() {
  436. start_date := this.GetString("record_date")
  437. storehouse_in_id, _ := this.GetInt64("storehouse_in_id")
  438. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  439. fmt.Println(storehouse_in_id, storehouse_out_id)
  440. timeLayout := "2006-01-02"
  441. loc, _ := time.LoadLocation("Local")
  442. var startDate int64
  443. if len(start_date) > 0 {
  444. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  445. if err != nil {
  446. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  447. return
  448. }
  449. startDate = theTime.Unix()
  450. }
  451. //生成购货订单
  452. timeStr := time.Now().Format("2006-01-02")
  453. timeArr := strings.Split(timeStr, "-")
  454. orgId := this.GetAdminUserInfo().CurrentOrgId
  455. warehousing_order := "DB1010" + timeArr[0] + timeArr[1] + timeArr[2] + fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000))
  456. recordDateStr := time.Now().Format("2006-01-02")
  457. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  458. record_date := recordDate.Unix()
  459. creater := this.GetAdminUserInfo().AdminUser.Id
  460. warehouse := models.XtSecondWarehouse{
  461. SecondOrderNumber: warehousing_order,
  462. Creater: creater,
  463. RecordDate: startDate,
  464. Checker: 0,
  465. IsCheck: 2,
  466. UserOrgId: orgId,
  467. Status: 1,
  468. Ctime: time.Now().Unix(),
  469. StorehouseInId: storehouse_in_id,
  470. StorehouseOutId: storehouse_out_id,
  471. }
  472. //查询改订单号是否存在
  473. _, errcode := service.GetSecondWarehouseByNumber(orgId, warehousing_order)
  474. if errcode == gorm.ErrRecordNotFound {
  475. service.CreateSecondeWarehouse(warehouse)
  476. } else if errcode == nil {
  477. order := "DB1010" + timeArr[0] + timeArr[1] + timeArr[2] + fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000))
  478. warehouse.SecondOrderNumber = order
  479. service.CreateSecondeWarehouse(warehouse)
  480. }
  481. secondWarehouse, _ := service.GetLastSecondWarehouse(orgId)
  482. var warehousingInfo []*models.XtSecondWarehouseInfo
  483. dataBody := make(map[string]interface{}, 0)
  484. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  485. if err != nil {
  486. utils.ErrorLog(err.Error())
  487. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  488. return
  489. }
  490. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  491. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  492. if len(thisStockIn) > 0 {
  493. for _, item := range thisStockIn {
  494. items := item.(map[string]interface{})
  495. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  496. utils.ErrorLog("project_id")
  497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  498. return
  499. }
  500. project_id := int64(items["project_id"].(float64))
  501. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  502. utils.ErrorLog("name")
  503. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  504. return
  505. }
  506. project_name := items["name"].(string)
  507. if items["project_type"] == nil || reflect.TypeOf(items["project_type"]).String() != "string" {
  508. utils.ErrorLog("project_type")
  509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  510. return
  511. }
  512. project_type := items["project_type"].(string)
  513. if items["second_specification_name"] == nil || reflect.TypeOf(items["second_specification_name"]).String() != "string" {
  514. utils.ErrorLog("second_specification_name")
  515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  516. return
  517. }
  518. second_specification_name := items["second_specification_name"].(string)
  519. if items["sencond_unit"] == nil || reflect.TypeOf(items["sencond_unit"]).String() != "string" {
  520. utils.ErrorLog("sencond_unit")
  521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  522. return
  523. }
  524. sencond_unit := items["sencond_unit"].(string)
  525. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  526. utils.ErrorLog("count")
  527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  528. return
  529. }
  530. count := int64(items["count"].(float64))
  531. if items["is_source"] == nil || reflect.TypeOf(items["is_source"]).String() != "float64" {
  532. utils.ErrorLog("is_source")
  533. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  534. return
  535. }
  536. is_source := int64(items["is_source"].(float64))
  537. if items["second_total"] == nil || reflect.TypeOf(items["second_total"]).String() != "string" {
  538. utils.ErrorLog("second_total")
  539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  540. return
  541. }
  542. second_total := items["second_total"].(string)
  543. if items["remake"] == nil || reflect.TypeOf(items["remake"]).String() != "string" {
  544. utils.ErrorLog("remake")
  545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  546. return
  547. }
  548. remake := items["remake"].(string)
  549. if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "float64" {
  550. utils.ErrorLog("min_price")
  551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  552. return
  553. }
  554. min_price := items["min_price"].(float64)
  555. info := &models.XtSecondWarehouseInfo{
  556. ProjectName: project_name,
  557. SecondSpecificationName: second_specification_name,
  558. ProjectType: project_type,
  559. SencondUnit: sencond_unit,
  560. Count: count,
  561. SecondTotal: second_total,
  562. SecondOrderNumber: secondWarehouse.SecondOrderNumber,
  563. RecordDate: record_date,
  564. StorehouseInId: storehouse_in_id,
  565. StorehouseOutId: storehouse_out_id,
  566. Creater: creater,
  567. ProjectId: project_id,
  568. Remake: remake,
  569. UserOrgId: orgId,
  570. Status: 1,
  571. Ctime: time.Now().Unix(),
  572. Mtime: 0,
  573. MinPrice: min_price,
  574. IsSource: is_source,
  575. WarehouseId: secondWarehouse.ID,
  576. }
  577. warehousingInfo = append(warehousingInfo, info)
  578. }
  579. }
  580. }
  581. for _, item := range warehousingInfo {
  582. service.CreateSencondWarehousingInfo(item)
  583. }
  584. //获取最后一条入库单
  585. lastSecondWarehouse, _ := service.GetLastSecondWarehouse(orgId)
  586. this.ServeSuccessJSON(map[string]interface{}{
  587. "warehousingInfo": warehousingInfo,
  588. "id": lastSecondWarehouse.ID,
  589. })
  590. return
  591. }
  592. func (this *SecondaryOrderApiController) GetAllSecondeOrderList() {
  593. check_id, _ := this.GetInt64("check_id")
  594. start_time := this.GetString("start_time")
  595. timeLayout := "2006-01-02"
  596. loc, _ := time.LoadLocation("Local")
  597. var startTime int64
  598. if len(start_time) > 0 {
  599. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  600. if err != nil {
  601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  602. return
  603. }
  604. startTime = theTime.Unix()
  605. }
  606. end_time := this.GetString("end_time")
  607. var endTime int64
  608. if len(end_time) > 0 {
  609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  610. if err != nil {
  611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  612. return
  613. }
  614. endTime = theTime.Unix()
  615. }
  616. keyword := this.GetString("keyword")
  617. page, _ := this.GetInt64("page")
  618. limit, _ := this.GetInt64("limit")
  619. orgId := this.GetAdminUserInfo().CurrentOrgId
  620. list, total, _ := service.GetAllSecondeOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
  621. houseList, _ := service.GetAllStoreHouseList(orgId)
  622. appId := this.GetAdminUserInfo().CurrentAppId
  623. doctor, _ := service.GetAllDoctorListSix(orgId, appId)
  624. this.ServeSuccessJSON(map[string]interface{}{
  625. "list": list,
  626. "total": total,
  627. "houseList": houseList,
  628. "doctorList": doctor,
  629. })
  630. return
  631. }
  632. func (this *SecondaryOrderApiController) GetSencondOrderDetail() {
  633. id, _ := this.GetInt64("id")
  634. orgId := this.GetAdminUserInfo().CurrentOrgId
  635. warehouse, _ := service.GetSecondWarehouseOrderById(id)
  636. //获取药品库数据
  637. baseList, _ := service.GetSupplyDrugListOne(orgId, warehouse.StorehouseOutId)
  638. goodList, _ := service.GetSupplyGoodListOne(orgId, warehouse.StorehouseOutId)
  639. goodTypeList, _ := service.GetAllGoodType(orgId)
  640. configlist, _ := service.GetAllStoreHouseConfig(orgId)
  641. var drugType = "药品类型"
  642. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  643. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  644. list, _ := service.GetSencondOrderDetail(id, orgId)
  645. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  646. this.ServeSuccessJSON(map[string]interface{}{
  647. "list": list,
  648. "warehouse": warehouse,
  649. "drugList": baseList,
  650. "goodList": goodList,
  651. "goodTypeList": goodTypeList,
  652. "drugTypeList": drugTypeList,
  653. "configlist": configlist,
  654. "manufacturerList": manufacturerList,
  655. })
  656. return
  657. }
  658. func (this *SecondaryOrderApiController) UpdateSencondOrder() {
  659. warehouse_id, _ := this.GetInt64("id")
  660. start_date := this.GetString("record_date")
  661. storehouse_in_id, _ := this.GetInt64("storehouse_in_id")
  662. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  663. fmt.Println(storehouse_in_id, storehouse_out_id)
  664. timeLayout := "2006-01-02"
  665. loc, _ := time.LoadLocation("Local")
  666. var startDate int64
  667. if len(start_date) > 0 {
  668. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  669. if err != nil {
  670. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  671. return
  672. }
  673. startDate = theTime.Unix()
  674. }
  675. recordDateStr := time.Now().Format("2006-01-02")
  676. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  677. record_date := recordDate.Unix()
  678. orgId := this.GetAdminUserInfo().CurrentOrgId
  679. creater := this.GetAdminUserInfo().AdminUser.Id
  680. warehouse := models.XtSecondWarehouse{
  681. StorehouseInId: storehouse_in_id,
  682. StorehouseOutId: storehouse_out_id,
  683. RecordDate: startDate,
  684. }
  685. service.UpdateModifySecondWarehouse(warehouse_id, warehouse)
  686. warehouseInfo, _ := service.GetSecondWarehouseOrderById(warehouse_id)
  687. var warehousingInfo []*models.XtSecondWarehouseInfo
  688. var updateWarehousingInfo []*models.XtSecondWarehouseInfo
  689. dataBody := make(map[string]interface{}, 0)
  690. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  691. if err != nil {
  692. utils.ErrorLog(err.Error())
  693. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  694. return
  695. }
  696. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  697. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  698. if len(thisStockIn) > 0 {
  699. for _, item := range thisStockIn {
  700. items := item.(map[string]interface{})
  701. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  702. utils.ErrorLog("id")
  703. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  704. return
  705. }
  706. id := int64(items["id"].(float64))
  707. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  708. utils.ErrorLog("project_id")
  709. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  710. return
  711. }
  712. project_id := int64(items["project_id"].(float64))
  713. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  714. utils.ErrorLog("name")
  715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  716. return
  717. }
  718. project_name := items["name"].(string)
  719. if items["project_type"] == nil || reflect.TypeOf(items["project_type"]).String() != "string" {
  720. utils.ErrorLog("project_type")
  721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  722. return
  723. }
  724. project_type := items["project_type"].(string)
  725. if items["second_specification_name"] == nil || reflect.TypeOf(items["second_specification_name"]).String() != "string" {
  726. utils.ErrorLog("second_specification_name")
  727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  728. return
  729. }
  730. second_specification_name := items["second_specification_name"].(string)
  731. if items["sencond_unit"] == nil || reflect.TypeOf(items["sencond_unit"]).String() != "string" {
  732. utils.ErrorLog("sencond_unit")
  733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  734. return
  735. }
  736. sencond_unit := items["sencond_unit"].(string)
  737. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  738. utils.ErrorLog("count")
  739. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  740. return
  741. }
  742. count := int64(items["count"].(float64))
  743. if items["is_source"] == nil || reflect.TypeOf(items["is_source"]).String() != "float64" {
  744. utils.ErrorLog("is_source")
  745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  746. return
  747. }
  748. is_source := int64(items["is_source"].(float64))
  749. if items["second_total"] == nil || reflect.TypeOf(items["second_total"]).String() != "string" {
  750. utils.ErrorLog("second_total")
  751. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  752. return
  753. }
  754. second_total := items["second_total"].(string)
  755. if items["remake"] == nil || reflect.TypeOf(items["remake"]).String() != "string" {
  756. utils.ErrorLog("remake")
  757. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  758. return
  759. }
  760. remake := items["remake"].(string)
  761. if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "float64" {
  762. utils.ErrorLog("min_price")
  763. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  764. return
  765. }
  766. min_price := items["min_price"].(float64)
  767. if id == 0 {
  768. info := &models.XtSecondWarehouseInfo{
  769. ProjectName: project_name,
  770. SecondSpecificationName: second_specification_name,
  771. ProjectType: project_type,
  772. SencondUnit: sencond_unit,
  773. Count: count,
  774. SecondTotal: second_total,
  775. RecordDate: record_date,
  776. StorehouseInId: storehouse_in_id,
  777. StorehouseOutId: storehouse_out_id,
  778. Creater: creater,
  779. ProjectId: project_id,
  780. Remake: remake,
  781. UserOrgId: orgId,
  782. Status: 1,
  783. Ctime: time.Now().Unix(),
  784. Mtime: 0,
  785. MinPrice: min_price,
  786. IsSource: is_source,
  787. WarehouseId: warehouse_id,
  788. SecondOrderNumber: warehouseInfo.SecondOrderNumber,
  789. }
  790. warehousingInfo = append(warehousingInfo, info)
  791. }
  792. if id > 0 {
  793. updateInfo := &models.XtSecondWarehouseInfo{
  794. ID: id,
  795. ProjectName: project_name,
  796. SecondSpecificationName: second_specification_name,
  797. ProjectType: project_type,
  798. SencondUnit: sencond_unit,
  799. Count: count,
  800. SecondTotal: second_total,
  801. SecondOrderNumber: warehouse.SecondOrderNumber,
  802. RecordDate: record_date,
  803. StorehouseInId: storehouse_in_id,
  804. StorehouseOutId: storehouse_out_id,
  805. Creater: creater,
  806. ProjectId: project_id,
  807. Remake: remake,
  808. UserOrgId: orgId,
  809. MinPrice: min_price,
  810. IsSource: is_source,
  811. }
  812. updateWarehousingInfo = append(updateWarehousingInfo, updateInfo)
  813. }
  814. }
  815. }
  816. }
  817. for _, item := range warehousingInfo {
  818. service.CreateSencondWarehousingInfo(item)
  819. }
  820. for _, item := range updateWarehousingInfo {
  821. service.UpdateStoreWarehousing(item)
  822. }
  823. this.ServeSuccessJSON(map[string]interface{}{
  824. "warehousingInfo": warehousingInfo,
  825. })
  826. return
  827. }
  828. func (this *SecondaryOrderApiController) GetSecondOrderById() {
  829. id, _ := this.GetInt64("id")
  830. orgId := this.GetAdminUserInfo().CurrentOrgId
  831. warehouse, _ := service.GetSecondWarehouseOrderById(id)
  832. list, _ := service.GetSencondOrderDetail(id, orgId)
  833. appId := this.GetAdminUserInfo().CurrentAppId
  834. doctor, _ := service.GetAllDoctorSix(orgId, appId)
  835. houseList, _ := service.GetAllStoreHouseList(orgId)
  836. this.ServeSuccessJSON(map[string]interface{}{
  837. "warehouse": warehouse,
  838. "list": list,
  839. "doctorList": doctor,
  840. "houseList": houseList,
  841. })
  842. return
  843. }
  844. func (this *SecondaryOrderApiController) CheckSecondOrer() {
  845. ids := this.GetString("ids")
  846. if len(ids) == 0 {
  847. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  848. return
  849. }
  850. idArray := strings.Split(ids, ",")
  851. orgId := this.GetAdminUserInfo().CurrentOrgId
  852. creater := this.GetAdminUserInfo().AdminUser.Id
  853. //根据订单id获取商品详情
  854. list, _ := service.GetSecondOrderList(idArray, orgId)
  855. for _, item := range list {
  856. if item.IsSource == 1 {
  857. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  858. //查询该仓库的药品库存是否满足调出数量
  859. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  860. var total int64
  861. var total_count int64
  862. for _, it := range drugInfoList {
  863. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  864. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  865. }
  866. }
  867. for _, it := range drugInfoList {
  868. total += it.StockMaxNumber + it.StockMinNumber
  869. }
  870. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  871. total_count = item.Count * medical.MinNumber
  872. }
  873. if item.SencondUnit == medical.MinUnit {
  874. total_count = item.Count
  875. }
  876. if total_count > total {
  877. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  878. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseOutId, item.UserOrgId)
  879. this.ServeSuccessJSON(map[string]interface{}{
  880. "msg": "3",
  881. "drug_name": goodObj.DrugName,
  882. "dose": goodObj.Dose,
  883. "dose_unit": goodObj.DoseUnit,
  884. "min_number": goodObj.MinNumber,
  885. "min_unit": goodObj.MinUnit,
  886. "max_unit": goodObj.MaxUnit,
  887. "storehose_name": storehouse.StorehouseName,
  888. })
  889. return
  890. }
  891. }
  892. if item.IsSource == 2 {
  893. //查询该仓库的耗材库存是否满足调出数量
  894. var total int64
  895. infoList, _ := service.GetWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  896. for _, it := range infoList {
  897. total += it.StockCount
  898. }
  899. if item.Count > total {
  900. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseOutId, item.UserOrgId)
  901. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  902. this.ServeSuccessJSON(map[string]interface{}{
  903. "msg": "2",
  904. "good_name": goodObj.GoodName,
  905. "specification_name": goodObj.SpecificationName,
  906. "storehose_name": storehouse.StorehouseName,
  907. })
  908. return
  909. }
  910. }
  911. }
  912. err := service.UpdateStoreOrderByArray(idArray, orgId, creater)
  913. //如果审核成功
  914. if err == nil {
  915. //调用出库接口
  916. timeStr := time.Now().Format("2006-01-02")
  917. timeArr := strings.Split(timeStr, "-")
  918. total, _ := service.FindAllWarehouseOut(orgId)
  919. total = total + 1
  920. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  921. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  922. number = number + total
  923. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  924. operation_time := time.Now().Unix()
  925. creater := this.GetAdminUserInfo().AdminUser.Id
  926. recordDateStr := time.Now().Format("2006-01-02")
  927. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  928. record_date := recordDate.Unix()
  929. totals, _ := service.FindAllWarehouseTotal(orgId)
  930. totals = totals + 1
  931. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(totals, 10)
  932. for _, item := range list {
  933. //药品
  934. if item.IsSource == 1 {
  935. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  936. //查询该仓库的药品库存是否满足调出数量
  937. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  938. var total int64
  939. var total_count int64
  940. for _, it := range drugInfoList {
  941. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  942. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  943. }
  944. }
  945. for _, it := range drugInfoList {
  946. total += it.StockMaxNumber + it.StockMinNumber
  947. }
  948. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  949. total_count = item.Count * medical.MinNumber
  950. }
  951. if item.SencondUnit == medical.MinUnit {
  952. total_count = item.Count
  953. }
  954. if total_count <= total {
  955. drug_total, _ := service.FindAllDrugWarehouseOut(orgId)
  956. drug_total = drug_total + 1
  957. drug_warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  958. number, _ := strconv.ParseInt(drug_warehousing_out_order, 10, 64)
  959. number = number + drug_total
  960. drug_warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  961. operation_time := time.Now().Unix()
  962. drugWarehouseOut := models.DrugWarehouseOut{
  963. WarehouseOutOrderNumber: drug_warehousing_out_order,
  964. OperationTime: operation_time,
  965. OrgId: orgId,
  966. Creater: creater,
  967. Ctime: time.Now().Unix(),
  968. Status: 1,
  969. WarehouseOutTime: record_date,
  970. Type: 2,
  971. StorehouseId: item.StorehouseOutId,
  972. SecondWarehouseId: item.WarehouseId,
  973. IsSys: 12,
  974. }
  975. _, drugerrcodes := service.GetDrugWarehouseBySyS(orgId, 12, item.WarehouseId, record_date)
  976. if drugerrcodes == gorm.ErrRecordNotFound {
  977. service.AddSigleDrugWarehouseOut(&drugWarehouseOut)
  978. }
  979. drugOut, _ := service.GetLastDrugWarehouseOutById(12, item.WarehouseId, orgId, record_date)
  980. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  981. WarehouseOutOrderNumber: drugOut.WarehouseOutOrderNumber,
  982. WarehouseOutId: drugOut.ID,
  983. DrugId: item.ProjectId,
  984. Count: item.Count,
  985. Price: medical.RetailPrice,
  986. TotalPrice: 0,
  987. Status: 1,
  988. Ctime: time.Now().Unix(),
  989. Remark: item.Remake,
  990. OrgId: orgId,
  991. Type: 2,
  992. Manufacturer: 0,
  993. Dealer: 0,
  994. RetailPrice: item.MinPrice,
  995. RetailTotalPrice: 0,
  996. CountUnit: item.SencondUnit,
  997. ExpiryDate: 0,
  998. ProductDate: 0,
  999. Number: "",
  1000. BatchNumber: "",
  1001. IsSys: 0,
  1002. WarehouseInfoId: 0,
  1003. StorehouseId: item.StorehouseOutId,
  1004. SecondWarehouseInfoId: item.ID,
  1005. }
  1006. drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
  1007. drug_in_total, _ := service.FindAllWarehouseTotalOne(orgId)
  1008. drug_in_total = drug_in_total + 1
  1009. warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(drug_in_total, 10)
  1010. drug_warehousing := models.DrugWarehouse{
  1011. WarehousingOrder: warehousing_order,
  1012. OperationTime: operation_time,
  1013. OrgId: orgId,
  1014. Creater: creater,
  1015. Ctime: time.Now().Unix(),
  1016. Status: 1,
  1017. WarehousingTime: record_date,
  1018. Type: 1,
  1019. StorehouseId: item.StorehouseInId,
  1020. IsSys: 13,
  1021. SecondWarehouseId: item.WarehouseId,
  1022. }
  1023. //查询该调拨单是否有生成入库单
  1024. _, drugerrcodess := service.GetDrugWarehouseingBySys(13, item.WarehouseId, orgId, record_date)
  1025. if drugerrcodess == gorm.ErrRecordNotFound {
  1026. service.CreateDrugWaresing(drug_warehousing)
  1027. }
  1028. drugInfoObj, _ := service.GetLastDrugWarehouseBySys(13, item.WarehouseId, orgId, record_date)
  1029. drugwarehouseInfo := &models.DrugWarehouseInfo{
  1030. WarehousingOrder: drugInfoObj.WarehousingOrder,
  1031. WarehousingId: drugInfoObj.ID,
  1032. DrugId: item.ProjectId,
  1033. Number: "",
  1034. ProductDate: 0,
  1035. ExpiryDate: 0,
  1036. WarehousingCount: 0,
  1037. Price: 0,
  1038. TotalPrice: 0,
  1039. Status: 1,
  1040. Ctime: time.Now().Unix(),
  1041. Remark: "",
  1042. OrgId: orgId,
  1043. Type: 2,
  1044. Manufacturer: 0,
  1045. Dealer: 0,
  1046. StockMaxNumber: 0,
  1047. RetailTotalPrice: 0,
  1048. BatchNumber: "",
  1049. MaxUnit: "",
  1050. MinUnit: "",
  1051. RetailPrice: 0,
  1052. StorehouseId: item.StorehouseInId,
  1053. SecondWarehouseInfoId: item.ID,
  1054. }
  1055. service.AutoDrugDeliverInfoTwelve(orgId, item.Count, &drugWarehouseOut, &drup, warehouseOutInfo, drugwarehouseInfo)
  1056. //查询默认仓库
  1057. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1058. //查询默认仓库剩余多少库存
  1059. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ProjectId)
  1060. var sum_count int64
  1061. var sum_in_count int64
  1062. for _, it := range list {
  1063. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  1064. if it.MaxUnit == baseDrug.MaxUnit {
  1065. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  1066. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  1067. }
  1068. sum_count += it.StockMaxNumber + it.StockMinNumber
  1069. sum_in_count += it.WarehousingCount
  1070. }
  1071. service.UpdateMedicalSumCount(item.ProjectId, sum_count, sum_in_count, item.UserOrgId)
  1072. }
  1073. }
  1074. //耗材
  1075. if item.IsSource == 2 {
  1076. //查询该仓库的耗材库存是否满足调出数量
  1077. var total int64
  1078. infoList, _ := service.GetWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  1079. for _, it := range infoList {
  1080. total += it.StockCount
  1081. }
  1082. //满足调拨
  1083. if item.Count <= total {
  1084. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1085. warehouseOut := models.WarehouseOut{
  1086. WarehouseOutOrderNumber: warehousing_out_order,
  1087. OperationTime: operation_time,
  1088. OrgId: orgId,
  1089. Creater: creater,
  1090. Ctime: time.Now().Unix(),
  1091. Status: 1,
  1092. WarehouseOutTime: record_date,
  1093. Type: 1,
  1094. StorehouseId: item.StorehouseOutId,
  1095. IsSys: 12,
  1096. SecondWarehouseId: item.WarehouseId,
  1097. }
  1098. //查询今日是否存在调拨出库
  1099. _, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
  1100. if errcodes == gorm.ErrRecordNotFound {
  1101. service.AddSigleWarehouseOut(&warehouseOut)
  1102. }
  1103. out, _ := service.GetLastWarehouseOutBySys(12, orgId, record_date, item.WarehouseId)
  1104. warehouseOutInfo := &models.WarehouseOutInfo{
  1105. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1106. WarehouseOutId: out.ID,
  1107. GoodId: item.ProjectId,
  1108. GoodTypeId: goodObj.GoodTypeId,
  1109. Count: item.Count,
  1110. Price: item.MinPrice,
  1111. TotalPrice: 0,
  1112. Status: 1,
  1113. Ctime: time.Now().Unix(),
  1114. Remark: item.Remake,
  1115. OrgId: orgId,
  1116. Type: 1,
  1117. Manufacturer: 0,
  1118. Number: "",
  1119. ExpiryDate: 0,
  1120. ProductDate: 0,
  1121. Dealer: 0,
  1122. LicenseNumber: "",
  1123. WarehouseInfotId: 0,
  1124. StorehouseId: item.StorehouseOutId,
  1125. SecondWarehouseInfoId: item.ID,
  1126. }
  1127. //入库操作
  1128. warehousing := models.Warehousing{
  1129. WarehousingOrder: warehousing_order,
  1130. OperationTime: operation_time,
  1131. OrgId: orgId,
  1132. Creater: creater,
  1133. Ctime: time.Now().Unix(),
  1134. Status: 1,
  1135. WarehousingTime: record_date,
  1136. Type: 1,
  1137. StorehouseId: item.StorehouseInId,
  1138. IsSys: 12,
  1139. SecondWarehouseId: item.WarehouseId,
  1140. }
  1141. //查询该调拨单是否有生成入库单
  1142. _, errcodess := service.GetWarehouseBySecondWarehouseId(12, item.WarehouseId, orgId, record_date)
  1143. if errcodess == gorm.ErrRecordNotFound {
  1144. service.AddSigleWarehouse(&warehousing)
  1145. }
  1146. infoObj, _ := service.GetLastWarehouseById(12, item.WarehouseId, orgId, record_date)
  1147. warehouseInfo := &models.WarehousingInfo{
  1148. WarehousingOrder: infoObj.WarehousingOrder,
  1149. WarehousingId: infoObj.ID,
  1150. GoodId: item.ProjectId,
  1151. Number: "",
  1152. GoodTypeId: goodObj.GoodTypeId,
  1153. ProductDate: 0,
  1154. ExpiryDate: 0,
  1155. WarehousingCount: item.Count,
  1156. Price: goodObj.BuyPrice,
  1157. TotalPrice: 0,
  1158. Status: 1,
  1159. Ctime: time.Now().Unix(),
  1160. Remark: item.Remake,
  1161. OrgId: orgId,
  1162. Type: 1,
  1163. Manufacturer: 0,
  1164. StockCount: item.Count,
  1165. Dealer: 0,
  1166. LicenseNumber: "",
  1167. PackingPrice: item.MinPrice,
  1168. StorehouseId: item.StorehouseInId,
  1169. SecondWarehouseInfoId: item.ID,
  1170. }
  1171. //出库逻辑
  1172. parseDateErr := service.ConsumablesDeliveryTwelve(orgId, record_date, warehouseOutInfo, &warehouseOut, item.Count, creater, warehouseInfo)
  1173. fmt.Println(parseDateErr)
  1174. }
  1175. //查询默认仓库
  1176. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1177. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId)
  1178. var sum_count int64
  1179. var sum_in_count int64
  1180. for _, it := range goodList {
  1181. sum_count += it.StockCount
  1182. sum_in_count += it.WarehousingCount
  1183. }
  1184. service.UpdateGoodByGoodId(item.ProjectId, sum_count, sum_in_count, item.UserOrgId)
  1185. }
  1186. }
  1187. }
  1188. this.ServeSuccessJSON(map[string]interface{}{
  1189. "msg": 1,
  1190. })
  1191. return
  1192. }
  1193. func (this *SecondaryOrderApiController) DeleteStorehouseList() {
  1194. id, _ := this.GetInt64("id")
  1195. err := service.DeleteStorehouseList(id)
  1196. if err == nil {
  1197. returnData := make(map[string]interface{}, 0)
  1198. returnData["msg"] = "ok"
  1199. this.ServeSuccessJSON(returnData)
  1200. return
  1201. } else {
  1202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1203. }
  1204. }
  1205. func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
  1206. ids := this.GetString("ids")
  1207. if len(ids) == 0 {
  1208. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1209. return
  1210. }
  1211. idArray := strings.Split(ids, ",")
  1212. orgId := this.GetAdminUserInfo().CurrentOrgId
  1213. //根据订单id获取商品详情
  1214. list, _ := service.GetSecondOrderList(idArray, orgId)
  1215. //药品
  1216. for _, item := range list {
  1217. //药品
  1218. if item.IsSource == 1 {
  1219. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1220. //查询该仓库的药品库存是否满足调出数量
  1221. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1222. var total int64
  1223. var total_count int64
  1224. for _, it := range drugInfoList {
  1225. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1226. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1227. }
  1228. }
  1229. for _, it := range drugInfoList {
  1230. total += it.StockMaxNumber + it.StockMinNumber
  1231. }
  1232. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1233. total_count = item.Count * medical.MinNumber
  1234. }
  1235. if item.SencondUnit == medical.MinUnit {
  1236. total_count = item.Count
  1237. }
  1238. if total_count > total {
  1239. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  1240. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
  1241. this.ServeSuccessJSON(map[string]interface{}{
  1242. "msg": "3",
  1243. "drug_name": goodObj.DrugName,
  1244. "dose": goodObj.Dose,
  1245. "dose_unit": goodObj.DoseUnit,
  1246. "min_number": goodObj.MinNumber,
  1247. "min_unit": goodObj.MinUnit,
  1248. "max_unit": goodObj.MaxUnit,
  1249. "storehose_name": storehouse.StorehouseName,
  1250. })
  1251. return
  1252. }
  1253. }
  1254. //耗材
  1255. if item.IsSource == 2 {
  1256. //查询该仓库的耗材库存是否满足调出数量
  1257. var total int64
  1258. infoList, _ := service.GetWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1259. for _, it := range infoList {
  1260. total += it.StockCount
  1261. }
  1262. if item.Count > total {
  1263. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
  1264. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1265. this.ServeSuccessJSON(map[string]interface{}{
  1266. "msg": "2",
  1267. "good_name": goodObj.GoodName,
  1268. "specification_name": goodObj.SpecificationName,
  1269. "storehose_name": storehouse.StorehouseName,
  1270. })
  1271. return
  1272. }
  1273. }
  1274. }
  1275. //反审核操作
  1276. err := service.ModifyStoreHouseById(idArray, orgId)
  1277. if err != nil {
  1278. this.ServeSuccessJSON(map[string]interface{}{
  1279. "msg": "0",
  1280. })
  1281. return
  1282. }
  1283. for _, item := range list {
  1284. //药品
  1285. if item.IsSource == 1 {
  1286. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1287. //查询该仓库的药品库存是否满足调出数量
  1288. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1289. var total int64
  1290. var total_count int64
  1291. for _, it := range drugInfoList {
  1292. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1293. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1294. }
  1295. }
  1296. for _, it := range drugInfoList {
  1297. total += it.StockMaxNumber + it.StockMinNumber
  1298. }
  1299. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1300. total_count = item.Count * medical.MinNumber
  1301. }
  1302. if item.SencondUnit == medical.MinUnit {
  1303. total_count = item.Count
  1304. }
  1305. if total_count <= total {
  1306. //回退库存,查询该订单出库记录
  1307. drugOutList, _ := service.GetStoreDrugWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
  1308. for _, it := range drugOutList {
  1309. if medical.MaxUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
  1310. //回退库存
  1311. service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
  1312. }
  1313. if medical.MaxUnit == it.CountUnit && medical.MaxUnit == medical.MinUnit {
  1314. //回退库存
  1315. service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
  1316. }
  1317. if medical.MinUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
  1318. service.ModifyDrugStoreWarehouseInfoOne(it.WarehouseInfoId, it.Count)
  1319. }
  1320. //查询入库单
  1321. storeWareing, _ := service.GetStoreDrugWarehouseById(item.WarehouseId, it.OrgId)
  1322. //删除入库单
  1323. service.DeleteStoreWarehousingId(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
  1324. //查询出单
  1325. storeWarehouseOut, _ := service.GetStoreDrugWarehouseOutById(it.WarehouseOutId, it.OrgId)
  1326. //删除出库单
  1327. service.DeleteStoreWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
  1328. }
  1329. }
  1330. //查询默认仓库
  1331. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1332. //查询默认仓库剩余多少库存
  1333. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ProjectId)
  1334. var sum_count int64
  1335. var sum_in_count int64
  1336. for _, it := range list {
  1337. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  1338. if it.MaxUnit == baseDrug.MaxUnit {
  1339. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  1340. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  1341. }
  1342. sum_count += it.StockMaxNumber + it.StockMinNumber
  1343. sum_in_count += it.WarehousingCount
  1344. }
  1345. service.UpdateMedicalSumCount(item.ProjectId, sum_count, sum_in_count, item.UserOrgId)
  1346. }
  1347. //耗材
  1348. if item.IsSource == 2 {
  1349. //查询该仓库的耗材库存是否满足调出数量
  1350. var total int64
  1351. infoList, _ := service.GetWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1352. for _, it := range infoList {
  1353. total += it.StockCount
  1354. }
  1355. //满足调拨
  1356. if item.Count <= total {
  1357. //回退库存,查询该订单出库记录
  1358. outList, _ := service.GetStoreWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
  1359. for _, it := range outList {
  1360. //回退库存
  1361. service.ModifyStoreWarehouseById(it.WarehouseInfotId, it.Count)
  1362. //获取入库单
  1363. storeWareing, _ := service.GetStoreWarehouseById(item.WarehouseId, it.OrgId)
  1364. //删除入库单 入库流水
  1365. service.ModifyStoreWarehouse(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
  1366. //获取出库单
  1367. storeWarehouseOut, _ := service.GetStoreWarehouseOutById(it.WarehouseOutId, it.OrgId)
  1368. //删除出库单
  1369. service.ModifyWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
  1370. }
  1371. }
  1372. //查询默认仓库
  1373. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1374. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId)
  1375. var sum_count int64
  1376. var sum_in_count int64
  1377. for _, it := range goodList {
  1378. sum_count += it.StockCount
  1379. sum_in_count += it.WarehousingCount
  1380. }
  1381. service.UpdateGoodByGoodId(item.ProjectId, sum_count, sum_in_count, item.UserOrgId)
  1382. }
  1383. }
  1384. this.ServeSuccessJSON(map[string]interface{}{
  1385. "msg": "1",
  1386. })
  1387. return
  1388. }
  1389. func (this *SecondaryOrderApiController) GetStoreHouseGoodList() {
  1390. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  1391. orgId := this.GetAdminUserInfo().CurrentOrgId
  1392. //获取药品库数据
  1393. baseList, _ := service.GetSupplyDrugListOne(orgId, storehouse_out_id)
  1394. goodList, _ := service.GetSupplyGoodListOne(orgId, storehouse_out_id)
  1395. goodTypeList, _ := service.GetAllGoodType(orgId)
  1396. configlist, _ := service.GetAllStoreHouseConfig(orgId)
  1397. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1398. var drugType = "药品类型"
  1399. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1400. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  1401. this.ServeSuccessJSON(map[string]interface{}{
  1402. "drugList": baseList,
  1403. "goodList": goodList,
  1404. "goodTypeList": goodTypeList,
  1405. "drugTypeList": drugTypeList,
  1406. "configlist": configlist,
  1407. "manufacturerList": manufacturerList,
  1408. })
  1409. return
  1410. }
  1411. func (this *SecondaryOrderApiController) GetSumSecondCount() {
  1412. project_id, _ := this.GetInt64("project_id")
  1413. sencond_unit := this.GetString("sencond_unit")
  1414. is_source, _ := this.GetInt64("is_source")
  1415. count, _ := this.GetInt64("count")
  1416. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  1417. orgId := this.GetAdminUserInfo().CurrentOrgId
  1418. var sum_in_count int64
  1419. var sum_count int64
  1420. //药品
  1421. if is_source == 1 {
  1422. medical, _ := service.GetBaseDrugMedical(project_id)
  1423. fmt.Println("senconde_unit233223", sencond_unit)
  1424. if sencond_unit == medical.MaxUnit {
  1425. sum_in_count = count * medical.MinNumber
  1426. }
  1427. if sencond_unit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1428. sum_in_count = count
  1429. }
  1430. //查询该药品剩余的库存
  1431. secondCountList, _ := service.GetDrugSumSecondCount(project_id, storehouse_out_id, orgId)
  1432. for _, it := range secondCountList {
  1433. if it.MaxUnit == medical.MaxUnit {
  1434. sum_count += (it.StockMaxNumber * medical.MinNumber) + it.StockMinNumber
  1435. }
  1436. if it.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1437. sum_count += (it.StockMaxNumber + it.StockMinNumber)
  1438. }
  1439. }
  1440. fmt.Println("sum_iin_coutn23232323", sum_in_count)
  1441. fmt.Println("sum_count", sum_count)
  1442. if sum_in_count > sum_count {
  1443. this.ServeSuccessJSON(map[string]interface{}{
  1444. "msg": "2",
  1445. })
  1446. return
  1447. } else {
  1448. this.ServeSuccessJSON(map[string]interface{}{
  1449. "msg": "1",
  1450. })
  1451. return
  1452. }
  1453. }
  1454. //耗材
  1455. if is_source == 2 {
  1456. var sum_good_count int64
  1457. secondCountGoodList, _ := service.GetGoodSumSecondCount(project_id, storehouse_out_id, orgId)
  1458. for _, it := range secondCountGoodList {
  1459. sum_good_count += it.StockCount
  1460. }
  1461. if count > sum_good_count {
  1462. this.ServeSuccessJSON(map[string]interface{}{
  1463. "msg": "2",
  1464. })
  1465. return
  1466. } else {
  1467. this.ServeSuccessJSON(map[string]interface{}{
  1468. "msg": "1",
  1469. })
  1470. return
  1471. }
  1472. }
  1473. }
  1474. func (this *SecondaryOrderApiController) DeleteSecondOrderInfo() {
  1475. id, _ := this.GetInt64("id")
  1476. err := service.DeleteSecondOrderInfo(id)
  1477. if err == nil {
  1478. returnData := make(map[string]interface{}, 0)
  1479. returnData["msg"] = "ok"
  1480. this.ServeSuccessJSON(returnData)
  1481. return
  1482. } else {
  1483. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1484. }
  1485. }
  1486. //查询一条仓库信息
  1487. func (this *SecondaryOrderApiController) GetOneStorehouse() {
  1488. orgId := this.GetAdminUserInfo().CurrentOrgId
  1489. check := map[string][]string{
  1490. "id": {"must", "int", "id"},
  1491. }
  1492. _, err := checkParams(this, &check)
  1493. if err != nil {
  1494. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1495. return
  1496. }
  1497. id, _ := this.GetInt64("id")
  1498. var list models.Storehouse
  1499. list, err = service.GetOneStorehouse(id, orgId)
  1500. if err != nil {
  1501. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1502. return
  1503. }
  1504. this.ServeSuccessJSON(map[string]interface{}{
  1505. "list": list,
  1506. })
  1507. return
  1508. }
  1509. //获取当前机构所有可用仓库的名字
  1510. func (this *SecondaryOrderApiController) GetAllStorehouseName() {
  1511. orgId := this.GetAdminUserInfo().CurrentOrgId
  1512. list, err := service.GetAllStorehouseName(orgId)
  1513. if err != nil {
  1514. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1515. return
  1516. }
  1517. this.ServeSuccessJSON(map[string]interface{}{
  1518. "list": list,
  1519. })
  1520. }
  1521. //根据机构id查询仓库配置
  1522. func (this *SecondaryOrderApiController) FindStorehouseConfig() {
  1523. orgId := this.GetAdminUserInfo().CurrentOrgId
  1524. storehouse, err := service.FindStorehouseConfig(orgId)
  1525. //如果没有仓库配置信息就新建一个
  1526. if err == gorm.ErrRecordNotFound {
  1527. err := service.GetDefaultStorehouse(orgId)
  1528. if err != nil {
  1529. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1530. return
  1531. }
  1532. storehouse, err = service.FindStorehouseConfig(orgId)
  1533. if err != nil {
  1534. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1535. return
  1536. }
  1537. }
  1538. if err != nil && err.Error() != "record not found" {
  1539. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1540. return
  1541. }
  1542. var storehouse_info, storehouse_out_info, drug_storehouse_info, drug_storehouse_out models.Storehouse
  1543. storehouse_info, err = service.FindStorehouseName(storehouse.StorehouseInfo)
  1544. if err != nil {
  1545. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1546. return
  1547. }
  1548. storehouse_out_info, err = service.FindStorehouseName(storehouse.StorehouseOutInfo)
  1549. if err != nil {
  1550. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1551. return
  1552. }
  1553. drug_storehouse_info, err = service.FindStorehouseName(storehouse.DrugStorehouseInfo)
  1554. if err != nil {
  1555. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1556. return
  1557. }
  1558. drug_storehouse_out, err = service.FindStorehouseName(storehouse.DrugStorehouseOut)
  1559. if err != nil {
  1560. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1561. return
  1562. }
  1563. this.ServeSuccessJSON(map[string]interface{}{
  1564. "storehouse_info": storehouse_info.StorehouseName,
  1565. "storehouse_out_info": storehouse_out_info.StorehouseName,
  1566. "drug_storehouse_info": drug_storehouse_info.StorehouseName,
  1567. "drug_storehouse_out": drug_storehouse_out.StorehouseName,
  1568. })
  1569. return
  1570. }
  1571. //更改耗材自动入库仓库
  1572. func (this *SecondaryOrderApiController) UpdateInfo() {
  1573. orgId := this.GetAdminUserInfo().CurrentOrgId
  1574. check := map[string][]string{
  1575. "id": {"must", "int", "id"},
  1576. }
  1577. _, err := checkParams(this, &check)
  1578. if err != nil {
  1579. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1580. return
  1581. }
  1582. id, _ := this.GetInt64("id")
  1583. err = service.UpdateInfo(orgId, id)
  1584. //查询默认仓库
  1585. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1586. list, _ := service.GetAllGoodList(orgId)
  1587. for _, item := range list {
  1588. var sum_count int64
  1589. var sum_in_count int64
  1590. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ID, orgId)
  1591. for _, it := range goodList {
  1592. sum_count += it.StockCount
  1593. sum_in_count += it.WarehousingCount
  1594. }
  1595. service.UpdateGoodByGoodId(item.ID, sum_count, sum_in_count, orgId)
  1596. }
  1597. if err != nil {
  1598. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1599. return
  1600. }
  1601. this.ServeSuccessJSON(map[string]interface{}{
  1602. "list": "修改成功",
  1603. })
  1604. return
  1605. }
  1606. //更改耗材自动出库仓库
  1607. func (this *SecondaryOrderApiController) UpdateOutInfo() {
  1608. orgId := this.GetAdminUserInfo().CurrentOrgId
  1609. check := map[string][]string{
  1610. "id": {"must", "int", "id"},
  1611. }
  1612. _, err := checkParams(this, &check)
  1613. if err != nil {
  1614. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1615. return
  1616. }
  1617. id, _ := this.GetInt64("id")
  1618. err = service.UpdateOutInfo(orgId, id)
  1619. //查询默认仓库
  1620. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1621. list, _ := service.GetAllGoodList(orgId)
  1622. for _, item := range list {
  1623. var sum_count int64
  1624. var sum_in_count int64
  1625. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ID, orgId)
  1626. for _, it := range goodList {
  1627. sum_count += it.StockCount
  1628. sum_in_count += it.WarehousingCount
  1629. }
  1630. service.UpdateGoodByGoodId(item.ID, sum_count, sum_in_count, orgId)
  1631. }
  1632. if err != nil {
  1633. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1634. return
  1635. }
  1636. this.ServeSuccessJSON(map[string]interface{}{
  1637. "list": "修改成功",
  1638. })
  1639. return
  1640. }
  1641. //更改药品自动入库仓库
  1642. func (this *SecondaryOrderApiController) UpdateDrugInfo() {
  1643. orgId := this.GetAdminUserInfo().CurrentOrgId
  1644. check := map[string][]string{
  1645. "id": {"must", "int", "id"},
  1646. }
  1647. _, err := checkParams(this, &check)
  1648. if err != nil {
  1649. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1650. return
  1651. }
  1652. id, _ := this.GetInt64("id")
  1653. err = service.UpdateDrugInfo2(orgId, id)
  1654. //查询默认仓库
  1655. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1656. baseDrug, _ := service.GetAllBaseDrugList(orgId)
  1657. for _, item := range baseDrug {
  1658. var sum_drug_count int64
  1659. var sum_drug_in_count int64
  1660. //查询默认仓库剩余多少库存
  1661. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ID)
  1662. for _, it := range list {
  1663. if it.MaxUnit == item.MaxUnit {
  1664. it.StockMaxNumber = it.StockMaxNumber * item.MinNumber
  1665. it.WarehousingCount = it.WarehousingCount * item.MinNumber
  1666. }
  1667. sum_drug_count += it.StockMaxNumber + it.StockMinNumber
  1668. sum_drug_in_count += it.WarehousingCount
  1669. }
  1670. service.UpdateMedicalSumCount(item.ID, sum_drug_count, sum_drug_in_count, orgId)
  1671. }
  1672. if err != nil {
  1673. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1674. return
  1675. }
  1676. this.ServeSuccessJSON(map[string]interface{}{
  1677. "list": "修改成功",
  1678. })
  1679. return
  1680. }
  1681. //更改药品自动出库仓库
  1682. func (this *SecondaryOrderApiController) UpdateDrugOut() {
  1683. orgId := this.GetAdminUserInfo().CurrentOrgId
  1684. check := map[string][]string{
  1685. "id": {"must", "int", "id"},
  1686. }
  1687. _, err := checkParams(this, &check)
  1688. if err != nil {
  1689. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1690. return
  1691. }
  1692. id, _ := this.GetInt64("id")
  1693. err = service.UpdateDrugOut(orgId, id)
  1694. //查询默认仓库
  1695. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1696. baseDrug, _ := service.GetAllBaseDrugList(orgId)
  1697. for _, item := range baseDrug {
  1698. var sum_drug_count int64
  1699. var sum_drug_in_count int64
  1700. //查询默认仓库剩余多少库存
  1701. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ID)
  1702. for _, it := range list {
  1703. if it.MaxUnit == item.MaxUnit {
  1704. it.StockMaxNumber = it.StockMaxNumber * item.MinNumber
  1705. it.WarehousingCount = it.WarehousingCount * item.MinNumber
  1706. }
  1707. sum_drug_count += it.StockMaxNumber + it.StockMinNumber
  1708. sum_drug_in_count += it.WarehousingCount
  1709. }
  1710. service.UpdateMedicalSumCount(item.ID, sum_drug_count, sum_drug_in_count, orgId)
  1711. }
  1712. if err != nil {
  1713. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1714. return
  1715. }
  1716. this.ServeSuccessJSON(map[string]interface{}{
  1717. "list": "修改成功",
  1718. })
  1719. return
  1720. }
  1721. //判断前端参数是否为空
  1722. func checkParams(this *SecondaryOrderApiController, m *map[string][]string) (map[string]string, error) {
  1723. tmp := make(map[string]string)
  1724. for k, v := range *m {
  1725. t := this.GetString(k)
  1726. if v[0] == "must" && t == "" {
  1727. return nil, fmt.Errorf(v[2] + "不能为空")
  1728. }
  1729. tmp[k] = t
  1730. }
  1731. return tmp, nil
  1732. }
  1733. //兼容旧数据
  1734. func (this *SecondaryOrderApiController) Byliinit() {
  1735. err := service.Byliinit()
  1736. if err != nil {
  1737. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1738. return
  1739. }
  1740. this.ServeSuccessJSON(map[string]interface{}{
  1741. "list": "初始化成功",
  1742. })
  1743. return
  1744. }
  1745. //查询机构所属管理员
  1746. func (this *SecondaryOrderApiController) GetuserName() {
  1747. adminUserInfo := this.GetAdminUserInfo()
  1748. viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1749. //viewModels, _, _ := service.GetAdminUsersAndLoginInfo(10164, 12123, 1, 100)
  1750. c, _ := service.Getcreateid(adminUserInfo.CurrentOrgId)
  1751. //c, _ := service.Getcreateid(10164)
  1752. admin := []*service.AdminUserManageViewModel{} //记录当前管理员的信息
  1753. //去除禁用的角色
  1754. tmp := []*service.AdminUserManageViewModel{}
  1755. for i := 0; i < len(viewModels); i++ {
  1756. if viewModels[i].Status == 1 {
  1757. tmp = append(tmp, viewModels[i])
  1758. }
  1759. if int64(viewModels[i].AdminUserId) == c.Creator {
  1760. admin = append(admin, viewModels[i])
  1761. }
  1762. }
  1763. roles := service.FindRoles(adminUserInfo.CurrentOrgId)
  1764. //roles := service.FindRoles(10164)
  1765. //去除没有权限的角色
  1766. tmplist := []*service.AdminUserManageViewModel{}
  1767. if roles == nil || len(roles) == 0 {
  1768. this.ServeSuccessJSON(map[string]interface{}{
  1769. "list": admin,
  1770. })
  1771. return
  1772. }
  1773. for i := 0; i < len(tmp); i++ {
  1774. boolean := false
  1775. //获取并解析当前用户的角色
  1776. tmproles := strings.Split(tmp[i].RoleIds, ",")
  1777. for j := 0; j < len(tmproles); j++ {
  1778. //判断这些角色是否有权限
  1779. if _, ok := roles[tmproles[j]]; ok {
  1780. boolean = true
  1781. }
  1782. }
  1783. if boolean {
  1784. tmplist = append(tmplist, tmp[i])
  1785. }
  1786. }
  1787. isappend := true //判断结果中是否添加机构创建者,true添加,false不添加
  1788. if len(tmplist) > 0 {
  1789. for i := 0; i < len(tmplist); i++ {
  1790. if int64(tmplist[i].AdminUserId) == c.Creator {
  1791. isappend = false
  1792. }
  1793. }
  1794. }
  1795. if isappend {
  1796. tmplist = append(tmplist, admin...)
  1797. }
  1798. this.ServeSuccessJSON(map[string]interface{}{
  1799. "list": tmplist,
  1800. })
  1801. return
  1802. }
  1803. func (this *SecondaryOrderApiController) GetCreaterId() {
  1804. creater := this.GetAdminUserInfo().AdminUser.Id
  1805. this.ServeSuccessJSON(map[string]interface{}{
  1806. "list": creater,
  1807. })
  1808. }