stock_in_api_controller.go 262KB

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