stock_in_api_controller.go 276KB

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