stock_in_api_controller.go 261KB

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