stock_in_api_controller.go 265KB

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