secondary_order_api_contorller.go 73KB

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