stock_in_api_controller.go 262KB

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