stock_in_api_controller.go 274KB

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