stock_in_api_controller.go 252KB

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