stock_in_api_controller.go 256KB

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