stock_in_api_controller.go 279KB

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