stock_in_api_controller.go 241KB

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