stock_in_api_controller.go 256KB

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