secondary_order_api_contorller.go 73KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233
  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. defer func() {
  267. if err != nil {
  268. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  269. }
  270. }()
  271. var storehouse_status, admin_id int64
  272. tmpstatus := dataBody["storehouse_status"]
  273. tmpid := dataBody["storehouse_admin_id"] //管理员id
  274. if tmpstatus == nil {
  275. storehouse_status = 1
  276. } else {
  277. storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
  278. }
  279. if tmpid == nil {
  280. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
  281. return
  282. } else {
  283. admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
  284. }
  285. switch {
  286. case dataBody["storehouse_code"] == nil:
  287. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库编号不能为空")
  288. return
  289. case dataBody["storehouse_name"] == nil:
  290. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  291. return
  292. case dataBody["storehouse_address"] == nil:
  293. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  294. return
  295. }
  296. code := dataBody["storehouse_code"].(string) //仓库编号
  297. name := dataBody["storehouse_name"].(string) //仓库名称
  298. address := dataBody["storehouse_address"].(string) //地址
  299. switch {
  300. case name == "":
  301. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  302. return
  303. case address == "":
  304. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  305. return
  306. }
  307. //判断仓库名称是否重复
  308. var bo bool
  309. bo, err = service.IsStorehouseName(orgId, name)
  310. if bo == true {
  311. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  312. return
  313. }
  314. //判断仓库地址是否重复
  315. bo, err = service.IsStorehouseAddress(orgId, address)
  316. if bo == true {
  317. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  318. return
  319. }
  320. storehouse := models.Storehouse{
  321. StorehouseCode: code,
  322. StorehouseName: name,
  323. StorehouseAddress: address,
  324. StorehouseStatus: storehouse_status,
  325. UserOrgId: orgId,
  326. Status: 1,
  327. StorehouseAdminId: admin_id,
  328. Ctime: time.Now().Unix(),
  329. }
  330. var shiwu string
  331. shiwu, err = service.AddStroehouse(storehouse)
  332. if err != nil {
  333. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
  334. return
  335. }
  336. this.ServeSuccessJSON(map[string]interface{}{
  337. "list": "保存成功",
  338. "shiwu": shiwu,
  339. })
  340. return
  341. }
  342. //修改仓库
  343. func (this *SecondaryOrderApiController) UpdateStorehouse() {
  344. orgId := this.GetAdminUserInfo().CurrentOrgId
  345. dataBody := make(map[string]interface{}, 0)
  346. //orgId := this.GetAdminUserInfo().CurrentOrgId
  347. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  348. if err != nil {
  349. utils.ErrorLog(err.Error())
  350. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  351. return
  352. }
  353. var storehouse_status, admin_id int64
  354. tmpstatus := dataBody["storehouse_status"]
  355. tmpid := dataBody["storehouse_admin_id"]
  356. if tmpstatus == nil {
  357. storehouse_status = 1
  358. } else {
  359. storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
  360. }
  361. if tmpid == nil {
  362. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
  363. return
  364. } else {
  365. admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
  366. }
  367. switch {
  368. case dataBody["id"] == nil:
  369. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库id不能为空")
  370. return
  371. case dataBody["storehouse_name"] == nil:
  372. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  373. return
  374. case dataBody["storehouse_address"] == nil:
  375. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  376. return
  377. }
  378. id := int64(dataBody["id"].(float64))
  379. name := dataBody["storehouse_name"].(string) //仓库名称
  380. address := dataBody["storehouse_address"].(string) //地址
  381. //查询当前仓库状态,根据当前状态判断是否需要更改
  382. list, errs := service.GetOneStorehouse(id, orgId)
  383. if errs != nil {
  384. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  385. return
  386. }
  387. if storehouse_status != list.StorehouseStatus && storehouse_status == 0 {
  388. //判断该仓库的库存是否为零
  389. boolean := service.IsStorehouseNil(id, orgId)
  390. if boolean == false {
  391. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  392. return
  393. }
  394. //判断该仓库是否在仓库配置表中
  395. boolean = service.IsInConfig(orgId, id)
  396. if boolean == true {
  397. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  398. return
  399. }
  400. }
  401. //判断仓库名称是否重复
  402. var bo bool
  403. bo, err = service.IsStorehouseNameUp(orgId, id, name)
  404. if bo == true {
  405. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  406. return
  407. }
  408. //判断仓库地址是否重复
  409. bo, err = service.IsStorehouseAddressUp(orgId, id, address)
  410. if bo == true {
  411. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  412. return
  413. }
  414. storehouse := models.Storehouse{
  415. ID: id,
  416. StorehouseName: name,
  417. StorehouseAddress: address,
  418. StorehouseStatus: storehouse_status,
  419. StorehouseAdminId: admin_id,
  420. Mtime: time.Now().Unix(),
  421. }
  422. err = service.UpdateStroehouse(storehouse)
  423. if err != nil {
  424. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
  425. return
  426. }
  427. this.ServeSuccessJSON(map[string]interface{}{
  428. "list": "保存成功",
  429. })
  430. return
  431. }
  432. func (this *SecondaryOrderApiController) GetSencondeGoodList() {
  433. orgId := this.GetAdminUserInfo().CurrentOrgId
  434. houseList, _ := service.GetAllStoreHouseListThree(orgId)
  435. this.ServeSuccessJSON(map[string]interface{}{
  436. "houseList": houseList,
  437. })
  438. return
  439. }
  440. func (this *SecondaryOrderApiController) SaveSencondOrder() {
  441. start_date := this.GetString("record_date")
  442. storehouse_in_id, _ := this.GetInt64("storehouse_in_id")
  443. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  444. fmt.Println(storehouse_in_id, storehouse_out_id)
  445. timeLayout := "2006-01-02"
  446. loc, _ := time.LoadLocation("Local")
  447. var startDate int64
  448. if len(start_date) > 0 {
  449. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  450. if err != nil {
  451. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  452. return
  453. }
  454. startDate = theTime.Unix()
  455. }
  456. //生成购货订单
  457. timeStr := time.Now().Format("2006-01-02")
  458. timeArr := strings.Split(timeStr, "-")
  459. orgId := this.GetAdminUserInfo().CurrentOrgId
  460. warehousing_order := "DB1010" + timeArr[0] + timeArr[1] + timeArr[2] + fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000))
  461. recordDateStr := time.Now().Format("2006-01-02")
  462. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  463. record_date := recordDate.Unix()
  464. creater := this.GetAdminUserInfo().AdminUser.Id
  465. warehouse := models.XtSecondWarehouse{
  466. SecondOrderNumber: warehousing_order,
  467. Creater: creater,
  468. RecordDate: startDate,
  469. Checker: 0,
  470. IsCheck: 2,
  471. UserOrgId: orgId,
  472. Status: 1,
  473. Ctime: time.Now().Unix(),
  474. StorehouseInId: storehouse_in_id,
  475. StorehouseOutId: storehouse_out_id,
  476. }
  477. //查询改订单号是否存在
  478. _, errcode := service.GetSecondWarehouseByNumber(orgId, warehousing_order)
  479. if errcode == gorm.ErrRecordNotFound {
  480. service.CreateSecondeWarehouse(warehouse)
  481. } else if errcode == nil {
  482. order := "DB1010" + timeArr[0] + timeArr[1] + timeArr[2] + fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000))
  483. warehouse.SecondOrderNumber = order
  484. service.CreateSecondeWarehouse(warehouse)
  485. }
  486. secondWarehouse, _ := service.GetLastSecondWarehouse(orgId)
  487. var warehousingInfo []*models.XtSecondWarehouseInfo
  488. dataBody := make(map[string]interface{}, 0)
  489. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  490. if err != nil {
  491. utils.ErrorLog(err.Error())
  492. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  493. return
  494. }
  495. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  496. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  497. if len(thisStockIn) > 0 {
  498. for _, item := range thisStockIn {
  499. items := item.(map[string]interface{})
  500. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  501. utils.ErrorLog("project_id")
  502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  503. return
  504. }
  505. project_id := int64(items["project_id"].(float64))
  506. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  507. utils.ErrorLog("name")
  508. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  509. return
  510. }
  511. project_name := items["name"].(string)
  512. if items["project_type"] == nil || reflect.TypeOf(items["project_type"]).String() != "string" {
  513. utils.ErrorLog("project_type")
  514. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. project_type := items["project_type"].(string)
  518. if items["second_specification_name"] == nil || reflect.TypeOf(items["second_specification_name"]).String() != "string" {
  519. utils.ErrorLog("second_specification_name")
  520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  521. return
  522. }
  523. second_specification_name := items["second_specification_name"].(string)
  524. if items["sencond_unit"] == nil || reflect.TypeOf(items["sencond_unit"]).String() != "string" {
  525. utils.ErrorLog("sencond_unit")
  526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  527. return
  528. }
  529. sencond_unit := items["sencond_unit"].(string)
  530. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  531. utils.ErrorLog("count")
  532. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  533. return
  534. }
  535. count := int64(items["count"].(float64))
  536. if items["is_source"] == nil || reflect.TypeOf(items["is_source"]).String() != "float64" {
  537. utils.ErrorLog("is_source")
  538. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  539. return
  540. }
  541. is_source := int64(items["is_source"].(float64))
  542. if items["second_total"] == nil || reflect.TypeOf(items["second_total"]).String() != "string" {
  543. utils.ErrorLog("second_total")
  544. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  545. return
  546. }
  547. second_total := items["second_total"].(string)
  548. if items["remake"] == nil || reflect.TypeOf(items["remake"]).String() != "string" {
  549. utils.ErrorLog("remake")
  550. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  551. return
  552. }
  553. remake := items["remake"].(string)
  554. if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "float64" {
  555. utils.ErrorLog("min_price")
  556. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  557. return
  558. }
  559. min_price := items["min_price"].(float64)
  560. info := &models.XtSecondWarehouseInfo{
  561. ProjectName: project_name,
  562. SecondSpecificationName: second_specification_name,
  563. ProjectType: project_type,
  564. SencondUnit: sencond_unit,
  565. Count: count,
  566. SecondTotal: second_total,
  567. SecondOrderNumber: secondWarehouse.SecondOrderNumber,
  568. RecordDate: record_date,
  569. StorehouseInId: storehouse_in_id,
  570. StorehouseOutId: storehouse_out_id,
  571. Creater: creater,
  572. ProjectId: project_id,
  573. Remake: remake,
  574. UserOrgId: orgId,
  575. Status: 1,
  576. Ctime: time.Now().Unix(),
  577. Mtime: 0,
  578. MinPrice: min_price,
  579. IsSource: is_source,
  580. WarehouseId: secondWarehouse.ID,
  581. }
  582. warehousingInfo = append(warehousingInfo, info)
  583. }
  584. }
  585. }
  586. for _, item := range warehousingInfo {
  587. service.CreateSencondWarehousingInfo(item)
  588. }
  589. //获取最后一条入库单
  590. lastSecondWarehouse, _ := service.GetLastSecondWarehouse(orgId)
  591. this.ServeSuccessJSON(map[string]interface{}{
  592. "warehousingInfo": warehousingInfo,
  593. "id": lastSecondWarehouse.ID,
  594. })
  595. return
  596. }
  597. func (this *SecondaryOrderApiController) GetAllSecondeOrderList() {
  598. check_id, _ := this.GetInt64("check_id")
  599. start_time := this.GetString("start_time")
  600. timeLayout := "2006-01-02"
  601. loc, _ := time.LoadLocation("Local")
  602. var startTime int64
  603. if len(start_time) > 0 {
  604. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  605. if err != nil {
  606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  607. return
  608. }
  609. startTime = theTime.Unix()
  610. }
  611. end_time := this.GetString("end_time")
  612. var endTime int64
  613. if len(end_time) > 0 {
  614. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  615. if err != nil {
  616. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  617. return
  618. }
  619. endTime = theTime.Unix()
  620. }
  621. keyword := this.GetString("keyword")
  622. page, _ := this.GetInt64("page")
  623. limit, _ := this.GetInt64("limit")
  624. orgId := this.GetAdminUserInfo().CurrentOrgId
  625. list, total, _ := service.GetAllSecondeOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
  626. houseList, _ := service.GetAllStoreHouseList(orgId)
  627. appId := this.GetAdminUserInfo().CurrentAppId
  628. doctor, _ := service.GetAllDoctorListSix(orgId, appId)
  629. this.ServeSuccessJSON(map[string]interface{}{
  630. "list": list,
  631. "total": total,
  632. "houseList": houseList,
  633. "doctorList": doctor,
  634. })
  635. return
  636. }
  637. func (this *SecondaryOrderApiController) GetSencondOrderDetail() {
  638. id, _ := this.GetInt64("id")
  639. orgId := this.GetAdminUserInfo().CurrentOrgId
  640. warehouse, _ := service.GetSecondWarehouseOrderById(id)
  641. //获取药品库数据
  642. baseList, _ := service.GetSupplyDrugListOne(orgId, warehouse.StorehouseOutId)
  643. goodList, _ := service.GetSupplyGoodListOne(orgId, warehouse.StorehouseOutId)
  644. goodTypeList, _ := service.GetAllGoodType(orgId)
  645. configlist, _ := service.GetAllStoreHouseConfig(orgId)
  646. var drugType = "药品类型"
  647. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  648. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  649. list, _ := service.GetSencondOrderDetail(id, orgId)
  650. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  651. this.ServeSuccessJSON(map[string]interface{}{
  652. "list": list,
  653. "warehouse": warehouse,
  654. "drugList": baseList,
  655. "goodList": goodList,
  656. "goodTypeList": goodTypeList,
  657. "drugTypeList": drugTypeList,
  658. "configlist": configlist,
  659. "manufacturerList": manufacturerList,
  660. })
  661. return
  662. }
  663. func (this *SecondaryOrderApiController) UpdateSencondOrder() {
  664. warehouse_id, _ := this.GetInt64("id")
  665. start_date := this.GetString("record_date")
  666. storehouse_in_id, _ := this.GetInt64("storehouse_in_id")
  667. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  668. fmt.Println(storehouse_in_id, storehouse_out_id)
  669. timeLayout := "2006-01-02"
  670. loc, _ := time.LoadLocation("Local")
  671. var startDate int64
  672. if len(start_date) > 0 {
  673. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  674. if err != nil {
  675. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  676. return
  677. }
  678. startDate = theTime.Unix()
  679. }
  680. recordDateStr := time.Now().Format("2006-01-02")
  681. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  682. record_date := recordDate.Unix()
  683. orgId := this.GetAdminUserInfo().CurrentOrgId
  684. creater := this.GetAdminUserInfo().AdminUser.Id
  685. warehouse := models.XtSecondWarehouse{
  686. StorehouseInId: storehouse_in_id,
  687. StorehouseOutId: storehouse_out_id,
  688. RecordDate: startDate,
  689. }
  690. service.UpdateModifySecondWarehouse(warehouse_id, warehouse)
  691. warehouseInfo, _ := service.GetSecondWarehouseOrderById(warehouse_id)
  692. var warehousingInfo []*models.XtSecondWarehouseInfo
  693. var updateWarehousingInfo []*models.XtSecondWarehouseInfo
  694. dataBody := make(map[string]interface{}, 0)
  695. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  696. if err != nil {
  697. utils.ErrorLog(err.Error())
  698. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  699. return
  700. }
  701. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  702. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  703. if len(thisStockIn) > 0 {
  704. for _, item := range thisStockIn {
  705. items := item.(map[string]interface{})
  706. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  707. utils.ErrorLog("id")
  708. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  709. return
  710. }
  711. id := int64(items["id"].(float64))
  712. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  713. utils.ErrorLog("project_id")
  714. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  715. return
  716. }
  717. project_id := int64(items["project_id"].(float64))
  718. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  719. utils.ErrorLog("name")
  720. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  721. return
  722. }
  723. project_name := items["name"].(string)
  724. if items["project_type"] == nil || reflect.TypeOf(items["project_type"]).String() != "string" {
  725. utils.ErrorLog("project_type")
  726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  727. return
  728. }
  729. project_type := items["project_type"].(string)
  730. if items["second_specification_name"] == nil || reflect.TypeOf(items["second_specification_name"]).String() != "string" {
  731. utils.ErrorLog("second_specification_name")
  732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  733. return
  734. }
  735. second_specification_name := items["second_specification_name"].(string)
  736. if items["sencond_unit"] == nil || reflect.TypeOf(items["sencond_unit"]).String() != "string" {
  737. utils.ErrorLog("sencond_unit")
  738. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  739. return
  740. }
  741. sencond_unit := items["sencond_unit"].(string)
  742. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  743. utils.ErrorLog("count")
  744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  745. return
  746. }
  747. count := int64(items["count"].(float64))
  748. if items["is_source"] == nil || reflect.TypeOf(items["is_source"]).String() != "float64" {
  749. utils.ErrorLog("is_source")
  750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  751. return
  752. }
  753. is_source := int64(items["is_source"].(float64))
  754. if items["second_total"] == nil || reflect.TypeOf(items["second_total"]).String() != "string" {
  755. utils.ErrorLog("second_total")
  756. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  757. return
  758. }
  759. second_total := items["second_total"].(string)
  760. if items["remake"] == nil || reflect.TypeOf(items["remake"]).String() != "string" {
  761. utils.ErrorLog("remake")
  762. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  763. return
  764. }
  765. remake := items["remake"].(string)
  766. if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "float64" {
  767. utils.ErrorLog("min_price")
  768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  769. return
  770. }
  771. min_price := items["min_price"].(float64)
  772. if id == 0 {
  773. info := &models.XtSecondWarehouseInfo{
  774. ProjectName: project_name,
  775. SecondSpecificationName: second_specification_name,
  776. ProjectType: project_type,
  777. SencondUnit: sencond_unit,
  778. Count: count,
  779. SecondTotal: second_total,
  780. RecordDate: record_date,
  781. StorehouseInId: storehouse_in_id,
  782. StorehouseOutId: storehouse_out_id,
  783. Creater: creater,
  784. ProjectId: project_id,
  785. Remake: remake,
  786. UserOrgId: orgId,
  787. Status: 1,
  788. Ctime: time.Now().Unix(),
  789. Mtime: 0,
  790. MinPrice: min_price,
  791. IsSource: is_source,
  792. WarehouseId: warehouse_id,
  793. SecondOrderNumber: warehouseInfo.SecondOrderNumber,
  794. }
  795. warehousingInfo = append(warehousingInfo, info)
  796. }
  797. if id > 0 {
  798. updateInfo := &models.XtSecondWarehouseInfo{
  799. ID: id,
  800. ProjectName: project_name,
  801. SecondSpecificationName: second_specification_name,
  802. ProjectType: project_type,
  803. SencondUnit: sencond_unit,
  804. Count: count,
  805. SecondTotal: second_total,
  806. SecondOrderNumber: warehouse.SecondOrderNumber,
  807. RecordDate: record_date,
  808. StorehouseInId: storehouse_in_id,
  809. StorehouseOutId: storehouse_out_id,
  810. Creater: creater,
  811. ProjectId: project_id,
  812. Remake: remake,
  813. UserOrgId: orgId,
  814. MinPrice: min_price,
  815. IsSource: is_source,
  816. }
  817. updateWarehousingInfo = append(updateWarehousingInfo, updateInfo)
  818. }
  819. }
  820. }
  821. }
  822. for _, item := range warehousingInfo {
  823. service.CreateSencondWarehousingInfo(item)
  824. }
  825. for _, item := range updateWarehousingInfo {
  826. service.UpdateStoreWarehousing(item)
  827. }
  828. this.ServeSuccessJSON(map[string]interface{}{
  829. "warehousingInfo": warehousingInfo,
  830. })
  831. return
  832. }
  833. func (this *SecondaryOrderApiController) GetSecondOrderById() {
  834. id, _ := this.GetInt64("id")
  835. orgId := this.GetAdminUserInfo().CurrentOrgId
  836. warehouse, _ := service.GetSecondWarehouseOrderById(id)
  837. list, _ := service.GetSencondOrderDetail(id, orgId)
  838. appId := this.GetAdminUserInfo().CurrentAppId
  839. doctor, _ := service.GetAllDoctorSix(orgId, appId)
  840. houseList, _ := service.GetAllStoreHouseList(orgId)
  841. this.ServeSuccessJSON(map[string]interface{}{
  842. "warehouse": warehouse,
  843. "list": list,
  844. "doctorList": doctor,
  845. "houseList": houseList,
  846. })
  847. return
  848. }
  849. func (this *SecondaryOrderApiController) CheckSecondOrer() {
  850. ids := this.GetString("ids")
  851. if len(ids) == 0 {
  852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  853. return
  854. }
  855. idArray := strings.Split(ids, ",")
  856. orgId := this.GetAdminUserInfo().CurrentOrgId
  857. creater := this.GetAdminUserInfo().AdminUser.Id
  858. //根据订单id获取商品详情
  859. list, _ := service.GetSecondOrderList(idArray, orgId)
  860. for _, item := range list {
  861. if item.IsSource == 1 {
  862. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  863. //查询该仓库的药品库存是否满足调出数量
  864. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  865. var total int64
  866. var total_count int64
  867. for _, it := range drugInfoList {
  868. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  869. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  870. }
  871. }
  872. for _, it := range drugInfoList {
  873. total += it.StockMaxNumber + it.StockMinNumber
  874. }
  875. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  876. total_count = item.Count * medical.MinNumber
  877. }
  878. if item.SencondUnit == medical.MinUnit {
  879. total_count = item.Count
  880. }
  881. if total_count > total {
  882. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  883. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseOutId, item.UserOrgId)
  884. this.ServeSuccessJSON(map[string]interface{}{
  885. "msg": "3",
  886. "drug_name": goodObj.DrugName,
  887. "dose": goodObj.Dose,
  888. "dose_unit": goodObj.DoseUnit,
  889. "min_number": goodObj.MinNumber,
  890. "min_unit": goodObj.MinUnit,
  891. "max_unit": goodObj.MaxUnit,
  892. "storehose_name": storehouse.StorehouseName,
  893. })
  894. return
  895. }
  896. }
  897. if item.IsSource == 2 {
  898. //查询该仓库的耗材库存是否满足调出数量
  899. var total int64
  900. infoList, _ := service.GetWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  901. for _, it := range infoList {
  902. total += it.StockCount
  903. }
  904. if item.Count > total {
  905. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseOutId, item.UserOrgId)
  906. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  907. this.ServeSuccessJSON(map[string]interface{}{
  908. "msg": "2",
  909. "good_name": goodObj.GoodName,
  910. "specification_name": goodObj.SpecificationName,
  911. "storehose_name": storehouse.StorehouseName,
  912. })
  913. return
  914. }
  915. }
  916. }
  917. err := service.UpdateStoreOrderByArray(idArray, orgId, creater)
  918. //如果审核成功
  919. if err == nil {
  920. //调用出库接口
  921. timeStr := time.Now().Format("2006-01-02")
  922. timeArr := strings.Split(timeStr, "-")
  923. total, _ := service.FindAllWarehouseOut(orgId)
  924. total = total + 1
  925. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  926. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  927. number = number + total
  928. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  929. operation_time := time.Now().Unix()
  930. creater := this.GetAdminUserInfo().AdminUser.Id
  931. recordDateStr := time.Now().Format("2006-01-02")
  932. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  933. record_date := recordDate.Unix()
  934. totals, _ := service.FindAllWarehouseTotal(orgId)
  935. totals = totals + 1
  936. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(totals, 10)
  937. for _, item := range list {
  938. //药品
  939. if item.IsSource == 1 {
  940. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  941. //查询该仓库的药品库存是否满足调出数量
  942. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  943. var total int64
  944. var total_count int64
  945. for _, it := range drugInfoList {
  946. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  947. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  948. }
  949. }
  950. for _, it := range drugInfoList {
  951. total += it.StockMaxNumber + it.StockMinNumber
  952. }
  953. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  954. total_count = item.Count * medical.MinNumber
  955. }
  956. if item.SencondUnit == medical.MinUnit {
  957. total_count = item.Count
  958. }
  959. if total_count <= total {
  960. drug_total, _ := service.FindAllDrugWarehouseOut(orgId)
  961. drug_total = drug_total + 1
  962. drug_warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  963. number, _ := strconv.ParseInt(drug_warehousing_out_order, 10, 64)
  964. number = number + drug_total
  965. drug_warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  966. operation_time := time.Now().Unix()
  967. drugWarehouseOut := models.DrugWarehouseOut{
  968. WarehouseOutOrderNumber: drug_warehousing_out_order,
  969. OperationTime: operation_time,
  970. OrgId: orgId,
  971. Creater: creater,
  972. Ctime: time.Now().Unix(),
  973. Status: 1,
  974. WarehouseOutTime: record_date,
  975. Type: 2,
  976. StorehouseId: item.StorehouseOutId,
  977. SecondWarehouseId: item.WarehouseId,
  978. IsSys: 12,
  979. IsCheck: 1,
  980. }
  981. _, drugerrcodes := service.GetDrugWarehouseBySyS(orgId, 12, item.WarehouseId, record_date)
  982. if drugerrcodes == gorm.ErrRecordNotFound {
  983. service.AddSigleDrugWarehouseOut(&drugWarehouseOut)
  984. }
  985. drugOut, _ := service.GetLastDrugWarehouseOutById(12, item.WarehouseId, orgId, record_date)
  986. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  987. WarehouseOutOrderNumber: drugOut.WarehouseOutOrderNumber,
  988. WarehouseOutId: drugOut.ID,
  989. DrugId: item.ProjectId,
  990. Count: item.Count,
  991. Price: medical.RetailPrice,
  992. TotalPrice: 0,
  993. Status: 1,
  994. Ctime: time.Now().Unix(),
  995. Remark: item.Remake,
  996. OrgId: orgId,
  997. Type: 2,
  998. Manufacturer: 0,
  999. Dealer: 0,
  1000. RetailPrice: item.MinPrice,
  1001. RetailTotalPrice: 0,
  1002. CountUnit: item.SencondUnit,
  1003. ExpiryDate: 0,
  1004. ProductDate: 0,
  1005. Number: "",
  1006. BatchNumber: "",
  1007. IsSys: 0,
  1008. WarehouseInfoId: 0,
  1009. StorehouseId: item.StorehouseOutId,
  1010. SecondWarehouseInfoId: item.ID,
  1011. IsCheck: 1,
  1012. }
  1013. drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
  1014. drug_in_total, _ := service.FindAllWarehouseTotalOne(orgId)
  1015. drug_in_total = drug_in_total + 1
  1016. warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(drug_in_total, 10)
  1017. drug_warehousing := models.DrugWarehouse{
  1018. WarehousingOrder: warehousing_order,
  1019. OperationTime: operation_time,
  1020. OrgId: orgId,
  1021. Creater: creater,
  1022. Ctime: time.Now().Unix(),
  1023. Status: 1,
  1024. WarehousingTime: record_date,
  1025. Type: 1,
  1026. StorehouseId: item.StorehouseInId,
  1027. IsSys: 13,
  1028. SecondWarehouseId: item.WarehouseId,
  1029. IsCheck: 1,
  1030. }
  1031. //查询该调拨单是否有生成入库单
  1032. _, drugerrcodess := service.GetDrugWarehouseingBySys(13, item.WarehouseId, orgId, record_date)
  1033. if drugerrcodess == gorm.ErrRecordNotFound {
  1034. service.CreateDrugWaresing(drug_warehousing)
  1035. }
  1036. drugInfoObj, _ := service.GetLastDrugWarehouseBySys(13, item.WarehouseId, orgId, record_date)
  1037. drugwarehouseInfo := &models.DrugWarehouseInfo{
  1038. WarehousingOrder: drugInfoObj.WarehousingOrder,
  1039. WarehousingId: drugInfoObj.ID,
  1040. DrugId: item.ProjectId,
  1041. Number: "",
  1042. ProductDate: 0,
  1043. ExpiryDate: 0,
  1044. WarehousingCount: 0,
  1045. Price: 0,
  1046. TotalPrice: 0,
  1047. Status: 1,
  1048. Ctime: time.Now().Unix(),
  1049. Remark: "",
  1050. OrgId: orgId,
  1051. Type: 2,
  1052. Manufacturer: 0,
  1053. Dealer: 0,
  1054. StockMaxNumber: 0,
  1055. RetailTotalPrice: 0,
  1056. BatchNumber: "",
  1057. MaxUnit: "",
  1058. MinUnit: "",
  1059. RetailPrice: 0,
  1060. StorehouseId: item.StorehouseInId,
  1061. SecondWarehouseInfoId: item.ID,
  1062. IsCheck: 1,
  1063. }
  1064. service.AutoDrugDeliverInfoTwelve(orgId, item.Count, &drugWarehouseOut, &drup, warehouseOutInfo, drugwarehouseInfo)
  1065. //查询默认仓库
  1066. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1067. //更新字典里面的库存
  1068. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
  1069. var sum_count int64
  1070. for _, its := range stockInfo {
  1071. sum_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
  1072. }
  1073. service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
  1074. }
  1075. }
  1076. //耗材
  1077. if item.IsSource == 2 {
  1078. //查询该仓库的耗材库存是否满足调出数量
  1079. var total int64
  1080. infoList, _ := service.GetWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  1081. for _, it := range infoList {
  1082. total += it.StockCount
  1083. }
  1084. //满足调拨
  1085. if item.Count <= total {
  1086. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1087. warehouseOut := models.WarehouseOut{
  1088. WarehouseOutOrderNumber: warehousing_out_order,
  1089. OperationTime: operation_time,
  1090. OrgId: orgId,
  1091. Creater: creater,
  1092. Ctime: time.Now().Unix(),
  1093. Status: 1,
  1094. WarehouseOutTime: record_date,
  1095. Type: 1,
  1096. StorehouseId: item.StorehouseOutId,
  1097. IsSys: 12,
  1098. SecondWarehouseId: item.WarehouseId,
  1099. IsCheck: 1,
  1100. }
  1101. //查询今日是否存在调拨出库
  1102. _, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
  1103. if errcodes == gorm.ErrRecordNotFound {
  1104. service.AddSigleWarehouseOut(&warehouseOut)
  1105. }
  1106. out, _ := service.GetLastWarehouseOutBySys(12, orgId, record_date, item.WarehouseId)
  1107. warehouseOutInfo := &models.WarehouseOutInfo{
  1108. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1109. WarehouseOutId: out.ID,
  1110. GoodId: item.ProjectId,
  1111. GoodTypeId: goodObj.GoodTypeId,
  1112. Count: item.Count,
  1113. Price: item.MinPrice,
  1114. TotalPrice: 0,
  1115. Status: 1,
  1116. Ctime: time.Now().Unix(),
  1117. Remark: item.Remake,
  1118. OrgId: orgId,
  1119. Type: 1,
  1120. Manufacturer: 0,
  1121. Number: "",
  1122. ExpiryDate: 0,
  1123. ProductDate: 0,
  1124. Dealer: 0,
  1125. LicenseNumber: "",
  1126. WarehouseInfotId: 0,
  1127. StorehouseId: item.StorehouseOutId,
  1128. SecondWarehouseInfoId: item.ID,
  1129. IsCheck: 1,
  1130. }
  1131. //入库操作
  1132. warehousing := models.Warehousing{
  1133. WarehousingOrder: warehousing_order,
  1134. OperationTime: operation_time,
  1135. OrgId: orgId,
  1136. Creater: creater,
  1137. Ctime: time.Now().Unix(),
  1138. Status: 1,
  1139. WarehousingTime: record_date,
  1140. Type: 1,
  1141. StorehouseId: item.StorehouseInId,
  1142. IsSys: 12,
  1143. SecondWarehouseId: item.WarehouseId,
  1144. IsCheck: 1,
  1145. }
  1146. //查询该调拨单是否有生成入库单
  1147. _, errcodess := service.GetWarehouseBySecondWarehouseId(12, item.WarehouseId, orgId, record_date)
  1148. if errcodess == gorm.ErrRecordNotFound {
  1149. service.AddSigleWarehouse(&warehousing)
  1150. }
  1151. infoObj, _ := service.GetLastWarehouseById(12, item.WarehouseId, orgId, record_date)
  1152. warehouseInfo := &models.WarehousingInfo{
  1153. WarehousingOrder: infoObj.WarehousingOrder,
  1154. WarehousingId: infoObj.ID,
  1155. GoodId: item.ProjectId,
  1156. Number: "",
  1157. GoodTypeId: goodObj.GoodTypeId,
  1158. ProductDate: 0,
  1159. ExpiryDate: 0,
  1160. WarehousingCount: item.Count,
  1161. Price: goodObj.BuyPrice,
  1162. TotalPrice: 0,
  1163. Status: 1,
  1164. Ctime: time.Now().Unix(),
  1165. Remark: item.Remake,
  1166. OrgId: orgId,
  1167. Type: 1,
  1168. Manufacturer: 0,
  1169. StockCount: item.Count,
  1170. Dealer: 0,
  1171. LicenseNumber: "",
  1172. PackingPrice: item.MinPrice,
  1173. StorehouseId: item.StorehouseInId,
  1174. SecondWarehouseInfoId: item.ID,
  1175. IsCheck: 1,
  1176. }
  1177. //出库逻辑
  1178. parseDateErr := service.ConsumablesDeliveryTwelve(orgId, record_date, warehouseOutInfo, &warehouseOut, item.Count, creater, warehouseInfo)
  1179. fmt.Println(parseDateErr)
  1180. }
  1181. //查询默认仓库
  1182. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1183. stockList, _ := service.GetStockCountByGoodId(item.ProjectId, storeHouseConfig.StorehouseOutInfo, orgId)
  1184. var total_count int64
  1185. for _, it := range stockList {
  1186. total_count += it.StockCount
  1187. }
  1188. //基础库插入数据
  1189. service.UpdateGoodInfoSumCountSix(item.ProjectId, total_count, orgId)
  1190. }
  1191. }
  1192. }
  1193. //获取所有的入库仓库
  1194. druglist, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
  1195. for _, item := range druglist {
  1196. //查询该药品该仓库是否有数据
  1197. drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
  1198. //查询该仓库该药品的入库数量
  1199. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1200. var sum_in_count int64
  1201. var flush_count int64
  1202. var sum_out_count int64
  1203. var cancel_out_count int64
  1204. //查询入库数量和剩余库存
  1205. infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
  1206. for _, it := range infolist {
  1207. if it.MaxUnit == medical.MaxUnit {
  1208. it.WarehousingCount = it.WarehousingCount * medical.MinNumber
  1209. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1210. }
  1211. sum_in_count += it.WarehousingCount
  1212. flush_count += it.StockMaxNumber + it.StockMinNumber
  1213. }
  1214. //获取出库数量
  1215. outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
  1216. for _, it := range outinfolist {
  1217. if it.MaxUnit == medical.MaxUnit {
  1218. it.Count = it.Count * medical.MinNumber
  1219. }
  1220. sum_out_count += it.Count
  1221. }
  1222. //获取退库数量
  1223. cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
  1224. for _, it := range cancelinfolist {
  1225. if it.MaxUnit == medical.MaxUnit {
  1226. it.Count = it.Count * medical.MinNumber
  1227. }
  1228. cancel_out_count += it.Count
  1229. }
  1230. //新增
  1231. if drug.ID == 0 {
  1232. drugstock := models.XtDrugStockCount{
  1233. UserOrgId: orgId,
  1234. StorehouseId: item.StorehouseId,
  1235. SumInCount: sum_in_count,
  1236. SumOutCount: sum_out_count - cancel_out_count,
  1237. SumCancelCount: cancel_out_count,
  1238. DrugId: item.DrugId,
  1239. Ctime: time.Now().Unix(),
  1240. Mtime: 0,
  1241. Status: 1,
  1242. FlushCount: flush_count,
  1243. SumActOutCount: sum_out_count,
  1244. }
  1245. service.CreateDrugStockCount(drugstock)
  1246. }
  1247. }
  1248. //获取入库数据
  1249. goodlist, _ := service.GetSendGoodInformation(orgId)
  1250. for _, it := range goodlist {
  1251. //查询是否有数据
  1252. _, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
  1253. //获取总退库数量
  1254. var cancel_count int64
  1255. var out_count int64
  1256. var act_count int64
  1257. //退库总数量
  1258. cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
  1259. for _, item := range cancellist {
  1260. cancel_count += item.Count
  1261. }
  1262. //出库总数量
  1263. outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  1264. for _, item := range outlist {
  1265. out_count += item.Count
  1266. }
  1267. //实际出库总数量
  1268. actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  1269. for _, item := range actlist {
  1270. act_count += item.Count
  1271. }
  1272. if errcode == gorm.ErrRecordNotFound {
  1273. good := models.XtGoodStockCount{
  1274. UserOrgId: it.OrgId,
  1275. GoodId: it.GoodId,
  1276. StorehouseId: it.StorehouseId,
  1277. Status: 1,
  1278. Ctime: time.Now().Unix(),
  1279. Mtime: 0,
  1280. StockInCount: it.WarehousingCount,
  1281. StockOutCount: out_count - cancel_count,
  1282. StockCancelCount: cancel_count,
  1283. FlushCount: it.StockCount,
  1284. StockActOutCount: act_count,
  1285. }
  1286. service.CreateGoodCountSix(good)
  1287. }
  1288. if errcode == nil {
  1289. service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
  1290. }
  1291. }
  1292. this.ServeSuccessJSON(map[string]interface{}{
  1293. "msg": 1,
  1294. })
  1295. return
  1296. }
  1297. func (this *SecondaryOrderApiController) DeleteStorehouseList() {
  1298. id, _ := this.GetInt64("id")
  1299. err := service.DeleteStorehouseList(id)
  1300. if err == nil {
  1301. returnData := make(map[string]interface{}, 0)
  1302. returnData["msg"] = "ok"
  1303. this.ServeSuccessJSON(returnData)
  1304. return
  1305. } else {
  1306. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1307. }
  1308. }
  1309. func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
  1310. ids := this.GetString("ids")
  1311. if len(ids) == 0 {
  1312. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1313. return
  1314. }
  1315. idArray := strings.Split(ids, ",")
  1316. orgId := this.GetAdminUserInfo().CurrentOrgId
  1317. //根据订单id获取商品详情
  1318. list, _ := service.GetSecondOrderList(idArray, orgId)
  1319. //药品
  1320. for _, item := range list {
  1321. //药品
  1322. if item.IsSource == 1 {
  1323. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1324. //查询该仓库的药品库存是否满足调出数量
  1325. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1326. var total int64
  1327. var total_count int64
  1328. for _, it := range drugInfoList {
  1329. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1330. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1331. }
  1332. }
  1333. for _, it := range drugInfoList {
  1334. total += it.StockMaxNumber + it.StockMinNumber
  1335. }
  1336. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1337. total_count = item.Count * medical.MinNumber
  1338. }
  1339. if item.SencondUnit == medical.MinUnit {
  1340. total_count = item.Count
  1341. }
  1342. if total_count > total {
  1343. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  1344. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
  1345. this.ServeSuccessJSON(map[string]interface{}{
  1346. "msg": "3",
  1347. "drug_name": goodObj.DrugName,
  1348. "dose": goodObj.Dose,
  1349. "dose_unit": goodObj.DoseUnit,
  1350. "min_number": goodObj.MinNumber,
  1351. "min_unit": goodObj.MinUnit,
  1352. "max_unit": goodObj.MaxUnit,
  1353. "storehose_name": storehouse.StorehouseName,
  1354. })
  1355. return
  1356. }
  1357. }
  1358. //耗材
  1359. if item.IsSource == 2 {
  1360. //查询该仓库的耗材库存是否满足调出数量
  1361. var total int64
  1362. infoList, _ := service.GetWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1363. for _, it := range infoList {
  1364. total += it.StockCount
  1365. }
  1366. if item.Count > total {
  1367. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
  1368. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1369. this.ServeSuccessJSON(map[string]interface{}{
  1370. "msg": "2",
  1371. "good_name": goodObj.GoodName,
  1372. "specification_name": goodObj.SpecificationName,
  1373. "storehose_name": storehouse.StorehouseName,
  1374. })
  1375. return
  1376. }
  1377. }
  1378. }
  1379. //反审核操作
  1380. err := service.ModifyStoreHouseById(idArray, orgId)
  1381. if err != nil {
  1382. this.ServeSuccessJSON(map[string]interface{}{
  1383. "msg": "0",
  1384. })
  1385. return
  1386. }
  1387. for _, item := range list {
  1388. //药品
  1389. if item.IsSource == 1 {
  1390. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1391. //查询该仓库的药品库存是否满足调出数量
  1392. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1393. var total int64
  1394. var total_count int64
  1395. for _, it := range drugInfoList {
  1396. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1397. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1398. }
  1399. }
  1400. for _, it := range drugInfoList {
  1401. total += it.StockMaxNumber + it.StockMinNumber
  1402. }
  1403. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1404. total_count = item.Count * medical.MinNumber
  1405. }
  1406. if item.SencondUnit == medical.MinUnit {
  1407. total_count = item.Count
  1408. }
  1409. if total_count <= total {
  1410. //回退库存,查询该订单出库记录
  1411. drugOutList, _ := service.GetStoreDrugWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
  1412. for _, it := range drugOutList {
  1413. if medical.MaxUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
  1414. //回退库存
  1415. service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
  1416. }
  1417. if medical.MaxUnit == it.CountUnit && medical.MaxUnit == medical.MinUnit {
  1418. //回退库存
  1419. service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
  1420. }
  1421. if medical.MinUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
  1422. service.ModifyDrugStoreWarehouseInfoOne(it.WarehouseInfoId, it.Count)
  1423. }
  1424. //查询入库单
  1425. storeWareing, _ := service.GetStoreDrugWarehouseById(item.WarehouseId, it.OrgId)
  1426. //删除入库单
  1427. service.DeleteStoreWarehousingId(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
  1428. //查询出单
  1429. storeWarehouseOut, _ := service.GetStoreDrugWarehouseOutById(it.WarehouseOutId, it.OrgId)
  1430. //删除出库单
  1431. service.DeleteStoreWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
  1432. }
  1433. }
  1434. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1435. var sum_count int64
  1436. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
  1437. for _, its := range stockInfo {
  1438. sum_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
  1439. }
  1440. service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
  1441. }
  1442. //耗材
  1443. if item.IsSource == 2 {
  1444. //查询该仓库的耗材库存是否满足调出数量
  1445. var total int64
  1446. infoList, _ := service.GetWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1447. for _, it := range infoList {
  1448. total += it.StockCount
  1449. }
  1450. //满足调拨
  1451. if item.Count <= total {
  1452. //回退库存,查询该订单出库记录
  1453. outList, _ := service.GetStoreWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
  1454. for _, it := range outList {
  1455. //回退库存
  1456. service.ModifyStoreWarehouseById(it.WarehouseInfotId, it.Count)
  1457. //获取入库单
  1458. storeWareing, _ := service.GetStoreWarehouseById(item.WarehouseId, it.OrgId)
  1459. //删除入库单 入库流水
  1460. service.ModifyStoreWarehouse(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
  1461. //获取出库单
  1462. storeWarehouseOut, _ := service.GetStoreWarehouseOutById(it.WarehouseOutId, it.OrgId)
  1463. //删除出库单
  1464. service.ModifyWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
  1465. }
  1466. }
  1467. //查询默认仓库
  1468. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1469. stockList, _ := service.GetStockCountByGoodId(item.ProjectId, storeHouseConfig.StorehouseOutInfo, orgId)
  1470. var total_count int64
  1471. for _, it := range stockList {
  1472. total_count += it.StockCount
  1473. }
  1474. //基础库插入数据
  1475. service.UpdateGoodInfoSumCount(item.ProjectId, total_count, orgId)
  1476. }
  1477. }
  1478. //获取所有的入库仓库
  1479. druglist, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
  1480. for _, item := range druglist {
  1481. //查询该药品该仓库是否有数据
  1482. drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
  1483. //查询该仓库该药品的入库数量
  1484. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1485. var sum_in_count int64
  1486. var flush_count int64
  1487. var sum_out_count int64
  1488. var cancel_out_count int64
  1489. //查询入库数量和剩余库存
  1490. infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
  1491. for _, it := range infolist {
  1492. if it.MaxUnit == medical.MaxUnit {
  1493. it.WarehousingCount = it.WarehousingCount * medical.MinNumber
  1494. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1495. }
  1496. sum_in_count += it.WarehousingCount
  1497. flush_count += it.StockMaxNumber + it.StockMinNumber
  1498. }
  1499. //获取出库数量
  1500. outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
  1501. for _, it := range outinfolist {
  1502. if it.MaxUnit == medical.MaxUnit {
  1503. it.Count = it.Count * medical.MinNumber
  1504. }
  1505. sum_out_count += it.Count
  1506. }
  1507. //获取退库数量
  1508. cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
  1509. for _, it := range cancelinfolist {
  1510. if it.MaxUnit == medical.MaxUnit {
  1511. it.Count = it.Count * medical.MinNumber
  1512. }
  1513. cancel_out_count += it.Count
  1514. }
  1515. //新增
  1516. if drug.ID == 0 {
  1517. drugstock := models.XtDrugStockCount{
  1518. UserOrgId: orgId,
  1519. StorehouseId: item.StorehouseId,
  1520. SumInCount: sum_in_count,
  1521. SumOutCount: sum_out_count - cancel_out_count,
  1522. SumCancelCount: cancel_out_count,
  1523. DrugId: item.DrugId,
  1524. Ctime: time.Now().Unix(),
  1525. Mtime: 0,
  1526. Status: 1,
  1527. FlushCount: flush_count,
  1528. SumActOutCount: sum_out_count,
  1529. }
  1530. service.CreateDrugStockCount(drugstock)
  1531. }
  1532. }
  1533. //获取入库数据
  1534. goodlist, _ := service.GetSendGoodInformation(orgId)
  1535. for _, it := range goodlist {
  1536. //查询是否有数据
  1537. _, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
  1538. //获取总退库数量
  1539. var cancel_count int64
  1540. var out_count int64
  1541. var act_count int64
  1542. //退库总数量
  1543. cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
  1544. for _, item := range cancellist {
  1545. cancel_count += item.Count
  1546. }
  1547. //出库总数量
  1548. outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  1549. for _, item := range outlist {
  1550. out_count += item.Count
  1551. }
  1552. //实际出库总数量
  1553. actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  1554. for _, item := range actlist {
  1555. act_count += item.Count
  1556. }
  1557. if errcode == gorm.ErrRecordNotFound {
  1558. good := models.XtGoodStockCount{
  1559. UserOrgId: it.OrgId,
  1560. GoodId: it.GoodId,
  1561. StorehouseId: it.StorehouseId,
  1562. Status: 1,
  1563. Ctime: time.Now().Unix(),
  1564. Mtime: 0,
  1565. StockInCount: it.WarehousingCount,
  1566. StockOutCount: out_count - cancel_count,
  1567. StockCancelCount: cancel_count,
  1568. FlushCount: it.StockCount,
  1569. StockActOutCount: act_count,
  1570. }
  1571. service.CreateGoodCountSix(good)
  1572. }
  1573. if errcode == nil {
  1574. service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
  1575. }
  1576. }
  1577. this.ServeSuccessJSON(map[string]interface{}{
  1578. "msg": "1",
  1579. })
  1580. return
  1581. }
  1582. func (this *SecondaryOrderApiController) GetStoreHouseGoodList() {
  1583. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  1584. orgId := this.GetAdminUserInfo().CurrentOrgId
  1585. //获取药品库数据
  1586. baseList, _ := service.GetSupplyDrugListOne(orgId, storehouse_out_id)
  1587. goodList, _ := service.GetSupplyGoodListOne(orgId, storehouse_out_id)
  1588. goodTypeList, _ := service.GetAllGoodType(orgId)
  1589. configlist, _ := service.GetAllStoreHouseConfig(orgId)
  1590. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1591. var drugType = "药品类型"
  1592. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1593. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  1594. this.ServeSuccessJSON(map[string]interface{}{
  1595. "drugList": baseList,
  1596. "goodList": goodList,
  1597. "goodTypeList": goodTypeList,
  1598. "drugTypeList": drugTypeList,
  1599. "configlist": configlist,
  1600. "manufacturerList": manufacturerList,
  1601. })
  1602. return
  1603. }
  1604. func (this *SecondaryOrderApiController) GetSumSecondCount() {
  1605. project_id, _ := this.GetInt64("project_id")
  1606. sencond_unit := this.GetString("sencond_unit")
  1607. is_source, _ := this.GetInt64("is_source")
  1608. count, _ := this.GetInt64("count")
  1609. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  1610. orgId := this.GetAdminUserInfo().CurrentOrgId
  1611. var sum_in_count int64
  1612. var sum_count int64
  1613. //药品
  1614. if is_source == 1 {
  1615. medical, _ := service.GetBaseDrugMedical(project_id)
  1616. fmt.Println("senconde_unit233223", sencond_unit)
  1617. if sencond_unit == medical.MaxUnit {
  1618. sum_in_count = count * medical.MinNumber
  1619. }
  1620. if sencond_unit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1621. sum_in_count = count
  1622. }
  1623. //查询该药品剩余的库存
  1624. secondCountList, _ := service.GetDrugSumSecondCount(project_id, storehouse_out_id, orgId)
  1625. for _, it := range secondCountList {
  1626. if it.MaxUnit == medical.MaxUnit {
  1627. sum_count += (it.StockMaxNumber * medical.MinNumber) + it.StockMinNumber
  1628. }
  1629. if it.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1630. sum_count += (it.StockMaxNumber + it.StockMinNumber)
  1631. }
  1632. }
  1633. fmt.Println("sum_iin_coutn23232323", sum_in_count)
  1634. fmt.Println("sum_count", sum_count)
  1635. if sum_in_count > sum_count {
  1636. this.ServeSuccessJSON(map[string]interface{}{
  1637. "msg": "2",
  1638. })
  1639. return
  1640. } else {
  1641. this.ServeSuccessJSON(map[string]interface{}{
  1642. "msg": "1",
  1643. })
  1644. return
  1645. }
  1646. }
  1647. //耗材
  1648. if is_source == 2 {
  1649. var sum_good_count int64
  1650. secondCountGoodList, _ := service.GetGoodSumSecondCount(project_id, storehouse_out_id, orgId)
  1651. for _, it := range secondCountGoodList {
  1652. sum_good_count += it.StockCount
  1653. }
  1654. if count > sum_good_count {
  1655. this.ServeSuccessJSON(map[string]interface{}{
  1656. "msg": "2",
  1657. })
  1658. return
  1659. } else {
  1660. this.ServeSuccessJSON(map[string]interface{}{
  1661. "msg": "1",
  1662. })
  1663. return
  1664. }
  1665. }
  1666. }
  1667. func (this *SecondaryOrderApiController) DeleteSecondOrderInfo() {
  1668. id, _ := this.GetInt64("id")
  1669. err := service.DeleteSecondOrderInfo(id)
  1670. if err == nil {
  1671. returnData := make(map[string]interface{}, 0)
  1672. returnData["msg"] = "ok"
  1673. this.ServeSuccessJSON(returnData)
  1674. return
  1675. } else {
  1676. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1677. }
  1678. }
  1679. //查询一条仓库信息
  1680. func (this *SecondaryOrderApiController) GetOneStorehouse() {
  1681. orgId := this.GetAdminUserInfo().CurrentOrgId
  1682. check := map[string][]string{
  1683. "id": {"must", "int", "id"},
  1684. }
  1685. _, err := checkParams(this, &check)
  1686. if err != nil {
  1687. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1688. return
  1689. }
  1690. id, _ := this.GetInt64("id")
  1691. var list models.Storehouse
  1692. list, err = service.GetOneStorehouse(id, orgId)
  1693. if err != nil {
  1694. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1695. return
  1696. }
  1697. this.ServeSuccessJSON(map[string]interface{}{
  1698. "list": list,
  1699. })
  1700. return
  1701. }
  1702. //获取当前机构所有可用仓库的名字
  1703. func (this *SecondaryOrderApiController) GetAllStorehouseName() {
  1704. orgId := this.GetAdminUserInfo().CurrentOrgId
  1705. list, err := service.GetAllStorehouseName(orgId)
  1706. if err != nil {
  1707. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1708. return
  1709. }
  1710. this.ServeSuccessJSON(map[string]interface{}{
  1711. "list": list,
  1712. })
  1713. }
  1714. //根据机构id查询仓库配置
  1715. func (this *SecondaryOrderApiController) FindStorehouseConfig() {
  1716. orgId := this.GetAdminUserInfo().CurrentOrgId
  1717. storehouse, err := service.FindStorehouseConfig(orgId)
  1718. //如果没有仓库配置信息就新建一个
  1719. if err == gorm.ErrRecordNotFound {
  1720. err := service.GetDefaultStorehouse(orgId)
  1721. if err != nil {
  1722. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1723. return
  1724. }
  1725. storehouse, err = service.FindStorehouseConfig(orgId)
  1726. if err != nil {
  1727. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1728. return
  1729. }
  1730. }
  1731. if err != nil && err.Error() != "record not found" {
  1732. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1733. return
  1734. }
  1735. var storehouse_info, storehouse_out_info, drug_storehouse_info, drug_storehouse_out models.Storehouse
  1736. storehouse_info, err = service.FindStorehouseName(storehouse.StorehouseInfo)
  1737. if err != nil {
  1738. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1739. return
  1740. }
  1741. storehouse_out_info, err = service.FindStorehouseName(storehouse.StorehouseOutInfo)
  1742. if err != nil {
  1743. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1744. return
  1745. }
  1746. drug_storehouse_info, err = service.FindStorehouseName(storehouse.DrugStorehouseInfo)
  1747. if err != nil {
  1748. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1749. return
  1750. }
  1751. drug_storehouse_out, err = service.FindStorehouseName(storehouse.DrugStorehouseOut)
  1752. if err != nil {
  1753. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1754. return
  1755. }
  1756. this.ServeSuccessJSON(map[string]interface{}{
  1757. "storehouse_info": storehouse_info.StorehouseName,
  1758. "storehouse_out_info": storehouse_out_info.StorehouseName,
  1759. "drug_storehouse_info": drug_storehouse_info.StorehouseName,
  1760. "drug_storehouse_out": drug_storehouse_out.StorehouseName,
  1761. })
  1762. return
  1763. }
  1764. //更改耗材自动入库仓库
  1765. func (this *SecondaryOrderApiController) UpdateInfo() {
  1766. orgId := this.GetAdminUserInfo().CurrentOrgId
  1767. check := map[string][]string{
  1768. "id": {"must", "int", "id"},
  1769. }
  1770. _, err := checkParams(this, &check)
  1771. if err != nil {
  1772. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1773. return
  1774. }
  1775. id, _ := this.GetInt64("id")
  1776. err = service.UpdateInfo(orgId, id)
  1777. //查询默认仓库
  1778. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1779. list, _ := service.GetAllGoodList(orgId)
  1780. for _, item := range list {
  1781. var sum_count int64
  1782. var sum_in_count int64
  1783. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ID, orgId)
  1784. for _, it := range goodList {
  1785. sum_count += it.StockCount
  1786. sum_in_count += it.WarehousingCount
  1787. }
  1788. service.UpdateGoodByGoodId(item.ID, sum_count, sum_in_count, orgId)
  1789. }
  1790. if err != nil {
  1791. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1792. return
  1793. }
  1794. this.ServeSuccessJSON(map[string]interface{}{
  1795. "list": "修改成功",
  1796. })
  1797. return
  1798. }
  1799. //更改耗材自动出库仓库
  1800. func (this *SecondaryOrderApiController) UpdateOutInfo() {
  1801. orgId := this.GetAdminUserInfo().CurrentOrgId
  1802. check := map[string][]string{
  1803. "id": {"must", "int", "id"},
  1804. }
  1805. _, err := checkParams(this, &check)
  1806. if err != nil {
  1807. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1808. return
  1809. }
  1810. id, _ := this.GetInt64("id")
  1811. err = service.UpdateOutInfo(orgId, id)
  1812. //查询默认仓库
  1813. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1814. list, _ := service.GetAllGoodList(orgId)
  1815. for _, item := range list {
  1816. var sum_count int64
  1817. var sum_in_count int64
  1818. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ID, orgId)
  1819. for _, it := range goodList {
  1820. sum_count += it.StockCount
  1821. sum_in_count += it.WarehousingCount
  1822. }
  1823. service.UpdateGoodByGoodId(item.ID, sum_count, sum_in_count, orgId)
  1824. }
  1825. if err != nil {
  1826. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1827. return
  1828. }
  1829. this.ServeSuccessJSON(map[string]interface{}{
  1830. "list": "修改成功",
  1831. })
  1832. return
  1833. }
  1834. //更改药品自动入库仓库
  1835. func (this *SecondaryOrderApiController) UpdateDrugInfo() {
  1836. orgId := this.GetAdminUserInfo().CurrentOrgId
  1837. check := map[string][]string{
  1838. "id": {"must", "int", "id"},
  1839. }
  1840. _, err := checkParams(this, &check)
  1841. if err != nil {
  1842. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1843. return
  1844. }
  1845. id, _ := this.GetInt64("id")
  1846. err = service.UpdateDrugInfo2(orgId, id)
  1847. //查询默认仓库
  1848. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1849. baseDrug, _ := service.GetAllBaseDrugList(orgId)
  1850. for _, item := range baseDrug {
  1851. var sum_drug_count int64
  1852. var sum_drug_in_count int64
  1853. //查询默认仓库剩余多少库存
  1854. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ID)
  1855. for _, it := range list {
  1856. if it.MaxUnit == item.MaxUnit {
  1857. it.StockMaxNumber = it.StockMaxNumber * item.MinNumber
  1858. it.WarehousingCount = it.WarehousingCount * item.MinNumber
  1859. }
  1860. sum_drug_count += it.StockMaxNumber + it.StockMinNumber
  1861. sum_drug_in_count += it.WarehousingCount
  1862. }
  1863. service.UpdateMedicalSumCount(item.ID, sum_drug_count, sum_drug_in_count, orgId)
  1864. }
  1865. if err != nil {
  1866. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1867. return
  1868. }
  1869. this.ServeSuccessJSON(map[string]interface{}{
  1870. "list": "修改成功",
  1871. })
  1872. return
  1873. }
  1874. //更改药品自动出库仓库
  1875. func (this *SecondaryOrderApiController) UpdateDrugOut() {
  1876. orgId := this.GetAdminUserInfo().CurrentOrgId
  1877. check := map[string][]string{
  1878. "id": {"must", "int", "id"},
  1879. }
  1880. _, err := checkParams(this, &check)
  1881. if err != nil {
  1882. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1883. return
  1884. }
  1885. id, _ := this.GetInt64("id")
  1886. err = service.UpdateDrugOut(orgId, id)
  1887. //查询默认仓库
  1888. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1889. baseDrug, _ := service.GetAllBaseDrugList(orgId)
  1890. for _, item := range baseDrug {
  1891. var sum_drug_count int64
  1892. var sum_drug_in_count int64
  1893. //查询默认仓库剩余多少库存
  1894. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ID)
  1895. for _, it := range list {
  1896. if it.MaxUnit == item.MaxUnit {
  1897. it.StockMaxNumber = it.StockMaxNumber * item.MinNumber
  1898. it.WarehousingCount = it.WarehousingCount * item.MinNumber
  1899. }
  1900. sum_drug_count += it.StockMaxNumber + it.StockMinNumber
  1901. sum_drug_in_count += it.WarehousingCount
  1902. }
  1903. service.UpdateMedicalSumCount(item.ID, sum_drug_count, sum_drug_in_count, orgId)
  1904. }
  1905. if err != nil {
  1906. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1907. return
  1908. }
  1909. this.ServeSuccessJSON(map[string]interface{}{
  1910. "list": "修改成功",
  1911. })
  1912. return
  1913. }
  1914. //判断前端参数是否为空
  1915. func checkParams(this *SecondaryOrderApiController, m *map[string][]string) (map[string]string, error) {
  1916. tmp := make(map[string]string)
  1917. for k, v := range *m {
  1918. t := this.GetString(k)
  1919. if v[0] == "must" && t == "" {
  1920. return nil, fmt.Errorf(v[2] + "不能为空")
  1921. }
  1922. tmp[k] = t
  1923. }
  1924. return tmp, nil
  1925. }
  1926. //兼容旧数据
  1927. func (this *SecondaryOrderApiController) Byliinit() {
  1928. err := service.Byliinit()
  1929. if err != nil {
  1930. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1931. return
  1932. }
  1933. this.ServeSuccessJSON(map[string]interface{}{
  1934. "list": "初始化成功",
  1935. })
  1936. return
  1937. }
  1938. //查询机构所属管理员
  1939. func (this *SecondaryOrderApiController) GetuserName() {
  1940. adminUserInfo := this.GetAdminUserInfo()
  1941. viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1942. //viewModels, _, _ := service.GetAdminUsersAndLoginInfo(10164, 12123, 1, 100)
  1943. c, _ := service.Getcreateid(adminUserInfo.CurrentOrgId)
  1944. //c, _ := service.Getcreateid(10164)
  1945. admin := []*service.AdminUserManageViewModel{} //记录当前管理员的信息
  1946. //去除禁用的角色
  1947. tmp := []*service.AdminUserManageViewModel{}
  1948. for i := 0; i < len(viewModels); i++ {
  1949. if viewModels[i].Status == 1 {
  1950. tmp = append(tmp, viewModels[i])
  1951. }
  1952. if int64(viewModels[i].AdminUserId) == c.Creator {
  1953. admin = append(admin, viewModels[i])
  1954. }
  1955. }
  1956. roles := service.FindRoles(adminUserInfo.CurrentOrgId)
  1957. //roles := service.FindRoles(10164)
  1958. //去除没有权限的角色
  1959. tmplist := []*service.AdminUserManageViewModel{}
  1960. if roles == nil || len(roles) == 0 {
  1961. this.ServeSuccessJSON(map[string]interface{}{
  1962. "list": admin,
  1963. })
  1964. return
  1965. }
  1966. for i := 0; i < len(tmp); i++ {
  1967. boolean := false
  1968. //获取并解析当前用户的角色
  1969. tmproles := strings.Split(tmp[i].RoleIds, ",")
  1970. for j := 0; j < len(tmproles); j++ {
  1971. //判断这些角色是否有权限
  1972. if _, ok := roles[tmproles[j]]; ok {
  1973. boolean = true
  1974. }
  1975. }
  1976. if boolean {
  1977. tmplist = append(tmplist, tmp[i])
  1978. }
  1979. }
  1980. isappend := true //判断结果中是否添加机构创建者,true添加,false不添加
  1981. if len(tmplist) > 0 {
  1982. for i := 0; i < len(tmplist); i++ {
  1983. if int64(tmplist[i].AdminUserId) == c.Creator {
  1984. isappend = false
  1985. }
  1986. }
  1987. }
  1988. if isappend {
  1989. tmplist = append(tmplist, admin...)
  1990. }
  1991. this.ServeSuccessJSON(map[string]interface{}{
  1992. "list": tmplist,
  1993. })
  1994. return
  1995. }
  1996. func (this *SecondaryOrderApiController) GetCreaterId() {
  1997. creater := this.GetAdminUserInfo().AdminUser.Id
  1998. this.ServeSuccessJSON(map[string]interface{}{
  1999. "list": creater,
  2000. })
  2001. }