secondary_order_api_contorller.go 67KB

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