stock_in_api_controller.go 260KB

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