secondary_order_api_contorller.go 84KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485
  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. medical_insurance_number := items["medical_insurance_number"].(string)
  561. info := &models.XtSecondWarehouseInfo{
  562. ProjectName: project_name,
  563. SecondSpecificationName: second_specification_name,
  564. ProjectType: project_type,
  565. SencondUnit: sencond_unit,
  566. Count: count,
  567. SecondTotal: second_total,
  568. SecondOrderNumber: secondWarehouse.SecondOrderNumber,
  569. RecordDate: record_date,
  570. StorehouseInId: storehouse_in_id,
  571. StorehouseOutId: storehouse_out_id,
  572. Creater: creater,
  573. ProjectId: project_id,
  574. Remake: remake,
  575. UserOrgId: orgId,
  576. Status: 1,
  577. Ctime: time.Now().Unix(),
  578. Mtime: 0,
  579. MinPrice: min_price,
  580. IsSource: is_source,
  581. WarehouseId: secondWarehouse.ID,
  582. MedicalInsuranceNumber: medical_insurance_number,
  583. }
  584. warehousingInfo = append(warehousingInfo, info)
  585. }
  586. }
  587. }
  588. for _, item := range warehousingInfo {
  589. service.CreateSencondWarehousingInfo(item)
  590. }
  591. //获取最后一条入库单
  592. lastSecondWarehouse, _ := service.GetLastSecondWarehouse(orgId)
  593. this.ServeSuccessJSON(map[string]interface{}{
  594. "warehousingInfo": warehousingInfo,
  595. "id": lastSecondWarehouse.ID,
  596. })
  597. return
  598. }
  599. func (this *SecondaryOrderApiController) GetAllSecondeOrderList() {
  600. check_id, _ := this.GetInt64("check_id")
  601. start_time := this.GetString("start_time")
  602. timeLayout := "2006-01-02"
  603. loc, _ := time.LoadLocation("Local")
  604. var startTime int64
  605. if len(start_time) > 0 {
  606. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  607. if err != nil {
  608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  609. return
  610. }
  611. startTime = theTime.Unix()
  612. }
  613. end_time := this.GetString("end_time")
  614. var endTime int64
  615. if len(end_time) > 0 {
  616. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  617. if err != nil {
  618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. endTime = theTime.Unix()
  622. }
  623. keyword := this.GetString("keyword")
  624. page, _ := this.GetInt64("page")
  625. limit, _ := this.GetInt64("limit")
  626. orgId := this.GetAdminUserInfo().CurrentOrgId
  627. list, total, _ := service.GetAllSecondeOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
  628. houseList, _ := service.GetAllStoreHouseList(orgId)
  629. appId := this.GetAdminUserInfo().CurrentAppId
  630. doctor, _ := service.GetAllDoctorListSix(orgId, appId)
  631. this.ServeSuccessJSON(map[string]interface{}{
  632. "list": list,
  633. "total": total,
  634. "houseList": houseList,
  635. "doctorList": doctor,
  636. })
  637. return
  638. }
  639. func (this *SecondaryOrderApiController) GetSencondOrderDetail() {
  640. id, _ := this.GetInt64("id")
  641. orgId := this.GetAdminUserInfo().CurrentOrgId
  642. warehouse, _ := service.GetSecondWarehouseOrderById(id)
  643. //获取药品库数据
  644. baseList, _ := service.GetSupplyDrugListOne(orgId, warehouse.StorehouseOutId)
  645. goodList, _ := service.GetSupplyGoodListOne(orgId, warehouse.StorehouseOutId)
  646. goodTypeList, _ := service.GetAllGoodType(orgId)
  647. configlist, _ := service.GetAllStoreHouseConfig(orgId)
  648. var drugType = "药品类型"
  649. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  650. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  651. list, _ := service.GetSencondOrderDetail(id, orgId)
  652. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  653. this.ServeSuccessJSON(map[string]interface{}{
  654. "list": list,
  655. "warehouse": warehouse,
  656. "drugList": baseList,
  657. "goodList": goodList,
  658. "goodTypeList": goodTypeList,
  659. "drugTypeList": drugTypeList,
  660. "configlist": configlist,
  661. "manufacturerList": manufacturerList,
  662. })
  663. return
  664. }
  665. func (this *SecondaryOrderApiController) UpdateSencondOrder() {
  666. warehouse_id, _ := this.GetInt64("id")
  667. start_date := this.GetString("record_date")
  668. storehouse_in_id, _ := this.GetInt64("storehouse_in_id")
  669. storehouse_out_id, _ := this.GetInt64("storehouse_out_id")
  670. fmt.Println(storehouse_in_id, storehouse_out_id)
  671. timeLayout := "2006-01-02"
  672. loc, _ := time.LoadLocation("Local")
  673. var startDate int64
  674. if len(start_date) > 0 {
  675. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  676. if err != nil {
  677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  678. return
  679. }
  680. startDate = theTime.Unix()
  681. }
  682. recordDateStr := time.Now().Format("2006-01-02")
  683. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  684. record_date := recordDate.Unix()
  685. orgId := this.GetAdminUserInfo().CurrentOrgId
  686. creater := this.GetAdminUserInfo().AdminUser.Id
  687. warehouse := models.XtSecondWarehouse{
  688. StorehouseInId: storehouse_in_id,
  689. StorehouseOutId: storehouse_out_id,
  690. RecordDate: startDate,
  691. }
  692. service.UpdateModifySecondWarehouse(warehouse_id, warehouse)
  693. warehouseInfo, _ := service.GetSecondWarehouseOrderById(warehouse_id)
  694. var warehousingInfo []*models.XtSecondWarehouseInfo
  695. var updateWarehousingInfo []*models.XtSecondWarehouseInfo
  696. dataBody := make(map[string]interface{}, 0)
  697. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  698. if err != nil {
  699. utils.ErrorLog(err.Error())
  700. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  701. return
  702. }
  703. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  704. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  705. if len(thisStockIn) > 0 {
  706. for _, item := range thisStockIn {
  707. items := item.(map[string]interface{})
  708. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  709. utils.ErrorLog("id")
  710. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  711. return
  712. }
  713. id := int64(items["id"].(float64))
  714. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  715. utils.ErrorLog("project_id")
  716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  717. return
  718. }
  719. project_id := int64(items["project_id"].(float64))
  720. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  721. utils.ErrorLog("name")
  722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  723. return
  724. }
  725. project_name := items["name"].(string)
  726. if items["project_type"] == nil || reflect.TypeOf(items["project_type"]).String() != "string" {
  727. utils.ErrorLog("project_type")
  728. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  729. return
  730. }
  731. project_type := items["project_type"].(string)
  732. if items["second_specification_name"] == nil || reflect.TypeOf(items["second_specification_name"]).String() != "string" {
  733. utils.ErrorLog("second_specification_name")
  734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  735. return
  736. }
  737. second_specification_name := items["second_specification_name"].(string)
  738. if items["sencond_unit"] == nil || reflect.TypeOf(items["sencond_unit"]).String() != "string" {
  739. utils.ErrorLog("sencond_unit")
  740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. sencond_unit := items["sencond_unit"].(string)
  744. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  745. utils.ErrorLog("count")
  746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  747. return
  748. }
  749. count := int64(items["count"].(float64))
  750. if items["is_source"] == nil || reflect.TypeOf(items["is_source"]).String() != "float64" {
  751. utils.ErrorLog("is_source")
  752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  753. return
  754. }
  755. is_source := int64(items["is_source"].(float64))
  756. if items["second_total"] == nil || reflect.TypeOf(items["second_total"]).String() != "string" {
  757. utils.ErrorLog("second_total")
  758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  759. return
  760. }
  761. second_total := items["second_total"].(string)
  762. if items["remake"] == nil || reflect.TypeOf(items["remake"]).String() != "string" {
  763. utils.ErrorLog("remake")
  764. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  765. return
  766. }
  767. remake := items["remake"].(string)
  768. if items["min_price"] == nil || reflect.TypeOf(items["min_price"]).String() != "float64" {
  769. utils.ErrorLog("min_price")
  770. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  771. return
  772. }
  773. min_price := items["min_price"].(float64)
  774. if id == 0 {
  775. info := &models.XtSecondWarehouseInfo{
  776. ProjectName: project_name,
  777. SecondSpecificationName: second_specification_name,
  778. ProjectType: project_type,
  779. SencondUnit: sencond_unit,
  780. Count: count,
  781. SecondTotal: second_total,
  782. RecordDate: record_date,
  783. StorehouseInId: storehouse_in_id,
  784. StorehouseOutId: storehouse_out_id,
  785. Creater: creater,
  786. ProjectId: project_id,
  787. Remake: remake,
  788. UserOrgId: orgId,
  789. Status: 1,
  790. Ctime: time.Now().Unix(),
  791. Mtime: 0,
  792. MinPrice: min_price,
  793. IsSource: is_source,
  794. WarehouseId: warehouse_id,
  795. SecondOrderNumber: warehouseInfo.SecondOrderNumber,
  796. }
  797. warehousingInfo = append(warehousingInfo, info)
  798. }
  799. if id > 0 {
  800. updateInfo := &models.XtSecondWarehouseInfo{
  801. ID: id,
  802. ProjectName: project_name,
  803. SecondSpecificationName: second_specification_name,
  804. ProjectType: project_type,
  805. SencondUnit: sencond_unit,
  806. Count: count,
  807. SecondTotal: second_total,
  808. SecondOrderNumber: warehouse.SecondOrderNumber,
  809. RecordDate: record_date,
  810. StorehouseInId: storehouse_in_id,
  811. StorehouseOutId: storehouse_out_id,
  812. Creater: creater,
  813. ProjectId: project_id,
  814. Remake: remake,
  815. UserOrgId: orgId,
  816. MinPrice: min_price,
  817. IsSource: is_source,
  818. }
  819. updateWarehousingInfo = append(updateWarehousingInfo, updateInfo)
  820. }
  821. }
  822. }
  823. }
  824. for _, item := range warehousingInfo {
  825. service.CreateSencondWarehousingInfo(item)
  826. }
  827. for _, item := range updateWarehousingInfo {
  828. service.UpdateStoreWarehousing(item)
  829. }
  830. this.ServeSuccessJSON(map[string]interface{}{
  831. "warehousingInfo": warehousingInfo,
  832. })
  833. return
  834. }
  835. func (this *SecondaryOrderApiController) GetSecondOrderById() {
  836. id, _ := this.GetInt64("id")
  837. orgId := this.GetAdminUserInfo().CurrentOrgId
  838. warehouse, _ := service.GetSecondWarehouseOrderById(id)
  839. list, _ := service.GetSencondOrderDetail(id, orgId)
  840. appId := this.GetAdminUserInfo().CurrentAppId
  841. doctor, _ := service.GetAllDoctorSix(orgId, appId)
  842. houseList, _ := service.GetAllStoreHouseList(orgId)
  843. this.ServeSuccessJSON(map[string]interface{}{
  844. "warehouse": warehouse,
  845. "list": list,
  846. "doctorList": doctor,
  847. "houseList": houseList,
  848. })
  849. return
  850. }
  851. func (this *SecondaryOrderApiController) CheckSecondOrer() {
  852. ids := this.GetString("ids")
  853. if len(ids) == 0 {
  854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  855. return
  856. }
  857. idArray := strings.Split(ids, ",")
  858. orgId := this.GetAdminUserInfo().CurrentOrgId
  859. creater := this.GetAdminUserInfo().AdminUser.Id
  860. //根据订单id获取商品详情
  861. list, _ := service.GetSecondOrderList(idArray, orgId)
  862. for _, item := range list {
  863. if item.IsSource == 1 {
  864. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  865. //查询该仓库的药品库存是否满足调出数量
  866. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  867. var total int64
  868. var total_count int64
  869. for _, it := range drugInfoList {
  870. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  871. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  872. }
  873. }
  874. for _, it := range drugInfoList {
  875. total += it.StockMaxNumber + it.StockMinNumber
  876. }
  877. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  878. total_count = item.Count * medical.MinNumber
  879. }
  880. if item.SencondUnit == medical.MinUnit {
  881. total_count = item.Count
  882. }
  883. if total_count > total {
  884. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  885. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseOutId, item.UserOrgId)
  886. this.ServeSuccessJSON(map[string]interface{}{
  887. "msg": "3",
  888. "drug_name": goodObj.DrugName,
  889. "dose": goodObj.Dose,
  890. "dose_unit": goodObj.DoseUnit,
  891. "min_number": goodObj.MinNumber,
  892. "min_unit": goodObj.MinUnit,
  893. "max_unit": goodObj.MaxUnit,
  894. "storehose_name": storehouse.StorehouseName,
  895. })
  896. return
  897. }
  898. }
  899. if item.IsSource == 2 {
  900. //查询该仓库的耗材库存是否满足调出数量
  901. var total int64
  902. infoList, _ := service.GetWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  903. for _, it := range infoList {
  904. total += it.StockCount
  905. }
  906. if item.Count > total {
  907. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseOutId, item.UserOrgId)
  908. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  909. this.ServeSuccessJSON(map[string]interface{}{
  910. "msg": "2",
  911. "good_name": goodObj.GoodName,
  912. "specification_name": goodObj.SpecificationName,
  913. "storehose_name": storehouse.StorehouseName,
  914. })
  915. return
  916. }
  917. }
  918. }
  919. err := service.UpdateStoreOrderByArray(idArray, orgId, creater)
  920. //如果审核成功
  921. if err == nil {
  922. //调用出库接口
  923. timeStr := time.Now().Format("2006-01-02")
  924. timeArr := strings.Split(timeStr, "-")
  925. total, _ := service.FindAllWarehouseOut(orgId)
  926. total = total + 1
  927. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  928. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  929. number = number + total
  930. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  931. operation_time := time.Now().Unix()
  932. creater := this.GetAdminUserInfo().AdminUser.Id
  933. recordDateStr := time.Now().Format("2006-01-02")
  934. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  935. record_date := recordDate.Unix()
  936. totals, _ := service.FindAllWarehouseTotal(orgId)
  937. totals = totals + 1
  938. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(totals, 10)
  939. for _, item := range list {
  940. //药品
  941. if item.IsSource == 1 {
  942. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  943. //查询该仓库的药品库存是否满足调出数量
  944. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  945. var total int64
  946. var total_count int64
  947. for _, it := range drugInfoList {
  948. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  949. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  950. }
  951. }
  952. for _, it := range drugInfoList {
  953. total += it.StockMaxNumber + it.StockMinNumber
  954. }
  955. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  956. total_count = item.Count * medical.MinNumber
  957. }
  958. if item.SencondUnit == medical.MinUnit {
  959. total_count = item.Count
  960. }
  961. if total_count <= total {
  962. drug_total, _ := service.FindAllDrugWarehouseOut(orgId)
  963. drug_total = drug_total + 1
  964. drug_warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  965. number, _ := strconv.ParseInt(drug_warehousing_out_order, 10, 64)
  966. number = number + drug_total
  967. drug_warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  968. operation_time := time.Now().Unix()
  969. drugWarehouseOut := models.DrugWarehouseOut{
  970. WarehouseOutOrderNumber: drug_warehousing_out_order,
  971. OperationTime: operation_time,
  972. OrgId: orgId,
  973. Creater: creater,
  974. Ctime: time.Now().Unix(),
  975. Status: 1,
  976. WarehouseOutTime: record_date,
  977. Type: 2,
  978. StorehouseId: item.StorehouseOutId,
  979. SecondWarehouseId: item.WarehouseId,
  980. IsSys: 12,
  981. IsCheck: 1,
  982. }
  983. _, drugerrcodes := service.GetDrugWarehouseBySyS(orgId, 12, item.WarehouseId, record_date)
  984. if drugerrcodes == gorm.ErrRecordNotFound {
  985. service.AddSigleDrugWarehouseOut(&drugWarehouseOut)
  986. }
  987. drugOut, _ := service.GetLastDrugWarehouseOutById(12, item.WarehouseId, orgId, record_date)
  988. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  989. WarehouseOutOrderNumber: drugOut.WarehouseOutOrderNumber,
  990. WarehouseOutId: drugOut.ID,
  991. DrugId: item.ProjectId,
  992. Count: item.Count,
  993. Price: medical.RetailPrice,
  994. TotalPrice: 0,
  995. Status: 1,
  996. Ctime: time.Now().Unix(),
  997. Remark: item.Remake,
  998. OrgId: orgId,
  999. Type: 2,
  1000. Manufacturer: 0,
  1001. Dealer: 0,
  1002. RetailPrice: item.MinPrice,
  1003. RetailTotalPrice: 0,
  1004. CountUnit: item.SencondUnit,
  1005. ExpiryDate: 0,
  1006. ProductDate: 0,
  1007. Number: "",
  1008. BatchNumber: "",
  1009. IsSys: 0,
  1010. WarehouseInfoId: 0,
  1011. StorehouseId: item.StorehouseOutId,
  1012. SecondWarehouseInfoId: item.ID,
  1013. IsCheck: 1,
  1014. }
  1015. drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
  1016. drug_in_total, _ := service.FindAllWarehouseTotalOne(orgId)
  1017. drug_in_total = drug_in_total + 1
  1018. warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(drug_in_total, 10)
  1019. drug_warehousing := models.DrugWarehouse{
  1020. WarehousingOrder: warehousing_order,
  1021. OperationTime: operation_time,
  1022. OrgId: orgId,
  1023. Creater: creater,
  1024. Ctime: time.Now().Unix(),
  1025. Status: 1,
  1026. WarehousingTime: record_date,
  1027. Type: 1,
  1028. StorehouseId: item.StorehouseInId,
  1029. IsSys: 13,
  1030. SecondWarehouseId: item.WarehouseId,
  1031. IsCheck: 1,
  1032. }
  1033. //查询该调拨单是否有生成入库单
  1034. _, drugerrcodess := service.GetDrugWarehouseingBySys(13, item.WarehouseId, orgId, record_date)
  1035. if drugerrcodess == gorm.ErrRecordNotFound {
  1036. service.CreateDrugWaresing(drug_warehousing)
  1037. }
  1038. drugInfoObj, _ := service.GetLastDrugWarehouseBySys(13, item.WarehouseId, orgId, record_date)
  1039. drugwarehouseInfo := &models.DrugWarehouseInfo{
  1040. WarehousingOrder: drugInfoObj.WarehousingOrder,
  1041. WarehousingId: drugInfoObj.ID,
  1042. DrugId: item.ProjectId,
  1043. Number: "",
  1044. ProductDate: 0,
  1045. ExpiryDate: 0,
  1046. WarehousingCount: 0,
  1047. Price: 0,
  1048. TotalPrice: 0,
  1049. Status: 1,
  1050. Ctime: time.Now().Unix(),
  1051. Remark: "",
  1052. OrgId: orgId,
  1053. Type: 2,
  1054. Manufacturer: 0,
  1055. Dealer: 0,
  1056. StockMaxNumber: 0,
  1057. RetailTotalPrice: 0,
  1058. BatchNumber: "",
  1059. MaxUnit: "",
  1060. MinUnit: "",
  1061. RetailPrice: 0,
  1062. StorehouseId: item.StorehouseInId,
  1063. SecondWarehouseInfoId: item.ID,
  1064. IsCheck: 1,
  1065. }
  1066. service.AutoDrugDeliverInfoTwelve(orgId, item.Count, &drugWarehouseOut, &drup, warehouseOutInfo, drugwarehouseInfo)
  1067. //查询默认仓库
  1068. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1069. //更新字典里面的库存
  1070. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
  1071. var sum_count int64
  1072. for _, its := range stockInfo {
  1073. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1074. if its.MaxUnit == baseDrug.MaxUnit {
  1075. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1076. }
  1077. sum_count += its.StockMaxNumber + its.StockMinNumber
  1078. }
  1079. service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
  1080. }
  1081. //查询该药品该仓库是否有数据
  1082. drug, _ := service.GetDrugStockCout(item.ProjectId, item.StorehouseInId, item.UserOrgId)
  1083. var sum_out_count int64
  1084. baseDrug, _ := service.GetBaseDrugMedical(item.ProjectId)
  1085. if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
  1086. sum_out_count = item.Count * baseDrug.MinNumber
  1087. }
  1088. if item.SencondUnit == baseDrug.MinUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
  1089. sum_out_count = item.Count
  1090. }
  1091. if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit == baseDrug.MinUnit {
  1092. sum_out_count = item.Count
  1093. }
  1094. if drug.ID == 0 {
  1095. drugstock := models.XtDrugStockCount{
  1096. UserOrgId: orgId,
  1097. StorehouseId: item.StorehouseInId,
  1098. SumInCount: sum_out_count,
  1099. SumOutCount: 0,
  1100. SumCancelCount: 0,
  1101. DrugId: item.ProjectId,
  1102. Ctime: time.Now().Unix(),
  1103. Mtime: 0,
  1104. Status: 1,
  1105. FlushCount: sum_out_count,
  1106. SumActOutCount: 0,
  1107. }
  1108. service.CreateDrugStockCount(drugstock)
  1109. }
  1110. if drug.ID > 0 {
  1111. service.AddDrugStockCount(item.StorehouseInId, item.ProjectId, item.UserOrgId, sum_out_count)
  1112. }
  1113. //更新出库数据
  1114. service.ReduceDrugStockCountSix(item.StorehouseOutId, item.ProjectId, item.UserOrgId, sum_out_count)
  1115. }
  1116. //耗材
  1117. if item.IsSource == 2 {
  1118. //查询该仓库的耗材库存是否满足调出数量
  1119. var total int64
  1120. infoList, _ := service.GetWarehouseInfoByStoreHouseId(item.ProjectId, item.StorehouseOutId, item.UserOrgId)
  1121. for _, it := range infoList {
  1122. total += it.StockCount
  1123. }
  1124. //满足调拨
  1125. if item.Count <= total {
  1126. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1127. warehouseOut := models.WarehouseOut{
  1128. WarehouseOutOrderNumber: warehousing_out_order,
  1129. OperationTime: operation_time,
  1130. OrgId: orgId,
  1131. Creater: creater,
  1132. Ctime: time.Now().Unix(),
  1133. Status: 1,
  1134. WarehouseOutTime: record_date,
  1135. Type: 1,
  1136. StorehouseId: item.StorehouseOutId,
  1137. IsSys: 12,
  1138. SecondWarehouseId: item.WarehouseId,
  1139. IsCheck: 1,
  1140. }
  1141. //查询今日是否存在调拨出库
  1142. _, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
  1143. if errcodes == gorm.ErrRecordNotFound {
  1144. service.AddSigleWarehouseOut(&warehouseOut)
  1145. }
  1146. out, _ := service.GetLastWarehouseOutBySys(12, orgId, record_date, item.WarehouseId)
  1147. warehouseOutInfo := &models.WarehouseOutInfo{
  1148. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1149. WarehouseOutId: out.ID,
  1150. GoodId: item.ProjectId,
  1151. GoodTypeId: goodObj.GoodTypeId,
  1152. Count: item.Count,
  1153. Price: item.MinPrice,
  1154. TotalPrice: 0,
  1155. Status: 1,
  1156. Ctime: time.Now().Unix(),
  1157. Remark: item.Remake,
  1158. OrgId: orgId,
  1159. Type: 1,
  1160. Manufacturer: 0,
  1161. Number: "",
  1162. ExpiryDate: 0,
  1163. ProductDate: 0,
  1164. Dealer: 0,
  1165. LicenseNumber: "",
  1166. WarehouseInfotId: 0,
  1167. StorehouseId: item.StorehouseOutId,
  1168. SecondWarehouseInfoId: item.ID,
  1169. IsCheck: 1,
  1170. }
  1171. //入库操作
  1172. warehousing := models.Warehousing{
  1173. WarehousingOrder: warehousing_order,
  1174. OperationTime: operation_time,
  1175. OrgId: orgId,
  1176. Creater: creater,
  1177. Ctime: time.Now().Unix(),
  1178. Status: 1,
  1179. WarehousingTime: record_date,
  1180. Type: 1,
  1181. StorehouseId: item.StorehouseInId,
  1182. IsSys: 12,
  1183. SecondWarehouseId: item.WarehouseId,
  1184. IsCheck: 1,
  1185. }
  1186. //查询该调拨单是否有生成入库单
  1187. _, errcodess := service.GetWarehouseBySecondWarehouseId(12, item.WarehouseId, orgId, record_date)
  1188. if errcodess == gorm.ErrRecordNotFound {
  1189. service.AddSigleWarehouse(&warehousing)
  1190. }
  1191. infoObj, _ := service.GetLastWarehouseById(12, item.WarehouseId, orgId, record_date)
  1192. warehouseInfo := &models.WarehousingInfo{
  1193. WarehousingOrder: infoObj.WarehousingOrder,
  1194. WarehousingId: infoObj.ID,
  1195. GoodId: item.ProjectId,
  1196. Number: "",
  1197. GoodTypeId: goodObj.GoodTypeId,
  1198. ProductDate: 0,
  1199. ExpiryDate: 0,
  1200. WarehousingCount: item.Count,
  1201. Price: goodObj.BuyPrice,
  1202. TotalPrice: 0,
  1203. Status: 1,
  1204. Ctime: time.Now().Unix(),
  1205. Remark: item.Remake,
  1206. OrgId: orgId,
  1207. Type: 1,
  1208. Manufacturer: 0,
  1209. StockCount: item.Count,
  1210. Dealer: 0,
  1211. LicenseNumber: "",
  1212. PackingPrice: item.MinPrice,
  1213. StorehouseId: item.StorehouseInId,
  1214. SecondWarehouseInfoId: item.ID,
  1215. IsCheck: 1,
  1216. }
  1217. //出库逻辑
  1218. parseDateErr := service.ConsumablesDeliveryTwelve(orgId, record_date, warehouseOutInfo, &warehouseOut, item.Count, creater, warehouseInfo)
  1219. fmt.Println(parseDateErr)
  1220. }
  1221. //查询默认仓库
  1222. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1223. stockList, _ := service.GetStockCountByGoodId(item.ProjectId, storeHouseConfig.StorehouseOutInfo, orgId)
  1224. var total_count int64
  1225. for _, it := range stockList {
  1226. total_count += it.StockCount
  1227. }
  1228. //基础库插入数据
  1229. service.UpdateGoodInfoSumCountSix(item.ProjectId, total_count, orgId)
  1230. //查询是否有数据
  1231. _, errcodes := service.GetStockFlush(item.StorehouseInId, item.ProjectId, item.UserOrgId)
  1232. if errcodes == gorm.ErrRecordNotFound {
  1233. good := models.XtGoodStockCount{
  1234. UserOrgId: item.UserOrgId,
  1235. GoodId: item.ProjectId,
  1236. StorehouseId: item.StorehouseInId,
  1237. Status: 1,
  1238. Ctime: time.Now().Unix(),
  1239. Mtime: 0,
  1240. StockInCount: item.Count,
  1241. StockOutCount: 0,
  1242. StockCancelCount: 0,
  1243. FlushCount: item.Count,
  1244. StockActOutCount: 0,
  1245. }
  1246. service.CreateGoodCountSix(good)
  1247. } else if errcodes == nil {
  1248. service.AddGoodStockCount(item.StorehouseInId, item.ProjectId, item.UserOrgId, item.Count)
  1249. }
  1250. //更新出库数据
  1251. service.ReduceStockCount(item.StorehouseOutId, item.ProjectId, item.UserOrgId, item.Count)
  1252. }
  1253. }
  1254. }
  1255. this.ServeSuccessJSON(map[string]interface{}{
  1256. "msg": 1,
  1257. })
  1258. return
  1259. }
  1260. func (this *SecondaryOrderApiController) DeleteStorehouseList() {
  1261. id, _ := this.GetInt64("id")
  1262. err := service.DeleteStorehouseList(id)
  1263. if err == nil {
  1264. returnData := make(map[string]interface{}, 0)
  1265. returnData["msg"] = "ok"
  1266. this.ServeSuccessJSON(returnData)
  1267. return
  1268. } else {
  1269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1270. }
  1271. }
  1272. func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
  1273. ids := this.GetString("ids")
  1274. if len(ids) == 0 {
  1275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1276. return
  1277. }
  1278. idArray := strings.Split(ids, ",")
  1279. orgId := this.GetAdminUserInfo().CurrentOrgId
  1280. //根据订单id获取商品详情
  1281. list, _ := service.GetSecondOrderList(idArray, orgId)
  1282. //药品
  1283. for _, item := range list {
  1284. //药品
  1285. if item.IsSource == 1 {
  1286. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1287. //查询该仓库的药品库存是否满足调出数量
  1288. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1289. var total int64
  1290. var total_count int64
  1291. for _, it := range drugInfoList {
  1292. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1293. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1294. }
  1295. }
  1296. for _, it := range drugInfoList {
  1297. total += it.StockMaxNumber + it.StockMinNumber
  1298. }
  1299. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1300. total_count = item.Count * medical.MinNumber
  1301. }
  1302. if item.SencondUnit == medical.MinUnit {
  1303. total_count = item.Count
  1304. }
  1305. if total_count > total {
  1306. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  1307. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
  1308. this.ServeSuccessJSON(map[string]interface{}{
  1309. "msg": "3",
  1310. "drug_name": goodObj.DrugName,
  1311. "dose": goodObj.Dose,
  1312. "dose_unit": goodObj.DoseUnit,
  1313. "min_number": goodObj.MinNumber,
  1314. "min_unit": goodObj.MinUnit,
  1315. "max_unit": goodObj.MaxUnit,
  1316. "storehose_name": storehouse.StorehouseName,
  1317. })
  1318. return
  1319. }
  1320. }
  1321. //耗材
  1322. if item.IsSource == 2 {
  1323. //查询该仓库的耗材库存是否满足调出数量
  1324. var total int64
  1325. infoList, _ := service.GetWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1326. for _, it := range infoList {
  1327. total += it.StockCount
  1328. }
  1329. if item.Count > total {
  1330. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
  1331. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1332. this.ServeSuccessJSON(map[string]interface{}{
  1333. "msg": "2",
  1334. "good_name": goodObj.GoodName,
  1335. "specification_name": goodObj.SpecificationName,
  1336. "storehose_name": storehouse.StorehouseName,
  1337. })
  1338. return
  1339. }
  1340. }
  1341. }
  1342. //反审核操作
  1343. err := service.ModifyStoreHouseById(idArray, orgId)
  1344. if err != nil {
  1345. this.ServeSuccessJSON(map[string]interface{}{
  1346. "msg": "0",
  1347. })
  1348. return
  1349. }
  1350. for _, item := range list {
  1351. //药品
  1352. if item.IsSource == 1 {
  1353. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  1354. //查询该仓库的药品库存是否满足调出数量
  1355. drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1356. var total int64
  1357. var total_count int64
  1358. for _, it := range drugInfoList {
  1359. if medical.MaxUnit == it.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1360. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  1361. }
  1362. }
  1363. for _, it := range drugInfoList {
  1364. total += it.StockMaxNumber + it.StockMinNumber
  1365. }
  1366. if item.SencondUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1367. total_count = item.Count * medical.MinNumber
  1368. }
  1369. if item.SencondUnit == medical.MinUnit {
  1370. total_count = item.Count
  1371. }
  1372. fmt.Println("total_count2332232333233223", total_count)
  1373. fmt.Println("totoal2323232332322332", total)
  1374. if total_count <= total {
  1375. timeStr := time.Now().Format("2006-01-02")
  1376. timeArr := strings.Split(timeStr, "-")
  1377. creater := this.GetAdminUserInfo().AdminUser.Id
  1378. drug_total, _ := service.FindAllDrugWarehouseOut(orgId)
  1379. recordDateStr := time.Now().Format("2006-01-02")
  1380. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1381. record_date := recordDate.Unix()
  1382. drug_total = drug_total + 1
  1383. drug_warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1384. number, _ := strconv.ParseInt(drug_warehousing_out_order, 10, 64)
  1385. number = number + drug_total
  1386. drug_warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1387. operation_time := time.Now().Unix()
  1388. drugWarehouseOut := models.DrugWarehouseOut{
  1389. WarehouseOutOrderNumber: drug_warehousing_out_order,
  1390. OperationTime: operation_time,
  1391. OrgId: orgId,
  1392. Creater: creater,
  1393. Ctime: time.Now().Unix(),
  1394. Status: 1,
  1395. WarehouseOutTime: record_date,
  1396. Type: 2,
  1397. StorehouseId: item.StorehouseInId,
  1398. SecondWarehouseId: item.WarehouseId,
  1399. IsSys: 12,
  1400. IsCheck: 1,
  1401. }
  1402. _, drugerrcodes := service.GetDrugWarehouseBySyS(orgId, 12, item.WarehouseId, record_date)
  1403. if drugerrcodes == gorm.ErrRecordNotFound {
  1404. service.AddSigleDrugWarehouseOut(&drugWarehouseOut)
  1405. }
  1406. drugOut, _ := service.GetLastDrugWarehouseOutById(12, item.WarehouseId, orgId, record_date)
  1407. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1408. WarehouseOutOrderNumber: drugOut.WarehouseOutOrderNumber,
  1409. WarehouseOutId: drugOut.ID,
  1410. DrugId: item.ProjectId,
  1411. Count: item.Count,
  1412. Price: medical.RetailPrice,
  1413. TotalPrice: 0,
  1414. Status: 1,
  1415. Ctime: time.Now().Unix(),
  1416. Remark: item.Remake,
  1417. OrgId: orgId,
  1418. Type: 2,
  1419. Manufacturer: 0,
  1420. Dealer: 0,
  1421. RetailPrice: item.MinPrice,
  1422. RetailTotalPrice: 0,
  1423. CountUnit: item.SencondUnit,
  1424. ExpiryDate: 0,
  1425. ProductDate: 0,
  1426. Number: "",
  1427. BatchNumber: "",
  1428. IsSys: 0,
  1429. WarehouseInfoId: 0,
  1430. StorehouseId: item.StorehouseInId,
  1431. SecondWarehouseInfoId: item.ID,
  1432. IsCheck: 1,
  1433. }
  1434. drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
  1435. drug_in_total, _ := service.FindAllWarehouseTotalOne(orgId)
  1436. drug_in_total = drug_in_total + 1
  1437. warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(drug_in_total, 10)
  1438. drug_warehousing := models.DrugWarehouse{
  1439. WarehousingOrder: warehousing_order,
  1440. OperationTime: operation_time,
  1441. OrgId: orgId,
  1442. Creater: creater,
  1443. Ctime: time.Now().Unix(),
  1444. Status: 1,
  1445. WarehousingTime: record_date,
  1446. Type: 1,
  1447. StorehouseId: item.StorehouseOutId,
  1448. IsSys: 13,
  1449. SecondWarehouseId: item.WarehouseId,
  1450. IsCheck: 1,
  1451. }
  1452. //查询该调拨单是否有生成入库单
  1453. _, drugerrcodess := service.GetDrugWarehouseingBySys(13, item.WarehouseId, orgId, record_date)
  1454. if drugerrcodess == gorm.ErrRecordNotFound {
  1455. service.CreateDrugWaresing(drug_warehousing)
  1456. }
  1457. drugInfoObj, _ := service.GetLastDrugWarehouseBySys(13, item.WarehouseId, orgId, record_date)
  1458. drugwarehouseInfo := &models.DrugWarehouseInfo{
  1459. WarehousingOrder: drugInfoObj.WarehousingOrder,
  1460. WarehousingId: drugInfoObj.ID,
  1461. DrugId: item.ProjectId,
  1462. Number: "",
  1463. ProductDate: 0,
  1464. ExpiryDate: 0,
  1465. WarehousingCount: 0,
  1466. Price: 0,
  1467. TotalPrice: 0,
  1468. Status: 1,
  1469. Ctime: time.Now().Unix(),
  1470. Remark: "",
  1471. OrgId: orgId,
  1472. Type: 2,
  1473. Manufacturer: 0,
  1474. Dealer: 0,
  1475. StockMaxNumber: 0,
  1476. RetailTotalPrice: 0,
  1477. BatchNumber: "",
  1478. MaxUnit: "",
  1479. MinUnit: "",
  1480. RetailPrice: 0,
  1481. StorehouseId: item.StorehouseOutId,
  1482. SecondWarehouseInfoId: item.ID,
  1483. IsCheck: 1,
  1484. }
  1485. fmt.Println("尽力发的233223323232")
  1486. service.AutoDrugDeliverInfoTwelve(orgId, item.Count, &drugWarehouseOut, &drup, warehouseOutInfo, drugwarehouseInfo)
  1487. //查询默认仓库
  1488. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1489. //更新字典里面的库存
  1490. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
  1491. var sum_count int64
  1492. for _, its := range stockInfo {
  1493. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1494. if its.MaxUnit == baseDrug.MaxUnit {
  1495. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1496. }
  1497. sum_count += its.StockMaxNumber + its.StockMinNumber
  1498. }
  1499. service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
  1500. //回退库存,查询该订单出库记录
  1501. //drugOutList, _ := service.GetStoreDrugWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
  1502. //for _, it := range drugOutList {
  1503. //
  1504. // if medical.MaxUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
  1505. // //回退库存
  1506. // service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
  1507. // }
  1508. //
  1509. // if medical.MaxUnit == it.CountUnit && medical.MaxUnit == medical.MinUnit {
  1510. // //回退库存
  1511. // service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
  1512. // }
  1513. //
  1514. // if medical.MinUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
  1515. //
  1516. // service.ModifyDrugStoreWarehouseInfoOne(it.WarehouseInfoId, it.Count)
  1517. // }
  1518. //
  1519. // //查询入库单
  1520. // //storeWareing, _ := service.GetStoreDrugWarehouseById(item.WarehouseId, it.OrgId)
  1521. // //删除入库单
  1522. // //service.DeleteStoreWarehousingId(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
  1523. //
  1524. // //查询出单
  1525. // //storeWarehouseOut, _ := service.GetStoreDrugWarehouseOutById(it.WarehouseOutId, it.OrgId)
  1526. //
  1527. // //删除出库单
  1528. // //service.DeleteStoreWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
  1529. //}
  1530. }
  1531. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1532. var sum_count int64
  1533. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
  1534. for _, its := range stockInfo {
  1535. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1536. if its.MaxUnit == baseDrug.MaxUnit {
  1537. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1538. }
  1539. sum_count += its.StockMaxNumber + its.StockMinNumber
  1540. }
  1541. service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
  1542. var sum_out_count int64
  1543. baseDrug, _ := service.GetBaseDrugMedical(item.ProjectId)
  1544. if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
  1545. sum_out_count = item.Count * baseDrug.MinNumber
  1546. }
  1547. if item.SencondUnit == baseDrug.MinUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
  1548. sum_out_count = item.Count
  1549. }
  1550. if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit == baseDrug.MinUnit {
  1551. sum_out_count = item.Count
  1552. }
  1553. //入库仓库减少
  1554. service.ReduceDrugStockCountSeven(item.StorehouseInId, item.ProjectId, item.UserOrgId, sum_out_count)
  1555. //出库仓库增加
  1556. service.AddDrugStockCount(item.StorehouseOutId, item.ProjectId, item.UserOrgId, sum_out_count)
  1557. }
  1558. //耗材
  1559. if item.IsSource == 2 {
  1560. //查询该仓库的耗材库存是否满足调出数量
  1561. var total int64
  1562. infoList, _ := service.GetWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
  1563. for _, it := range infoList {
  1564. total += it.StockCount
  1565. }
  1566. //满足调拨
  1567. if item.Count <= total {
  1568. timeStr := time.Now().Format("2006-01-02")
  1569. timeArr := strings.Split(timeStr, "-")
  1570. total, _ := service.FindAllWarehouseOut(orgId)
  1571. total = total + 1
  1572. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1573. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1574. number = number + total
  1575. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1576. operation_time := time.Now().Unix()
  1577. creater := this.GetAdminUserInfo().AdminUser.Id
  1578. recordDateStr := time.Now().Format("2006-01-02")
  1579. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1580. record_date := recordDate.Unix()
  1581. totals, _ := service.FindAllWarehouseTotal(orgId)
  1582. totals = totals + 1
  1583. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(totals, 10)
  1584. //创建出库单
  1585. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1586. warehouseOut := models.WarehouseOut{
  1587. WarehouseOutOrderNumber: warehousing_out_order,
  1588. OperationTime: operation_time,
  1589. OrgId: orgId,
  1590. Creater: creater,
  1591. Ctime: time.Now().Unix(),
  1592. Status: 1,
  1593. WarehouseOutTime: record_date,
  1594. Type: 1,
  1595. StorehouseId: item.StorehouseInId,
  1596. IsSys: 12,
  1597. SecondWarehouseId: item.WarehouseId,
  1598. IsCheck: 1,
  1599. }
  1600. //查询今日是否存在调拨出库
  1601. _, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
  1602. if errcodes == gorm.ErrRecordNotFound {
  1603. service.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. }