secondary_order_api_contorller.go 84KB

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