stock_in_api_controller.go 276KB

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