stock_in_api_controller.go 261KB

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