stock_in_api_controller.go 256KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type StockManagerApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func StockManagerApiRegistRouters() {
  20. //入库管理和其他入库管理相关接口
  21. beego.Router("/api/warehouse/create", &StockManagerApiController{}, "post:CreateWarehouse")
  22. beego.Router("/api/warehouse/list", &StockManagerApiController{}, "get:GetWarehouseList")
  23. beego.Router("/api/warehouse/delete", &StockManagerApiController{}, "post:DeleteWarehouse")
  24. beego.Router("/api/warehouseinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseInfo")
  25. beego.Router("/api/warehouseinfo/list", &StockManagerApiController{}, "get:GetWarehouseInfoList")
  26. beego.Router("/api/warehouse/edit", &StockManagerApiController{}, "post:EditWarehouse")
  27. //退货管理和其他退货管理相关接口
  28. beego.Router("/api/salesreturn/create", &StockManagerApiController{}, "post:CreateSalesReturn")
  29. beego.Router("/api/salesreturn/delete", &StockManagerApiController{}, "post:DeleteSalesReturn")
  30. beego.Router("/api/salesreturninfo/delete", &StockManagerApiController{}, "post:DeleteSalesReturnInfo")
  31. beego.Router("/api/salesreturninfo/list", &StockManagerApiController{}, "get:GetSalesReturnInfoList")
  32. beego.Router("/api/salesreturn/list", &StockManagerApiController{}, "get:GetSalesReturnList")
  33. beego.Router("/api/salesreturn/edit", &StockManagerApiController{}, "post:EditReturnInfo")
  34. //出库管理和其他出库管理相关接口
  35. beego.Router("/api/warehouseout/create", &StockManagerApiController{}, "post:CreateWarehouseOut")
  36. beego.Router("/api/warehouseout/delete", &StockManagerApiController{}, "post:DeleteWarehouseOut")
  37. beego.Router("/api/warehouseoutinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseOutInfo")
  38. beego.Router("/api/warehouseout/list", &StockManagerApiController{}, "get:GetWarehouseOutList")
  39. beego.Router("/api/warehouseout/edit", &StockManagerApiController{}, "post:EditWarehouseOut")
  40. beego.Router("/api/warehouseout/info", &StockManagerApiController{}, "get:GetWarehouseOutInfoList")
  41. //出库退库管理和其他出库退库管理相关接口
  42. beego.Router("/api/cancelstock/create", &StockManagerApiController{}, "post:CreateCancelStock")
  43. beego.Router("/api/cancelstock/list", &StockManagerApiController{}, "get:GetCancelStockList")
  44. beego.Router("/api/cancelstock/info", &StockManagerApiController{}, "get:GetCancelStockInfoList")
  45. beego.Router("/api/cancelstock/delete", &StockManagerApiController{}, "post:DeleteCancelStock")
  46. beego.Router("/api/cancelstockinfo/delete", &StockManagerApiController{}, "post:DeleteCancelStockInfo")
  47. beego.Router("/api/cancelstockinfo/edit", &StockManagerApiController{}, "post:EditCancelStock")
  48. beego.Router("/api/cancelstockinfo/config", &StockManagerApiController{}, "get:GetCancelStockConfig")
  49. //库存相关全局配置
  50. beego.Router("/api/stock/config", &StockManagerApiController{}, "get:GetAllConfig")
  51. beego.Router("/api/return/config", &StockManagerApiController{}, "get:GetAllSalesReturnConfig")
  52. //库存查询
  53. beego.Router("/api/stock/query", &StockManagerApiController{}, "get:GetQueryInfo")
  54. beego.Router("/api/stock/detail", &StockManagerApiController{}, "get:GetDetailInfo")
  55. beego.Router("/api/warehouseout/user", &StockManagerApiController{}, "get:GetUserDetailInfo")
  56. beego.Router("/api/warehouseout/postsearchstock", &StockManagerApiController{}, "Get:PostSearchStock")
  57. beego.Router("/api/warehouseout/getoutstocktotalcount", &StockManagerApiController{}, "Get:GetOutStockTotalCount")
  58. beego.Router("/api/good/postgoodinformation", &StockManagerApiController{}, "Post:AddGoodInformation")
  59. beego.Router("/api/good/postdruginformation", &StockManagerApiController{}, "Post:AddDrugInformation")
  60. beego.Router("/api/good/initializtion", &StockManagerApiController{}, "Get:GetInitializtion")
  61. beego.Router("/api/good/getwarehouseorderinfolist", &StockManagerApiController{}, "Get:GetWarehouseOrderInfolist")
  62. beego.Router("/api/good/postsearchgoodlist", &StockManagerApiController{}, "Get:PostSearchGoodList")
  63. beego.Router("/api/good/getallstocklist", &StockManagerApiController{}, "Get:GetAllStockList")
  64. beego.Router("/api/stock/getstocklistbyid", &StockManagerApiController{}, "Get:GetStockListById")
  65. beego.Router("/api/stock/getstockoutlist", &StockManagerApiController{}, "Get:GetStockOutList")
  66. beego.Router("/api/good/getstockdrugcount", &StockManagerApiController{}, "Get:GetStockDrugCount")
  67. beego.Router("/api/good/getorderdetialbyorderid", &StockManagerApiController{}, "Get:GetOrderDetialByOrderId")
  68. beego.Router("/api/good/getorderdetaibyid", &StockManagerApiController{}, "Get:GetOrderDetailById")
  69. beego.Router("/api/good/getsingleoutorderdetail", &StockManagerApiController{}, "Get:GetSingleOutOrderDetail")
  70. beego.Router("/api/stock/getexportstocklist", &StockManagerApiController{}, "Get:GetExprotStockList")
  71. beego.Router("/api/stock/getoutexprotlist", &StockManagerApiController{}, "Get:GetOutExprotList")
  72. beego.Router("/api/stock/getsinglecancelorder", &StockManagerApiController{}, "Get:GetSingleCancelOrder")
  73. beego.Router("/api/stock/getcancelstockorderprint", &StockManagerApiController{}, "Get:GetCancelStockOrderPrint")
  74. beego.Router("/api/stock/getstockbatchnumber", &StockManagerApiController{}, "Get:GetStockBatchNumber")
  75. beego.Router("/api/stock/getstockflow", &StockManagerApiController{}, "Get:GetStockFlow")
  76. beego.Router("/api/cancel/getcancelexportlist", &StockManagerApiController{}, "Get:GetCancelExportList")
  77. //耗材调价
  78. 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. beego.Router("/api/stock/getgoodinventorywarehouselist", &StockManagerApiController{}, "Get:GetGoodInventoryWarehouseList")
  107. beego.Router("/api/stock/savestockinentorylist", &StockManagerApiController{}, "Post:SaveStockInventoryList")
  108. beego.Router("/api/sotck/getdamagedetailbygoodid", &StockManagerApiController{}, "Get:GetDamageDetailByGoodId")
  109. beego.Router("/api/stock/getinventoryexportlist", &StockManagerApiController{}, "Get:GetInventoryExportList")
  110. //处理历史数据
  111. beego.Router("/api/stock/updatecancelstockorder", &StockManagerApiController{}, "Get:UpdateCancelStockOrder")
  112. beego.Router("/api/stock/getdrugdetailsummary", &StockManagerApiController{}, "Get:GetDrugDetailSummary")
  113. beego.Router("/api/stock/getgooddetialsummary", &StockManagerApiController{}, "Get:GetGoodDetailSummary")
  114. }
  115. func (c *StockManagerApiController) CreateWarehouse() {
  116. warehousing_time := c.GetString("warehousing_time")
  117. types, _ := c.GetInt64("type", 0)
  118. storehouse_id, _ := c.GetInt64("storehouse_id")
  119. ctime := time.Now().Unix()
  120. adminUserInfo := c.GetAdminUserInfo()
  121. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  122. if parseDateErr != nil {
  123. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  125. return
  126. }
  127. timeStr := time.Now().Format("2006-01-02")
  128. timeArr := strings.Split(timeStr, "-")
  129. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  130. total = total + 1
  131. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  132. operation_time := time.Now().Unix()
  133. creater := adminUserInfo.AdminUser.Id
  134. warehousing := models.Warehousing{
  135. WarehousingOrder: warehousing_order,
  136. OperationTime: operation_time,
  137. OrgId: adminUserInfo.CurrentOrgId,
  138. Creater: creater,
  139. Ctime: ctime,
  140. Status: 1,
  141. WarehousingTime: warehousingDate.Unix(),
  142. Type: types,
  143. StorehouseId: storehouse_id,
  144. }
  145. service.AddSigleWarehouse(&warehousing)
  146. dataBody := make(map[string]interface{}, 0)
  147. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  148. if err != nil {
  149. utils.ErrorLog(err.Error())
  150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  151. return
  152. }
  153. var warehousingInfo []*models.WarehousingInfo
  154. var stockFlow []*models.VmStockFlow
  155. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  156. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  157. if len(thisStockIn) > 0 {
  158. for _, item := range thisStockIn {
  159. items := item.(map[string]interface{})
  160. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  161. utils.ErrorLog("good_id")
  162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  163. return
  164. }
  165. good_id := int64(items["good_id"].(float64))
  166. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  167. utils.ErrorLog("good_type_id")
  168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  169. return
  170. }
  171. good_type_id := int64(items["good_type_id"].(float64))
  172. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  173. utils.ErrorLog("warehousing_count")
  174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  175. return
  176. }
  177. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  178. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  179. utils.ErrorLog("price")
  180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  181. return
  182. }
  183. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  184. total := float64(warehousing_count) * price
  185. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  186. utils.ErrorLog("packing_price")
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  188. return
  189. }
  190. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  191. var productDates int64
  192. var expiryDates int64
  193. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  194. expiryDates = 0
  195. } else {
  196. if len(items["expiry_date"].(string)) == 0 {
  197. expiryDates = 0
  198. } else {
  199. expiryDate, _ := items["expiry_date"].(string)
  200. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  201. expiryDates = expiry_date.Unix()
  202. }
  203. }
  204. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  205. productDates = 0
  206. } else {
  207. if len(items["product_date"].(string)) == 0 {
  208. productDates = 0
  209. } else {
  210. productDate, _ := items["product_date"].(string)
  211. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  212. productDates = product_date.Unix()
  213. }
  214. }
  215. number, _ := items["number"].(string)
  216. remark, _ := items["remark"].(string)
  217. manufacturer := int64(items["manufacturer"].(float64))
  218. dealer := int64(items["dealer"].(float64))
  219. license_number, _ := items["license_number"].(string)
  220. //入库单表格
  221. warehouseInfo := &models.WarehousingInfo{
  222. WarehousingOrder: warehousing.WarehousingOrder,
  223. WarehousingId: warehousing.ID,
  224. GoodId: good_id,
  225. Number: number,
  226. GoodTypeId: good_type_id,
  227. ProductDate: productDates,
  228. ExpiryDate: expiryDates,
  229. WarehousingCount: warehousing_count,
  230. Price: price,
  231. TotalPrice: total,
  232. Status: 1,
  233. Ctime: ctime,
  234. Remark: remark,
  235. OrgId: adminUserInfo.CurrentOrgId,
  236. Type: types,
  237. Manufacturer: manufacturer,
  238. StockCount: warehousing_count,
  239. Dealer: dealer,
  240. LicenseNumber: license_number,
  241. PackingPrice: packing_price,
  242. StorehouseId: storehouse_id,
  243. }
  244. warehousingInfo = append(warehousingInfo, warehouseInfo)
  245. flow := &models.VmStockFlow{
  246. WarehousingOrder: warehousing.WarehousingOrder,
  247. WarehousingId: warehousing.ID,
  248. GoodId: good_id,
  249. Number: number,
  250. ProductDate: productDates,
  251. ExpireDate: expiryDates,
  252. Count: warehousing_count,
  253. Price: price,
  254. Status: 1,
  255. Ctime: ctime,
  256. UserOrgId: adminUserInfo.CurrentOrgId,
  257. Manufacturer: manufacturer,
  258. Dealer: dealer,
  259. LicenseNumber: license_number,
  260. IsEdit: 1,
  261. Creator: adminUserInfo.AdminUser.Id,
  262. SystemTime: operation_time,
  263. ConsumableType: 1,
  264. WarehousingDetailId: warehouseInfo.ID,
  265. StorehouseId: storehouse_id,
  266. }
  267. stockFlow = append(stockFlow, flow)
  268. }
  269. }
  270. }
  271. for _, item := range warehousingInfo {
  272. service.CreatedWarehouseingDetail(item)
  273. warehousinginfo, _ := service.GetLastWarehousingInfo(item.GoodId)
  274. flow := models.VmStockFlow{
  275. WarehousingOrder: item.WarehousingOrder,
  276. WarehousingId: item.WarehousingId,
  277. GoodId: item.GoodId,
  278. Number: item.Number,
  279. ProductDate: item.ProductDate,
  280. ExpireDate: item.ExpiryDate,
  281. Count: item.StockCount,
  282. Price: item.Price,
  283. Status: 1,
  284. Ctime: ctime,
  285. UserOrgId: item.OrgId,
  286. Manufacturer: item.Manufacturer,
  287. Dealer: item.Dealer,
  288. LicenseNumber: item.LicenseNumber,
  289. IsEdit: 1,
  290. Creator: adminUserInfo.AdminUser.Id,
  291. SystemTime: operation_time,
  292. ConsumableType: 1,
  293. WarehousingDetailId: warehousinginfo.ID,
  294. StorehouseId: storehouse_id,
  295. }
  296. service.CreateStockFlowOne(flow)
  297. }
  298. info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
  299. for _, item := range warehousingInfo {
  300. goodInfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  301. str := strconv.FormatInt(item.WarehousingCount, 10)
  302. minFloat, _ := strconv.ParseFloat(str, 64)
  303. good := models.GoodInfo{
  304. Total: minFloat + goodInfo.Total,
  305. }
  306. //更该库存
  307. service.UpdateGoodInfoList(good, item.GoodId)
  308. //查询默认仓库
  309. houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  310. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.GoodId, item.OrgId)
  311. var sum_count int64
  312. var sum_in_count int64
  313. for _, it := range goodList {
  314. sum_count += it.StockCount
  315. sum_in_count += it.WarehousingCount
  316. }
  317. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
  318. }
  319. c.ServeSuccessJSON(map[string]interface{}{
  320. "msg": "入库成功",
  321. "warehousing_order": warehousing_order,
  322. "info": info,
  323. })
  324. }
  325. func (c *StockManagerApiController) GetWarehouseList() {
  326. page, _ := c.GetInt64("page", -1)
  327. limit, _ := c.GetInt64("limit", -1)
  328. start_time := c.GetString("start_time")
  329. end_time := c.GetString("end_time")
  330. types, _ := c.GetInt64("type", 0)
  331. keywords := c.GetString("keywords")
  332. storehouse_id, _ := c.GetInt64("storehouse_id")
  333. timeLayout := "2006-01-02"
  334. loc, _ := time.LoadLocation("Local")
  335. var startTime int64
  336. if len(start_time) > 0 {
  337. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  338. if err != nil {
  339. fmt.Println(err)
  340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  341. return
  342. }
  343. startTime = theTime.Unix()
  344. }
  345. var endTime int64
  346. if len(end_time) > 0 {
  347. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  348. if err != nil {
  349. utils.ErrorLog(err.Error())
  350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  351. return
  352. }
  353. endTime = theTime.Unix()
  354. }
  355. adminUserInfo := c.GetAdminUserInfo()
  356. var ids []int64
  357. var goodids []int64
  358. //查询商品名称
  359. if len(keywords) > 0 {
  360. //查询商品名称
  361. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  362. for _, item := range list {
  363. goodids = append(goodids, item.ID)
  364. //入库详情但里面查询
  365. }
  366. if len(goodids) > 0 {
  367. info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id)
  368. for _, it := range info {
  369. ids = append(ids, it.WarehousingId)
  370. }
  371. }
  372. }
  373. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id)
  374. houselist, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  375. if err == nil {
  376. c.ServeSuccessJSON(map[string]interface{}{
  377. "list": warehouseList,
  378. "total": total,
  379. "houselist": houselist,
  380. })
  381. } else {
  382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  383. }
  384. }
  385. func (c *StockManagerApiController) GetWarehouseInfoList() {
  386. id := c.GetString("id")
  387. idArray := strings.Split(id, ",")
  388. warehousing, err := service.FindWarehousingByIdOne(idArray)
  389. if err != nil {
  390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  391. return
  392. }
  393. var ids []int64
  394. for _, item := range warehousing {
  395. ids = append(ids, item.ID)
  396. }
  397. warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
  398. if err == nil {
  399. c.ServeSuccessJSON(map[string]interface{}{
  400. "info": warehousingInfo,
  401. "warehousing": warehousing,
  402. })
  403. } else {
  404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  405. }
  406. }
  407. func (c *StockManagerApiController) EditWarehouse() {
  408. warehousing_time := c.GetString("warehousing_time")
  409. id, _ := c.GetInt64("id", 0)
  410. types, _ := c.GetInt64("type", 0)
  411. storehouse_id, _ := c.GetInt64("storehouse_id")
  412. if id == 0 {
  413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  414. return
  415. }
  416. ctime := time.Now().Unix()
  417. mtime := time.Now().Unix()
  418. adminUserInfo := c.GetAdminUserInfo()
  419. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  420. if parseDateErr != nil {
  421. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  423. return
  424. }
  425. warehouse, _ := service.FindWarehousingById(id)
  426. warehousing := models.Warehousing{
  427. WarehousingOrder: warehouse.WarehousingOrder,
  428. OrgId: adminUserInfo.CurrentOrgId,
  429. Modifier: adminUserInfo.AdminUser.Id,
  430. Mtime: mtime,
  431. Status: 1,
  432. WarehousingTime: warehousingDate.Unix(),
  433. Type: warehouse.Type,
  434. StorehouseId: storehouse_id,
  435. }
  436. service.EditWarehousing(warehousing)
  437. dataBody := make(map[string]interface{}, 0)
  438. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  439. if err != nil {
  440. utils.ErrorLog(err.Error())
  441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  442. return
  443. }
  444. var warehousingInfo []*models.WarehousingInfo
  445. var upDateWarehousingInfo []*models.WarehousingInfo
  446. var stockFlow []*models.VmStockFlow
  447. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  448. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  449. if len(thisStockIn) > 0 {
  450. for _, item := range thisStockIn {
  451. items := item.(map[string]interface{})
  452. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  453. utils.ErrorLog("good_id")
  454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  455. return
  456. }
  457. good_id := int64(items["good_id"].(float64))
  458. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  459. utils.ErrorLog("good_type_id")
  460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  461. return
  462. }
  463. good_type_id := int64(items["good_type_id"].(float64))
  464. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  465. utils.ErrorLog("warehousing_count")
  466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  467. return
  468. }
  469. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  470. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  471. utils.ErrorLog("price")
  472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  473. return
  474. }
  475. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  476. total := float64(warehousing_count) * price
  477. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  478. utils.ErrorLog("packing_price")
  479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  480. return
  481. }
  482. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  483. var productDates int64
  484. var expiryDates int64
  485. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  486. expiryDates = 0
  487. } else {
  488. if len(items["expiry_date"].(string)) == 0 {
  489. expiryDates = 0
  490. } else {
  491. expiryDate, _ := items["expiry_date"].(string)
  492. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  493. expiryDates = expiry_date.Unix()
  494. }
  495. }
  496. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  497. productDates = 0
  498. } else {
  499. if len(items["product_date"].(string)) == 0 {
  500. productDates = 0
  501. } else {
  502. productDate, _ := items["product_date"].(string)
  503. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  504. productDates = product_date.Unix()
  505. }
  506. }
  507. number, _ := items["number"].(string)
  508. remark, _ := items["remark"].(string)
  509. manufacturer := int64(items["manufacturer"].(float64))
  510. dealer := int64(items["dealer"].(float64))
  511. license_number, _ := items["license_number"].(string)
  512. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  513. utils.ErrorLog("id")
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. id := int64(items["id"].(float64))
  518. if id == 0 {
  519. warehouseInfo := &models.WarehousingInfo{
  520. WarehousingOrder: warehouse.WarehousingOrder,
  521. WarehousingId: warehouse.ID,
  522. GoodId: good_id,
  523. Number: number,
  524. GoodTypeId: good_type_id,
  525. ProductDate: productDates,
  526. ExpiryDate: expiryDates,
  527. WarehousingCount: warehousing_count,
  528. Price: price,
  529. TotalPrice: total,
  530. Status: 1,
  531. Ctime: ctime,
  532. Remark: remark,
  533. OrgId: adminUserInfo.CurrentOrgId,
  534. Type: types,
  535. Manufacturer: manufacturer,
  536. Dealer: dealer,
  537. StockCount: warehousing_count,
  538. LicenseNumber: license_number,
  539. PackingPrice: packing_price,
  540. StorehouseId: storehouse_id,
  541. }
  542. warehousingInfo = append(warehousingInfo, warehouseInfo)
  543. } else {
  544. warehouseInfo := &models.WarehousingInfo{
  545. ID: id,
  546. WarehousingOrder: warehouse.WarehousingOrder,
  547. WarehousingId: warehouse.ID,
  548. GoodId: good_id,
  549. Number: number,
  550. GoodTypeId: good_type_id,
  551. ProductDate: productDates,
  552. ExpiryDate: expiryDates,
  553. WarehousingCount: warehousing_count,
  554. Price: price,
  555. TotalPrice: total,
  556. Status: 1,
  557. Ctime: ctime,
  558. Remark: remark,
  559. OrgId: adminUserInfo.CurrentOrgId,
  560. Type: types,
  561. Manufacturer: manufacturer,
  562. Dealer: dealer,
  563. LicenseNumber: license_number,
  564. PackingPrice: packing_price,
  565. StorehouseId: storehouse_id,
  566. }
  567. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  568. flow := &models.VmStockFlow{
  569. WarehousingOrder: warehousing.WarehousingOrder,
  570. WarehousingId: id,
  571. GoodId: good_id,
  572. Number: number,
  573. ProductDate: productDates,
  574. ExpireDate: expiryDates,
  575. Count: warehousing_count,
  576. Price: price,
  577. Status: 1,
  578. Ctime: ctime,
  579. UserOrgId: adminUserInfo.CurrentOrgId,
  580. Manufacturer: manufacturer,
  581. Dealer: dealer,
  582. LicenseNumber: license_number,
  583. IsEdit: 2,
  584. Creator: adminUserInfo.AdminUser.Id,
  585. SystemTime: ctime,
  586. ConsumableType: 1,
  587. WarehousingDetailId: warehouseInfo.ID,
  588. StorehouseId: storehouse_id,
  589. }
  590. stockFlow = append(stockFlow, flow)
  591. }
  592. }
  593. }
  594. }
  595. var errs error
  596. if len(warehousingInfo) > 0 {
  597. errs = service.CreateWarehousingInfo(warehousingInfo)
  598. for _, its := range warehousingInfo {
  599. //查询
  600. info, _ := service.GetLastGoodWarehouseInfo(its.GoodId)
  601. flows := models.VmStockFlow{
  602. WarehousingOrder: info.WarehousingOrder,
  603. WarehousingId: info.ID,
  604. GoodId: info.GoodId,
  605. Number: info.Number,
  606. ProductDate: info.ProductDate,
  607. ExpireDate: info.ExpiryDate,
  608. Count: info.WarehousingCount,
  609. Price: info.Price,
  610. Status: 1,
  611. Ctime: ctime,
  612. UserOrgId: adminUserInfo.CurrentOrgId,
  613. Manufacturer: info.Manufacturer,
  614. Dealer: info.Dealer,
  615. LicenseNumber: info.LicenseNumber,
  616. IsEdit: 1,
  617. Creator: adminUserInfo.AdminUser.Id,
  618. SystemTime: ctime,
  619. ConsumableType: 1,
  620. WarehousingDetailId: info.ID,
  621. }
  622. _, errcodescode := service.GetGoodStockFlowInfo(info.ID, info.GoodId)
  623. if errcodescode == gorm.ErrRecordNotFound {
  624. service.CreateStockFlowOne(flows)
  625. }
  626. //改变库存
  627. good, _ := service.GetLastInfoMationById(info.GoodId)
  628. warhouseCount := strconv.FormatInt(info.WarehousingCount, 10)
  629. total, _ := strconv.ParseFloat(warhouseCount, 64)
  630. goodInfo := models.GoodInfo{
  631. Total: good.Total + total,
  632. }
  633. errcodescode = service.UpdateGoodInfoMation(info.GoodId, goodInfo)
  634. fmt.Println(errcodescode)
  635. //查询该机构默认仓库
  636. storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  637. //查询剩余库存
  638. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, adminUserInfo.CurrentOrgId)
  639. var sum_count int64
  640. var sum_in_count int64
  641. for _, item := range goodList {
  642. sum_count += item.StockCount
  643. sum_in_count += item.WarehousingCount
  644. }
  645. service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
  646. }
  647. }
  648. if len(upDateWarehousingInfo) > 0 {
  649. for _, item := range upDateWarehousingInfo {
  650. var total int64
  651. //获取该批次该型号的库存
  652. info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
  653. //增加库存
  654. if item.WarehousingCount > info.WarehousingCount {
  655. total = item.WarehousingCount - info.WarehousingCount
  656. goodinfo := models.WarehousingInfo{
  657. WarehousingCount: item.WarehousingCount,
  658. StockCount: info.StockCount + total,
  659. Price: item.Price,
  660. Manufacturer: item.Manufacturer,
  661. Number: item.Number,
  662. ProductDate: item.ProductDate,
  663. ExpiryDate: item.ExpiryDate,
  664. LicenseNumber: item.LicenseNumber,
  665. Dealer: item.Dealer,
  666. Remark: item.Remark,
  667. PackingPrice: item.PackingPrice,
  668. StorehouseId: storehouse_id,
  669. }
  670. //改变库存
  671. good, _ := service.GetLastInfoMationById(info.GoodId)
  672. warhouseCount := strconv.FormatInt(total, 10)
  673. all_total, _ := strconv.ParseFloat(warhouseCount, 64)
  674. goodInfo := models.GoodInfo{
  675. Total: good.Total + all_total,
  676. }
  677. service.UpdateGoodInfoMation(info.GoodId, goodInfo)
  678. service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
  679. //查询该机构默认仓库
  680. storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  681. //查询剩余库存
  682. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
  683. var sum_count int64
  684. var sum_in_count int64
  685. for _, item := range goodList {
  686. sum_count += item.StockCount
  687. sum_in_count += item.WarehousingCount
  688. }
  689. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
  690. }
  691. if item.WarehousingCount < info.WarehousingCount {
  692. total = info.WarehousingCount - item.WarehousingCount
  693. goodinfo := models.WarehousingInfo{
  694. WarehousingCount: item.WarehousingCount,
  695. StockCount: info.StockCount - total,
  696. Price: item.Price,
  697. Manufacturer: item.Manufacturer,
  698. Number: item.Number,
  699. ProductDate: item.ProductDate,
  700. ExpiryDate: item.ExpiryDate,
  701. LicenseNumber: item.LicenseNumber,
  702. Dealer: item.Dealer,
  703. Remark: item.Remark,
  704. PackingPrice: item.PackingPrice,
  705. StorehouseId: storehouse_id,
  706. }
  707. //改变库存
  708. good, _ := service.GetLastInfoMationById(info.GoodId)
  709. warhouseCount := strconv.FormatInt(total, 10)
  710. all_total, _ := strconv.ParseFloat(warhouseCount, 64)
  711. goodInfo := models.GoodInfo{
  712. Total: good.Total - all_total,
  713. }
  714. service.UpdateGoodInfoMation(info.GoodId, goodInfo)
  715. service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
  716. //查询该机构默认仓库
  717. storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  718. //查询剩余库存
  719. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
  720. var sum_count int64
  721. var sum_in_count int64
  722. for _, item := range goodList {
  723. sum_count += item.StockCount
  724. sum_in_count += item.WarehousingCount
  725. }
  726. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
  727. }
  728. if item.WarehousingCount == info.WarehousingCount {
  729. goodinfo := models.WarehousingInfo{
  730. WarehousingCount: item.WarehousingCount,
  731. StockCount: info.StockCount,
  732. Price: item.Price,
  733. Manufacturer: item.Manufacturer,
  734. Number: item.Number,
  735. ProductDate: item.ProductDate,
  736. ExpiryDate: item.ExpiryDate,
  737. LicenseNumber: item.LicenseNumber,
  738. Dealer: item.Dealer,
  739. Remark: item.Remark,
  740. PackingPrice: item.PackingPrice,
  741. StorehouseId: storehouse_id,
  742. }
  743. service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
  744. //查询该机构默认仓库
  745. storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  746. //查询剩余库存
  747. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
  748. var sum_count int64
  749. var sum_in_count int64
  750. for _, item := range goodList {
  751. sum_count += item.StockCount
  752. sum_in_count += item.WarehousingCount
  753. }
  754. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
  755. }
  756. }
  757. }
  758. if len(stockFlow) > 0 {
  759. for _, item := range stockFlow {
  760. flow := models.VmStockFlow{
  761. Count: item.Count,
  762. Number: item.Number,
  763. ProductDate: item.ProductDate,
  764. ExpireDate: item.ExpireDate,
  765. Price: item.Price,
  766. Manufacturer: item.Manufacturer,
  767. Dealer: item.Dealer,
  768. LicenseNumber: item.LicenseNumber,
  769. StorehouseId: storehouse_id,
  770. }
  771. parseDateErr := service.UpdatedStockFlowByGoodIdOne(item.WarehousingId, item.GoodId, flow)
  772. fmt.Println(parseDateErr)
  773. }
  774. }
  775. if errs != nil {
  776. utils.ErrorLog(errs.Error())
  777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  778. return
  779. }
  780. c.ServeSuccessJSON(map[string]interface{}{
  781. "msg": "编辑成功",
  782. })
  783. }
  784. func (c *StockManagerApiController) DeleteWarehouse() {
  785. ids := c.GetString("ids")
  786. if len(ids) == 0 {
  787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  788. return
  789. }
  790. orgId := c.GetAdminUserInfo().CurrentOrgId
  791. idArray := strings.Split(ids, ",")
  792. err := service.DeleteWarehouse(idArray)
  793. //删除流水
  794. service.DeleteStockFlow(idArray)
  795. //查询入库单的库存
  796. list, _ := service.GetWarehousingByIdListTwenty(idArray, orgId)
  797. for _, item := range list {
  798. //查询该机构默认仓库
  799. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  800. //查询剩余库存
  801. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, orgId)
  802. var sum_count int64
  803. var sum_in_count int64
  804. for _, item := range goodList {
  805. sum_count += item.StockCount
  806. sum_in_count += item.WarehousingCount
  807. }
  808. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, orgId)
  809. }
  810. if err != nil {
  811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  812. } else {
  813. c.ServeSuccessJSON(map[string]interface{}{
  814. "msg": "删除成功",
  815. })
  816. }
  817. }
  818. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  819. id, _ := c.GetInt64("id", 0)
  820. if id == 0 {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. orgId := c.GetAdminUserInfo().CurrentOrgId
  825. err := service.UpDateWarehouseStatus(id)
  826. service.UpdatedStockFlowById(id)
  827. //查询入库记录
  828. info, _ := service.GetWarehouseInfoByIdTwenty(id, orgId)
  829. //查询该机构默认仓库
  830. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  831. //查询剩余库存
  832. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, orgId)
  833. var sum_count int64
  834. var sum_in_count int64
  835. for _, item := range goodList {
  836. sum_count += item.StockCount
  837. sum_in_count += item.WarehousingCount
  838. }
  839. service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
  840. if err != nil {
  841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  842. } else {
  843. c.ServeSuccessJSON(map[string]interface{}{
  844. "msg": "删除成功",
  845. })
  846. }
  847. }
  848. func (c *StockManagerApiController) CreateSalesReturn() {
  849. dealer_id, _ := c.GetInt64("dealer_id", 0)
  850. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  851. sales_return_time := c.GetString("time")
  852. types, _ := c.GetInt64("type", 0)
  853. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  854. if parseDateErr != nil {
  855. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. return
  858. }
  859. adminUserInfo := c.GetAdminUserInfo()
  860. operation_time := time.Now().Unix()
  861. creater := adminUserInfo.AdminUser.Id
  862. ctime := time.Now().Unix()
  863. timeStr := time.Now().Format("2006-01-02")
  864. timeArr := strings.Split(timeStr, "-")
  865. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  866. total = total + 1
  867. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  868. salesReturn := models.SalesReturn{
  869. OrderNumber: orderNumber,
  870. OperaTime: operation_time,
  871. OrgId: adminUserInfo.CurrentOrgId,
  872. Creater: creater,
  873. Ctime: ctime,
  874. Status: 1,
  875. ReturnTime: salesReturnDate.Unix(),
  876. Dealer: dealer_id,
  877. Manufacturer: manufacturer_id,
  878. Type: types,
  879. }
  880. service.AddSigleSalesReturn(&salesReturn)
  881. dataBody := make(map[string]interface{}, 0)
  882. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  883. if err != nil {
  884. utils.ErrorLog(err.Error())
  885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  886. return
  887. }
  888. var salesReturnInfos []*models.SalesReturnInfo
  889. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  890. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  891. if len(thisStockIn) > 0 {
  892. for _, item := range thisStockIn {
  893. items := item.(map[string]interface{})
  894. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  895. utils.ErrorLog("good_id")
  896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  897. return
  898. }
  899. good_id := int64(items["good_id"].(float64))
  900. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  901. utils.ErrorLog("good_type_id")
  902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  903. return
  904. }
  905. good_type_id := int64(items["good_type_id"].(float64))
  906. return_count, _ := items["return_count"].(string)
  907. if len(return_count) == 0 {
  908. utils.ErrorLog("len(return_count) == 0")
  909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  910. return
  911. }
  912. count, _ := strconv.ParseInt(return_count, 10, 64)
  913. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  914. total := float64(count) * price
  915. salesReturnInfo := &models.SalesReturnInfo{
  916. OrderNumber: salesReturn.OrderNumber,
  917. SalesReturnId: salesReturn.ID,
  918. GoodId: good_id,
  919. GoodTypeId: good_type_id,
  920. Count: count,
  921. Price: price,
  922. Total: total,
  923. Status: 1,
  924. Ctime: ctime,
  925. OrgId: adminUserInfo.CurrentOrgId,
  926. Type: types,
  927. Manufacturer: manufacturer_id,
  928. Dealer: dealer_id,
  929. }
  930. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  931. }
  932. }
  933. }
  934. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  935. if errs != nil {
  936. utils.ErrorLog(errs.Error())
  937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  938. return
  939. }
  940. c.ServeSuccessJSON(map[string]interface{}{
  941. "msg": "退货成功",
  942. })
  943. }
  944. func (c *StockManagerApiController) GetSalesReturnList() {
  945. page, _ := c.GetInt64("page", -1)
  946. limit, _ := c.GetInt64("limit", -1)
  947. start_time := c.GetString("start_time")
  948. end_time := c.GetString("end_time")
  949. types, _ := c.GetInt64("type", 0)
  950. keywords := c.GetString("keywords")
  951. timeLayout := "2006-01-02"
  952. loc, _ := time.LoadLocation("Local")
  953. var startTime int64
  954. if len(start_time) > 0 {
  955. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  956. if err != nil {
  957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  958. return
  959. }
  960. startTime = theTime.Unix()
  961. }
  962. var endTime int64
  963. if len(end_time) > 0 {
  964. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  965. if err != nil {
  966. utils.ErrorLog(err.Error())
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  968. return
  969. }
  970. endTime = theTime.Unix()
  971. }
  972. adminUserInfo := c.GetAdminUserInfo()
  973. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  974. if err == nil {
  975. c.ServeSuccessJSON(map[string]interface{}{
  976. "list": returnList,
  977. "total": total,
  978. })
  979. } else {
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  981. }
  982. }
  983. func (this *StockManagerApiController) DeleteSalesReturn() {
  984. ids := this.GetString("ids")
  985. if len(ids) == 0 {
  986. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  987. return
  988. }
  989. idArray := strings.Split(ids, ",")
  990. err := service.DeleteSalesReturn(idArray)
  991. if err != nil {
  992. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  993. } else {
  994. this.ServeSuccessJSON(map[string]interface{}{
  995. "msg": "删除成功",
  996. })
  997. }
  998. }
  999. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  1000. id, _ := this.GetInt64("id", 0)
  1001. fmt.Println(id)
  1002. if id == 0 {
  1003. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1004. return
  1005. }
  1006. err := service.UpDateSaleReturnStatus(id)
  1007. if err != nil {
  1008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1009. } else {
  1010. this.ServeSuccessJSON(map[string]interface{}{
  1011. "msg": "删除成功",
  1012. })
  1013. }
  1014. }
  1015. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  1016. id, _ := this.GetInt64("id", 0)
  1017. list, _ := service.FindAllSalesReturnInfoById(id)
  1018. salesReturn, _ := service.FindAllSalesReturnById(id)
  1019. this.ServeSuccessJSON(map[string]interface{}{
  1020. "list": list,
  1021. "salesReturn": salesReturn,
  1022. })
  1023. }
  1024. func (c *StockManagerApiController) EditReturnInfo() {
  1025. return_time := c.GetString("return_time")
  1026. id, _ := c.GetInt64("id", 0)
  1027. types, _ := c.GetInt64("type", 0)
  1028. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1029. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1030. if id == 0 {
  1031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1032. return
  1033. }
  1034. ctime := time.Now().Unix()
  1035. mtime := time.Now().Unix()
  1036. adminUserInfo := c.GetAdminUserInfo()
  1037. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  1038. if parseDateErr != nil {
  1039. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  1040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1041. return
  1042. }
  1043. salesReturns, _ := service.FindSalesReturnById(id)
  1044. sales := models.SalesReturn{
  1045. ID: salesReturns.ID,
  1046. Mtime: mtime,
  1047. ReturnTime: returnDate.Unix(),
  1048. Manufacturer: manufacturer_id,
  1049. Dealer: dealer_id,
  1050. }
  1051. service.EditSaleReturn(sales)
  1052. dataBody := make(map[string]interface{}, 0)
  1053. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1054. if err != nil {
  1055. utils.ErrorLog(err.Error())
  1056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1057. return
  1058. }
  1059. var returnInfos []*models.SalesReturnInfo
  1060. var upDateReturnInfos []*models.SalesReturnInfo
  1061. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  1062. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  1063. if len(thisStockIn) > 0 {
  1064. for _, item := range thisStockIn {
  1065. items := item.(map[string]interface{})
  1066. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1067. utils.ErrorLog("good_id")
  1068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1069. return
  1070. }
  1071. good_id := int64(items["good_id"].(float64))
  1072. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1073. utils.ErrorLog("good_type_id")
  1074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1075. return
  1076. }
  1077. good_type_id := int64(items["good_type_id"].(float64))
  1078. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1079. utils.ErrorLog("count")
  1080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1081. return
  1082. }
  1083. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1084. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1085. utils.ErrorLog("id")
  1086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1087. return
  1088. }
  1089. id := int64(items["id"].(float64))
  1090. if id == 0 {
  1091. returnInfo := &models.SalesReturnInfo{
  1092. GoodId: good_id,
  1093. GoodTypeId: good_type_id,
  1094. Count: count,
  1095. Status: 1,
  1096. Ctime: ctime,
  1097. OrgId: adminUserInfo.CurrentOrgId,
  1098. OrderNumber: sales.OrderNumber,
  1099. SalesReturnId: sales.ID,
  1100. Mtime: time.Now().Unix(),
  1101. Type: types,
  1102. Manufacturer: manufacturer_id,
  1103. Dealer: dealer_id,
  1104. }
  1105. returnInfos = append(returnInfos, returnInfo)
  1106. } else {
  1107. returnInfo := &models.SalesReturnInfo{
  1108. ID: id,
  1109. GoodId: good_id,
  1110. GoodTypeId: good_type_id,
  1111. Count: count,
  1112. Status: 1,
  1113. Ctime: ctime,
  1114. OrgId: adminUserInfo.CurrentOrgId,
  1115. OrderNumber: sales.OrderNumber,
  1116. SalesReturnId: sales.ID,
  1117. Mtime: time.Now().Unix(),
  1118. Type: types,
  1119. Manufacturer: manufacturer_id,
  1120. Dealer: dealer_id,
  1121. }
  1122. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  1123. }
  1124. }
  1125. }
  1126. }
  1127. var errs error
  1128. if len(returnInfos) > 0 {
  1129. errs = service.CreateSalesReturnInfo(returnInfos)
  1130. }
  1131. if len(upDateReturnInfos) > 0 {
  1132. for _, item := range upDateReturnInfos {
  1133. errs = service.UpDateSalesReturnInfo(item)
  1134. }
  1135. }
  1136. if errs != nil {
  1137. utils.ErrorLog(errs.Error())
  1138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1139. return
  1140. }
  1141. c.ServeSuccessJSON(map[string]interface{}{
  1142. "msg": "编辑成功",
  1143. })
  1144. }
  1145. func (c *StockManagerApiController) CreateWarehouseOut() {
  1146. types, _ := c.GetInt64("type", 0)
  1147. storehouse_id, _ := c.GetInt64("storehouse_id")
  1148. ctime := time.Now().Unix()
  1149. adminUserInfo := c.GetAdminUserInfo()
  1150. warehousing_out_time := c.GetString("warehousing_out_time")
  1151. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  1152. if parseDateErr != nil {
  1153. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  1154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1155. return
  1156. }
  1157. timeStr := time.Now().Format("2006-01-02")
  1158. timeArr := strings.Split(timeStr, "-")
  1159. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  1160. total = total + 1
  1161. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1162. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1163. number = number + total
  1164. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1165. operation_time := time.Now().Unix()
  1166. creater := adminUserInfo.AdminUser.Id
  1167. warehouseOut := models.WarehouseOut{
  1168. WarehouseOutOrderNumber: warehousing_out_order,
  1169. OperationTime: operation_time,
  1170. OrgId: adminUserInfo.CurrentOrgId,
  1171. Creater: creater,
  1172. Ctime: ctime,
  1173. Status: 1,
  1174. WarehouseOutTime: warehousingOutDate.Unix(),
  1175. Type: types,
  1176. StorehouseId: storehouse_id,
  1177. }
  1178. dataBody := make(map[string]interface{}, 0)
  1179. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1180. if err != nil {
  1181. utils.ErrorLog(err.Error())
  1182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1183. return
  1184. }
  1185. var warehousingOutInfo []*models.WarehouseOutInfo
  1186. var beforePrepares []*models.DialysisBeforePrepareGoods
  1187. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  1188. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1189. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  1190. if len(thisStockIn) > 0 {
  1191. for _, item := range thisStockIn {
  1192. items := item.(map[string]interface{})
  1193. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1194. utils.ErrorLog("good_id")
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1196. return
  1197. }
  1198. good_id := int64(items["good_id"].(float64))
  1199. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1200. utils.ErrorLog("good_type_id")
  1201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1202. return
  1203. }
  1204. good_type_id := int64(items["good_type_id"].(float64))
  1205. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1206. utils.ErrorLog("count")
  1207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1208. return
  1209. }
  1210. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1211. utils.ErrorLog("price")
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1213. return
  1214. }
  1215. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1216. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1217. total := float64(count) * price
  1218. remark := items["remark"].(string)
  1219. manufacturer := int64(items["manufacturer"].(float64))
  1220. dealer := int64(items["dealer"].(float64))
  1221. number := items["number"].(string)
  1222. expiry_date := items["expiry_date"].(string)
  1223. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1224. admin_user_id := int64(items["admin_user_id"].(float64))
  1225. timeLayout := "2006-01-02"
  1226. loc, _ := time.LoadLocation("Local")
  1227. var expiryDate int64
  1228. if len(expiry_date) > 0 {
  1229. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1230. if err != nil {
  1231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1232. return
  1233. }
  1234. expiryDate = theTime.Unix()
  1235. }
  1236. product_date := items["product_date"].(string)
  1237. var productDate int64
  1238. if len(product_date) > 0 {
  1239. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
  1240. if err != nil {
  1241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1242. return
  1243. }
  1244. productDate = theTime.Unix()
  1245. }
  1246. license_number := items["license_number"].(string)
  1247. warehouseOutInfo := &models.WarehouseOutInfo{
  1248. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1249. WarehouseOutId: warehouseOut.ID,
  1250. GoodId: good_id,
  1251. GoodTypeId: good_type_id,
  1252. Count: count,
  1253. Price: price,
  1254. TotalPrice: total,
  1255. Status: 1,
  1256. Ctime: ctime,
  1257. Remark: remark,
  1258. OrgId: adminUserInfo.CurrentOrgId,
  1259. Type: types,
  1260. Manufacturer: manufacturer,
  1261. Number: number,
  1262. ExpiryDate: expiryDate,
  1263. ProductDate: productDate,
  1264. Dealer: dealer,
  1265. LicenseNumber: license_number,
  1266. WarehouseInfotId: warehouse_info_id,
  1267. StorehouseId: storehouse_id,
  1268. AdminUserId: admin_user_id,
  1269. }
  1270. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1271. prepareGoods := &models.DialysisBeforePrepareGoods{
  1272. GoodTypeId: good_type_id,
  1273. GoodId: good_id,
  1274. Count: count,
  1275. StorehouseId: storehouse_id,
  1276. }
  1277. beforePrepares = append(beforePrepares, prepareGoods)
  1278. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  1279. GoodTypeId: good_type_id,
  1280. GoodId: good_id,
  1281. Count: count,
  1282. StorehouseId: storehouse_id,
  1283. }
  1284. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  1285. }
  1286. }
  1287. }
  1288. //出库逻辑
  1289. for _, item := range warehousingOutInfo {
  1290. // 查询该耗材是否有库存
  1291. warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId, item.StorehouseId)
  1292. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseId, item.OrgId)
  1293. // 如果出库数量大于该批次剩余库存数量
  1294. if item.Count > warehouseOne.StockCount {
  1295. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1296. c.ServeSuccessJSON(map[string]interface{}{
  1297. "msg": "1",
  1298. "good_name": goodObj.GoodName,
  1299. "specification_name": goodObj.SpecificationName,
  1300. "storehose_name": storehouse.StorehouseName,
  1301. })
  1302. return
  1303. }
  1304. }
  1305. for _, it := range warehousingOutInfo {
  1306. //查询是否生成出库单
  1307. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  1308. if errcodes == gorm.ErrRecordNotFound {
  1309. service.AddSigleWarehouseOut(&warehouseOut)
  1310. }
  1311. //出库逻辑
  1312. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), it, &warehouseOut, it.Count, creater)
  1313. if parseDateErr != nil {
  1314. utils.ErrorLog(parseDateErr.Error())
  1315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1316. return
  1317. }
  1318. }
  1319. c.ServeSuccessJSON(map[string]interface{}{
  1320. "msg": "2",
  1321. "good_name": "",
  1322. "specification_name": "",
  1323. })
  1324. return
  1325. }
  1326. func (c *StockManagerApiController) GetWarehouseOutList() {
  1327. page, _ := c.GetInt64("page", -1)
  1328. limit, _ := c.GetInt64("limit", -1)
  1329. start_time := c.GetString("start_time")
  1330. end_time := c.GetString("end_time")
  1331. types, _ := c.GetInt64("type", 0)
  1332. keywords := c.GetString("keywords")
  1333. storehouse_id, _ := c.GetInt64("storehouse_id")
  1334. timeLayout := "2006-01-02"
  1335. loc, _ := time.LoadLocation("Local")
  1336. var startTime int64
  1337. if len(start_time) > 0 {
  1338. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1339. if err != nil {
  1340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1341. return
  1342. }
  1343. startTime = theTime.Unix()
  1344. }
  1345. var endTime int64
  1346. if len(end_time) > 0 {
  1347. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1348. if err != nil {
  1349. utils.ErrorLog(err.Error())
  1350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1351. return
  1352. }
  1353. endTime = theTime.Unix()
  1354. }
  1355. adminUserInfo := c.GetAdminUserInfo()
  1356. var ids []int64
  1357. var goodids []int64
  1358. if len(keywords) > 0 {
  1359. //查询商品名称
  1360. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  1361. for _, item := range list {
  1362. goodids = append(goodids, item.ID)
  1363. }
  1364. if len(goodids) > 0 {
  1365. //出库详情但里面查询
  1366. info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id)
  1367. for _, it := range info {
  1368. ids = append(ids, it.WarehouseOutId)
  1369. }
  1370. }
  1371. }
  1372. warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id)
  1373. houselist, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  1374. fmt.Println(err)
  1375. if err == nil {
  1376. c.ServeSuccessJSON(map[string]interface{}{
  1377. "list": warehouseOutList,
  1378. "total": total,
  1379. "houselist": houselist,
  1380. })
  1381. } else {
  1382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1383. }
  1384. }
  1385. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1386. ids := c.GetString("ids")
  1387. if len(ids) == 0 {
  1388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1389. return
  1390. }
  1391. idArray := strings.Split(ids, ",")
  1392. err := service.DeleteWarehouseOut(idArray)
  1393. list, _ := service.GetWarehouseOutInfoByIds(idArray)
  1394. for _, item := range list {
  1395. //添加库存
  1396. service.UpdateWarehouseInfoById(item.WarehouseInfotId, item.Count)
  1397. //添加库存
  1398. //查询该机构默认仓库
  1399. storeConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  1400. //查询剩余库存
  1401. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, item.OrgId)
  1402. var sum_count int64
  1403. var sum_in_count int64
  1404. for _, item := range goodList {
  1405. sum_count += item.StockCount
  1406. sum_in_count += item.WarehousingCount
  1407. }
  1408. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
  1409. }
  1410. if err != nil {
  1411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1412. } else {
  1413. c.ServeSuccessJSON(map[string]interface{}{
  1414. "msg": "删除成功",
  1415. })
  1416. }
  1417. }
  1418. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1419. id, _ := this.GetInt64("id", 0)
  1420. fmt.Println(id)
  1421. if id == 0 {
  1422. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1423. return
  1424. }
  1425. //添加库存
  1426. out, _ := service.GetWarhouseOutById(id)
  1427. service.UpdateWareInfoById(out.WarehouseInfotId, out.Count)
  1428. //查询该机构默认仓库
  1429. storeConfig, _ := service.GetAllStoreHouseConfig(out.OrgId)
  1430. //查询剩余库存
  1431. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, out.GoodId, out.OrgId)
  1432. var sum_count int64
  1433. var sum_in_count int64
  1434. for _, item := range goodList {
  1435. sum_count += item.StockCount
  1436. sum_in_count += item.WarehousingCount
  1437. }
  1438. service.UpdateGoodByGoodId(out.GoodId, sum_count, sum_in_count, out.OrgId)
  1439. err := service.UpDateWarehouseOutStatus(id)
  1440. service.UpdateStockFlowWarehouseOutById(id)
  1441. if err != nil {
  1442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1443. } else {
  1444. this.ServeSuccessJSON(map[string]interface{}{
  1445. "msg": "删除成功",
  1446. })
  1447. }
  1448. }
  1449. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1450. id, _ := c.GetInt64("id", 0)
  1451. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1452. warehouseOut, _ := service.FindWareHouseOutById(id)
  1453. adminUserInfo := c.GetAdminUserInfo()
  1454. orgId := adminUserInfo.CurrentOrgId
  1455. wareoutList, _ := service.GetWareOutInfoById(id, orgId)
  1456. c.ServeSuccessJSON(map[string]interface{}{
  1457. "list": warehouseOutInfo,
  1458. "info": warehouseOut,
  1459. "wareoutList": wareoutList,
  1460. })
  1461. }
  1462. func (c *StockManagerApiController) EditWarehouseOut() {
  1463. warehouse_out_time := c.GetString("warehouse_out_time")
  1464. id, _ := c.GetInt64("id", 0)
  1465. types, _ := c.GetInt64("type", 0)
  1466. storehouse_id, _ := c.GetInt64("storehouse_id")
  1467. if id == 0 {
  1468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1469. return
  1470. }
  1471. ctime := time.Now().Unix()
  1472. mtime := time.Now().Unix()
  1473. adminUserInfo := c.GetAdminUserInfo()
  1474. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1475. if parseDateErr != nil {
  1476. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1478. return
  1479. }
  1480. warehouseOut, _ := service.FindWareHouseOutById(id)
  1481. tempWarehouseOut := models.WarehouseOut{
  1482. ID: warehouseOut.ID,
  1483. Mtime: mtime,
  1484. WarehouseOutTime: warehouseOutDate.Unix(),
  1485. StorehouseId: storehouse_id,
  1486. }
  1487. service.EditWarehouseOut(tempWarehouseOut)
  1488. dataBody := make(map[string]interface{}, 0)
  1489. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1490. if err != nil {
  1491. utils.ErrorLog(err.Error())
  1492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1493. return
  1494. }
  1495. var warehousingOutInfo []*models.WarehouseOutInfo
  1496. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1497. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1498. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1499. if len(thisStockOut) > 0 {
  1500. for _, item := range thisStockOut {
  1501. items := item.(map[string]interface{})
  1502. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1503. utils.ErrorLog("good_id")
  1504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1505. return
  1506. }
  1507. good_id := int64(items["good_id"].(float64))
  1508. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1509. utils.ErrorLog("good_type_id")
  1510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1511. return
  1512. }
  1513. good_type_id := int64(items["good_type_id"].(float64))
  1514. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1515. utils.ErrorLog("count")
  1516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1517. return
  1518. }
  1519. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1520. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1521. utils.ErrorLog("price")
  1522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1523. return
  1524. }
  1525. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1526. total := float64(count) * price
  1527. remark := items["remark"].(string)
  1528. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1529. utils.ErrorLog("id")
  1530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1531. return
  1532. }
  1533. id := int64(items["id"].(float64))
  1534. manufacturer := int64(items["manufacturer"].(float64))
  1535. dealer := int64(items["dealer"].(float64))
  1536. number := items["number"].(string)
  1537. license_number := items["license_number"].(string)
  1538. timeLayout := "2006-01-02"
  1539. loc, _ := time.LoadLocation("Local")
  1540. expiry_date := items["expiry_date"].(string)
  1541. var expiryDate int64
  1542. if len(expiry_date) > 0 {
  1543. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1544. if err != nil {
  1545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1546. return
  1547. }
  1548. expiryDate = theTime.Unix()
  1549. }
  1550. product_date := items["product_date"].(string)
  1551. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1552. admin_user_id := int64(items["admin_user_id"].(float64))
  1553. var productDate int64
  1554. if len(product_date) > 0 {
  1555. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
  1556. if err != nil {
  1557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1558. return
  1559. }
  1560. productDate = theTime.Unix()
  1561. }
  1562. if id == 0 {
  1563. warehouseOutInfo := &models.WarehouseOutInfo{
  1564. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1565. WarehouseOutId: warehouseOut.ID,
  1566. GoodId: good_id,
  1567. GoodTypeId: good_type_id,
  1568. Count: count,
  1569. Price: price,
  1570. TotalPrice: total,
  1571. Status: 1,
  1572. Ctime: ctime,
  1573. Remark: remark,
  1574. OrgId: adminUserInfo.CurrentOrgId,
  1575. Type: types,
  1576. IsSys: 0,
  1577. SysRecordTime: 0,
  1578. Number: number,
  1579. ExpiryDate: expiryDate,
  1580. ProductDate: productDate,
  1581. Dealer: dealer,
  1582. Manufacturer: manufacturer,
  1583. LicenseNumber: license_number,
  1584. ConsumableType: 1,
  1585. WarehouseInfotId: warehouse_info_id,
  1586. StorehouseId: storehouse_id,
  1587. AdminUserId: admin_user_id,
  1588. }
  1589. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1590. } else {
  1591. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1592. utils.ErrorLog("is_sys")
  1593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1594. return
  1595. }
  1596. is_sys := int64(items["is_sys"].(float64))
  1597. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1598. utils.ErrorLog("sys_record_time")
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1600. return
  1601. }
  1602. sys_record_time := int64(items["sys_record_time"].(float64))
  1603. warehouseOutInfo := &models.WarehouseOutInfo{
  1604. ID: id,
  1605. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1606. WarehouseOutId: warehouseOut.ID,
  1607. GoodId: good_id,
  1608. GoodTypeId: good_type_id,
  1609. Count: count,
  1610. Price: price,
  1611. TotalPrice: total,
  1612. Status: 1,
  1613. Ctime: ctime,
  1614. Remark: remark,
  1615. OrgId: adminUserInfo.CurrentOrgId,
  1616. Mtime: time.Now().Unix(),
  1617. Type: types,
  1618. Manufacturer: manufacturer,
  1619. IsSys: is_sys,
  1620. SysRecordTime: sys_record_time,
  1621. Number: number,
  1622. ExpiryDate: expiryDate,
  1623. ProductDate: productDate,
  1624. Dealer: dealer,
  1625. LicenseNumber: license_number,
  1626. ConsumableType: 2,
  1627. WarehouseInfotId: warehouse_info_id,
  1628. StorehouseId: storehouse_id,
  1629. AdminUserId: admin_user_id,
  1630. }
  1631. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1632. }
  1633. }
  1634. }
  1635. }
  1636. var errs error
  1637. //新增出库
  1638. if len(warehousingOutInfo) > 0 {
  1639. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1640. if parseDateErr != nil {
  1641. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  1642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1643. return
  1644. }
  1645. creater := adminUserInfo.AdminUser.Id
  1646. for _, item := range warehousingOutInfo {
  1647. // 查询该耗材是否有库存
  1648. warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId, storehouse_id)
  1649. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseId, item.OrgId)
  1650. // 如果出库数量大于该批次剩余库存数量
  1651. if item.Count > warehouseOne.StockCount {
  1652. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1653. c.ServeSuccessJSON(map[string]interface{}{
  1654. "msg": "7",
  1655. "good_name": goodObj.GoodName,
  1656. "specification_name": goodObj.SpecificationName,
  1657. "storehouse_name": storehouse.StorehouseName,
  1658. })
  1659. return
  1660. } else {
  1661. warehouseOut, _ := service.GetWarehouseById(id)
  1662. //出库逻辑
  1663. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
  1664. if parseDateErr != nil {
  1665. utils.ErrorLog(parseDateErr.Error())
  1666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1667. return
  1668. }
  1669. }
  1670. }
  1671. }
  1672. if len(upDateWarehouseOutInfos) > 0 {
  1673. for _, item := range upDateWarehouseOutInfos {
  1674. //1.查询该耗材该批次的最后一次出库记录
  1675. lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, item.OrgId)
  1676. //如果出库数量大于 最后一次批次的数量(那么要进行出库)
  1677. if item.Count > lastGood.Count {
  1678. //查询该耗材是否还有库存
  1679. warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId, item.StorehouseId)
  1680. //无库存
  1681. if warehouseinfo.StockCount <= 0 {
  1682. c.ServeSuccessJSON(map[string]interface{}{
  1683. "msg": "5",
  1684. })
  1685. return
  1686. }
  1687. //有库存,进行出库,调用出库接口
  1688. if warehouseinfo.StockCount > 0 {
  1689. var total int64
  1690. var stock_cout int64
  1691. var total_count int64
  1692. //计算和最后一次出库数据的差
  1693. total = item.Count - lastGood.Count
  1694. if total > warehouseinfo.StockCount {
  1695. c.ServeSuccessJSON(map[string]interface{}{
  1696. "msg": "6",
  1697. })
  1698. return
  1699. }
  1700. //获取该耗材该批次的剩余库存量
  1701. info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1702. //判断该批次的剩余库存 和出库的库存进行比较
  1703. //如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
  1704. if total > info.StockCount {
  1705. //计算出库和该批次相差的库存
  1706. total_count = item.Count - info.StockCount
  1707. //清空本批次次库存
  1708. service.DeleteWarehouseInfo(item.WarehouseInfotId)
  1709. //调用出库逻辑
  1710. parseDateErr := service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
  1711. if parseDateErr != nil {
  1712. utils.ErrorLog(errs.Error())
  1713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1714. return
  1715. }
  1716. }
  1717. //如果与上次比的库存小于或等于于该批次的剩余库存,那么需要该批次出库
  1718. if total <= info.StockCount {
  1719. stock_cout = lastGood.Count + total
  1720. fmt.Println(stock_cout)
  1721. //扣减库存
  1722. warehouse := models.WarehousingInfo{
  1723. StockCount: info.StockCount - total,
  1724. }
  1725. errs := service.UpdateWarehousingInfo(warehouse, info.ID)
  1726. warehouseOutInfo := &models.WarehouseOutInfo{
  1727. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1728. WarehouseOutId: id,
  1729. WarehouseInfotId: item.WarehouseInfotId,
  1730. Status: 1,
  1731. Ctime: time.Now().Unix(),
  1732. Remark: item.Remark,
  1733. OrgId: item.OrgId,
  1734. Type: 1,
  1735. Manufacturer: item.Manufacturer,
  1736. Dealer: item.Dealer,
  1737. IsSys: 0,
  1738. SysRecordTime: item.SysRecordTime,
  1739. GoodTypeId: item.GoodTypeId,
  1740. GoodId: item.GoodId,
  1741. ExpiryDate: item.ExpiryDate,
  1742. ProductDate: item.ProductDate,
  1743. Number: item.Number,
  1744. Price: item.Price,
  1745. LicenseNumber: item.LicenseNumber,
  1746. Count: item.Count,
  1747. ConsumableType: 2,
  1748. StorehouseId: item.StorehouseId,
  1749. AdminUserId: item.AdminUserId,
  1750. }
  1751. //查询是否存在
  1752. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1753. if errcode == gorm.ErrRecordNotFound {
  1754. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1755. if errOne != nil {
  1756. utils.ErrorLog(errs.Error())
  1757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1758. return
  1759. }
  1760. } else if errcode == nil {
  1761. service.UpDateWarehouseOutInfo(item)
  1762. //更新流水
  1763. flow := models.VmStockFlow{
  1764. Number: item.Number,
  1765. LicenseNumber: item.LicenseNumber,
  1766. Count: item.Count,
  1767. Manufacturer: item.Manufacturer,
  1768. Dealer: item.Dealer,
  1769. ProductDate: item.ProductDate,
  1770. ExpireDate: item.ExpiryDate,
  1771. Price: item.Price,
  1772. StorehouseId: item.StorehouseId,
  1773. AdminUserId: item.AdminUserId,
  1774. }
  1775. service.UpdateStockFlowByDetailId(flow, item.ID)
  1776. goodInfo := models.GoodInfo{
  1777. Manufacturer: item.Manufacturer,
  1778. Dealer: item.Dealer,
  1779. }
  1780. service.UpdatedGoodInfo(goodInfo, item.GoodId)
  1781. }
  1782. }
  1783. }
  1784. }
  1785. var last_count int64
  1786. var all_total int64
  1787. var stock_total int64
  1788. //如果退库数量小于最后一次批次的数量(要么要进行退库)
  1789. if item.Count < lastGood.Count {
  1790. //退库数量和最后一次出库数据进行计算
  1791. last_count = lastGood.Count - item.Count
  1792. //获取该耗材该批次的剩余库存量
  1793. infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1794. //退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
  1795. all_total = last_count + infoInfo.StockCount
  1796. //如果库存大于总数量,则退回到这个批次
  1797. if infoInfo.WarehousingCount > all_total {
  1798. stock_total = last_count + infoInfo.StockCount
  1799. //退回该批次,计算数量
  1800. warehousingInfoOne := models.WarehousingInfo{
  1801. StockCount: stock_total,
  1802. ID: item.WarehouseInfotId,
  1803. OrgId: item.OrgId,
  1804. StorehouseId: item.StorehouseId,
  1805. }
  1806. parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
  1807. fmt.Println("parseDateErr", parseDateErr)
  1808. //插入一条新纪录
  1809. warehouseOutInfoThree := &models.WarehouseOutInfo{
  1810. WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  1811. WarehouseOutId: id,
  1812. WarehouseInfotId: item.WarehouseInfotId,
  1813. Status: 1,
  1814. Ctime: time.Now().Unix(),
  1815. Remark: item.Remark,
  1816. OrgId: item.OrgId,
  1817. Type: 1,
  1818. Manufacturer: item.Manufacturer,
  1819. Dealer: item.Dealer,
  1820. IsSys: 0,
  1821. GoodTypeId: item.GoodTypeId,
  1822. GoodId: item.GoodId,
  1823. ExpiryDate: item.ExpiryDate,
  1824. ProductDate: item.ProductDate,
  1825. Number: item.Number,
  1826. Price: item.Price,
  1827. LicenseNumber: item.LicenseNumber,
  1828. ConsumableType: 2,
  1829. Count: item.Count,
  1830. StorehouseId: item.StorehouseId,
  1831. AdminUserId: item.AdminUserId,
  1832. }
  1833. //查询是否存在
  1834. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1835. if errcode == gorm.ErrRecordNotFound {
  1836. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
  1837. if errOne != nil {
  1838. utils.ErrorLog(errs.Error())
  1839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1840. return
  1841. }
  1842. } else if errcode == nil {
  1843. service.UpDateWarehouseOutInfo(item)
  1844. flow := models.VmStockFlow{
  1845. Number: item.Number,
  1846. LicenseNumber: item.LicenseNumber,
  1847. Count: item.Count,
  1848. Manufacturer: item.Manufacturer,
  1849. Dealer: item.Dealer,
  1850. ProductDate: item.ProductDate,
  1851. ExpireDate: item.ExpiryDate,
  1852. Price: item.Price,
  1853. StorehouseId: item.StorehouseId,
  1854. AdminUserId: item.AdminUserId,
  1855. }
  1856. service.UpdateStockFlowByDetailId(flow, item.ID)
  1857. goodInfo := models.GoodInfo{
  1858. Manufacturer: item.Manufacturer,
  1859. Dealer: item.Dealer,
  1860. }
  1861. service.UpdatedGoodInfo(goodInfo, item.GoodId)
  1862. }
  1863. }
  1864. //如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
  1865. if infoInfo.WarehousingCount < all_total {
  1866. c.ServeSuccessJSON(map[string]interface{}{
  1867. "msg": "6",
  1868. })
  1869. return
  1870. }
  1871. }
  1872. if item.Count == lastGood.Count {
  1873. errs = service.UpDateWarehouseOutInfo(item)
  1874. flow := models.VmStockFlow{
  1875. Number: item.Number,
  1876. LicenseNumber: item.LicenseNumber,
  1877. Count: item.Count,
  1878. Manufacturer: item.Manufacturer,
  1879. Dealer: item.Dealer,
  1880. ProductDate: item.ProductDate,
  1881. ExpireDate: item.ExpiryDate,
  1882. Price: item.Price,
  1883. StorehouseId: item.StorehouseId,
  1884. AdminUserId: item.AdminUserId,
  1885. }
  1886. service.UpdateStockFlowByDetailId(flow, item.ID)
  1887. goodInfo := models.GoodInfo{
  1888. Manufacturer: item.Manufacturer,
  1889. Dealer: item.Dealer,
  1890. }
  1891. service.UpdatedGoodInfo(goodInfo, item.GoodId)
  1892. }
  1893. //查询该机构默认仓库
  1894. storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  1895. //查询剩余库存
  1896. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
  1897. var sum_count int64
  1898. var sum_in_count int64
  1899. for _, item := range goodList {
  1900. sum_count += item.StockCount
  1901. sum_in_count += item.WarehousingCount
  1902. }
  1903. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
  1904. }
  1905. }
  1906. if errs != nil {
  1907. utils.ErrorLog(errs.Error())
  1908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1909. return
  1910. }
  1911. c.ServeSuccessJSON(map[string]interface{}{
  1912. "msg": "1",
  1913. })
  1914. }
  1915. func (c *StockManagerApiController) CreateCancelStock() {
  1916. cancel_stock_time := c.GetString("time")
  1917. types, _ := c.GetInt64("type", 0)
  1918. storehouse_id, _ := c.GetInt64("storehouse_id")
  1919. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1920. if parseDateErr != nil {
  1921. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1923. return
  1924. }
  1925. adminUserInfo := c.GetAdminUserInfo()
  1926. operation_time := time.Now().Unix()
  1927. creater := adminUserInfo.AdminUser.Id
  1928. ctime := time.Now().Unix()
  1929. timeStr := time.Now().Format("2006-01-02")
  1930. timeArr := strings.Split(timeStr, "-")
  1931. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1932. total = total + 1
  1933. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1934. cancelStock := models.CancelStock{
  1935. OrderNumber: orderNumber,
  1936. OperaTime: operation_time,
  1937. OrgId: adminUserInfo.CurrentOrgId,
  1938. Creater: creater,
  1939. Ctime: ctime,
  1940. Status: 1,
  1941. ReturnTime: cancelStockDate.Unix(),
  1942. Type: types,
  1943. StorehouseId: storehouse_id,
  1944. }
  1945. dataBody := make(map[string]interface{}, 0)
  1946. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1947. if err != nil {
  1948. utils.ErrorLog(err.Error())
  1949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1950. return
  1951. }
  1952. var cancelStockInfos []*models.CancelStockInfo
  1953. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1954. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1955. if len(thisStockIn) > 0 {
  1956. for _, item := range thisStockIn {
  1957. items := item.(map[string]interface{})
  1958. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1959. utils.ErrorLog("good_id")
  1960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1961. return
  1962. }
  1963. good_id := int64(items["good_id"].(float64))
  1964. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1965. utils.ErrorLog("good_type_id")
  1966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1967. return
  1968. }
  1969. good_type_id := int64(items["good_type_id"].(float64))
  1970. return_count, _ := items["return_count"].(string)
  1971. if len(return_count) == 0 {
  1972. utils.ErrorLog("len(return_count) == 0")
  1973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1974. return
  1975. }
  1976. count, _ := strconv.ParseInt(return_count, 10, 64)
  1977. number := items["number"].(string)
  1978. register_account := items["register_account"].(string)
  1979. manufacturer, _ := items["manufacturer"].(string)
  1980. dealer, _ := items["dealer"].(string)
  1981. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1982. var expiryDates int64
  1983. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1984. expiryDates = 0
  1985. } else {
  1986. if len(items["expiry_date"].(string)) == 0 {
  1987. expiryDates = 0
  1988. } else {
  1989. expiryDate, _ := items["expiry_date"].(string)
  1990. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1991. expiryDates = expiry_date.Unix()
  1992. }
  1993. }
  1994. var productDates int64
  1995. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1996. productDates = 0
  1997. } else {
  1998. if len(items["product_date"].(string)) == 0 {
  1999. productDates = 0
  2000. } else {
  2001. productDate, _ := items["product_date"].(string)
  2002. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  2003. productDates = product_date.Unix()
  2004. }
  2005. }
  2006. remark := items["remark"].(string)
  2007. retail_prices := items["price"].(string)
  2008. price, _ := strconv.ParseFloat(retail_prices, 64)
  2009. cancelStockInfo := &models.CancelStockInfo{
  2010. OrderNumber: cancelStock.OrderNumber,
  2011. CancelStockId: cancelStock.ID,
  2012. GoodId: good_id,
  2013. GoodTypeId: good_type_id,
  2014. Count: count,
  2015. Status: 1,
  2016. Ctime: ctime,
  2017. OrgId: adminUserInfo.CurrentOrgId,
  2018. Type: types,
  2019. Manufacturer: manufacturer,
  2020. Dealer: dealer,
  2021. Number: number,
  2022. ProductDate: productDates,
  2023. ExpiryDate: expiryDates,
  2024. RegisterAccount: register_account,
  2025. Remark: remark,
  2026. Price: price,
  2027. WarehouseInfoId: warehouse_info_id,
  2028. StorehouseId: storehouse_id,
  2029. }
  2030. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  2031. }
  2032. }
  2033. }
  2034. for _, item := range cancelStockInfos {
  2035. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseId, item.OrgId)
  2036. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  2037. info, _ := service.GetWarehoureOrderStockOutFlow(item.GoodId, item.OrgId, item.WarehouseInfoId, storehouse_id)
  2038. if item.Count > info.Count {
  2039. service.UpdateCancelInfo(item.CancelStockId)
  2040. c.ServeSuccessJSON(map[string]interface{}{
  2041. "msg": "2",
  2042. "good_name": goodObj.GoodName,
  2043. "specification_name": goodObj.SpecificationName,
  2044. "storehouse_name": storehouse.StorehouseName,
  2045. })
  2046. return
  2047. }
  2048. //查询该批次入库的值
  2049. infolist, _ := service.GetWarehouseInfoByIdSeven(item.WarehouseInfoId)
  2050. if item.Count > infolist.WarehousingCount {
  2051. c.ServeSuccessJSON(map[string]interface{}{
  2052. "msg": "4",
  2053. "good_name": goodObj.GoodName,
  2054. "specification_name": goodObj.SpecificationName,
  2055. "storehouse_name": storehouse.StorehouseName,
  2056. })
  2057. return
  2058. }
  2059. if item.Count <= infolist.WarehousingCount {
  2060. _, msgerrkonde := service.GetCancelStockDetailByOrderNumber(orderNumber, adminUserInfo.CurrentOrgId)
  2061. if msgerrkonde == gorm.ErrRecordNotFound {
  2062. service.AddSigleCancelStock(&cancelStock)
  2063. }
  2064. listcancel, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
  2065. item.CancelStockId = listcancel.ID
  2066. errs := service.CreateCancelStockInfoOne(item)
  2067. list, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  2068. var manufacturer_id int64
  2069. for _, items := range list {
  2070. if item.Manufacturer == items.ManufacturerName {
  2071. manufacturer_id = items.ID
  2072. }
  2073. }
  2074. flow := models.VmStockFlow{
  2075. WarehousingId: 0,
  2076. GoodId: item.GoodId,
  2077. Number: item.Number,
  2078. LicenseNumber: "",
  2079. Count: item.Count,
  2080. UserOrgId: adminUserInfo.CurrentOrgId,
  2081. PatientId: 0,
  2082. SystemTime: time.Now().Unix(),
  2083. ConsumableType: 4,
  2084. IsSys: 0,
  2085. WarehousingOrder: "",
  2086. WarehouseOutId: 0,
  2087. WarehouseOutOrderNumber: "",
  2088. IsEdit: 0,
  2089. CancelStockId: cancelStock.ID,
  2090. CancelOrderNumber: cancelStock.OrderNumber,
  2091. Manufacturer: manufacturer_id,
  2092. Dealer: 0,
  2093. Creator: adminUserInfo.AdminUser.Id,
  2094. UpdateCreator: 0,
  2095. Status: 1,
  2096. Ctime: time.Now().Unix(),
  2097. Mtime: 0,
  2098. Price: item.Price,
  2099. WarehousingDetailId: 0,
  2100. WarehouseOutDetailId: 0,
  2101. CancelOutDetailId: 0,
  2102. ProductDate: item.ProductDate,
  2103. ExpireDate: item.ExpiryDate,
  2104. StorehouseId: item.StorehouseId,
  2105. }
  2106. cancelStockInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  2107. flow.CancelStockId = cancelStockInfo.CancelStockId
  2108. flow.CancelOutDetailId = cancelStockInfo.ID
  2109. service.CreateStockFlowOne(flow)
  2110. if errs != nil {
  2111. utils.ErrorLog(errs.Error())
  2112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2113. return
  2114. }
  2115. //查询该批次的剩余库存
  2116. wareouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2117. if (wareouseinfo.StockCount + item.Count) > wareouseinfo.WarehousingCount {
  2118. c.ServeSuccessJSON(map[string]interface{}{
  2119. "msg": "5",
  2120. "good_name": goodObj.GoodName,
  2121. "specification_name": goodObj.SpecificationName,
  2122. "storehouse_name": storehouse.StorehouseName,
  2123. })
  2124. return
  2125. }
  2126. //更改入库数量
  2127. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  2128. storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2129. //查询剩余库存
  2130. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
  2131. var sum_count int64
  2132. var sum_in_count int64
  2133. for _, it := range goodList {
  2134. sum_count += it.StockCount
  2135. sum_in_count += it.WarehousingCount
  2136. }
  2137. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, adminUserInfo.CurrentOrgId)
  2138. if err != nil {
  2139. utils.ErrorLog(err.Error())
  2140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2141. return
  2142. }
  2143. }
  2144. }
  2145. c.ServeSuccessJSON(map[string]interface{}{
  2146. "msg": "3",
  2147. })
  2148. return
  2149. }
  2150. func (c *StockManagerApiController) GetCancelStockInfoList() {
  2151. id, _ := c.GetInt64("id", 0)
  2152. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  2153. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  2154. manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
  2155. dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
  2156. c.ServeSuccessJSON(map[string]interface{}{
  2157. "list": cancelStockInfoList,
  2158. "info": info,
  2159. "manufacturerList": manufacturerList,
  2160. "dealerList": dealerList,
  2161. })
  2162. }
  2163. func (c *StockManagerApiController) GetCancelStockList() {
  2164. page, _ := c.GetInt64("page", -1)
  2165. limit, _ := c.GetInt64("limit", -1)
  2166. start_time := c.GetString("start_time")
  2167. end_time := c.GetString("end_time")
  2168. types, _ := c.GetInt64("type", 0)
  2169. keywords := c.GetString("keywords")
  2170. storehouse_id, _ := c.GetInt64("storehouse_id")
  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. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2178. return
  2179. }
  2180. startTime = theTime.Unix()
  2181. }
  2182. var endTime int64
  2183. if len(end_time) > 0 {
  2184. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2185. if err != nil {
  2186. utils.ErrorLog(err.Error())
  2187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2188. return
  2189. }
  2190. endTime = theTime.Unix()
  2191. }
  2192. adminUserInfo := c.GetAdminUserInfo()
  2193. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, storehouse_id)
  2194. houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  2195. if err == nil {
  2196. c.ServeSuccessJSON(map[string]interface{}{
  2197. "list": returnList,
  2198. "total": total,
  2199. "houseList": houseList,
  2200. })
  2201. } else {
  2202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2203. }
  2204. }
  2205. func (this *StockManagerApiController) DeleteCancelStock() {
  2206. ids := this.GetString("ids")
  2207. if len(ids) == 0 {
  2208. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2209. return
  2210. }
  2211. idArray := strings.Split(ids, ",")
  2212. //获取
  2213. list, _ := service.GetCancelWarehosueInfo(idArray)
  2214. for _, item := range list {
  2215. info, _ := service.GetCancelStockById(item.WarehouseInfoId)
  2216. warehousingInfo := models.WarehousingInfo{
  2217. StockCount: info.Count,
  2218. }
  2219. //扣减库存
  2220. service.ModefyWarehouseInfoNight(warehousingInfo, info.WarehouseInfoId)
  2221. //查询该机构默认仓库
  2222. storeConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  2223. //查询剩余库存
  2224. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, item.OrgId)
  2225. var sum_count int64
  2226. var sum_in_count int64
  2227. for _, item := range goodList {
  2228. sum_count += item.StockCount
  2229. sum_in_count += item.WarehousingCount
  2230. }
  2231. service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
  2232. //删除流水
  2233. service.UpdatedStockFlowByCancelId(info.ID, info.GoodId)
  2234. }
  2235. //获取
  2236. err := service.DeleteCancelStock(idArray)
  2237. if err != nil {
  2238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2239. } else {
  2240. this.ServeSuccessJSON(map[string]interface{}{
  2241. "msg": "删除成功",
  2242. })
  2243. }
  2244. }
  2245. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  2246. id, _ := this.GetInt64("id", 0)
  2247. fmt.Println(id)
  2248. if id == 0 {
  2249. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2250. return
  2251. }
  2252. //改变库存
  2253. info, _ := service.GetCancelStockById(id)
  2254. warehousingInfo := models.WarehousingInfo{
  2255. StockCount: info.Count,
  2256. }
  2257. //扣减库存
  2258. service.ModefyWarehouseInfoNight(warehousingInfo, info.WarehouseInfoId)
  2259. //查询该机构默认仓库
  2260. storeConfig, _ := service.GetAllStoreHouseConfig(info.OrgId)
  2261. //查询剩余库存
  2262. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, info.OrgId)
  2263. var sum_count int64
  2264. var sum_in_count int64
  2265. for _, item := range goodList {
  2266. sum_count += item.StockCount
  2267. sum_in_count += item.WarehousingCount
  2268. }
  2269. service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
  2270. //删除详情
  2271. err := service.UpDateCancleStockStatus(id)
  2272. //删除流水
  2273. err = service.UpdatedStockFlowByCancelId(id, info.GoodId)
  2274. if err != nil {
  2275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2276. } else {
  2277. this.ServeSuccessJSON(map[string]interface{}{
  2278. "msg": "删除成功",
  2279. })
  2280. }
  2281. }
  2282. func (c *StockManagerApiController) EditCancelStock() {
  2283. cancel_time := c.GetString("cancel_time")
  2284. id, _ := c.GetInt64("id", 0)
  2285. storehouse_id, _ := c.GetInt64("storehouse_id")
  2286. if id == 0 {
  2287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2288. return
  2289. }
  2290. ctime := time.Now().Unix()
  2291. mtime := time.Now().Unix()
  2292. adminUserInfo := c.GetAdminUserInfo()
  2293. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  2294. if parseDateErr != nil {
  2295. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  2296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2297. return
  2298. }
  2299. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  2300. tempCancelStock := models.CancelStock{
  2301. ID: cancelStock.ID,
  2302. Mtime: mtime,
  2303. ReturnTime: cancelDate.Unix(),
  2304. StorehouseId: storehouse_id,
  2305. }
  2306. service.EditCancelStock(tempCancelStock)
  2307. dataBody := make(map[string]interface{}, 0)
  2308. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2309. if err != nil {
  2310. utils.ErrorLog(err.Error())
  2311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2312. return
  2313. }
  2314. var cancelStockInfos []*models.CancelStockInfo
  2315. var upDateCancelStockInfos []*models.CancelStockInfo
  2316. var stockFlow []*models.VmStockFlow
  2317. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  2318. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  2319. if len(thisCancelStock) > 0 {
  2320. for _, item := range thisCancelStock {
  2321. items := item.(map[string]interface{})
  2322. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2323. utils.ErrorLog("good_id")
  2324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2325. return
  2326. }
  2327. good_id := int64(items["good_id"].(float64))
  2328. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2329. utils.ErrorLog("good_type_id")
  2330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2331. return
  2332. }
  2333. good_type_id := int64(items["good_type_id"].(float64))
  2334. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2335. utils.ErrorLog("count")
  2336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2337. return
  2338. }
  2339. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2340. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2341. utils.ErrorLog("id")
  2342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2343. return
  2344. }
  2345. id := int64(items["id"].(float64))
  2346. number := items["number"].(string)
  2347. register_account := items["register_account"].(string)
  2348. manufacturer, _ := items["manufacturer"].(string)
  2349. dealer, _ := items["dealer"].(string)
  2350. remark := items["remark"].(string)
  2351. var productDates int64
  2352. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  2353. productDates = 0
  2354. } else {
  2355. if len(items["product_date"].(string)) == 0 {
  2356. productDates = 0
  2357. } else {
  2358. productDate, _ := items["product_date"].(string)
  2359. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  2360. productDates = product_date.Unix()
  2361. }
  2362. }
  2363. var expiryDates int64
  2364. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  2365. expiryDates = 0
  2366. } else {
  2367. if len(items["expiry_date"].(string)) == 0 {
  2368. expiryDates = 0
  2369. } else {
  2370. expiryDate, _ := items["expiry_date"].(string)
  2371. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  2372. expiryDates = expiry_date.Unix()
  2373. }
  2374. }
  2375. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2376. utils.ErrorLog("price")
  2377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2378. return
  2379. }
  2380. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2381. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  2382. if id == 0 {
  2383. cancelStockInfo := &models.CancelStockInfo{
  2384. GoodId: good_id,
  2385. GoodTypeId: good_type_id,
  2386. Count: count,
  2387. Status: 1,
  2388. Ctime: ctime,
  2389. OrgId: adminUserInfo.CurrentOrgId,
  2390. OrderNumber: cancelStock.OrderNumber,
  2391. CancelStockId: cancelStock.ID,
  2392. Mtime: time.Now().Unix(),
  2393. Number: number,
  2394. RegisterAccount: register_account,
  2395. Manufacturer: manufacturer,
  2396. Dealer: dealer,
  2397. ProductDate: productDates,
  2398. ExpiryDate: expiryDates,
  2399. Remark: remark,
  2400. Price: price,
  2401. WarehouseInfoId: warehouse_info_id,
  2402. StorehouseId: storehouse_id,
  2403. }
  2404. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  2405. flow := &models.VmStockFlow{
  2406. WarehousingId: 0,
  2407. GoodId: good_id,
  2408. Number: number,
  2409. LicenseNumber: "",
  2410. Count: count,
  2411. UserOrgId: adminUserInfo.CurrentOrgId,
  2412. PatientId: 0,
  2413. SystemTime: time.Now().Unix(),
  2414. ConsumableType: 4,
  2415. IsSys: 0,
  2416. WarehousingOrder: "",
  2417. WarehouseOutId: 0,
  2418. WarehouseOutOrderNumber: "",
  2419. IsEdit: 2,
  2420. CancelStockId: cancelStock.ID,
  2421. CancelOrderNumber: cancelStock.OrderNumber,
  2422. Manufacturer: 0,
  2423. Dealer: 0,
  2424. Creator: adminUserInfo.AdminUser.Id,
  2425. UpdateCreator: 0,
  2426. Status: 1,
  2427. Ctime: time.Now().Unix(),
  2428. Mtime: 0,
  2429. Price: price,
  2430. WarehousingDetailId: warehouse_info_id,
  2431. WarehouseOutDetailId: 0,
  2432. CancelOutDetailId: 0,
  2433. ProductDate: productDates,
  2434. ExpireDate: expiryDates,
  2435. StorehouseId: storehouse_id,
  2436. }
  2437. stockFlow = append(stockFlow, flow)
  2438. } else {
  2439. cancelStockInfo := &models.CancelStockInfo{
  2440. ID: id,
  2441. GoodId: good_id,
  2442. GoodTypeId: good_type_id,
  2443. Count: count,
  2444. Status: 1,
  2445. Ctime: ctime,
  2446. OrgId: adminUserInfo.CurrentOrgId,
  2447. OrderNumber: cancelStock.OrderNumber,
  2448. CancelStockId: cancelStock.ID,
  2449. Mtime: time.Now().Unix(),
  2450. Number: number,
  2451. RegisterAccount: register_account,
  2452. Manufacturer: manufacturer,
  2453. Dealer: dealer,
  2454. ProductDate: productDates,
  2455. ExpiryDate: expiryDates,
  2456. Remark: remark,
  2457. Price: price,
  2458. WarehouseInfoId: warehouse_info_id,
  2459. StorehouseId: storehouse_id,
  2460. }
  2461. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  2462. list, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  2463. var manufacuture_id int64
  2464. for _, it := range list {
  2465. if it.ManufacturerName == manufacturer {
  2466. manufacuture_id = it.ID
  2467. }
  2468. }
  2469. flow := &models.VmStockFlow{
  2470. WarehousingId: 0,
  2471. GoodId: good_id,
  2472. Number: number,
  2473. LicenseNumber: "",
  2474. Count: count,
  2475. UserOrgId: adminUserInfo.CurrentOrgId,
  2476. PatientId: 0,
  2477. SystemTime: time.Now().Unix(),
  2478. ConsumableType: 4,
  2479. IsSys: 0,
  2480. WarehousingOrder: "",
  2481. WarehouseOutId: 0,
  2482. WarehouseOutOrderNumber: "",
  2483. IsEdit: 2,
  2484. CancelStockId: cancelStock.ID,
  2485. CancelOrderNumber: cancelStock.OrderNumber,
  2486. Manufacturer: manufacuture_id,
  2487. Dealer: 0,
  2488. Creator: adminUserInfo.AdminUser.Id,
  2489. UpdateCreator: 0,
  2490. Status: 1,
  2491. Ctime: time.Now().Unix(),
  2492. Mtime: 0,
  2493. Price: price,
  2494. WarehousingDetailId: warehouse_info_id,
  2495. WarehouseOutDetailId: 0,
  2496. CancelOutDetailId: 0,
  2497. ProductDate: productDates,
  2498. ExpireDate: expiryDates,
  2499. StorehouseId: storehouse_id,
  2500. }
  2501. stockFlow = append(stockFlow, flow)
  2502. }
  2503. }
  2504. }
  2505. }
  2506. var errs error
  2507. //判断是否更改了仓库
  2508. if storehouse_id == cancelStock.ID {
  2509. if len(cancelStockInfos) > 0 {
  2510. for _, item := range cancelStockInfos {
  2511. //统计该耗材的出库数量
  2512. info, _ := service.GetWarehoureOrderStockOutFlow(item.GoodId, item.OrgId, item.WarehouseInfoId, storehouse_id)
  2513. storeObj, _ := service.FindStoreHouseByStorehouseId(storehouse_id, item.OrgId)
  2514. if item.Count > info.Count {
  2515. c.ServeSuccessJSON(map[string]interface{}{
  2516. "msg": "2",
  2517. "storehouse_name": storeObj.StorehouseName,
  2518. })
  2519. return
  2520. }
  2521. //查询该批次入库的值
  2522. infolist, _ := service.GetWarehouseInfoByIdSix(item.WarehouseInfoId, storehouse_id)
  2523. if item.Count > infolist.WarehousingCount {
  2524. c.ServeSuccessJSON(map[string]interface{}{
  2525. "msg": "4",
  2526. "storehouse_name": storeObj.StorehouseName,
  2527. })
  2528. return
  2529. }
  2530. if item.Count <= infolist.WarehousingCount {
  2531. errs := service.CreateCancelStockInfo(cancelStockInfos)
  2532. if errs != nil {
  2533. utils.ErrorLog(errs.Error())
  2534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2535. return
  2536. }
  2537. //更改入库数量
  2538. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  2539. //查询该机构默认仓库
  2540. storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2541. //查询剩余库存
  2542. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
  2543. var sum_count int64
  2544. var sum_in_count int64
  2545. for _, it := range goodList {
  2546. sum_count += it.StockCount
  2547. sum_in_count += it.WarehousingCount
  2548. }
  2549. service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, adminUserInfo.CurrentOrgId)
  2550. break
  2551. }
  2552. }
  2553. if len(stockFlow) > 0 {
  2554. for _, itemcancel := range stockFlow {
  2555. //查询是否存在
  2556. stockInfo, errcode := service.IsExsitStockFlow(itemcancel.GoodId, itemcancel.CancelOrderNumber)
  2557. if errcode == gorm.ErrRecordNotFound {
  2558. service.CreateStockFlowSix(itemcancel)
  2559. } else {
  2560. flow := models.VmStockFlow{
  2561. Count: itemcancel.Count,
  2562. Manufacturer: itemcancel.Manufacturer,
  2563. Dealer: itemcancel.Dealer,
  2564. Price: itemcancel.Price,
  2565. ProductDate: itemcancel.ProductDate,
  2566. ExpireDate: itemcancel.ExpireDate,
  2567. StorehouseId: itemcancel.StorehouseId,
  2568. }
  2569. service.UpdateStockFlowThree(stockInfo.ID, flow)
  2570. }
  2571. }
  2572. }
  2573. }
  2574. if len(upDateCancelStockInfos) > 0 {
  2575. for _, item := range upDateCancelStockInfos {
  2576. var all_total int64
  2577. //获取该批次最后一套退库记录
  2578. info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
  2579. //查询该批次总的退库数量
  2580. list, _ := service.GetAllCancelInfoById(item.WarehouseInfoId, item.GoodId)
  2581. for _, it := range list {
  2582. all_total += it.Count
  2583. }
  2584. //比较退库库数量和最后一次退库库数据大小
  2585. //退库(加)
  2586. if item.Count > info.Count {
  2587. var total = item.Count - info.Count
  2588. errs = service.UpDateCancelStockInfo(item)
  2589. warehouseinfo, _ := service.GetWarehouseInfoByIdSix(item.WarehouseInfoId, storehouse_id)
  2590. storeObj, _ := service.FindStoreHouseByStorehouseId(storehouse_id, item.OrgId)
  2591. // 总退库数量大于入库数据
  2592. if all_total > warehouseinfo.StockCount {
  2593. c.ServeSuccessJSON(map[string]interface{}{
  2594. "msg": "5",
  2595. "storehouse_name": storeObj.StorehouseName,
  2596. })
  2597. return
  2598. }
  2599. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
  2600. if parseDateErr != nil {
  2601. utils.ErrorLog(errs.Error())
  2602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2603. break
  2604. }
  2605. }
  2606. //(减)
  2607. if item.Count < info.Count {
  2608. errs = service.UpDateCancelStockInfo(item)
  2609. var total_count = info.Count - item.Count
  2610. parseDateErr := service.UpdateWareInfoByIdSix(item.WarehouseInfoId, total_count)
  2611. if parseDateErr != nil {
  2612. utils.ErrorLog(errs.Error())
  2613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2614. return
  2615. }
  2616. }
  2617. if item.Count == info.Count {
  2618. errs = service.UpDateCancelStockInfo(item)
  2619. }
  2620. //查询该机构默认仓库
  2621. storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2622. //查询剩余库存
  2623. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
  2624. var sum_count int64
  2625. var sum_in_count int64
  2626. for _, it := range goodList {
  2627. sum_count += it.StockCount
  2628. sum_in_count += it.WarehousingCount
  2629. }
  2630. service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, adminUserInfo.CurrentOrgId)
  2631. }
  2632. }
  2633. if len(stockFlow) > 0 {
  2634. for _, itemcancel := range stockFlow {
  2635. //查询是否存在
  2636. stockInfo, errcode := service.IsExsitStockFlow(itemcancel.GoodId, itemcancel.CancelOrderNumber)
  2637. if errcode == gorm.ErrRecordNotFound {
  2638. } else {
  2639. flow := models.VmStockFlow{
  2640. Count: itemcancel.Count,
  2641. Manufacturer: itemcancel.Manufacturer,
  2642. Dealer: itemcancel.Dealer,
  2643. Price: itemcancel.Price,
  2644. LicenseNumber: itemcancel.LicenseNumber,
  2645. Number: itemcancel.Number,
  2646. ExpireDate: itemcancel.ExpireDate,
  2647. ProductDate: itemcancel.ProductDate,
  2648. StorehouseId: itemcancel.StorehouseId,
  2649. }
  2650. service.UpdateStockFlowThree(stockInfo.ID, flow)
  2651. }
  2652. }
  2653. }
  2654. }
  2655. if errs != nil {
  2656. utils.ErrorLog(errs.Error())
  2657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2658. return
  2659. }
  2660. c.ServeSuccessJSON(map[string]interface{}{
  2661. "msg": "3",
  2662. })
  2663. }
  2664. func (this *StockManagerApiController) GetCancelStockConfig() {
  2665. types, _ := this.GetInt64("type", 0)
  2666. adminUserInfo := this.GetAdminUserInfo()
  2667. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  2668. this.ServeSuccessJSON(map[string]interface{}{
  2669. "warehouseOutInfoList": warehouseOutInfoList,
  2670. })
  2671. }
  2672. func (c *StockManagerApiController) GetQueryInfo() {
  2673. page, _ := c.GetInt64("page", -1)
  2674. limit, _ := c.GetInt64("limit", -1)
  2675. keyword := c.GetString("keyword")
  2676. start_time := c.GetString("start_time")
  2677. end_time := c.GetString("end_time")
  2678. type_name, _ := c.GetInt64("type_name")
  2679. timeLayout := "2006-01-02"
  2680. loc, _ := time.LoadLocation("Local")
  2681. var startTime int64
  2682. if len(start_time) > 0 {
  2683. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2684. if err != nil {
  2685. fmt.Println(err)
  2686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2687. return
  2688. }
  2689. startTime = theTime.Unix()
  2690. }
  2691. var endTime int64
  2692. if len(end_time) > 0 {
  2693. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2694. if err != nil {
  2695. utils.ErrorLog(err.Error())
  2696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2697. return
  2698. }
  2699. endTime = theTime.Unix()
  2700. }
  2701. adminUserInfo := c.GetAdminUserInfo()
  2702. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  2703. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  2704. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
  2705. if err == nil {
  2706. c.ServeSuccessJSON(map[string]interface{}{
  2707. "list": list,
  2708. "total": total,
  2709. "info": info,
  2710. "infomationList": infomationList,
  2711. "orgid": adminUserInfo.CurrentOrgId,
  2712. })
  2713. } else {
  2714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2715. }
  2716. }
  2717. func (c *StockManagerApiController) SearchWarehouse() {
  2718. keywords := c.GetString("keywords")
  2719. adminUserInfo := c.GetAdminUserInfo()
  2720. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  2721. if err == nil {
  2722. c.ServeSuccessJSON(map[string]interface{}{
  2723. "list": warehouseList,
  2724. "total": total,
  2725. })
  2726. } else {
  2727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2728. }
  2729. }
  2730. func (c *StockManagerApiController) GetAllConfig() {
  2731. adminUserInfo := c.GetAdminUserInfo()
  2732. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  2733. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  2734. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  2735. goodInfo, _ := service.FindAllGoodInfoTwo(adminUserInfo.CurrentOrgId)
  2736. //获取所有仓库看列表
  2737. list, _ := service.GetAllStoreHouseListThree(adminUserInfo.CurrentOrgId)
  2738. //获取仓库配置列表
  2739. configList, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2740. appId := c.GetAdminUserInfo().CurrentAppId
  2741. doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
  2742. c.ServeSuccessJSON(map[string]interface{}{
  2743. "manufacturer": manufacturer,
  2744. "dealer": dealer,
  2745. "goodType": goodType,
  2746. "goodInfo": goodInfo,
  2747. "list": list,
  2748. "configlist": configList,
  2749. "doctorList": doctorList,
  2750. })
  2751. }
  2752. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  2753. types, _ := this.GetInt64("type", 0)
  2754. adminUserInfo := this.GetAdminUserInfo()
  2755. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  2756. this.ServeSuccessJSON(map[string]interface{}{
  2757. "warehouseInfoList": warehouseInfoList,
  2758. })
  2759. }
  2760. func (this *StockManagerApiController) GetDetailInfo() {
  2761. page, _ := this.GetInt64("page", 0)
  2762. limit, _ := this.GetInt64("limit", 0)
  2763. start_time := this.GetString("start_time")
  2764. end_time := this.GetString("end_time")
  2765. types, _ := this.GetInt64("type", 0)
  2766. keywords := this.GetString("keywords")
  2767. manufacturer, _ := this.GetInt64("manufacturer", 0)
  2768. order_type, _ := this.GetInt64("order_type", 0)
  2769. dealer, _ := this.GetInt64("dealer", 0)
  2770. storehouse_id, _ := this.GetInt64("storehouse_id")
  2771. timeLayout := "2006-01-02"
  2772. loc, _ := time.LoadLocation("Local")
  2773. var startTime int64
  2774. if len(start_time) > 0 {
  2775. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2776. if err != nil {
  2777. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2778. return
  2779. }
  2780. startTime = theTime.Unix()
  2781. }
  2782. var endTime int64
  2783. if len(end_time) > 0 {
  2784. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2785. if err != nil {
  2786. utils.ErrorLog(err.Error())
  2787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2788. return
  2789. }
  2790. endTime = theTime.Unix()
  2791. }
  2792. adminUserInfo := this.GetAdminUserInfo()
  2793. var list []*models.WarehousingInfo
  2794. var list1 []*models.WarehouseOutInfo
  2795. var list2 []*models.SalesReturnInfo
  2796. var list3 []*models.CancelStockInfo
  2797. var total int64
  2798. var err error
  2799. var total_price float64
  2800. houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  2801. if types == 1 {
  2802. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2803. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2804. if err == nil {
  2805. this.ServeSuccessJSON(map[string]interface{}{
  2806. "list": list,
  2807. "total": total,
  2808. "total_price": total_price,
  2809. "houseList": houseList,
  2810. })
  2811. } else {
  2812. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2813. }
  2814. } else if types == 2 {
  2815. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2816. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2817. if err == nil {
  2818. this.ServeSuccessJSON(map[string]interface{}{
  2819. "list": list1,
  2820. "total": total,
  2821. "total_price": total_price,
  2822. "houseList": houseList,
  2823. })
  2824. } else {
  2825. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2826. }
  2827. } else if types == 3 {
  2828. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2829. if err == nil {
  2830. this.ServeSuccessJSON(map[string]interface{}{
  2831. "list": list2,
  2832. "total": total,
  2833. })
  2834. } else {
  2835. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2836. }
  2837. } else if types == 4 {
  2838. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2839. listGroup, err := service.FindeCancelGroup(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2840. if err == nil {
  2841. this.ServeSuccessJSON(map[string]interface{}{
  2842. "list": list3,
  2843. "total": total,
  2844. "listgroup": listGroup,
  2845. "houseList": houseList,
  2846. })
  2847. } else {
  2848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2849. }
  2850. }
  2851. }
  2852. func (this *StockManagerApiController) GetUserDetailInfo() {
  2853. order_id, _ := this.GetInt64("id")
  2854. if order_id <= 0 {
  2855. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2856. return
  2857. }
  2858. adminUserInfo := this.GetAdminUserInfo()
  2859. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2860. if err == nil {
  2861. this.ServeSuccessJSON(map[string]interface{}{
  2862. "list": userDetails,
  2863. "total": total,
  2864. })
  2865. } else {
  2866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2867. return
  2868. }
  2869. }
  2870. func (this *StockManagerApiController) PostSearchStock() {
  2871. keyword := this.GetString("keyword")
  2872. adminUserInfo := this.GetAdminUserInfo()
  2873. orgId := adminUserInfo.CurrentOrgId
  2874. stock, err := service.PostSearchStock(keyword, orgId)
  2875. if err != nil {
  2876. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2877. }
  2878. this.ServeSuccessJSON(map[string]interface{}{
  2879. "stock": stock,
  2880. })
  2881. }
  2882. func (this *StockManagerApiController) GetOutStockTotalCount() {
  2883. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  2884. adminUserInfo := this.GetAdminUserInfo()
  2885. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  2886. if err != nil {
  2887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2888. }
  2889. this.ServeSuccessJSON(map[string]interface{}{
  2890. "stockCount": stockCount,
  2891. })
  2892. }
  2893. func (this *StockManagerApiController) AddGoodInformation() {
  2894. adminUserInfo := this.GetAdminUserInfo()
  2895. orgId := adminUserInfo.CurrentOrgId
  2896. dataBody := make(map[string]interface{}, 0)
  2897. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2898. if err != nil {
  2899. utils.ErrorLog(err.Error())
  2900. return
  2901. }
  2902. utils.ErrorLog("%v", dataBody)
  2903. var goods []*models.GoodInfo
  2904. var total_goods []interface{}
  2905. tempGoods := dataBody["goods"].([]interface{})
  2906. total_goods = tempGoods
  2907. for index, goodMap := range tempGoods {
  2908. goodNameM := goodMap.(map[string]interface{})
  2909. var good models.GoodInfo
  2910. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  2911. utils.ErrorLog("good_name")
  2912. return
  2913. }
  2914. good_name, _ := goodNameM["good_name"].(string)
  2915. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  2916. err_log := models.ExportErrLog{
  2917. LogType: 5,
  2918. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2919. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  2920. Status: 1,
  2921. CreateTime: time.Now().Unix(),
  2922. UpdateTime: time.Now().Unix(),
  2923. ExportTime: time.Now().Unix(),
  2924. }
  2925. service.CreateExportErrLog(&err_log)
  2926. continue
  2927. }
  2928. good.GoodName = good_name
  2929. // 获取数据字典数据
  2930. var good_kind_id int64
  2931. var name = "耗材种类"
  2932. config, _ := service.GetDrugDataConfig(0, name)
  2933. good_kind := goodNameM["good_kind"].(string)
  2934. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  2935. err_log := models.ExportErrLog{
  2936. LogType: 5,
  2937. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2938. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  2939. Status: 1,
  2940. CreateTime: time.Now().Unix(),
  2941. UpdateTime: time.Now().Unix(),
  2942. ExportTime: time.Now().Unix(),
  2943. }
  2944. service.CreateExportErrLog(&err_log)
  2945. continue
  2946. }
  2947. if len(good_kind) != 0 {
  2948. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  2949. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  2950. dataconfig := models.DictDataconfig{
  2951. ParentId: config.ID,
  2952. Module: "system",
  2953. OrgId: orgId,
  2954. Name: good_kind,
  2955. FieldName: "",
  2956. Value: lastConfig.Value + 1,
  2957. CreatedTime: "",
  2958. UpdatedTime: "",
  2959. CreateUserId: adminUserInfo.AdminUser.Id,
  2960. Status: 1,
  2961. Remark: "",
  2962. DeleteIdSystem: 0,
  2963. Title: "",
  2964. Content: "",
  2965. Order: 0,
  2966. Code: "",
  2967. }
  2968. if errcodegoodkind == gorm.ErrRecordNotFound {
  2969. service.CreatedDicConfig(&dataconfig)
  2970. }
  2971. }
  2972. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  2973. for _, it := range dataConfig {
  2974. if good_kind == it.Name {
  2975. fmt.Println(it.Name)
  2976. good_kind_id = int64(it.Value)
  2977. }
  2978. }
  2979. good.GoodKind = good_kind_id
  2980. good_type := goodNameM["type_name"].(string)
  2981. if len(good_type) == 0 {
  2982. err_log := models.ExportErrLog{
  2983. LogType: 5,
  2984. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2985. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  2986. Status: 1,
  2987. CreateTime: time.Now().Unix(),
  2988. UpdateTime: time.Now().Unix(),
  2989. ExportTime: time.Now().Unix(),
  2990. }
  2991. service.CreateExportErrLog(&err_log)
  2992. continue
  2993. }
  2994. if len(good_type) != 0 {
  2995. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  2996. if errcodegoodtype == gorm.ErrRecordNotFound {
  2997. goodsType := models.GoodsType{
  2998. TypeName: good_type,
  2999. Remark: "",
  3000. Ctime: time.Now().Unix(),
  3001. Mtime: 0,
  3002. Creater: adminUserInfo.AdminUser.Id,
  3003. Modifier: 0,
  3004. OrgId: adminUserInfo.CurrentOrgId,
  3005. Status: 1,
  3006. Type: 0,
  3007. Number: 0,
  3008. OutStock: 0,
  3009. StockAttribute: 1,
  3010. }
  3011. service.CreatedGoodType(&goodsType)
  3012. }
  3013. }
  3014. goodType, _ := service.GetAllGoodType(orgId)
  3015. var good_type_id int64
  3016. for _, it := range goodType {
  3017. if good_type == it.TypeName {
  3018. good_type_id = it.ID
  3019. }
  3020. }
  3021. good.GoodTypeId = good_type_id
  3022. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  3023. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  3024. err_log := models.ExportErrLog{
  3025. LogType: 5,
  3026. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3027. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  3028. Status: 1,
  3029. CreateTime: time.Now().Unix(),
  3030. UpdateTime: time.Now().Unix(),
  3031. ExportTime: time.Now().Unix(),
  3032. }
  3033. service.CreateExportErrLog(&err_log)
  3034. continue
  3035. }
  3036. var medical_insurance_id int64
  3037. var medicalInsurance = "医保等级"
  3038. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  3039. if len(medical_insurance_level) != 0 {
  3040. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  3041. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  3042. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  3043. dataconfig := models.DictDataconfig{
  3044. ParentId: medicalInsuranceDataConfig.ID,
  3045. Module: "system",
  3046. OrgId: orgId,
  3047. Name: medical_insurance_level,
  3048. FieldName: "",
  3049. Value: mediConfigOne.Value + 1,
  3050. CreatedTime: "",
  3051. UpdatedTime: "",
  3052. CreateUserId: adminUserInfo.AdminUser.Id,
  3053. Status: 1,
  3054. Remark: "",
  3055. DeleteIdSystem: 0,
  3056. Title: "",
  3057. Content: "",
  3058. Order: 0,
  3059. Code: "",
  3060. }
  3061. service.CreatedDicConfig(&dataconfig)
  3062. }
  3063. }
  3064. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  3065. for _, it := range medicalInsuranceList {
  3066. if medical_insurance_level == it.Name {
  3067. medical_insurance_id = int64(it.Value)
  3068. }
  3069. }
  3070. good.MedicalInsuranceLevel = medical_insurance_id
  3071. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  3072. utils.ErrorLog("specification_name")
  3073. return
  3074. }
  3075. specification_name := goodNameM["specification_name"].(string)
  3076. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  3077. err_log := models.ExportErrLog{
  3078. LogType: 5,
  3079. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3080. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  3081. Status: 1,
  3082. CreateTime: time.Now().Unix(),
  3083. UpdateTime: time.Now().Unix(),
  3084. ExportTime: time.Now().Unix(),
  3085. }
  3086. service.CreateExportErrLog(&err_log)
  3087. continue
  3088. }
  3089. good.SpecificationName = specification_name
  3090. var manufacturer_id int64
  3091. manufacturer := goodNameM["manufacturer"].(string)
  3092. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3093. err_log := models.ExportErrLog{
  3094. LogType: 5,
  3095. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3096. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  3097. Status: 1,
  3098. CreateTime: time.Now().Unix(),
  3099. UpdateTime: time.Now().Unix(),
  3100. ExportTime: time.Now().Unix(),
  3101. }
  3102. service.CreateExportErrLog(&err_log)
  3103. continue
  3104. }
  3105. if len(manufacturer) != 0 {
  3106. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  3107. manu := models.Manufacturer{
  3108. ManufacturerName: manufacturer,
  3109. Status: 1,
  3110. OrgId: orgId,
  3111. Creater: adminUserInfo.AdminUser.Id,
  3112. }
  3113. if errcodes == gorm.ErrRecordNotFound {
  3114. service.CreateManufacturer(&manu)
  3115. }
  3116. }
  3117. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3118. for _, it := range manufacturerList {
  3119. if manufacturer == it.ManufacturerName {
  3120. manufacturer_id = it.ID
  3121. }
  3122. }
  3123. good.Manufacturer = manufacturer_id
  3124. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  3125. utils.ErrorLog("unit_id")
  3126. return
  3127. }
  3128. unit_id := int64(goodNameM["unit_id"].(float64))
  3129. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  3130. err_log := models.ExportErrLog{
  3131. LogType: 5,
  3132. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3133. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  3134. Status: 1,
  3135. CreateTime: time.Now().Unix(),
  3136. UpdateTime: time.Now().Unix(),
  3137. ExportTime: time.Now().Unix(),
  3138. }
  3139. service.CreateExportErrLog(&err_log)
  3140. continue
  3141. }
  3142. good.GoodUnit = unit_id
  3143. retail_prices := goodNameM["retail_price"].(string)
  3144. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3145. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3146. err_log := models.ExportErrLog{
  3147. LogType: 5,
  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. good.RetailPrice = retail_price
  3159. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  3160. utils.ErrorLog("stock_warn_count")
  3161. return
  3162. }
  3163. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  3164. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  3165. err_log := models.ExportErrLog{
  3166. LogType: 5,
  3167. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3168. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  3169. Status: 1,
  3170. CreateTime: time.Now().Unix(),
  3171. UpdateTime: time.Now().Unix(),
  3172. ExportTime: time.Now().Unix(),
  3173. }
  3174. service.CreateExportErrLog(&err_log)
  3175. continue
  3176. }
  3177. good.StockWarnCount = stock_warn_count
  3178. var dealer_id int64
  3179. dealerName := goodNameM["dealer"].(string)
  3180. fmt.Println("经销商", dealerName)
  3181. dealer := models.Dealer{
  3182. OrgId: orgId,
  3183. Status: 1,
  3184. DealerName: dealerName,
  3185. Creater: adminUserInfo.AdminUser.Id,
  3186. Ctime: time.Now().Unix(),
  3187. }
  3188. if len(dealerName) != 0 {
  3189. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  3190. if errcodedealer == gorm.ErrRecordNotFound {
  3191. service.CreateDealer(&dealer)
  3192. }
  3193. }
  3194. dealerList, _ := service.GetAllDealerList(orgId)
  3195. for _, it := range dealerList {
  3196. if dealerName == it.DealerName {
  3197. dealer_id = it.ID
  3198. }
  3199. }
  3200. good.Dealer = dealer_id
  3201. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  3202. utils.ErrorLog("pinyin")
  3203. return
  3204. }
  3205. pinyin := goodNameM["pinyin"].(string)
  3206. good.Pinyin = pinyin
  3207. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  3208. utils.ErrorLog("wubi")
  3209. return
  3210. }
  3211. wubi := goodNameM["wubi"].(string)
  3212. good.Wubi = wubi
  3213. buy_prices := goodNameM["buy_price"].(string)
  3214. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  3215. good.BuyPrice = buy_price
  3216. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  3217. utils.ErrorLog("social_security_directory_code")
  3218. return
  3219. }
  3220. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3221. good.SocialSecurityDirectoryCode = social_security_directory_code
  3222. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  3223. utils.ErrorLog("is_special_diseases")
  3224. return
  3225. }
  3226. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3227. good.IsSpecialDiseases = is_special_diseases
  3228. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  3229. utils.ErrorLog("is_record")
  3230. return
  3231. }
  3232. is_record := int64(goodNameM["is_record"].(float64))
  3233. good.IsRecord = is_record
  3234. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  3235. utils.ErrorLog("good_status")
  3236. return
  3237. }
  3238. good_status := goodNameM["good_status"].(string)
  3239. good.GoodStatus = good_status
  3240. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  3241. utils.ErrorLog("medical_insurance_number")
  3242. return
  3243. }
  3244. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3245. good.MedicalInsuranceNumber = medical_insurance_number
  3246. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  3247. utils.ErrorLog("production_type")
  3248. return
  3249. }
  3250. production_type := goodNameM["production_type"].(string)
  3251. good.ProductionType = production_type
  3252. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  3253. utils.ErrorLog("remark")
  3254. return
  3255. }
  3256. remark := goodNameM["remark"].(string)
  3257. good.Remark = remark
  3258. statistics_category := goodNameM["statistics_category"].(string)
  3259. var categoryName = "统计分类"
  3260. var statistic_id int64
  3261. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  3262. if len(statistics_category) != 0 {
  3263. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  3264. if errcodecagegory == gorm.ErrRecordNotFound {
  3265. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  3266. dataconfig := models.DictDataconfig{
  3267. ParentId: drugDataConfig.ID,
  3268. Module: "system",
  3269. OrgId: orgId,
  3270. Name: statistics_category,
  3271. FieldName: "",
  3272. Value: dicConfigThree.Value + 1,
  3273. CreatedTime: "",
  3274. UpdatedTime: "",
  3275. CreateUserId: adminUserInfo.AdminUser.Id,
  3276. Status: 1,
  3277. Remark: "",
  3278. DeleteIdSystem: 0,
  3279. Title: "",
  3280. Content: "",
  3281. Order: 0,
  3282. Code: "",
  3283. }
  3284. service.CreatedDicConfig(&dataconfig)
  3285. }
  3286. }
  3287. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  3288. for _, it := range parentDataConfig {
  3289. if statistics_category == it.Name {
  3290. statistic_id = int64(it.Value)
  3291. }
  3292. }
  3293. good.StatisticsCategory = statistic_id
  3294. special_medical := goodNameM["special_medical"].(string)
  3295. good.SpecialMedical = special_medical
  3296. goods = append(goods, &good)
  3297. }
  3298. export_time := time.Now().Unix()
  3299. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3300. if len(goods) > 0 {
  3301. for _, item := range goods {
  3302. goodInfo := models.GoodInfo{
  3303. GoodName: item.GoodName,
  3304. SpecificationName: item.SpecificationName,
  3305. GoodKind: item.GoodKind,
  3306. GoodTypeId: item.GoodTypeId,
  3307. Dealer: item.Dealer,
  3308. GoodUnit: item.GoodUnit,
  3309. IsRecord: item.IsRecord,
  3310. IsSpecialDiseases: item.IsSpecialDiseases,
  3311. Manufacturer: item.Manufacturer,
  3312. Pinyin: item.Pinyin,
  3313. GoodStatus: item.GoodStatus,
  3314. ProductionType: item.ProductionType,
  3315. Remark: item.Remark,
  3316. RetailPrice: item.RetailPrice,
  3317. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3318. SpecialMedical: item.SpecialMedical,
  3319. Wubi: item.Wubi,
  3320. StockWarnCount: item.StockWarnCount,
  3321. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3322. OrgId: orgId,
  3323. Status: 1,
  3324. Ctime: time.Now().Unix(),
  3325. StatisticsCategory: item.StatisticsCategory,
  3326. GoodCode: item.GoodCode,
  3327. BuyPrice: item.BuyPrice,
  3328. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3329. }
  3330. //查询同种耗材名称同种类型同种规格的耗材是否存在
  3331. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  3332. if errcodegood == gorm.ErrRecordNotFound {
  3333. service.CreateGoodsInfomation(&goodInfo)
  3334. } else if errcodegood == nil {
  3335. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  3336. }
  3337. log := models.ExportLog{
  3338. LogType: 5,
  3339. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3340. TotalNum: int64(len(total_goods)),
  3341. FailNum: int64(len(errLogs)),
  3342. SuccessNum: int64(len(goods)),
  3343. CreateTime: time.Now().Unix(),
  3344. UpdateTime: time.Now().Unix(),
  3345. ExportTime: export_time,
  3346. Status: 1,
  3347. }
  3348. service.CreateExportLog(&log)
  3349. this.ServeSuccessJSON(map[string]interface{}{
  3350. "msg": "导入成功",
  3351. "total_num": len(total_goods),
  3352. "success_num": len(goods),
  3353. "fail_num": int64(len(errLogs)),
  3354. })
  3355. }
  3356. } else {
  3357. log := models.ExportLog{
  3358. LogType: 5,
  3359. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3360. TotalNum: int64(len(total_goods)),
  3361. FailNum: int64(len(errLogs)),
  3362. SuccessNum: int64(len(goods)),
  3363. CreateTime: time.Now().Unix(),
  3364. UpdateTime: time.Now().Unix(),
  3365. ExportTime: export_time,
  3366. Status: 1,
  3367. }
  3368. service.CreateExportLog(&log)
  3369. this.ServeSuccessJSON(map[string]interface{}{
  3370. "msg": "导入成功",
  3371. "total_num": len(total_goods),
  3372. "success_num": len(goods),
  3373. "fail_num": int64(len(errLogs)),
  3374. })
  3375. }
  3376. }
  3377. func (this *StockManagerApiController) AddDrugInformation() {
  3378. adminUser := this.GetAdminUserInfo()
  3379. orgId := adminUser.CurrentOrgId
  3380. dataBody := make(map[string]interface{}, 0)
  3381. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  3382. if err != nil {
  3383. utils.ErrorLog(err.Error())
  3384. return
  3385. }
  3386. utils.ErrorLog("%v", dataBody)
  3387. var drugList []*models.BaseDrugLib
  3388. var total_goods []interface{}
  3389. tempDrugs := dataBody["drugs"].([]interface{})
  3390. total_goods = tempDrugs
  3391. for index, drugMap := range tempDrugs {
  3392. goodNameM := drugMap.(map[string]interface{})
  3393. var drug models.BaseDrugLib
  3394. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  3395. utils.ErrorLog("drug_name")
  3396. return
  3397. }
  3398. drug_name, _ := goodNameM["drug_name"].(string)
  3399. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  3400. err_log := models.ExportErrLog{
  3401. LogType: 4,
  3402. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3403. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  3404. Status: 1,
  3405. CreateTime: time.Now().Unix(),
  3406. UpdateTime: time.Now().Unix(),
  3407. ExportTime: time.Now().Unix(),
  3408. }
  3409. service.CreateExportErrLog(&err_log)
  3410. continue
  3411. }
  3412. drug.DrugName = drug_name
  3413. dose := goodNameM["dose"].(float64)
  3414. if dose < 0 { //名字为空则生成一条导入错误日志
  3415. err_log := models.ExportErrLog{
  3416. LogType: 4,
  3417. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3418. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  3419. Status: 1,
  3420. CreateTime: time.Now().Unix(),
  3421. UpdateTime: time.Now().Unix(),
  3422. ExportTime: time.Now().Unix(),
  3423. }
  3424. service.CreateExportErrLog(&err_log)
  3425. continue
  3426. }
  3427. drug.Dose = dose
  3428. dose_unit := goodNameM["dose_unit"].(string)
  3429. if dose < 0 { //名字为空则生成一条导入错误日志
  3430. err_log := models.ExportErrLog{
  3431. LogType: 4,
  3432. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3433. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  3434. Status: 1,
  3435. CreateTime: time.Now().Unix(),
  3436. UpdateTime: time.Now().Unix(),
  3437. ExportTime: time.Now().Unix(),
  3438. }
  3439. service.CreateExportErrLog(&err_log)
  3440. continue
  3441. }
  3442. drug.DoseUnit = dose_unit
  3443. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  3444. utils.ErrorLog("min_number")
  3445. return
  3446. }
  3447. min_number, _ := goodNameM["min_number"].(string)
  3448. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  3449. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  3450. err_log := models.ExportErrLog{
  3451. LogType: 4,
  3452. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3453. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  3454. Status: 1,
  3455. CreateTime: time.Now().Unix(),
  3456. UpdateTime: time.Now().Unix(),
  3457. ExportTime: time.Now().Unix(),
  3458. }
  3459. service.CreateExportErrLog(&err_log)
  3460. continue
  3461. }
  3462. drug.MinNumber = minNumber
  3463. min_unit := goodNameM["min_unit"].(string)
  3464. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  3465. err_log := models.ExportErrLog{
  3466. LogType: 4,
  3467. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3468. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  3469. Status: 1,
  3470. CreateTime: time.Now().Unix(),
  3471. UpdateTime: time.Now().Unix(),
  3472. ExportTime: time.Now().Unix(),
  3473. }
  3474. service.CreateExportErrLog(&err_log)
  3475. continue
  3476. }
  3477. drug.MinUnit = min_unit
  3478. max_unit_id := goodNameM["max_unit"].(string)
  3479. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3480. err_log := models.ExportErrLog{
  3481. LogType: 4,
  3482. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3483. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  3484. Status: 1,
  3485. CreateTime: time.Now().Unix(),
  3486. UpdateTime: time.Now().Unix(),
  3487. ExportTime: time.Now().Unix(),
  3488. }
  3489. service.CreateExportErrLog(&err_log)
  3490. continue
  3491. }
  3492. drug.MaxUnit = max_unit_id
  3493. max_unit := goodNameM["max_unit"].(string)
  3494. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  3495. err_log := models.ExportErrLog{
  3496. LogType: 4,
  3497. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3498. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  3499. Status: 1,
  3500. CreateTime: time.Now().Unix(),
  3501. UpdateTime: time.Now().Unix(),
  3502. ExportTime: time.Now().Unix(),
  3503. }
  3504. service.CreateExportErrLog(&err_log)
  3505. continue
  3506. }
  3507. drug.MaxUnit = max_unit
  3508. drug_type := goodNameM["drug_type"].(string)
  3509. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  3510. err_log := models.ExportErrLog{
  3511. LogType: 4,
  3512. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3513. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  3514. Status: 1,
  3515. CreateTime: time.Now().Unix(),
  3516. UpdateTime: time.Now().Unix(),
  3517. ExportTime: time.Now().Unix(),
  3518. }
  3519. service.CreateExportErrLog(&err_log)
  3520. continue
  3521. }
  3522. var drug_type_id int64
  3523. var drugType = "药品类型"
  3524. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  3525. if len(drug_type) != 0 {
  3526. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  3527. if errcodes == gorm.ErrRecordNotFound {
  3528. //获取该型号最后一条数据型号
  3529. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  3530. dataconfig := models.DictDataconfig{
  3531. ParentId: drugconfig.ID,
  3532. Module: "system",
  3533. OrgId: orgId,
  3534. Name: drug_type,
  3535. FieldName: "",
  3536. Value: config.Value + 1,
  3537. CreatedTime: "",
  3538. UpdatedTime: "",
  3539. CreateUserId: adminUser.AdminUser.Id,
  3540. Status: 1,
  3541. Remark: "",
  3542. DeleteIdSystem: 0,
  3543. Title: "",
  3544. Content: "",
  3545. Order: 0,
  3546. Code: "",
  3547. }
  3548. service.CreatedDicConfig(&dataconfig)
  3549. }
  3550. }
  3551. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  3552. for _, it := range drugTypeList {
  3553. if drug_type == it.Name {
  3554. drug_type_id = int64(it.Value)
  3555. }
  3556. }
  3557. drug.DrugType = drug_type_id
  3558. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  3559. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  3560. err_log := models.ExportErrLog{
  3561. LogType: 4,
  3562. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3563. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  3564. Status: 1,
  3565. CreateTime: time.Now().Unix(),
  3566. UpdateTime: time.Now().Unix(),
  3567. ExportTime: time.Now().Unix(),
  3568. }
  3569. service.CreateExportErrLog(&err_log)
  3570. continue
  3571. }
  3572. drug.DrugStockLimit = drug_stock_limit
  3573. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  3574. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  3575. err_log := models.ExportErrLog{
  3576. LogType: 4,
  3577. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3578. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  3579. Status: 1,
  3580. CreateTime: time.Now().Unix(),
  3581. UpdateTime: time.Now().Unix(),
  3582. ExportTime: time.Now().Unix(),
  3583. }
  3584. service.CreateExportErrLog(&err_log)
  3585. continue
  3586. }
  3587. drug.DrugOriginPlace = drug_origin_place
  3588. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  3589. if len(drug_dosage_form) == 0 {
  3590. err_log := models.ExportErrLog{
  3591. LogType: 4,
  3592. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3593. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  3594. Status: 1,
  3595. CreateTime: time.Now().Unix(),
  3596. UpdateTime: time.Now().Unix(),
  3597. ExportTime: time.Now().Unix(),
  3598. }
  3599. service.CreateExportErrLog(&err_log)
  3600. continue
  3601. }
  3602. var drug_dosage = "药品剂型"
  3603. var drug_dosage_form_id int64
  3604. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  3605. if len(drug_dosage_form) != 0 {
  3606. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  3607. if errcodess == gorm.ErrRecordNotFound {
  3608. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  3609. dataconfig := models.DictDataconfig{
  3610. ParentId: drugDosageconfig.ID,
  3611. Module: "system",
  3612. OrgId: orgId,
  3613. Name: drug_dosage_form,
  3614. FieldName: "",
  3615. Value: configOne.Value + 1,
  3616. CreatedTime: "",
  3617. UpdatedTime: "",
  3618. CreateUserId: adminUser.AdminUser.Id,
  3619. Status: 1,
  3620. Remark: "",
  3621. DeleteIdSystem: 0,
  3622. Title: "",
  3623. Content: "",
  3624. Order: 0,
  3625. Code: "",
  3626. }
  3627. service.CreatedDicConfig(&dataconfig)
  3628. }
  3629. }
  3630. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  3631. for _, it := range drugDosageList {
  3632. if drug_dosage_form == it.Name {
  3633. drug_dosage_form_id = int64(it.Value)
  3634. }
  3635. }
  3636. drug.DrugDosageForm = drug_dosage_form_id
  3637. retail_prices := goodNameM["retail_price"].(string)
  3638. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3639. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3640. err_log := models.ExportErrLog{
  3641. LogType: 4,
  3642. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3643. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  3644. Status: 1,
  3645. CreateTime: time.Now().Unix(),
  3646. UpdateTime: time.Now().Unix(),
  3647. ExportTime: time.Now().Unix(),
  3648. }
  3649. service.CreateExportErrLog(&err_log)
  3650. continue
  3651. }
  3652. drug.RetailPrice = retail_price
  3653. last_prices := goodNameM["last_price"].(string)
  3654. last_price, _ := strconv.ParseFloat(last_prices, 64)
  3655. if last_price <= 0 { //名字为空则生成一条导入错误日志
  3656. err_log := models.ExportErrLog{
  3657. LogType: 4,
  3658. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3659. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  3660. Status: 1,
  3661. CreateTime: time.Now().Unix(),
  3662. UpdateTime: time.Now().Unix(),
  3663. ExportTime: time.Now().Unix(),
  3664. }
  3665. service.CreateExportErrLog(&err_log)
  3666. continue
  3667. }
  3668. drug.LastPrice = last_price
  3669. drug_classify := goodNameM["drug_classify"].(string)
  3670. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  3671. err_log := models.ExportErrLog{
  3672. LogType: 4,
  3673. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3674. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  3675. Status: 1,
  3676. CreateTime: time.Now().Unix(),
  3677. UpdateTime: time.Now().Unix(),
  3678. ExportTime: time.Now().Unix(),
  3679. }
  3680. service.CreateExportErrLog(&err_log)
  3681. continue
  3682. }
  3683. var drugClassify = "药物分类"
  3684. var drug_classify_id int64
  3685. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  3686. if len(drug_classify) != 0 {
  3687. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  3688. if errcodesClass == gorm.ErrRecordNotFound {
  3689. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  3690. dataconfig := models.DictDataconfig{
  3691. ParentId: drugClassifyConfig.ID,
  3692. Module: "system",
  3693. OrgId: orgId,
  3694. Name: drug_classify,
  3695. FieldName: "",
  3696. Value: drugClassConfig.Value + 1,
  3697. CreatedTime: "",
  3698. UpdatedTime: "",
  3699. CreateUserId: adminUser.AdminUser.Id,
  3700. Status: 1,
  3701. Remark: "",
  3702. DeleteIdSystem: 0,
  3703. Title: "",
  3704. Content: "",
  3705. Order: 0,
  3706. Code: "",
  3707. }
  3708. service.CreatedDicConfig(&dataconfig)
  3709. }
  3710. }
  3711. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  3712. for _, it := range drugClassList {
  3713. if drug_classify == it.Name {
  3714. drug_classify_id = int64(it.Value)
  3715. }
  3716. }
  3717. drug_dose := goodNameM["drug_dose"].(string)
  3718. if len(drug_dose) == 0 {
  3719. err_log := models.ExportErrLog{
  3720. LogType: 4,
  3721. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3722. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  3723. Status: 1,
  3724. CreateTime: time.Now().Unix(),
  3725. UpdateTime: time.Now().Unix(),
  3726. ExportTime: time.Now().Unix(),
  3727. }
  3728. service.CreateExportErrLog(&err_log)
  3729. continue
  3730. }
  3731. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  3732. drug.DrugDose = drugDoses
  3733. var units = "单位"
  3734. var unit_id int64
  3735. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  3736. if len(drugDoseUnit) == 0 {
  3737. err_log := models.ExportErrLog{
  3738. LogType: 4,
  3739. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3740. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  3741. Status: 1,
  3742. CreateTime: time.Now().Unix(),
  3743. UpdateTime: time.Now().Unix(),
  3744. ExportTime: time.Now().Unix(),
  3745. }
  3746. service.CreateExportErrLog(&err_log)
  3747. continue
  3748. }
  3749. manufacturer := goodNameM["manufacturer"].(string)
  3750. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3751. err_log := models.ExportErrLog{
  3752. LogType: 4,
  3753. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3754. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  3755. Status: 1,
  3756. CreateTime: time.Now().Unix(),
  3757. UpdateTime: time.Now().Unix(),
  3758. ExportTime: time.Now().Unix(),
  3759. }
  3760. service.CreateExportErrLog(&err_log)
  3761. continue
  3762. }
  3763. if len(manufacturer) != 0 {
  3764. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  3765. if errcodema == gorm.ErrRecordNotFound {
  3766. manufactur := models.Manufacturer{
  3767. OrgId: orgId,
  3768. Status: 1,
  3769. ManufacturerName: manufacturer,
  3770. Ctime: time.Now().Unix(),
  3771. Creater: adminUser.AdminUser.Id,
  3772. }
  3773. service.CreateManufacturer(&manufactur)
  3774. }
  3775. }
  3776. var manufacturer_id int64
  3777. manufacturList, _ := service.GetAllManufacturerList(orgId)
  3778. for _, it := range manufacturList {
  3779. if manufacturer == it.ManufacturerName {
  3780. manufacturer_id = it.ID
  3781. }
  3782. }
  3783. drug.Manufacturer = manufacturer_id
  3784. dealer := goodNameM["dealer"].(string)
  3785. if len(dealer) != 0 {
  3786. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  3787. if errcodesdealer == gorm.ErrRecordNotFound {
  3788. dealerconfig := models.Dealer{
  3789. DealerName: dealer,
  3790. Status: 1,
  3791. OrgId: orgId,
  3792. Ctime: time.Now().Unix(),
  3793. Creater: adminUser.AdminUser.Id,
  3794. }
  3795. service.CreateDealer(&dealerconfig)
  3796. }
  3797. }
  3798. var dealer_id int64
  3799. dealerList, _ := service.GetAllDealerList(orgId)
  3800. for _, it := range dealerList {
  3801. if dealer == it.DealerName {
  3802. dealer_id = it.ID
  3803. }
  3804. }
  3805. drug.Dealer = dealer_id
  3806. delivery_way := goodNameM["delivery_way"].(string)
  3807. if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
  3808. err_log := models.ExportErrLog{
  3809. LogType: 4,
  3810. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3811. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  3812. Status: 1,
  3813. CreateTime: time.Now().Unix(),
  3814. UpdateTime: time.Now().Unix(),
  3815. ExportTime: time.Now().Unix(),
  3816. }
  3817. service.CreateExportErrLog(&err_log)
  3818. continue
  3819. }
  3820. drug.DeliveryWay = delivery_way
  3821. execution_frequency := goodNameM["execution_frequency"].(string)
  3822. if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
  3823. err_log := models.ExportErrLog{
  3824. LogType: 4,
  3825. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3826. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  3827. Status: 1,
  3828. CreateTime: time.Now().Unix(),
  3829. UpdateTime: time.Now().Unix(),
  3830. ExportTime: time.Now().Unix(),
  3831. }
  3832. service.CreateExportErrLog(&err_log)
  3833. continue
  3834. }
  3835. drug.ExecutionFrequency = execution_frequency
  3836. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  3837. drug.LmtUsedFlag = lmt_used_flags
  3838. //medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  3839. //var medical_insurance_level_id int64
  3840. //if len(medical_insurance_level) == 0 { //名字为空则生成一条导入错误日志
  3841. // err_log := models.ExportErrLog{
  3842. // LogType: 4,
  3843. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3844. // ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  3845. // Status: 1,
  3846. // CreateTime: time.Now().Unix(),
  3847. // UpdateTime: time.Now().Unix(),
  3848. // ExportTime: time.Now().Unix(),
  3849. // }
  3850. // service.CreateExportErrLog(&err_log)
  3851. // continue
  3852. //}
  3853. //var medicalInsuranceName = "医保等级"
  3854. //medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
  3855. //if len(medical_insurance_level) != 0 {
  3856. // _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
  3857. // if errcodemedical == gorm.ErrRecordNotFound {
  3858. // medConfig, _ := service.GetLastDicConfig(medicalInsuranceConfig.ID, orgId)
  3859. // dataconfig := models.DictDataconfig{
  3860. // ParentId: medicalInsuranceConfig.ID,
  3861. // Module: "system",
  3862. // OrgId: orgId,
  3863. // Name: medical_insurance_level,
  3864. // FieldName: "",
  3865. // Value: medConfig.Value + 1,
  3866. // CreatedTime: "",
  3867. // UpdatedTime: "",
  3868. // CreateUserId: adminUser.AdminUser.Id,
  3869. // Status: 1,
  3870. // Remark: "",
  3871. // DeleteIdSystem: 0,
  3872. // Title: "",
  3873. // Content: "",
  3874. // Order: 0,
  3875. // Code: "",
  3876. // }
  3877. // service.CreatedDicConfig(&dataconfig)
  3878. // }
  3879. //}
  3880. //medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
  3881. //for _, it := range medicalInsuranceList {
  3882. // if medical_insurance_level == it.Name {
  3883. // medical_insurance_level_id = int64(it.Value)
  3884. // }
  3885. //}
  3886. //drug.MedicalInsuranceLevel = medical_insurance_level_id
  3887. //unit_matrixing := goodNameM["unit_matrixing"].(string)
  3888. //if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3889. // err_log := models.ExportErrLog{
  3890. // LogType: 4,
  3891. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3892. // ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
  3893. // Status: 1,
  3894. // CreateTime: time.Now().Unix(),
  3895. // UpdateTime: time.Now().Unix(),
  3896. // ExportTime: time.Now().Unix(),
  3897. // }
  3898. // service.CreateExportErrLog(&err_log)
  3899. // continue
  3900. //}
  3901. //
  3902. //drug.UnitMatrixing = unit_matrixing
  3903. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  3904. if len(drugDoseUnit) != 0 {
  3905. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  3906. if errcodedataconfig == gorm.ErrRecordNotFound {
  3907. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  3908. dataconfig := models.Dataconfig{
  3909. ParentId: dataConfig.ID,
  3910. Module: "hemodialysis",
  3911. OrgId: orgId,
  3912. Name: drugDoseUnit,
  3913. FieldName: "",
  3914. Value: childConfig.Value + 1,
  3915. CreatedTime: "",
  3916. UpdatedTime: "",
  3917. CreateUserId: adminUser.AdminUser.Id,
  3918. Status: 1,
  3919. Remark: "",
  3920. DeleteIdSystem: 0,
  3921. Title: "",
  3922. Content: "",
  3923. Order: 0,
  3924. Code: "",
  3925. FieldType: 0,
  3926. }
  3927. service.CreateDataConfig(&dataconfig)
  3928. }
  3929. }
  3930. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  3931. for _, it := range list {
  3932. if drugDoseUnit == it.Name {
  3933. unit_id = int64(it.Value)
  3934. }
  3935. }
  3936. drug.DrugDoseUnit = unit_id
  3937. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  3938. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  3939. utils.ErrorLog("drug_alias")
  3940. return
  3941. }
  3942. drug_alias, _ := goodNameM["drug_alias"].(string)
  3943. drug.DrugAlias = drug_alias
  3944. drug_category := goodNameM["drug_category"].(string)
  3945. var drugCategory = "药品类别"
  3946. var drug_category_id int64
  3947. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  3948. if len(drug_category) != 0 {
  3949. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  3950. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  3951. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  3952. dataconfig := models.DictDataconfig{
  3953. ParentId: drugCategoryConfig.ID,
  3954. Module: "system",
  3955. OrgId: orgId,
  3956. Name: drug_category,
  3957. FieldName: "",
  3958. Value: drugCategoryConfigSix.Value + 1,
  3959. CreatedTime: "",
  3960. UpdatedTime: "",
  3961. CreateUserId: adminUser.AdminUser.Id,
  3962. Status: 1,
  3963. Remark: "",
  3964. DeleteIdSystem: 0,
  3965. Title: "",
  3966. Content: "",
  3967. Order: 0,
  3968. Code: "",
  3969. }
  3970. service.CreatedDicConfig(&dataconfig)
  3971. }
  3972. }
  3973. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  3974. fmt.Println("drugCategoryList", drugCategoryList)
  3975. for _, it := range drugCategoryList {
  3976. if drug_category == it.Name {
  3977. drug_category_id = int64(it.Value)
  3978. }
  3979. }
  3980. drug.DrugCategory = drug_category_id
  3981. statistics_category := goodNameM["statistics_category"].(string)
  3982. for index, drugMap := range tempDrugs {
  3983. goodNameM := drugMap.(map[string]interface{})
  3984. var drug models.BaseDrugLib
  3985. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  3986. utils.ErrorLog("drug_name")
  3987. return
  3988. }
  3989. drug_name, _ := goodNameM["drug_name"].(string)
  3990. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  3991. err_log := models.ExportErrLog{
  3992. LogType: 4,
  3993. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3994. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  3995. Status: 1,
  3996. CreateTime: time.Now().Unix(),
  3997. UpdateTime: time.Now().Unix(),
  3998. ExportTime: time.Now().Unix(),
  3999. }
  4000. service.CreateExportErrLog(&err_log)
  4001. continue
  4002. }
  4003. drug.DrugName = drug_name
  4004. dose := goodNameM["dose"].(float64)
  4005. if dose < 0 { //名字为空则生成一条导入错误日志
  4006. err_log := models.ExportErrLog{
  4007. LogType: 4,
  4008. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4009. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  4010. Status: 1,
  4011. CreateTime: time.Now().Unix(),
  4012. UpdateTime: time.Now().Unix(),
  4013. ExportTime: time.Now().Unix(),
  4014. }
  4015. service.CreateExportErrLog(&err_log)
  4016. continue
  4017. }
  4018. drug.Dose = dose
  4019. dose_unit := goodNameM["dose_unit"].(string)
  4020. if dose < 0 { //名字为空则生成一条导入错误日志
  4021. err_log := models.ExportErrLog{
  4022. LogType: 4,
  4023. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4024. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  4025. Status: 1,
  4026. CreateTime: time.Now().Unix(),
  4027. UpdateTime: time.Now().Unix(),
  4028. ExportTime: time.Now().Unix(),
  4029. }
  4030. service.CreateExportErrLog(&err_log)
  4031. continue
  4032. }
  4033. drug.DoseUnit = dose_unit
  4034. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  4035. utils.ErrorLog("min_number")
  4036. return
  4037. }
  4038. min_number, _ := goodNameM["min_number"].(string)
  4039. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  4040. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  4041. err_log := models.ExportErrLog{
  4042. LogType: 4,
  4043. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4044. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  4045. Status: 1,
  4046. CreateTime: time.Now().Unix(),
  4047. UpdateTime: time.Now().Unix(),
  4048. ExportTime: time.Now().Unix(),
  4049. }
  4050. service.CreateExportErrLog(&err_log)
  4051. continue
  4052. }
  4053. drug.MinNumber = minNumber
  4054. min_unit := goodNameM["min_unit"].(string)
  4055. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  4056. err_log := models.ExportErrLog{
  4057. LogType: 4,
  4058. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4059. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  4060. Status: 1,
  4061. CreateTime: time.Now().Unix(),
  4062. UpdateTime: time.Now().Unix(),
  4063. ExportTime: time.Now().Unix(),
  4064. }
  4065. service.CreateExportErrLog(&err_log)
  4066. continue
  4067. }
  4068. drug.MinUnit = min_unit
  4069. max_unit_id := goodNameM["max_unit"].(string)
  4070. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  4071. err_log := models.ExportErrLog{
  4072. LogType: 4,
  4073. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4074. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  4075. Status: 1,
  4076. CreateTime: time.Now().Unix(),
  4077. UpdateTime: time.Now().Unix(),
  4078. ExportTime: time.Now().Unix(),
  4079. }
  4080. service.CreateExportErrLog(&err_log)
  4081. continue
  4082. }
  4083. drug.MaxUnit = max_unit_id
  4084. max_unit := goodNameM["max_unit"].(string)
  4085. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  4086. err_log := models.ExportErrLog{
  4087. LogType: 4,
  4088. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4089. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  4090. Status: 1,
  4091. CreateTime: time.Now().Unix(),
  4092. UpdateTime: time.Now().Unix(),
  4093. ExportTime: time.Now().Unix(),
  4094. }
  4095. service.CreateExportErrLog(&err_log)
  4096. continue
  4097. }
  4098. drug.MaxUnit = max_unit
  4099. drug_type := goodNameM["drug_type"].(string)
  4100. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  4101. err_log := models.ExportErrLog{
  4102. LogType: 4,
  4103. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4104. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  4105. Status: 1,
  4106. CreateTime: time.Now().Unix(),
  4107. UpdateTime: time.Now().Unix(),
  4108. ExportTime: time.Now().Unix(),
  4109. }
  4110. service.CreateExportErrLog(&err_log)
  4111. continue
  4112. }
  4113. var drug_type_id int64
  4114. var drugType = "药品类型"
  4115. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  4116. if len(drug_type) != 0 {
  4117. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  4118. if errcodes == gorm.ErrRecordNotFound {
  4119. //获取该型号最后一条数据型号
  4120. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  4121. dataconfig := models.DictDataconfig{
  4122. ParentId: drugconfig.ID,
  4123. Module: "system",
  4124. OrgId: orgId,
  4125. Name: drug_type,
  4126. FieldName: "",
  4127. Value: config.Value + 1,
  4128. CreatedTime: "",
  4129. UpdatedTime: "",
  4130. CreateUserId: adminUser.AdminUser.Id,
  4131. Status: 1,
  4132. Remark: "",
  4133. DeleteIdSystem: 0,
  4134. Title: "",
  4135. Content: "",
  4136. Order: 0,
  4137. Code: "",
  4138. }
  4139. service.CreatedDicConfig(&dataconfig)
  4140. }
  4141. }
  4142. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  4143. for _, it := range drugTypeList {
  4144. if drug_type == it.Name {
  4145. drug_type_id = int64(it.Value)
  4146. }
  4147. }
  4148. drug.DrugType = drug_type_id
  4149. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  4150. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  4151. err_log := models.ExportErrLog{
  4152. LogType: 4,
  4153. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4154. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  4155. Status: 1,
  4156. CreateTime: time.Now().Unix(),
  4157. UpdateTime: time.Now().Unix(),
  4158. ExportTime: time.Now().Unix(),
  4159. }
  4160. service.CreateExportErrLog(&err_log)
  4161. continue
  4162. }
  4163. drug.DrugStockLimit = drug_stock_limit
  4164. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  4165. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  4166. err_log := models.ExportErrLog{
  4167. LogType: 4,
  4168. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4169. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  4170. Status: 1,
  4171. CreateTime: time.Now().Unix(),
  4172. UpdateTime: time.Now().Unix(),
  4173. ExportTime: time.Now().Unix(),
  4174. }
  4175. service.CreateExportErrLog(&err_log)
  4176. continue
  4177. }
  4178. drug.DrugOriginPlace = drug_origin_place
  4179. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  4180. if len(drug_dosage_form) == 0 {
  4181. err_log := models.ExportErrLog{
  4182. LogType: 4,
  4183. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4184. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  4185. Status: 1,
  4186. CreateTime: time.Now().Unix(),
  4187. UpdateTime: time.Now().Unix(),
  4188. ExportTime: time.Now().Unix(),
  4189. }
  4190. service.CreateExportErrLog(&err_log)
  4191. continue
  4192. }
  4193. var drug_dosage = "药品剂型"
  4194. var drug_dosage_form_id int64
  4195. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  4196. if len(drug_dosage_form) != 0 {
  4197. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  4198. if errcodess == gorm.ErrRecordNotFound {
  4199. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  4200. dataconfig := models.DictDataconfig{
  4201. ParentId: drugDosageconfig.ID,
  4202. Module: "system",
  4203. OrgId: orgId,
  4204. Name: drug_dosage_form,
  4205. FieldName: "",
  4206. Value: configOne.Value + 1,
  4207. CreatedTime: "",
  4208. UpdatedTime: "",
  4209. CreateUserId: adminUser.AdminUser.Id,
  4210. Status: 1,
  4211. Remark: "",
  4212. DeleteIdSystem: 0,
  4213. Title: "",
  4214. Content: "",
  4215. Order: 0,
  4216. Code: "",
  4217. }
  4218. service.CreatedDicConfig(&dataconfig)
  4219. }
  4220. }
  4221. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  4222. for _, it := range drugDosageList {
  4223. if drug_dosage_form == it.Name {
  4224. drug_dosage_form_id = int64(it.Value)
  4225. }
  4226. }
  4227. drug.DrugDosageForm = drug_dosage_form_id
  4228. retail_prices := goodNameM["retail_price"].(string)
  4229. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  4230. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  4231. err_log := models.ExportErrLog{
  4232. LogType: 4,
  4233. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4234. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  4235. Status: 1,
  4236. CreateTime: time.Now().Unix(),
  4237. UpdateTime: time.Now().Unix(),
  4238. ExportTime: time.Now().Unix(),
  4239. }
  4240. service.CreateExportErrLog(&err_log)
  4241. continue
  4242. }
  4243. drug.RetailPrice = retail_price
  4244. last_prices := goodNameM["last_price"].(string)
  4245. last_price, _ := strconv.ParseFloat(last_prices, 64)
  4246. if last_price <= 0 { //名字为空则生成一条导入错误日志
  4247. err_log := models.ExportErrLog{
  4248. LogType: 4,
  4249. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4250. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  4251. Status: 1,
  4252. CreateTime: time.Now().Unix(),
  4253. UpdateTime: time.Now().Unix(),
  4254. ExportTime: time.Now().Unix(),
  4255. }
  4256. service.CreateExportErrLog(&err_log)
  4257. continue
  4258. }
  4259. drug.LastPrice = last_price
  4260. drug_classify := goodNameM["drug_classify"].(string)
  4261. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  4262. err_log := models.ExportErrLog{
  4263. LogType: 4,
  4264. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4265. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  4266. Status: 1,
  4267. CreateTime: time.Now().Unix(),
  4268. UpdateTime: time.Now().Unix(),
  4269. ExportTime: time.Now().Unix(),
  4270. }
  4271. service.CreateExportErrLog(&err_log)
  4272. continue
  4273. }
  4274. var drugClassify = "药物分类"
  4275. var drug_classify_id int64
  4276. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  4277. if len(drug_classify) != 0 {
  4278. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  4279. if errcodesClass == gorm.ErrRecordNotFound {
  4280. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  4281. dataconfig := models.DictDataconfig{
  4282. ParentId: drugClassifyConfig.ID,
  4283. Module: "system",
  4284. OrgId: orgId,
  4285. Name: drug_classify,
  4286. FieldName: "",
  4287. Value: drugClassConfig.Value + 1,
  4288. CreatedTime: "",
  4289. UpdatedTime: "",
  4290. CreateUserId: adminUser.AdminUser.Id,
  4291. Status: 1,
  4292. Remark: "",
  4293. DeleteIdSystem: 0,
  4294. Title: "",
  4295. Content: "",
  4296. Order: 0,
  4297. Code: "",
  4298. }
  4299. service.CreatedDicConfig(&dataconfig)
  4300. }
  4301. }
  4302. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  4303. for _, it := range drugClassList {
  4304. if drug_classify == it.Name {
  4305. drug_classify_id = int64(it.Value)
  4306. }
  4307. }
  4308. drug_dose := goodNameM["drug_dose"].(string)
  4309. if len(drug_dose) == 0 {
  4310. err_log := models.ExportErrLog{
  4311. LogType: 4,
  4312. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4313. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  4314. Status: 1,
  4315. CreateTime: time.Now().Unix(),
  4316. UpdateTime: time.Now().Unix(),
  4317. ExportTime: time.Now().Unix(),
  4318. }
  4319. service.CreateExportErrLog(&err_log)
  4320. continue
  4321. }
  4322. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  4323. drug.DrugDose = drugDoses
  4324. var units = "单位"
  4325. var unit_id int64
  4326. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  4327. if len(drugDoseUnit) == 0 {
  4328. err_log := models.ExportErrLog{
  4329. LogType: 4,
  4330. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4331. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  4332. Status: 1,
  4333. CreateTime: time.Now().Unix(),
  4334. UpdateTime: time.Now().Unix(),
  4335. ExportTime: time.Now().Unix(),
  4336. }
  4337. service.CreateExportErrLog(&err_log)
  4338. continue
  4339. }
  4340. manufacturer := goodNameM["manufacturer"].(string)
  4341. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  4342. err_log := models.ExportErrLog{
  4343. LogType: 4,
  4344. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4345. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  4346. Status: 1,
  4347. CreateTime: time.Now().Unix(),
  4348. UpdateTime: time.Now().Unix(),
  4349. ExportTime: time.Now().Unix(),
  4350. }
  4351. service.CreateExportErrLog(&err_log)
  4352. continue
  4353. }
  4354. if len(manufacturer) != 0 {
  4355. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  4356. if errcodema == gorm.ErrRecordNotFound {
  4357. manufactur := models.Manufacturer{
  4358. OrgId: orgId,
  4359. Status: 1,
  4360. ManufacturerName: manufacturer,
  4361. Ctime: time.Now().Unix(),
  4362. Creater: adminUser.AdminUser.Id,
  4363. }
  4364. service.CreateManufacturer(&manufactur)
  4365. }
  4366. }
  4367. var manufacturer_id int64
  4368. manufacturList, _ := service.GetAllManufacturerList(orgId)
  4369. for _, it := range manufacturList {
  4370. if manufacturer == it.ManufacturerName {
  4371. manufacturer_id = it.ID
  4372. }
  4373. }
  4374. drug.Manufacturer = manufacturer_id
  4375. dealer := goodNameM["dealer"].(string)
  4376. if len(dealer) != 0 {
  4377. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  4378. if errcodesdealer == gorm.ErrRecordNotFound {
  4379. dealerconfig := models.Dealer{
  4380. DealerName: dealer,
  4381. Status: 1,
  4382. OrgId: orgId,
  4383. Ctime: time.Now().Unix(),
  4384. Creater: adminUser.AdminUser.Id,
  4385. }
  4386. service.CreateDealer(&dealerconfig)
  4387. }
  4388. }
  4389. var dealer_id int64
  4390. dealerList, _ := service.GetAllDealerList(orgId)
  4391. for _, it := range dealerList {
  4392. if dealer == it.DealerName {
  4393. dealer_id = it.ID
  4394. }
  4395. }
  4396. drug.Dealer = dealer_id
  4397. delivery_way := goodNameM["delivery_way"].(string)
  4398. if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
  4399. err_log := models.ExportErrLog{
  4400. LogType: 4,
  4401. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4402. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  4403. Status: 1,
  4404. CreateTime: time.Now().Unix(),
  4405. UpdateTime: time.Now().Unix(),
  4406. ExportTime: time.Now().Unix(),
  4407. }
  4408. service.CreateExportErrLog(&err_log)
  4409. continue
  4410. }
  4411. drug.DeliveryWay = delivery_way
  4412. execution_frequency := goodNameM["execution_frequency"].(string)
  4413. if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
  4414. err_log := models.ExportErrLog{
  4415. LogType: 4,
  4416. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4417. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  4418. Status: 1,
  4419. CreateTime: time.Now().Unix(),
  4420. UpdateTime: time.Now().Unix(),
  4421. ExportTime: time.Now().Unix(),
  4422. }
  4423. service.CreateExportErrLog(&err_log)
  4424. continue
  4425. }
  4426. drug.ExecutionFrequency = execution_frequency
  4427. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  4428. drug.LmtUsedFlag = lmt_used_flags
  4429. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  4430. utils.ErrorLog("drug_alias")
  4431. return
  4432. }
  4433. drug_alias, _ := goodNameM["drug_alias"].(string)
  4434. drug.DrugAlias = drug_alias
  4435. drug_category := goodNameM["drug_category"].(string)
  4436. var drugCategory = "药品类别"
  4437. var drug_category_id int64
  4438. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  4439. if len(drug_category) != 0 {
  4440. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  4441. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  4442. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  4443. dataconfig := models.DictDataconfig{
  4444. ParentId: drugCategoryConfig.ID,
  4445. Module: "system",
  4446. OrgId: orgId,
  4447. Name: drug_category,
  4448. FieldName: "",
  4449. Value: drugCategoryConfigSix.Value + 1,
  4450. CreatedTime: "",
  4451. UpdatedTime: "",
  4452. CreateUserId: adminUser.AdminUser.Id,
  4453. Status: 1,
  4454. Remark: "",
  4455. DeleteIdSystem: 0,
  4456. Title: "",
  4457. Content: "",
  4458. Order: 0,
  4459. Code: "",
  4460. }
  4461. service.CreatedDicConfig(&dataconfig)
  4462. }
  4463. }
  4464. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  4465. fmt.Println("drugCategoryList", drugCategoryList)
  4466. for _, it := range drugCategoryList {
  4467. if drug_category == it.Name {
  4468. drug_category_id = int64(it.Value)
  4469. }
  4470. }
  4471. drug.DrugCategory = drug_category_id
  4472. drug_control := goodNameM["drug_control"].(string)
  4473. var drugControl = "开药控制"
  4474. var drug_control_id int64
  4475. drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
  4476. if len(drug_control) != 0 {
  4477. _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
  4478. if errcodesdrugcontrol == gorm.ErrRecordNotFound {
  4479. drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
  4480. dataconfig := models.DictDataconfig{
  4481. ParentId: drugContorlConfig.ID,
  4482. Module: "system",
  4483. OrgId: orgId,
  4484. Name: drug_control,
  4485. FieldName: "",
  4486. Value: drugContorlConfigOne.Value + 1,
  4487. CreatedTime: "",
  4488. UpdatedTime: "",
  4489. CreateUserId: adminUser.AdminUser.Id,
  4490. Status: 1,
  4491. Remark: "",
  4492. DeleteIdSystem: 0,
  4493. Title: "",
  4494. Content: "",
  4495. Order: 0,
  4496. Code: "",
  4497. }
  4498. service.CreatedDicConfig(&dataconfig)
  4499. }
  4500. }
  4501. drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
  4502. for _, it := range drugContorlList {
  4503. if drug_control == it.Name {
  4504. drug_control_id = int64(it.Value)
  4505. }
  4506. }
  4507. drug.DrugControl = drug_control_id
  4508. number := goodNameM["number"].(string)
  4509. drug.Number = number
  4510. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  4511. if len(drugDoseUnit) != 0 {
  4512. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  4513. if errcodedataconfig == gorm.ErrRecordNotFound {
  4514. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  4515. dataconfig := models.Dataconfig{
  4516. ParentId: dataConfig.ID,
  4517. Module: "hemodialysis",
  4518. OrgId: orgId,
  4519. Name: drugDoseUnit,
  4520. FieldName: "",
  4521. Value: childConfig.Value + 1,
  4522. CreatedTime: "",
  4523. UpdatedTime: "",
  4524. CreateUserId: adminUser.AdminUser.Id,
  4525. Status: 1,
  4526. Remark: "",
  4527. DeleteIdSystem: 0,
  4528. Title: "",
  4529. Content: "",
  4530. Order: 0,
  4531. Code: "",
  4532. FieldType: 0,
  4533. }
  4534. service.CreateDataConfig(&dataconfig)
  4535. }
  4536. }
  4537. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  4538. for _, it := range list {
  4539. if drugDoseUnit == it.Name {
  4540. unit_id = int64(it.Value)
  4541. }
  4542. }
  4543. drug.DrugDoseUnit = unit_id
  4544. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  4545. var statisticsCategory = "统计分类"
  4546. var statistics_category_id int64
  4547. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  4548. if len(statistics_category) != 0 {
  4549. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  4550. if errcodestatistc == gorm.ErrRecordNotFound {
  4551. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  4552. dataconfig := models.DictDataconfig{
  4553. ParentId: statistcConfig.ID,
  4554. Module: "system",
  4555. OrgId: orgId,
  4556. Name: statistics_category,
  4557. FieldName: "",
  4558. Value: staConfig.Value + 1,
  4559. CreatedTime: "",
  4560. UpdatedTime: "",
  4561. CreateUserId: adminUser.AdminUser.Id,
  4562. Status: 1,
  4563. Remark: "",
  4564. DeleteIdSystem: 0,
  4565. Title: "",
  4566. Content: "",
  4567. Order: 0,
  4568. Code: "",
  4569. }
  4570. service.CreatedDicConfig(&dataconfig)
  4571. }
  4572. }
  4573. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  4574. for _, it := range statisticsCategoryList {
  4575. if statistics_category == it.Name {
  4576. statistics_category_id = int64(it.Value)
  4577. }
  4578. }
  4579. drug.StatisticsCategory = statistics_category_id
  4580. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  4581. drug.HospApprFlag = hosp_appr_flag
  4582. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  4583. drug.MedicalInsuranceNumber = medical_insurance_number
  4584. pharmacology_category := goodNameM["pharmacology_category"].(string)
  4585. var pharmacology = "药理分类"
  4586. var pharmacology_category_id int64
  4587. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  4588. if len(pharmacology_category) != 0 {
  4589. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  4590. if errcodespharmacology == gorm.ErrRecordNotFound {
  4591. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  4592. dataconfig := models.DictDataconfig{
  4593. ParentId: pharmacologyConfig.ID,
  4594. Module: "system",
  4595. OrgId: orgId,
  4596. Name: pharmacology_category,
  4597. FieldName: "",
  4598. Value: dicConfig.Value + 1,
  4599. CreatedTime: "",
  4600. UpdatedTime: "",
  4601. CreateUserId: adminUser.AdminUser.Id,
  4602. Status: 1,
  4603. Remark: "",
  4604. DeleteIdSystem: 0,
  4605. Title: "",
  4606. Content: "",
  4607. Order: 0,
  4608. Code: "",
  4609. }
  4610. service.CreatedDicConfig(&dataconfig)
  4611. }
  4612. }
  4613. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  4614. for _, it := range pharmacologyList {
  4615. if pharmacology_category == it.Name {
  4616. pharmacology_category_id = int64(it.Value)
  4617. }
  4618. }
  4619. drug.PharmacologyCategory = pharmacology_category_id
  4620. code := goodNameM["code"].(string)
  4621. drug.Code = code
  4622. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  4623. drug.IsSpecialDiseases = is_special_diseases
  4624. is_record := int64(goodNameM["is_record"].(float64))
  4625. drug.IsRecord = is_record
  4626. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  4627. drug.PrescriptionMark = prescription_mark
  4628. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  4629. drug.SocialSecurityDirectoryCode = social_security_directory_code
  4630. record_date := goodNameM["record_date"].(string)
  4631. timeLayout := "2006-01-02"
  4632. loc, _ := time.LoadLocation("Local")
  4633. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4634. drug.RecordDate = theTime.Unix()
  4635. drug_remark := goodNameM["drug_remark"].(string)
  4636. drug.DrugRemark = drug_remark
  4637. drug_status := goodNameM["drug_status"].(string)
  4638. drug.DrugStatus = drug_status
  4639. limit_remark := goodNameM["limit_remark"].(string)
  4640. drug.LimitRemark = limit_remark
  4641. drugList = append(drugList, &drug)
  4642. }
  4643. export_time := time.Now().Unix()
  4644. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  4645. if len(drugList) > 0 {
  4646. for _, item := range drugList {
  4647. goodInfo := models.BaseDrugLib{
  4648. DrugName: item.DrugName,
  4649. DrugAlias: item.DrugAlias,
  4650. DrugSpec: item.DrugSpec,
  4651. DrugType: item.DrugType,
  4652. DrugStockLimit: item.DrugStockLimit,
  4653. DrugOriginPlace: item.DrugOriginPlace,
  4654. DrugDosageForm: item.DrugDosageForm,
  4655. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  4656. MaxUnit: item.MaxUnit,
  4657. MinUnit: item.MinUnit,
  4658. UnitMatrixing: item.UnitMatrixing,
  4659. RetailPrice: item.RetailPrice,
  4660. LastPrice: item.LastPrice,
  4661. DrugClassify: item.DrugClassify,
  4662. Manufacturer: item.Manufacturer,
  4663. Dealer: item.Dealer,
  4664. OrgId: orgId,
  4665. Status: 1,
  4666. Ctime: time.Now().Unix(),
  4667. Pinyin: item.Pinyin,
  4668. Wubi: item.Wubi,
  4669. DrugAliasPinyin: item.DrugAliasPinyin,
  4670. DrugAliasWubi: item.DrugAliasWubi,
  4671. DrugControl: item.DrugControl,
  4672. Number: item.Number,
  4673. HospApprFlag: item.HospApprFlag,
  4674. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  4675. PharmacologyCategory: item.PharmacologyCategory,
  4676. StatisticsCategory: item.StatisticsCategory,
  4677. Code: item.Code,
  4678. IsSpecialDiseases: item.IsSpecialDiseases,
  4679. IsRecord: item.IsRecord,
  4680. PrescriptionMark: item.PrescriptionMark,
  4681. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  4682. RecordDate: item.RecordDate,
  4683. DrugRemark: item.DrugRemark,
  4684. DrugStatus: item.DrugStatus,
  4685. LimitRemark: item.LimitRemark,
  4686. DrugCategory: item.DrugCategory,
  4687. DrugDose: item.DrugDose,
  4688. DrugDoseUnit: item.DrugDoseUnit,
  4689. LmtUsedFlag: item.LmtUsedFlag,
  4690. DrugDay: item.DrugDay,
  4691. DeliveryWay: item.DeliveryWay,
  4692. ExecutionFrequency: item.ExecutionFrequency,
  4693. DoseUnit: item.DoseUnit,
  4694. Dose: item.Dose,
  4695. MinNumber: item.MinNumber,
  4696. }
  4697. //查询同种药品同种规格是否存在
  4698. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.DoseUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  4699. if drugerror == gorm.ErrRecordNotFound {
  4700. service.CreateDrugsInfomation(&goodInfo)
  4701. } else if drugerror == nil {
  4702. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  4703. }
  4704. log := models.ExportLog{
  4705. LogType: 4,
  4706. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4707. TotalNum: int64(len(total_goods)),
  4708. FailNum: int64(len(errLogs)),
  4709. SuccessNum: int64(len(drugList)),
  4710. CreateTime: time.Now().Unix(),
  4711. UpdateTime: time.Now().Unix(),
  4712. ExportTime: export_time,
  4713. Status: 1,
  4714. }
  4715. service.CreateExportLog(&log)
  4716. this.ServeSuccessJSON(map[string]interface{}{
  4717. "msg": "导入成功",
  4718. "total_num": len(total_goods),
  4719. "success_num": len(drugList),
  4720. "fail_num": int64(len(errLogs)),
  4721. })
  4722. }
  4723. } else {
  4724. log := models.ExportLog{
  4725. LogType: 4,
  4726. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4727. TotalNum: int64(len(total_goods)),
  4728. FailNum: int64(len(errLogs)),
  4729. SuccessNum: int64(len(drugList)),
  4730. CreateTime: time.Now().Unix(),
  4731. UpdateTime: time.Now().Unix(),
  4732. ExportTime: export_time,
  4733. Status: 1,
  4734. }
  4735. service.CreateExportLog(&log)
  4736. this.ServeSuccessJSON(map[string]interface{}{
  4737. "msg": "导入成功",
  4738. "total_num": len(total_goods),
  4739. "success_num": len(drugList),
  4740. "fail_num": int64(len(errLogs)),
  4741. })
  4742. }
  4743. }
  4744. }
  4745. func (this *StockManagerApiController) GetInitializtion() {
  4746. orgId := this.GetAdminUserInfo().CurrentOrgId
  4747. var drugCategory = "药品类别"
  4748. var drugType = "药品类型"
  4749. var drugDosageForm = "药品剂型"
  4750. var medicalInsuranceLevel = "医保等级"
  4751. var drugControl = "开药控制"
  4752. var drugClassify = "药物分类"
  4753. var statisticsCategory = "统计分类"
  4754. var pharmacologyCategory = "药理分类"
  4755. var goodKind = "耗材种类"
  4756. var tubeColor = "试管颜色"
  4757. var costClassify = "费用类别"
  4758. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  4759. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  4760. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  4761. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  4762. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  4763. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  4764. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  4765. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  4766. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  4767. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  4768. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  4769. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  4770. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  4771. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  4772. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  4773. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  4774. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  4775. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  4776. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  4777. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  4778. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  4779. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  4780. this.ServeSuccessJSON(map[string]interface{}{
  4781. "drugCategoryList": drugCategoryList,
  4782. "drugTypeList": drugTypeList,
  4783. "drugDosageFormList": drugDosageFormList,
  4784. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  4785. "drugControlList": drugControlList,
  4786. "drugClassifyList": drugClassifyList,
  4787. "statisticsCategoryList": statisticsCategoryList,
  4788. "pharmacologyCategoryList": pharmacologyCategoryList,
  4789. "goodKindList": goodKindList,
  4790. "tubeColorList": tubeColorList,
  4791. "costClassifyList": costClassifyList,
  4792. })
  4793. }
  4794. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  4795. adminUserInfo := this.GetAdminUserInfo()
  4796. orgId := adminUserInfo.CurrentOrgId
  4797. list, _ := service.GetWarehouseOrderInfoList(orgId)
  4798. this.ServeSuccessJSON(map[string]interface{}{
  4799. "list": list,
  4800. })
  4801. }
  4802. func (this *StockManagerApiController) PostSearchGoodList() {
  4803. keyword := this.GetString("keyword")
  4804. adminUserInfo := this.GetAdminUserInfo()
  4805. orgId := adminUserInfo.CurrentOrgId
  4806. list, _ := service.GetSearchGoodList(keyword, orgId)
  4807. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4808. dealerList, _ := service.GetAllDealerList(orgId)
  4809. this.ServeSuccessJSON(map[string]interface{}{
  4810. "list": list,
  4811. "manufacturerList": manufacturerList,
  4812. "dealerList": dealerList,
  4813. })
  4814. }
  4815. func (this *StockManagerApiController) GetAllStockList() {
  4816. page, _ := this.GetInt64("page", -1)
  4817. limit, _ := this.GetInt64("limit", -1)
  4818. start_time := this.GetString("start_time")
  4819. end_time := this.GetString("end_time")
  4820. types, _ := this.GetInt64("type", 0)
  4821. keywords := this.GetString("keywords")
  4822. good_id, _ := this.GetInt64("good_id")
  4823. storehouse_id, _ := this.GetInt64("storehouse_id")
  4824. timeLayout := "2006-01-02"
  4825. loc, _ := time.LoadLocation("Local")
  4826. var startTime int64
  4827. if len(start_time) > 0 {
  4828. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4829. if err != nil {
  4830. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4831. return
  4832. }
  4833. startTime = theTime.Unix()
  4834. }
  4835. var endTime int64
  4836. if len(end_time) > 0 {
  4837. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4838. if err != nil {
  4839. utils.ErrorLog(err.Error())
  4840. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4841. return
  4842. }
  4843. endTime = theTime.Unix()
  4844. }
  4845. adminUserInfo := this.GetAdminUserInfo()
  4846. orgId := adminUserInfo.CurrentOrgId
  4847. list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId, good_id, storehouse_id)
  4848. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4849. this.ServeSuccessJSON(map[string]interface{}{
  4850. "list": list,
  4851. "total": total,
  4852. "manufacturerList": manufacturerList,
  4853. })
  4854. }
  4855. func (this *StockManagerApiController) GetStockListById() {
  4856. id, _ := this.GetInt64("id")
  4857. adminUserInfo := this.GetAdminUserInfo()
  4858. orgId := adminUserInfo.CurrentOrgId
  4859. limit, _ := this.GetInt64("limit")
  4860. page, _ := this.GetInt64("page")
  4861. timeLayout := "2006-01-02"
  4862. loc, _ := time.LoadLocation("Local")
  4863. start_time := this.GetString("start_time")
  4864. end_time := this.GetString("end_time")
  4865. var startTime int64
  4866. if len(start_time) > 0 {
  4867. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4868. if err != nil {
  4869. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4870. return
  4871. }
  4872. startTime = theTime.Unix()
  4873. }
  4874. var endTime int64
  4875. if len(end_time) > 0 {
  4876. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4877. if err != nil {
  4878. utils.ErrorLog(err.Error())
  4879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4880. return
  4881. }
  4882. endTime = theTime.Unix()
  4883. }
  4884. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4885. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime)
  4886. houseList, _ := service.GetAllStoreHouseList(orgId)
  4887. this.ServeSuccessJSON(map[string]interface{}{
  4888. "list": list,
  4889. "total": total,
  4890. "manufacturerList": manufacturerList,
  4891. "houseList": houseList,
  4892. })
  4893. }
  4894. func (this *StockManagerApiController) GetStockOutList() {
  4895. id, _ := this.GetInt64("id")
  4896. adminUserInfo := this.GetAdminUserInfo()
  4897. orgId := adminUserInfo.CurrentOrgId
  4898. limit, _ := this.GetInt64("limit")
  4899. page, _ := this.GetInt64("page")
  4900. timeLayout := "2006-01-02"
  4901. loc, _ := time.LoadLocation("Local")
  4902. start_time := this.GetString("start_time")
  4903. end_time := this.GetString("end_time")
  4904. is_sys, _ := this.GetInt64("is_sys")
  4905. var startTime int64
  4906. if len(start_time) > 0 {
  4907. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4908. if err != nil {
  4909. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4910. return
  4911. }
  4912. startTime = theTime.Unix()
  4913. }
  4914. var endTime int64
  4915. if len(end_time) > 0 {
  4916. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4917. if err != nil {
  4918. utils.ErrorLog(err.Error())
  4919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4920. return
  4921. }
  4922. endTime = theTime.Unix()
  4923. }
  4924. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  4925. this.ServeSuccessJSON(map[string]interface{}{
  4926. "outList": outList,
  4927. "total": total,
  4928. })
  4929. }
  4930. func (this *StockManagerApiController) GetStockDrugCount() {
  4931. adminUserInfo := this.GetAdminUserInfo()
  4932. orgId := adminUserInfo.CurrentOrgId
  4933. fmt.Println(orgId)
  4934. timeLayout := "2006-01-02"
  4935. loc, _ := time.LoadLocation("Local")
  4936. start_time := this.GetString("start_time")
  4937. end_time := this.GetString("end_time")
  4938. var startTime int64
  4939. if len(start_time) > 0 {
  4940. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4941. if err != nil {
  4942. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4943. return
  4944. }
  4945. startTime = theTime.Unix()
  4946. }
  4947. var endTime int64
  4948. if len(end_time) > 0 {
  4949. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4950. if err != nil {
  4951. utils.ErrorLog(err.Error())
  4952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4953. return
  4954. }
  4955. endTime = theTime.Unix()
  4956. }
  4957. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  4958. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  4959. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  4960. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  4961. this.ServeSuccessJSON(map[string]interface{}{
  4962. "count": count,
  4963. "outList": outList,
  4964. "autoCount": autoCount,
  4965. "totalCount": totalCount,
  4966. })
  4967. }
  4968. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  4969. ids := this.GetString("id")
  4970. idsArray := strings.Split(ids, ",")
  4971. orgId := this.GetAdminUserInfo().CurrentOrgId
  4972. order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
  4973. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  4974. this.ServeSuccessJSON(map[string]interface{}{
  4975. "list": list,
  4976. "order": order,
  4977. })
  4978. }
  4979. func (this *StockManagerApiController) GetOrderDetailById() {
  4980. id, _ := this.GetInt64("id")
  4981. good_id, _ := this.GetInt64("good_id")
  4982. record_time, _ := this.GetInt64("record_time")
  4983. orgId := this.GetAdminUserInfo().CurrentOrgId
  4984. //自动出库
  4985. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  4986. //手动出库
  4987. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  4988. stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
  4989. if err == nil {
  4990. this.ServeSuccessJSON(map[string]interface{}{
  4991. "list": userDetails,
  4992. "total": total,
  4993. "info": info,
  4994. "stockFlowList": stockFlowList,
  4995. })
  4996. } else {
  4997. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4998. return
  4999. }
  5000. }
  5001. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  5002. id, _ := this.GetInt64("id", 0)
  5003. orgId := this.GetAdminUserInfo().CurrentOrgId
  5004. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  5005. out, _ := service.GetGoodWarehouseOutById(id, orgId)
  5006. storelist, _ := service.GetAllStoreHouseList(orgId)
  5007. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  5008. dealerList, _ := service.GetAllDealerList(orgId)
  5009. goodType, _ := service.GetAllGoodType(orgId)
  5010. appId := this.GetAdminUserInfo().CurrentAppId
  5011. doctorlist, _ := service.GetAllDoctorListSix(orgId, appId)
  5012. this.ServeSuccessJSON(map[string]interface{}{
  5013. "list": warehouseOutInfo,
  5014. "dealerList": dealerList,
  5015. "manufacturerList": manufacturerList,
  5016. "goodType": goodType,
  5017. "out": out,
  5018. "storelist": storelist,
  5019. "doctorlist": doctorlist,
  5020. })
  5021. }
  5022. func (this *StockManagerApiController) GetExprotStockList() {
  5023. adminUserInfo := this.GetAdminUserInfo()
  5024. orgId := adminUserInfo.CurrentOrgId
  5025. timeLayout := "2006-01-02"
  5026. loc, _ := time.LoadLocation("Local")
  5027. start_time := this.GetString("start_time")
  5028. end_time := this.GetString("end_time")
  5029. storehouse_id, _ := this.GetInt64("storehouse_id")
  5030. idArray := this.GetString("id")
  5031. ids := strings.Split(idArray, ",")
  5032. var startTime int64
  5033. if len(start_time) > 0 {
  5034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5035. if err != nil {
  5036. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5037. return
  5038. }
  5039. startTime = theTime.Unix()
  5040. }
  5041. var endTime int64
  5042. if len(end_time) > 0 {
  5043. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5044. if err != nil {
  5045. utils.ErrorLog(err.Error())
  5046. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5047. return
  5048. }
  5049. endTime = theTime.Unix()
  5050. }
  5051. fmt.Println("ids2222222222222222", ids)
  5052. list, _ := service.GetExprotStockListTwenty(orgId, ids, startTime, endTime, storehouse_id)
  5053. this.ServeSuccessJSON(map[string]interface{}{
  5054. "list": list,
  5055. })
  5056. }
  5057. func (this *StockManagerApiController) GetOutExprotList() {
  5058. adminUserInfo := this.GetAdminUserInfo()
  5059. orgId := adminUserInfo.CurrentOrgId
  5060. timeLayout := "2006-01-02"
  5061. loc, _ := time.LoadLocation("Local")
  5062. start_time := this.GetString("start_time")
  5063. end_time := this.GetString("end_time")
  5064. idArray := this.GetString("id")
  5065. ids := strings.Split(idArray, ",")
  5066. fmt.Println("ids2222222222", ids)
  5067. var startTime int64
  5068. if len(start_time) > 0 {
  5069. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5070. if err != nil {
  5071. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5072. return
  5073. }
  5074. startTime = theTime.Unix()
  5075. }
  5076. var endTime int64
  5077. if len(end_time) > 0 {
  5078. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5079. if err != nil {
  5080. utils.ErrorLog(err.Error())
  5081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5082. return
  5083. }
  5084. endTime = theTime.Unix()
  5085. }
  5086. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  5087. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  5088. this.ServeSuccessJSON(map[string]interface{}{
  5089. "list": list,
  5090. "count": outCount,
  5091. })
  5092. }
  5093. func (this *StockManagerApiController) GetSingleCancelOrder() {
  5094. id, _ := this.GetInt64("id")
  5095. adminUserInfo := this.GetAdminUserInfo()
  5096. orgId := adminUserInfo.CurrentOrgId
  5097. order, _ := service.GetSingleCancelOrder(id, orgId)
  5098. this.ServeSuccessJSON(map[string]interface{}{
  5099. "list": order,
  5100. })
  5101. }
  5102. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  5103. id := this.GetString("id")
  5104. idStr := strings.Split(id, ",")
  5105. orgId := this.GetAdminUserInfo().CurrentOrgId
  5106. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  5107. this.ServeSuccessJSON(map[string]interface{}{
  5108. "list": list,
  5109. })
  5110. }
  5111. func (this *StockManagerApiController) GetStockBatchNumber() {
  5112. id, _ := this.GetInt64("id")
  5113. orgId := this.GetAdminUserInfo().CurrentOrgId
  5114. list, _ := service.GetStockBatchNumber(id, orgId)
  5115. this.ServeSuccessJSON(map[string]interface{}{
  5116. "list": list,
  5117. })
  5118. }
  5119. func (this *StockManagerApiController) GetStockFlow() {
  5120. limit, _ := this.GetInt64("limit")
  5121. page, _ := this.GetInt64("page")
  5122. good_id, _ := this.GetInt64("good_id")
  5123. consumable_type, _ := this.GetInt64("is_sys")
  5124. adminUserInfo := this.GetAdminUserInfo()
  5125. orgId := adminUserInfo.CurrentOrgId
  5126. timeLayout := "2006-01-02"
  5127. loc, _ := time.LoadLocation("Local")
  5128. start_time := this.GetString("start_time")
  5129. end_time := this.GetString("end_time")
  5130. var startTime int64
  5131. if len(start_time) > 0 {
  5132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5133. if err != nil {
  5134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5135. return
  5136. }
  5137. startTime = theTime.Unix()
  5138. }
  5139. var endTime int64
  5140. if len(end_time) > 0 {
  5141. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5142. if err != nil {
  5143. utils.ErrorLog(err.Error())
  5144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5145. return
  5146. }
  5147. endTime = theTime.Unix()
  5148. }
  5149. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  5150. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  5151. good, _ := service.GetGoodInformationByGoodId(good_id)
  5152. houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  5153. this.ServeSuccessJSON(map[string]interface{}{
  5154. "list": list,
  5155. "total": total,
  5156. "manufacturerList": manufacturerList,
  5157. "good": good,
  5158. "houseList": houseList,
  5159. })
  5160. }
  5161. func (this *StockManagerApiController) GetCancelExportList() {
  5162. adminUserInfo := this.GetAdminUserInfo()
  5163. orgId := adminUserInfo.CurrentOrgId
  5164. timeLayout := "2006-01-02"
  5165. loc, _ := time.LoadLocation("Local")
  5166. start_time := this.GetString("start_time")
  5167. end_time := this.GetString("end_time")
  5168. idArray := this.GetString("order_id")
  5169. fmt.Println("232323232323232232", idArray)
  5170. ids := strings.Split(idArray, ",")
  5171. var startTime int64
  5172. if len(start_time) > 0 {
  5173. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5174. if err != nil {
  5175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5176. return
  5177. }
  5178. startTime = theTime.Unix()
  5179. }
  5180. var endTime int64
  5181. if len(end_time) > 0 {
  5182. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5183. if err != nil {
  5184. utils.ErrorLog(err.Error())
  5185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5186. return
  5187. }
  5188. endTime = theTime.Unix()
  5189. }
  5190. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  5191. this.ServeSuccessJSON(map[string]interface{}{
  5192. "list": list,
  5193. })
  5194. }
  5195. func (this *StockManagerApiController) GetSearchGoodWarehouseList() {
  5196. keyword := this.GetString("keyword")
  5197. storehouse_id, _ := this.GetInt64("storehouse_id")
  5198. orgId := this.GetAdminUserInfo().CurrentOrgId
  5199. list, _ := service.GetSearchGoodWarehouseList(keyword, orgId, storehouse_id)
  5200. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  5201. dealerList, _ := service.GetAllDealerList(orgId)
  5202. this.ServeSuccessJSON(map[string]interface{}{
  5203. "list": list,
  5204. "manufacturerList": manufacturerList,
  5205. "dealerList": dealerList,
  5206. })
  5207. }
  5208. func (this *StockManagerApiController) SaveAdjuestPrice() {
  5209. timeLayout := "2006-01-02"
  5210. loc, _ := time.LoadLocation("Local")
  5211. dataBody := make(map[string]interface{}, 0)
  5212. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5213. if err != nil {
  5214. utils.ErrorLog(err.Error())
  5215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5216. return
  5217. }
  5218. tableData, _ := dataBody["tableData"].([]interface{})
  5219. if len(tableData) > 0 {
  5220. for _, item := range tableData {
  5221. items := item.(map[string]interface{})
  5222. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5223. utils.ErrorLog("good_name")
  5224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5225. return
  5226. }
  5227. good_name := items["good_name"].(string)
  5228. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5229. utils.ErrorLog("good_name")
  5230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5231. return
  5232. }
  5233. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  5234. utils.ErrorLog("packing_price")
  5235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5236. return
  5237. }
  5238. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  5239. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5240. utils.ErrorLog("warehousing_order")
  5241. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5242. return
  5243. }
  5244. warehousing_order := items["warehousing_order"].(string)
  5245. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  5246. utils.ErrorLog("license_number")
  5247. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5248. return
  5249. }
  5250. license_number := items["license_number"].(string)
  5251. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  5252. utils.ErrorLog("dealer")
  5253. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5254. return
  5255. }
  5256. dealer := items["dealer"].(string)
  5257. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  5258. utils.ErrorLog("manufacturer")
  5259. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5260. return
  5261. }
  5262. manufacturer := items["manufacturer"].(string)
  5263. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5264. utils.ErrorLog("specification_name")
  5265. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5266. return
  5267. }
  5268. specification_name := items["specification_name"].(string)
  5269. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  5270. utils.ErrorLog("remark")
  5271. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5272. return
  5273. }
  5274. remark := items["remark"].(string)
  5275. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5276. utils.ErrorLog("warehousing_unit")
  5277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5278. return
  5279. }
  5280. warehousing_unit := items["warehousing_unit"].(string)
  5281. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  5282. utils.ErrorLog("buy_price")
  5283. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5284. return
  5285. }
  5286. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  5287. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  5288. utils.ErrorLog("count")
  5289. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5290. return
  5291. }
  5292. count := int64(items["count"].(float64))
  5293. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  5294. utils.ErrorLog("new_price")
  5295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5296. return
  5297. }
  5298. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  5299. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5300. utils.ErrorLog("good_id")
  5301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5302. return
  5303. }
  5304. good_id := int64(items["good_id"].(float64))
  5305. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  5306. utils.ErrorLog("start_time")
  5307. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5308. return
  5309. }
  5310. var startTime int64
  5311. start_time := items["start_time"].(string)
  5312. if len(start_time) > 0 {
  5313. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5314. if err != nil {
  5315. fmt.Println(err)
  5316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5317. return
  5318. }
  5319. startTime = theTime.Unix()
  5320. }
  5321. orgId := this.GetAdminUserInfo().CurrentOrgId
  5322. adjustprice := models.XtStockAdjustPrice{
  5323. GoodName: good_name,
  5324. SpecificationName: specification_name,
  5325. WarehousingUnit: warehousing_unit,
  5326. Count: count,
  5327. BuyPrice: buy_price,
  5328. PackingPrice: packing_price,
  5329. NewPrice: new_price,
  5330. Manufacturer: manufacturer,
  5331. Dealer: dealer,
  5332. Remark: remark,
  5333. GoodId: good_id,
  5334. UserOrgId: orgId,
  5335. Ctime: time.Now().Unix(),
  5336. Mtime: 0,
  5337. Status: 1,
  5338. WarehousingOrder: warehousing_order,
  5339. LicenseNumber: license_number,
  5340. StartTime: startTime,
  5341. Creater: this.GetAdminUserInfo().AdminUser.Id,
  5342. CheckerStatus: 2,
  5343. }
  5344. service.CreateAdjustPrice(&adjustprice)
  5345. }
  5346. }
  5347. this.ServeSuccessJSON(map[string]interface{}{
  5348. "msg": "保存成功!",
  5349. })
  5350. }
  5351. func (this *StockManagerApiController) GetAllStockPrice() {
  5352. timeLayout := "2006-01-02"
  5353. loc, _ := time.LoadLocation("Local")
  5354. dataBody := make(map[string]interface{}, 0)
  5355. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5356. fmt.Println(err)
  5357. orgId := this.GetAdminUserInfo().CurrentOrgId
  5358. keyword := this.GetString("keyword")
  5359. start_time := this.GetString("start_time")
  5360. end_time := this.GetString("end_time")
  5361. limit, _ := this.GetInt64("limit")
  5362. page, _ := this.GetInt64("page")
  5363. var startTime int64
  5364. if len(start_time) > 0 {
  5365. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5366. if err != nil {
  5367. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5368. return
  5369. }
  5370. startTime = theTime.Unix()
  5371. }
  5372. var endTime int64
  5373. if len(end_time) > 0 {
  5374. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5375. if err != nil {
  5376. utils.ErrorLog(err.Error())
  5377. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5378. return
  5379. }
  5380. endTime = theTime.Unix()
  5381. }
  5382. list, total, _ := service.GetAllStockPrice(orgId, startTime, endTime, keyword, limit, page)
  5383. doctor, _ := service.GetAllDoctorThree(orgId)
  5384. this.ServeSuccessJSON(map[string]interface{}{
  5385. "list": list,
  5386. "doctor": doctor,
  5387. "total": total,
  5388. })
  5389. }
  5390. func (this *StockManagerApiController) SaveCheckPrice() {
  5391. timeLayout := "2006-01-02"
  5392. loc, _ := time.LoadLocation("Local")
  5393. dataBody := make(map[string]interface{}, 0)
  5394. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5395. fmt.Println(err)
  5396. idstr := this.GetString("ids")
  5397. ids := strings.Split(idstr, ",")
  5398. check_time := this.GetString("check_time")
  5399. var checkTime int64
  5400. if len(check_time) > 0 {
  5401. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5402. if err != nil {
  5403. fmt.Println(err)
  5404. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5405. return
  5406. }
  5407. checkTime = theTime.Unix()
  5408. }
  5409. checker, _ := this.GetInt64("checker")
  5410. adjustPrice := models.XtStockAdjustPrice{
  5411. Checker: checker,
  5412. CheckerStatus: 1,
  5413. CheckerTime: checkTime,
  5414. }
  5415. err = service.UpdateAdjustPrice(ids, adjustPrice)
  5416. fmt.Println(err)
  5417. list, _ := service.GetAdjustCheckPriceList(ids)
  5418. fmt.Println("list2333223323232323232323", list)
  5419. for _, item := range list {
  5420. info := models.GoodInfo{
  5421. PackingPrice: item.NewPrice,
  5422. BuyPrice: item.NewPrice,
  5423. }
  5424. err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
  5425. fmt.Println(err)
  5426. }
  5427. this.ServeSuccessJSON(map[string]interface{}{
  5428. "adjustPrice": adjustPrice,
  5429. })
  5430. }
  5431. func (this *StockManagerApiController) GetAdjustPriceById() {
  5432. ids := this.GetString("ids")
  5433. fmt.Println("ids23232233223233232", ids)
  5434. splitIds := strings.Split(ids, ",")
  5435. list, _ := service.GetAdjustPricebyIdOne(splitIds)
  5436. fmt.Println("list2322322323", list)
  5437. this.ServeSuccessJSON(map[string]interface{}{
  5438. "list": list,
  5439. })
  5440. }
  5441. func (this *StockManagerApiController) SaveReportStock() {
  5442. timeLayout := "2006-01-02"
  5443. loc, _ := time.LoadLocation("Local")
  5444. dataBody := make(map[string]interface{}, 0)
  5445. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5446. if err != nil {
  5447. utils.ErrorLog(err.Error())
  5448. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5449. return
  5450. }
  5451. tableData, _ := dataBody["tableData"].([]interface{})
  5452. if len(tableData) > 0 {
  5453. for _, item := range tableData {
  5454. items := item.(map[string]interface{})
  5455. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5456. utils.ErrorLog("good_name")
  5457. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5458. return
  5459. }
  5460. good_name := items["good_name"].(string)
  5461. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5462. utils.ErrorLog("good_name")
  5463. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5464. return
  5465. }
  5466. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  5467. utils.ErrorLog("packing_price")
  5468. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5469. return
  5470. }
  5471. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  5472. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5473. utils.ErrorLog("warehousing_order")
  5474. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5475. return
  5476. }
  5477. warehousing_order := items["warehousing_order"].(string)
  5478. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  5479. utils.ErrorLog("license_number")
  5480. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5481. return
  5482. }
  5483. license_number := items["license_number"].(string)
  5484. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  5485. utils.ErrorLog("dealer")
  5486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5487. return
  5488. }
  5489. dealer := items["dealer"].(string)
  5490. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  5491. utils.ErrorLog("manufacturer")
  5492. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5493. return
  5494. }
  5495. manufacturer := items["manufacturer"].(string)
  5496. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5497. utils.ErrorLog("specification_name")
  5498. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5499. return
  5500. }
  5501. specification_name := items["specification_name"].(string)
  5502. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  5503. utils.ErrorLog("remark")
  5504. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5505. return
  5506. }
  5507. remark := items["remark"].(string)
  5508. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5509. utils.ErrorLog("warehousing_unit")
  5510. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5511. return
  5512. }
  5513. warehousing_unit := items["warehousing_unit"].(string)
  5514. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  5515. utils.ErrorLog("buy_price")
  5516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5517. return
  5518. }
  5519. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  5520. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  5521. utils.ErrorLog("count")
  5522. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5523. return
  5524. }
  5525. count := int64(items["count"].(float64))
  5526. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5527. utils.ErrorLog("good_id")
  5528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5529. return
  5530. }
  5531. good_id := int64(items["good_id"].(float64))
  5532. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  5533. utils.ErrorLog("start_time")
  5534. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5535. return
  5536. }
  5537. var startTime int64
  5538. start_time := items["start_time"].(string)
  5539. if len(start_time) > 0 {
  5540. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5541. if err != nil {
  5542. fmt.Println(err)
  5543. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5544. return
  5545. }
  5546. startTime = theTime.Unix()
  5547. }
  5548. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5549. utils.ErrorLog("number")
  5550. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5551. return
  5552. }
  5553. number := items["number"].(string)
  5554. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  5555. utils.ErrorLog("warehousing_info_id")
  5556. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5557. return
  5558. }
  5559. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  5560. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  5561. utils.ErrorLog("expiry_date")
  5562. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5563. return
  5564. }
  5565. expiry_date := int64(items["expiry_date"].(float64))
  5566. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  5567. utils.ErrorLog("product_date")
  5568. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5569. return
  5570. }
  5571. product_date := int64(items["product_date"].(float64))
  5572. orgId := this.GetAdminUserInfo().CurrentOrgId
  5573. Creater := this.GetAdminUserInfo().AdminUser.Id
  5574. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  5575. utils.ErrorLog("total")
  5576. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5577. return
  5578. }
  5579. total := int64(items["total"].(float64))
  5580. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  5581. utils.ErrorLog("good_origin_place")
  5582. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5583. return
  5584. }
  5585. good_origin_place := items["good_origin_place"].(string)
  5586. reportPrice := models.XtStockReportPrice{
  5587. GoodName: good_name,
  5588. SpecificationName: specification_name,
  5589. WarehousingUnit: warehousing_unit,
  5590. Count: count,
  5591. BuyPrice: buy_price,
  5592. PackingPrice: packing_price,
  5593. Manufacturer: manufacturer,
  5594. Dealer: dealer,
  5595. Remark: remark,
  5596. GoodId: good_id,
  5597. UserOrgId: orgId,
  5598. Ctime: time.Now().Unix(),
  5599. Mtime: 0,
  5600. Status: 1,
  5601. WarehousingOrder: warehousing_order,
  5602. LicenseNumber: license_number,
  5603. StartTime: startTime,
  5604. Creater: Creater,
  5605. Checker: 0,
  5606. CheckerStatus: 2,
  5607. CheckerTime: 0,
  5608. Number: number,
  5609. WarehousingInfoId: warehousing_info_id,
  5610. ExpiryDate: expiry_date,
  5611. ProductDate: product_date,
  5612. Total: total,
  5613. GoodOriginPlace: good_origin_place,
  5614. }
  5615. err := service.CreateReportPrice(&reportPrice)
  5616. fmt.Println(err)
  5617. }
  5618. }
  5619. this.ServeSuccessJSON(map[string]interface{}{
  5620. "msg": "保存成功!",
  5621. })
  5622. }
  5623. func (this *StockManagerApiController) GetReportStockList() {
  5624. timeLayout := "2006-01-02"
  5625. loc, _ := time.LoadLocation("Local")
  5626. start_time := this.GetString("start_time")
  5627. end_time := this.GetString("end_time")
  5628. page, _ := this.GetInt64("page")
  5629. limit, _ := this.GetInt64("limit")
  5630. storehouse_id, _ := this.GetInt64("storehouse_id")
  5631. var startTime int64
  5632. if len(start_time) > 0 {
  5633. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5634. if err != nil {
  5635. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5636. return
  5637. }
  5638. startTime = theTime.Unix()
  5639. fmt.Println("开始时间", startTime)
  5640. }
  5641. var endTime int64
  5642. if len(end_time) > 0 {
  5643. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5644. if err != nil {
  5645. utils.ErrorLog(err.Error())
  5646. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5647. return
  5648. }
  5649. endTime = theTime.Unix()
  5650. }
  5651. orgId := this.GetAdminUserInfo().CurrentOrgId
  5652. keyword := this.GetString("keyword")
  5653. list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit, startTime, endTime, storehouse_id)
  5654. damageList, _ := service.GetStockDamagedCount(orgId)
  5655. doctorlist, _ := service.GetAllDoctorThree(orgId)
  5656. houseList, _ := service.GetAllStoreHouseList(orgId)
  5657. this.ServeSuccessJSON(map[string]interface{}{
  5658. "list": list,
  5659. "total": total,
  5660. "doctorlist": doctorlist,
  5661. "damageList": damageList,
  5662. "houseList": houseList,
  5663. })
  5664. }
  5665. func (this *StockManagerApiController) SaveCheckDamage() {
  5666. timeLayout := "2006-01-02"
  5667. loc, _ := time.LoadLocation("Local")
  5668. idstr := this.GetString("ids")
  5669. ids := strings.Split(idstr, ",")
  5670. check_time := this.GetString("check_time")
  5671. var checkTime int64
  5672. if len(check_time) > 0 {
  5673. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5674. if err != nil {
  5675. fmt.Println(err)
  5676. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5677. return
  5678. }
  5679. checkTime = theTime.Unix()
  5680. }
  5681. checker, _ := this.GetInt64("checker")
  5682. reportprice := models.XtStockReportPrice{
  5683. Checker: checker,
  5684. CheckerStatus: 1,
  5685. CheckerTime: checkTime,
  5686. }
  5687. err := service.UpdateCheckDamage(ids, reportprice)
  5688. fmt.Println(err)
  5689. //获取当前核对的数据
  5690. list, _ := service.GetCheckDamageList(ids)
  5691. ctime := time.Now().Unix()
  5692. adminUserInfo := this.GetAdminUserInfo()
  5693. timeStr := time.Now().Format("2006-01-02")
  5694. timeArr := strings.Split(timeStr, "-")
  5695. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5696. total = total + 1
  5697. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5698. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5699. number = number + total
  5700. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5701. operation_time := time.Now().Unix()
  5702. creater := adminUserInfo.AdminUser.Id
  5703. warehouseOut := models.WarehouseOut{
  5704. WarehouseOutOrderNumber: warehousing_out_order,
  5705. OperationTime: operation_time,
  5706. OrgId: adminUserInfo.CurrentOrgId,
  5707. Creater: creater,
  5708. Ctime: ctime,
  5709. Status: 1,
  5710. WarehouseOutTime: ctime,
  5711. Type: 1,
  5712. }
  5713. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  5714. if errcodes == gorm.ErrRecordNotFound {
  5715. service.AddSigleWarehouseOut(&warehouseOut)
  5716. }
  5717. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  5718. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  5719. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  5720. var manufacturer_id int64
  5721. var dealer_id int64
  5722. for _, item := range list {
  5723. for _, it := range manufacturerList {
  5724. if item.Manufacturer == it.ManufacturerName {
  5725. manufacturer_id = it.ID
  5726. }
  5727. }
  5728. for _, its := range dealerList {
  5729. if item.Dealer == its.DealerName {
  5730. dealer_id = its.ID
  5731. }
  5732. }
  5733. goodinfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5734. //插入出库单
  5735. warehouseOutInfo := &models.WarehouseOutInfo{
  5736. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  5737. WarehouseOutId: out.ID,
  5738. GoodId: item.GoodId,
  5739. Count: item.Count,
  5740. Price: item.PackingPrice,
  5741. Status: 1,
  5742. Ctime: ctime,
  5743. Remark: item.Remark,
  5744. OrgId: adminUserInfo.CurrentOrgId,
  5745. Type: 2,
  5746. Manufacturer: manufacturer_id,
  5747. Number: item.Number,
  5748. ExpiryDate: item.ExpiryDate,
  5749. ProductDate: item.ProductDate,
  5750. Dealer: dealer_id,
  5751. LicenseNumber: item.LicenseNumber,
  5752. GoodTypeId: goodinfo.GoodTypeId,
  5753. }
  5754. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5755. fmt.Println("99999999999999", errOne)
  5756. //更改库存
  5757. info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5758. warehousingInfo := models.WarehousingInfo{
  5759. StockCount: info.StockCount - item.Count,
  5760. }
  5761. errOne = service.UpdateGoodWarehouseInfo(item.WarehousingInfoId, warehousingInfo)
  5762. fmt.Println(errOne)
  5763. flow := models.VmStockFlow{
  5764. WarehousingId: 0,
  5765. GoodId: item.GoodId,
  5766. Number: item.Number,
  5767. LicenseNumber: item.LicenseNumber,
  5768. Count: item.Count,
  5769. UserOrgId: adminUserInfo.CurrentOrgId,
  5770. PatientId: 0,
  5771. SystemTime: time.Now().Unix(),
  5772. ConsumableType: 5,
  5773. IsSys: 0,
  5774. WarehousingOrder: "",
  5775. WarehouseOutId: out.ID,
  5776. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  5777. IsEdit: 0,
  5778. CancelStockId: 0,
  5779. CancelOrderNumber: "",
  5780. Manufacturer: 0,
  5781. Dealer: 0,
  5782. Creator: adminUserInfo.AdminUser.Id,
  5783. UpdateCreator: 0,
  5784. Status: 1,
  5785. Ctime: time.Now().Unix(),
  5786. Mtime: 0,
  5787. Price: item.PackingPrice,
  5788. WarehousingDetailId: 0,
  5789. WarehouseOutDetailId: 0,
  5790. CancelOutDetailId: 0,
  5791. ProductDate: item.ProductDate,
  5792. ExpireDate: item.ExpiryDate,
  5793. }
  5794. service.CreateStockFlowOne(flow)
  5795. }
  5796. this.ServeSuccessJSON(map[string]interface{}{
  5797. "reportPrice": reportprice,
  5798. })
  5799. }
  5800. func (this *StockManagerApiController) SaveInventory() {
  5801. timeLayout := "2006-01-02"
  5802. loc, _ := time.LoadLocation("Local")
  5803. dataBody := make(map[string]interface{}, 0)
  5804. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5805. if err != nil {
  5806. utils.ErrorLog(err.Error())
  5807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5808. return
  5809. }
  5810. tableData, _ := dataBody["tableData"].([]interface{})
  5811. if len(tableData) > 0 {
  5812. for _, item := range tableData {
  5813. items := item.(map[string]interface{})
  5814. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5815. utils.ErrorLog("good_name")
  5816. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5817. return
  5818. }
  5819. good_name := items["good_name"].(string)
  5820. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5821. utils.ErrorLog("good_name")
  5822. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5823. return
  5824. }
  5825. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  5826. utils.ErrorLog("packing_price")
  5827. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5828. return
  5829. }
  5830. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  5831. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5832. utils.ErrorLog("warehousing_order")
  5833. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5834. return
  5835. }
  5836. warehousing_order := items["warehousing_order"].(string)
  5837. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  5838. utils.ErrorLog("license_number")
  5839. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5840. return
  5841. }
  5842. license_number := items["license_number"].(string)
  5843. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  5844. utils.ErrorLog("dealer")
  5845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5846. return
  5847. }
  5848. dealer := items["dealer"].(string)
  5849. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  5850. utils.ErrorLog("manufacturer")
  5851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5852. return
  5853. }
  5854. manufacturer := items["manufacturer"].(string)
  5855. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5856. utils.ErrorLog("specification_name")
  5857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5858. return
  5859. }
  5860. specification_name := items["specification_name"].(string)
  5861. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  5862. utils.ErrorLog("remark")
  5863. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5864. return
  5865. }
  5866. remark := items["remark"].(string)
  5867. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5868. utils.ErrorLog("warehousing_unit")
  5869. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5870. return
  5871. }
  5872. warehousing_unit := items["warehousing_unit"].(string)
  5873. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  5874. utils.ErrorLog("buy_price")
  5875. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5876. return
  5877. }
  5878. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  5879. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  5880. utils.ErrorLog("count")
  5881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5882. return
  5883. }
  5884. count := int64(items["count"].(float64))
  5885. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5886. utils.ErrorLog("good_id")
  5887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5888. return
  5889. }
  5890. good_id := int64(items["good_id"].(float64))
  5891. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  5892. utils.ErrorLog("start_time")
  5893. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5894. return
  5895. }
  5896. var startTime int64
  5897. start_time := items["start_time"].(string)
  5898. if len(start_time) > 0 {
  5899. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5900. if err != nil {
  5901. fmt.Println(err)
  5902. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5903. return
  5904. }
  5905. startTime = theTime.Unix()
  5906. }
  5907. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  5908. utils.ErrorLog("total")
  5909. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5910. return
  5911. }
  5912. total := int64(items["total"].(float64))
  5913. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  5914. utils.ErrorLog("expiry_date")
  5915. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5916. return
  5917. }
  5918. expiry_date := int64(items["expiry_date"].(float64))
  5919. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  5920. utils.ErrorLog("product_date")
  5921. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5922. return
  5923. }
  5924. product_date := int64(items["product_date"].(float64))
  5925. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5926. utils.ErrorLog("number")
  5927. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5928. return
  5929. }
  5930. number := items["number"].(string)
  5931. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  5932. utils.ErrorLog("warehousing_info_id")
  5933. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5934. return
  5935. }
  5936. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  5937. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  5938. utils.ErrorLog("good_origin_place")
  5939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5940. return
  5941. }
  5942. good_origin_place := items["good_origin_place"].(string)
  5943. orgId := this.GetAdminUserInfo().CurrentOrgId
  5944. Creater := this.GetAdminUserInfo().AdminUser.Id
  5945. inventory := models.XtStockInventory{
  5946. GoodName: good_name,
  5947. SpecificationName: specification_name,
  5948. WarehousingUnit: warehousing_unit,
  5949. Count: count,
  5950. BuyPrice: buy_price,
  5951. PackingPrice: packing_price,
  5952. NewPrice: 0,
  5953. Manufacturer: manufacturer,
  5954. Dealer: dealer,
  5955. Remark: remark,
  5956. GoodId: good_id,
  5957. UserOrgId: orgId,
  5958. Ctime: time.Now().Unix(),
  5959. Mtime: 0,
  5960. Status: 1,
  5961. WarehousingOrder: warehousing_order,
  5962. LicenseNumber: license_number,
  5963. StartTime: startTime,
  5964. Creater: Creater,
  5965. Checker: 0,
  5966. CheckerStatus: 2,
  5967. CheckerTime: 0,
  5968. Total: total,
  5969. ExpireDate: expiry_date,
  5970. ProductDate: product_date,
  5971. Number: number,
  5972. WarehousingInfoId: warehousing_info_id,
  5973. GoodOriginPlace: good_origin_place,
  5974. }
  5975. err = service.CreateInentory(inventory)
  5976. fmt.Println(err)
  5977. }
  5978. }
  5979. this.ServeSuccessJSON(map[string]interface{}{
  5980. "msg": "保存成功!",
  5981. })
  5982. }
  5983. func (this *StockManagerApiController) GetInventorylist() {
  5984. timeLayout := "2006-01-02"
  5985. loc, _ := time.LoadLocation("Local")
  5986. start_time := this.GetString("start_time")
  5987. end_time := this.GetString("end_time")
  5988. page, _ := this.GetInt64("page")
  5989. limit, _ := this.GetInt64("limit")
  5990. keyword := this.GetString("keyword")
  5991. inventory_status, _ := this.GetInt64("inventory_status")
  5992. var startTime int64
  5993. if len(start_time) > 0 {
  5994. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5995. if err != nil {
  5996. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5997. return
  5998. }
  5999. startTime = theTime.Unix()
  6000. fmt.Println("开始时间", startTime)
  6001. }
  6002. var endTime int64
  6003. if len(end_time) > 0 {
  6004. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6005. if err != nil {
  6006. utils.ErrorLog(err.Error())
  6007. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6008. return
  6009. }
  6010. endTime = theTime.Unix()
  6011. }
  6012. orgId := this.GetAdminUserInfo().CurrentOrgId
  6013. list, total, _ := service.GetInventorylist(startTime, endTime, page, limit, inventory_status, keyword, orgId)
  6014. doctorlist, _ := service.GetAllDoctorThree(orgId)
  6015. houseList, _ := service.GetAllStoreHouseList(orgId)
  6016. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6017. this.ServeSuccessJSON(map[string]interface{}{
  6018. "list": list,
  6019. "total": total,
  6020. "doctorlist": doctorlist,
  6021. "houseList": houseList,
  6022. "houseConfig": houseConfig,
  6023. })
  6024. }
  6025. func (this *StockManagerApiController) SaveCheckInventory() {
  6026. timeLayout := "2006-01-02"
  6027. loc, _ := time.LoadLocation("Local")
  6028. dataBody := make(map[string]interface{}, 0)
  6029. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6030. fmt.Println(err)
  6031. idstr := this.GetString("ids")
  6032. ids := strings.Split(idstr, ",")
  6033. check_time := this.GetString("check_time")
  6034. var checkTime int64
  6035. if len(check_time) > 0 {
  6036. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  6037. if err != nil {
  6038. fmt.Println(err)
  6039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6040. return
  6041. }
  6042. checkTime = theTime.Unix()
  6043. }
  6044. checker, _ := this.GetInt64("checker")
  6045. inventory := models.XtStockInventory{
  6046. Checker: checker,
  6047. CheckerStatus: 1,
  6048. CheckerTime: checkTime,
  6049. }
  6050. adminUserInfo := this.GetAdminUserInfo()
  6051. err = service.UpdateCheckInventory(ids, inventory)
  6052. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  6053. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  6054. var manufactuer_id int64
  6055. var dealer_id int64
  6056. //查询耗材信息
  6057. list, _ := service.GetInventoryDetailById(ids)
  6058. for _, item := range list {
  6059. for _, it := range manufacturerList {
  6060. if item.Manufacturer == it.ManufacturerName {
  6061. manufactuer_id = it.ID
  6062. }
  6063. }
  6064. for _, its := range dealerList {
  6065. if item.Dealer == its.DealerName {
  6066. dealer_id = its.ID
  6067. }
  6068. }
  6069. //查寻该批次的库存量
  6070. list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  6071. //查询该耗材最后1条批次
  6072. info, _ := service.GetLastWarehouseInfo(item.GoodId)
  6073. good, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6074. fmt.Println("总共", item.Count)
  6075. fmt.Println("数据", list.StockCount)
  6076. //盘点盘点库存和et实际库存的大小
  6077. // 如果盘点库存大于实际库存,怎需要入库
  6078. if item.Count > list.StockCount {
  6079. ctime := time.Now().Unix()
  6080. timeStr := time.Now().Format("2006-01-02")
  6081. timeArr := strings.Split(timeStr, "-")
  6082. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  6083. total = total + 1
  6084. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6085. operation_time := time.Now().Unix()
  6086. creater := adminUserInfo.AdminUser.Id
  6087. warehousing := models.Warehousing{
  6088. WarehousingOrder: warehousing_order,
  6089. OperationTime: operation_time,
  6090. OrgId: adminUserInfo.CurrentOrgId,
  6091. Creater: creater,
  6092. Ctime: ctime,
  6093. Status: 1,
  6094. WarehousingTime: ctime,
  6095. Type: 1,
  6096. }
  6097. service.AddSigleWarehouse(&warehousing)
  6098. //获取最
  6099. //入库单表格
  6100. warehouseInfo := models.WarehousingInfo{
  6101. WarehousingOrder: warehousing.WarehousingOrder,
  6102. WarehousingId: warehousing.ID,
  6103. GoodId: item.GoodId,
  6104. Number: info.Number,
  6105. ProductDate: info.ProductDate,
  6106. ExpiryDate: info.ExpiryDate,
  6107. WarehousingCount: item.Count - list.StockCount,
  6108. Price: info.Price,
  6109. Status: 1,
  6110. Ctime: ctime,
  6111. Remark: item.Remark,
  6112. OrgId: adminUserInfo.CurrentOrgId,
  6113. Type: 1,
  6114. Manufacturer: manufactuer_id,
  6115. StockCount: item.Count - list.StockCount,
  6116. Dealer: dealer_id,
  6117. LicenseNumber: info.LicenseNumber,
  6118. WarehouseInfoId: item.WarehousingInfoId,
  6119. GoodTypeId: good.GoodTypeId,
  6120. }
  6121. flow := models.VmStockFlow{
  6122. WarehousingOrder: warehousing.WarehousingOrder,
  6123. WarehousingId: warehousing.ID,
  6124. GoodId: item.GoodId,
  6125. Number: info.Number,
  6126. ProductDate: info.ProductDate,
  6127. ExpireDate: info.ExpiryDate,
  6128. Count: item.Count - list.StockCount,
  6129. Price: item.BuyPrice,
  6130. Status: 1,
  6131. Ctime: ctime,
  6132. UserOrgId: adminUserInfo.CurrentOrgId,
  6133. Manufacturer: info.Manufacturer,
  6134. Dealer: info.Dealer,
  6135. LicenseNumber: info.LicenseNumber,
  6136. IsEdit: 1,
  6137. Creator: adminUserInfo.AdminUser.Id,
  6138. SystemTime: operation_time,
  6139. ConsumableType: 1,
  6140. WarehousingDetailId: warehouseInfo.ID,
  6141. }
  6142. service.CreateWarehouseInfo(warehouseInfo)
  6143. service.CreateStockFlowOne(flow)
  6144. }
  6145. //如果盘点库存小于实际库存,需要出库
  6146. if item.Count < list.StockCount {
  6147. timeStr := time.Now().Format("2006-01-02")
  6148. timeArr := strings.Split(timeStr, "-")
  6149. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  6150. total = total + 1
  6151. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6152. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6153. number = number + total
  6154. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6155. operation_time := time.Now().Unix()
  6156. creater := adminUserInfo.AdminUser.Id
  6157. //查询最早的1条批次
  6158. warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
  6159. warehouseOut := models.WarehouseOut{
  6160. WarehouseOutOrderNumber: warehousing_out_order,
  6161. OperationTime: operation_time,
  6162. OrgId: adminUserInfo.CurrentOrgId,
  6163. Creater: creater,
  6164. Ctime: time.Now().Unix(),
  6165. Status: 1,
  6166. WarehouseOutTime: time.Now().Unix(),
  6167. Type: 1,
  6168. }
  6169. err = service.CreateWarehouseOut(warehouseOut)
  6170. fmt.Println(err)
  6171. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  6172. warehouseOutInfo := &models.WarehouseOutInfo{
  6173. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  6174. WarehouseOutId: out.ID,
  6175. GoodId: warehouseInfo.GoodId,
  6176. Count: list.StockCount - item.Count,
  6177. Price: warehouseInfo.Price,
  6178. Status: 1,
  6179. Ctime: time.Now().Unix(),
  6180. Remark: item.Remark,
  6181. OrgId: adminUserInfo.CurrentOrgId,
  6182. Type: 1,
  6183. Manufacturer: manufactuer_id,
  6184. Number: warehouseInfo.Number,
  6185. ExpiryDate: warehouseInfo.ExpiryDate,
  6186. ProductDate: warehouseInfo.ProductDate,
  6187. Dealer: dealer_id,
  6188. LicenseNumber: warehouseInfo.LicenseNumber,
  6189. GoodTypeId: good.GoodTypeId,
  6190. }
  6191. stockFlow := models.VmStockFlow{
  6192. WarehousingId: item.WarehousingInfoId,
  6193. GoodId: warehouseInfo.GoodId,
  6194. Number: warehouseInfo.Number,
  6195. LicenseNumber: warehouseInfo.LicenseNumber,
  6196. Count: list.StockCount - item.Count,
  6197. UserOrgId: warehouseInfo.OrgId,
  6198. PatientId: 0,
  6199. SystemTime: 0,
  6200. ConsumableType: 2,
  6201. IsSys: 2,
  6202. WarehousingOrder: "",
  6203. WarehouseOutId: out.ID,
  6204. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6205. IsEdit: 1,
  6206. CancelStockId: 0,
  6207. CancelOrderNumber: "",
  6208. Manufacturer: manufactuer_id,
  6209. Dealer: dealer_id,
  6210. Creator: adminUserInfo.AdminUser.Id,
  6211. UpdateCreator: 0,
  6212. Status: 1,
  6213. Ctime: time.Now().Unix(),
  6214. Mtime: 0,
  6215. Price: warehouseInfo.Price,
  6216. WarehousingDetailId: 0,
  6217. WarehouseOutDetailId: out.ID,
  6218. CancelOutDetailId: 0,
  6219. ProductDate: warehouseInfo.ProductDate,
  6220. ExpireDate: warehouseInfo.ExpiryDate,
  6221. }
  6222. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6223. fmt.Println(errOne)
  6224. //创建出库明细
  6225. service.CreateStockFlowOne(stockFlow)
  6226. //更改库存
  6227. warehousingInfos := models.WarehousingInfo{
  6228. StockCount: item.Count,
  6229. }
  6230. service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
  6231. }
  6232. }
  6233. fmt.Println(err)
  6234. this.ServeSuccessJSON(map[string]interface{}{
  6235. "inventory": inventory,
  6236. })
  6237. }
  6238. func (this *StockManagerApiController) GetModifyPriceDetail() {
  6239. id, _ := this.GetInt64("id")
  6240. detail, _ := service.GetModifyPriceDetail(id)
  6241. this.ServeSuccessJSON(map[string]interface{}{
  6242. "detail": detail,
  6243. })
  6244. }
  6245. func (this *StockManagerApiController) UpdateStockPrice() {
  6246. id, _ := this.GetInt64("id")
  6247. newPrice := this.GetString("new_price")
  6248. new_price, _ := strconv.ParseFloat(newPrice, 64)
  6249. good_name := this.GetString("good_name")
  6250. packingPrice := this.GetString("packing_price")
  6251. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  6252. remark := this.GetString("remark")
  6253. good_id, _ := this.GetInt64("good_id")
  6254. manufacturer := this.GetString("manufacturer")
  6255. dealer := this.GetString("dealer")
  6256. adjust := models.XtStockAdjustPrice{
  6257. NewPrice: new_price,
  6258. GoodName: good_name,
  6259. PackingPrice: packing_price,
  6260. Remark: remark,
  6261. GoodId: good_id,
  6262. Manufacturer: manufacturer,
  6263. Dealer: dealer,
  6264. }
  6265. err := service.UpdateStockPrice(adjust, id)
  6266. fmt.Println(err)
  6267. this.ServeSuccessJSON(map[string]interface{}{
  6268. "adjust": adjust,
  6269. })
  6270. }
  6271. func (this *StockManagerApiController) DeleteStockPrice() {
  6272. id, _ := this.GetInt64("id")
  6273. err := service.DeleteStockPrice(id)
  6274. fmt.Println(err)
  6275. returnData := make(map[string]interface{}, 0)
  6276. returnData["msg"] = "ok"
  6277. this.ServeSuccessJSON(returnData)
  6278. return
  6279. }
  6280. func (this *StockManagerApiController) GetStockDamageDetail() {
  6281. id, _ := this.GetInt64("id")
  6282. detail, err := service.GetStockDamageDetail(id)
  6283. fmt.Println(err)
  6284. this.ServeSuccessJSON(map[string]interface{}{
  6285. "detail": detail,
  6286. })
  6287. }
  6288. func (this *StockManagerApiController) ModifyPrice() {
  6289. count, _ := this.GetInt64("count")
  6290. id, _ := this.GetInt64("id")
  6291. good_name := this.GetString("good_name")
  6292. specification_name := this.GetString("specification_name")
  6293. number := this.GetString("number")
  6294. warehousing_unit := this.GetString("warehousing_unit")
  6295. buyPrice := this.GetString("buy_price")
  6296. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  6297. packingPrice := this.GetString("packing_price")
  6298. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  6299. good_origin_place := this.GetString("good_origin_place")
  6300. manufacturer := this.GetString("manufacturer")
  6301. dealer := this.GetString("dealer")
  6302. total, _ := this.GetInt64("total")
  6303. remark := this.GetString("remark")
  6304. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  6305. good_id, _ := this.GetInt64("good_id")
  6306. adjust := models.XtStockReportPrice{
  6307. Count: count,
  6308. SpecificationName: specification_name,
  6309. Number: number,
  6310. GoodName: good_name,
  6311. WarehousingUnit: warehousing_unit,
  6312. BuyPrice: buy_price,
  6313. PackingPrice: packing_price,
  6314. GoodOriginPlace: good_origin_place,
  6315. Manufacturer: manufacturer,
  6316. Dealer: dealer,
  6317. Total: total,
  6318. Remark: remark,
  6319. WarehousingInfoId: warehousing_info_id,
  6320. GoodId: good_id,
  6321. }
  6322. err := service.ModifyPrice(id, adjust)
  6323. fmt.Println(err)
  6324. this.ServeSuccessJSON(map[string]interface{}{
  6325. "adjust": adjust,
  6326. })
  6327. }
  6328. func (this *StockManagerApiController) DeleteDamage() {
  6329. id, _ := this.GetInt64("id")
  6330. err := service.DeleteDamage(id)
  6331. fmt.Println(err)
  6332. returnData := make(map[string]interface{}, 0)
  6333. returnData["msg"] = "ok"
  6334. this.ServeSuccessJSON(returnData)
  6335. return
  6336. }
  6337. func (this *StockManagerApiController) GetStockDamageById() {
  6338. ids := this.GetString("ids")
  6339. splitIds := strings.Split(ids, ",")
  6340. list, _ := service.GetStockDamageById(splitIds)
  6341. this.ServeSuccessJSON(map[string]interface{}{
  6342. "list": list,
  6343. })
  6344. }
  6345. func (this *StockManagerApiController) GetInventoryDetail() {
  6346. id, _ := this.GetInt64("id")
  6347. detail, _ := service.GetInventoryDetail(id)
  6348. this.ServeSuccessJSON(map[string]interface{}{
  6349. "detail": detail,
  6350. })
  6351. }
  6352. func (this *StockManagerApiController) ModifyInventory() {
  6353. id, _ := this.GetInt64("id")
  6354. good_id, _ := this.GetInt64("good_id")
  6355. good_name := this.GetString("good_name")
  6356. specification_name := this.GetString("specification_name")
  6357. number := this.GetString("number")
  6358. warehousing_unit := this.GetString("warehousing_unit")
  6359. buyPrice := this.GetString("buy_price")
  6360. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  6361. packingPrice := this.GetString("packing_price")
  6362. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  6363. total, _ := this.GetInt64("total")
  6364. good_origin_place := this.GetString("good_origin_place")
  6365. license_number := this.GetString("license_number")
  6366. dealer := this.GetString("dealer")
  6367. manufacturer := this.GetString("manufacturer")
  6368. count, _ := this.GetInt64("count")
  6369. remark := this.GetString("remark")
  6370. inventory := models.XtStockInventory{
  6371. GoodId: good_id,
  6372. GoodName: good_name,
  6373. SpecificationName: specification_name,
  6374. Number: number,
  6375. WarehousingUnit: warehousing_unit,
  6376. BuyPrice: buy_price,
  6377. PackingPrice: packing_price,
  6378. Total: total,
  6379. GoodOriginPlace: good_origin_place,
  6380. LicenseNumber: license_number,
  6381. Dealer: dealer,
  6382. Manufacturer: manufacturer,
  6383. Count: count,
  6384. Remark: remark,
  6385. }
  6386. err := service.ModifyInventory(id, inventory)
  6387. fmt.Println(err)
  6388. this.ServeSuccessJSON(map[string]interface{}{
  6389. "inventory": inventory,
  6390. })
  6391. }
  6392. func (this *StockManagerApiController) DeleteInventory() {
  6393. id, _ := this.GetInt64("id")
  6394. err := service.DeleteInventory(id)
  6395. fmt.Println(err)
  6396. returnData := make(map[string]interface{}, 0)
  6397. returnData["msg"] = "ok"
  6398. this.ServeSuccessJSON(returnData)
  6399. return
  6400. }
  6401. func (this *StockManagerApiController) GetInventoryDetailList() {
  6402. keyword := this.GetString("keyword")
  6403. limit, _ := this.GetInt64("limit")
  6404. page, _ := this.GetInt64("page")
  6405. orgId := this.GetAdminUserInfo().CurrentOrgId
  6406. storehouse_id, _ := this.GetInt64("storehouse_id")
  6407. houseList, _ := service.GetAllStoreHouseList(orgId)
  6408. list, total, _ := service.GetInventoryDetailList(keyword, limit, page, orgId, storehouse_id)
  6409. this.ServeSuccessJSON(map[string]interface{}{
  6410. "list": list,
  6411. "total": total,
  6412. "houseList": houseList,
  6413. })
  6414. }
  6415. func (this *StockManagerApiController) GetInventoryPrintList() {
  6416. ids := this.GetString("ids")
  6417. splitIds := strings.Split(ids, ",")
  6418. list, _ := service.GetInventoryPrintList(splitIds)
  6419. this.ServeSuccessJSON(map[string]interface{}{
  6420. "list": list,
  6421. })
  6422. }
  6423. func (this *StockManagerApiController) GetInventoryDetailPrintList() {
  6424. ids := this.GetString("ids")
  6425. splitIds := strings.Split(ids, ",")
  6426. list, _ := service.GetInventoryDetailPrintList(splitIds)
  6427. this.ServeSuccessJSON(map[string]interface{}{
  6428. "list": list,
  6429. })
  6430. }
  6431. func (this *StockManagerApiController) DeleteDrugPrice() {
  6432. id, _ := this.GetInt64("id")
  6433. err := service.DeleteDrugPrice(id)
  6434. fmt.Println(err)
  6435. returnData := make(map[string]interface{}, 0)
  6436. returnData["msg"] = "ok"
  6437. this.ServeSuccessJSON(returnData)
  6438. return
  6439. }
  6440. func (this *StockManagerApiController) GetGoodWarehouseList() {
  6441. id, _ := this.GetInt64("id")
  6442. list, _ := service.GetGoodWarehouseList(id)
  6443. this.ServeSuccessJSON(map[string]interface{}{
  6444. "list": list,
  6445. })
  6446. }
  6447. func (this *StockManagerApiController) ProofInventory() {
  6448. id, _ := this.GetInt64("id")
  6449. good_id, _ := this.GetInt64("good_id")
  6450. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  6451. proof_count, _ := this.GetInt64("proof_count")
  6452. total, _ := this.GetInt64("total")
  6453. orgId := this.GetAdminUserInfo().CurrentOrgId
  6454. creater := this.GetAdminUserInfo().AdminUser.Id
  6455. info := models.WarehousingInfo{
  6456. GoodId: good_id,
  6457. StockCount: proof_count,
  6458. }
  6459. err := service.UpdateProofInventory(warehousing_info_id, info)
  6460. inventory := models.XtStockInventory{
  6461. Total: proof_count,
  6462. }
  6463. err = service.UpdateStockInventory(inventory, id)
  6464. fmt.Println(err)
  6465. record := models.XtStockCorrectRecord{
  6466. GoodId: good_id,
  6467. OrdCount: total,
  6468. WarehousingInfoId: warehousing_info_id,
  6469. NewCount: proof_count,
  6470. UserOrgId: orgId,
  6471. Status: 1,
  6472. Creater: creater,
  6473. Ctime: time.Now().Unix(),
  6474. Mtime: 0,
  6475. }
  6476. service.CeateStockCorrectRecord(record)
  6477. this.ServeSuccessJSON(map[string]interface{}{
  6478. "list": info,
  6479. })
  6480. }
  6481. func (this *StockManagerApiController) GetWarehouseTotal() {
  6482. id, _ := this.GetInt64("id")
  6483. list, _ := service.GetWarehouseTotal(id)
  6484. this.ServeSuccessJSON(map[string]interface{}{
  6485. "list": list,
  6486. })
  6487. }
  6488. func (this *StockManagerApiController) GetGoodInventoryWarehouseList() {
  6489. id, _ := this.GetInt64("id")
  6490. storehouse_id, _ := this.GetInt64("storehouse_id")
  6491. list, _ := service.GetGoodInventoryWarehouseList(id, storehouse_id)
  6492. orgId := this.GetAdminUserInfo().CurrentOrgId
  6493. fmt.Println(orgId)
  6494. this.ServeSuccessJSON(map[string]interface{}{
  6495. "list": list,
  6496. })
  6497. }
  6498. func (this *StockManagerApiController) SaveStockInventoryList() {
  6499. dataBody := make(map[string]interface{}, 0)
  6500. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6501. fmt.Println(err)
  6502. tableData, _ := dataBody["tableData"].([]interface{})
  6503. if len(tableData) > 0 {
  6504. for _, item := range tableData {
  6505. items := item.(map[string]interface{})
  6506. good_name := items["good_name"].(string)
  6507. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  6508. utils.ErrorLog("good_name")
  6509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6510. return
  6511. }
  6512. specification_name := items["specification_name"].(string)
  6513. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  6514. utils.ErrorLog("specification_name")
  6515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6516. return
  6517. }
  6518. warehousing_unit := items["warehousing_unit"].(string)
  6519. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  6520. utils.ErrorLog("warehousing_unit")
  6521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6522. return
  6523. }
  6524. stock_count := int64(items["stock_count"].(float64))
  6525. if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
  6526. utils.ErrorLog("stock_count")
  6527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6528. return
  6529. }
  6530. price := items["price"].(float64)
  6531. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
  6532. utils.ErrorLog("price")
  6533. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6534. return
  6535. }
  6536. manufacturer_name := items["manufacturer_name"].(string)
  6537. if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
  6538. utils.ErrorLog("manufacturer_name")
  6539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6540. return
  6541. }
  6542. good_id := int64(items["good_id"].(float64))
  6543. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6544. utils.ErrorLog("good_id")
  6545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6546. return
  6547. }
  6548. manufacturer := int64(items["manufacturer"].(float64))
  6549. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
  6550. utils.ErrorLog("manufacturer")
  6551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6552. return
  6553. }
  6554. warehousing_order := items["warehousing_order"].(string)
  6555. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  6556. utils.ErrorLog("warehousing_order")
  6557. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6558. return
  6559. }
  6560. number := items["number"].(string)
  6561. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  6562. utils.ErrorLog("number")
  6563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6564. return
  6565. }
  6566. id := int64(items["id"].(float64))
  6567. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  6568. utils.ErrorLog("id")
  6569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6570. return
  6571. }
  6572. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  6573. utils.ErrorLog("expiry_date")
  6574. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6575. return
  6576. }
  6577. expiry_date := int64(items["expiry_date"].(float64))
  6578. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  6579. utils.ErrorLog("product_date")
  6580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6581. return
  6582. }
  6583. product_date := int64(items["product_date"].(float64))
  6584. orgId := this.GetAdminUserInfo().CurrentOrgId
  6585. adminId := this.GetAdminUserInfo().AdminUser.Id
  6586. stock_type := int64(items["type"].(float64))
  6587. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6588. utils.ErrorLog("type")
  6589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6590. return
  6591. }
  6592. last_stock_count := int64(items["last_stock_count"].(float64))
  6593. if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
  6594. utils.ErrorLog("last_stock_count")
  6595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6596. return
  6597. }
  6598. storehouse_id := int64(items["storehouse_id"].(float64))
  6599. if items["storehouse_id"] == nil || reflect.TypeOf(items["storehouse_id"]).String() != "float64" {
  6600. utils.ErrorLog("storehouse_id")
  6601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6602. return
  6603. }
  6604. var total_count int64
  6605. var inventory_type int64
  6606. if stock_count > last_stock_count {
  6607. total_count = stock_count - last_stock_count
  6608. inventory_type = 11
  6609. }
  6610. if stock_count < last_stock_count {
  6611. total_count = last_stock_count - stock_count
  6612. inventory_type = 10
  6613. }
  6614. creater := this.GetAdminUserInfo().AdminUser.Id
  6615. inventory := models.XtStockInventory{
  6616. GoodName: good_name,
  6617. SpecificationName: specification_name,
  6618. WarehousingUnit: warehousing_unit,
  6619. Count: total_count,
  6620. BuyPrice: price,
  6621. PackingPrice: price,
  6622. NewPrice: 0,
  6623. Manufacturer: manufacturer_name,
  6624. Dealer: "",
  6625. Remark: "",
  6626. GoodId: good_id,
  6627. UserOrgId: orgId,
  6628. Ctime: time.Now().Unix(),
  6629. Mtime: 0,
  6630. Status: 1,
  6631. WarehousingOrder: warehousing_order,
  6632. LicenseNumber: number,
  6633. StartTime: time.Now().Unix(),
  6634. Creater: adminId,
  6635. Checker: 0,
  6636. CheckerStatus: 0,
  6637. CheckerTime: 0,
  6638. Total: 0,
  6639. Number: number,
  6640. WarehousingInfoId: id,
  6641. ExpireDate: expiry_date,
  6642. ProductDate: product_date,
  6643. GoodOriginPlace: "",
  6644. Type: 10,
  6645. InventoryType: stock_type,
  6646. LastStockCount: last_stock_count,
  6647. StockCount: stock_count,
  6648. StorehouseId: storehouse_id,
  6649. }
  6650. service.CreateInentory(inventory)
  6651. stockFlow := models.VmStockFlow{
  6652. WarehousingId: 0,
  6653. GoodId: good_id,
  6654. Number: number,
  6655. LicenseNumber: "",
  6656. Count: total_count,
  6657. UserOrgId: orgId,
  6658. PatientId: 0,
  6659. SystemTime: 0,
  6660. ConsumableType: inventory_type,
  6661. IsSys: 0,
  6662. WarehousingOrder: "",
  6663. WarehouseOutId: 0,
  6664. WarehouseOutOrderNumber: warehousing_order,
  6665. IsEdit: 0,
  6666. CancelStockId: 0,
  6667. CancelOrderNumber: "",
  6668. Manufacturer: manufacturer,
  6669. Dealer: 0,
  6670. Creator: creater,
  6671. UpdateCreator: 0,
  6672. Status: 1,
  6673. Ctime: time.Now().Unix(),
  6674. Mtime: 0,
  6675. Price: price,
  6676. WarehousingDetailId: 0,
  6677. WarehouseOutDetailId: 0,
  6678. CancelOutDetailId: 0,
  6679. ProductDate: product_date,
  6680. ExpireDate: expiry_date,
  6681. ReturnCount: 0,
  6682. StorehouseId: storehouse_id,
  6683. }
  6684. info := models.WarehousingInfo{
  6685. StockCount: last_stock_count,
  6686. WarehousingCount: last_stock_count,
  6687. }
  6688. warehosueinfos, _ := service.GetWarehouseInfoByIdNight(id)
  6689. //如果当前的盘点后的数量大于当前库存数量,则新增库存
  6690. if last_stock_count > warehosueinfos.StockCount && last_stock_count <= warehosueinfos.WarehousingCount {
  6691. //更改库存
  6692. service.UpdatedWarehousingInfo(info, id)
  6693. }
  6694. if last_stock_count > warehosueinfos.StockCount && last_stock_count > warehosueinfos.WarehousingCount {
  6695. //更改库存
  6696. service.UpdatedWarehousingInfoSix(info, id)
  6697. }
  6698. //如果当前的盘点后的数量大于当前库存数量,则扣减库存
  6699. if last_stock_count < warehosueinfos.StockCount {
  6700. //更改库存
  6701. service.UpdatedWarehousingInfo(info, id)
  6702. }
  6703. if stock_count != last_stock_count {
  6704. service.CreateStockFlowOne(stockFlow)
  6705. }
  6706. //查询该机构默认仓库
  6707. storeConfig, _ := service.GetAllStoreHouseConfig(warehosueinfos.OrgId)
  6708. //查询剩余库存
  6709. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, warehosueinfos.OrgId)
  6710. var sum_count int64
  6711. var sum_in_count int64
  6712. for _, item := range goodList {
  6713. sum_count += item.StockCount
  6714. sum_in_count += item.WarehousingCount
  6715. }
  6716. service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
  6717. this.ServeSuccessJSON(map[string]interface{}{
  6718. "inventory": inventory,
  6719. })
  6720. }
  6721. }
  6722. }
  6723. func (this *StockManagerApiController) GetDamageDetailByGoodId() {
  6724. good_id, _ := this.GetInt64("good_id")
  6725. warehousing_order := this.GetString("warehousing_order")
  6726. inventory_type, _ := this.GetInt64("type")
  6727. fmt.Println("inventory_type23232323223322332", inventory_type)
  6728. list, _ := service.GetDamageDetailByGoodId(good_id, warehousing_order, inventory_type)
  6729. orgId := this.GetAdminUserInfo().CurrentOrgId
  6730. damageList, _ := service.GetStockDamagedCountOne(orgId, warehousing_order, inventory_type)
  6731. this.ServeSuccessJSON(map[string]interface{}{
  6732. "list": list,
  6733. "damageList": damageList,
  6734. })
  6735. }
  6736. func (this *StockManagerApiController) GetInventoryExportList() {
  6737. orgId := this.GetAdminUserInfo().CurrentOrgId
  6738. list, _ := service.GetInventoryExportList(orgId)
  6739. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  6740. this.ServeSuccessJSON(map[string]interface{}{
  6741. "list": list,
  6742. "manufacturerList": manufacturerList,
  6743. })
  6744. }
  6745. func (this *StockManagerApiController) UpdateCancelStockOrder() {
  6746. type_id, _ := this.GetInt64("type_id")
  6747. //获取目前在使用的机构ID
  6748. list, _ := service.GetOrgIdList()
  6749. //耗材
  6750. if type_id == 1 {
  6751. for _, item := range list {
  6752. fmt.Println("item23323223", item)
  6753. //查询该机构的所有耗材
  6754. goodList, _ := service.GetAllGoodList(item.OrgId)
  6755. for _, it := range goodList {
  6756. //查询该耗材的入库总数
  6757. info, _ := service.GetStockCountWarehouseInfoById(it.ID)
  6758. var total int64
  6759. for _, its := range info {
  6760. total += its.StockCount
  6761. }
  6762. //更新库存
  6763. service.ModifyGoodAddInformationSeven(it.ID, total, it.OrgId)
  6764. }
  6765. }
  6766. }
  6767. //药品
  6768. if type_id == 2 {
  6769. for _, item := range list {
  6770. fmt.Println(item)
  6771. //查询该机构的所有药品
  6772. drugList, _ := service.GetAllBaseDrugStockList(4)
  6773. for _, it := range drugList {
  6774. //查询该药品的入库总数
  6775. info, _ := service.GetDrugStockCountWarehoseInfoById(it.ID)
  6776. var sum_count int64
  6777. for _, its := range info {
  6778. if its.MaxUnit == it.MaxUnit {
  6779. its.StockMaxNumber = its.StockMaxNumber * it.MinNumber
  6780. }
  6781. sum_count += its.StockMaxNumber + its.StockMinNumber
  6782. }
  6783. service.UpdateModifyDrugInfoById(it.ID, sum_count, it.OrgId)
  6784. }
  6785. }
  6786. }
  6787. }
  6788. func (this *StockManagerApiController) GetDrugDetailSummary() {
  6789. timeLayout := "2006-01-02"
  6790. loc, _ := time.LoadLocation("Local")
  6791. start_time := this.GetString("start_time")
  6792. end_time := this.GetString("end_time")
  6793. var startTime int64
  6794. if len(start_time) > 0 {
  6795. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6796. if err != nil {
  6797. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6798. return
  6799. }
  6800. startTime = theTime.Unix()
  6801. fmt.Println("开始时间", startTime)
  6802. }
  6803. var endTime int64
  6804. if len(end_time) > 0 {
  6805. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6806. if err != nil {
  6807. utils.ErrorLog(err.Error())
  6808. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6809. return
  6810. }
  6811. endTime = theTime.Unix()
  6812. }
  6813. keyword := this.GetString("keyword")
  6814. limit, _ := this.GetInt64("limit")
  6815. page, _ := this.GetInt64("page")
  6816. orgId := this.GetAdminUserInfo().CurrentOrgId
  6817. list, total, err := service.GetDrugDetailSummary(startTime, endTime, keyword, limit, page, orgId)
  6818. druglist, _, _ := service.GetDrugDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
  6819. patients, _ := service.GetAllpatient(orgId)
  6820. var drugType = "药品类型"
  6821. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  6822. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  6823. for _, item := range list {
  6824. for _, it := range druglist {
  6825. if item.DrugId == it.DrugId {
  6826. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6827. }
  6828. }
  6829. }
  6830. drug, _ := service.GetAllDrugSummary(orgId)
  6831. if err == nil {
  6832. this.ServeSuccessJSON(map[string]interface{}{
  6833. "list": list,
  6834. "total": total,
  6835. "drug": drug,
  6836. "drugTypeList": drugTypeList,
  6837. "patients": patients,
  6838. })
  6839. }
  6840. }
  6841. func (this *StockManagerApiController) GetGoodDetailSummary() {
  6842. timeLayout := "2006-01-02"
  6843. loc, _ := time.LoadLocation("Local")
  6844. start_time := this.GetString("start_time")
  6845. end_time := this.GetString("end_time")
  6846. var startTime int64
  6847. if len(start_time) > 0 {
  6848. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6849. if err != nil {
  6850. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6851. return
  6852. }
  6853. startTime = theTime.Unix()
  6854. fmt.Println("开始时间", startTime)
  6855. }
  6856. var endTime int64
  6857. if len(end_time) > 0 {
  6858. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6859. if err != nil {
  6860. utils.ErrorLog(err.Error())
  6861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6862. return
  6863. }
  6864. endTime = theTime.Unix()
  6865. }
  6866. keyword := this.GetString("keyword")
  6867. limit, _ := this.GetInt64("limit")
  6868. page, _ := this.GetInt64("page")
  6869. orgId := this.GetAdminUserInfo().CurrentOrgId
  6870. list, total, err := service.GetGoodDetailSummary(startTime, endTime, keyword, limit, page, orgId)
  6871. goodlist, _, _ := service.GetGoodDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
  6872. for _, item := range list {
  6873. for _, it := range goodlist {
  6874. if item.ProjectId == it.ProjectId {
  6875. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6876. }
  6877. }
  6878. }
  6879. information, _ := service.GeAllGoodInformation(orgId)
  6880. patients, _ := service.GetAllpatient(orgId)
  6881. goodType, _ := service.GetAllGoodType(orgId)
  6882. if err == nil {
  6883. this.ServeSuccessJSON(map[string]interface{}{
  6884. "list": list,
  6885. "total": total,
  6886. "good": information,
  6887. "patients": patients,
  6888. "goodType": goodType,
  6889. })
  6890. }
  6891. }