secondary_order_api_contorller.go 66KB

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