secondary_order_api_contorller.go 89KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730
  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. import (
  18. "XT_New/enums"
  19. "XT_New/models"
  20. "XT_New/service"
  21. "XT_New/utils"
  22. "encoding/json"
  23. "fmt"
  24. "github.com/astaxie/beego"
  25. "github.com/jinzhu/gorm"
  26. "strings"
  27. "time"
  28. )
  29. type SecondaryOrderApiController struct {
  30. BaseAuthAPIController
  31. }
  32. func SecondaryOrderApiRegistRouters() {
  33. beego.Router("/api/secondary/getcode", &SecondaryOrderApiController{}, "get:GetStoreCode") //获取仓库编码
  34. beego.Router("/api/secondary/updatestatus", &SecondaryOrderApiController{}, "get:UpdateStatus") //修改仓库状态
  35. beego.Router("/api/secondary/deletestorehouse", &SecondaryOrderApiController{}, "get:DeleteStorehouse") //删除仓库
  36. beego.Router("/api/secondary/isstorehousename", &SecondaryOrderApiController{}, "get:IsStorehouseName") //仓库名称是否重复
  37. beego.Router("/api/secondary/isstorehouseaddress", &SecondaryOrderApiController{}, "get:IsStorehouseAddress") //仓库地址是否重复
  38. beego.Router("/api/secondary/storehouselist", &SecondaryOrderApiController{}, "get:StorehouseList") //分页
  39. beego.Router("/api/secondary/addstorehouse", &SecondaryOrderApiController{}, "post:AddStorehouse") //新增仓库
  40. beego.Router("/api/secondary/updatestorehouse", &SecondaryOrderApiController{}, "post:UpdateStorehouse") //修改
  41. beego.Router("/api/secondary/getonestorehouse", &SecondaryOrderApiController{}, "get:GetOneStorehouse") //查一条仓库的信息
  42. beego.Router("/api/secondary/getallstorehousename", &SecondaryOrderApiController{}, "get:GetAllStorehouseName") //获取当前机构的所有可用仓库名称
  43. beego.Router("/api/secondary/findstorehouseconfig", &SecondaryOrderApiController{}, "get:FindStorehouseConfig") //查询该机构的仓库配置
  44. beego.Router("/api/secondary/updateinfo", &SecondaryOrderApiController{}, "get:UpdateInfo") //更改耗材自动入库仓库
  45. beego.Router("/api/secondary/updateoutinfo", &SecondaryOrderApiController{}, "get:UpdateOutInfo") //更改耗材自动出库仓库
  46. beego.Router("/api/secondary/updatedruginfo", &SecondaryOrderApiController{}, "get:UpdateDrugInfo") //更改药品自动入库仓库
  47. beego.Router("/api/secondary/updatedrugout", &SecondaryOrderApiController{}, "get:UpdateDrugOut") //更改药品自动出库仓库
  48. beego.Router("/api/secondary/getusername", &SecondaryOrderApiController{}, "get:GetuserName") //获取仓库管理员信息
  49. beego.Router("/api/secondary/byliinit", &SecondaryOrderApiController{}, "get:Byliinit") //初始化旧数据
  50. beego.Router("/api/secondary/getcreaterid", &SecondaryOrderApiController{}, "get:GetCreaterId") //获取当前登录的人的id
  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. err = service.AddStroehouse(storehouse)
  326. if err != nil {
  327. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
  328. return
  329. }
  330. this.ServeSuccessJSON(map[string]interface{}{
  331. "list": "保存成功",
  332. })
  333. return
  334. }
  335. //修改仓库
  336. func (this *SecondaryOrderApiController) UpdateStorehouse() {
  337. orgId := this.GetAdminUserInfo().CurrentOrgId
  338. dataBody := make(map[string]interface{}, 0)
  339. //orgId := this.GetAdminUserInfo().CurrentOrgId
  340. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  341. if err != nil {
  342. utils.ErrorLog(err.Error())
  343. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  344. return
  345. }
  346. var storehouse_status, admin_id int64
  347. tmpstatus := dataBody["storehouse_status"]
  348. tmpid := dataBody["storehouse_admin_id"]
  349. if tmpstatus == nil {
  350. storehouse_status = 1
  351. } else {
  352. storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
  353. }
  354. if tmpid == nil {
  355. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
  356. return
  357. } else {
  358. admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
  359. }
  360. switch {
  361. case dataBody["id"] == nil:
  362. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库id不能为空")
  363. return
  364. case dataBody["storehouse_name"] == nil:
  365. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  366. return
  367. case dataBody["storehouse_address"] == nil:
  368. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  369. return
  370. }
  371. id := int64(dataBody["id"].(float64))
  372. name := dataBody["storehouse_name"].(string) //仓库名称
  373. address := dataBody["storehouse_address"].(string) //地址
  374. //查询当前仓库状态,根据当前状态判断是否需要更改
  375. list, errs := service.GetOneStorehouse(id, orgId)
  376. if errs != nil {
  377. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  378. return
  379. }
  380. if storehouse_status != list.StorehouseStatus && storehouse_status == 0 {
  381. //判断该仓库的库存是否为零
  382. boolean := service.IsStorehouseNil(id, orgId)
  383. if boolean == false {
  384. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  385. return
  386. }
  387. //判断该仓库是否在仓库配置表中
  388. boolean = service.IsInConfig(orgId, id)
  389. if boolean == true {
  390. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  391. return
  392. }
  393. }
  394. //判断仓库名称是否重复
  395. var bo bool
  396. bo, err = service.IsStorehouseNameUp(orgId, id, name)
  397. if bo == true {
  398. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  399. return
  400. }
  401. //判断仓库地址是否重复
  402. bo, err = service.IsStorehouseAddressUp(orgId, id, address)
  403. if bo == true {
  404. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  405. return
  406. }
  407. storehouse := models.Storehouse{
  408. ID: id,
  409. StorehouseName: name,
  410. StorehouseAddress: address,
  411. StorehouseStatus: storehouse_status,
  412. StorehouseAdminId: admin_id,
  413. Mtime: time.Now().Unix(),
  414. }
  415. err = service.UpdateStroehouse(storehouse)
  416. if err != nil {
  417. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
  418. return
  419. }
  420. this.ServeSuccessJSON(map[string]interface{}{
  421. "list": "保存成功",
  422. })
  423. return
  424. beego.Router("/api/secondary/getcode", &SecondaryOrderApiController{}, "get:GetStoreCode") //获取仓库编码
  425. beego.Router("/api/secondary/updatestatus", &SecondaryOrderApiController{}, "get:UpdateStatus") //修改仓库状态
  426. beego.Router("/api/secondary/deletestorehouse", &SecondaryOrderApiController{}, "get:DeleteStorehouse") //删除仓库
  427. beego.Router("/api/secondary/isstorehousename", &SecondaryOrderApiController{}, "get:IsStorehouseName") //仓库名称是否重复
  428. beego.Router("/api/secondary/isstorehouseaddress", &SecondaryOrderApiController{}, "get:IsStorehouseAddress") //仓库地址是否重复
  429. beego.Router("/api/secondary/storehouselist", &SecondaryOrderApiController{}, "get:StorehouseList") //分页
  430. beego.Router("/api/secondary/addstorehouse", &SecondaryOrderApiController{}, "post:AddStorehouse") //新增仓库
  431. beego.Router("/api/secondary/updatestorehouse", &SecondaryOrderApiController{}, "post:UpdateStorehouse") //修改
  432. beego.Router("/api/secondary/getonestorehouse", &SecondaryOrderApiController{}, "get:GetOneStorehouse") //查一条仓库的信息
  433. beego.Router("/api/secondary/getallstorehousename", &SecondaryOrderApiController{}, "get:GetAllStorehouseName") //获取当前机构的所有可用仓库名称
  434. beego.Router("/api/secondary/findstorehouseconfig", &SecondaryOrderApiController{}, "get:FindStorehouseConfig") //查询该机构的仓库配置
  435. beego.Router("/api/secondary/updateinfo", &SecondaryOrderApiController{}, "get:UpdateInfo") //更改耗材自动入库仓库
  436. beego.Router("/api/secondary/updateoutinfo", &SecondaryOrderApiController{}, "get:UpdateOutInfo") //更改耗材自动出库仓库
  437. beego.Router("/api/secondary/updatedruginfo", &SecondaryOrderApiController{}, "get:UpdateDrugInfo") //更改药品自动入库仓库
  438. beego.Router("/api/secondary/updatedrugout", &SecondaryOrderApiController{}, "get:UpdateDrugOut") //更改药品自动出库仓库
  439. beego.Router("/api/secondary/getusername", &SecondaryOrderApiController{}, "get:GetuserName") //获取仓库管理员信息
  440. beego.Router("/api/secondary/byliinit", &SecondaryOrderApiController{}, "get:Byliinit") //初始化旧数据
  441. beego.Router("/api/secondary/getcreaterid", &SecondaryOrderApiController{}, "get:GetCreaterId")
  442. beego.Router("/api/seconde/getsencondegoodlist", &SecondaryOrderApiController{}, "Get:GetSencondeGoodList")
  443. beego.Router("/api/senconde/savesencondorder", &SecondaryOrderApiController{}, "Post:SaveSencondOrder")
  444. beego.Router("/api/senconde/getallsecondeorderlist", &SecondaryOrderApiController{}, "Get:GetAllSecondeOrderList")
  445. beego.Router("/api/senconde/getsencondorderdetail", &SecondaryOrderApiController{}, "Get:GetSencondOrderDetail")
  446. beego.Router("/api/senconde/updatesencondorder", &SecondaryOrderApiController{}, "Post:UpdateSencondOrder")
  447. beego.Router("/api/sencond/getsecondorderbyid", &SecondaryOrderApiController{}, "Get:GetSecondOrderById")
  448. beego.Router("/api/sencond/checksecondorder", &SecondaryOrderApiController{}, "Get:CheckSecondOrer")
  449. beego.Router("/api/sencond/deletestorehouselist", &SecondaryOrderApiController{}, "Get:DeleteStorehouseList")
  450. beego.Router("/api/sencond/returnchecksecondeorder", &SecondaryOrderApiController{}, "Get:ReturnCheckSecondOrder")
  451. beego.Router("/api/second/getstorehousegoodlist", &SecondaryOrderApiController{}, "Get:GetStoreHouseGoodList")
  452. beego.Router("/api/second/getsumsecondecount", &SecondaryOrderApiController{}, "Get:GetSumSecondCount")
  453. beego.Router("/api/second/deletesecondorderinfo", &SecondaryOrderApiController{}, "Get:DeleteSecondOrderInfo")
  454. }
  455. //获取仓库编码
  456. func (this *SecondaryOrderApiController) GetStoreCode() {
  457. orgId := this.GetAdminUserInfo().CurrentOrgId
  458. var code string
  459. for a := true; a == true; {
  460. code = service.CreateCode()
  461. tmp := service.FindStorehouseCode(orgId, code)
  462. //如果没有重复的编码结束循环
  463. if tmp == false {
  464. a = false
  465. }
  466. }
  467. this.ServeSuccessJSON(map[string]interface{}{
  468. "list": code,
  469. })
  470. return
  471. }
  472. //修改仓库状态
  473. func (this *SecondaryOrderApiController) UpdateStatus() {
  474. orgId := this.GetAdminUserInfo().CurrentOrgId
  475. check := map[string][]string{
  476. "id": {"must", "int", "id"},
  477. }
  478. _, err := checkParams(this, &check)
  479. if err != nil {
  480. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  481. return
  482. }
  483. id, _ := this.GetInt64("id")
  484. //判断该仓库的库存是否为零
  485. boolean := service.IsStorehouseNil(id, orgId)
  486. if boolean == false {
  487. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  488. return
  489. }
  490. //判断该仓库是否在仓库配置表中
  491. boolean = service.IsInConfig(orgId, id)
  492. if boolean == true {
  493. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  494. return
  495. }
  496. //修改仓库状态
  497. err = service.UpdateStorehouseStatus(id)
  498. if err != nil {
  499. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  500. return
  501. }
  502. this.ServeSuccessJSON(map[string]interface{}{
  503. "list": "修改成功",
  504. })
  505. return
  506. }
  507. //删除仓库
  508. func (this *SecondaryOrderApiController) DeleteStorehouse() {
  509. orgId := this.GetAdminUserInfo().CurrentOrgId
  510. check := map[string][]string{
  511. "id": {"must", "int", "id"},
  512. }
  513. _, err := checkParams(this, &check)
  514. if err != nil {
  515. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  516. return
  517. }
  518. id, _ := this.GetInt64("id")
  519. //判断该仓库的库存是否为零
  520. boolean := service.IsStorehouseNil(id, orgId)
  521. if boolean == false {
  522. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  523. return
  524. }
  525. //判断该仓库是否在仓库配置表中
  526. boolean = service.IsInConfig(orgId, id)
  527. if boolean == true {
  528. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  529. return
  530. }
  531. err = service.DeleteStorehouse(id)
  532. if err != nil {
  533. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  534. return
  535. }
  536. this.ServeSuccessJSON(map[string]interface{}{
  537. "list": "删除成功",
  538. })
  539. return
  540. }
  541. //仓库名称是否重复
  542. func (this *SecondaryOrderApiController) IsStorehouseName() {
  543. orgId := this.GetAdminUserInfo().CurrentOrgId
  544. storehouse_name := this.GetString("storehouse_name")
  545. check := map[string][]string{
  546. "storehouse_name": {"must", "string", "storehouse_name"},
  547. }
  548. _, err := checkParams(this, &check)
  549. if err != nil {
  550. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  551. return
  552. }
  553. var bo bool
  554. bo, err = service.IsStorehouseName(orgId, storehouse_name)
  555. if bo == true {
  556. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  557. return
  558. }
  559. this.ServeSuccessJSON(map[string]interface{}{
  560. "list": "ok",
  561. })
  562. return
  563. }
  564. //仓库地址是否重复
  565. func (this *SecondaryOrderApiController) IsStorehouseAddress() {
  566. orgId := this.GetAdminUserInfo().CurrentOrgId
  567. storehouse_address := this.GetString("storehouse_address")
  568. check := map[string][]string{
  569. "storehouse_address": {"must", "string", "storehouse_address"},
  570. }
  571. _, err := checkParams(this, &check)
  572. if err != nil {
  573. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  574. return
  575. }
  576. var bo bool
  577. bo, err = service.IsStorehouseAddress(orgId, storehouse_address)
  578. if bo == true {
  579. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  580. return
  581. }
  582. this.ServeSuccessJSON(map[string]interface{}{
  583. "list": "ok",
  584. })
  585. return
  586. }
  587. //分页
  588. func (this *SecondaryOrderApiController) StorehouseList() {
  589. adminUserInfo := this.GetAdminUserInfo()
  590. page, _ := this.GetInt64("page") //页码
  591. limit, _ := this.GetInt64("limit") //每一页查出来的条数
  592. check := map[string][]string{
  593. "page": {"must", "string", "page"},
  594. "limit": {"must", "string", "limit"},
  595. }
  596. _, err := checkParams(this, &check)
  597. keyword := this.GetString("keyword")
  598. orgId := this.GetAdminUserInfo().CurrentOrgId
  599. if err != nil {
  600. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  601. }
  602. namemap := make(map[int64]string)
  603. //根据管理员id获取管理员
  604. viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  605. for _, v := range viewModels {
  606. namemap[int64(v.AdminUserId)] = v.UserName
  607. }
  608. slicekey := make([]int64, 0)
  609. if len(keyword) > 0 {
  610. for k, v := range namemap {
  611. res := strings.Contains(v, keyword)
  612. if res == true {
  613. slicekey = append(slicekey, k)
  614. }
  615. }
  616. }
  617. //获取分页的数据
  618. list, total, err := service.StorehouseList(page, limit, orgId, keyword, slicekey)
  619. //分页
  620. type Storehouselist struct {
  621. ID int64
  622. StorehouseCode string //仓库编号
  623. StorehouseName string //仓库名称
  624. StorehouseAddress string //仓库地址
  625. StorehouseStatus int64 //仓库状态
  626. Status int64 //数据状态
  627. StorehouseAdminId int64 //仓库管理员id
  628. StorehouseAdminName string //仓库管理员名字
  629. UserOrgId int64
  630. }
  631. //初始化该结构体
  632. tmplist := []*Storehouselist{}
  633. for i := 0; i < len(list); i++ {
  634. tlist := &Storehouselist{
  635. list[i].ID,
  636. list[i].StorehouseCode,
  637. list[i].StorehouseName,
  638. list[i].StorehouseAddress,
  639. list[i].StorehouseStatus,
  640. list[i].Status,
  641. list[i].StorehouseAdminId,
  642. "",
  643. list[i].UserOrgId,
  644. }
  645. tmplist = append(tmplist, tlist)
  646. }
  647. for _, v := range tmplist {
  648. if k, ok := namemap[v.StorehouseAdminId]; ok {
  649. v.StorehouseAdminName = k
  650. } else {
  651. v.StorehouseAdminName = "超级管理员"
  652. }
  653. }
  654. this.ServeSuccessJSON(map[string]interface{}{
  655. "list": tmplist,
  656. "total": total,
  657. })
  658. }
  659. //新增仓库
  660. func (this *SecondaryOrderApiController) AddStorehouse() {
  661. orgId := this.GetAdminUserInfo().CurrentOrgId
  662. dataBody := make(map[string]interface{}, 0)
  663. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  664. if err != nil {
  665. utils.ErrorLog(err.Error())
  666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  667. return
  668. }
  669. var storehouse_status, admin_id int64
  670. tmpstatus := dataBody["storehouse_status"]
  671. tmpid := dataBody["storehouse_admin_id"] //管理员id
  672. if tmpstatus == nil {
  673. storehouse_status = 1
  674. } else {
  675. storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
  676. }
  677. if tmpid == nil {
  678. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
  679. return
  680. } else {
  681. admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
  682. }
  683. switch {
  684. case dataBody["storehouse_code"] == nil:
  685. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库编号不能为空")
  686. return
  687. case dataBody["storehouse_name"] == nil:
  688. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  689. return
  690. case dataBody["storehouse_address"] == nil:
  691. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  692. return
  693. }
  694. code := dataBody["storehouse_code"].(string) //仓库编号
  695. name := dataBody["storehouse_name"].(string) //仓库名称
  696. address := dataBody["storehouse_address"].(string) //地址
  697. switch {
  698. case name == "":
  699. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  700. return
  701. case address == "":
  702. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  703. return
  704. }
  705. //判断仓库名称是否重复
  706. var bo bool
  707. bo, err = service.IsStorehouseName(orgId, name)
  708. if bo == true {
  709. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  710. return
  711. }
  712. //判断仓库地址是否重复
  713. bo, err = service.IsStorehouseAddress(orgId, address)
  714. if bo == true {
  715. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  716. return
  717. }
  718. storehouse := models.Storehouse{
  719. StorehouseCode: code,
  720. StorehouseName: name,
  721. StorehouseAddress: address,
  722. StorehouseStatus: storehouse_status,
  723. UserOrgId: orgId,
  724. Status: 1,
  725. StorehouseAdminId: admin_id,
  726. Ctime: time.Now().Unix(),
  727. }
  728. err = service.AddStroehouse(storehouse)
  729. if err != nil {
  730. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
  731. return
  732. }
  733. this.ServeSuccessJSON(map[string]interface{}{
  734. "list": "保存成功",
  735. })
  736. return
  737. }
  738. //修改仓库
  739. func (this *SecondaryOrderApiController) UpdateStorehouse() {
  740. orgId := this.GetAdminUserInfo().CurrentOrgId
  741. dataBody := make(map[string]interface{}, 0)
  742. //orgId := this.GetAdminUserInfo().CurrentOrgId
  743. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  744. if err != nil {
  745. utils.ErrorLog(err.Error())
  746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  747. return
  748. }
  749. var storehouse_status, admin_id int64
  750. tmpstatus := dataBody["storehouse_status"]
  751. tmpid := dataBody["storehouse_admin_id"]
  752. if tmpstatus == nil {
  753. storehouse_status = 1
  754. } else {
  755. storehouse_status = int64(dataBody["storehouse_status"].(float64)) //状态
  756. }
  757. if tmpid == nil {
  758. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "管理员id不能为空")
  759. return
  760. } else {
  761. admin_id = int64(dataBody["storehouse_admin_id"].(float64)) //管理员id
  762. }
  763. switch {
  764. case dataBody["id"] == nil:
  765. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库id不能为空")
  766. return
  767. case dataBody["storehouse_name"] == nil:
  768. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库名称不能为空")
  769. return
  770. case dataBody["storehouse_address"] == nil:
  771. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "仓库地址不能为空")
  772. return
  773. }
  774. id := int64(dataBody["id"].(float64))
  775. name := dataBody["storehouse_name"].(string) //仓库名称
  776. address := dataBody["storehouse_address"].(string) //地址
  777. //查询当前仓库状态,根据当前状态判断是否需要更改
  778. list, errs := service.GetOneStorehouse(id, orgId)
  779. if errs != nil {
  780. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  781. return
  782. }
  783. if storehouse_status != list.StorehouseStatus && storehouse_status == 0 {
  784. //判断该仓库的库存是否为零
  785. boolean := service.IsStorehouseNil(id, orgId)
  786. if boolean == false {
  787. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库库存不为0,不支持该操作")
  788. return
  789. }
  790. //判断该仓库是否在仓库配置表中
  791. boolean = service.IsInConfig(orgId, id)
  792. if boolean == true {
  793. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前仓库是自动出入库仓库,请先取消自动出入库之后才能进行此操作")
  794. return
  795. }
  796. }
  797. //判断仓库名称是否重复
  798. var bo bool
  799. bo, err = service.IsStorehouseName(orgId, name)
  800. if bo == true {
  801. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该仓库已存在,请重新输入")
  802. return
  803. }
  804. //判断仓库地址是否重复
  805. bo, err = service.IsStorehouseAddress(orgId, address)
  806. if bo == true {
  807. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "该地址已存在,请重新输入")
  808. return
  809. }
  810. storehouse := models.Storehouse{
  811. ID: id,
  812. StorehouseName: name,
  813. StorehouseAddress: address,
  814. StorehouseStatus: storehouse_status,
  815. StorehouseAdminId: admin_id,
  816. Mtime: time.Now().Unix(),
  817. }
  818. err = service.UpdateStroehouse(storehouse)
  819. if err != nil {
  820. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "保存失败")
  821. return
  822. }
  823. this.ServeSuccessJSON(map[string]interface{}{
  824. "list": "保存成功",
  825. })
  826. return
  827. }
  828. //查询一条仓库信息
  829. func (this *SecondaryOrderApiController) GetOneStorehouse() {
  830. orgId := this.GetAdminUserInfo().CurrentOrgId
  831. check := map[string][]string{
  832. "id": {"must", "int", "id"},
  833. }
  834. _, err := checkParams(this, &check)
  835. if err != nil {
  836. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  837. return
  838. }
  839. id, _ := this.GetInt64("id")
  840. var list models.Storehouse
  841. list, err = service.GetOneStorehouse(id, orgId)
  842. if err != nil {
  843. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  844. return
  845. }
  846. this.ServeSuccessJSON(map[string]interface{}{
  847. "list": list,
  848. })
  849. return
  850. }
  851. //获取当前机构所有可用仓库的名字
  852. func (this *SecondaryOrderApiController) GetAllStorehouseName() {
  853. orgId := this.GetAdminUserInfo().CurrentOrgId
  854. list, err := service.GetAllStorehouseName(orgId)
  855. if err != nil {
  856. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  857. return
  858. }
  859. this.ServeSuccessJSON(map[string]interface{}{
  860. "list": list,
  861. })
  862. }
  863. //根据机构id查询仓库配置
  864. func (this *SecondaryOrderApiController) FindStorehouseConfig() {
  865. orgId := this.GetAdminUserInfo().CurrentOrgId
  866. storehouse, err := service.FindStorehouseConfig(orgId)
  867. //如果没有仓库配置信息就新建一个
  868. if err == gorm.ErrRecordNotFound {
  869. err := service.GetDefaultStorehouse(orgId)
  870. if err != nil {
  871. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  872. return
  873. }
  874. storehouse, err = service.FindStorehouseConfig(orgId)
  875. if err != nil {
  876. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  877. return
  878. }
  879. }
  880. if err != nil && err.Error() != "record not found" {
  881. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  882. return
  883. }
  884. var storehouse_info, storehouse_out_info, drug_storehouse_info, drug_storehouse_out models.Storehouse
  885. storehouse_info, err = service.FindStorehouseName(storehouse.StorehouseInfo)
  886. if err != nil {
  887. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  888. return
  889. }
  890. storehouse_out_info, err = service.FindStorehouseName(storehouse.StorehouseOutInfo)
  891. if err != nil {
  892. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  893. return
  894. }
  895. drug_storehouse_info, err = service.FindStorehouseName(storehouse.DrugStorehouseInfo)
  896. if err != nil {
  897. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  898. return
  899. }
  900. drug_storehouse_out, err = service.FindStorehouseName(storehouse.DrugStorehouseOut)
  901. if err != nil {
  902. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  903. return
  904. }
  905. this.ServeSuccessJSON(map[string]interface{}{
  906. "storehouse_info": storehouse_info.StorehouseName,
  907. "storehouse_out_info": storehouse_out_info.StorehouseName,
  908. "drug_storehouse_info": drug_storehouse_info.StorehouseName,
  909. "drug_storehouse_out": drug_storehouse_out.StorehouseName,
  910. })
  911. return
  912. }
  913. //更改耗材自动入库仓库
  914. func (this *SecondaryOrderApiController) UpdateInfo() {
  915. orgId := this.GetAdminUserInfo().CurrentOrgId
  916. check := map[string][]string{
  917. "id": {"must", "int", "id"},
  918. }
  919. _, err := checkParams(this, &check)
  920. if err != nil {
  921. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  922. return
  923. }
  924. id, _ := this.GetInt64("id")
  925. err = service.UpdateInfo(orgId, id)
  926. //查询默认仓库
  927. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  928. list, _ := service.GetAllGoodList(orgId)
  929. for _, item := range list {
  930. var sum_count int64
  931. var sum_in_count int64
  932. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ID, orgId)
  933. for _, it := range goodList {
  934. sum_count += it.StockCount
  935. sum_in_count += it.WarehousingCount
  936. }
  937. service.UpdateGoodByGoodId(item.ID, sum_count, sum_in_count, orgId)
  938. }
  939. if err != nil {
  940. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  941. return
  942. }
  943. this.ServeSuccessJSON(map[string]interface{}{
  944. "list": "修改成功",
  945. })
  946. return
  947. }
  948. //更改耗材自动出库仓库
  949. func (this *SecondaryOrderApiController) UpdateOutInfo() {
  950. orgId := this.GetAdminUserInfo().CurrentOrgId
  951. check := map[string][]string{
  952. "id": {"must", "int", "id"},
  953. }
  954. _, err := checkParams(this, &check)
  955. if err != nil {
  956. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  957. return
  958. }
  959. id, _ := this.GetInt64("id")
  960. err = service.UpdateOutInfo(orgId, id)
  961. //查询默认仓库
  962. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  963. list, _ := service.GetAllGoodList(orgId)
  964. for _, item := range list {
  965. var sum_count int64
  966. var sum_in_count int64
  967. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ID, orgId)
  968. for _, it := range goodList {
  969. sum_count += it.StockCount
  970. sum_in_count += it.WarehousingCount
  971. }
  972. service.UpdateGoodByGoodId(item.ID, sum_count, sum_in_count, orgId)
  973. }
  974. if err != nil {
  975. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  976. return
  977. }
  978. this.ServeSuccessJSON(map[string]interface{}{
  979. "list": "修改成功",
  980. })
  981. return
  982. }
  983. //更改药品自动入库仓库
  984. func (this *SecondaryOrderApiController) UpdateDrugInfo() {
  985. orgId := this.GetAdminUserInfo().CurrentOrgId
  986. check := map[string][]string{
  987. "id": {"must", "int", "id"},
  988. }
  989. _, err := checkParams(this, &check)
  990. if err != nil {
  991. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  992. return
  993. }
  994. id, _ := this.GetInt64("id")
  995. err = service.UpdateDrugInfo2(orgId, id)
  996. //查询默认仓库
  997. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  998. baseDrug, _ := service.GetAllBaseDrugList(orgId)
  999. for _, item := range baseDrug {
  1000. var sum_drug_count int64
  1001. var sum_drug_in_count int64
  1002. //查询默认仓库剩余多少库存
  1003. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ID)
  1004. for _, it := range list {
  1005. if it.MaxUnit == item.MaxUnit {
  1006. it.StockMaxNumber = it.StockMaxNumber * item.MinNumber
  1007. it.WarehousingCount = it.WarehousingCount * item.MinNumber
  1008. }
  1009. sum_drug_count += it.StockMaxNumber + it.StockMinNumber
  1010. sum_drug_in_count += it.WarehousingCount
  1011. }
  1012. service.UpdateMedicalSumCount(item.ID, sum_drug_count, sum_drug_in_count, orgId)
  1013. }
  1014. if err != nil {
  1015. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1016. return
  1017. }
  1018. this.ServeSuccessJSON(map[string]interface{}{
  1019. "list": "修改成功",
  1020. })
  1021. return
  1022. }
  1023. //更改药品自动出库仓库
  1024. func (this *SecondaryOrderApiController) UpdateDrugOut() {
  1025. orgId := this.GetAdminUserInfo().CurrentOrgId
  1026. check := map[string][]string{
  1027. "id": {"must", "int", "id"},
  1028. }
  1029. _, err := checkParams(this, &check)
  1030. if err != nil {
  1031. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1032. return
  1033. }
  1034. id, _ := this.GetInt64("id")
  1035. err = service.UpdateDrugOut(orgId, id)
  1036. //查询默认仓库
  1037. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1038. baseDrug, _ := service.GetAllBaseDrugList(orgId)
  1039. for _, item := range baseDrug {
  1040. var sum_drug_count int64
  1041. var sum_drug_in_count int64
  1042. //查询默认仓库剩余多少库存
  1043. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ID)
  1044. for _, it := range list {
  1045. if it.MaxUnit == item.MaxUnit {
  1046. it.StockMaxNumber = it.StockMaxNumber * item.MinNumber
  1047. it.WarehousingCount = it.WarehousingCount * item.MinNumber
  1048. }
  1049. sum_drug_count += it.StockMaxNumber + it.StockMinNumber
  1050. sum_drug_in_count += it.WarehousingCount
  1051. }
  1052. service.UpdateMedicalSumCount(item.ID, sum_drug_count, sum_drug_in_count, orgId)
  1053. }
  1054. if err != nil {
  1055. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1056. return
  1057. }
  1058. this.ServeSuccessJSON(map[string]interface{}{
  1059. "list": "修改成功",
  1060. })
  1061. return
  1062. }
  1063. //判断前端参数是否为空
  1064. func checkParams(this *SecondaryOrderApiController, m *map[string][]string) (map[string]string, error) {
  1065. tmp := make(map[string]string)
  1066. for k, v := range *m {
  1067. t := this.GetString(k)
  1068. if v[0] == "must" && t == "" {
  1069. return nil, fmt.Errorf(v[2] + "不能为空")
  1070. }
  1071. tmp[k] = t
  1072. }
  1073. return tmp, nil
  1074. }
  1075. //兼容旧数据
  1076. func (this *SecondaryOrderApiController) Byliinit() {
  1077. err := service.Byliinit()
  1078. if err != nil {
  1079. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1080. return
  1081. }
  1082. this.ServeSuccessJSON(map[string]interface{}{
  1083. "list": "初始化成功",
  1084. })
  1085. return
  1086. }
  1087. //查询机构所属管理员
  1088. func (this *SecondaryOrderApiController) GetuserName() {
  1089. adminUserInfo := this.GetAdminUserInfo()
  1090. viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1091. c, _ := service.Getcreateid(adminUserInfo.CurrentOrgId)
  1092. //c.Creator
  1093. admin := []*service.AdminUserManageViewModel{} //记录当前管理员的信息
  1094. //去除禁用的角色
  1095. tmp := []*service.AdminUserManageViewModel{}
  1096. for i := 0; i < len(viewModels); i++ {
  1097. if viewModels[i].Status == 1 {
  1098. tmp = append(tmp, viewModels[i])
  1099. }
  1100. if int64(viewModels[i].AdminUserId) == c.Creator {
  1101. admin = append(admin, viewModels[i])
  1102. }
  1103. }
  1104. roles := service.FindRoles(adminUserInfo.CurrentOrgId)
  1105. //去除没有权限的角色
  1106. tmplist := []*service.AdminUserManageViewModel{}
  1107. if roles == nil || len(roles) == 0 {
  1108. this.ServeSuccessJSON(map[string]interface{}{
  1109. "list": tmplist,
  1110. })
  1111. return
  1112. }
  1113. for i := 0; i < len(tmp); i++ {
  1114. boolean := false
  1115. //获取并解析当前用户的角色
  1116. tmproles := strings.Split(tmp[i].RoleIds, ",")
  1117. for j := 0; j < len(tmproles); j++ {
  1118. //判断这些角色是否有权限
  1119. if _, ok := roles[tmproles[j]]; ok {
  1120. boolean = true
  1121. }
  1122. }
  1123. if boolean {
  1124. tmplist = append(tmplist, tmp[i])
  1125. }
  1126. }
  1127. isappend := true //判断结果中是否添加机构创建者,true添加,false不添加
  1128. if len(tmplist) > 0 {
  1129. for i := 0; i < len(tmplist); i++ {
  1130. if int64(tmplist[i].AdminUserId) == c.Creator {
  1131. isappend = false
  1132. }
  1133. }
  1134. }
  1135. if isappend {
  1136. tmplist = append(tmplist, admin...)
  1137. }
  1138. this.ServeSuccessJSON(map[string]interface{}{
  1139. "list": tmplist,
  1140. })
  1141. return
  1142. }
  1143. func (this *SecondaryOrderApiController) GetCreaterId() {
  1144. creater := this.GetAdminUserInfo().AdminUser.Id
  1145. this.ServeSuccessJSON(map[string]interface{}{
  1146. "list": creater,
  1147. })
  1148. }
  1149. //
  1150. func (this *SecondaryOrderApiController) GetSencondeGoodList() {
  1151. orgId := this.GetAdminUserInfo().CurrentOrgId
  1152. //houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1153. ////获取药品库数据
  1154. //baseList, _ := service.GetSupplyDrugListOne(orgId,houseConfig.DrugStorehouseOut)
  1155. //
  1156. //goodList, _ := service.GetSupplyGoodListOne(orgId,houseConfig.StorehouseOutInfo)
  1157. //
  1158. //goodTypeList, _ := service.GetAllGoodType(orgId)
  1159. houseList, _ := service.GetAllStoreHouseListThree(orgId)
  1160. //configlist, _ := service.GetAllStoreHouseConfig(orgId)
  1161. //var drugType = "药品类型"
  1162. //drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1163. //drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  1164. this.ServeSuccessJSON(map[string]interface{}{
  1165. //"drugList": baseList,
  1166. //"goodList": goodList,
  1167. //"goodTypeList": goodTypeList,
  1168. //"drugTypeList": drugTypeList,
  1169. "houseList": houseList,
  1170. //"configlist":configlist,
  1171. })
  1172. return
  1173. }
  1174. func (this *SecondaryOrderApiController) SaveSencondOrder() {
  1175. start_date := this.GetString("record_date")
  1176. storehouse_in_id, _ := this.GetInt64("storehouse_in_id")
  1177. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  1178. fmt.Println(storehouse_in_id, storehouse_out_id)
  1179. timeLayout := "2006-01-02"
  1180. loc, _ := time.LoadLocation("Local")
  1181. var startDate int64
  1182. if len(start_date) > 0 {
  1183. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1184. if err != nil {
  1185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1186. return
  1187. }
  1188. startDate = theTime.Unix()
  1189. }
  1190. //生成购货订单
  1191. timeStr := time.Now().Format("2006-01-02")
  1192. timeArr := strings.Split(timeStr, "-")
  1193. orgId := this.GetAdminUserInfo().CurrentOrgId
  1194. warehousing_order := "DB1010" + timeArr[0] + timeArr[1] + timeArr[2] + fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000))
  1195. recordDateStr := time.Now().Format("2006-01-02")
  1196. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1197. record_date := recordDate.Unix()
  1198. creater := this.GetAdminUserInfo().AdminUser.Id
  1199. warehouse := models.XtSecondWarehouse{
  1200. SecondOrderNumber: warehousing_order,
  1201. Creater: creater,
  1202. RecordDate: startDate,
  1203. Checker: 0,
  1204. IsCheck: 2,
  1205. UserOrgId: orgId,
  1206. Status: 1,
  1207. Ctime: time.Now().Unix(),
  1208. StorehouseInId: storehouse_in_id,
  1209. StorehouseOutId: storehouse_out_id,
  1210. }
  1211. //查询改订单号是否存在
  1212. _, errcode := service.GetSecondWarehouseByNumber(orgId, warehousing_order)
  1213. if errcode == gorm.ErrRecordNotFound {
  1214. service.CreateSecondeWarehouse(warehouse)
  1215. } else if errcode == nil {
  1216. order := "DB1010" + timeArr[0] + timeArr[1] + timeArr[2] + fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000))
  1217. warehouse.SecondOrderNumber = order
  1218. service.CreateSecondeWarehouse(warehouse)
  1219. }
  1220. secondWarehouse, _ := service.GetLastSecondWarehouse(orgId)
  1221. var warehousingInfo []*models.XtSecondWarehouseInfo
  1222. dataBody := make(map[string]interface{}, 0)
  1223. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1224. if err != nil {
  1225. utils.ErrorLog(err.Error())
  1226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1227. return
  1228. }
  1229. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1230. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1231. if len(thisStockIn) > 0 {
  1232. for _, item := range thisStockIn {
  1233. items := item.(map[string]interface{})
  1234. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1235. utils.ErrorLog("project_id")
  1236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1237. return
  1238. }
  1239. project_id := int64(items["project_id"].(float64))
  1240. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1241. utils.ErrorLog("name")
  1242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1243. return
  1244. }
  1245. project_name := items["name"].(string)
  1246. if items["project_type"] == nil || reflect.TypeOf(items["project_type"]).String() != "string" {
  1247. utils.ErrorLog("project_type")
  1248. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1249. return
  1250. }
  1251. project_type := items["project_type"].(string)
  1252. if items["second_specification_name"] == nil || reflect.TypeOf(items["second_specification_name"]).String() != "string" {
  1253. utils.ErrorLog("second_specification_name")
  1254. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1255. return
  1256. }
  1257. second_specification_name := items["second_specification_name"].(string)
  1258. if items["sencond_unit"] == nil || reflect.TypeOf(items["sencond_unit"]).String() != "string" {
  1259. utils.ErrorLog("sencond_unit")
  1260. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1261. return
  1262. }
  1263. sencond_unit := items["sencond_unit"].(string)
  1264. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1265. utils.ErrorLog("count")
  1266. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1267. return
  1268. }
  1269. count := int64(items["count"].(float64))
  1270. if items["is_source"] == nil || reflect.TypeOf(items["is_source"]).String() != "float64" {
  1271. utils.ErrorLog("is_source")
  1272. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1273. return
  1274. }
  1275. is_source := int64(items["is_source"].(float64))
  1276. if items["second_total"] == nil || reflect.TypeOf(items["second_total"]).String() != "string" {
  1277. utils.ErrorLog("second_total")
  1278. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1279. return
  1280. }
  1281. second_total := items["second_total"].(string)
  1282. if items["remake"] == nil || reflect.TypeOf(items["remake"]).String() != "string" {
  1283. utils.ErrorLog("remake")
  1284. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1285. return
  1286. }
  1287. remake := items["remake"].(string)
  1288. if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "float64" {
  1289. utils.ErrorLog("min_price")
  1290. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1291. return
  1292. }
  1293. min_price := items["min_price"].(float64)
  1294. info := &models.XtSecondWarehouseInfo{
  1295. ProjectName: project_name,
  1296. SecondSpecificationName: second_specification_name,
  1297. ProjectType: project_type,
  1298. SencondUnit: sencond_unit,
  1299. Count: count,
  1300. SecondTotal: second_total,
  1301. SecondOrderNumber: secondWarehouse.SecondOrderNumber,
  1302. RecordDate: record_date,
  1303. StorehouseInId: storehouse_in_id,
  1304. StorehouseOutId: storehouse_out_id,
  1305. Creater: creater,
  1306. ProjectId: project_id,
  1307. Remake: remake,
  1308. UserOrgId: orgId,
  1309. Status: 1,
  1310. Ctime: time.Now().Unix(),
  1311. Mtime: 0,
  1312. MinPrice: min_price,
  1313. IsSource: is_source,
  1314. WarehouseId: secondWarehouse.ID,
  1315. }
  1316. warehousingInfo = append(warehousingInfo, info)
  1317. }
  1318. }
  1319. }
  1320. for _, item := range warehousingInfo {
  1321. service.CreateSencondWarehousingInfo(item)
  1322. }
  1323. //获取最后一条入库单
  1324. lastSecondWarehouse, _ := service.GetLastSecondWarehouse(orgId)
  1325. this.ServeSuccessJSON(map[string]interface{}{
  1326. "warehousingInfo": warehousingInfo,
  1327. "id": lastSecondWarehouse.ID,
  1328. })
  1329. return
  1330. }
  1331. func (this *SecondaryOrderApiController) GetAllSecondeOrderList() {
  1332. check_id, _ := this.GetInt64("check_id")
  1333. start_time := this.GetString("start_time")
  1334. timeLayout := "2006-01-02"
  1335. loc, _ := time.LoadLocation("Local")
  1336. var startTime int64
  1337. if len(start_time) > 0 {
  1338. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1339. if err != nil {
  1340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1341. return
  1342. }
  1343. startTime = theTime.Unix()
  1344. }
  1345. end_time := this.GetString("end_time")
  1346. var endTime int64
  1347. if len(end_time) > 0 {
  1348. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1349. if err != nil {
  1350. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1351. return
  1352. }
  1353. endTime = theTime.Unix()
  1354. }
  1355. keyword := this.GetString("keyword")
  1356. page, _ := this.GetInt64("page")
  1357. limit, _ := this.GetInt64("limit")
  1358. orgId := this.GetAdminUserInfo().CurrentOrgId
  1359. list, total, _ := service.GetAllSecondeOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
  1360. houseList, _ := service.GetAllStoreHouseList(orgId)
  1361. appId := this.GetAdminUserInfo().CurrentAppId
  1362. doctor, _ := service.GetAllDoctorListSix(orgId, appId)
  1363. this.ServeSuccessJSON(map[string]interface{}{
  1364. "list": list,
  1365. "total": total,
  1366. "houseList": houseList,
  1367. "doctorList": doctor,
  1368. })
  1369. return
  1370. }
  1371. func (this *SecondaryOrderApiController) GetSencondOrderDetail() {
  1372. id, _ := this.GetInt64("id")
  1373. orgId := this.GetAdminUserInfo().CurrentOrgId
  1374. warehouse, _ := service.GetSecondWarehouseOrderById(id)
  1375. //获取药品库数据
  1376. baseList, _ := service.GetSupplyDrugListOne(orgId, warehouse.StorehouseOutId)
  1377. goodList, _ := service.GetSupplyGoodListOne(orgId, warehouse.StorehouseOutId)
  1378. goodTypeList, _ := service.GetAllGoodType(orgId)
  1379. configlist, _ := service.GetAllStoreHouseConfig(orgId)
  1380. var drugType = "药品类型"
  1381. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1382. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  1383. list, _ := service.GetSencondOrderDetail(id, orgId)
  1384. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1385. this.ServeSuccessJSON(map[string]interface{}{
  1386. "list": list,
  1387. "warehouse": warehouse,
  1388. "drugList": baseList,
  1389. "goodList": goodList,
  1390. "goodTypeList": goodTypeList,
  1391. "drugTypeList": drugTypeList,
  1392. "configlist": configlist,
  1393. "manufacturerList": manufacturerList,
  1394. })
  1395. return
  1396. }
  1397. func (this *SecondaryOrderApiController) UpdateSencondOrder() {
  1398. warehouse_id, _ := this.GetInt64("id")
  1399. start_date := this.GetString("record_date")
  1400. storehouse_in_id, _ := this.GetInt64("storehouse_in_id")
  1401. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  1402. fmt.Println(storehouse_in_id, storehouse_out_id)
  1403. timeLayout := "2006-01-02"
  1404. loc, _ := time.LoadLocation("Local")
  1405. var startDate int64
  1406. if len(start_date) > 0 {
  1407. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1408. if err != nil {
  1409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1410. return
  1411. }
  1412. startDate = theTime.Unix()
  1413. }
  1414. recordDateStr := time.Now().Format("2006-01-02")
  1415. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1416. record_date := recordDate.Unix()
  1417. orgId := this.GetAdminUserInfo().CurrentOrgId
  1418. creater := this.GetAdminUserInfo().AdminUser.Id
  1419. warehouse := models.XtSecondWarehouse{
  1420. StorehouseInId: storehouse_in_id,
  1421. StorehouseOutId: storehouse_out_id,
  1422. RecordDate: startDate,
  1423. }
  1424. service.UpdateModifySecondWarehouse(warehouse_id, warehouse)
  1425. warehouseInfo, _ := service.GetSecondWarehouseOrderById(warehouse_id)
  1426. var warehousingInfo []*models.XtSecondWarehouseInfo
  1427. var updateWarehousingInfo []*models.XtSecondWarehouseInfo
  1428. dataBody := make(map[string]interface{}, 0)
  1429. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1430. if err != nil {
  1431. utils.ErrorLog(err.Error())
  1432. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1433. return
  1434. }
  1435. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1436. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1437. if len(thisStockIn) > 0 {
  1438. for _, item := range thisStockIn {
  1439. items := item.(map[string]interface{})
  1440. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1441. utils.ErrorLog("id")
  1442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1443. return
  1444. }
  1445. id := int64(items["id"].(float64))
  1446. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1447. utils.ErrorLog("project_id")
  1448. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1449. return
  1450. }
  1451. project_id := int64(items["project_id"].(float64))
  1452. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1453. utils.ErrorLog("name")
  1454. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1455. return
  1456. }
  1457. project_name := items["name"].(string)
  1458. if items["project_type"] == nil || reflect.TypeOf(items["project_type"]).String() != "string" {
  1459. utils.ErrorLog("project_type")
  1460. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1461. return
  1462. }
  1463. project_type := items["project_type"].(string)
  1464. if items["second_specification_name"] == nil || reflect.TypeOf(items["second_specification_name"]).String() != "string" {
  1465. utils.ErrorLog("second_specification_name")
  1466. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1467. return
  1468. }
  1469. second_specification_name := items["second_specification_name"].(string)
  1470. if items["sencond_unit"] == nil || reflect.TypeOf(items["sencond_unit"]).String() != "string" {
  1471. utils.ErrorLog("sencond_unit")
  1472. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1473. return
  1474. }
  1475. sencond_unit := items["sencond_unit"].(string)
  1476. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1477. utils.ErrorLog("count")
  1478. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1479. return
  1480. }
  1481. count := int64(items["count"].(float64))
  1482. if items["is_source"] == nil || reflect.TypeOf(items["is_source"]).String() != "float64" {
  1483. utils.ErrorLog("is_source")
  1484. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1485. return
  1486. }
  1487. is_source := int64(items["is_source"].(float64))
  1488. if items["second_total"] == nil || reflect.TypeOf(items["second_total"]).String() != "string" {
  1489. utils.ErrorLog("second_total")
  1490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1491. return
  1492. }
  1493. second_total := items["second_total"].(string)
  1494. if items["remake"] == nil || reflect.TypeOf(items["remake"]).String() != "string" {
  1495. utils.ErrorLog("remake")
  1496. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1497. return
  1498. }
  1499. remake := items["remake"].(string)
  1500. if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "float64" {
  1501. utils.ErrorLog("min_price")
  1502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1503. return
  1504. }
  1505. min_price := items["min_price"].(float64)
  1506. if id == 0 {
  1507. info := &models.XtSecondWarehouseInfo{
  1508. ProjectName: project_name,
  1509. SecondSpecificationName: second_specification_name,
  1510. ProjectType: project_type,
  1511. SencondUnit: sencond_unit,
  1512. Count: count,
  1513. SecondTotal: second_total,
  1514. RecordDate: record_date,
  1515. StorehouseInId: storehouse_in_id,
  1516. StorehouseOutId: storehouse_out_id,
  1517. Creater: creater,
  1518. ProjectId: project_id,
  1519. Remake: remake,
  1520. UserOrgId: orgId,
  1521. Status: 1,
  1522. Ctime: time.Now().Unix(),
  1523. Mtime: 0,
  1524. MinPrice: min_price,
  1525. IsSource: is_source,
  1526. WarehouseId: warehouse_id,
  1527. SecondOrderNumber: warehouseInfo.SecondOrderNumber,
  1528. }
  1529. warehousingInfo = append(warehousingInfo, info)
  1530. }
  1531. if id > 0 {
  1532. updateInfo := &models.XtSecondWarehouseInfo{
  1533. ID: id,
  1534. ProjectName: project_name,
  1535. SecondSpecificationName: second_specification_name,
  1536. ProjectType: project_type,
  1537. SencondUnit: sencond_unit,
  1538. Count: count,
  1539. SecondTotal: second_total,
  1540. SecondOrderNumber: warehouse.SecondOrderNumber,
  1541. RecordDate: record_date,
  1542. StorehouseInId: storehouse_in_id,
  1543. StorehouseOutId: storehouse_out_id,
  1544. Creater: creater,
  1545. ProjectId: project_id,
  1546. Remake: remake,
  1547. UserOrgId: orgId,
  1548. MinPrice: min_price,
  1549. IsSource: is_source,
  1550. }
  1551. updateWarehousingInfo = append(updateWarehousingInfo, updateInfo)
  1552. }
  1553. }
  1554. }
  1555. }
  1556. for _, item := range warehousingInfo {
  1557. service.CreateSencondWarehousingInfo(item)
  1558. }
  1559. for _, item := range updateWarehousingInfo {
  1560. service.UpdateStoreWarehousing(item)
  1561. }
  1562. this.ServeSuccessJSON(map[string]interface{}{
  1563. "warehousingInfo": warehousingInfo,
  1564. })
  1565. return
  1566. }
  1567. func (this *SecondaryOrderApiController) GetSecondOrderById() {
  1568. id, _ := this.GetInt64("id")
  1569. orgId := this.GetAdminUserInfo().CurrentOrgId
  1570. warehouse, _ := service.GetSecondWarehouseOrderById(id)
  1571. list, _ := service.GetSencondOrderDetail(id, orgId)
  1572. appId := this.GetAdminUserInfo().CurrentAppId
  1573. doctor, _ := service.GetAllDoctor(orgId, appId)
  1574. houseList, _ := service.GetAllStoreHouseList(orgId)
  1575. this.ServeSuccessJSON(map[string]interface{}{
  1576. "warehouse": warehouse,
  1577. "list": list,
  1578. "doctorList": doctor,
  1579. "houseList": houseList,
  1580. })
  1581. return
  1582. }
  1583. func (this *SecondaryOrderApiController) CheckSecondOrer() {
  1584. ids := this.GetString("ids")
  1585. if len(ids) == 0 {
  1586. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1587. return
  1588. }
  1589. idArray := strings.Split(ids, ",")
  1590. orgId := this.GetAdminUserInfo().CurrentOrgId
  1591. creater := this.GetAdminUserInfo().AdminUser.Id
  1592. //根据订单id获取商品详情
  1593. list, _ := service.GetSecondOrderList(idArray, orgId)
  1594. for _, item := range list {
  1595. if item.IsSource == 1 {
  1596. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1597. //查询该仓库的药品库存是否满足调出数量
  1598. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  1599. var total int64
  1600. var total_count int64
  1601. for _, it := range drugInfoList {
  1602. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1603. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1604. }
  1605. }
  1606. for _, it := range drugInfoList {
  1607. total += it.StockMaxNumber + it.StockMinNumber
  1608. }
  1609. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1610. total_count = item.Count * medical.MinNumber
  1611. }
  1612. if item.SencondUnit == medical.MinUnit {
  1613. total_count = item.Count
  1614. }
  1615. if total_count > total {
  1616. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  1617. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseOutId, item.UserOrgId)
  1618. this.ServeSuccessJSON(map[string]interface{}{
  1619. "msg": "3",
  1620. "drug_name": goodObj.DrugName,
  1621. "dose": goodObj.Dose,
  1622. "dose_unit": goodObj.DoseUnit,
  1623. "min_number": goodObj.MinNumber,
  1624. "min_unit": goodObj.MinUnit,
  1625. "max_unit": goodObj.MaxUnit,
  1626. "storehose_name": storehouse.StorehouseName,
  1627. })
  1628. return
  1629. }
  1630. }
  1631. if item.IsSource == 2 {
  1632. //查询该仓库的耗材库存是否满足调出数量
  1633. var total int64
  1634. infoList, _ := service.GetWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  1635. for _, it := range infoList {
  1636. total += it.StockCount
  1637. }
  1638. if item.Count > total {
  1639. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseOutId, item.UserOrgId)
  1640. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1641. this.ServeSuccessJSON(map[string]interface{}{
  1642. "msg": "2",
  1643. "good_name": goodObj.GoodName,
  1644. "specification_name": goodObj.SpecificationName,
  1645. "storehose_name": storehouse.StorehouseName,
  1646. })
  1647. return
  1648. }
  1649. }
  1650. }
  1651. err := service.UpdateStoreOrderByArray(idArray, orgId, creater)
  1652. //如果审核成功
  1653. if err == nil {
  1654. //调用出库接口
  1655. timeStr := time.Now().Format("2006-01-02")
  1656. timeArr := strings.Split(timeStr, "-")
  1657. total, _ := service.FindAllWarehouseOut(orgId)
  1658. total = total + 1
  1659. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1660. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1661. number = number + total
  1662. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1663. operation_time := time.Now().Unix()
  1664. creater := this.GetAdminUserInfo().AdminUser.Id
  1665. recordDateStr := time.Now().Format("2006-01-02")
  1666. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1667. record_date := recordDate.Unix()
  1668. totals, _ := service.FindAllWarehouseTotal(orgId)
  1669. totals = totals + 1
  1670. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(totals, 10)
  1671. for _, item := range list {
  1672. //药品
  1673. if item.IsSource == 1 {
  1674. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1675. //查询该仓库的药品库存是否满足调出数量
  1676. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  1677. var total int64
  1678. var total_count int64
  1679. for _, it := range drugInfoList {
  1680. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1681. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1682. }
  1683. }
  1684. for _, it := range drugInfoList {
  1685. total += it.StockMaxNumber + it.StockMinNumber
  1686. }
  1687. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1688. total_count = item.Count * medical.MinNumber
  1689. }
  1690. if item.SencondUnit == medical.MinUnit {
  1691. total_count = item.Count
  1692. }
  1693. if total_count <= total {
  1694. drug_total, _ := service.FindAllDrugWarehouseOut(orgId)
  1695. drug_total = drug_total + 1
  1696. drug_warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1697. number, _ := strconv.ParseInt(drug_warehousing_out_order, 10, 64)
  1698. number = number + drug_total
  1699. drug_warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1700. operation_time := time.Now().Unix()
  1701. drugWarehouseOut := models.DrugWarehouseOut{
  1702. WarehouseOutOrderNumber: drug_warehousing_out_order,
  1703. OperationTime: operation_time,
  1704. OrgId: orgId,
  1705. Creater: creater,
  1706. Ctime: time.Now().Unix(),
  1707. Status: 1,
  1708. WarehouseOutTime: record_date,
  1709. Type: 2,
  1710. StorehouseId: item.StorehouseOutId,
  1711. SecondWarehouseId: item.WarehouseId,
  1712. IsSys: 12,
  1713. }
  1714. _, drugerrcodes := service.GetDrugWarehouseBySyS(orgId, 12, item.WarehouseId, record_date)
  1715. if drugerrcodes == gorm.ErrRecordNotFound {
  1716. service.AddSigleDrugWarehouseOut(&drugWarehouseOut)
  1717. }
  1718. drugOut, _ := service.GetLastDrugWarehouseOutById(12, item.WarehouseId, orgId, record_date)
  1719. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1720. WarehouseOutOrderNumber: drugOut.WarehouseOutOrderNumber,
  1721. WarehouseOutId: drugOut.ID,
  1722. DrugId: item.ProjectId,
  1723. Count: item.Count,
  1724. Price: medical.RetailPrice,
  1725. TotalPrice: 0,
  1726. Status: 1,
  1727. Ctime: time.Now().Unix(),
  1728. Remark: item.Remake,
  1729. OrgId: orgId,
  1730. Type: 2,
  1731. Manufacturer: 0,
  1732. Dealer: 0,
  1733. RetailPrice: item.MinPrice,
  1734. RetailTotalPrice: 0,
  1735. CountUnit: item.SencondUnit,
  1736. ExpiryDate: 0,
  1737. ProductDate: 0,
  1738. Number: "",
  1739. BatchNumber: "",
  1740. IsSys: 0,
  1741. WarehouseInfoId: 0,
  1742. StorehouseId: item.StorehouseOutId,
  1743. SecondWarehouseInfoId: item.ID,
  1744. }
  1745. drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
  1746. drug_in_total, _ := service.FindAllWarehouseTotalOne(orgId)
  1747. drug_in_total = drug_in_total + 1
  1748. warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(drug_in_total, 10)
  1749. drug_warehousing := models.DrugWarehouse{
  1750. WarehousingOrder: warehousing_order,
  1751. OperationTime: operation_time,
  1752. OrgId: orgId,
  1753. Creater: creater,
  1754. Ctime: time.Now().Unix(),
  1755. Status: 1,
  1756. WarehousingTime: record_date,
  1757. Type: 1,
  1758. StorehouseId: item.StorehouseInId,
  1759. IsSys: 13,
  1760. SecondWarehouseId: item.WarehouseId,
  1761. }
  1762. //查询该调拨单是否有生成入库单
  1763. _, drugerrcodess := service.GetDrugWarehouseingBySys(13, item.WarehouseId, orgId, record_date)
  1764. if drugerrcodess == gorm.ErrRecordNotFound {
  1765. service.CreateDrugWaresing(drug_warehousing)
  1766. }
  1767. drugInfoObj, _ := service.GetLastDrugWarehouseBySys(13, item.WarehouseId, orgId, record_date)
  1768. drugwarehouseInfo := &models.DrugWarehouseInfo{
  1769. WarehousingOrder: drugInfoObj.WarehousingOrder,
  1770. WarehousingId: drugInfoObj.ID,
  1771. DrugId: item.ProjectId,
  1772. Number: "",
  1773. ProductDate: 0,
  1774. ExpiryDate: 0,
  1775. WarehousingCount: 0,
  1776. Price: 0,
  1777. TotalPrice: 0,
  1778. Status: 1,
  1779. Ctime: time.Now().Unix(),
  1780. Remark: "",
  1781. OrgId: orgId,
  1782. Type: 2,
  1783. Manufacturer: 0,
  1784. Dealer: 0,
  1785. StockMaxNumber: 0,
  1786. RetailTotalPrice: 0,
  1787. BatchNumber: "",
  1788. MaxUnit: "",
  1789. MinUnit: "",
  1790. RetailPrice: 0,
  1791. StorehouseId: item.StorehouseInId,
  1792. SecondWarehouseInfoId: item.ID,
  1793. }
  1794. service.AutoDrugDeliverInfoTwelve(orgId, item.Count, &drugWarehouseOut, &drup, warehouseOutInfo, drugwarehouseInfo)
  1795. //查询默认仓库
  1796. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1797. //查询默认仓库剩余多少库存
  1798. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ProjectId)
  1799. var sum_count int64
  1800. var sum_in_count int64
  1801. for _, it := range list {
  1802. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  1803. if it.MaxUnit == baseDrug.MaxUnit {
  1804. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  1805. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  1806. }
  1807. sum_count += it.StockMaxNumber + it.StockMinNumber
  1808. sum_in_count += it.WarehousingCount
  1809. }
  1810. service.UpdateMedicalSumCount(item.ProjectId, sum_count, sum_in_count, item.UserOrgId)
  1811. }
  1812. }
  1813. //耗材
  1814. if item.IsSource == 2 {
  1815. //查询该仓库的耗材库存是否满足调出数量
  1816. var total int64
  1817. infoList, _ := service.GetWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  1818. for _, it := range infoList {
  1819. total += it.StockCount
  1820. }
  1821. //满足调拨
  1822. if item.Count <= total {
  1823. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1824. warehouseOut := models.WarehouseOut{
  1825. WarehouseOutOrderNumber: warehousing_out_order,
  1826. OperationTime: operation_time,
  1827. OrgId: orgId,
  1828. Creater: creater,
  1829. Ctime: time.Now().Unix(),
  1830. Status: 1,
  1831. WarehouseOutTime: record_date,
  1832. Type: 1,
  1833. StorehouseId: item.StorehouseOutId,
  1834. IsSys: 12,
  1835. SecondWarehouseId: item.WarehouseId,
  1836. }
  1837. //查询今日是否存在调拨出库
  1838. _, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
  1839. if errcodes == gorm.ErrRecordNotFound {
  1840. service.AddSigleWarehouseOut(&warehouseOut)
  1841. }
  1842. out, _ := service.GetLastWarehouseOutBySys(12, orgId, record_date, item.WarehouseId)
  1843. warehouseOutInfo := &models.WarehouseOutInfo{
  1844. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1845. WarehouseOutId: out.ID,
  1846. GoodId: item.ProjectId,
  1847. GoodTypeId: goodObj.GoodTypeId,
  1848. Count: item.Count,
  1849. Price: item.MinPrice,
  1850. TotalPrice: 0,
  1851. Status: 1,
  1852. Ctime: time.Now().Unix(),
  1853. Remark: item.Remake,
  1854. OrgId: orgId,
  1855. Type: 1,
  1856. Manufacturer: 0,
  1857. Number: "",
  1858. ExpiryDate: 0,
  1859. ProductDate: 0,
  1860. Dealer: 0,
  1861. LicenseNumber: "",
  1862. WarehouseInfotId: 0,
  1863. StorehouseId: item.StorehouseOutId,
  1864. SecondWarehouseInfoId: item.ID,
  1865. }
  1866. //入库操作
  1867. warehousing := models.Warehousing{
  1868. WarehousingOrder: warehousing_order,
  1869. OperationTime: operation_time,
  1870. OrgId: orgId,
  1871. Creater: creater,
  1872. Ctime: time.Now().Unix(),
  1873. Status: 1,
  1874. WarehousingTime: record_date,
  1875. Type: 1,
  1876. StorehouseId: item.StorehouseInId,
  1877. IsSys: 12,
  1878. SecondWarehouseId: item.WarehouseId,
  1879. }
  1880. //查询该调拨单是否有生成入库单
  1881. _, errcodess := service.GetWarehouseBySecondWarehouseId(12, item.WarehouseId, orgId, record_date)
  1882. if errcodess == gorm.ErrRecordNotFound {
  1883. service.AddSigleWarehouse(&warehousing)
  1884. }
  1885. infoObj, _ := service.GetLastWarehouseById(12, item.WarehouseId, orgId, record_date)
  1886. warehouseInfo := &models.WarehousingInfo{
  1887. WarehousingOrder: infoObj.WarehousingOrder,
  1888. WarehousingId: infoObj.ID,
  1889. GoodId: item.ProjectId,
  1890. Number: "",
  1891. GoodTypeId: goodObj.GoodTypeId,
  1892. ProductDate: 0,
  1893. ExpiryDate: 0,
  1894. WarehousingCount: item.Count,
  1895. Price: goodObj.BuyPrice,
  1896. TotalPrice: 0,
  1897. Status: 1,
  1898. Ctime: time.Now().Unix(),
  1899. Remark: item.Remake,
  1900. OrgId: orgId,
  1901. Type: 1,
  1902. Manufacturer: 0,
  1903. StockCount: item.Count,
  1904. Dealer: 0,
  1905. LicenseNumber: "",
  1906. PackingPrice: item.MinPrice,
  1907. StorehouseId: item.StorehouseInId,
  1908. SecondWarehouseInfoId: item.ID,
  1909. }
  1910. //出库逻辑
  1911. parseDateErr := service.ConsumablesDeliveryTwelve(orgId, record_date, warehouseOutInfo, &warehouseOut, item.Count, creater, warehouseInfo)
  1912. fmt.Println(parseDateErr)
  1913. }
  1914. //查询默认仓库
  1915. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1916. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId)
  1917. var sum_count int64
  1918. var sum_in_count int64
  1919. for _, it := range goodList {
  1920. sum_count += it.StockCount
  1921. sum_in_count += it.WarehousingCount
  1922. }
  1923. service.UpdateGoodByGoodId(item.ProjectId, sum_count, sum_in_count, item.UserOrgId)
  1924. }
  1925. }
  1926. }
  1927. this.ServeSuccessJSON(map[string]interface{}{
  1928. "msg": 1,
  1929. })
  1930. return
  1931. }
  1932. func (this *SecondaryOrderApiController) DeleteStorehouseList() {
  1933. id, _ := this.GetInt64("id")
  1934. err := service.DeleteStorehouseList(id)
  1935. if err == nil {
  1936. returnData := make(map[string]interface{}, 0)
  1937. returnData["msg"] = "ok"
  1938. this.ServeSuccessJSON(returnData)
  1939. return
  1940. } else {
  1941. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1942. }
  1943. }
  1944. func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
  1945. ids := this.GetString("ids")
  1946. if len(ids) == 0 {
  1947. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1948. return
  1949. }
  1950. idArray := strings.Split(ids, ",")
  1951. orgId := this.GetAdminUserInfo().CurrentOrgId
  1952. //根据订单id获取商品详情
  1953. list, _ := service.GetSecondOrderList(idArray, orgId)
  1954. //药品
  1955. for _, item := range list {
  1956. //药品
  1957. if item.IsSource == 1 {
  1958. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1959. //查询该仓库的药品库存是否满足调出数量
  1960. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1961. var total int64
  1962. var total_count int64
  1963. for _, it := range drugInfoList {
  1964. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1965. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1966. }
  1967. }
  1968. for _, it := range drugInfoList {
  1969. total += it.StockMaxNumber + it.StockMinNumber
  1970. }
  1971. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1972. total_count = item.Count * medical.MinNumber
  1973. }
  1974. if item.SencondUnit == medical.MinUnit {
  1975. total_count = item.Count
  1976. }
  1977. if total_count > total {
  1978. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  1979. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
  1980. this.ServeSuccessJSON(map[string]interface{}{
  1981. "msg": "3",
  1982. "drug_name": goodObj.DrugName,
  1983. "dose": goodObj.Dose,
  1984. "dose_unit": goodObj.DoseUnit,
  1985. "min_number": goodObj.MinNumber,
  1986. "min_unit": goodObj.MinUnit,
  1987. "max_unit": goodObj.MaxUnit,
  1988. "storehose_name": storehouse.StorehouseName,
  1989. })
  1990. return
  1991. }
  1992. }
  1993. //耗材
  1994. if item.IsSource == 2 {
  1995. //查询该仓库的耗材库存是否满足调出数量
  1996. var total int64
  1997. infoList, _ := service.GetWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1998. for _, it := range infoList {
  1999. total += it.StockCount
  2000. }
  2001. if item.Count > total {
  2002. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
  2003. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  2004. this.ServeSuccessJSON(map[string]interface{}{
  2005. "msg": "2",
  2006. "good_name": goodObj.GoodName,
  2007. "specification_name": goodObj.SpecificationName,
  2008. "storehose_name": storehouse.StorehouseName,
  2009. })
  2010. return
  2011. }
  2012. }
  2013. }
  2014. //反审核操作
  2015. err := service.ModifyStoreHouseById(idArray, orgId)
  2016. if err != nil {
  2017. this.ServeSuccessJSON(map[string]interface{}{
  2018. "msg": "0",
  2019. })
  2020. return
  2021. }
  2022. for _, item := range list {
  2023. //药品
  2024. if item.IsSource == 1 {
  2025. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  2026. //查询该仓库的药品库存是否满足调出数量
  2027. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  2028. var total int64
  2029. var total_count int64
  2030. for _, it := range drugInfoList {
  2031. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2032. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  2033. }
  2034. }
  2035. for _, it := range drugInfoList {
  2036. total += it.StockMaxNumber + it.StockMinNumber
  2037. }
  2038. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2039. total_count = item.Count * medical.MinNumber
  2040. }
  2041. if item.SencondUnit == medical.MinUnit {
  2042. total_count = item.Count
  2043. }
  2044. fmt.Println("total_count2332323223233232332", total_count)
  2045. fmt.Println("total2323322332322332233", total)
  2046. if total_count <= total {
  2047. //回退库存,查询该订单出库记录
  2048. drugOutList, _ := service.GetStoreDrugWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
  2049. for _, it := range drugOutList {
  2050. if medical.MaxUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
  2051. //回退库存
  2052. service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
  2053. }
  2054. if medical.MaxUnit == it.CountUnit && medical.MaxUnit == medical.MinUnit {
  2055. //回退库存
  2056. service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
  2057. }
  2058. if medical.MinUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
  2059. service.ModifyDrugStoreWarehouseInfoOne(it.WarehouseInfoId, it.Count)
  2060. }
  2061. //查询入库单
  2062. storeWareing, _ := service.GetStoreDrugWarehouseById(item.WarehouseId, it.OrgId)
  2063. //删除入库单
  2064. service.DeleteStoreWarehousingId(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
  2065. //查询出单
  2066. storeWarehouseOut, _ := service.GetStoreDrugWarehouseOutById(it.WarehouseOutId, it.OrgId)
  2067. fmt.Println("ss喊出232323232332232323232332232333333333333333333333")
  2068. //删除出库单
  2069. service.DeleteStoreWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
  2070. }
  2071. }
  2072. //查询默认仓库
  2073. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  2074. //查询默认仓库剩余多少库存
  2075. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseInfo, orgId, item.ProjectId)
  2076. var sum_count int64
  2077. var sum_in_count int64
  2078. for _, it := range list {
  2079. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2080. if it.MaxUnit == baseDrug.MaxUnit {
  2081. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2082. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2083. }
  2084. sum_count += it.StockMaxNumber + it.StockMinNumber
  2085. sum_in_count += it.WarehousingCount
  2086. }
  2087. service.UpdateMedicalSumCount(item.ProjectId, sum_count, sum_in_count, item.UserOrgId)
  2088. }
  2089. //耗材
  2090. if item.IsSource == 2 {
  2091. //查询该仓库的耗材库存是否满足调出数量
  2092. var total int64
  2093. infoList, _ := service.GetWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  2094. for _, it := range infoList {
  2095. total += it.StockCount
  2096. }
  2097. //满足调拨
  2098. if item.Count <= total {
  2099. //回退库存,查询该订单出库记录
  2100. outList, _ := service.GetStoreWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
  2101. for _, it := range outList {
  2102. //回退库存
  2103. service.ModifyStoreWarehouseById(it.WarehouseInfotId, item.Count)
  2104. //获取入库单
  2105. storeWareing, _ := service.GetStoreWarehouseById(item.WarehouseId, it.OrgId)
  2106. //删除入库单 入库流水
  2107. service.ModifyStoreWarehouse(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
  2108. //获取出库单
  2109. storeWarehouseOut, _ := service.GetStoreWarehouseOutById(it.WarehouseOutId, it.OrgId)
  2110. //删除出库单
  2111. service.ModifyWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
  2112. }
  2113. }
  2114. //查询默认仓库
  2115. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  2116. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseInfo, item.ProjectId, item.UserOrgId)
  2117. var sum_count int64
  2118. var sum_in_count int64
  2119. for _, it := range goodList {
  2120. sum_count += it.StockCount
  2121. sum_in_count += it.WarehousingCount
  2122. }
  2123. service.UpdateGoodByGoodId(item.ProjectId, sum_count, sum_in_count, item.UserOrgId)
  2124. }
  2125. }
  2126. this.ServeSuccessJSON(map[string]interface{}{
  2127. "msg": "1",
  2128. })
  2129. return
  2130. }
  2131. func (this *SecondaryOrderApiController) GetStoreHouseGoodList() {
  2132. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  2133. orgId := this.GetAdminUserInfo().CurrentOrgId
  2134. //获取药品库数据
  2135. baseList, _ := service.GetSupplyDrugListOne(orgId, storehouse_out_id)
  2136. goodList, _ := service.GetSupplyGoodListOne(orgId, storehouse_out_id)
  2137. goodTypeList, _ := service.GetAllGoodType(orgId)
  2138. configlist, _ := service.GetAllStoreHouseConfig(orgId)
  2139. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2140. var drugType = "药品类型"
  2141. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  2142. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  2143. this.ServeSuccessJSON(map[string]interface{}{
  2144. "drugList": baseList,
  2145. "goodList": goodList,
  2146. "goodTypeList": goodTypeList,
  2147. "drugTypeList": drugTypeList,
  2148. "configlist": configlist,
  2149. "manufacturerList": manufacturerList,
  2150. })
  2151. return
  2152. }
  2153. func (this *SecondaryOrderApiController) GetSumSecondCount() {
  2154. project_id, _ := this.GetInt64("project_id")
  2155. sencond_unit := this.GetString("sencond_unit")
  2156. is_source, _ := this.GetInt64("is_source")
  2157. count, _ := this.GetInt64("count")
  2158. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  2159. orgId := this.GetAdminUserInfo().CurrentOrgId
  2160. var sum_in_count int64
  2161. var sum_count int64
  2162. //药品
  2163. if is_source == 1 {
  2164. medical, _ := service.GetBaseDrugMedical(project_id)
  2165. fmt.Println("senconde_unit233223", sencond_unit)
  2166. if sencond_unit == medical.MaxUnit {
  2167. sum_in_count = count * medical.MinNumber
  2168. }
  2169. if sencond_unit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2170. sum_in_count = count
  2171. }
  2172. //查询该药品剩余的库存
  2173. secondCountList, _ := service.GetDrugSumSecondCount(project_id, storehouse_out_id, orgId)
  2174. for _, it := range secondCountList {
  2175. if it.MaxUnit == medical.MaxUnit {
  2176. sum_count += (it.StockMaxNumber * medical.MinNumber) + it.StockMinNumber
  2177. }
  2178. if it.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2179. sum_count += (it.StockMaxNumber + it.StockMinNumber)
  2180. }
  2181. }
  2182. fmt.Println("sum_iin_coutn23232323", sum_in_count)
  2183. fmt.Println("sum_count", sum_count)
  2184. if sum_in_count > sum_count {
  2185. this.ServeSuccessJSON(map[string]interface{}{
  2186. "msg": "2",
  2187. })
  2188. return
  2189. } else {
  2190. this.ServeSuccessJSON(map[string]interface{}{
  2191. "msg": "1",
  2192. })
  2193. return
  2194. }
  2195. }
  2196. //耗材
  2197. if is_source == 2 {
  2198. var sum_good_count int64
  2199. secondCountGoodList, _ := service.GetGoodSumSecondCount(project_id, storehouse_out_id, orgId)
  2200. for _, it := range secondCountGoodList {
  2201. sum_good_count += it.StockCount
  2202. }
  2203. if count > sum_good_count {
  2204. this.ServeSuccessJSON(map[string]interface{}{
  2205. "msg": "2",
  2206. })
  2207. return
  2208. } else {
  2209. this.ServeSuccessJSON(map[string]interface{}{
  2210. "msg": "1",
  2211. })
  2212. return
  2213. }
  2214. }
  2215. }
  2216. func (this *SecondaryOrderApiController) DeleteSecondOrderInfo() {
  2217. id, _ := this.GetInt64("id")
  2218. err := service.DeleteSecondOrderInfo(id)
  2219. if err == nil {
  2220. returnData := make(map[string]interface{}, 0)
  2221. returnData["msg"] = "ok"
  2222. this.ServeSuccessJSON(returnData)
  2223. return
  2224. } else {
  2225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2226. }
  2227. }
  2228. //查询一条仓库信息
  2229. func (this *SecondaryOrderApiController) GetOneStorehouse() {
  2230. orgId := this.GetAdminUserInfo().CurrentOrgId
  2231. check := map[string][]string{
  2232. "id": {"must", "int", "id"},
  2233. }
  2234. _, err := checkParams(this, &check)
  2235. if err != nil {
  2236. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2237. return
  2238. }
  2239. id, _ := this.GetInt64("id")
  2240. var list models.Storehouse
  2241. list, err = service.GetOneStorehouse(id, orgId)
  2242. if err != nil {
  2243. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2244. return
  2245. }
  2246. this.ServeSuccessJSON(map[string]interface{}{
  2247. "list": list,
  2248. })
  2249. return
  2250. }
  2251. //获取当前机构所有可用仓库的名字
  2252. func (this *SecondaryOrderApiController) GetAllStorehouseName() {
  2253. orgId := this.GetAdminUserInfo().CurrentOrgId
  2254. list, err := service.GetAllStorehouseName(orgId)
  2255. if err != nil {
  2256. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2257. return
  2258. }
  2259. this.ServeSuccessJSON(map[string]interface{}{
  2260. "list": list,
  2261. })
  2262. }
  2263. //根据机构id查询仓库配置
  2264. func (this *SecondaryOrderApiController) FindStorehouseConfig() {
  2265. orgId := this.GetAdminUserInfo().CurrentOrgId
  2266. storehouse, err := service.FindStorehouseConfig(orgId)
  2267. //如果没有仓库配置信息就新建一个
  2268. if err == gorm.ErrRecordNotFound {
  2269. err := service.GetDefaultStorehouse(orgId)
  2270. if err != nil {
  2271. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2272. return
  2273. }
  2274. storehouse, err = service.FindStorehouseConfig(orgId)
  2275. if err != nil {
  2276. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2277. return
  2278. }
  2279. }
  2280. if err != nil && err.Error() != "record not found" {
  2281. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2282. return
  2283. }
  2284. var storehouse_info, storehouse_out_info, drug_storehouse_info, drug_storehouse_out models.Storehouse
  2285. storehouse_info, err = service.FindStorehouseName(storehouse.StorehouseInfo)
  2286. if err != nil {
  2287. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2288. return
  2289. }
  2290. storehouse_out_info, err = service.FindStorehouseName(storehouse.StorehouseOutInfo)
  2291. if err != nil {
  2292. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2293. return
  2294. }
  2295. drug_storehouse_info, err = service.FindStorehouseName(storehouse.DrugStorehouseInfo)
  2296. if err != nil {
  2297. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2298. return
  2299. }
  2300. drug_storehouse_out, err = service.FindStorehouseName(storehouse.DrugStorehouseOut)
  2301. if err != nil {
  2302. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2303. return
  2304. }
  2305. this.ServeSuccessJSON(map[string]interface{}{
  2306. "storehouse_info": storehouse_info.StorehouseName,
  2307. "storehouse_out_info": storehouse_out_info.StorehouseName,
  2308. "drug_storehouse_info": drug_storehouse_info.StorehouseName,
  2309. "drug_storehouse_out": drug_storehouse_out.StorehouseName,
  2310. })
  2311. return
  2312. }
  2313. //更改耗材自动入库仓库
  2314. func (this *SecondaryOrderApiController) UpdateInfo() {
  2315. orgId := this.GetAdminUserInfo().CurrentOrgId
  2316. check := map[string][]string{
  2317. "id": {"must", "int", "id"},
  2318. }
  2319. _, err := checkParams(this, &check)
  2320. if err != nil {
  2321. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2322. return
  2323. }
  2324. id, _ := this.GetInt64("id")
  2325. err = service.UpdateInfo(orgId, id)
  2326. if err != nil {
  2327. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2328. return
  2329. }
  2330. this.ServeSuccessJSON(map[string]interface{}{
  2331. "list": "修改成功",
  2332. })
  2333. return
  2334. }
  2335. //更改耗材自动出库仓库
  2336. func (this *SecondaryOrderApiController) UpdateOutInfo() {
  2337. orgId := this.GetAdminUserInfo().CurrentOrgId
  2338. check := map[string][]string{
  2339. "id": {"must", "int", "id"},
  2340. }
  2341. _, err := checkParams(this, &check)
  2342. if err != nil {
  2343. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2344. return
  2345. }
  2346. id, _ := this.GetInt64("id")
  2347. err = service.UpdateOutInfo(orgId, id)
  2348. if err != nil {
  2349. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2350. return
  2351. }
  2352. this.ServeSuccessJSON(map[string]interface{}{
  2353. "list": "修改成功",
  2354. })
  2355. return
  2356. }
  2357. //更改药品自动入库仓库
  2358. func (this *SecondaryOrderApiController) UpdateDrugInfo() {
  2359. orgId := this.GetAdminUserInfo().CurrentOrgId
  2360. check := map[string][]string{
  2361. "id": {"must", "int", "id"},
  2362. }
  2363. _, err := checkParams(this, &check)
  2364. if err != nil {
  2365. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2366. return
  2367. }
  2368. id, _ := this.GetInt64("id")
  2369. err = service.UpdateDrugInfo2(orgId, id)
  2370. if err != nil {
  2371. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2372. return
  2373. }
  2374. this.ServeSuccessJSON(map[string]interface{}{
  2375. "list": "修改成功",
  2376. })
  2377. return
  2378. }
  2379. //更改药品自动出库仓库
  2380. func (this *SecondaryOrderApiController) UpdateDrugOut() {
  2381. orgId := this.GetAdminUserInfo().CurrentOrgId
  2382. check := map[string][]string{
  2383. "id": {"must", "int", "id"},
  2384. }
  2385. _, err := checkParams(this, &check)
  2386. if err != nil {
  2387. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2388. return
  2389. }
  2390. id, _ := this.GetInt64("id")
  2391. err = service.UpdateDrugOut(orgId, id)
  2392. if err != nil {
  2393. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2394. return
  2395. }
  2396. this.ServeSuccessJSON(map[string]interface{}{
  2397. "list": "修改成功",
  2398. })
  2399. return
  2400. }
  2401. //判断前端参数是否为空
  2402. func checkParams(this *SecondaryOrderApiController, m *map[string][]string) (map[string]string, error) {
  2403. tmp := make(map[string]string)
  2404. for k, v := range *m {
  2405. t := this.GetString(k)
  2406. if v[0] == "must" && t == "" {
  2407. return nil, fmt.Errorf(v[2] + "不能为空")
  2408. }
  2409. tmp[k] = t
  2410. }
  2411. return tmp, nil
  2412. }
  2413. //兼容旧数据
  2414. func (this *SecondaryOrderApiController) Byliinit() {
  2415. err := service.Byliinit()
  2416. if err != nil {
  2417. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2418. return
  2419. }
  2420. this.ServeSuccessJSON(map[string]interface{}{
  2421. "list": "初始化成功",
  2422. })
  2423. return
  2424. }
  2425. //查询机构所属管理员
  2426. func (this *SecondaryOrderApiController) GetuserName() {
  2427. adminUserInfo := this.GetAdminUserInfo()
  2428. viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  2429. c, _ := service.Getcreateid(adminUserInfo.CurrentOrgId)
  2430. //c.Creator
  2431. admin := []*service.AdminUserManageViewModel{} //记录当前管理员的信息
  2432. //去除禁用的角色
  2433. tmp := []*service.AdminUserManageViewModel{}
  2434. for i := 0; i < len(viewModels); i++ {
  2435. if viewModels[i].Status == 1 {
  2436. tmp = append(tmp, viewModels[i])
  2437. }
  2438. if int64(viewModels[i].AdminUserId) == c.Creator {
  2439. admin = append(admin, viewModels[i])
  2440. }
  2441. }
  2442. roles := service.FindRoles(adminUserInfo.CurrentOrgId)
  2443. //去除没有权限的角色
  2444. tmplist := []*service.AdminUserManageViewModel{}
  2445. if roles == nil || len(roles) == 0 {
  2446. this.ServeSuccessJSON(map[string]interface{}{
  2447. "list": tmplist,
  2448. })
  2449. return
  2450. }
  2451. for i := 0; i < len(tmp); i++ {
  2452. boolean := false
  2453. //获取并解析当前用户的角色
  2454. tmproles := strings.Split(tmp[i].RoleIds, ",")
  2455. for j := 0; j < len(tmproles); j++ {
  2456. //判断这些角色是否有权限
  2457. if _, ok := roles[tmproles[j]]; ok {
  2458. boolean = true
  2459. }
  2460. }
  2461. if boolean {
  2462. tmplist = append(tmplist, tmp[i])
  2463. }
  2464. }
  2465. isappend := true //判断结果中是否添加机构创建者,true添加,false不添加
  2466. if len(tmplist) > 0 {
  2467. for i := 0; i < len(tmplist); i++ {
  2468. if int64(tmplist[i].AdminUserId) == c.Creator {
  2469. isappend = false
  2470. }
  2471. }
  2472. }
  2473. if isappend {
  2474. tmplist = append(tmplist, admin...)
  2475. }
  2476. this.ServeSuccessJSON(map[string]interface{}{
  2477. "list": tmplist,
  2478. })
  2479. return
  2480. }
  2481. func (this *SecondaryOrderApiController) GetCreaterId() {
  2482. creater := this.GetAdminUserInfo().AdminUser.Id
  2483. this.ServeSuccessJSON(map[string]interface{}{
  2484. "list": creater,
  2485. })
  2486. }