12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- "reflect"
- "strconv"
- "strings"
- "time"
- )
-
- type StockManagerApiController struct {
- BaseAuthAPIController
- }
-
- func StockManagerApiRegistRouters() {
-
- //入库管理和其他入库管理相关接口
- beego.Router("/api/warehouse/create", &StockManagerApiController{}, "post:CreateWarehouse")
- beego.Router("/api/warehouse/list", &StockManagerApiController{}, "get:GetWarehouseList")
- beego.Router("/api/warehouse/delete", &StockManagerApiController{}, "post:DeleteWarehouse")
- beego.Router("/api/warehouseinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseInfo")
- beego.Router("/api/warehouseinfo/list", &StockManagerApiController{}, "get:GetWarehouseInfoList")
- beego.Router("/api/warehouse/edit", &StockManagerApiController{}, "post:EditWarehouse")
-
- //退货管理和其他退货管理相关接口
- beego.Router("/api/salesreturn/create", &StockManagerApiController{}, "post:CreateSalesReturn")
- beego.Router("/api/salesreturn/delete", &StockManagerApiController{}, "post:DeleteSalesReturn")
- beego.Router("/api/salesreturninfo/delete", &StockManagerApiController{}, "post:DeleteSalesReturnInfo")
- beego.Router("/api/salesreturninfo/list", &StockManagerApiController{}, "get:GetSalesReturnInfoList")
- beego.Router("/api/salesreturn/list", &StockManagerApiController{}, "get:GetSalesReturnList")
- beego.Router("/api/salesreturn/edit", &StockManagerApiController{}, "post:EditReturnInfo")
-
- //出库管理和其他出库管理相关接口
- beego.Router("/api/warehouseout/create", &StockManagerApiController{}, "post:CreateWarehouseOut")
- beego.Router("/api/warehouseout/delete", &StockManagerApiController{}, "post:DeleteWarehouseOut")
- beego.Router("/api/warehouseoutinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseOutInfo")
- beego.Router("/api/warehouseout/list", &StockManagerApiController{}, "get:GetWarehouseOutList")
- beego.Router("/api/warehouseout/edit", &StockManagerApiController{}, "post:EditWarehouseOut")
- beego.Router("/api/warehouseout/info", &StockManagerApiController{}, "get:GetWarehouseOutInfoList")
-
- //出库退库管理和其他出库退库管理相关接口
- beego.Router("/api/cancelstock/create", &StockManagerApiController{}, "post:CreateCancelStock")
- beego.Router("/api/cancelstock/list", &StockManagerApiController{}, "get:GetCancelStockList")
- beego.Router("/api/cancelstock/info", &StockManagerApiController{}, "get:GetCancelStockInfoList")
- beego.Router("/api/cancelstock/delete", &StockManagerApiController{}, "post:DeleteCancelStock")
- beego.Router("/api/cancelstockinfo/delete", &StockManagerApiController{}, "post:DeleteCancelStockInfo")
- beego.Router("/api/cancelstockinfo/edit", &StockManagerApiController{}, "post:EditCancelStock")
- beego.Router("/api/cancelstockinfo/config", &StockManagerApiController{}, "get:GetCancelStockConfig")
-
- //库存相关全局配置
- beego.Router("/api/stock/config", &StockManagerApiController{}, "get:GetAllConfig")
- beego.Router("/api/return/config", &StockManagerApiController{}, "get:GetAllSalesReturnConfig")
-
- //库存查询
- beego.Router("/api/stock/query", &StockManagerApiController{}, "get:GetQueryInfo")
-
- beego.Router("/api/stock/detail", &StockManagerApiController{}, "get:GetDetailInfo")
-
- beego.Router("/api/warehouseout/user", &StockManagerApiController{}, "get:GetUserDetailInfo")
-
- beego.Router("/api/warehouseout/postsearchstock", &StockManagerApiController{}, "Get:PostSearchStock")
-
- beego.Router("/api/warehouseout/getoutstocktotalcount", &StockManagerApiController{}, "Get:GetOutStockTotalCount")
-
- beego.Router("/api/good/postgoodinformation", &StockManagerApiController{}, "Post:AddGoodInformation")
-
- beego.Router("/api/good/postdruginformation", &StockManagerApiController{}, "Post:AddDrugInformation")
-
- beego.Router("/api/good/initializtion", &StockManagerApiController{}, "Get:GetInitializtion")
-
- beego.Router("/api/good/getwarehouseorderinfolist", &StockManagerApiController{}, "Get:GetWarehouseOrderInfolist")
-
- beego.Router("/api/good/postsearchgoodlist", &StockManagerApiController{}, "Get:PostSearchGoodList")
-
- beego.Router("/api/good/getallstocklist", &StockManagerApiController{}, "Get:GetAllStockList")
-
- beego.Router("/api/stock/getstocklistbyid", &StockManagerApiController{}, "Get:GetStockListById")
- beego.Router("/api/stock/getstockoutlist", &StockManagerApiController{}, "Get:GetStockOutList")
-
- beego.Router("/api/good/getstockdrugcount", &StockManagerApiController{}, "Get:GetStockDrugCount")
-
- beego.Router("/api/good/getorderdetialbyorderid", &StockManagerApiController{}, "Get:GetOrderDetialByOrderId")
- beego.Router("/api/good/getorderdetaibyid", &StockManagerApiController{}, "Get:GetOrderDetailById")
- beego.Router("/api/good/getsingleoutorderdetail", &StockManagerApiController{}, "Get:GetSingleOutOrderDetail")
- beego.Router("/api/stock/getexportstocklist", &StockManagerApiController{}, "Get:GetExprotStockList")
- beego.Router("/api/stock/getoutexprotlist", &StockManagerApiController{}, "Get:GetOutExprotList")
- beego.Router("/api/stock/getsinglecancelorder", &StockManagerApiController{}, "Get:GetSingleCancelOrder")
- beego.Router("/api/stock/getcancelstockorderprint", &StockManagerApiController{}, "Get:GetCancelStockOrderPrint")
- beego.Router("/api/stock/getstockbatchnumber", &StockManagerApiController{}, "Get:GetStockBatchNumber")
-
- beego.Router("/api/stock/getstockflow", &StockManagerApiController{}, "Get:GetStockFlow")
-
- beego.Router("/api/cancel/getcancelexportlist", &StockManagerApiController{}, "Get:GetCancelExportList")
-
- //耗材调价
- beego.Router("/api/stock/postsearchgoodwarehouselist", &StockManagerApiController{}, "Get:GetSearchGoodWarehouseList")
- beego.Router("/api/stock/saveadjustprice", &StockManagerApiController{}, "Post:SaveAdjuestPrice")
- beego.Router("/api/stock/getallstockprice", &StockManagerApiController{}, "Get:GetAllStockPrice")
- beego.Router("/api/stock/savecheckedprice", &StockManagerApiController{}, "Get:SaveCheckPrice")
- beego.Router("/api/stock/getadjustpriceinfo", &StockManagerApiController{}, "Get:GetAdjustPriceById")
- beego.Router("/api/stock/savereportstock", &StockManagerApiController{}, "Post:SaveReportStock")
- beego.Router("/api/stock/getreportstocklist", &StockManagerApiController{}, "Get:GetReportStockList")
- beego.Router("/api/stock/savecheckdamage", &StockManagerApiController{}, "Get:SaveCheckDamage")
- beego.Router("/api/stock/saveinventory", &StockManagerApiController{}, "Post:SaveInventory")
- beego.Router("/api/stock/getinventorylist", &StockManagerApiController{}, "Get:GetInventorylist")
- beego.Router("/api/stock/savecheckinventory", &StockManagerApiController{}, "Get:SaveCheckInventory")
- beego.Router("/api/stock/getmodifypriceDetail", &StockManagerApiController{}, "Get:GetModifyPriceDetail")
- beego.Router("/api/stock/updatestockprice", &StockManagerApiController{}, "Get:UpdateStockPrice")
- beego.Router("/api/stock/deletestockprice", &StockManagerApiController{}, "Get:DeleteStockPrice")
- beego.Router("/api/stock/getstockdamagedetal", &StockManagerApiController{}, "Get:GetStockDamageDetail")
- beego.Router("/api/sotck/modifyprice", &StockManagerApiController{}, "Get:ModifyPrice")
- beego.Router("/api/stock/deletestockdamage", &StockManagerApiController{}, "Get:DeleteDamage")
- beego.Router("/api/stock/getstockdamagebyid", &StockManagerApiController{}, "Get:GetStockDamageById")
- beego.Router("api/sotck/getinventorydetail", &StockManagerApiController{}, "Get:GetInventoryDetail")
- beego.Router("/api/stock/modifyinventory", &StockManagerApiController{}, "Get:ModifyInventory")
- beego.Router("/api/stock/deleteinventory", &StockManagerApiController{}, "Get:DeleteInventory")
- beego.Router("/api/stock/getinventorydetaillist", &StockManagerApiController{}, "Get:GetInventoryDetailList")
- beego.Router("/api/stock/getinventoryprintlist", &StockManagerApiController{}, "Get:GetInventoryPrintList")
- beego.Router("/api/stock/getinventorydetailprintlist", &StockManagerApiController{}, "Get:GetInventoryDetailPrintList")
- beego.Router("/api/drug/deletedrugprice", &StockManagerApiController{}, "Get:DeleteDrugPrice")
- beego.Router("/api/stock/getgoodwarehouselist", &StockManagerApiController{}, "Get:GetGoodWarehouseList")
- beego.Router("/api/stock/proofinventory", &StockManagerApiController{}, "Get:ProofInventory")
- beego.Router("/api/stock/getwarehousetotal", &StockManagerApiController{}, "Get:GetWarehouseTotal")
- beego.Router("/api/stock/getgoodinventorywarehouselist", &StockManagerApiController{}, "Get:GetGoodInventoryWarehouseList")
- beego.Router("/api/stock/savestockinentorylist", &StockManagerApiController{}, "Post:SaveStockInventoryList")
- beego.Router("/api/sotck/getdamagedetailbygoodid", &StockManagerApiController{}, "Get:GetDamageDetailByGoodId")
- beego.Router("/api/stock/getinventoryexportlist", &StockManagerApiController{}, "Get:GetInventoryExportList")
-
- //处理历史数据
- beego.Router("/api/stock/updatecancelstockorder", &StockManagerApiController{}, "Get:UpdateCancelStockOrder")
-
- beego.Router("/api/stock/getdrugdetailsummary", &StockManagerApiController{}, "Get:GetDrugDetailSummary")
- beego.Router("/api/stock/getgooddetialsummary", &StockManagerApiController{}, "Get:GetGoodDetailSummary")
-
- //库存优化接口
- beego.Router("/api/stock/checkwarehouseout", &StockManagerApiController{}, "Get:CheckWarehouseOut")
- beego.Router("/api/stock/returncheckwarehouseout", &StockManagerApiController{}, "Get:ReturnCheckWarehouseOut")
- beego.Router("/api/stock/tocheckwarehouseinfo", &StockManagerApiController{}, "Get:CheckWarehouseInfo")
- beego.Router("/api/stock/returncheckwarehouseinfo", &StockManagerApiController{}, "Get:ReturnCheckWarehouseInfo")
- beego.Router("/api/stock/checkstockwarehouseinfo", &StockManagerApiController{}, "Get:CheckStockWarehouseInfo")
- beego.Router("/api/stock/checkreturnstockwarehouseinfo", &StockManagerApiController{}, "Get:CheckReturnStockWarehouseInfo")
- }
-
- func (c *StockManagerApiController) CreateWarehouse() {
-
- warehousing_time := c.GetString("warehousing_time")
- fmt.Println("warehousing_time我的", warehousing_time)
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- warehousing_info_id, _ := c.GetInt64("warehousing_info_id")
- ctime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- warehousing := models.Warehousing{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehousingTime: warehousingDate.Unix(),
- Type: types,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- if warehousing_info_id == 0 {
- service.AddSigleWarehouse(&warehousing)
- }
- if warehousing_info_id > 0 {
- service.UpdateWarehouse(warehousing_info_id, storehouse_id)
- }
- info, _ := service.FindLastWarehousingSix(adminUserInfo.CurrentOrgId)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingInfo []*models.WarehousingInfo
-
- if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockIn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
- utils.ErrorLog("warehousing_count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- total := float64(warehousing_count) * price
-
- if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
- utils.ErrorLog("packing_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
-
- var productDates int64
- var expiryDates int64
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- number, _ := items["number"].(string)
-
- remark, _ := items["remark"].(string)
-
- manufacturer := int64(items["manufacturer"].(float64))
- dealer := int64(items["dealer"].(float64))
-
- license_number, _ := items["license_number"].(string)
-
- register_number, _ := items["register_number"].(string)
- //入库单表格
- warehouseInfo := &models.WarehousingInfo{
- ID: id,
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: info.ID,
- GoodId: good_id,
- Number: number,
- GoodTypeId: good_type_id,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- StockCount: 0,
- Dealer: dealer,
- LicenseNumber: license_number,
- PackingPrice: packing_price,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- RegisterNumber: register_number,
- }
- warehousingInfo = append(warehousingInfo, warehouseInfo)
-
- }
- }
- }
-
- for _, item := range warehousingInfo {
- if item.ID == 0 {
- service.CreatedWarehouseingDetail(item)
- }
- if item.ID > 0 {
- service.UpdateWarehouseDetail(item, item.ID)
- }
-
- }
-
- //查询入库数据
- list, _ := service.GetGoodWarehouseInfoById(info.ID, info.OrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "入库成功",
- "warehousing_order": warehousing_order,
- "info": info,
- "list": list,
- "dealerList": dealerList,
- "manufacturerList": manufacturerList,
- })
-
- }
- func (c *StockManagerApiController) GetWarehouseList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- check_type, _ := c.GetInt64("check_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- var ids []int64
- var goodids []int64
- //查询商品名称
- if len(keywords) > 0 {
- //查询商品名称
- list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
- for _, item := range list {
- goodids = append(goodids, item.ID)
- //入库详情但里面查询
- }
- if len(goodids) > 0 {
- info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id)
- for _, it := range info {
- ids = append(ids, it.WarehousingId)
- }
- }
- }
-
- warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id, check_type)
- houselist, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseList,
- "total": total,
- "houselist": houselist,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockManagerApiController) GetWarehouseInfoList() {
-
- id := c.GetString("id")
- idArray := strings.Split(id, ",")
- warehousing, err := service.FindWarehousingByIdOne(idArray)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- var ids []int64
-
- for _, item := range warehousing {
- ids = append(ids, item.ID)
- }
-
- warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "info": warehousingInfo,
- "warehousing": warehousing,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockManagerApiController) EditWarehouse() {
- warehousing_time := c.GetString("warehousing_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehouse, _ := service.FindWarehousingById(id)
-
- warehousing := models.Warehousing{
- WarehousingOrder: warehouse.WarehousingOrder,
- OrgId: adminUserInfo.CurrentOrgId,
- Modifier: adminUserInfo.AdminUser.Id,
- Mtime: mtime,
- Status: 1,
- WarehousingTime: warehousingDate.Unix(),
- Type: warehouse.Type,
- StorehouseId: storehouse_id,
- }
-
- service.EditWarehousing(warehousing)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingInfo []*models.WarehousingInfo
- var upDateWarehousingInfo []*models.WarehousingInfo
- var stockFlow []*models.VmStockFlow
-
- if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockIn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
- utils.ErrorLog("warehousing_count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(warehousing_count) * price
- if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
- utils.ErrorLog("packing_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
- var productDates int64
- var expiryDates int64
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- number, _ := items["number"].(string)
-
- remark, _ := items["remark"].(string)
-
- manufacturer := int64(items["manufacturer"].(float64))
- dealer := int64(items["dealer"].(float64))
- license_number, _ := items["license_number"].(string)
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if id == 0 {
- warehouseInfo := &models.WarehousingInfo{
- WarehousingOrder: warehouse.WarehousingOrder,
- WarehousingId: warehouse.ID,
- GoodId: good_id,
- Number: number,
- GoodTypeId: good_type_id,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- StockCount: warehousing_count,
- LicenseNumber: license_number,
- PackingPrice: packing_price,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- warehousingInfo = append(warehousingInfo, warehouseInfo)
-
- } else {
-
- warehouseInfo := &models.WarehousingInfo{
- ID: id,
- WarehousingOrder: warehouse.WarehousingOrder,
- WarehousingId: warehouse.ID,
- GoodId: good_id,
- Number: number,
- GoodTypeId: good_type_id,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- LicenseNumber: license_number,
- PackingPrice: packing_price,
- StorehouseId: storehouse_id,
- }
- upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
-
- flow := &models.VmStockFlow{
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: id,
- GoodId: good_id,
- Number: number,
- ProductDate: productDates,
- ExpireDate: expiryDates,
- Count: warehousing_count,
- Price: price,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: manufacturer,
- Dealer: dealer,
- LicenseNumber: license_number,
- IsEdit: 2,
- Creator: adminUserInfo.AdminUser.Id,
- SystemTime: ctime,
- ConsumableType: 1,
- WarehousingDetailId: warehouseInfo.ID,
- StorehouseId: storehouse_id,
- }
-
- stockFlow = append(stockFlow, flow)
- }
- }
- }
- }
- var errs error
- if len(warehousingInfo) > 0 {
- errs = service.CreateWarehousingInfo(warehousingInfo)
- }
-
- if len(upDateWarehousingInfo) > 0 {
- for _, item := range upDateWarehousingInfo {
- service.UpdateWarehouseInfoByGoodIdOne(item, item.ID)
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- list, _ := service.GetAllStockInList(id, adminUserInfo.CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "编辑成功",
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
-
- }
- func (c *StockManagerApiController) DeleteWarehouse() {
- ids := c.GetString("ids")
- if len(ids) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- idArray := strings.Split(ids, ",")
- err := service.DeleteWarehouse(idArray)
- //删除流水
- service.DeleteStockFlow(idArray)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (c *StockManagerApiController) DeleteWarehouseInfo() {
- id, _ := c.GetInt64("id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- err := service.UpDateWarehouseStatus(id)
- service.UpdatedStockFlowById(id)
- //查询入库记录
- info, _ := service.GetWarehouseInfoByIdTwenty(id, orgId)
- //查询该机构默认仓库
- storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
- //查询剩余库存
- goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, orgId)
- var sum_count int64
- var sum_in_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- sum_in_count += item.WarehousingCount
- }
- service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
-
- func (c *StockManagerApiController) CreateSalesReturn() {
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- sales_return_time := c.GetString("time")
- types, _ := c.GetInt64("type", 0)
-
- salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- ctime := time.Now().Unix()
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- salesReturn := models.SalesReturn{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: salesReturnDate.Unix(),
- Dealer: dealer_id,
- Manufacturer: manufacturer_id,
- Type: types,
- }
-
- service.AddSigleSalesReturn(&salesReturn)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var salesReturnInfos []*models.SalesReturnInfo
-
- if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["salesReturn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
- return_count, _ := items["return_count"].(string)
- if len(return_count) == 0 {
- utils.ErrorLog("len(return_count) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
-
- return
- }
-
- count, _ := strconv.ParseInt(return_count, 10, 64)
- price, _ := strconv.ParseFloat(items["price"].(string), 10)
- total := float64(count) * price
-
- salesReturnInfo := &models.SalesReturnInfo{
- OrderNumber: salesReturn.OrderNumber,
- SalesReturnId: salesReturn.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Price: price,
- Total: total,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
-
- salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
-
- }
- }
- }
- errs := service.CreateSalesReturnInfo(salesReturnInfos)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "退货成功",
- })
-
- }
- func (c *StockManagerApiController) GetSalesReturnList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": returnList,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- func (this *StockManagerApiController) DeleteSalesReturn() {
- ids := this.GetString("ids")
-
- if len(ids) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- err := service.DeleteSalesReturn(idArray)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockManagerApiController) DeleteSalesReturnInfo() {
- id, _ := this.GetInt64("id", 0)
- fmt.Println(id)
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- err := service.UpDateSaleReturnStatus(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (this *StockManagerApiController) GetSalesReturnInfoList() {
- id, _ := this.GetInt64("id", 0)
- list, _ := service.FindAllSalesReturnInfoById(id)
- salesReturn, _ := service.FindAllSalesReturnById(id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "salesReturn": salesReturn,
- })
-
- }
- func (c *StockManagerApiController) EditReturnInfo() {
- return_time := c.GetString("return_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- dealer_id, _ := c.GetInt64("dealer_id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- salesReturns, _ := service.FindSalesReturnById(id)
-
- sales := models.SalesReturn{
- ID: salesReturns.ID,
- Mtime: mtime,
- ReturnTime: returnDate.Unix(),
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
-
- service.EditSaleReturn(sales)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var returnInfos []*models.SalesReturnInfo
- var upDateReturnInfos []*models.SalesReturnInfo
-
- if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["salesReturn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if id == 0 {
- returnInfo := &models.SalesReturnInfo{
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: sales.OrderNumber,
- SalesReturnId: sales.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- returnInfos = append(returnInfos, returnInfo)
-
- } else {
- returnInfo := &models.SalesReturnInfo{
- ID: id,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: sales.OrderNumber,
- SalesReturnId: sales.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- upDateReturnInfos = append(upDateReturnInfos, returnInfo)
- }
- }
- }
- }
- var errs error
- if len(returnInfos) > 0 {
- errs = service.CreateSalesReturnInfo(returnInfos)
- }
-
- if len(upDateReturnInfos) > 0 {
- for _, item := range upDateReturnInfos {
- errs = service.UpDateSalesReturnInfo(item)
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "编辑成功",
- })
-
- }
-
- func (c *StockManagerApiController) CreateWarehouseOut() {
-
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- warehouseOut_id, _ := c.GetInt64("warehouseOut_id")
-
- ctime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousing_out_time := c.GetString("warehousing_out_time")
- warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
-
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehouseOutTime: warehousingOutDate.Unix(),
- Type: types,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingOutInfo []*models.WarehouseOutInfo
-
- if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockOut"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- total := float64(count) * price
- remark := items["remark"].(string)
-
- manufacturer := int64(items["manufacturer"].(float64))
-
- dealer := int64(items["dealer"].(float64))
- number := items["number"].(string)
-
- expiry_date := items["expiry_date"].(string)
-
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
-
- admin_user_id := int64(items["admin_user_id"].(float64))
-
- if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
- utils.ErrorLog("buy_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
-
- stock_count := items["stock_count"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var expiryDate int64
- if len(expiry_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiryDate = theTime.Unix()
- }
-
- product_date := items["product_date"].(string)
-
- var productDate int64
- if len(product_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- productDate = theTime.Unix()
- }
- license_number := items["license_number"].(string)
-
- warehouseOutInfo := &models.WarehouseOutInfo{
- ID: id,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Number: number,
- ExpiryDate: expiryDate,
- ProductDate: productDate,
- Dealer: dealer,
- LicenseNumber: license_number,
- WarehouseInfotId: warehouse_info_id,
- StorehouseId: storehouse_id,
- AdminUserId: admin_user_id,
- BuyPrice: buy_price,
- StockCount: stock_count,
- IsCheck: 2,
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- }
- }
- }
- if warehouseOut_id == 0 {
- //查询是否生成出库单
- _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
- if errcodes == gorm.ErrRecordNotFound {
- service.AddSigleWarehouseOut(&warehouseOut)
- }
- }
- if warehouseOut_id > 0 {
- service.UpdateSingleWarehoseOut(warehouseOut_id, storehouse_id)
- }
-
- goodWarehouseOut, _ := service.GetLastGoodWarehouseOutTwenty(adminUserInfo.CurrentOrgId)
-
- for _, it := range warehousingOutInfo {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: goodWarehouseOut.ID,
- WarehouseInfotId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: it.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: it.Manufacturer,
- Dealer: it.Dealer,
- IsSys: 0,
- SysRecordTime: it.SysRecordTime,
- GoodTypeId: it.GoodTypeId,
- GoodId: it.GoodId,
- ExpiryDate: it.ExpiryDate,
- ProductDate: it.ProductDate,
- Number: it.Number,
- Price: it.Price,
- LicenseNumber: it.LicenseNumber,
- SupplyWarehouseId: 0,
- StorehouseId: storehouse_id,
- AdminUserId: it.AdminUserId,
- BuyPrice: it.BuyPrice,
- StockCount: it.StockCount,
- Count: it.Count,
- IsCheck: 2,
- }
- if it.ID == 0 {
- service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- }
- if it.ID > 0 {
- service.ModifyWarehouseOutInfo(it.ID, warehouseOutInfo)
- }
-
- //lastWarehouseOutInfo, _ := service.GetLastGoodWarehouseOutInfoById(it.OrgId)
-
- //if(it.ID == 0){
- // //创建出库流水
- // service.CreateStockFlowOne(stockFlow)
- //}
- //if(it.ID > 0){
- // //更新流水
- // service.UpdateWarehouseOutFlow(stockFlow,it.ID)
- //}
-
- }
- appId := adminUserInfo.CurrentAppId
-
- warehouseOutInfoList, _ := service.GetLastGoodWarehouseOutInfo(adminUserInfo.CurrentOrgId, goodWarehouseOut.ID)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "good_name": "",
- "specification_name": "",
- "warehouseOut": goodWarehouseOut,
- "warehouseOutInfoList": warehouseOutInfoList,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "doctorList": doctorList,
- })
- return
- }
- func (c *StockManagerApiController) GetWarehouseOutList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- way_type, _ := c.GetInt64("way_type")
- check_type, _ := c.GetInt64("check_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- var ids []int64
- var goodids []int64
- if len(keywords) > 0 {
- //查询商品名称
- list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
- for _, item := range list {
- goodids = append(goodids, item.ID)
- }
-
- if len(goodids) > 0 {
- //出库详情但里面查询
- info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id)
- for _, it := range info {
- ids = append(ids, it.WarehouseOutId)
- }
- }
-
- }
- warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id, way_type, check_type)
- houselist, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- fmt.Println(err)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutList,
- "total": total,
- "houselist": houselist,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockManagerApiController) DeleteWarehouseOut() {
- ids := c.GetString("ids")
-
- if len(ids) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
-
- err := service.DeleteWarehouseOut(idArray)
- //list, _ := service.GetWarehouseOutInfoByIds(idArray)
- //for _, item := range list {
- // //添加库存
- // service.UpdateWarehouseInfoById(item.WarehouseInfotId, item.Count)
- // //添加库存
- // //查询该机构默认仓库
- // storeConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询剩余库存
- // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, item.OrgId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, item := range goodList {
- // sum_count += item.StockCount
- // sum_in_count += item.WarehousingCount
- // }
- // service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
- //}
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
- id, _ := this.GetInt64("id", 0)
- fmt.Println(id)
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- err := service.UpDateWarehouseOutStatus(id)
- //添加库存
- //out, _ := service.GetWarhouseOutById(id)
- //
- //service.UpdateWareInfoById(out.WarehouseInfotId, out.Count)
- //
- ////查询该机构默认仓库
- //storeConfig, _ := service.GetAllStoreHouseConfig(out.OrgId)
- ////查询剩余库存
- //goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, out.GoodId, out.OrgId)
- //var sum_count int64
- //var sum_in_count int64
- //for _, item := range goodList {
- // sum_count += item.StockCount
- // sum_in_count += item.WarehousingCount
- //}
- //service.UpdateGoodByGoodId(out.GoodId, sum_count, sum_in_count, out.OrgId)
- //
- //
- //service.UpdateStockFlowWarehouseOutById(id)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (c *StockManagerApiController) GetWarehouseOutInfoList() {
- id, _ := c.GetInt64("id", 0)
- warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
- warehouseOut, _ := service.FindWareHouseOutById(id)
- adminUserInfo := c.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- wareoutList, _ := service.GetWareOutInfoById(id, orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutInfo,
- "info": warehouseOut,
- "wareoutList": wareoutList,
- })
-
- }
- func (c *StockManagerApiController) EditWarehouseOut() {
- warehouse_out_time := c.GetString("warehouse_out_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehouseOut, _ := service.FindWareHouseOutById(id)
-
- tempWarehouseOut := models.WarehouseOut{
- ID: warehouseOut.ID,
- Mtime: mtime,
- WarehouseOutTime: warehouseOutDate.Unix(),
- StorehouseId: storehouse_id,
- }
-
- service.EditWarehouseOut(tempWarehouseOut)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingOutInfo []*models.WarehouseOutInfo
- var upDateWarehouseOutInfos []*models.WarehouseOutInfo
-
- if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
- thisStockOut, _ := dataBody["stockOut"].([]interface{})
- if len(thisStockOut) > 0 {
- for _, item := range thisStockOut {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- total := float64(count) * price
- remark := items["remark"].(string)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- manufacturer := int64(items["manufacturer"].(float64))
-
- dealer := int64(items["dealer"].(float64))
-
- number := items["number"].(string)
-
- license_number := items["license_number"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- expiry_date := items["expiry_date"].(string)
-
- var expiryDate int64
- if len(expiry_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiryDate = theTime.Unix()
- }
-
- product_date := items["product_date"].(string)
-
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
-
- admin_user_id := int64(items["admin_user_id"].(float64))
-
- //if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
- // utils.ErrorLog("buy_price")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
- //buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
-
- stock_count := items["stock_count"].(string)
-
- var productDate int64
- if len(product_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- productDate = theTime.Unix()
- }
-
- if id == 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- IsSys: 0,
- SysRecordTime: 0,
- Number: number,
- ExpiryDate: expiryDate,
- ProductDate: productDate,
- Dealer: dealer,
- Manufacturer: manufacturer,
- LicenseNumber: license_number,
- ConsumableType: 1,
- WarehouseInfotId: warehouse_info_id,
- StorehouseId: storehouse_id,
- AdminUserId: admin_user_id,
- StockCount: stock_count,
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- } else {
- if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
- utils.ErrorLog("is_sys")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- is_sys := int64(items["is_sys"].(float64))
-
- if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
- utils.ErrorLog("sys_record_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- sys_record_time := int64(items["sys_record_time"].(float64))
-
- warehouseOutInfo := &models.WarehouseOutInfo{
- ID: id,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer,
- IsSys: is_sys,
- SysRecordTime: sys_record_time,
- Number: number,
- ExpiryDate: expiryDate,
- ProductDate: productDate,
- Dealer: dealer,
- LicenseNumber: license_number,
- ConsumableType: 2,
- WarehouseInfotId: warehouse_info_id,
- StorehouseId: storehouse_id,
- AdminUserId: admin_user_id,
- StockCount: stock_count,
- }
- upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
- }
- }
- }
- }
-
- var errs error
-
- //新增出库
- if len(warehousingOutInfo) > 0 {
-
- warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- for _, item := range warehousingOutInfo {
- service.AddSigleWarehouseOutInfo(item)
- }
- }
-
- if len(upDateWarehouseOutInfos) > 0 {
- for _, item := range upDateWarehouseOutInfos {
- service.UpDateWarehouseOutInfo(item)
- ////1.查询该耗材该批次的最后一次出库记录
- //lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, item.OrgId)
- //
- ////如果出库数量大于 最后一次批次的数量(那么要进行出库)
- //
- //if item.Count > lastGood.Count {
- //
- // //查询该耗材是否还有库存
- // warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId, item.StorehouseId)
- //
- // //无库存
- // if warehouseinfo.StockCount <= 0 {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "5",
- // })
- // return
- // }
- //
- // //有库存,进行出库,调用出库接口
- // if warehouseinfo.StockCount > 0 {
- // var total int64
- // var stock_cout int64
- // var total_count int64
- // //计算和最后一次出库数据的差
- // total = item.Count - lastGood.Count
- //
- // if total > warehouseinfo.StockCount {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "6",
- // })
- // return
- // }
- // //获取该耗材该批次的剩余库存量
- // info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
- //
- // //判断该批次的剩余库存 和出库的库存进行比较
- // //如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
- //
- // if total > info.StockCount {
- // //计算出库和该批次相差的库存
- // total_count = item.Count - info.StockCount
- // //清空本批次次库存
- // service.DeleteWarehouseInfo(item.WarehouseInfotId)
- // //调用出库逻辑
- // parseDateErr := service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- // return
- // }
- // }
- // //如果与上次比的库存小于或等于于该批次的剩余库存,那么需要该批次出库
- // if total <= info.StockCount {
- // stock_cout = lastGood.Count + total
- // fmt.Println(stock_cout)
- // //扣减库存
- // warehouse := models.WarehousingInfo{
- // StockCount: info.StockCount - total,
- // }
- // errs := service.UpdateWarehousingInfo(warehouse, info.ID)
- //
- // warehouseOutInfo := &models.WarehouseOutInfo{
- // WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- // WarehouseOutId: id,
- // WarehouseInfotId: item.WarehouseInfotId,
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Remark: item.Remark,
- // OrgId: item.OrgId,
- // Type: 1,
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // IsSys: 0,
- // SysRecordTime: item.SysRecordTime,
- // GoodTypeId: item.GoodTypeId,
- // GoodId: item.GoodId,
- // ExpiryDate: item.ExpiryDate,
- // ProductDate: item.ProductDate,
- // Number: item.Number,
- // Price: item.Price,
- // LicenseNumber: item.LicenseNumber,
- // Count: item.Count,
- // ConsumableType: 2,
- // StorehouseId: item.StorehouseId,
- // AdminUserId: item.AdminUserId,
- // StockCount: item.StockCount,
- // }
- //
- // //查询是否存在
- // _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
- // if errcode == gorm.ErrRecordNotFound {
- //
- // errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- // if errOne != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- // return
- // }
- // } else if errcode == nil {
- // service.UpDateWarehouseOutInfo(item)
- // //更新流水
- // flow := models.VmStockFlow{
- // Number: item.Number,
- // LicenseNumber: item.LicenseNumber,
- // Count: item.Count,
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // ProductDate: item.ProductDate,
- // ExpireDate: item.ExpiryDate,
- // Price: item.Price,
- // StorehouseId: item.StorehouseId,
- // AdminUserId: item.AdminUserId,
- // StockCount: item.StockCount,
- // }
- // service.UpdateStockFlowByDetailId(flow, item.ID)
- //
- // goodInfo := models.GoodInfo{
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // }
- // service.UpdatedGoodInfo(goodInfo, item.GoodId)
- // }
- // }
- // }
- //}
- //
- //var last_count int64
- //var all_total int64
- //var stock_total int64
- ////如果退库数量小于最后一次批次的数量(要么要进行退库)
- //if item.Count < lastGood.Count {
- //
- // //退库数量和最后一次出库数据进行计算
- // last_count = lastGood.Count - item.Count
- //
- // //获取该耗材该批次的剩余库存量
- // infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
- //
- // //退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
- // all_total = last_count + infoInfo.StockCount
- //
- // //如果库存大于总数量,则退回到这个批次
- //
- // if infoInfo.WarehousingCount > all_total {
- // stock_total = last_count + infoInfo.StockCount
- //
- // //退回该批次,计算数量
- // warehousingInfoOne := models.WarehousingInfo{
- // StockCount: stock_total,
- // ID: item.WarehouseInfotId,
- // OrgId: item.OrgId,
- // StorehouseId: item.StorehouseId,
- // }
- //
- // parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
- //
- // fmt.Println("parseDateErr", parseDateErr)
- // //插入一条新纪录
- // warehouseOutInfoThree := &models.WarehouseOutInfo{
- // WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
- // WarehouseOutId: id,
- // WarehouseInfotId: item.WarehouseInfotId,
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Remark: item.Remark,
- // OrgId: item.OrgId,
- // Type: 1,
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // IsSys: 0,
- // GoodTypeId: item.GoodTypeId,
- // GoodId: item.GoodId,
- // ExpiryDate: item.ExpiryDate,
- // ProductDate: item.ProductDate,
- // Number: item.Number,
- // Price: item.Price,
- // LicenseNumber: item.LicenseNumber,
- // ConsumableType: 2,
- // Count: item.Count,
- // StorehouseId: item.StorehouseId,
- // AdminUserId: item.AdminUserId,
- // StockCount: item.StockCount,
- // }
- // //查询是否存在
- // _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
- // if errcode == gorm.ErrRecordNotFound {
- // errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
- // if errOne != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- // return
- // }
- //
- // } else if errcode == nil {
- // service.UpDateWarehouseOutInfo(item)
- // flow := models.VmStockFlow{
- // Number: item.Number,
- // LicenseNumber: item.LicenseNumber,
- // Count: item.Count,
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // ProductDate: item.ProductDate,
- // ExpireDate: item.ExpiryDate,
- // Price: item.Price,
- // StorehouseId: item.StorehouseId,
- // AdminUserId: item.AdminUserId,
- // StockCount: item.StockCount,
- // }
- // service.UpdateStockFlowByDetailId(flow, item.ID)
- // goodInfo := models.GoodInfo{
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // }
- // service.UpdatedGoodInfo(goodInfo, item.GoodId)
- //
- // }
- // }
- //
- // //如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
- // if infoInfo.WarehousingCount < all_total {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "6",
- // })
- // return
- // }
- //}
- //
- //if item.Count == lastGood.Count {
- //
- // errs = service.UpDateWarehouseOutInfo(item)
- // flow := models.VmStockFlow{
- // Number: item.Number,
- // LicenseNumber: item.LicenseNumber,
- // Count: item.Count,
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // ProductDate: item.ProductDate,
- // ExpireDate: item.ExpiryDate,
- // Price: item.Price,
- // StorehouseId: item.StorehouseId,
- // AdminUserId: item.AdminUserId,
- // BuyPrice: item.BuyPrice,
- // StockCount: item.StockCount,
- // }
- // service.UpdateStockFlowByDetailId(flow, item.ID)
- // goodInfo := models.GoodInfo{
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // }
- // service.UpdatedGoodInfo(goodInfo, item.GoodId)
- //
- //}
- //
- ////查询该机构默认仓库
- //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- ////查询剩余库存
- //goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
- //var sum_count int64
- //var sum_in_count int64
- //for _, item := range goodList {
- // sum_count += item.StockCount
- // sum_in_count += item.WarehousingCount
- //}
- //service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
-
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
-
- }
-
- func (c *StockManagerApiController) CreateCancelStock() {
-
- cancel_stock_time := c.GetString("time")
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- cancel_stock_id, _ := c.GetInt64("cancel_stock_id")
- cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- ctime := time.Now().Unix()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: cancelStockDate.Unix(),
- Type: types,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- if cancel_stock_id == 0 {
- service.AddSigleCancelStock(&cancelStock)
- } else {
- service.UpdateSigleCancelStock(cancel_stock_id, storehouse_id)
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var cancelStockInfos []*models.CancelStockInfo
- if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["cancelStock"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- return_count, _ := items["return_count"].(string)
- if len(return_count) == 0 {
- utils.ErrorLog("len(return_count) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
-
- return
- }
-
- count, _ := strconv.ParseInt(return_count, 10, 64)
-
- number := items["number"].(string)
-
- register_account := items["register_account"].(string)
-
- manufacturer, _ := items["manufacturer"].(string)
-
- dealer, _ := items["dealer"].(string)
-
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
-
- var expiryDates int64
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
- }
-
- var productDates int64
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
-
- }
- }
-
- remark := items["remark"].(string)
-
- retail_prices := items["price"].(string)
- price, _ := strconv.ParseFloat(retail_prices, 64)
- cancelStockInfo := &models.CancelStockInfo{
- ID: id,
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Number: number,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- RegisterAccount: register_account,
- Remark: remark,
- Price: price,
- WarehouseInfoId: warehouse_info_id,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
-
- }
- }
- }
- lastCancelStock, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
- for _, item := range cancelStockInfos {
- item.CancelStockId = lastCancelStock.ID
- if item.ID == 0 {
- service.CreateCancelStockInfoOne(item)
- }
- if item.ID > 0 {
- service.ModifyCancelStockInfo(item.ID, item)
- }
- }
-
- list, _ := service.GetCancelStockInfo(lastCancelStock.ID, adminUserInfo.CurrentOrgId)
-
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
-
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
-
- // storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseId, item.OrgId)
- // goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- // info, _ := service.GetWarehoureOrderStockOutFlow(item.GoodId, item.OrgId, item.WarehouseInfoId, storehouse_id)
- // if item.Count > info.Count {
- // service.UpdateCancelInfo(item.CancelStockId)
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "good_name": goodObj.GoodName,
- // "specification_name": goodObj.SpecificationName,
- // "storehouse_name": storehouse.StorehouseName,
- // })
- // return
- // }
- //
- // //查询该批次入库的值
- // infolist, _ := service.GetWarehouseInfoByIdSeven(item.WarehouseInfoId)
- //
- // if item.Count > infolist.WarehousingCount {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "4",
- // "good_name": goodObj.GoodName,
- // "specification_name": goodObj.SpecificationName,
- // "storehouse_name": storehouse.StorehouseName,
- // })
- // return
- // }
- //
- // if item.Count <= infolist.WarehousingCount {
- // _, msgerrkonde := service.GetCancelStockDetailByOrderNumber(orderNumber, adminUserInfo.CurrentOrgId)
- // if msgerrkonde == gorm.ErrRecordNotFound {
- // service.AddSigleCancelStock(&cancelStock)
- // }
- // listcancel, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
- //
- // item.CancelStockId = listcancel.ID
- // errs := service.CreateCancelStockInfoOne(item)
- // list, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- //
- // var manufacturer_id int64
- //
- // for _, items := range list {
- // if item.Manufacturer == items.ManufacturerName {
- // manufacturer_id = items.ID
- // }
- // }
- // flow := models.VmStockFlow{
- // WarehousingId: 0,
- // GoodId: item.GoodId,
- // Number: item.Number,
- // LicenseNumber: "",
- // Count: item.Count,
- // UserOrgId: adminUserInfo.CurrentOrgId,
- // PatientId: 0,
- // SystemTime: time.Now().Unix(),
- // ConsumableType: 4,
- // IsSys: 0,
- // WarehousingOrder: "",
- // WarehouseOutId: 0,
- // WarehouseOutOrderNumber: "",
- // IsEdit: 0,
- // CancelStockId: cancelStock.ID,
- // CancelOrderNumber: cancelStock.OrderNumber,
- // Manufacturer: manufacturer_id,
- // Dealer: 0,
- // Creator: adminUserInfo.AdminUser.Id,
- // UpdateCreator: 0,
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // Price: item.Price,
- // WarehousingDetailId: 0,
- // WarehouseOutDetailId: 0,
- // CancelOutDetailId: 0,
- // ProductDate: item.ProductDate,
- // ExpireDate: item.ExpiryDate,
- // StorehouseId: item.StorehouseId,
- // }
- // cancelStockInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
- // flow.CancelStockId = cancelStockInfo.CancelStockId
- // flow.CancelOutDetailId = cancelStockInfo.ID
- // service.CreateStockFlowOne(flow)
- // if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- // return
- // }
- //
- // //查询该批次的剩余库存
- // wareouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
- // if (wareouseinfo.StockCount + item.Count) > wareouseinfo.WarehousingCount {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "5",
- // "good_name": goodObj.GoodName,
- // "specification_name": goodObj.SpecificationName,
- // "storehouse_name": storehouse.StorehouseName,
- // })
- // return
- // }
- // //更改入库数量
- // errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
- //
- // storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- // //查询剩余库存
- // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range goodList {
- // sum_count += it.StockCount
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, adminUserInfo.CurrentOrgId)
- //
- // if err != nil {
- // utils.ErrorLog(err.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // }
- //}
-
- c.ServeSuccessJSON(map[string]interface{}{
- "cancelStock": lastCancelStock,
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
- return
-
- }
- func (c *StockManagerApiController) GetCancelStockInfoList() {
- id, _ := c.GetInt64("id", 0)
-
- cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
- info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cancelStockInfoList,
- "info": info,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
-
- }
- func (c *StockManagerApiController) GetCancelStockList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- check_type, _ := c.GetInt64("check_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, storehouse_id, check_type)
- houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": returnList,
- "total": total,
- "houseList": houseList,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- func (this *StockManagerApiController) DeleteCancelStock() {
- ids := this.GetString("ids")
-
- if len(ids) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- ////获取
- //list, _ := service.GetCancelWarehosueInfo(idArray)
- //for _, item := range list {
- // info, _ := service.GetCancelStockById(item.WarehouseInfoId)
- // warehousingInfo := models.WarehousingInfo{
- // StockCount: info.Count,
- // }
- // //扣减库存
- // service.ModefyWarehouseInfoNight(warehousingInfo, info.WarehouseInfoId)
- //
- // //查询该机构默认仓库
- // storeConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询剩余库存
- // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, item.OrgId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, item := range goodList {
- // sum_count += item.StockCount
- // sum_in_count += item.WarehousingCount
- // }
- // service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
- //
- // //删除流水
- // service.UpdatedStockFlowByCancelId(info.ID, info.GoodId)
- //}
- //获取
- err := service.DeleteCancelStock(idArray)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockManagerApiController) DeleteCancelStockInfo() {
- id, _ := this.GetInt64("id", 0)
- fmt.Println(id)
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ////改变库存
- //info, _ := service.GetCancelStockById(id)
- //
- //warehousingInfo := models.WarehousingInfo{
- // StockCount: info.Count,
- //}
- ////扣减库存
- //service.ModefyWarehouseInfoNight(warehousingInfo, info.WarehouseInfoId)
- //
- ////查询该机构默认仓库
- //storeConfig, _ := service.GetAllStoreHouseConfig(info.OrgId)
- ////查询剩余库存
- //goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, info.OrgId)
- //var sum_count int64
- //var sum_in_count int64
- //for _, item := range goodList {
- // sum_count += item.StockCount
- // sum_in_count += item.WarehousingCount
- //}
- //service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
-
- //删除详情
- err := service.UpDateCancleStockStatus(id)
- //删除流水
- //err = service.UpdatedStockFlowByCancelId(id, info.GoodId)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (c *StockManagerApiController) EditCancelStock() {
- cancel_time := c.GetString("cancel_time")
- id, _ := c.GetInt64("id", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
-
- tempCancelStock := models.CancelStock{
- ID: cancelStock.ID,
- Mtime: mtime,
- ReturnTime: cancelDate.Unix(),
- StorehouseId: storehouse_id,
- }
-
- service.EditCancelStock(tempCancelStock)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var cancelStockInfos []*models.CancelStockInfo
- var upDateCancelStockInfos []*models.CancelStockInfo
- var stockFlow []*models.VmStockFlow
- if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
- thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
- if len(thisCancelStock) > 0 {
- for _, item := range thisCancelStock {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
- number := items["number"].(string)
-
- register_account := items["register_account"].(string)
-
- manufacturer, _ := items["manufacturer"].(string)
-
- dealer, _ := items["dealer"].(string)
-
- remark := items["remark"].(string)
-
- var productDates int64
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
-
- }
-
- }
- var expiryDates int64
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
- if id == 0 {
- cancelStockInfo := &models.CancelStockInfo{
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- Mtime: time.Now().Unix(),
- Number: number,
- RegisterAccount: register_account,
- Manufacturer: manufacturer,
- Dealer: dealer,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- Remark: remark,
- Price: price,
- WarehouseInfoId: warehouse_info_id,
- StorehouseId: storehouse_id,
- }
- cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
-
- flow := &models.VmStockFlow{
- WarehousingId: 0,
- GoodId: good_id,
- Number: number,
- LicenseNumber: "",
- Count: count,
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: 0,
- SystemTime: time.Now().Unix(),
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 2,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: 0,
- Dealer: 0,
- Creator: adminUserInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: price,
- WarehousingDetailId: warehouse_info_id,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ProductDate: productDates,
- ExpireDate: expiryDates,
- StorehouseId: storehouse_id,
- }
-
- stockFlow = append(stockFlow, flow)
-
- } else {
- cancelStockInfo := &models.CancelStockInfo{
- ID: id,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- Mtime: time.Now().Unix(),
- Number: number,
- RegisterAccount: register_account,
- Manufacturer: manufacturer,
- Dealer: dealer,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- Remark: remark,
- Price: price,
- WarehouseInfoId: warehouse_info_id,
- StorehouseId: storehouse_id,
- }
- upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
-
- list, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
-
- var manufacuture_id int64
- for _, it := range list {
- if it.ManufacturerName == manufacturer {
- manufacuture_id = it.ID
- }
- }
-
- flow := &models.VmStockFlow{
- WarehousingId: 0,
- GoodId: good_id,
- Number: number,
- LicenseNumber: "",
- Count: count,
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: 0,
- SystemTime: time.Now().Unix(),
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 2,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: manufacuture_id,
- Dealer: 0,
- Creator: adminUserInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: price,
- WarehousingDetailId: warehouse_info_id,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ProductDate: productDates,
- ExpireDate: expiryDates,
- StorehouseId: storehouse_id,
- }
-
- stockFlow = append(stockFlow, flow)
- }
- }
- }
- }
- var errs error
- for _, item := range cancelStockInfos {
- service.CreateCancelStockInfoOne(item)
- }
- if len(upDateCancelStockInfos) > 0 {
- for _, item := range upDateCancelStockInfos {
- service.ModifyCancelStockInfo(item.ID, item)
- }
- }
- //判断是否更改了仓库
- //if storehouse_id == cancelStock.ID {
- //
- // if len(cancelStockInfos) > 0 {
- //
- // for _, item := range cancelStockInfos {
- // //统计该耗材的出库数量
- // info, _ := service.GetWarehoureOrderStockOutFlow(item.GoodId, item.OrgId, item.WarehouseInfoId, storehouse_id)
- // storeObj, _ := service.FindStoreHouseByStorehouseId(storehouse_id, item.OrgId)
- // if item.Count > info.Count {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "storehouse_name": storeObj.StorehouseName,
- // })
- // return
- // }
- // //查询该批次入库的值
- // infolist, _ := service.GetWarehouseInfoByIdSix(item.WarehouseInfoId, storehouse_id)
- //
- // if item.Count > infolist.WarehousingCount {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "4",
- // "storehouse_name": storeObj.StorehouseName,
- // })
- // return
- // }
- //
- // if item.Count <= infolist.WarehousingCount {
- //
- // errs := service.CreateCancelStockInfo(cancelStockInfos)
- //
- // if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- // return
- // }
- //
- // //更改入库数量
- // errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
- //
- // //查询该机构默认仓库
- // storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- // //查询剩余库存
- // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range goodList {
- // sum_count += it.StockCount
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, adminUserInfo.CurrentOrgId)
- //
- // break
- // }
- //
- // }
- //
- // if len(stockFlow) > 0 {
- // for _, itemcancel := range stockFlow {
- // //查询是否存在
- // stockInfo, errcode := service.IsExsitStockFlow(itemcancel.GoodId, itemcancel.CancelOrderNumber)
- // if errcode == gorm.ErrRecordNotFound {
- // service.CreateStockFlowSix(itemcancel)
- // } else {
- // flow := models.VmStockFlow{
- // Count: itemcancel.Count,
- // Manufacturer: itemcancel.Manufacturer,
- // Dealer: itemcancel.Dealer,
- // Price: itemcancel.Price,
- // ProductDate: itemcancel.ProductDate,
- // ExpireDate: itemcancel.ExpireDate,
- // StorehouseId: itemcancel.StorehouseId,
- // }
- // service.UpdateStockFlowThree(stockInfo.ID, flow)
- // }
- // }
- // }
- // }
- //
- // if len(upDateCancelStockInfos) > 0 {
- // for _, item := range upDateCancelStockInfos {
- //
- // var all_total int64
- // //获取该批次最后一套退库记录
- // info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
- // //查询该批次总的退库数量
- // list, _ := service.GetAllCancelInfoById(item.WarehouseInfoId, item.GoodId)
- // for _, it := range list {
- // all_total += it.Count
- // }
- //
- // //比较退库库数量和最后一次退库库数据大小
- // //退库(加)
- // if item.Count > info.Count {
- // var total = item.Count - info.Count
- // errs = service.UpDateCancelStockInfo(item)
- //
- // warehouseinfo, _ := service.GetWarehouseInfoByIdSix(item.WarehouseInfoId, storehouse_id)
- // storeObj, _ := service.FindStoreHouseByStorehouseId(storehouse_id, item.OrgId)
- //
- // // 总退库数量大于入库数据
- // if all_total > warehouseinfo.StockCount {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "5",
- // "storehouse_name": storeObj.StorehouseName,
- // })
- // return
- // }
- // parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- // break
- // }
- // }
- // //(减)
- // if item.Count < info.Count {
- // errs = service.UpDateCancelStockInfo(item)
- //
- // var total_count = info.Count - item.Count
- //
- // parseDateErr := service.UpdateWareInfoByIdSix(item.WarehouseInfoId, total_count)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- // return
- // }
- //
- // }
- // if item.Count == info.Count {
- // errs = service.UpDateCancelStockInfo(item)
- //
- // }
- //
- // //查询该机构默认仓库
- // storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- // //查询剩余库存
- // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range goodList {
- // sum_count += it.StockCount
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, adminUserInfo.CurrentOrgId)
- // }
- // }
- //
- // if len(stockFlow) > 0 {
- // for _, itemcancel := range stockFlow {
- //
- // //查询是否存在
- // stockInfo, errcode := service.IsExsitStockFlow(itemcancel.GoodId, itemcancel.CancelOrderNumber)
- // if errcode == gorm.ErrRecordNotFound {
- //
- // } else {
- // flow := models.VmStockFlow{
- // Count: itemcancel.Count,
- // Manufacturer: itemcancel.Manufacturer,
- // Dealer: itemcancel.Dealer,
- // Price: itemcancel.Price,
- // LicenseNumber: itemcancel.LicenseNumber,
- // Number: itemcancel.Number,
- // ExpireDate: itemcancel.ExpireDate,
- // ProductDate: itemcancel.ProductDate,
- // StorehouseId: itemcancel.StorehouseId,
- // }
- // service.UpdateStockFlowThree(stockInfo.ID, flow)
- // }
- // }
- // }
- //
- //}
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- })
-
- }
- func (this *StockManagerApiController) GetCancelStockConfig() {
- types, _ := this.GetInt64("type", 0)
- adminUserInfo := this.GetAdminUserInfo()
- warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
- this.ServeSuccessJSON(map[string]interface{}{
- "warehouseOutInfoList": warehouseOutInfoList,
- })
- }
-
- func (c *StockManagerApiController) GetQueryInfo() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- keyword := c.GetString("keyword")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- type_name, _ := c.GetInt64("type_name")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- adminUserInfo := c.GetAdminUserInfo()
- list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
- info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
-
- infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "info": info,
- "infomationList": infomationList,
- "orgid": adminUserInfo.CurrentOrgId,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (c *StockManagerApiController) SearchWarehouse() {
- keywords := c.GetString("keywords")
- adminUserInfo := c.GetAdminUserInfo()
- warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseList,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockManagerApiController) GetAllConfig() {
- adminUserInfo := c.GetAdminUserInfo()
- manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
- dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
- goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
- goodInfo, _ := service.FindAllGoodInfoTwo(adminUserInfo.CurrentOrgId)
-
- //获取所有仓库看列表
- list, _ := service.GetAllStoreHouseListThree(adminUserInfo.CurrentOrgId)
- //获取仓库配置列表
- configList, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- appId := c.GetAdminUserInfo().CurrentAppId
- doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
- c.ServeSuccessJSON(map[string]interface{}{
- "manufacturer": manufacturer,
- "dealer": dealer,
- "goodType": goodType,
- "goodInfo": goodInfo,
- "list": list,
- "configlist": configList,
- "doctorList": doctorList,
- })
- }
- func (this *StockManagerApiController) GetAllSalesReturnConfig() {
- types, _ := this.GetInt64("type", 0)
- adminUserInfo := this.GetAdminUserInfo()
- warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
- this.ServeSuccessJSON(map[string]interface{}{
- "warehouseInfoList": warehouseInfoList,
- })
- }
-
- func (this *StockManagerApiController) GetDetailInfo() {
-
- page, _ := this.GetInt64("page", 0)
- limit, _ := this.GetInt64("limit", 0)
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- types, _ := this.GetInt64("type", 0)
-
- keywords := this.GetString("keywords")
- manufacturer, _ := this.GetInt64("manufacturer", 0)
- order_type, _ := this.GetInt64("order_type", 0)
- dealer, _ := this.GetInt64("dealer", 0)
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := this.GetAdminUserInfo()
-
- var list []*models.WarehousingInfo
- var list1 []*models.WarehouseOutInfo
- var list2 []*models.SalesReturnInfo
- var list3 []*models.CancelStockInfo
-
- var total int64
- var err error
- var total_price float64
- houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- if types == 1 {
- list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
- _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "total_price": total_price,
- "houseList": houseList,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- } else if types == 2 {
- list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
- _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list1,
- "total": total,
- "total_price": total_price,
- "houseList": houseList,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- } else if types == 3 {
- list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list2,
- "total": total,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- } else if types == 4 {
- list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
- listGroup, err := service.FindeCancelGroup(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list3,
- "total": total,
- "listgroup": listGroup,
- "houseList": houseList,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- }
-
- func (this *StockManagerApiController) GetUserDetailInfo() {
- order_id, _ := this.GetInt64("id")
- if order_id <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := this.GetAdminUserInfo()
- userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": userDetails,
- "total": total,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func (this *StockManagerApiController) PostSearchStock() {
-
- keyword := this.GetString("keyword")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- stock, err := service.PostSearchStock(keyword, orgId)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "stock": stock,
- })
- }
-
- func (this *StockManagerApiController) GetOutStockTotalCount() {
-
- warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
- adminUserInfo := this.GetAdminUserInfo()
- stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "stockCount": stockCount,
- })
- }
-
- func (this *StockManagerApiController) AddGoodInformation() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- var goods []*models.GoodInfo
- var total_goods []interface{}
- tempGoods := dataBody["goods"].([]interface{})
-
- total_goods = tempGoods
- for index, goodMap := range tempGoods {
- goodNameM := goodMap.(map[string]interface{})
-
- var good models.GoodInfo
-
- if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- return
- }
-
- good_name, _ := goodNameM["good_name"].(string)
- if len(good_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.GoodName = good_name
-
- // 获取数据字典数据
- var good_kind_id int64
- var name = "耗材种类"
- config, _ := service.GetDrugDataConfig(0, name)
-
- good_kind := goodNameM["good_kind"].(string)
-
- if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- if len(good_kind) != 0 {
- _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
- lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: config.ID,
- Module: "system",
- OrgId: orgId,
- Name: good_kind,
- FieldName: "",
- Value: lastConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUserInfo.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- if errcodegoodkind == gorm.ErrRecordNotFound {
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
- for _, it := range dataConfig {
- if good_kind == it.Name {
- fmt.Println(it.Name)
- good_kind_id = int64(it.Value)
- }
- }
- good.GoodKind = good_kind_id
-
- good_type := goodNameM["type_name"].(string)
- if len(good_type) == 0 {
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- if len(good_type) != 0 {
- _, errcodegoodtype := service.GetGoodType(good_type, orgId)
- if errcodegoodtype == gorm.ErrRecordNotFound {
- goodsType := models.GoodsType{
- TypeName: good_type,
- Remark: "",
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Creater: adminUserInfo.AdminUser.Id,
- Modifier: 0,
- OrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- Type: 0,
- Number: 0,
- OutStock: 0,
- StockAttribute: 1,
- }
- service.CreatedGoodType(&goodsType)
- }
- }
-
- goodType, _ := service.GetAllGoodType(orgId)
- var good_type_id int64
- for _, it := range goodType {
- if good_type == it.TypeName {
- good_type_id = it.ID
- }
- }
- good.GoodTypeId = good_type_id
-
- medical_insurance_level := goodNameM["medical_insurance_level"].(string)
- if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var medical_insurance_id int64
- var medicalInsurance = "医保等级"
- medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
-
- if len(medical_insurance_level) != 0 {
- _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
- if errcodemedicalInsurance == gorm.ErrRecordNotFound {
- mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: medicalInsuranceDataConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: medical_insurance_level,
- FieldName: "",
- Value: mediConfigOne.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUserInfo.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
- for _, it := range medicalInsuranceList {
- if medical_insurance_level == it.Name {
- medical_insurance_id = int64(it.Value)
- }
- }
- good.MedicalInsuranceLevel = medical_insurance_id
-
- if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- return
- }
- specification_name := goodNameM["specification_name"].(string)
- if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.SpecificationName = specification_name
-
- var manufacturer_id int64
- manufacturer := goodNameM["manufacturer"].(string)
- if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- if len(manufacturer) != 0 {
- _, errcodes := service.GetManufacturerName(orgId, manufacturer)
- manu := models.Manufacturer{
- ManufacturerName: manufacturer,
- Status: 1,
- OrgId: orgId,
- Creater: adminUserInfo.AdminUser.Id,
- }
- if errcodes == gorm.ErrRecordNotFound {
-
- service.CreateManufacturer(&manu)
-
- }
- }
-
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- for _, it := range manufacturerList {
- if manufacturer == it.ManufacturerName {
- manufacturer_id = it.ID
- }
- }
-
- good.Manufacturer = manufacturer_id
-
- if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
- utils.ErrorLog("unit_id")
- return
- }
-
- unit_id := int64(goodNameM["unit_id"].(float64))
- if unit_id <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.GoodUnit = unit_id
-
- retail_prices := goodNameM["retail_price"].(string)
- retail_price, _ := strconv.ParseFloat(retail_prices, 64)
- if retail_price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.RetailPrice = retail_price
-
- if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
- utils.ErrorLog("stock_warn_count")
- return
- }
-
- stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
- if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.StockWarnCount = stock_warn_count
-
- var dealer_id int64
- dealerName := goodNameM["dealer"].(string)
-
- fmt.Println("经销商", dealerName)
- dealer := models.Dealer{
- OrgId: orgId,
- Status: 1,
- DealerName: dealerName,
- Creater: adminUserInfo.AdminUser.Id,
- Ctime: time.Now().Unix(),
- }
- if len(dealerName) != 0 {
- _, errcodedealer := service.GetDealerByName(orgId, dealerName)
-
- if errcodedealer == gorm.ErrRecordNotFound {
- service.CreateDealer(&dealer)
- }
- }
-
- dealerList, _ := service.GetAllDealerList(orgId)
- for _, it := range dealerList {
- if dealerName == it.DealerName {
- dealer_id = it.ID
- }
- }
-
- good.Dealer = dealer_id
- if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
- utils.ErrorLog("pinyin")
- return
- }
- pinyin := goodNameM["pinyin"].(string)
-
- good.Pinyin = pinyin
-
- if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
- utils.ErrorLog("wubi")
- return
- }
- wubi := goodNameM["wubi"].(string)
-
- good.Wubi = wubi
-
- buy_prices := goodNameM["buy_price"].(string)
- buy_price, _ := strconv.ParseFloat(buy_prices, 64)
- good.BuyPrice = buy_price
-
- if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
- utils.ErrorLog("social_security_directory_code")
- return
- }
- social_security_directory_code := goodNameM["social_security_directory_code"].(string)
-
- good.SocialSecurityDirectoryCode = social_security_directory_code
-
- if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
- utils.ErrorLog("is_special_diseases")
- return
- }
-
- is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
- good.IsSpecialDiseases = is_special_diseases
-
- if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
- utils.ErrorLog("is_record")
- return
- }
-
- is_record := int64(goodNameM["is_record"].(float64))
- good.IsRecord = is_record
-
- if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
- utils.ErrorLog("good_status")
- return
- }
- good_status := goodNameM["good_status"].(string)
- good.GoodStatus = good_status
-
- if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
- utils.ErrorLog("medical_insurance_number")
- return
- }
- medical_insurance_number := goodNameM["medical_insurance_number"].(string)
- good.MedicalInsuranceNumber = medical_insurance_number
-
- if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
- utils.ErrorLog("production_type")
- return
- }
- production_type := goodNameM["production_type"].(string)
- good.ProductionType = production_type
-
- if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- return
- }
- remark := goodNameM["remark"].(string)
- good.Remark = remark
-
- statistics_category := goodNameM["statistics_category"].(string)
-
- var categoryName = "统计分类"
- var statistic_id int64
- drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
-
- if len(statistics_category) != 0 {
- _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
-
- if errcodecagegory == gorm.ErrRecordNotFound {
- dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: drugDataConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: statistics_category,
- FieldName: "",
- Value: dicConfigThree.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUserInfo.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
-
- for _, it := range parentDataConfig {
- if statistics_category == it.Name {
- statistic_id = int64(it.Value)
- }
- }
-
- good.StatisticsCategory = statistic_id
-
- special_medical := goodNameM["special_medical"].(string)
- good.SpecialMedical = special_medical
- goods = append(goods, &good)
-
- }
-
- export_time := time.Now().Unix()
- errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
- if len(goods) > 0 {
-
- for _, item := range goods {
-
- goodInfo := models.GoodInfo{
- GoodName: item.GoodName,
- SpecificationName: item.SpecificationName,
- GoodKind: item.GoodKind,
- GoodTypeId: item.GoodTypeId,
- Dealer: item.Dealer,
- GoodUnit: item.GoodUnit,
- IsRecord: item.IsRecord,
- IsSpecialDiseases: item.IsSpecialDiseases,
- Manufacturer: item.Manufacturer,
- Pinyin: item.Pinyin,
- GoodStatus: item.GoodStatus,
- ProductionType: item.ProductionType,
- Remark: item.Remark,
- RetailPrice: item.RetailPrice,
- SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
- SpecialMedical: item.SpecialMedical,
- Wubi: item.Wubi,
- StockWarnCount: item.StockWarnCount,
- MedicalInsuranceLevel: item.MedicalInsuranceLevel,
- OrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- StatisticsCategory: item.StatisticsCategory,
- GoodCode: item.GoodCode,
- BuyPrice: item.BuyPrice,
- MedicalInsuranceNumber: item.MedicalInsuranceNumber,
- }
-
- //查询同种耗材名称同种类型同种规格的耗材是否存在
- _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
-
- if errcodegood == gorm.ErrRecordNotFound {
- service.CreateGoodsInfomation(&goodInfo)
- } else if errcodegood == nil {
- service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
- }
-
- log := models.ExportLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(goods)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(goods),
- "fail_num": int64(len(errLogs)),
- })
- }
- } else {
- log := models.ExportLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(goods)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(goods),
- "fail_num": int64(len(errLogs)),
- })
- }
- }
-
- func (this *StockManagerApiController) AddDrugInformation() {
- adminUser := this.GetAdminUserInfo()
- orgId := adminUser.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- var drugList []*models.BaseDrugLib
- var total_goods []interface{}
- tempDrugs := dataBody["drugs"].([]interface{})
-
- total_goods = tempDrugs
- for index, drugMap := range tempDrugs {
-
- goodNameM := drugMap.(map[string]interface{})
- var drug models.BaseDrugLib
- if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return
- }
-
- drug_name, _ := goodNameM["drug_name"].(string)
- if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugName = drug_name
-
- dose := goodNameM["dose"].(float64)
- if dose < 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.Dose = dose
-
- dose_unit := goodNameM["dose_unit"].(string)
- if dose < 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DoseUnit = dose_unit
-
- if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
- utils.ErrorLog("min_number")
- return
- }
-
- min_number, _ := goodNameM["min_number"].(string)
- minNumber, _ := strconv.ParseInt(min_number, 10, 64)
- if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MinNumber = minNumber
-
- min_unit := goodNameM["min_unit"].(string)
- if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MinUnit = min_unit
-
- max_unit_id := goodNameM["max_unit"].(string)
- if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MaxUnit = max_unit_id
-
- max_unit := goodNameM["max_unit"].(string)
- if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MaxUnit = max_unit
-
- drug_type := goodNameM["drug_type"].(string)
- if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var drug_type_id int64
- var drugType = "药品类型"
-
- drugconfig, _ := service.GetDrugDataConfig(0, drugType)
- if len(drug_type) != 0 {
- _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
- if errcodes == gorm.ErrRecordNotFound {
- //获取该型号最后一条数据型号
- config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
-
- dataconfig := models.DictDataconfig{
- ParentId: drugconfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_type,
- FieldName: "",
- Value: config.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
- for _, it := range drugTypeList {
- if drug_type == it.Name {
- drug_type_id = int64(it.Value)
- }
- }
-
- drug.DrugType = drug_type_id
-
- drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
- if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugStockLimit = drug_stock_limit
-
- drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
- if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugOriginPlace = drug_origin_place
-
- drug_dosage_form := goodNameM["drug_dosage_form"].(string)
-
- if len(drug_dosage_form) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var drug_dosage = "药品剂型"
- var drug_dosage_form_id int64
- drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
- if len(drug_dosage_form) != 0 {
- _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
- if errcodess == gorm.ErrRecordNotFound {
- configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: drugDosageconfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_dosage_form,
- FieldName: "",
- Value: configOne.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
- for _, it := range drugDosageList {
- if drug_dosage_form == it.Name {
- drug_dosage_form_id = int64(it.Value)
- }
- }
-
- drug.DrugDosageForm = drug_dosage_form_id
-
- retail_prices := goodNameM["retail_price"].(string)
- retail_price, _ := strconv.ParseFloat(retail_prices, 64)
-
- if retail_price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.RetailPrice = retail_price
-
- last_prices := goodNameM["last_price"].(string)
- last_price, _ := strconv.ParseFloat(last_prices, 64)
- if last_price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.LastPrice = last_price
-
- drug_classify := goodNameM["drug_classify"].(string)
-
- if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var drugClassify = "药物分类"
- var drug_classify_id int64
- drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
-
- if len(drug_classify) != 0 {
- _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
- if errcodesClass == gorm.ErrRecordNotFound {
- drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: drugClassifyConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_classify,
- FieldName: "",
- Value: drugClassConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
- for _, it := range drugClassList {
- if drug_classify == it.Name {
- drug_classify_id = int64(it.Value)
- }
- }
-
- drug_dose := goodNameM["drug_dose"].(string)
-
- if len(drug_dose) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
- drug.DrugDose = drugDoses
-
- var units = "单位"
- var unit_id int64
- drugDoseUnit := goodNameM["drug_dose_unit"].(string)
-
- if len(drugDoseUnit) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- manufacturer := goodNameM["manufacturer"].(string)
- if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- if len(manufacturer) != 0 {
- _, errcodema := service.GetManufacturerName(orgId, manufacturer)
- if errcodema == gorm.ErrRecordNotFound {
- manufactur := models.Manufacturer{
- OrgId: orgId,
- Status: 1,
- ManufacturerName: manufacturer,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- }
- service.CreateManufacturer(&manufactur)
- }
- }
-
- var manufacturer_id int64
-
- manufacturList, _ := service.GetAllManufacturerList(orgId)
- for _, it := range manufacturList {
- if manufacturer == it.ManufacturerName {
- manufacturer_id = it.ID
- }
- }
-
- drug.Manufacturer = manufacturer_id
-
- dealer := goodNameM["dealer"].(string)
- if len(dealer) != 0 {
- _, errcodesdealer := service.GetDealerByName(orgId, dealer)
- if errcodesdealer == gorm.ErrRecordNotFound {
- dealerconfig := models.Dealer{
- DealerName: dealer,
- Status: 1,
- OrgId: orgId,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- }
- service.CreateDealer(&dealerconfig)
- }
- }
-
- var dealer_id int64
- dealerList, _ := service.GetAllDealerList(orgId)
- for _, it := range dealerList {
- if dealer == it.DealerName {
- dealer_id = it.ID
- }
- }
- drug.Dealer = dealer_id
-
- delivery_way := goodNameM["delivery_way"].(string)
- //if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
- // err_log := models.ExportErrLog{
- // LogType: 4,
- // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- // ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
- // Status: 1,
- // CreateTime: time.Now().Unix(),
- // UpdateTime: time.Now().Unix(),
- // ExportTime: time.Now().Unix(),
- // }
- // service.CreateExportErrLog(&err_log)
- // continue
- //}
-
- drug.DeliveryWay = delivery_way
-
- execution_frequency := goodNameM["execution_frequency"].(string)
- //if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
- // err_log := models.ExportErrLog{
- // LogType: 4,
- // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- // ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
- // Status: 1,
- // CreateTime: time.Now().Unix(),
- // UpdateTime: time.Now().Unix(),
- // ExportTime: time.Now().Unix(),
- // }
- // service.CreateExportErrLog(&err_log)
- // continue
- //}
-
- drug.ExecutionFrequency = execution_frequency
-
- lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
-
- drug.LmtUsedFlag = lmt_used_flags
-
- dataConfig, _ := service.GetDataConfigIsExist(0, units)
- if len(drugDoseUnit) != 0 {
- _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
- if errcodedataconfig == gorm.ErrRecordNotFound {
- childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
- dataconfig := models.Dataconfig{
- ParentId: dataConfig.ID,
- Module: "hemodialysis",
- OrgId: orgId,
- Name: drugDoseUnit,
- FieldName: "",
- Value: childConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- FieldType: 0,
- }
- service.CreateDataConfig(&dataconfig)
- }
- }
- list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
- for _, it := range list {
- if drugDoseUnit == it.Name {
- unit_id = int64(it.Value)
- }
- }
- drug.DrugDoseUnit = unit_id
-
- drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
-
- if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
- utils.ErrorLog("drug_alias")
- return
- }
-
- drug_alias, _ := goodNameM["drug_alias"].(string)
-
- drug.DrugAlias = drug_alias
-
- drug_category := goodNameM["drug_category"].(string)
-
- var drugCategory = "药品类别"
- var drug_category_id int64
-
- drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
-
- if len(drug_category) != 0 {
- _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
- if drugcategoryerrcodes == gorm.ErrRecordNotFound {
- drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: drugCategoryConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_category,
- FieldName: "",
- Value: drugCategoryConfigSix.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
- fmt.Println("drugCategoryList", drugCategoryList)
- for _, it := range drugCategoryList {
- if drug_category == it.Name {
- drug_category_id = int64(it.Value)
- }
- }
-
- drug.DrugCategory = drug_category_id
-
- statistics_category := goodNameM["statistics_category"].(string)
- for index, drugMap := range tempDrugs {
-
- goodNameM := drugMap.(map[string]interface{})
- var drug models.BaseDrugLib
- if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return
- }
-
- drug_name, _ := goodNameM["drug_name"].(string)
- if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugName = drug_name
-
- dose := goodNameM["dose"].(float64)
- if dose < 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.Dose = dose
-
- dose_unit := goodNameM["dose_unit"].(string)
- if dose < 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DoseUnit = dose_unit
-
- if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
- utils.ErrorLog("min_number")
- return
- }
-
- min_number, _ := goodNameM["min_number"].(string)
- minNumber, _ := strconv.ParseInt(min_number, 10, 64)
- if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MinNumber = minNumber
-
- min_unit := goodNameM["min_unit"].(string)
- if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MinUnit = min_unit
-
- max_unit_id := goodNameM["max_unit"].(string)
- if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MaxUnit = max_unit_id
-
- max_unit := goodNameM["max_unit"].(string)
- if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MaxUnit = max_unit
-
- drug_type := goodNameM["drug_type"].(string)
- if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var drug_type_id int64
- var drugType = "药品类型"
-
- drugconfig, _ := service.GetDrugDataConfig(0, drugType)
- if len(drug_type) != 0 {
- _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
- if errcodes == gorm.ErrRecordNotFound {
- //获取该型号最后一条数据型号
- config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
-
- dataconfig := models.DictDataconfig{
- ParentId: drugconfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_type,
- FieldName: "",
- Value: config.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
- for _, it := range drugTypeList {
- if drug_type == it.Name {
- drug_type_id = int64(it.Value)
- }
- }
-
- drug.DrugType = drug_type_id
-
- drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
- if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugStockLimit = drug_stock_limit
-
- drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
- if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugOriginPlace = drug_origin_place
-
- drug_dosage_form := goodNameM["drug_dosage_form"].(string)
-
- if len(drug_dosage_form) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var drug_dosage = "药品剂型"
- var drug_dosage_form_id int64
- drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
- if len(drug_dosage_form) != 0 {
- _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
- if errcodess == gorm.ErrRecordNotFound {
- configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: drugDosageconfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_dosage_form,
- FieldName: "",
- Value: configOne.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
- for _, it := range drugDosageList {
- if drug_dosage_form == it.Name {
- drug_dosage_form_id = int64(it.Value)
- }
- }
-
- drug.DrugDosageForm = drug_dosage_form_id
-
- retail_prices := goodNameM["retail_price"].(string)
- retail_price, _ := strconv.ParseFloat(retail_prices, 64)
-
- if retail_price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.RetailPrice = retail_price
-
- last_prices := goodNameM["last_price"].(string)
- last_price, _ := strconv.ParseFloat(last_prices, 64)
- if last_price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.LastPrice = last_price
-
- drug_classify := goodNameM["drug_classify"].(string)
-
- if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var drugClassify = "药物分类"
- var drug_classify_id int64
- drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
-
- if len(drug_classify) != 0 {
- _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
- if errcodesClass == gorm.ErrRecordNotFound {
- drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: drugClassifyConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_classify,
- FieldName: "",
- Value: drugClassConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
- for _, it := range drugClassList {
- if drug_classify == it.Name {
- drug_classify_id = int64(it.Value)
- }
- }
-
- drug_dose := goodNameM["drug_dose"].(string)
-
- if len(drug_dose) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
- drug.DrugDose = drugDoses
-
- var units = "单位"
- var unit_id int64
- drugDoseUnit := goodNameM["drug_dose_unit"].(string)
-
- if len(drugDoseUnit) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- manufacturer := goodNameM["manufacturer"].(string)
- if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- if len(manufacturer) != 0 {
- _, errcodema := service.GetManufacturerName(orgId, manufacturer)
- if errcodema == gorm.ErrRecordNotFound {
- manufactur := models.Manufacturer{
- OrgId: orgId,
- Status: 1,
- ManufacturerName: manufacturer,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- }
- service.CreateManufacturer(&manufactur)
- }
- }
-
- var manufacturer_id int64
-
- manufacturList, _ := service.GetAllManufacturerList(orgId)
- for _, it := range manufacturList {
- if manufacturer == it.ManufacturerName {
- manufacturer_id = it.ID
- }
- }
-
- drug.Manufacturer = manufacturer_id
-
- dealer := goodNameM["dealer"].(string)
- if len(dealer) != 0 {
- _, errcodesdealer := service.GetDealerByName(orgId, dealer)
- if errcodesdealer == gorm.ErrRecordNotFound {
- dealerconfig := models.Dealer{
- DealerName: dealer,
- Status: 1,
- OrgId: orgId,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- }
- service.CreateDealer(&dealerconfig)
- }
- }
-
- var dealer_id int64
- dealerList, _ := service.GetAllDealerList(orgId)
- for _, it := range dealerList {
- if dealer == it.DealerName {
- dealer_id = it.ID
- }
- }
- drug.Dealer = dealer_id
-
- delivery_way := goodNameM["delivery_way"].(string)
- //if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
- // err_log := models.ExportErrLog{
- // LogType: 4,
- // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- // ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
- // Status: 1,
- // CreateTime: time.Now().Unix(),
- // UpdateTime: time.Now().Unix(),
- // ExportTime: time.Now().Unix(),
- // }
- // service.CreateExportErrLog(&err_log)
- // continue
- //}
-
- drug.DeliveryWay = delivery_way
-
- execution_frequency := goodNameM["execution_frequency"].(string)
- //if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
- // err_log := models.ExportErrLog{
- // LogType: 4,
- // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- // ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
- // Status: 1,
- // CreateTime: time.Now().Unix(),
- // UpdateTime: time.Now().Unix(),
- // ExportTime: time.Now().Unix(),
- // }
- // service.CreateExportErrLog(&err_log)
- // continue
- //}
-
- drug.ExecutionFrequency = execution_frequency
-
- lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
-
- drug.LmtUsedFlag = lmt_used_flags
-
- if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
- utils.ErrorLog("drug_alias")
- return
- }
-
- drug_alias, _ := goodNameM["drug_alias"].(string)
-
- drug.DrugAlias = drug_alias
-
- drug_category := goodNameM["drug_category"].(string)
-
- var drugCategory = "药品类别"
- var drug_category_id int64
-
- drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
-
- if len(drug_category) != 0 {
- _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
- if drugcategoryerrcodes == gorm.ErrRecordNotFound {
- drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: drugCategoryConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_category,
- FieldName: "",
- Value: drugCategoryConfigSix.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
- fmt.Println("drugCategoryList", drugCategoryList)
- for _, it := range drugCategoryList {
- if drug_category == it.Name {
- drug_category_id = int64(it.Value)
- }
- }
-
- drug.DrugCategory = drug_category_id
-
- drug_control := goodNameM["drug_control"].(string)
-
- var drugControl = "开药控制"
- var drug_control_id int64
-
- drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
- if len(drug_control) != 0 {
- _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
- if errcodesdrugcontrol == gorm.ErrRecordNotFound {
- drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: drugContorlConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_control,
- FieldName: "",
- Value: drugContorlConfigOne.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
- for _, it := range drugContorlList {
- if drug_control == it.Name {
- drug_control_id = int64(it.Value)
- }
- }
- drug.DrugControl = drug_control_id
-
- number := goodNameM["number"].(string)
- drug.Number = number
-
- dataConfig, _ := service.GetDataConfigIsExist(0, units)
- if len(drugDoseUnit) != 0 {
- _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
- if errcodedataconfig == gorm.ErrRecordNotFound {
- childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
- dataconfig := models.Dataconfig{
- ParentId: dataConfig.ID,
- Module: "hemodialysis",
- OrgId: orgId,
- Name: drugDoseUnit,
- FieldName: "",
- Value: childConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- FieldType: 0,
- }
- service.CreateDataConfig(&dataconfig)
- }
- }
- list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
- for _, it := range list {
- if drugDoseUnit == it.Name {
- unit_id = int64(it.Value)
- }
- }
- drug.DrugDoseUnit = unit_id
-
- drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
-
- var statisticsCategory = "统计分类"
- var statistics_category_id int64
-
- statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
- if len(statistics_category) != 0 {
- _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
- if errcodestatistc == gorm.ErrRecordNotFound {
- staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: statistcConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: statistics_category,
- FieldName: "",
- Value: staConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
-
- }
-
- statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
- for _, it := range statisticsCategoryList {
- if statistics_category == it.Name {
- statistics_category_id = int64(it.Value)
- }
- }
- drug.StatisticsCategory = statistics_category_id
-
- hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
- drug.HospApprFlag = hosp_appr_flag
- medical_insurance_number := goodNameM["medical_insurance_number"].(string)
- drug.MedicalInsuranceNumber = medical_insurance_number
-
- pharmacology_category := goodNameM["pharmacology_category"].(string)
-
- var pharmacology = "药理分类"
- var pharmacology_category_id int64
- pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
- if len(pharmacology_category) != 0 {
- _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
- if errcodespharmacology == gorm.ErrRecordNotFound {
- dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: pharmacologyConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: pharmacology_category,
- FieldName: "",
- Value: dicConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
- for _, it := range pharmacologyList {
- if pharmacology_category == it.Name {
- pharmacology_category_id = int64(it.Value)
- }
- }
- drug.PharmacologyCategory = pharmacology_category_id
-
- code := goodNameM["code"].(string)
- drug.Code = code
- is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
- drug.IsSpecialDiseases = is_special_diseases
- is_record := int64(goodNameM["is_record"].(float64))
- drug.IsRecord = is_record
- prescription_mark := int64(goodNameM["prescription_mark"].(float64))
- drug.PrescriptionMark = prescription_mark
- social_security_directory_code := goodNameM["social_security_directory_code"].(string)
- drug.SocialSecurityDirectoryCode = social_security_directory_code
- record_date := goodNameM["record_date"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- drug.RecordDate = theTime.Unix()
- drug_remark := goodNameM["drug_remark"].(string)
- drug.DrugRemark = drug_remark
- drug_status := goodNameM["drug_status"].(string)
- drug.DrugStatus = drug_status
- limit_remark := goodNameM["limit_remark"].(string)
- drug.LimitRemark = limit_remark
-
- drugList = append(drugList, &drug)
- }
-
- export_time := time.Now().Unix()
- errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
-
- if len(drugList) > 0 {
- for _, item := range drugList {
-
- goodInfo := models.BaseDrugLib{
- DrugName: item.DrugName,
- DrugAlias: item.DrugAlias,
- DrugSpec: item.DrugSpec,
- DrugType: item.DrugType,
- DrugStockLimit: item.DrugStockLimit,
- DrugOriginPlace: item.DrugOriginPlace,
- DrugDosageForm: item.DrugDosageForm,
- MedicalInsuranceLevel: item.MedicalInsuranceLevel,
- MaxUnit: item.MaxUnit,
- MinUnit: item.MinUnit,
- UnitMatrixing: item.UnitMatrixing,
- RetailPrice: item.RetailPrice,
- LastPrice: item.LastPrice,
- DrugClassify: item.DrugClassify,
- Manufacturer: item.Manufacturer,
- Dealer: item.Dealer,
- OrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Pinyin: item.Pinyin,
- Wubi: item.Wubi,
- DrugAliasPinyin: item.DrugAliasPinyin,
- DrugAliasWubi: item.DrugAliasWubi,
- DrugControl: item.DrugControl,
- Number: item.Number,
- HospApprFlag: item.HospApprFlag,
- MedicalInsuranceNumber: item.MedicalInsuranceNumber,
- PharmacologyCategory: item.PharmacologyCategory,
- StatisticsCategory: item.StatisticsCategory,
- Code: item.Code,
- IsSpecialDiseases: item.IsSpecialDiseases,
- IsRecord: item.IsRecord,
- PrescriptionMark: item.PrescriptionMark,
- SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
- RecordDate: item.RecordDate,
- DrugRemark: item.DrugRemark,
- DrugStatus: item.DrugStatus,
- LimitRemark: item.LimitRemark,
- DrugCategory: item.DrugCategory,
- DrugDose: item.DrugDose,
- DrugDoseUnit: item.DrugDoseUnit,
- LmtUsedFlag: item.LmtUsedFlag,
- DrugDay: item.DrugDay,
- DeliveryWay: item.DeliveryWay,
- ExecutionFrequency: item.ExecutionFrequency,
- DoseUnit: item.DoseUnit,
- Dose: item.Dose,
- MinNumber: item.MinNumber,
- IsUse: 2,
- }
-
- //查询同种药品同种规格是否存在
- _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.DoseUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
-
- if drugerror == gorm.ErrRecordNotFound {
- service.CreateDrugsInfomation(&goodInfo)
- } else if drugerror == nil {
- service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
- }
- log := models.ExportLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(drugList)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(drugList),
- "fail_num": int64(len(errLogs)),
- })
- }
- } else {
- log := models.ExportLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(drugList)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(drugList),
- "fail_num": int64(len(errLogs)),
- })
- }
- }
- }
-
- func (this *StockManagerApiController) GetInitializtion() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- var drugCategory = "药品类别"
- var drugType = "药品类型"
- var drugDosageForm = "药品剂型"
- var medicalInsuranceLevel = "医保等级"
- var drugControl = "开药控制"
- var drugClassify = "药物分类"
- var statisticsCategory = "统计分类"
- var pharmacologyCategory = "药理分类"
- var goodKind = "耗材种类"
- var tubeColor = "试管颜色"
- var costClassify = "费用类别"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
-
- drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
- drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
-
- drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
- drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
-
- medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
- medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
-
- drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
- drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
-
- drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
- drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
-
- statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
- statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
-
- pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
- pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
-
- goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
- goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
-
- tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
- tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
-
- costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
- costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "drugCategoryList": drugCategoryList,
- "drugTypeList": drugTypeList,
- "drugDosageFormList": drugDosageFormList,
- "medicalInsuranceLevelList": medicalInsuranceLevelList,
- "drugControlList": drugControlList,
- "drugClassifyList": drugClassifyList,
- "statisticsCategoryList": statisticsCategoryList,
- "pharmacologyCategoryList": pharmacologyCategoryList,
- "goodKindList": goodKindList,
- "tubeColorList": tubeColorList,
- "costClassifyList": costClassifyList,
- })
- }
-
- func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- list, _ := service.GetWarehouseOrderInfoList(orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) PostSearchGoodList() {
-
- keyword := this.GetString("keyword")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
- list, _ := service.GetSearchGoodListSix(keyword, orgId, storehouse_id)
-
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
- }
-
- func (this *StockManagerApiController) GetAllStockList() {
-
- page, _ := this.GetInt64("page", -1)
- limit, _ := this.GetInt64("limit", -1)
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- types, _ := this.GetInt64("type", 0)
- keywords := this.GetString("keywords")
- good_id, _ := this.GetInt64("good_id")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId, good_id, storehouse_id)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "manufacturerList": manufacturerList,
- })
- }
-
- func (this *StockManagerApiController) GetStockListById() {
-
- id, _ := this.GetInt64("id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime)
- houseList, _ := service.GetAllStoreHouseList(orgId)
- good, _ := service.GetGoodInformationByGoodId(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "manufacturerList": manufacturerList,
- "houseList": houseList,
- "good": good,
- })
-
- }
-
- func (this *StockManagerApiController) GetStockOutList() {
-
- id, _ := this.GetInt64("id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- is_sys, _ := this.GetInt64("is_sys")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "outList": outList,
- "total": total,
- })
- }
-
- func (this *StockManagerApiController) GetStockDrugCount() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- fmt.Println(orgId)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
- outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
- autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
- totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "count": count,
- "outList": outList,
- "autoCount": autoCount,
- "totalCount": totalCount,
- })
- }
-
- func (this *StockManagerApiController) GetOrderDetialByOrderId() {
-
- ids := this.GetString("id")
- idsArray := strings.Split(ids, ",")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
- list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "order": order,
- })
- }
-
- func (this *StockManagerApiController) GetOrderDetailById() {
-
- id, _ := this.GetInt64("id")
- good_id, _ := this.GetInt64("good_id")
- record_time, _ := this.GetInt64("record_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- //自动出库
- userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
-
- //手动出库
- info, _ := service.GetWarehouseOutInfoById(id, good_id)
-
- stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": userDetails,
- "total": total,
- "info": info,
- "stockFlowList": stockFlowList,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (this *StockManagerApiController) GetSingleOutOrderDetail() {
- id, _ := this.GetInt64("id", 0)
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
- out, _ := service.GetGoodWarehouseOutById(id, orgId)
- storelist, _ := service.GetAllStoreHouseList(orgId)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- goodType, _ := service.GetAllGoodType(orgId)
- appId := this.GetAdminUserInfo().CurrentAppId
- doctorlist, _ := service.GetAllDoctorListSix(orgId, appId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutInfo,
- "dealerList": dealerList,
- "manufacturerList": manufacturerList,
- "goodType": goodType,
- "out": out,
- "storelist": storelist,
- "doctorlist": doctorlist,
- })
- }
-
- func (this *StockManagerApiController) GetExprotStockList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- idArray := this.GetString("id")
- ids := strings.Split(idArray, ",")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, _ := service.GetExprotStockListTwenty(orgId, ids, startTime, endTime, storehouse_id)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetOutExprotList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- idArray := this.GetString("id")
- ids := strings.Split(idArray, ",")
- fmt.Println("ids2222222222", ids)
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
- outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "count": outCount,
- })
- }
-
- func (this *StockManagerApiController) GetSingleCancelOrder() {
-
- id, _ := this.GetInt64("id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- order, _ := service.GetSingleCancelOrder(id, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": order,
- })
- }
-
- func (this *StockManagerApiController) GetCancelStockOrderPrint() {
- id := this.GetString("id")
- idStr := strings.Split(id, ",")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetStockBatchNumber() {
-
- id, _ := this.GetInt64("id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetStockBatchNumber(id, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetStockFlow() {
-
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- good_id, _ := this.GetInt64("good_id")
- consumable_type, _ := this.GetInt64("is_sys")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- good, _ := service.GetGoodInformationByGoodId(good_id)
- houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "manufacturerList": manufacturerList,
- "good": good,
- "houseList": houseList,
- })
- }
-
- func (this *StockManagerApiController) GetCancelExportList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- idArray := this.GetString("order_id")
- fmt.Println("232323232323232232", idArray)
- ids := strings.Split(idArray, ",")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetSearchGoodWarehouseList() {
-
- keyword := this.GetString("keyword")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetSearchGoodWarehouseList(keyword, orgId, storehouse_id)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
- }
-
- func (this *StockManagerApiController) SaveAdjuestPrice() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- tableData, _ := dataBody["tableData"].([]interface{})
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
-
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_name := items["good_name"].(string)
-
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
- utils.ErrorLog("packing_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
-
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_order := items["warehousing_order"].(string)
-
- if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
- utils.ErrorLog("license_number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- license_number := items["license_number"].(string)
-
- if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
- utils.ErrorLog("dealer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dealer := items["dealer"].(string)
-
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- manufacturer := items["manufacturer"].(string)
-
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- specification_name := items["specification_name"].(string)
-
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- remark := items["remark"].(string)
-
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_unit := items["warehousing_unit"].(string)
-
- if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
- utils.ErrorLog("buy_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
- utils.ErrorLog("count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- count := int64(items["count"].(float64))
-
- if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
- utils.ErrorLog("new_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var startTime int64
- start_time := items["start_time"].(string)
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- orgId := this.GetAdminUserInfo().CurrentOrgId
- adjustprice := models.XtStockAdjustPrice{
- GoodName: good_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: count,
- BuyPrice: buy_price,
- PackingPrice: packing_price,
- NewPrice: new_price,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Remark: remark,
- GoodId: good_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- LicenseNumber: license_number,
- StartTime: startTime,
- Creater: this.GetAdminUserInfo().AdminUser.Id,
- CheckerStatus: 2,
- }
-
- service.CreateAdjustPrice(&adjustprice)
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功!",
- })
- }
-
- func (this *StockManagerApiController) GetAllStockPrice() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- list, total, _ := service.GetAllStockPrice(orgId, startTime, endTime, keyword, limit, page)
- doctor, _ := service.GetAllDoctorThree(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "doctor": doctor,
- "total": total,
- })
- }
-
- func (this *StockManagerApiController) SaveCheckPrice() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- idstr := this.GetString("ids")
- ids := strings.Split(idstr, ",")
- check_time := this.GetString("check_time")
- var checkTime int64
- if len(check_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkTime = theTime.Unix()
- }
- checker, _ := this.GetInt64("checker")
- adjustPrice := models.XtStockAdjustPrice{
- Checker: checker,
- CheckerStatus: 1,
- CheckerTime: checkTime,
- }
- err = service.UpdateAdjustPrice(ids, adjustPrice)
- fmt.Println(err)
-
- list, _ := service.GetAdjustCheckPriceList(ids)
- fmt.Println("list2333223323232323232323", list)
- for _, item := range list {
- info := models.GoodInfo{
- PackingPrice: item.NewPrice,
- BuyPrice: item.NewPrice,
- }
- err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
- fmt.Println(err)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "adjustPrice": adjustPrice,
- })
- }
-
- func (this *StockManagerApiController) GetAdjustPriceById() {
-
- ids := this.GetString("ids")
- fmt.Println("ids23232233223233232", ids)
- splitIds := strings.Split(ids, ",")
- list, _ := service.GetAdjustPricebyIdOne(splitIds)
- fmt.Println("list2322322323", list)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) SaveReportStock() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- tableData, _ := dataBody["tableData"].([]interface{})
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
-
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_name := items["good_name"].(string)
-
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
- utils.ErrorLog("packing_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
-
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_order := items["warehousing_order"].(string)
-
- if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
- utils.ErrorLog("license_number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- license_number := items["license_number"].(string)
-
- if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
- utils.ErrorLog("dealer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dealer := items["dealer"].(string)
-
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- manufacturer := items["manufacturer"].(string)
-
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- specification_name := items["specification_name"].(string)
-
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- remark := items["remark"].(string)
-
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_unit := items["warehousing_unit"].(string)
-
- if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
- utils.ErrorLog("buy_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
- utils.ErrorLog("count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- count := int64(items["count"].(float64))
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var startTime int64
- start_time := items["start_time"].(string)
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- number := items["number"].(string)
-
- if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
- utils.ErrorLog("warehousing_info_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_info_id := int64(items["warehousing_info_id"].(float64))
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
- utils.ErrorLog("product_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- product_date := int64(items["product_date"].(float64))
- orgId := this.GetAdminUserInfo().CurrentOrgId
- Creater := this.GetAdminUserInfo().AdminUser.Id
-
- if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
- utils.ErrorLog("total")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- total := int64(items["total"].(float64))
-
- if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
- utils.ErrorLog("good_origin_place")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_origin_place := items["good_origin_place"].(string)
- reportPrice := models.XtStockReportPrice{
- GoodName: good_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: count,
- BuyPrice: buy_price,
- PackingPrice: packing_price,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Remark: remark,
- GoodId: good_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- LicenseNumber: license_number,
- StartTime: startTime,
- Creater: Creater,
- Checker: 0,
- CheckerStatus: 2,
- CheckerTime: 0,
- Number: number,
- WarehousingInfoId: warehousing_info_id,
- ExpiryDate: expiry_date,
- ProductDate: product_date,
- Total: total,
- GoodOriginPlace: good_origin_place,
- }
- err := service.CreateReportPrice(&reportPrice)
- fmt.Println(err)
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功!",
- })
- }
-
- func (this *StockManagerApiController) GetReportStockList() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- fmt.Println("开始时间", startTime)
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
-
- }
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
- list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit, startTime, endTime, storehouse_id)
- damageList, _ := service.GetStockDamagedCount(orgId)
- doctorlist, _ := service.GetAllDoctorThree(orgId)
- houseList, _ := service.GetAllStoreHouseList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "doctorlist": doctorlist,
- "damageList": damageList,
- "houseList": houseList,
- })
- }
-
- func (this *StockManagerApiController) SaveCheckDamage() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- idstr := this.GetString("ids")
- ids := strings.Split(idstr, ",")
- check_time := this.GetString("check_time")
- var checkTime int64
- if len(check_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkTime = theTime.Unix()
- }
- checker, _ := this.GetInt64("checker")
- reportprice := models.XtStockReportPrice{
- Checker: checker,
- CheckerStatus: 1,
- CheckerTime: checkTime,
- }
- err := service.UpdateCheckDamage(ids, reportprice)
- fmt.Println(err)
-
- //获取当前核对的数据
- list, _ := service.GetCheckDamageList(ids)
-
- ctime := time.Now().Unix()
- adminUserInfo := this.GetAdminUserInfo()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehouseOutTime: ctime,
- Type: 1,
- }
-
- _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
-
- if errcodes == gorm.ErrRecordNotFound {
- service.AddSigleWarehouseOut(&warehouseOut)
-
- }
- out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- var manufacturer_id int64
- var dealer_id int64
-
- for _, item := range list {
- for _, it := range manufacturerList {
- if item.Manufacturer == it.ManufacturerName {
- manufacturer_id = it.ID
- }
- }
- for _, its := range dealerList {
- if item.Dealer == its.DealerName {
- dealer_id = its.ID
- }
- }
- goodinfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
- //插入出库单
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- GoodId: item.GoodId,
- Count: item.Count,
- Price: item.PackingPrice,
- Status: 1,
- Ctime: ctime,
- Remark: item.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 2,
- Manufacturer: manufacturer_id,
- Number: item.Number,
- ExpiryDate: item.ExpiryDate,
- ProductDate: item.ProductDate,
- Dealer: dealer_id,
- LicenseNumber: item.LicenseNumber,
- GoodTypeId: goodinfo.GoodTypeId,
- }
- errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- fmt.Println("99999999999999", errOne)
-
- //更改库存
- info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
-
- warehousingInfo := models.WarehousingInfo{
- StockCount: info.StockCount - item.Count,
- }
- errOne = service.UpdateGoodWarehouseInfo(item.WarehousingInfoId, warehousingInfo)
- fmt.Println(errOne)
- flow := models.VmStockFlow{
- WarehousingId: 0,
- GoodId: item.GoodId,
- Number: item.Number,
- LicenseNumber: item.LicenseNumber,
- Count: item.Count,
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: 0,
- SystemTime: time.Now().Unix(),
- ConsumableType: 5,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: out.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: 0,
- Dealer: 0,
- Creator: adminUserInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: item.PackingPrice,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ProductDate: item.ProductDate,
- ExpireDate: item.ExpiryDate,
- }
- service.CreateStockFlowOne(flow)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "reportPrice": reportprice,
- })
- }
-
- func (this *StockManagerApiController) SaveInventory() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- tableData, _ := dataBody["tableData"].([]interface{})
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
-
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_name := items["good_name"].(string)
-
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
- utils.ErrorLog("packing_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
-
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_order := items["warehousing_order"].(string)
-
- if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
- utils.ErrorLog("license_number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- license_number := items["license_number"].(string)
-
- if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
- utils.ErrorLog("dealer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dealer := items["dealer"].(string)
-
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- manufacturer := items["manufacturer"].(string)
-
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- specification_name := items["specification_name"].(string)
-
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- remark := items["remark"].(string)
-
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_unit := items["warehousing_unit"].(string)
-
- if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
- utils.ErrorLog("buy_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
- utils.ErrorLog("count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- count := int64(items["count"].(float64))
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var startTime int64
- start_time := items["start_time"].(string)
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
- utils.ErrorLog("total")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- total := int64(items["total"].(float64))
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
- utils.ErrorLog("product_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- product_date := int64(items["product_date"].(float64))
-
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- number := items["number"].(string)
-
- if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
- utils.ErrorLog("warehousing_info_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_info_id := int64(items["warehousing_info_id"].(float64))
-
- if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
- utils.ErrorLog("good_origin_place")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_origin_place := items["good_origin_place"].(string)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- Creater := this.GetAdminUserInfo().AdminUser.Id
-
- inventory := models.XtStockInventory{
- GoodName: good_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: count,
- BuyPrice: buy_price,
- PackingPrice: packing_price,
- NewPrice: 0,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Remark: remark,
- GoodId: good_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- LicenseNumber: license_number,
- StartTime: startTime,
- Creater: Creater,
- Checker: 0,
- CheckerStatus: 2,
- CheckerTime: 0,
- Total: total,
- ExpireDate: expiry_date,
- ProductDate: product_date,
- Number: number,
- WarehousingInfoId: warehousing_info_id,
- GoodOriginPlace: good_origin_place,
- }
- err = service.CreateInentory(inventory)
- fmt.Println(err)
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功!",
- })
- }
-
- func (this *StockManagerApiController) GetInventorylist() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- keyword := this.GetString("keyword")
- inventory_status, _ := this.GetInt64("inventory_status")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- fmt.Println("开始时间", startTime)
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
-
- }
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, total, _ := service.GetInventorylist(startTime, endTime, page, limit, inventory_status, keyword, orgId)
- doctorlist, _ := service.GetAllDoctorThree(orgId)
-
- houseList, _ := service.GetAllStoreHouseList(orgId)
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "doctorlist": doctorlist,
- "houseList": houseList,
- "houseConfig": houseConfig,
- })
- }
-
- func (this *StockManagerApiController) SaveCheckInventory() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- idstr := this.GetString("ids")
- ids := strings.Split(idstr, ",")
- check_time := this.GetString("check_time")
- var checkTime int64
- if len(check_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkTime = theTime.Unix()
- }
- checker, _ := this.GetInt64("checker")
- inventory := models.XtStockInventory{
- Checker: checker,
- CheckerStatus: 1,
- CheckerTime: checkTime,
- }
- adminUserInfo := this.GetAdminUserInfo()
- err = service.UpdateCheckInventory(ids, inventory)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- var manufactuer_id int64
- var dealer_id int64
- //查询耗材信息
- list, _ := service.GetInventoryDetailById(ids)
- for _, item := range list {
- for _, it := range manufacturerList {
- if item.Manufacturer == it.ManufacturerName {
- manufactuer_id = it.ID
- }
- }
-
- for _, its := range dealerList {
- if item.Dealer == its.DealerName {
- dealer_id = its.ID
- }
- }
- //查寻该批次的库存量
- list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
-
- //查询该耗材最后1条批次
- info, _ := service.GetLastWarehouseInfo(item.GoodId)
- good, _ := service.GetGoodInformationByGoodId(item.GoodId)
- fmt.Println("总共", item.Count)
- fmt.Println("数据", list.StockCount)
- //盘点盘点库存和et实际库存的大小
- // 如果盘点库存大于实际库存,怎需要入库
- if item.Count > list.StockCount {
-
- ctime := time.Now().Unix()
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- warehousing := models.Warehousing{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehousingTime: ctime,
- Type: 1,
- }
- service.AddSigleWarehouse(&warehousing)
-
- //获取最
- //入库单表格
- warehouseInfo := models.WarehousingInfo{
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: warehousing.ID,
- GoodId: item.GoodId,
- Number: info.Number,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- WarehousingCount: item.Count - list.StockCount,
- Price: info.Price,
- Status: 1,
- Ctime: ctime,
- Remark: item.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: manufactuer_id,
- StockCount: item.Count - list.StockCount,
- Dealer: dealer_id,
- LicenseNumber: info.LicenseNumber,
- WarehouseInfoId: item.WarehousingInfoId,
- GoodTypeId: good.GoodTypeId,
- }
-
- flow := models.VmStockFlow{
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: warehousing.ID,
- GoodId: item.GoodId,
- Number: info.Number,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- Count: item.Count - list.StockCount,
- Price: item.BuyPrice,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: info.Manufacturer,
- Dealer: info.Dealer,
- LicenseNumber: info.LicenseNumber,
- IsEdit: 1,
- Creator: adminUserInfo.AdminUser.Id,
- SystemTime: operation_time,
- ConsumableType: 1,
- WarehousingDetailId: warehouseInfo.ID,
- }
-
- service.CreateWarehouseInfo(warehouseInfo)
- service.CreateStockFlowOne(flow)
-
- }
-
- //如果盘点库存小于实际库存,需要出库
- if item.Count < list.StockCount {
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- //查询最早的1条批次
- warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: time.Now().Unix(),
- Type: 1,
- }
- err = service.CreateWarehouseOut(warehouseOut)
- fmt.Println(err)
- out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- GoodId: warehouseInfo.GoodId,
- Count: list.StockCount - item.Count,
- Price: warehouseInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: item.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: manufactuer_id,
- Number: warehouseInfo.Number,
- ExpiryDate: warehouseInfo.ExpiryDate,
- ProductDate: warehouseInfo.ProductDate,
- Dealer: dealer_id,
- LicenseNumber: warehouseInfo.LicenseNumber,
- GoodTypeId: good.GoodTypeId,
- }
-
- stockFlow := models.VmStockFlow{
- WarehousingId: item.WarehousingInfoId,
- GoodId: warehouseInfo.GoodId,
- Number: warehouseInfo.Number,
- LicenseNumber: warehouseInfo.LicenseNumber,
- Count: list.StockCount - item.Count,
- UserOrgId: warehouseInfo.OrgId,
- PatientId: 0,
- SystemTime: 0,
- ConsumableType: 2,
- IsSys: 2,
- WarehousingOrder: "",
- WarehouseOutId: out.ID,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- IsEdit: 1,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: manufactuer_id,
- Dealer: dealer_id,
- Creator: adminUserInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: warehouseInfo.Price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: out.ID,
- CancelOutDetailId: 0,
- ProductDate: warehouseInfo.ProductDate,
- ExpireDate: warehouseInfo.ExpiryDate,
- }
- errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- fmt.Println(errOne)
- //创建出库明细
- service.CreateStockFlowOne(stockFlow)
-
- //更改库存
- warehousingInfos := models.WarehousingInfo{
- StockCount: item.Count,
- }
- service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
-
- }
- }
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "inventory": inventory,
- })
- }
-
- func (this *StockManagerApiController) GetModifyPriceDetail() {
-
- id, _ := this.GetInt64("id")
-
- detail, _ := service.GetModifyPriceDetail(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- }
-
- func (this *StockManagerApiController) UpdateStockPrice() {
-
- id, _ := this.GetInt64("id")
- newPrice := this.GetString("new_price")
- new_price, _ := strconv.ParseFloat(newPrice, 64)
- good_name := this.GetString("good_name")
- packingPrice := this.GetString("packing_price")
- packing_price, _ := strconv.ParseFloat(packingPrice, 64)
- remark := this.GetString("remark")
- good_id, _ := this.GetInt64("good_id")
- manufacturer := this.GetString("manufacturer")
- dealer := this.GetString("dealer")
- adjust := models.XtStockAdjustPrice{
- NewPrice: new_price,
- GoodName: good_name,
- PackingPrice: packing_price,
- Remark: remark,
- GoodId: good_id,
- Manufacturer: manufacturer,
- Dealer: dealer,
- }
- err := service.UpdateStockPrice(adjust, id)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "adjust": adjust,
- })
- }
-
- func (this *StockManagerApiController) DeleteStockPrice() {
-
- id, _ := this.GetInt64("id")
- err := service.DeleteStockPrice(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *StockManagerApiController) GetStockDamageDetail() {
-
- id, _ := this.GetInt64("id")
- detail, err := service.GetStockDamageDetail(id)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- }
-
- func (this *StockManagerApiController) ModifyPrice() {
-
- count, _ := this.GetInt64("count")
- id, _ := this.GetInt64("id")
- good_name := this.GetString("good_name")
- specification_name := this.GetString("specification_name")
- number := this.GetString("number")
- warehousing_unit := this.GetString("warehousing_unit")
- buyPrice := this.GetString("buy_price")
- buy_price, _ := strconv.ParseFloat(buyPrice, 64)
- packingPrice := this.GetString("packing_price")
- packing_price, _ := strconv.ParseFloat(packingPrice, 64)
- good_origin_place := this.GetString("good_origin_place")
- manufacturer := this.GetString("manufacturer")
- dealer := this.GetString("dealer")
- total, _ := this.GetInt64("total")
- remark := this.GetString("remark")
- warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
- good_id, _ := this.GetInt64("good_id")
- adjust := models.XtStockReportPrice{
- Count: count,
- SpecificationName: specification_name,
- Number: number,
- GoodName: good_name,
- WarehousingUnit: warehousing_unit,
- BuyPrice: buy_price,
- PackingPrice: packing_price,
- GoodOriginPlace: good_origin_place,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Total: total,
- Remark: remark,
- WarehousingInfoId: warehousing_info_id,
- GoodId: good_id,
- }
- err := service.ModifyPrice(id, adjust)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "adjust": adjust,
- })
- }
-
- func (this *StockManagerApiController) DeleteDamage() {
-
- id, _ := this.GetInt64("id")
- err := service.DeleteDamage(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *StockManagerApiController) GetStockDamageById() {
- ids := this.GetString("ids")
-
- splitIds := strings.Split(ids, ",")
- list, _ := service.GetStockDamageById(splitIds)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetInventoryDetail() {
- id, _ := this.GetInt64("id")
- detail, _ := service.GetInventoryDetail(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- }
-
- func (this *StockManagerApiController) ModifyInventory() {
- id, _ := this.GetInt64("id")
- good_id, _ := this.GetInt64("good_id")
- good_name := this.GetString("good_name")
- specification_name := this.GetString("specification_name")
- number := this.GetString("number")
- warehousing_unit := this.GetString("warehousing_unit")
- buyPrice := this.GetString("buy_price")
- buy_price, _ := strconv.ParseFloat(buyPrice, 64)
- packingPrice := this.GetString("packing_price")
- packing_price, _ := strconv.ParseFloat(packingPrice, 64)
- total, _ := this.GetInt64("total")
- good_origin_place := this.GetString("good_origin_place")
- license_number := this.GetString("license_number")
- dealer := this.GetString("dealer")
- manufacturer := this.GetString("manufacturer")
- count, _ := this.GetInt64("count")
- remark := this.GetString("remark")
- inventory := models.XtStockInventory{
- GoodId: good_id,
- GoodName: good_name,
- SpecificationName: specification_name,
- Number: number,
- WarehousingUnit: warehousing_unit,
- BuyPrice: buy_price,
- PackingPrice: packing_price,
- Total: total,
- GoodOriginPlace: good_origin_place,
- LicenseNumber: license_number,
- Dealer: dealer,
- Manufacturer: manufacturer,
- Count: count,
- Remark: remark,
- }
- err := service.ModifyInventory(id, inventory)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "inventory": inventory,
- })
- }
-
- func (this *StockManagerApiController) DeleteInventory() {
- id, _ := this.GetInt64("id")
- err := service.DeleteInventory(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *StockManagerApiController) GetInventoryDetailList() {
- keyword := this.GetString("keyword")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- storehouse_id, _ := this.GetInt64("storehouse_id")
- houseList, _ := service.GetAllStoreHouseList(orgId)
- list, total, _ := service.GetInventoryDetailList(keyword, limit, page, orgId, storehouse_id)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "houseList": houseList,
- })
- }
-
- func (this *StockManagerApiController) GetInventoryPrintList() {
-
- ids := this.GetString("ids")
- splitIds := strings.Split(ids, ",")
- list, _ := service.GetInventoryPrintList(splitIds)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetInventoryDetailPrintList() {
- ids := this.GetString("ids")
- splitIds := strings.Split(ids, ",")
- list, _ := service.GetInventoryDetailPrintList(splitIds)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) DeleteDrugPrice() {
-
- id, _ := this.GetInt64("id")
- err := service.DeleteDrugPrice(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *StockManagerApiController) GetGoodWarehouseList() {
-
- id, _ := this.GetInt64("id")
- list, _ := service.GetGoodWarehouseList(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) ProofInventory() {
-
- id, _ := this.GetInt64("id")
- good_id, _ := this.GetInt64("good_id")
- warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
- proof_count, _ := this.GetInt64("proof_count")
- total, _ := this.GetInt64("total")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- creater := this.GetAdminUserInfo().AdminUser.Id
-
- info := models.WarehousingInfo{
- GoodId: good_id,
- StockCount: proof_count,
- }
- err := service.UpdateProofInventory(warehousing_info_id, info)
- inventory := models.XtStockInventory{
- Total: proof_count,
- }
- err = service.UpdateStockInventory(inventory, id)
- fmt.Println(err)
- record := models.XtStockCorrectRecord{
- GoodId: good_id,
- OrdCount: total,
- WarehousingInfoId: warehousing_info_id,
- NewCount: proof_count,
- UserOrgId: orgId,
- Status: 1,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- }
- service.CeateStockCorrectRecord(record)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": info,
- })
- }
-
- func (this *StockManagerApiController) GetWarehouseTotal() {
-
- id, _ := this.GetInt64("id")
- list, _ := service.GetWarehouseTotal(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetGoodInventoryWarehouseList() {
-
- id, _ := this.GetInt64("id")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- list, _ := service.GetGoodInventoryWarehouseList(id, storehouse_id)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- fmt.Println(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) SaveStockInventoryList() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- tableData, _ := dataBody["tableData"].([]interface{})
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
- good_name := items["good_name"].(string)
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- specification_name := items["specification_name"].(string)
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_unit := items["warehousing_unit"].(string)
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- stock_count := int64(items["stock_count"].(float64))
- if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
- utils.ErrorLog("stock_count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- price := items["price"].(float64)
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
- utils.ErrorLog("price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- manufacturer_name := items["manufacturer_name"].(string)
- if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
- utils.ErrorLog("manufacturer_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- good_id := int64(items["good_id"].(float64))
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- manufacturer := int64(items["manufacturer"].(float64))
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_order := items["warehousing_order"].(string)
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- number := items["number"].(string)
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- id := int64(items["id"].(float64))
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
- utils.ErrorLog("product_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- product_date := int64(items["product_date"].(float64))
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- adminId := this.GetAdminUserInfo().AdminUser.Id
-
- stock_type := int64(items["type"].(float64))
- if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- utils.ErrorLog("type")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- last_stock_count := int64(items["last_stock_count"].(float64))
- if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
- utils.ErrorLog("last_stock_count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- storehouse_id := int64(items["storehouse_id"].(float64))
- if items["storehouse_id"] == nil || reflect.TypeOf(items["storehouse_id"]).String() != "float64" {
- utils.ErrorLog("storehouse_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var total_count int64
- var inventory_type int64
-
- if stock_count > last_stock_count {
- total_count = stock_count - last_stock_count
- inventory_type = 11
- }
- if stock_count < last_stock_count {
- total_count = last_stock_count - stock_count
- inventory_type = 10
- }
-
- creater := this.GetAdminUserInfo().AdminUser.Id
- inventory := models.XtStockInventory{
- GoodName: good_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: total_count,
- BuyPrice: price,
- PackingPrice: price,
- NewPrice: 0,
- Manufacturer: manufacturer_name,
- Dealer: "",
- Remark: "",
- GoodId: good_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- LicenseNumber: number,
- StartTime: time.Now().Unix(),
- Creater: adminId,
- Checker: 0,
- CheckerStatus: 0,
- CheckerTime: 0,
- Total: 0,
- Number: number,
- WarehousingInfoId: id,
- ExpireDate: expiry_date,
- ProductDate: product_date,
- GoodOriginPlace: "",
- Type: 10,
- InventoryType: stock_type,
- LastStockCount: last_stock_count,
- StockCount: stock_count,
- StorehouseId: storehouse_id,
- }
- service.CreateInentory(inventory)
-
- stockFlow := models.VmStockFlow{
- WarehousingId: 0,
- GoodId: good_id,
- Number: number,
- LicenseNumber: "",
- Count: total_count,
- UserOrgId: orgId,
- PatientId: 0,
- SystemTime: 0,
- ConsumableType: inventory_type,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: warehousing_order,
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: manufacturer,
- Dealer: 0,
- Creator: creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ProductDate: product_date,
- ExpireDate: expiry_date,
- ReturnCount: 0,
- StorehouseId: storehouse_id,
- }
-
- info := models.WarehousingInfo{
- StockCount: last_stock_count,
- WarehousingCount: last_stock_count,
- }
-
- warehosueinfos, _ := service.GetWarehouseInfoByIdNight(id)
- //如果当前的盘点后的数量大于当前库存数量,则新增库存
- if last_stock_count > warehosueinfos.StockCount && last_stock_count <= warehosueinfos.WarehousingCount {
- //更改库存
- service.UpdatedWarehousingInfo(info, id)
- }
-
- if last_stock_count > warehosueinfos.StockCount && last_stock_count > warehosueinfos.WarehousingCount {
-
- //更改库存
- service.UpdatedWarehousingInfoSix(info, id)
- }
- //如果当前的盘点后的数量大于当前库存数量,则扣减库存
- if last_stock_count < warehosueinfos.StockCount {
-
- //更改库存
- service.UpdatedWarehousingInfo(info, id)
- }
-
- if stock_count != last_stock_count {
- service.CreateStockFlowOne(stockFlow)
- }
-
- //查询该机构默认仓库
- storeConfig, _ := service.GetAllStoreHouseConfig(warehosueinfos.OrgId)
- //查询已审核单据的剩余库存
- goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, good_id, warehosueinfos.OrgId)
- var sum_count int64
- var sum_in_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- sum_in_count += item.WarehousingCount
- }
- service.UpdateGoodByGoodId(good_id, sum_count, sum_in_count, warehosueinfos.OrgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "inventory": inventory,
- })
- }
- }
- }
-
- func (this *StockManagerApiController) GetDamageDetailByGoodId() {
-
- good_id, _ := this.GetInt64("good_id")
- warehousing_order := this.GetString("warehousing_order")
- inventory_type, _ := this.GetInt64("type")
- list, _ := service.GetDamageDetailByGoodId(good_id, warehousing_order, inventory_type)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- damageList, _ := service.GetStockDamagedCountOne(orgId, warehousing_order, inventory_type)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "damageList": damageList,
- })
- }
-
- func (this *StockManagerApiController) GetInventoryExportList() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- list, _ := service.GetInventoryExportList(orgId)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- })
- }
-
- func (this *StockManagerApiController) UpdateCancelStockOrder() {
-
- type_id, _ := this.GetInt64("type_id")
- //获取目前在使用的机构ID
- list, _ := service.GetOrgIdList()
-
- //耗材
- if type_id == 1 {
- for _, item := range list {
- //查询该机构的所有耗材
- goodList, _ := service.GetAllGoodList(item.OrgId)
-
- for _, it := range goodList {
- //查询该耗材的入库总数
- info, _ := service.GetStockCountWarehouseInfoById(it.ID)
- var total int64
- for _, its := range info {
- total += its.StockCount
- }
- //更新库存
- service.ModifyGoodAddInformationSeven(it.ID, total, it.OrgId)
- }
- }
- }
-
- //药品
- if type_id == 2 {
-
- for _, item := range list {
- fmt.Println(item)
- //查询该机构的所有药品
- drugList, _ := service.GetAllBaseDrugStockList(4)
- for _, it := range drugList {
- //查询该药品的入库总数
- info, _ := service.GetDrugStockCountWarehoseInfoById(it.ID)
- var sum_count int64
- for _, its := range info {
- if its.MaxUnit == it.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * it.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateModifyDrugInfoById(it.ID, sum_count, it.OrgId)
- }
-
- }
- }
- }
-
- func (this *StockManagerApiController) GetDrugDetailSummary() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
-
- end_time := this.GetString("end_time")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- fmt.Println("开始时间", startTime)
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- keyword := this.GetString("keyword")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, total, err := service.GetDrugDetailSummary(startTime, endTime, keyword, limit, page, orgId)
- druglist, _, _ := service.GetDrugDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
-
- patients, _ := service.GetAllpatient(orgId)
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
- for _, item := range list {
- for _, it := range druglist {
- if item.DrugId == it.DrugId {
- item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
- }
- }
- }
- drug, _ := service.GetAllDrugSummary(orgId)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "drug": drug,
- "drugTypeList": drugTypeList,
- "patients": patients,
- })
- }
- }
-
- func (this *StockManagerApiController) GetGoodDetailSummary() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
-
- end_time := this.GetString("end_time")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
-
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- keyword := this.GetString("keyword")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, total, err := service.GetGoodDetailSummary(startTime, endTime, keyword, limit, page, orgId)
-
- goodlist, _, _ := service.GetGoodDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
- for _, item := range list {
- for _, it := range goodlist {
- if item.ProjectId == it.ProjectId {
- item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
- }
- }
- }
-
- information, _ := service.GeAllGoodInformation(orgId)
- patients, _ := service.GetAllpatient(orgId)
- goodType, _ := service.GetAllGoodType(orgId)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "good": information,
- "patients": patients,
- "goodType": goodType,
- })
- }
- }
-
- func (this *StockManagerApiController) CheckWarehouseOut() {
-
- id, _ := this.GetInt64("id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- warehouseOut, _ := service.GetWarehouseById(id)
- //查询已审核的单据
- warehousingOutInfo, _ := service.GetWarehouseOutById(id, orgId)
- ////出库逻辑
- for _, item := range warehousingOutInfo {
- // 查询该耗材是否有库存
- warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId, item.StorehouseId)
- storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseId, item.OrgId)
-
- // 如果出库数量大于该批次剩余库存数量
- if item.Count > warehouseOne.StockCount {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- "storehose_name": storehouse.StorehouseName,
- })
- return
- }
-
- }
- for _, item := range warehousingOutInfo {
- creater := this.GetAdminUserInfo().AdminUser.Id
- service.ConsumablesDeliveryThirty(orgId, item.SysRecordTime, item, &warehouseOut, item.Count, creater)
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库扣减库存
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, orgId)
- }
-
- //审核单据
- err := service.UpdatedWarehouseOut(id)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "good_name": "",
- "specification_name": "",
- "storehose_name": "",
- })
- }
-
- }
-
- func (this *StockManagerApiController) ReturnCheckWarehouseOut() {
-
- id, _ := this.GetInt64("id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- // 查询出库数据
- list, err := service.GetWarehouseOutById(id, orgId)
- for _, item := range list {
- //回退库存
- service.UpdateaGoodWarehouseInfo(item.Count, item.GoodId, item.OrgId, item.WarehouseInfotId)
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库扣减库存
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, orgId)
- }
- //删除流水,改变审核状态
- service.ModifyGoodWarehouseOut(id)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "list",
- })
- }
- }
-
- func (this *StockManagerApiController) CheckWarehouseInfo() {
-
- warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
- //更改审核状态
- err := service.UpdateCheckWarehouseInfo(warehousing_info_id)
- if err == nil {
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetWarehouseInfoList(warehousing_info_id, orgId)
- Creator := this.GetAdminUserInfo().AdminUser.Id
- for _, item := range list {
- service.UpdateWarehouseInfoByIdList(item.WarehousingCount, item.ID)
- stockFlow := models.VmStockFlow{
- WarehousingId: item.WarehousingId,
- GoodId: item.GoodId,
- Number: item.Number,
- LicenseNumber: item.LicenseNumber,
- Count: item.WarehousingCount,
- UserOrgId: item.OrgId,
- PatientId: 0,
- SystemTime: 0,
- ConsumableType: 1,
- IsSys: 1,
- WarehousingOrder: item.WarehousingOrder,
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 1,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: item.Manufacturer,
- Dealer: item.Dealer,
- Creator: Creator,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: item.PackingPrice,
- WarehousingDetailId: item.ID,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ProductDate: item.ProductDate,
- ExpireDate: item.ExpiryDate,
- SupplyWarehouseId: item.SupplyWarehouseId,
- StorehouseId: item.StorehouseId,
- AdminUserId: 0,
- BuyPrice: item.Price,
- StockCount: "",
- }
- //创建出库流水
- service.CreateStockFlowOne(stockFlow)
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoSumCount(item.GoodId, total_count, orgId)
- }
- }
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "list",
- })
- }
- }
-
- func (this *StockManagerApiController) ReturnCheckWarehouseInfo() {
-
- warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- //查询入库数据
- list, _ := service.GetWarehouseInfoList(warehousing_info_id, orgId)
- for _, item := range list {
- //nightInfo, _ := service.GetWarehouseInfoByIdNight(item.ID)
- //if nightInfo.WarehousingCount != nightInfo.StockCount {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
- // return
- //}
- //查询该耗材 是否有出库数据
- outlist, _ := service.GetWarehouseOutByWarehouseInfoId(item.ID, item.GoodId, item.OrgId)
-
- if len(outlist) > 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
- return
- }
- }
- for _, item := range list {
-
- //退库
- service.UpdateWarehouseInfoByIdListTwo(item.WarehousingCount, item.ID)
- //删除流水
- service.UpdateWarehouseInfoFlow(item.ID)
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
- var sum_count int64
- var sum_in_count int64
- for _, it := range stockList {
- sum_count += it.StockCount
- sum_in_count += it.WarehousingCount
- }
- service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, orgId)
- }
- err := service.ReturnCheckWarehouseInfo(warehousing_info_id)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "反审核成功!",
- })
- return
- }
-
- }
-
- func (this *StockManagerApiController) CheckStockWarehouseInfo() {
-
- cancel_stock_id, _ := this.GetInt64("cancel_stock_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetCancelStockInfoListById(cancel_stock_id, orgId)
- creater := this.GetAdminUserInfo().AdminUser.Id
-
- manufacturerlist, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- var manufacturer_id int64
- var cancel_total_count int64
- var out_total_count int64
- var dealer_id int64
- for _, item := range list {
- for _, items := range manufacturerlist {
- if item.Manufacturer == items.ManufacturerName {
- manufacturer_id = items.ID
- }
- }
- for _, it := range dealerList {
- if item.Dealer == it.DealerName {
- dealer_id = it.ID
- }
- }
- //查询该药品该批次的出库数量是否满足退库需求
- outList, _ := service.GetWarehouseOutList(item.OrgId, item.GoodId, item.WarehouseInfoId)
- for _, it := range outList {
- out_total_count += it.Count
- }
- warehouseList, _ := service.GetCancelWarehouseList(item.OrgId, item.GoodId, item.WarehouseInfoId)
- for _, it := range warehouseList {
- cancel_total_count += it.Count
- }
- if cancel_total_count > out_total_count {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
-
- stockFlow := models.VmStockFlow{
- ID: 0,
- WarehousingId: 0,
- GoodId: item.GoodId,
- Number: item.Number,
- LicenseNumber: "",
- Count: item.Count,
- UserOrgId: item.OrgId,
- PatientId: item.PatientId,
- SystemTime: item.RecordDate,
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: cancel_stock_id,
- CancelOrderNumber: item.OrderNumber,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- Creator: creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: item.Price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: item.ID,
- ProductDate: item.ProductDate,
- ExpireDate: item.ExpiryDate,
- ReturnCount: 0,
- ProjectId: 0,
- SupplyWarehouseId: 0,
- SupplyCancelOutId: 0,
- SupplyWarehouseDetailInfo: 0,
- StorehouseId: item.StorehouseId,
- SecondWarehouseInfoId: 0,
- AdminUserId: 0,
- BuyPrice: item.Price,
- StockCount: "",
- }
- service.CreateStockFlowOne(stockFlow)
- }
-
- cancelStock := models.CancelStock{
- IsCheck: 1,
- }
- service.CheckCancelStock(cancelStock, cancel_stock_id, orgId)
-
- //回退库存
- cancellist, _ := service.GetCancelStockInfoById(cancel_stock_id, orgId)
- for _, item := range cancellist {
- service.UpdateCancelStockNumber(item.Count, item.WarehouseInfoId, orgId)
- service.UpdateGoodSumCount(item.Count, item.GoodId, orgId)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "good_name": "",
- "specification_name": "",
- })
- return
- }
-
- func (this *StockManagerApiController) CheckReturnStockWarehouseInfo() {
-
- cancel_stock_id, _ := this.GetInt64("cancel_stock_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- cancelStock := models.CancelStock{
- IsCheck: 2,
- }
- list, _ := service.GetCancelStockInfoListById(cancel_stock_id, orgId)
- for _, item := range list {
- //回退库存
- service.UpdateStockNumberWarehouseInfo(item.WarehouseInfoId, item.GoodId, item.OrgId, item.Count)
- service.UpdateStockWarehouseInfoStockFlow(item.ID, orgId, item.GoodId)
- }
- err := service.UpdateStockWarehouseInfo(cancel_stock_id, orgId, cancelStock)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "反审核成功!",
- })
- return
- }
- }
|