secondary_order_api_contorller.go 67KB

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