stock_in_api_controller.go 212KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521
  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. func (c *StockManagerApiController) CreateWarehouse() {
  112. warehousing_time := c.GetString("warehousing_time")
  113. types, _ := c.GetInt64("type", 0)
  114. ctime := time.Now().Unix()
  115. adminUserInfo := c.GetAdminUserInfo()
  116. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  117. if parseDateErr != nil {
  118. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  120. return
  121. }
  122. timeStr := time.Now().Format("2006-01-02")
  123. timeArr := strings.Split(timeStr, "-")
  124. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  125. total = total + 1
  126. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  127. operation_time := time.Now().Unix()
  128. creater := adminUserInfo.AdminUser.Id
  129. warehousing := models.Warehousing{
  130. WarehousingOrder: warehousing_order,
  131. OperationTime: operation_time,
  132. OrgId: adminUserInfo.CurrentOrgId,
  133. Creater: creater,
  134. Ctime: ctime,
  135. Status: 1,
  136. WarehousingTime: warehousingDate.Unix(),
  137. Type: types,
  138. }
  139. service.AddSigleWarehouse(&warehousing)
  140. dataBody := make(map[string]interface{}, 0)
  141. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  142. if err != nil {
  143. utils.ErrorLog(err.Error())
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. var warehousingInfo []*models.WarehousingInfo
  148. var stockFlow []*models.VmStockFlow
  149. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  150. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  151. if len(thisStockIn) > 0 {
  152. for _, item := range thisStockIn {
  153. items := item.(map[string]interface{})
  154. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  155. utils.ErrorLog("good_id")
  156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  157. return
  158. }
  159. good_id := int64(items["good_id"].(float64))
  160. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  161. utils.ErrorLog("good_type_id")
  162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  163. return
  164. }
  165. good_type_id := int64(items["good_type_id"].(float64))
  166. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  167. utils.ErrorLog("warehousing_count")
  168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  169. return
  170. }
  171. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  172. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  173. utils.ErrorLog("price")
  174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  175. return
  176. }
  177. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  178. total := float64(warehousing_count) * price
  179. var productDates int64
  180. var expiryDates int64
  181. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  182. expiryDates = 0
  183. } else {
  184. if len(items["expiry_date"].(string)) == 0 {
  185. expiryDates = 0
  186. } else {
  187. expiryDate, _ := items["expiry_date"].(string)
  188. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  189. expiryDates = expiry_date.Unix()
  190. }
  191. }
  192. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  193. productDates = 0
  194. } else {
  195. if len(items["product_date"].(string)) == 0 {
  196. productDates = 0
  197. } else {
  198. productDate, _ := items["product_date"].(string)
  199. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  200. productDates = product_date.Unix()
  201. }
  202. }
  203. number, _ := items["number"].(string)
  204. remark, _ := items["remark"].(string)
  205. manufacturer := int64(items["manufacturer"].(float64))
  206. dealer := int64(items["dealer"].(float64))
  207. license_number, _ := items["license_number"].(string)
  208. //入库单表格
  209. warehouseInfo := &models.WarehousingInfo{
  210. WarehousingOrder: warehousing.WarehousingOrder,
  211. WarehousingId: warehousing.ID,
  212. GoodId: good_id,
  213. Number: number,
  214. GoodTypeId: good_type_id,
  215. ProductDate: productDates,
  216. ExpiryDate: expiryDates,
  217. WarehousingCount: warehousing_count,
  218. Price: price,
  219. TotalPrice: total,
  220. Status: 1,
  221. Ctime: ctime,
  222. Remark: remark,
  223. OrgId: adminUserInfo.CurrentOrgId,
  224. Type: types,
  225. Manufacturer: manufacturer,
  226. StockCount: warehousing_count,
  227. Dealer: dealer,
  228. LicenseNumber: license_number,
  229. }
  230. warehousingInfo = append(warehousingInfo, warehouseInfo)
  231. flow := &models.VmStockFlow{
  232. WarehousingOrder: warehousing.WarehousingOrder,
  233. WarehousingId: warehousing.ID,
  234. GoodId: good_id,
  235. Number: number,
  236. ProductDate: productDates,
  237. ExpireDate: expiryDates,
  238. Count: warehousing_count,
  239. Price: price,
  240. Status: 1,
  241. Ctime: ctime,
  242. UserOrgId: adminUserInfo.CurrentOrgId,
  243. Manufacturer: manufacturer,
  244. Dealer: dealer,
  245. LicenseNumber: license_number,
  246. IsEdit: 1,
  247. Creator: adminUserInfo.AdminUser.Id,
  248. SystemTime: operation_time,
  249. ConsumableType: 1,
  250. WarehousingDetailId: warehouseInfo.ID,
  251. }
  252. stockFlow = append(stockFlow, flow)
  253. }
  254. }
  255. }
  256. //入库单创建成功
  257. errs := service.CreateWarehousingInfo(warehousingInfo)
  258. //创建入库单流水
  259. service.CreateStockFlow(stockFlow)
  260. info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
  261. for _, item := range warehousingInfo {
  262. goodInfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  263. str := strconv.FormatInt(item.WarehousingCount, 10)
  264. minFloat, _ := strconv.ParseFloat(str, 64)
  265. good := models.GoodInfo{
  266. Total: minFloat + goodInfo.Total,
  267. }
  268. //更该库存
  269. parseDateErr := service.UpdateGoodInfoList(good, goodInfo.ID)
  270. break
  271. fmt.Println(parseDateErr)
  272. }
  273. if errs != nil {
  274. utils.ErrorLog(errs.Error())
  275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  276. return
  277. }
  278. c.ServeSuccessJSON(map[string]interface{}{
  279. "msg": "入库成功",
  280. "warehousing_order": warehousing_order,
  281. "info": info,
  282. })
  283. }
  284. func (c *StockManagerApiController) GetWarehouseList() {
  285. page, _ := c.GetInt64("page", -1)
  286. limit, _ := c.GetInt64("limit", -1)
  287. start_time := c.GetString("start_time")
  288. end_time := c.GetString("end_time")
  289. types, _ := c.GetInt64("type", 0)
  290. keywords := c.GetString("keywords")
  291. timeLayout := "2006-01-02"
  292. loc, _ := time.LoadLocation("Local")
  293. var startTime int64
  294. if len(start_time) > 0 {
  295. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  296. if err != nil {
  297. fmt.Println(err)
  298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  299. return
  300. }
  301. startTime = theTime.Unix()
  302. }
  303. var endTime int64
  304. if len(end_time) > 0 {
  305. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  306. if err != nil {
  307. utils.ErrorLog(err.Error())
  308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. endTime = theTime.Unix()
  312. }
  313. adminUserInfo := c.GetAdminUserInfo()
  314. var ids []int64
  315. var goodids []int64
  316. //查询商品名称
  317. if len(keywords) > 0 {
  318. //查询商品名称
  319. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  320. for _, item := range list {
  321. goodids = append(goodids, item.ID)
  322. //入库详情但里面查询
  323. }
  324. if len(goodids) > 0 {
  325. info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  326. for _, it := range info {
  327. ids = append(ids, it.WarehousingId)
  328. }
  329. }
  330. }
  331. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  332. if err == nil {
  333. c.ServeSuccessJSON(map[string]interface{}{
  334. "list": warehouseList,
  335. "total": total,
  336. })
  337. } else {
  338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  339. }
  340. }
  341. func (c *StockManagerApiController) GetWarehouseInfoList() {
  342. id := c.GetString("id")
  343. idArray := strings.Split(id, ",")
  344. warehousing, err := service.FindWarehousingByIdOne(idArray)
  345. if err != nil {
  346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  347. return
  348. }
  349. var ids []int64
  350. for _, item := range warehousing {
  351. ids = append(ids, item.ID)
  352. }
  353. warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
  354. if err == nil {
  355. c.ServeSuccessJSON(map[string]interface{}{
  356. "info": warehousingInfo,
  357. "warehousing": warehousing,
  358. })
  359. } else {
  360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  361. }
  362. }
  363. func (c *StockManagerApiController) EditWarehouse() {
  364. warehousing_time := c.GetString("warehousing_time")
  365. id, _ := c.GetInt64("id", 0)
  366. types, _ := c.GetInt64("type", 0)
  367. if id == 0 {
  368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  369. return
  370. }
  371. ctime := time.Now().Unix()
  372. mtime := time.Now().Unix()
  373. adminUserInfo := c.GetAdminUserInfo()
  374. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  375. if parseDateErr != nil {
  376. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  378. return
  379. }
  380. warehouse, _ := service.FindWarehousingById(id)
  381. warehousing := models.Warehousing{
  382. WarehousingOrder: warehouse.WarehousingOrder,
  383. OrgId: adminUserInfo.CurrentOrgId,
  384. Modifier: adminUserInfo.AdminUser.Id,
  385. Mtime: mtime,
  386. Status: 1,
  387. WarehousingTime: warehousingDate.Unix(),
  388. Type: warehouse.Type,
  389. }
  390. service.EditWarehousing(warehousing)
  391. dataBody := make(map[string]interface{}, 0)
  392. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  393. if err != nil {
  394. utils.ErrorLog(err.Error())
  395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  396. return
  397. }
  398. var warehousingInfo []*models.WarehousingInfo
  399. var upDateWarehousingInfo []*models.WarehousingInfo
  400. var stockFlow []*models.VmStockFlow
  401. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  402. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  403. if len(thisStockIn) > 0 {
  404. for _, item := range thisStockIn {
  405. items := item.(map[string]interface{})
  406. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  407. utils.ErrorLog("good_id")
  408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  409. return
  410. }
  411. good_id := int64(items["good_id"].(float64))
  412. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  413. utils.ErrorLog("good_type_id")
  414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  415. return
  416. }
  417. good_type_id := int64(items["good_type_id"].(float64))
  418. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  419. utils.ErrorLog("warehousing_count")
  420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  421. return
  422. }
  423. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  424. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  425. utils.ErrorLog("price")
  426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  427. return
  428. }
  429. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  430. total := float64(warehousing_count) * price
  431. var productDates int64
  432. var expiryDates int64
  433. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  434. expiryDates = 0
  435. } else {
  436. if len(items["expiry_date"].(string)) == 0 {
  437. expiryDates = 0
  438. } else {
  439. expiryDate, _ := items["expiry_date"].(string)
  440. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  441. expiryDates = expiry_date.Unix()
  442. }
  443. }
  444. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  445. productDates = 0
  446. } else {
  447. if len(items["product_date"].(string)) == 0 {
  448. productDates = 0
  449. } else {
  450. productDate, _ := items["product_date"].(string)
  451. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  452. productDates = product_date.Unix()
  453. }
  454. }
  455. number, _ := items["number"].(string)
  456. remark, _ := items["remark"].(string)
  457. manufacturer := int64(items["manufacturer"].(float64))
  458. dealer := int64(items["dealer"].(float64))
  459. license_number, _ := items["license_number"].(string)
  460. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  461. utils.ErrorLog("id")
  462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  463. return
  464. }
  465. id := int64(items["id"].(float64))
  466. if id == 0 {
  467. warehouseInfo := &models.WarehousingInfo{
  468. WarehousingOrder: warehouse.WarehousingOrder,
  469. WarehousingId: warehouse.ID,
  470. GoodId: good_id,
  471. Number: number,
  472. GoodTypeId: good_type_id,
  473. ProductDate: productDates,
  474. ExpiryDate: expiryDates,
  475. WarehousingCount: warehousing_count,
  476. Price: price,
  477. TotalPrice: total,
  478. Status: 1,
  479. Ctime: ctime,
  480. Remark: remark,
  481. OrgId: adminUserInfo.CurrentOrgId,
  482. Type: types,
  483. Manufacturer: manufacturer,
  484. Dealer: dealer,
  485. StockCount: warehousing_count,
  486. LicenseNumber: license_number,
  487. }
  488. warehousingInfo = append(warehousingInfo, warehouseInfo)
  489. } else {
  490. warehouseInfo := &models.WarehousingInfo{
  491. ID: id,
  492. WarehousingOrder: warehouse.WarehousingOrder,
  493. WarehousingId: warehouse.ID,
  494. GoodId: good_id,
  495. Number: number,
  496. GoodTypeId: good_type_id,
  497. ProductDate: productDates,
  498. ExpiryDate: expiryDates,
  499. WarehousingCount: warehousing_count,
  500. Price: price,
  501. TotalPrice: total,
  502. Status: 1,
  503. Ctime: ctime,
  504. Remark: remark,
  505. OrgId: adminUserInfo.CurrentOrgId,
  506. Type: types,
  507. Manufacturer: manufacturer,
  508. Dealer: dealer,
  509. LicenseNumber: license_number,
  510. }
  511. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  512. flow := &models.VmStockFlow{
  513. WarehousingOrder: warehousing.WarehousingOrder,
  514. WarehousingId: id,
  515. GoodId: good_id,
  516. Number: number,
  517. ProductDate: productDates,
  518. ExpireDate: expiryDates,
  519. Count: warehousing_count,
  520. Price: price,
  521. Status: 1,
  522. Ctime: ctime,
  523. UserOrgId: adminUserInfo.CurrentOrgId,
  524. Manufacturer: manufacturer,
  525. Dealer: dealer,
  526. LicenseNumber: license_number,
  527. IsEdit: 2,
  528. Creator: adminUserInfo.AdminUser.Id,
  529. SystemTime: ctime,
  530. ConsumableType: 1,
  531. WarehousingDetailId: warehouseInfo.ID,
  532. }
  533. stockFlow = append(stockFlow, flow)
  534. }
  535. }
  536. }
  537. }
  538. var errs error
  539. if len(warehousingInfo) > 0 {
  540. errs = service.CreateWarehousingInfo(warehousingInfo)
  541. for _, its := range warehousingInfo {
  542. //查询
  543. info, _ := service.GetLastGoodWarehouseInfo(its.GoodId)
  544. flows := models.VmStockFlow{
  545. WarehousingOrder: info.WarehousingOrder,
  546. WarehousingId: info.ID,
  547. GoodId: info.GoodId,
  548. Number: info.Number,
  549. ProductDate: info.ProductDate,
  550. ExpireDate: info.ExpiryDate,
  551. Count: info.WarehousingCount,
  552. Price: info.Price,
  553. Status: 1,
  554. Ctime: ctime,
  555. UserOrgId: adminUserInfo.CurrentOrgId,
  556. Manufacturer: info.Manufacturer,
  557. Dealer: info.Dealer,
  558. LicenseNumber: info.LicenseNumber,
  559. IsEdit: 1,
  560. Creator: adminUserInfo.AdminUser.Id,
  561. SystemTime: ctime,
  562. ConsumableType: 1,
  563. WarehousingDetailId: info.ID,
  564. }
  565. _, errcodescode := service.GetGoodStockFlowInfo(info.ID, info.GoodId)
  566. if errcodescode == gorm.ErrRecordNotFound {
  567. service.CreateStockFlowOne(flows)
  568. }
  569. //改变库存
  570. good, _ := service.GetLastInfoMationById(info.GoodId)
  571. warhouseCount := strconv.FormatInt(info.WarehousingCount, 10)
  572. total, _ := strconv.ParseFloat(warhouseCount, 64)
  573. goodInfo := models.GoodInfo{
  574. Total: good.Total + total,
  575. }
  576. errcodescode = service.UpdateGoodInfoMation(info.GoodId, goodInfo)
  577. fmt.Println(errcodescode)
  578. }
  579. }
  580. if len(upDateWarehousingInfo) > 0 {
  581. for _, item := range upDateWarehousingInfo {
  582. var total int64
  583. //获取该批次该型号的库存
  584. info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
  585. //增加库存
  586. if item.WarehousingCount > info.WarehousingCount {
  587. total = item.WarehousingCount - info.WarehousingCount
  588. goodinfo := models.WarehousingInfo{
  589. WarehousingCount: item.WarehousingCount,
  590. StockCount: info.StockCount + total,
  591. }
  592. service.UpdateWarehouseInfoByGoodId(goodinfo, item.ID)
  593. flowStock := models.VmStockFlow{
  594. Count: item.WarehousingCount,
  595. }
  596. service.UpdatedStockFlowByGoodId(item.WarehousingId, item.GoodId, flowStock)
  597. //改变库存
  598. good, _ := service.GetLastInfoMationById(info.GoodId)
  599. warhouseCount := strconv.FormatInt(total, 10)
  600. all_total, _ := strconv.ParseFloat(warhouseCount, 64)
  601. goodInfo := models.GoodInfo{
  602. Total: good.Total + all_total,
  603. }
  604. service.UpdateGoodInfoMation(info.GoodId, goodInfo)
  605. }
  606. if item.WarehousingCount < info.WarehousingCount {
  607. total = info.WarehousingCount - item.WarehousingCount
  608. goodinfo := models.WarehousingInfo{
  609. WarehousingCount: item.WarehousingCount,
  610. StockCount: info.StockCount - total,
  611. }
  612. service.UpdateWarehouseInfoByGoodId(goodinfo, item.ID)
  613. //改变库存
  614. good, _ := service.GetLastInfoMationById(info.GoodId)
  615. warhouseCount := strconv.FormatInt(total, 10)
  616. all_total, _ := strconv.ParseFloat(warhouseCount, 64)
  617. goodInfo := models.GoodInfo{
  618. Total: good.Total - all_total,
  619. }
  620. service.UpdateGoodInfoMation(info.GoodId, goodInfo)
  621. }
  622. if item.WarehousingCount == info.WarehousingCount {
  623. goodinfo := models.WarehousingInfo{
  624. WarehousingCount: item.WarehousingCount,
  625. StockCount: info.StockCount,
  626. Price: item.Price,
  627. Manufacturer: item.Manufacturer,
  628. Number: item.Number,
  629. ProductDate: item.ProductDate,
  630. ExpiryDate: item.ExpiryDate,
  631. LicenseNumber: item.LicenseNumber,
  632. Dealer: item.Dealer,
  633. Remark: item.Remark,
  634. }
  635. service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
  636. }
  637. }
  638. }
  639. if len(stockFlow) > 0 {
  640. for _, item := range stockFlow {
  641. flow := models.VmStockFlow{
  642. Count: item.Count,
  643. }
  644. parseDateErr := service.UpdateStockFlow(flow, item.GoodId, item.WarehousingId)
  645. fmt.Println(parseDateErr)
  646. }
  647. }
  648. if errs != nil {
  649. utils.ErrorLog(errs.Error())
  650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  651. return
  652. }
  653. c.ServeSuccessJSON(map[string]interface{}{
  654. "msg": "编辑成功",
  655. })
  656. }
  657. func (c *StockManagerApiController) DeleteWarehouse() {
  658. ids := c.GetString("ids")
  659. if len(ids) == 0 {
  660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  661. return
  662. }
  663. idArray := strings.Split(ids, ",")
  664. err := service.DeleteWarehouse(idArray)
  665. if err != nil {
  666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  667. } else {
  668. c.ServeSuccessJSON(map[string]interface{}{
  669. "msg": "删除成功",
  670. })
  671. }
  672. }
  673. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  674. id, _ := c.GetInt64("id", 0)
  675. if id == 0 {
  676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  677. return
  678. }
  679. err := service.UpDateWarehouseStatus(id)
  680. if err != nil {
  681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  682. } else {
  683. c.ServeSuccessJSON(map[string]interface{}{
  684. "msg": "删除成功",
  685. })
  686. }
  687. }
  688. func (c *StockManagerApiController) CreateSalesReturn() {
  689. dealer_id, _ := c.GetInt64("dealer_id", 0)
  690. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  691. sales_return_time := c.GetString("time")
  692. types, _ := c.GetInt64("type", 0)
  693. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  694. if parseDateErr != nil {
  695. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  697. return
  698. }
  699. adminUserInfo := c.GetAdminUserInfo()
  700. operation_time := time.Now().Unix()
  701. creater := adminUserInfo.AdminUser.Id
  702. ctime := time.Now().Unix()
  703. timeStr := time.Now().Format("2006-01-02")
  704. timeArr := strings.Split(timeStr, "-")
  705. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  706. total = total + 1
  707. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  708. salesReturn := models.SalesReturn{
  709. OrderNumber: orderNumber,
  710. OperaTime: operation_time,
  711. OrgId: adminUserInfo.CurrentOrgId,
  712. Creater: creater,
  713. Ctime: ctime,
  714. Status: 1,
  715. ReturnTime: salesReturnDate.Unix(),
  716. Dealer: dealer_id,
  717. Manufacturer: manufacturer_id,
  718. Type: types,
  719. }
  720. service.AddSigleSalesReturn(&salesReturn)
  721. dataBody := make(map[string]interface{}, 0)
  722. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  723. if err != nil {
  724. utils.ErrorLog(err.Error())
  725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  726. return
  727. }
  728. var salesReturnInfos []*models.SalesReturnInfo
  729. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  730. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  731. if len(thisStockIn) > 0 {
  732. for _, item := range thisStockIn {
  733. items := item.(map[string]interface{})
  734. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  735. utils.ErrorLog("good_id")
  736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  737. return
  738. }
  739. good_id := int64(items["good_id"].(float64))
  740. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  741. utils.ErrorLog("good_type_id")
  742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  743. return
  744. }
  745. good_type_id := int64(items["good_type_id"].(float64))
  746. return_count, _ := items["return_count"].(string)
  747. if len(return_count) == 0 {
  748. utils.ErrorLog("len(return_count) == 0")
  749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  750. return
  751. }
  752. count, _ := strconv.ParseInt(return_count, 10, 64)
  753. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  754. total := float64(count) * price
  755. salesReturnInfo := &models.SalesReturnInfo{
  756. OrderNumber: salesReturn.OrderNumber,
  757. SalesReturnId: salesReturn.ID,
  758. GoodId: good_id,
  759. GoodTypeId: good_type_id,
  760. Count: count,
  761. Price: price,
  762. Total: total,
  763. Status: 1,
  764. Ctime: ctime,
  765. OrgId: adminUserInfo.CurrentOrgId,
  766. Type: types,
  767. Manufacturer: manufacturer_id,
  768. Dealer: dealer_id,
  769. }
  770. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  771. }
  772. }
  773. }
  774. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  775. if errs != nil {
  776. utils.ErrorLog(errs.Error())
  777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  778. return
  779. }
  780. c.ServeSuccessJSON(map[string]interface{}{
  781. "msg": "退货成功",
  782. })
  783. }
  784. func (c *StockManagerApiController) GetSalesReturnList() {
  785. page, _ := c.GetInt64("page", -1)
  786. limit, _ := c.GetInt64("limit", -1)
  787. start_time := c.GetString("start_time")
  788. end_time := c.GetString("end_time")
  789. types, _ := c.GetInt64("type", 0)
  790. keywords := c.GetString("keywords")
  791. timeLayout := "2006-01-02"
  792. loc, _ := time.LoadLocation("Local")
  793. var startTime int64
  794. if len(start_time) > 0 {
  795. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  796. if err != nil {
  797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  798. return
  799. }
  800. startTime = theTime.Unix()
  801. }
  802. var endTime int64
  803. if len(end_time) > 0 {
  804. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  805. if err != nil {
  806. utils.ErrorLog(err.Error())
  807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  808. return
  809. }
  810. endTime = theTime.Unix()
  811. }
  812. adminUserInfo := c.GetAdminUserInfo()
  813. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  814. if err == nil {
  815. c.ServeSuccessJSON(map[string]interface{}{
  816. "list": returnList,
  817. "total": total,
  818. })
  819. } else {
  820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  821. }
  822. }
  823. func (this *StockManagerApiController) DeleteSalesReturn() {
  824. ids := this.GetString("ids")
  825. if len(ids) == 0 {
  826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  827. return
  828. }
  829. idArray := strings.Split(ids, ",")
  830. err := service.DeleteSalesReturn(idArray)
  831. if err != nil {
  832. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  833. } else {
  834. this.ServeSuccessJSON(map[string]interface{}{
  835. "msg": "删除成功",
  836. })
  837. }
  838. }
  839. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  840. id, _ := this.GetInt64("id", 0)
  841. fmt.Println(id)
  842. if id == 0 {
  843. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  844. return
  845. }
  846. err := service.UpDateSaleReturnStatus(id)
  847. if err != nil {
  848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  849. } else {
  850. this.ServeSuccessJSON(map[string]interface{}{
  851. "msg": "删除成功",
  852. })
  853. }
  854. }
  855. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  856. id, _ := this.GetInt64("id", 0)
  857. list, _ := service.FindAllSalesReturnInfoById(id)
  858. salesReturn, _ := service.FindAllSalesReturnById(id)
  859. this.ServeSuccessJSON(map[string]interface{}{
  860. "list": list,
  861. "salesReturn": salesReturn,
  862. })
  863. }
  864. func (c *StockManagerApiController) EditReturnInfo() {
  865. return_time := c.GetString("return_time")
  866. id, _ := c.GetInt64("id", 0)
  867. types, _ := c.GetInt64("type", 0)
  868. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  869. dealer_id, _ := c.GetInt64("dealer_id", 0)
  870. if id == 0 {
  871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  872. return
  873. }
  874. ctime := time.Now().Unix()
  875. mtime := time.Now().Unix()
  876. adminUserInfo := c.GetAdminUserInfo()
  877. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  878. if parseDateErr != nil {
  879. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  881. return
  882. }
  883. salesReturns, _ := service.FindSalesReturnById(id)
  884. sales := models.SalesReturn{
  885. ID: salesReturns.ID,
  886. Mtime: mtime,
  887. ReturnTime: returnDate.Unix(),
  888. Manufacturer: manufacturer_id,
  889. Dealer: dealer_id,
  890. }
  891. service.EditSaleReturn(sales)
  892. dataBody := make(map[string]interface{}, 0)
  893. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  894. if err != nil {
  895. utils.ErrorLog(err.Error())
  896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  897. return
  898. }
  899. var returnInfos []*models.SalesReturnInfo
  900. var upDateReturnInfos []*models.SalesReturnInfo
  901. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  902. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  903. if len(thisStockIn) > 0 {
  904. for _, item := range thisStockIn {
  905. items := item.(map[string]interface{})
  906. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  907. utils.ErrorLog("good_id")
  908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  909. return
  910. }
  911. good_id := int64(items["good_id"].(float64))
  912. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  913. utils.ErrorLog("good_type_id")
  914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  915. return
  916. }
  917. good_type_id := int64(items["good_type_id"].(float64))
  918. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  919. utils.ErrorLog("count")
  920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  921. return
  922. }
  923. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  924. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  925. utils.ErrorLog("id")
  926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  927. return
  928. }
  929. id := int64(items["id"].(float64))
  930. if id == 0 {
  931. returnInfo := &models.SalesReturnInfo{
  932. GoodId: good_id,
  933. GoodTypeId: good_type_id,
  934. Count: count,
  935. Status: 1,
  936. Ctime: ctime,
  937. OrgId: adminUserInfo.CurrentOrgId,
  938. OrderNumber: sales.OrderNumber,
  939. SalesReturnId: sales.ID,
  940. Mtime: time.Now().Unix(),
  941. Type: types,
  942. Manufacturer: manufacturer_id,
  943. Dealer: dealer_id,
  944. }
  945. returnInfos = append(returnInfos, returnInfo)
  946. } else {
  947. returnInfo := &models.SalesReturnInfo{
  948. ID: id,
  949. GoodId: good_id,
  950. GoodTypeId: good_type_id,
  951. Count: count,
  952. Status: 1,
  953. Ctime: ctime,
  954. OrgId: adminUserInfo.CurrentOrgId,
  955. OrderNumber: sales.OrderNumber,
  956. SalesReturnId: sales.ID,
  957. Mtime: time.Now().Unix(),
  958. Type: types,
  959. Manufacturer: manufacturer_id,
  960. Dealer: dealer_id,
  961. }
  962. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  963. }
  964. }
  965. }
  966. }
  967. var errs error
  968. if len(returnInfos) > 0 {
  969. errs = service.CreateSalesReturnInfo(returnInfos)
  970. }
  971. if len(upDateReturnInfos) > 0 {
  972. for _, item := range upDateReturnInfos {
  973. errs = service.UpDateSalesReturnInfo(item)
  974. }
  975. }
  976. if errs != nil {
  977. utils.ErrorLog(errs.Error())
  978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  979. return
  980. }
  981. c.ServeSuccessJSON(map[string]interface{}{
  982. "msg": "编辑成功",
  983. })
  984. }
  985. func (c *StockManagerApiController) CreateWarehouseOut() {
  986. types, _ := c.GetInt64("type", 0)
  987. ctime := time.Now().Unix()
  988. adminUserInfo := c.GetAdminUserInfo()
  989. warehousing_out_time := c.GetString("warehousing_out_time")
  990. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  991. if parseDateErr != nil {
  992. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  994. return
  995. }
  996. timeStr := time.Now().Format("2006-01-02")
  997. timeArr := strings.Split(timeStr, "-")
  998. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  999. total = total + 1
  1000. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1001. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1002. number = number + total
  1003. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1004. operation_time := time.Now().Unix()
  1005. creater := adminUserInfo.AdminUser.Id
  1006. warehouseOut := models.WarehouseOut{
  1007. WarehouseOutOrderNumber: warehousing_out_order,
  1008. OperationTime: operation_time,
  1009. OrgId: adminUserInfo.CurrentOrgId,
  1010. Creater: creater,
  1011. Ctime: ctime,
  1012. Status: 1,
  1013. WarehouseOutTime: warehousingOutDate.Unix(),
  1014. Type: types,
  1015. }
  1016. dataBody := make(map[string]interface{}, 0)
  1017. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1018. if err != nil {
  1019. utils.ErrorLog(err.Error())
  1020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1021. return
  1022. }
  1023. var warehousingOutInfo []*models.WarehouseOutInfo
  1024. var beforePrepares []*models.DialysisBeforePrepareGoods
  1025. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  1026. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1027. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  1028. if len(thisStockIn) > 0 {
  1029. for _, item := range thisStockIn {
  1030. items := item.(map[string]interface{})
  1031. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1032. utils.ErrorLog("good_id")
  1033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1034. return
  1035. }
  1036. good_id := int64(items["good_id"].(float64))
  1037. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1038. utils.ErrorLog("good_type_id")
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1040. return
  1041. }
  1042. good_type_id := int64(items["good_type_id"].(float64))
  1043. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1044. utils.ErrorLog("count")
  1045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1046. return
  1047. }
  1048. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1049. utils.ErrorLog("price")
  1050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1051. return
  1052. }
  1053. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1054. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1055. total := float64(count) * price
  1056. remark := items["remark"].(string)
  1057. manufacturer := int64(items["manufacturer"].(float64))
  1058. dealer := int64(items["dealer"].(float64))
  1059. number := items["number"].(string)
  1060. expiry_date := items["expiry_date"].(string)
  1061. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1062. timeLayout := "2006-01-02"
  1063. loc, _ := time.LoadLocation("Local")
  1064. var expiryDate int64
  1065. if len(expiry_date) > 0 {
  1066. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1067. if err != nil {
  1068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1069. return
  1070. }
  1071. expiryDate = theTime.Unix()
  1072. }
  1073. product_date := items["product_date"].(string)
  1074. var productDate int64
  1075. if len(product_date) > 0 {
  1076. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1077. if err != nil {
  1078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1079. return
  1080. }
  1081. productDate = theTime.Unix()
  1082. }
  1083. license_number := items["license_number"].(string)
  1084. warehouseOutInfo := &models.WarehouseOutInfo{
  1085. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1086. WarehouseOutId: warehouseOut.ID,
  1087. GoodId: good_id,
  1088. GoodTypeId: good_type_id,
  1089. Count: count,
  1090. Price: price,
  1091. TotalPrice: total,
  1092. Status: 1,
  1093. Ctime: ctime,
  1094. Remark: remark,
  1095. OrgId: adminUserInfo.CurrentOrgId,
  1096. Type: types,
  1097. Manufacturer: manufacturer,
  1098. Number: number,
  1099. ExpiryDate: expiryDate,
  1100. ProductDate: productDate,
  1101. Dealer: dealer,
  1102. LicenseNumber: license_number,
  1103. WarehouseInfotId: warehouse_info_id,
  1104. }
  1105. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1106. prepareGoods := &models.DialysisBeforePrepareGoods{
  1107. GoodTypeId: good_type_id,
  1108. GoodId: good_id,
  1109. Count: count,
  1110. }
  1111. beforePrepares = append(beforePrepares, prepareGoods)
  1112. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  1113. GoodTypeId: good_type_id,
  1114. GoodId: good_id,
  1115. Count: count,
  1116. }
  1117. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  1118. }
  1119. }
  1120. }
  1121. //出库逻辑
  1122. for _, item := range warehousingOutInfo {
  1123. // 查询该耗材是否有库存
  1124. warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId)
  1125. fmt.Println("hhh2333223223", item.GoodId, item.Count, warehouseOne.StockCount)
  1126. // 如果出库数量大于该批次剩余库存数量
  1127. if item.Count > warehouseOne.StockCount {
  1128. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1129. c.ServeSuccessJSON(map[string]interface{}{
  1130. "msg": "1",
  1131. "good_name": goodObj.GoodName,
  1132. "specification_name": goodObj.SpecificationName,
  1133. })
  1134. return
  1135. }
  1136. }
  1137. for _, it := range warehousingOutInfo {
  1138. //查询是否生成出库单
  1139. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  1140. if errcodes == gorm.ErrRecordNotFound {
  1141. service.AddSigleWarehouseOut(&warehouseOut)
  1142. }
  1143. //出库逻辑
  1144. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), it, &warehouseOut, it.Count, creater)
  1145. if parseDateErr != nil {
  1146. utils.ErrorLog(parseDateErr.Error())
  1147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1148. return
  1149. }
  1150. c.ServeSuccessJSON(map[string]interface{}{
  1151. "msg": "2",
  1152. "good_name": "",
  1153. "specification_name": "",
  1154. })
  1155. }
  1156. }
  1157. func (c *StockManagerApiController) GetWarehouseOutList() {
  1158. page, _ := c.GetInt64("page", -1)
  1159. limit, _ := c.GetInt64("limit", -1)
  1160. start_time := c.GetString("start_time")
  1161. end_time := c.GetString("end_time")
  1162. types, _ := c.GetInt64("type", 0)
  1163. keywords := c.GetString("keywords")
  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)
  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)
  1203. fmt.Println(err)
  1204. if err == nil {
  1205. c.ServeSuccessJSON(map[string]interface{}{
  1206. "list": warehouseOutList,
  1207. "total": total,
  1208. })
  1209. } else {
  1210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1211. }
  1212. }
  1213. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1214. ids := c.GetString("ids")
  1215. if len(ids) == 0 {
  1216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1217. return
  1218. }
  1219. idArray := strings.Split(ids, ",")
  1220. err := service.DeleteWarehouseOut(idArray)
  1221. if err != nil {
  1222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1223. } else {
  1224. c.ServeSuccessJSON(map[string]interface{}{
  1225. "msg": "删除成功",
  1226. })
  1227. }
  1228. }
  1229. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1230. id, _ := this.GetInt64("id", 0)
  1231. fmt.Println(id)
  1232. if id == 0 {
  1233. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1234. return
  1235. }
  1236. err := service.UpDateWarehouseOutStatus(id)
  1237. if err != nil {
  1238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1239. } else {
  1240. this.ServeSuccessJSON(map[string]interface{}{
  1241. "msg": "删除成功",
  1242. })
  1243. }
  1244. }
  1245. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1246. id, _ := c.GetInt64("id", 0)
  1247. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1248. warehouseOut, _ := service.FindWareHouseOutById(id)
  1249. adminUserInfo := c.GetAdminUserInfo()
  1250. orgId := adminUserInfo.CurrentOrgId
  1251. wareoutList, _ := service.GetWareOutInfoById(id, orgId)
  1252. c.ServeSuccessJSON(map[string]interface{}{
  1253. "list": warehouseOutInfo,
  1254. "info": warehouseOut,
  1255. "wareoutList": wareoutList,
  1256. })
  1257. }
  1258. func (c *StockManagerApiController) EditWarehouseOut() {
  1259. warehouse_out_time := c.GetString("warehouse_out_time")
  1260. id, _ := c.GetInt64("id", 0)
  1261. types, _ := c.GetInt64("type", 0)
  1262. if id == 0 {
  1263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1264. return
  1265. }
  1266. ctime := time.Now().Unix()
  1267. mtime := time.Now().Unix()
  1268. adminUserInfo := c.GetAdminUserInfo()
  1269. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1270. if parseDateErr != nil {
  1271. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1273. return
  1274. }
  1275. warehouseOut, _ := service.FindWareHouseOutById(id)
  1276. tempWarehouseOut := models.WarehouseOut{
  1277. ID: warehouseOut.ID,
  1278. Mtime: mtime,
  1279. WarehouseOutTime: warehouseOutDate.Unix(),
  1280. }
  1281. service.EditWarehouseOut(tempWarehouseOut)
  1282. dataBody := make(map[string]interface{}, 0)
  1283. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1284. if err != nil {
  1285. utils.ErrorLog(err.Error())
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1287. return
  1288. }
  1289. var warehousingOutInfo []*models.WarehouseOutInfo
  1290. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1291. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1292. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1293. if len(thisStockOut) > 0 {
  1294. for _, item := range thisStockOut {
  1295. items := item.(map[string]interface{})
  1296. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1297. utils.ErrorLog("good_id")
  1298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1299. return
  1300. }
  1301. good_id := int64(items["good_id"].(float64))
  1302. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1303. utils.ErrorLog("good_type_id")
  1304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1305. return
  1306. }
  1307. good_type_id := int64(items["good_type_id"].(float64))
  1308. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1309. utils.ErrorLog("count")
  1310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1311. return
  1312. }
  1313. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1314. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1315. utils.ErrorLog("price")
  1316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1317. return
  1318. }
  1319. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1320. total := float64(count) * price
  1321. remark := items["remark"].(string)
  1322. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1323. utils.ErrorLog("id")
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1325. return
  1326. }
  1327. id := int64(items["id"].(float64))
  1328. manufacturer := int64(items["manufacturer"].(float64))
  1329. dealer := int64(items["dealer"].(float64))
  1330. number := items["number"].(string)
  1331. license_number := items["license_number"].(string)
  1332. timeLayout := "2006-01-02"
  1333. loc, _ := time.LoadLocation("Local")
  1334. expiry_date := items["expiry_date"].(string)
  1335. var expiryDate int64
  1336. if len(expiry_date) > 0 {
  1337. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1338. if err != nil {
  1339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1340. return
  1341. }
  1342. expiryDate = theTime.Unix()
  1343. }
  1344. product_date := items["product_date"].(string)
  1345. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1346. var productDate int64
  1347. if len(product_date) > 0 {
  1348. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1349. if err != nil {
  1350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1351. return
  1352. }
  1353. productDate = theTime.Unix()
  1354. }
  1355. if id == 0 {
  1356. warehouseOutInfo := &models.WarehouseOutInfo{
  1357. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1358. WarehouseOutId: warehouseOut.ID,
  1359. GoodId: good_id,
  1360. GoodTypeId: good_type_id,
  1361. Count: count,
  1362. Price: price,
  1363. TotalPrice: total,
  1364. Status: 1,
  1365. Ctime: ctime,
  1366. Remark: remark,
  1367. OrgId: adminUserInfo.CurrentOrgId,
  1368. Type: types,
  1369. IsSys: 0,
  1370. SysRecordTime: 0,
  1371. Number: number,
  1372. ExpiryDate: expiryDate,
  1373. ProductDate: productDate,
  1374. Dealer: dealer,
  1375. Manufacturer: manufacturer,
  1376. LicenseNumber: license_number,
  1377. ConsumableType: 1,
  1378. WarehouseInfotId: warehouse_info_id,
  1379. }
  1380. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1381. } else {
  1382. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1383. utils.ErrorLog("is_sys")
  1384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1385. return
  1386. }
  1387. is_sys := int64(items["is_sys"].(float64))
  1388. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1389. utils.ErrorLog("sys_record_time")
  1390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1391. return
  1392. }
  1393. sys_record_time := int64(items["sys_record_time"].(float64))
  1394. warehouseOutInfo := &models.WarehouseOutInfo{
  1395. ID: id,
  1396. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1397. WarehouseOutId: warehouseOut.ID,
  1398. GoodId: good_id,
  1399. GoodTypeId: good_type_id,
  1400. Count: count,
  1401. Price: price,
  1402. TotalPrice: total,
  1403. Status: 1,
  1404. Ctime: ctime,
  1405. Remark: remark,
  1406. OrgId: adminUserInfo.CurrentOrgId,
  1407. Mtime: time.Now().Unix(),
  1408. Type: types,
  1409. Manufacturer: manufacturer,
  1410. IsSys: is_sys,
  1411. SysRecordTime: sys_record_time,
  1412. Number: number,
  1413. ExpiryDate: expiryDate,
  1414. ProductDate: productDate,
  1415. Dealer: dealer,
  1416. LicenseNumber: license_number,
  1417. ConsumableType: 2,
  1418. WarehouseInfotId: warehouse_info_id,
  1419. }
  1420. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1421. }
  1422. }
  1423. }
  1424. }
  1425. var errs error
  1426. //新增出库
  1427. if len(warehousingOutInfo) > 0 {
  1428. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1429. if parseDateErr != nil {
  1430. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. return
  1433. }
  1434. creater := adminUserInfo.AdminUser.Id
  1435. for _, item := range warehousingOutInfo {
  1436. // 查询该耗材是否有库存
  1437. warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId)
  1438. // 如果出库数量大于该批次剩余库存数量
  1439. if item.Count > warehouseOne.StockCount {
  1440. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1441. c.ServeSuccessJSON(map[string]interface{}{
  1442. "msg": "7",
  1443. "good_name": goodObj.GoodName,
  1444. "specification_name": goodObj.SpecificationName,
  1445. })
  1446. return
  1447. } else {
  1448. warehouseOut, _ := service.GetWarehouseById(id)
  1449. //出库逻辑
  1450. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
  1451. if parseDateErr != nil {
  1452. utils.ErrorLog(parseDateErr.Error())
  1453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1454. return
  1455. }
  1456. }
  1457. }
  1458. }
  1459. if len(upDateWarehouseOutInfos) > 0 {
  1460. for _, item := range upDateWarehouseOutInfos {
  1461. //1.查询该耗材该批次的最后一次出库记录
  1462. lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId)
  1463. // 退库的库存和该耗材该批次最后一次出库数量进行比较
  1464. //如果退库数量大于 最后一次批次的数量(要么要进行出库)
  1465. if item.Count > lastGood.Count {
  1466. //查询该耗材是否还有库存
  1467. warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
  1468. //无库存
  1469. if warehouseinfo.StockCount <= 0 {
  1470. c.ServeSuccessJSON(map[string]interface{}{
  1471. "msg": "5",
  1472. })
  1473. return
  1474. }
  1475. //有库存,进行出库,调用出库接口
  1476. if warehouseinfo.StockCount > 0 {
  1477. var total int64
  1478. var stock_cout int64
  1479. var total_count int64
  1480. //计算和最后一次出库数据的差
  1481. total = item.Count - lastGood.Count
  1482. //获取该耗材该批次的剩余库存量
  1483. info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1484. //判断该批次的剩余库存 和出库的库存进行比较
  1485. //如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
  1486. if item.Count > info.StockCount {
  1487. //计算出库和该批次相差的库存
  1488. total_count = item.Count - info.StockCount
  1489. //清空本批次次库存
  1490. service.DeleteWarehouseInfo(item.WarehouseInfotId)
  1491. //调用出库逻辑
  1492. parseDateErr := service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
  1493. if parseDateErr != nil {
  1494. utils.ErrorLog(errs.Error())
  1495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1496. return
  1497. }
  1498. c.ServeSuccessJSON(map[string]interface{}{
  1499. "msg": "1",
  1500. })
  1501. }
  1502. //如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
  1503. if item.Count <= info.StockCount {
  1504. stock_cout = lastGood.Count + total
  1505. fmt.Println(stock_cout)
  1506. //扣减库存
  1507. warehouse := models.WarehousingInfo{
  1508. StockCount: info.StockCount - total,
  1509. }
  1510. errs := service.UpdateWarehousingInfo(warehouse, info.ID)
  1511. warehouseOutInfo := &models.WarehouseOutInfo{
  1512. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1513. WarehouseOutId: id,
  1514. WarehouseInfotId: item.WarehouseInfotId,
  1515. Status: 1,
  1516. Ctime: time.Now().Unix(),
  1517. Remark: item.Remark,
  1518. OrgId: item.OrgId,
  1519. Type: 1,
  1520. Manufacturer: item.Manufacturer,
  1521. Dealer: item.Dealer,
  1522. IsSys: 0,
  1523. SysRecordTime: item.SysRecordTime,
  1524. GoodTypeId: item.GoodTypeId,
  1525. GoodId: item.GoodId,
  1526. ExpiryDate: item.ExpiryDate,
  1527. ProductDate: item.ProductDate,
  1528. Number: item.Number,
  1529. Price: item.Price,
  1530. LicenseNumber: item.LicenseNumber,
  1531. Count: item.Count,
  1532. ConsumableType: 2,
  1533. }
  1534. //查询是否存在
  1535. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1536. if errcode == gorm.ErrRecordNotFound {
  1537. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1538. if errOne != nil {
  1539. utils.ErrorLog(errs.Error())
  1540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1541. return
  1542. }
  1543. c.ServeSuccessJSON(map[string]interface{}{
  1544. "msg": "1",
  1545. })
  1546. return
  1547. } else if errcode == nil {
  1548. service.UpDateWarehouseOutInfo(item)
  1549. c.ServeSuccessJSON(map[string]interface{}{
  1550. "msg": "1",
  1551. })
  1552. return
  1553. }
  1554. }
  1555. }
  1556. }
  1557. var last_count int64
  1558. var all_total int64
  1559. var stock_total int64
  1560. //如果退库数量小于最后一次批次的数量(要么要进行退库)
  1561. if item.Count < lastGood.Count {
  1562. //退库数量和最后一次出库数据进行计算
  1563. last_count = lastGood.Count - item.Count
  1564. //获取该耗材该批次的剩余库存量
  1565. infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1566. //退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
  1567. all_total = last_count + infoInfo.StockCount
  1568. //如果库存大于总数量,则退回到这个批次
  1569. if infoInfo.WarehousingCount > all_total {
  1570. stock_total = last_count + infoInfo.StockCount
  1571. //退回该批次,计算数量
  1572. warehousingInfoOne := models.WarehousingInfo{
  1573. StockCount: stock_total,
  1574. ID: item.WarehouseInfotId,
  1575. OrgId: item.OrgId,
  1576. }
  1577. parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
  1578. fmt.Println("parseDateErr", parseDateErr)
  1579. //插入一条新纪录
  1580. warehouseOutInfoThree := &models.WarehouseOutInfo{
  1581. WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  1582. WarehouseOutId: id,
  1583. WarehouseInfotId: item.WarehouseInfotId,
  1584. Status: 1,
  1585. Ctime: time.Now().Unix(),
  1586. Remark: item.Remark,
  1587. OrgId: item.OrgId,
  1588. Type: 1,
  1589. Manufacturer: item.Manufacturer,
  1590. Dealer: item.Dealer,
  1591. IsSys: 0,
  1592. GoodTypeId: item.GoodTypeId,
  1593. GoodId: item.GoodId,
  1594. ExpiryDate: item.ExpiryDate,
  1595. ProductDate: item.ProductDate,
  1596. Number: item.Number,
  1597. Price: item.Price,
  1598. LicenseNumber: item.LicenseNumber,
  1599. ConsumableType: 2,
  1600. Count: item.Count,
  1601. }
  1602. //查询是否存在
  1603. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1604. if errcode == gorm.ErrRecordNotFound {
  1605. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
  1606. if errOne != nil {
  1607. utils.ErrorLog(errs.Error())
  1608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1609. return
  1610. }
  1611. c.ServeSuccessJSON(map[string]interface{}{
  1612. "msg": "1",
  1613. })
  1614. return
  1615. } else if errcode == nil {
  1616. service.UpDateWarehouseOutInfo(item)
  1617. return
  1618. }
  1619. }
  1620. //如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
  1621. if infoInfo.WarehousingCount < all_total {
  1622. c.ServeSuccessJSON(map[string]interface{}{
  1623. "msg": "6",
  1624. })
  1625. return
  1626. }
  1627. }
  1628. if item.Count == lastGood.Count {
  1629. errs = service.UpDateWarehouseOutInfo(item)
  1630. if errs != nil {
  1631. utils.ErrorLog(errs.Error())
  1632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1633. return
  1634. }
  1635. c.ServeSuccessJSON(map[string]interface{}{
  1636. "msg": "1",
  1637. })
  1638. return
  1639. }
  1640. }
  1641. }
  1642. if errs != nil {
  1643. utils.ErrorLog(errs.Error())
  1644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1645. return
  1646. }
  1647. c.ServeSuccessJSON(map[string]interface{}{
  1648. "msg": "1",
  1649. })
  1650. }
  1651. func (c *StockManagerApiController) CreateCancelStock() {
  1652. cancel_stock_time := c.GetString("time")
  1653. types, _ := c.GetInt64("type", 0)
  1654. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1655. if parseDateErr != nil {
  1656. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1658. return
  1659. }
  1660. adminUserInfo := c.GetAdminUserInfo()
  1661. operation_time := time.Now().Unix()
  1662. creater := adminUserInfo.AdminUser.Id
  1663. ctime := time.Now().Unix()
  1664. timeStr := time.Now().Format("2006-01-02")
  1665. timeArr := strings.Split(timeStr, "-")
  1666. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1667. total = total + 1
  1668. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1669. cancelStock := models.CancelStock{
  1670. OrderNumber: orderNumber,
  1671. OperaTime: operation_time,
  1672. OrgId: adminUserInfo.CurrentOrgId,
  1673. Creater: creater,
  1674. Ctime: ctime,
  1675. Status: 1,
  1676. ReturnTime: cancelStockDate.Unix(),
  1677. Type: types,
  1678. }
  1679. dataBody := make(map[string]interface{}, 0)
  1680. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1681. if err != nil {
  1682. utils.ErrorLog(err.Error())
  1683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1684. return
  1685. }
  1686. var cancelStockInfos []*models.CancelStockInfo
  1687. var stockFLow []*models.VmStockFlow
  1688. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1689. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1690. if len(thisStockIn) > 0 {
  1691. for _, item := range thisStockIn {
  1692. items := item.(map[string]interface{})
  1693. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1694. utils.ErrorLog("good_id")
  1695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1696. return
  1697. }
  1698. good_id := int64(items["good_id"].(float64))
  1699. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1700. utils.ErrorLog("good_type_id")
  1701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1702. return
  1703. }
  1704. good_type_id := int64(items["good_type_id"].(float64))
  1705. return_count, _ := items["return_count"].(string)
  1706. if len(return_count) == 0 {
  1707. utils.ErrorLog("len(return_count) == 0")
  1708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1709. return
  1710. }
  1711. count, _ := strconv.ParseInt(return_count, 10, 64)
  1712. number := items["number"].(string)
  1713. register_account := items["register_account"].(string)
  1714. manufacturer, _ := items["manufacturer"].(string)
  1715. dealer, _ := items["dealer"].(string)
  1716. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1717. var expiryDates int64
  1718. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1719. expiryDates = 0
  1720. } else {
  1721. if len(items["expiry_date"].(string)) == 0 {
  1722. expiryDates = 0
  1723. } else {
  1724. expiryDate, _ := items["expiry_date"].(string)
  1725. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1726. expiryDates = expiry_date.Unix()
  1727. }
  1728. }
  1729. var productDates int64
  1730. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1731. productDates = 0
  1732. } else {
  1733. if len(items["product_date"].(string)) == 0 {
  1734. productDates = 0
  1735. } else {
  1736. productDate, _ := items["product_date"].(string)
  1737. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1738. productDates = product_date.Unix()
  1739. }
  1740. }
  1741. remark := items["remark"].(string)
  1742. retail_prices := items["price"].(string)
  1743. price, _ := strconv.ParseFloat(retail_prices, 64)
  1744. cancelStockInfo := &models.CancelStockInfo{
  1745. OrderNumber: cancelStock.OrderNumber,
  1746. CancelStockId: cancelStock.ID,
  1747. GoodId: good_id,
  1748. GoodTypeId: good_type_id,
  1749. Count: count,
  1750. Status: 1,
  1751. Ctime: ctime,
  1752. OrgId: adminUserInfo.CurrentOrgId,
  1753. Type: types,
  1754. Manufacturer: manufacturer,
  1755. Dealer: dealer,
  1756. Number: number,
  1757. ProductDate: productDates,
  1758. ExpiryDate: expiryDates,
  1759. RegisterAccount: register_account,
  1760. Remark: remark,
  1761. Price: price,
  1762. WarehouseInfoId: warehouse_info_id,
  1763. }
  1764. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1765. flow := &models.VmStockFlow{
  1766. WarehousingId: 0,
  1767. GoodId: good_id,
  1768. Number: number,
  1769. LicenseNumber: "",
  1770. Count: count,
  1771. UserOrgId: adminUserInfo.CurrentOrgId,
  1772. PatientId: 0,
  1773. SystemTime: time.Now().Unix(),
  1774. ConsumableType: 4,
  1775. IsSys: 0,
  1776. WarehousingOrder: "",
  1777. WarehouseOutId: 0,
  1778. WarehouseOutOrderNumber: "",
  1779. IsEdit: 0,
  1780. CancelStockId: cancelStock.ID,
  1781. CancelOrderNumber: cancelStock.OrderNumber,
  1782. Manufacturer: 0,
  1783. Dealer: 0,
  1784. Creator: adminUserInfo.AdminUser.Id,
  1785. UpdateCreator: 0,
  1786. Status: 1,
  1787. Ctime: time.Now().Unix(),
  1788. Mtime: 0,
  1789. Price: price,
  1790. WarehousingDetailId: 0,
  1791. WarehouseOutDetailId: 0,
  1792. CancelOutDetailId: 0,
  1793. ProductDate: productDates,
  1794. ExpireDate: expiryDates,
  1795. }
  1796. stockFLow = append(stockFLow, flow)
  1797. }
  1798. }
  1799. }
  1800. for _, item := range cancelStockInfos {
  1801. //统计该批次耗材的出库数量
  1802. //info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId, item.WarehouseInfoId)
  1803. info, _ := service.GetWarehoureOrderStockOutFlow(item.GoodId, item.OrgId, item.WarehouseInfoId)
  1804. fmt.Println("2333223323322332233223322323", item.Count, info.Count)
  1805. if item.Count > info.Count {
  1806. service.UpdateCancelInfo(item.CancelStockId)
  1807. c.ServeSuccessJSON(map[string]interface{}{
  1808. "msg": "2",
  1809. })
  1810. return
  1811. }
  1812. //查询该批次入库的值
  1813. infolist, _ := service.GetWarehouseInfoByIdSeven(item.WarehouseInfoId)
  1814. if item.Count > infolist.WarehousingCount {
  1815. c.ServeSuccessJSON(map[string]interface{}{
  1816. "msg": "4",
  1817. })
  1818. return
  1819. }
  1820. if item.Count <= infolist.WarehousingCount {
  1821. _, msgerrkonde := service.GetCancelStockDetailByOrderNumber(orderNumber, adminUserInfo.CurrentOrgId)
  1822. if msgerrkonde == gorm.ErrRecordNotFound {
  1823. service.AddSigleCancelStock(&cancelStock)
  1824. }
  1825. listcancel, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
  1826. fmt.Println("2332323232323232323", cancelStockInfos)
  1827. item.CancelStockId = listcancel.ID
  1828. errs := service.CreateCancelStockInfoOne(item)
  1829. if len(stockFLow) > 0 {
  1830. service.CreateStockFlow(stockFLow)
  1831. }
  1832. if errs != nil {
  1833. utils.ErrorLog(errs.Error())
  1834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1835. return
  1836. }
  1837. //查询该批次的剩余库存
  1838. wareouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  1839. if (wareouseinfo.StockCount + item.Count) > wareouseinfo.WarehousingCount {
  1840. c.ServeSuccessJSON(map[string]interface{}{
  1841. "msg": "5",
  1842. })
  1843. return
  1844. }
  1845. //更改入库数量
  1846. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  1847. if err != nil {
  1848. utils.ErrorLog(err.Error())
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1850. return
  1851. }
  1852. }
  1853. }
  1854. c.ServeSuccessJSON(map[string]interface{}{
  1855. "msg": "3",
  1856. })
  1857. return
  1858. }
  1859. func (c *StockManagerApiController) GetCancelStockInfoList() {
  1860. id, _ := c.GetInt64("id", 0)
  1861. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  1862. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1863. manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
  1864. dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
  1865. c.ServeSuccessJSON(map[string]interface{}{
  1866. "list": cancelStockInfoList,
  1867. "info": info,
  1868. "manufacturerList": manufacturerList,
  1869. "dealerList": dealerList,
  1870. })
  1871. }
  1872. func (c *StockManagerApiController) GetCancelStockList() {
  1873. page, _ := c.GetInt64("page", -1)
  1874. limit, _ := c.GetInt64("limit", -1)
  1875. start_time := c.GetString("start_time")
  1876. end_time := c.GetString("end_time")
  1877. types, _ := c.GetInt64("type", 0)
  1878. keywords := c.GetString("keywords")
  1879. timeLayout := "2006-01-02"
  1880. loc, _ := time.LoadLocation("Local")
  1881. var startTime int64
  1882. if len(start_time) > 0 {
  1883. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1884. if err != nil {
  1885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1886. return
  1887. }
  1888. startTime = theTime.Unix()
  1889. }
  1890. var endTime int64
  1891. if len(end_time) > 0 {
  1892. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1893. if err != nil {
  1894. utils.ErrorLog(err.Error())
  1895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1896. return
  1897. }
  1898. endTime = theTime.Unix()
  1899. }
  1900. adminUserInfo := c.GetAdminUserInfo()
  1901. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1902. if err == nil {
  1903. c.ServeSuccessJSON(map[string]interface{}{
  1904. "list": returnList,
  1905. "total": total,
  1906. })
  1907. } else {
  1908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1909. }
  1910. }
  1911. func (this *StockManagerApiController) DeleteCancelStock() {
  1912. ids := this.GetString("ids")
  1913. if len(ids) == 0 {
  1914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1915. return
  1916. }
  1917. idArray := strings.Split(ids, ",")
  1918. err := service.DeleteCancelStock(idArray)
  1919. if err != nil {
  1920. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1921. } else {
  1922. this.ServeSuccessJSON(map[string]interface{}{
  1923. "msg": "删除成功",
  1924. })
  1925. }
  1926. }
  1927. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  1928. id, _ := this.GetInt64("id", 0)
  1929. fmt.Println(id)
  1930. if id == 0 {
  1931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1932. return
  1933. }
  1934. err := service.UpDateCancleStockStatus(id)
  1935. if err != nil {
  1936. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1937. } else {
  1938. this.ServeSuccessJSON(map[string]interface{}{
  1939. "msg": "删除成功",
  1940. })
  1941. }
  1942. }
  1943. func (c *StockManagerApiController) EditCancelStock() {
  1944. cancel_time := c.GetString("cancel_time")
  1945. id, _ := c.GetInt64("id", 0)
  1946. if id == 0 {
  1947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1948. return
  1949. }
  1950. ctime := time.Now().Unix()
  1951. mtime := time.Now().Unix()
  1952. adminUserInfo := c.GetAdminUserInfo()
  1953. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1954. if parseDateErr != nil {
  1955. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1957. return
  1958. }
  1959. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1960. tempCancelStock := models.CancelStock{
  1961. ID: cancelStock.ID,
  1962. Mtime: mtime,
  1963. ReturnTime: cancelDate.Unix(),
  1964. }
  1965. service.EditCancelStock(tempCancelStock)
  1966. dataBody := make(map[string]interface{}, 0)
  1967. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1968. if err != nil {
  1969. utils.ErrorLog(err.Error())
  1970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1971. return
  1972. }
  1973. var cancelStockInfos []*models.CancelStockInfo
  1974. var upDateCancelStockInfos []*models.CancelStockInfo
  1975. var stockFlow []*models.VmStockFlow
  1976. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1977. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1978. if len(thisCancelStock) > 0 {
  1979. for _, item := range thisCancelStock {
  1980. items := item.(map[string]interface{})
  1981. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1982. utils.ErrorLog("good_id")
  1983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1984. return
  1985. }
  1986. good_id := int64(items["good_id"].(float64))
  1987. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1988. utils.ErrorLog("good_type_id")
  1989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1990. return
  1991. }
  1992. good_type_id := int64(items["good_type_id"].(float64))
  1993. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1994. utils.ErrorLog("count")
  1995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1996. return
  1997. }
  1998. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1999. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2000. utils.ErrorLog("id")
  2001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2002. return
  2003. }
  2004. id := int64(items["id"].(float64))
  2005. number := items["number"].(string)
  2006. register_account := items["register_account"].(string)
  2007. manufacturer, _ := items["manufacturer"].(string)
  2008. dealer, _ := items["dealer"].(string)
  2009. remark := items["remark"].(string)
  2010. var productDates int64
  2011. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  2012. productDates = 0
  2013. } else {
  2014. if len(items["product_date"].(string)) == 0 {
  2015. productDates = 0
  2016. } else {
  2017. productDate, _ := items["product_date"].(string)
  2018. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  2019. productDates = product_date.Unix()
  2020. }
  2021. }
  2022. var expiryDates int64
  2023. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  2024. expiryDates = 0
  2025. } else {
  2026. if len(items["expiry_date"].(string)) == 0 {
  2027. expiryDates = 0
  2028. } else {
  2029. expiryDate, _ := items["expiry_date"].(string)
  2030. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  2031. expiryDates = expiry_date.Unix()
  2032. }
  2033. }
  2034. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2035. utils.ErrorLog("price")
  2036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2037. return
  2038. }
  2039. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2040. if id == 0 {
  2041. cancelStockInfo := &models.CancelStockInfo{
  2042. GoodId: good_id,
  2043. GoodTypeId: good_type_id,
  2044. Count: count,
  2045. Status: 1,
  2046. Ctime: ctime,
  2047. OrgId: adminUserInfo.CurrentOrgId,
  2048. OrderNumber: cancelStock.OrderNumber,
  2049. CancelStockId: cancelStock.ID,
  2050. Mtime: time.Now().Unix(),
  2051. Number: number,
  2052. RegisterAccount: register_account,
  2053. Manufacturer: manufacturer,
  2054. Dealer: dealer,
  2055. ProductDate: productDates,
  2056. ExpiryDate: expiryDates,
  2057. Remark: remark,
  2058. Price: price,
  2059. }
  2060. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  2061. flow := &models.VmStockFlow{
  2062. WarehousingId: 0,
  2063. GoodId: good_id,
  2064. Number: number,
  2065. LicenseNumber: "",
  2066. Count: count,
  2067. UserOrgId: adminUserInfo.CurrentOrgId,
  2068. PatientId: 0,
  2069. SystemTime: time.Now().Unix(),
  2070. ConsumableType: 4,
  2071. IsSys: 0,
  2072. WarehousingOrder: "",
  2073. WarehouseOutId: 0,
  2074. WarehouseOutOrderNumber: "",
  2075. IsEdit: 2,
  2076. CancelStockId: cancelStock.ID,
  2077. CancelOrderNumber: cancelStock.OrderNumber,
  2078. Manufacturer: 0,
  2079. Dealer: 0,
  2080. Creator: adminUserInfo.AdminUser.Id,
  2081. UpdateCreator: 0,
  2082. Status: 1,
  2083. Ctime: time.Now().Unix(),
  2084. Mtime: 0,
  2085. Price: price,
  2086. WarehousingDetailId: 0,
  2087. WarehouseOutDetailId: 0,
  2088. CancelOutDetailId: 0,
  2089. ProductDate: productDates,
  2090. ExpireDate: expiryDates,
  2091. }
  2092. stockFlow = append(stockFlow, flow)
  2093. } else {
  2094. cancelStockInfo := &models.CancelStockInfo{
  2095. ID: id,
  2096. GoodId: good_id,
  2097. GoodTypeId: good_type_id,
  2098. Count: count,
  2099. Status: 1,
  2100. Ctime: ctime,
  2101. OrgId: adminUserInfo.CurrentOrgId,
  2102. OrderNumber: cancelStock.OrderNumber,
  2103. CancelStockId: cancelStock.ID,
  2104. Mtime: time.Now().Unix(),
  2105. Number: number,
  2106. RegisterAccount: register_account,
  2107. Manufacturer: manufacturer,
  2108. Dealer: dealer,
  2109. ProductDate: productDates,
  2110. ExpiryDate: expiryDates,
  2111. Remark: remark,
  2112. Price: price,
  2113. }
  2114. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  2115. flow := &models.VmStockFlow{
  2116. WarehousingId: 0,
  2117. GoodId: good_id,
  2118. Number: number,
  2119. LicenseNumber: "",
  2120. Count: count,
  2121. UserOrgId: adminUserInfo.CurrentOrgId,
  2122. PatientId: 0,
  2123. SystemTime: time.Now().Unix(),
  2124. ConsumableType: 4,
  2125. IsSys: 0,
  2126. WarehousingOrder: "",
  2127. WarehouseOutId: 0,
  2128. WarehouseOutOrderNumber: "",
  2129. IsEdit: 2,
  2130. CancelStockId: cancelStock.ID,
  2131. CancelOrderNumber: cancelStock.OrderNumber,
  2132. Manufacturer: 0,
  2133. Dealer: 0,
  2134. Creator: adminUserInfo.AdminUser.Id,
  2135. UpdateCreator: 0,
  2136. Status: 1,
  2137. Ctime: time.Now().Unix(),
  2138. Mtime: 0,
  2139. Price: price,
  2140. WarehousingDetailId: 0,
  2141. WarehouseOutDetailId: 0,
  2142. CancelOutDetailId: 0,
  2143. ProductDate: productDates,
  2144. ExpireDate: expiryDates,
  2145. }
  2146. stockFlow = append(stockFlow, flow)
  2147. }
  2148. }
  2149. }
  2150. }
  2151. var errs error
  2152. fmt.Println("出库22322333223", cancelStockInfos)
  2153. fmt.Println("更新23232323232323233", upDateCancelStockInfos)
  2154. if len(cancelStockInfos) > 0 {
  2155. for _, item := range cancelStockInfos {
  2156. //统计该耗材的出库数量
  2157. info, _ := service.GetWarehoureOrderStockOutFlow(item.GoodId, item.OrgId, item.WarehouseInfoId)
  2158. if item.Count > info.Count {
  2159. c.ServeSuccessJSON(map[string]interface{}{
  2160. "msg": "2",
  2161. })
  2162. return
  2163. }
  2164. //查询该批次入库的值
  2165. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2166. if item.Count > infolist.WarehousingCount {
  2167. c.ServeSuccessJSON(map[string]interface{}{
  2168. "msg": "4",
  2169. })
  2170. return
  2171. }
  2172. if item.Count <= infolist.WarehousingCount {
  2173. errs := service.CreateCancelStockInfo(cancelStockInfos)
  2174. if len(stockFlow) > 0 {
  2175. service.CreateStockFlow(stockFlow)
  2176. }
  2177. if errs != nil {
  2178. utils.ErrorLog(errs.Error())
  2179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2180. return
  2181. }
  2182. //更改入库数量
  2183. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  2184. break
  2185. }
  2186. }
  2187. }
  2188. if len(upDateCancelStockInfos) > 0 {
  2189. for _, item := range upDateCancelStockInfos {
  2190. //获取该批次最后一套出库记录
  2191. info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
  2192. fmt.Println("info232332322332233223", info.Count, item.Count)
  2193. //比较出库数量和最后一次出库数据大小
  2194. //退库(加)
  2195. if item.Count < info.Count {
  2196. var total = info.Count - item.Count
  2197. errs = service.UpDateCancelStockInfo(item)
  2198. service.CreateStockFlow(stockFlow)
  2199. warehouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2200. if (warehouseinfo.StockCount + total) > warehouseinfo.StockCount {
  2201. c.ServeSuccessJSON(map[string]interface{}{
  2202. "msg": "5",
  2203. })
  2204. return
  2205. }
  2206. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
  2207. if parseDateErr != nil {
  2208. utils.ErrorLog(errs.Error())
  2209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2210. break
  2211. }
  2212. }
  2213. //(减)
  2214. if item.Count > info.Count {
  2215. errs = service.UpDateCancelStockInfo(item)
  2216. service.CreateStockFlow(stockFlow)
  2217. //查询该批次入库的值
  2218. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2219. if item.Count > infolist.WarehousingCount {
  2220. c.ServeSuccessJSON(map[string]interface{}{
  2221. "msg": "4",
  2222. })
  2223. return
  2224. }
  2225. if item.Count <= infolist.WarehousingCount {
  2226. var total_count = info.Count - item.Count
  2227. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total_count)
  2228. if parseDateErr != nil {
  2229. utils.ErrorLog(errs.Error())
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2231. return
  2232. }
  2233. }
  2234. }
  2235. }
  2236. if errs != nil {
  2237. utils.ErrorLog(errs.Error())
  2238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2239. return
  2240. }
  2241. c.ServeSuccessJSON(map[string]interface{}{
  2242. "msg": "3",
  2243. })
  2244. }
  2245. if errs != nil {
  2246. utils.ErrorLog(errs.Error())
  2247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2248. return
  2249. }
  2250. c.ServeSuccessJSON(map[string]interface{}{
  2251. "msg": "3",
  2252. })
  2253. }
  2254. func (this *StockManagerApiController) GetCancelStockConfig() {
  2255. types, _ := this.GetInt64("type", 0)
  2256. adminUserInfo := this.GetAdminUserInfo()
  2257. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  2258. this.ServeSuccessJSON(map[string]interface{}{
  2259. "warehouseOutInfoList": warehouseOutInfoList,
  2260. })
  2261. }
  2262. func (c *StockManagerApiController) GetQueryInfo() {
  2263. page, _ := c.GetInt64("page", -1)
  2264. limit, _ := c.GetInt64("limit", -1)
  2265. keyword := c.GetString("keyword")
  2266. start_time := c.GetString("start_time")
  2267. end_time := c.GetString("end_time")
  2268. type_name, _ := c.GetInt64("type_name")
  2269. timeLayout := "2006-01-02"
  2270. loc, _ := time.LoadLocation("Local")
  2271. var startTime int64
  2272. if len(start_time) > 0 {
  2273. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2274. if err != nil {
  2275. fmt.Println(err)
  2276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2277. return
  2278. }
  2279. startTime = theTime.Unix()
  2280. }
  2281. var endTime int64
  2282. if len(end_time) > 0 {
  2283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2284. if err != nil {
  2285. utils.ErrorLog(err.Error())
  2286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2287. return
  2288. }
  2289. endTime = theTime.Unix()
  2290. }
  2291. adminUserInfo := c.GetAdminUserInfo()
  2292. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  2293. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  2294. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
  2295. if err == nil {
  2296. c.ServeSuccessJSON(map[string]interface{}{
  2297. "list": list,
  2298. "total": total,
  2299. "info": info,
  2300. "infomationList": infomationList,
  2301. "orgid": adminUserInfo.CurrentOrgId,
  2302. })
  2303. } else {
  2304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2305. }
  2306. }
  2307. func (c *StockManagerApiController) SearchWarehouse() {
  2308. keywords := c.GetString("keywords")
  2309. adminUserInfo := c.GetAdminUserInfo()
  2310. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  2311. if err == nil {
  2312. c.ServeSuccessJSON(map[string]interface{}{
  2313. "list": warehouseList,
  2314. "total": total,
  2315. })
  2316. } else {
  2317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2318. }
  2319. }
  2320. func (c *StockManagerApiController) GetAllConfig() {
  2321. adminUserInfo := c.GetAdminUserInfo()
  2322. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  2323. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  2324. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  2325. goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  2326. c.ServeSuccessJSON(map[string]interface{}{
  2327. "manufacturer": manufacturer,
  2328. "dealer": dealer,
  2329. "goodType": goodType,
  2330. "goodInfo": goodInfo,
  2331. })
  2332. }
  2333. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  2334. types, _ := this.GetInt64("type", 0)
  2335. adminUserInfo := this.GetAdminUserInfo()
  2336. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  2337. this.ServeSuccessJSON(map[string]interface{}{
  2338. "warehouseInfoList": warehouseInfoList,
  2339. })
  2340. }
  2341. func (this *StockManagerApiController) GetDetailInfo() {
  2342. page, _ := this.GetInt64("page", 0)
  2343. limit, _ := this.GetInt64("limit", 0)
  2344. start_time := this.GetString("start_time")
  2345. end_time := this.GetString("end_time")
  2346. types, _ := this.GetInt64("type", 0)
  2347. keywords := this.GetString("keywords")
  2348. manufacturer, _ := this.GetInt64("manufacturer", 0)
  2349. order_type, _ := this.GetInt64("order_type", 0)
  2350. dealer, _ := this.GetInt64("dealer", 0)
  2351. timeLayout := "2006-01-02"
  2352. loc, _ := time.LoadLocation("Local")
  2353. var startTime int64
  2354. if len(start_time) > 0 {
  2355. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2356. if err != nil {
  2357. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2358. return
  2359. }
  2360. startTime = theTime.Unix()
  2361. }
  2362. var endTime int64
  2363. if len(end_time) > 0 {
  2364. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2365. if err != nil {
  2366. utils.ErrorLog(err.Error())
  2367. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2368. return
  2369. }
  2370. endTime = theTime.Unix()
  2371. }
  2372. adminUserInfo := this.GetAdminUserInfo()
  2373. var list []*models.WarehousingInfo
  2374. var list1 []*models.WarehouseOutInfo
  2375. var list2 []*models.SalesReturnInfo
  2376. var list3 []*models.CancelStockInfo
  2377. var total int64
  2378. var err error
  2379. var total_price float64
  2380. if types == 1 {
  2381. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2382. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2383. if err == nil {
  2384. this.ServeSuccessJSON(map[string]interface{}{
  2385. "list": list,
  2386. "total": total,
  2387. "total_price": total_price,
  2388. })
  2389. } else {
  2390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2391. }
  2392. } else if types == 2 {
  2393. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2394. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2395. if err == nil {
  2396. this.ServeSuccessJSON(map[string]interface{}{
  2397. "list": list1,
  2398. "total": total,
  2399. "total_price": total_price,
  2400. })
  2401. } else {
  2402. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2403. }
  2404. } else if types == 3 {
  2405. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2406. if err == nil {
  2407. this.ServeSuccessJSON(map[string]interface{}{
  2408. "list": list2,
  2409. "total": total,
  2410. })
  2411. } else {
  2412. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2413. }
  2414. } else if types == 4 {
  2415. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2416. listGroup, err := service.FindeCancelGroup(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2417. if err == nil {
  2418. this.ServeSuccessJSON(map[string]interface{}{
  2419. "list": list3,
  2420. "total": total,
  2421. "listgroup": listGroup,
  2422. })
  2423. } else {
  2424. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2425. }
  2426. }
  2427. }
  2428. func (this *StockManagerApiController) GetUserDetailInfo() {
  2429. order_id, _ := this.GetInt64("id")
  2430. if order_id <= 0 {
  2431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2432. return
  2433. }
  2434. adminUserInfo := this.GetAdminUserInfo()
  2435. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2436. if err == nil {
  2437. this.ServeSuccessJSON(map[string]interface{}{
  2438. "list": userDetails,
  2439. "total": total,
  2440. })
  2441. } else {
  2442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2443. return
  2444. }
  2445. }
  2446. func (this *StockManagerApiController) PostSearchStock() {
  2447. keyword := this.GetString("keyword")
  2448. adminUserInfo := this.GetAdminUserInfo()
  2449. orgId := adminUserInfo.CurrentOrgId
  2450. stock, err := service.PostSearchStock(keyword, orgId)
  2451. if err != nil {
  2452. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2453. }
  2454. this.ServeSuccessJSON(map[string]interface{}{
  2455. "stock": stock,
  2456. })
  2457. }
  2458. func (this *StockManagerApiController) GetOutStockTotalCount() {
  2459. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  2460. adminUserInfo := this.GetAdminUserInfo()
  2461. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  2462. if err != nil {
  2463. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2464. }
  2465. this.ServeSuccessJSON(map[string]interface{}{
  2466. "stockCount": stockCount,
  2467. })
  2468. }
  2469. func (this *StockManagerApiController) AddGoodInformation() {
  2470. adminUserInfo := this.GetAdminUserInfo()
  2471. orgId := adminUserInfo.CurrentOrgId
  2472. dataBody := make(map[string]interface{}, 0)
  2473. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2474. if err != nil {
  2475. utils.ErrorLog(err.Error())
  2476. return
  2477. }
  2478. utils.ErrorLog("%v", dataBody)
  2479. var goods []*models.GoodInfo
  2480. var total_goods []interface{}
  2481. tempGoods := dataBody["goods"].([]interface{})
  2482. total_goods = tempGoods
  2483. for index, goodMap := range tempGoods {
  2484. goodNameM := goodMap.(map[string]interface{})
  2485. var good models.GoodInfo
  2486. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  2487. utils.ErrorLog("good_name")
  2488. return
  2489. }
  2490. good_name, _ := goodNameM["good_name"].(string)
  2491. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  2492. err_log := models.ExportErrLog{
  2493. LogType: 5,
  2494. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2495. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  2496. Status: 1,
  2497. CreateTime: time.Now().Unix(),
  2498. UpdateTime: time.Now().Unix(),
  2499. ExportTime: time.Now().Unix(),
  2500. }
  2501. service.CreateExportErrLog(&err_log)
  2502. continue
  2503. }
  2504. good.GoodName = good_name
  2505. // 获取数据字典数据
  2506. var good_kind_id int64
  2507. var name = "耗材种类"
  2508. config, _ := service.GetDrugDataConfig(0, name)
  2509. good_kind := goodNameM["good_kind"].(string)
  2510. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  2511. err_log := models.ExportErrLog{
  2512. LogType: 5,
  2513. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2514. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  2515. Status: 1,
  2516. CreateTime: time.Now().Unix(),
  2517. UpdateTime: time.Now().Unix(),
  2518. ExportTime: time.Now().Unix(),
  2519. }
  2520. service.CreateExportErrLog(&err_log)
  2521. continue
  2522. }
  2523. if len(good_kind) != 0 {
  2524. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  2525. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  2526. dataconfig := models.DictDataconfig{
  2527. ParentId: config.ID,
  2528. Module: "system",
  2529. OrgId: orgId,
  2530. Name: good_kind,
  2531. FieldName: "",
  2532. Value: lastConfig.Value + 1,
  2533. CreatedTime: "",
  2534. UpdatedTime: "",
  2535. CreateUserId: adminUserInfo.AdminUser.Id,
  2536. Status: 1,
  2537. Remark: "",
  2538. DeleteIdSystem: 0,
  2539. Title: "",
  2540. Content: "",
  2541. Order: 0,
  2542. Code: "",
  2543. }
  2544. if errcodegoodkind == gorm.ErrRecordNotFound {
  2545. service.CreatedDicConfig(&dataconfig)
  2546. }
  2547. }
  2548. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  2549. for _, it := range dataConfig {
  2550. if good_kind == it.Name {
  2551. fmt.Println(it.Name)
  2552. good_kind_id = int64(it.Value)
  2553. }
  2554. }
  2555. good.GoodKind = good_kind_id
  2556. good_type := goodNameM["type_name"].(string)
  2557. if len(good_type) == 0 {
  2558. err_log := models.ExportErrLog{
  2559. LogType: 5,
  2560. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2561. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  2562. Status: 1,
  2563. CreateTime: time.Now().Unix(),
  2564. UpdateTime: time.Now().Unix(),
  2565. ExportTime: time.Now().Unix(),
  2566. }
  2567. service.CreateExportErrLog(&err_log)
  2568. continue
  2569. }
  2570. if len(good_type) != 0 {
  2571. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  2572. if errcodegoodtype == gorm.ErrRecordNotFound {
  2573. goodsType := models.GoodsType{
  2574. TypeName: good_type,
  2575. Remark: "",
  2576. Ctime: time.Now().Unix(),
  2577. Mtime: 0,
  2578. Creater: adminUserInfo.AdminUser.Id,
  2579. Modifier: 0,
  2580. OrgId: adminUserInfo.CurrentOrgId,
  2581. Status: 1,
  2582. Type: 0,
  2583. Number: 0,
  2584. OutStock: 0,
  2585. StockAttribute: 1,
  2586. }
  2587. service.CreatedGoodType(&goodsType)
  2588. }
  2589. }
  2590. goodType, _ := service.GetAllGoodType(orgId)
  2591. var good_type_id int64
  2592. for _, it := range goodType {
  2593. if good_type == it.TypeName {
  2594. good_type_id = it.ID
  2595. }
  2596. }
  2597. good.GoodTypeId = good_type_id
  2598. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  2599. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  2600. err_log := models.ExportErrLog{
  2601. LogType: 5,
  2602. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2603. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  2604. Status: 1,
  2605. CreateTime: time.Now().Unix(),
  2606. UpdateTime: time.Now().Unix(),
  2607. ExportTime: time.Now().Unix(),
  2608. }
  2609. service.CreateExportErrLog(&err_log)
  2610. continue
  2611. }
  2612. var medical_insurance_id int64
  2613. var medicalInsurance = "医保等级"
  2614. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  2615. if len(medical_insurance_level) != 0 {
  2616. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  2617. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  2618. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  2619. dataconfig := models.DictDataconfig{
  2620. ParentId: medicalInsuranceDataConfig.ID,
  2621. Module: "system",
  2622. OrgId: orgId,
  2623. Name: medical_insurance_level,
  2624. FieldName: "",
  2625. Value: mediConfigOne.Value + 1,
  2626. CreatedTime: "",
  2627. UpdatedTime: "",
  2628. CreateUserId: adminUserInfo.AdminUser.Id,
  2629. Status: 1,
  2630. Remark: "",
  2631. DeleteIdSystem: 0,
  2632. Title: "",
  2633. Content: "",
  2634. Order: 0,
  2635. Code: "",
  2636. }
  2637. service.CreatedDicConfig(&dataconfig)
  2638. }
  2639. }
  2640. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  2641. for _, it := range medicalInsuranceList {
  2642. if medical_insurance_level == it.Name {
  2643. medical_insurance_id = int64(it.Value)
  2644. }
  2645. }
  2646. good.MedicalInsuranceLevel = medical_insurance_id
  2647. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  2648. utils.ErrorLog("specification_name")
  2649. return
  2650. }
  2651. specification_name := goodNameM["specification_name"].(string)
  2652. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  2653. err_log := models.ExportErrLog{
  2654. LogType: 5,
  2655. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2656. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  2657. Status: 1,
  2658. CreateTime: time.Now().Unix(),
  2659. UpdateTime: time.Now().Unix(),
  2660. ExportTime: time.Now().Unix(),
  2661. }
  2662. service.CreateExportErrLog(&err_log)
  2663. continue
  2664. }
  2665. good.SpecificationName = specification_name
  2666. var manufacturer_id int64
  2667. manufacturer := goodNameM["manufacturer"].(string)
  2668. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  2669. err_log := models.ExportErrLog{
  2670. LogType: 5,
  2671. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2672. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  2673. Status: 1,
  2674. CreateTime: time.Now().Unix(),
  2675. UpdateTime: time.Now().Unix(),
  2676. ExportTime: time.Now().Unix(),
  2677. }
  2678. service.CreateExportErrLog(&err_log)
  2679. continue
  2680. }
  2681. if len(manufacturer) != 0 {
  2682. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  2683. manu := models.Manufacturer{
  2684. ManufacturerName: manufacturer,
  2685. Status: 1,
  2686. OrgId: orgId,
  2687. Creater: adminUserInfo.AdminUser.Id,
  2688. }
  2689. if errcodes == gorm.ErrRecordNotFound {
  2690. service.CreateManufacturer(&manu)
  2691. }
  2692. }
  2693. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2694. for _, it := range manufacturerList {
  2695. if manufacturer == it.ManufacturerName {
  2696. manufacturer_id = it.ID
  2697. }
  2698. }
  2699. good.Manufacturer = manufacturer_id
  2700. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  2701. utils.ErrorLog("unit_id")
  2702. return
  2703. }
  2704. unit_id := int64(goodNameM["unit_id"].(float64))
  2705. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  2706. err_log := models.ExportErrLog{
  2707. LogType: 5,
  2708. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2709. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  2710. Status: 1,
  2711. CreateTime: time.Now().Unix(),
  2712. UpdateTime: time.Now().Unix(),
  2713. ExportTime: time.Now().Unix(),
  2714. }
  2715. service.CreateExportErrLog(&err_log)
  2716. continue
  2717. }
  2718. good.GoodUnit = unit_id
  2719. retail_prices := goodNameM["retail_price"].(string)
  2720. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2721. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  2722. err_log := models.ExportErrLog{
  2723. LogType: 5,
  2724. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2725. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
  2726. Status: 1,
  2727. CreateTime: time.Now().Unix(),
  2728. UpdateTime: time.Now().Unix(),
  2729. ExportTime: time.Now().Unix(),
  2730. }
  2731. service.CreateExportErrLog(&err_log)
  2732. continue
  2733. }
  2734. good.RetailPrice = retail_price
  2735. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  2736. utils.ErrorLog("stock_warn_count")
  2737. return
  2738. }
  2739. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  2740. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  2741. err_log := models.ExportErrLog{
  2742. LogType: 5,
  2743. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2744. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  2745. Status: 1,
  2746. CreateTime: time.Now().Unix(),
  2747. UpdateTime: time.Now().Unix(),
  2748. ExportTime: time.Now().Unix(),
  2749. }
  2750. service.CreateExportErrLog(&err_log)
  2751. continue
  2752. }
  2753. good.StockWarnCount = stock_warn_count
  2754. var dealer_id int64
  2755. dealerName := goodNameM["dealer"].(string)
  2756. fmt.Println("经销商", dealerName)
  2757. dealer := models.Dealer{
  2758. OrgId: orgId,
  2759. Status: 1,
  2760. DealerName: dealerName,
  2761. Creater: adminUserInfo.AdminUser.Id,
  2762. Ctime: time.Now().Unix(),
  2763. }
  2764. if len(dealerName) != 0 {
  2765. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  2766. if errcodedealer == gorm.ErrRecordNotFound {
  2767. service.CreateDealer(&dealer)
  2768. }
  2769. }
  2770. dealerList, _ := service.GetAllDealerList(orgId)
  2771. for _, it := range dealerList {
  2772. if dealerName == it.DealerName {
  2773. dealer_id = it.ID
  2774. }
  2775. }
  2776. good.Dealer = dealer_id
  2777. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  2778. utils.ErrorLog("pinyin")
  2779. return
  2780. }
  2781. pinyin := goodNameM["pinyin"].(string)
  2782. good.Pinyin = pinyin
  2783. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  2784. utils.ErrorLog("wubi")
  2785. return
  2786. }
  2787. wubi := goodNameM["wubi"].(string)
  2788. good.Wubi = wubi
  2789. buy_prices := goodNameM["buy_price"].(string)
  2790. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  2791. good.BuyPrice = buy_price
  2792. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  2793. utils.ErrorLog("social_security_directory_code")
  2794. return
  2795. }
  2796. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2797. good.SocialSecurityDirectoryCode = social_security_directory_code
  2798. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  2799. utils.ErrorLog("is_special_diseases")
  2800. return
  2801. }
  2802. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2803. good.IsSpecialDiseases = is_special_diseases
  2804. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  2805. utils.ErrorLog("is_record")
  2806. return
  2807. }
  2808. is_record := int64(goodNameM["is_record"].(float64))
  2809. good.IsRecord = is_record
  2810. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  2811. utils.ErrorLog("good_status")
  2812. return
  2813. }
  2814. good_status := goodNameM["good_status"].(string)
  2815. good.GoodStatus = good_status
  2816. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  2817. utils.ErrorLog("medical_insurance_number")
  2818. return
  2819. }
  2820. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2821. good.MedicalInsuranceNumber = medical_insurance_number
  2822. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  2823. utils.ErrorLog("production_type")
  2824. return
  2825. }
  2826. production_type := goodNameM["production_type"].(string)
  2827. good.ProductionType = production_type
  2828. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  2829. utils.ErrorLog("remark")
  2830. return
  2831. }
  2832. remark := goodNameM["remark"].(string)
  2833. good.Remark = remark
  2834. statistics_category := goodNameM["statistics_category"].(string)
  2835. var categoryName = "统计分类"
  2836. var statistic_id int64
  2837. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  2838. if len(statistics_category) != 0 {
  2839. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  2840. if errcodecagegory == gorm.ErrRecordNotFound {
  2841. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  2842. dataconfig := models.DictDataconfig{
  2843. ParentId: drugDataConfig.ID,
  2844. Module: "system",
  2845. OrgId: orgId,
  2846. Name: statistics_category,
  2847. FieldName: "",
  2848. Value: dicConfigThree.Value + 1,
  2849. CreatedTime: "",
  2850. UpdatedTime: "",
  2851. CreateUserId: adminUserInfo.AdminUser.Id,
  2852. Status: 1,
  2853. Remark: "",
  2854. DeleteIdSystem: 0,
  2855. Title: "",
  2856. Content: "",
  2857. Order: 0,
  2858. Code: "",
  2859. }
  2860. service.CreatedDicConfig(&dataconfig)
  2861. }
  2862. }
  2863. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  2864. for _, it := range parentDataConfig {
  2865. if statistics_category == it.Name {
  2866. statistic_id = int64(it.Value)
  2867. }
  2868. }
  2869. good.StatisticsCategory = statistic_id
  2870. special_medical := goodNameM["special_medical"].(string)
  2871. good.SpecialMedical = special_medical
  2872. goods = append(goods, &good)
  2873. }
  2874. export_time := time.Now().Unix()
  2875. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2876. if len(goods) > 0 {
  2877. for _, item := range goods {
  2878. goodInfo := models.GoodInfo{
  2879. GoodName: item.GoodName,
  2880. SpecificationName: item.SpecificationName,
  2881. GoodKind: item.GoodKind,
  2882. GoodTypeId: item.GoodTypeId,
  2883. Dealer: item.Dealer,
  2884. GoodUnit: item.GoodUnit,
  2885. IsRecord: item.IsRecord,
  2886. IsSpecialDiseases: item.IsSpecialDiseases,
  2887. Manufacturer: item.Manufacturer,
  2888. Pinyin: item.Pinyin,
  2889. GoodStatus: item.GoodStatus,
  2890. ProductionType: item.ProductionType,
  2891. Remark: item.Remark,
  2892. RetailPrice: item.RetailPrice,
  2893. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  2894. SpecialMedical: item.SpecialMedical,
  2895. Wubi: item.Wubi,
  2896. StockWarnCount: item.StockWarnCount,
  2897. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  2898. OrgId: orgId,
  2899. Status: 1,
  2900. Ctime: time.Now().Unix(),
  2901. StatisticsCategory: item.StatisticsCategory,
  2902. GoodCode: item.GoodCode,
  2903. BuyPrice: item.BuyPrice,
  2904. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  2905. }
  2906. //查询同种耗材名称同种类型同种规格的耗材是否存在
  2907. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2908. if errcodegood == gorm.ErrRecordNotFound {
  2909. service.CreateGoodsInfomation(&goodInfo)
  2910. } else if errcodegood == nil {
  2911. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2912. }
  2913. log := models.ExportLog{
  2914. LogType: 5,
  2915. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2916. TotalNum: int64(len(total_goods)),
  2917. FailNum: int64(len(errLogs)),
  2918. SuccessNum: int64(len(goods)),
  2919. CreateTime: time.Now().Unix(),
  2920. UpdateTime: time.Now().Unix(),
  2921. ExportTime: export_time,
  2922. Status: 1,
  2923. }
  2924. service.CreateExportLog(&log)
  2925. this.ServeSuccessJSON(map[string]interface{}{
  2926. "msg": "导入成功",
  2927. "total_num": len(total_goods),
  2928. "success_num": len(goods),
  2929. "fail_num": int64(len(errLogs)),
  2930. })
  2931. }
  2932. } else {
  2933. log := models.ExportLog{
  2934. LogType: 5,
  2935. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2936. TotalNum: int64(len(total_goods)),
  2937. FailNum: int64(len(errLogs)),
  2938. SuccessNum: int64(len(goods)),
  2939. CreateTime: time.Now().Unix(),
  2940. UpdateTime: time.Now().Unix(),
  2941. ExportTime: export_time,
  2942. Status: 1,
  2943. }
  2944. service.CreateExportLog(&log)
  2945. this.ServeSuccessJSON(map[string]interface{}{
  2946. "msg": "导入成功",
  2947. "total_num": len(total_goods),
  2948. "success_num": len(goods),
  2949. "fail_num": int64(len(errLogs)),
  2950. })
  2951. }
  2952. }
  2953. func (this *StockManagerApiController) AddDrugInformation() {
  2954. adminUser := this.GetAdminUserInfo()
  2955. orgId := adminUser.CurrentOrgId
  2956. dataBody := make(map[string]interface{}, 0)
  2957. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2958. if err != nil {
  2959. utils.ErrorLog(err.Error())
  2960. return
  2961. }
  2962. utils.ErrorLog("%v", dataBody)
  2963. var drugList []*models.BaseDrugLib
  2964. var total_goods []interface{}
  2965. tempDrugs := dataBody["drugs"].([]interface{})
  2966. total_goods = tempDrugs
  2967. for index, drugMap := range tempDrugs {
  2968. goodNameM := drugMap.(map[string]interface{})
  2969. var drug models.BaseDrugLib
  2970. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  2971. utils.ErrorLog("drug_name")
  2972. return
  2973. }
  2974. drug_name, _ := goodNameM["drug_name"].(string)
  2975. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2976. err_log := models.ExportErrLog{
  2977. LogType: 4,
  2978. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2979. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  2980. Status: 1,
  2981. CreateTime: time.Now().Unix(),
  2982. UpdateTime: time.Now().Unix(),
  2983. ExportTime: time.Now().Unix(),
  2984. }
  2985. service.CreateExportErrLog(&err_log)
  2986. continue
  2987. }
  2988. drug.DrugName = drug_name
  2989. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  2990. utils.ErrorLog("min_number")
  2991. return
  2992. }
  2993. min_number, _ := goodNameM["min_number"].(string)
  2994. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  2995. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2996. err_log := models.ExportErrLog{
  2997. LogType: 4,
  2998. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2999. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  3000. Status: 1,
  3001. CreateTime: time.Now().Unix(),
  3002. UpdateTime: time.Now().Unix(),
  3003. ExportTime: time.Now().Unix(),
  3004. }
  3005. service.CreateExportErrLog(&err_log)
  3006. continue
  3007. }
  3008. drug.MinNumber = minNumber
  3009. min_unit := goodNameM["min_unit"].(string)
  3010. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  3011. err_log := models.ExportErrLog{
  3012. LogType: 4,
  3013. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3014. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  3015. Status: 1,
  3016. CreateTime: time.Now().Unix(),
  3017. UpdateTime: time.Now().Unix(),
  3018. ExportTime: time.Now().Unix(),
  3019. }
  3020. service.CreateExportErrLog(&err_log)
  3021. continue
  3022. }
  3023. drug.MinUnit = min_unit
  3024. dose := goodNameM["dose"].(float64)
  3025. if dose < 0 { //名字为空则生成一条导入错误日志
  3026. err_log := models.ExportErrLog{
  3027. LogType: 4,
  3028. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3029. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  3030. Status: 1,
  3031. CreateTime: time.Now().Unix(),
  3032. UpdateTime: time.Now().Unix(),
  3033. ExportTime: time.Now().Unix(),
  3034. }
  3035. service.CreateExportErrLog(&err_log)
  3036. continue
  3037. }
  3038. drug.Dose = dose
  3039. max_unit_id := goodNameM["max_unit"].(string)
  3040. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3041. err_log := models.ExportErrLog{
  3042. LogType: 4,
  3043. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3044. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  3045. Status: 1,
  3046. CreateTime: time.Now().Unix(),
  3047. UpdateTime: time.Now().Unix(),
  3048. ExportTime: time.Now().Unix(),
  3049. }
  3050. service.CreateExportErrLog(&err_log)
  3051. continue
  3052. }
  3053. drug.MaxUnit = max_unit_id
  3054. max_unit := goodNameM["max_unit"].(string)
  3055. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  3056. err_log := models.ExportErrLog{
  3057. LogType: 4,
  3058. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3059. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  3060. Status: 1,
  3061. CreateTime: time.Now().Unix(),
  3062. UpdateTime: time.Now().Unix(),
  3063. ExportTime: time.Now().Unix(),
  3064. }
  3065. service.CreateExportErrLog(&err_log)
  3066. continue
  3067. }
  3068. drug.MaxUnit = max_unit
  3069. delivery_way := goodNameM["delivery_way"].(string)
  3070. if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
  3071. err_log := models.ExportErrLog{
  3072. LogType: 4,
  3073. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3074. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  3075. Status: 1,
  3076. CreateTime: time.Now().Unix(),
  3077. UpdateTime: time.Now().Unix(),
  3078. ExportTime: time.Now().Unix(),
  3079. }
  3080. service.CreateExportErrLog(&err_log)
  3081. continue
  3082. }
  3083. drug.DeliveryWay = delivery_way
  3084. execution_frequency := goodNameM["execution_frequency"].(string)
  3085. if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
  3086. err_log := models.ExportErrLog{
  3087. LogType: 4,
  3088. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3089. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  3090. Status: 1,
  3091. CreateTime: time.Now().Unix(),
  3092. UpdateTime: time.Now().Unix(),
  3093. ExportTime: time.Now().Unix(),
  3094. }
  3095. service.CreateExportErrLog(&err_log)
  3096. continue
  3097. }
  3098. drug.ExecutionFrequency = execution_frequency
  3099. drug_day := goodNameM["drug_day"].(string)
  3100. if len(drug_day) == 0 { //名字为空则生成一条导入错误日志
  3101. err_log := models.ExportErrLog{
  3102. LogType: 4,
  3103. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3104. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  3105. Status: 1,
  3106. CreateTime: time.Now().Unix(),
  3107. UpdateTime: time.Now().Unix(),
  3108. ExportTime: time.Now().Unix(),
  3109. }
  3110. service.CreateExportErrLog(&err_log)
  3111. continue
  3112. }
  3113. drug.DrugDay = drug_day
  3114. drug_type := goodNameM["drug_type"].(string)
  3115. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  3116. err_log := models.ExportErrLog{
  3117. LogType: 4,
  3118. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3119. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  3120. Status: 1,
  3121. CreateTime: time.Now().Unix(),
  3122. UpdateTime: time.Now().Unix(),
  3123. ExportTime: time.Now().Unix(),
  3124. }
  3125. service.CreateExportErrLog(&err_log)
  3126. continue
  3127. }
  3128. var drug_type_id int64
  3129. var drugType = "药品类型"
  3130. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  3131. if len(drug_type) != 0 {
  3132. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  3133. if errcodes == gorm.ErrRecordNotFound {
  3134. //获取该型号最后一条数据型号
  3135. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  3136. dataconfig := models.DictDataconfig{
  3137. ParentId: drugconfig.ID,
  3138. Module: "system",
  3139. OrgId: orgId,
  3140. Name: drug_type,
  3141. FieldName: "",
  3142. Value: config.Value + 1,
  3143. CreatedTime: "",
  3144. UpdatedTime: "",
  3145. CreateUserId: adminUser.AdminUser.Id,
  3146. Status: 1,
  3147. Remark: "",
  3148. DeleteIdSystem: 0,
  3149. Title: "",
  3150. Content: "",
  3151. Order: 0,
  3152. Code: "",
  3153. }
  3154. service.CreatedDicConfig(&dataconfig)
  3155. }
  3156. }
  3157. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  3158. for _, it := range drugTypeList {
  3159. if drug_type == it.Name {
  3160. drug_type_id = int64(it.Value)
  3161. }
  3162. }
  3163. drug.DrugType = drug_type_id
  3164. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  3165. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  3166. err_log := models.ExportErrLog{
  3167. LogType: 4,
  3168. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3169. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  3170. Status: 1,
  3171. CreateTime: time.Now().Unix(),
  3172. UpdateTime: time.Now().Unix(),
  3173. ExportTime: time.Now().Unix(),
  3174. }
  3175. service.CreateExportErrLog(&err_log)
  3176. continue
  3177. }
  3178. drug.DrugStockLimit = drug_stock_limit
  3179. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  3180. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  3181. err_log := models.ExportErrLog{
  3182. LogType: 4,
  3183. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3184. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  3185. Status: 1,
  3186. CreateTime: time.Now().Unix(),
  3187. UpdateTime: time.Now().Unix(),
  3188. ExportTime: time.Now().Unix(),
  3189. }
  3190. service.CreateExportErrLog(&err_log)
  3191. continue
  3192. }
  3193. drug.DrugOriginPlace = drug_origin_place
  3194. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  3195. if len(drug_dosage_form) == 0 {
  3196. err_log := models.ExportErrLog{
  3197. LogType: 4,
  3198. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3199. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  3200. Status: 1,
  3201. CreateTime: time.Now().Unix(),
  3202. UpdateTime: time.Now().Unix(),
  3203. ExportTime: time.Now().Unix(),
  3204. }
  3205. service.CreateExportErrLog(&err_log)
  3206. continue
  3207. }
  3208. var drug_dosage = "药品剂型"
  3209. var drug_dosage_form_id int64
  3210. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  3211. if len(drug_dosage_form) != 0 {
  3212. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  3213. if errcodess == gorm.ErrRecordNotFound {
  3214. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  3215. dataconfig := models.DictDataconfig{
  3216. ParentId: drugDosageconfig.ID,
  3217. Module: "system",
  3218. OrgId: orgId,
  3219. Name: drug_dosage_form,
  3220. FieldName: "",
  3221. Value: configOne.Value + 1,
  3222. CreatedTime: "",
  3223. UpdatedTime: "",
  3224. CreateUserId: adminUser.AdminUser.Id,
  3225. Status: 1,
  3226. Remark: "",
  3227. DeleteIdSystem: 0,
  3228. Title: "",
  3229. Content: "",
  3230. Order: 0,
  3231. Code: "",
  3232. }
  3233. service.CreatedDicConfig(&dataconfig)
  3234. }
  3235. }
  3236. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  3237. for _, it := range drugDosageList {
  3238. if drug_dosage_form == it.Name {
  3239. drug_dosage_form_id = int64(it.Value)
  3240. }
  3241. }
  3242. drug.DrugDosageForm = drug_dosage_form_id
  3243. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  3244. var medical_insurance_level_id int64
  3245. if len(medical_insurance_level) == 0 { //名字为空则生成一条导入错误日志
  3246. err_log := models.ExportErrLog{
  3247. LogType: 4,
  3248. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3249. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  3250. Status: 1,
  3251. CreateTime: time.Now().Unix(),
  3252. UpdateTime: time.Now().Unix(),
  3253. ExportTime: time.Now().Unix(),
  3254. }
  3255. service.CreateExportErrLog(&err_log)
  3256. continue
  3257. }
  3258. var medicalInsuranceName = "医保等级"
  3259. medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
  3260. if len(medical_insurance_level) != 0 {
  3261. _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
  3262. if errcodemedical == gorm.ErrRecordNotFound {
  3263. medConfig, _ := service.GetLastDicConfig(medicalInsuranceConfig.ID, orgId)
  3264. dataconfig := models.DictDataconfig{
  3265. ParentId: medicalInsuranceConfig.ID,
  3266. Module: "system",
  3267. OrgId: orgId,
  3268. Name: medical_insurance_level,
  3269. FieldName: "",
  3270. Value: medConfig.Value + 1,
  3271. CreatedTime: "",
  3272. UpdatedTime: "",
  3273. CreateUserId: adminUser.AdminUser.Id,
  3274. Status: 1,
  3275. Remark: "",
  3276. DeleteIdSystem: 0,
  3277. Title: "",
  3278. Content: "",
  3279. Order: 0,
  3280. Code: "",
  3281. }
  3282. service.CreatedDicConfig(&dataconfig)
  3283. }
  3284. }
  3285. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
  3286. for _, it := range medicalInsuranceList {
  3287. if medical_insurance_level == it.Name {
  3288. medical_insurance_level_id = int64(it.Value)
  3289. }
  3290. }
  3291. drug.MedicalInsuranceLevel = medical_insurance_level_id
  3292. unit_matrixing := goodNameM["unit_matrixing"].(string)
  3293. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3294. err_log := models.ExportErrLog{
  3295. LogType: 4,
  3296. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3297. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
  3298. Status: 1,
  3299. CreateTime: time.Now().Unix(),
  3300. UpdateTime: time.Now().Unix(),
  3301. ExportTime: time.Now().Unix(),
  3302. }
  3303. service.CreateExportErrLog(&err_log)
  3304. continue
  3305. }
  3306. drug.UnitMatrixing = unit_matrixing
  3307. retail_prices := goodNameM["retail_price"].(string)
  3308. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3309. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3310. err_log := models.ExportErrLog{
  3311. LogType: 4,
  3312. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3313. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  3314. Status: 1,
  3315. CreateTime: time.Now().Unix(),
  3316. UpdateTime: time.Now().Unix(),
  3317. ExportTime: time.Now().Unix(),
  3318. }
  3319. service.CreateExportErrLog(&err_log)
  3320. continue
  3321. }
  3322. drug.RetailPrice = retail_price
  3323. packing_prices := goodNameM["packing_price"].(string)
  3324. packing_price, _ := strconv.ParseFloat(packing_prices, 64)
  3325. if packing_price <= 0 { //名字为空则生成一条导入错误日志
  3326. err_log := models.ExportErrLog{
  3327. LogType: 4,
  3328. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3329. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装零售价不能为空",
  3330. Status: 1,
  3331. CreateTime: time.Now().Unix(),
  3332. UpdateTime: time.Now().Unix(),
  3333. ExportTime: time.Now().Unix(),
  3334. }
  3335. service.CreateExportErrLog(&err_log)
  3336. continue
  3337. }
  3338. drug.RetailPrice = retail_price
  3339. last_prices := goodNameM["last_price"].(string)
  3340. last_price, _ := strconv.ParseFloat(last_prices, 64)
  3341. if last_price <= 0 { //名字为空则生成一条导入错误日志
  3342. err_log := models.ExportErrLog{
  3343. LogType: 4,
  3344. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3345. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  3346. Status: 1,
  3347. CreateTime: time.Now().Unix(),
  3348. UpdateTime: time.Now().Unix(),
  3349. ExportTime: time.Now().Unix(),
  3350. }
  3351. service.CreateExportErrLog(&err_log)
  3352. continue
  3353. }
  3354. drug.LastPrice = last_price
  3355. drug_classify := goodNameM["drug_classify"].(string)
  3356. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  3357. err_log := models.ExportErrLog{
  3358. LogType: 4,
  3359. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3360. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  3361. Status: 1,
  3362. CreateTime: time.Now().Unix(),
  3363. UpdateTime: time.Now().Unix(),
  3364. ExportTime: time.Now().Unix(),
  3365. }
  3366. service.CreateExportErrLog(&err_log)
  3367. continue
  3368. }
  3369. var drugClassify = "药物分类"
  3370. var drug_classify_id int64
  3371. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  3372. if len(drug_classify) != 0 {
  3373. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  3374. if errcodesClass == gorm.ErrRecordNotFound {
  3375. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  3376. dataconfig := models.DictDataconfig{
  3377. ParentId: drugClassifyConfig.ID,
  3378. Module: "system",
  3379. OrgId: orgId,
  3380. Name: drug_classify,
  3381. FieldName: "",
  3382. Value: drugClassConfig.Value + 1,
  3383. CreatedTime: "",
  3384. UpdatedTime: "",
  3385. CreateUserId: adminUser.AdminUser.Id,
  3386. Status: 1,
  3387. Remark: "",
  3388. DeleteIdSystem: 0,
  3389. Title: "",
  3390. Content: "",
  3391. Order: 0,
  3392. Code: "",
  3393. }
  3394. service.CreatedDicConfig(&dataconfig)
  3395. }
  3396. }
  3397. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  3398. for _, it := range drugClassList {
  3399. if drug_classify == it.Name {
  3400. drug_classify_id = int64(it.Value)
  3401. }
  3402. }
  3403. drug_dose := goodNameM["drug_dose"].(string)
  3404. if len(drug_dose) == 0 {
  3405. err_log := models.ExportErrLog{
  3406. LogType: 4,
  3407. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3408. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  3409. Status: 1,
  3410. CreateTime: time.Now().Unix(),
  3411. UpdateTime: time.Now().Unix(),
  3412. ExportTime: time.Now().Unix(),
  3413. }
  3414. service.CreateExportErrLog(&err_log)
  3415. continue
  3416. }
  3417. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  3418. drug.DrugDose = drugDoses
  3419. var units = "单位"
  3420. var unit_id int64
  3421. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  3422. if len(drugDoseUnit) == 0 {
  3423. err_log := models.ExportErrLog{
  3424. LogType: 4,
  3425. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3426. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  3427. Status: 1,
  3428. CreateTime: time.Now().Unix(),
  3429. UpdateTime: time.Now().Unix(),
  3430. ExportTime: time.Now().Unix(),
  3431. }
  3432. service.CreateExportErrLog(&err_log)
  3433. continue
  3434. }
  3435. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  3436. if len(drugDoseUnit) != 0 {
  3437. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  3438. if errcodedataconfig == gorm.ErrRecordNotFound {
  3439. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  3440. dataconfig := models.Dataconfig{
  3441. ParentId: dataConfig.ID,
  3442. Module: "hemodialysis",
  3443. OrgId: orgId,
  3444. Name: drugDoseUnit,
  3445. FieldName: "",
  3446. Value: childConfig.Value + 1,
  3447. CreatedTime: "",
  3448. UpdatedTime: "",
  3449. CreateUserId: adminUser.AdminUser.Id,
  3450. Status: 1,
  3451. Remark: "",
  3452. DeleteIdSystem: 0,
  3453. Title: "",
  3454. Content: "",
  3455. Order: 0,
  3456. Code: "",
  3457. FieldType: 0,
  3458. }
  3459. service.CreateDataConfig(&dataconfig)
  3460. }
  3461. }
  3462. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  3463. for _, it := range list {
  3464. if drugDoseUnit == it.Name {
  3465. unit_id = int64(it.Value)
  3466. }
  3467. }
  3468. drug.DrugDoseUnit = unit_id
  3469. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  3470. manufacturer := goodNameM["manufacturer"].(string)
  3471. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3472. err_log := models.ExportErrLog{
  3473. LogType: 4,
  3474. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3475. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  3476. Status: 1,
  3477. CreateTime: time.Now().Unix(),
  3478. UpdateTime: time.Now().Unix(),
  3479. ExportTime: time.Now().Unix(),
  3480. }
  3481. service.CreateExportErrLog(&err_log)
  3482. continue
  3483. }
  3484. if len(manufacturer) != 0 {
  3485. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  3486. if errcodema == gorm.ErrRecordNotFound {
  3487. manufactur := models.Manufacturer{
  3488. OrgId: orgId,
  3489. Status: 1,
  3490. ManufacturerName: manufacturer,
  3491. Ctime: time.Now().Unix(),
  3492. Creater: adminUser.AdminUser.Id,
  3493. }
  3494. service.CreateManufacturer(&manufactur)
  3495. }
  3496. }
  3497. var manufacturer_id int64
  3498. manufacturList, _ := service.GetAllManufacturerList(orgId)
  3499. for _, it := range manufacturList {
  3500. if manufacturer == it.ManufacturerName {
  3501. manufacturer_id = it.ID
  3502. }
  3503. }
  3504. drug.Manufacturer = manufacturer_id
  3505. dealer := goodNameM["dealer"].(string)
  3506. if len(dealer) != 0 {
  3507. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  3508. if errcodesdealer == gorm.ErrRecordNotFound {
  3509. dealerconfig := models.Dealer{
  3510. DealerName: dealer,
  3511. Status: 1,
  3512. OrgId: orgId,
  3513. Ctime: time.Now().Unix(),
  3514. Creater: adminUser.AdminUser.Id,
  3515. }
  3516. service.CreateDealer(&dealerconfig)
  3517. }
  3518. }
  3519. var dealer_id int64
  3520. dealerList, _ := service.GetAllDealerList(orgId)
  3521. for _, it := range dealerList {
  3522. if dealer == it.DealerName {
  3523. dealer_id = it.ID
  3524. }
  3525. }
  3526. drug.Dealer = dealer_id
  3527. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  3528. drug.LmtUsedFlag = lmt_used_flags
  3529. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  3530. utils.ErrorLog("drug_alias")
  3531. return
  3532. }
  3533. drug_alias, _ := goodNameM["drug_alias"].(string)
  3534. drug.DrugAlias = drug_alias
  3535. drug_category := goodNameM["drug_category"].(string)
  3536. var drugCategory = "药品类别"
  3537. var drug_category_id int64
  3538. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  3539. if len(drug_category) != 0 {
  3540. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  3541. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  3542. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  3543. dataconfig := models.DictDataconfig{
  3544. ParentId: drugCategoryConfig.ID,
  3545. Module: "system",
  3546. OrgId: orgId,
  3547. Name: drug_category,
  3548. FieldName: "",
  3549. Value: drugCategoryConfigSix.Value + 1,
  3550. CreatedTime: "",
  3551. UpdatedTime: "",
  3552. CreateUserId: adminUser.AdminUser.Id,
  3553. Status: 1,
  3554. Remark: "",
  3555. DeleteIdSystem: 0,
  3556. Title: "",
  3557. Content: "",
  3558. Order: 0,
  3559. Code: "",
  3560. }
  3561. service.CreatedDicConfig(&dataconfig)
  3562. }
  3563. }
  3564. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  3565. fmt.Println("drugCategoryList", drugCategoryList)
  3566. for _, it := range drugCategoryList {
  3567. if drug_category == it.Name {
  3568. drug_category_id = int64(it.Value)
  3569. }
  3570. }
  3571. drug.DrugCategory = drug_category_id
  3572. statistics_category := goodNameM["statistics_category"].(string)
  3573. var statisticsCategory = "统计分类"
  3574. var statistics_category_id int64
  3575. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3576. if len(statistics_category) != 0 {
  3577. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  3578. if errcodestatistc == gorm.ErrRecordNotFound {
  3579. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  3580. dataconfig := models.DictDataconfig{
  3581. ParentId: statistcConfig.ID,
  3582. Module: "system",
  3583. OrgId: orgId,
  3584. Name: statistics_category,
  3585. FieldName: "",
  3586. Value: staConfig.Value + 1,
  3587. CreatedTime: "",
  3588. UpdatedTime: "",
  3589. CreateUserId: adminUser.AdminUser.Id,
  3590. Status: 1,
  3591. Remark: "",
  3592. DeleteIdSystem: 0,
  3593. Title: "",
  3594. Content: "",
  3595. Order: 0,
  3596. Code: "",
  3597. }
  3598. service.CreatedDicConfig(&dataconfig)
  3599. }
  3600. }
  3601. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  3602. for _, it := range statisticsCategoryList {
  3603. if statistics_category == it.Name {
  3604. statistics_category_id = int64(it.Value)
  3605. }
  3606. }
  3607. drug.StatisticsCategory = statistics_category_id
  3608. number := goodNameM["number"].(string)
  3609. drug.Number = number
  3610. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  3611. drug.HospApprFlag = hosp_appr_flag
  3612. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3613. drug.MedicalInsuranceNumber = medical_insurance_number
  3614. pharmacology_category := goodNameM["pharmacology_category"].(string)
  3615. var pharmacology = "药理分类"
  3616. var pharmacology_category_id int64
  3617. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  3618. if len(pharmacology_category) != 0 {
  3619. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  3620. if errcodespharmacology == gorm.ErrRecordNotFound {
  3621. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  3622. dataconfig := models.DictDataconfig{
  3623. ParentId: pharmacologyConfig.ID,
  3624. Module: "system",
  3625. OrgId: orgId,
  3626. Name: pharmacology_category,
  3627. FieldName: "",
  3628. Value: dicConfig.Value + 1,
  3629. CreatedTime: "",
  3630. UpdatedTime: "",
  3631. CreateUserId: adminUser.AdminUser.Id,
  3632. Status: 1,
  3633. Remark: "",
  3634. DeleteIdSystem: 0,
  3635. Title: "",
  3636. Content: "",
  3637. Order: 0,
  3638. Code: "",
  3639. }
  3640. service.CreatedDicConfig(&dataconfig)
  3641. }
  3642. }
  3643. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  3644. for _, it := range pharmacologyList {
  3645. if pharmacology_category == it.Name {
  3646. pharmacology_category_id = int64(it.Value)
  3647. }
  3648. }
  3649. drug.PharmacologyCategory = pharmacology_category_id
  3650. code := goodNameM["code"].(string)
  3651. drug.Code = code
  3652. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3653. drug.IsSpecialDiseases = is_special_diseases
  3654. is_record := int64(goodNameM["is_record"].(float64))
  3655. drug.IsRecord = is_record
  3656. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  3657. drug.PrescriptionMark = prescription_mark
  3658. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3659. drug.SocialSecurityDirectoryCode = social_security_directory_code
  3660. record_date := goodNameM["record_date"].(string)
  3661. timeLayout := "2006-01-02"
  3662. loc, _ := time.LoadLocation("Local")
  3663. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3664. drug.RecordDate = theTime.Unix()
  3665. drug_remark := goodNameM["drug_remark"].(string)
  3666. drug.DrugRemark = drug_remark
  3667. drug_status := goodNameM["drug_status"].(string)
  3668. drug.DrugStatus = drug_status
  3669. limit_remark := goodNameM["limit_remark"].(string)
  3670. drug.LimitRemark = limit_remark
  3671. drug_control := goodNameM["drug_control"].(string)
  3672. var drugControl = "开药控制"
  3673. var drug_control_id int64
  3674. drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
  3675. if len(drug_control) != 0 {
  3676. _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
  3677. if errcodesdrugcontrol == gorm.ErrRecordNotFound {
  3678. drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
  3679. dataconfig := models.DictDataconfig{
  3680. ParentId: drugContorlConfig.ID,
  3681. Module: "system",
  3682. OrgId: orgId,
  3683. Name: drug_control,
  3684. FieldName: "",
  3685. Value: drugContorlConfigOne.Value + 1,
  3686. CreatedTime: "",
  3687. UpdatedTime: "",
  3688. CreateUserId: adminUser.AdminUser.Id,
  3689. Status: 1,
  3690. Remark: "",
  3691. DeleteIdSystem: 0,
  3692. Title: "",
  3693. Content: "",
  3694. Order: 0,
  3695. Code: "",
  3696. }
  3697. service.CreatedDicConfig(&dataconfig)
  3698. }
  3699. }
  3700. drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
  3701. for _, it := range drugContorlList {
  3702. if drug_control == it.Name {
  3703. drug_control_id = int64(it.Value)
  3704. }
  3705. }
  3706. drug.DrugControl = drug_control_id
  3707. drugList = append(drugList, &drug)
  3708. }
  3709. export_time := time.Now().Unix()
  3710. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3711. if len(drugList) > 0 {
  3712. for _, item := range drugList {
  3713. goodInfo := models.BaseDrugLib{
  3714. DrugName: item.DrugName,
  3715. DrugAlias: item.DrugAlias,
  3716. DrugSpec: item.DrugSpec,
  3717. DrugType: item.DrugType,
  3718. DrugStockLimit: item.DrugStockLimit,
  3719. DrugOriginPlace: item.DrugOriginPlace,
  3720. DrugDosageForm: item.DrugDosageForm,
  3721. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3722. MaxUnit: item.MaxUnit,
  3723. MinUnit: item.MinUnit,
  3724. UnitMatrixing: item.UnitMatrixing,
  3725. RetailPrice: item.RetailPrice,
  3726. LastPrice: item.LastPrice,
  3727. DrugClassify: item.DrugClassify,
  3728. Manufacturer: item.Manufacturer,
  3729. Dealer: item.Dealer,
  3730. OrgId: orgId,
  3731. Status: 1,
  3732. Ctime: time.Now().Unix(),
  3733. Pinyin: item.Pinyin,
  3734. Wubi: item.Wubi,
  3735. DrugAliasPinyin: item.DrugAliasPinyin,
  3736. DrugAliasWubi: item.DrugAliasWubi,
  3737. DrugControl: item.DrugControl,
  3738. Number: item.Number,
  3739. HospApprFlag: item.HospApprFlag,
  3740. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3741. PharmacologyCategory: item.PharmacologyCategory,
  3742. StatisticsCategory: item.StatisticsCategory,
  3743. Code: item.Code,
  3744. IsSpecialDiseases: item.IsSpecialDiseases,
  3745. IsRecord: item.IsRecord,
  3746. PrescriptionMark: item.PrescriptionMark,
  3747. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3748. RecordDate: item.RecordDate,
  3749. DrugRemark: item.DrugRemark,
  3750. DrugStatus: item.DrugStatus,
  3751. LimitRemark: item.LimitRemark,
  3752. DrugCategory: item.DrugCategory,
  3753. DrugDose: item.DrugDose,
  3754. DrugDoseUnit: item.DrugDoseUnit,
  3755. LmtUsedFlag: item.LmtUsedFlag,
  3756. DrugDay: item.DrugDay,
  3757. DeliveryWay: item.DeliveryWay,
  3758. ExecutionFrequency: item.ExecutionFrequency,
  3759. DoseUnit: item.DoseUnit,
  3760. }
  3761. //查询同种药品同种规格是否存在
  3762. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.MaxUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  3763. if drugerror == gorm.ErrRecordNotFound {
  3764. service.CreateDrugsInfomation(&goodInfo)
  3765. } else if drugerror == nil {
  3766. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  3767. }
  3768. log := models.ExportLog{
  3769. LogType: 4,
  3770. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3771. TotalNum: int64(len(total_goods)),
  3772. FailNum: int64(len(errLogs)),
  3773. SuccessNum: int64(len(drugList)),
  3774. CreateTime: time.Now().Unix(),
  3775. UpdateTime: time.Now().Unix(),
  3776. ExportTime: export_time,
  3777. Status: 1,
  3778. }
  3779. service.CreateExportLog(&log)
  3780. this.ServeSuccessJSON(map[string]interface{}{
  3781. "msg": "导入成功",
  3782. "total_num": len(total_goods),
  3783. "success_num": len(drugList),
  3784. "fail_num": int64(len(errLogs)),
  3785. })
  3786. }
  3787. } else {
  3788. log := models.ExportLog{
  3789. LogType: 4,
  3790. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3791. TotalNum: int64(len(total_goods)),
  3792. FailNum: int64(len(errLogs)),
  3793. SuccessNum: int64(len(drugList)),
  3794. CreateTime: time.Now().Unix(),
  3795. UpdateTime: time.Now().Unix(),
  3796. ExportTime: export_time,
  3797. Status: 1,
  3798. }
  3799. service.CreateExportLog(&log)
  3800. this.ServeSuccessJSON(map[string]interface{}{
  3801. "msg": "导入成功",
  3802. "total_num": len(total_goods),
  3803. "success_num": len(drugList),
  3804. "fail_num": int64(len(errLogs)),
  3805. })
  3806. }
  3807. }
  3808. func (this *StockManagerApiController) GetInitializtion() {
  3809. orgId := this.GetAdminUserInfo().CurrentOrgId
  3810. var drugCategory = "药品类别"
  3811. var drugType = "药品类型"
  3812. var drugDosageForm = "药品剂型"
  3813. var medicalInsuranceLevel = "医保等级"
  3814. var drugControl = "开药控制"
  3815. var drugClassify = "药物分类"
  3816. var statisticsCategory = "统计分类"
  3817. var pharmacologyCategory = "药理分类"
  3818. var goodKind = "耗材种类"
  3819. var tubeColor = "试管颜色"
  3820. var costClassify = "费用类别"
  3821. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3822. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3823. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  3824. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  3825. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  3826. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  3827. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  3828. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  3829. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  3830. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  3831. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  3832. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  3833. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3834. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  3835. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  3836. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  3837. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  3838. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  3839. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  3840. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  3841. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  3842. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  3843. this.ServeSuccessJSON(map[string]interface{}{
  3844. "drugCategoryList": drugCategoryList,
  3845. "drugTypeList": drugTypeList,
  3846. "drugDosageFormList": drugDosageFormList,
  3847. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  3848. "drugControlList": drugControlList,
  3849. "drugClassifyList": drugClassifyList,
  3850. "statisticsCategoryList": statisticsCategoryList,
  3851. "pharmacologyCategoryList": pharmacologyCategoryList,
  3852. "goodKindList": goodKindList,
  3853. "tubeColorList": tubeColorList,
  3854. "costClassifyList": costClassifyList,
  3855. })
  3856. }
  3857. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  3858. adminUserInfo := this.GetAdminUserInfo()
  3859. orgId := adminUserInfo.CurrentOrgId
  3860. list, _ := service.GetWarehouseOrderInfoList(orgId)
  3861. this.ServeSuccessJSON(map[string]interface{}{
  3862. "list": list,
  3863. })
  3864. }
  3865. func (this *StockManagerApiController) PostSearchGoodList() {
  3866. keyword := this.GetString("keyword")
  3867. adminUserInfo := this.GetAdminUserInfo()
  3868. orgId := adminUserInfo.CurrentOrgId
  3869. list, _ := service.GetSearchGoodList(keyword, orgId)
  3870. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3871. dealerList, _ := service.GetAllDealerList(orgId)
  3872. this.ServeSuccessJSON(map[string]interface{}{
  3873. "list": list,
  3874. "manufacturerList": manufacturerList,
  3875. "dealerList": dealerList,
  3876. })
  3877. }
  3878. func (this *StockManagerApiController) GetAllStockList() {
  3879. page, _ := this.GetInt64("page", -1)
  3880. limit, _ := this.GetInt64("limit", -1)
  3881. start_time := this.GetString("start_time")
  3882. end_time := this.GetString("end_time")
  3883. types, _ := this.GetInt64("type", 0)
  3884. keywords := this.GetString("keywords")
  3885. timeLayout := "2006-01-02"
  3886. loc, _ := time.LoadLocation("Local")
  3887. var startTime int64
  3888. if len(start_time) > 0 {
  3889. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3890. if err != nil {
  3891. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3892. return
  3893. }
  3894. startTime = theTime.Unix()
  3895. }
  3896. var endTime int64
  3897. if len(end_time) > 0 {
  3898. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3899. if err != nil {
  3900. utils.ErrorLog(err.Error())
  3901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3902. return
  3903. }
  3904. endTime = theTime.Unix()
  3905. }
  3906. adminUserInfo := this.GetAdminUserInfo()
  3907. orgId := adminUserInfo.CurrentOrgId
  3908. list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId)
  3909. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3910. this.ServeSuccessJSON(map[string]interface{}{
  3911. "list": list,
  3912. "total": total,
  3913. "manufacturerList": manufacturerList,
  3914. })
  3915. }
  3916. func (this *StockManagerApiController) GetStockListById() {
  3917. id, _ := this.GetInt64("id")
  3918. adminUserInfo := this.GetAdminUserInfo()
  3919. orgId := adminUserInfo.CurrentOrgId
  3920. limit, _ := this.GetInt64("limit")
  3921. page, _ := this.GetInt64("page")
  3922. timeLayout := "2006-01-02"
  3923. loc, _ := time.LoadLocation("Local")
  3924. start_time := this.GetString("start_time")
  3925. end_time := this.GetString("end_time")
  3926. var startTime int64
  3927. if len(start_time) > 0 {
  3928. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3929. if err != nil {
  3930. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3931. return
  3932. }
  3933. startTime = theTime.Unix()
  3934. }
  3935. var endTime int64
  3936. if len(end_time) > 0 {
  3937. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3938. if err != nil {
  3939. utils.ErrorLog(err.Error())
  3940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3941. return
  3942. }
  3943. endTime = theTime.Unix()
  3944. }
  3945. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3946. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime)
  3947. this.ServeSuccessJSON(map[string]interface{}{
  3948. "list": list,
  3949. "total": total,
  3950. "manufacturerList": manufacturerList,
  3951. })
  3952. }
  3953. func (this *StockManagerApiController) GetStockOutList() {
  3954. id, _ := this.GetInt64("id")
  3955. adminUserInfo := this.GetAdminUserInfo()
  3956. orgId := adminUserInfo.CurrentOrgId
  3957. limit, _ := this.GetInt64("limit")
  3958. page, _ := this.GetInt64("page")
  3959. timeLayout := "2006-01-02"
  3960. loc, _ := time.LoadLocation("Local")
  3961. start_time := this.GetString("start_time")
  3962. end_time := this.GetString("end_time")
  3963. is_sys, _ := this.GetInt64("is_sys")
  3964. var startTime int64
  3965. if len(start_time) > 0 {
  3966. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3967. if err != nil {
  3968. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3969. return
  3970. }
  3971. startTime = theTime.Unix()
  3972. }
  3973. var endTime int64
  3974. if len(end_time) > 0 {
  3975. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3976. if err != nil {
  3977. utils.ErrorLog(err.Error())
  3978. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3979. return
  3980. }
  3981. endTime = theTime.Unix()
  3982. }
  3983. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  3984. this.ServeSuccessJSON(map[string]interface{}{
  3985. "outList": outList,
  3986. "total": total,
  3987. })
  3988. }
  3989. func (this *StockManagerApiController) GetStockDrugCount() {
  3990. adminUserInfo := this.GetAdminUserInfo()
  3991. orgId := adminUserInfo.CurrentOrgId
  3992. fmt.Println(orgId)
  3993. timeLayout := "2006-01-02"
  3994. loc, _ := time.LoadLocation("Local")
  3995. start_time := this.GetString("start_time")
  3996. end_time := this.GetString("end_time")
  3997. var startTime int64
  3998. if len(start_time) > 0 {
  3999. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4000. if err != nil {
  4001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4002. return
  4003. }
  4004. startTime = theTime.Unix()
  4005. }
  4006. var endTime int64
  4007. if len(end_time) > 0 {
  4008. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4009. if err != nil {
  4010. utils.ErrorLog(err.Error())
  4011. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4012. return
  4013. }
  4014. endTime = theTime.Unix()
  4015. }
  4016. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  4017. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  4018. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  4019. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  4020. this.ServeSuccessJSON(map[string]interface{}{
  4021. "count": count,
  4022. "outList": outList,
  4023. "autoCount": autoCount,
  4024. "totalCount": totalCount,
  4025. })
  4026. }
  4027. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  4028. ids := this.GetString("id")
  4029. idsArray := strings.Split(ids, ",")
  4030. orgId := this.GetAdminUserInfo().CurrentOrgId
  4031. order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
  4032. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  4033. this.ServeSuccessJSON(map[string]interface{}{
  4034. "list": list,
  4035. "order": order,
  4036. })
  4037. }
  4038. func (this *StockManagerApiController) GetOrderDetailById() {
  4039. id, _ := this.GetInt64("id")
  4040. good_id, _ := this.GetInt64("good_id")
  4041. record_time, _ := this.GetInt64("record_time")
  4042. orgId := this.GetAdminUserInfo().CurrentOrgId
  4043. //自动出库
  4044. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  4045. //手动出库
  4046. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  4047. stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
  4048. if err == nil {
  4049. this.ServeSuccessJSON(map[string]interface{}{
  4050. "list": userDetails,
  4051. "total": total,
  4052. "info": info,
  4053. "stockFlowList": stockFlowList,
  4054. })
  4055. } else {
  4056. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4057. return
  4058. }
  4059. }
  4060. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  4061. id, _ := this.GetInt64("id", 0)
  4062. orgId := this.GetAdminUserInfo().CurrentOrgId
  4063. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  4064. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4065. dealerList, _ := service.GetAllDealerList(orgId)
  4066. goodType, _ := service.GetAllGoodType(orgId)
  4067. this.ServeSuccessJSON(map[string]interface{}{
  4068. "list": warehouseOutInfo,
  4069. "dealerList": dealerList,
  4070. "manufacturerList": manufacturerList,
  4071. "goodType": goodType,
  4072. })
  4073. }
  4074. func (this *StockManagerApiController) GetExprotStockList() {
  4075. adminUserInfo := this.GetAdminUserInfo()
  4076. orgId := adminUserInfo.CurrentOrgId
  4077. timeLayout := "2006-01-02"
  4078. loc, _ := time.LoadLocation("Local")
  4079. start_time := this.GetString("start_time")
  4080. end_time := this.GetString("end_time")
  4081. idArray := this.GetString("id")
  4082. ids := strings.Split(idArray, ",")
  4083. var startTime int64
  4084. if len(start_time) > 0 {
  4085. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4086. if err != nil {
  4087. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4088. return
  4089. }
  4090. startTime = theTime.Unix()
  4091. }
  4092. var endTime int64
  4093. if len(end_time) > 0 {
  4094. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4095. if err != nil {
  4096. utils.ErrorLog(err.Error())
  4097. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4098. return
  4099. }
  4100. endTime = theTime.Unix()
  4101. }
  4102. fmt.Println("ids2222222222222222", ids)
  4103. list, _ := service.GetExprotStockList(orgId, ids, startTime, endTime)
  4104. this.ServeSuccessJSON(map[string]interface{}{
  4105. "list": list,
  4106. })
  4107. }
  4108. func (this *StockManagerApiController) GetOutExprotList() {
  4109. adminUserInfo := this.GetAdminUserInfo()
  4110. orgId := adminUserInfo.CurrentOrgId
  4111. timeLayout := "2006-01-02"
  4112. loc, _ := time.LoadLocation("Local")
  4113. start_time := this.GetString("start_time")
  4114. end_time := this.GetString("end_time")
  4115. idArray := this.GetString("id")
  4116. ids := strings.Split(idArray, ",")
  4117. fmt.Println("ids2222222222", ids)
  4118. var startTime int64
  4119. if len(start_time) > 0 {
  4120. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4121. if err != nil {
  4122. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4123. return
  4124. }
  4125. startTime = theTime.Unix()
  4126. }
  4127. var endTime int64
  4128. if len(end_time) > 0 {
  4129. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4130. if err != nil {
  4131. utils.ErrorLog(err.Error())
  4132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4133. return
  4134. }
  4135. endTime = theTime.Unix()
  4136. }
  4137. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  4138. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  4139. this.ServeSuccessJSON(map[string]interface{}{
  4140. "list": list,
  4141. "count": outCount,
  4142. })
  4143. }
  4144. func (this *StockManagerApiController) GetSingleCancelOrder() {
  4145. id, _ := this.GetInt64("id")
  4146. adminUserInfo := this.GetAdminUserInfo()
  4147. orgId := adminUserInfo.CurrentOrgId
  4148. order, _ := service.GetSingleCancelOrder(id, orgId)
  4149. this.ServeSuccessJSON(map[string]interface{}{
  4150. "list": order,
  4151. })
  4152. }
  4153. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  4154. id := this.GetString("id")
  4155. idStr := strings.Split(id, ",")
  4156. orgId := this.GetAdminUserInfo().CurrentOrgId
  4157. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  4158. this.ServeSuccessJSON(map[string]interface{}{
  4159. "list": list,
  4160. })
  4161. }
  4162. func (this *StockManagerApiController) GetStockBatchNumber() {
  4163. id, _ := this.GetInt64("id")
  4164. orgId := this.GetAdminUserInfo().CurrentOrgId
  4165. list, _ := service.GetStockBatchNumber(id, orgId)
  4166. this.ServeSuccessJSON(map[string]interface{}{
  4167. "list": list,
  4168. })
  4169. }
  4170. func (this *StockManagerApiController) GetStockFlow() {
  4171. limit, _ := this.GetInt64("limit")
  4172. page, _ := this.GetInt64("page")
  4173. good_id, _ := this.GetInt64("good_id")
  4174. consumable_type, _ := this.GetInt64("is_sys")
  4175. adminUserInfo := this.GetAdminUserInfo()
  4176. orgId := adminUserInfo.CurrentOrgId
  4177. timeLayout := "2006-01-02"
  4178. loc, _ := time.LoadLocation("Local")
  4179. start_time := this.GetString("start_time")
  4180. end_time := this.GetString("end_time")
  4181. var startTime int64
  4182. if len(start_time) > 0 {
  4183. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4184. if err != nil {
  4185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4186. return
  4187. }
  4188. startTime = theTime.Unix()
  4189. }
  4190. var endTime int64
  4191. if len(end_time) > 0 {
  4192. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4193. if err != nil {
  4194. utils.ErrorLog(err.Error())
  4195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4196. return
  4197. }
  4198. endTime = theTime.Unix()
  4199. }
  4200. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  4201. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4202. this.ServeSuccessJSON(map[string]interface{}{
  4203. "list": list,
  4204. "total": total,
  4205. "manufacturerList": manufacturerList,
  4206. })
  4207. }
  4208. func (this *StockManagerApiController) GetCancelExportList() {
  4209. adminUserInfo := this.GetAdminUserInfo()
  4210. orgId := adminUserInfo.CurrentOrgId
  4211. timeLayout := "2006-01-02"
  4212. loc, _ := time.LoadLocation("Local")
  4213. start_time := this.GetString("start_time")
  4214. end_time := this.GetString("end_time")
  4215. idArray := this.GetString("order_id")
  4216. fmt.Println("232323232323232232", idArray)
  4217. ids := strings.Split(idArray, ",")
  4218. var startTime int64
  4219. if len(start_time) > 0 {
  4220. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4221. if err != nil {
  4222. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4223. return
  4224. }
  4225. startTime = theTime.Unix()
  4226. }
  4227. var endTime int64
  4228. if len(end_time) > 0 {
  4229. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4230. if err != nil {
  4231. utils.ErrorLog(err.Error())
  4232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4233. return
  4234. }
  4235. endTime = theTime.Unix()
  4236. }
  4237. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  4238. this.ServeSuccessJSON(map[string]interface{}{
  4239. "list": list,
  4240. })
  4241. }
  4242. func (this *StockManagerApiController) GetSearchGoodWarehouseList() {
  4243. keyword := this.GetString("keyword")
  4244. orgId := this.GetAdminUserInfo().CurrentOrgId
  4245. list, _ := service.GetSearchGoodWarehouseList(keyword, orgId)
  4246. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4247. dealerList, _ := service.GetAllDealerList(orgId)
  4248. this.ServeSuccessJSON(map[string]interface{}{
  4249. "list": list,
  4250. "manufacturerList": manufacturerList,
  4251. "dealerList": dealerList,
  4252. })
  4253. }
  4254. func (this *StockManagerApiController) SaveAdjuestPrice() {
  4255. timeLayout := "2006-01-02"
  4256. loc, _ := time.LoadLocation("Local")
  4257. dataBody := make(map[string]interface{}, 0)
  4258. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4259. if err != nil {
  4260. utils.ErrorLog(err.Error())
  4261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4262. return
  4263. }
  4264. tableData, _ := dataBody["tableData"].([]interface{})
  4265. if len(tableData) > 0 {
  4266. for _, item := range tableData {
  4267. items := item.(map[string]interface{})
  4268. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4269. utils.ErrorLog("good_name")
  4270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4271. return
  4272. }
  4273. good_name := items["good_name"].(string)
  4274. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4275. utils.ErrorLog("good_name")
  4276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4277. return
  4278. }
  4279. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4280. utils.ErrorLog("packing_price")
  4281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4282. return
  4283. }
  4284. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4285. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4286. utils.ErrorLog("warehousing_order")
  4287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4288. return
  4289. }
  4290. warehousing_order := items["warehousing_order"].(string)
  4291. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4292. utils.ErrorLog("license_number")
  4293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4294. return
  4295. }
  4296. license_number := items["license_number"].(string)
  4297. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4298. utils.ErrorLog("dealer")
  4299. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4300. return
  4301. }
  4302. dealer := items["dealer"].(string)
  4303. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4304. utils.ErrorLog("manufacturer")
  4305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4306. return
  4307. }
  4308. manufacturer := items["manufacturer"].(string)
  4309. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4310. utils.ErrorLog("specification_name")
  4311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4312. return
  4313. }
  4314. specification_name := items["specification_name"].(string)
  4315. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4316. utils.ErrorLog("remark")
  4317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4318. return
  4319. }
  4320. remark := items["remark"].(string)
  4321. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4322. utils.ErrorLog("warehousing_unit")
  4323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4324. return
  4325. }
  4326. warehousing_unit := items["warehousing_unit"].(string)
  4327. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4328. utils.ErrorLog("buy_price")
  4329. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4330. return
  4331. }
  4332. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4333. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4334. utils.ErrorLog("count")
  4335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4336. return
  4337. }
  4338. count := int64(items["count"].(float64))
  4339. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  4340. utils.ErrorLog("new_price")
  4341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4342. return
  4343. }
  4344. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  4345. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4346. utils.ErrorLog("good_id")
  4347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4348. return
  4349. }
  4350. good_id := int64(items["good_id"].(float64))
  4351. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4352. utils.ErrorLog("start_time")
  4353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4354. return
  4355. }
  4356. var startTime int64
  4357. start_time := items["start_time"].(string)
  4358. if len(start_time) > 0 {
  4359. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4360. if err != nil {
  4361. fmt.Println(err)
  4362. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4363. return
  4364. }
  4365. startTime = theTime.Unix()
  4366. }
  4367. orgId := this.GetAdminUserInfo().CurrentOrgId
  4368. adjustprice := models.XtStockAdjustPrice{
  4369. GoodName: good_name,
  4370. SpecificationName: specification_name,
  4371. WarehousingUnit: warehousing_unit,
  4372. Count: count,
  4373. BuyPrice: buy_price,
  4374. PackingPrice: packing_price,
  4375. NewPrice: new_price,
  4376. Manufacturer: manufacturer,
  4377. Dealer: dealer,
  4378. Remark: remark,
  4379. GoodId: good_id,
  4380. UserOrgId: orgId,
  4381. Ctime: time.Now().Unix(),
  4382. Mtime: 0,
  4383. Status: 1,
  4384. WarehousingOrder: warehousing_order,
  4385. LicenseNumber: license_number,
  4386. StartTime: startTime,
  4387. Creater: this.GetAdminUserInfo().AdminUser.Id,
  4388. CheckerStatus: 2,
  4389. }
  4390. service.CreateAdjustPrice(&adjustprice)
  4391. }
  4392. }
  4393. this.ServeSuccessJSON(map[string]interface{}{
  4394. "msg": "保存成功!",
  4395. })
  4396. }
  4397. func (this *StockManagerApiController) GetAllStockPrice() {
  4398. timeLayout := "2006-01-02"
  4399. loc, _ := time.LoadLocation("Local")
  4400. dataBody := make(map[string]interface{}, 0)
  4401. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4402. fmt.Println(err)
  4403. orgId := this.GetAdminUserInfo().CurrentOrgId
  4404. keyword := this.GetString("keyword")
  4405. start_time := this.GetString("start_time")
  4406. end_time := this.GetString("end_time")
  4407. limit, _ := this.GetInt64("limit")
  4408. page, _ := this.GetInt64("page")
  4409. var startTime int64
  4410. if len(start_time) > 0 {
  4411. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4412. if err != nil {
  4413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4414. return
  4415. }
  4416. startTime = theTime.Unix()
  4417. }
  4418. var endTime int64
  4419. if len(end_time) > 0 {
  4420. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4421. if err != nil {
  4422. utils.ErrorLog(err.Error())
  4423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4424. return
  4425. }
  4426. endTime = theTime.Unix()
  4427. }
  4428. list, total, _ := service.GetAllStockPrice(orgId, startTime, endTime, keyword, limit, page)
  4429. doctor, _ := service.GetAllDoctorThree(orgId)
  4430. this.ServeSuccessJSON(map[string]interface{}{
  4431. "list": list,
  4432. "doctor": doctor,
  4433. "total": total,
  4434. })
  4435. }
  4436. func (this *StockManagerApiController) SaveCheckPrice() {
  4437. timeLayout := "2006-01-02"
  4438. loc, _ := time.LoadLocation("Local")
  4439. dataBody := make(map[string]interface{}, 0)
  4440. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4441. fmt.Println(err)
  4442. idstr := this.GetString("ids")
  4443. ids := strings.Split(idstr, ",")
  4444. check_time := this.GetString("check_time")
  4445. var checkTime int64
  4446. if len(check_time) > 0 {
  4447. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4448. if err != nil {
  4449. fmt.Println(err)
  4450. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4451. return
  4452. }
  4453. checkTime = theTime.Unix()
  4454. }
  4455. checker, _ := this.GetInt64("checker")
  4456. adjustPrice := models.XtStockAdjustPrice{
  4457. Checker: checker,
  4458. CheckerStatus: 1,
  4459. CheckerTime: checkTime,
  4460. }
  4461. err = service.UpdateAdjustPrice(ids, adjustPrice)
  4462. fmt.Println(err)
  4463. list, _ := service.GetAdjustCheckPriceList(ids)
  4464. fmt.Println("list2333223323232323232323", list)
  4465. for _, item := range list {
  4466. info := models.GoodInfo{
  4467. PackingPrice: item.NewPrice,
  4468. BuyPrice: item.NewPrice,
  4469. }
  4470. err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
  4471. fmt.Println(err)
  4472. }
  4473. this.ServeSuccessJSON(map[string]interface{}{
  4474. "adjustPrice": adjustPrice,
  4475. })
  4476. }
  4477. func (this *StockManagerApiController) GetAdjustPriceById() {
  4478. ids := this.GetString("ids")
  4479. fmt.Println("ids23232233223233232", ids)
  4480. splitIds := strings.Split(ids, ",")
  4481. list, _ := service.GetAdjustPricebyIdOne(splitIds)
  4482. fmt.Println("list2322322323", list)
  4483. this.ServeSuccessJSON(map[string]interface{}{
  4484. "list": list,
  4485. })
  4486. }
  4487. func (this *StockManagerApiController) SaveReportStock() {
  4488. timeLayout := "2006-01-02"
  4489. loc, _ := time.LoadLocation("Local")
  4490. dataBody := make(map[string]interface{}, 0)
  4491. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4492. if err != nil {
  4493. utils.ErrorLog(err.Error())
  4494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4495. return
  4496. }
  4497. tableData, _ := dataBody["tableData"].([]interface{})
  4498. if len(tableData) > 0 {
  4499. for _, item := range tableData {
  4500. items := item.(map[string]interface{})
  4501. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4502. utils.ErrorLog("good_name")
  4503. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4504. return
  4505. }
  4506. good_name := items["good_name"].(string)
  4507. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4508. utils.ErrorLog("good_name")
  4509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4510. return
  4511. }
  4512. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4513. utils.ErrorLog("packing_price")
  4514. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4515. return
  4516. }
  4517. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4518. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4519. utils.ErrorLog("warehousing_order")
  4520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4521. return
  4522. }
  4523. warehousing_order := items["warehousing_order"].(string)
  4524. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4525. utils.ErrorLog("license_number")
  4526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4527. return
  4528. }
  4529. license_number := items["license_number"].(string)
  4530. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4531. utils.ErrorLog("dealer")
  4532. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4533. return
  4534. }
  4535. dealer := items["dealer"].(string)
  4536. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4537. utils.ErrorLog("manufacturer")
  4538. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4539. return
  4540. }
  4541. manufacturer := items["manufacturer"].(string)
  4542. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4543. utils.ErrorLog("specification_name")
  4544. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4545. return
  4546. }
  4547. specification_name := items["specification_name"].(string)
  4548. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4549. utils.ErrorLog("remark")
  4550. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4551. return
  4552. }
  4553. remark := items["remark"].(string)
  4554. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4555. utils.ErrorLog("warehousing_unit")
  4556. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4557. return
  4558. }
  4559. warehousing_unit := items["warehousing_unit"].(string)
  4560. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4561. utils.ErrorLog("buy_price")
  4562. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4563. return
  4564. }
  4565. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4566. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4567. utils.ErrorLog("count")
  4568. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4569. return
  4570. }
  4571. count := int64(items["count"].(float64))
  4572. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4573. utils.ErrorLog("good_id")
  4574. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4575. return
  4576. }
  4577. good_id := int64(items["good_id"].(float64))
  4578. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4579. utils.ErrorLog("start_time")
  4580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4581. return
  4582. }
  4583. var startTime int64
  4584. start_time := items["start_time"].(string)
  4585. if len(start_time) > 0 {
  4586. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4587. if err != nil {
  4588. fmt.Println(err)
  4589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4590. return
  4591. }
  4592. startTime = theTime.Unix()
  4593. }
  4594. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4595. utils.ErrorLog("number")
  4596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4597. return
  4598. }
  4599. number := items["number"].(string)
  4600. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4601. utils.ErrorLog("warehousing_info_id")
  4602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4603. return
  4604. }
  4605. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4606. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4607. utils.ErrorLog("expiry_date")
  4608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4609. return
  4610. }
  4611. expiry_date := int64(items["expiry_date"].(float64))
  4612. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4613. utils.ErrorLog("product_date")
  4614. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4615. return
  4616. }
  4617. product_date := int64(items["product_date"].(float64))
  4618. orgId := this.GetAdminUserInfo().CurrentOrgId
  4619. Creater := this.GetAdminUserInfo().AdminUser.Id
  4620. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4621. utils.ErrorLog("total")
  4622. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4623. return
  4624. }
  4625. total := int64(items["total"].(float64))
  4626. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  4627. utils.ErrorLog("good_origin_place")
  4628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4629. return
  4630. }
  4631. good_origin_place := items["good_origin_place"].(string)
  4632. reportPrice := models.XtStockReportPrice{
  4633. GoodName: good_name,
  4634. SpecificationName: specification_name,
  4635. WarehousingUnit: warehousing_unit,
  4636. Count: count,
  4637. BuyPrice: buy_price,
  4638. PackingPrice: packing_price,
  4639. Manufacturer: manufacturer,
  4640. Dealer: dealer,
  4641. Remark: remark,
  4642. GoodId: good_id,
  4643. UserOrgId: orgId,
  4644. Ctime: time.Now().Unix(),
  4645. Mtime: 0,
  4646. Status: 1,
  4647. WarehousingOrder: warehousing_order,
  4648. LicenseNumber: license_number,
  4649. StartTime: startTime,
  4650. Creater: Creater,
  4651. Checker: 0,
  4652. CheckerStatus: 2,
  4653. CheckerTime: 0,
  4654. Number: number,
  4655. WarehousingInfoId: warehousing_info_id,
  4656. ExpiryDate: expiry_date,
  4657. ProductDate: product_date,
  4658. Total: total,
  4659. GoodOriginPlace: good_origin_place,
  4660. }
  4661. err := service.CreateReportPrice(&reportPrice)
  4662. fmt.Println(err)
  4663. }
  4664. }
  4665. this.ServeSuccessJSON(map[string]interface{}{
  4666. "msg": "保存成功!",
  4667. })
  4668. }
  4669. func (this *StockManagerApiController) GetReportStockList() {
  4670. timeLayout := "2006-01-02"
  4671. loc, _ := time.LoadLocation("Local")
  4672. start_time := this.GetString("start_time")
  4673. end_time := this.GetString("end_time")
  4674. page, _ := this.GetInt64("page")
  4675. limit, _ := this.GetInt64("limit")
  4676. var startTime int64
  4677. if len(start_time) > 0 {
  4678. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4679. if err != nil {
  4680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4681. return
  4682. }
  4683. startTime = theTime.Unix()
  4684. fmt.Println("开始时间", startTime)
  4685. }
  4686. var endTime int64
  4687. if len(end_time) > 0 {
  4688. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4689. if err != nil {
  4690. utils.ErrorLog(err.Error())
  4691. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4692. return
  4693. }
  4694. endTime = theTime.Unix()
  4695. }
  4696. orgId := this.GetAdminUserInfo().CurrentOrgId
  4697. keyword := this.GetString("keyword")
  4698. fmt.Println("startTime", startTime, "endTime", endTime)
  4699. //list, total, _ := service.GetReportStockList(startTime, endTime, orgId, keyword, page, limit)
  4700. list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit, startTime, endTime)
  4701. damageList, _ := service.GetStockDamagedCount(orgId)
  4702. doctorlist, _ := service.GetAllDoctorThree(orgId)
  4703. this.ServeSuccessJSON(map[string]interface{}{
  4704. "list": list,
  4705. "total": total,
  4706. "doctorlist": doctorlist,
  4707. "damageList": damageList,
  4708. })
  4709. }
  4710. func (this *StockManagerApiController) SaveCheckDamage() {
  4711. timeLayout := "2006-01-02"
  4712. loc, _ := time.LoadLocation("Local")
  4713. idstr := this.GetString("ids")
  4714. ids := strings.Split(idstr, ",")
  4715. check_time := this.GetString("check_time")
  4716. var checkTime int64
  4717. if len(check_time) > 0 {
  4718. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4719. if err != nil {
  4720. fmt.Println(err)
  4721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4722. return
  4723. }
  4724. checkTime = theTime.Unix()
  4725. }
  4726. checker, _ := this.GetInt64("checker")
  4727. reportprice := models.XtStockReportPrice{
  4728. Checker: checker,
  4729. CheckerStatus: 1,
  4730. CheckerTime: checkTime,
  4731. }
  4732. err := service.UpdateCheckDamage(ids, reportprice)
  4733. fmt.Println(err)
  4734. //获取当前核对的数据
  4735. list, _ := service.GetCheckDamageList(ids)
  4736. ctime := time.Now().Unix()
  4737. adminUserInfo := this.GetAdminUserInfo()
  4738. timeStr := time.Now().Format("2006-01-02")
  4739. timeArr := strings.Split(timeStr, "-")
  4740. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  4741. total = total + 1
  4742. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4743. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4744. number = number + total
  4745. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4746. operation_time := time.Now().Unix()
  4747. creater := adminUserInfo.AdminUser.Id
  4748. warehouseOut := models.WarehouseOut{
  4749. WarehouseOutOrderNumber: warehousing_out_order,
  4750. OperationTime: operation_time,
  4751. OrgId: adminUserInfo.CurrentOrgId,
  4752. Creater: creater,
  4753. Ctime: ctime,
  4754. Status: 1,
  4755. WarehouseOutTime: ctime,
  4756. Type: 1,
  4757. }
  4758. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  4759. if errcodes == gorm.ErrRecordNotFound {
  4760. service.AddSigleWarehouseOut(&warehouseOut)
  4761. }
  4762. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  4763. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  4764. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  4765. var manufacturer_id int64
  4766. var dealer_id int64
  4767. for _, item := range list {
  4768. for _, it := range manufacturerList {
  4769. if item.Manufacturer == it.ManufacturerName {
  4770. manufacturer_id = it.ID
  4771. }
  4772. }
  4773. for _, its := range dealerList {
  4774. if item.Dealer == its.DealerName {
  4775. dealer_id = its.ID
  4776. }
  4777. }
  4778. goodinfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4779. //插入出库单
  4780. warehouseOutInfo := &models.WarehouseOutInfo{
  4781. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4782. WarehouseOutId: out.ID,
  4783. GoodId: item.GoodId,
  4784. Count: item.Count,
  4785. Price: item.PackingPrice,
  4786. Status: 1,
  4787. Ctime: ctime,
  4788. Remark: item.Remark,
  4789. OrgId: adminUserInfo.CurrentOrgId,
  4790. Type: 2,
  4791. Manufacturer: manufacturer_id,
  4792. Number: item.Number,
  4793. ExpiryDate: item.ExpiryDate,
  4794. ProductDate: item.ProductDate,
  4795. Dealer: dealer_id,
  4796. LicenseNumber: item.LicenseNumber,
  4797. GoodTypeId: goodinfo.GoodTypeId,
  4798. }
  4799. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4800. fmt.Println("99999999999999", errOne)
  4801. //更改库存
  4802. info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  4803. warehousingInfo := models.WarehousingInfo{
  4804. StockCount: info.StockCount - item.Count,
  4805. }
  4806. errOne = service.UpdateGoodWarehouseInfo(item.WarehousingInfoId, warehousingInfo)
  4807. fmt.Println(errOne)
  4808. flow := models.VmStockFlow{
  4809. WarehousingId: 0,
  4810. GoodId: item.GoodId,
  4811. Number: item.Number,
  4812. LicenseNumber: item.LicenseNumber,
  4813. Count: item.Count,
  4814. UserOrgId: adminUserInfo.CurrentOrgId,
  4815. PatientId: 0,
  4816. SystemTime: time.Now().Unix(),
  4817. ConsumableType: 5,
  4818. IsSys: 0,
  4819. WarehousingOrder: "",
  4820. WarehouseOutId: out.ID,
  4821. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4822. IsEdit: 0,
  4823. CancelStockId: 0,
  4824. CancelOrderNumber: "",
  4825. Manufacturer: 0,
  4826. Dealer: 0,
  4827. Creator: adminUserInfo.AdminUser.Id,
  4828. UpdateCreator: 0,
  4829. Status: 1,
  4830. Ctime: time.Now().Unix(),
  4831. Mtime: 0,
  4832. Price: item.PackingPrice,
  4833. WarehousingDetailId: 0,
  4834. WarehouseOutDetailId: 0,
  4835. CancelOutDetailId: 0,
  4836. ProductDate: item.ProductDate,
  4837. ExpireDate: item.ExpiryDate,
  4838. }
  4839. service.CreateStockFlowOne(flow)
  4840. }
  4841. this.ServeSuccessJSON(map[string]interface{}{
  4842. "reportPrice": reportprice,
  4843. })
  4844. }
  4845. func (this *StockManagerApiController) SaveInventory() {
  4846. timeLayout := "2006-01-02"
  4847. loc, _ := time.LoadLocation("Local")
  4848. dataBody := make(map[string]interface{}, 0)
  4849. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4850. if err != nil {
  4851. utils.ErrorLog(err.Error())
  4852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4853. return
  4854. }
  4855. tableData, _ := dataBody["tableData"].([]interface{})
  4856. if len(tableData) > 0 {
  4857. for _, item := range tableData {
  4858. items := item.(map[string]interface{})
  4859. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4860. utils.ErrorLog("good_name")
  4861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4862. return
  4863. }
  4864. good_name := items["good_name"].(string)
  4865. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4866. utils.ErrorLog("good_name")
  4867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4868. return
  4869. }
  4870. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4871. utils.ErrorLog("packing_price")
  4872. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4873. return
  4874. }
  4875. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4876. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4877. utils.ErrorLog("warehousing_order")
  4878. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4879. return
  4880. }
  4881. warehousing_order := items["warehousing_order"].(string)
  4882. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4883. utils.ErrorLog("license_number")
  4884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4885. return
  4886. }
  4887. license_number := items["license_number"].(string)
  4888. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4889. utils.ErrorLog("dealer")
  4890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4891. return
  4892. }
  4893. dealer := items["dealer"].(string)
  4894. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4895. utils.ErrorLog("manufacturer")
  4896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4897. return
  4898. }
  4899. manufacturer := items["manufacturer"].(string)
  4900. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4901. utils.ErrorLog("specification_name")
  4902. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4903. return
  4904. }
  4905. specification_name := items["specification_name"].(string)
  4906. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4907. utils.ErrorLog("remark")
  4908. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4909. return
  4910. }
  4911. remark := items["remark"].(string)
  4912. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4913. utils.ErrorLog("warehousing_unit")
  4914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4915. return
  4916. }
  4917. warehousing_unit := items["warehousing_unit"].(string)
  4918. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4919. utils.ErrorLog("buy_price")
  4920. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4921. return
  4922. }
  4923. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4924. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4925. utils.ErrorLog("count")
  4926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4927. return
  4928. }
  4929. count := int64(items["count"].(float64))
  4930. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4931. utils.ErrorLog("good_id")
  4932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4933. return
  4934. }
  4935. good_id := int64(items["good_id"].(float64))
  4936. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4937. utils.ErrorLog("start_time")
  4938. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4939. return
  4940. }
  4941. var startTime int64
  4942. start_time := items["start_time"].(string)
  4943. if len(start_time) > 0 {
  4944. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4945. if err != nil {
  4946. fmt.Println(err)
  4947. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4948. return
  4949. }
  4950. startTime = theTime.Unix()
  4951. }
  4952. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4953. utils.ErrorLog("total")
  4954. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4955. return
  4956. }
  4957. total := int64(items["total"].(float64))
  4958. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4959. utils.ErrorLog("expiry_date")
  4960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4961. return
  4962. }
  4963. expiry_date := int64(items["expiry_date"].(float64))
  4964. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4965. utils.ErrorLog("product_date")
  4966. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4967. return
  4968. }
  4969. product_date := int64(items["product_date"].(float64))
  4970. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4971. utils.ErrorLog("number")
  4972. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4973. return
  4974. }
  4975. number := items["number"].(string)
  4976. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4977. utils.ErrorLog("warehousing_info_id")
  4978. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4979. return
  4980. }
  4981. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4982. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  4983. utils.ErrorLog("good_origin_place")
  4984. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4985. return
  4986. }
  4987. good_origin_place := items["good_origin_place"].(string)
  4988. orgId := this.GetAdminUserInfo().CurrentOrgId
  4989. Creater := this.GetAdminUserInfo().AdminUser.Id
  4990. inventory := models.XtStockInventory{
  4991. GoodName: good_name,
  4992. SpecificationName: specification_name,
  4993. WarehousingUnit: warehousing_unit,
  4994. Count: count,
  4995. BuyPrice: buy_price,
  4996. PackingPrice: packing_price,
  4997. NewPrice: 0,
  4998. Manufacturer: manufacturer,
  4999. Dealer: dealer,
  5000. Remark: remark,
  5001. GoodId: good_id,
  5002. UserOrgId: orgId,
  5003. Ctime: time.Now().Unix(),
  5004. Mtime: 0,
  5005. Status: 1,
  5006. WarehousingOrder: warehousing_order,
  5007. LicenseNumber: license_number,
  5008. StartTime: startTime,
  5009. Creater: Creater,
  5010. Checker: 0,
  5011. CheckerStatus: 2,
  5012. CheckerTime: 0,
  5013. Total: total,
  5014. ExpireDate: expiry_date,
  5015. ProductDate: product_date,
  5016. Number: number,
  5017. WarehousingInfoId: warehousing_info_id,
  5018. GoodOriginPlace: good_origin_place,
  5019. }
  5020. err = service.CreateInentory(inventory)
  5021. fmt.Println(err)
  5022. }
  5023. }
  5024. this.ServeSuccessJSON(map[string]interface{}{
  5025. "msg": "保存成功!",
  5026. })
  5027. }
  5028. func (this *StockManagerApiController) GetInventorylist() {
  5029. timeLayout := "2006-01-02"
  5030. loc, _ := time.LoadLocation("Local")
  5031. start_time := this.GetString("start_time")
  5032. end_time := this.GetString("end_time")
  5033. page, _ := this.GetInt64("page")
  5034. limit, _ := this.GetInt64("limit")
  5035. keyword := this.GetString("keyword")
  5036. inventory_status, _ := this.GetInt64("inventory_status")
  5037. var startTime int64
  5038. if len(start_time) > 0 {
  5039. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5040. if err != nil {
  5041. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5042. return
  5043. }
  5044. startTime = theTime.Unix()
  5045. fmt.Println("开始时间", startTime)
  5046. }
  5047. var endTime int64
  5048. if len(end_time) > 0 {
  5049. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5050. if err != nil {
  5051. utils.ErrorLog(err.Error())
  5052. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5053. return
  5054. }
  5055. endTime = theTime.Unix()
  5056. }
  5057. orgId := this.GetAdminUserInfo().CurrentOrgId
  5058. list, total, _ := service.GetInventorylist(startTime, endTime, page, limit, inventory_status, keyword, orgId)
  5059. doctorlist, _ := service.GetAllDoctorThree(orgId)
  5060. this.ServeSuccessJSON(map[string]interface{}{
  5061. "list": list,
  5062. "total": total,
  5063. "doctorlist": doctorlist,
  5064. })
  5065. }
  5066. func (this *StockManagerApiController) SaveCheckInventory() {
  5067. timeLayout := "2006-01-02"
  5068. loc, _ := time.LoadLocation("Local")
  5069. dataBody := make(map[string]interface{}, 0)
  5070. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5071. fmt.Println(err)
  5072. idstr := this.GetString("ids")
  5073. ids := strings.Split(idstr, ",")
  5074. check_time := this.GetString("check_time")
  5075. var checkTime int64
  5076. if len(check_time) > 0 {
  5077. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5078. if err != nil {
  5079. fmt.Println(err)
  5080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5081. return
  5082. }
  5083. checkTime = theTime.Unix()
  5084. }
  5085. checker, _ := this.GetInt64("checker")
  5086. inventory := models.XtStockInventory{
  5087. Checker: checker,
  5088. CheckerStatus: 1,
  5089. CheckerTime: checkTime,
  5090. }
  5091. adminUserInfo := this.GetAdminUserInfo()
  5092. err = service.UpdateCheckInventory(ids, inventory)
  5093. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  5094. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  5095. var manufactuer_id int64
  5096. var dealer_id int64
  5097. //查询耗材信息
  5098. list, _ := service.GetInventoryDetailById(ids)
  5099. for _, item := range list {
  5100. for _, it := range manufacturerList {
  5101. if item.Manufacturer == it.ManufacturerName {
  5102. manufactuer_id = it.ID
  5103. }
  5104. }
  5105. for _, its := range dealerList {
  5106. if item.Dealer == its.DealerName {
  5107. dealer_id = its.ID
  5108. }
  5109. }
  5110. //查寻该批次的库存量
  5111. list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5112. //查询该耗材最后1条批次
  5113. info, _ := service.GetLastWarehouseInfo(item.GoodId)
  5114. good, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5115. fmt.Println("总共", item.Count)
  5116. fmt.Println("数据", list.StockCount)
  5117. //盘点盘点库存和et实际库存的大小
  5118. // 如果盘点库存大于实际库存,怎需要入库
  5119. if item.Count > list.StockCount {
  5120. ctime := time.Now().Unix()
  5121. timeStr := time.Now().Format("2006-01-02")
  5122. timeArr := strings.Split(timeStr, "-")
  5123. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  5124. total = total + 1
  5125. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5126. operation_time := time.Now().Unix()
  5127. creater := adminUserInfo.AdminUser.Id
  5128. warehousing := models.Warehousing{
  5129. WarehousingOrder: warehousing_order,
  5130. OperationTime: operation_time,
  5131. OrgId: adminUserInfo.CurrentOrgId,
  5132. Creater: creater,
  5133. Ctime: ctime,
  5134. Status: 1,
  5135. WarehousingTime: ctime,
  5136. Type: 1,
  5137. }
  5138. service.AddSigleWarehouse(&warehousing)
  5139. //获取最
  5140. //入库单表格
  5141. warehouseInfo := models.WarehousingInfo{
  5142. WarehousingOrder: warehousing.WarehousingOrder,
  5143. WarehousingId: warehousing.ID,
  5144. GoodId: item.GoodId,
  5145. Number: info.Number,
  5146. ProductDate: info.ProductDate,
  5147. ExpiryDate: info.ExpiryDate,
  5148. WarehousingCount: item.Count - list.StockCount,
  5149. Price: info.Price,
  5150. Status: 1,
  5151. Ctime: ctime,
  5152. Remark: item.Remark,
  5153. OrgId: adminUserInfo.CurrentOrgId,
  5154. Type: 1,
  5155. Manufacturer: manufactuer_id,
  5156. StockCount: item.Count - list.StockCount,
  5157. Dealer: dealer_id,
  5158. LicenseNumber: info.LicenseNumber,
  5159. WarehouseInfoId: item.WarehousingInfoId,
  5160. GoodTypeId: good.GoodTypeId,
  5161. }
  5162. flow := models.VmStockFlow{
  5163. WarehousingOrder: warehousing.WarehousingOrder,
  5164. WarehousingId: warehousing.ID,
  5165. GoodId: item.GoodId,
  5166. Number: info.Number,
  5167. ProductDate: info.ProductDate,
  5168. ExpireDate: info.ExpiryDate,
  5169. Count: item.Count - list.StockCount,
  5170. Price: item.BuyPrice,
  5171. Status: 1,
  5172. Ctime: ctime,
  5173. UserOrgId: adminUserInfo.CurrentOrgId,
  5174. Manufacturer: info.Manufacturer,
  5175. Dealer: info.Dealer,
  5176. LicenseNumber: info.LicenseNumber,
  5177. IsEdit: 1,
  5178. Creator: adminUserInfo.AdminUser.Id,
  5179. SystemTime: operation_time,
  5180. ConsumableType: 1,
  5181. WarehousingDetailId: warehouseInfo.ID,
  5182. }
  5183. service.CreateWarehouseInfo(warehouseInfo)
  5184. service.CreateStockFlowOne(flow)
  5185. }
  5186. //如果盘点库存小于实际库存,需要出库
  5187. if item.Count < list.StockCount {
  5188. timeStr := time.Now().Format("2006-01-02")
  5189. timeArr := strings.Split(timeStr, "-")
  5190. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5191. total = total + 1
  5192. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5193. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5194. number = number + total
  5195. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5196. operation_time := time.Now().Unix()
  5197. creater := adminUserInfo.AdminUser.Id
  5198. //查询最早的1条批次
  5199. warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
  5200. warehouseOut := models.WarehouseOut{
  5201. WarehouseOutOrderNumber: warehousing_out_order,
  5202. OperationTime: operation_time,
  5203. OrgId: adminUserInfo.CurrentOrgId,
  5204. Creater: creater,
  5205. Ctime: time.Now().Unix(),
  5206. Status: 1,
  5207. WarehouseOutTime: time.Now().Unix(),
  5208. Type: 1,
  5209. }
  5210. err = service.CreateWarehouseOut(warehouseOut)
  5211. fmt.Println(err)
  5212. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  5213. warehouseOutInfo := &models.WarehouseOutInfo{
  5214. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  5215. WarehouseOutId: out.ID,
  5216. GoodId: warehouseInfo.GoodId,
  5217. Count: list.StockCount - item.Count,
  5218. Price: warehouseInfo.Price,
  5219. Status: 1,
  5220. Ctime: time.Now().Unix(),
  5221. Remark: item.Remark,
  5222. OrgId: adminUserInfo.CurrentOrgId,
  5223. Type: 1,
  5224. Manufacturer: manufactuer_id,
  5225. Number: warehouseInfo.Number,
  5226. ExpiryDate: warehouseInfo.ExpiryDate,
  5227. ProductDate: warehouseInfo.ProductDate,
  5228. Dealer: dealer_id,
  5229. LicenseNumber: warehouseInfo.LicenseNumber,
  5230. GoodTypeId: good.GoodTypeId,
  5231. }
  5232. stockFlow := models.VmStockFlow{
  5233. WarehousingId: item.WarehousingInfoId,
  5234. GoodId: warehouseInfo.GoodId,
  5235. Number: warehouseInfo.Number,
  5236. LicenseNumber: warehouseInfo.LicenseNumber,
  5237. Count: list.StockCount - item.Count,
  5238. UserOrgId: warehouseInfo.OrgId,
  5239. PatientId: 0,
  5240. SystemTime: 0,
  5241. ConsumableType: 2,
  5242. IsSys: 2,
  5243. WarehousingOrder: "",
  5244. WarehouseOutId: out.ID,
  5245. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5246. IsEdit: 1,
  5247. CancelStockId: 0,
  5248. CancelOrderNumber: "",
  5249. Manufacturer: manufactuer_id,
  5250. Dealer: dealer_id,
  5251. Creator: adminUserInfo.AdminUser.Id,
  5252. UpdateCreator: 0,
  5253. Status: 1,
  5254. Ctime: time.Now().Unix(),
  5255. Mtime: 0,
  5256. Price: warehouseInfo.Price,
  5257. WarehousingDetailId: 0,
  5258. WarehouseOutDetailId: out.ID,
  5259. CancelOutDetailId: 0,
  5260. ProductDate: warehouseInfo.ProductDate,
  5261. ExpireDate: warehouseInfo.ExpiryDate,
  5262. }
  5263. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5264. fmt.Println(errOne)
  5265. //创建出库明细
  5266. service.CreateStockFlowOne(stockFlow)
  5267. //更改库存
  5268. warehousingInfos := models.WarehousingInfo{
  5269. StockCount: item.Count,
  5270. }
  5271. service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
  5272. }
  5273. }
  5274. fmt.Println(err)
  5275. this.ServeSuccessJSON(map[string]interface{}{
  5276. "inventory": inventory,
  5277. })
  5278. }
  5279. func (this *StockManagerApiController) GetModifyPriceDetail() {
  5280. id, _ := this.GetInt64("id")
  5281. detail, _ := service.GetModifyPriceDetail(id)
  5282. this.ServeSuccessJSON(map[string]interface{}{
  5283. "detail": detail,
  5284. })
  5285. }
  5286. func (this *StockManagerApiController) UpdateStockPrice() {
  5287. id, _ := this.GetInt64("id")
  5288. newPrice := this.GetString("new_price")
  5289. new_price, _ := strconv.ParseFloat(newPrice, 64)
  5290. good_name := this.GetString("good_name")
  5291. packingPrice := this.GetString("packing_price")
  5292. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5293. remark := this.GetString("remark")
  5294. good_id, _ := this.GetInt64("good_id")
  5295. manufacturer := this.GetString("manufacturer")
  5296. dealer := this.GetString("dealer")
  5297. adjust := models.XtStockAdjustPrice{
  5298. NewPrice: new_price,
  5299. GoodName: good_name,
  5300. PackingPrice: packing_price,
  5301. Remark: remark,
  5302. GoodId: good_id,
  5303. Manufacturer: manufacturer,
  5304. Dealer: dealer,
  5305. }
  5306. err := service.UpdateStockPrice(adjust, id)
  5307. fmt.Println(err)
  5308. this.ServeSuccessJSON(map[string]interface{}{
  5309. "adjust": adjust,
  5310. })
  5311. }
  5312. func (this *StockManagerApiController) DeleteStockPrice() {
  5313. id, _ := this.GetInt64("id")
  5314. err := service.DeleteStockPrice(id)
  5315. fmt.Println(err)
  5316. returnData := make(map[string]interface{}, 0)
  5317. returnData["msg"] = "ok"
  5318. this.ServeSuccessJSON(returnData)
  5319. return
  5320. }
  5321. func (this *StockManagerApiController) GetStockDamageDetail() {
  5322. id, _ := this.GetInt64("id")
  5323. detail, err := service.GetStockDamageDetail(id)
  5324. fmt.Println(err)
  5325. this.ServeSuccessJSON(map[string]interface{}{
  5326. "detail": detail,
  5327. })
  5328. }
  5329. func (this *StockManagerApiController) ModifyPrice() {
  5330. count, _ := this.GetInt64("count")
  5331. id, _ := this.GetInt64("id")
  5332. good_name := this.GetString("good_name")
  5333. specification_name := this.GetString("specification_name")
  5334. number := this.GetString("number")
  5335. warehousing_unit := this.GetString("warehousing_unit")
  5336. buyPrice := this.GetString("buy_price")
  5337. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5338. packingPrice := this.GetString("packing_price")
  5339. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5340. good_origin_place := this.GetString("good_origin_place")
  5341. manufacturer := this.GetString("manufacturer")
  5342. dealer := this.GetString("dealer")
  5343. total, _ := this.GetInt64("total")
  5344. remark := this.GetString("remark")
  5345. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5346. good_id, _ := this.GetInt64("good_id")
  5347. adjust := models.XtStockReportPrice{
  5348. Count: count,
  5349. SpecificationName: specification_name,
  5350. Number: number,
  5351. GoodName: good_name,
  5352. WarehousingUnit: warehousing_unit,
  5353. BuyPrice: buy_price,
  5354. PackingPrice: packing_price,
  5355. GoodOriginPlace: good_origin_place,
  5356. Manufacturer: manufacturer,
  5357. Dealer: dealer,
  5358. Total: total,
  5359. Remark: remark,
  5360. WarehousingInfoId: warehousing_info_id,
  5361. GoodId: good_id,
  5362. }
  5363. err := service.ModifyPrice(id, adjust)
  5364. fmt.Println(err)
  5365. this.ServeSuccessJSON(map[string]interface{}{
  5366. "adjust": adjust,
  5367. })
  5368. }
  5369. func (this *StockManagerApiController) DeleteDamage() {
  5370. id, _ := this.GetInt64("id")
  5371. err := service.DeleteDamage(id)
  5372. fmt.Println(err)
  5373. returnData := make(map[string]interface{}, 0)
  5374. returnData["msg"] = "ok"
  5375. this.ServeSuccessJSON(returnData)
  5376. return
  5377. }
  5378. func (this *StockManagerApiController) GetStockDamageById() {
  5379. ids := this.GetString("ids")
  5380. splitIds := strings.Split(ids, ",")
  5381. list, _ := service.GetStockDamageById(splitIds)
  5382. this.ServeSuccessJSON(map[string]interface{}{
  5383. "list": list,
  5384. })
  5385. }
  5386. func (this *StockManagerApiController) GetInventoryDetail() {
  5387. id, _ := this.GetInt64("id")
  5388. detail, _ := service.GetInventoryDetail(id)
  5389. this.ServeSuccessJSON(map[string]interface{}{
  5390. "detail": detail,
  5391. })
  5392. }
  5393. func (this *StockManagerApiController) ModifyInventory() {
  5394. id, _ := this.GetInt64("id")
  5395. good_id, _ := this.GetInt64("good_id")
  5396. good_name := this.GetString("good_name")
  5397. specification_name := this.GetString("specification_name")
  5398. number := this.GetString("number")
  5399. warehousing_unit := this.GetString("warehousing_unit")
  5400. buyPrice := this.GetString("buy_price")
  5401. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5402. packingPrice := this.GetString("packing_price")
  5403. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5404. total, _ := this.GetInt64("total")
  5405. good_origin_place := this.GetString("good_origin_place")
  5406. license_number := this.GetString("license_number")
  5407. dealer := this.GetString("dealer")
  5408. manufacturer := this.GetString("manufacturer")
  5409. count, _ := this.GetInt64("count")
  5410. remark := this.GetString("remark")
  5411. inventory := models.XtStockInventory{
  5412. GoodId: good_id,
  5413. GoodName: good_name,
  5414. SpecificationName: specification_name,
  5415. Number: number,
  5416. WarehousingUnit: warehousing_unit,
  5417. BuyPrice: buy_price,
  5418. PackingPrice: packing_price,
  5419. Total: total,
  5420. GoodOriginPlace: good_origin_place,
  5421. LicenseNumber: license_number,
  5422. Dealer: dealer,
  5423. Manufacturer: manufacturer,
  5424. Count: count,
  5425. Remark: remark,
  5426. }
  5427. err := service.ModifyInventory(id, inventory)
  5428. fmt.Println(err)
  5429. this.ServeSuccessJSON(map[string]interface{}{
  5430. "inventory": inventory,
  5431. })
  5432. }
  5433. func (this *StockManagerApiController) DeleteInventory() {
  5434. id, _ := this.GetInt64("id")
  5435. err := service.DeleteInventory(id)
  5436. fmt.Println(err)
  5437. returnData := make(map[string]interface{}, 0)
  5438. returnData["msg"] = "ok"
  5439. this.ServeSuccessJSON(returnData)
  5440. return
  5441. }
  5442. func (this *StockManagerApiController) GetInventoryDetailList() {
  5443. keyword := this.GetString("keyword")
  5444. limit, _ := this.GetInt64("limit")
  5445. page, _ := this.GetInt64("page")
  5446. orgId := this.GetAdminUserInfo().CurrentOrgId
  5447. list, total, _ := service.GetInventoryDetailList(keyword, limit, page, orgId)
  5448. this.ServeSuccessJSON(map[string]interface{}{
  5449. "list": list,
  5450. "total": total,
  5451. })
  5452. }
  5453. func (this *StockManagerApiController) GetInventoryPrintList() {
  5454. ids := this.GetString("ids")
  5455. splitIds := strings.Split(ids, ",")
  5456. list, _ := service.GetInventoryPrintList(splitIds)
  5457. this.ServeSuccessJSON(map[string]interface{}{
  5458. "list": list,
  5459. })
  5460. }
  5461. func (this *StockManagerApiController) GetInventoryDetailPrintList() {
  5462. ids := this.GetString("ids")
  5463. splitIds := strings.Split(ids, ",")
  5464. list, _ := service.GetInventoryDetailPrintList(splitIds)
  5465. this.ServeSuccessJSON(map[string]interface{}{
  5466. "list": list,
  5467. })
  5468. }
  5469. func (this *StockManagerApiController) DeleteDrugPrice() {
  5470. id, _ := this.GetInt64("id")
  5471. err := service.DeleteDrugPrice(id)
  5472. fmt.Println(err)
  5473. returnData := make(map[string]interface{}, 0)
  5474. returnData["msg"] = "ok"
  5475. this.ServeSuccessJSON(returnData)
  5476. return
  5477. }
  5478. func (this *StockManagerApiController) GetGoodWarehouseList() {
  5479. id, _ := this.GetInt64("id")
  5480. list, _ := service.GetGoodWarehouseList(id)
  5481. this.ServeSuccessJSON(map[string]interface{}{
  5482. "list": list,
  5483. })
  5484. }
  5485. func (this *StockManagerApiController) ProofInventory() {
  5486. id, _ := this.GetInt64("id")
  5487. good_id, _ := this.GetInt64("good_id")
  5488. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5489. proof_count, _ := this.GetInt64("proof_count")
  5490. total, _ := this.GetInt64("total")
  5491. orgId := this.GetAdminUserInfo().CurrentOrgId
  5492. creater := this.GetAdminUserInfo().AdminUser.Id
  5493. info := models.WarehousingInfo{
  5494. GoodId: good_id,
  5495. StockCount: proof_count,
  5496. }
  5497. err := service.UpdateProofInventory(warehousing_info_id, info)
  5498. inventory := models.XtStockInventory{
  5499. Total: proof_count,
  5500. }
  5501. err = service.UpdateStockInventory(inventory, id)
  5502. fmt.Println(err)
  5503. record := models.XtStockCorrectRecord{
  5504. GoodId: good_id,
  5505. OrdCount: total,
  5506. WarehousingInfoId: warehousing_info_id,
  5507. NewCount: proof_count,
  5508. UserOrgId: orgId,
  5509. Status: 1,
  5510. Creater: creater,
  5511. Ctime: time.Now().Unix(),
  5512. Mtime: 0,
  5513. }
  5514. service.CeateStockCorrectRecord(record)
  5515. this.ServeSuccessJSON(map[string]interface{}{
  5516. "list": info,
  5517. })
  5518. }
  5519. func (this *StockManagerApiController) GetWarehouseTotal() {
  5520. id, _ := this.GetInt64("id")
  5521. list, _ := service.GetWarehouseTotal(id)
  5522. this.ServeSuccessJSON(map[string]interface{}{
  5523. "list": list,
  5524. })
  5525. }
  5526. func (this *StockManagerApiController) GetGoodInventoryWarehouseList() {
  5527. id, _ := this.GetInt64("id")
  5528. list, _ := service.GetGoodInventoryWarehouseList(id)
  5529. orgId := this.GetAdminUserInfo().CurrentOrgId
  5530. fmt.Println(orgId)
  5531. this.ServeSuccessJSON(map[string]interface{}{
  5532. "list": list,
  5533. })
  5534. }
  5535. func (this *StockManagerApiController) SaveStockInventoryList() {
  5536. dataBody := make(map[string]interface{}, 0)
  5537. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5538. fmt.Println(err)
  5539. tableData, _ := dataBody["tableData"].([]interface{})
  5540. if len(tableData) > 0 {
  5541. for _, item := range tableData {
  5542. items := item.(map[string]interface{})
  5543. good_name := items["good_name"].(string)
  5544. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5545. utils.ErrorLog("good_name")
  5546. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5547. return
  5548. }
  5549. specification_name := items["specification_name"].(string)
  5550. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5551. utils.ErrorLog("specification_name")
  5552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5553. return
  5554. }
  5555. warehousing_unit := items["warehousing_unit"].(string)
  5556. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5557. utils.ErrorLog("warehousing_unit")
  5558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5559. return
  5560. }
  5561. stock_count := int64(items["stock_count"].(float64))
  5562. if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
  5563. utils.ErrorLog("stock_count")
  5564. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5565. return
  5566. }
  5567. price := items["price"].(float64)
  5568. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
  5569. utils.ErrorLog("price")
  5570. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5571. return
  5572. }
  5573. manufacturer_name := items["manufacturer_name"].(string)
  5574. if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
  5575. utils.ErrorLog("manufacturer_name")
  5576. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5577. return
  5578. }
  5579. good_id := int64(items["good_id"].(float64))
  5580. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5581. utils.ErrorLog("good_id")
  5582. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5583. return
  5584. }
  5585. manufacturer := int64(items["manufacturer"].(float64))
  5586. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
  5587. utils.ErrorLog("manufacturer")
  5588. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5589. return
  5590. }
  5591. warehousing_order := items["warehousing_order"].(string)
  5592. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5593. utils.ErrorLog("warehousing_order")
  5594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5595. return
  5596. }
  5597. number := items["number"].(string)
  5598. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5599. utils.ErrorLog("number")
  5600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5601. return
  5602. }
  5603. id := int64(items["id"].(float64))
  5604. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5605. utils.ErrorLog("id")
  5606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5607. return
  5608. }
  5609. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  5610. utils.ErrorLog("expiry_date")
  5611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5612. return
  5613. }
  5614. expiry_date := int64(items["expiry_date"].(float64))
  5615. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  5616. utils.ErrorLog("product_date")
  5617. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5618. return
  5619. }
  5620. product_date := int64(items["product_date"].(float64))
  5621. orgId := this.GetAdminUserInfo().CurrentOrgId
  5622. adminId := this.GetAdminUserInfo().AdminUser.Id
  5623. stock_type := int64(items["type"].(float64))
  5624. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5625. utils.ErrorLog("type")
  5626. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5627. return
  5628. }
  5629. last_stock_count := int64(items["last_stock_count"].(float64))
  5630. if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
  5631. utils.ErrorLog("last_stock_count")
  5632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5633. return
  5634. }
  5635. var total_count int64
  5636. var inventory_type int64
  5637. fmt.Println("盘点前", stock_count)
  5638. fmt.Println("盘点后", last_stock_count)
  5639. if stock_count > last_stock_count {
  5640. total_count = stock_count - last_stock_count
  5641. inventory_type = 11
  5642. }
  5643. if stock_count < last_stock_count {
  5644. total_count = last_stock_count - stock_count
  5645. inventory_type = 10
  5646. }
  5647. creater := this.GetAdminUserInfo().AdminUser.Id
  5648. inventory := models.XtStockInventory{
  5649. GoodName: good_name,
  5650. SpecificationName: specification_name,
  5651. WarehousingUnit: warehousing_unit,
  5652. Count: total_count,
  5653. BuyPrice: price,
  5654. PackingPrice: price,
  5655. NewPrice: 0,
  5656. Manufacturer: manufacturer_name,
  5657. Dealer: "",
  5658. Remark: "",
  5659. GoodId: good_id,
  5660. UserOrgId: orgId,
  5661. Ctime: time.Now().Unix(),
  5662. Mtime: 0,
  5663. Status: 1,
  5664. WarehousingOrder: warehousing_order,
  5665. LicenseNumber: number,
  5666. StartTime: time.Now().Unix(),
  5667. Creater: adminId,
  5668. Checker: 0,
  5669. CheckerStatus: 0,
  5670. CheckerTime: 0,
  5671. Total: 0,
  5672. Number: number,
  5673. WarehousingInfoId: id,
  5674. ExpireDate: expiry_date,
  5675. ProductDate: product_date,
  5676. GoodOriginPlace: "",
  5677. Type: 10,
  5678. InventoryType: stock_type,
  5679. LastStockCount: last_stock_count,
  5680. StockCount: stock_count,
  5681. }
  5682. service.CreateInentory(inventory)
  5683. stockFlow := models.VmStockFlow{
  5684. WarehousingId: 0,
  5685. GoodId: good_id,
  5686. Number: number,
  5687. LicenseNumber: "",
  5688. Count: total_count,
  5689. UserOrgId: orgId,
  5690. PatientId: 0,
  5691. SystemTime: 0,
  5692. ConsumableType: inventory_type,
  5693. IsSys: 0,
  5694. WarehousingOrder: "",
  5695. WarehouseOutId: 0,
  5696. WarehouseOutOrderNumber: warehousing_order,
  5697. IsEdit: 0,
  5698. CancelStockId: 0,
  5699. CancelOrderNumber: "",
  5700. Manufacturer: manufacturer,
  5701. Dealer: 0,
  5702. Creator: creater,
  5703. UpdateCreator: 0,
  5704. Status: 1,
  5705. Ctime: time.Now().Unix(),
  5706. Mtime: 0,
  5707. Price: price,
  5708. WarehousingDetailId: 0,
  5709. WarehouseOutDetailId: 0,
  5710. CancelOutDetailId: 0,
  5711. ProductDate: product_date,
  5712. ExpireDate: expiry_date,
  5713. ReturnCount: 0,
  5714. }
  5715. info := models.WarehousingInfo{
  5716. StockCount: last_stock_count,
  5717. }
  5718. //更改库存
  5719. service.UpdatedWarehousingInfo(info, id)
  5720. if stock_count != last_stock_count {
  5721. service.CreateStockFlowOne(stockFlow)
  5722. }
  5723. this.ServeSuccessJSON(map[string]interface{}{
  5724. "inventory": inventory,
  5725. })
  5726. }
  5727. }
  5728. }
  5729. func (this *StockManagerApiController) GetDamageDetailByGoodId() {
  5730. good_id, _ := this.GetInt64("good_id")
  5731. warehousing_order := this.GetString("warehousing_order")
  5732. inventory_type, _ := this.GetInt64("type")
  5733. fmt.Println("inventory_type23232323223322332", inventory_type)
  5734. list, _ := service.GetDamageDetailByGoodId(good_id, warehousing_order, inventory_type)
  5735. orgId := this.GetAdminUserInfo().CurrentOrgId
  5736. damageList, _ := service.GetStockDamagedCountOne(orgId, warehousing_order, inventory_type)
  5737. this.ServeSuccessJSON(map[string]interface{}{
  5738. "list": list,
  5739. "damageList": damageList,
  5740. })
  5741. }
  5742. func (this *StockManagerApiController) GetInventoryExportList() {
  5743. orgId := this.GetAdminUserInfo().CurrentOrgId
  5744. list, _ := service.GetInventoryExportList(orgId)
  5745. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  5746. this.ServeSuccessJSON(map[string]interface{}{
  5747. "list": list,
  5748. "manufacturerList": manufacturerList,
  5749. })
  5750. }