secondary_order_api_contorller.go 90KB

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