secondary_order_api_contorller.go 84KB

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