stock_in_api_controller.go 241KB

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