stock_in_api_controller.go 199KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138
  1. package controllers
  2. import (
  3. "Xcx_New/enums"
  4. "Xcx_New/models"
  5. "Xcx_New/service"
  6. "Xcx_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. beego.Router("/api/stock/postsearchgoodwarehouselist", &StockManagerApiController{}, "Get:GetSearchGoodWarehouseList")
  79. beego.Router("/api/stock/saveadjustprice", &StockManagerApiController{}, "Post:SaveAdjuestPrice")
  80. beego.Router("/api/stock/getallstockprice", &StockManagerApiController{}, "Get:GetAllStockPrice")
  81. beego.Router("/api/stock/savecheckedprice", &StockManagerApiController{}, "Get:SaveCheckPrice")
  82. beego.Router("/api/stock/getadjustpriceinfo", &StockManagerApiController{}, "Get:GetAdjustPriceById")
  83. beego.Router("/api/stock/savereportstock", &StockManagerApiController{}, "Post:SaveReportStock")
  84. beego.Router("/api/stock/getreportstocklist", &StockManagerApiController{}, "Get:GetReportStockList")
  85. beego.Router("/api/stock/savecheckdamage", &StockManagerApiController{}, "Get:SaveCheckDamage")
  86. beego.Router("/api/stock/saveinventory", &StockManagerApiController{}, "Post:SaveInventory")
  87. beego.Router("/api/stock/getinventorylist", &StockManagerApiController{}, "Get:GetInventorylist")
  88. beego.Router("/api/stock/savecheckinventory", &StockManagerApiController{}, "Get:SaveCheckInventory")
  89. beego.Router("/api/stock/getmodifypriceDetail", &StockManagerApiController{}, "Get:GetModifyPriceDetail")
  90. beego.Router("/api/stock/updatestockprice", &StockManagerApiController{}, "Get:UpdateStockPrice")
  91. beego.Router("/api/stock/deletestockprice", &StockManagerApiController{}, "Get:DeleteStockPrice")
  92. beego.Router("/api/stock/getstockdamagedetal", &StockManagerApiController{}, "Get:GetStockDamageDetail")
  93. beego.Router("/api/sotck/modifyprice", &StockManagerApiController{}, "Get:ModifyPrice")
  94. beego.Router("/api/stock/deletestockdamage", &StockManagerApiController{}, "Get:DeleteDamage")
  95. beego.Router("/api/stock/getstockdamagebyid", &StockManagerApiController{}, "Get:GetStockDamageById")
  96. beego.Router("api/sotck/getinventorydetail", &StockManagerApiController{}, "Get:GetInventoryDetail")
  97. beego.Router("/api/stock/modifyinventory", &StockManagerApiController{}, "Get:ModifyInventory")
  98. beego.Router("/api/stock/deleteinventory", &StockManagerApiController{}, "Get:DeleteInventory")
  99. beego.Router("/api/stock/getinventorydetaillist", &StockManagerApiController{}, "Get:GetInventoryDetailList")
  100. beego.Router("/api/stock/getinventoryprintlist", &StockManagerApiController{}, "Get:GetInventoryPrintList")
  101. beego.Router("/api/stock/getinventorydetailprintlist", &StockManagerApiController{}, "Get:GetInventoryDetailPrintList")
  102. beego.Router("/api/drug/deletedrugprice", &StockManagerApiController{}, "Get:DeleteDrugPrice")
  103. beego.Router("/api/stock/getgoodwarehouselist", &StockManagerApiController{}, "Get:GetGoodWarehouseList")
  104. beego.Router("/api/stock/proofinventory", &StockManagerApiController{}, "Get:ProofInventory")
  105. beego.Router("/api/stock/getwarehousetotal", &StockManagerApiController{}, "Get:GetWarehouseTotal")
  106. }
  107. func (c *StockManagerApiController) CreateWarehouse() {
  108. warehousing_time := c.GetString("warehousing_time")
  109. types, _ := c.GetInt64("type", 0)
  110. ctime := time.Now().Unix()
  111. adminUserInfo := c.GetAdminUserInfo()
  112. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  113. if parseDateErr != nil {
  114. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  116. return
  117. }
  118. timeStr := time.Now().Format("2006-01-02")
  119. timeArr := strings.Split(timeStr, "-")
  120. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  121. total = total + 1
  122. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  123. operation_time := time.Now().Unix()
  124. creater := adminUserInfo.AdminUser.Id
  125. warehousing := models.Warehousing{
  126. WarehousingOrder: warehousing_order,
  127. OperationTime: operation_time,
  128. OrgId: adminUserInfo.CurrentOrgId,
  129. Creater: creater,
  130. Ctime: ctime,
  131. Status: 1,
  132. WarehousingTime: warehousingDate.Unix(),
  133. Type: types,
  134. }
  135. service.AddSigleWarehouse(&warehousing)
  136. dataBody := make(map[string]interface{}, 0)
  137. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  138. if err != nil {
  139. utils.ErrorLog(err.Error())
  140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  141. return
  142. }
  143. var warehousingInfo []*models.WarehousingInfo
  144. var stockFlow []*models.VmStockFlow
  145. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  146. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  147. if len(thisStockIn) > 0 {
  148. for _, item := range thisStockIn {
  149. items := item.(map[string]interface{})
  150. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  151. utils.ErrorLog("good_id")
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  153. return
  154. }
  155. good_id := int64(items["good_id"].(float64))
  156. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  157. utils.ErrorLog("good_type_id")
  158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  159. return
  160. }
  161. good_type_id := int64(items["good_type_id"].(float64))
  162. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  163. utils.ErrorLog("warehousing_count")
  164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  165. return
  166. }
  167. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  168. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  169. utils.ErrorLog("price")
  170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  171. return
  172. }
  173. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  174. total := float64(warehousing_count) * price
  175. var productDates int64
  176. var expiryDates int64
  177. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  178. expiryDates = 0
  179. } else {
  180. if len(items["expiry_date"].(string)) == 0 {
  181. expiryDates = 0
  182. } else {
  183. expiryDate, _ := items["expiry_date"].(string)
  184. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  185. expiryDates = expiry_date.Unix()
  186. }
  187. }
  188. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  189. productDates = 0
  190. } else {
  191. if len(items["product_date"].(string)) == 0 {
  192. productDates = 0
  193. } else {
  194. productDate, _ := items["product_date"].(string)
  195. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  196. productDates = product_date.Unix()
  197. }
  198. }
  199. number, _ := items["number"].(string)
  200. remark, _ := items["remark"].(string)
  201. manufacturer := int64(items["manufacturer"].(float64))
  202. dealer := int64(items["dealer"].(float64))
  203. license_number, _ := items["license_number"].(string)
  204. //入库单表格
  205. warehouseInfo := &models.WarehousingInfo{
  206. WarehousingOrder: warehousing.WarehousingOrder,
  207. WarehousingId: warehousing.ID,
  208. GoodId: good_id,
  209. Number: number,
  210. GoodTypeId: good_type_id,
  211. ProductDate: productDates,
  212. ExpiryDate: expiryDates,
  213. WarehousingCount: warehousing_count,
  214. Price: price,
  215. TotalPrice: total,
  216. Status: 1,
  217. Ctime: ctime,
  218. Remark: remark,
  219. OrgId: adminUserInfo.CurrentOrgId,
  220. Type: types,
  221. Manufacturer: manufacturer,
  222. StockCount: warehousing_count,
  223. Dealer: dealer,
  224. LicenseNumber: license_number,
  225. }
  226. warehousingInfo = append(warehousingInfo, warehouseInfo)
  227. flow := &models.VmStockFlow{
  228. WarehousingOrder: warehousing.WarehousingOrder,
  229. WarehousingId: warehousing.ID,
  230. GoodId: good_id,
  231. Number: number,
  232. ProductDate: productDates,
  233. ExpireDate: expiryDates,
  234. Count: warehousing_count,
  235. Price: price,
  236. Status: 1,
  237. Ctime: ctime,
  238. UserOrgId: adminUserInfo.CurrentOrgId,
  239. Manufacturer: manufacturer,
  240. Dealer: dealer,
  241. LicenseNumber: license_number,
  242. IsEdit: 1,
  243. Creator: adminUserInfo.AdminUser.Id,
  244. SystemTime: operation_time,
  245. ConsumableType: 1,
  246. WarehousingDetailId: warehouseInfo.ID,
  247. }
  248. stockFlow = append(stockFlow, flow)
  249. }
  250. }
  251. }
  252. //入库单创建成功
  253. errs := service.CreateWarehousingInfo(warehousingInfo)
  254. //创建入库单流水
  255. service.CreateStockFlow(stockFlow)
  256. info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
  257. for _, item := range warehousingInfo {
  258. goodInfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  259. str := strconv.FormatInt(item.WarehousingCount, 10)
  260. minFloat, _ := strconv.ParseFloat(str, 64)
  261. good := models.GoodInfo{
  262. Total: minFloat + goodInfo.Total,
  263. }
  264. //更该库存
  265. parseDateErr := service.UpdateGoodInfoList(good, goodInfo.ID)
  266. break
  267. fmt.Println(parseDateErr)
  268. }
  269. if errs != nil {
  270. utils.ErrorLog(errs.Error())
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  272. return
  273. }
  274. c.ServeSuccessJSON(map[string]interface{}{
  275. "msg": "入库成功",
  276. "warehousing_order": warehousing_order,
  277. "info": info,
  278. })
  279. }
  280. func (c *StockManagerApiController) GetWarehouseList() {
  281. page, _ := c.GetInt64("page", -1)
  282. limit, _ := c.GetInt64("limit", -1)
  283. start_time := c.GetString("start_time")
  284. end_time := c.GetString("end_time")
  285. types, _ := c.GetInt64("type", 0)
  286. keywords := c.GetString("keywords")
  287. timeLayout := "2006-01-02"
  288. loc, _ := time.LoadLocation("Local")
  289. var startTime int64
  290. if len(start_time) > 0 {
  291. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  292. if err != nil {
  293. fmt.Println(err)
  294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  295. return
  296. }
  297. startTime = theTime.Unix()
  298. }
  299. var endTime int64
  300. if len(end_time) > 0 {
  301. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  302. if err != nil {
  303. utils.ErrorLog(err.Error())
  304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  305. return
  306. }
  307. endTime = theTime.Unix()
  308. }
  309. adminUserInfo := c.GetAdminUserInfo()
  310. var ids []int64
  311. var goodids []int64
  312. //查询商品名称
  313. if len(keywords) > 0 {
  314. //查询商品名称
  315. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  316. for _, item := range list {
  317. goodids = append(goodids, item.ID)
  318. //入库详情但里面查询
  319. }
  320. if len(goodids) > 0 {
  321. info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  322. for _, it := range info {
  323. ids = append(ids, it.WarehousingId)
  324. }
  325. }
  326. }
  327. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  328. if err == nil {
  329. c.ServeSuccessJSON(map[string]interface{}{
  330. "list": warehouseList,
  331. "total": total,
  332. })
  333. } else {
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  335. }
  336. }
  337. func (c *StockManagerApiController) GetWarehouseInfoList() {
  338. id := c.GetString("id")
  339. idArray := strings.Split(id, ",")
  340. warehousing, err := service.FindWarehousingByIdOne(idArray)
  341. if err != nil {
  342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  343. return
  344. }
  345. var ids []int64
  346. for _, item := range warehousing {
  347. ids = append(ids, item.ID)
  348. }
  349. warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
  350. if err == nil {
  351. c.ServeSuccessJSON(map[string]interface{}{
  352. "info": warehousingInfo,
  353. "warehousing": warehousing,
  354. })
  355. } else {
  356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  357. }
  358. }
  359. func (c *StockManagerApiController) EditWarehouse() {
  360. warehousing_time := c.GetString("warehousing_time")
  361. id, _ := c.GetInt64("id", 0)
  362. types, _ := c.GetInt64("type", 0)
  363. if id == 0 {
  364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  365. return
  366. }
  367. ctime := time.Now().Unix()
  368. mtime := time.Now().Unix()
  369. adminUserInfo := c.GetAdminUserInfo()
  370. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  371. if parseDateErr != nil {
  372. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  374. return
  375. }
  376. warehouse, _ := service.FindWarehousingById(id)
  377. warehousing := models.Warehousing{
  378. WarehousingOrder: warehouse.WarehousingOrder,
  379. OrgId: adminUserInfo.CurrentOrgId,
  380. Modifier: adminUserInfo.AdminUser.Id,
  381. Mtime: mtime,
  382. Status: 1,
  383. WarehousingTime: warehousingDate.Unix(),
  384. Type: warehouse.Type,
  385. }
  386. service.EditWarehousing(warehousing)
  387. dataBody := make(map[string]interface{}, 0)
  388. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  389. if err != nil {
  390. utils.ErrorLog(err.Error())
  391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  392. return
  393. }
  394. var warehousingInfo []*models.WarehousingInfo
  395. var upDateWarehousingInfo []*models.WarehousingInfo
  396. var stockFlow []*models.VmStockFlow
  397. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  398. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  399. if len(thisStockIn) > 0 {
  400. for _, item := range thisStockIn {
  401. items := item.(map[string]interface{})
  402. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  403. utils.ErrorLog("good_id")
  404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  405. return
  406. }
  407. good_id := int64(items["good_id"].(float64))
  408. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  409. utils.ErrorLog("good_type_id")
  410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  411. return
  412. }
  413. good_type_id := int64(items["good_type_id"].(float64))
  414. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  415. utils.ErrorLog("warehousing_count")
  416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  417. return
  418. }
  419. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  420. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  421. utils.ErrorLog("price")
  422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  423. return
  424. }
  425. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  426. total := float64(warehousing_count) * price
  427. var productDates int64
  428. var expiryDates int64
  429. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  430. expiryDates = 0
  431. } else {
  432. if len(items["expiry_date"].(string)) == 0 {
  433. expiryDates = 0
  434. } else {
  435. expiryDate, _ := items["expiry_date"].(string)
  436. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  437. expiryDates = expiry_date.Unix()
  438. }
  439. }
  440. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  441. productDates = 0
  442. } else {
  443. if len(items["product_date"].(string)) == 0 {
  444. productDates = 0
  445. } else {
  446. productDate, _ := items["product_date"].(string)
  447. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  448. productDates = product_date.Unix()
  449. }
  450. }
  451. number, _ := items["number"].(string)
  452. remark, _ := items["remark"].(string)
  453. manufacturer := int64(items["manufacturer"].(float64))
  454. dealer := int64(items["dealer"].(float64))
  455. license_number, _ := items["license_number"].(string)
  456. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  457. utils.ErrorLog("id")
  458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  459. return
  460. }
  461. id := int64(items["id"].(float64))
  462. if id == 0 {
  463. warehouseInfo := &models.WarehousingInfo{
  464. WarehousingOrder: warehouse.WarehousingOrder,
  465. WarehousingId: warehouse.ID,
  466. GoodId: good_id,
  467. Number: number,
  468. GoodTypeId: good_type_id,
  469. ProductDate: productDates,
  470. ExpiryDate: expiryDates,
  471. WarehousingCount: warehousing_count,
  472. Price: price,
  473. TotalPrice: total,
  474. Status: 1,
  475. Ctime: ctime,
  476. Remark: remark,
  477. OrgId: adminUserInfo.CurrentOrgId,
  478. Type: types,
  479. Manufacturer: manufacturer,
  480. Dealer: dealer,
  481. StockCount: warehousing_count,
  482. LicenseNumber: license_number,
  483. }
  484. warehousingInfo = append(warehousingInfo, warehouseInfo)
  485. flow := &models.VmStockFlow{
  486. WarehousingOrder: warehousing.WarehousingOrder,
  487. WarehousingId: warehousing.ID,
  488. GoodId: good_id,
  489. Number: number,
  490. ProductDate: productDates,
  491. ExpireDate: expiryDates,
  492. Count: warehousing_count,
  493. Price: price,
  494. Status: 1,
  495. Ctime: ctime,
  496. UserOrgId: adminUserInfo.CurrentOrgId,
  497. Manufacturer: manufacturer,
  498. Dealer: dealer,
  499. LicenseNumber: license_number,
  500. IsEdit: 1,
  501. Creator: adminUserInfo.AdminUser.Id,
  502. SystemTime: ctime,
  503. ConsumableType: 1,
  504. WarehousingDetailId: warehouseInfo.ID,
  505. }
  506. stockFlow = append(stockFlow, flow)
  507. } else {
  508. fmt.Println("id23233232323232323232323223", id)
  509. warehouseInfo := &models.WarehousingInfo{
  510. ID: id,
  511. WarehousingOrder: warehouse.WarehousingOrder,
  512. WarehousingId: warehouse.ID,
  513. GoodId: good_id,
  514. Number: number,
  515. GoodTypeId: good_type_id,
  516. ProductDate: productDates,
  517. ExpiryDate: expiryDates,
  518. WarehousingCount: warehousing_count,
  519. Price: price,
  520. TotalPrice: total,
  521. Status: 1,
  522. Ctime: ctime,
  523. Remark: remark,
  524. OrgId: adminUserInfo.CurrentOrgId,
  525. Type: types,
  526. Manufacturer: manufacturer,
  527. Dealer: dealer,
  528. LicenseNumber: license_number,
  529. }
  530. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  531. flow := &models.VmStockFlow{
  532. WarehousingOrder: warehousing.WarehousingOrder,
  533. WarehousingId: id,
  534. GoodId: good_id,
  535. Number: number,
  536. ProductDate: productDates,
  537. ExpireDate: expiryDates,
  538. Count: warehousing_count,
  539. Price: price,
  540. Status: 1,
  541. Ctime: ctime,
  542. UserOrgId: adminUserInfo.CurrentOrgId,
  543. Manufacturer: manufacturer,
  544. Dealer: dealer,
  545. LicenseNumber: license_number,
  546. IsEdit: 2,
  547. Creator: adminUserInfo.AdminUser.Id,
  548. SystemTime: ctime,
  549. ConsumableType: 1,
  550. WarehousingDetailId: warehouseInfo.ID,
  551. }
  552. stockFlow = append(stockFlow, flow)
  553. }
  554. }
  555. }
  556. }
  557. var errs error
  558. if len(warehousingInfo) > 0 {
  559. errs = service.CreateWarehousingInfo(warehousingInfo)
  560. service.CreateStockFlow(stockFlow)
  561. }
  562. if len(upDateWarehousingInfo) > 0 {
  563. for _, item := range upDateWarehousingInfo {
  564. var total int64
  565. var all_total int64
  566. //获取该批次该型号的库存
  567. info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
  568. fmt.Println("oooooooooo", info.WarehousingCount)
  569. //判断 该批次的入库数量
  570. total = item.WarehousingCount - info.WarehousingCount
  571. fmt.Println("total232323322332232332", total)
  572. all_total = info.StockCount + total
  573. item.StockCount = all_total
  574. fmt.Println("hhhhhhhhhhhhh", item.StockCount)
  575. errs = service.UpDateWarehousingInfo(item)
  576. }
  577. }
  578. if len(stockFlow) > 0 {
  579. for _, item := range stockFlow {
  580. flow := models.VmStockFlow{
  581. Count: item.Count,
  582. }
  583. parseDateErr := service.UpdateStockFlow(flow, item.GoodId, item.WarehousingId)
  584. fmt.Println(parseDateErr)
  585. }
  586. }
  587. if errs != nil {
  588. utils.ErrorLog(errs.Error())
  589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  590. return
  591. }
  592. c.ServeSuccessJSON(map[string]interface{}{
  593. "msg": "编辑成功",
  594. })
  595. }
  596. func (c *StockManagerApiController) DeleteWarehouse() {
  597. ids := c.GetString("ids")
  598. if len(ids) == 0 {
  599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  600. return
  601. }
  602. idArray := strings.Split(ids, ",")
  603. err := service.DeleteWarehouse(idArray)
  604. if err != nil {
  605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  606. } else {
  607. c.ServeSuccessJSON(map[string]interface{}{
  608. "msg": "删除成功",
  609. })
  610. }
  611. }
  612. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  613. id, _ := c.GetInt64("id", 0)
  614. if id == 0 {
  615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  616. return
  617. }
  618. err := service.UpDateWarehouseStatus(id)
  619. if err != nil {
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  621. } else {
  622. c.ServeSuccessJSON(map[string]interface{}{
  623. "msg": "删除成功",
  624. })
  625. }
  626. }
  627. func (c *StockManagerApiController) CreateSalesReturn() {
  628. dealer_id, _ := c.GetInt64("dealer_id", 0)
  629. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  630. sales_return_time := c.GetString("time")
  631. types, _ := c.GetInt64("type", 0)
  632. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  633. if parseDateErr != nil {
  634. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  636. return
  637. }
  638. adminUserInfo := c.GetAdminUserInfo()
  639. operation_time := time.Now().Unix()
  640. creater := adminUserInfo.AdminUser.Id
  641. ctime := time.Now().Unix()
  642. timeStr := time.Now().Format("2006-01-02")
  643. timeArr := strings.Split(timeStr, "-")
  644. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  645. total = total + 1
  646. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  647. salesReturn := models.SalesReturn{
  648. OrderNumber: orderNumber,
  649. OperaTime: operation_time,
  650. OrgId: adminUserInfo.CurrentOrgId,
  651. Creater: creater,
  652. Ctime: ctime,
  653. Status: 1,
  654. ReturnTime: salesReturnDate.Unix(),
  655. Dealer: dealer_id,
  656. Manufacturer: manufacturer_id,
  657. Type: types,
  658. }
  659. service.AddSigleSalesReturn(&salesReturn)
  660. dataBody := make(map[string]interface{}, 0)
  661. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  662. if err != nil {
  663. utils.ErrorLog(err.Error())
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  665. return
  666. }
  667. var salesReturnInfos []*models.SalesReturnInfo
  668. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  669. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  670. if len(thisStockIn) > 0 {
  671. for _, item := range thisStockIn {
  672. items := item.(map[string]interface{})
  673. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  674. utils.ErrorLog("good_id")
  675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  676. return
  677. }
  678. good_id := int64(items["good_id"].(float64))
  679. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  680. utils.ErrorLog("good_type_id")
  681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  682. return
  683. }
  684. good_type_id := int64(items["good_type_id"].(float64))
  685. return_count, _ := items["return_count"].(string)
  686. if len(return_count) == 0 {
  687. utils.ErrorLog("len(return_count) == 0")
  688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  689. return
  690. }
  691. count, _ := strconv.ParseInt(return_count, 10, 64)
  692. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  693. total := float64(count) * price
  694. salesReturnInfo := &models.SalesReturnInfo{
  695. OrderNumber: salesReturn.OrderNumber,
  696. SalesReturnId: salesReturn.ID,
  697. GoodId: good_id,
  698. GoodTypeId: good_type_id,
  699. Count: count,
  700. Price: price,
  701. Total: total,
  702. Status: 1,
  703. Ctime: ctime,
  704. OrgId: adminUserInfo.CurrentOrgId,
  705. Type: types,
  706. Manufacturer: manufacturer_id,
  707. Dealer: dealer_id,
  708. }
  709. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  710. }
  711. }
  712. }
  713. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  714. if errs != nil {
  715. utils.ErrorLog(errs.Error())
  716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  717. return
  718. }
  719. c.ServeSuccessJSON(map[string]interface{}{
  720. "msg": "退货成功",
  721. })
  722. }
  723. func (c *StockManagerApiController) GetSalesReturnList() {
  724. page, _ := c.GetInt64("page", -1)
  725. limit, _ := c.GetInt64("limit", -1)
  726. start_time := c.GetString("start_time")
  727. end_time := c.GetString("end_time")
  728. types, _ := c.GetInt64("type", 0)
  729. keywords := c.GetString("keywords")
  730. timeLayout := "2006-01-02"
  731. loc, _ := time.LoadLocation("Local")
  732. var startTime int64
  733. if len(start_time) > 0 {
  734. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  735. if err != nil {
  736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  737. return
  738. }
  739. startTime = theTime.Unix()
  740. }
  741. var endTime int64
  742. if len(end_time) > 0 {
  743. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  744. if err != nil {
  745. utils.ErrorLog(err.Error())
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  747. return
  748. }
  749. endTime = theTime.Unix()
  750. }
  751. adminUserInfo := c.GetAdminUserInfo()
  752. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  753. if err == nil {
  754. c.ServeSuccessJSON(map[string]interface{}{
  755. "list": returnList,
  756. "total": total,
  757. })
  758. } else {
  759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  760. }
  761. }
  762. func (this *StockManagerApiController) DeleteSalesReturn() {
  763. ids := this.GetString("ids")
  764. if len(ids) == 0 {
  765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  766. return
  767. }
  768. idArray := strings.Split(ids, ",")
  769. err := service.DeleteSalesReturn(idArray)
  770. if err != nil {
  771. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  772. } else {
  773. this.ServeSuccessJSON(map[string]interface{}{
  774. "msg": "删除成功",
  775. })
  776. }
  777. }
  778. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  779. id, _ := this.GetInt64("id", 0)
  780. fmt.Println(id)
  781. if id == 0 {
  782. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  783. return
  784. }
  785. err := service.UpDateSaleReturnStatus(id)
  786. if err != nil {
  787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  788. } else {
  789. this.ServeSuccessJSON(map[string]interface{}{
  790. "msg": "删除成功",
  791. })
  792. }
  793. }
  794. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  795. id, _ := this.GetInt64("id", 0)
  796. list, _ := service.FindAllSalesReturnInfoById(id)
  797. salesReturn, _ := service.FindAllSalesReturnById(id)
  798. this.ServeSuccessJSON(map[string]interface{}{
  799. "list": list,
  800. "salesReturn": salesReturn,
  801. })
  802. }
  803. func (c *StockManagerApiController) EditReturnInfo() {
  804. return_time := c.GetString("return_time")
  805. id, _ := c.GetInt64("id", 0)
  806. types, _ := c.GetInt64("type", 0)
  807. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  808. dealer_id, _ := c.GetInt64("dealer_id", 0)
  809. if id == 0 {
  810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  811. return
  812. }
  813. ctime := time.Now().Unix()
  814. mtime := time.Now().Unix()
  815. adminUserInfo := c.GetAdminUserInfo()
  816. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  817. if parseDateErr != nil {
  818. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  820. return
  821. }
  822. salesReturns, _ := service.FindSalesReturnById(id)
  823. sales := models.SalesReturn{
  824. ID: salesReturns.ID,
  825. Mtime: mtime,
  826. ReturnTime: returnDate.Unix(),
  827. Manufacturer: manufacturer_id,
  828. Dealer: dealer_id,
  829. }
  830. service.EditSaleReturn(sales)
  831. dataBody := make(map[string]interface{}, 0)
  832. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  833. if err != nil {
  834. utils.ErrorLog(err.Error())
  835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  836. return
  837. }
  838. var returnInfos []*models.SalesReturnInfo
  839. var upDateReturnInfos []*models.SalesReturnInfo
  840. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  841. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  842. if len(thisStockIn) > 0 {
  843. for _, item := range thisStockIn {
  844. items := item.(map[string]interface{})
  845. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  846. utils.ErrorLog("good_id")
  847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  848. return
  849. }
  850. good_id := int64(items["good_id"].(float64))
  851. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  852. utils.ErrorLog("good_type_id")
  853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  854. return
  855. }
  856. good_type_id := int64(items["good_type_id"].(float64))
  857. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  858. utils.ErrorLog("count")
  859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  860. return
  861. }
  862. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  863. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  864. utils.ErrorLog("id")
  865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  866. return
  867. }
  868. id := int64(items["id"].(float64))
  869. if id == 0 {
  870. returnInfo := &models.SalesReturnInfo{
  871. GoodId: good_id,
  872. GoodTypeId: good_type_id,
  873. Count: count,
  874. Status: 1,
  875. Ctime: ctime,
  876. OrgId: adminUserInfo.CurrentOrgId,
  877. OrderNumber: sales.OrderNumber,
  878. SalesReturnId: sales.ID,
  879. Mtime: time.Now().Unix(),
  880. Type: types,
  881. Manufacturer: manufacturer_id,
  882. Dealer: dealer_id,
  883. }
  884. returnInfos = append(returnInfos, returnInfo)
  885. } else {
  886. returnInfo := &models.SalesReturnInfo{
  887. ID: id,
  888. GoodId: good_id,
  889. GoodTypeId: good_type_id,
  890. Count: count,
  891. Status: 1,
  892. Ctime: ctime,
  893. OrgId: adminUserInfo.CurrentOrgId,
  894. OrderNumber: sales.OrderNumber,
  895. SalesReturnId: sales.ID,
  896. Mtime: time.Now().Unix(),
  897. Type: types,
  898. Manufacturer: manufacturer_id,
  899. Dealer: dealer_id,
  900. }
  901. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  902. }
  903. }
  904. }
  905. }
  906. var errs error
  907. if len(returnInfos) > 0 {
  908. errs = service.CreateSalesReturnInfo(returnInfos)
  909. }
  910. if len(upDateReturnInfos) > 0 {
  911. for _, item := range upDateReturnInfos {
  912. errs = service.UpDateSalesReturnInfo(item)
  913. }
  914. }
  915. if errs != nil {
  916. utils.ErrorLog(errs.Error())
  917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  918. return
  919. }
  920. c.ServeSuccessJSON(map[string]interface{}{
  921. "msg": "编辑成功",
  922. })
  923. }
  924. func (c *StockManagerApiController) CreateWarehouseOut() {
  925. types, _ := c.GetInt64("type", 0)
  926. ctime := time.Now().Unix()
  927. adminUserInfo := c.GetAdminUserInfo()
  928. warehousing_out_time := c.GetString("warehousing_out_time")
  929. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  930. if parseDateErr != nil {
  931. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  933. return
  934. }
  935. timeStr := time.Now().Format("2006-01-02")
  936. timeArr := strings.Split(timeStr, "-")
  937. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  938. total = total + 1
  939. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  940. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  941. number = number + total
  942. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  943. operation_time := time.Now().Unix()
  944. creater := adminUserInfo.AdminUser.Id
  945. warehouseOut := models.WarehouseOut{
  946. WarehouseOutOrderNumber: warehousing_out_order,
  947. OperationTime: operation_time,
  948. OrgId: adminUserInfo.CurrentOrgId,
  949. Creater: creater,
  950. Ctime: ctime,
  951. Status: 1,
  952. WarehouseOutTime: warehousingOutDate.Unix(),
  953. Type: types,
  954. }
  955. dataBody := make(map[string]interface{}, 0)
  956. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  957. if err != nil {
  958. utils.ErrorLog(err.Error())
  959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  960. return
  961. }
  962. var warehousingOutInfo []*models.WarehouseOutInfo
  963. var beforePrepares []*models.DialysisBeforePrepareGoods
  964. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  965. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  966. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  967. if len(thisStockIn) > 0 {
  968. for _, item := range thisStockIn {
  969. items := item.(map[string]interface{})
  970. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  971. utils.ErrorLog("good_id")
  972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  973. return
  974. }
  975. good_id := int64(items["good_id"].(float64))
  976. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  977. utils.ErrorLog("good_type_id")
  978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  979. return
  980. }
  981. good_type_id := int64(items["good_type_id"].(float64))
  982. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  983. utils.ErrorLog("count")
  984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  985. return
  986. }
  987. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  988. utils.ErrorLog("price")
  989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  990. return
  991. }
  992. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  993. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  994. total := float64(count) * price
  995. remark := items["remark"].(string)
  996. manufacturer := int64(items["manufacturer"].(float64))
  997. dealer := int64(items["dealer"].(float64))
  998. number := items["number"].(string)
  999. expiry_date := items["expiry_date"].(string)
  1000. timeLayout := "2006-01-02"
  1001. loc, _ := time.LoadLocation("Local")
  1002. var expiryDate int64
  1003. if len(expiry_date) > 0 {
  1004. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1005. if err != nil {
  1006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1007. return
  1008. }
  1009. expiryDate = theTime.Unix()
  1010. }
  1011. product_date := items["product_date"].(string)
  1012. var productDate int64
  1013. if len(product_date) > 0 {
  1014. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1015. if err != nil {
  1016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1017. return
  1018. }
  1019. productDate = theTime.Unix()
  1020. }
  1021. license_number := items["license_number"].(string)
  1022. warehouseOutInfo := &models.WarehouseOutInfo{
  1023. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1024. WarehouseOutId: warehouseOut.ID,
  1025. GoodId: good_id,
  1026. GoodTypeId: good_type_id,
  1027. Count: count,
  1028. Price: price,
  1029. TotalPrice: total,
  1030. Status: 1,
  1031. Ctime: ctime,
  1032. Remark: remark,
  1033. OrgId: adminUserInfo.CurrentOrgId,
  1034. Type: types,
  1035. Manufacturer: manufacturer,
  1036. Number: number,
  1037. ExpiryDate: expiryDate,
  1038. ProductDate: productDate,
  1039. Dealer: dealer,
  1040. LicenseNumber: license_number,
  1041. }
  1042. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1043. prepareGoods := &models.DialysisBeforePrepareGoods{
  1044. GoodTypeId: good_type_id,
  1045. GoodId: good_id,
  1046. Count: count,
  1047. }
  1048. beforePrepares = append(beforePrepares, prepareGoods)
  1049. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  1050. GoodTypeId: good_type_id,
  1051. GoodId: good_id,
  1052. Count: count,
  1053. }
  1054. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  1055. }
  1056. }
  1057. }
  1058. //出库逻辑
  1059. for _, item := range warehousingOutInfo {
  1060. //查询库存
  1061. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
  1062. fmt.Println("库存数量组吗", warehouse.Count)
  1063. if item.Count > warehouse.Count {
  1064. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1065. c.ServeSuccessJSON(map[string]interface{}{
  1066. "msg": "1",
  1067. "good_name": goodObj.GoodName,
  1068. "specification_name": goodObj.SpecificationName,
  1069. })
  1070. return
  1071. } else {
  1072. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  1073. if errcodes == gorm.ErrRecordNotFound {
  1074. service.AddSigleWarehouseOut(&warehouseOut)
  1075. }
  1076. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
  1077. if parseDateErr != nil {
  1078. utils.ErrorLog(parseDateErr.Error())
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1080. return
  1081. }
  1082. c.ServeSuccessJSON(map[string]interface{}{
  1083. "msg": "2",
  1084. "good_name": "",
  1085. "specification_name": "",
  1086. })
  1087. }
  1088. }
  1089. //errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
  1090. //info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
  1091. }
  1092. func (c *StockManagerApiController) GetWarehouseOutList() {
  1093. page, _ := c.GetInt64("page", -1)
  1094. limit, _ := c.GetInt64("limit", -1)
  1095. start_time := c.GetString("start_time")
  1096. end_time := c.GetString("end_time")
  1097. types, _ := c.GetInt64("type", 0)
  1098. keywords := c.GetString("keywords")
  1099. timeLayout := "2006-01-02"
  1100. loc, _ := time.LoadLocation("Local")
  1101. var startTime int64
  1102. if len(start_time) > 0 {
  1103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1104. if err != nil {
  1105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1106. return
  1107. }
  1108. startTime = theTime.Unix()
  1109. }
  1110. var endTime int64
  1111. if len(end_time) > 0 {
  1112. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1113. if err != nil {
  1114. utils.ErrorLog(err.Error())
  1115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1116. return
  1117. }
  1118. endTime = theTime.Unix()
  1119. }
  1120. adminUserInfo := c.GetAdminUserInfo()
  1121. var ids []int64
  1122. var goodids []int64
  1123. if len(keywords) > 0 {
  1124. //查询商品名称
  1125. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  1126. for _, item := range list {
  1127. goodids = append(goodids, item.ID)
  1128. }
  1129. if len(goodids) > 0 {
  1130. //出库详情但里面查询
  1131. info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  1132. for _, it := range info {
  1133. ids = append(ids, it.WarehouseOutId)
  1134. }
  1135. }
  1136. }
  1137. warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  1138. fmt.Println(err)
  1139. if err == nil {
  1140. c.ServeSuccessJSON(map[string]interface{}{
  1141. "list": warehouseOutList,
  1142. "total": total,
  1143. })
  1144. } else {
  1145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1146. }
  1147. }
  1148. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1149. ids := c.GetString("ids")
  1150. if len(ids) == 0 {
  1151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1152. return
  1153. }
  1154. idArray := strings.Split(ids, ",")
  1155. err := service.DeleteWarehouseOut(idArray)
  1156. if err != nil {
  1157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1158. } else {
  1159. c.ServeSuccessJSON(map[string]interface{}{
  1160. "msg": "删除成功",
  1161. })
  1162. }
  1163. }
  1164. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1165. id, _ := this.GetInt64("id", 0)
  1166. fmt.Println(id)
  1167. if id == 0 {
  1168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1169. return
  1170. }
  1171. err := service.UpDateWarehouseOutStatus(id)
  1172. if err != nil {
  1173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1174. } else {
  1175. this.ServeSuccessJSON(map[string]interface{}{
  1176. "msg": "删除成功",
  1177. })
  1178. }
  1179. }
  1180. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1181. id, _ := c.GetInt64("id", 0)
  1182. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1183. warehouseOut, _ := service.FindWareHouseOutById(id)
  1184. adminUserInfo := c.GetAdminUserInfo()
  1185. orgId := adminUserInfo.CurrentOrgId
  1186. wareoutList, _ := service.GetWareOutInfoById(id, orgId)
  1187. c.ServeSuccessJSON(map[string]interface{}{
  1188. "list": warehouseOutInfo,
  1189. "info": warehouseOut,
  1190. "wareoutList": wareoutList,
  1191. })
  1192. }
  1193. func (c *StockManagerApiController) EditWarehouseOut() {
  1194. warehouse_out_time := c.GetString("warehouse_out_time")
  1195. id, _ := c.GetInt64("id", 0)
  1196. types, _ := c.GetInt64("type", 0)
  1197. if id == 0 {
  1198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1199. return
  1200. }
  1201. ctime := time.Now().Unix()
  1202. mtime := time.Now().Unix()
  1203. adminUserInfo := c.GetAdminUserInfo()
  1204. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1205. if parseDateErr != nil {
  1206. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1208. return
  1209. }
  1210. warehouseOut, _ := service.FindWareHouseOutById(id)
  1211. tempWarehouseOut := models.WarehouseOut{
  1212. ID: warehouseOut.ID,
  1213. Mtime: mtime,
  1214. WarehouseOutTime: warehouseOutDate.Unix(),
  1215. }
  1216. service.EditWarehouseOut(tempWarehouseOut)
  1217. dataBody := make(map[string]interface{}, 0)
  1218. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1219. if err != nil {
  1220. utils.ErrorLog(err.Error())
  1221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1222. return
  1223. }
  1224. var warehousingOutInfo []*models.WarehouseOutInfo
  1225. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1226. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1227. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1228. if len(thisStockOut) > 0 {
  1229. for _, item := range thisStockOut {
  1230. items := item.(map[string]interface{})
  1231. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1232. utils.ErrorLog("good_id")
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1234. return
  1235. }
  1236. good_id := int64(items["good_id"].(float64))
  1237. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1238. utils.ErrorLog("good_type_id")
  1239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1240. return
  1241. }
  1242. good_type_id := int64(items["good_type_id"].(float64))
  1243. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1244. utils.ErrorLog("count")
  1245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1246. return
  1247. }
  1248. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1249. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1250. utils.ErrorLog("price")
  1251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1252. return
  1253. }
  1254. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1255. total := float64(count) * price
  1256. remark := items["remark"].(string)
  1257. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1258. utils.ErrorLog("id")
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1260. return
  1261. }
  1262. id := int64(items["id"].(float64))
  1263. manufacturer := int64(items["manufacturer"].(float64))
  1264. dealer := int64(items["dealer"].(float64))
  1265. number := items["number"].(string)
  1266. license_number := items["license_number"].(string)
  1267. timeLayout := "2006-01-02"
  1268. loc, _ := time.LoadLocation("Local")
  1269. expiry_date := items["expiry_date"].(string)
  1270. var expiryDate int64
  1271. if len(expiry_date) > 0 {
  1272. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1273. if err != nil {
  1274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1275. return
  1276. }
  1277. expiryDate = theTime.Unix()
  1278. }
  1279. product_date := items["product_date"].(string)
  1280. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1281. var productDate int64
  1282. if len(product_date) > 0 {
  1283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1284. if err != nil {
  1285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1286. return
  1287. }
  1288. productDate = theTime.Unix()
  1289. }
  1290. if id == 0 {
  1291. warehouseOutInfo := &models.WarehouseOutInfo{
  1292. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1293. WarehouseOutId: warehouseOut.ID,
  1294. GoodId: good_id,
  1295. GoodTypeId: good_type_id,
  1296. Count: count,
  1297. Price: price,
  1298. TotalPrice: total,
  1299. Status: 1,
  1300. Ctime: ctime,
  1301. Remark: remark,
  1302. OrgId: adminUserInfo.CurrentOrgId,
  1303. Type: types,
  1304. IsSys: 0,
  1305. SysRecordTime: 0,
  1306. Number: number,
  1307. ExpiryDate: expiryDate,
  1308. ProductDate: productDate,
  1309. Dealer: dealer,
  1310. Manufacturer: manufacturer,
  1311. LicenseNumber: license_number,
  1312. ConsumableType: 1,
  1313. WarehouseInfotId: warehouse_info_id,
  1314. }
  1315. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1316. } else {
  1317. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1318. utils.ErrorLog("is_sys")
  1319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1320. return
  1321. }
  1322. is_sys := int64(items["is_sys"].(float64))
  1323. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1324. utils.ErrorLog("sys_record_time")
  1325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1326. return
  1327. }
  1328. sys_record_time := int64(items["sys_record_time"].(float64))
  1329. warehouseOutInfo := &models.WarehouseOutInfo{
  1330. ID: id,
  1331. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1332. WarehouseOutId: warehouseOut.ID,
  1333. GoodId: good_id,
  1334. GoodTypeId: good_type_id,
  1335. Count: count,
  1336. Price: price,
  1337. TotalPrice: total,
  1338. Status: 1,
  1339. Ctime: ctime,
  1340. Remark: remark,
  1341. OrgId: adminUserInfo.CurrentOrgId,
  1342. Mtime: time.Now().Unix(),
  1343. Type: types,
  1344. Manufacturer: manufacturer,
  1345. IsSys: is_sys,
  1346. SysRecordTime: sys_record_time,
  1347. Number: number,
  1348. ExpiryDate: expiryDate,
  1349. ProductDate: productDate,
  1350. Dealer: dealer,
  1351. LicenseNumber: license_number,
  1352. ConsumableType: 2,
  1353. WarehouseInfotId: warehouse_info_id,
  1354. }
  1355. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1356. }
  1357. }
  1358. }
  1359. }
  1360. var errs error
  1361. if len(warehousingOutInfo) > 0 {
  1362. errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
  1363. }
  1364. if len(upDateWarehouseOutInfos) > 0 {
  1365. for _, item := range upDateWarehouseOutInfos {
  1366. //1.查询该耗材该批次的最后一次出库记录
  1367. lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, adminUserInfo.CurrentOrgId)
  1368. fmt.Println("lastGood", lastGood.Count)
  1369. fmt.Println("item2323232", item.Count)
  1370. // 退库的库存和该耗材该批次最后一次出库数量进行比较
  1371. //如果退库数量大于 最后一次批次的数量(要么要进行出库)
  1372. if item.Count > lastGood.Count {
  1373. //查询该耗材是否还有库存
  1374. warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
  1375. fmt.Println("hhhhhh23h2323232", warehouseinfo.StockCount)
  1376. //无库存
  1377. if warehouseinfo.StockCount <= 0 {
  1378. c.ServeSuccessJSON(map[string]interface{}{
  1379. "msg": "5",
  1380. })
  1381. return
  1382. }
  1383. //有库存,进行出库,调用出库接口
  1384. if warehouseinfo.StockCount > 0 {
  1385. var total int64
  1386. var stock_cout int64
  1387. var total_count int64
  1388. //计算和最后一次出库数据的差
  1389. total = item.Count - lastGood.Count
  1390. fmt.Println("total22323232", total)
  1391. //获取该耗材该批次的剩余库存量
  1392. info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1393. fmt.Println("info2232323232323", info)
  1394. //判断该批次的剩余库存 和出库的库存进行比较
  1395. //如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
  1396. if item.Count > info.StockCount {
  1397. //计算出库和该批次相差的库存
  1398. total_count = item.Count - info.StockCount
  1399. //清空本批次次库存
  1400. service.DeleteWarehouseInfo(item.WarehouseInfotId)
  1401. //调用出库逻辑
  1402. service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
  1403. }
  1404. //如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
  1405. if item.Count <= info.StockCount {
  1406. stock_cout = lastGood.Count + total
  1407. fmt.Println("232323223232323232323232", stock_cout)
  1408. //扣减库存
  1409. warehouse := models.WarehousingInfo{
  1410. StockCount: info.StockCount - total,
  1411. }
  1412. errs := service.UpdateWarehousingInfo(warehouse, info.ID)
  1413. warehouseOutInfo := &models.WarehouseOutInfo{
  1414. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1415. WarehouseOutId: id,
  1416. WarehouseInfotId: item.WarehouseInfotId,
  1417. Status: 1,
  1418. Ctime: time.Now().Unix(),
  1419. Remark: item.Remark,
  1420. OrgId: item.OrgId,
  1421. Type: 1,
  1422. Manufacturer: item.Manufacturer,
  1423. Dealer: item.Dealer,
  1424. IsSys: 0,
  1425. SysRecordTime: item.SysRecordTime,
  1426. GoodTypeId: item.GoodTypeId,
  1427. GoodId: item.GoodId,
  1428. ExpiryDate: item.ExpiryDate,
  1429. ProductDate: item.ProductDate,
  1430. Number: item.Number,
  1431. Price: item.Price,
  1432. LicenseNumber: item.LicenseNumber,
  1433. Count: item.Count,
  1434. ConsumableType: 2,
  1435. }
  1436. //查询是否存在
  1437. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1438. if errcode == gorm.ErrRecordNotFound {
  1439. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1440. if errOne != nil {
  1441. utils.ErrorLog(errs.Error())
  1442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1443. return
  1444. }
  1445. c.ServeSuccessJSON(map[string]interface{}{
  1446. "msg": "1",
  1447. })
  1448. } else if errcode == nil {
  1449. service.UpDateWarehouseOutInfo(item)
  1450. }
  1451. }
  1452. }
  1453. }
  1454. var last_count int64
  1455. var all_total int64
  1456. var stock_total int64
  1457. //如果退库数量小于最后一次批次的数量(要么要进行退库)
  1458. if item.Count < lastGood.Count {
  1459. fmt.Println("hh232323h2h3hh23hh23hh2h3h23")
  1460. //退库数量和最后一次出库数据进行计算
  1461. last_count = lastGood.Count - item.Count
  1462. fmt.Println("last_count", last_count)
  1463. //获取该耗材该批次的剩余库存量
  1464. infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1465. //退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
  1466. all_total = last_count + infoInfo.StockCount
  1467. fmt.Println("all_total", all_total)
  1468. //如果库存大于总数量,则退回到这个批次
  1469. fmt.Println("inf232323", infoInfo.WarehousingCount)
  1470. if infoInfo.WarehousingCount > all_total {
  1471. stock_total = last_count + infoInfo.StockCount
  1472. fmt.Println("经历323232323232232", last_count, stock_total)
  1473. //退回该批次,计算数量
  1474. warehousingInfoOne := models.WarehousingInfo{
  1475. StockCount: stock_total,
  1476. ID: item.WarehouseInfotId,
  1477. OrgId: item.OrgId,
  1478. }
  1479. fmt.Println("********************", warehousingInfoOne, item.WarehouseInfotId)
  1480. parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
  1481. fmt.Println("parseDateErr2323232322323", parseDateErr)
  1482. //插入一条新纪录
  1483. warehouseOutInfoThree := &models.WarehouseOutInfo{
  1484. WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  1485. WarehouseOutId: id,
  1486. WarehouseInfotId: item.WarehouseInfotId,
  1487. Status: 1,
  1488. Ctime: time.Now().Unix(),
  1489. Remark: item.Remark,
  1490. OrgId: item.OrgId,
  1491. Type: 1,
  1492. Manufacturer: item.Manufacturer,
  1493. Dealer: item.Dealer,
  1494. IsSys: 0,
  1495. GoodTypeId: item.GoodTypeId,
  1496. GoodId: item.GoodId,
  1497. ExpiryDate: item.ExpiryDate,
  1498. ProductDate: item.ProductDate,
  1499. Number: item.Number,
  1500. Price: item.Price,
  1501. LicenseNumber: item.LicenseNumber,
  1502. ConsumableType: 2,
  1503. Count: item.Count,
  1504. }
  1505. //查询是否存在
  1506. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1507. if errcode == gorm.ErrRecordNotFound {
  1508. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
  1509. if errOne != nil {
  1510. utils.ErrorLog(errs.Error())
  1511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1512. return
  1513. }
  1514. c.ServeSuccessJSON(map[string]interface{}{
  1515. "msg": "1",
  1516. })
  1517. } else if errcode == nil {
  1518. service.UpDateWarehouseOutInfo(item)
  1519. }
  1520. }
  1521. //如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
  1522. if infoInfo.WarehousingCount < all_total {
  1523. c.ServeSuccessJSON(map[string]interface{}{
  1524. "msg": "6",
  1525. })
  1526. return
  1527. }
  1528. }
  1529. if item.Count == lastGood.Count {
  1530. errs = service.UpDateWarehouseOutInfo(item)
  1531. if errs != nil {
  1532. utils.ErrorLog(errs.Error())
  1533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1534. return
  1535. }
  1536. c.ServeSuccessJSON(map[string]interface{}{
  1537. "msg": "1",
  1538. })
  1539. }
  1540. }
  1541. }
  1542. if errs != nil {
  1543. utils.ErrorLog(errs.Error())
  1544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1545. return
  1546. }
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "msg": "1",
  1549. })
  1550. }
  1551. func (c *StockManagerApiController) CreateCancelStock() {
  1552. cancel_stock_time := c.GetString("time")
  1553. types, _ := c.GetInt64("type", 0)
  1554. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1555. if parseDateErr != nil {
  1556. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1558. return
  1559. }
  1560. adminUserInfo := c.GetAdminUserInfo()
  1561. operation_time := time.Now().Unix()
  1562. creater := adminUserInfo.AdminUser.Id
  1563. ctime := time.Now().Unix()
  1564. timeStr := time.Now().Format("2006-01-02")
  1565. timeArr := strings.Split(timeStr, "-")
  1566. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1567. total = total + 1
  1568. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1569. cancelStock := models.CancelStock{
  1570. OrderNumber: orderNumber,
  1571. OperaTime: operation_time,
  1572. OrgId: adminUserInfo.CurrentOrgId,
  1573. Creater: creater,
  1574. Ctime: ctime,
  1575. Status: 1,
  1576. ReturnTime: cancelStockDate.Unix(),
  1577. Type: types,
  1578. }
  1579. service.AddSigleCancelStock(&cancelStock)
  1580. dataBody := make(map[string]interface{}, 0)
  1581. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1582. if err != nil {
  1583. utils.ErrorLog(err.Error())
  1584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1585. return
  1586. }
  1587. var cancelStockInfos []*models.CancelStockInfo
  1588. var stockFLow []*models.VmStockFlow
  1589. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1590. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1591. if len(thisStockIn) > 0 {
  1592. for _, item := range thisStockIn {
  1593. items := item.(map[string]interface{})
  1594. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1595. utils.ErrorLog("good_id")
  1596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1597. return
  1598. }
  1599. good_id := int64(items["good_id"].(float64))
  1600. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1601. utils.ErrorLog("good_type_id")
  1602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. good_type_id := int64(items["good_type_id"].(float64))
  1606. return_count, _ := items["return_count"].(string)
  1607. if len(return_count) == 0 {
  1608. utils.ErrorLog("len(return_count) == 0")
  1609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1610. return
  1611. }
  1612. count, _ := strconv.ParseInt(return_count, 10, 64)
  1613. number := items["number"].(string)
  1614. register_account := items["register_account"].(string)
  1615. manufacturer, _ := items["manufacturer"].(string)
  1616. dealer, _ := items["dealer"].(string)
  1617. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1618. var expiryDates int64
  1619. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1620. expiryDates = 0
  1621. } else {
  1622. if len(items["expiry_date"].(string)) == 0 {
  1623. expiryDates = 0
  1624. } else {
  1625. expiryDate, _ := items["expiry_date"].(string)
  1626. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1627. expiryDates = expiry_date.Unix()
  1628. }
  1629. }
  1630. var productDates int64
  1631. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1632. productDates = 0
  1633. } else {
  1634. if len(items["product_date"].(string)) == 0 {
  1635. productDates = 0
  1636. } else {
  1637. productDate, _ := items["product_date"].(string)
  1638. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1639. productDates = product_date.Unix()
  1640. }
  1641. }
  1642. remark := items["remark"].(string)
  1643. retail_prices := items["price"].(string)
  1644. price, _ := strconv.ParseFloat(retail_prices, 64)
  1645. cancelStockInfo := &models.CancelStockInfo{
  1646. OrderNumber: cancelStock.OrderNumber,
  1647. CancelStockId: cancelStock.ID,
  1648. GoodId: good_id,
  1649. GoodTypeId: good_type_id,
  1650. Count: count,
  1651. Status: 1,
  1652. Ctime: ctime,
  1653. OrgId: adminUserInfo.CurrentOrgId,
  1654. Type: types,
  1655. Manufacturer: manufacturer,
  1656. Dealer: dealer,
  1657. Number: number,
  1658. ProductDate: productDates,
  1659. ExpiryDate: expiryDates,
  1660. RegisterAccount: register_account,
  1661. Remark: remark,
  1662. Price: price,
  1663. WarehouseInfoId: warehouse_info_id,
  1664. }
  1665. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1666. flow := &models.VmStockFlow{
  1667. WarehousingId: 0,
  1668. GoodId: good_id,
  1669. Number: number,
  1670. LicenseNumber: "",
  1671. Count: count,
  1672. UserOrgId: adminUserInfo.CurrentOrgId,
  1673. PatientId: 0,
  1674. SystemTime: time.Now().Unix(),
  1675. ConsumableType: 4,
  1676. IsSys: 0,
  1677. WarehousingOrder: "",
  1678. WarehouseOutId: 0,
  1679. WarehouseOutOrderNumber: "",
  1680. IsEdit: 0,
  1681. CancelStockId: cancelStock.ID,
  1682. CancelOrderNumber: cancelStock.OrderNumber,
  1683. Manufacturer: 0,
  1684. Dealer: 0,
  1685. Creator: adminUserInfo.AdminUser.Id,
  1686. UpdateCreator: 0,
  1687. Status: 1,
  1688. Ctime: time.Now().Unix(),
  1689. Mtime: 0,
  1690. Price: price,
  1691. WarehousingDetailId: 0,
  1692. WarehouseOutDetailId: 0,
  1693. CancelOutDetailId: 0,
  1694. ProductDate: productDates,
  1695. ExpireDate: expiryDates,
  1696. }
  1697. stockFLow = append(stockFLow, flow)
  1698. }
  1699. }
  1700. }
  1701. for _, item := range cancelStockInfos {
  1702. ////查找该耗材是否有出库记录
  1703. //_, errcode := service.GetWarehoureOutOrderInfo(item.GoodId, item.OrgId)
  1704. //if errcode == gorm.ErrRecordNotFound {
  1705. // c.ServeSuccessJSON(map[string]interface{}{
  1706. // "msg": "1",
  1707. // })
  1708. // return
  1709. //}
  1710. //统计该耗材的出库数量
  1711. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
  1712. fmt.Println("2333223323322332233223322323", item.Count, info.Count)
  1713. if item.Count > info.Count {
  1714. service.UpdateCancelInfo(item.CancelStockId)
  1715. c.ServeSuccessJSON(map[string]interface{}{
  1716. "msg": "2",
  1717. })
  1718. return
  1719. }
  1720. //查询该批次入库的值
  1721. infolist, _ := service.GetWarehouseInfoByIdSeven(item.WarehouseInfoId)
  1722. if item.Count > infolist.WarehousingCount {
  1723. c.ServeSuccessJSON(map[string]interface{}{
  1724. "msg": "4",
  1725. })
  1726. return
  1727. }
  1728. if item.Count <= infolist.WarehousingCount {
  1729. errs := service.CreateCancelStockInfo(cancelStockInfos)
  1730. if len(stockFLow) > 0 {
  1731. service.CreateStockFlow(stockFLow)
  1732. }
  1733. if errs != nil {
  1734. utils.ErrorLog(errs.Error())
  1735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1736. return
  1737. }
  1738. //查询该批次的剩余库存
  1739. wareouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  1740. if (wareouseinfo.StockCount + item.Count) > wareouseinfo.WarehousingCount {
  1741. c.ServeSuccessJSON(map[string]interface{}{
  1742. "msg": "5",
  1743. })
  1744. return
  1745. }
  1746. //更改入库数量
  1747. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  1748. //查询该耗材的入库记录
  1749. //list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
  1750. ////调用退库的方法
  1751. //parseDateErr := service.UpdateCancelOut(list, item.Count)
  1752. //fmt.Println("999999999999", parseDateErr)
  1753. break
  1754. }
  1755. }
  1756. c.ServeSuccessJSON(map[string]interface{}{
  1757. "msg": "3",
  1758. })
  1759. return
  1760. }
  1761. func (c *StockManagerApiController) GetCancelStockInfoList() {
  1762. id, _ := c.GetInt64("id", 0)
  1763. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  1764. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1765. manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
  1766. dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
  1767. c.ServeSuccessJSON(map[string]interface{}{
  1768. "list": cancelStockInfoList,
  1769. "info": info,
  1770. "manufacturerList": manufacturerList,
  1771. "dealerList": dealerList,
  1772. })
  1773. }
  1774. func (c *StockManagerApiController) GetCancelStockList() {
  1775. page, _ := c.GetInt64("page", -1)
  1776. limit, _ := c.GetInt64("limit", -1)
  1777. start_time := c.GetString("start_time")
  1778. end_time := c.GetString("end_time")
  1779. types, _ := c.GetInt64("type", 0)
  1780. keywords := c.GetString("keywords")
  1781. timeLayout := "2006-01-02"
  1782. loc, _ := time.LoadLocation("Local")
  1783. var startTime int64
  1784. if len(start_time) > 0 {
  1785. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1786. if err != nil {
  1787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1788. return
  1789. }
  1790. startTime = theTime.Unix()
  1791. }
  1792. var endTime int64
  1793. if len(end_time) > 0 {
  1794. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1795. if err != nil {
  1796. utils.ErrorLog(err.Error())
  1797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1798. return
  1799. }
  1800. endTime = theTime.Unix()
  1801. }
  1802. adminUserInfo := c.GetAdminUserInfo()
  1803. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1804. if err == nil {
  1805. c.ServeSuccessJSON(map[string]interface{}{
  1806. "list": returnList,
  1807. "total": total,
  1808. })
  1809. } else {
  1810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1811. }
  1812. }
  1813. func (this *StockManagerApiController) DeleteCancelStock() {
  1814. ids := this.GetString("ids")
  1815. if len(ids) == 0 {
  1816. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1817. return
  1818. }
  1819. idArray := strings.Split(ids, ",")
  1820. err := service.DeleteCancelStock(idArray)
  1821. if err != nil {
  1822. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1823. } else {
  1824. this.ServeSuccessJSON(map[string]interface{}{
  1825. "msg": "删除成功",
  1826. })
  1827. }
  1828. }
  1829. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  1830. id, _ := this.GetInt64("id", 0)
  1831. fmt.Println(id)
  1832. if id == 0 {
  1833. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1834. return
  1835. }
  1836. err := service.UpDateCancleStockStatus(id)
  1837. if err != nil {
  1838. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1839. } else {
  1840. this.ServeSuccessJSON(map[string]interface{}{
  1841. "msg": "删除成功",
  1842. })
  1843. }
  1844. }
  1845. func (c *StockManagerApiController) EditCancelStock() {
  1846. cancel_time := c.GetString("cancel_time")
  1847. id, _ := c.GetInt64("id", 0)
  1848. if id == 0 {
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1850. return
  1851. }
  1852. ctime := time.Now().Unix()
  1853. mtime := time.Now().Unix()
  1854. adminUserInfo := c.GetAdminUserInfo()
  1855. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1856. if parseDateErr != nil {
  1857. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1859. return
  1860. }
  1861. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1862. tempCancelStock := models.CancelStock{
  1863. ID: cancelStock.ID,
  1864. Mtime: mtime,
  1865. ReturnTime: cancelDate.Unix(),
  1866. }
  1867. service.EditCancelStock(tempCancelStock)
  1868. dataBody := make(map[string]interface{}, 0)
  1869. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1870. if err != nil {
  1871. utils.ErrorLog(err.Error())
  1872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1873. return
  1874. }
  1875. var cancelStockInfos []*models.CancelStockInfo
  1876. var upDateCancelStockInfos []*models.CancelStockInfo
  1877. var stockFlow []*models.VmStockFlow
  1878. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1879. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1880. if len(thisCancelStock) > 0 {
  1881. for _, item := range thisCancelStock {
  1882. items := item.(map[string]interface{})
  1883. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1884. utils.ErrorLog("good_id")
  1885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1886. return
  1887. }
  1888. good_id := int64(items["good_id"].(float64))
  1889. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1890. utils.ErrorLog("good_type_id")
  1891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1892. return
  1893. }
  1894. good_type_id := int64(items["good_type_id"].(float64))
  1895. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1896. utils.ErrorLog("count")
  1897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1898. return
  1899. }
  1900. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1901. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1902. utils.ErrorLog("id")
  1903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1904. return
  1905. }
  1906. id := int64(items["id"].(float64))
  1907. number := items["number"].(string)
  1908. register_account := items["register_account"].(string)
  1909. manufacturer, _ := items["manufacturer"].(string)
  1910. dealer, _ := items["dealer"].(string)
  1911. remark := items["remark"].(string)
  1912. var productDates int64
  1913. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1914. productDates = 0
  1915. } else {
  1916. if len(items["product_date"].(string)) == 0 {
  1917. productDates = 0
  1918. } else {
  1919. productDate, _ := items["product_date"].(string)
  1920. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1921. productDates = product_date.Unix()
  1922. }
  1923. }
  1924. var expiryDates int64
  1925. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1926. expiryDates = 0
  1927. } else {
  1928. if len(items["expiry_date"].(string)) == 0 {
  1929. expiryDates = 0
  1930. } else {
  1931. expiryDate, _ := items["expiry_date"].(string)
  1932. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1933. expiryDates = expiry_date.Unix()
  1934. }
  1935. }
  1936. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1937. utils.ErrorLog("price")
  1938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1939. return
  1940. }
  1941. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1942. if id == 0 {
  1943. cancelStockInfo := &models.CancelStockInfo{
  1944. GoodId: good_id,
  1945. GoodTypeId: good_type_id,
  1946. Count: count,
  1947. Status: 1,
  1948. Ctime: ctime,
  1949. OrgId: adminUserInfo.CurrentOrgId,
  1950. OrderNumber: cancelStock.OrderNumber,
  1951. CancelStockId: cancelStock.ID,
  1952. Mtime: time.Now().Unix(),
  1953. Number: number,
  1954. RegisterAccount: register_account,
  1955. Manufacturer: manufacturer,
  1956. Dealer: dealer,
  1957. ProductDate: productDates,
  1958. ExpiryDate: expiryDates,
  1959. Remark: remark,
  1960. Price: price,
  1961. }
  1962. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1963. flow := &models.VmStockFlow{
  1964. WarehousingId: 0,
  1965. GoodId: good_id,
  1966. Number: number,
  1967. LicenseNumber: "",
  1968. Count: count,
  1969. UserOrgId: adminUserInfo.CurrentOrgId,
  1970. PatientId: 0,
  1971. SystemTime: time.Now().Unix(),
  1972. ConsumableType: 4,
  1973. IsSys: 0,
  1974. WarehousingOrder: "",
  1975. WarehouseOutId: 0,
  1976. WarehouseOutOrderNumber: "",
  1977. IsEdit: 2,
  1978. CancelStockId: cancelStock.ID,
  1979. CancelOrderNumber: cancelStock.OrderNumber,
  1980. Manufacturer: 0,
  1981. Dealer: 0,
  1982. Creator: adminUserInfo.AdminUser.Id,
  1983. UpdateCreator: 0,
  1984. Status: 1,
  1985. Ctime: time.Now().Unix(),
  1986. Mtime: 0,
  1987. Price: price,
  1988. WarehousingDetailId: 0,
  1989. WarehouseOutDetailId: 0,
  1990. CancelOutDetailId: 0,
  1991. ProductDate: productDates,
  1992. ExpireDate: expiryDates,
  1993. }
  1994. stockFlow = append(stockFlow, flow)
  1995. } else {
  1996. cancelStockInfo := &models.CancelStockInfo{
  1997. ID: id,
  1998. GoodId: good_id,
  1999. GoodTypeId: good_type_id,
  2000. Count: count,
  2001. Status: 1,
  2002. Ctime: ctime,
  2003. OrgId: adminUserInfo.CurrentOrgId,
  2004. OrderNumber: cancelStock.OrderNumber,
  2005. CancelStockId: cancelStock.ID,
  2006. Mtime: time.Now().Unix(),
  2007. Number: number,
  2008. RegisterAccount: register_account,
  2009. Manufacturer: manufacturer,
  2010. Dealer: dealer,
  2011. ProductDate: productDates,
  2012. ExpiryDate: expiryDates,
  2013. Remark: remark,
  2014. Price: price,
  2015. }
  2016. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  2017. flow := &models.VmStockFlow{
  2018. WarehousingId: 0,
  2019. GoodId: good_id,
  2020. Number: number,
  2021. LicenseNumber: "",
  2022. Count: count,
  2023. UserOrgId: adminUserInfo.CurrentOrgId,
  2024. PatientId: 0,
  2025. SystemTime: time.Now().Unix(),
  2026. ConsumableType: 4,
  2027. IsSys: 0,
  2028. WarehousingOrder: "",
  2029. WarehouseOutId: 0,
  2030. WarehouseOutOrderNumber: "",
  2031. IsEdit: 2,
  2032. CancelStockId: cancelStock.ID,
  2033. CancelOrderNumber: cancelStock.OrderNumber,
  2034. Manufacturer: 0,
  2035. Dealer: 0,
  2036. Creator: adminUserInfo.AdminUser.Id,
  2037. UpdateCreator: 0,
  2038. Status: 1,
  2039. Ctime: time.Now().Unix(),
  2040. Mtime: 0,
  2041. Price: price,
  2042. WarehousingDetailId: 0,
  2043. WarehouseOutDetailId: 0,
  2044. CancelOutDetailId: 0,
  2045. ProductDate: productDates,
  2046. ExpireDate: expiryDates,
  2047. }
  2048. stockFlow = append(stockFlow, flow)
  2049. }
  2050. }
  2051. }
  2052. }
  2053. var errs error
  2054. fmt.Println("出库22322333223", cancelStockInfos)
  2055. fmt.Println("更新23232323232323233", upDateCancelStockInfos)
  2056. if len(cancelStockInfos) > 0 {
  2057. for _, item := range cancelStockInfos {
  2058. //统计该耗材的出库数量
  2059. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
  2060. if item.Count > info.Count {
  2061. c.ServeSuccessJSON(map[string]interface{}{
  2062. "msg": "2",
  2063. })
  2064. return
  2065. }
  2066. //查询该批次入库的值
  2067. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2068. if item.Count > infolist.WarehousingCount {
  2069. c.ServeSuccessJSON(map[string]interface{}{
  2070. "msg": "4",
  2071. })
  2072. return
  2073. }
  2074. if item.Count <= infolist.WarehousingCount {
  2075. errs := service.CreateCancelStockInfo(cancelStockInfos)
  2076. if len(stockFlow) > 0 {
  2077. service.CreateStockFlow(stockFlow)
  2078. }
  2079. if errs != nil {
  2080. utils.ErrorLog(errs.Error())
  2081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2082. return
  2083. }
  2084. //更改入库数量
  2085. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  2086. break
  2087. }
  2088. }
  2089. }
  2090. if len(upDateCancelStockInfos) > 0 {
  2091. for _, item := range upDateCancelStockInfos {
  2092. //获取该批次最后一套出库记录
  2093. info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
  2094. fmt.Println("info232332322332233223", info.Count, item.Count)
  2095. //比较出库数量和最后一次出库数据大小
  2096. //退库(加)
  2097. if item.Count < info.Count {
  2098. var total = info.Count - item.Count
  2099. errs = service.UpDateCancelStockInfo(item)
  2100. service.CreateStockFlow(stockFlow)
  2101. warehouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2102. if (warehouseinfo.StockCount + total) > warehouseinfo.StockCount {
  2103. c.ServeSuccessJSON(map[string]interface{}{
  2104. "msg": "5",
  2105. })
  2106. return
  2107. }
  2108. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
  2109. if parseDateErr != nil {
  2110. utils.ErrorLog(errs.Error())
  2111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2112. break
  2113. }
  2114. }
  2115. //(减)
  2116. if item.Count > info.Count {
  2117. errs = service.UpDateCancelStockInfo(item)
  2118. service.CreateStockFlow(stockFlow)
  2119. //查询该批次入库的值
  2120. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2121. if item.Count > infolist.WarehousingCount {
  2122. c.ServeSuccessJSON(map[string]interface{}{
  2123. "msg": "4",
  2124. })
  2125. return
  2126. }
  2127. if item.Count <= infolist.WarehousingCount {
  2128. var total_count = info.Count - item.Count
  2129. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total_count)
  2130. if parseDateErr != nil {
  2131. utils.ErrorLog(errs.Error())
  2132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2133. return
  2134. }
  2135. }
  2136. }
  2137. }
  2138. if errs != nil {
  2139. utils.ErrorLog(errs.Error())
  2140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2141. return
  2142. }
  2143. c.ServeSuccessJSON(map[string]interface{}{
  2144. "msg": "3",
  2145. })
  2146. }
  2147. if errs != nil {
  2148. utils.ErrorLog(errs.Error())
  2149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2150. return
  2151. }
  2152. c.ServeSuccessJSON(map[string]interface{}{
  2153. "msg": "3",
  2154. })
  2155. }
  2156. func (this *StockManagerApiController) GetCancelStockConfig() {
  2157. types, _ := this.GetInt64("type", 0)
  2158. adminUserInfo := this.GetAdminUserInfo()
  2159. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  2160. this.ServeSuccessJSON(map[string]interface{}{
  2161. "warehouseOutInfoList": warehouseOutInfoList,
  2162. })
  2163. }
  2164. func (c *StockManagerApiController) GetQueryInfo() {
  2165. page, _ := c.GetInt64("page", -1)
  2166. limit, _ := c.GetInt64("limit", -1)
  2167. keyword := c.GetString("keyword")
  2168. start_time := c.GetString("start_time")
  2169. end_time := c.GetString("end_time")
  2170. type_name, _ := c.GetInt64("type_name")
  2171. timeLayout := "2006-01-02"
  2172. loc, _ := time.LoadLocation("Local")
  2173. var startTime int64
  2174. if len(start_time) > 0 {
  2175. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2176. if err != nil {
  2177. fmt.Println(err)
  2178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2179. return
  2180. }
  2181. startTime = theTime.Unix()
  2182. }
  2183. var endTime int64
  2184. if len(end_time) > 0 {
  2185. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2186. if err != nil {
  2187. utils.ErrorLog(err.Error())
  2188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2189. return
  2190. }
  2191. endTime = theTime.Unix()
  2192. }
  2193. adminUserInfo := c.GetAdminUserInfo()
  2194. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  2195. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  2196. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
  2197. if err == nil {
  2198. c.ServeSuccessJSON(map[string]interface{}{
  2199. "list": list,
  2200. "total": total,
  2201. "info": info,
  2202. "infomationList": infomationList,
  2203. "orgid": adminUserInfo.CurrentOrgId,
  2204. })
  2205. } else {
  2206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2207. }
  2208. }
  2209. func (c *StockManagerApiController) SearchWarehouse() {
  2210. keywords := c.GetString("keywords")
  2211. adminUserInfo := c.GetAdminUserInfo()
  2212. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  2213. if err == nil {
  2214. c.ServeSuccessJSON(map[string]interface{}{
  2215. "list": warehouseList,
  2216. "total": total,
  2217. })
  2218. } else {
  2219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2220. }
  2221. }
  2222. func (c *StockManagerApiController) GetAllConfig() {
  2223. adminUserInfo := c.GetAdminUserInfo()
  2224. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  2225. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  2226. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  2227. goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  2228. c.ServeSuccessJSON(map[string]interface{}{
  2229. "manufacturer": manufacturer,
  2230. "dealer": dealer,
  2231. "goodType": goodType,
  2232. "goodInfo": goodInfo,
  2233. })
  2234. }
  2235. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  2236. types, _ := this.GetInt64("type", 0)
  2237. adminUserInfo := this.GetAdminUserInfo()
  2238. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  2239. this.ServeSuccessJSON(map[string]interface{}{
  2240. "warehouseInfoList": warehouseInfoList,
  2241. })
  2242. }
  2243. func (this *StockManagerApiController) GetDetailInfo() {
  2244. page, _ := this.GetInt64("page", 0)
  2245. limit, _ := this.GetInt64("limit", 0)
  2246. start_time := this.GetString("start_time")
  2247. end_time := this.GetString("end_time")
  2248. types, _ := this.GetInt64("type", 0)
  2249. keywords := this.GetString("keywords")
  2250. manufacturer, _ := this.GetInt64("manufacturer", 0)
  2251. order_type, _ := this.GetInt64("order_type", 0)
  2252. dealer, _ := this.GetInt64("dealer", 0)
  2253. timeLayout := "2006-01-02"
  2254. loc, _ := time.LoadLocation("Local")
  2255. var startTime int64
  2256. if len(start_time) > 0 {
  2257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2258. if err != nil {
  2259. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2260. return
  2261. }
  2262. startTime = theTime.Unix()
  2263. }
  2264. var endTime int64
  2265. if len(end_time) > 0 {
  2266. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2267. if err != nil {
  2268. utils.ErrorLog(err.Error())
  2269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2270. return
  2271. }
  2272. endTime = theTime.Unix()
  2273. }
  2274. adminUserInfo := this.GetAdminUserInfo()
  2275. var list []*models.WarehousingInfo
  2276. var list1 []*models.WarehouseOutInfo
  2277. var list2 []*models.SalesReturnInfo
  2278. var list3 []*models.CancelStockInfo
  2279. var total int64
  2280. var err error
  2281. var total_price float64
  2282. if types == 1 {
  2283. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2284. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2285. if err == nil {
  2286. this.ServeSuccessJSON(map[string]interface{}{
  2287. "list": list,
  2288. "total": total,
  2289. "total_price": total_price,
  2290. })
  2291. } else {
  2292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2293. }
  2294. } else if types == 2 {
  2295. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2296. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2297. if err == nil {
  2298. this.ServeSuccessJSON(map[string]interface{}{
  2299. "list": list1,
  2300. "total": total,
  2301. "total_price": total_price,
  2302. })
  2303. } else {
  2304. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2305. }
  2306. } else if types == 3 {
  2307. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2308. if err == nil {
  2309. this.ServeSuccessJSON(map[string]interface{}{
  2310. "list": list2,
  2311. "total": total,
  2312. })
  2313. } else {
  2314. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2315. }
  2316. } else if types == 4 {
  2317. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2318. if err == nil {
  2319. this.ServeSuccessJSON(map[string]interface{}{
  2320. "list": list3,
  2321. "total": total,
  2322. })
  2323. } else {
  2324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2325. }
  2326. }
  2327. }
  2328. func (this *StockManagerApiController) GetUserDetailInfo() {
  2329. order_id, _ := this.GetInt64("id")
  2330. if order_id <= 0 {
  2331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2332. return
  2333. }
  2334. adminUserInfo := this.GetAdminUserInfo()
  2335. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2336. if err == nil {
  2337. this.ServeSuccessJSON(map[string]interface{}{
  2338. "list": userDetails,
  2339. "total": total,
  2340. })
  2341. } else {
  2342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2343. return
  2344. }
  2345. }
  2346. func (this *StockManagerApiController) PostSearchStock() {
  2347. keyword := this.GetString("keyword")
  2348. adminUserInfo := this.GetAdminUserInfo()
  2349. orgId := adminUserInfo.CurrentOrgId
  2350. stock, err := service.PostSearchStock(keyword, orgId)
  2351. if err != nil {
  2352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2353. }
  2354. this.ServeSuccessJSON(map[string]interface{}{
  2355. "stock": stock,
  2356. })
  2357. }
  2358. func (this *StockManagerApiController) GetOutStockTotalCount() {
  2359. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  2360. adminUserInfo := this.GetAdminUserInfo()
  2361. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  2362. if err != nil {
  2363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2364. }
  2365. this.ServeSuccessJSON(map[string]interface{}{
  2366. "stockCount": stockCount,
  2367. })
  2368. }
  2369. func (this *StockManagerApiController) AddGoodInformation() {
  2370. adminUserInfo := this.GetAdminUserInfo()
  2371. orgId := adminUserInfo.CurrentOrgId
  2372. dataBody := make(map[string]interface{}, 0)
  2373. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2374. if err != nil {
  2375. utils.ErrorLog(err.Error())
  2376. return
  2377. }
  2378. utils.ErrorLog("%v", dataBody)
  2379. var goods []*models.GoodInfo
  2380. var total_goods []interface{}
  2381. tempGoods := dataBody["goods"].([]interface{})
  2382. total_goods = tempGoods
  2383. for index, goodMap := range tempGoods {
  2384. goodNameM := goodMap.(map[string]interface{})
  2385. var good models.GoodInfo
  2386. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  2387. utils.ErrorLog("good_name")
  2388. return
  2389. }
  2390. good_name, _ := goodNameM["good_name"].(string)
  2391. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  2392. err_log := models.ExportErrLog{
  2393. LogType: 5,
  2394. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2395. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  2396. Status: 1,
  2397. CreateTime: time.Now().Unix(),
  2398. UpdateTime: time.Now().Unix(),
  2399. ExportTime: time.Now().Unix(),
  2400. }
  2401. service.CreateExportErrLog(&err_log)
  2402. continue
  2403. }
  2404. good.GoodName = good_name
  2405. // 获取数据字典数据
  2406. var good_kind_id int64
  2407. var name = "耗材种类"
  2408. config, _ := service.GetDrugDataConfig(0, name)
  2409. good_kind := goodNameM["good_kind"].(string)
  2410. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  2411. err_log := models.ExportErrLog{
  2412. LogType: 5,
  2413. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2414. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  2415. Status: 1,
  2416. CreateTime: time.Now().Unix(),
  2417. UpdateTime: time.Now().Unix(),
  2418. ExportTime: time.Now().Unix(),
  2419. }
  2420. service.CreateExportErrLog(&err_log)
  2421. continue
  2422. }
  2423. if len(good_kind) != 0 {
  2424. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  2425. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  2426. dataconfig := models.DictDataconfig{
  2427. ParentId: config.ID,
  2428. Module: "system",
  2429. OrgId: orgId,
  2430. Name: good_kind,
  2431. FieldName: "",
  2432. Value: lastConfig.Value + 1,
  2433. CreatedTime: "",
  2434. UpdatedTime: "",
  2435. CreateUserId: adminUserInfo.AdminUser.Id,
  2436. Status: 1,
  2437. Remark: "",
  2438. DeleteIdSystem: 0,
  2439. Title: "",
  2440. Content: "",
  2441. Order: 0,
  2442. Code: "",
  2443. }
  2444. if errcodegoodkind == gorm.ErrRecordNotFound {
  2445. service.CreatedDicConfig(&dataconfig)
  2446. }
  2447. }
  2448. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  2449. for _, it := range dataConfig {
  2450. if good_kind == it.Name {
  2451. fmt.Println(it.Name)
  2452. good_kind_id = int64(it.Value)
  2453. }
  2454. }
  2455. good.GoodKind = good_kind_id
  2456. good_type := goodNameM["type_name"].(string)
  2457. if len(good_type) == 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. if len(good_type) != 0 {
  2471. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  2472. if errcodegoodtype == gorm.ErrRecordNotFound {
  2473. goodsType := models.GoodsType{
  2474. TypeName: good_type,
  2475. Remark: "",
  2476. Ctime: time.Now().Unix(),
  2477. Mtime: 0,
  2478. Creater: adminUserInfo.AdminUser.Id,
  2479. Modifier: 0,
  2480. OrgId: adminUserInfo.CurrentOrgId,
  2481. Status: 1,
  2482. Type: 0,
  2483. Number: 0,
  2484. OutStock: 0,
  2485. StockAttribute: 1,
  2486. }
  2487. service.CreatedGoodType(&goodsType)
  2488. }
  2489. }
  2490. goodType, _ := service.GetAllGoodType(orgId)
  2491. var good_type_id int64
  2492. for _, it := range goodType {
  2493. if good_type == it.TypeName {
  2494. good_type_id = it.ID
  2495. }
  2496. }
  2497. good.GoodTypeId = good_type_id
  2498. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  2499. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  2500. err_log := models.ExportErrLog{
  2501. LogType: 5,
  2502. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2503. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  2504. Status: 1,
  2505. CreateTime: time.Now().Unix(),
  2506. UpdateTime: time.Now().Unix(),
  2507. ExportTime: time.Now().Unix(),
  2508. }
  2509. service.CreateExportErrLog(&err_log)
  2510. continue
  2511. }
  2512. var medical_insurance_id int64
  2513. var medicalInsurance = "医保等级"
  2514. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  2515. if len(medical_insurance_level) != 0 {
  2516. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  2517. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  2518. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  2519. dataconfig := models.DictDataconfig{
  2520. ParentId: medicalInsuranceDataConfig.ID,
  2521. Module: "system",
  2522. OrgId: orgId,
  2523. Name: medical_insurance_level,
  2524. FieldName: "",
  2525. Value: mediConfigOne.Value + 1,
  2526. CreatedTime: "",
  2527. UpdatedTime: "",
  2528. CreateUserId: adminUserInfo.AdminUser.Id,
  2529. Status: 1,
  2530. Remark: "",
  2531. DeleteIdSystem: 0,
  2532. Title: "",
  2533. Content: "",
  2534. Order: 0,
  2535. Code: "",
  2536. }
  2537. service.CreatedDicConfig(&dataconfig)
  2538. }
  2539. }
  2540. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  2541. for _, it := range medicalInsuranceList {
  2542. if medical_insurance_level == it.Name {
  2543. medical_insurance_id = int64(it.Value)
  2544. }
  2545. }
  2546. good.MedicalInsuranceLevel = medical_insurance_id
  2547. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  2548. utils.ErrorLog("specification_name")
  2549. return
  2550. }
  2551. specification_name := goodNameM["specification_name"].(string)
  2552. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  2553. err_log := models.ExportErrLog{
  2554. LogType: 5,
  2555. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2556. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  2557. Status: 1,
  2558. CreateTime: time.Now().Unix(),
  2559. UpdateTime: time.Now().Unix(),
  2560. ExportTime: time.Now().Unix(),
  2561. }
  2562. service.CreateExportErrLog(&err_log)
  2563. continue
  2564. }
  2565. good.SpecificationName = specification_name
  2566. var manufacturer_id int64
  2567. manufacturer := goodNameM["manufacturer"].(string)
  2568. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  2569. err_log := models.ExportErrLog{
  2570. LogType: 5,
  2571. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2572. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  2573. Status: 1,
  2574. CreateTime: time.Now().Unix(),
  2575. UpdateTime: time.Now().Unix(),
  2576. ExportTime: time.Now().Unix(),
  2577. }
  2578. service.CreateExportErrLog(&err_log)
  2579. continue
  2580. }
  2581. if len(manufacturer) != 0 {
  2582. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  2583. manu := models.Manufacturer{
  2584. ManufacturerName: manufacturer,
  2585. Status: 1,
  2586. OrgId: orgId,
  2587. Creater: adminUserInfo.AdminUser.Id,
  2588. }
  2589. if errcodes == gorm.ErrRecordNotFound {
  2590. service.CreateManufacturer(&manu)
  2591. }
  2592. }
  2593. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2594. for _, it := range manufacturerList {
  2595. if manufacturer == it.ManufacturerName {
  2596. manufacturer_id = it.ID
  2597. }
  2598. }
  2599. good.Manufacturer = manufacturer_id
  2600. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  2601. utils.ErrorLog("unit_id")
  2602. return
  2603. }
  2604. unit_id := int64(goodNameM["unit_id"].(float64))
  2605. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  2606. err_log := models.ExportErrLog{
  2607. LogType: 5,
  2608. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2609. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  2610. Status: 1,
  2611. CreateTime: time.Now().Unix(),
  2612. UpdateTime: time.Now().Unix(),
  2613. ExportTime: time.Now().Unix(),
  2614. }
  2615. service.CreateExportErrLog(&err_log)
  2616. continue
  2617. }
  2618. good.GoodUnit = unit_id
  2619. retail_prices := goodNameM["retail_price"].(string)
  2620. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2621. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  2622. err_log := models.ExportErrLog{
  2623. LogType: 5,
  2624. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2625. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
  2626. Status: 1,
  2627. CreateTime: time.Now().Unix(),
  2628. UpdateTime: time.Now().Unix(),
  2629. ExportTime: time.Now().Unix(),
  2630. }
  2631. service.CreateExportErrLog(&err_log)
  2632. continue
  2633. }
  2634. good.RetailPrice = retail_price
  2635. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  2636. utils.ErrorLog("stock_warn_count")
  2637. return
  2638. }
  2639. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  2640. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  2641. err_log := models.ExportErrLog{
  2642. LogType: 5,
  2643. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2644. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  2645. Status: 1,
  2646. CreateTime: time.Now().Unix(),
  2647. UpdateTime: time.Now().Unix(),
  2648. ExportTime: time.Now().Unix(),
  2649. }
  2650. service.CreateExportErrLog(&err_log)
  2651. continue
  2652. }
  2653. good.StockWarnCount = stock_warn_count
  2654. var dealer_id int64
  2655. dealerName := goodNameM["dealer"].(string)
  2656. fmt.Println("经销商", dealerName)
  2657. dealer := models.Dealer{
  2658. OrgId: orgId,
  2659. Status: 1,
  2660. DealerName: dealerName,
  2661. Creater: adminUserInfo.AdminUser.Id,
  2662. Ctime: time.Now().Unix(),
  2663. }
  2664. if len(dealerName) != 0 {
  2665. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  2666. if errcodedealer == gorm.ErrRecordNotFound {
  2667. service.CreateDealer(&dealer)
  2668. }
  2669. }
  2670. dealerList, _ := service.GetAllDealerList(orgId)
  2671. for _, it := range dealerList {
  2672. if dealerName == it.DealerName {
  2673. dealer_id = it.ID
  2674. }
  2675. }
  2676. good.Dealer = dealer_id
  2677. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  2678. utils.ErrorLog("pinyin")
  2679. return
  2680. }
  2681. pinyin := goodNameM["pinyin"].(string)
  2682. good.Pinyin = pinyin
  2683. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  2684. utils.ErrorLog("wubi")
  2685. return
  2686. }
  2687. wubi := goodNameM["wubi"].(string)
  2688. good.Wubi = wubi
  2689. buy_prices := goodNameM["buy_price"].(string)
  2690. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  2691. good.BuyPrice = buy_price
  2692. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  2693. utils.ErrorLog("social_security_directory_code")
  2694. return
  2695. }
  2696. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2697. good.SocialSecurityDirectoryCode = social_security_directory_code
  2698. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  2699. utils.ErrorLog("is_special_diseases")
  2700. return
  2701. }
  2702. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2703. good.IsSpecialDiseases = is_special_diseases
  2704. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  2705. utils.ErrorLog("is_record")
  2706. return
  2707. }
  2708. is_record := int64(goodNameM["is_record"].(float64))
  2709. good.IsRecord = is_record
  2710. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  2711. utils.ErrorLog("good_status")
  2712. return
  2713. }
  2714. good_status := goodNameM["good_status"].(string)
  2715. good.GoodStatus = good_status
  2716. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  2717. utils.ErrorLog("medical_insurance_number")
  2718. return
  2719. }
  2720. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2721. good.MedicalInsuranceNumber = medical_insurance_number
  2722. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  2723. utils.ErrorLog("production_type")
  2724. return
  2725. }
  2726. production_type := goodNameM["production_type"].(string)
  2727. good.ProductionType = production_type
  2728. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  2729. utils.ErrorLog("remark")
  2730. return
  2731. }
  2732. remark := goodNameM["remark"].(string)
  2733. good.Remark = remark
  2734. statistics_category := goodNameM["statistics_category"].(string)
  2735. var categoryName = "统计分类"
  2736. var statistic_id int64
  2737. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  2738. if len(statistics_category) != 0 {
  2739. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  2740. if errcodecagegory == gorm.ErrRecordNotFound {
  2741. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  2742. dataconfig := models.DictDataconfig{
  2743. ParentId: drugDataConfig.ID,
  2744. Module: "system",
  2745. OrgId: orgId,
  2746. Name: statistics_category,
  2747. FieldName: "",
  2748. Value: dicConfigThree.Value + 1,
  2749. CreatedTime: "",
  2750. UpdatedTime: "",
  2751. CreateUserId: adminUserInfo.AdminUser.Id,
  2752. Status: 1,
  2753. Remark: "",
  2754. DeleteIdSystem: 0,
  2755. Title: "",
  2756. Content: "",
  2757. Order: 0,
  2758. Code: "",
  2759. }
  2760. service.CreatedDicConfig(&dataconfig)
  2761. }
  2762. }
  2763. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  2764. for _, it := range parentDataConfig {
  2765. if statistics_category == it.Name {
  2766. statistic_id = int64(it.Value)
  2767. }
  2768. }
  2769. good.StatisticsCategory = statistic_id
  2770. special_medical := goodNameM["special_medical"].(string)
  2771. good.SpecialMedical = special_medical
  2772. goods = append(goods, &good)
  2773. }
  2774. export_time := time.Now().Unix()
  2775. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2776. if len(goods) > 0 {
  2777. for _, item := range goods {
  2778. goodInfo := models.GoodInfo{
  2779. GoodName: item.GoodName,
  2780. SpecificationName: item.SpecificationName,
  2781. GoodKind: item.GoodKind,
  2782. GoodTypeId: item.GoodTypeId,
  2783. Dealer: item.Dealer,
  2784. GoodUnit: item.GoodUnit,
  2785. IsRecord: item.IsRecord,
  2786. IsSpecialDiseases: item.IsSpecialDiseases,
  2787. Manufacturer: item.Manufacturer,
  2788. Pinyin: item.Pinyin,
  2789. GoodStatus: item.GoodStatus,
  2790. ProductionType: item.ProductionType,
  2791. Remark: item.Remark,
  2792. RetailPrice: item.RetailPrice,
  2793. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  2794. SpecialMedical: item.SpecialMedical,
  2795. Wubi: item.Wubi,
  2796. StockWarnCount: item.StockWarnCount,
  2797. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  2798. OrgId: orgId,
  2799. Status: 1,
  2800. Ctime: time.Now().Unix(),
  2801. StatisticsCategory: item.StatisticsCategory,
  2802. GoodCode: item.GoodCode,
  2803. BuyPrice: item.BuyPrice,
  2804. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  2805. }
  2806. //查询同种耗材名称同种类型同种规格的耗材是否存在
  2807. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2808. if errcodegood == gorm.ErrRecordNotFound {
  2809. service.CreateGoodsInfomation(&goodInfo)
  2810. } else if errcodegood == nil {
  2811. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2812. }
  2813. log := models.ExportLog{
  2814. LogType: 5,
  2815. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2816. TotalNum: int64(len(total_goods)),
  2817. FailNum: int64(len(errLogs)),
  2818. SuccessNum: int64(len(goods)),
  2819. CreateTime: time.Now().Unix(),
  2820. UpdateTime: time.Now().Unix(),
  2821. ExportTime: export_time,
  2822. Status: 1,
  2823. }
  2824. service.CreateExportLog(&log)
  2825. this.ServeSuccessJSON(map[string]interface{}{
  2826. "msg": "导入成功",
  2827. "total_num": len(total_goods),
  2828. "success_num": len(goods),
  2829. "fail_num": int64(len(errLogs)),
  2830. })
  2831. }
  2832. } else {
  2833. log := models.ExportLog{
  2834. LogType: 5,
  2835. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2836. TotalNum: int64(len(total_goods)),
  2837. FailNum: int64(len(errLogs)),
  2838. SuccessNum: int64(len(goods)),
  2839. CreateTime: time.Now().Unix(),
  2840. UpdateTime: time.Now().Unix(),
  2841. ExportTime: export_time,
  2842. Status: 1,
  2843. }
  2844. service.CreateExportLog(&log)
  2845. this.ServeSuccessJSON(map[string]interface{}{
  2846. "msg": "导入成功",
  2847. "total_num": len(total_goods),
  2848. "success_num": len(goods),
  2849. "fail_num": int64(len(errLogs)),
  2850. })
  2851. }
  2852. }
  2853. func (this *StockManagerApiController) AddDrugInformation() {
  2854. adminUser := this.GetAdminUserInfo()
  2855. orgId := adminUser.CurrentOrgId
  2856. dataBody := make(map[string]interface{}, 0)
  2857. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2858. if err != nil {
  2859. utils.ErrorLog(err.Error())
  2860. return
  2861. }
  2862. utils.ErrorLog("%v", dataBody)
  2863. var drugList []*models.BaseDrugLib
  2864. var total_goods []interface{}
  2865. tempDrugs := dataBody["drugs"].([]interface{})
  2866. total_goods = tempDrugs
  2867. for index, drugMap := range tempDrugs {
  2868. goodNameM := drugMap.(map[string]interface{})
  2869. var drug models.BaseDrugLib
  2870. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  2871. utils.ErrorLog("drug_name")
  2872. return
  2873. }
  2874. drug_name, _ := goodNameM["drug_name"].(string)
  2875. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2876. err_log := models.ExportErrLog{
  2877. LogType: 4,
  2878. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2879. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  2880. Status: 1,
  2881. CreateTime: time.Now().Unix(),
  2882. UpdateTime: time.Now().Unix(),
  2883. ExportTime: time.Now().Unix(),
  2884. }
  2885. service.CreateExportErrLog(&err_log)
  2886. continue
  2887. }
  2888. drug.DrugName = drug_name
  2889. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  2890. utils.ErrorLog("min_number")
  2891. return
  2892. }
  2893. min_number, _ := goodNameM["min_number"].(string)
  2894. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  2895. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2896. err_log := models.ExportErrLog{
  2897. LogType: 4,
  2898. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2899. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  2900. Status: 1,
  2901. CreateTime: time.Now().Unix(),
  2902. UpdateTime: time.Now().Unix(),
  2903. ExportTime: time.Now().Unix(),
  2904. }
  2905. service.CreateExportErrLog(&err_log)
  2906. continue
  2907. }
  2908. drug.MinNumber = minNumber
  2909. min_unit := goodNameM["min_unit"].(string)
  2910. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  2911. err_log := models.ExportErrLog{
  2912. LogType: 4,
  2913. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2914. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  2915. Status: 1,
  2916. CreateTime: time.Now().Unix(),
  2917. UpdateTime: time.Now().Unix(),
  2918. ExportTime: time.Now().Unix(),
  2919. }
  2920. service.CreateExportErrLog(&err_log)
  2921. continue
  2922. }
  2923. drug.MinUnit = min_unit
  2924. dose := goodNameM["dose"].(float64)
  2925. if dose < 0 { //名字为空则生成一条导入错误日志
  2926. err_log := models.ExportErrLog{
  2927. LogType: 4,
  2928. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2929. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  2930. Status: 1,
  2931. CreateTime: time.Now().Unix(),
  2932. UpdateTime: time.Now().Unix(),
  2933. ExportTime: time.Now().Unix(),
  2934. }
  2935. service.CreateExportErrLog(&err_log)
  2936. continue
  2937. }
  2938. drug.Dose = dose
  2939. max_unit_id := goodNameM["max_unit"].(string)
  2940. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  2941. err_log := models.ExportErrLog{
  2942. LogType: 4,
  2943. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2944. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  2945. Status: 1,
  2946. CreateTime: time.Now().Unix(),
  2947. UpdateTime: time.Now().Unix(),
  2948. ExportTime: time.Now().Unix(),
  2949. }
  2950. service.CreateExportErrLog(&err_log)
  2951. continue
  2952. }
  2953. drug.MaxUnit = max_unit_id
  2954. max_unit := goodNameM["max_unit"].(string)
  2955. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  2956. err_log := models.ExportErrLog{
  2957. LogType: 4,
  2958. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2959. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  2960. Status: 1,
  2961. CreateTime: time.Now().Unix(),
  2962. UpdateTime: time.Now().Unix(),
  2963. ExportTime: time.Now().Unix(),
  2964. }
  2965. service.CreateExportErrLog(&err_log)
  2966. continue
  2967. }
  2968. drug.MaxUnit = max_unit
  2969. delivery_way := goodNameM["delivery_way"].(string)
  2970. if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
  2971. err_log := models.ExportErrLog{
  2972. LogType: 4,
  2973. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2974. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  2975. Status: 1,
  2976. CreateTime: time.Now().Unix(),
  2977. UpdateTime: time.Now().Unix(),
  2978. ExportTime: time.Now().Unix(),
  2979. }
  2980. service.CreateExportErrLog(&err_log)
  2981. continue
  2982. }
  2983. drug.DeliveryWay = delivery_way
  2984. execution_frequency := goodNameM["execution_frequency"].(string)
  2985. if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
  2986. err_log := models.ExportErrLog{
  2987. LogType: 4,
  2988. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2989. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  2990. Status: 1,
  2991. CreateTime: time.Now().Unix(),
  2992. UpdateTime: time.Now().Unix(),
  2993. ExportTime: time.Now().Unix(),
  2994. }
  2995. service.CreateExportErrLog(&err_log)
  2996. continue
  2997. }
  2998. drug.ExecutionFrequency = execution_frequency
  2999. drug_day := goodNameM["drug_day"].(string)
  3000. if len(drug_day) == 0 { //名字为空则生成一条导入错误日志
  3001. err_log := models.ExportErrLog{
  3002. LogType: 4,
  3003. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3004. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  3005. Status: 1,
  3006. CreateTime: time.Now().Unix(),
  3007. UpdateTime: time.Now().Unix(),
  3008. ExportTime: time.Now().Unix(),
  3009. }
  3010. service.CreateExportErrLog(&err_log)
  3011. continue
  3012. }
  3013. drug.DrugDay = drug_day
  3014. drug_type := goodNameM["drug_type"].(string)
  3015. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  3016. err_log := models.ExportErrLog{
  3017. LogType: 4,
  3018. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3019. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  3020. Status: 1,
  3021. CreateTime: time.Now().Unix(),
  3022. UpdateTime: time.Now().Unix(),
  3023. ExportTime: time.Now().Unix(),
  3024. }
  3025. service.CreateExportErrLog(&err_log)
  3026. continue
  3027. }
  3028. var drug_type_id int64
  3029. var drugType = "药品类型"
  3030. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  3031. if len(drug_type) != 0 {
  3032. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  3033. if errcodes == gorm.ErrRecordNotFound {
  3034. //获取该型号最后一条数据型号
  3035. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  3036. dataconfig := models.DictDataconfig{
  3037. ParentId: drugconfig.ID,
  3038. Module: "system",
  3039. OrgId: orgId,
  3040. Name: drug_type,
  3041. FieldName: "",
  3042. Value: config.Value + 1,
  3043. CreatedTime: "",
  3044. UpdatedTime: "",
  3045. CreateUserId: adminUser.AdminUser.Id,
  3046. Status: 1,
  3047. Remark: "",
  3048. DeleteIdSystem: 0,
  3049. Title: "",
  3050. Content: "",
  3051. Order: 0,
  3052. Code: "",
  3053. }
  3054. service.CreatedDicConfig(&dataconfig)
  3055. }
  3056. }
  3057. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  3058. for _, it := range drugTypeList {
  3059. if drug_type == it.Name {
  3060. drug_type_id = int64(it.Value)
  3061. }
  3062. }
  3063. drug.DrugType = drug_type_id
  3064. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  3065. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  3066. err_log := models.ExportErrLog{
  3067. LogType: 4,
  3068. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3069. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  3070. Status: 1,
  3071. CreateTime: time.Now().Unix(),
  3072. UpdateTime: time.Now().Unix(),
  3073. ExportTime: time.Now().Unix(),
  3074. }
  3075. service.CreateExportErrLog(&err_log)
  3076. continue
  3077. }
  3078. drug.DrugStockLimit = drug_stock_limit
  3079. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  3080. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  3081. err_log := models.ExportErrLog{
  3082. LogType: 4,
  3083. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3084. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  3085. Status: 1,
  3086. CreateTime: time.Now().Unix(),
  3087. UpdateTime: time.Now().Unix(),
  3088. ExportTime: time.Now().Unix(),
  3089. }
  3090. service.CreateExportErrLog(&err_log)
  3091. continue
  3092. }
  3093. drug.DrugOriginPlace = drug_origin_place
  3094. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  3095. if len(drug_dosage_form) == 0 {
  3096. err_log := models.ExportErrLog{
  3097. LogType: 4,
  3098. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3099. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  3100. Status: 1,
  3101. CreateTime: time.Now().Unix(),
  3102. UpdateTime: time.Now().Unix(),
  3103. ExportTime: time.Now().Unix(),
  3104. }
  3105. service.CreateExportErrLog(&err_log)
  3106. continue
  3107. }
  3108. var drug_dosage = "药品剂型"
  3109. var drug_dosage_form_id int64
  3110. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  3111. if len(drug_dosage_form) != 0 {
  3112. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  3113. if errcodess == gorm.ErrRecordNotFound {
  3114. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  3115. dataconfig := models.DictDataconfig{
  3116. ParentId: drugDosageconfig.ID,
  3117. Module: "system",
  3118. OrgId: orgId,
  3119. Name: drug_dosage_form,
  3120. FieldName: "",
  3121. Value: configOne.Value + 1,
  3122. CreatedTime: "",
  3123. UpdatedTime: "",
  3124. CreateUserId: adminUser.AdminUser.Id,
  3125. Status: 1,
  3126. Remark: "",
  3127. DeleteIdSystem: 0,
  3128. Title: "",
  3129. Content: "",
  3130. Order: 0,
  3131. Code: "",
  3132. }
  3133. service.CreatedDicConfig(&dataconfig)
  3134. }
  3135. }
  3136. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  3137. for _, it := range drugDosageList {
  3138. if drug_dosage_form == it.Name {
  3139. drug_dosage_form_id = int64(it.Value)
  3140. }
  3141. }
  3142. drug.DrugDosageForm = drug_dosage_form_id
  3143. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  3144. var medical_insurance_level_id int64
  3145. if len(medical_insurance_level) == 0 { //名字为空则生成一条导入错误日志
  3146. err_log := models.ExportErrLog{
  3147. LogType: 4,
  3148. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3149. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  3150. Status: 1,
  3151. CreateTime: time.Now().Unix(),
  3152. UpdateTime: time.Now().Unix(),
  3153. ExportTime: time.Now().Unix(),
  3154. }
  3155. service.CreateExportErrLog(&err_log)
  3156. continue
  3157. }
  3158. var medicalInsuranceName = "医保等级"
  3159. medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
  3160. if len(medical_insurance_level) != 0 {
  3161. _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
  3162. if errcodemedical == gorm.ErrRecordNotFound {
  3163. medConfig, _ := service.GetLastDicConfig(medicalInsuranceConfig.ID, orgId)
  3164. dataconfig := models.DictDataconfig{
  3165. ParentId: medicalInsuranceConfig.ID,
  3166. Module: "system",
  3167. OrgId: orgId,
  3168. Name: medical_insurance_level,
  3169. FieldName: "",
  3170. Value: medConfig.Value + 1,
  3171. CreatedTime: "",
  3172. UpdatedTime: "",
  3173. CreateUserId: adminUser.AdminUser.Id,
  3174. Status: 1,
  3175. Remark: "",
  3176. DeleteIdSystem: 0,
  3177. Title: "",
  3178. Content: "",
  3179. Order: 0,
  3180. Code: "",
  3181. }
  3182. service.CreatedDicConfig(&dataconfig)
  3183. }
  3184. }
  3185. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
  3186. for _, it := range medicalInsuranceList {
  3187. if medical_insurance_level == it.Name {
  3188. medical_insurance_level_id = int64(it.Value)
  3189. }
  3190. }
  3191. drug.MedicalInsuranceLevel = medical_insurance_level_id
  3192. unit_matrixing := goodNameM["unit_matrixing"].(string)
  3193. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3194. err_log := models.ExportErrLog{
  3195. LogType: 4,
  3196. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3197. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
  3198. Status: 1,
  3199. CreateTime: time.Now().Unix(),
  3200. UpdateTime: time.Now().Unix(),
  3201. ExportTime: time.Now().Unix(),
  3202. }
  3203. service.CreateExportErrLog(&err_log)
  3204. continue
  3205. }
  3206. drug.UnitMatrixing = unit_matrixing
  3207. retail_prices := goodNameM["retail_price"].(string)
  3208. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3209. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3210. err_log := models.ExportErrLog{
  3211. LogType: 4,
  3212. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3213. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  3214. Status: 1,
  3215. CreateTime: time.Now().Unix(),
  3216. UpdateTime: time.Now().Unix(),
  3217. ExportTime: time.Now().Unix(),
  3218. }
  3219. service.CreateExportErrLog(&err_log)
  3220. continue
  3221. }
  3222. drug.RetailPrice = retail_price
  3223. packing_prices := goodNameM["packing_price"].(string)
  3224. packing_price, _ := strconv.ParseFloat(packing_prices, 64)
  3225. if packing_price <= 0 { //名字为空则生成一条导入错误日志
  3226. err_log := models.ExportErrLog{
  3227. LogType: 4,
  3228. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3229. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装零售价不能为空",
  3230. Status: 1,
  3231. CreateTime: time.Now().Unix(),
  3232. UpdateTime: time.Now().Unix(),
  3233. ExportTime: time.Now().Unix(),
  3234. }
  3235. service.CreateExportErrLog(&err_log)
  3236. continue
  3237. }
  3238. drug.RetailPrice = retail_price
  3239. last_prices := goodNameM["last_price"].(string)
  3240. last_price, _ := strconv.ParseFloat(last_prices, 64)
  3241. if last_price <= 0 { //名字为空则生成一条导入错误日志
  3242. err_log := models.ExportErrLog{
  3243. LogType: 4,
  3244. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3245. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  3246. Status: 1,
  3247. CreateTime: time.Now().Unix(),
  3248. UpdateTime: time.Now().Unix(),
  3249. ExportTime: time.Now().Unix(),
  3250. }
  3251. service.CreateExportErrLog(&err_log)
  3252. continue
  3253. }
  3254. drug.LastPrice = last_price
  3255. drug_classify := goodNameM["drug_classify"].(string)
  3256. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  3257. err_log := models.ExportErrLog{
  3258. LogType: 4,
  3259. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3260. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  3261. Status: 1,
  3262. CreateTime: time.Now().Unix(),
  3263. UpdateTime: time.Now().Unix(),
  3264. ExportTime: time.Now().Unix(),
  3265. }
  3266. service.CreateExportErrLog(&err_log)
  3267. continue
  3268. }
  3269. var drugClassify = "药物分类"
  3270. var drug_classify_id int64
  3271. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  3272. if len(drug_classify) != 0 {
  3273. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  3274. if errcodesClass == gorm.ErrRecordNotFound {
  3275. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  3276. dataconfig := models.DictDataconfig{
  3277. ParentId: drugClassifyConfig.ID,
  3278. Module: "system",
  3279. OrgId: orgId,
  3280. Name: drug_classify,
  3281. FieldName: "",
  3282. Value: drugClassConfig.Value + 1,
  3283. CreatedTime: "",
  3284. UpdatedTime: "",
  3285. CreateUserId: adminUser.AdminUser.Id,
  3286. Status: 1,
  3287. Remark: "",
  3288. DeleteIdSystem: 0,
  3289. Title: "",
  3290. Content: "",
  3291. Order: 0,
  3292. Code: "",
  3293. }
  3294. service.CreatedDicConfig(&dataconfig)
  3295. }
  3296. }
  3297. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  3298. for _, it := range drugClassList {
  3299. if drug_classify == it.Name {
  3300. drug_classify_id = int64(it.Value)
  3301. }
  3302. }
  3303. drug_dose := goodNameM["drug_dose"].(string)
  3304. if len(drug_dose) == 0 {
  3305. err_log := models.ExportErrLog{
  3306. LogType: 4,
  3307. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3308. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  3309. Status: 1,
  3310. CreateTime: time.Now().Unix(),
  3311. UpdateTime: time.Now().Unix(),
  3312. ExportTime: time.Now().Unix(),
  3313. }
  3314. service.CreateExportErrLog(&err_log)
  3315. continue
  3316. }
  3317. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  3318. drug.DrugDose = drugDoses
  3319. var units = "单位"
  3320. var unit_id int64
  3321. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  3322. if len(drugDoseUnit) == 0 {
  3323. err_log := models.ExportErrLog{
  3324. LogType: 4,
  3325. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3326. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  3327. Status: 1,
  3328. CreateTime: time.Now().Unix(),
  3329. UpdateTime: time.Now().Unix(),
  3330. ExportTime: time.Now().Unix(),
  3331. }
  3332. service.CreateExportErrLog(&err_log)
  3333. continue
  3334. }
  3335. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  3336. if len(drugDoseUnit) != 0 {
  3337. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  3338. if errcodedataconfig == gorm.ErrRecordNotFound {
  3339. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  3340. dataconfig := models.Dataconfig{
  3341. ParentId: dataConfig.ID,
  3342. Module: "hemodialysis",
  3343. OrgId: orgId,
  3344. Name: drugDoseUnit,
  3345. FieldName: "",
  3346. Value: childConfig.Value + 1,
  3347. CreatedTime: "",
  3348. UpdatedTime: "",
  3349. CreateUserId: adminUser.AdminUser.Id,
  3350. Status: 1,
  3351. Remark: "",
  3352. DeleteIdSystem: 0,
  3353. Title: "",
  3354. Content: "",
  3355. Order: 0,
  3356. Code: "",
  3357. FieldType: 0,
  3358. }
  3359. service.CreateDataConfig(&dataconfig)
  3360. }
  3361. }
  3362. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  3363. for _, it := range list {
  3364. if drugDoseUnit == it.Name {
  3365. unit_id = int64(it.Value)
  3366. }
  3367. }
  3368. drug.DrugDoseUnit = unit_id
  3369. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  3370. manufacturer := goodNameM["manufacturer"].(string)
  3371. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3372. err_log := models.ExportErrLog{
  3373. LogType: 4,
  3374. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3375. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  3376. Status: 1,
  3377. CreateTime: time.Now().Unix(),
  3378. UpdateTime: time.Now().Unix(),
  3379. ExportTime: time.Now().Unix(),
  3380. }
  3381. service.CreateExportErrLog(&err_log)
  3382. continue
  3383. }
  3384. if len(manufacturer) != 0 {
  3385. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  3386. if errcodema == gorm.ErrRecordNotFound {
  3387. manufactur := models.Manufacturer{
  3388. OrgId: orgId,
  3389. Status: 1,
  3390. ManufacturerName: manufacturer,
  3391. Ctime: time.Now().Unix(),
  3392. Creater: adminUser.AdminUser.Id,
  3393. }
  3394. service.CreateManufacturer(&manufactur)
  3395. }
  3396. }
  3397. var manufacturer_id int64
  3398. manufacturList, _ := service.GetAllManufacturerList(orgId)
  3399. for _, it := range manufacturList {
  3400. if manufacturer == it.ManufacturerName {
  3401. manufacturer_id = it.ID
  3402. }
  3403. }
  3404. drug.Manufacturer = manufacturer_id
  3405. dealer := goodNameM["dealer"].(string)
  3406. if len(dealer) != 0 {
  3407. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  3408. if errcodesdealer == gorm.ErrRecordNotFound {
  3409. dealerconfig := models.Dealer{
  3410. DealerName: dealer,
  3411. Status: 1,
  3412. OrgId: orgId,
  3413. Ctime: time.Now().Unix(),
  3414. Creater: adminUser.AdminUser.Id,
  3415. }
  3416. service.CreateDealer(&dealerconfig)
  3417. }
  3418. }
  3419. var dealer_id int64
  3420. dealerList, _ := service.GetAllDealerList(orgId)
  3421. for _, it := range dealerList {
  3422. if dealer == it.DealerName {
  3423. dealer_id = it.ID
  3424. }
  3425. }
  3426. drug.Dealer = dealer_id
  3427. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  3428. drug.LmtUsedFlag = lmt_used_flags
  3429. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  3430. utils.ErrorLog("drug_alias")
  3431. return
  3432. }
  3433. drug_alias, _ := goodNameM["drug_alias"].(string)
  3434. drug.DrugAlias = drug_alias
  3435. drug_category := goodNameM["drug_category"].(string)
  3436. var drugCategory = "药品类别"
  3437. var drug_category_id int64
  3438. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  3439. if len(drug_category) != 0 {
  3440. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  3441. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  3442. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  3443. dataconfig := models.DictDataconfig{
  3444. ParentId: drugCategoryConfig.ID,
  3445. Module: "system",
  3446. OrgId: orgId,
  3447. Name: drug_category,
  3448. FieldName: "",
  3449. Value: drugCategoryConfigSix.Value + 1,
  3450. CreatedTime: "",
  3451. UpdatedTime: "",
  3452. CreateUserId: adminUser.AdminUser.Id,
  3453. Status: 1,
  3454. Remark: "",
  3455. DeleteIdSystem: 0,
  3456. Title: "",
  3457. Content: "",
  3458. Order: 0,
  3459. Code: "",
  3460. }
  3461. service.CreatedDicConfig(&dataconfig)
  3462. }
  3463. }
  3464. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  3465. fmt.Println("drugCategoryList", drugCategoryList)
  3466. for _, it := range drugCategoryList {
  3467. if drug_category == it.Name {
  3468. drug_category_id = int64(it.Value)
  3469. }
  3470. }
  3471. drug.DrugCategory = drug_category_id
  3472. statistics_category := goodNameM["statistics_category"].(string)
  3473. var statisticsCategory = "统计分类"
  3474. var statistics_category_id int64
  3475. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3476. if len(statistics_category) != 0 {
  3477. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  3478. if errcodestatistc == gorm.ErrRecordNotFound {
  3479. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  3480. dataconfig := models.DictDataconfig{
  3481. ParentId: statistcConfig.ID,
  3482. Module: "system",
  3483. OrgId: orgId,
  3484. Name: statistics_category,
  3485. FieldName: "",
  3486. Value: staConfig.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. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  3502. for _, it := range statisticsCategoryList {
  3503. if statistics_category == it.Name {
  3504. statistics_category_id = int64(it.Value)
  3505. }
  3506. }
  3507. drug.StatisticsCategory = statistics_category_id
  3508. number := goodNameM["number"].(string)
  3509. drug.Number = number
  3510. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  3511. drug.HospApprFlag = hosp_appr_flag
  3512. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3513. drug.MedicalInsuranceNumber = medical_insurance_number
  3514. pharmacology_category := goodNameM["pharmacology_category"].(string)
  3515. var pharmacology = "药理分类"
  3516. var pharmacology_category_id int64
  3517. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  3518. if len(pharmacology_category) != 0 {
  3519. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  3520. if errcodespharmacology == gorm.ErrRecordNotFound {
  3521. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  3522. dataconfig := models.DictDataconfig{
  3523. ParentId: pharmacologyConfig.ID,
  3524. Module: "system",
  3525. OrgId: orgId,
  3526. Name: pharmacology_category,
  3527. FieldName: "",
  3528. Value: dicConfig.Value + 1,
  3529. CreatedTime: "",
  3530. UpdatedTime: "",
  3531. CreateUserId: adminUser.AdminUser.Id,
  3532. Status: 1,
  3533. Remark: "",
  3534. DeleteIdSystem: 0,
  3535. Title: "",
  3536. Content: "",
  3537. Order: 0,
  3538. Code: "",
  3539. }
  3540. service.CreatedDicConfig(&dataconfig)
  3541. }
  3542. }
  3543. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  3544. for _, it := range pharmacologyList {
  3545. if pharmacology_category == it.Name {
  3546. pharmacology_category_id = int64(it.Value)
  3547. }
  3548. }
  3549. drug.PharmacologyCategory = pharmacology_category_id
  3550. code := goodNameM["code"].(string)
  3551. drug.Code = code
  3552. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3553. drug.IsSpecialDiseases = is_special_diseases
  3554. is_record := int64(goodNameM["is_record"].(float64))
  3555. drug.IsRecord = is_record
  3556. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  3557. drug.PrescriptionMark = prescription_mark
  3558. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3559. drug.SocialSecurityDirectoryCode = social_security_directory_code
  3560. record_date := goodNameM["record_date"].(string)
  3561. timeLayout := "2006-01-02"
  3562. loc, _ := time.LoadLocation("Local")
  3563. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3564. drug.RecordDate = theTime.Unix()
  3565. drug_remark := goodNameM["drug_remark"].(string)
  3566. drug.DrugRemark = drug_remark
  3567. drug_status := goodNameM["drug_status"].(string)
  3568. drug.DrugStatus = drug_status
  3569. limit_remark := goodNameM["limit_remark"].(string)
  3570. drug.LimitRemark = limit_remark
  3571. drug_control := goodNameM["drug_control"].(string)
  3572. var drugControl = "开药控制"
  3573. var drug_control_id int64
  3574. drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
  3575. if len(drug_control) != 0 {
  3576. _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
  3577. if errcodesdrugcontrol == gorm.ErrRecordNotFound {
  3578. drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
  3579. dataconfig := models.DictDataconfig{
  3580. ParentId: drugContorlConfig.ID,
  3581. Module: "system",
  3582. OrgId: orgId,
  3583. Name: drug_control,
  3584. FieldName: "",
  3585. Value: drugContorlConfigOne.Value + 1,
  3586. CreatedTime: "",
  3587. UpdatedTime: "",
  3588. CreateUserId: adminUser.AdminUser.Id,
  3589. Status: 1,
  3590. Remark: "",
  3591. DeleteIdSystem: 0,
  3592. Title: "",
  3593. Content: "",
  3594. Order: 0,
  3595. Code: "",
  3596. }
  3597. service.CreatedDicConfig(&dataconfig)
  3598. }
  3599. }
  3600. drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
  3601. for _, it := range drugContorlList {
  3602. if drug_control == it.Name {
  3603. drug_control_id = int64(it.Value)
  3604. }
  3605. }
  3606. drug.DrugControl = drug_control_id
  3607. drugList = append(drugList, &drug)
  3608. }
  3609. export_time := time.Now().Unix()
  3610. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3611. if len(drugList) > 0 {
  3612. for _, item := range drugList {
  3613. goodInfo := models.BaseDrugLib{
  3614. DrugName: item.DrugName,
  3615. DrugAlias: item.DrugAlias,
  3616. DrugSpec: item.DrugSpec,
  3617. DrugType: item.DrugType,
  3618. DrugStockLimit: item.DrugStockLimit,
  3619. DrugOriginPlace: item.DrugOriginPlace,
  3620. DrugDosageForm: item.DrugDosageForm,
  3621. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3622. MaxUnit: item.MaxUnit,
  3623. MinUnit: item.MinUnit,
  3624. UnitMatrixing: item.UnitMatrixing,
  3625. RetailPrice: item.RetailPrice,
  3626. LastPrice: item.LastPrice,
  3627. DrugClassify: item.DrugClassify,
  3628. Manufacturer: item.Manufacturer,
  3629. Dealer: item.Dealer,
  3630. OrgId: orgId,
  3631. Status: 1,
  3632. Ctime: time.Now().Unix(),
  3633. Pinyin: item.Pinyin,
  3634. Wubi: item.Wubi,
  3635. DrugAliasPinyin: item.DrugAliasPinyin,
  3636. DrugAliasWubi: item.DrugAliasWubi,
  3637. DrugControl: item.DrugControl,
  3638. Number: item.Number,
  3639. HospApprFlag: item.HospApprFlag,
  3640. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3641. PharmacologyCategory: item.PharmacologyCategory,
  3642. StatisticsCategory: item.StatisticsCategory,
  3643. Code: item.Code,
  3644. IsSpecialDiseases: item.IsSpecialDiseases,
  3645. IsRecord: item.IsRecord,
  3646. PrescriptionMark: item.PrescriptionMark,
  3647. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3648. RecordDate: item.RecordDate,
  3649. DrugRemark: item.DrugRemark,
  3650. DrugStatus: item.DrugStatus,
  3651. LimitRemark: item.LimitRemark,
  3652. DrugCategory: item.DrugCategory,
  3653. DrugDose: item.DrugDose,
  3654. DrugDoseUnit: item.DrugDoseUnit,
  3655. LmtUsedFlag: item.LmtUsedFlag,
  3656. DrugDay: item.DrugDay,
  3657. DeliveryWay: item.DeliveryWay,
  3658. ExecutionFrequency: item.ExecutionFrequency,
  3659. DoseUnit: item.DoseUnit,
  3660. }
  3661. //查询同种药品同种规格是否存在
  3662. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.MaxUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  3663. if drugerror == gorm.ErrRecordNotFound {
  3664. service.CreateDrugsInfomation(&goodInfo)
  3665. } else if drugerror == nil {
  3666. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  3667. }
  3668. log := models.ExportLog{
  3669. LogType: 4,
  3670. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3671. TotalNum: int64(len(total_goods)),
  3672. FailNum: int64(len(errLogs)),
  3673. SuccessNum: int64(len(drugList)),
  3674. CreateTime: time.Now().Unix(),
  3675. UpdateTime: time.Now().Unix(),
  3676. ExportTime: export_time,
  3677. Status: 1,
  3678. }
  3679. service.CreateExportLog(&log)
  3680. this.ServeSuccessJSON(map[string]interface{}{
  3681. "msg": "导入成功",
  3682. "total_num": len(total_goods),
  3683. "success_num": len(drugList),
  3684. "fail_num": int64(len(errLogs)),
  3685. })
  3686. }
  3687. } else {
  3688. log := models.ExportLog{
  3689. LogType: 4,
  3690. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3691. TotalNum: int64(len(total_goods)),
  3692. FailNum: int64(len(errLogs)),
  3693. SuccessNum: int64(len(drugList)),
  3694. CreateTime: time.Now().Unix(),
  3695. UpdateTime: time.Now().Unix(),
  3696. ExportTime: export_time,
  3697. Status: 1,
  3698. }
  3699. service.CreateExportLog(&log)
  3700. this.ServeSuccessJSON(map[string]interface{}{
  3701. "msg": "导入成功",
  3702. "total_num": len(total_goods),
  3703. "success_num": len(drugList),
  3704. "fail_num": int64(len(errLogs)),
  3705. })
  3706. }
  3707. }
  3708. func (this *StockManagerApiController) GetInitializtion() {
  3709. orgId := this.GetAdminUserInfo().CurrentOrgId
  3710. var drugCategory = "药品类别"
  3711. var drugType = "药品类型"
  3712. var drugDosageForm = "药品剂型"
  3713. var medicalInsuranceLevel = "医保等级"
  3714. var drugControl = "开药控制"
  3715. var drugClassify = "药物分类"
  3716. var statisticsCategory = "统计分类"
  3717. var pharmacologyCategory = "药理分类"
  3718. var goodKind = "耗材种类"
  3719. var tubeColor = "试管颜色"
  3720. var costClassify = "费用类别"
  3721. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3722. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3723. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  3724. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  3725. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  3726. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  3727. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  3728. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  3729. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  3730. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  3731. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  3732. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  3733. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3734. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  3735. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  3736. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  3737. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  3738. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  3739. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  3740. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  3741. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  3742. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  3743. this.ServeSuccessJSON(map[string]interface{}{
  3744. "drugCategoryList": drugCategoryList,
  3745. "drugTypeList": drugTypeList,
  3746. "drugDosageFormList": drugDosageFormList,
  3747. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  3748. "drugControlList": drugControlList,
  3749. "drugClassifyList": drugClassifyList,
  3750. "statisticsCategoryList": statisticsCategoryList,
  3751. "pharmacologyCategoryList": pharmacologyCategoryList,
  3752. "goodKindList": goodKindList,
  3753. "tubeColorList": tubeColorList,
  3754. "costClassifyList": costClassifyList,
  3755. })
  3756. }
  3757. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  3758. adminUserInfo := this.GetAdminUserInfo()
  3759. orgId := adminUserInfo.CurrentOrgId
  3760. list, _ := service.GetWarehouseOrderInfoList(orgId)
  3761. this.ServeSuccessJSON(map[string]interface{}{
  3762. "list": list,
  3763. })
  3764. }
  3765. func (this *StockManagerApiController) PostSearchGoodList() {
  3766. keyword := this.GetString("keyword")
  3767. adminUserInfo := this.GetAdminUserInfo()
  3768. orgId := adminUserInfo.CurrentOrgId
  3769. list, _ := service.GetSearchGoodList(keyword, orgId)
  3770. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3771. dealerList, _ := service.GetAllDealerList(orgId)
  3772. this.ServeSuccessJSON(map[string]interface{}{
  3773. "list": list,
  3774. "manufacturerList": manufacturerList,
  3775. "dealerList": dealerList,
  3776. })
  3777. }
  3778. func (this *StockManagerApiController) GetAllStockList() {
  3779. page, _ := this.GetInt64("page", -1)
  3780. limit, _ := this.GetInt64("limit", -1)
  3781. start_time := this.GetString("start_time")
  3782. end_time := this.GetString("end_time")
  3783. types, _ := this.GetInt64("type", 0)
  3784. keywords := this.GetString("keywords")
  3785. timeLayout := "2006-01-02"
  3786. loc, _ := time.LoadLocation("Local")
  3787. var startTime int64
  3788. if len(start_time) > 0 {
  3789. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3790. if err != nil {
  3791. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3792. return
  3793. }
  3794. startTime = theTime.Unix()
  3795. }
  3796. var endTime int64
  3797. if len(end_time) > 0 {
  3798. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3799. if err != nil {
  3800. utils.ErrorLog(err.Error())
  3801. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3802. return
  3803. }
  3804. endTime = theTime.Unix()
  3805. }
  3806. adminUserInfo := this.GetAdminUserInfo()
  3807. orgId := adminUserInfo.CurrentOrgId
  3808. list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId)
  3809. fmt.Println("耗材总计23323232232323232323", total)
  3810. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3811. this.ServeSuccessJSON(map[string]interface{}{
  3812. "list": list,
  3813. "total": total,
  3814. "manufacturerList": manufacturerList,
  3815. })
  3816. }
  3817. func (this *StockManagerApiController) GetStockListById() {
  3818. id, _ := this.GetInt64("id")
  3819. adminUserInfo := this.GetAdminUserInfo()
  3820. orgId := adminUserInfo.CurrentOrgId
  3821. limit, _ := this.GetInt64("limit")
  3822. page, _ := this.GetInt64("page")
  3823. timeLayout := "2006-01-02"
  3824. loc, _ := time.LoadLocation("Local")
  3825. start_time := this.GetString("start_time")
  3826. end_time := this.GetString("end_time")
  3827. var startTime int64
  3828. if len(start_time) > 0 {
  3829. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3830. if err != nil {
  3831. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3832. return
  3833. }
  3834. startTime = theTime.Unix()
  3835. }
  3836. var endTime int64
  3837. if len(end_time) > 0 {
  3838. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3839. if err != nil {
  3840. utils.ErrorLog(err.Error())
  3841. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3842. return
  3843. }
  3844. endTime = theTime.Unix()
  3845. }
  3846. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3847. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime)
  3848. this.ServeSuccessJSON(map[string]interface{}{
  3849. "list": list,
  3850. "total": total,
  3851. "manufacturerList": manufacturerList,
  3852. })
  3853. }
  3854. func (this *StockManagerApiController) GetStockOutList() {
  3855. id, _ := this.GetInt64("id")
  3856. adminUserInfo := this.GetAdminUserInfo()
  3857. orgId := adminUserInfo.CurrentOrgId
  3858. limit, _ := this.GetInt64("limit")
  3859. page, _ := this.GetInt64("page")
  3860. timeLayout := "2006-01-02"
  3861. loc, _ := time.LoadLocation("Local")
  3862. start_time := this.GetString("start_time")
  3863. end_time := this.GetString("end_time")
  3864. is_sys, _ := this.GetInt64("is_sys")
  3865. var startTime int64
  3866. if len(start_time) > 0 {
  3867. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3868. if err != nil {
  3869. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3870. return
  3871. }
  3872. startTime = theTime.Unix()
  3873. }
  3874. var endTime int64
  3875. if len(end_time) > 0 {
  3876. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3877. if err != nil {
  3878. utils.ErrorLog(err.Error())
  3879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3880. return
  3881. }
  3882. endTime = theTime.Unix()
  3883. }
  3884. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  3885. this.ServeSuccessJSON(map[string]interface{}{
  3886. "outList": outList,
  3887. "total": total,
  3888. })
  3889. }
  3890. func (this *StockManagerApiController) GetStockDrugCount() {
  3891. adminUserInfo := this.GetAdminUserInfo()
  3892. orgId := adminUserInfo.CurrentOrgId
  3893. fmt.Println(orgId)
  3894. timeLayout := "2006-01-02"
  3895. loc, _ := time.LoadLocation("Local")
  3896. start_time := this.GetString("start_time")
  3897. end_time := this.GetString("end_time")
  3898. var startTime int64
  3899. if len(start_time) > 0 {
  3900. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3901. if err != nil {
  3902. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3903. return
  3904. }
  3905. startTime = theTime.Unix()
  3906. }
  3907. var endTime int64
  3908. if len(end_time) > 0 {
  3909. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3910. if err != nil {
  3911. utils.ErrorLog(err.Error())
  3912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3913. return
  3914. }
  3915. endTime = theTime.Unix()
  3916. }
  3917. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  3918. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  3919. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  3920. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  3921. this.ServeSuccessJSON(map[string]interface{}{
  3922. "count": count,
  3923. "outList": outList,
  3924. "autoCount": autoCount,
  3925. "totalCount": totalCount,
  3926. })
  3927. }
  3928. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  3929. ids := this.GetString("id")
  3930. idsArray := strings.Split(ids, ",")
  3931. orgId := this.GetAdminUserInfo().CurrentOrgId
  3932. order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
  3933. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  3934. //获取该耗材的最后一条数据
  3935. info, _ := service.GetLastWarehouseOutInfo(idsArray, orgId)
  3936. fmt.Println("info323e2342342342432342342432", info)
  3937. this.ServeSuccessJSON(map[string]interface{}{
  3938. "order": order,
  3939. "list": list,
  3940. "info": info,
  3941. })
  3942. }
  3943. func (this *StockManagerApiController) GetOrderDetailById() {
  3944. id, _ := this.GetInt64("id")
  3945. good_id, _ := this.GetInt64("good_id")
  3946. record_time, _ := this.GetInt64("record_time")
  3947. orgId := this.GetAdminUserInfo().CurrentOrgId
  3948. //自动出库
  3949. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  3950. //手动出库
  3951. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  3952. stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
  3953. if err == nil {
  3954. this.ServeSuccessJSON(map[string]interface{}{
  3955. "list": userDetails,
  3956. "total": total,
  3957. "info": info,
  3958. "stockFlowList": stockFlowList,
  3959. })
  3960. } else {
  3961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3962. return
  3963. }
  3964. }
  3965. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  3966. id, _ := this.GetInt64("id", 0)
  3967. orgId := this.GetAdminUserInfo().CurrentOrgId
  3968. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  3969. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3970. dealerList, _ := service.GetAllDealerList(orgId)
  3971. goodType, _ := service.GetAllGoodType(orgId)
  3972. this.ServeSuccessJSON(map[string]interface{}{
  3973. "list": warehouseOutInfo,
  3974. "dealerList": dealerList,
  3975. "manufacturerList": manufacturerList,
  3976. "goodType": goodType,
  3977. })
  3978. }
  3979. func (this *StockManagerApiController) GetExprotStockList() {
  3980. adminUserInfo := this.GetAdminUserInfo()
  3981. orgId := adminUserInfo.CurrentOrgId
  3982. timeLayout := "2006-01-02"
  3983. loc, _ := time.LoadLocation("Local")
  3984. start_time := this.GetString("start_time")
  3985. end_time := this.GetString("end_time")
  3986. idArray := this.GetString("id")
  3987. ids := strings.Split(idArray, ",")
  3988. var startTime int64
  3989. if len(start_time) > 0 {
  3990. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3991. if err != nil {
  3992. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3993. return
  3994. }
  3995. startTime = theTime.Unix()
  3996. }
  3997. var endTime int64
  3998. if len(end_time) > 0 {
  3999. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4000. if err != nil {
  4001. utils.ErrorLog(err.Error())
  4002. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4003. return
  4004. }
  4005. endTime = theTime.Unix()
  4006. }
  4007. fmt.Println("ids2222222222222222", ids)
  4008. list, _ := service.GetExprotStockList(orgId, ids, startTime, endTime)
  4009. this.ServeSuccessJSON(map[string]interface{}{
  4010. "list": list,
  4011. })
  4012. }
  4013. func (this *StockManagerApiController) GetOutExprotList() {
  4014. adminUserInfo := this.GetAdminUserInfo()
  4015. orgId := adminUserInfo.CurrentOrgId
  4016. timeLayout := "2006-01-02"
  4017. loc, _ := time.LoadLocation("Local")
  4018. start_time := this.GetString("start_time")
  4019. end_time := this.GetString("end_time")
  4020. idArray := this.GetString("id")
  4021. ids := strings.Split(idArray, ",")
  4022. fmt.Println("ids2222222222", ids)
  4023. var startTime int64
  4024. if len(start_time) > 0 {
  4025. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4026. if err != nil {
  4027. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4028. return
  4029. }
  4030. startTime = theTime.Unix()
  4031. }
  4032. var endTime int64
  4033. if len(end_time) > 0 {
  4034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4035. if err != nil {
  4036. utils.ErrorLog(err.Error())
  4037. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4038. return
  4039. }
  4040. endTime = theTime.Unix()
  4041. }
  4042. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  4043. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  4044. this.ServeSuccessJSON(map[string]interface{}{
  4045. "list": list,
  4046. "count": outCount,
  4047. })
  4048. }
  4049. func (this *StockManagerApiController) GetSingleCancelOrder() {
  4050. id, _ := this.GetInt64("id")
  4051. adminUserInfo := this.GetAdminUserInfo()
  4052. orgId := adminUserInfo.CurrentOrgId
  4053. order, _ := service.GetSingleCancelOrder(id, orgId)
  4054. this.ServeSuccessJSON(map[string]interface{}{
  4055. "list": order,
  4056. })
  4057. }
  4058. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  4059. id := this.GetString("id")
  4060. idStr := strings.Split(id, ",")
  4061. orgId := this.GetAdminUserInfo().CurrentOrgId
  4062. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  4063. this.ServeSuccessJSON(map[string]interface{}{
  4064. "list": list,
  4065. })
  4066. }
  4067. func (this *StockManagerApiController) GetStockBatchNumber() {
  4068. id, _ := this.GetInt64("id")
  4069. orgId := this.GetAdminUserInfo().CurrentOrgId
  4070. list, _ := service.GetStockBatchNumber(id, orgId)
  4071. this.ServeSuccessJSON(map[string]interface{}{
  4072. "list": list,
  4073. })
  4074. }
  4075. func (this *StockManagerApiController) GetStockFlow() {
  4076. limit, _ := this.GetInt64("limit")
  4077. page, _ := this.GetInt64("page")
  4078. good_id, _ := this.GetInt64("good_id")
  4079. consumable_type, _ := this.GetInt64("is_sys")
  4080. adminUserInfo := this.GetAdminUserInfo()
  4081. orgId := adminUserInfo.CurrentOrgId
  4082. timeLayout := "2006-01-02"
  4083. loc, _ := time.LoadLocation("Local")
  4084. start_time := this.GetString("start_time")
  4085. end_time := this.GetString("end_time")
  4086. var startTime int64
  4087. if len(start_time) > 0 {
  4088. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4089. if err != nil {
  4090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4091. return
  4092. }
  4093. startTime = theTime.Unix()
  4094. }
  4095. var endTime int64
  4096. if len(end_time) > 0 {
  4097. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4098. if err != nil {
  4099. utils.ErrorLog(err.Error())
  4100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4101. return
  4102. }
  4103. endTime = theTime.Unix()
  4104. }
  4105. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  4106. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4107. this.ServeSuccessJSON(map[string]interface{}{
  4108. "list": list,
  4109. "total": total,
  4110. "manufacturerList": manufacturerList,
  4111. })
  4112. }
  4113. func (this *StockManagerApiController) GetCancelExportList() {
  4114. adminUserInfo := this.GetAdminUserInfo()
  4115. orgId := adminUserInfo.CurrentOrgId
  4116. timeLayout := "2006-01-02"
  4117. loc, _ := time.LoadLocation("Local")
  4118. start_time := this.GetString("start_time")
  4119. end_time := this.GetString("end_time")
  4120. idArray := this.GetString("order_id")
  4121. fmt.Println("232323232323232232", idArray)
  4122. ids := strings.Split(idArray, ",")
  4123. var startTime int64
  4124. if len(start_time) > 0 {
  4125. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4126. if err != nil {
  4127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4128. return
  4129. }
  4130. startTime = theTime.Unix()
  4131. }
  4132. var endTime int64
  4133. if len(end_time) > 0 {
  4134. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4135. if err != nil {
  4136. utils.ErrorLog(err.Error())
  4137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4138. return
  4139. }
  4140. endTime = theTime.Unix()
  4141. }
  4142. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  4143. this.ServeSuccessJSON(map[string]interface{}{
  4144. "list": list,
  4145. })
  4146. }
  4147. func (this *StockManagerApiController) GetSearchGoodWarehouseList() {
  4148. keyword := this.GetString("keyword")
  4149. orgId := this.GetAdminUserInfo().CurrentOrgId
  4150. list, _ := service.GetSearchGoodWarehouseList(keyword, orgId)
  4151. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4152. dealerList, _ := service.GetAllDealerList(orgId)
  4153. this.ServeSuccessJSON(map[string]interface{}{
  4154. "list": list,
  4155. "manufacturerList": manufacturerList,
  4156. "dealerList": dealerList,
  4157. })
  4158. }
  4159. func (this *StockManagerApiController) SaveAdjuestPrice() {
  4160. timeLayout := "2006-01-02"
  4161. loc, _ := time.LoadLocation("Local")
  4162. dataBody := make(map[string]interface{}, 0)
  4163. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4164. if err != nil {
  4165. utils.ErrorLog(err.Error())
  4166. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4167. return
  4168. }
  4169. tableData, _ := dataBody["tableData"].([]interface{})
  4170. if len(tableData) > 0 {
  4171. for _, item := range tableData {
  4172. items := item.(map[string]interface{})
  4173. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4174. utils.ErrorLog("good_name")
  4175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4176. return
  4177. }
  4178. good_name := items["good_name"].(string)
  4179. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4180. utils.ErrorLog("good_name")
  4181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4182. return
  4183. }
  4184. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4185. utils.ErrorLog("packing_price")
  4186. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4187. return
  4188. }
  4189. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4190. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4191. utils.ErrorLog("warehousing_order")
  4192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4193. return
  4194. }
  4195. warehousing_order := items["warehousing_order"].(string)
  4196. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4197. utils.ErrorLog("license_number")
  4198. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4199. return
  4200. }
  4201. license_number := items["license_number"].(string)
  4202. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4203. utils.ErrorLog("dealer")
  4204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4205. return
  4206. }
  4207. dealer := items["dealer"].(string)
  4208. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4209. utils.ErrorLog("manufacturer")
  4210. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4211. return
  4212. }
  4213. manufacturer := items["manufacturer"].(string)
  4214. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4215. utils.ErrorLog("specification_name")
  4216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4217. return
  4218. }
  4219. specification_name := items["specification_name"].(string)
  4220. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4221. utils.ErrorLog("remark")
  4222. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4223. return
  4224. }
  4225. remark := items["remark"].(string)
  4226. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4227. utils.ErrorLog("warehousing_unit")
  4228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4229. return
  4230. }
  4231. warehousing_unit := items["warehousing_unit"].(string)
  4232. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4233. utils.ErrorLog("buy_price")
  4234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4235. return
  4236. }
  4237. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4238. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4239. utils.ErrorLog("count")
  4240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4241. return
  4242. }
  4243. count := int64(items["count"].(float64))
  4244. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  4245. utils.ErrorLog("new_price")
  4246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4247. return
  4248. }
  4249. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  4250. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4251. utils.ErrorLog("good_id")
  4252. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4253. return
  4254. }
  4255. good_id := int64(items["good_id"].(float64))
  4256. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4257. utils.ErrorLog("start_time")
  4258. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4259. return
  4260. }
  4261. var startTime int64
  4262. start_time := items["start_time"].(string)
  4263. if len(start_time) > 0 {
  4264. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4265. if err != nil {
  4266. fmt.Println(err)
  4267. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4268. return
  4269. }
  4270. startTime = theTime.Unix()
  4271. }
  4272. orgId := this.GetAdminUserInfo().CurrentOrgId
  4273. adjustprice := models.XtStockAdjustPrice{
  4274. GoodName: good_name,
  4275. SpecificationName: specification_name,
  4276. WarehousingUnit: warehousing_unit,
  4277. Count: count,
  4278. BuyPrice: buy_price,
  4279. PackingPrice: packing_price,
  4280. NewPrice: new_price,
  4281. Manufacturer: manufacturer,
  4282. Dealer: dealer,
  4283. Remark: remark,
  4284. GoodId: good_id,
  4285. UserOrgId: orgId,
  4286. Ctime: time.Now().Unix(),
  4287. Mtime: 0,
  4288. Status: 1,
  4289. WarehousingOrder: warehousing_order,
  4290. LicenseNumber: license_number,
  4291. StartTime: startTime,
  4292. Creater: this.GetAdminUserInfo().AdminUser.Id,
  4293. CheckerStatus: 2,
  4294. }
  4295. service.CreateAdjustPrice(&adjustprice)
  4296. }
  4297. }
  4298. this.ServeSuccessJSON(map[string]interface{}{
  4299. "msg": "保存成功!",
  4300. })
  4301. }
  4302. func (this *StockManagerApiController) GetAllStockPrice() {
  4303. timeLayout := "2006-01-02"
  4304. loc, _ := time.LoadLocation("Local")
  4305. dataBody := make(map[string]interface{}, 0)
  4306. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4307. fmt.Println(err)
  4308. orgId := this.GetAdminUserInfo().CurrentOrgId
  4309. keyword := this.GetString("keyword")
  4310. start_time := this.GetString("start_time")
  4311. end_time := this.GetString("end_time")
  4312. limit, _ := this.GetInt64("limit")
  4313. page, _ := this.GetInt64("page")
  4314. var startTime int64
  4315. if len(start_time) > 0 {
  4316. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4317. if err != nil {
  4318. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4319. return
  4320. }
  4321. startTime = theTime.Unix()
  4322. }
  4323. var endTime int64
  4324. if len(end_time) > 0 {
  4325. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4326. if err != nil {
  4327. utils.ErrorLog(err.Error())
  4328. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4329. return
  4330. }
  4331. endTime = theTime.Unix()
  4332. }
  4333. list, total, _ := service.GetAllStockPrice(orgId, startTime, endTime, keyword, limit, page)
  4334. doctor, _ := service.GetAllDoctorThree(orgId)
  4335. this.ServeSuccessJSON(map[string]interface{}{
  4336. "list": list,
  4337. "doctor": doctor,
  4338. "total": total,
  4339. })
  4340. }
  4341. func (this *StockManagerApiController) SaveCheckPrice() {
  4342. timeLayout := "2006-01-02"
  4343. loc, _ := time.LoadLocation("Local")
  4344. dataBody := make(map[string]interface{}, 0)
  4345. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4346. fmt.Println(err)
  4347. idstr := this.GetString("ids")
  4348. ids := strings.Split(idstr, ",")
  4349. check_time := this.GetString("check_time")
  4350. var checkTime int64
  4351. if len(check_time) > 0 {
  4352. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4353. if err != nil {
  4354. fmt.Println(err)
  4355. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4356. return
  4357. }
  4358. checkTime = theTime.Unix()
  4359. }
  4360. checker, _ := this.GetInt64("checker")
  4361. adjustPrice := models.XtStockAdjustPrice{
  4362. Checker: checker,
  4363. CheckerStatus: 1,
  4364. CheckerTime: checkTime,
  4365. }
  4366. err = service.UpdateAdjustPrice(ids, adjustPrice)
  4367. fmt.Println(err)
  4368. list, _ := service.GetAdjustCheckPriceList(ids)
  4369. for _, item := range list {
  4370. info := models.GoodInfo{
  4371. PackingPrice: item.NewPrice,
  4372. BuyPrice: item.BuyPrice,
  4373. }
  4374. err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
  4375. fmt.Println(err)
  4376. }
  4377. this.ServeSuccessJSON(map[string]interface{}{
  4378. "adjustPrice": adjustPrice,
  4379. })
  4380. }
  4381. func (this *StockManagerApiController) GetAdjustPriceById() {
  4382. ids := this.GetString("ids")
  4383. fmt.Println("ids23232233223233232", ids)
  4384. splitIds := strings.Split(ids, ",")
  4385. list, _ := service.GetAdjustPricebyIdOne(splitIds)
  4386. fmt.Println("list2322322323", list)
  4387. this.ServeSuccessJSON(map[string]interface{}{
  4388. "list": list,
  4389. })
  4390. }
  4391. func (this *StockManagerApiController) SaveReportStock() {
  4392. timeLayout := "2006-01-02"
  4393. loc, _ := time.LoadLocation("Local")
  4394. dataBody := make(map[string]interface{}, 0)
  4395. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4396. if err != nil {
  4397. utils.ErrorLog(err.Error())
  4398. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4399. return
  4400. }
  4401. tableData, _ := dataBody["tableData"].([]interface{})
  4402. if len(tableData) > 0 {
  4403. for _, item := range tableData {
  4404. items := item.(map[string]interface{})
  4405. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4406. utils.ErrorLog("good_name")
  4407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4408. return
  4409. }
  4410. good_name := items["good_name"].(string)
  4411. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4412. utils.ErrorLog("good_name")
  4413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4414. return
  4415. }
  4416. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4417. utils.ErrorLog("packing_price")
  4418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4419. return
  4420. }
  4421. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4422. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4423. utils.ErrorLog("warehousing_order")
  4424. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4425. return
  4426. }
  4427. warehousing_order := items["warehousing_order"].(string)
  4428. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4429. utils.ErrorLog("license_number")
  4430. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4431. return
  4432. }
  4433. license_number := items["license_number"].(string)
  4434. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4435. utils.ErrorLog("dealer")
  4436. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4437. return
  4438. }
  4439. dealer := items["dealer"].(string)
  4440. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4441. utils.ErrorLog("manufacturer")
  4442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4443. return
  4444. }
  4445. manufacturer := items["manufacturer"].(string)
  4446. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4447. utils.ErrorLog("specification_name")
  4448. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4449. return
  4450. }
  4451. specification_name := items["specification_name"].(string)
  4452. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4453. utils.ErrorLog("remark")
  4454. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4455. return
  4456. }
  4457. remark := items["remark"].(string)
  4458. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4459. utils.ErrorLog("warehousing_unit")
  4460. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4461. return
  4462. }
  4463. warehousing_unit := items["warehousing_unit"].(string)
  4464. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4465. utils.ErrorLog("buy_price")
  4466. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4467. return
  4468. }
  4469. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4470. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4471. utils.ErrorLog("count")
  4472. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4473. return
  4474. }
  4475. count := int64(items["count"].(float64))
  4476. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4477. utils.ErrorLog("good_id")
  4478. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4479. return
  4480. }
  4481. good_id := int64(items["good_id"].(float64))
  4482. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4483. utils.ErrorLog("start_time")
  4484. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4485. return
  4486. }
  4487. var startTime int64
  4488. start_time := items["start_time"].(string)
  4489. if len(start_time) > 0 {
  4490. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4491. if err != nil {
  4492. fmt.Println(err)
  4493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4494. return
  4495. }
  4496. startTime = theTime.Unix()
  4497. }
  4498. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4499. utils.ErrorLog("number")
  4500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4501. return
  4502. }
  4503. number := items["number"].(string)
  4504. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4505. utils.ErrorLog("warehousing_info_id")
  4506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4507. return
  4508. }
  4509. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4510. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4511. utils.ErrorLog("expiry_date")
  4512. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4513. return
  4514. }
  4515. expiry_date := int64(items["expiry_date"].(float64))
  4516. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4517. utils.ErrorLog("product_date")
  4518. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4519. return
  4520. }
  4521. product_date := int64(items["product_date"].(float64))
  4522. orgId := this.GetAdminUserInfo().CurrentOrgId
  4523. Creater := this.GetAdminUserInfo().AdminUser.Id
  4524. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4525. utils.ErrorLog("total")
  4526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4527. return
  4528. }
  4529. total := int64(items["total"].(float64))
  4530. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  4531. utils.ErrorLog("good_origin_place")
  4532. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4533. return
  4534. }
  4535. good_origin_place := items["good_origin_place"].(string)
  4536. reportPrice := models.XtStockReportPrice{
  4537. GoodName: good_name,
  4538. SpecificationName: specification_name,
  4539. WarehousingUnit: warehousing_unit,
  4540. Count: count,
  4541. BuyPrice: buy_price,
  4542. PackingPrice: packing_price,
  4543. Manufacturer: manufacturer,
  4544. Dealer: dealer,
  4545. Remark: remark,
  4546. GoodId: good_id,
  4547. UserOrgId: orgId,
  4548. Ctime: time.Now().Unix(),
  4549. Mtime: 0,
  4550. Status: 1,
  4551. WarehousingOrder: warehousing_order,
  4552. LicenseNumber: license_number,
  4553. StartTime: startTime,
  4554. Creater: Creater,
  4555. Checker: 0,
  4556. CheckerStatus: 2,
  4557. CheckerTime: 0,
  4558. Number: number,
  4559. WarehousingInfoId: warehousing_info_id,
  4560. ExpiryDate: expiry_date,
  4561. ProductDate: product_date,
  4562. Total: total,
  4563. GoodOriginPlace: good_origin_place,
  4564. }
  4565. err := service.CreateReportPrice(&reportPrice)
  4566. fmt.Println(err)
  4567. }
  4568. }
  4569. this.ServeSuccessJSON(map[string]interface{}{
  4570. "msg": "保存成功!",
  4571. })
  4572. }
  4573. func (this *StockManagerApiController) GetReportStockList() {
  4574. timeLayout := "2006-01-02"
  4575. loc, _ := time.LoadLocation("Local")
  4576. start_time := this.GetString("start_time")
  4577. end_time := this.GetString("end_time")
  4578. page, _ := this.GetInt64("page")
  4579. limit, _ := this.GetInt64("limit")
  4580. var startTime int64
  4581. if len(start_time) > 0 {
  4582. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4583. if err != nil {
  4584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4585. return
  4586. }
  4587. startTime = theTime.Unix()
  4588. fmt.Println("开始时间", startTime)
  4589. }
  4590. var endTime int64
  4591. if len(end_time) > 0 {
  4592. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4593. if err != nil {
  4594. utils.ErrorLog(err.Error())
  4595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4596. return
  4597. }
  4598. endTime = theTime.Unix()
  4599. }
  4600. orgId := this.GetAdminUserInfo().CurrentOrgId
  4601. keyword := this.GetString("keyword")
  4602. fmt.Println("startTime", startTime, "endTime", endTime)
  4603. list, total, _ := service.GetReportStockList(startTime, endTime, orgId, keyword, page, limit)
  4604. doctorlist, _ := service.GetAllDoctorThree(orgId)
  4605. this.ServeSuccessJSON(map[string]interface{}{
  4606. "list": list,
  4607. "total": total,
  4608. "doctorlist": doctorlist,
  4609. })
  4610. }
  4611. func (this *StockManagerApiController) SaveCheckDamage() {
  4612. timeLayout := "2006-01-02"
  4613. loc, _ := time.LoadLocation("Local")
  4614. idstr := this.GetString("ids")
  4615. ids := strings.Split(idstr, ",")
  4616. check_time := this.GetString("check_time")
  4617. var checkTime int64
  4618. if len(check_time) > 0 {
  4619. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4620. if err != nil {
  4621. fmt.Println(err)
  4622. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4623. return
  4624. }
  4625. checkTime = theTime.Unix()
  4626. }
  4627. checker, _ := this.GetInt64("checker")
  4628. reportprice := models.XtStockReportPrice{
  4629. Checker: checker,
  4630. CheckerStatus: 1,
  4631. CheckerTime: checkTime,
  4632. }
  4633. err := service.UpdateCheckDamage(ids, reportprice)
  4634. fmt.Println(err)
  4635. //获取当前核对的数据
  4636. list, _ := service.GetCheckDamageList(ids)
  4637. ctime := time.Now().Unix()
  4638. adminUserInfo := this.GetAdminUserInfo()
  4639. timeStr := time.Now().Format("2006-01-02")
  4640. timeArr := strings.Split(timeStr, "-")
  4641. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  4642. total = total + 1
  4643. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4644. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4645. number = number + total
  4646. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4647. operation_time := time.Now().Unix()
  4648. creater := adminUserInfo.AdminUser.Id
  4649. warehouseOut := models.WarehouseOut{
  4650. WarehouseOutOrderNumber: warehousing_out_order,
  4651. OperationTime: operation_time,
  4652. OrgId: adminUserInfo.CurrentOrgId,
  4653. Creater: creater,
  4654. Ctime: ctime,
  4655. Status: 1,
  4656. WarehouseOutTime: ctime,
  4657. Type: 1,
  4658. }
  4659. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  4660. if errcodes == gorm.ErrRecordNotFound {
  4661. service.AddSigleWarehouseOut(&warehouseOut)
  4662. }
  4663. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  4664. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  4665. var manufacturer_id int64
  4666. var dealer_id int64
  4667. for _, item := range list {
  4668. for _, it := range manufacturerList {
  4669. if item.Manufacturer == it.ManufacturerName {
  4670. manufacturer_id = it.ID
  4671. }
  4672. }
  4673. for _, its := range dealerList {
  4674. if item.Dealer == its.DealerName {
  4675. dealer_id = its.ID
  4676. }
  4677. }
  4678. //插入出库单
  4679. warehouseOutInfo := &models.WarehouseOutInfo{
  4680. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4681. WarehouseOutId: warehouseOut.ID,
  4682. GoodId: item.GoodId,
  4683. Count: item.Count,
  4684. Price: item.PackingPrice,
  4685. Status: 1,
  4686. Ctime: ctime,
  4687. Remark: item.Remark,
  4688. OrgId: adminUserInfo.CurrentOrgId,
  4689. Type: 2,
  4690. Manufacturer: manufacturer_id,
  4691. Number: item.Number,
  4692. ExpiryDate: item.ExpiryDate,
  4693. ProductDate: item.ProductDate,
  4694. Dealer: dealer_id,
  4695. LicenseNumber: item.LicenseNumber,
  4696. }
  4697. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4698. fmt.Println("99999999999999", errOne)
  4699. //更改库存
  4700. info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  4701. warehousingInfo := models.WarehousingInfo{
  4702. StockCount: info.StockCount - item.Count,
  4703. }
  4704. errOne = service.UpdateGoodWarehouseInfo(item.WarehousingInfoId, warehousingInfo)
  4705. fmt.Println(errOne)
  4706. flow := models.VmStockFlow{
  4707. WarehousingId: 0,
  4708. GoodId: item.GoodId,
  4709. Number: item.Number,
  4710. LicenseNumber: item.LicenseNumber,
  4711. Count: item.Count,
  4712. UserOrgId: adminUserInfo.CurrentOrgId,
  4713. PatientId: 0,
  4714. SystemTime: time.Now().Unix(),
  4715. ConsumableType: 5,
  4716. IsSys: 0,
  4717. WarehousingOrder: "",
  4718. WarehouseOutId: warehouseOutInfo.ID,
  4719. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4720. IsEdit: 0,
  4721. CancelStockId: 0,
  4722. CancelOrderNumber: "",
  4723. Manufacturer: 0,
  4724. Dealer: 0,
  4725. Creator: adminUserInfo.AdminUser.Id,
  4726. UpdateCreator: 0,
  4727. Status: 1,
  4728. Ctime: time.Now().Unix(),
  4729. Mtime: 0,
  4730. Price: item.PackingPrice,
  4731. WarehousingDetailId: 0,
  4732. WarehouseOutDetailId: 0,
  4733. CancelOutDetailId: 0,
  4734. ProductDate: item.ProductDate,
  4735. ExpireDate: item.ExpiryDate,
  4736. }
  4737. service.CreateStockFlowOne(flow)
  4738. }
  4739. this.ServeSuccessJSON(map[string]interface{}{
  4740. "reportPrice": reportprice,
  4741. })
  4742. }
  4743. func (this *StockManagerApiController) SaveInventory() {
  4744. timeLayout := "2006-01-02"
  4745. loc, _ := time.LoadLocation("Local")
  4746. dataBody := make(map[string]interface{}, 0)
  4747. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4748. if err != nil {
  4749. utils.ErrorLog(err.Error())
  4750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4751. return
  4752. }
  4753. tableData, _ := dataBody["tableData"].([]interface{})
  4754. if len(tableData) > 0 {
  4755. for _, item := range tableData {
  4756. items := item.(map[string]interface{})
  4757. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4758. utils.ErrorLog("good_name")
  4759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4760. return
  4761. }
  4762. good_name := items["good_name"].(string)
  4763. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4764. utils.ErrorLog("good_name")
  4765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4766. return
  4767. }
  4768. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4769. utils.ErrorLog("packing_price")
  4770. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4771. return
  4772. }
  4773. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4774. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4775. utils.ErrorLog("warehousing_order")
  4776. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4777. return
  4778. }
  4779. warehousing_order := items["warehousing_order"].(string)
  4780. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4781. utils.ErrorLog("license_number")
  4782. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4783. return
  4784. }
  4785. license_number := items["license_number"].(string)
  4786. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4787. utils.ErrorLog("dealer")
  4788. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4789. return
  4790. }
  4791. dealer := items["dealer"].(string)
  4792. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4793. utils.ErrorLog("manufacturer")
  4794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4795. return
  4796. }
  4797. manufacturer := items["manufacturer"].(string)
  4798. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4799. utils.ErrorLog("specification_name")
  4800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4801. return
  4802. }
  4803. specification_name := items["specification_name"].(string)
  4804. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4805. utils.ErrorLog("remark")
  4806. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4807. return
  4808. }
  4809. remark := items["remark"].(string)
  4810. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4811. utils.ErrorLog("warehousing_unit")
  4812. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4813. return
  4814. }
  4815. warehousing_unit := items["warehousing_unit"].(string)
  4816. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4817. utils.ErrorLog("buy_price")
  4818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4819. return
  4820. }
  4821. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4822. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4823. utils.ErrorLog("count")
  4824. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4825. return
  4826. }
  4827. count := int64(items["count"].(float64))
  4828. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4829. utils.ErrorLog("good_id")
  4830. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4831. return
  4832. }
  4833. good_id := int64(items["good_id"].(float64))
  4834. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4835. utils.ErrorLog("start_time")
  4836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4837. return
  4838. }
  4839. var startTime int64
  4840. start_time := items["start_time"].(string)
  4841. if len(start_time) > 0 {
  4842. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4843. if err != nil {
  4844. fmt.Println(err)
  4845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4846. return
  4847. }
  4848. startTime = theTime.Unix()
  4849. }
  4850. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4851. utils.ErrorLog("total")
  4852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4853. return
  4854. }
  4855. total := int64(items["total"].(float64))
  4856. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4857. utils.ErrorLog("expiry_date")
  4858. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4859. return
  4860. }
  4861. expiry_date := int64(items["expiry_date"].(float64))
  4862. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4863. utils.ErrorLog("product_date")
  4864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4865. return
  4866. }
  4867. product_date := int64(items["product_date"].(float64))
  4868. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4869. utils.ErrorLog("number")
  4870. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4871. return
  4872. }
  4873. number := items["number"].(string)
  4874. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4875. utils.ErrorLog("warehousing_info_id")
  4876. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4877. return
  4878. }
  4879. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4880. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  4881. utils.ErrorLog("good_origin_place")
  4882. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4883. return
  4884. }
  4885. good_origin_place := items["good_origin_place"].(string)
  4886. orgId := this.GetAdminUserInfo().CurrentOrgId
  4887. Creater := this.GetAdminUserInfo().AdminUser.Id
  4888. inventory := models.XtStockInventory{
  4889. GoodName: good_name,
  4890. SpecificationName: specification_name,
  4891. WarehousingUnit: warehousing_unit,
  4892. Count: count,
  4893. BuyPrice: buy_price,
  4894. PackingPrice: packing_price,
  4895. NewPrice: 0,
  4896. Manufacturer: manufacturer,
  4897. Dealer: dealer,
  4898. Remark: remark,
  4899. GoodId: good_id,
  4900. UserOrgId: orgId,
  4901. Ctime: time.Now().Unix(),
  4902. Mtime: 0,
  4903. Status: 1,
  4904. WarehousingOrder: warehousing_order,
  4905. LicenseNumber: license_number,
  4906. StartTime: startTime,
  4907. Creater: Creater,
  4908. Checker: 0,
  4909. CheckerStatus: 2,
  4910. CheckerTime: 0,
  4911. Total: total,
  4912. ExpireDate: expiry_date,
  4913. ProductDate: product_date,
  4914. Number: number,
  4915. WarehousingInfoId: warehousing_info_id,
  4916. GoodOriginPlace: good_origin_place,
  4917. }
  4918. err = service.CreateInentory(inventory)
  4919. fmt.Println(err)
  4920. }
  4921. }
  4922. this.ServeSuccessJSON(map[string]interface{}{
  4923. "msg": "保存成功!",
  4924. })
  4925. }
  4926. func (this *StockManagerApiController) GetInventorylist() {
  4927. timeLayout := "2006-01-02"
  4928. loc, _ := time.LoadLocation("Local")
  4929. start_time := this.GetString("start_time")
  4930. end_time := this.GetString("end_time")
  4931. page, _ := this.GetInt64("page")
  4932. limit, _ := this.GetInt64("limit")
  4933. keyword := this.GetString("keyword")
  4934. inventory_status, _ := this.GetInt64("inventory_status")
  4935. var startTime int64
  4936. if len(start_time) > 0 {
  4937. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4938. if err != nil {
  4939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4940. return
  4941. }
  4942. startTime = theTime.Unix()
  4943. fmt.Println("开始时间", startTime)
  4944. }
  4945. var endTime int64
  4946. if len(end_time) > 0 {
  4947. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4948. if err != nil {
  4949. utils.ErrorLog(err.Error())
  4950. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4951. return
  4952. }
  4953. endTime = theTime.Unix()
  4954. }
  4955. orgId := this.GetAdminUserInfo().CurrentOrgId
  4956. list, total, _ := service.GetInventorylist(startTime, endTime, page, limit, inventory_status, keyword, orgId)
  4957. doctorlist, _ := service.GetAllDoctorThree(orgId)
  4958. this.ServeSuccessJSON(map[string]interface{}{
  4959. "list": list,
  4960. "total": total,
  4961. "doctorlist": doctorlist,
  4962. })
  4963. }
  4964. func (this *StockManagerApiController) SaveCheckInventory() {
  4965. timeLayout := "2006-01-02"
  4966. loc, _ := time.LoadLocation("Local")
  4967. dataBody := make(map[string]interface{}, 0)
  4968. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4969. fmt.Println(err)
  4970. idstr := this.GetString("ids")
  4971. ids := strings.Split(idstr, ",")
  4972. check_time := this.GetString("check_time")
  4973. var checkTime int64
  4974. if len(check_time) > 0 {
  4975. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4976. if err != nil {
  4977. fmt.Println(err)
  4978. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4979. return
  4980. }
  4981. checkTime = theTime.Unix()
  4982. }
  4983. checker, _ := this.GetInt64("checker")
  4984. inventory := models.XtStockInventory{
  4985. Checker: checker,
  4986. CheckerStatus: 1,
  4987. CheckerTime: checkTime,
  4988. }
  4989. adminUserInfo := this.GetAdminUserInfo()
  4990. err = service.UpdateCheckInventory(ids, inventory)
  4991. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  4992. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  4993. var manufactuer_id int64
  4994. var dealer_id int64
  4995. //查询耗材信息
  4996. list, _ := service.GetInventoryDetailById(ids)
  4997. for _, item := range list {
  4998. for _, it := range manufacturerList {
  4999. if item.Manufacturer == it.ManufacturerName {
  5000. manufactuer_id = it.ID
  5001. }
  5002. }
  5003. for _, its := range dealerList {
  5004. if item.Dealer == its.DealerName {
  5005. dealer_id = its.ID
  5006. }
  5007. }
  5008. //查寻该批次的库存量
  5009. list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5010. //查询该耗材最后1条批次
  5011. info, _ := service.GetLastWarehouseInfo(item.GoodId)
  5012. fmt.Println("总共", item.Count)
  5013. fmt.Println("数据", list.StockCount)
  5014. //盘点盘点库存和et实际库存的大小
  5015. // 如果盘点库存大于实际库存,怎需要入库
  5016. if item.Count > list.StockCount {
  5017. ctime := time.Now().Unix()
  5018. timeStr := time.Now().Format("2006-01-02")
  5019. timeArr := strings.Split(timeStr, "-")
  5020. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  5021. total = total + 1
  5022. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5023. operation_time := time.Now().Unix()
  5024. creater := adminUserInfo.AdminUser.Id
  5025. warehousing := models.Warehousing{
  5026. WarehousingOrder: warehousing_order,
  5027. OperationTime: operation_time,
  5028. OrgId: adminUserInfo.CurrentOrgId,
  5029. Creater: creater,
  5030. Ctime: ctime,
  5031. Status: 1,
  5032. WarehousingTime: ctime,
  5033. Type: 1,
  5034. }
  5035. service.AddSigleWarehouse(&warehousing)
  5036. //获取最
  5037. //入库单表格
  5038. warehouseInfo := models.WarehousingInfo{
  5039. WarehousingOrder: warehousing.WarehousingOrder,
  5040. WarehousingId: warehousing.ID,
  5041. GoodId: item.GoodId,
  5042. Number: info.Number,
  5043. ProductDate: info.ProductDate,
  5044. ExpiryDate: info.ExpiryDate,
  5045. WarehousingCount: item.Count - list.StockCount,
  5046. Price: info.Price,
  5047. Status: 1,
  5048. Ctime: ctime,
  5049. Remark: item.Remark,
  5050. OrgId: adminUserInfo.CurrentOrgId,
  5051. Type: 1,
  5052. Manufacturer: manufactuer_id,
  5053. StockCount: item.Count - list.StockCount,
  5054. Dealer: dealer_id,
  5055. LicenseNumber: info.LicenseNumber,
  5056. }
  5057. flow := models.VmStockFlow{
  5058. WarehousingOrder: warehousing.WarehousingOrder,
  5059. WarehousingId: warehousing.ID,
  5060. GoodId: item.GoodId,
  5061. Number: info.Number,
  5062. ProductDate: info.ProductDate,
  5063. ExpireDate: info.ExpiryDate,
  5064. Count: item.Count - list.StockCount,
  5065. Price: item.BuyPrice,
  5066. Status: 1,
  5067. Ctime: ctime,
  5068. UserOrgId: adminUserInfo.CurrentOrgId,
  5069. Manufacturer: info.Manufacturer,
  5070. Dealer: info.Dealer,
  5071. LicenseNumber: info.LicenseNumber,
  5072. IsEdit: 1,
  5073. Creator: adminUserInfo.AdminUser.Id,
  5074. SystemTime: operation_time,
  5075. ConsumableType: 1,
  5076. WarehousingDetailId: warehouseInfo.ID,
  5077. }
  5078. service.CreateWarehouseInfo(warehouseInfo)
  5079. service.CreateStockFlowOne(flow)
  5080. }
  5081. //如果盘点库存小于实际库存,需要出库
  5082. if item.Count < list.StockCount {
  5083. timeStr := time.Now().Format("2006-01-02")
  5084. timeArr := strings.Split(timeStr, "-")
  5085. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5086. total = total + 1
  5087. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5088. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5089. number = number + total
  5090. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5091. operation_time := time.Now().Unix()
  5092. creater := adminUserInfo.AdminUser.Id
  5093. //查询最早的1条批次
  5094. warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
  5095. warehouseOut := models.WarehouseOut{
  5096. WarehouseOutOrderNumber: warehousing_out_order,
  5097. OperationTime: operation_time,
  5098. OrgId: adminUserInfo.CurrentOrgId,
  5099. Creater: creater,
  5100. Ctime: time.Now().Unix(),
  5101. Status: 1,
  5102. WarehouseOutTime: time.Now().Unix(),
  5103. Type: 1,
  5104. }
  5105. err = service.CreateWarehouseOut(warehouseOut)
  5106. fmt.Println(err)
  5107. warehouseOutInfo := &models.WarehouseOutInfo{
  5108. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5109. WarehouseOutId: warehouseOut.ID,
  5110. GoodId: warehouseInfo.GoodId,
  5111. Count: list.StockCount - item.Count,
  5112. Price: warehouseInfo.Price,
  5113. Status: 1,
  5114. Ctime: time.Now().Unix(),
  5115. Remark: item.Remark,
  5116. OrgId: adminUserInfo.CurrentOrgId,
  5117. Type: 1,
  5118. Manufacturer: manufactuer_id,
  5119. Number: warehouseInfo.Number,
  5120. ExpiryDate: warehouseInfo.ExpiryDate,
  5121. ProductDate: warehouseInfo.ProductDate,
  5122. Dealer: dealer_id,
  5123. LicenseNumber: warehouseInfo.LicenseNumber,
  5124. }
  5125. stockFlow := models.VmStockFlow{
  5126. WarehousingId: item.WarehousingInfoId,
  5127. GoodId: warehouseInfo.GoodId,
  5128. Number: warehouseInfo.Number,
  5129. LicenseNumber: warehouseInfo.LicenseNumber,
  5130. Count: list.StockCount - item.Count,
  5131. UserOrgId: warehouseInfo.OrgId,
  5132. PatientId: 0,
  5133. SystemTime: 0,
  5134. ConsumableType: 2,
  5135. IsSys: 2,
  5136. WarehousingOrder: "",
  5137. WarehouseOutId: warehouseOut.ID,
  5138. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5139. IsEdit: 1,
  5140. CancelStockId: 0,
  5141. CancelOrderNumber: "",
  5142. Manufacturer: manufactuer_id,
  5143. Dealer: dealer_id,
  5144. Creator: adminUserInfo.AdminUser.Id,
  5145. UpdateCreator: 0,
  5146. Status: 1,
  5147. Ctime: time.Now().Unix(),
  5148. Mtime: 0,
  5149. Price: warehouseInfo.Price,
  5150. WarehousingDetailId: 0,
  5151. WarehouseOutDetailId: warehouseOutInfo.ID,
  5152. CancelOutDetailId: 0,
  5153. ProductDate: warehouseInfo.ProductDate,
  5154. ExpireDate: warehouseInfo.ExpiryDate,
  5155. }
  5156. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5157. fmt.Println(errOne)
  5158. //创建出库明细
  5159. service.CreateStockFlowOne(stockFlow)
  5160. //更改库存
  5161. warehousingInfos := models.WarehousingInfo{
  5162. StockCount: item.Count,
  5163. }
  5164. service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
  5165. }
  5166. }
  5167. fmt.Println(err)
  5168. this.ServeSuccessJSON(map[string]interface{}{
  5169. "inventory": inventory,
  5170. })
  5171. }
  5172. func (this *StockManagerApiController) GetModifyPriceDetail() {
  5173. id, _ := this.GetInt64("id")
  5174. detail, _ := service.GetModifyPriceDetail(id)
  5175. this.ServeSuccessJSON(map[string]interface{}{
  5176. "detail": detail,
  5177. })
  5178. }
  5179. func (this *StockManagerApiController) UpdateStockPrice() {
  5180. id, _ := this.GetInt64("id")
  5181. newPrice := this.GetString("new_price")
  5182. new_price, _ := strconv.ParseFloat(newPrice, 64)
  5183. good_name := this.GetString("good_name")
  5184. packingPrice := this.GetString("packing_price")
  5185. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5186. remark := this.GetString("remark")
  5187. good_id, _ := this.GetInt64("good_id")
  5188. manufacturer := this.GetString("manufacturer")
  5189. dealer := this.GetString("dealer")
  5190. adjust := models.XtStockAdjustPrice{
  5191. NewPrice: new_price,
  5192. GoodName: good_name,
  5193. PackingPrice: packing_price,
  5194. Remark: remark,
  5195. GoodId: good_id,
  5196. Manufacturer: manufacturer,
  5197. Dealer: dealer,
  5198. }
  5199. err := service.UpdateStockPrice(adjust, id)
  5200. fmt.Println(err)
  5201. this.ServeSuccessJSON(map[string]interface{}{
  5202. "adjust": adjust,
  5203. })
  5204. }
  5205. func (this *StockManagerApiController) DeleteStockPrice() {
  5206. id, _ := this.GetInt64("id")
  5207. err := service.DeleteStockPrice(id)
  5208. fmt.Println(err)
  5209. returnData := make(map[string]interface{}, 0)
  5210. returnData["msg"] = "ok"
  5211. this.ServeSuccessJSON(returnData)
  5212. return
  5213. }
  5214. func (this *StockManagerApiController) GetStockDamageDetail() {
  5215. id, _ := this.GetInt64("id")
  5216. detail, err := service.GetStockDamageDetail(id)
  5217. fmt.Println(err)
  5218. this.ServeSuccessJSON(map[string]interface{}{
  5219. "detail": detail,
  5220. })
  5221. }
  5222. func (this *StockManagerApiController) ModifyPrice() {
  5223. count, _ := this.GetInt64("count")
  5224. id, _ := this.GetInt64("id")
  5225. good_name := this.GetString("good_name")
  5226. specification_name := this.GetString("specification_name")
  5227. number := this.GetString("number")
  5228. warehousing_unit := this.GetString("warehousing_unit")
  5229. buyPrice := this.GetString("buy_price")
  5230. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5231. packingPrice := this.GetString("packing_price")
  5232. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5233. good_origin_place := this.GetString("good_origin_place")
  5234. manufacturer := this.GetString("manufacturer")
  5235. dealer := this.GetString("dealer")
  5236. total, _ := this.GetInt64("total")
  5237. remark := this.GetString("remark")
  5238. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5239. good_id, _ := this.GetInt64("good_id")
  5240. adjust := models.XtStockReportPrice{
  5241. Count: count,
  5242. SpecificationName: specification_name,
  5243. Number: number,
  5244. GoodName: good_name,
  5245. WarehousingUnit: warehousing_unit,
  5246. BuyPrice: buy_price,
  5247. PackingPrice: packing_price,
  5248. GoodOriginPlace: good_origin_place,
  5249. Manufacturer: manufacturer,
  5250. Dealer: dealer,
  5251. Total: total,
  5252. Remark: remark,
  5253. WarehousingInfoId: warehousing_info_id,
  5254. GoodId: good_id,
  5255. }
  5256. err := service.ModifyPrice(id, adjust)
  5257. fmt.Println(err)
  5258. this.ServeSuccessJSON(map[string]interface{}{
  5259. "adjust": adjust,
  5260. })
  5261. }
  5262. func (this *StockManagerApiController) DeleteDamage() {
  5263. id, _ := this.GetInt64("id")
  5264. err := service.DeleteDamage(id)
  5265. fmt.Println(err)
  5266. returnData := make(map[string]interface{}, 0)
  5267. returnData["msg"] = "ok"
  5268. this.ServeSuccessJSON(returnData)
  5269. return
  5270. }
  5271. func (this *StockManagerApiController) GetStockDamageById() {
  5272. ids := this.GetString("ids")
  5273. splitIds := strings.Split(ids, ",")
  5274. list, _ := service.GetStockDamageById(splitIds)
  5275. this.ServeSuccessJSON(map[string]interface{}{
  5276. "list": list,
  5277. })
  5278. }
  5279. func (this *StockManagerApiController) GetInventoryDetail() {
  5280. id, _ := this.GetInt64("id")
  5281. detail, _ := service.GetInventoryDetail(id)
  5282. this.ServeSuccessJSON(map[string]interface{}{
  5283. "detail": detail,
  5284. })
  5285. }
  5286. func (this *StockManagerApiController) ModifyInventory() {
  5287. id, _ := this.GetInt64("id")
  5288. good_id, _ := this.GetInt64("good_id")
  5289. good_name := this.GetString("good_name")
  5290. specification_name := this.GetString("specification_name")
  5291. number := this.GetString("number")
  5292. warehousing_unit := this.GetString("warehousing_unit")
  5293. buyPrice := this.GetString("buy_price")
  5294. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5295. packingPrice := this.GetString("packing_price")
  5296. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5297. total, _ := this.GetInt64("total")
  5298. good_origin_place := this.GetString("good_origin_place")
  5299. license_number := this.GetString("license_number")
  5300. dealer := this.GetString("dealer")
  5301. manufacturer := this.GetString("manufacturer")
  5302. count, _ := this.GetInt64("count")
  5303. remark := this.GetString("remark")
  5304. inventory := models.XtStockInventory{
  5305. GoodId: good_id,
  5306. GoodName: good_name,
  5307. SpecificationName: specification_name,
  5308. Number: number,
  5309. WarehousingUnit: warehousing_unit,
  5310. BuyPrice: buy_price,
  5311. PackingPrice: packing_price,
  5312. Total: total,
  5313. GoodOriginPlace: good_origin_place,
  5314. LicenseNumber: license_number,
  5315. Dealer: dealer,
  5316. Manufacturer: manufacturer,
  5317. Count: count,
  5318. Remark: remark,
  5319. }
  5320. err := service.ModifyInventory(id, inventory)
  5321. fmt.Println(err)
  5322. this.ServeSuccessJSON(map[string]interface{}{
  5323. "inventory": inventory,
  5324. })
  5325. }
  5326. func (this *StockManagerApiController) DeleteInventory() {
  5327. id, _ := this.GetInt64("id")
  5328. err := service.DeleteInventory(id)
  5329. fmt.Println(err)
  5330. returnData := make(map[string]interface{}, 0)
  5331. returnData["msg"] = "ok"
  5332. this.ServeSuccessJSON(returnData)
  5333. return
  5334. }
  5335. func (this *StockManagerApiController) GetInventoryDetailList() {
  5336. keyword := this.GetString("keyword")
  5337. limit, _ := this.GetInt64("limit")
  5338. page, _ := this.GetInt64("page")
  5339. orgId := this.GetAdminUserInfo().CurrentOrgId
  5340. list, total, _ := service.GetInventoryDetailList(keyword, limit, page, orgId)
  5341. this.ServeSuccessJSON(map[string]interface{}{
  5342. "list": list,
  5343. "total": total,
  5344. })
  5345. }
  5346. func (this *StockManagerApiController) GetInventoryPrintList() {
  5347. ids := this.GetString("ids")
  5348. splitIds := strings.Split(ids, ",")
  5349. list, _ := service.GetInventoryPrintList(splitIds)
  5350. this.ServeSuccessJSON(map[string]interface{}{
  5351. "list": list,
  5352. })
  5353. }
  5354. func (this *StockManagerApiController) GetInventoryDetailPrintList() {
  5355. ids := this.GetString("ids")
  5356. splitIds := strings.Split(ids, ",")
  5357. list, _ := service.GetInventoryDetailPrintList(splitIds)
  5358. this.ServeSuccessJSON(map[string]interface{}{
  5359. "list": list,
  5360. })
  5361. }
  5362. func (this *StockManagerApiController) DeleteDrugPrice() {
  5363. id, _ := this.GetInt64("id")
  5364. err := service.DeleteDrugPrice(id)
  5365. fmt.Println(err)
  5366. returnData := make(map[string]interface{}, 0)
  5367. returnData["msg"] = "ok"
  5368. this.ServeSuccessJSON(returnData)
  5369. return
  5370. }
  5371. func (this *StockManagerApiController) GetGoodWarehouseList() {
  5372. id, _ := this.GetInt64("id")
  5373. list, _ := service.GetGoodWarehouseList(id)
  5374. this.ServeSuccessJSON(map[string]interface{}{
  5375. "list": list,
  5376. })
  5377. }
  5378. func (this *StockManagerApiController) ProofInventory() {
  5379. id, _ := this.GetInt64("id")
  5380. good_id, _ := this.GetInt64("good_id")
  5381. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5382. proof_count, _ := this.GetInt64("proof_count")
  5383. total, _ := this.GetInt64("total")
  5384. orgId := this.GetAdminUserInfo().CurrentOrgId
  5385. creater := this.GetAdminUserInfo().AdminUser.Id
  5386. info := models.WarehousingInfo{
  5387. GoodId: good_id,
  5388. StockCount: proof_count,
  5389. }
  5390. err := service.UpdateProofInventory(warehousing_info_id, info)
  5391. inventory := models.XtStockInventory{
  5392. Total: proof_count,
  5393. }
  5394. err = service.UpdateStockInventory(inventory, id)
  5395. fmt.Println(err)
  5396. record := models.XtStockCorrectRecord{
  5397. GoodId: good_id,
  5398. OrdCount: total,
  5399. WarehousingInfoId: warehousing_info_id,
  5400. NewCount: proof_count,
  5401. UserOrgId: orgId,
  5402. Status: 1,
  5403. Creater: creater,
  5404. Ctime: time.Now().Unix(),
  5405. Mtime: 0,
  5406. }
  5407. service.CeateStockCorrectRecord(record)
  5408. this.ServeSuccessJSON(map[string]interface{}{
  5409. "list": info,
  5410. })
  5411. }
  5412. func (this *StockManagerApiController) GetWarehouseTotal() {
  5413. id, _ := this.GetInt64("id")
  5414. list, _ := service.GetWarehouseTotal(id)
  5415. this.ServeSuccessJSON(map[string]interface{}{
  5416. "list": list,
  5417. })
  5418. }