secondary_order_api_contorller.go 67KB

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