stock_in_api_controller.go 261KB

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