stock_in_api_controller.go 230KB

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