secondary_order_api_contorller.go 66KB

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