stock_in_api_controller.go 149KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684
  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. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type StockManagerApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func StockManagerApiRegistRouters() {
  20. //入库管理和其他入库管理相关接口
  21. beego.Router("/api/warehouse/create", &StockManagerApiController{}, "post:CreateWarehouse")
  22. beego.Router("/api/warehouse/list", &StockManagerApiController{}, "get:GetWarehouseList")
  23. beego.Router("/api/warehouse/delete", &StockManagerApiController{}, "post:DeleteWarehouse")
  24. beego.Router("/api/warehouseinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseInfo")
  25. beego.Router("/api/warehouseinfo/list", &StockManagerApiController{}, "get:GetWarehouseInfoList")
  26. beego.Router("/api/warehouse/edit", &StockManagerApiController{}, "post:EditWarehouse")
  27. //退货管理和其他退货管理相关接口
  28. beego.Router("/api/salesreturn/create", &StockManagerApiController{}, "post:CreateSalesReturn")
  29. beego.Router("/api/salesreturn/delete", &StockManagerApiController{}, "post:DeleteSalesReturn")
  30. beego.Router("/api/salesreturninfo/delete", &StockManagerApiController{}, "post:DeleteSalesReturnInfo")
  31. beego.Router("/api/salesreturninfo/list", &StockManagerApiController{}, "get:GetSalesReturnInfoList")
  32. beego.Router("/api/salesreturn/list", &StockManagerApiController{}, "get:GetSalesReturnList")
  33. beego.Router("/api/salesreturn/edit", &StockManagerApiController{}, "post:EditReturnInfo")
  34. //出库管理和其他出库管理相关接口
  35. beego.Router("/api/warehouseout/create", &StockManagerApiController{}, "post:CreateWarehouseOut")
  36. beego.Router("/api/warehouseout/delete", &StockManagerApiController{}, "post:DeleteWarehouseOut")
  37. beego.Router("/api/warehouseoutinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseOutInfo")
  38. beego.Router("/api/warehouseout/list", &StockManagerApiController{}, "get:GetWarehouseOutList")
  39. beego.Router("/api/warehouseout/edit", &StockManagerApiController{}, "post:EditWarehouseOut")
  40. beego.Router("/api/warehouseout/info", &StockManagerApiController{}, "get:GetWarehouseOutInfoList")
  41. //出库退库管理和其他出库退库管理相关接口
  42. beego.Router("/api/cancelstock/create", &StockManagerApiController{}, "post:CreateCancelStock")
  43. beego.Router("/api/cancelstock/list", &StockManagerApiController{}, "get:GetCancelStockList")
  44. beego.Router("/api/cancelstock/info", &StockManagerApiController{}, "get:GetCancelStockInfoList")
  45. beego.Router("/api/cancelstock/delete", &StockManagerApiController{}, "post:DeleteCancelStock")
  46. beego.Router("/api/cancelstockinfo/delete", &StockManagerApiController{}, "post:DeleteCancelStockInfo")
  47. beego.Router("/api/cancelstockinfo/edit", &StockManagerApiController{}, "post:EditCancelStock")
  48. beego.Router("/api/cancelstockinfo/config", &StockManagerApiController{}, "get:GetCancelStockConfig")
  49. //库存相关全局配置
  50. beego.Router("/api/stock/config", &StockManagerApiController{}, "get:GetAllConfig")
  51. beego.Router("/api/return/config", &StockManagerApiController{}, "get:GetAllSalesReturnConfig")
  52. //库存查询
  53. beego.Router("/api/stock/query", &StockManagerApiController{}, "get:GetQueryInfo")
  54. beego.Router("/api/stock/detail", &StockManagerApiController{}, "get:GetDetailInfo")
  55. beego.Router("/api/warehouseout/user", &StockManagerApiController{}, "get:GetUserDetailInfo")
  56. beego.Router("/api/warehouseout/postsearchstock", &StockManagerApiController{}, "Get:PostSearchStock")
  57. beego.Router("/api/warehouseout/getoutstocktotalcount", &StockManagerApiController{}, "Get:GetOutStockTotalCount")
  58. beego.Router("/api/good/postgoodinformation", &StockManagerApiController{}, "Post:AddGoodInformation")
  59. beego.Router("/api/good/postdruginformation", &StockManagerApiController{}, "Post:AddDrugInformation")
  60. beego.Router("/api/good/initializtion", &StockManagerApiController{}, "Get:GetInitializtion")
  61. beego.Router("/api/good/getwarehouseorderinfolist", &StockManagerApiController{}, "Get:GetWarehouseOrderInfolist")
  62. beego.Router("/api/good/postsearchgoodlist", &StockManagerApiController{}, "Get:PostSearchGoodList")
  63. beego.Router("/api/good/getallstocklist", &StockManagerApiController{}, "Get:GetAllStockList")
  64. beego.Router("/api/stock/getstocklistbyid", &StockManagerApiController{}, "Get:GetStockListById")
  65. beego.Router("/api/stock/getstockoutlist", &StockManagerApiController{}, "Get:GetStockOutList")
  66. beego.Router("/api/good/getstockdrugcount", &StockManagerApiController{}, "Get:GetStockDrugCount")
  67. beego.Router("/api/good/getorderdetialbyorderid", &StockManagerApiController{}, "Get:GetOrderDetialByOrderId")
  68. beego.Router("/api/good/getorderdetaibyid", &StockManagerApiController{}, "Get:GetOrderDetailById")
  69. beego.Router("/api/good/getsingleoutorderdetail", &StockManagerApiController{}, "Get:GetSingleOutOrderDetail")
  70. beego.Router("/api/stock/getexportstocklist", &StockManagerApiController{}, "Get:GetExprotStockList")
  71. beego.Router("/api/stock/getoutexprotlist", &StockManagerApiController{}, "Get:GetOutExprotList")
  72. beego.Router("/api/stock/getsinglecancelorder", &StockManagerApiController{}, "Get:GetSingleCancelOrder")
  73. beego.Router("/api/stock/getcancelstockorderprint", &StockManagerApiController{}, "Get:GetCancelStockOrderPrint")
  74. beego.Router("/api/stock/getstockbatchnumber", &StockManagerApiController{}, "Get:GetStockBatchNumber")
  75. beego.Router("/api/stock/getstockflow", &StockManagerApiController{}, "Get:GetStockFlow")
  76. beego.Router("/api/cancel/getcancelexportlist", &StockManagerApiController{}, "Get:GetCancelExportList")
  77. }
  78. func (c *StockManagerApiController) CreateWarehouse() {
  79. warehousing_time := c.GetString("warehousing_time")
  80. types, _ := c.GetInt64("type", 0)
  81. ctime := time.Now().Unix()
  82. adminUserInfo := c.GetAdminUserInfo()
  83. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  84. if parseDateErr != nil {
  85. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  86. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  87. return
  88. }
  89. timeStr := time.Now().Format("2006-01-02")
  90. timeArr := strings.Split(timeStr, "-")
  91. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  92. total = total + 1
  93. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  94. operation_time := time.Now().Unix()
  95. creater := adminUserInfo.AdminUser.Id
  96. warehousing := models.Warehousing{
  97. WarehousingOrder: warehousing_order,
  98. OperationTime: operation_time,
  99. OrgId: adminUserInfo.CurrentOrgId,
  100. Creater: creater,
  101. Ctime: ctime,
  102. Status: 1,
  103. WarehousingTime: warehousingDate.Unix(),
  104. Type: types,
  105. }
  106. service.AddSigleWarehouse(&warehousing)
  107. dataBody := make(map[string]interface{}, 0)
  108. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  109. if err != nil {
  110. utils.ErrorLog(err.Error())
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. return
  113. }
  114. var warehousingInfo []*models.WarehousingInfo
  115. var stockFlow []*models.VmStockFlow
  116. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  117. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  118. if len(thisStockIn) > 0 {
  119. for _, item := range thisStockIn {
  120. items := item.(map[string]interface{})
  121. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  122. utils.ErrorLog("good_id")
  123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  124. return
  125. }
  126. good_id := int64(items["good_id"].(float64))
  127. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  128. utils.ErrorLog("good_type_id")
  129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  130. return
  131. }
  132. good_type_id := int64(items["good_type_id"].(float64))
  133. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  134. utils.ErrorLog("warehousing_count")
  135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  136. return
  137. }
  138. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  139. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  140. utils.ErrorLog("price")
  141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  142. return
  143. }
  144. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  145. total := float64(warehousing_count) * price
  146. var productDates int64
  147. var expiryDates int64
  148. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  149. expiryDates = 0
  150. } else {
  151. if len(items["expiry_date"].(string)) == 0 {
  152. expiryDates = 0
  153. } else {
  154. expiryDate, _ := items["expiry_date"].(string)
  155. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  156. expiryDates = expiry_date.Unix()
  157. }
  158. }
  159. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  160. productDates = 0
  161. } else {
  162. if len(items["product_date"].(string)) == 0 {
  163. productDates = 0
  164. } else {
  165. productDate, _ := items["product_date"].(string)
  166. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  167. productDates = product_date.Unix()
  168. }
  169. }
  170. number, _ := items["number"].(string)
  171. remark, _ := items["remark"].(string)
  172. manufacturer := int64(items["manufacturer"].(float64))
  173. dealer := int64(items["dealer"].(float64))
  174. license_number, _ := items["license_number"].(string)
  175. //入库单表格
  176. warehouseInfo := &models.WarehousingInfo{
  177. WarehousingOrder: warehousing.WarehousingOrder,
  178. WarehousingId: warehousing.ID,
  179. GoodId: good_id,
  180. Number: number,
  181. GoodTypeId: good_type_id,
  182. ProductDate: productDates,
  183. ExpiryDate: expiryDates,
  184. WarehousingCount: warehousing_count,
  185. Price: price,
  186. TotalPrice: total,
  187. Status: 1,
  188. Ctime: ctime,
  189. Remark: remark,
  190. OrgId: adminUserInfo.CurrentOrgId,
  191. Type: types,
  192. Manufacturer: manufacturer,
  193. StockCount: warehousing_count,
  194. Dealer: dealer,
  195. LicenseNumber: license_number,
  196. }
  197. warehousingInfo = append(warehousingInfo, warehouseInfo)
  198. flow := &models.VmStockFlow{
  199. WarehousingOrder: warehousing.WarehousingOrder,
  200. WarehousingId: warehousing.ID,
  201. GoodId: good_id,
  202. Number: number,
  203. ProductDate: productDates,
  204. ExpireDate: expiryDates,
  205. Count: warehousing_count,
  206. Price: price,
  207. Status: 1,
  208. Ctime: ctime,
  209. UserOrgId: adminUserInfo.CurrentOrgId,
  210. Manufacturer: manufacturer,
  211. Dealer: dealer,
  212. LicenseNumber: license_number,
  213. IsEdit: 1,
  214. Creator: adminUserInfo.AdminUser.Id,
  215. SystemTime: operation_time,
  216. ConsumableType: 1,
  217. WarehousingDetailId: warehouseInfo.ID,
  218. }
  219. stockFlow = append(stockFlow, flow)
  220. }
  221. }
  222. }
  223. //入库单创建成功
  224. errs := service.CreateWarehousingInfo(warehousingInfo)
  225. //创建入库单流水
  226. service.CreateStockFlow(stockFlow)
  227. info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
  228. if errs != nil {
  229. utils.ErrorLog(errs.Error())
  230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  231. return
  232. }
  233. c.ServeSuccessJSON(map[string]interface{}{
  234. "msg": "入库成功",
  235. "warehousing_order": warehousing_order,
  236. "info": info,
  237. })
  238. }
  239. func (c *StockManagerApiController) GetWarehouseList() {
  240. page, _ := c.GetInt64("page", -1)
  241. limit, _ := c.GetInt64("limit", -1)
  242. start_time := c.GetString("start_time")
  243. end_time := c.GetString("end_time")
  244. types, _ := c.GetInt64("type", 0)
  245. keywords := c.GetString("keywords")
  246. timeLayout := "2006-01-02"
  247. loc, _ := time.LoadLocation("Local")
  248. var startTime int64
  249. if len(start_time) > 0 {
  250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  251. if err != nil {
  252. fmt.Println(err)
  253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  254. return
  255. }
  256. startTime = theTime.Unix()
  257. }
  258. var endTime int64
  259. if len(end_time) > 0 {
  260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  261. if err != nil {
  262. utils.ErrorLog(err.Error())
  263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  264. return
  265. }
  266. endTime = theTime.Unix()
  267. }
  268. adminUserInfo := c.GetAdminUserInfo()
  269. var ids []int64
  270. var goodids []int64
  271. //查询商品名称
  272. if len(keywords) > 0 {
  273. //查询商品名称
  274. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  275. for _, item := range list {
  276. goodids = append(goodids, item.ID)
  277. //入库详情但里面查询
  278. }
  279. if len(goodids) > 0 {
  280. info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  281. for _, it := range info {
  282. ids = append(ids, it.WarehousingId)
  283. }
  284. }
  285. }
  286. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  287. if err == nil {
  288. c.ServeSuccessJSON(map[string]interface{}{
  289. "list": warehouseList,
  290. "total": total,
  291. })
  292. } else {
  293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  294. }
  295. }
  296. func (c *StockManagerApiController) GetWarehouseInfoList() {
  297. id := c.GetString("id")
  298. idArray := strings.Split(id, ",")
  299. warehousing, err := service.FindWarehousingByIdOne(idArray)
  300. if err != nil {
  301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  302. return
  303. }
  304. var ids []int64
  305. for _, item := range warehousing {
  306. ids = append(ids, item.ID)
  307. }
  308. warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
  309. if err == nil {
  310. c.ServeSuccessJSON(map[string]interface{}{
  311. "info": warehousingInfo,
  312. "warehousing": warehousing,
  313. })
  314. } else {
  315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  316. }
  317. }
  318. func (c *StockManagerApiController) EditWarehouse() {
  319. warehousing_time := c.GetString("warehousing_time")
  320. id, _ := c.GetInt64("id", 0)
  321. types, _ := c.GetInt64("type", 0)
  322. if id == 0 {
  323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  324. return
  325. }
  326. ctime := time.Now().Unix()
  327. mtime := time.Now().Unix()
  328. adminUserInfo := c.GetAdminUserInfo()
  329. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  330. if parseDateErr != nil {
  331. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  333. return
  334. }
  335. warehouse, _ := service.FindWarehousingById(id)
  336. warehousing := models.Warehousing{
  337. WarehousingOrder: warehouse.WarehousingOrder,
  338. OrgId: adminUserInfo.CurrentOrgId,
  339. Modifier: adminUserInfo.AdminUser.Id,
  340. Mtime: mtime,
  341. Status: 1,
  342. WarehousingTime: warehousingDate.Unix(),
  343. Type: warehouse.Type,
  344. }
  345. service.EditWarehousing(warehousing)
  346. dataBody := make(map[string]interface{}, 0)
  347. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  348. if err != nil {
  349. utils.ErrorLog(err.Error())
  350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  351. return
  352. }
  353. var warehousingInfo []*models.WarehousingInfo
  354. var upDateWarehousingInfo []*models.WarehousingInfo
  355. var stockFlow []*models.VmStockFlow
  356. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  357. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  358. if len(thisStockIn) > 0 {
  359. for _, item := range thisStockIn {
  360. items := item.(map[string]interface{})
  361. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  362. utils.ErrorLog("good_id")
  363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  364. return
  365. }
  366. good_id := int64(items["good_id"].(float64))
  367. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  368. utils.ErrorLog("good_type_id")
  369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  370. return
  371. }
  372. good_type_id := int64(items["good_type_id"].(float64))
  373. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  374. utils.ErrorLog("warehousing_count")
  375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  376. return
  377. }
  378. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  379. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  380. utils.ErrorLog("price")
  381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  382. return
  383. }
  384. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  385. total := float64(warehousing_count) * price
  386. var productDates int64
  387. var expiryDates int64
  388. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  389. expiryDates = 0
  390. } else {
  391. if len(items["expiry_date"].(string)) == 0 {
  392. expiryDates = 0
  393. } else {
  394. expiryDate, _ := items["expiry_date"].(string)
  395. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  396. expiryDates = expiry_date.Unix()
  397. }
  398. }
  399. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  400. productDates = 0
  401. } else {
  402. if len(items["product_date"].(string)) == 0 {
  403. productDates = 0
  404. } else {
  405. productDate, _ := items["product_date"].(string)
  406. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  407. productDates = product_date.Unix()
  408. }
  409. }
  410. number, _ := items["number"].(string)
  411. remark, _ := items["remark"].(string)
  412. manufacturer := int64(items["manufacturer"].(float64))
  413. dealer := int64(items["dealer"].(float64))
  414. license_number, _ := items["license_number"].(string)
  415. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  416. utils.ErrorLog("id")
  417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  418. return
  419. }
  420. id := int64(items["id"].(float64))
  421. if id == 0 {
  422. warehouseInfo := &models.WarehousingInfo{
  423. WarehousingOrder: warehouse.WarehousingOrder,
  424. WarehousingId: warehouse.ID,
  425. GoodId: good_id,
  426. Number: number,
  427. GoodTypeId: good_type_id,
  428. ProductDate: productDates,
  429. ExpiryDate: expiryDates,
  430. WarehousingCount: warehousing_count,
  431. Price: price,
  432. TotalPrice: total,
  433. Status: 1,
  434. Ctime: ctime,
  435. Remark: remark,
  436. OrgId: adminUserInfo.CurrentOrgId,
  437. Type: types,
  438. Manufacturer: manufacturer,
  439. Dealer: dealer,
  440. StockCount: warehousing_count,
  441. LicenseNumber: license_number,
  442. }
  443. warehousingInfo = append(warehousingInfo, warehouseInfo)
  444. flow := &models.VmStockFlow{
  445. WarehousingOrder: warehousing.WarehousingOrder,
  446. WarehousingId: warehousing.ID,
  447. GoodId: good_id,
  448. Number: number,
  449. ProductDate: productDates,
  450. ExpireDate: expiryDates,
  451. Count: warehousing_count,
  452. Price: price,
  453. Status: 1,
  454. Ctime: ctime,
  455. UserOrgId: adminUserInfo.CurrentOrgId,
  456. Manufacturer: manufacturer,
  457. Dealer: dealer,
  458. LicenseNumber: license_number,
  459. IsEdit: 1,
  460. Creator: adminUserInfo.AdminUser.Id,
  461. SystemTime: ctime,
  462. ConsumableType: 1,
  463. WarehousingDetailId: warehouseInfo.ID,
  464. }
  465. stockFlow = append(stockFlow, flow)
  466. } else {
  467. fmt.Println("id23233232323232323232323223", id)
  468. warehouseInfo := &models.WarehousingInfo{
  469. ID: id,
  470. WarehousingOrder: warehouse.WarehousingOrder,
  471. WarehousingId: warehouse.ID,
  472. GoodId: good_id,
  473. Number: number,
  474. GoodTypeId: good_type_id,
  475. ProductDate: productDates,
  476. ExpiryDate: expiryDates,
  477. WarehousingCount: warehousing_count,
  478. Price: price,
  479. TotalPrice: total,
  480. Status: 1,
  481. Ctime: ctime,
  482. Remark: remark,
  483. OrgId: adminUserInfo.CurrentOrgId,
  484. Type: types,
  485. Manufacturer: manufacturer,
  486. Dealer: dealer,
  487. LicenseNumber: license_number,
  488. }
  489. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  490. flow := &models.VmStockFlow{
  491. WarehousingOrder: warehousing.WarehousingOrder,
  492. WarehousingId: id,
  493. GoodId: good_id,
  494. Number: number,
  495. ProductDate: productDates,
  496. ExpireDate: expiryDates,
  497. Count: warehousing_count,
  498. Price: price,
  499. Status: 1,
  500. Ctime: ctime,
  501. UserOrgId: adminUserInfo.CurrentOrgId,
  502. Manufacturer: manufacturer,
  503. Dealer: dealer,
  504. LicenseNumber: license_number,
  505. IsEdit: 2,
  506. Creator: adminUserInfo.AdminUser.Id,
  507. SystemTime: ctime,
  508. ConsumableType: 1,
  509. WarehousingDetailId: warehouseInfo.ID,
  510. }
  511. stockFlow = append(stockFlow, flow)
  512. }
  513. }
  514. }
  515. }
  516. var errs error
  517. if len(warehousingInfo) > 0 {
  518. errs = service.CreateWarehousingInfo(warehousingInfo)
  519. service.CreateStockFlow(stockFlow)
  520. }
  521. if len(upDateWarehousingInfo) > 0 {
  522. for _, item := range upDateWarehousingInfo {
  523. var total int64
  524. var all_total int64
  525. //获取该批次该型号的库存
  526. info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
  527. fmt.Println("oooooooooo", info.WarehousingCount)
  528. //判断 该批次的入库数量
  529. total = item.WarehousingCount - info.WarehousingCount
  530. fmt.Println("total232323322332232332", total)
  531. all_total = info.StockCount + total
  532. item.StockCount = all_total
  533. fmt.Println("hhhhhhhhhhhhh", item.StockCount)
  534. errs = service.UpDateWarehousingInfo(item)
  535. }
  536. }
  537. if len(stockFlow) > 0 {
  538. for _, item := range stockFlow {
  539. flow := models.VmStockFlow{
  540. Count: item.Count,
  541. }
  542. parseDateErr := service.UpdateStockFlow(flow, item.GoodId, item.WarehousingId)
  543. fmt.Println(parseDateErr)
  544. }
  545. }
  546. if errs != nil {
  547. utils.ErrorLog(errs.Error())
  548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  549. return
  550. }
  551. c.ServeSuccessJSON(map[string]interface{}{
  552. "msg": "编辑成功",
  553. })
  554. }
  555. func (c *StockManagerApiController) DeleteWarehouse() {
  556. ids := c.GetString("ids")
  557. if len(ids) == 0 {
  558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  559. return
  560. }
  561. idArray := strings.Split(ids, ",")
  562. err := service.DeleteWarehouse(idArray)
  563. if err != nil {
  564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  565. } else {
  566. c.ServeSuccessJSON(map[string]interface{}{
  567. "msg": "删除成功",
  568. })
  569. }
  570. }
  571. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  572. id, _ := c.GetInt64("id", 0)
  573. if id == 0 {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. err := service.UpDateWarehouseStatus(id)
  578. if err != nil {
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  580. } else {
  581. c.ServeSuccessJSON(map[string]interface{}{
  582. "msg": "删除成功",
  583. })
  584. }
  585. }
  586. func (c *StockManagerApiController) CreateSalesReturn() {
  587. dealer_id, _ := c.GetInt64("dealer_id", 0)
  588. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  589. sales_return_time := c.GetString("time")
  590. types, _ := c.GetInt64("type", 0)
  591. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  592. if parseDateErr != nil {
  593. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  595. return
  596. }
  597. adminUserInfo := c.GetAdminUserInfo()
  598. operation_time := time.Now().Unix()
  599. creater := adminUserInfo.AdminUser.Id
  600. ctime := time.Now().Unix()
  601. timeStr := time.Now().Format("2006-01-02")
  602. timeArr := strings.Split(timeStr, "-")
  603. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  604. total = total + 1
  605. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  606. salesReturn := models.SalesReturn{
  607. OrderNumber: orderNumber,
  608. OperaTime: operation_time,
  609. OrgId: adminUserInfo.CurrentOrgId,
  610. Creater: creater,
  611. Ctime: ctime,
  612. Status: 1,
  613. ReturnTime: salesReturnDate.Unix(),
  614. Dealer: dealer_id,
  615. Manufacturer: manufacturer_id,
  616. Type: types,
  617. }
  618. service.AddSigleSalesReturn(&salesReturn)
  619. dataBody := make(map[string]interface{}, 0)
  620. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  621. if err != nil {
  622. utils.ErrorLog(err.Error())
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  624. return
  625. }
  626. var salesReturnInfos []*models.SalesReturnInfo
  627. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  628. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  629. if len(thisStockIn) > 0 {
  630. for _, item := range thisStockIn {
  631. items := item.(map[string]interface{})
  632. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  633. utils.ErrorLog("good_id")
  634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  635. return
  636. }
  637. good_id := int64(items["good_id"].(float64))
  638. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  639. utils.ErrorLog("good_type_id")
  640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  641. return
  642. }
  643. good_type_id := int64(items["good_type_id"].(float64))
  644. return_count, _ := items["return_count"].(string)
  645. if len(return_count) == 0 {
  646. utils.ErrorLog("len(return_count) == 0")
  647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  648. return
  649. }
  650. count, _ := strconv.ParseInt(return_count, 10, 64)
  651. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  652. total := float64(count) * price
  653. salesReturnInfo := &models.SalesReturnInfo{
  654. OrderNumber: salesReturn.OrderNumber,
  655. SalesReturnId: salesReturn.ID,
  656. GoodId: good_id,
  657. GoodTypeId: good_type_id,
  658. Count: count,
  659. Price: price,
  660. Total: total,
  661. Status: 1,
  662. Ctime: ctime,
  663. OrgId: adminUserInfo.CurrentOrgId,
  664. Type: types,
  665. Manufacturer: manufacturer_id,
  666. Dealer: dealer_id,
  667. }
  668. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  669. }
  670. }
  671. }
  672. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  673. if errs != nil {
  674. utils.ErrorLog(errs.Error())
  675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  676. return
  677. }
  678. c.ServeSuccessJSON(map[string]interface{}{
  679. "msg": "退货成功",
  680. })
  681. }
  682. func (c *StockManagerApiController) GetSalesReturnList() {
  683. page, _ := c.GetInt64("page", -1)
  684. limit, _ := c.GetInt64("limit", -1)
  685. start_time := c.GetString("start_time")
  686. end_time := c.GetString("end_time")
  687. types, _ := c.GetInt64("type", 0)
  688. keywords := c.GetString("keywords")
  689. timeLayout := "2006-01-02"
  690. loc, _ := time.LoadLocation("Local")
  691. var startTime int64
  692. if len(start_time) > 0 {
  693. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  694. if err != nil {
  695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  696. return
  697. }
  698. startTime = theTime.Unix()
  699. }
  700. var endTime int64
  701. if len(end_time) > 0 {
  702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  703. if err != nil {
  704. utils.ErrorLog(err.Error())
  705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  706. return
  707. }
  708. endTime = theTime.Unix()
  709. }
  710. adminUserInfo := c.GetAdminUserInfo()
  711. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  712. if err == nil {
  713. c.ServeSuccessJSON(map[string]interface{}{
  714. "list": returnList,
  715. "total": total,
  716. })
  717. } else {
  718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  719. }
  720. }
  721. func (this *StockManagerApiController) DeleteSalesReturn() {
  722. ids := this.GetString("ids")
  723. if len(ids) == 0 {
  724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  725. return
  726. }
  727. idArray := strings.Split(ids, ",")
  728. err := service.DeleteSalesReturn(idArray)
  729. if err != nil {
  730. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  731. } else {
  732. this.ServeSuccessJSON(map[string]interface{}{
  733. "msg": "删除成功",
  734. })
  735. }
  736. }
  737. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  738. id, _ := this.GetInt64("id", 0)
  739. fmt.Println(id)
  740. if id == 0 {
  741. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  742. return
  743. }
  744. err := service.UpDateSaleReturnStatus(id)
  745. if err != nil {
  746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  747. } else {
  748. this.ServeSuccessJSON(map[string]interface{}{
  749. "msg": "删除成功",
  750. })
  751. }
  752. }
  753. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  754. id, _ := this.GetInt64("id", 0)
  755. list, _ := service.FindAllSalesReturnInfoById(id)
  756. salesReturn, _ := service.FindAllSalesReturnById(id)
  757. this.ServeSuccessJSON(map[string]interface{}{
  758. "list": list,
  759. "salesReturn": salesReturn,
  760. })
  761. }
  762. func (c *StockManagerApiController) EditReturnInfo() {
  763. return_time := c.GetString("return_time")
  764. id, _ := c.GetInt64("id", 0)
  765. types, _ := c.GetInt64("type", 0)
  766. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  767. dealer_id, _ := c.GetInt64("dealer_id", 0)
  768. if id == 0 {
  769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  770. return
  771. }
  772. ctime := time.Now().Unix()
  773. mtime := time.Now().Unix()
  774. adminUserInfo := c.GetAdminUserInfo()
  775. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  776. if parseDateErr != nil {
  777. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  779. return
  780. }
  781. salesReturns, _ := service.FindSalesReturnById(id)
  782. sales := models.SalesReturn{
  783. ID: salesReturns.ID,
  784. Mtime: mtime,
  785. ReturnTime: returnDate.Unix(),
  786. Manufacturer: manufacturer_id,
  787. Dealer: dealer_id,
  788. }
  789. service.EditSaleReturn(sales)
  790. dataBody := make(map[string]interface{}, 0)
  791. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  792. if err != nil {
  793. utils.ErrorLog(err.Error())
  794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  795. return
  796. }
  797. var returnInfos []*models.SalesReturnInfo
  798. var upDateReturnInfos []*models.SalesReturnInfo
  799. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  800. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  801. if len(thisStockIn) > 0 {
  802. for _, item := range thisStockIn {
  803. items := item.(map[string]interface{})
  804. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  805. utils.ErrorLog("good_id")
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  807. return
  808. }
  809. good_id := int64(items["good_id"].(float64))
  810. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  811. utils.ErrorLog("good_type_id")
  812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  813. return
  814. }
  815. good_type_id := int64(items["good_type_id"].(float64))
  816. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  817. utils.ErrorLog("count")
  818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  819. return
  820. }
  821. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  822. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  823. utils.ErrorLog("id")
  824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  825. return
  826. }
  827. id := int64(items["id"].(float64))
  828. if id == 0 {
  829. returnInfo := &models.SalesReturnInfo{
  830. GoodId: good_id,
  831. GoodTypeId: good_type_id,
  832. Count: count,
  833. Status: 1,
  834. Ctime: ctime,
  835. OrgId: adminUserInfo.CurrentOrgId,
  836. OrderNumber: sales.OrderNumber,
  837. SalesReturnId: sales.ID,
  838. Mtime: time.Now().Unix(),
  839. Type: types,
  840. Manufacturer: manufacturer_id,
  841. Dealer: dealer_id,
  842. }
  843. returnInfos = append(returnInfos, returnInfo)
  844. } else {
  845. returnInfo := &models.SalesReturnInfo{
  846. ID: id,
  847. GoodId: good_id,
  848. GoodTypeId: good_type_id,
  849. Count: count,
  850. Status: 1,
  851. Ctime: ctime,
  852. OrgId: adminUserInfo.CurrentOrgId,
  853. OrderNumber: sales.OrderNumber,
  854. SalesReturnId: sales.ID,
  855. Mtime: time.Now().Unix(),
  856. Type: types,
  857. Manufacturer: manufacturer_id,
  858. Dealer: dealer_id,
  859. }
  860. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  861. }
  862. }
  863. }
  864. }
  865. var errs error
  866. if len(returnInfos) > 0 {
  867. errs = service.CreateSalesReturnInfo(returnInfos)
  868. }
  869. if len(upDateReturnInfos) > 0 {
  870. for _, item := range upDateReturnInfos {
  871. errs = service.UpDateSalesReturnInfo(item)
  872. }
  873. }
  874. if errs != nil {
  875. utils.ErrorLog(errs.Error())
  876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  877. return
  878. }
  879. c.ServeSuccessJSON(map[string]interface{}{
  880. "msg": "编辑成功",
  881. })
  882. }
  883. func (c *StockManagerApiController) CreateWarehouseOut() {
  884. types, _ := c.GetInt64("type", 0)
  885. ctime := time.Now().Unix()
  886. adminUserInfo := c.GetAdminUserInfo()
  887. warehousing_out_time := c.GetString("warehousing_out_time")
  888. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  889. if parseDateErr != nil {
  890. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  892. return
  893. }
  894. timeStr := time.Now().Format("2006-01-02")
  895. timeArr := strings.Split(timeStr, "-")
  896. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  897. total = total + 1
  898. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  899. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  900. number = number + total
  901. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  902. operation_time := time.Now().Unix()
  903. creater := adminUserInfo.AdminUser.Id
  904. warehouseOut := models.WarehouseOut{
  905. WarehouseOutOrderNumber: warehousing_out_order,
  906. OperationTime: operation_time,
  907. OrgId: adminUserInfo.CurrentOrgId,
  908. Creater: creater,
  909. Ctime: ctime,
  910. Status: 1,
  911. WarehouseOutTime: warehousingOutDate.Unix(),
  912. Type: types,
  913. }
  914. dataBody := make(map[string]interface{}, 0)
  915. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  916. if err != nil {
  917. utils.ErrorLog(err.Error())
  918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  919. return
  920. }
  921. var warehousingOutInfo []*models.WarehouseOutInfo
  922. var beforePrepares []*models.DialysisBeforePrepareGoods
  923. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  924. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  925. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  926. if len(thisStockIn) > 0 {
  927. for _, item := range thisStockIn {
  928. items := item.(map[string]interface{})
  929. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  930. utils.ErrorLog("good_id")
  931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  932. return
  933. }
  934. good_id := int64(items["good_id"].(float64))
  935. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  936. utils.ErrorLog("good_type_id")
  937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  938. return
  939. }
  940. good_type_id := int64(items["good_type_id"].(float64))
  941. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  942. utils.ErrorLog("count")
  943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  944. return
  945. }
  946. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  947. utils.ErrorLog("price")
  948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  949. return
  950. }
  951. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  952. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  953. total := float64(count) * price
  954. remark := items["remark"].(string)
  955. manufacturer := int64(items["manufacturer"].(float64))
  956. dealer := int64(items["dealer"].(float64))
  957. number := items["number"].(string)
  958. expiry_date := items["expiry_date"].(string)
  959. timeLayout := "2006-01-02"
  960. loc, _ := time.LoadLocation("Local")
  961. var expiryDate int64
  962. if len(expiry_date) > 0 {
  963. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  964. if err != nil {
  965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  966. return
  967. }
  968. expiryDate = theTime.Unix()
  969. }
  970. product_date := items["product_date"].(string)
  971. var productDate int64
  972. if len(product_date) > 0 {
  973. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  974. if err != nil {
  975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  976. return
  977. }
  978. productDate = theTime.Unix()
  979. }
  980. license_number := items["license_number"].(string)
  981. warehouseOutInfo := &models.WarehouseOutInfo{
  982. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  983. WarehouseOutId: warehouseOut.ID,
  984. GoodId: good_id,
  985. GoodTypeId: good_type_id,
  986. Count: count,
  987. Price: price,
  988. TotalPrice: total,
  989. Status: 1,
  990. Ctime: ctime,
  991. Remark: remark,
  992. OrgId: adminUserInfo.CurrentOrgId,
  993. Type: types,
  994. Manufacturer: manufacturer,
  995. Number: number,
  996. ExpiryDate: expiryDate,
  997. ProductDate: productDate,
  998. Dealer: dealer,
  999. LicenseNumber: license_number,
  1000. }
  1001. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1002. prepareGoods := &models.DialysisBeforePrepareGoods{
  1003. GoodTypeId: good_type_id,
  1004. GoodId: good_id,
  1005. Count: count,
  1006. }
  1007. beforePrepares = append(beforePrepares, prepareGoods)
  1008. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  1009. GoodTypeId: good_type_id,
  1010. GoodId: good_id,
  1011. Count: count,
  1012. }
  1013. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  1014. }
  1015. }
  1016. }
  1017. //出库逻辑
  1018. for _, item := range warehousingOutInfo {
  1019. //查询库存
  1020. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
  1021. fmt.Println("库存数量组吗", warehouse.Count)
  1022. if item.Count > warehouse.Count {
  1023. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1024. c.ServeSuccessJSON(map[string]interface{}{
  1025. "msg": "1",
  1026. "good_name": goodObj.GoodName,
  1027. "specification_name": goodObj.SpecificationName,
  1028. })
  1029. return
  1030. } else {
  1031. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  1032. if errcodes == gorm.ErrRecordNotFound {
  1033. service.AddSigleWarehouseOut(&warehouseOut)
  1034. }
  1035. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
  1036. if parseDateErr != nil {
  1037. utils.ErrorLog(parseDateErr.Error())
  1038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1039. return
  1040. }
  1041. c.ServeSuccessJSON(map[string]interface{}{
  1042. "msg": "2",
  1043. "good_name": "",
  1044. "specification_name": "",
  1045. })
  1046. }
  1047. }
  1048. //errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
  1049. //info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
  1050. }
  1051. func (c *StockManagerApiController) GetWarehouseOutList() {
  1052. page, _ := c.GetInt64("page", -1)
  1053. limit, _ := c.GetInt64("limit", -1)
  1054. start_time := c.GetString("start_time")
  1055. end_time := c.GetString("end_time")
  1056. types, _ := c.GetInt64("type", 0)
  1057. keywords := c.GetString("keywords")
  1058. timeLayout := "2006-01-02"
  1059. loc, _ := time.LoadLocation("Local")
  1060. var startTime int64
  1061. if len(start_time) > 0 {
  1062. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1063. if err != nil {
  1064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1065. return
  1066. }
  1067. startTime = theTime.Unix()
  1068. }
  1069. var endTime int64
  1070. if len(end_time) > 0 {
  1071. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1072. if err != nil {
  1073. utils.ErrorLog(err.Error())
  1074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1075. return
  1076. }
  1077. endTime = theTime.Unix()
  1078. }
  1079. adminUserInfo := c.GetAdminUserInfo()
  1080. var ids []int64
  1081. var goodids []int64
  1082. if len(keywords) > 0 {
  1083. //查询商品名称
  1084. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  1085. for _, item := range list {
  1086. goodids = append(goodids, item.ID)
  1087. }
  1088. if len(goodids) > 0 {
  1089. //出库详情但里面查询
  1090. info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  1091. for _, it := range info {
  1092. ids = append(ids, it.WarehouseOutId)
  1093. }
  1094. }
  1095. }
  1096. warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  1097. fmt.Println(err)
  1098. if err == nil {
  1099. c.ServeSuccessJSON(map[string]interface{}{
  1100. "list": warehouseOutList,
  1101. "total": total,
  1102. })
  1103. } else {
  1104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1105. }
  1106. }
  1107. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1108. ids := c.GetString("ids")
  1109. if len(ids) == 0 {
  1110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1111. return
  1112. }
  1113. idArray := strings.Split(ids, ",")
  1114. err := service.DeleteWarehouseOut(idArray)
  1115. if err != nil {
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1117. } else {
  1118. c.ServeSuccessJSON(map[string]interface{}{
  1119. "msg": "删除成功",
  1120. })
  1121. }
  1122. }
  1123. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1124. id, _ := this.GetInt64("id", 0)
  1125. fmt.Println(id)
  1126. if id == 0 {
  1127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1128. return
  1129. }
  1130. err := service.UpDateWarehouseOutStatus(id)
  1131. if err != nil {
  1132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1133. } else {
  1134. this.ServeSuccessJSON(map[string]interface{}{
  1135. "msg": "删除成功",
  1136. })
  1137. }
  1138. }
  1139. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1140. id, _ := c.GetInt64("id", 0)
  1141. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1142. warehouseOut, _ := service.FindWareHouseOutById(id)
  1143. adminUserInfo := c.GetAdminUserInfo()
  1144. orgId := adminUserInfo.CurrentOrgId
  1145. wareoutList, _ := service.GetWareOutInfoById(id, orgId)
  1146. c.ServeSuccessJSON(map[string]interface{}{
  1147. "list": warehouseOutInfo,
  1148. "info": warehouseOut,
  1149. "wareoutList": wareoutList,
  1150. })
  1151. }
  1152. func (c *StockManagerApiController) EditWarehouseOut() {
  1153. warehouse_out_time := c.GetString("warehouse_out_time")
  1154. id, _ := c.GetInt64("id", 0)
  1155. types, _ := c.GetInt64("type", 0)
  1156. if id == 0 {
  1157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1158. return
  1159. }
  1160. ctime := time.Now().Unix()
  1161. mtime := time.Now().Unix()
  1162. adminUserInfo := c.GetAdminUserInfo()
  1163. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1164. if parseDateErr != nil {
  1165. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1167. return
  1168. }
  1169. warehouseOut, _ := service.FindWareHouseOutById(id)
  1170. tempWarehouseOut := models.WarehouseOut{
  1171. ID: warehouseOut.ID,
  1172. Mtime: mtime,
  1173. WarehouseOutTime: warehouseOutDate.Unix(),
  1174. }
  1175. service.EditWarehouseOut(tempWarehouseOut)
  1176. dataBody := make(map[string]interface{}, 0)
  1177. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1178. if err != nil {
  1179. utils.ErrorLog(err.Error())
  1180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1181. return
  1182. }
  1183. var warehousingOutInfo []*models.WarehouseOutInfo
  1184. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1185. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1186. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1187. if len(thisStockOut) > 0 {
  1188. for _, item := range thisStockOut {
  1189. items := item.(map[string]interface{})
  1190. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1191. utils.ErrorLog("good_id")
  1192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1193. return
  1194. }
  1195. good_id := int64(items["good_id"].(float64))
  1196. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1197. utils.ErrorLog("good_type_id")
  1198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1199. return
  1200. }
  1201. good_type_id := int64(items["good_type_id"].(float64))
  1202. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1203. utils.ErrorLog("count")
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1208. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1209. utils.ErrorLog("price")
  1210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1211. return
  1212. }
  1213. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1214. total := float64(count) * price
  1215. remark := items["remark"].(string)
  1216. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1217. utils.ErrorLog("id")
  1218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1219. return
  1220. }
  1221. id := int64(items["id"].(float64))
  1222. manufacturer := int64(items["manufacturer"].(float64))
  1223. dealer := int64(items["dealer"].(float64))
  1224. number := items["number"].(string)
  1225. license_number := items["license_number"].(string)
  1226. timeLayout := "2006-01-02"
  1227. loc, _ := time.LoadLocation("Local")
  1228. expiry_date := items["expiry_date"].(string)
  1229. var expiryDate int64
  1230. if len(expiry_date) > 0 {
  1231. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1232. if err != nil {
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1234. return
  1235. }
  1236. expiryDate = theTime.Unix()
  1237. }
  1238. product_date := items["product_date"].(string)
  1239. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1240. var productDate int64
  1241. if len(product_date) > 0 {
  1242. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1243. if err != nil {
  1244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1245. return
  1246. }
  1247. productDate = theTime.Unix()
  1248. }
  1249. if id == 0 {
  1250. warehouseOutInfo := &models.WarehouseOutInfo{
  1251. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1252. WarehouseOutId: warehouseOut.ID,
  1253. GoodId: good_id,
  1254. GoodTypeId: good_type_id,
  1255. Count: count,
  1256. Price: price,
  1257. TotalPrice: total,
  1258. Status: 1,
  1259. Ctime: ctime,
  1260. Remark: remark,
  1261. OrgId: adminUserInfo.CurrentOrgId,
  1262. Type: types,
  1263. IsSys: 0,
  1264. SysRecordTime: 0,
  1265. Number: number,
  1266. ExpiryDate: expiryDate,
  1267. ProductDate: productDate,
  1268. Dealer: dealer,
  1269. Manufacturer: manufacturer,
  1270. LicenseNumber: license_number,
  1271. ConsumableType: 1,
  1272. WarehouseInfotId: warehouse_info_id,
  1273. }
  1274. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1275. } else {
  1276. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1277. utils.ErrorLog("is_sys")
  1278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1279. return
  1280. }
  1281. is_sys := int64(items["is_sys"].(float64))
  1282. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1283. utils.ErrorLog("sys_record_time")
  1284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1285. return
  1286. }
  1287. sys_record_time := int64(items["sys_record_time"].(float64))
  1288. warehouseOutInfo := &models.WarehouseOutInfo{
  1289. ID: id,
  1290. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1291. WarehouseOutId: warehouseOut.ID,
  1292. GoodId: good_id,
  1293. GoodTypeId: good_type_id,
  1294. Count: count,
  1295. Price: price,
  1296. TotalPrice: total,
  1297. Status: 1,
  1298. Ctime: ctime,
  1299. Remark: remark,
  1300. OrgId: adminUserInfo.CurrentOrgId,
  1301. Mtime: time.Now().Unix(),
  1302. Type: types,
  1303. Manufacturer: manufacturer,
  1304. IsSys: is_sys,
  1305. SysRecordTime: sys_record_time,
  1306. Number: number,
  1307. ExpiryDate: expiryDate,
  1308. ProductDate: productDate,
  1309. Dealer: dealer,
  1310. LicenseNumber: license_number,
  1311. ConsumableType: 2,
  1312. WarehouseInfotId: warehouse_info_id,
  1313. }
  1314. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1315. }
  1316. }
  1317. }
  1318. }
  1319. var errs error
  1320. if len(warehousingOutInfo) > 0 {
  1321. errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
  1322. }
  1323. if len(upDateWarehouseOutInfos) > 0 {
  1324. for _, item := range upDateWarehouseOutInfos {
  1325. //1.查询该耗材该批次的最后一次出库记录
  1326. lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, adminUserInfo.CurrentOrgId)
  1327. fmt.Println("lastGood", lastGood.Count)
  1328. fmt.Println("item2323232", item.Count)
  1329. // 退库的库存和该耗材该批次最后一次出库数量进行比较
  1330. //如果退库数量大于 最后一次批次的数量(要么要进行出库)
  1331. if item.Count > lastGood.Count {
  1332. //查询该耗材是否还有库存
  1333. warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
  1334. fmt.Println("hhhhhh23h2323232", warehouseinfo.StockCount)
  1335. //无库存
  1336. if warehouseinfo.StockCount <= 0 {
  1337. c.ServeSuccessJSON(map[string]interface{}{
  1338. "msg": "5",
  1339. })
  1340. return
  1341. }
  1342. //有库存,进行出库,调用出库接口
  1343. if warehouseinfo.StockCount > 0 {
  1344. var total int64
  1345. var stock_cout int64
  1346. var total_count int64
  1347. //计算和最后一次出库数据的差
  1348. total = item.Count - lastGood.Count
  1349. fmt.Println("total22323232", total)
  1350. //获取该耗材该批次的剩余库存量
  1351. info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1352. fmt.Println("info2232323232323", info)
  1353. //判断该批次的剩余库存 和出库的库存进行比较
  1354. //如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
  1355. if item.Count > info.StockCount {
  1356. //计算出库和该批次相差的库存
  1357. total_count = item.Count - info.StockCount
  1358. //清空本批次次库存
  1359. service.DeleteWarehouseInfo(item.WarehouseInfotId)
  1360. //调用出库逻辑
  1361. service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
  1362. }
  1363. //如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
  1364. if item.Count <= info.StockCount {
  1365. stock_cout = lastGood.Count + total
  1366. fmt.Println("232323223232323232323232", stock_cout)
  1367. //扣减库存
  1368. warehouse := models.WarehousingInfo{
  1369. StockCount: info.StockCount - total,
  1370. }
  1371. errs := service.UpdateWarehousingInfo(warehouse, info.ID)
  1372. warehouseOutInfo := &models.WarehouseOutInfo{
  1373. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1374. WarehouseOutId: id,
  1375. WarehouseInfotId: item.WarehouseInfotId,
  1376. Status: 1,
  1377. Ctime: time.Now().Unix(),
  1378. Remark: item.Remark,
  1379. OrgId: item.OrgId,
  1380. Type: 1,
  1381. Manufacturer: item.Manufacturer,
  1382. Dealer: item.Dealer,
  1383. IsSys: 0,
  1384. SysRecordTime: item.SysRecordTime,
  1385. GoodTypeId: item.GoodTypeId,
  1386. GoodId: item.GoodId,
  1387. ExpiryDate: item.ExpiryDate,
  1388. ProductDate: item.ProductDate,
  1389. Number: item.Number,
  1390. Price: item.Price,
  1391. LicenseNumber: item.LicenseNumber,
  1392. Count: item.Count,
  1393. ConsumableType: 2,
  1394. }
  1395. //查询是否存在
  1396. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1397. if errcode == gorm.ErrRecordNotFound {
  1398. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1399. if errOne != nil {
  1400. utils.ErrorLog(errs.Error())
  1401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1402. return
  1403. }
  1404. c.ServeSuccessJSON(map[string]interface{}{
  1405. "msg": "1",
  1406. })
  1407. } else if errcode == nil {
  1408. service.UpDateWarehouseOutInfo(item)
  1409. }
  1410. }
  1411. }
  1412. }
  1413. var last_count int64
  1414. var all_total int64
  1415. var stock_total int64
  1416. //如果退库数量小于最后一次批次的数量(要么要进行退库)
  1417. if item.Count < lastGood.Count {
  1418. fmt.Println("hh232323h2h3hh23hh23hh2h3h23")
  1419. //退库数量和最后一次出库数据进行计算
  1420. last_count = lastGood.Count - item.Count
  1421. fmt.Println("last_count", last_count)
  1422. //获取该耗材该批次的剩余库存量
  1423. infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1424. //退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
  1425. all_total = last_count + infoInfo.StockCount
  1426. fmt.Println("all_total", all_total)
  1427. //如果库存大于总数量,则退回到这个批次
  1428. fmt.Println("inf232323", infoInfo.WarehousingCount)
  1429. if infoInfo.WarehousingCount > all_total {
  1430. stock_total = last_count + infoInfo.StockCount
  1431. fmt.Println("经历323232323232232", last_count, stock_total)
  1432. //退回该批次,计算数量
  1433. warehousingInfoOne := models.WarehousingInfo{
  1434. StockCount: stock_total,
  1435. ID: item.WarehouseInfotId,
  1436. OrgId: item.OrgId,
  1437. }
  1438. fmt.Println("********************", warehousingInfoOne, item.WarehouseInfotId)
  1439. parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
  1440. fmt.Println("parseDateErr2323232322323", parseDateErr)
  1441. //插入一条新纪录
  1442. warehouseOutInfoThree := &models.WarehouseOutInfo{
  1443. WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  1444. WarehouseOutId: id,
  1445. WarehouseInfotId: item.WarehouseInfotId,
  1446. Status: 1,
  1447. Ctime: time.Now().Unix(),
  1448. Remark: item.Remark,
  1449. OrgId: item.OrgId,
  1450. Type: 1,
  1451. Manufacturer: item.Manufacturer,
  1452. Dealer: item.Dealer,
  1453. IsSys: 0,
  1454. GoodTypeId: item.GoodTypeId,
  1455. GoodId: item.GoodId,
  1456. ExpiryDate: item.ExpiryDate,
  1457. ProductDate: item.ProductDate,
  1458. Number: item.Number,
  1459. Price: item.Price,
  1460. LicenseNumber: item.LicenseNumber,
  1461. ConsumableType: 2,
  1462. Count: item.Count,
  1463. }
  1464. //查询是否存在
  1465. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1466. if errcode == gorm.ErrRecordNotFound {
  1467. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
  1468. if errOne != nil {
  1469. utils.ErrorLog(errs.Error())
  1470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1471. return
  1472. }
  1473. c.ServeSuccessJSON(map[string]interface{}{
  1474. "msg": "1",
  1475. })
  1476. } else if errcode == nil {
  1477. service.UpDateWarehouseOutInfo(item)
  1478. }
  1479. }
  1480. //如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
  1481. if infoInfo.WarehousingCount < all_total {
  1482. c.ServeSuccessJSON(map[string]interface{}{
  1483. "msg": "6",
  1484. })
  1485. return
  1486. }
  1487. }
  1488. if item.Count == lastGood.Count {
  1489. errs = service.UpDateWarehouseOutInfo(item)
  1490. if errs != nil {
  1491. utils.ErrorLog(errs.Error())
  1492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1493. return
  1494. }
  1495. c.ServeSuccessJSON(map[string]interface{}{
  1496. "msg": "1",
  1497. })
  1498. }
  1499. }
  1500. }
  1501. if errs != nil {
  1502. utils.ErrorLog(errs.Error())
  1503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1504. return
  1505. }
  1506. c.ServeSuccessJSON(map[string]interface{}{
  1507. "msg": "1",
  1508. })
  1509. }
  1510. func (c *StockManagerApiController) CreateCancelStock() {
  1511. cancel_stock_time := c.GetString("time")
  1512. types, _ := c.GetInt64("type", 0)
  1513. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1514. if parseDateErr != nil {
  1515. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1517. return
  1518. }
  1519. adminUserInfo := c.GetAdminUserInfo()
  1520. operation_time := time.Now().Unix()
  1521. creater := adminUserInfo.AdminUser.Id
  1522. ctime := time.Now().Unix()
  1523. timeStr := time.Now().Format("2006-01-02")
  1524. timeArr := strings.Split(timeStr, "-")
  1525. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1526. total = total + 1
  1527. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1528. cancelStock := models.CancelStock{
  1529. OrderNumber: orderNumber,
  1530. OperaTime: operation_time,
  1531. OrgId: adminUserInfo.CurrentOrgId,
  1532. Creater: creater,
  1533. Ctime: ctime,
  1534. Status: 1,
  1535. ReturnTime: cancelStockDate.Unix(),
  1536. Type: types,
  1537. }
  1538. service.AddSigleCancelStock(&cancelStock)
  1539. dataBody := make(map[string]interface{}, 0)
  1540. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1541. if err != nil {
  1542. utils.ErrorLog(err.Error())
  1543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1544. return
  1545. }
  1546. var cancelStockInfos []*models.CancelStockInfo
  1547. var stockFLow []*models.VmStockFlow
  1548. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1549. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1550. if len(thisStockIn) > 0 {
  1551. for _, item := range thisStockIn {
  1552. items := item.(map[string]interface{})
  1553. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1554. utils.ErrorLog("good_id")
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1556. return
  1557. }
  1558. good_id := int64(items["good_id"].(float64))
  1559. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1560. utils.ErrorLog("good_type_id")
  1561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1562. return
  1563. }
  1564. good_type_id := int64(items["good_type_id"].(float64))
  1565. return_count, _ := items["return_count"].(string)
  1566. if len(return_count) == 0 {
  1567. utils.ErrorLog("len(return_count) == 0")
  1568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1569. return
  1570. }
  1571. count, _ := strconv.ParseInt(return_count, 10, 64)
  1572. number := items["number"].(string)
  1573. register_account := items["register_account"].(string)
  1574. manufacturer, _ := items["manufacturer"].(string)
  1575. dealer, _ := items["dealer"].(string)
  1576. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1577. var expiryDates int64
  1578. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1579. expiryDates = 0
  1580. } else {
  1581. if len(items["expiry_date"].(string)) == 0 {
  1582. expiryDates = 0
  1583. } else {
  1584. expiryDate, _ := items["expiry_date"].(string)
  1585. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1586. expiryDates = expiry_date.Unix()
  1587. }
  1588. }
  1589. var productDates int64
  1590. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1591. productDates = 0
  1592. } else {
  1593. if len(items["product_date"].(string)) == 0 {
  1594. productDates = 0
  1595. } else {
  1596. productDate, _ := items["product_date"].(string)
  1597. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1598. productDates = product_date.Unix()
  1599. }
  1600. }
  1601. remark := items["remark"].(string)
  1602. retail_prices := items["price"].(string)
  1603. price, _ := strconv.ParseFloat(retail_prices, 64)
  1604. cancelStockInfo := &models.CancelStockInfo{
  1605. OrderNumber: cancelStock.OrderNumber,
  1606. CancelStockId: cancelStock.ID,
  1607. GoodId: good_id,
  1608. GoodTypeId: good_type_id,
  1609. Count: count,
  1610. Status: 1,
  1611. Ctime: ctime,
  1612. OrgId: adminUserInfo.CurrentOrgId,
  1613. Type: types,
  1614. Manufacturer: manufacturer,
  1615. Dealer: dealer,
  1616. Number: number,
  1617. ProductDate: productDates,
  1618. ExpiryDate: expiryDates,
  1619. RegisterAccount: register_account,
  1620. Remark: remark,
  1621. Price: price,
  1622. WarehouseInfoId: warehouse_info_id,
  1623. }
  1624. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1625. flow := &models.VmStockFlow{
  1626. WarehousingId: 0,
  1627. GoodId: good_id,
  1628. Number: number,
  1629. LicenseNumber: "",
  1630. Count: count,
  1631. UserOrgId: adminUserInfo.CurrentOrgId,
  1632. PatientId: 0,
  1633. SystemTime: time.Now().Unix(),
  1634. ConsumableType: 4,
  1635. IsSys: 0,
  1636. WarehousingOrder: "",
  1637. WarehouseOutId: 0,
  1638. WarehouseOutOrderNumber: "",
  1639. IsEdit: 0,
  1640. CancelStockId: cancelStock.ID,
  1641. CancelOrderNumber: cancelStock.OrderNumber,
  1642. Manufacturer: 0,
  1643. Dealer: 0,
  1644. Creator: adminUserInfo.AdminUser.Id,
  1645. UpdateCreator: 0,
  1646. Status: 1,
  1647. Ctime: time.Now().Unix(),
  1648. Mtime: 0,
  1649. Price: price,
  1650. WarehousingDetailId: 0,
  1651. WarehouseOutDetailId: 0,
  1652. CancelOutDetailId: 0,
  1653. ProductDate: productDates,
  1654. ExpireDate: expiryDates,
  1655. }
  1656. stockFLow = append(stockFLow, flow)
  1657. }
  1658. }
  1659. }
  1660. for _, item := range cancelStockInfos {
  1661. ////查找该耗材是否有出库记录
  1662. //_, errcode := service.GetWarehoureOutOrderInfo(item.GoodId, item.OrgId)
  1663. //if errcode == gorm.ErrRecordNotFound {
  1664. // c.ServeSuccessJSON(map[string]interface{}{
  1665. // "msg": "1",
  1666. // })
  1667. // return
  1668. //}
  1669. //统计该耗材的出库数量
  1670. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
  1671. if item.Count > info.Count {
  1672. service.UpdateCancelInfo(item.CancelStockId)
  1673. c.ServeSuccessJSON(map[string]interface{}{
  1674. "msg": "2",
  1675. })
  1676. return
  1677. }
  1678. //查询该批次入库的值
  1679. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  1680. if item.Count > infolist.WarehousingCount {
  1681. c.ServeSuccessJSON(map[string]interface{}{
  1682. "msg": "4",
  1683. })
  1684. return
  1685. }
  1686. if item.Count <= infolist.WarehousingCount {
  1687. errs := service.CreateCancelStockInfo(cancelStockInfos)
  1688. if len(stockFLow) > 0 {
  1689. service.CreateStockFlow(stockFLow)
  1690. }
  1691. if errs != nil {
  1692. utils.ErrorLog(errs.Error())
  1693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1694. return
  1695. }
  1696. //查询该批次的剩余库存
  1697. wareouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  1698. if (wareouseinfo.StockCount + item.Count) > wareouseinfo.WarehousingCount {
  1699. c.ServeSuccessJSON(map[string]interface{}{
  1700. "msg": "5",
  1701. })
  1702. return
  1703. }
  1704. //更改入库数量
  1705. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  1706. //查询该耗材的入库记录
  1707. //list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
  1708. ////调用退库的方法
  1709. //parseDateErr := service.UpdateCancelOut(list, item.Count)
  1710. //fmt.Println("999999999999", parseDateErr)
  1711. break
  1712. }
  1713. }
  1714. c.ServeSuccessJSON(map[string]interface{}{
  1715. "msg": "3",
  1716. })
  1717. return
  1718. }
  1719. func (c *StockManagerApiController) GetCancelStockInfoList() {
  1720. id, _ := c.GetInt64("id", 0)
  1721. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  1722. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1723. manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
  1724. dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
  1725. c.ServeSuccessJSON(map[string]interface{}{
  1726. "list": cancelStockInfoList,
  1727. "info": info,
  1728. "manufacturerList": manufacturerList,
  1729. "dealerList": dealerList,
  1730. })
  1731. }
  1732. func (c *StockManagerApiController) GetCancelStockList() {
  1733. page, _ := c.GetInt64("page", -1)
  1734. limit, _ := c.GetInt64("limit", -1)
  1735. start_time := c.GetString("start_time")
  1736. end_time := c.GetString("end_time")
  1737. types, _ := c.GetInt64("type", 0)
  1738. keywords := c.GetString("keywords")
  1739. timeLayout := "2006-01-02"
  1740. loc, _ := time.LoadLocation("Local")
  1741. var startTime int64
  1742. if len(start_time) > 0 {
  1743. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1744. if err != nil {
  1745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1746. return
  1747. }
  1748. startTime = theTime.Unix()
  1749. }
  1750. var endTime int64
  1751. if len(end_time) > 0 {
  1752. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1753. if err != nil {
  1754. utils.ErrorLog(err.Error())
  1755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1756. return
  1757. }
  1758. endTime = theTime.Unix()
  1759. }
  1760. adminUserInfo := c.GetAdminUserInfo()
  1761. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1762. if err == nil {
  1763. c.ServeSuccessJSON(map[string]interface{}{
  1764. "list": returnList,
  1765. "total": total,
  1766. })
  1767. } else {
  1768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1769. }
  1770. }
  1771. func (this *StockManagerApiController) DeleteCancelStock() {
  1772. ids := this.GetString("ids")
  1773. if len(ids) == 0 {
  1774. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1775. return
  1776. }
  1777. idArray := strings.Split(ids, ",")
  1778. err := service.DeleteCancelStock(idArray)
  1779. if err != nil {
  1780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1781. } else {
  1782. this.ServeSuccessJSON(map[string]interface{}{
  1783. "msg": "删除成功",
  1784. })
  1785. }
  1786. }
  1787. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  1788. id, _ := this.GetInt64("id", 0)
  1789. fmt.Println(id)
  1790. if id == 0 {
  1791. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1792. return
  1793. }
  1794. err := service.UpDateCancleStockStatus(id)
  1795. if err != nil {
  1796. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1797. } else {
  1798. this.ServeSuccessJSON(map[string]interface{}{
  1799. "msg": "删除成功",
  1800. })
  1801. }
  1802. }
  1803. func (c *StockManagerApiController) EditCancelStock() {
  1804. cancel_time := c.GetString("cancel_time")
  1805. id, _ := c.GetInt64("id", 0)
  1806. if id == 0 {
  1807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1808. return
  1809. }
  1810. ctime := time.Now().Unix()
  1811. mtime := time.Now().Unix()
  1812. adminUserInfo := c.GetAdminUserInfo()
  1813. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1814. if parseDateErr != nil {
  1815. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1817. return
  1818. }
  1819. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1820. tempCancelStock := models.CancelStock{
  1821. ID: cancelStock.ID,
  1822. Mtime: mtime,
  1823. ReturnTime: cancelDate.Unix(),
  1824. }
  1825. service.EditCancelStock(tempCancelStock)
  1826. dataBody := make(map[string]interface{}, 0)
  1827. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1828. if err != nil {
  1829. utils.ErrorLog(err.Error())
  1830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1831. return
  1832. }
  1833. var cancelStockInfos []*models.CancelStockInfo
  1834. var upDateCancelStockInfos []*models.CancelStockInfo
  1835. var stockFlow []*models.VmStockFlow
  1836. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1837. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1838. if len(thisCancelStock) > 0 {
  1839. for _, item := range thisCancelStock {
  1840. items := item.(map[string]interface{})
  1841. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1842. utils.ErrorLog("good_id")
  1843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1844. return
  1845. }
  1846. good_id := int64(items["good_id"].(float64))
  1847. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1848. utils.ErrorLog("good_type_id")
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1850. return
  1851. }
  1852. good_type_id := int64(items["good_type_id"].(float64))
  1853. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1854. utils.ErrorLog("count")
  1855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1856. return
  1857. }
  1858. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1859. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1860. utils.ErrorLog("id")
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. id := int64(items["id"].(float64))
  1865. number := items["number"].(string)
  1866. register_account := items["register_account"].(string)
  1867. manufacturer, _ := items["manufacturer"].(string)
  1868. dealer, _ := items["dealer"].(string)
  1869. remark := items["remark"].(string)
  1870. var productDates int64
  1871. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1872. productDates = 0
  1873. } else {
  1874. if len(items["product_date"].(string)) == 0 {
  1875. productDates = 0
  1876. } else {
  1877. productDate, _ := items["product_date"].(string)
  1878. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1879. productDates = product_date.Unix()
  1880. }
  1881. }
  1882. var expiryDates int64
  1883. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1884. expiryDates = 0
  1885. } else {
  1886. if len(items["expiry_date"].(string)) == 0 {
  1887. expiryDates = 0
  1888. } else {
  1889. expiryDate, _ := items["expiry_date"].(string)
  1890. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1891. expiryDates = expiry_date.Unix()
  1892. }
  1893. }
  1894. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1895. utils.ErrorLog("price")
  1896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1897. return
  1898. }
  1899. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1900. if id == 0 {
  1901. cancelStockInfo := &models.CancelStockInfo{
  1902. GoodId: good_id,
  1903. GoodTypeId: good_type_id,
  1904. Count: count,
  1905. Status: 1,
  1906. Ctime: ctime,
  1907. OrgId: adminUserInfo.CurrentOrgId,
  1908. OrderNumber: cancelStock.OrderNumber,
  1909. CancelStockId: cancelStock.ID,
  1910. Mtime: time.Now().Unix(),
  1911. Number: number,
  1912. RegisterAccount: register_account,
  1913. Manufacturer: manufacturer,
  1914. Dealer: dealer,
  1915. ProductDate: productDates,
  1916. ExpiryDate: expiryDates,
  1917. Remark: remark,
  1918. Price: price,
  1919. }
  1920. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1921. flow := &models.VmStockFlow{
  1922. WarehousingId: 0,
  1923. GoodId: good_id,
  1924. Number: number,
  1925. LicenseNumber: "",
  1926. Count: count,
  1927. UserOrgId: adminUserInfo.CurrentOrgId,
  1928. PatientId: 0,
  1929. SystemTime: time.Now().Unix(),
  1930. ConsumableType: 4,
  1931. IsSys: 0,
  1932. WarehousingOrder: "",
  1933. WarehouseOutId: 0,
  1934. WarehouseOutOrderNumber: "",
  1935. IsEdit: 2,
  1936. CancelStockId: cancelStock.ID,
  1937. CancelOrderNumber: cancelStock.OrderNumber,
  1938. Manufacturer: 0,
  1939. Dealer: 0,
  1940. Creator: adminUserInfo.AdminUser.Id,
  1941. UpdateCreator: 0,
  1942. Status: 1,
  1943. Ctime: time.Now().Unix(),
  1944. Mtime: 0,
  1945. Price: price,
  1946. WarehousingDetailId: 0,
  1947. WarehouseOutDetailId: 0,
  1948. CancelOutDetailId: 0,
  1949. ProductDate: productDates,
  1950. ExpireDate: expiryDates,
  1951. }
  1952. stockFlow = append(stockFlow, flow)
  1953. } else {
  1954. cancelStockInfo := &models.CancelStockInfo{
  1955. ID: id,
  1956. GoodId: good_id,
  1957. GoodTypeId: good_type_id,
  1958. Count: count,
  1959. Status: 1,
  1960. Ctime: ctime,
  1961. OrgId: adminUserInfo.CurrentOrgId,
  1962. OrderNumber: cancelStock.OrderNumber,
  1963. CancelStockId: cancelStock.ID,
  1964. Mtime: time.Now().Unix(),
  1965. Number: number,
  1966. RegisterAccount: register_account,
  1967. Manufacturer: manufacturer,
  1968. Dealer: dealer,
  1969. ProductDate: productDates,
  1970. ExpiryDate: expiryDates,
  1971. Remark: remark,
  1972. Price: price,
  1973. }
  1974. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  1975. flow := &models.VmStockFlow{
  1976. WarehousingId: 0,
  1977. GoodId: good_id,
  1978. Number: number,
  1979. LicenseNumber: "",
  1980. Count: count,
  1981. UserOrgId: adminUserInfo.CurrentOrgId,
  1982. PatientId: 0,
  1983. SystemTime: time.Now().Unix(),
  1984. ConsumableType: 4,
  1985. IsSys: 0,
  1986. WarehousingOrder: "",
  1987. WarehouseOutId: 0,
  1988. WarehouseOutOrderNumber: "",
  1989. IsEdit: 2,
  1990. CancelStockId: cancelStock.ID,
  1991. CancelOrderNumber: cancelStock.OrderNumber,
  1992. Manufacturer: 0,
  1993. Dealer: 0,
  1994. Creator: adminUserInfo.AdminUser.Id,
  1995. UpdateCreator: 0,
  1996. Status: 1,
  1997. Ctime: time.Now().Unix(),
  1998. Mtime: 0,
  1999. Price: price,
  2000. WarehousingDetailId: 0,
  2001. WarehouseOutDetailId: 0,
  2002. CancelOutDetailId: 0,
  2003. ProductDate: productDates,
  2004. ExpireDate: expiryDates,
  2005. }
  2006. stockFlow = append(stockFlow, flow)
  2007. }
  2008. }
  2009. }
  2010. }
  2011. var errs error
  2012. fmt.Println("出库22322333223", cancelStockInfos)
  2013. fmt.Println("更新23232323232323233", upDateCancelStockInfos)
  2014. if len(cancelStockInfos) > 0 {
  2015. for _, item := range cancelStockInfos {
  2016. //统计该耗材的出库数量
  2017. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
  2018. if item.Count > info.Count {
  2019. c.ServeSuccessJSON(map[string]interface{}{
  2020. "msg": "2",
  2021. })
  2022. return
  2023. }
  2024. //查询该批次入库的值
  2025. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2026. if item.Count > infolist.WarehousingCount {
  2027. c.ServeSuccessJSON(map[string]interface{}{
  2028. "msg": "4",
  2029. })
  2030. return
  2031. }
  2032. if item.Count <= infolist.WarehousingCount {
  2033. errs := service.CreateCancelStockInfo(cancelStockInfos)
  2034. if len(stockFlow) > 0 {
  2035. service.CreateStockFlow(stockFlow)
  2036. }
  2037. if errs != nil {
  2038. utils.ErrorLog(errs.Error())
  2039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2040. return
  2041. }
  2042. //更改入库数量
  2043. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  2044. break
  2045. }
  2046. }
  2047. }
  2048. if len(upDateCancelStockInfos) > 0 {
  2049. for _, item := range upDateCancelStockInfos {
  2050. //获取该批次最后一套出库记录
  2051. info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
  2052. fmt.Println("info232332322332233223", info.Count, item.Count)
  2053. //比较出库数量和最后一次出库数据大小
  2054. //退库(加)
  2055. if item.Count < info.Count {
  2056. var total = info.Count - item.Count
  2057. errs = service.UpDateCancelStockInfo(item)
  2058. service.CreateStockFlow(stockFlow)
  2059. warehouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2060. if (warehouseinfo.StockCount + total) > warehouseinfo.StockCount {
  2061. c.ServeSuccessJSON(map[string]interface{}{
  2062. "msg": "5",
  2063. })
  2064. return
  2065. }
  2066. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
  2067. if parseDateErr != nil {
  2068. utils.ErrorLog(errs.Error())
  2069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2070. break
  2071. }
  2072. }
  2073. //(减)
  2074. if item.Count > info.Count {
  2075. errs = service.UpDateCancelStockInfo(item)
  2076. service.CreateStockFlow(stockFlow)
  2077. //查询该批次入库的值
  2078. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2079. if item.Count > infolist.WarehousingCount {
  2080. c.ServeSuccessJSON(map[string]interface{}{
  2081. "msg": "4",
  2082. })
  2083. return
  2084. }
  2085. if item.Count <= infolist.WarehousingCount {
  2086. var total_count = info.Count - item.Count
  2087. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total_count)
  2088. if parseDateErr != nil {
  2089. utils.ErrorLog(errs.Error())
  2090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2091. return
  2092. }
  2093. }
  2094. }
  2095. }
  2096. if errs != nil {
  2097. utils.ErrorLog(errs.Error())
  2098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2099. return
  2100. }
  2101. c.ServeSuccessJSON(map[string]interface{}{
  2102. "msg": "3",
  2103. })
  2104. }
  2105. if errs != nil {
  2106. utils.ErrorLog(errs.Error())
  2107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2108. return
  2109. }
  2110. c.ServeSuccessJSON(map[string]interface{}{
  2111. "msg": "3",
  2112. })
  2113. }
  2114. func (this *StockManagerApiController) GetCancelStockConfig() {
  2115. types, _ := this.GetInt64("type", 0)
  2116. adminUserInfo := this.GetAdminUserInfo()
  2117. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  2118. this.ServeSuccessJSON(map[string]interface{}{
  2119. "warehouseOutInfoList": warehouseOutInfoList,
  2120. })
  2121. }
  2122. func (c *StockManagerApiController) GetQueryInfo() {
  2123. page, _ := c.GetInt64("page", -1)
  2124. limit, _ := c.GetInt64("limit", -1)
  2125. keyword := c.GetString("keyword")
  2126. start_time := c.GetString("start_time")
  2127. end_time := c.GetString("end_time")
  2128. type_name, _ := c.GetInt64("type_name")
  2129. timeLayout := "2006-01-02"
  2130. loc, _ := time.LoadLocation("Local")
  2131. var startTime int64
  2132. if len(start_time) > 0 {
  2133. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2134. if err != nil {
  2135. fmt.Println(err)
  2136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2137. return
  2138. }
  2139. startTime = theTime.Unix()
  2140. }
  2141. var endTime int64
  2142. if len(end_time) > 0 {
  2143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2144. if err != nil {
  2145. utils.ErrorLog(err.Error())
  2146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2147. return
  2148. }
  2149. endTime = theTime.Unix()
  2150. }
  2151. adminUserInfo := c.GetAdminUserInfo()
  2152. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  2153. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  2154. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
  2155. if err == nil {
  2156. c.ServeSuccessJSON(map[string]interface{}{
  2157. "list": list,
  2158. "total": total,
  2159. "info": info,
  2160. "infomationList": infomationList,
  2161. "orgid": adminUserInfo.CurrentOrgId,
  2162. })
  2163. } else {
  2164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2165. }
  2166. }
  2167. func (c *StockManagerApiController) SearchWarehouse() {
  2168. keywords := c.GetString("keywords")
  2169. adminUserInfo := c.GetAdminUserInfo()
  2170. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  2171. if err == nil {
  2172. c.ServeSuccessJSON(map[string]interface{}{
  2173. "list": warehouseList,
  2174. "total": total,
  2175. })
  2176. } else {
  2177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2178. }
  2179. }
  2180. func (c *StockManagerApiController) GetAllConfig() {
  2181. adminUserInfo := c.GetAdminUserInfo()
  2182. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  2183. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  2184. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  2185. goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  2186. c.ServeSuccessJSON(map[string]interface{}{
  2187. "manufacturer": manufacturer,
  2188. "dealer": dealer,
  2189. "goodType": goodType,
  2190. "goodInfo": goodInfo,
  2191. })
  2192. }
  2193. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  2194. types, _ := this.GetInt64("type", 0)
  2195. adminUserInfo := this.GetAdminUserInfo()
  2196. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  2197. this.ServeSuccessJSON(map[string]interface{}{
  2198. "warehouseInfoList": warehouseInfoList,
  2199. })
  2200. }
  2201. func (this *StockManagerApiController) GetDetailInfo() {
  2202. page, _ := this.GetInt64("page", 0)
  2203. limit, _ := this.GetInt64("limit", 0)
  2204. start_time := this.GetString("start_time")
  2205. end_time := this.GetString("end_time")
  2206. types, _ := this.GetInt64("type", 0)
  2207. keywords := this.GetString("keywords")
  2208. manufacturer, _ := this.GetInt64("manufacturer", 0)
  2209. order_type, _ := this.GetInt64("order_type", 0)
  2210. dealer, _ := this.GetInt64("dealer", 0)
  2211. timeLayout := "2006-01-02"
  2212. loc, _ := time.LoadLocation("Local")
  2213. var startTime int64
  2214. if len(start_time) > 0 {
  2215. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2216. if err != nil {
  2217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2218. return
  2219. }
  2220. startTime = theTime.Unix()
  2221. }
  2222. var endTime int64
  2223. if len(end_time) > 0 {
  2224. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2225. if err != nil {
  2226. utils.ErrorLog(err.Error())
  2227. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2228. return
  2229. }
  2230. endTime = theTime.Unix()
  2231. }
  2232. adminUserInfo := this.GetAdminUserInfo()
  2233. var list []*models.WarehousingInfo
  2234. var list1 []*models.WarehouseOutInfo
  2235. var list2 []*models.SalesReturnInfo
  2236. var list3 []*models.CancelStockInfo
  2237. var total int64
  2238. var err error
  2239. var total_price float64
  2240. if types == 1 {
  2241. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2242. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2243. if err == nil {
  2244. this.ServeSuccessJSON(map[string]interface{}{
  2245. "list": list,
  2246. "total": total,
  2247. "total_price": total_price,
  2248. })
  2249. } else {
  2250. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2251. }
  2252. } else if types == 2 {
  2253. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2254. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2255. if err == nil {
  2256. this.ServeSuccessJSON(map[string]interface{}{
  2257. "list": list1,
  2258. "total": total,
  2259. "total_price": total_price,
  2260. })
  2261. } else {
  2262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2263. }
  2264. } else if types == 3 {
  2265. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2266. if err == nil {
  2267. this.ServeSuccessJSON(map[string]interface{}{
  2268. "list": list2,
  2269. "total": total,
  2270. })
  2271. } else {
  2272. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2273. }
  2274. } else if types == 4 {
  2275. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2276. if err == nil {
  2277. this.ServeSuccessJSON(map[string]interface{}{
  2278. "list": list3,
  2279. "total": total,
  2280. })
  2281. } else {
  2282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2283. }
  2284. }
  2285. }
  2286. func (this *StockManagerApiController) GetUserDetailInfo() {
  2287. order_id, _ := this.GetInt64("id")
  2288. if order_id <= 0 {
  2289. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2290. return
  2291. }
  2292. adminUserInfo := this.GetAdminUserInfo()
  2293. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2294. if err == nil {
  2295. this.ServeSuccessJSON(map[string]interface{}{
  2296. "list": userDetails,
  2297. "total": total,
  2298. })
  2299. } else {
  2300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2301. return
  2302. }
  2303. }
  2304. func (this *StockManagerApiController) PostSearchStock() {
  2305. keyword := this.GetString("keyword")
  2306. adminUserInfo := this.GetAdminUserInfo()
  2307. orgId := adminUserInfo.CurrentOrgId
  2308. stock, err := service.PostSearchStock(keyword, orgId)
  2309. if err != nil {
  2310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2311. }
  2312. this.ServeSuccessJSON(map[string]interface{}{
  2313. "stock": stock,
  2314. })
  2315. }
  2316. func (this *StockManagerApiController) GetOutStockTotalCount() {
  2317. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  2318. adminUserInfo := this.GetAdminUserInfo()
  2319. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  2320. if err != nil {
  2321. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2322. }
  2323. this.ServeSuccessJSON(map[string]interface{}{
  2324. "stockCount": stockCount,
  2325. })
  2326. }
  2327. func (this *StockManagerApiController) AddGoodInformation() {
  2328. adminUserInfo := this.GetAdminUserInfo()
  2329. orgId := adminUserInfo.CurrentOrgId
  2330. dataBody := make(map[string]interface{}, 0)
  2331. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2332. if err != nil {
  2333. utils.ErrorLog(err.Error())
  2334. return
  2335. }
  2336. utils.ErrorLog("%v", dataBody)
  2337. var goods []*models.GoodInfo
  2338. var total_goods []interface{}
  2339. tempGoods := dataBody["goods"].([]interface{})
  2340. total_goods = tempGoods
  2341. for index, goodMap := range tempGoods {
  2342. goodNameM := goodMap.(map[string]interface{})
  2343. var good models.GoodInfo
  2344. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  2345. utils.ErrorLog("good_name")
  2346. return
  2347. }
  2348. good_name, _ := goodNameM["good_name"].(string)
  2349. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  2350. err_log := models.ExportErrLog{
  2351. LogType: 5,
  2352. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2353. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  2354. Status: 1,
  2355. CreateTime: time.Now().Unix(),
  2356. UpdateTime: time.Now().Unix(),
  2357. ExportTime: time.Now().Unix(),
  2358. }
  2359. service.CreateExportErrLog(&err_log)
  2360. continue
  2361. }
  2362. good.GoodName = good_name
  2363. // 获取数据字典数据
  2364. var good_kind_id int64
  2365. var name = "耗材种类"
  2366. config, _ := service.GetDrugDataConfig(0, name)
  2367. good_kind := goodNameM["good_kind"].(string)
  2368. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  2369. err_log := models.ExportErrLog{
  2370. LogType: 5,
  2371. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2372. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  2373. Status: 1,
  2374. CreateTime: time.Now().Unix(),
  2375. UpdateTime: time.Now().Unix(),
  2376. ExportTime: time.Now().Unix(),
  2377. }
  2378. service.CreateExportErrLog(&err_log)
  2379. continue
  2380. }
  2381. if len(good_kind) != 0 {
  2382. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  2383. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  2384. dataconfig := models.DictDataconfig{
  2385. ParentId: config.ID,
  2386. Module: "system",
  2387. OrgId: orgId,
  2388. Name: good_kind,
  2389. FieldName: "",
  2390. Value: lastConfig.Value + 1,
  2391. CreatedTime: "",
  2392. UpdatedTime: "",
  2393. CreateUserId: adminUserInfo.AdminUser.Id,
  2394. Status: 1,
  2395. Remark: "",
  2396. DeleteIdSystem: 0,
  2397. Title: "",
  2398. Content: "",
  2399. Order: 0,
  2400. Code: "",
  2401. }
  2402. if errcodegoodkind == gorm.ErrRecordNotFound {
  2403. service.CreatedDicConfig(&dataconfig)
  2404. }
  2405. }
  2406. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  2407. for _, it := range dataConfig {
  2408. if good_kind == it.Name {
  2409. fmt.Println(it.Name)
  2410. good_kind_id = int64(it.Value)
  2411. }
  2412. }
  2413. good.GoodKind = good_kind_id
  2414. good_type := goodNameM["type_name"].(string)
  2415. if len(good_type) == 0 {
  2416. err_log := models.ExportErrLog{
  2417. LogType: 5,
  2418. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2419. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  2420. Status: 1,
  2421. CreateTime: time.Now().Unix(),
  2422. UpdateTime: time.Now().Unix(),
  2423. ExportTime: time.Now().Unix(),
  2424. }
  2425. service.CreateExportErrLog(&err_log)
  2426. continue
  2427. }
  2428. if len(good_type) != 0 {
  2429. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  2430. if errcodegoodtype == gorm.ErrRecordNotFound {
  2431. goodsType := models.GoodsType{
  2432. TypeName: good_type,
  2433. Remark: "",
  2434. Ctime: time.Now().Unix(),
  2435. Mtime: 0,
  2436. Creater: adminUserInfo.AdminUser.Id,
  2437. Modifier: 0,
  2438. OrgId: adminUserInfo.CurrentOrgId,
  2439. Status: 1,
  2440. Type: 0,
  2441. Number: 0,
  2442. OutStock: 0,
  2443. StockAttribute: 1,
  2444. }
  2445. service.CreatedGoodType(&goodsType)
  2446. }
  2447. }
  2448. goodType, _ := service.GetAllGoodType(orgId)
  2449. var good_type_id int64
  2450. for _, it := range goodType {
  2451. if good_type == it.TypeName {
  2452. good_type_id = it.ID
  2453. }
  2454. }
  2455. good.GoodTypeId = good_type_id
  2456. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  2457. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  2458. err_log := models.ExportErrLog{
  2459. LogType: 5,
  2460. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2461. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  2462. Status: 1,
  2463. CreateTime: time.Now().Unix(),
  2464. UpdateTime: time.Now().Unix(),
  2465. ExportTime: time.Now().Unix(),
  2466. }
  2467. service.CreateExportErrLog(&err_log)
  2468. continue
  2469. }
  2470. var medical_insurance_id int64
  2471. var medicalInsurance = "医保等级"
  2472. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  2473. if len(medical_insurance_level) != 0 {
  2474. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  2475. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  2476. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  2477. dataconfig := models.DictDataconfig{
  2478. ParentId: medicalInsuranceDataConfig.ID,
  2479. Module: "system",
  2480. OrgId: orgId,
  2481. Name: medical_insurance_level,
  2482. FieldName: "",
  2483. Value: mediConfigOne.Value + 1,
  2484. CreatedTime: "",
  2485. UpdatedTime: "",
  2486. CreateUserId: adminUserInfo.AdminUser.Id,
  2487. Status: 1,
  2488. Remark: "",
  2489. DeleteIdSystem: 0,
  2490. Title: "",
  2491. Content: "",
  2492. Order: 0,
  2493. Code: "",
  2494. }
  2495. service.CreatedDicConfig(&dataconfig)
  2496. }
  2497. }
  2498. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  2499. for _, it := range medicalInsuranceList {
  2500. if medical_insurance_level == it.Name {
  2501. medical_insurance_id = int64(it.Value)
  2502. }
  2503. }
  2504. good.MedicalInsuranceLevel = medical_insurance_id
  2505. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  2506. utils.ErrorLog("specification_name")
  2507. return
  2508. }
  2509. specification_name := goodNameM["specification_name"].(string)
  2510. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  2511. err_log := models.ExportErrLog{
  2512. LogType: 5,
  2513. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2514. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  2515. Status: 1,
  2516. CreateTime: time.Now().Unix(),
  2517. UpdateTime: time.Now().Unix(),
  2518. ExportTime: time.Now().Unix(),
  2519. }
  2520. service.CreateExportErrLog(&err_log)
  2521. continue
  2522. }
  2523. good.SpecificationName = specification_name
  2524. var manufacturer_id int64
  2525. manufacturer := goodNameM["manufacturer"].(string)
  2526. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  2527. err_log := models.ExportErrLog{
  2528. LogType: 5,
  2529. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2530. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  2531. Status: 1,
  2532. CreateTime: time.Now().Unix(),
  2533. UpdateTime: time.Now().Unix(),
  2534. ExportTime: time.Now().Unix(),
  2535. }
  2536. service.CreateExportErrLog(&err_log)
  2537. continue
  2538. }
  2539. if len(manufacturer) != 0 {
  2540. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  2541. manu := models.Manufacturer{
  2542. ManufacturerName: manufacturer,
  2543. Status: 1,
  2544. OrgId: orgId,
  2545. Creater: adminUserInfo.AdminUser.Id,
  2546. }
  2547. if errcodes == gorm.ErrRecordNotFound {
  2548. service.CreateManufacturer(&manu)
  2549. }
  2550. }
  2551. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2552. for _, it := range manufacturerList {
  2553. if manufacturer == it.ManufacturerName {
  2554. manufacturer_id = it.ID
  2555. }
  2556. }
  2557. good.Manufacturer = manufacturer_id
  2558. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  2559. utils.ErrorLog("unit_id")
  2560. return
  2561. }
  2562. unit_id := int64(goodNameM["unit_id"].(float64))
  2563. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  2564. err_log := models.ExportErrLog{
  2565. LogType: 5,
  2566. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2567. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  2568. Status: 1,
  2569. CreateTime: time.Now().Unix(),
  2570. UpdateTime: time.Now().Unix(),
  2571. ExportTime: time.Now().Unix(),
  2572. }
  2573. service.CreateExportErrLog(&err_log)
  2574. continue
  2575. }
  2576. good.GoodUnit = unit_id
  2577. retail_prices := goodNameM["retail_price"].(string)
  2578. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2579. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  2580. err_log := models.ExportErrLog{
  2581. LogType: 5,
  2582. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2583. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
  2584. Status: 1,
  2585. CreateTime: time.Now().Unix(),
  2586. UpdateTime: time.Now().Unix(),
  2587. ExportTime: time.Now().Unix(),
  2588. }
  2589. service.CreateExportErrLog(&err_log)
  2590. continue
  2591. }
  2592. good.RetailPrice = retail_price
  2593. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  2594. utils.ErrorLog("stock_warn_count")
  2595. return
  2596. }
  2597. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  2598. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  2599. err_log := models.ExportErrLog{
  2600. LogType: 5,
  2601. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2602. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  2603. Status: 1,
  2604. CreateTime: time.Now().Unix(),
  2605. UpdateTime: time.Now().Unix(),
  2606. ExportTime: time.Now().Unix(),
  2607. }
  2608. service.CreateExportErrLog(&err_log)
  2609. continue
  2610. }
  2611. good.StockWarnCount = stock_warn_count
  2612. var dealer_id int64
  2613. dealerName := goodNameM["dealer"].(string)
  2614. fmt.Println("经销商", dealerName)
  2615. dealer := models.Dealer{
  2616. OrgId: orgId,
  2617. Status: 1,
  2618. DealerName: dealerName,
  2619. Creater: adminUserInfo.AdminUser.Id,
  2620. Ctime: time.Now().Unix(),
  2621. }
  2622. if len(dealerName) != 0 {
  2623. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  2624. if errcodedealer == gorm.ErrRecordNotFound {
  2625. service.CreateDealer(&dealer)
  2626. }
  2627. }
  2628. dealerList, _ := service.GetAllDealerList(orgId)
  2629. for _, it := range dealerList {
  2630. if dealerName == it.DealerName {
  2631. dealer_id = it.ID
  2632. }
  2633. }
  2634. good.Dealer = dealer_id
  2635. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  2636. utils.ErrorLog("pinyin")
  2637. return
  2638. }
  2639. pinyin := goodNameM["pinyin"].(string)
  2640. good.Pinyin = pinyin
  2641. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  2642. utils.ErrorLog("wubi")
  2643. return
  2644. }
  2645. wubi := goodNameM["wubi"].(string)
  2646. good.Wubi = wubi
  2647. buy_prices := goodNameM["buy_price"].(string)
  2648. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  2649. good.BuyPrice = buy_price
  2650. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  2651. utils.ErrorLog("social_security_directory_code")
  2652. return
  2653. }
  2654. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2655. good.SocialSecurityDirectoryCode = social_security_directory_code
  2656. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  2657. utils.ErrorLog("is_special_diseases")
  2658. return
  2659. }
  2660. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2661. good.IsSpecialDiseases = is_special_diseases
  2662. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  2663. utils.ErrorLog("is_record")
  2664. return
  2665. }
  2666. is_record := int64(goodNameM["is_record"].(float64))
  2667. good.IsRecord = is_record
  2668. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  2669. utils.ErrorLog("good_status")
  2670. return
  2671. }
  2672. good_status := goodNameM["good_status"].(string)
  2673. good.GoodStatus = good_status
  2674. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  2675. utils.ErrorLog("medical_insurance_number")
  2676. return
  2677. }
  2678. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2679. good.MedicalInsuranceNumber = medical_insurance_number
  2680. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  2681. utils.ErrorLog("production_type")
  2682. return
  2683. }
  2684. production_type := goodNameM["production_type"].(string)
  2685. good.ProductionType = production_type
  2686. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  2687. utils.ErrorLog("remark")
  2688. return
  2689. }
  2690. remark := goodNameM["remark"].(string)
  2691. good.Remark = remark
  2692. statistics_category := goodNameM["statistics_category"].(string)
  2693. var categoryName = "统计分类"
  2694. var statistic_id int64
  2695. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  2696. if len(statistics_category) != 0 {
  2697. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  2698. if errcodecagegory == gorm.ErrRecordNotFound {
  2699. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  2700. dataconfig := models.DictDataconfig{
  2701. ParentId: drugDataConfig.ID,
  2702. Module: "system",
  2703. OrgId: orgId,
  2704. Name: statistics_category,
  2705. FieldName: "",
  2706. Value: dicConfigThree.Value + 1,
  2707. CreatedTime: "",
  2708. UpdatedTime: "",
  2709. CreateUserId: adminUserInfo.AdminUser.Id,
  2710. Status: 1,
  2711. Remark: "",
  2712. DeleteIdSystem: 0,
  2713. Title: "",
  2714. Content: "",
  2715. Order: 0,
  2716. Code: "",
  2717. }
  2718. service.CreatedDicConfig(&dataconfig)
  2719. }
  2720. }
  2721. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  2722. for _, it := range parentDataConfig {
  2723. if statistics_category == it.Name {
  2724. statistic_id = int64(it.Value)
  2725. }
  2726. }
  2727. good.StatisticsCategory = statistic_id
  2728. special_medical := goodNameM["special_medical"].(string)
  2729. good.SpecialMedical = special_medical
  2730. goods = append(goods, &good)
  2731. }
  2732. export_time := time.Now().Unix()
  2733. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2734. if len(goods) > 0 {
  2735. for _, item := range goods {
  2736. goodInfo := models.GoodInfo{
  2737. GoodName: item.GoodName,
  2738. SpecificationName: item.SpecificationName,
  2739. GoodKind: item.GoodKind,
  2740. GoodTypeId: item.GoodTypeId,
  2741. Dealer: item.Dealer,
  2742. GoodUnit: item.GoodUnit,
  2743. IsRecord: item.IsRecord,
  2744. IsSpecialDiseases: item.IsSpecialDiseases,
  2745. Manufacturer: item.Manufacturer,
  2746. Pinyin: item.Pinyin,
  2747. GoodStatus: item.GoodStatus,
  2748. ProductionType: item.ProductionType,
  2749. Remark: item.Remark,
  2750. RetailPrice: item.RetailPrice,
  2751. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  2752. SpecialMedical: item.SpecialMedical,
  2753. Wubi: item.Wubi,
  2754. StockWarnCount: item.StockWarnCount,
  2755. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  2756. OrgId: orgId,
  2757. Status: 1,
  2758. Ctime: time.Now().Unix(),
  2759. StatisticsCategory: item.StatisticsCategory,
  2760. GoodCode: item.GoodCode,
  2761. BuyPrice: item.BuyPrice,
  2762. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  2763. }
  2764. //查询同种耗材名称同种类型同种规格的耗材是否存在
  2765. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2766. if errcodegood == gorm.ErrRecordNotFound {
  2767. service.CreateGoodsInfomation(&goodInfo)
  2768. } else if errcodegood == nil {
  2769. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2770. }
  2771. log := models.ExportLog{
  2772. LogType: 5,
  2773. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2774. TotalNum: int64(len(total_goods)),
  2775. FailNum: int64(len(errLogs)),
  2776. SuccessNum: int64(len(goods)),
  2777. CreateTime: time.Now().Unix(),
  2778. UpdateTime: time.Now().Unix(),
  2779. ExportTime: export_time,
  2780. Status: 1,
  2781. }
  2782. service.CreateExportLog(&log)
  2783. this.ServeSuccessJSON(map[string]interface{}{
  2784. "msg": "导入成功",
  2785. "total_num": len(total_goods),
  2786. "success_num": len(goods),
  2787. "fail_num": int64(len(errLogs)),
  2788. })
  2789. }
  2790. } else {
  2791. log := models.ExportLog{
  2792. LogType: 5,
  2793. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2794. TotalNum: int64(len(total_goods)),
  2795. FailNum: int64(len(errLogs)),
  2796. SuccessNum: int64(len(goods)),
  2797. CreateTime: time.Now().Unix(),
  2798. UpdateTime: time.Now().Unix(),
  2799. ExportTime: export_time,
  2800. Status: 1,
  2801. }
  2802. service.CreateExportLog(&log)
  2803. this.ServeSuccessJSON(map[string]interface{}{
  2804. "msg": "导入成功",
  2805. "total_num": len(total_goods),
  2806. "success_num": len(goods),
  2807. "fail_num": int64(len(errLogs)),
  2808. })
  2809. }
  2810. }
  2811. func (this *StockManagerApiController) AddDrugInformation() {
  2812. adminUser := this.GetAdminUserInfo()
  2813. orgId := adminUser.CurrentOrgId
  2814. dataBody := make(map[string]interface{}, 0)
  2815. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2816. if err != nil {
  2817. utils.ErrorLog(err.Error())
  2818. return
  2819. }
  2820. utils.ErrorLog("%v", dataBody)
  2821. var drugList []*models.BaseDrugLib
  2822. var total_goods []interface{}
  2823. tempDrugs := dataBody["drugs"].([]interface{})
  2824. total_goods = tempDrugs
  2825. for index, drugMap := range tempDrugs {
  2826. goodNameM := drugMap.(map[string]interface{})
  2827. var drug models.BaseDrugLib
  2828. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  2829. utils.ErrorLog("drug_name")
  2830. return
  2831. }
  2832. drug_name, _ := goodNameM["drug_name"].(string)
  2833. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2834. err_log := models.ExportErrLog{
  2835. LogType: 4,
  2836. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2837. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  2838. Status: 1,
  2839. CreateTime: time.Now().Unix(),
  2840. UpdateTime: time.Now().Unix(),
  2841. ExportTime: time.Now().Unix(),
  2842. }
  2843. service.CreateExportErrLog(&err_log)
  2844. continue
  2845. }
  2846. drug.DrugName = drug_name
  2847. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  2848. utils.ErrorLog("min_number")
  2849. return
  2850. }
  2851. min_number, _ := goodNameM["min_number"].(string)
  2852. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  2853. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2854. err_log := models.ExportErrLog{
  2855. LogType: 4,
  2856. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2857. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  2858. Status: 1,
  2859. CreateTime: time.Now().Unix(),
  2860. UpdateTime: time.Now().Unix(),
  2861. ExportTime: time.Now().Unix(),
  2862. }
  2863. service.CreateExportErrLog(&err_log)
  2864. continue
  2865. }
  2866. drug.MinNumber = minNumber
  2867. min_unit := goodNameM["min_unit"].(string)
  2868. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  2869. err_log := models.ExportErrLog{
  2870. LogType: 4,
  2871. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2872. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  2873. Status: 1,
  2874. CreateTime: time.Now().Unix(),
  2875. UpdateTime: time.Now().Unix(),
  2876. ExportTime: time.Now().Unix(),
  2877. }
  2878. service.CreateExportErrLog(&err_log)
  2879. continue
  2880. }
  2881. drug.MinUnit = min_unit
  2882. dose := goodNameM["dose"].(float64)
  2883. if dose < 0 { //名字为空则生成一条导入错误日志
  2884. err_log := models.ExportErrLog{
  2885. LogType: 4,
  2886. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2887. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  2888. Status: 1,
  2889. CreateTime: time.Now().Unix(),
  2890. UpdateTime: time.Now().Unix(),
  2891. ExportTime: time.Now().Unix(),
  2892. }
  2893. service.CreateExportErrLog(&err_log)
  2894. continue
  2895. }
  2896. drug.Dose = dose
  2897. max_unit_id := goodNameM["max_unit"].(string)
  2898. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  2899. err_log := models.ExportErrLog{
  2900. LogType: 4,
  2901. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2902. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  2903. Status: 1,
  2904. CreateTime: time.Now().Unix(),
  2905. UpdateTime: time.Now().Unix(),
  2906. ExportTime: time.Now().Unix(),
  2907. }
  2908. service.CreateExportErrLog(&err_log)
  2909. continue
  2910. }
  2911. drug.MaxUnit = max_unit_id
  2912. max_unit := goodNameM["max_unit"].(string)
  2913. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  2914. err_log := models.ExportErrLog{
  2915. LogType: 4,
  2916. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2917. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  2918. Status: 1,
  2919. CreateTime: time.Now().Unix(),
  2920. UpdateTime: time.Now().Unix(),
  2921. ExportTime: time.Now().Unix(),
  2922. }
  2923. service.CreateExportErrLog(&err_log)
  2924. continue
  2925. }
  2926. drug.MaxUnit = max_unit
  2927. delivery_way := goodNameM["delivery_way"].(string)
  2928. if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
  2929. err_log := models.ExportErrLog{
  2930. LogType: 4,
  2931. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2932. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  2933. Status: 1,
  2934. CreateTime: time.Now().Unix(),
  2935. UpdateTime: time.Now().Unix(),
  2936. ExportTime: time.Now().Unix(),
  2937. }
  2938. service.CreateExportErrLog(&err_log)
  2939. continue
  2940. }
  2941. drug.DeliveryWay = delivery_way
  2942. execution_frequency := goodNameM["execution_frequency"].(string)
  2943. if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
  2944. err_log := models.ExportErrLog{
  2945. LogType: 4,
  2946. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2947. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  2948. Status: 1,
  2949. CreateTime: time.Now().Unix(),
  2950. UpdateTime: time.Now().Unix(),
  2951. ExportTime: time.Now().Unix(),
  2952. }
  2953. service.CreateExportErrLog(&err_log)
  2954. continue
  2955. }
  2956. drug.ExecutionFrequency = execution_frequency
  2957. drug_day := goodNameM["drug_day"].(string)
  2958. if len(drug_day) == 0 { //名字为空则生成一条导入错误日志
  2959. err_log := models.ExportErrLog{
  2960. LogType: 4,
  2961. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2962. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  2963. Status: 1,
  2964. CreateTime: time.Now().Unix(),
  2965. UpdateTime: time.Now().Unix(),
  2966. ExportTime: time.Now().Unix(),
  2967. }
  2968. service.CreateExportErrLog(&err_log)
  2969. continue
  2970. }
  2971. drug.DrugDay = drug_day
  2972. drug_type := goodNameM["drug_type"].(string)
  2973. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  2974. err_log := models.ExportErrLog{
  2975. LogType: 4,
  2976. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2977. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  2978. Status: 1,
  2979. CreateTime: time.Now().Unix(),
  2980. UpdateTime: time.Now().Unix(),
  2981. ExportTime: time.Now().Unix(),
  2982. }
  2983. service.CreateExportErrLog(&err_log)
  2984. continue
  2985. }
  2986. var drug_type_id int64
  2987. var drugType = "药品类型"
  2988. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  2989. if len(drug_type) != 0 {
  2990. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  2991. if errcodes == gorm.ErrRecordNotFound {
  2992. //获取该型号最后一条数据型号
  2993. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  2994. dataconfig := models.DictDataconfig{
  2995. ParentId: drugconfig.ID,
  2996. Module: "system",
  2997. OrgId: orgId,
  2998. Name: drug_type,
  2999. FieldName: "",
  3000. Value: config.Value + 1,
  3001. CreatedTime: "",
  3002. UpdatedTime: "",
  3003. CreateUserId: adminUser.AdminUser.Id,
  3004. Status: 1,
  3005. Remark: "",
  3006. DeleteIdSystem: 0,
  3007. Title: "",
  3008. Content: "",
  3009. Order: 0,
  3010. Code: "",
  3011. }
  3012. service.CreatedDicConfig(&dataconfig)
  3013. }
  3014. }
  3015. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  3016. for _, it := range drugTypeList {
  3017. if drug_type == it.Name {
  3018. drug_type_id = int64(it.Value)
  3019. }
  3020. }
  3021. drug.DrugType = drug_type_id
  3022. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  3023. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  3024. err_log := models.ExportErrLog{
  3025. LogType: 4,
  3026. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3027. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  3028. Status: 1,
  3029. CreateTime: time.Now().Unix(),
  3030. UpdateTime: time.Now().Unix(),
  3031. ExportTime: time.Now().Unix(),
  3032. }
  3033. service.CreateExportErrLog(&err_log)
  3034. continue
  3035. }
  3036. drug.DrugStockLimit = drug_stock_limit
  3037. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  3038. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  3039. err_log := models.ExportErrLog{
  3040. LogType: 4,
  3041. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3042. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  3043. Status: 1,
  3044. CreateTime: time.Now().Unix(),
  3045. UpdateTime: time.Now().Unix(),
  3046. ExportTime: time.Now().Unix(),
  3047. }
  3048. service.CreateExportErrLog(&err_log)
  3049. continue
  3050. }
  3051. drug.DrugOriginPlace = drug_origin_place
  3052. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  3053. if len(drug_dosage_form) == 0 {
  3054. err_log := models.ExportErrLog{
  3055. LogType: 4,
  3056. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3057. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  3058. Status: 1,
  3059. CreateTime: time.Now().Unix(),
  3060. UpdateTime: time.Now().Unix(),
  3061. ExportTime: time.Now().Unix(),
  3062. }
  3063. service.CreateExportErrLog(&err_log)
  3064. continue
  3065. }
  3066. var drug_dosage = "药品剂型"
  3067. var drug_dosage_form_id int64
  3068. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  3069. if len(drug_dosage_form) != 0 {
  3070. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  3071. if errcodess == gorm.ErrRecordNotFound {
  3072. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  3073. dataconfig := models.DictDataconfig{
  3074. ParentId: drugDosageconfig.ID,
  3075. Module: "system",
  3076. OrgId: orgId,
  3077. Name: drug_dosage_form,
  3078. FieldName: "",
  3079. Value: configOne.Value + 1,
  3080. CreatedTime: "",
  3081. UpdatedTime: "",
  3082. CreateUserId: adminUser.AdminUser.Id,
  3083. Status: 1,
  3084. Remark: "",
  3085. DeleteIdSystem: 0,
  3086. Title: "",
  3087. Content: "",
  3088. Order: 0,
  3089. Code: "",
  3090. }
  3091. service.CreatedDicConfig(&dataconfig)
  3092. }
  3093. }
  3094. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  3095. for _, it := range drugDosageList {
  3096. if drug_dosage_form == it.Name {
  3097. drug_dosage_form_id = int64(it.Value)
  3098. }
  3099. }
  3100. drug.DrugDosageForm = drug_dosage_form_id
  3101. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  3102. var medical_insurance_level_id int64
  3103. if len(medical_insurance_level) == 0 { //名字为空则生成一条导入错误日志
  3104. err_log := models.ExportErrLog{
  3105. LogType: 4,
  3106. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3107. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  3108. Status: 1,
  3109. CreateTime: time.Now().Unix(),
  3110. UpdateTime: time.Now().Unix(),
  3111. ExportTime: time.Now().Unix(),
  3112. }
  3113. service.CreateExportErrLog(&err_log)
  3114. continue
  3115. }
  3116. var medicalInsuranceName = "医保等级"
  3117. medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
  3118. if len(medical_insurance_level) != 0 {
  3119. _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
  3120. if errcodemedical == gorm.ErrRecordNotFound {
  3121. medConfig, _ := service.GetLastDicConfig(medicalInsuranceConfig.ID, orgId)
  3122. dataconfig := models.DictDataconfig{
  3123. ParentId: medicalInsuranceConfig.ID,
  3124. Module: "system",
  3125. OrgId: orgId,
  3126. Name: medical_insurance_level,
  3127. FieldName: "",
  3128. Value: medConfig.Value + 1,
  3129. CreatedTime: "",
  3130. UpdatedTime: "",
  3131. CreateUserId: adminUser.AdminUser.Id,
  3132. Status: 1,
  3133. Remark: "",
  3134. DeleteIdSystem: 0,
  3135. Title: "",
  3136. Content: "",
  3137. Order: 0,
  3138. Code: "",
  3139. }
  3140. service.CreatedDicConfig(&dataconfig)
  3141. }
  3142. }
  3143. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
  3144. for _, it := range medicalInsuranceList {
  3145. if medical_insurance_level == it.Name {
  3146. medical_insurance_level_id = int64(it.Value)
  3147. }
  3148. }
  3149. drug.MedicalInsuranceLevel = medical_insurance_level_id
  3150. unit_matrixing := goodNameM["unit_matrixing"].(string)
  3151. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3152. err_log := models.ExportErrLog{
  3153. LogType: 4,
  3154. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3155. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
  3156. Status: 1,
  3157. CreateTime: time.Now().Unix(),
  3158. UpdateTime: time.Now().Unix(),
  3159. ExportTime: time.Now().Unix(),
  3160. }
  3161. service.CreateExportErrLog(&err_log)
  3162. continue
  3163. }
  3164. drug.UnitMatrixing = unit_matrixing
  3165. retail_prices := goodNameM["retail_price"].(string)
  3166. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3167. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3168. err_log := models.ExportErrLog{
  3169. LogType: 4,
  3170. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3171. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  3172. Status: 1,
  3173. CreateTime: time.Now().Unix(),
  3174. UpdateTime: time.Now().Unix(),
  3175. ExportTime: time.Now().Unix(),
  3176. }
  3177. service.CreateExportErrLog(&err_log)
  3178. continue
  3179. }
  3180. drug.RetailPrice = retail_price
  3181. packing_prices := goodNameM["packing_price"].(string)
  3182. packing_price, _ := strconv.ParseFloat(packing_prices, 64)
  3183. if packing_price <= 0 { //名字为空则生成一条导入错误日志
  3184. err_log := models.ExportErrLog{
  3185. LogType: 4,
  3186. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3187. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装零售价不能为空",
  3188. Status: 1,
  3189. CreateTime: time.Now().Unix(),
  3190. UpdateTime: time.Now().Unix(),
  3191. ExportTime: time.Now().Unix(),
  3192. }
  3193. service.CreateExportErrLog(&err_log)
  3194. continue
  3195. }
  3196. drug.RetailPrice = retail_price
  3197. last_prices := goodNameM["last_price"].(string)
  3198. last_price, _ := strconv.ParseFloat(last_prices, 64)
  3199. if last_price <= 0 { //名字为空则生成一条导入错误日志
  3200. err_log := models.ExportErrLog{
  3201. LogType: 4,
  3202. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3203. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  3204. Status: 1,
  3205. CreateTime: time.Now().Unix(),
  3206. UpdateTime: time.Now().Unix(),
  3207. ExportTime: time.Now().Unix(),
  3208. }
  3209. service.CreateExportErrLog(&err_log)
  3210. continue
  3211. }
  3212. drug.LastPrice = last_price
  3213. drug_classify := goodNameM["drug_classify"].(string)
  3214. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  3215. err_log := models.ExportErrLog{
  3216. LogType: 4,
  3217. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3218. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  3219. Status: 1,
  3220. CreateTime: time.Now().Unix(),
  3221. UpdateTime: time.Now().Unix(),
  3222. ExportTime: time.Now().Unix(),
  3223. }
  3224. service.CreateExportErrLog(&err_log)
  3225. continue
  3226. }
  3227. var drugClassify = "药物分类"
  3228. var drug_classify_id int64
  3229. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  3230. if len(drug_classify) != 0 {
  3231. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  3232. if errcodesClass == gorm.ErrRecordNotFound {
  3233. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  3234. dataconfig := models.DictDataconfig{
  3235. ParentId: drugClassifyConfig.ID,
  3236. Module: "system",
  3237. OrgId: orgId,
  3238. Name: drug_classify,
  3239. FieldName: "",
  3240. Value: drugClassConfig.Value + 1,
  3241. CreatedTime: "",
  3242. UpdatedTime: "",
  3243. CreateUserId: adminUser.AdminUser.Id,
  3244. Status: 1,
  3245. Remark: "",
  3246. DeleteIdSystem: 0,
  3247. Title: "",
  3248. Content: "",
  3249. Order: 0,
  3250. Code: "",
  3251. }
  3252. service.CreatedDicConfig(&dataconfig)
  3253. }
  3254. }
  3255. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  3256. for _, it := range drugClassList {
  3257. if drug_classify == it.Name {
  3258. drug_classify_id = int64(it.Value)
  3259. }
  3260. }
  3261. drug_dose := goodNameM["drug_dose"].(string)
  3262. if len(drug_dose) == 0 {
  3263. err_log := models.ExportErrLog{
  3264. LogType: 4,
  3265. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3266. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  3267. Status: 1,
  3268. CreateTime: time.Now().Unix(),
  3269. UpdateTime: time.Now().Unix(),
  3270. ExportTime: time.Now().Unix(),
  3271. }
  3272. service.CreateExportErrLog(&err_log)
  3273. continue
  3274. }
  3275. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  3276. drug.DrugDose = drugDoses
  3277. var units = "单位"
  3278. var unit_id int64
  3279. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  3280. if len(drugDoseUnit) == 0 {
  3281. err_log := models.ExportErrLog{
  3282. LogType: 4,
  3283. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3284. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  3285. Status: 1,
  3286. CreateTime: time.Now().Unix(),
  3287. UpdateTime: time.Now().Unix(),
  3288. ExportTime: time.Now().Unix(),
  3289. }
  3290. service.CreateExportErrLog(&err_log)
  3291. continue
  3292. }
  3293. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  3294. if len(drugDoseUnit) != 0 {
  3295. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  3296. if errcodedataconfig == gorm.ErrRecordNotFound {
  3297. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  3298. dataconfig := models.Dataconfig{
  3299. ParentId: dataConfig.ID,
  3300. Module: "hemodialysis",
  3301. OrgId: orgId,
  3302. Name: drugDoseUnit,
  3303. FieldName: "",
  3304. Value: childConfig.Value + 1,
  3305. CreatedTime: "",
  3306. UpdatedTime: "",
  3307. CreateUserId: adminUser.AdminUser.Id,
  3308. Status: 1,
  3309. Remark: "",
  3310. DeleteIdSystem: 0,
  3311. Title: "",
  3312. Content: "",
  3313. Order: 0,
  3314. Code: "",
  3315. FieldType: 0,
  3316. }
  3317. service.CreateDataConfig(&dataconfig)
  3318. }
  3319. }
  3320. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  3321. for _, it := range list {
  3322. if drugDoseUnit == it.Name {
  3323. unit_id = int64(it.Value)
  3324. }
  3325. }
  3326. drug.DrugDoseUnit = unit_id
  3327. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  3328. manufacturer := goodNameM["manufacturer"].(string)
  3329. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3330. err_log := models.ExportErrLog{
  3331. LogType: 4,
  3332. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3333. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  3334. Status: 1,
  3335. CreateTime: time.Now().Unix(),
  3336. UpdateTime: time.Now().Unix(),
  3337. ExportTime: time.Now().Unix(),
  3338. }
  3339. service.CreateExportErrLog(&err_log)
  3340. continue
  3341. }
  3342. if len(manufacturer) != 0 {
  3343. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  3344. if errcodema == gorm.ErrRecordNotFound {
  3345. manufactur := models.Manufacturer{
  3346. OrgId: orgId,
  3347. Status: 1,
  3348. ManufacturerName: manufacturer,
  3349. Ctime: time.Now().Unix(),
  3350. Creater: adminUser.AdminUser.Id,
  3351. }
  3352. service.CreateManufacturer(&manufactur)
  3353. }
  3354. }
  3355. var manufacturer_id int64
  3356. manufacturList, _ := service.GetAllManufacturerList(orgId)
  3357. for _, it := range manufacturList {
  3358. if manufacturer == it.ManufacturerName {
  3359. manufacturer_id = it.ID
  3360. }
  3361. }
  3362. drug.Manufacturer = manufacturer_id
  3363. dealer := goodNameM["dealer"].(string)
  3364. if len(dealer) != 0 {
  3365. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  3366. if errcodesdealer == gorm.ErrRecordNotFound {
  3367. dealerconfig := models.Dealer{
  3368. DealerName: dealer,
  3369. Status: 1,
  3370. OrgId: orgId,
  3371. Ctime: time.Now().Unix(),
  3372. Creater: adminUser.AdminUser.Id,
  3373. }
  3374. service.CreateDealer(&dealerconfig)
  3375. }
  3376. }
  3377. var dealer_id int64
  3378. dealerList, _ := service.GetAllDealerList(orgId)
  3379. for _, it := range dealerList {
  3380. if dealer == it.DealerName {
  3381. dealer_id = it.ID
  3382. }
  3383. }
  3384. drug.Dealer = dealer_id
  3385. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  3386. drug.LmtUsedFlag = lmt_used_flags
  3387. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  3388. utils.ErrorLog("drug_alias")
  3389. return
  3390. }
  3391. drug_alias, _ := goodNameM["drug_alias"].(string)
  3392. drug.DrugAlias = drug_alias
  3393. drug_category := goodNameM["drug_category"].(string)
  3394. var drugCategory = "药品类别"
  3395. var drug_category_id int64
  3396. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  3397. if len(drug_category) != 0 {
  3398. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  3399. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  3400. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  3401. dataconfig := models.DictDataconfig{
  3402. ParentId: drugCategoryConfig.ID,
  3403. Module: "system",
  3404. OrgId: orgId,
  3405. Name: drug_category,
  3406. FieldName: "",
  3407. Value: drugCategoryConfigSix.Value + 1,
  3408. CreatedTime: "",
  3409. UpdatedTime: "",
  3410. CreateUserId: adminUser.AdminUser.Id,
  3411. Status: 1,
  3412. Remark: "",
  3413. DeleteIdSystem: 0,
  3414. Title: "",
  3415. Content: "",
  3416. Order: 0,
  3417. Code: "",
  3418. }
  3419. service.CreatedDicConfig(&dataconfig)
  3420. }
  3421. }
  3422. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  3423. fmt.Println("drugCategoryList", drugCategoryList)
  3424. for _, it := range drugCategoryList {
  3425. if drug_category == it.Name {
  3426. drug_category_id = int64(it.Value)
  3427. }
  3428. }
  3429. drug.DrugCategory = drug_category_id
  3430. statistics_category := goodNameM["statistics_category"].(string)
  3431. var statisticsCategory = "统计分类"
  3432. var statistics_category_id int64
  3433. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3434. if len(statistics_category) != 0 {
  3435. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  3436. if errcodestatistc == gorm.ErrRecordNotFound {
  3437. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  3438. dataconfig := models.DictDataconfig{
  3439. ParentId: statistcConfig.ID,
  3440. Module: "system",
  3441. OrgId: orgId,
  3442. Name: statistics_category,
  3443. FieldName: "",
  3444. Value: staConfig.Value + 1,
  3445. CreatedTime: "",
  3446. UpdatedTime: "",
  3447. CreateUserId: adminUser.AdminUser.Id,
  3448. Status: 1,
  3449. Remark: "",
  3450. DeleteIdSystem: 0,
  3451. Title: "",
  3452. Content: "",
  3453. Order: 0,
  3454. Code: "",
  3455. }
  3456. service.CreatedDicConfig(&dataconfig)
  3457. }
  3458. }
  3459. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  3460. for _, it := range statisticsCategoryList {
  3461. if statistics_category == it.Name {
  3462. statistics_category_id = int64(it.Value)
  3463. }
  3464. }
  3465. drug.StatisticsCategory = statistics_category_id
  3466. number := goodNameM["number"].(string)
  3467. drug.Number = number
  3468. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  3469. drug.HospApprFlag = hosp_appr_flag
  3470. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3471. drug.MedicalInsuranceNumber = medical_insurance_number
  3472. pharmacology_category := goodNameM["pharmacology_category"].(string)
  3473. var pharmacology = "药理分类"
  3474. var pharmacology_category_id int64
  3475. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  3476. if len(pharmacology_category) != 0 {
  3477. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  3478. if errcodespharmacology == gorm.ErrRecordNotFound {
  3479. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  3480. dataconfig := models.DictDataconfig{
  3481. ParentId: pharmacologyConfig.ID,
  3482. Module: "system",
  3483. OrgId: orgId,
  3484. Name: pharmacology_category,
  3485. FieldName: "",
  3486. Value: dicConfig.Value + 1,
  3487. CreatedTime: "",
  3488. UpdatedTime: "",
  3489. CreateUserId: adminUser.AdminUser.Id,
  3490. Status: 1,
  3491. Remark: "",
  3492. DeleteIdSystem: 0,
  3493. Title: "",
  3494. Content: "",
  3495. Order: 0,
  3496. Code: "",
  3497. }
  3498. service.CreatedDicConfig(&dataconfig)
  3499. }
  3500. }
  3501. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  3502. for _, it := range pharmacologyList {
  3503. if pharmacology_category == it.Name {
  3504. pharmacology_category_id = int64(it.Value)
  3505. }
  3506. }
  3507. drug.PharmacologyCategory = pharmacology_category_id
  3508. code := goodNameM["code"].(string)
  3509. drug.Code = code
  3510. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3511. drug.IsSpecialDiseases = is_special_diseases
  3512. is_record := int64(goodNameM["is_record"].(float64))
  3513. drug.IsRecord = is_record
  3514. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  3515. drug.PrescriptionMark = prescription_mark
  3516. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3517. drug.SocialSecurityDirectoryCode = social_security_directory_code
  3518. record_date := goodNameM["record_date"].(string)
  3519. timeLayout := "2006-01-02"
  3520. loc, _ := time.LoadLocation("Local")
  3521. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3522. drug.RecordDate = theTime.Unix()
  3523. drug_remark := goodNameM["drug_remark"].(string)
  3524. drug.DrugRemark = drug_remark
  3525. drug_status := goodNameM["drug_status"].(string)
  3526. drug.DrugStatus = drug_status
  3527. limit_remark := goodNameM["limit_remark"].(string)
  3528. drug.LimitRemark = limit_remark
  3529. drug_control := goodNameM["drug_control"].(string)
  3530. var drugControl = "开药控制"
  3531. var drug_control_id int64
  3532. drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
  3533. if len(drug_control) != 0 {
  3534. _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
  3535. if errcodesdrugcontrol == gorm.ErrRecordNotFound {
  3536. drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
  3537. dataconfig := models.DictDataconfig{
  3538. ParentId: drugContorlConfig.ID,
  3539. Module: "system",
  3540. OrgId: orgId,
  3541. Name: drug_control,
  3542. FieldName: "",
  3543. Value: drugContorlConfigOne.Value + 1,
  3544. CreatedTime: "",
  3545. UpdatedTime: "",
  3546. CreateUserId: adminUser.AdminUser.Id,
  3547. Status: 1,
  3548. Remark: "",
  3549. DeleteIdSystem: 0,
  3550. Title: "",
  3551. Content: "",
  3552. Order: 0,
  3553. Code: "",
  3554. }
  3555. service.CreatedDicConfig(&dataconfig)
  3556. }
  3557. }
  3558. drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
  3559. for _, it := range drugContorlList {
  3560. if drug_control == it.Name {
  3561. drug_control_id = int64(it.Value)
  3562. }
  3563. }
  3564. drug.DrugControl = drug_control_id
  3565. drugList = append(drugList, &drug)
  3566. }
  3567. export_time := time.Now().Unix()
  3568. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3569. if len(drugList) > 0 {
  3570. for _, item := range drugList {
  3571. goodInfo := models.BaseDrugLib{
  3572. DrugName: item.DrugName,
  3573. DrugAlias: item.DrugAlias,
  3574. DrugSpec: item.DrugSpec,
  3575. DrugType: item.DrugType,
  3576. DrugStockLimit: item.DrugStockLimit,
  3577. DrugOriginPlace: item.DrugOriginPlace,
  3578. DrugDosageForm: item.DrugDosageForm,
  3579. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3580. MaxUnit: item.MaxUnit,
  3581. MinUnit: item.MinUnit,
  3582. UnitMatrixing: item.UnitMatrixing,
  3583. RetailPrice: item.RetailPrice,
  3584. LastPrice: item.LastPrice,
  3585. DrugClassify: item.DrugClassify,
  3586. Manufacturer: item.Manufacturer,
  3587. Dealer: item.Dealer,
  3588. OrgId: orgId,
  3589. Status: 1,
  3590. Ctime: time.Now().Unix(),
  3591. Pinyin: item.Pinyin,
  3592. Wubi: item.Wubi,
  3593. DrugAliasPinyin: item.DrugAliasPinyin,
  3594. DrugAliasWubi: item.DrugAliasWubi,
  3595. DrugControl: item.DrugControl,
  3596. Number: item.Number,
  3597. HospApprFlag: item.HospApprFlag,
  3598. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3599. PharmacologyCategory: item.PharmacologyCategory,
  3600. StatisticsCategory: item.StatisticsCategory,
  3601. Code: item.Code,
  3602. IsSpecialDiseases: item.IsSpecialDiseases,
  3603. IsRecord: item.IsRecord,
  3604. PrescriptionMark: item.PrescriptionMark,
  3605. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3606. RecordDate: item.RecordDate,
  3607. DrugRemark: item.DrugRemark,
  3608. DrugStatus: item.DrugStatus,
  3609. LimitRemark: item.LimitRemark,
  3610. DrugCategory: item.DrugCategory,
  3611. DrugDose: item.DrugDose,
  3612. DrugDoseUnit: item.DrugDoseUnit,
  3613. LmtUsedFlag: item.LmtUsedFlag,
  3614. DrugDay: item.DrugDay,
  3615. DeliveryWay: item.DeliveryWay,
  3616. ExecutionFrequency: item.ExecutionFrequency,
  3617. DoseUnit: item.DoseUnit,
  3618. }
  3619. //查询同种药品同种规格是否存在
  3620. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.MaxUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  3621. if drugerror == gorm.ErrRecordNotFound {
  3622. service.CreateDrugsInfomation(&goodInfo)
  3623. } else if drugerror == nil {
  3624. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  3625. }
  3626. log := models.ExportLog{
  3627. LogType: 4,
  3628. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3629. TotalNum: int64(len(total_goods)),
  3630. FailNum: int64(len(errLogs)),
  3631. SuccessNum: int64(len(drugList)),
  3632. CreateTime: time.Now().Unix(),
  3633. UpdateTime: time.Now().Unix(),
  3634. ExportTime: export_time,
  3635. Status: 1,
  3636. }
  3637. service.CreateExportLog(&log)
  3638. this.ServeSuccessJSON(map[string]interface{}{
  3639. "msg": "导入成功",
  3640. "total_num": len(total_goods),
  3641. "success_num": len(drugList),
  3642. "fail_num": int64(len(errLogs)),
  3643. })
  3644. }
  3645. } else {
  3646. log := models.ExportLog{
  3647. LogType: 4,
  3648. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3649. TotalNum: int64(len(total_goods)),
  3650. FailNum: int64(len(errLogs)),
  3651. SuccessNum: int64(len(drugList)),
  3652. CreateTime: time.Now().Unix(),
  3653. UpdateTime: time.Now().Unix(),
  3654. ExportTime: export_time,
  3655. Status: 1,
  3656. }
  3657. service.CreateExportLog(&log)
  3658. this.ServeSuccessJSON(map[string]interface{}{
  3659. "msg": "导入成功",
  3660. "total_num": len(total_goods),
  3661. "success_num": len(drugList),
  3662. "fail_num": int64(len(errLogs)),
  3663. })
  3664. }
  3665. }
  3666. func (this *StockManagerApiController) GetInitializtion() {
  3667. orgId := this.GetAdminUserInfo().CurrentOrgId
  3668. var drugCategory = "药品类别"
  3669. var drugType = "药品类型"
  3670. var drugDosageForm = "药品剂型"
  3671. var medicalInsuranceLevel = "医保等级"
  3672. var drugControl = "开药控制"
  3673. var drugClassify = "药物分类"
  3674. var statisticsCategory = "统计分类"
  3675. var pharmacologyCategory = "药理分类"
  3676. var goodKind = "耗材种类"
  3677. var tubeColor = "试管颜色"
  3678. var costClassify = "费用类别"
  3679. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3680. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3681. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  3682. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  3683. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  3684. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  3685. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  3686. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  3687. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  3688. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  3689. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  3690. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  3691. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3692. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  3693. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  3694. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  3695. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  3696. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  3697. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  3698. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  3699. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  3700. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  3701. this.ServeSuccessJSON(map[string]interface{}{
  3702. "drugCategoryList": drugCategoryList,
  3703. "drugTypeList": drugTypeList,
  3704. "drugDosageFormList": drugDosageFormList,
  3705. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  3706. "drugControlList": drugControlList,
  3707. "drugClassifyList": drugClassifyList,
  3708. "statisticsCategoryList": statisticsCategoryList,
  3709. "pharmacologyCategoryList": pharmacologyCategoryList,
  3710. "goodKindList": goodKindList,
  3711. "tubeColorList": tubeColorList,
  3712. "costClassifyList": costClassifyList,
  3713. })
  3714. }
  3715. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  3716. adminUserInfo := this.GetAdminUserInfo()
  3717. orgId := adminUserInfo.CurrentOrgId
  3718. list, _ := service.GetWarehouseOrderInfoList(orgId)
  3719. this.ServeSuccessJSON(map[string]interface{}{
  3720. "list": list,
  3721. })
  3722. }
  3723. func (this *StockManagerApiController) PostSearchGoodList() {
  3724. keyword := this.GetString("keyword")
  3725. adminUserInfo := this.GetAdminUserInfo()
  3726. orgId := adminUserInfo.CurrentOrgId
  3727. list, _ := service.GetSearchGoodList(keyword, orgId)
  3728. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3729. dealerList, _ := service.GetAllDealerList(orgId)
  3730. this.ServeSuccessJSON(map[string]interface{}{
  3731. "list": list,
  3732. "manufacturerList": manufacturerList,
  3733. "dealerList": dealerList,
  3734. })
  3735. }
  3736. func (this *StockManagerApiController) GetAllStockList() {
  3737. page, _ := this.GetInt64("page", -1)
  3738. limit, _ := this.GetInt64("limit", -1)
  3739. start_time := this.GetString("start_time")
  3740. end_time := this.GetString("end_time")
  3741. types, _ := this.GetInt64("type", 0)
  3742. keywords := this.GetString("keywords")
  3743. timeLayout := "2006-01-02"
  3744. loc, _ := time.LoadLocation("Local")
  3745. var startTime int64
  3746. if len(start_time) > 0 {
  3747. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3748. if err != nil {
  3749. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3750. return
  3751. }
  3752. startTime = theTime.Unix()
  3753. }
  3754. var endTime int64
  3755. if len(end_time) > 0 {
  3756. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3757. if err != nil {
  3758. utils.ErrorLog(err.Error())
  3759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3760. return
  3761. }
  3762. endTime = theTime.Unix()
  3763. }
  3764. adminUserInfo := this.GetAdminUserInfo()
  3765. orgId := adminUserInfo.CurrentOrgId
  3766. list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId)
  3767. fmt.Println("耗材总计23323232232323232323", total)
  3768. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3769. this.ServeSuccessJSON(map[string]interface{}{
  3770. "list": list,
  3771. "total": total,
  3772. "manufacturerList": manufacturerList,
  3773. })
  3774. }
  3775. func (this *StockManagerApiController) GetStockListById() {
  3776. id, _ := this.GetInt64("id")
  3777. adminUserInfo := this.GetAdminUserInfo()
  3778. orgId := adminUserInfo.CurrentOrgId
  3779. limit, _ := this.GetInt64("limit")
  3780. page, _ := this.GetInt64("page")
  3781. timeLayout := "2006-01-02"
  3782. loc, _ := time.LoadLocation("Local")
  3783. start_time := this.GetString("start_time")
  3784. end_time := this.GetString("end_time")
  3785. var startTime int64
  3786. if len(start_time) > 0 {
  3787. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3788. if err != nil {
  3789. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3790. return
  3791. }
  3792. startTime = theTime.Unix()
  3793. }
  3794. var endTime int64
  3795. if len(end_time) > 0 {
  3796. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3797. if err != nil {
  3798. utils.ErrorLog(err.Error())
  3799. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3800. return
  3801. }
  3802. endTime = theTime.Unix()
  3803. }
  3804. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3805. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime)
  3806. this.ServeSuccessJSON(map[string]interface{}{
  3807. "list": list,
  3808. "total": total,
  3809. "manufacturerList": manufacturerList,
  3810. })
  3811. }
  3812. func (this *StockManagerApiController) GetStockOutList() {
  3813. id, _ := this.GetInt64("id")
  3814. adminUserInfo := this.GetAdminUserInfo()
  3815. orgId := adminUserInfo.CurrentOrgId
  3816. limit, _ := this.GetInt64("limit")
  3817. page, _ := this.GetInt64("page")
  3818. timeLayout := "2006-01-02"
  3819. loc, _ := time.LoadLocation("Local")
  3820. start_time := this.GetString("start_time")
  3821. end_time := this.GetString("end_time")
  3822. is_sys, _ := this.GetInt64("is_sys")
  3823. var startTime int64
  3824. if len(start_time) > 0 {
  3825. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3826. if err != nil {
  3827. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3828. return
  3829. }
  3830. startTime = theTime.Unix()
  3831. }
  3832. var endTime int64
  3833. if len(end_time) > 0 {
  3834. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3835. if err != nil {
  3836. utils.ErrorLog(err.Error())
  3837. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3838. return
  3839. }
  3840. endTime = theTime.Unix()
  3841. }
  3842. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  3843. this.ServeSuccessJSON(map[string]interface{}{
  3844. "outList": outList,
  3845. "total": total,
  3846. })
  3847. }
  3848. func (this *StockManagerApiController) GetStockDrugCount() {
  3849. adminUserInfo := this.GetAdminUserInfo()
  3850. orgId := adminUserInfo.CurrentOrgId
  3851. fmt.Println(orgId)
  3852. timeLayout := "2006-01-02"
  3853. loc, _ := time.LoadLocation("Local")
  3854. start_time := this.GetString("start_time")
  3855. end_time := this.GetString("end_time")
  3856. var startTime int64
  3857. if len(start_time) > 0 {
  3858. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3859. if err != nil {
  3860. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3861. return
  3862. }
  3863. startTime = theTime.Unix()
  3864. }
  3865. var endTime int64
  3866. if len(end_time) > 0 {
  3867. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3868. if err != nil {
  3869. utils.ErrorLog(err.Error())
  3870. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3871. return
  3872. }
  3873. endTime = theTime.Unix()
  3874. }
  3875. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  3876. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  3877. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  3878. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  3879. this.ServeSuccessJSON(map[string]interface{}{
  3880. "count": count,
  3881. "outList": outList,
  3882. "autoCount": autoCount,
  3883. "totalCount": totalCount,
  3884. })
  3885. }
  3886. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  3887. ids := this.GetString("id")
  3888. idsArray := strings.Split(ids, ",")
  3889. orgId := this.GetAdminUserInfo().CurrentOrgId
  3890. order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
  3891. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  3892. //获取该耗材的最后一条数据
  3893. info, _ := service.GetLastWarehouseOutInfo(idsArray, orgId)
  3894. fmt.Println("info323e2342342342432342342432", info)
  3895. this.ServeSuccessJSON(map[string]interface{}{
  3896. "order": order,
  3897. "list": list,
  3898. "info": info,
  3899. })
  3900. }
  3901. func (this *StockManagerApiController) GetOrderDetailById() {
  3902. id, _ := this.GetInt64("id")
  3903. good_id, _ := this.GetInt64("good_id")
  3904. record_time, _ := this.GetInt64("record_time")
  3905. orgId := this.GetAdminUserInfo().CurrentOrgId
  3906. //自动出库
  3907. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  3908. //手动出库
  3909. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  3910. stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
  3911. if err == nil {
  3912. this.ServeSuccessJSON(map[string]interface{}{
  3913. "list": userDetails,
  3914. "total": total,
  3915. "info": info,
  3916. "stockFlowList": stockFlowList,
  3917. })
  3918. } else {
  3919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3920. return
  3921. }
  3922. }
  3923. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  3924. id, _ := this.GetInt64("id", 0)
  3925. orgId := this.GetAdminUserInfo().CurrentOrgId
  3926. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  3927. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3928. dealerList, _ := service.GetAllDealerList(orgId)
  3929. goodType, _ := service.GetAllGoodType(orgId)
  3930. this.ServeSuccessJSON(map[string]interface{}{
  3931. "list": warehouseOutInfo,
  3932. "dealerList": dealerList,
  3933. "manufacturerList": manufacturerList,
  3934. "goodType": goodType,
  3935. })
  3936. }
  3937. func (this *StockManagerApiController) GetExprotStockList() {
  3938. adminUserInfo := this.GetAdminUserInfo()
  3939. orgId := adminUserInfo.CurrentOrgId
  3940. timeLayout := "2006-01-02"
  3941. loc, _ := time.LoadLocation("Local")
  3942. start_time := this.GetString("start_time")
  3943. end_time := this.GetString("end_time")
  3944. idArray := this.GetString("id")
  3945. ids := strings.Split(idArray, ",")
  3946. var startTime int64
  3947. if len(start_time) > 0 {
  3948. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3949. if err != nil {
  3950. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3951. return
  3952. }
  3953. startTime = theTime.Unix()
  3954. }
  3955. var endTime int64
  3956. if len(end_time) > 0 {
  3957. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3958. if err != nil {
  3959. utils.ErrorLog(err.Error())
  3960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3961. return
  3962. }
  3963. endTime = theTime.Unix()
  3964. }
  3965. fmt.Println("ids2222222222222222", ids)
  3966. list, _ := service.GetExprotStockList(orgId, ids, startTime, endTime)
  3967. this.ServeSuccessJSON(map[string]interface{}{
  3968. "list": list,
  3969. })
  3970. }
  3971. func (this *StockManagerApiController) GetOutExprotList() {
  3972. adminUserInfo := this.GetAdminUserInfo()
  3973. orgId := adminUserInfo.CurrentOrgId
  3974. timeLayout := "2006-01-02"
  3975. loc, _ := time.LoadLocation("Local")
  3976. start_time := this.GetString("start_time")
  3977. end_time := this.GetString("end_time")
  3978. idArray := this.GetString("id")
  3979. ids := strings.Split(idArray, ",")
  3980. fmt.Println("ids2222222222", ids)
  3981. var startTime int64
  3982. if len(start_time) > 0 {
  3983. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3984. if err != nil {
  3985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3986. return
  3987. }
  3988. startTime = theTime.Unix()
  3989. }
  3990. var endTime int64
  3991. if len(end_time) > 0 {
  3992. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3993. if err != nil {
  3994. utils.ErrorLog(err.Error())
  3995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3996. return
  3997. }
  3998. endTime = theTime.Unix()
  3999. }
  4000. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  4001. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  4002. this.ServeSuccessJSON(map[string]interface{}{
  4003. "list": list,
  4004. "count": outCount,
  4005. })
  4006. }
  4007. func (this *StockManagerApiController) GetSingleCancelOrder() {
  4008. id, _ := this.GetInt64("id")
  4009. adminUserInfo := this.GetAdminUserInfo()
  4010. orgId := adminUserInfo.CurrentOrgId
  4011. order, _ := service.GetSingleCancelOrder(id, orgId)
  4012. this.ServeSuccessJSON(map[string]interface{}{
  4013. "list": order,
  4014. })
  4015. }
  4016. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  4017. id := this.GetString("id")
  4018. idStr := strings.Split(id, ",")
  4019. orgId := this.GetAdminUserInfo().CurrentOrgId
  4020. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  4021. this.ServeSuccessJSON(map[string]interface{}{
  4022. "list": list,
  4023. })
  4024. }
  4025. func (this *StockManagerApiController) GetStockBatchNumber() {
  4026. id, _ := this.GetInt64("id")
  4027. orgId := this.GetAdminUserInfo().CurrentOrgId
  4028. list, _ := service.GetStockBatchNumber(id, orgId)
  4029. this.ServeSuccessJSON(map[string]interface{}{
  4030. "list": list,
  4031. })
  4032. }
  4033. func (this *StockManagerApiController) GetStockFlow() {
  4034. limit, _ := this.GetInt64("limit")
  4035. page, _ := this.GetInt64("page")
  4036. good_id, _ := this.GetInt64("good_id")
  4037. consumable_type, _ := this.GetInt64("is_sys")
  4038. adminUserInfo := this.GetAdminUserInfo()
  4039. orgId := adminUserInfo.CurrentOrgId
  4040. timeLayout := "2006-01-02"
  4041. loc, _ := time.LoadLocation("Local")
  4042. start_time := this.GetString("start_time")
  4043. end_time := this.GetString("end_time")
  4044. var startTime int64
  4045. if len(start_time) > 0 {
  4046. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4047. if err != nil {
  4048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4049. return
  4050. }
  4051. startTime = theTime.Unix()
  4052. }
  4053. var endTime int64
  4054. if len(end_time) > 0 {
  4055. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4056. if err != nil {
  4057. utils.ErrorLog(err.Error())
  4058. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4059. return
  4060. }
  4061. endTime = theTime.Unix()
  4062. }
  4063. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  4064. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4065. this.ServeSuccessJSON(map[string]interface{}{
  4066. "list": list,
  4067. "total": total,
  4068. "manufacturerList": manufacturerList,
  4069. })
  4070. }
  4071. func (this *StockManagerApiController) GetCancelExportList() {
  4072. adminUserInfo := this.GetAdminUserInfo()
  4073. orgId := adminUserInfo.CurrentOrgId
  4074. timeLayout := "2006-01-02"
  4075. loc, _ := time.LoadLocation("Local")
  4076. start_time := this.GetString("start_time")
  4077. end_time := this.GetString("end_time")
  4078. idArray := this.GetString("order_id")
  4079. fmt.Println("232323232323232232", idArray)
  4080. ids := strings.Split(idArray, ",")
  4081. var startTime int64
  4082. if len(start_time) > 0 {
  4083. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4084. if err != nil {
  4085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4086. return
  4087. }
  4088. startTime = theTime.Unix()
  4089. }
  4090. var endTime int64
  4091. if len(end_time) > 0 {
  4092. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4093. if err != nil {
  4094. utils.ErrorLog(err.Error())
  4095. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4096. return
  4097. }
  4098. endTime = theTime.Unix()
  4099. }
  4100. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  4101. this.ServeSuccessJSON(map[string]interface{}{
  4102. "list": list,
  4103. })
  4104. }