stock_in_api_controller.go 238KB

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