secondary_order_api_contorller.go 77KB

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