stock_in_api_controller.go 271KB

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