stock_in_api_controller.go 257KB

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