secondary_order_api_contorller.go 84KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "XT_New/enums"
  11. "XT_New/models"
  12. "XT_New/service"
  13. "XT_New/utils"
  14. "github.com/astaxie/beego"
  15. "github.com/jinzhu/gorm"
  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. medical_insurance_number := items["medical_insurance_number"].(string)
  561. info := &models.XtSecondWarehouseInfo{
  562. ProjectName: project_name,
  563. SecondSpecificationName: second_specification_name,
  564. ProjectType: project_type,
  565. SencondUnit: sencond_unit,
  566. Count: count,
  567. SecondTotal: second_total,
  568. SecondOrderNumber: secondWarehouse.SecondOrderNumber,
  569. RecordDate: record_date,
  570. StorehouseInId: storehouse_in_id,
  571. StorehouseOutId: storehouse_out_id,
  572. Creater: creater,
  573. ProjectId: project_id,
  574. Remake: remake,
  575. UserOrgId: orgId,
  576. Status: 1,
  577. Ctime: time.Now().Unix(),
  578. Mtime: 0,
  579. MinPrice: min_price,
  580. IsSource: is_source,
  581. WarehouseId: secondWarehouse.ID,
  582. MedicalInsuranceNumber: medical_insurance_number,
  583. }
  584. warehousingInfo = append(warehousingInfo, info)
  585. }
  586. }
  587. }
  588. for _, item := range warehousingInfo {
  589. service.CreateSencondWarehousingInfo(item)
  590. }
  591. //获取最后一条入库单
  592. lastSecondWarehouse, _ := service.GetLastSecondWarehouse(orgId)
  593. this.ServeSuccessJSON(map[string]interface{}{
  594. "warehousingInfo": warehousingInfo,
  595. "id": lastSecondWarehouse.ID,
  596. })
  597. return
  598. }
  599. func (this *SecondaryOrderApiController) GetAllSecondeOrderList() {
  600. check_id, _ := this.GetInt64("check_id")
  601. start_time := this.GetString("start_time")
  602. timeLayout := "2006-01-02"
  603. loc, _ := time.LoadLocation("Local")
  604. var startTime int64
  605. if len(start_time) > 0 {
  606. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  607. if err != nil {
  608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  609. return
  610. }
  611. startTime = theTime.Unix()
  612. }
  613. end_time := this.GetString("end_time")
  614. var endTime int64
  615. if len(end_time) > 0 {
  616. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  617. if err != nil {
  618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. endTime = theTime.Unix()
  622. }
  623. keyword := this.GetString("keyword")
  624. page, _ := this.GetInt64("page")
  625. limit, _ := this.GetInt64("limit")
  626. orgId := this.GetAdminUserInfo().CurrentOrgId
  627. list, total, _ := service.GetAllSecondeOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
  628. houseList, _ := service.GetAllStoreHouseList(orgId)
  629. appId := this.GetAdminUserInfo().CurrentAppId
  630. doctor, _ := service.GetAllDoctorListSix(orgId, appId)
  631. this.ServeSuccessJSON(map[string]interface{}{
  632. "list": list,
  633. "total": total,
  634. "houseList": houseList,
  635. "doctorList": doctor,
  636. })
  637. return
  638. }
  639. func (this *SecondaryOrderApiController) GetSencondOrderDetail() {
  640. id, _ := this.GetInt64("id")
  641. orgId := this.GetAdminUserInfo().CurrentOrgId
  642. warehouse, _ := service.GetSecondWarehouseOrderById(id)
  643. //获取药品库数据
  644. baseList, _ := service.GetSupplyDrugListOne(orgId, warehouse.StorehouseOutId)
  645. goodList, _ := service.GetSupplyGoodListOne(orgId, warehouse.StorehouseOutId)
  646. goodTypeList, _ := service.GetAllGoodType(orgId)
  647. configlist, _ := service.GetAllStoreHouseConfig(orgId)
  648. var drugType = "药品类型"
  649. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  650. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  651. list, _ := service.GetSencondOrderDetail(id, orgId)
  652. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  653. this.ServeSuccessJSON(map[string]interface{}{
  654. "list": list,
  655. "warehouse": warehouse,
  656. "drugList": baseList,
  657. "goodList": goodList,
  658. "goodTypeList": goodTypeList,
  659. "drugTypeList": drugTypeList,
  660. "configlist": configlist,
  661. "manufacturerList": manufacturerList,
  662. })
  663. return
  664. }
  665. func (this *SecondaryOrderApiController) UpdateSencondOrder() {
  666. warehouse_id, _ := this.GetInt64("id")
  667. start_date := this.GetString("record_date")
  668. storehouse_in_id, _ := this.GetInt64("storehouse_in_id")
  669. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  670. fmt.Println(storehouse_in_id, storehouse_out_id)
  671. timeLayout := "2006-01-02"
  672. loc, _ := time.LoadLocation("Local")
  673. var startDate int64
  674. if len(start_date) > 0 {
  675. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  676. if err != nil {
  677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  678. return
  679. }
  680. startDate = theTime.Unix()
  681. }
  682. recordDateStr := time.Now().Format("2006-01-02")
  683. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  684. record_date := recordDate.Unix()
  685. orgId := this.GetAdminUserInfo().CurrentOrgId
  686. creater := this.GetAdminUserInfo().AdminUser.Id
  687. warehouse := models.XtSecondWarehouse{
  688. StorehouseInId: storehouse_in_id,
  689. StorehouseOutId: storehouse_out_id,
  690. RecordDate: startDate,
  691. }
  692. service.UpdateModifySecondWarehouse(warehouse_id, warehouse)
  693. warehouseInfo, _ := service.GetSecondWarehouseOrderById(warehouse_id)
  694. var warehousingInfo []*models.XtSecondWarehouseInfo
  695. var updateWarehousingInfo []*models.XtSecondWarehouseInfo
  696. dataBody := make(map[string]interface{}, 0)
  697. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  698. if err != nil {
  699. utils.ErrorLog(err.Error())
  700. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  701. return
  702. }
  703. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  704. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  705. if len(thisStockIn) > 0 {
  706. for _, item := range thisStockIn {
  707. items := item.(map[string]interface{})
  708. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  709. utils.ErrorLog("id")
  710. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  711. return
  712. }
  713. id := int64(items["id"].(float64))
  714. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  715. utils.ErrorLog("project_id")
  716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  717. return
  718. }
  719. project_id := int64(items["project_id"].(float64))
  720. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  721. utils.ErrorLog("name")
  722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  723. return
  724. }
  725. project_name := items["name"].(string)
  726. if items["project_type"] == nil || reflect.TypeOf(items["project_type"]).String() != "string" {
  727. utils.ErrorLog("project_type")
  728. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  729. return
  730. }
  731. project_type := items["project_type"].(string)
  732. if items["second_specification_name"] == nil || reflect.TypeOf(items["second_specification_name"]).String() != "string" {
  733. utils.ErrorLog("second_specification_name")
  734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  735. return
  736. }
  737. second_specification_name := items["second_specification_name"].(string)
  738. if items["sencond_unit"] == nil || reflect.TypeOf(items["sencond_unit"]).String() != "string" {
  739. utils.ErrorLog("sencond_unit")
  740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. sencond_unit := items["sencond_unit"].(string)
  744. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  745. utils.ErrorLog("count")
  746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  747. return
  748. }
  749. count := int64(items["count"].(float64))
  750. if items["is_source"] == nil || reflect.TypeOf(items["is_source"]).String() != "float64" {
  751. utils.ErrorLog("is_source")
  752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  753. return
  754. }
  755. is_source := int64(items["is_source"].(float64))
  756. if items["second_total"] == nil || reflect.TypeOf(items["second_total"]).String() != "string" {
  757. utils.ErrorLog("second_total")
  758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  759. return
  760. }
  761. second_total := items["second_total"].(string)
  762. if items["remake"] == nil || reflect.TypeOf(items["remake"]).String() != "string" {
  763. utils.ErrorLog("remake")
  764. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  765. return
  766. }
  767. remake := items["remake"].(string)
  768. if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "float64" {
  769. utils.ErrorLog("min_price")
  770. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  771. return
  772. }
  773. min_price := items["min_price"].(float64)
  774. if id == 0 {
  775. info := &models.XtSecondWarehouseInfo{
  776. ProjectName: project_name,
  777. SecondSpecificationName: second_specification_name,
  778. ProjectType: project_type,
  779. SencondUnit: sencond_unit,
  780. Count: count,
  781. SecondTotal: second_total,
  782. RecordDate: record_date,
  783. StorehouseInId: storehouse_in_id,
  784. StorehouseOutId: storehouse_out_id,
  785. Creater: creater,
  786. ProjectId: project_id,
  787. Remake: remake,
  788. UserOrgId: orgId,
  789. Status: 1,
  790. Ctime: time.Now().Unix(),
  791. Mtime: 0,
  792. MinPrice: min_price,
  793. IsSource: is_source,
  794. WarehouseId: warehouse_id,
  795. SecondOrderNumber: warehouseInfo.SecondOrderNumber,
  796. }
  797. warehousingInfo = append(warehousingInfo, info)
  798. }
  799. if id > 0 {
  800. updateInfo := &models.XtSecondWarehouseInfo{
  801. ID: id,
  802. ProjectName: project_name,
  803. SecondSpecificationName: second_specification_name,
  804. ProjectType: project_type,
  805. SencondUnit: sencond_unit,
  806. Count: count,
  807. SecondTotal: second_total,
  808. SecondOrderNumber: warehouse.SecondOrderNumber,
  809. RecordDate: record_date,
  810. StorehouseInId: storehouse_in_id,
  811. StorehouseOutId: storehouse_out_id,
  812. Creater: creater,
  813. ProjectId: project_id,
  814. Remake: remake,
  815. UserOrgId: orgId,
  816. MinPrice: min_price,
  817. IsSource: is_source,
  818. }
  819. updateWarehousingInfo = append(updateWarehousingInfo, updateInfo)
  820. }
  821. }
  822. }
  823. }
  824. for _, item := range warehousingInfo {
  825. service.CreateSencondWarehousingInfo(item)
  826. }
  827. for _, item := range updateWarehousingInfo {
  828. service.UpdateStoreWarehousing(item)
  829. }
  830. this.ServeSuccessJSON(map[string]interface{}{
  831. "warehousingInfo": warehousingInfo,
  832. })
  833. return
  834. }
  835. func (this *SecondaryOrderApiController) GetSecondOrderById() {
  836. id, _ := this.GetInt64("id")
  837. orgId := this.GetAdminUserInfo().CurrentOrgId
  838. warehouse, _ := service.GetSecondWarehouseOrderById(id)
  839. list, _ := service.GetSencondOrderDetail(id, orgId)
  840. appId := this.GetAdminUserInfo().CurrentAppId
  841. doctor, _ := service.GetAllDoctorSix(orgId, appId)
  842. houseList, _ := service.GetAllStoreHouseList(orgId)
  843. this.ServeSuccessJSON(map[string]interface{}{
  844. "warehouse": warehouse,
  845. "list": list,
  846. "doctorList": doctor,
  847. "houseList": houseList,
  848. })
  849. return
  850. }
  851. func (this *SecondaryOrderApiController) CheckSecondOrer() {
  852. ids := this.GetString("ids")
  853. if len(ids) == 0 {
  854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  855. return
  856. }
  857. idArray := strings.Split(ids, ",")
  858. orgId := this.GetAdminUserInfo().CurrentOrgId
  859. creater := this.GetAdminUserInfo().AdminUser.Id
  860. //根据订单id获取商品详情
  861. list, _ := service.GetSecondOrderList(idArray, orgId)
  862. for _, item := range list {
  863. if item.IsSource == 1 {
  864. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  865. //查询该仓库的药品库存是否满足调出数量
  866. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  867. var total int64
  868. var total_count int64
  869. for _, it := range drugInfoList {
  870. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  871. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  872. }
  873. }
  874. for _, it := range drugInfoList {
  875. total += it.StockMaxNumber + it.StockMinNumber
  876. }
  877. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  878. total_count = item.Count * medical.MinNumber
  879. }
  880. if item.SencondUnit == medical.MinUnit {
  881. total_count = item.Count
  882. }
  883. if total_count > total {
  884. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  885. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseOutId, item.UserOrgId)
  886. this.ServeSuccessJSON(map[string]interface{}{
  887. "msg": "3",
  888. "drug_name": goodObj.DrugName,
  889. "dose": goodObj.Dose,
  890. "dose_unit": goodObj.DoseUnit,
  891. "min_number": goodObj.MinNumber,
  892. "min_unit": goodObj.MinUnit,
  893. "max_unit": goodObj.MaxUnit,
  894. "storehose_name": storehouse.StorehouseName,
  895. })
  896. return
  897. }
  898. }
  899. if item.IsSource == 2 {
  900. //查询该仓库的耗材库存是否满足调出数量
  901. var total int64
  902. infoList, _ := service.GetWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  903. for _, it := range infoList {
  904. total += it.StockCount
  905. }
  906. if item.Count > total {
  907. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseOutId, item.UserOrgId)
  908. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  909. this.ServeSuccessJSON(map[string]interface{}{
  910. "msg": "2",
  911. "good_name": goodObj.GoodName,
  912. "specification_name": goodObj.SpecificationName,
  913. "storehose_name": storehouse.StorehouseName,
  914. })
  915. return
  916. }
  917. }
  918. }
  919. err := service.UpdateStoreOrderByArray(idArray, orgId, creater)
  920. //如果审核成功
  921. if err == nil {
  922. //调用出库接口
  923. timeStr := time.Now().Format("2006-01-02")
  924. timeArr := strings.Split(timeStr, "-")
  925. total, _ := service.FindAllWarehouseOut(orgId)
  926. total = total + 1
  927. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  928. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  929. number = number + total
  930. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  931. operation_time := time.Now().Unix()
  932. creater := this.GetAdminUserInfo().AdminUser.Id
  933. recordDateStr := time.Now().Format("2006-01-02")
  934. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  935. record_date := recordDate.Unix()
  936. totals, _ := service.FindAllWarehouseTotal(orgId)
  937. totals = totals + 1
  938. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(totals, 10)
  939. for _, item := range list {
  940. //药品
  941. if item.IsSource == 1 {
  942. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  943. //查询该仓库的药品库存是否满足调出数量
  944. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  945. var total int64
  946. var total_count int64
  947. for _, it := range drugInfoList {
  948. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  949. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  950. }
  951. }
  952. for _, it := range drugInfoList {
  953. total += it.StockMaxNumber + it.StockMinNumber
  954. }
  955. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  956. total_count = item.Count * medical.MinNumber
  957. }
  958. if item.SencondUnit == medical.MinUnit {
  959. total_count = item.Count
  960. }
  961. if total_count <= total {
  962. drug_total, _ := service.FindAllDrugWarehouseOut(orgId)
  963. drug_total = drug_total + 1
  964. drug_warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  965. number, _ := strconv.ParseInt(drug_warehousing_out_order, 10, 64)
  966. number = number + drug_total
  967. drug_warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  968. operation_time := time.Now().Unix()
  969. drugWarehouseOut := models.DrugWarehouseOut{
  970. WarehouseOutOrderNumber: drug_warehousing_out_order,
  971. OperationTime: operation_time,
  972. OrgId: orgId,
  973. Creater: creater,
  974. Ctime: time.Now().Unix(),
  975. Status: 1,
  976. WarehouseOutTime: record_date,
  977. Type: 2,
  978. StorehouseId: item.StorehouseOutId,
  979. SecondWarehouseId: item.WarehouseId,
  980. IsSys: 12,
  981. IsCheck: 1,
  982. }
  983. _, drugerrcodes := service.GetDrugWarehouseBySyS(orgId, 12, item.WarehouseId, record_date)
  984. if drugerrcodes == gorm.ErrRecordNotFound {
  985. service.AddSigleDrugWarehouseOut(&drugWarehouseOut)
  986. }
  987. drugOut, _ := service.GetLastDrugWarehouseOutById(12, item.WarehouseId, orgId, record_date)
  988. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  989. WarehouseOutOrderNumber: drugOut.WarehouseOutOrderNumber,
  990. WarehouseOutId: drugOut.ID,
  991. DrugId: item.ProjectId,
  992. Count: item.Count,
  993. Price: medical.RetailPrice,
  994. TotalPrice: 0,
  995. Status: 1,
  996. Ctime: time.Now().Unix(),
  997. Remark: item.Remake,
  998. OrgId: orgId,
  999. Type: 2,
  1000. Manufacturer: 0,
  1001. Dealer: 0,
  1002. RetailPrice: item.MinPrice,
  1003. RetailTotalPrice: 0,
  1004. CountUnit: item.SencondUnit,
  1005. ExpiryDate: 0,
  1006. ProductDate: 0,
  1007. Number: "",
  1008. BatchNumber: "",
  1009. IsSys: 0,
  1010. WarehouseInfoId: 0,
  1011. StorehouseId: item.StorehouseOutId,
  1012. SecondWarehouseInfoId: item.ID,
  1013. IsCheck: 1,
  1014. }
  1015. drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
  1016. drug_in_total, _ := service.FindAllWarehouseTotalOne(orgId)
  1017. drug_in_total = drug_in_total + 1
  1018. warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(drug_in_total, 10)
  1019. drug_warehousing := models.DrugWarehouse{
  1020. WarehousingOrder: warehousing_order,
  1021. OperationTime: operation_time,
  1022. OrgId: orgId,
  1023. Creater: creater,
  1024. Ctime: time.Now().Unix(),
  1025. Status: 1,
  1026. WarehousingTime: record_date,
  1027. Type: 1,
  1028. StorehouseId: item.StorehouseInId,
  1029. IsSys: 13,
  1030. SecondWarehouseId: item.WarehouseId,
  1031. IsCheck: 1,
  1032. }
  1033. //查询该调拨单是否有生成入库单
  1034. _, drugerrcodess := service.GetDrugWarehouseingBySys(13, item.WarehouseId, orgId, record_date)
  1035. if drugerrcodess == gorm.ErrRecordNotFound {
  1036. service.CreateDrugWaresing(drug_warehousing)
  1037. }
  1038. drugInfoObj, _ := service.GetLastDrugWarehouseBySys(13, item.WarehouseId, orgId, record_date)
  1039. drugwarehouseInfo := &models.DrugWarehouseInfo{
  1040. WarehousingOrder: drugInfoObj.WarehousingOrder,
  1041. WarehousingId: drugInfoObj.ID,
  1042. DrugId: item.ProjectId,
  1043. Number: "",
  1044. ProductDate: 0,
  1045. ExpiryDate: 0,
  1046. WarehousingCount: 0,
  1047. Price: 0,
  1048. TotalPrice: 0,
  1049. Status: 1,
  1050. Ctime: time.Now().Unix(),
  1051. Remark: "",
  1052. OrgId: orgId,
  1053. Type: 2,
  1054. Manufacturer: 0,
  1055. Dealer: 0,
  1056. StockMaxNumber: 0,
  1057. RetailTotalPrice: 0,
  1058. BatchNumber: "",
  1059. MaxUnit: "",
  1060. MinUnit: "",
  1061. RetailPrice: 0,
  1062. StorehouseId: item.StorehouseInId,
  1063. SecondWarehouseInfoId: item.ID,
  1064. IsCheck: 1,
  1065. }
  1066. service.AutoDrugDeliverInfoTwelve(orgId, item.Count, &drugWarehouseOut, &drup, warehouseOutInfo, drugwarehouseInfo)
  1067. //查询默认仓库
  1068. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1069. //更新字典里面的库存
  1070. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
  1071. var sum_count int64
  1072. for _, its := range stockInfo {
  1073. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1074. if its.MaxUnit == baseDrug.MaxUnit {
  1075. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1076. }
  1077. sum_count += its.StockMaxNumber + its.StockMinNumber
  1078. }
  1079. service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
  1080. }
  1081. //查询该药品该仓库是否有数据
  1082. drug, _ := service.GetDrugStockCout(item.ProjectId, item.StorehouseInId, item.UserOrgId)
  1083. var sum_out_count int64
  1084. baseDrug, _ := service.GetBaseDrugMedical(item.ProjectId)
  1085. if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
  1086. sum_out_count = item.Count * baseDrug.MinNumber
  1087. }
  1088. if item.SencondUnit == baseDrug.MinUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
  1089. sum_out_count = item.Count
  1090. }
  1091. if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit == baseDrug.MinUnit {
  1092. sum_out_count = item.Count
  1093. }
  1094. if drug.ID == 0 {
  1095. drugstock := models.XtDrugStockCount{
  1096. UserOrgId: orgId,
  1097. StorehouseId: item.StorehouseInId,
  1098. SumInCount: sum_out_count,
  1099. SumOutCount: 0,
  1100. SumCancelCount: 0,
  1101. DrugId: item.ProjectId,
  1102. Ctime: time.Now().Unix(),
  1103. Mtime: 0,
  1104. Status: 1,
  1105. FlushCount: sum_out_count,
  1106. SumActOutCount: 0,
  1107. }
  1108. service.CreateDrugStockCount(drugstock)
  1109. }
  1110. if drug.ID > 0 {
  1111. service.AddDrugStockCount(item.StorehouseInId, item.ProjectId, item.UserOrgId, sum_out_count)
  1112. }
  1113. //更新出库数据
  1114. service.ReduceDrugStockCountSix(item.StorehouseOutId, item.ProjectId, item.UserOrgId, sum_out_count)
  1115. }
  1116. //耗材
  1117. if item.IsSource == 2 {
  1118. //查询该仓库的耗材库存是否满足调出数量
  1119. var total int64
  1120. infoList, _ := service.GetWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  1121. for _, it := range infoList {
  1122. total += it.StockCount
  1123. }
  1124. //满足调拨
  1125. if item.Count <= total {
  1126. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1127. warehouseOut := models.WarehouseOut{
  1128. WarehouseOutOrderNumber: warehousing_out_order,
  1129. OperationTime: operation_time,
  1130. OrgId: orgId,
  1131. Creater: creater,
  1132. Ctime: time.Now().Unix(),
  1133. Status: 1,
  1134. WarehouseOutTime: record_date,
  1135. Type: 1,
  1136. StorehouseId: item.StorehouseOutId,
  1137. IsSys: 12,
  1138. SecondWarehouseId: item.WarehouseId,
  1139. IsCheck: 1,
  1140. }
  1141. //查询今日是否存在调拨出库
  1142. _, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
  1143. if errcodes == gorm.ErrRecordNotFound {
  1144. service.AddSigleWarehouseOutOne(&warehouseOut)
  1145. }
  1146. out, _ := service.GetLastWarehouseOutBySys(12, orgId, record_date, item.WarehouseId)
  1147. warehouseOutInfo := &models.WarehouseOutInfo{
  1148. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1149. WarehouseOutId: out.ID,
  1150. GoodId: item.ProjectId,
  1151. GoodTypeId: goodObj.GoodTypeId,
  1152. Count: item.Count,
  1153. Price: item.MinPrice,
  1154. TotalPrice: 0,
  1155. Status: 1,
  1156. Ctime: time.Now().Unix(),
  1157. Remark: item.Remake,
  1158. OrgId: orgId,
  1159. Type: 1,
  1160. Manufacturer: 0,
  1161. Number: "",
  1162. ExpiryDate: 0,
  1163. ProductDate: 0,
  1164. Dealer: 0,
  1165. LicenseNumber: "",
  1166. WarehouseInfotId: 0,
  1167. StorehouseId: item.StorehouseOutId,
  1168. SecondWarehouseInfoId: item.ID,
  1169. IsCheck: 1,
  1170. }
  1171. //入库操作
  1172. warehousing := models.Warehousing{
  1173. WarehousingOrder: warehousing_order,
  1174. OperationTime: operation_time,
  1175. OrgId: orgId,
  1176. Creater: creater,
  1177. Ctime: time.Now().Unix(),
  1178. Status: 1,
  1179. WarehousingTime: record_date,
  1180. Type: 1,
  1181. StorehouseId: item.StorehouseInId,
  1182. IsSys: 12,
  1183. SecondWarehouseId: item.WarehouseId,
  1184. IsCheck: 1,
  1185. }
  1186. //查询该调拨单是否有生成入库单
  1187. _, errcodess := service.GetWarehouseBySecondWarehouseId(12, item.WarehouseId, orgId, record_date)
  1188. if errcodess == gorm.ErrRecordNotFound {
  1189. service.AddSigleWarehouse(&warehousing)
  1190. }
  1191. infoObj, _ := service.GetLastWarehouseById(12, item.WarehouseId, orgId, record_date)
  1192. warehouseInfo := &models.WarehousingInfo{
  1193. WarehousingOrder: infoObj.WarehousingOrder,
  1194. WarehousingId: infoObj.ID,
  1195. GoodId: item.ProjectId,
  1196. Number: "",
  1197. GoodTypeId: goodObj.GoodTypeId,
  1198. ProductDate: 0,
  1199. ExpiryDate: 0,
  1200. WarehousingCount: item.Count,
  1201. Price: goodObj.BuyPrice,
  1202. TotalPrice: 0,
  1203. Status: 1,
  1204. Ctime: time.Now().Unix(),
  1205. Remark: item.Remake,
  1206. OrgId: orgId,
  1207. Type: 1,
  1208. Manufacturer: 0,
  1209. StockCount: item.Count,
  1210. Dealer: 0,
  1211. LicenseNumber: "",
  1212. PackingPrice: item.MinPrice,
  1213. StorehouseId: item.StorehouseInId,
  1214. SecondWarehouseInfoId: item.ID,
  1215. IsCheck: 1,
  1216. }
  1217. //出库逻辑
  1218. parseDateErr := service.ConsumablesDeliveryTwelve(orgId, record_date, warehouseOutInfo, &warehouseOut, item.Count, creater, warehouseInfo)
  1219. fmt.Println(parseDateErr)
  1220. }
  1221. //查询默认仓库
  1222. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1223. stockList, _ := service.GetStockCountByGoodId(item.ProjectId, storeHouseConfig.StorehouseOutInfo, orgId)
  1224. var total_count int64
  1225. for _, it := range stockList {
  1226. total_count += it.StockCount
  1227. }
  1228. //基础库插入数据
  1229. service.UpdateGoodInfoSumCountSix(item.ProjectId, total_count, orgId)
  1230. //查询是否有数据
  1231. _, errcodes := service.GetStockFlush(item.StorehouseInId, item.ProjectId, item.UserOrgId)
  1232. if errcodes == gorm.ErrRecordNotFound {
  1233. good := models.XtGoodStockCount{
  1234. UserOrgId: item.UserOrgId,
  1235. GoodId: item.ProjectId,
  1236. StorehouseId: item.StorehouseInId,
  1237. Status: 1,
  1238. Ctime: time.Now().Unix(),
  1239. Mtime: 0,
  1240. StockInCount: item.Count,
  1241. StockOutCount: 0,
  1242. StockCancelCount: 0,
  1243. FlushCount: item.Count,
  1244. StockActOutCount: 0,
  1245. }
  1246. service.CreateGoodCountSix(good)
  1247. } else if errcodes == nil {
  1248. service.AddGoodStockCount(item.StorehouseInId, item.ProjectId, item.UserOrgId, item.Count)
  1249. }
  1250. //更新出库数据
  1251. service.ReduceStockCount(item.StorehouseOutId, item.ProjectId, item.UserOrgId, item.Count)
  1252. }
  1253. }
  1254. }
  1255. this.ServeSuccessJSON(map[string]interface{}{
  1256. "msg": 1,
  1257. })
  1258. return
  1259. }
  1260. func (this *SecondaryOrderApiController) DeleteStorehouseList() {
  1261. id, _ := this.GetInt64("id")
  1262. err := service.DeleteStorehouseList(id)
  1263. if err == nil {
  1264. returnData := make(map[string]interface{}, 0)
  1265. returnData["msg"] = "ok"
  1266. this.ServeSuccessJSON(returnData)
  1267. return
  1268. } else {
  1269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1270. }
  1271. }
  1272. func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
  1273. ids := this.GetString("ids")
  1274. if len(ids) == 0 {
  1275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1276. return
  1277. }
  1278. idArray := strings.Split(ids, ",")
  1279. orgId := this.GetAdminUserInfo().CurrentOrgId
  1280. //根据订单id获取商品详情
  1281. list, _ := service.GetSecondOrderList(idArray, orgId)
  1282. //药品
  1283. for _, item := range list {
  1284. //药品
  1285. if item.IsSource == 1 {
  1286. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1287. //查询该仓库的药品库存是否满足调出数量
  1288. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1289. var total int64
  1290. var total_count int64
  1291. for _, it := range drugInfoList {
  1292. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1293. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1294. }
  1295. }
  1296. for _, it := range drugInfoList {
  1297. total += it.StockMaxNumber + it.StockMinNumber
  1298. }
  1299. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1300. total_count = item.Count * medical.MinNumber
  1301. }
  1302. if item.SencondUnit == medical.MinUnit {
  1303. total_count = item.Count
  1304. }
  1305. if total_count > total {
  1306. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  1307. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
  1308. this.ServeSuccessJSON(map[string]interface{}{
  1309. "msg": "3",
  1310. "drug_name": goodObj.DrugName,
  1311. "dose": goodObj.Dose,
  1312. "dose_unit": goodObj.DoseUnit,
  1313. "min_number": goodObj.MinNumber,
  1314. "min_unit": goodObj.MinUnit,
  1315. "max_unit": goodObj.MaxUnit,
  1316. "storehose_name": storehouse.StorehouseName,
  1317. })
  1318. return
  1319. }
  1320. }
  1321. //耗材
  1322. if item.IsSource == 2 {
  1323. //查询该仓库的耗材库存是否满足调出数量
  1324. var total int64
  1325. infoList, _ := service.GetWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1326. for _, it := range infoList {
  1327. total += it.StockCount
  1328. }
  1329. if item.Count > total {
  1330. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
  1331. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1332. this.ServeSuccessJSON(map[string]interface{}{
  1333. "msg": "2",
  1334. "good_name": goodObj.GoodName,
  1335. "specification_name": goodObj.SpecificationName,
  1336. "storehose_name": storehouse.StorehouseName,
  1337. })
  1338. return
  1339. }
  1340. }
  1341. }
  1342. //反审核操作
  1343. err := service.ModifyStoreHouseById(idArray, orgId)
  1344. if err != nil {
  1345. this.ServeSuccessJSON(map[string]interface{}{
  1346. "msg": "0",
  1347. })
  1348. return
  1349. }
  1350. for _, item := range list {
  1351. //药品
  1352. if item.IsSource == 1 {
  1353. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1354. //查询该仓库的药品库存是否满足调出数量
  1355. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1356. var total int64
  1357. var total_count int64
  1358. for _, it := range drugInfoList {
  1359. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1360. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1361. }
  1362. }
  1363. for _, it := range drugInfoList {
  1364. total += it.StockMaxNumber + it.StockMinNumber
  1365. }
  1366. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1367. total_count = item.Count * medical.MinNumber
  1368. }
  1369. if item.SencondUnit == medical.MinUnit {
  1370. total_count = item.Count
  1371. }
  1372. fmt.Println("total_count2332232333233223", total_count)
  1373. fmt.Println("totoal2323232332322332", total)
  1374. if total_count <= total {
  1375. timeStr := time.Now().Format("2006-01-02")
  1376. timeArr := strings.Split(timeStr, "-")
  1377. creater := this.GetAdminUserInfo().AdminUser.Id
  1378. drug_total, _ := service.FindAllDrugWarehouseOut(orgId)
  1379. recordDateStr := time.Now().Format("2006-01-02")
  1380. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1381. record_date := recordDate.Unix()
  1382. drug_total = drug_total + 1
  1383. drug_warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1384. number, _ := strconv.ParseInt(drug_warehousing_out_order, 10, 64)
  1385. number = number + drug_total
  1386. drug_warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1387. operation_time := time.Now().Unix()
  1388. drugWarehouseOut := models.DrugWarehouseOut{
  1389. WarehouseOutOrderNumber: drug_warehousing_out_order,
  1390. OperationTime: operation_time,
  1391. OrgId: orgId,
  1392. Creater: creater,
  1393. Ctime: time.Now().Unix(),
  1394. Status: 1,
  1395. WarehouseOutTime: record_date,
  1396. Type: 2,
  1397. StorehouseId: item.StorehouseInId,
  1398. SecondWarehouseId: item.WarehouseId,
  1399. IsSys: 12,
  1400. IsCheck: 1,
  1401. }
  1402. _, drugerrcodes := service.GetDrugWarehouseBySyS(orgId, 12, item.WarehouseId, record_date)
  1403. if drugerrcodes == gorm.ErrRecordNotFound {
  1404. service.AddSigleDrugWarehouseOut(&drugWarehouseOut)
  1405. }
  1406. drugOut, _ := service.GetLastDrugWarehouseOutById(12, item.WarehouseId, orgId, record_date)
  1407. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1408. WarehouseOutOrderNumber: drugOut.WarehouseOutOrderNumber,
  1409. WarehouseOutId: drugOut.ID,
  1410. DrugId: item.ProjectId,
  1411. Count: item.Count,
  1412. Price: medical.RetailPrice,
  1413. TotalPrice: 0,
  1414. Status: 1,
  1415. Ctime: time.Now().Unix(),
  1416. Remark: item.Remake,
  1417. OrgId: orgId,
  1418. Type: 2,
  1419. Manufacturer: 0,
  1420. Dealer: 0,
  1421. RetailPrice: item.MinPrice,
  1422. RetailTotalPrice: 0,
  1423. CountUnit: item.SencondUnit,
  1424. ExpiryDate: 0,
  1425. ProductDate: 0,
  1426. Number: "",
  1427. BatchNumber: "",
  1428. IsSys: 0,
  1429. WarehouseInfoId: 0,
  1430. StorehouseId: item.StorehouseInId,
  1431. SecondWarehouseInfoId: item.ID,
  1432. IsCheck: 1,
  1433. }
  1434. drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
  1435. drug_in_total, _ := service.FindAllWarehouseTotalOne(orgId)
  1436. drug_in_total = drug_in_total + 1
  1437. warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(drug_in_total, 10)
  1438. drug_warehousing := models.DrugWarehouse{
  1439. WarehousingOrder: warehousing_order,
  1440. OperationTime: operation_time,
  1441. OrgId: orgId,
  1442. Creater: creater,
  1443. Ctime: time.Now().Unix(),
  1444. Status: 1,
  1445. WarehousingTime: record_date,
  1446. Type: 1,
  1447. StorehouseId: item.StorehouseOutId,
  1448. IsSys: 13,
  1449. SecondWarehouseId: item.WarehouseId,
  1450. IsCheck: 1,
  1451. }
  1452. //查询该调拨单是否有生成入库单
  1453. _, drugerrcodess := service.GetDrugWarehouseingBySys(13, item.WarehouseId, orgId, record_date)
  1454. if drugerrcodess == gorm.ErrRecordNotFound {
  1455. service.CreateDrugWaresing(drug_warehousing)
  1456. }
  1457. drugInfoObj, _ := service.GetLastDrugWarehouseBySys(13, item.WarehouseId, orgId, record_date)
  1458. drugwarehouseInfo := &models.DrugWarehouseInfo{
  1459. WarehousingOrder: drugInfoObj.WarehousingOrder,
  1460. WarehousingId: drugInfoObj.ID,
  1461. DrugId: item.ProjectId,
  1462. Number: "",
  1463. ProductDate: 0,
  1464. ExpiryDate: 0,
  1465. WarehousingCount: 0,
  1466. Price: 0,
  1467. TotalPrice: 0,
  1468. Status: 1,
  1469. Ctime: time.Now().Unix(),
  1470. Remark: "",
  1471. OrgId: orgId,
  1472. Type: 2,
  1473. Manufacturer: 0,
  1474. Dealer: 0,
  1475. StockMaxNumber: 0,
  1476. RetailTotalPrice: 0,
  1477. BatchNumber: "",
  1478. MaxUnit: "",
  1479. MinUnit: "",
  1480. RetailPrice: 0,
  1481. StorehouseId: item.StorehouseOutId,
  1482. SecondWarehouseInfoId: item.ID,
  1483. IsCheck: 1,
  1484. }
  1485. fmt.Println("尽力发的233223323232")
  1486. service.AutoDrugDeliverInfoTwelve(orgId, item.Count, &drugWarehouseOut, &drup, warehouseOutInfo, drugwarehouseInfo)
  1487. //查询默认仓库
  1488. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1489. //更新字典里面的库存
  1490. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
  1491. var sum_count int64
  1492. for _, its := range stockInfo {
  1493. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1494. if its.MaxUnit == baseDrug.MaxUnit {
  1495. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1496. }
  1497. sum_count += its.StockMaxNumber + its.StockMinNumber
  1498. }
  1499. service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
  1500. //回退库存,查询该订单出库记录
  1501. //drugOutList, _ := service.GetStoreDrugWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
  1502. //for _, it := range drugOutList {
  1503. //
  1504. // if medical.MaxUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
  1505. // //回退库存
  1506. // service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
  1507. // }
  1508. //
  1509. // if medical.MaxUnit == it.CountUnit && medical.MaxUnit == medical.MinUnit {
  1510. // //回退库存
  1511. // service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
  1512. // }
  1513. //
  1514. // if medical.MinUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
  1515. //
  1516. // service.ModifyDrugStoreWarehouseInfoOne(it.WarehouseInfoId, it.Count)
  1517. // }
  1518. //
  1519. // //查询入库单
  1520. // //storeWareing, _ := service.GetStoreDrugWarehouseById(item.WarehouseId, it.OrgId)
  1521. // //删除入库单
  1522. // //service.DeleteStoreWarehousingId(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
  1523. //
  1524. // //查询出单
  1525. // //storeWarehouseOut, _ := service.GetStoreDrugWarehouseOutById(it.WarehouseOutId, it.OrgId)
  1526. //
  1527. // //删除出库单
  1528. // //service.DeleteStoreWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
  1529. //}
  1530. }
  1531. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1532. var sum_count int64
  1533. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
  1534. for _, its := range stockInfo {
  1535. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1536. if its.MaxUnit == baseDrug.MaxUnit {
  1537. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1538. }
  1539. sum_count += its.StockMaxNumber + its.StockMinNumber
  1540. }
  1541. service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
  1542. var sum_out_count int64
  1543. baseDrug, _ := service.GetBaseDrugMedical(item.ProjectId)
  1544. if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
  1545. sum_out_count = item.Count * baseDrug.MinNumber
  1546. }
  1547. if item.SencondUnit == baseDrug.MinUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
  1548. sum_out_count = item.Count
  1549. }
  1550. if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit == baseDrug.MinUnit {
  1551. sum_out_count = item.Count
  1552. }
  1553. //入库仓库减少
  1554. service.ReduceDrugStockCountSeven(item.StorehouseInId, item.ProjectId, item.UserOrgId, sum_out_count)
  1555. //出库仓库增加
  1556. service.AddDrugStockCount(item.StorehouseOutId, item.ProjectId, item.UserOrgId, sum_out_count)
  1557. }
  1558. //耗材
  1559. if item.IsSource == 2 {
  1560. //查询该仓库的耗材库存是否满足调出数量
  1561. var total int64
  1562. infoList, _ := service.GetWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1563. for _, it := range infoList {
  1564. total += it.StockCount
  1565. }
  1566. //满足调拨
  1567. if item.Count <= total {
  1568. timeStr := time.Now().Format("2006-01-02")
  1569. timeArr := strings.Split(timeStr, "-")
  1570. total, _ := service.FindAllWarehouseOut(orgId)
  1571. total = total + 1
  1572. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1573. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1574. number = number + total
  1575. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1576. operation_time := time.Now().Unix()
  1577. creater := this.GetAdminUserInfo().AdminUser.Id
  1578. recordDateStr := time.Now().Format("2006-01-02")
  1579. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1580. record_date := recordDate.Unix()
  1581. totals, _ := service.FindAllWarehouseTotal(orgId)
  1582. totals = totals + 1
  1583. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(totals, 10)
  1584. //创建出库单
  1585. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1586. warehouseOut := models.WarehouseOut{
  1587. WarehouseOutOrderNumber: warehousing_out_order,
  1588. OperationTime: operation_time,
  1589. OrgId: orgId,
  1590. Creater: creater,
  1591. Ctime: time.Now().Unix(),
  1592. Status: 1,
  1593. WarehouseOutTime: record_date,
  1594. Type: 1,
  1595. StorehouseId: item.StorehouseInId,
  1596. IsSys: 12,
  1597. SecondWarehouseId: item.WarehouseId,
  1598. IsCheck: 1,
  1599. }
  1600. //查询今日是否存在调拨出库
  1601. _, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
  1602. if errcodes == gorm.ErrRecordNotFound {
  1603. service.AddSigleWarehouseOutOne(&warehouseOut)
  1604. }
  1605. out, _ := service.GetLastWarehouseOutBySys(12, orgId, record_date, item.WarehouseId)
  1606. warehouseOutInfo := &models.WarehouseOutInfo{
  1607. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1608. WarehouseOutId: out.ID,
  1609. GoodId: item.ProjectId,
  1610. GoodTypeId: goodObj.GoodTypeId,
  1611. Count: item.Count,
  1612. Price: item.MinPrice,
  1613. TotalPrice: 0,
  1614. Status: 1,
  1615. Ctime: time.Now().Unix(),
  1616. Remark: item.Remake,
  1617. OrgId: orgId,
  1618. Type: 1,
  1619. Manufacturer: 0,
  1620. Number: "",
  1621. ExpiryDate: 0,
  1622. ProductDate: 0,
  1623. Dealer: 0,
  1624. LicenseNumber: "",
  1625. WarehouseInfotId: 0,
  1626. StorehouseId: item.StorehouseInId,
  1627. SecondWarehouseInfoId: item.ID,
  1628. IsCheck: 1,
  1629. }
  1630. //入库操作
  1631. warehousing := models.Warehousing{
  1632. WarehousingOrder: warehousing_order,
  1633. OperationTime: operation_time,
  1634. OrgId: orgId,
  1635. Creater: creater,
  1636. Ctime: time.Now().Unix(),
  1637. Status: 1,
  1638. WarehousingTime: record_date,
  1639. Type: 1,
  1640. StorehouseId: item.StorehouseOutId,
  1641. IsSys: 12,
  1642. SecondWarehouseId: item.WarehouseId,
  1643. IsCheck: 1,
  1644. }
  1645. //查询该调拨单是否有生成入库单
  1646. _, errcodess := service.GetWarehouseBySecondWarehouseId(12, item.WarehouseId, orgId, record_date)
  1647. if errcodess == gorm.ErrRecordNotFound {
  1648. service.AddSigleWarehouse(&warehousing)
  1649. }
  1650. infoObj, _ := service.GetLastWarehouseById(12, item.WarehouseId, orgId, record_date)
  1651. warehouseInfo := &models.WarehousingInfo{
  1652. WarehousingOrder: infoObj.WarehousingOrder,
  1653. WarehousingId: infoObj.ID,
  1654. GoodId: item.ProjectId,
  1655. Number: "",
  1656. GoodTypeId: goodObj.GoodTypeId,
  1657. ProductDate: 0,
  1658. ExpiryDate: 0,
  1659. WarehousingCount: item.Count,
  1660. Price: goodObj.BuyPrice,
  1661. TotalPrice: 0,
  1662. Status: 1,
  1663. Ctime: time.Now().Unix(),
  1664. Remark: item.Remake,
  1665. OrgId: orgId,
  1666. Type: 1,
  1667. Manufacturer: 0,
  1668. StockCount: item.Count,
  1669. Dealer: 0,
  1670. LicenseNumber: "",
  1671. PackingPrice: item.MinPrice,
  1672. StorehouseId: item.StorehouseOutId,
  1673. SecondWarehouseInfoId: item.ID,
  1674. IsCheck: 1,
  1675. }
  1676. //出库逻辑
  1677. parseDateErr := service.ConsumablesDeliveryTwelve(orgId, record_date, warehouseOutInfo, &warehouseOut, item.Count, creater, warehouseInfo)
  1678. fmt.Println(parseDateErr)
  1679. //回退库存,查询该订单出库记录
  1680. //outList, _ := service.GetStoreWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
  1681. //for _, it := range outList {
  1682. // //回退库存
  1683. // service.ModifyStoreWarehouseById(it.WarehouseInfotId, it.Count)
  1684. //
  1685. // //获取入库单
  1686. // //storeWareing, _ := service.GetStoreWarehouseById(item.WarehouseId, it.OrgId)
  1687. // //删除入库单 入库流水
  1688. // //service.ModifyStoreWarehouse(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
  1689. // //获取出库单
  1690. // //storeWarehouseOut, _ := service.GetStoreWarehouseOutById(it.WarehouseOutId, it.OrgId)
  1691. // //删除出库单
  1692. // //service.ModifyWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
  1693. //}
  1694. }
  1695. //查询默认仓库
  1696. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1697. stockList, _ := service.GetStockCountByGoodId(item.ProjectId, storeHouseConfig.StorehouseOutInfo, orgId)
  1698. var total_count int64
  1699. for _, it := range stockList {
  1700. total_count += it.StockCount
  1701. }
  1702. //基础库插入数据
  1703. service.UpdateGoodInfoSumCount(item.ProjectId, total_count, orgId)
  1704. //入库仓库减少
  1705. service.ReduceStockCountTwo(item.StorehouseInId, item.ProjectId, item.UserOrgId, item.Count)
  1706. //出库仓库增加
  1707. service.AddGoodStockCount(item.StorehouseOutId, item.ProjectId, item.UserOrgId, item.Count)
  1708. }
  1709. }
  1710. ////获取所有的入库仓库
  1711. //druglist, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
  1712. //for _, item := range druglist {
  1713. // //查询该药品该仓库是否有数据
  1714. // drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
  1715. //
  1716. // //查询该仓库该药品的入库数量
  1717. // medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1718. //
  1719. // var sum_in_count int64
  1720. // var flush_count int64
  1721. // var sum_out_count int64
  1722. // var cancel_out_count int64
  1723. // //查询入库数量和剩余库存
  1724. // infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
  1725. // for _, it := range infolist {
  1726. // if it.MaxUnit == medical.MaxUnit {
  1727. // it.WarehousingCount = it.WarehousingCount * medical.MinNumber
  1728. // it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1729. // }
  1730. // sum_in_count += it.WarehousingCount
  1731. // flush_count += it.StockMaxNumber + it.StockMinNumber
  1732. // }
  1733. //
  1734. // //获取出库数量
  1735. // outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
  1736. // for _, it := range outinfolist {
  1737. // if it.MaxUnit == medical.MaxUnit {
  1738. // it.Count = it.Count * medical.MinNumber
  1739. // }
  1740. // sum_out_count += it.Count
  1741. // }
  1742. //
  1743. // //获取退库数量
  1744. // cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
  1745. // for _, it := range cancelinfolist {
  1746. // if it.MaxUnit == medical.MaxUnit {
  1747. // it.Count = it.Count * medical.MinNumber
  1748. // }
  1749. // cancel_out_count += it.Count
  1750. // }
  1751. //
  1752. // //新增
  1753. // if drug.ID == 0 {
  1754. // drugstock := models.XtDrugStockCount{
  1755. // UserOrgId: orgId,
  1756. // StorehouseId: item.StorehouseId,
  1757. // SumInCount: sum_in_count,
  1758. // SumOutCount: sum_out_count - cancel_out_count,
  1759. // SumCancelCount: cancel_out_count,
  1760. // DrugId: item.DrugId,
  1761. // Ctime: time.Now().Unix(),
  1762. // Mtime: 0,
  1763. // Status: 1,
  1764. // FlushCount: flush_count,
  1765. // SumActOutCount: sum_out_count,
  1766. // }
  1767. // service.CreateDrugStockCount(drugstock)
  1768. // }
  1769. //}
  1770. ////获取入库数据
  1771. //goodlist, _ := service.GetSendGoodInformation(orgId)
  1772. //for _, it := range goodlist {
  1773. // //查询是否有数据
  1774. // _, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
  1775. // //获取总退库数量
  1776. // var cancel_count int64
  1777. // var out_count int64
  1778. // var act_count int64
  1779. // //退库总数量
  1780. // cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
  1781. // for _, item := range cancellist {
  1782. // cancel_count += item.Count
  1783. // }
  1784. // //出库总数量
  1785. // outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  1786. // for _, item := range outlist {
  1787. // out_count += item.Count
  1788. // }
  1789. //
  1790. // //实际出库总数量
  1791. // actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
  1792. // for _, item := range actlist {
  1793. // act_count += item.Count
  1794. // }
  1795. //
  1796. // if errcode == gorm.ErrRecordNotFound {
  1797. // good := models.XtGoodStockCount{
  1798. // UserOrgId: it.OrgId,
  1799. // GoodId: it.GoodId,
  1800. // StorehouseId: it.StorehouseId,
  1801. // Status: 1,
  1802. // Ctime: time.Now().Unix(),
  1803. // Mtime: 0,
  1804. // StockInCount: it.WarehousingCount,
  1805. // StockOutCount: out_count - cancel_count,
  1806. // StockCancelCount: cancel_count,
  1807. // FlushCount: it.StockCount,
  1808. // StockActOutCount: act_count,
  1809. // }
  1810. // service.CreateGoodCountSix(good)
  1811. // }
  1812. // if errcode == nil {
  1813. // service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
  1814. // }
  1815. //}
  1816. this.ServeSuccessJSON(map[string]interface{}{
  1817. "msg": "1",
  1818. })
  1819. return
  1820. }
  1821. func (this *SecondaryOrderApiController) GetStoreHouseGoodList() {
  1822. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  1823. orgId := this.GetAdminUserInfo().CurrentOrgId
  1824. //获取药品库数据
  1825. baseList, _ := service.GetSupplyDrugListOne(orgId, storehouse_out_id)
  1826. goodList, _ := service.GetSupplyGoodListOne(orgId, storehouse_out_id)
  1827. goodTypeList, _ := service.GetAllGoodType(orgId)
  1828. configlist, _ := service.GetAllStoreHouseConfig(orgId)
  1829. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1830. var drugType = "药品类型"
  1831. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1832. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  1833. this.ServeSuccessJSON(map[string]interface{}{
  1834. "drugList": baseList,
  1835. "goodList": goodList,
  1836. "goodTypeList": goodTypeList,
  1837. "drugTypeList": drugTypeList,
  1838. "configlist": configlist,
  1839. "manufacturerList": manufacturerList,
  1840. })
  1841. return
  1842. }
  1843. func (this *SecondaryOrderApiController) GetSumSecondCount() {
  1844. project_id, _ := this.GetInt64("project_id")
  1845. sencond_unit := this.GetString("sencond_unit")
  1846. is_source, _ := this.GetInt64("is_source")
  1847. count, _ := this.GetInt64("count")
  1848. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  1849. orgId := this.GetAdminUserInfo().CurrentOrgId
  1850. var sum_in_count int64
  1851. var sum_count int64
  1852. //药品
  1853. if is_source == 1 {
  1854. medical, _ := service.GetBaseDrugMedical(project_id)
  1855. fmt.Println("senconde_unit233223", sencond_unit)
  1856. if sencond_unit == medical.MaxUnit {
  1857. sum_in_count = count * medical.MinNumber
  1858. }
  1859. if sencond_unit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1860. sum_in_count = count
  1861. }
  1862. //查询该药品剩余的库存
  1863. secondCountList, _ := service.GetDrugSumSecondCount(project_id, storehouse_out_id, orgId)
  1864. for _, it := range secondCountList {
  1865. if it.MaxUnit == medical.MaxUnit {
  1866. sum_count += (it.StockMaxNumber * medical.MinNumber) + it.StockMinNumber
  1867. }
  1868. if it.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1869. sum_count += (it.StockMaxNumber + it.StockMinNumber)
  1870. }
  1871. }
  1872. fmt.Println("sum_iin_coutn23232323", sum_in_count)
  1873. fmt.Println("sum_count", sum_count)
  1874. if sum_in_count > sum_count {
  1875. this.ServeSuccessJSON(map[string]interface{}{
  1876. "msg": "2",
  1877. })
  1878. return
  1879. } else {
  1880. this.ServeSuccessJSON(map[string]interface{}{
  1881. "msg": "1",
  1882. })
  1883. return
  1884. }
  1885. }
  1886. //耗材
  1887. if is_source == 2 {
  1888. var sum_good_count int64
  1889. secondCountGoodList, _ := service.GetGoodSumSecondCount(project_id, storehouse_out_id, orgId)
  1890. for _, it := range secondCountGoodList {
  1891. sum_good_count += it.StockCount
  1892. }
  1893. if count > sum_good_count {
  1894. this.ServeSuccessJSON(map[string]interface{}{
  1895. "msg": "2",
  1896. })
  1897. return
  1898. } else {
  1899. this.ServeSuccessJSON(map[string]interface{}{
  1900. "msg": "1",
  1901. })
  1902. return
  1903. }
  1904. }
  1905. }
  1906. func (this *SecondaryOrderApiController) DeleteSecondOrderInfo() {
  1907. id, _ := this.GetInt64("id")
  1908. err := service.DeleteSecondOrderInfo(id)
  1909. if err == nil {
  1910. returnData := make(map[string]interface{}, 0)
  1911. returnData["msg"] = "ok"
  1912. this.ServeSuccessJSON(returnData)
  1913. return
  1914. } else {
  1915. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1916. }
  1917. }
  1918. // 查询一条仓库信息
  1919. func (this *SecondaryOrderApiController) GetOneStorehouse() {
  1920. orgId := this.GetAdminUserInfo().CurrentOrgId
  1921. check := map[string][]string{
  1922. "id": {"must", "int", "id"},
  1923. }
  1924. _, err := checkParams(this, &check)
  1925. if err != nil {
  1926. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1927. return
  1928. }
  1929. id, _ := this.GetInt64("id")
  1930. var list models.Storehouse
  1931. list, err = service.GetOneStorehouse(id, orgId)
  1932. if err != nil {
  1933. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1934. return
  1935. }
  1936. this.ServeSuccessJSON(map[string]interface{}{
  1937. "list": list,
  1938. })
  1939. return
  1940. }
  1941. // 获取当前机构所有可用仓库的名字
  1942. func (this *SecondaryOrderApiController) GetAllStorehouseName() {
  1943. orgId := this.GetAdminUserInfo().CurrentOrgId
  1944. list, err := service.GetAllStorehouseName(orgId)
  1945. if err != nil {
  1946. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1947. return
  1948. }
  1949. this.ServeSuccessJSON(map[string]interface{}{
  1950. "list": list,
  1951. })
  1952. }
  1953. // 根据机构id查询仓库配置
  1954. func (this *SecondaryOrderApiController) FindStorehouseConfig() {
  1955. orgId := this.GetAdminUserInfo().CurrentOrgId
  1956. storehouse, err := service.FindStorehouseConfig(orgId)
  1957. //如果没有仓库配置信息就新建一个
  1958. if err == gorm.ErrRecordNotFound {
  1959. err := service.GetDefaultStorehouse(orgId)
  1960. if err != nil {
  1961. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1962. return
  1963. }
  1964. storehouse, err = service.FindStorehouseConfig(orgId)
  1965. if err != nil {
  1966. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1967. return
  1968. }
  1969. }
  1970. if err != nil && err.Error() != "record not found" {
  1971. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1972. return
  1973. }
  1974. var storehouse_info, storehouse_out_info, drug_storehouse_info, drug_storehouse_out models.Storehouse
  1975. storehouse_info, err = service.FindStorehouseName(storehouse.StorehouseInfo)
  1976. if err != nil {
  1977. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1978. return
  1979. }
  1980. storehouse_out_info, err = service.FindStorehouseName(storehouse.StorehouseOutInfo)
  1981. if err != nil {
  1982. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1983. return
  1984. }
  1985. drug_storehouse_info, err = service.FindStorehouseName(storehouse.DrugStorehouseInfo)
  1986. if err != nil {
  1987. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1988. return
  1989. }
  1990. drug_storehouse_out, err = service.FindStorehouseName(storehouse.DrugStorehouseOut)
  1991. if err != nil {
  1992. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1993. return
  1994. }
  1995. this.ServeSuccessJSON(map[string]interface{}{
  1996. "storehouse_info": storehouse_info.StorehouseName,
  1997. "storehouse_out_info": storehouse_out_info.StorehouseName,
  1998. "drug_storehouse_info": drug_storehouse_info.StorehouseName,
  1999. "drug_storehouse_out": drug_storehouse_out.StorehouseName,
  2000. })
  2001. return
  2002. }
  2003. // 更改耗材自动入库仓库
  2004. func (this *SecondaryOrderApiController) UpdateInfo() {
  2005. orgId := this.GetAdminUserInfo().CurrentOrgId
  2006. check := map[string][]string{
  2007. "id": {"must", "int", "id"},
  2008. }
  2009. _, err := checkParams(this, &check)
  2010. if err != nil {
  2011. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2012. return
  2013. }
  2014. id, _ := this.GetInt64("id")
  2015. err = service.UpdateInfo(orgId, id)
  2016. //查询默认仓库
  2017. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  2018. list, _ := service.GetAllGoodList(orgId)
  2019. for _, item := range list {
  2020. var sum_count int64
  2021. var sum_in_count int64
  2022. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ID, orgId)
  2023. for _, it := range goodList {
  2024. sum_count += it.StockCount
  2025. sum_in_count += it.WarehousingCount
  2026. }
  2027. service.UpdateGoodByGoodId(item.ID, sum_count, sum_in_count, orgId)
  2028. }
  2029. if err != nil {
  2030. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2031. return
  2032. }
  2033. this.ServeSuccessJSON(map[string]interface{}{
  2034. "list": "修改成功",
  2035. })
  2036. return
  2037. }
  2038. // 更改耗材自动出库仓库
  2039. func (this *SecondaryOrderApiController) UpdateOutInfo() {
  2040. orgId := this.GetAdminUserInfo().CurrentOrgId
  2041. check := map[string][]string{
  2042. "id": {"must", "int", "id"},
  2043. }
  2044. _, err := checkParams(this, &check)
  2045. if err != nil {
  2046. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2047. return
  2048. }
  2049. id, _ := this.GetInt64("id")
  2050. err = service.UpdateOutInfo(orgId, id)
  2051. //查询默认仓库
  2052. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  2053. list, _ := service.GetAllGoodList(orgId)
  2054. for _, item := range list {
  2055. var sum_count int64
  2056. var sum_in_count int64
  2057. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ID, orgId)
  2058. for _, it := range goodList {
  2059. sum_count += it.StockCount
  2060. sum_in_count += it.WarehousingCount
  2061. }
  2062. service.UpdateGoodByGoodId(item.ID, sum_count, sum_in_count, orgId)
  2063. }
  2064. if err != nil {
  2065. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2066. return
  2067. }
  2068. this.ServeSuccessJSON(map[string]interface{}{
  2069. "list": "修改成功",
  2070. })
  2071. return
  2072. }
  2073. // 更改药品自动入库仓库
  2074. func (this *SecondaryOrderApiController) UpdateDrugInfo() {
  2075. orgId := this.GetAdminUserInfo().CurrentOrgId
  2076. check := map[string][]string{
  2077. "id": {"must", "int", "id"},
  2078. }
  2079. _, err := checkParams(this, &check)
  2080. if err != nil {
  2081. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2082. return
  2083. }
  2084. id, _ := this.GetInt64("id")
  2085. err = service.UpdateDrugInfo2(orgId, id)
  2086. //查询默认仓库
  2087. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  2088. baseDrug, _ := service.GetAllBaseDrugList(orgId)
  2089. for _, item := range baseDrug {
  2090. var sum_drug_count int64
  2091. var sum_drug_in_count int64
  2092. //查询默认仓库剩余多少库存
  2093. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ID)
  2094. for _, it := range list {
  2095. if it.MaxUnit == item.MaxUnit {
  2096. it.StockMaxNumber = it.StockMaxNumber * item.MinNumber
  2097. it.WarehousingCount = it.WarehousingCount * item.MinNumber
  2098. }
  2099. sum_drug_count += it.StockMaxNumber + it.StockMinNumber
  2100. sum_drug_in_count += it.WarehousingCount
  2101. }
  2102. service.UpdateMedicalSumCount(item.ID, sum_drug_count, sum_drug_in_count, orgId)
  2103. }
  2104. if err != nil {
  2105. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2106. return
  2107. }
  2108. this.ServeSuccessJSON(map[string]interface{}{
  2109. "list": "修改成功",
  2110. })
  2111. return
  2112. }
  2113. // 更改药品自动出库仓库
  2114. func (this *SecondaryOrderApiController) UpdateDrugOut() {
  2115. orgId := this.GetAdminUserInfo().CurrentOrgId
  2116. check := map[string][]string{
  2117. "id": {"must", "int", "id"},
  2118. }
  2119. _, err := checkParams(this, &check)
  2120. if err != nil {
  2121. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2122. return
  2123. }
  2124. id, _ := this.GetInt64("id")
  2125. err = service.UpdateDrugOut(orgId, id)
  2126. //查询默认仓库
  2127. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  2128. baseDrug, _ := service.GetAllBaseDrugList(orgId)
  2129. for _, item := range baseDrug {
  2130. var sum_drug_count int64
  2131. var sum_drug_in_count int64
  2132. //查询默认仓库剩余多少库存
  2133. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ID)
  2134. for _, it := range list {
  2135. if it.MaxUnit == item.MaxUnit {
  2136. it.StockMaxNumber = it.StockMaxNumber * item.MinNumber
  2137. it.WarehousingCount = it.WarehousingCount * item.MinNumber
  2138. }
  2139. sum_drug_count += it.StockMaxNumber + it.StockMinNumber
  2140. sum_drug_in_count += it.WarehousingCount
  2141. }
  2142. service.UpdateMedicalSumCount(item.ID, sum_drug_count, sum_drug_in_count, orgId)
  2143. }
  2144. if err != nil {
  2145. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2146. return
  2147. }
  2148. this.ServeSuccessJSON(map[string]interface{}{
  2149. "list": "修改成功",
  2150. })
  2151. return
  2152. }
  2153. // 判断前端参数是否为空
  2154. func checkParams(this *SecondaryOrderApiController, m *map[string][]string) (map[string]string, error) {
  2155. tmp := make(map[string]string)
  2156. for k, v := range *m {
  2157. t := this.GetString(k)
  2158. if v[0] == "must" && t == "" {
  2159. return nil, fmt.Errorf(v[2] + "不能为空")
  2160. }
  2161. tmp[k] = t
  2162. }
  2163. return tmp, nil
  2164. }
  2165. // 兼容旧数据
  2166. func (this *SecondaryOrderApiController) Byliinit() {
  2167. err := service.Byliinit()
  2168. if err != nil {
  2169. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  2170. return
  2171. }
  2172. this.ServeSuccessJSON(map[string]interface{}{
  2173. "list": "初始化成功",
  2174. })
  2175. return
  2176. }
  2177. // 查询机构所属管理员
  2178. func (this *SecondaryOrderApiController) GetuserName() {
  2179. adminUserInfo := this.GetAdminUserInfo()
  2180. viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  2181. //viewModels, _, _ := service.GetAdminUsersAndLoginInfo(10164, 12123, 1, 100)
  2182. c, _ := service.Getcreateid(adminUserInfo.CurrentOrgId)
  2183. //c, _ := service.Getcreateid(10164)
  2184. admin := []*service.AdminUserManageViewModel{} //记录当前管理员的信息
  2185. //去除禁用的角色
  2186. tmp := []*service.AdminUserManageViewModel{}
  2187. for i := 0; i < len(viewModels); i++ {
  2188. if viewModels[i].Status == 1 {
  2189. tmp = append(tmp, viewModels[i])
  2190. }
  2191. if int64(viewModels[i].AdminUserId) == c.Creator {
  2192. admin = append(admin, viewModels[i])
  2193. }
  2194. }
  2195. roles := service.FindRoles(adminUserInfo.CurrentOrgId)
  2196. //roles := service.FindRoles(10164)
  2197. //去除没有权限的角色
  2198. tmplist := []*service.AdminUserManageViewModel{}
  2199. if roles == nil || len(roles) == 0 {
  2200. this.ServeSuccessJSON(map[string]interface{}{
  2201. "list": admin,
  2202. })
  2203. return
  2204. }
  2205. for i := 0; i < len(tmp); i++ {
  2206. boolean := false
  2207. //获取并解析当前用户的角色
  2208. tmproles := strings.Split(tmp[i].RoleIds, ",")
  2209. for j := 0; j < len(tmproles); j++ {
  2210. //判断这些角色是否有权限
  2211. if _, ok := roles[tmproles[j]]; ok {
  2212. boolean = true
  2213. }
  2214. }
  2215. if boolean {
  2216. tmplist = append(tmplist, tmp[i])
  2217. }
  2218. }
  2219. isappend := true //判断结果中是否添加机构创建者,true添加,false不添加
  2220. if len(tmplist) > 0 {
  2221. for i := 0; i < len(tmplist); i++ {
  2222. if int64(tmplist[i].AdminUserId) == c.Creator {
  2223. isappend = false
  2224. }
  2225. }
  2226. }
  2227. if isappend {
  2228. tmplist = append(tmplist, admin...)
  2229. }
  2230. this.ServeSuccessJSON(map[string]interface{}{
  2231. "list": tmplist,
  2232. })
  2233. return
  2234. }
  2235. func (this *SecondaryOrderApiController) GetCreaterId() {
  2236. creater := this.GetAdminUserInfo().AdminUser.Id
  2237. this.ServeSuccessJSON(map[string]interface{}{
  2238. "list": creater,
  2239. })
  2240. }