stock_in_api_controller.go 257KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804
  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. }
  127. func (c *StockManagerApiController) HandleRefundStock() {
  128. order_id, _ := c.GetInt64("order_id", 0)
  129. order, _ := service.GetHisOrderByIDThree(order_id)
  130. if order.ID == 0 {
  131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  132. return
  133. }
  134. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  135. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  136. var goods []*models.DialysisBeforePrepareGoods
  137. var newGoods []*models.NewDialysisBeforePrepareGoods
  138. var infos []*models.HisDoctorAdviceInfo
  139. for _, info := range orders {
  140. if info.AdviceId > 0 && info.ProjectId == 0 {
  141. infos = append(infos, &info.HisDoctorAdviceInfo)
  142. }
  143. if info.ProjectId > 0 && info.AdviceId == 0 {
  144. if info.HisPrescriptionProject.Type == 3 {
  145. var good models.DialysisBeforePrepareGoods
  146. var newGood models.NewDialysisBeforePrepareGoods
  147. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  148. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  149. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  150. good.Count = int64(count)
  151. good.StorehouseId = houseConfig.StorehouseOutInfo
  152. good.ProjectId = info.HisPrescriptionProject.ID
  153. goods = append(goods, &good)
  154. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  155. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  156. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  157. newGood.Count = int64(count2)
  158. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  159. newGood.ProjectId = info.HisPrescriptionProject.ID
  160. newGoods = append(newGoods, &newGood)
  161. }
  162. }
  163. }
  164. for _, item := range infos {
  165. //service.HisDrugsDelivery(item.UserOrgId, order.Creator, item)
  166. service.DrugAutoAddCancelInfo(item, order.Creator)
  167. }
  168. }
  169. func (c *StockManagerApiController) HandleSettleStock() {
  170. order_id, _ := c.GetInt64("order_id", 0)
  171. order, _ := service.GetHisOrderByID(order_id)
  172. if order.ID == 0 {
  173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. return
  175. }
  176. orders, _ := service.GetHisOrderDetailByNumberTwo(order.Number, order.UserOrgId)
  177. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  178. var goods []*models.DialysisBeforePrepareGoods
  179. var newGoods []*models.NewDialysisBeforePrepareGoods
  180. var infos []*models.HisDoctorAdviceInfo
  181. for _, info := range orders {
  182. if info.AdviceId > 0 && info.ProjectId == 0 {
  183. infos = append(infos, &info.HisDoctorAdviceInfo)
  184. }
  185. if info.ProjectId > 0 && info.AdviceId == 0 {
  186. if info.HisPrescriptionProject.Type == 3 {
  187. var good models.DialysisBeforePrepareGoods
  188. var newGood models.NewDialysisBeforePrepareGoods
  189. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  190. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  191. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  192. good.Count = int64(count)
  193. good.StorehouseId = houseConfig.StorehouseOutInfo
  194. good.ProjectId = info.HisPrescriptionProject.ID
  195. goods = append(goods, &good)
  196. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  197. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  198. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  199. newGood.Count = int64(count2)
  200. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  201. newGood.ProjectId = info.HisPrescriptionProject.ID
  202. newGoods = append(newGoods, &newGood)
  203. }
  204. }
  205. }
  206. service.ConsumablesDeliveryTotal(order.UserOrgId, order.PatientId, order.SettleAccountsDate, goods, newGoods, order.Creator)
  207. for _, item := range infos {
  208. service.HisDrugsDelivery(item.UserOrgId, order.Creator, item)
  209. }
  210. }
  211. func (c *StockManagerApiController) CreateWarehouse() {
  212. warehousing_time := c.GetString("warehousing_time")
  213. types, _ := c.GetInt64("type", 0)
  214. storehouse_id, _ := c.GetInt64("storehouse_id")
  215. warehousing_info_id, _ := c.GetInt64("warehousing_info_id")
  216. ctime := time.Now().Unix()
  217. adminUserInfo := c.GetAdminUserInfo()
  218. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  219. if parseDateErr != nil {
  220. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  222. return
  223. }
  224. timeStr := time.Now().Format("2006-01-02")
  225. timeArr := strings.Split(timeStr, "-")
  226. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  227. total = total + 1
  228. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  229. operation_time := time.Now().Unix()
  230. creater := adminUserInfo.AdminUser.Id
  231. warehousing := models.Warehousing{
  232. WarehousingOrder: warehousing_order,
  233. OperationTime: operation_time,
  234. OrgId: adminUserInfo.CurrentOrgId,
  235. Creater: creater,
  236. Ctime: ctime,
  237. Status: 1,
  238. WarehousingTime: warehousingDate.Unix(),
  239. Type: types,
  240. StorehouseId: storehouse_id,
  241. IsCheck: 2,
  242. }
  243. if warehousing_info_id == 0 {
  244. service.AddSigleWarehouse(&warehousing)
  245. }
  246. if warehousing_info_id > 0 {
  247. service.UpdateWarehouse(warehousing_info_id, storehouse_id)
  248. }
  249. info, _ := service.FindLastWarehousingSix(adminUserInfo.CurrentOrgId)
  250. dataBody := make(map[string]interface{}, 0)
  251. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  252. if err != nil {
  253. utils.ErrorLog(err.Error())
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. return
  256. }
  257. var warehousingInfo []*models.WarehousingInfo
  258. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  259. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  260. if len(thisStockIn) > 0 {
  261. for _, item := range thisStockIn {
  262. items := item.(map[string]interface{})
  263. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  264. utils.ErrorLog("id")
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. id := int64(items["id"].(float64))
  269. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  270. utils.ErrorLog("good_id")
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  272. return
  273. }
  274. good_id := int64(items["good_id"].(float64))
  275. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  276. utils.ErrorLog("good_type_id")
  277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  278. return
  279. }
  280. good_type_id := int64(items["good_type_id"].(float64))
  281. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  282. utils.ErrorLog("warehousing_count")
  283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  284. return
  285. }
  286. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  287. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  288. utils.ErrorLog("price")
  289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  290. return
  291. }
  292. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  293. total := float64(warehousing_count) * price
  294. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  295. utils.ErrorLog("packing_price")
  296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  297. return
  298. }
  299. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  300. var productDates int64
  301. var expiryDates int64
  302. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  303. expiryDates = 0
  304. } else {
  305. if len(items["expiry_date"].(string)) == 0 {
  306. expiryDates = 0
  307. } else {
  308. expiryDate, _ := items["expiry_date"].(string)
  309. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  310. expiryDates = expiry_date.Unix()
  311. }
  312. }
  313. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  314. productDates = 0
  315. } else {
  316. if len(items["product_date"].(string)) == 0 {
  317. productDates = 0
  318. } else {
  319. productDate, _ := items["product_date"].(string)
  320. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  321. productDates = product_date.Unix()
  322. }
  323. }
  324. number, _ := items["number"].(string)
  325. remark, _ := items["remark"].(string)
  326. manufacturer := int64(items["manufacturer"].(float64))
  327. dealer := int64(items["dealer"].(float64))
  328. license_number, _ := items["license_number"].(string)
  329. register_number, _ := items["register_number"].(string)
  330. //入库单表格
  331. warehouseInfo := &models.WarehousingInfo{
  332. ID: id,
  333. WarehousingOrder: warehousing.WarehousingOrder,
  334. WarehousingId: info.ID,
  335. GoodId: good_id,
  336. Number: number,
  337. GoodTypeId: good_type_id,
  338. ProductDate: productDates,
  339. ExpiryDate: expiryDates,
  340. WarehousingCount: warehousing_count,
  341. Price: price,
  342. TotalPrice: total,
  343. Status: 1,
  344. Ctime: ctime,
  345. Remark: remark,
  346. OrgId: adminUserInfo.CurrentOrgId,
  347. Type: types,
  348. Manufacturer: manufacturer,
  349. StockCount: 0,
  350. Dealer: dealer,
  351. LicenseNumber: license_number,
  352. PackingPrice: packing_price,
  353. StorehouseId: storehouse_id,
  354. IsCheck: 2,
  355. RegisterNumber: register_number,
  356. }
  357. warehousingInfo = append(warehousingInfo, warehouseInfo)
  358. }
  359. }
  360. }
  361. for _, item := range warehousingInfo {
  362. if item.ID == 0 {
  363. service.CreatedWarehouseingDetail(item)
  364. }
  365. if item.ID > 0 {
  366. service.UpdateWarehouseDetail(item, item.ID)
  367. }
  368. }
  369. //查询入库数据
  370. list, _ := service.GetGoodWarehouseInfoById(info.ID, info.OrgId)
  371. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  372. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  373. c.ServeSuccessJSON(map[string]interface{}{
  374. "msg": "入库成功",
  375. "warehousing_order": warehousing_order,
  376. "info": info,
  377. "list": list,
  378. "dealerList": dealerList,
  379. "manufacturerList": manufacturerList,
  380. })
  381. }
  382. func (c *StockManagerApiController) GetWarehouseList() {
  383. page, _ := c.GetInt64("page", -1)
  384. limit, _ := c.GetInt64("limit", -1)
  385. start_time := c.GetString("start_time")
  386. end_time := c.GetString("end_time")
  387. types, _ := c.GetInt64("type", 0)
  388. keywords := c.GetString("keywords")
  389. storehouse_id, _ := c.GetInt64("storehouse_id")
  390. check_type, _ := c.GetInt64("check_type")
  391. timeLayout := "2006-01-02"
  392. loc, _ := time.LoadLocation("Local")
  393. var startTime int64
  394. if len(start_time) > 0 {
  395. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  396. if err != nil {
  397. fmt.Println(err)
  398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  399. return
  400. }
  401. startTime = theTime.Unix()
  402. }
  403. var endTime int64
  404. if len(end_time) > 0 {
  405. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  406. if err != nil {
  407. utils.ErrorLog(err.Error())
  408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  409. return
  410. }
  411. endTime = theTime.Unix()
  412. }
  413. adminUserInfo := c.GetAdminUserInfo()
  414. var ids []int64
  415. var goodids []int64
  416. //查询商品名称
  417. if len(keywords) > 0 {
  418. //查询商品名称
  419. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  420. for _, item := range list {
  421. goodids = append(goodids, item.ID)
  422. //入库详情但里面查询
  423. }
  424. if len(goodids) > 0 {
  425. info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id)
  426. for _, it := range info {
  427. ids = append(ids, it.WarehousingId)
  428. }
  429. }
  430. }
  431. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id, check_type)
  432. houselist, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  433. if err == nil {
  434. c.ServeSuccessJSON(map[string]interface{}{
  435. "list": warehouseList,
  436. "total": total,
  437. "houselist": houselist,
  438. })
  439. } else {
  440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  441. }
  442. }
  443. func (c *StockManagerApiController) GetWarehouseInfoList() {
  444. id := c.GetString("id")
  445. idArray := strings.Split(id, ",")
  446. warehousing, err := service.FindWarehousingByIdOne(idArray)
  447. if err != nil {
  448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  449. return
  450. }
  451. var ids []int64
  452. for _, item := range warehousing {
  453. ids = append(ids, item.ID)
  454. }
  455. warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
  456. if err == nil {
  457. c.ServeSuccessJSON(map[string]interface{}{
  458. "info": warehousingInfo,
  459. "warehousing": warehousing,
  460. })
  461. } else {
  462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  463. }
  464. }
  465. func (c *StockManagerApiController) EditWarehouse() {
  466. warehousing_time := c.GetString("warehousing_time")
  467. id, _ := c.GetInt64("id", 0)
  468. types, _ := c.GetInt64("type", 0)
  469. storehouse_id, _ := c.GetInt64("storehouse_id")
  470. if id == 0 {
  471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  472. return
  473. }
  474. ctime := time.Now().Unix()
  475. mtime := time.Now().Unix()
  476. adminUserInfo := c.GetAdminUserInfo()
  477. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  478. if parseDateErr != nil {
  479. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  481. return
  482. }
  483. warehouse, _ := service.FindWarehousingById(id)
  484. warehousing := models.Warehousing{
  485. WarehousingOrder: warehouse.WarehousingOrder,
  486. OrgId: adminUserInfo.CurrentOrgId,
  487. Modifier: adminUserInfo.AdminUser.Id,
  488. Mtime: mtime,
  489. Status: 1,
  490. WarehousingTime: warehousingDate.Unix(),
  491. Type: warehouse.Type,
  492. StorehouseId: storehouse_id,
  493. }
  494. service.EditWarehousing(warehousing)
  495. dataBody := make(map[string]interface{}, 0)
  496. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  497. if err != nil {
  498. utils.ErrorLog(err.Error())
  499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  500. return
  501. }
  502. var warehousingInfo []*models.WarehousingInfo
  503. var upDateWarehousingInfo []*models.WarehousingInfo
  504. var stockFlow []*models.VmStockFlow
  505. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  506. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  507. if len(thisStockIn) > 0 {
  508. for _, item := range thisStockIn {
  509. items := item.(map[string]interface{})
  510. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  511. utils.ErrorLog("good_id")
  512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  513. return
  514. }
  515. good_id := int64(items["good_id"].(float64))
  516. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  517. utils.ErrorLog("good_type_id")
  518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  519. return
  520. }
  521. good_type_id := int64(items["good_type_id"].(float64))
  522. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  523. utils.ErrorLog("warehousing_count")
  524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  525. return
  526. }
  527. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  528. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  529. utils.ErrorLog("price")
  530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  531. return
  532. }
  533. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  534. total := float64(warehousing_count) * price
  535. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  536. utils.ErrorLog("packing_price")
  537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  538. return
  539. }
  540. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  541. var productDates int64
  542. var expiryDates int64
  543. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  544. expiryDates = 0
  545. } else {
  546. if len(items["expiry_date"].(string)) == 0 {
  547. expiryDates = 0
  548. } else {
  549. expiryDate, _ := items["expiry_date"].(string)
  550. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  551. expiryDates = expiry_date.Unix()
  552. }
  553. }
  554. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  555. productDates = 0
  556. } else {
  557. if len(items["product_date"].(string)) == 0 {
  558. productDates = 0
  559. } else {
  560. productDate, _ := items["product_date"].(string)
  561. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  562. productDates = product_date.Unix()
  563. }
  564. }
  565. number, _ := items["number"].(string)
  566. remark, _ := items["remark"].(string)
  567. manufacturer := int64(items["manufacturer"].(float64))
  568. dealer := int64(items["dealer"].(float64))
  569. license_number, _ := items["license_number"].(string)
  570. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  571. utils.ErrorLog("id")
  572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  573. return
  574. }
  575. id := int64(items["id"].(float64))
  576. if id == 0 {
  577. warehouseInfo := &models.WarehousingInfo{
  578. WarehousingOrder: warehouse.WarehousingOrder,
  579. WarehousingId: warehouse.ID,
  580. GoodId: good_id,
  581. Number: number,
  582. GoodTypeId: good_type_id,
  583. ProductDate: productDates,
  584. ExpiryDate: expiryDates,
  585. WarehousingCount: warehousing_count,
  586. Price: price,
  587. TotalPrice: total,
  588. Status: 1,
  589. Ctime: ctime,
  590. Remark: remark,
  591. OrgId: adminUserInfo.CurrentOrgId,
  592. Type: types,
  593. Manufacturer: manufacturer,
  594. Dealer: dealer,
  595. StockCount: warehousing_count,
  596. LicenseNumber: license_number,
  597. PackingPrice: packing_price,
  598. StorehouseId: storehouse_id,
  599. IsCheck: 2,
  600. }
  601. warehousingInfo = append(warehousingInfo, warehouseInfo)
  602. } else {
  603. warehouseInfo := &models.WarehousingInfo{
  604. ID: id,
  605. WarehousingOrder: warehouse.WarehousingOrder,
  606. WarehousingId: warehouse.ID,
  607. GoodId: good_id,
  608. Number: number,
  609. GoodTypeId: good_type_id,
  610. ProductDate: productDates,
  611. ExpiryDate: expiryDates,
  612. WarehousingCount: warehousing_count,
  613. Price: price,
  614. TotalPrice: total,
  615. Status: 1,
  616. Ctime: ctime,
  617. Remark: remark,
  618. OrgId: adminUserInfo.CurrentOrgId,
  619. Type: types,
  620. Manufacturer: manufacturer,
  621. Dealer: dealer,
  622. LicenseNumber: license_number,
  623. PackingPrice: packing_price,
  624. StorehouseId: storehouse_id,
  625. }
  626. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  627. flow := &models.VmStockFlow{
  628. WarehousingOrder: warehousing.WarehousingOrder,
  629. WarehousingId: id,
  630. GoodId: good_id,
  631. Number: number,
  632. ProductDate: productDates,
  633. ExpireDate: expiryDates,
  634. Count: warehousing_count,
  635. Price: price,
  636. Status: 1,
  637. Ctime: ctime,
  638. UserOrgId: adminUserInfo.CurrentOrgId,
  639. Manufacturer: manufacturer,
  640. Dealer: dealer,
  641. LicenseNumber: license_number,
  642. IsEdit: 2,
  643. Creator: adminUserInfo.AdminUser.Id,
  644. SystemTime: ctime,
  645. ConsumableType: 1,
  646. WarehousingDetailId: warehouseInfo.ID,
  647. StorehouseId: storehouse_id,
  648. }
  649. stockFlow = append(stockFlow, flow)
  650. }
  651. }
  652. }
  653. }
  654. var errs error
  655. if len(warehousingInfo) > 0 {
  656. errs = service.CreateWarehousingInfo(warehousingInfo)
  657. }
  658. if len(upDateWarehousingInfo) > 0 {
  659. for _, item := range upDateWarehousingInfo {
  660. service.UpdateWarehouseInfoByGoodIdOne(item, item.ID)
  661. }
  662. }
  663. if errs != nil {
  664. utils.ErrorLog(errs.Error())
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  666. return
  667. }
  668. list, _ := service.GetAllStockInList(id, adminUserInfo.CurrentOrgId)
  669. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  670. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "msg": "编辑成功",
  673. "list": list,
  674. "manufacturerList": manufacturerList,
  675. "dealerList": dealerList,
  676. })
  677. }
  678. func (c *StockManagerApiController) DeleteWarehouse() {
  679. ids := c.GetString("ids")
  680. if len(ids) == 0 {
  681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  682. return
  683. }
  684. idArray := strings.Split(ids, ",")
  685. err := service.DeleteWarehouse(idArray)
  686. //删除流水
  687. service.DeleteStockFlow(idArray)
  688. if err != nil {
  689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  690. } else {
  691. c.ServeSuccessJSON(map[string]interface{}{
  692. "msg": "删除成功",
  693. })
  694. }
  695. }
  696. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  697. id, _ := c.GetInt64("id", 0)
  698. if id == 0 {
  699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  700. return
  701. }
  702. orgId := c.GetAdminUserInfo().CurrentOrgId
  703. err := service.UpDateWarehouseStatus(id)
  704. service.UpdatedStockFlowById(id)
  705. //查询入库记录
  706. info, _ := service.GetWarehouseInfoByIdTwenty(id, orgId)
  707. //查询该机构默认仓库
  708. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  709. //查询剩余库存
  710. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, orgId)
  711. var sum_count int64
  712. var sum_in_count int64
  713. for _, item := range goodList {
  714. sum_count += item.StockCount
  715. sum_in_count += item.WarehousingCount
  716. }
  717. service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
  718. if err != nil {
  719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  720. } else {
  721. c.ServeSuccessJSON(map[string]interface{}{
  722. "msg": "删除成功",
  723. })
  724. }
  725. }
  726. func (c *StockManagerApiController) CreateSalesReturn() {
  727. dealer_id, _ := c.GetInt64("dealer_id", 0)
  728. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  729. sales_return_time := c.GetString("time")
  730. types, _ := c.GetInt64("type", 0)
  731. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  732. if parseDateErr != nil {
  733. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  735. return
  736. }
  737. adminUserInfo := c.GetAdminUserInfo()
  738. operation_time := time.Now().Unix()
  739. creater := adminUserInfo.AdminUser.Id
  740. ctime := time.Now().Unix()
  741. timeStr := time.Now().Format("2006-01-02")
  742. timeArr := strings.Split(timeStr, "-")
  743. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  744. total = total + 1
  745. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  746. salesReturn := models.SalesReturn{
  747. OrderNumber: orderNumber,
  748. OperaTime: operation_time,
  749. OrgId: adminUserInfo.CurrentOrgId,
  750. Creater: creater,
  751. Ctime: ctime,
  752. Status: 1,
  753. ReturnTime: salesReturnDate.Unix(),
  754. Dealer: dealer_id,
  755. Manufacturer: manufacturer_id,
  756. Type: types,
  757. }
  758. service.AddSigleSalesReturn(&salesReturn)
  759. dataBody := make(map[string]interface{}, 0)
  760. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  761. if err != nil {
  762. utils.ErrorLog(err.Error())
  763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  764. return
  765. }
  766. var salesReturnInfos []*models.SalesReturnInfo
  767. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  768. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  769. if len(thisStockIn) > 0 {
  770. for _, item := range thisStockIn {
  771. items := item.(map[string]interface{})
  772. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  773. utils.ErrorLog("good_id")
  774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  775. return
  776. }
  777. good_id := int64(items["good_id"].(float64))
  778. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  779. utils.ErrorLog("good_type_id")
  780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  781. return
  782. }
  783. good_type_id := int64(items["good_type_id"].(float64))
  784. return_count, _ := items["return_count"].(string)
  785. if len(return_count) == 0 {
  786. utils.ErrorLog("len(return_count) == 0")
  787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  788. return
  789. }
  790. count, _ := strconv.ParseInt(return_count, 10, 64)
  791. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  792. total := float64(count) * price
  793. salesReturnInfo := &models.SalesReturnInfo{
  794. OrderNumber: salesReturn.OrderNumber,
  795. SalesReturnId: salesReturn.ID,
  796. GoodId: good_id,
  797. GoodTypeId: good_type_id,
  798. Count: count,
  799. Price: price,
  800. Total: total,
  801. Status: 1,
  802. Ctime: ctime,
  803. OrgId: adminUserInfo.CurrentOrgId,
  804. Type: types,
  805. Manufacturer: manufacturer_id,
  806. Dealer: dealer_id,
  807. }
  808. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  809. }
  810. }
  811. }
  812. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  813. if errs != nil {
  814. utils.ErrorLog(errs.Error())
  815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  816. return
  817. }
  818. c.ServeSuccessJSON(map[string]interface{}{
  819. "msg": "退货成功",
  820. })
  821. }
  822. func (c *StockManagerApiController) GetSalesReturnList() {
  823. page, _ := c.GetInt64("page", -1)
  824. limit, _ := c.GetInt64("limit", -1)
  825. start_time := c.GetString("start_time")
  826. end_time := c.GetString("end_time")
  827. types, _ := c.GetInt64("type", 0)
  828. keywords := c.GetString("keywords")
  829. timeLayout := "2006-01-02"
  830. loc, _ := time.LoadLocation("Local")
  831. var startTime int64
  832. if len(start_time) > 0 {
  833. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  834. if err != nil {
  835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  836. return
  837. }
  838. startTime = theTime.Unix()
  839. }
  840. var endTime int64
  841. if len(end_time) > 0 {
  842. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  843. if err != nil {
  844. utils.ErrorLog(err.Error())
  845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  846. return
  847. }
  848. endTime = theTime.Unix()
  849. }
  850. adminUserInfo := c.GetAdminUserInfo()
  851. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  852. if err == nil {
  853. c.ServeSuccessJSON(map[string]interface{}{
  854. "list": returnList,
  855. "total": total,
  856. })
  857. } else {
  858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  859. }
  860. }
  861. func (this *StockManagerApiController) DeleteSalesReturn() {
  862. ids := this.GetString("ids")
  863. if len(ids) == 0 {
  864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  865. return
  866. }
  867. idArray := strings.Split(ids, ",")
  868. err := service.DeleteSalesReturn(idArray)
  869. if err != nil {
  870. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  871. } else {
  872. this.ServeSuccessJSON(map[string]interface{}{
  873. "msg": "删除成功",
  874. })
  875. }
  876. }
  877. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  878. id, _ := this.GetInt64("id", 0)
  879. fmt.Println(id)
  880. if id == 0 {
  881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  882. return
  883. }
  884. err := service.UpDateSaleReturnStatus(id)
  885. if err != nil {
  886. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  887. } else {
  888. this.ServeSuccessJSON(map[string]interface{}{
  889. "msg": "删除成功",
  890. })
  891. }
  892. }
  893. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  894. id, _ := this.GetInt64("id", 0)
  895. list, _ := service.FindAllSalesReturnInfoById(id)
  896. salesReturn, _ := service.FindAllSalesReturnById(id)
  897. this.ServeSuccessJSON(map[string]interface{}{
  898. "list": list,
  899. "salesReturn": salesReturn,
  900. })
  901. }
  902. func (c *StockManagerApiController) EditReturnInfo() {
  903. return_time := c.GetString("return_time")
  904. id, _ := c.GetInt64("id", 0)
  905. types, _ := c.GetInt64("type", 0)
  906. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  907. dealer_id, _ := c.GetInt64("dealer_id", 0)
  908. if id == 0 {
  909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  910. return
  911. }
  912. ctime := time.Now().Unix()
  913. mtime := time.Now().Unix()
  914. adminUserInfo := c.GetAdminUserInfo()
  915. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  916. if parseDateErr != nil {
  917. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  919. return
  920. }
  921. salesReturns, _ := service.FindSalesReturnById(id)
  922. sales := models.SalesReturn{
  923. ID: salesReturns.ID,
  924. Mtime: mtime,
  925. ReturnTime: returnDate.Unix(),
  926. Manufacturer: manufacturer_id,
  927. Dealer: dealer_id,
  928. }
  929. service.EditSaleReturn(sales)
  930. dataBody := make(map[string]interface{}, 0)
  931. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  932. if err != nil {
  933. utils.ErrorLog(err.Error())
  934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  935. return
  936. }
  937. var returnInfos []*models.SalesReturnInfo
  938. var upDateReturnInfos []*models.SalesReturnInfo
  939. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  940. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  941. if len(thisStockIn) > 0 {
  942. for _, item := range thisStockIn {
  943. items := item.(map[string]interface{})
  944. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  945. utils.ErrorLog("good_id")
  946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  947. return
  948. }
  949. good_id := int64(items["good_id"].(float64))
  950. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  951. utils.ErrorLog("good_type_id")
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  953. return
  954. }
  955. good_type_id := int64(items["good_type_id"].(float64))
  956. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  957. utils.ErrorLog("count")
  958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  959. return
  960. }
  961. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  962. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  963. utils.ErrorLog("id")
  964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  965. return
  966. }
  967. id := int64(items["id"].(float64))
  968. if id == 0 {
  969. returnInfo := &models.SalesReturnInfo{
  970. GoodId: good_id,
  971. GoodTypeId: good_type_id,
  972. Count: count,
  973. Status: 1,
  974. Ctime: ctime,
  975. OrgId: adminUserInfo.CurrentOrgId,
  976. OrderNumber: sales.OrderNumber,
  977. SalesReturnId: sales.ID,
  978. Mtime: time.Now().Unix(),
  979. Type: types,
  980. Manufacturer: manufacturer_id,
  981. Dealer: dealer_id,
  982. }
  983. returnInfos = append(returnInfos, returnInfo)
  984. } else {
  985. returnInfo := &models.SalesReturnInfo{
  986. ID: id,
  987. GoodId: good_id,
  988. GoodTypeId: good_type_id,
  989. Count: count,
  990. Status: 1,
  991. Ctime: ctime,
  992. OrgId: adminUserInfo.CurrentOrgId,
  993. OrderNumber: sales.OrderNumber,
  994. SalesReturnId: sales.ID,
  995. Mtime: time.Now().Unix(),
  996. Type: types,
  997. Manufacturer: manufacturer_id,
  998. Dealer: dealer_id,
  999. }
  1000. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  1001. }
  1002. }
  1003. }
  1004. }
  1005. var errs error
  1006. if len(returnInfos) > 0 {
  1007. errs = service.CreateSalesReturnInfo(returnInfos)
  1008. }
  1009. if len(upDateReturnInfos) > 0 {
  1010. for _, item := range upDateReturnInfos {
  1011. errs = service.UpDateSalesReturnInfo(item)
  1012. }
  1013. }
  1014. if errs != nil {
  1015. utils.ErrorLog(errs.Error())
  1016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1017. return
  1018. }
  1019. c.ServeSuccessJSON(map[string]interface{}{
  1020. "msg": "编辑成功",
  1021. })
  1022. }
  1023. func (c *StockManagerApiController) CreateWarehouseOut() {
  1024. types, _ := c.GetInt64("type", 0)
  1025. storehouse_id, _ := c.GetInt64("storehouse_id")
  1026. warehouseOut_id, _ := c.GetInt64("warehouseOut_id")
  1027. ctime := time.Now().Unix()
  1028. adminUserInfo := c.GetAdminUserInfo()
  1029. warehousing_out_time := c.GetString("warehousing_out_time")
  1030. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  1031. if parseDateErr != nil {
  1032. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  1033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1034. return
  1035. }
  1036. timeStr := time.Now().Format("2006-01-02")
  1037. timeArr := strings.Split(timeStr, "-")
  1038. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  1039. total = total + 1
  1040. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1041. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1042. number = number + total
  1043. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1044. operation_time := time.Now().Unix()
  1045. creater := adminUserInfo.AdminUser.Id
  1046. warehouseOut := models.WarehouseOut{
  1047. WarehouseOutOrderNumber: warehousing_out_order,
  1048. OperationTime: operation_time,
  1049. OrgId: adminUserInfo.CurrentOrgId,
  1050. Creater: creater,
  1051. Ctime: ctime,
  1052. Status: 1,
  1053. WarehouseOutTime: warehousingOutDate.Unix(),
  1054. Type: types,
  1055. StorehouseId: storehouse_id,
  1056. IsCheck: 2,
  1057. }
  1058. dataBody := make(map[string]interface{}, 0)
  1059. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1060. if err != nil {
  1061. utils.ErrorLog(err.Error())
  1062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1063. return
  1064. }
  1065. var warehousingOutInfo []*models.WarehouseOutInfo
  1066. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1067. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  1068. if len(thisStockIn) > 0 {
  1069. for _, item := range thisStockIn {
  1070. items := item.(map[string]interface{})
  1071. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1072. utils.ErrorLog("id")
  1073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1074. return
  1075. }
  1076. id := int64(items["id"].(float64))
  1077. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1078. utils.ErrorLog("good_id")
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1080. return
  1081. }
  1082. good_id := int64(items["good_id"].(float64))
  1083. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1084. utils.ErrorLog("good_type_id")
  1085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1086. return
  1087. }
  1088. good_type_id := int64(items["good_type_id"].(float64))
  1089. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1090. utils.ErrorLog("count")
  1091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1092. return
  1093. }
  1094. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1095. utils.ErrorLog("price")
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1100. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1101. total := float64(count) * price
  1102. remark := items["remark"].(string)
  1103. manufacturer := int64(items["manufacturer"].(float64))
  1104. dealer := int64(items["dealer"].(float64))
  1105. number := items["number"].(string)
  1106. expiry_date := items["expiry_date"].(string)
  1107. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1108. admin_user_id := int64(items["admin_user_id"].(float64))
  1109. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  1110. utils.ErrorLog("buy_price")
  1111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1112. return
  1113. }
  1114. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  1115. stock_count := items["stock_count"].(string)
  1116. register_number := items["register_number"].(string)
  1117. timeLayout := "2006-01-02"
  1118. loc, _ := time.LoadLocation("Local")
  1119. var expiryDate int64
  1120. if len(expiry_date) > 0 {
  1121. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1122. if err != nil {
  1123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1124. return
  1125. }
  1126. expiryDate = theTime.Unix()
  1127. }
  1128. product_date := items["product_date"].(string)
  1129. var productDate int64
  1130. if len(product_date) > 0 {
  1131. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
  1132. if err != nil {
  1133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1134. return
  1135. }
  1136. productDate = theTime.Unix()
  1137. }
  1138. license_number := items["license_number"].(string)
  1139. warehouseOutInfo := &models.WarehouseOutInfo{
  1140. ID: id,
  1141. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1142. WarehouseOutId: warehouseOut.ID,
  1143. GoodId: good_id,
  1144. GoodTypeId: good_type_id,
  1145. Count: count,
  1146. Price: price,
  1147. TotalPrice: total,
  1148. Status: 1,
  1149. Ctime: ctime,
  1150. Remark: remark,
  1151. OrgId: adminUserInfo.CurrentOrgId,
  1152. Type: types,
  1153. Manufacturer: manufacturer,
  1154. Number: number,
  1155. ExpiryDate: expiryDate,
  1156. ProductDate: productDate,
  1157. Dealer: dealer,
  1158. LicenseNumber: license_number,
  1159. WarehouseInfotId: warehouse_info_id,
  1160. StorehouseId: storehouse_id,
  1161. AdminUserId: admin_user_id,
  1162. BuyPrice: buy_price,
  1163. StockCount: stock_count,
  1164. IsCheck: 2,
  1165. RegisterNumber: register_number,
  1166. }
  1167. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1168. }
  1169. }
  1170. }
  1171. if warehouseOut_id == 0 {
  1172. //查询是否生成出库单
  1173. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  1174. if errcodes == gorm.ErrRecordNotFound {
  1175. service.AddSigleWarehouseOut(&warehouseOut)
  1176. }
  1177. }
  1178. if warehouseOut_id > 0 {
  1179. service.UpdateSingleWarehoseOut(warehouseOut_id, storehouse_id)
  1180. }
  1181. goodWarehouseOut, _ := service.GetLastGoodWarehouseOutTwenty(adminUserInfo.CurrentOrgId)
  1182. for _, it := range warehousingOutInfo {
  1183. warehouseOutInfo := &models.WarehouseOutInfo{
  1184. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1185. WarehouseOutId: goodWarehouseOut.ID,
  1186. WarehouseInfotId: 0,
  1187. Status: 1,
  1188. Ctime: time.Now().Unix(),
  1189. Remark: it.Remark,
  1190. OrgId: adminUserInfo.CurrentOrgId,
  1191. Type: 1,
  1192. Manufacturer: it.Manufacturer,
  1193. Dealer: it.Dealer,
  1194. IsSys: 0,
  1195. SysRecordTime: it.SysRecordTime,
  1196. GoodTypeId: it.GoodTypeId,
  1197. GoodId: it.GoodId,
  1198. ExpiryDate: it.ExpiryDate,
  1199. ProductDate: it.ProductDate,
  1200. Number: it.Number,
  1201. Price: it.Price,
  1202. LicenseNumber: it.LicenseNumber,
  1203. SupplyWarehouseId: 0,
  1204. StorehouseId: storehouse_id,
  1205. AdminUserId: it.AdminUserId,
  1206. BuyPrice: it.BuyPrice,
  1207. StockCount: it.StockCount,
  1208. Count: it.Count,
  1209. IsCheck: 2,
  1210. RegisterNumber: it.RegisterNumber,
  1211. }
  1212. if it.ID == 0 {
  1213. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1214. }
  1215. if it.ID > 0 {
  1216. service.ModifyWarehouseOutInfo(it.ID, warehouseOutInfo)
  1217. }
  1218. //lastWarehouseOutInfo, _ := service.GetLastGoodWarehouseOutInfoById(it.OrgId)
  1219. //if(it.ID == 0){
  1220. // //创建出库流水
  1221. // service.CreateStockFlowOne(stockFlow)
  1222. //}
  1223. //if(it.ID > 0){
  1224. // //更新流水
  1225. // service.UpdateWarehouseOutFlow(stockFlow,it.ID)
  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. ctime := time.Now().Unix()
  1397. mtime := time.Now().Unix()
  1398. adminUserInfo := c.GetAdminUserInfo()
  1399. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1400. if parseDateErr != nil {
  1401. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1403. return
  1404. }
  1405. warehouseOut, _ := service.FindWareHouseOutById(id)
  1406. tempWarehouseOut := models.WarehouseOut{
  1407. ID: warehouseOut.ID,
  1408. Mtime: mtime,
  1409. WarehouseOutTime: warehouseOutDate.Unix(),
  1410. StorehouseId: storehouse_id,
  1411. }
  1412. service.EditWarehouseOut(tempWarehouseOut)
  1413. dataBody := make(map[string]interface{}, 0)
  1414. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1415. if err != nil {
  1416. utils.ErrorLog(err.Error())
  1417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1418. return
  1419. }
  1420. var warehousingOutInfo []*models.WarehouseOutInfo
  1421. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1422. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1423. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1424. if len(thisStockOut) > 0 {
  1425. for _, item := range thisStockOut {
  1426. items := item.(map[string]interface{})
  1427. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1428. utils.ErrorLog("good_id")
  1429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1430. return
  1431. }
  1432. good_id := int64(items["good_id"].(float64))
  1433. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1434. utils.ErrorLog("good_type_id")
  1435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1436. return
  1437. }
  1438. good_type_id := int64(items["good_type_id"].(float64))
  1439. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1440. utils.ErrorLog("count")
  1441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1442. return
  1443. }
  1444. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1445. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1446. utils.ErrorLog("price")
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1448. return
  1449. }
  1450. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1451. total := float64(count) * price
  1452. remark := items["remark"].(string)
  1453. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1454. utils.ErrorLog("id")
  1455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1456. return
  1457. }
  1458. id := int64(items["id"].(float64))
  1459. manufacturer := int64(items["manufacturer"].(float64))
  1460. dealer := int64(items["dealer"].(float64))
  1461. number := items["number"].(string)
  1462. license_number := items["license_number"].(string)
  1463. timeLayout := "2006-01-02"
  1464. loc, _ := time.LoadLocation("Local")
  1465. expiry_date := items["expiry_date"].(string)
  1466. var expiryDate int64
  1467. if len(expiry_date) > 0 {
  1468. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1469. if err != nil {
  1470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1471. return
  1472. }
  1473. expiryDate = theTime.Unix()
  1474. }
  1475. product_date := items["product_date"].(string)
  1476. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1477. admin_user_id := int64(items["admin_user_id"].(float64))
  1478. //if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  1479. // utils.ErrorLog("buy_price")
  1480. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1481. // return
  1482. //}
  1483. //buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  1484. stock_count := items["stock_count"].(string)
  1485. register_number := items["register_number"].(string)
  1486. var productDate int64
  1487. if len(product_date) > 0 {
  1488. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
  1489. if err != nil {
  1490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1491. return
  1492. }
  1493. productDate = theTime.Unix()
  1494. }
  1495. if id == 0 {
  1496. warehouseOutInfo := &models.WarehouseOutInfo{
  1497. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1498. WarehouseOutId: warehouseOut.ID,
  1499. GoodId: good_id,
  1500. GoodTypeId: good_type_id,
  1501. Count: count,
  1502. Price: price,
  1503. TotalPrice: total,
  1504. Status: 1,
  1505. Ctime: ctime,
  1506. Remark: remark,
  1507. OrgId: adminUserInfo.CurrentOrgId,
  1508. Type: types,
  1509. IsSys: 0,
  1510. SysRecordTime: 0,
  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: ctime,
  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. if types == 1 {
  2831. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2832. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2833. if err == nil {
  2834. this.ServeSuccessJSON(map[string]interface{}{
  2835. "list": list,
  2836. "total": total,
  2837. "total_price": total_price,
  2838. "houseList": houseList,
  2839. })
  2840. } else {
  2841. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2842. }
  2843. } else if types == 2 {
  2844. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2845. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2846. if err == nil {
  2847. this.ServeSuccessJSON(map[string]interface{}{
  2848. "list": list1,
  2849. "total": total,
  2850. "total_price": total_price,
  2851. "houseList": houseList,
  2852. })
  2853. } else {
  2854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2855. }
  2856. } else if types == 3 {
  2857. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2858. if err == nil {
  2859. this.ServeSuccessJSON(map[string]interface{}{
  2860. "list": list2,
  2861. "total": total,
  2862. })
  2863. } else {
  2864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2865. }
  2866. } else if types == 4 {
  2867. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2868. listGroup, err := service.FindeCancelGroup(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2869. if err == nil {
  2870. this.ServeSuccessJSON(map[string]interface{}{
  2871. "list": list3,
  2872. "total": total,
  2873. "listgroup": listGroup,
  2874. "houseList": houseList,
  2875. })
  2876. } else {
  2877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2878. }
  2879. }
  2880. }
  2881. func (this *StockManagerApiController) GetUserDetailInfo() {
  2882. order_id, _ := this.GetInt64("id")
  2883. if order_id <= 0 {
  2884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2885. return
  2886. }
  2887. adminUserInfo := this.GetAdminUserInfo()
  2888. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2889. if err == nil {
  2890. this.ServeSuccessJSON(map[string]interface{}{
  2891. "list": userDetails,
  2892. "total": total,
  2893. })
  2894. } else {
  2895. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2896. return
  2897. }
  2898. }
  2899. func (this *StockManagerApiController) PostSearchStock() {
  2900. keyword := this.GetString("keyword")
  2901. adminUserInfo := this.GetAdminUserInfo()
  2902. orgId := adminUserInfo.CurrentOrgId
  2903. stock, err := service.PostSearchStock(keyword, orgId)
  2904. if err != nil {
  2905. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2906. }
  2907. this.ServeSuccessJSON(map[string]interface{}{
  2908. "stock": stock,
  2909. })
  2910. }
  2911. func (this *StockManagerApiController) GetOutStockTotalCount() {
  2912. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  2913. adminUserInfo := this.GetAdminUserInfo()
  2914. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  2915. if err != nil {
  2916. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2917. }
  2918. this.ServeSuccessJSON(map[string]interface{}{
  2919. "stockCount": stockCount,
  2920. })
  2921. }
  2922. func (this *StockManagerApiController) AddGoodInformation() {
  2923. adminUserInfo := this.GetAdminUserInfo()
  2924. orgId := adminUserInfo.CurrentOrgId
  2925. dataBody := make(map[string]interface{}, 0)
  2926. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2927. if err != nil {
  2928. utils.ErrorLog(err.Error())
  2929. return
  2930. }
  2931. utils.ErrorLog("%v", dataBody)
  2932. var goods []*models.GoodInfo
  2933. var total_goods []interface{}
  2934. tempGoods := dataBody["goods"].([]interface{})
  2935. total_goods = tempGoods
  2936. for index, goodMap := range tempGoods {
  2937. goodNameM := goodMap.(map[string]interface{})
  2938. var good models.GoodInfo
  2939. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  2940. utils.ErrorLog("good_name")
  2941. return
  2942. }
  2943. good_name, _ := goodNameM["good_name"].(string)
  2944. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  2945. err_log := models.ExportErrLog{
  2946. LogType: 5,
  2947. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2948. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  2949. Status: 1,
  2950. CreateTime: time.Now().Unix(),
  2951. UpdateTime: time.Now().Unix(),
  2952. ExportTime: time.Now().Unix(),
  2953. }
  2954. service.CreateExportErrLog(&err_log)
  2955. continue
  2956. }
  2957. good.GoodName = good_name
  2958. // 获取数据字典数据
  2959. var good_kind_id int64
  2960. var name = "耗材种类"
  2961. config, _ := service.GetDrugDataConfig(0, name)
  2962. good_kind := goodNameM["good_kind"].(string)
  2963. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  2964. err_log := models.ExportErrLog{
  2965. LogType: 5,
  2966. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2967. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  2968. Status: 1,
  2969. CreateTime: time.Now().Unix(),
  2970. UpdateTime: time.Now().Unix(),
  2971. ExportTime: time.Now().Unix(),
  2972. }
  2973. service.CreateExportErrLog(&err_log)
  2974. continue
  2975. }
  2976. if len(good_kind) != 0 {
  2977. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  2978. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  2979. dataconfig := models.DictDataconfig{
  2980. ParentId: config.ID,
  2981. Module: "system",
  2982. OrgId: orgId,
  2983. Name: good_kind,
  2984. FieldName: "",
  2985. Value: lastConfig.Value + 1,
  2986. CreatedTime: "",
  2987. UpdatedTime: "",
  2988. CreateUserId: adminUserInfo.AdminUser.Id,
  2989. Status: 1,
  2990. Remark: "",
  2991. DeleteIdSystem: 0,
  2992. Title: "",
  2993. Content: "",
  2994. Order: 0,
  2995. Code: "",
  2996. }
  2997. if errcodegoodkind == gorm.ErrRecordNotFound {
  2998. service.CreatedDicConfig(&dataconfig)
  2999. }
  3000. }
  3001. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  3002. for _, it := range dataConfig {
  3003. if good_kind == it.Name {
  3004. fmt.Println(it.Name)
  3005. good_kind_id = int64(it.Value)
  3006. }
  3007. }
  3008. good.GoodKind = good_kind_id
  3009. good_type := goodNameM["type_name"].(string)
  3010. if len(good_type) == 0 {
  3011. err_log := models.ExportErrLog{
  3012. LogType: 5,
  3013. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3014. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  3015. Status: 1,
  3016. CreateTime: time.Now().Unix(),
  3017. UpdateTime: time.Now().Unix(),
  3018. ExportTime: time.Now().Unix(),
  3019. }
  3020. service.CreateExportErrLog(&err_log)
  3021. continue
  3022. }
  3023. if len(good_type) != 0 {
  3024. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  3025. if errcodegoodtype == gorm.ErrRecordNotFound {
  3026. goodsType := models.GoodsType{
  3027. TypeName: good_type,
  3028. Remark: "",
  3029. Ctime: time.Now().Unix(),
  3030. Mtime: 0,
  3031. Creater: adminUserInfo.AdminUser.Id,
  3032. Modifier: 0,
  3033. OrgId: adminUserInfo.CurrentOrgId,
  3034. Status: 1,
  3035. Type: 0,
  3036. Number: 0,
  3037. OutStock: 0,
  3038. StockAttribute: 1,
  3039. }
  3040. service.CreatedGoodType(&goodsType)
  3041. }
  3042. }
  3043. goodType, _ := service.GetAllGoodType(orgId)
  3044. var good_type_id int64
  3045. for _, it := range goodType {
  3046. if good_type == it.TypeName {
  3047. good_type_id = it.ID
  3048. }
  3049. }
  3050. good.GoodTypeId = good_type_id
  3051. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  3052. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  3053. err_log := models.ExportErrLog{
  3054. LogType: 5,
  3055. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3056. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  3057. Status: 1,
  3058. CreateTime: time.Now().Unix(),
  3059. UpdateTime: time.Now().Unix(),
  3060. ExportTime: time.Now().Unix(),
  3061. }
  3062. service.CreateExportErrLog(&err_log)
  3063. continue
  3064. }
  3065. var medical_insurance_id int64
  3066. var medicalInsurance = "医保等级"
  3067. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  3068. if len(medical_insurance_level) != 0 {
  3069. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  3070. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  3071. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  3072. dataconfig := models.DictDataconfig{
  3073. ParentId: medicalInsuranceDataConfig.ID,
  3074. Module: "system",
  3075. OrgId: orgId,
  3076. Name: medical_insurance_level,
  3077. FieldName: "",
  3078. Value: mediConfigOne.Value + 1,
  3079. CreatedTime: "",
  3080. UpdatedTime: "",
  3081. CreateUserId: adminUserInfo.AdminUser.Id,
  3082. Status: 1,
  3083. Remark: "",
  3084. DeleteIdSystem: 0,
  3085. Title: "",
  3086. Content: "",
  3087. Order: 0,
  3088. Code: "",
  3089. }
  3090. service.CreatedDicConfig(&dataconfig)
  3091. }
  3092. }
  3093. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  3094. for _, it := range medicalInsuranceList {
  3095. if medical_insurance_level == it.Name {
  3096. medical_insurance_id = int64(it.Value)
  3097. }
  3098. }
  3099. good.MedicalInsuranceLevel = medical_insurance_id
  3100. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  3101. utils.ErrorLog("specification_name")
  3102. return
  3103. }
  3104. specification_name := goodNameM["specification_name"].(string)
  3105. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  3106. err_log := models.ExportErrLog{
  3107. LogType: 5,
  3108. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3109. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  3110. Status: 1,
  3111. CreateTime: time.Now().Unix(),
  3112. UpdateTime: time.Now().Unix(),
  3113. ExportTime: time.Now().Unix(),
  3114. }
  3115. service.CreateExportErrLog(&err_log)
  3116. continue
  3117. }
  3118. good.SpecificationName = specification_name
  3119. var manufacturer_id int64
  3120. manufacturer := goodNameM["manufacturer"].(string)
  3121. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3122. err_log := models.ExportErrLog{
  3123. LogType: 5,
  3124. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3125. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  3126. Status: 1,
  3127. CreateTime: time.Now().Unix(),
  3128. UpdateTime: time.Now().Unix(),
  3129. ExportTime: time.Now().Unix(),
  3130. }
  3131. service.CreateExportErrLog(&err_log)
  3132. continue
  3133. }
  3134. if len(manufacturer) != 0 {
  3135. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  3136. manu := models.Manufacturer{
  3137. ManufacturerName: manufacturer,
  3138. Status: 1,
  3139. OrgId: orgId,
  3140. Creater: adminUserInfo.AdminUser.Id,
  3141. }
  3142. if errcodes == gorm.ErrRecordNotFound {
  3143. service.CreateManufacturer(&manu)
  3144. }
  3145. }
  3146. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3147. for _, it := range manufacturerList {
  3148. if manufacturer == it.ManufacturerName {
  3149. manufacturer_id = it.ID
  3150. }
  3151. }
  3152. good.Manufacturer = manufacturer_id
  3153. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  3154. utils.ErrorLog("unit_id")
  3155. return
  3156. }
  3157. unit_id := int64(goodNameM["unit_id"].(float64))
  3158. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  3159. err_log := models.ExportErrLog{
  3160. LogType: 5,
  3161. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3162. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  3163. Status: 1,
  3164. CreateTime: time.Now().Unix(),
  3165. UpdateTime: time.Now().Unix(),
  3166. ExportTime: time.Now().Unix(),
  3167. }
  3168. service.CreateExportErrLog(&err_log)
  3169. continue
  3170. }
  3171. good.GoodUnit = unit_id
  3172. retail_prices := goodNameM["retail_price"].(string)
  3173. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3174. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3175. err_log := models.ExportErrLog{
  3176. LogType: 5,
  3177. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3178. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
  3179. Status: 1,
  3180. CreateTime: time.Now().Unix(),
  3181. UpdateTime: time.Now().Unix(),
  3182. ExportTime: time.Now().Unix(),
  3183. }
  3184. service.CreateExportErrLog(&err_log)
  3185. continue
  3186. }
  3187. good.RetailPrice = retail_price
  3188. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  3189. utils.ErrorLog("stock_warn_count")
  3190. return
  3191. }
  3192. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  3193. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  3194. err_log := models.ExportErrLog{
  3195. LogType: 5,
  3196. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3197. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  3198. Status: 1,
  3199. CreateTime: time.Now().Unix(),
  3200. UpdateTime: time.Now().Unix(),
  3201. ExportTime: time.Now().Unix(),
  3202. }
  3203. service.CreateExportErrLog(&err_log)
  3204. continue
  3205. }
  3206. good.StockWarnCount = stock_warn_count
  3207. var dealer_id int64
  3208. dealerName := goodNameM["dealer"].(string)
  3209. fmt.Println("经销商", dealerName)
  3210. dealer := models.Dealer{
  3211. OrgId: orgId,
  3212. Status: 1,
  3213. DealerName: dealerName,
  3214. Creater: adminUserInfo.AdminUser.Id,
  3215. Ctime: time.Now().Unix(),
  3216. }
  3217. if len(dealerName) != 0 {
  3218. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  3219. if errcodedealer == gorm.ErrRecordNotFound {
  3220. service.CreateDealer(&dealer)
  3221. }
  3222. }
  3223. dealerList, _ := service.GetAllDealerList(orgId)
  3224. for _, it := range dealerList {
  3225. if dealerName == it.DealerName {
  3226. dealer_id = it.ID
  3227. }
  3228. }
  3229. good.Dealer = dealer_id
  3230. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  3231. utils.ErrorLog("pinyin")
  3232. return
  3233. }
  3234. pinyin := goodNameM["pinyin"].(string)
  3235. good.Pinyin = pinyin
  3236. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  3237. utils.ErrorLog("wubi")
  3238. return
  3239. }
  3240. wubi := goodNameM["wubi"].(string)
  3241. good.Wubi = wubi
  3242. buy_prices := goodNameM["buy_price"].(string)
  3243. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  3244. good.BuyPrice = buy_price
  3245. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  3246. utils.ErrorLog("social_security_directory_code")
  3247. return
  3248. }
  3249. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3250. good.SocialSecurityDirectoryCode = social_security_directory_code
  3251. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  3252. utils.ErrorLog("is_special_diseases")
  3253. return
  3254. }
  3255. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3256. good.IsSpecialDiseases = is_special_diseases
  3257. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  3258. utils.ErrorLog("is_record")
  3259. return
  3260. }
  3261. is_record := int64(goodNameM["is_record"].(float64))
  3262. good.IsRecord = is_record
  3263. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  3264. utils.ErrorLog("good_status")
  3265. return
  3266. }
  3267. good_status := goodNameM["good_status"].(string)
  3268. good.GoodStatus = good_status
  3269. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  3270. utils.ErrorLog("medical_insurance_number")
  3271. return
  3272. }
  3273. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3274. good.MedicalInsuranceNumber = medical_insurance_number
  3275. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  3276. utils.ErrorLog("production_type")
  3277. return
  3278. }
  3279. production_type := goodNameM["production_type"].(string)
  3280. good.ProductionType = production_type
  3281. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  3282. utils.ErrorLog("remark")
  3283. return
  3284. }
  3285. remark := goodNameM["remark"].(string)
  3286. good.Remark = remark
  3287. statistics_category := goodNameM["statistics_category"].(string)
  3288. var categoryName = "统计分类"
  3289. var statistic_id int64
  3290. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  3291. if len(statistics_category) != 0 {
  3292. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  3293. if errcodecagegory == gorm.ErrRecordNotFound {
  3294. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  3295. dataconfig := models.DictDataconfig{
  3296. ParentId: drugDataConfig.ID,
  3297. Module: "system",
  3298. OrgId: orgId,
  3299. Name: statistics_category,
  3300. FieldName: "",
  3301. Value: dicConfigThree.Value + 1,
  3302. CreatedTime: "",
  3303. UpdatedTime: "",
  3304. CreateUserId: adminUserInfo.AdminUser.Id,
  3305. Status: 1,
  3306. Remark: "",
  3307. DeleteIdSystem: 0,
  3308. Title: "",
  3309. Content: "",
  3310. Order: 0,
  3311. Code: "",
  3312. }
  3313. service.CreatedDicConfig(&dataconfig)
  3314. }
  3315. }
  3316. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  3317. for _, it := range parentDataConfig {
  3318. if statistics_category == it.Name {
  3319. statistic_id = int64(it.Value)
  3320. }
  3321. }
  3322. good.StatisticsCategory = statistic_id
  3323. special_medical := goodNameM["special_medical"].(string)
  3324. good.SpecialMedical = special_medical
  3325. packing_unit := goodNameM["good_unit"].(string)
  3326. good.PackingUnit = packing_unit
  3327. goods = append(goods, &good)
  3328. }
  3329. export_time := time.Now().Unix()
  3330. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3331. if len(goods) > 0 {
  3332. for _, item := range goods {
  3333. goodInfo := models.GoodInfo{
  3334. GoodName: item.GoodName,
  3335. SpecificationName: item.SpecificationName,
  3336. GoodKind: item.GoodKind,
  3337. GoodTypeId: item.GoodTypeId,
  3338. Dealer: item.Dealer,
  3339. GoodUnit: item.GoodUnit,
  3340. IsRecord: item.IsRecord,
  3341. IsSpecialDiseases: item.IsSpecialDiseases,
  3342. Manufacturer: item.Manufacturer,
  3343. Pinyin: item.Pinyin,
  3344. GoodStatus: item.GoodStatus,
  3345. ProductionType: item.ProductionType,
  3346. Remark: item.Remark,
  3347. RetailPrice: item.RetailPrice,
  3348. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3349. SpecialMedical: item.SpecialMedical,
  3350. Wubi: item.Wubi,
  3351. StockWarnCount: item.StockWarnCount,
  3352. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3353. OrgId: orgId,
  3354. Status: 1,
  3355. Ctime: time.Now().Unix(),
  3356. StatisticsCategory: item.StatisticsCategory,
  3357. GoodCode: item.GoodCode,
  3358. BuyPrice: item.BuyPrice,
  3359. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3360. IsUser: 2,
  3361. PackingUnit: item.PackingUnit,
  3362. PackingPrice: item.RetailPrice,
  3363. IsWarehouse: 1,
  3364. }
  3365. //查询同种耗材名称同种类型同种规格的耗材是否存在
  3366. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  3367. if errcodegood == gorm.ErrRecordNotFound {
  3368. service.CreateGoodsInfomation(&goodInfo)
  3369. } else if errcodegood == nil {
  3370. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  3371. }
  3372. log := models.ExportLog{
  3373. LogType: 5,
  3374. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3375. TotalNum: int64(len(total_goods)),
  3376. FailNum: int64(len(errLogs)),
  3377. SuccessNum: int64(len(goods)),
  3378. CreateTime: time.Now().Unix(),
  3379. UpdateTime: time.Now().Unix(),
  3380. ExportTime: export_time,
  3381. Status: 1,
  3382. }
  3383. service.CreateExportLog(&log)
  3384. this.ServeSuccessJSON(map[string]interface{}{
  3385. "msg": "导入成功",
  3386. "total_num": len(total_goods),
  3387. "success_num": len(goods),
  3388. "fail_num": int64(len(errLogs)),
  3389. })
  3390. }
  3391. } else {
  3392. log := models.ExportLog{
  3393. LogType: 5,
  3394. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3395. TotalNum: int64(len(total_goods)),
  3396. FailNum: int64(len(errLogs)),
  3397. SuccessNum: int64(len(goods)),
  3398. CreateTime: time.Now().Unix(),
  3399. UpdateTime: time.Now().Unix(),
  3400. ExportTime: export_time,
  3401. Status: 1,
  3402. }
  3403. service.CreateExportLog(&log)
  3404. this.ServeSuccessJSON(map[string]interface{}{
  3405. "msg": "导入成功",
  3406. "total_num": len(total_goods),
  3407. "success_num": len(goods),
  3408. "fail_num": int64(len(errLogs)),
  3409. })
  3410. }
  3411. }
  3412. func (this *StockManagerApiController) AddDrugInformation() {
  3413. adminUser := this.GetAdminUserInfo()
  3414. orgId := adminUser.CurrentOrgId
  3415. dataBody := make(map[string]interface{}, 0)
  3416. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  3417. if err != nil {
  3418. utils.ErrorLog(err.Error())
  3419. return
  3420. }
  3421. utils.ErrorLog("%v", dataBody)
  3422. var drugList []*models.BaseDrugLib
  3423. var total_goods []interface{}
  3424. tempDrugs := dataBody["drugs"].([]interface{})
  3425. total_goods = tempDrugs
  3426. for index, drugMap := range tempDrugs {
  3427. goodNameM := drugMap.(map[string]interface{})
  3428. var drug models.BaseDrugLib
  3429. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  3430. utils.ErrorLog("drug_name")
  3431. return
  3432. }
  3433. drug_name, _ := goodNameM["drug_name"].(string)
  3434. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  3435. err_log := models.ExportErrLog{
  3436. LogType: 4,
  3437. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3438. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  3439. Status: 1,
  3440. CreateTime: time.Now().Unix(),
  3441. UpdateTime: time.Now().Unix(),
  3442. ExportTime: time.Now().Unix(),
  3443. }
  3444. service.CreateExportErrLog(&err_log)
  3445. continue
  3446. }
  3447. drug.DrugName = drug_name
  3448. dose_unit := goodNameM["dose_unit"].(string)
  3449. drug.DoseUnit = dose_unit
  3450. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  3451. utils.ErrorLog("min_number")
  3452. return
  3453. }
  3454. min_number, _ := goodNameM["min_number"].(string)
  3455. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  3456. if len(min_number) == 0 { //名字为空则生成一条导入错误日志
  3457. err_log := models.ExportErrLog{
  3458. LogType: 4,
  3459. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3460. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  3461. Status: 1,
  3462. CreateTime: time.Now().Unix(),
  3463. UpdateTime: time.Now().Unix(),
  3464. ExportTime: time.Now().Unix(),
  3465. }
  3466. service.CreateExportErrLog(&err_log)
  3467. continue
  3468. }
  3469. drug.MinNumber = minNumber
  3470. min_unit := goodNameM["min_unit"].(string)
  3471. if len(min_unit) == 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.MinUnit = min_unit
  3485. max_unit_id := goodNameM["max_unit"].(string)
  3486. if len(max_unit_id) == 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.MaxUnit = max_unit_id
  3500. max_unit := goodNameM["max_unit"].(string)
  3501. if len(max_unit) == 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
  3515. drug_type := goodNameM["drug_type"].(string)
  3516. if len(drug_type) == 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. var drug_type_id int64
  3530. var drugType = "药品类型"
  3531. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  3532. if len(drug_type) != 0 {
  3533. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  3534. if errcodes == gorm.ErrRecordNotFound {
  3535. //获取该型号最后一条数据型号
  3536. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  3537. dataconfig := models.DictDataconfig{
  3538. ParentId: drugconfig.ID,
  3539. Module: "system",
  3540. OrgId: orgId,
  3541. Name: drug_type,
  3542. FieldName: "",
  3543. Value: config.Value + 1,
  3544. CreatedTime: "",
  3545. UpdatedTime: "",
  3546. CreateUserId: adminUser.AdminUser.Id,
  3547. Status: 1,
  3548. Remark: "",
  3549. DeleteIdSystem: 0,
  3550. Title: "",
  3551. Content: "",
  3552. Order: 0,
  3553. Code: "",
  3554. }
  3555. service.CreatedDicConfig(&dataconfig)
  3556. }
  3557. }
  3558. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  3559. for _, it := range drugTypeList {
  3560. if drug_type == it.Name {
  3561. drug_type_id = int64(it.Value)
  3562. }
  3563. }
  3564. drug.DrugType = drug_type_id
  3565. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  3566. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  3567. err_log := models.ExportErrLog{
  3568. LogType: 4,
  3569. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3570. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  3571. Status: 1,
  3572. CreateTime: time.Now().Unix(),
  3573. UpdateTime: time.Now().Unix(),
  3574. ExportTime: time.Now().Unix(),
  3575. }
  3576. service.CreateExportErrLog(&err_log)
  3577. continue
  3578. }
  3579. drug.DrugStockLimit = drug_stock_limit
  3580. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  3581. if len(drug_origin_place) == 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.DrugOriginPlace = drug_origin_place
  3595. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  3596. if len(drug_dosage_form) == 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. var drug_dosage = "药品剂型"
  3610. var drug_dosage_form_id int64
  3611. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  3612. if len(drug_dosage_form) != 0 {
  3613. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  3614. if errcodess == gorm.ErrRecordNotFound {
  3615. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  3616. dataconfig := models.DictDataconfig{
  3617. ParentId: drugDosageconfig.ID,
  3618. Module: "system",
  3619. OrgId: orgId,
  3620. Name: drug_dosage_form,
  3621. FieldName: "",
  3622. Value: configOne.Value + 1,
  3623. CreatedTime: "",
  3624. UpdatedTime: "",
  3625. CreateUserId: adminUser.AdminUser.Id,
  3626. Status: 1,
  3627. Remark: "",
  3628. DeleteIdSystem: 0,
  3629. Title: "",
  3630. Content: "",
  3631. Order: 0,
  3632. Code: "",
  3633. }
  3634. service.CreatedDicConfig(&dataconfig)
  3635. }
  3636. }
  3637. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  3638. for _, it := range drugDosageList {
  3639. if drug_dosage_form == it.Name {
  3640. drug_dosage_form_id = int64(it.Value)
  3641. }
  3642. }
  3643. drug.DrugDosageForm = drug_dosage_form_id
  3644. retail_prices := goodNameM["retail_price"].(string)
  3645. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3646. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3647. err_log := models.ExportErrLog{
  3648. LogType: 4,
  3649. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3650. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  3651. Status: 1,
  3652. CreateTime: time.Now().Unix(),
  3653. UpdateTime: time.Now().Unix(),
  3654. ExportTime: time.Now().Unix(),
  3655. }
  3656. service.CreateExportErrLog(&err_log)
  3657. continue
  3658. }
  3659. drug.RetailPrice = retail_price
  3660. last_prices := goodNameM["last_price"].(string)
  3661. last_price, _ := strconv.ParseFloat(last_prices, 64)
  3662. if last_price <= 0 { //名字为空则生成一条导入错误日志
  3663. err_log := models.ExportErrLog{
  3664. LogType: 4,
  3665. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3666. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  3667. Status: 1,
  3668. CreateTime: time.Now().Unix(),
  3669. UpdateTime: time.Now().Unix(),
  3670. ExportTime: time.Now().Unix(),
  3671. }
  3672. service.CreateExportErrLog(&err_log)
  3673. continue
  3674. }
  3675. drug.LastPrice = last_price
  3676. drug_classify := goodNameM["drug_classify"].(string)
  3677. if len(drug_classify) == 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. var drugClassify = "药物分类"
  3691. var drug_classify_id int64
  3692. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  3693. if len(drug_classify) != 0 {
  3694. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  3695. if errcodesClass == gorm.ErrRecordNotFound {
  3696. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  3697. dataconfig := models.DictDataconfig{
  3698. ParentId: drugClassifyConfig.ID,
  3699. Module: "system",
  3700. OrgId: orgId,
  3701. Name: drug_classify,
  3702. FieldName: "",
  3703. Value: drugClassConfig.Value + 1,
  3704. CreatedTime: "",
  3705. UpdatedTime: "",
  3706. CreateUserId: adminUser.AdminUser.Id,
  3707. Status: 1,
  3708. Remark: "",
  3709. DeleteIdSystem: 0,
  3710. Title: "",
  3711. Content: "",
  3712. Order: 0,
  3713. Code: "",
  3714. }
  3715. service.CreatedDicConfig(&dataconfig)
  3716. }
  3717. }
  3718. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  3719. for _, it := range drugClassList {
  3720. if drug_classify == it.Name {
  3721. drug_classify_id = int64(it.Value)
  3722. }
  3723. }
  3724. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  3725. drug_dose := goodNameM["drug_dose"].(string)
  3726. if len(drug_dose) == 0 {
  3727. err_log := models.ExportErrLog{
  3728. LogType: 4,
  3729. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3730. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  3731. Status: 1,
  3732. CreateTime: time.Now().Unix(),
  3733. UpdateTime: time.Now().Unix(),
  3734. ExportTime: time.Now().Unix(),
  3735. }
  3736. service.CreateExportErrLog(&err_log)
  3737. continue
  3738. }
  3739. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  3740. drug.DrugDose = drugDoses
  3741. var units = "单位"
  3742. var unit_id int64
  3743. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  3744. if len(drugDoseUnit) == 0 {
  3745. err_log := models.ExportErrLog{
  3746. LogType: 4,
  3747. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3748. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  3749. Status: 1,
  3750. CreateTime: time.Now().Unix(),
  3751. UpdateTime: time.Now().Unix(),
  3752. ExportTime: time.Now().Unix(),
  3753. }
  3754. service.CreateExportErrLog(&err_log)
  3755. continue
  3756. }
  3757. manufacturer := goodNameM["manufacturer"].(string)
  3758. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3759. err_log := models.ExportErrLog{
  3760. LogType: 4,
  3761. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3762. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  3763. Status: 1,
  3764. CreateTime: time.Now().Unix(),
  3765. UpdateTime: time.Now().Unix(),
  3766. ExportTime: time.Now().Unix(),
  3767. }
  3768. service.CreateExportErrLog(&err_log)
  3769. continue
  3770. }
  3771. if len(manufacturer) != 0 {
  3772. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  3773. if errcodema == gorm.ErrRecordNotFound {
  3774. manufactur := models.Manufacturer{
  3775. OrgId: orgId,
  3776. Status: 1,
  3777. ManufacturerName: manufacturer,
  3778. Ctime: time.Now().Unix(),
  3779. Creater: adminUser.AdminUser.Id,
  3780. }
  3781. service.CreateManufacturer(&manufactur)
  3782. }
  3783. }
  3784. var manufacturer_id int64
  3785. manufacturList, _ := service.GetAllManufacturerList(orgId)
  3786. for _, it := range manufacturList {
  3787. if manufacturer == it.ManufacturerName {
  3788. manufacturer_id = it.ID
  3789. }
  3790. }
  3791. drug.Manufacturer = manufacturer_id
  3792. dealer := goodNameM["dealer"].(string)
  3793. if len(dealer) != 0 {
  3794. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  3795. if errcodesdealer == gorm.ErrRecordNotFound {
  3796. dealerconfig := models.Dealer{
  3797. DealerName: dealer,
  3798. Status: 1,
  3799. OrgId: orgId,
  3800. Ctime: time.Now().Unix(),
  3801. Creater: adminUser.AdminUser.Id,
  3802. }
  3803. service.CreateDealer(&dealerconfig)
  3804. }
  3805. }
  3806. var dealer_id int64
  3807. dealerList, _ := service.GetAllDealerList(orgId)
  3808. for _, it := range dealerList {
  3809. if dealer == it.DealerName {
  3810. dealer_id = it.ID
  3811. }
  3812. }
  3813. drug.Dealer = dealer_id
  3814. delivery_way := goodNameM["delivery_way"].(string)
  3815. drug.DeliveryWay = delivery_way
  3816. execution_frequency := goodNameM["execution_frequency"].(string)
  3817. drug.ExecutionFrequency = execution_frequency
  3818. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  3819. drug.LmtUsedFlag = lmt_used_flags
  3820. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  3821. if len(drugDoseUnit) != 0 {
  3822. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  3823. if errcodedataconfig == gorm.ErrRecordNotFound {
  3824. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  3825. dataconfig := models.Dataconfig{
  3826. ParentId: dataConfig.ID,
  3827. Module: "hemodialysis",
  3828. OrgId: orgId,
  3829. Name: drugDoseUnit,
  3830. FieldName: "",
  3831. Value: childConfig.Value + 1,
  3832. CreatedTime: "",
  3833. UpdatedTime: "",
  3834. CreateUserId: adminUser.AdminUser.Id,
  3835. Status: 1,
  3836. Remark: "",
  3837. DeleteIdSystem: 0,
  3838. Title: "",
  3839. Content: "",
  3840. Order: 0,
  3841. Code: "",
  3842. FieldType: 0,
  3843. }
  3844. service.CreateDataConfig(&dataconfig)
  3845. }
  3846. }
  3847. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  3848. for _, it := range list {
  3849. if drugDoseUnit == it.Name {
  3850. unit_id = int64(it.Value)
  3851. }
  3852. }
  3853. drug.DrugDoseUnit = unit_id
  3854. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  3855. utils.ErrorLog("drug_alias")
  3856. return
  3857. }
  3858. drug_alias, _ := goodNameM["drug_alias"].(string)
  3859. drug.DrugAlias = drug_alias
  3860. drug_category := goodNameM["drug_category"].(string)
  3861. var drugCategory = "药品类别"
  3862. var drug_category_id int64
  3863. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  3864. if len(drug_category) != 0 {
  3865. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  3866. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  3867. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  3868. dataconfig := models.DictDataconfig{
  3869. ParentId: drugCategoryConfig.ID,
  3870. Module: "system",
  3871. OrgId: orgId,
  3872. Name: drug_category,
  3873. FieldName: "",
  3874. Value: drugCategoryConfigSix.Value + 1,
  3875. CreatedTime: "",
  3876. UpdatedTime: "",
  3877. CreateUserId: adminUser.AdminUser.Id,
  3878. Status: 1,
  3879. Remark: "",
  3880. DeleteIdSystem: 0,
  3881. Title: "",
  3882. Content: "",
  3883. Order: 0,
  3884. Code: "",
  3885. }
  3886. service.CreatedDicConfig(&dataconfig)
  3887. }
  3888. }
  3889. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  3890. fmt.Println("drugCategoryList", drugCategoryList)
  3891. for _, it := range drugCategoryList {
  3892. if drug_category == it.Name {
  3893. drug_category_id = int64(it.Value)
  3894. }
  3895. }
  3896. drug.DrugCategory = drug_category_id
  3897. statistics_category := goodNameM["statistics_category"].(string)
  3898. var statisticsCategory = "统计分类"
  3899. var statistics_category_id int64
  3900. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3901. if len(statistics_category) != 0 {
  3902. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  3903. if errcodestatistc == gorm.ErrRecordNotFound {
  3904. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  3905. dataconfig := models.DictDataconfig{
  3906. ParentId: statistcConfig.ID,
  3907. Module: "system",
  3908. OrgId: orgId,
  3909. Name: statistics_category,
  3910. FieldName: "",
  3911. Value: staConfig.Value + 1,
  3912. CreatedTime: "",
  3913. UpdatedTime: "",
  3914. CreateUserId: adminUser.AdminUser.Id,
  3915. Status: 1,
  3916. Remark: "",
  3917. DeleteIdSystem: 0,
  3918. Title: "",
  3919. Content: "",
  3920. Order: 0,
  3921. Code: "",
  3922. }
  3923. service.CreatedDicConfig(&dataconfig)
  3924. }
  3925. }
  3926. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  3927. for _, it := range statisticsCategoryList {
  3928. if statistics_category == it.Name {
  3929. statistics_category_id = int64(it.Value)
  3930. }
  3931. }
  3932. drug.StatisticsCategory = statistics_category_id
  3933. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  3934. drug.HospApprFlag = hosp_appr_flag
  3935. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3936. drug.MedicalInsuranceNumber = medical_insurance_number
  3937. pharmacology_category := goodNameM["pharmacology_category"].(string)
  3938. var pharmacology = "药理分类"
  3939. var pharmacology_category_id int64
  3940. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  3941. if len(pharmacology_category) != 0 {
  3942. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  3943. if errcodespharmacology == gorm.ErrRecordNotFound {
  3944. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  3945. dataconfig := models.DictDataconfig{
  3946. ParentId: pharmacologyConfig.ID,
  3947. Module: "system",
  3948. OrgId: orgId,
  3949. Name: pharmacology_category,
  3950. FieldName: "",
  3951. Value: dicConfig.Value + 1,
  3952. CreatedTime: "",
  3953. UpdatedTime: "",
  3954. CreateUserId: adminUser.AdminUser.Id,
  3955. Status: 1,
  3956. Remark: "",
  3957. DeleteIdSystem: 0,
  3958. Title: "",
  3959. Content: "",
  3960. Order: 0,
  3961. Code: "",
  3962. }
  3963. service.CreatedDicConfig(&dataconfig)
  3964. }
  3965. }
  3966. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  3967. for _, it := range pharmacologyList {
  3968. if pharmacology_category == it.Name {
  3969. pharmacology_category_id = int64(it.Value)
  3970. }
  3971. }
  3972. drug.PharmacologyCategory = pharmacology_category_id
  3973. code := goodNameM["code"].(string)
  3974. drug.Code = code
  3975. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3976. drug.IsSpecialDiseases = is_special_diseases
  3977. is_record := int64(goodNameM["is_record"].(float64))
  3978. drug.IsRecord = is_record
  3979. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  3980. drug.PrescriptionMark = prescription_mark
  3981. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3982. drug.SocialSecurityDirectoryCode = social_security_directory_code
  3983. record_date := goodNameM["record_date"].(string)
  3984. timeLayout := "2006-01-02"
  3985. loc, _ := time.LoadLocation("Local")
  3986. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3987. drug.RecordDate = theTime.Unix()
  3988. drug_remark := goodNameM["drug_remark"].(string)
  3989. drug.DrugRemark = drug_remark
  3990. drug_status := goodNameM["drug_status"].(string)
  3991. drug.DrugStatus = drug_status
  3992. limit_remark := goodNameM["limit_remark"].(string)
  3993. drug.LimitRemark = limit_remark
  3994. min_prices := goodNameM["min_price"].(string)
  3995. min_price, _ := strconv.ParseFloat(min_prices, 64)
  3996. drug.MinPrice = min_price
  3997. dose := goodNameM["dose"].(string)
  3998. //dose, _ := strconv.ParseFloat(doses, 64)
  3999. if len(dose) < 0 { //名字为空则生成一条导入错误日志
  4000. err_log := models.ExportErrLog{
  4001. LogType: 4,
  4002. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4003. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  4004. Status: 1,
  4005. CreateTime: time.Now().Unix(),
  4006. UpdateTime: time.Now().Unix(),
  4007. ExportTime: time.Now().Unix(),
  4008. }
  4009. service.CreateExportErrLog(&err_log)
  4010. continue
  4011. }
  4012. drug.Dose = dose
  4013. if len(dose) < 0 { //名字为空则生成一条导入错误日志
  4014. err_log := models.ExportErrLog{
  4015. LogType: 4,
  4016. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4017. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  4018. Status: 1,
  4019. CreateTime: time.Now().Unix(),
  4020. UpdateTime: time.Now().Unix(),
  4021. ExportTime: time.Now().Unix(),
  4022. }
  4023. service.CreateExportErrLog(&err_log)
  4024. continue
  4025. }
  4026. drugList = append(drugList, &drug)
  4027. }
  4028. export_time := time.Now().Unix()
  4029. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  4030. if len(drugList) > 0 {
  4031. for _, item := range drugList {
  4032. fmt.Println("retial2332332233232323223322323", item.DoseUnit)
  4033. goodInfo := models.BaseDrugLib{
  4034. DrugName: item.DrugName,
  4035. DrugAlias: item.DrugAlias,
  4036. DrugSpec: item.DrugSpec,
  4037. DrugType: item.DrugType,
  4038. DrugStockLimit: item.DrugStockLimit,
  4039. DrugOriginPlace: item.DrugOriginPlace,
  4040. DrugDosageForm: item.DrugDosageForm,
  4041. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  4042. MaxUnit: item.MaxUnit,
  4043. MinUnit: item.MinUnit,
  4044. UnitMatrixing: item.UnitMatrixing,
  4045. RetailPrice: item.RetailPrice,
  4046. LastPrice: item.LastPrice,
  4047. DrugClassify: item.DrugClassify,
  4048. Manufacturer: item.Manufacturer,
  4049. Dealer: item.Dealer,
  4050. OrgId: orgId,
  4051. Status: 1,
  4052. Ctime: time.Now().Unix(),
  4053. Pinyin: item.Pinyin,
  4054. Wubi: item.Wubi,
  4055. DrugAliasPinyin: item.DrugAliasPinyin,
  4056. DrugAliasWubi: item.DrugAliasWubi,
  4057. DrugControl: item.DrugControl,
  4058. Number: item.Number,
  4059. HospApprFlag: item.HospApprFlag,
  4060. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  4061. PharmacologyCategory: item.PharmacologyCategory,
  4062. StatisticsCategory: item.StatisticsCategory,
  4063. Code: item.Code,
  4064. IsSpecialDiseases: item.IsSpecialDiseases,
  4065. IsRecord: item.IsRecord,
  4066. PrescriptionMark: item.PrescriptionMark,
  4067. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  4068. RecordDate: item.RecordDate,
  4069. DrugRemark: item.DrugRemark,
  4070. DrugStatus: item.DrugStatus,
  4071. LimitRemark: item.LimitRemark,
  4072. DrugCategory: item.DrugCategory,
  4073. DrugDose: item.DrugDose,
  4074. DrugDoseUnit: item.DrugDoseUnit,
  4075. LmtUsedFlag: item.LmtUsedFlag,
  4076. DrugDay: item.DrugDay,
  4077. DeliveryWay: item.DeliveryWay,
  4078. ExecutionFrequency: item.ExecutionFrequency,
  4079. DoseUnit: item.DoseUnit,
  4080. Dose: item.Dose,
  4081. MinNumber: item.MinNumber,
  4082. IsUse: 2,
  4083. MinPrice: item.MinPrice,
  4084. }
  4085. //查询同种药品同种规格是否存在
  4086. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.DoseUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  4087. if drugerror == gorm.ErrRecordNotFound {
  4088. service.CreateDrugsInfomation(&goodInfo)
  4089. } else if drugerror == nil {
  4090. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  4091. }
  4092. log := models.ExportLog{
  4093. LogType: 4,
  4094. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4095. TotalNum: int64(len(total_goods)),
  4096. FailNum: int64(len(errLogs)),
  4097. SuccessNum: int64(len(drugList)),
  4098. CreateTime: time.Now().Unix(),
  4099. UpdateTime: time.Now().Unix(),
  4100. ExportTime: export_time,
  4101. Status: 1,
  4102. }
  4103. service.CreateExportLog(&log)
  4104. this.ServeSuccessJSON(map[string]interface{}{
  4105. "msg": "导入成功",
  4106. "total_num": len(total_goods),
  4107. "success_num": len(drugList),
  4108. "fail_num": int64(len(errLogs)),
  4109. })
  4110. }
  4111. } else {
  4112. log := models.ExportLog{
  4113. LogType: 4,
  4114. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4115. TotalNum: int64(len(total_goods)),
  4116. FailNum: int64(len(errLogs)),
  4117. SuccessNum: int64(len(drugList)),
  4118. CreateTime: time.Now().Unix(),
  4119. UpdateTime: time.Now().Unix(),
  4120. ExportTime: export_time,
  4121. Status: 1,
  4122. }
  4123. service.CreateExportLog(&log)
  4124. this.ServeSuccessJSON(map[string]interface{}{
  4125. "msg": "导入成功",
  4126. "total_num": len(total_goods),
  4127. "success_num": len(drugList),
  4128. "fail_num": int64(len(errLogs)),
  4129. })
  4130. }
  4131. }
  4132. func (this *StockManagerApiController) GetInitializtion() {
  4133. orgId := this.GetAdminUserInfo().CurrentOrgId
  4134. var drugCategory = "药品类别"
  4135. var drugType = "药品类型"
  4136. var drugDosageForm = "药品剂型"
  4137. var medicalInsuranceLevel = "医保等级"
  4138. var drugControl = "开药控制"
  4139. var drugClassify = "药物分类"
  4140. var statisticsCategory = "统计分类"
  4141. var pharmacologyCategory = "药理分类"
  4142. var goodKind = "耗材种类"
  4143. var tubeColor = "试管颜色"
  4144. var costClassify = "费用类别"
  4145. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  4146. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  4147. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  4148. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  4149. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  4150. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  4151. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  4152. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  4153. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  4154. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  4155. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  4156. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  4157. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  4158. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  4159. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  4160. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  4161. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  4162. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  4163. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  4164. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  4165. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  4166. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  4167. this.ServeSuccessJSON(map[string]interface{}{
  4168. "drugCategoryList": drugCategoryList,
  4169. "drugTypeList": drugTypeList,
  4170. "drugDosageFormList": drugDosageFormList,
  4171. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  4172. "drugControlList": drugControlList,
  4173. "drugClassifyList": drugClassifyList,
  4174. "statisticsCategoryList": statisticsCategoryList,
  4175. "pharmacologyCategoryList": pharmacologyCategoryList,
  4176. "goodKindList": goodKindList,
  4177. "tubeColorList": tubeColorList,
  4178. "costClassifyList": costClassifyList,
  4179. })
  4180. }
  4181. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  4182. adminUserInfo := this.GetAdminUserInfo()
  4183. orgId := adminUserInfo.CurrentOrgId
  4184. list, _ := service.GetWarehouseOrderInfoList(orgId)
  4185. this.ServeSuccessJSON(map[string]interface{}{
  4186. "list": list,
  4187. })
  4188. }
  4189. func (this *StockManagerApiController) PostSearchGoodList() {
  4190. keyword := this.GetString("keyword")
  4191. adminUserInfo := this.GetAdminUserInfo()
  4192. orgId := adminUserInfo.CurrentOrgId
  4193. storehouse_id, _ := this.GetInt64("storehouse_id")
  4194. list, _ := service.GetSearchGoodListSix(keyword, orgId, storehouse_id)
  4195. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4196. dealerList, _ := service.GetAllDealerList(orgId)
  4197. this.ServeSuccessJSON(map[string]interface{}{
  4198. "list": list,
  4199. "manufacturerList": manufacturerList,
  4200. "dealerList": dealerList,
  4201. })
  4202. }
  4203. func (this *StockManagerApiController) GetAllStockList() {
  4204. page, _ := this.GetInt64("page", -1)
  4205. limit, _ := this.GetInt64("limit", -1)
  4206. start_time := this.GetString("start_time")
  4207. end_time := this.GetString("end_time")
  4208. types, _ := this.GetInt64("type", 0)
  4209. keywords := this.GetString("keywords")
  4210. good_id, _ := this.GetInt64("good_id")
  4211. storehouse_id, _ := this.GetInt64("storehouse_id")
  4212. timeLayout := "2006-01-02"
  4213. loc, _ := time.LoadLocation("Local")
  4214. var startTime int64
  4215. if len(start_time) > 0 {
  4216. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4217. if err != nil {
  4218. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4219. return
  4220. }
  4221. startTime = theTime.Unix()
  4222. }
  4223. var endTime int64
  4224. if len(end_time) > 0 {
  4225. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4226. if err != nil {
  4227. utils.ErrorLog(err.Error())
  4228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4229. return
  4230. }
  4231. endTime = theTime.Unix()
  4232. }
  4233. adminUserInfo := this.GetAdminUserInfo()
  4234. orgId := adminUserInfo.CurrentOrgId
  4235. list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId, good_id, storehouse_id)
  4236. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4237. this.ServeSuccessJSON(map[string]interface{}{
  4238. "list": list,
  4239. "total": total,
  4240. "manufacturerList": manufacturerList,
  4241. })
  4242. }
  4243. func (this *StockManagerApiController) GetStockListById() {
  4244. id, _ := this.GetInt64("id")
  4245. adminUserInfo := this.GetAdminUserInfo()
  4246. orgId := adminUserInfo.CurrentOrgId
  4247. limit, _ := this.GetInt64("limit")
  4248. page, _ := this.GetInt64("page")
  4249. timeLayout := "2006-01-02"
  4250. loc, _ := time.LoadLocation("Local")
  4251. start_time := this.GetString("start_time")
  4252. end_time := this.GetString("end_time")
  4253. start_first_time := this.GetString("start_first_time")
  4254. end_first_time := this.GetString("end_first_time")
  4255. var startTime int64
  4256. if len(start_time) > 0 {
  4257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4258. if err != nil {
  4259. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4260. return
  4261. }
  4262. startTime = theTime.Unix()
  4263. }
  4264. var endTime int64
  4265. if len(end_time) > 0 {
  4266. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4267. if err != nil {
  4268. utils.ErrorLog(err.Error())
  4269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4270. return
  4271. }
  4272. endTime = theTime.Unix()
  4273. }
  4274. var startFistTime int64
  4275. if len(start_first_time) > 0 {
  4276. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_first_time+" 00:00:00", loc)
  4277. if err != nil {
  4278. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4279. return
  4280. }
  4281. startFistTime = theTime.Unix()
  4282. }
  4283. var endFirstTime int64
  4284. if len(end_first_time) > 0 {
  4285. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_first_time+" 23:59:59", loc)
  4286. if err != nil {
  4287. utils.ErrorLog(err.Error())
  4288. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4289. return
  4290. }
  4291. endFirstTime = theTime.Unix()
  4292. }
  4293. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4294. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime, startFistTime, endFirstTime)
  4295. houseList, _ := service.GetAllStoreHouseList(orgId)
  4296. good, _ := service.GetGoodInformationByGoodId(id)
  4297. this.ServeSuccessJSON(map[string]interface{}{
  4298. "list": list,
  4299. "total": total,
  4300. "manufacturerList": manufacturerList,
  4301. "houseList": houseList,
  4302. "good": good,
  4303. })
  4304. }
  4305. func (this *StockManagerApiController) GetStockOutList() {
  4306. id, _ := this.GetInt64("id")
  4307. adminUserInfo := this.GetAdminUserInfo()
  4308. orgId := adminUserInfo.CurrentOrgId
  4309. limit, _ := this.GetInt64("limit")
  4310. page, _ := this.GetInt64("page")
  4311. timeLayout := "2006-01-02"
  4312. loc, _ := time.LoadLocation("Local")
  4313. start_time := this.GetString("start_time")
  4314. end_time := this.GetString("end_time")
  4315. is_sys, _ := this.GetInt64("is_sys")
  4316. var startTime int64
  4317. if len(start_time) > 0 {
  4318. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4319. if err != nil {
  4320. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4321. return
  4322. }
  4323. startTime = theTime.Unix()
  4324. }
  4325. var endTime int64
  4326. if len(end_time) > 0 {
  4327. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4328. if err != nil {
  4329. utils.ErrorLog(err.Error())
  4330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4331. return
  4332. }
  4333. endTime = theTime.Unix()
  4334. }
  4335. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  4336. this.ServeSuccessJSON(map[string]interface{}{
  4337. "outList": outList,
  4338. "total": total,
  4339. })
  4340. }
  4341. func (this *StockManagerApiController) GetStockDrugCount() {
  4342. adminUserInfo := this.GetAdminUserInfo()
  4343. orgId := adminUserInfo.CurrentOrgId
  4344. fmt.Println(orgId)
  4345. timeLayout := "2006-01-02"
  4346. loc, _ := time.LoadLocation("Local")
  4347. start_time := this.GetString("start_time")
  4348. end_time := this.GetString("end_time")
  4349. var startTime int64
  4350. if len(start_time) > 0 {
  4351. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4352. if err != nil {
  4353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4354. return
  4355. }
  4356. startTime = theTime.Unix()
  4357. }
  4358. var endTime int64
  4359. if len(end_time) > 0 {
  4360. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4361. if err != nil {
  4362. utils.ErrorLog(err.Error())
  4363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4364. return
  4365. }
  4366. endTime = theTime.Unix()
  4367. }
  4368. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  4369. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  4370. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  4371. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  4372. this.ServeSuccessJSON(map[string]interface{}{
  4373. "count": count,
  4374. "outList": outList,
  4375. "autoCount": autoCount,
  4376. "totalCount": totalCount,
  4377. })
  4378. }
  4379. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  4380. ids := this.GetString("id")
  4381. idsArray := strings.Split(ids, ",")
  4382. orgId := this.GetAdminUserInfo().CurrentOrgId
  4383. order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
  4384. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  4385. stockFlowListGroup, _ := service.GetOrderDetailStockFlowByStorehouseById(idsArray, orgId)
  4386. stockFlowList, _ := service.GetOrderDetailStockFlow(idsArray, orgId)
  4387. //获取耗材退库数据
  4388. cancelInfolist, _ := service.GetOrderStockFlow(idsArray, orgId)
  4389. this.ServeSuccessJSON(map[string]interface{}{
  4390. "list": list,
  4391. "order": order,
  4392. "stockFlowList": stockFlowList,
  4393. "stockFlowListGroup": stockFlowListGroup,
  4394. "cancelInfolist": cancelInfolist,
  4395. })
  4396. }
  4397. func (this *StockManagerApiController) GetOrderDetailById() {
  4398. id, _ := this.GetInt64("id")
  4399. good_id, _ := this.GetInt64("good_id")
  4400. record_time, _ := this.GetInt64("record_time")
  4401. orgId := this.GetAdminUserInfo().CurrentOrgId
  4402. //自动出库
  4403. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  4404. //手动出库
  4405. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  4406. //出库数据
  4407. stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
  4408. //退库数据
  4409. cancelInfo, err := service.GetStockFlowCancelInfo(id, good_id)
  4410. if err == nil {
  4411. this.ServeSuccessJSON(map[string]interface{}{
  4412. "list": userDetails,
  4413. "total": total,
  4414. "info": info,
  4415. "stockFlowList": stockFlowList,
  4416. "cancelInfo": cancelInfo,
  4417. })
  4418. } else {
  4419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4420. return
  4421. }
  4422. }
  4423. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  4424. id, _ := this.GetInt64("id", 0)
  4425. orgId := this.GetAdminUserInfo().CurrentOrgId
  4426. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  4427. out, _ := service.GetGoodWarehouseOutById(id, orgId)
  4428. storelist, _ := service.GetAllStoreHouseList(orgId)
  4429. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4430. dealerList, _ := service.GetAllDealerList(orgId)
  4431. goodType, _ := service.GetAllGoodType(orgId)
  4432. appId := this.GetAdminUserInfo().CurrentAppId
  4433. doctorlist, _ := service.GetAllDoctorListSix(orgId, appId)
  4434. this.ServeSuccessJSON(map[string]interface{}{
  4435. "list": warehouseOutInfo,
  4436. "dealerList": dealerList,
  4437. "manufacturerList": manufacturerList,
  4438. "goodType": goodType,
  4439. "out": out,
  4440. "storelist": storelist,
  4441. "doctorlist": doctorlist,
  4442. })
  4443. }
  4444. func (this *StockManagerApiController) GetExprotStockList() {
  4445. adminUserInfo := this.GetAdminUserInfo()
  4446. orgId := adminUserInfo.CurrentOrgId
  4447. timeLayout := "2006-01-02"
  4448. loc, _ := time.LoadLocation("Local")
  4449. start_time := this.GetString("start_time")
  4450. end_time := this.GetString("end_time")
  4451. storehouse_id, _ := this.GetInt64("storehouse_id")
  4452. idArray := this.GetString("id")
  4453. ids := strings.Split(idArray, ",")
  4454. var startTime int64
  4455. if len(start_time) > 0 {
  4456. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4457. if err != nil {
  4458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4459. return
  4460. }
  4461. startTime = theTime.Unix()
  4462. }
  4463. var endTime int64
  4464. if len(end_time) > 0 {
  4465. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4466. if err != nil {
  4467. utils.ErrorLog(err.Error())
  4468. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4469. return
  4470. }
  4471. endTime = theTime.Unix()
  4472. }
  4473. list, _ := service.GetExprotStockListTwenty(orgId, ids, startTime, endTime, storehouse_id)
  4474. this.ServeSuccessJSON(map[string]interface{}{
  4475. "list": list,
  4476. })
  4477. }
  4478. func (this *StockManagerApiController) GetOutExprotList() {
  4479. adminUserInfo := this.GetAdminUserInfo()
  4480. orgId := adminUserInfo.CurrentOrgId
  4481. timeLayout := "2006-01-02"
  4482. loc, _ := time.LoadLocation("Local")
  4483. start_time := this.GetString("start_time")
  4484. end_time := this.GetString("end_time")
  4485. idArray := this.GetString("id")
  4486. ids := strings.Split(idArray, ",")
  4487. fmt.Println("ids2222222222", ids)
  4488. var startTime int64
  4489. if len(start_time) > 0 {
  4490. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4491. if err != nil {
  4492. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4493. return
  4494. }
  4495. startTime = theTime.Unix()
  4496. }
  4497. var endTime int64
  4498. if len(end_time) > 0 {
  4499. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4500. if err != nil {
  4501. utils.ErrorLog(err.Error())
  4502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4503. return
  4504. }
  4505. endTime = theTime.Unix()
  4506. }
  4507. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  4508. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  4509. this.ServeSuccessJSON(map[string]interface{}{
  4510. "list": list,
  4511. "count": outCount,
  4512. })
  4513. }
  4514. func (this *StockManagerApiController) GetSingleCancelOrder() {
  4515. id, _ := this.GetInt64("id")
  4516. adminUserInfo := this.GetAdminUserInfo()
  4517. orgId := adminUserInfo.CurrentOrgId
  4518. order, _ := service.GetSingleCancelOrder(id, orgId)
  4519. this.ServeSuccessJSON(map[string]interface{}{
  4520. "list": order,
  4521. })
  4522. }
  4523. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  4524. id := this.GetString("id")
  4525. idStr := strings.Split(id, ",")
  4526. orgId := this.GetAdminUserInfo().CurrentOrgId
  4527. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  4528. this.ServeSuccessJSON(map[string]interface{}{
  4529. "list": list,
  4530. })
  4531. }
  4532. func (this *StockManagerApiController) GetStockBatchNumber() {
  4533. id, _ := this.GetInt64("id")
  4534. orgId := this.GetAdminUserInfo().CurrentOrgId
  4535. list, _ := service.GetStockBatchNumber(id, orgId)
  4536. this.ServeSuccessJSON(map[string]interface{}{
  4537. "list": list,
  4538. })
  4539. }
  4540. func (this *StockManagerApiController) GetStockFlow() {
  4541. limit, _ := this.GetInt64("limit")
  4542. page, _ := this.GetInt64("page")
  4543. good_id, _ := this.GetInt64("good_id")
  4544. consumable_type, _ := this.GetInt64("is_sys")
  4545. adminUserInfo := this.GetAdminUserInfo()
  4546. orgId := adminUserInfo.CurrentOrgId
  4547. timeLayout := "2006-01-02"
  4548. loc, _ := time.LoadLocation("Local")
  4549. start_time := this.GetString("start_time")
  4550. end_time := this.GetString("end_time")
  4551. var startTime int64
  4552. if len(start_time) > 0 {
  4553. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4554. if err != nil {
  4555. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4556. return
  4557. }
  4558. startTime = theTime.Unix()
  4559. }
  4560. var endTime int64
  4561. if len(end_time) > 0 {
  4562. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4563. if err != nil {
  4564. utils.ErrorLog(err.Error())
  4565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4566. return
  4567. }
  4568. endTime = theTime.Unix()
  4569. }
  4570. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  4571. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4572. good, _ := service.GetGoodInformationByGoodId(good_id)
  4573. houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  4574. this.ServeSuccessJSON(map[string]interface{}{
  4575. "list": list,
  4576. "total": total,
  4577. "manufacturerList": manufacturerList,
  4578. "good": good,
  4579. "houseList": houseList,
  4580. })
  4581. }
  4582. func (this *StockManagerApiController) GetCancelExportList() {
  4583. adminUserInfo := this.GetAdminUserInfo()
  4584. orgId := adminUserInfo.CurrentOrgId
  4585. timeLayout := "2006-01-02"
  4586. loc, _ := time.LoadLocation("Local")
  4587. start_time := this.GetString("start_time")
  4588. end_time := this.GetString("end_time")
  4589. idArray := this.GetString("order_id")
  4590. fmt.Println("232323232323232232", idArray)
  4591. ids := strings.Split(idArray, ",")
  4592. var startTime int64
  4593. if len(start_time) > 0 {
  4594. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4595. if err != nil {
  4596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4597. return
  4598. }
  4599. startTime = theTime.Unix()
  4600. }
  4601. var endTime int64
  4602. if len(end_time) > 0 {
  4603. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4604. if err != nil {
  4605. utils.ErrorLog(err.Error())
  4606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4607. return
  4608. }
  4609. endTime = theTime.Unix()
  4610. }
  4611. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  4612. this.ServeSuccessJSON(map[string]interface{}{
  4613. "list": list,
  4614. })
  4615. }
  4616. func (this *StockManagerApiController) GetSearchGoodWarehouseList() {
  4617. keyword := this.GetString("keyword")
  4618. storehouse_id, _ := this.GetInt64("storehouse_id")
  4619. orgId := this.GetAdminUserInfo().CurrentOrgId
  4620. list, _ := service.GetSearchGoodWarehouseList(keyword, orgId, storehouse_id)
  4621. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4622. dealerList, _ := service.GetAllDealerList(orgId)
  4623. this.ServeSuccessJSON(map[string]interface{}{
  4624. "list": list,
  4625. "manufacturerList": manufacturerList,
  4626. "dealerList": dealerList,
  4627. })
  4628. }
  4629. func (this *StockManagerApiController) SaveAdjuestPrice() {
  4630. timeLayout := "2006-01-02"
  4631. loc, _ := time.LoadLocation("Local")
  4632. dataBody := make(map[string]interface{}, 0)
  4633. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4634. if err != nil {
  4635. utils.ErrorLog(err.Error())
  4636. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4637. return
  4638. }
  4639. tableData, _ := dataBody["tableData"].([]interface{})
  4640. if len(tableData) > 0 {
  4641. for _, item := range tableData {
  4642. items := item.(map[string]interface{})
  4643. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4644. utils.ErrorLog("good_name")
  4645. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4646. return
  4647. }
  4648. good_name := items["good_name"].(string)
  4649. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4650. utils.ErrorLog("good_name")
  4651. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4652. return
  4653. }
  4654. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4655. utils.ErrorLog("packing_price")
  4656. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4657. return
  4658. }
  4659. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4660. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4661. utils.ErrorLog("warehousing_order")
  4662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4663. return
  4664. }
  4665. warehousing_order := items["warehousing_order"].(string)
  4666. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4667. utils.ErrorLog("license_number")
  4668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4669. return
  4670. }
  4671. license_number := items["license_number"].(string)
  4672. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4673. utils.ErrorLog("dealer")
  4674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4675. return
  4676. }
  4677. dealer := items["dealer"].(string)
  4678. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4679. utils.ErrorLog("manufacturer")
  4680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4681. return
  4682. }
  4683. manufacturer := items["manufacturer"].(string)
  4684. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4685. utils.ErrorLog("specification_name")
  4686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4687. return
  4688. }
  4689. specification_name := items["specification_name"].(string)
  4690. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4691. utils.ErrorLog("remark")
  4692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4693. return
  4694. }
  4695. remark := items["remark"].(string)
  4696. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4697. utils.ErrorLog("warehousing_unit")
  4698. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4699. return
  4700. }
  4701. warehousing_unit := items["warehousing_unit"].(string)
  4702. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4703. utils.ErrorLog("buy_price")
  4704. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4705. return
  4706. }
  4707. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4708. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4709. utils.ErrorLog("count")
  4710. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4711. return
  4712. }
  4713. count := int64(items["count"].(float64))
  4714. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  4715. utils.ErrorLog("new_price")
  4716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4717. return
  4718. }
  4719. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  4720. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4721. utils.ErrorLog("good_id")
  4722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4723. return
  4724. }
  4725. good_id := int64(items["good_id"].(float64))
  4726. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4727. utils.ErrorLog("start_time")
  4728. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4729. return
  4730. }
  4731. var startTime int64
  4732. start_time := items["start_time"].(string)
  4733. if len(start_time) > 0 {
  4734. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4735. if err != nil {
  4736. fmt.Println(err)
  4737. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4738. return
  4739. }
  4740. startTime = theTime.Unix()
  4741. }
  4742. orgId := this.GetAdminUserInfo().CurrentOrgId
  4743. adjustprice := models.XtStockAdjustPrice{
  4744. GoodName: good_name,
  4745. SpecificationName: specification_name,
  4746. WarehousingUnit: warehousing_unit,
  4747. Count: count,
  4748. BuyPrice: buy_price,
  4749. PackingPrice: packing_price,
  4750. NewPrice: new_price,
  4751. Manufacturer: manufacturer,
  4752. Dealer: dealer,
  4753. Remark: remark,
  4754. GoodId: good_id,
  4755. UserOrgId: orgId,
  4756. Ctime: time.Now().Unix(),
  4757. Mtime: 0,
  4758. Status: 1,
  4759. WarehousingOrder: warehousing_order,
  4760. LicenseNumber: license_number,
  4761. StartTime: startTime,
  4762. Creater: this.GetAdminUserInfo().AdminUser.Id,
  4763. CheckerStatus: 2,
  4764. }
  4765. service.CreateAdjustPrice(&adjustprice)
  4766. }
  4767. }
  4768. this.ServeSuccessJSON(map[string]interface{}{
  4769. "msg": "保存成功!",
  4770. })
  4771. }
  4772. func (this *StockManagerApiController) GetAllStockPrice() {
  4773. timeLayout := "2006-01-02"
  4774. loc, _ := time.LoadLocation("Local")
  4775. dataBody := make(map[string]interface{}, 0)
  4776. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4777. fmt.Println(err)
  4778. orgId := this.GetAdminUserInfo().CurrentOrgId
  4779. keyword := this.GetString("keyword")
  4780. start_time := this.GetString("start_time")
  4781. end_time := this.GetString("end_time")
  4782. limit, _ := this.GetInt64("limit")
  4783. page, _ := this.GetInt64("page")
  4784. var startTime int64
  4785. if len(start_time) > 0 {
  4786. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4787. if err != nil {
  4788. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4789. return
  4790. }
  4791. startTime = theTime.Unix()
  4792. }
  4793. var endTime int64
  4794. if len(end_time) > 0 {
  4795. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4796. if err != nil {
  4797. utils.ErrorLog(err.Error())
  4798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4799. return
  4800. }
  4801. endTime = theTime.Unix()
  4802. }
  4803. list, total, _ := service.GetAllStockPrice(orgId, startTime, endTime, keyword, limit, page)
  4804. doctor, _ := service.GetAllDoctorThree(orgId)
  4805. this.ServeSuccessJSON(map[string]interface{}{
  4806. "list": list,
  4807. "doctor": doctor,
  4808. "total": total,
  4809. })
  4810. }
  4811. func (this *StockManagerApiController) SaveCheckPrice() {
  4812. timeLayout := "2006-01-02"
  4813. loc, _ := time.LoadLocation("Local")
  4814. dataBody := make(map[string]interface{}, 0)
  4815. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4816. fmt.Println(err)
  4817. idstr := this.GetString("ids")
  4818. ids := strings.Split(idstr, ",")
  4819. check_time := this.GetString("check_time")
  4820. var checkTime int64
  4821. if len(check_time) > 0 {
  4822. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4823. if err != nil {
  4824. fmt.Println(err)
  4825. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4826. return
  4827. }
  4828. checkTime = theTime.Unix()
  4829. }
  4830. checker, _ := this.GetInt64("checker")
  4831. adjustPrice := models.XtStockAdjustPrice{
  4832. Checker: checker,
  4833. CheckerStatus: 1,
  4834. CheckerTime: checkTime,
  4835. }
  4836. err = service.UpdateAdjustPrice(ids, adjustPrice)
  4837. fmt.Println(err)
  4838. list, _ := service.GetAdjustCheckPriceList(ids)
  4839. fmt.Println("list2333223323232323232323", list)
  4840. for _, item := range list {
  4841. info := models.GoodInfo{
  4842. PackingPrice: item.NewPrice,
  4843. BuyPrice: item.NewPrice,
  4844. }
  4845. err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
  4846. fmt.Println(err)
  4847. }
  4848. this.ServeSuccessJSON(map[string]interface{}{
  4849. "adjustPrice": adjustPrice,
  4850. })
  4851. }
  4852. func (this *StockManagerApiController) GetAdjustPriceById() {
  4853. ids := this.GetString("ids")
  4854. fmt.Println("ids23232233223233232", ids)
  4855. splitIds := strings.Split(ids, ",")
  4856. list, _ := service.GetAdjustPricebyIdOne(splitIds)
  4857. fmt.Println("list2322322323", list)
  4858. this.ServeSuccessJSON(map[string]interface{}{
  4859. "list": list,
  4860. })
  4861. }
  4862. func (this *StockManagerApiController) SaveReportStock() {
  4863. timeLayout := "2006-01-02"
  4864. loc, _ := time.LoadLocation("Local")
  4865. dataBody := make(map[string]interface{}, 0)
  4866. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4867. if err != nil {
  4868. utils.ErrorLog(err.Error())
  4869. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4870. return
  4871. }
  4872. tableData, _ := dataBody["tableData"].([]interface{})
  4873. if len(tableData) > 0 {
  4874. for _, item := range tableData {
  4875. items := item.(map[string]interface{})
  4876. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4877. utils.ErrorLog("good_name")
  4878. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4879. return
  4880. }
  4881. good_name := items["good_name"].(string)
  4882. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4883. utils.ErrorLog("good_name")
  4884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4885. return
  4886. }
  4887. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4888. utils.ErrorLog("packing_price")
  4889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4890. return
  4891. }
  4892. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4893. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4894. utils.ErrorLog("warehousing_order")
  4895. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4896. return
  4897. }
  4898. warehousing_order := items["warehousing_order"].(string)
  4899. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4900. utils.ErrorLog("license_number")
  4901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4902. return
  4903. }
  4904. license_number := items["license_number"].(string)
  4905. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4906. utils.ErrorLog("dealer")
  4907. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4908. return
  4909. }
  4910. dealer := items["dealer"].(string)
  4911. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4912. utils.ErrorLog("manufacturer")
  4913. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4914. return
  4915. }
  4916. manufacturer := items["manufacturer"].(string)
  4917. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4918. utils.ErrorLog("specification_name")
  4919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4920. return
  4921. }
  4922. specification_name := items["specification_name"].(string)
  4923. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4924. utils.ErrorLog("remark")
  4925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4926. return
  4927. }
  4928. remark := items["remark"].(string)
  4929. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4930. utils.ErrorLog("warehousing_unit")
  4931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4932. return
  4933. }
  4934. warehousing_unit := items["warehousing_unit"].(string)
  4935. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4936. utils.ErrorLog("buy_price")
  4937. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4938. return
  4939. }
  4940. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4941. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4942. utils.ErrorLog("count")
  4943. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4944. return
  4945. }
  4946. count := int64(items["count"].(float64))
  4947. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4948. utils.ErrorLog("good_id")
  4949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4950. return
  4951. }
  4952. good_id := int64(items["good_id"].(float64))
  4953. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4954. utils.ErrorLog("start_time")
  4955. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4956. return
  4957. }
  4958. var startTime int64
  4959. start_time := items["start_time"].(string)
  4960. if len(start_time) > 0 {
  4961. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4962. if err != nil {
  4963. fmt.Println(err)
  4964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4965. return
  4966. }
  4967. startTime = theTime.Unix()
  4968. }
  4969. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4970. utils.ErrorLog("number")
  4971. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4972. return
  4973. }
  4974. number := items["number"].(string)
  4975. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4976. utils.ErrorLog("warehousing_info_id")
  4977. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4978. return
  4979. }
  4980. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4981. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4982. utils.ErrorLog("expiry_date")
  4983. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4984. return
  4985. }
  4986. expiry_date := int64(items["expiry_date"].(float64))
  4987. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4988. utils.ErrorLog("product_date")
  4989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4990. return
  4991. }
  4992. product_date := int64(items["product_date"].(float64))
  4993. orgId := this.GetAdminUserInfo().CurrentOrgId
  4994. Creater := this.GetAdminUserInfo().AdminUser.Id
  4995. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4996. utils.ErrorLog("total")
  4997. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4998. return
  4999. }
  5000. total := int64(items["total"].(float64))
  5001. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  5002. utils.ErrorLog("good_origin_place")
  5003. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5004. return
  5005. }
  5006. good_origin_place := items["good_origin_place"].(string)
  5007. reportPrice := models.XtStockReportPrice{
  5008. GoodName: good_name,
  5009. SpecificationName: specification_name,
  5010. WarehousingUnit: warehousing_unit,
  5011. Count: count,
  5012. BuyPrice: buy_price,
  5013. PackingPrice: packing_price,
  5014. Manufacturer: manufacturer,
  5015. Dealer: dealer,
  5016. Remark: remark,
  5017. GoodId: good_id,
  5018. UserOrgId: orgId,
  5019. Ctime: time.Now().Unix(),
  5020. Mtime: 0,
  5021. Status: 1,
  5022. WarehousingOrder: warehousing_order,
  5023. LicenseNumber: license_number,
  5024. StartTime: startTime,
  5025. Creater: Creater,
  5026. Checker: 0,
  5027. CheckerStatus: 2,
  5028. CheckerTime: 0,
  5029. Number: number,
  5030. WarehousingInfoId: warehousing_info_id,
  5031. ExpiryDate: expiry_date,
  5032. ProductDate: product_date,
  5033. Total: total,
  5034. GoodOriginPlace: good_origin_place,
  5035. }
  5036. err := service.CreateReportPrice(&reportPrice)
  5037. fmt.Println(err)
  5038. }
  5039. }
  5040. this.ServeSuccessJSON(map[string]interface{}{
  5041. "msg": "保存成功!",
  5042. })
  5043. }
  5044. func (this *StockManagerApiController) GetReportStockList() {
  5045. timeLayout := "2006-01-02"
  5046. loc, _ := time.LoadLocation("Local")
  5047. start_time := this.GetString("start_time")
  5048. end_time := this.GetString("end_time")
  5049. page, _ := this.GetInt64("page")
  5050. limit, _ := this.GetInt64("limit")
  5051. storehouse_id, _ := this.GetInt64("storehouse_id")
  5052. var startTime int64
  5053. if len(start_time) > 0 {
  5054. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5055. if err != nil {
  5056. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5057. return
  5058. }
  5059. startTime = theTime.Unix()
  5060. fmt.Println("开始时间", startTime)
  5061. }
  5062. var endTime int64
  5063. if len(end_time) > 0 {
  5064. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5065. if err != nil {
  5066. utils.ErrorLog(err.Error())
  5067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5068. return
  5069. }
  5070. endTime = theTime.Unix()
  5071. }
  5072. orgId := this.GetAdminUserInfo().CurrentOrgId
  5073. keyword := this.GetString("keyword")
  5074. list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit, startTime, endTime, storehouse_id)
  5075. damageList, _ := service.GetStockDamagedCount(orgId)
  5076. doctorlist, _ := service.GetAllDoctorThree(orgId)
  5077. houseList, _ := service.GetAllStoreHouseList(orgId)
  5078. this.ServeSuccessJSON(map[string]interface{}{
  5079. "list": list,
  5080. "total": total,
  5081. "doctorlist": doctorlist,
  5082. "damageList": damageList,
  5083. "houseList": houseList,
  5084. })
  5085. }
  5086. func (this *StockManagerApiController) SaveCheckDamage() {
  5087. timeLayout := "2006-01-02"
  5088. loc, _ := time.LoadLocation("Local")
  5089. idstr := this.GetString("ids")
  5090. ids := strings.Split(idstr, ",")
  5091. check_time := this.GetString("check_time")
  5092. var checkTime int64
  5093. if len(check_time) > 0 {
  5094. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5095. if err != nil {
  5096. fmt.Println(err)
  5097. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5098. return
  5099. }
  5100. checkTime = theTime.Unix()
  5101. }
  5102. checker, _ := this.GetInt64("checker")
  5103. reportprice := models.XtStockReportPrice{
  5104. Checker: checker,
  5105. CheckerStatus: 1,
  5106. CheckerTime: checkTime,
  5107. }
  5108. err := service.UpdateCheckDamage(ids, reportprice)
  5109. fmt.Println(err)
  5110. //获取当前核对的数据
  5111. list, _ := service.GetCheckDamageList(ids)
  5112. ctime := time.Now().Unix()
  5113. adminUserInfo := this.GetAdminUserInfo()
  5114. timeStr := time.Now().Format("2006-01-02")
  5115. timeArr := strings.Split(timeStr, "-")
  5116. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5117. total = total + 1
  5118. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5119. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5120. number = number + total
  5121. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5122. operation_time := time.Now().Unix()
  5123. creater := adminUserInfo.AdminUser.Id
  5124. warehouseOut := models.WarehouseOut{
  5125. WarehouseOutOrderNumber: warehousing_out_order,
  5126. OperationTime: operation_time,
  5127. OrgId: adminUserInfo.CurrentOrgId,
  5128. Creater: creater,
  5129. Ctime: ctime,
  5130. Status: 1,
  5131. WarehouseOutTime: ctime,
  5132. Type: 1,
  5133. }
  5134. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  5135. if errcodes == gorm.ErrRecordNotFound {
  5136. service.AddSigleWarehouseOut(&warehouseOut)
  5137. }
  5138. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  5139. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  5140. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  5141. var manufacturer_id int64
  5142. var dealer_id int64
  5143. for _, item := range list {
  5144. for _, it := range manufacturerList {
  5145. if item.Manufacturer == it.ManufacturerName {
  5146. manufacturer_id = it.ID
  5147. }
  5148. }
  5149. for _, its := range dealerList {
  5150. if item.Dealer == its.DealerName {
  5151. dealer_id = its.ID
  5152. }
  5153. }
  5154. goodinfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5155. //插入出库单
  5156. warehouseOutInfo := &models.WarehouseOutInfo{
  5157. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  5158. WarehouseOutId: out.ID,
  5159. GoodId: item.GoodId,
  5160. Count: item.Count,
  5161. Price: item.PackingPrice,
  5162. Status: 1,
  5163. Ctime: ctime,
  5164. Remark: item.Remark,
  5165. OrgId: adminUserInfo.CurrentOrgId,
  5166. Type: 2,
  5167. Manufacturer: manufacturer_id,
  5168. Number: item.Number,
  5169. ExpiryDate: item.ExpiryDate,
  5170. ProductDate: item.ProductDate,
  5171. Dealer: dealer_id,
  5172. LicenseNumber: item.LicenseNumber,
  5173. GoodTypeId: goodinfo.GoodTypeId,
  5174. }
  5175. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5176. fmt.Println("99999999999999", errOne)
  5177. //更改库存
  5178. info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5179. warehousingInfo := models.WarehousingInfo{
  5180. StockCount: info.StockCount - item.Count,
  5181. }
  5182. errOne = service.UpdateGoodWarehouseInfo(item.WarehousingInfoId, warehousingInfo)
  5183. fmt.Println(errOne)
  5184. flow := models.VmStockFlow{
  5185. WarehousingId: 0,
  5186. GoodId: item.GoodId,
  5187. Number: item.Number,
  5188. LicenseNumber: item.LicenseNumber,
  5189. Count: item.Count,
  5190. UserOrgId: adminUserInfo.CurrentOrgId,
  5191. PatientId: 0,
  5192. SystemTime: time.Now().Unix(),
  5193. ConsumableType: 5,
  5194. IsSys: 0,
  5195. WarehousingOrder: "",
  5196. WarehouseOutId: out.ID,
  5197. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  5198. IsEdit: 0,
  5199. CancelStockId: 0,
  5200. CancelOrderNumber: "",
  5201. Manufacturer: 0,
  5202. Dealer: 0,
  5203. Creator: adminUserInfo.AdminUser.Id,
  5204. UpdateCreator: 0,
  5205. Status: 1,
  5206. Ctime: time.Now().Unix(),
  5207. Mtime: 0,
  5208. Price: item.PackingPrice,
  5209. WarehousingDetailId: 0,
  5210. WarehouseOutDetailId: 0,
  5211. CancelOutDetailId: 0,
  5212. ProductDate: item.ProductDate,
  5213. ExpireDate: item.ExpiryDate,
  5214. }
  5215. service.CreateStockFlowOne(flow)
  5216. }
  5217. this.ServeSuccessJSON(map[string]interface{}{
  5218. "reportPrice": reportprice,
  5219. })
  5220. }
  5221. func (this *StockManagerApiController) SaveInventory() {
  5222. timeLayout := "2006-01-02"
  5223. loc, _ := time.LoadLocation("Local")
  5224. dataBody := make(map[string]interface{}, 0)
  5225. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5226. if err != nil {
  5227. utils.ErrorLog(err.Error())
  5228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5229. return
  5230. }
  5231. tableData, _ := dataBody["tableData"].([]interface{})
  5232. if len(tableData) > 0 {
  5233. for _, item := range tableData {
  5234. items := item.(map[string]interface{})
  5235. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5236. utils.ErrorLog("good_name")
  5237. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5238. return
  5239. }
  5240. good_name := items["good_name"].(string)
  5241. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5242. utils.ErrorLog("good_name")
  5243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5244. return
  5245. }
  5246. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  5247. utils.ErrorLog("packing_price")
  5248. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5249. return
  5250. }
  5251. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  5252. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5253. utils.ErrorLog("warehousing_order")
  5254. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5255. return
  5256. }
  5257. warehousing_order := items["warehousing_order"].(string)
  5258. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  5259. utils.ErrorLog("license_number")
  5260. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5261. return
  5262. }
  5263. license_number := items["license_number"].(string)
  5264. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  5265. utils.ErrorLog("dealer")
  5266. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5267. return
  5268. }
  5269. dealer := items["dealer"].(string)
  5270. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  5271. utils.ErrorLog("manufacturer")
  5272. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5273. return
  5274. }
  5275. manufacturer := items["manufacturer"].(string)
  5276. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5277. utils.ErrorLog("specification_name")
  5278. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5279. return
  5280. }
  5281. specification_name := items["specification_name"].(string)
  5282. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  5283. utils.ErrorLog("remark")
  5284. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5285. return
  5286. }
  5287. remark := items["remark"].(string)
  5288. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5289. utils.ErrorLog("warehousing_unit")
  5290. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5291. return
  5292. }
  5293. warehousing_unit := items["warehousing_unit"].(string)
  5294. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  5295. utils.ErrorLog("buy_price")
  5296. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5297. return
  5298. }
  5299. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  5300. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  5301. utils.ErrorLog("count")
  5302. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5303. return
  5304. }
  5305. count := int64(items["count"].(float64))
  5306. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5307. utils.ErrorLog("good_id")
  5308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5309. return
  5310. }
  5311. good_id := int64(items["good_id"].(float64))
  5312. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  5313. utils.ErrorLog("start_time")
  5314. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5315. return
  5316. }
  5317. var startTime int64
  5318. start_time := items["start_time"].(string)
  5319. if len(start_time) > 0 {
  5320. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5321. if err != nil {
  5322. fmt.Println(err)
  5323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5324. return
  5325. }
  5326. startTime = theTime.Unix()
  5327. }
  5328. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  5329. utils.ErrorLog("total")
  5330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5331. return
  5332. }
  5333. total := int64(items["total"].(float64))
  5334. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  5335. utils.ErrorLog("expiry_date")
  5336. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5337. return
  5338. }
  5339. expiry_date := int64(items["expiry_date"].(float64))
  5340. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  5341. utils.ErrorLog("product_date")
  5342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5343. return
  5344. }
  5345. product_date := int64(items["product_date"].(float64))
  5346. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5347. utils.ErrorLog("number")
  5348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5349. return
  5350. }
  5351. number := items["number"].(string)
  5352. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  5353. utils.ErrorLog("warehousing_info_id")
  5354. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5355. return
  5356. }
  5357. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  5358. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  5359. utils.ErrorLog("good_origin_place")
  5360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5361. return
  5362. }
  5363. good_origin_place := items["good_origin_place"].(string)
  5364. orgId := this.GetAdminUserInfo().CurrentOrgId
  5365. Creater := this.GetAdminUserInfo().AdminUser.Id
  5366. inventory := models.XtStockInventory{
  5367. GoodName: good_name,
  5368. SpecificationName: specification_name,
  5369. WarehousingUnit: warehousing_unit,
  5370. Count: count,
  5371. BuyPrice: buy_price,
  5372. PackingPrice: packing_price,
  5373. NewPrice: 0,
  5374. Manufacturer: manufacturer,
  5375. Dealer: dealer,
  5376. Remark: remark,
  5377. GoodId: good_id,
  5378. UserOrgId: orgId,
  5379. Ctime: time.Now().Unix(),
  5380. Mtime: 0,
  5381. Status: 1,
  5382. WarehousingOrder: warehousing_order,
  5383. LicenseNumber: license_number,
  5384. StartTime: startTime,
  5385. Creater: Creater,
  5386. Checker: 0,
  5387. CheckerStatus: 2,
  5388. CheckerTime: 0,
  5389. Total: total,
  5390. ExpireDate: expiry_date,
  5391. ProductDate: product_date,
  5392. Number: number,
  5393. WarehousingInfoId: warehousing_info_id,
  5394. GoodOriginPlace: good_origin_place,
  5395. }
  5396. err = service.CreateInentory(inventory)
  5397. fmt.Println(err)
  5398. }
  5399. }
  5400. this.ServeSuccessJSON(map[string]interface{}{
  5401. "msg": "保存成功!",
  5402. })
  5403. }
  5404. func (this *StockManagerApiController) GetInventorylist() {
  5405. timeLayout := "2006-01-02"
  5406. loc, _ := time.LoadLocation("Local")
  5407. start_time := this.GetString("start_time")
  5408. end_time := this.GetString("end_time")
  5409. page, _ := this.GetInt64("page")
  5410. limit, _ := this.GetInt64("limit")
  5411. keyword := this.GetString("keyword")
  5412. inventory_status, _ := this.GetInt64("inventory_status")
  5413. var startTime int64
  5414. if len(start_time) > 0 {
  5415. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5416. if err != nil {
  5417. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5418. return
  5419. }
  5420. startTime = theTime.Unix()
  5421. fmt.Println("开始时间", startTime)
  5422. }
  5423. var endTime int64
  5424. if len(end_time) > 0 {
  5425. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5426. if err != nil {
  5427. utils.ErrorLog(err.Error())
  5428. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5429. return
  5430. }
  5431. endTime = theTime.Unix()
  5432. }
  5433. orgId := this.GetAdminUserInfo().CurrentOrgId
  5434. list, total, _ := service.GetInventorylist(startTime, endTime, page, limit, inventory_status, keyword, orgId)
  5435. doctorlist, _ := service.GetAllDoctorThree(orgId)
  5436. houseList, _ := service.GetAllStoreHouseList(orgId)
  5437. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5438. this.ServeSuccessJSON(map[string]interface{}{
  5439. "list": list,
  5440. "total": total,
  5441. "doctorlist": doctorlist,
  5442. "houseList": houseList,
  5443. "houseConfig": houseConfig,
  5444. })
  5445. }
  5446. func (this *StockManagerApiController) SaveCheckInventory() {
  5447. timeLayout := "2006-01-02"
  5448. loc, _ := time.LoadLocation("Local")
  5449. dataBody := make(map[string]interface{}, 0)
  5450. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5451. fmt.Println(err)
  5452. idstr := this.GetString("ids")
  5453. ids := strings.Split(idstr, ",")
  5454. check_time := this.GetString("check_time")
  5455. var checkTime int64
  5456. if len(check_time) > 0 {
  5457. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5458. if err != nil {
  5459. fmt.Println(err)
  5460. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5461. return
  5462. }
  5463. checkTime = theTime.Unix()
  5464. }
  5465. checker, _ := this.GetInt64("checker")
  5466. inventory := models.XtStockInventory{
  5467. Checker: checker,
  5468. CheckerStatus: 1,
  5469. CheckerTime: checkTime,
  5470. }
  5471. adminUserInfo := this.GetAdminUserInfo()
  5472. err = service.UpdateCheckInventory(ids, inventory)
  5473. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  5474. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  5475. var manufactuer_id int64
  5476. var dealer_id int64
  5477. //查询耗材信息
  5478. list, _ := service.GetInventoryDetailById(ids)
  5479. for _, item := range list {
  5480. for _, it := range manufacturerList {
  5481. if item.Manufacturer == it.ManufacturerName {
  5482. manufactuer_id = it.ID
  5483. }
  5484. }
  5485. for _, its := range dealerList {
  5486. if item.Dealer == its.DealerName {
  5487. dealer_id = its.ID
  5488. }
  5489. }
  5490. //查寻该批次的库存量
  5491. list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5492. //查询该耗材最后1条批次
  5493. info, _ := service.GetLastWarehouseInfo(item.GoodId)
  5494. good, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5495. fmt.Println("总共", item.Count)
  5496. fmt.Println("数据", list.StockCount)
  5497. //盘点盘点库存和et实际库存的大小
  5498. // 如果盘点库存大于实际库存,怎需要入库
  5499. if item.Count > list.StockCount {
  5500. ctime := time.Now().Unix()
  5501. timeStr := time.Now().Format("2006-01-02")
  5502. timeArr := strings.Split(timeStr, "-")
  5503. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  5504. total = total + 1
  5505. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5506. operation_time := time.Now().Unix()
  5507. creater := adminUserInfo.AdminUser.Id
  5508. warehousing := models.Warehousing{
  5509. WarehousingOrder: warehousing_order,
  5510. OperationTime: operation_time,
  5511. OrgId: adminUserInfo.CurrentOrgId,
  5512. Creater: creater,
  5513. Ctime: ctime,
  5514. Status: 1,
  5515. WarehousingTime: ctime,
  5516. Type: 1,
  5517. }
  5518. service.AddSigleWarehouse(&warehousing)
  5519. //获取最
  5520. //入库单表格
  5521. warehouseInfo := models.WarehousingInfo{
  5522. WarehousingOrder: warehousing.WarehousingOrder,
  5523. WarehousingId: warehousing.ID,
  5524. GoodId: item.GoodId,
  5525. Number: info.Number,
  5526. ProductDate: info.ProductDate,
  5527. ExpiryDate: info.ExpiryDate,
  5528. WarehousingCount: item.Count - list.StockCount,
  5529. Price: info.Price,
  5530. Status: 1,
  5531. Ctime: ctime,
  5532. Remark: item.Remark,
  5533. OrgId: adminUserInfo.CurrentOrgId,
  5534. Type: 1,
  5535. Manufacturer: manufactuer_id,
  5536. StockCount: item.Count - list.StockCount,
  5537. Dealer: dealer_id,
  5538. LicenseNumber: info.LicenseNumber,
  5539. WarehouseInfoId: item.WarehousingInfoId,
  5540. GoodTypeId: good.GoodTypeId,
  5541. }
  5542. flow := models.VmStockFlow{
  5543. WarehousingOrder: warehousing.WarehousingOrder,
  5544. WarehousingId: warehousing.ID,
  5545. GoodId: item.GoodId,
  5546. Number: info.Number,
  5547. ProductDate: info.ProductDate,
  5548. ExpireDate: info.ExpiryDate,
  5549. Count: item.Count - list.StockCount,
  5550. Price: item.BuyPrice,
  5551. Status: 1,
  5552. Ctime: ctime,
  5553. UserOrgId: adminUserInfo.CurrentOrgId,
  5554. Manufacturer: info.Manufacturer,
  5555. Dealer: info.Dealer,
  5556. LicenseNumber: info.LicenseNumber,
  5557. IsEdit: 1,
  5558. Creator: adminUserInfo.AdminUser.Id,
  5559. SystemTime: operation_time,
  5560. ConsumableType: 1,
  5561. WarehousingDetailId: warehouseInfo.ID,
  5562. }
  5563. service.CreateWarehouseInfo(warehouseInfo)
  5564. service.CreateStockFlowOne(flow)
  5565. }
  5566. //如果盘点库存小于实际库存,需要出库
  5567. if item.Count < list.StockCount {
  5568. timeStr := time.Now().Format("2006-01-02")
  5569. timeArr := strings.Split(timeStr, "-")
  5570. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5571. total = total + 1
  5572. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5573. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5574. number = number + total
  5575. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5576. operation_time := time.Now().Unix()
  5577. creater := adminUserInfo.AdminUser.Id
  5578. //查询最早的1条批次
  5579. warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
  5580. warehouseOut := models.WarehouseOut{
  5581. WarehouseOutOrderNumber: warehousing_out_order,
  5582. OperationTime: operation_time,
  5583. OrgId: adminUserInfo.CurrentOrgId,
  5584. Creater: creater,
  5585. Ctime: time.Now().Unix(),
  5586. Status: 1,
  5587. WarehouseOutTime: time.Now().Unix(),
  5588. Type: 1,
  5589. }
  5590. err = service.CreateWarehouseOut(warehouseOut)
  5591. fmt.Println(err)
  5592. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  5593. warehouseOutInfo := &models.WarehouseOutInfo{
  5594. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  5595. WarehouseOutId: out.ID,
  5596. GoodId: warehouseInfo.GoodId,
  5597. Count: list.StockCount - item.Count,
  5598. Price: warehouseInfo.Price,
  5599. Status: 1,
  5600. Ctime: time.Now().Unix(),
  5601. Remark: item.Remark,
  5602. OrgId: adminUserInfo.CurrentOrgId,
  5603. Type: 1,
  5604. Manufacturer: manufactuer_id,
  5605. Number: warehouseInfo.Number,
  5606. ExpiryDate: warehouseInfo.ExpiryDate,
  5607. ProductDate: warehouseInfo.ProductDate,
  5608. Dealer: dealer_id,
  5609. LicenseNumber: warehouseInfo.LicenseNumber,
  5610. GoodTypeId: good.GoodTypeId,
  5611. }
  5612. stockFlow := models.VmStockFlow{
  5613. WarehousingId: item.WarehousingInfoId,
  5614. GoodId: warehouseInfo.GoodId,
  5615. Number: warehouseInfo.Number,
  5616. LicenseNumber: warehouseInfo.LicenseNumber,
  5617. Count: list.StockCount - item.Count,
  5618. UserOrgId: warehouseInfo.OrgId,
  5619. PatientId: 0,
  5620. SystemTime: 0,
  5621. ConsumableType: 2,
  5622. IsSys: 2,
  5623. WarehousingOrder: "",
  5624. WarehouseOutId: out.ID,
  5625. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5626. IsEdit: 1,
  5627. CancelStockId: 0,
  5628. CancelOrderNumber: "",
  5629. Manufacturer: manufactuer_id,
  5630. Dealer: dealer_id,
  5631. Creator: adminUserInfo.AdminUser.Id,
  5632. UpdateCreator: 0,
  5633. Status: 1,
  5634. Ctime: time.Now().Unix(),
  5635. Mtime: 0,
  5636. Price: warehouseInfo.Price,
  5637. WarehousingDetailId: 0,
  5638. WarehouseOutDetailId: out.ID,
  5639. CancelOutDetailId: 0,
  5640. ProductDate: warehouseInfo.ProductDate,
  5641. ExpireDate: warehouseInfo.ExpiryDate,
  5642. }
  5643. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5644. fmt.Println(errOne)
  5645. //创建出库明细
  5646. service.CreateStockFlowOne(stockFlow)
  5647. //更改库存
  5648. warehousingInfos := models.WarehousingInfo{
  5649. StockCount: item.Count,
  5650. }
  5651. service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
  5652. }
  5653. }
  5654. fmt.Println(err)
  5655. this.ServeSuccessJSON(map[string]interface{}{
  5656. "inventory": inventory,
  5657. })
  5658. }
  5659. func (this *StockManagerApiController) GetModifyPriceDetail() {
  5660. id, _ := this.GetInt64("id")
  5661. detail, _ := service.GetModifyPriceDetail(id)
  5662. this.ServeSuccessJSON(map[string]interface{}{
  5663. "detail": detail,
  5664. })
  5665. }
  5666. func (this *StockManagerApiController) UpdateStockPrice() {
  5667. id, _ := this.GetInt64("id")
  5668. newPrice := this.GetString("new_price")
  5669. new_price, _ := strconv.ParseFloat(newPrice, 64)
  5670. good_name := this.GetString("good_name")
  5671. packingPrice := this.GetString("packing_price")
  5672. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5673. remark := this.GetString("remark")
  5674. good_id, _ := this.GetInt64("good_id")
  5675. manufacturer := this.GetString("manufacturer")
  5676. dealer := this.GetString("dealer")
  5677. adjust := models.XtStockAdjustPrice{
  5678. NewPrice: new_price,
  5679. GoodName: good_name,
  5680. PackingPrice: packing_price,
  5681. Remark: remark,
  5682. GoodId: good_id,
  5683. Manufacturer: manufacturer,
  5684. Dealer: dealer,
  5685. }
  5686. err := service.UpdateStockPrice(adjust, id)
  5687. fmt.Println(err)
  5688. this.ServeSuccessJSON(map[string]interface{}{
  5689. "adjust": adjust,
  5690. })
  5691. }
  5692. func (this *StockManagerApiController) DeleteStockPrice() {
  5693. id, _ := this.GetInt64("id")
  5694. err := service.DeleteStockPrice(id)
  5695. fmt.Println(err)
  5696. returnData := make(map[string]interface{}, 0)
  5697. returnData["msg"] = "ok"
  5698. this.ServeSuccessJSON(returnData)
  5699. return
  5700. }
  5701. func (this *StockManagerApiController) GetStockDamageDetail() {
  5702. id, _ := this.GetInt64("id")
  5703. detail, err := service.GetStockDamageDetail(id)
  5704. fmt.Println(err)
  5705. this.ServeSuccessJSON(map[string]interface{}{
  5706. "detail": detail,
  5707. })
  5708. }
  5709. func (this *StockManagerApiController) ModifyPrice() {
  5710. count, _ := this.GetInt64("count")
  5711. id, _ := this.GetInt64("id")
  5712. good_name := this.GetString("good_name")
  5713. specification_name := this.GetString("specification_name")
  5714. number := this.GetString("number")
  5715. warehousing_unit := this.GetString("warehousing_unit")
  5716. buyPrice := this.GetString("buy_price")
  5717. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5718. packingPrice := this.GetString("packing_price")
  5719. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5720. good_origin_place := this.GetString("good_origin_place")
  5721. manufacturer := this.GetString("manufacturer")
  5722. dealer := this.GetString("dealer")
  5723. total, _ := this.GetInt64("total")
  5724. remark := this.GetString("remark")
  5725. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5726. good_id, _ := this.GetInt64("good_id")
  5727. adjust := models.XtStockReportPrice{
  5728. Count: count,
  5729. SpecificationName: specification_name,
  5730. Number: number,
  5731. GoodName: good_name,
  5732. WarehousingUnit: warehousing_unit,
  5733. BuyPrice: buy_price,
  5734. PackingPrice: packing_price,
  5735. GoodOriginPlace: good_origin_place,
  5736. Manufacturer: manufacturer,
  5737. Dealer: dealer,
  5738. Total: total,
  5739. Remark: remark,
  5740. WarehousingInfoId: warehousing_info_id,
  5741. GoodId: good_id,
  5742. }
  5743. err := service.ModifyPrice(id, adjust)
  5744. fmt.Println(err)
  5745. this.ServeSuccessJSON(map[string]interface{}{
  5746. "adjust": adjust,
  5747. })
  5748. }
  5749. func (this *StockManagerApiController) DeleteDamage() {
  5750. id, _ := this.GetInt64("id")
  5751. err := service.DeleteDamage(id)
  5752. fmt.Println(err)
  5753. returnData := make(map[string]interface{}, 0)
  5754. returnData["msg"] = "ok"
  5755. this.ServeSuccessJSON(returnData)
  5756. return
  5757. }
  5758. func (this *StockManagerApiController) GetStockDamageById() {
  5759. ids := this.GetString("ids")
  5760. splitIds := strings.Split(ids, ",")
  5761. list, _ := service.GetStockDamageById(splitIds)
  5762. this.ServeSuccessJSON(map[string]interface{}{
  5763. "list": list,
  5764. })
  5765. }
  5766. func (this *StockManagerApiController) GetInventoryDetail() {
  5767. id, _ := this.GetInt64("id")
  5768. detail, _ := service.GetInventoryDetail(id)
  5769. this.ServeSuccessJSON(map[string]interface{}{
  5770. "detail": detail,
  5771. })
  5772. }
  5773. func (this *StockManagerApiController) ModifyInventory() {
  5774. id, _ := this.GetInt64("id")
  5775. good_id, _ := this.GetInt64("good_id")
  5776. good_name := this.GetString("good_name")
  5777. specification_name := this.GetString("specification_name")
  5778. number := this.GetString("number")
  5779. warehousing_unit := this.GetString("warehousing_unit")
  5780. buyPrice := this.GetString("buy_price")
  5781. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5782. packingPrice := this.GetString("packing_price")
  5783. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5784. total, _ := this.GetInt64("total")
  5785. good_origin_place := this.GetString("good_origin_place")
  5786. license_number := this.GetString("license_number")
  5787. dealer := this.GetString("dealer")
  5788. manufacturer := this.GetString("manufacturer")
  5789. count, _ := this.GetInt64("count")
  5790. remark := this.GetString("remark")
  5791. inventory := models.XtStockInventory{
  5792. GoodId: good_id,
  5793. GoodName: good_name,
  5794. SpecificationName: specification_name,
  5795. Number: number,
  5796. WarehousingUnit: warehousing_unit,
  5797. BuyPrice: buy_price,
  5798. PackingPrice: packing_price,
  5799. Total: total,
  5800. GoodOriginPlace: good_origin_place,
  5801. LicenseNumber: license_number,
  5802. Dealer: dealer,
  5803. Manufacturer: manufacturer,
  5804. Count: count,
  5805. Remark: remark,
  5806. }
  5807. err := service.ModifyInventory(id, inventory)
  5808. fmt.Println(err)
  5809. this.ServeSuccessJSON(map[string]interface{}{
  5810. "inventory": inventory,
  5811. })
  5812. }
  5813. func (this *StockManagerApiController) DeleteInventory() {
  5814. id, _ := this.GetInt64("id")
  5815. err := service.DeleteInventory(id)
  5816. fmt.Println(err)
  5817. returnData := make(map[string]interface{}, 0)
  5818. returnData["msg"] = "ok"
  5819. this.ServeSuccessJSON(returnData)
  5820. return
  5821. }
  5822. func (this *StockManagerApiController) GetInventoryDetailList() {
  5823. keyword := this.GetString("keyword")
  5824. limit, _ := this.GetInt64("limit")
  5825. page, _ := this.GetInt64("page")
  5826. orgId := this.GetAdminUserInfo().CurrentOrgId
  5827. storehouse_id, _ := this.GetInt64("storehouse_id")
  5828. houseList, _ := service.GetAllStoreHouseList(orgId)
  5829. list, total, _ := service.GetInventoryDetailList(keyword, limit, page, orgId, storehouse_id)
  5830. this.ServeSuccessJSON(map[string]interface{}{
  5831. "list": list,
  5832. "total": total,
  5833. "houseList": houseList,
  5834. })
  5835. }
  5836. func (this *StockManagerApiController) GetInventoryPrintList() {
  5837. ids := this.GetString("ids")
  5838. splitIds := strings.Split(ids, ",")
  5839. list, _ := service.GetInventoryPrintList(splitIds)
  5840. this.ServeSuccessJSON(map[string]interface{}{
  5841. "list": list,
  5842. })
  5843. }
  5844. func (this *StockManagerApiController) GetInventoryDetailPrintList() {
  5845. ids := this.GetString("ids")
  5846. splitIds := strings.Split(ids, ",")
  5847. list, _ := service.GetInventoryDetailPrintList(splitIds)
  5848. this.ServeSuccessJSON(map[string]interface{}{
  5849. "list": list,
  5850. })
  5851. }
  5852. func (this *StockManagerApiController) DeleteDrugPrice() {
  5853. id, _ := this.GetInt64("id")
  5854. err := service.DeleteDrugPrice(id)
  5855. fmt.Println(err)
  5856. returnData := make(map[string]interface{}, 0)
  5857. returnData["msg"] = "ok"
  5858. this.ServeSuccessJSON(returnData)
  5859. return
  5860. }
  5861. func (this *StockManagerApiController) GetGoodWarehouseList() {
  5862. id, _ := this.GetInt64("id")
  5863. list, _ := service.GetGoodWarehouseList(id)
  5864. this.ServeSuccessJSON(map[string]interface{}{
  5865. "list": list,
  5866. })
  5867. }
  5868. func (this *StockManagerApiController) ProofInventory() {
  5869. id, _ := this.GetInt64("id")
  5870. good_id, _ := this.GetInt64("good_id")
  5871. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5872. proof_count, _ := this.GetInt64("proof_count")
  5873. total, _ := this.GetInt64("total")
  5874. orgId := this.GetAdminUserInfo().CurrentOrgId
  5875. creater := this.GetAdminUserInfo().AdminUser.Id
  5876. info := models.WarehousingInfo{
  5877. GoodId: good_id,
  5878. StockCount: proof_count,
  5879. }
  5880. err := service.UpdateProofInventory(warehousing_info_id, info)
  5881. inventory := models.XtStockInventory{
  5882. Total: proof_count,
  5883. }
  5884. err = service.UpdateStockInventory(inventory, id)
  5885. fmt.Println(err)
  5886. record := models.XtStockCorrectRecord{
  5887. GoodId: good_id,
  5888. OrdCount: total,
  5889. WarehousingInfoId: warehousing_info_id,
  5890. NewCount: proof_count,
  5891. UserOrgId: orgId,
  5892. Status: 1,
  5893. Creater: creater,
  5894. Ctime: time.Now().Unix(),
  5895. Mtime: 0,
  5896. }
  5897. service.CeateStockCorrectRecord(record)
  5898. this.ServeSuccessJSON(map[string]interface{}{
  5899. "list": info,
  5900. })
  5901. }
  5902. func (this *StockManagerApiController) GetWarehouseTotal() {
  5903. id, _ := this.GetInt64("id")
  5904. list, _ := service.GetWarehouseTotal(id)
  5905. this.ServeSuccessJSON(map[string]interface{}{
  5906. "list": list,
  5907. })
  5908. }
  5909. func (this *StockManagerApiController) GetGoodInventoryWarehouseList() {
  5910. id, _ := this.GetInt64("id")
  5911. storehouse_id, _ := this.GetInt64("storehouse_id")
  5912. list, _ := service.GetGoodInventoryWarehouseList(id, storehouse_id)
  5913. orgId := this.GetAdminUserInfo().CurrentOrgId
  5914. fmt.Println(orgId)
  5915. this.ServeSuccessJSON(map[string]interface{}{
  5916. "list": list,
  5917. })
  5918. }
  5919. func (this *StockManagerApiController) SaveStockInventoryList() {
  5920. dataBody := make(map[string]interface{}, 0)
  5921. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5922. fmt.Println(err)
  5923. tableData, _ := dataBody["tableData"].([]interface{})
  5924. if len(tableData) > 0 {
  5925. for _, item := range tableData {
  5926. items := item.(map[string]interface{})
  5927. good_name := items["good_name"].(string)
  5928. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5929. utils.ErrorLog("good_name")
  5930. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5931. return
  5932. }
  5933. specification_name := items["specification_name"].(string)
  5934. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5935. utils.ErrorLog("specification_name")
  5936. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5937. return
  5938. }
  5939. warehousing_unit := items["warehousing_unit"].(string)
  5940. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5941. utils.ErrorLog("warehousing_unit")
  5942. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5943. return
  5944. }
  5945. stock_count := int64(items["stock_count"].(float64))
  5946. if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
  5947. utils.ErrorLog("stock_count")
  5948. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5949. return
  5950. }
  5951. price := items["price"].(float64)
  5952. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
  5953. utils.ErrorLog("price")
  5954. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5955. return
  5956. }
  5957. manufacturer_name := items["manufacturer_name"].(string)
  5958. if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
  5959. utils.ErrorLog("manufacturer_name")
  5960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5961. return
  5962. }
  5963. good_id := int64(items["good_id"].(float64))
  5964. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5965. utils.ErrorLog("good_id")
  5966. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5967. return
  5968. }
  5969. manufacturer := int64(items["manufacturer"].(float64))
  5970. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
  5971. utils.ErrorLog("manufacturer")
  5972. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5973. return
  5974. }
  5975. warehousing_order := items["warehousing_order"].(string)
  5976. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5977. utils.ErrorLog("warehousing_order")
  5978. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5979. return
  5980. }
  5981. number := items["number"].(string)
  5982. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5983. utils.ErrorLog("number")
  5984. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5985. return
  5986. }
  5987. id := int64(items["id"].(float64))
  5988. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5989. utils.ErrorLog("id")
  5990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5991. return
  5992. }
  5993. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  5994. utils.ErrorLog("expiry_date")
  5995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5996. return
  5997. }
  5998. expiry_date := int64(items["expiry_date"].(float64))
  5999. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  6000. utils.ErrorLog("product_date")
  6001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6002. return
  6003. }
  6004. product_date := int64(items["product_date"].(float64))
  6005. orgId := this.GetAdminUserInfo().CurrentOrgId
  6006. adminId := this.GetAdminUserInfo().AdminUser.Id
  6007. stock_type := int64(items["type"].(float64))
  6008. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6009. utils.ErrorLog("type")
  6010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6011. return
  6012. }
  6013. last_stock_count := int64(items["last_stock_count"].(float64))
  6014. if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
  6015. utils.ErrorLog("last_stock_count")
  6016. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6017. return
  6018. }
  6019. storehouse_id := int64(items["storehouse_id"].(float64))
  6020. if items["storehouse_id"] == nil || reflect.TypeOf(items["storehouse_id"]).String() != "float64" {
  6021. utils.ErrorLog("storehouse_id")
  6022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6023. return
  6024. }
  6025. var total_count int64
  6026. var inventory_type int64
  6027. if stock_count > last_stock_count {
  6028. total_count = stock_count - last_stock_count
  6029. inventory_type = 11
  6030. }
  6031. if stock_count < last_stock_count {
  6032. total_count = last_stock_count - stock_count
  6033. inventory_type = 10
  6034. }
  6035. creater := this.GetAdminUserInfo().AdminUser.Id
  6036. inventory := models.XtStockInventory{
  6037. GoodName: good_name,
  6038. SpecificationName: specification_name,
  6039. WarehousingUnit: warehousing_unit,
  6040. Count: total_count,
  6041. BuyPrice: price,
  6042. PackingPrice: price,
  6043. NewPrice: 0,
  6044. Manufacturer: manufacturer_name,
  6045. Dealer: "",
  6046. Remark: "",
  6047. GoodId: good_id,
  6048. UserOrgId: orgId,
  6049. Ctime: time.Now().Unix(),
  6050. Mtime: 0,
  6051. Status: 1,
  6052. WarehousingOrder: warehousing_order,
  6053. LicenseNumber: number,
  6054. StartTime: time.Now().Unix(),
  6055. Creater: adminId,
  6056. Checker: 0,
  6057. CheckerStatus: 0,
  6058. CheckerTime: 0,
  6059. Total: 0,
  6060. Number: number,
  6061. WarehousingInfoId: id,
  6062. ExpireDate: expiry_date,
  6063. ProductDate: product_date,
  6064. GoodOriginPlace: "",
  6065. Type: 10,
  6066. InventoryType: stock_type,
  6067. LastStockCount: last_stock_count,
  6068. StockCount: stock_count,
  6069. StorehouseId: storehouse_id,
  6070. }
  6071. service.CreateInentory(inventory)
  6072. stockFlow := models.VmStockFlow{
  6073. WarehousingId: 0,
  6074. GoodId: good_id,
  6075. Number: number,
  6076. LicenseNumber: "",
  6077. Count: total_count,
  6078. UserOrgId: orgId,
  6079. PatientId: 0,
  6080. SystemTime: 0,
  6081. ConsumableType: inventory_type,
  6082. IsSys: 0,
  6083. WarehousingOrder: "",
  6084. WarehouseOutId: 0,
  6085. WarehouseOutOrderNumber: warehousing_order,
  6086. IsEdit: 0,
  6087. CancelStockId: 0,
  6088. CancelOrderNumber: "",
  6089. Manufacturer: manufacturer,
  6090. Dealer: 0,
  6091. Creator: creater,
  6092. UpdateCreator: 0,
  6093. Status: 1,
  6094. Ctime: time.Now().Unix(),
  6095. Mtime: 0,
  6096. Price: price,
  6097. WarehousingDetailId: 0,
  6098. WarehouseOutDetailId: 0,
  6099. CancelOutDetailId: 0,
  6100. ProductDate: product_date,
  6101. ExpireDate: expiry_date,
  6102. ReturnCount: 0,
  6103. StorehouseId: storehouse_id,
  6104. }
  6105. info := models.WarehousingInfo{
  6106. StockCount: last_stock_count,
  6107. WarehousingCount: last_stock_count,
  6108. }
  6109. warehosueinfos, _ := service.GetWarehouseInfoByIdNight(id)
  6110. //如果当前的盘点后的数量大于当前库存数量,则新增库存
  6111. if last_stock_count > warehosueinfos.StockCount && last_stock_count <= warehosueinfos.WarehousingCount {
  6112. //更改库存
  6113. service.UpdatedWarehousingInfo(info, id)
  6114. }
  6115. if last_stock_count > warehosueinfos.StockCount && last_stock_count > warehosueinfos.WarehousingCount {
  6116. //更改库存
  6117. service.UpdatedWarehousingInfoSix(info, id)
  6118. }
  6119. //如果当前的盘点后的数量大于当前库存数量,则扣减库存
  6120. if last_stock_count < warehosueinfos.StockCount {
  6121. //更改库存
  6122. service.UpdatedWarehousingInfo(info, id)
  6123. }
  6124. if stock_count != last_stock_count {
  6125. service.CreateStockFlowOne(stockFlow)
  6126. }
  6127. //查询该机构默认仓库
  6128. storeConfig, _ := service.GetAllStoreHouseConfig(warehosueinfos.OrgId)
  6129. //查询已审核单据的剩余库存
  6130. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, good_id, warehosueinfos.OrgId)
  6131. var sum_count int64
  6132. var sum_in_count int64
  6133. for _, item := range goodList {
  6134. sum_count += item.StockCount
  6135. sum_in_count += item.WarehousingCount
  6136. }
  6137. service.UpdateGoodByGoodId(good_id, sum_count, sum_in_count, warehosueinfos.OrgId)
  6138. goodListOne, _ := service.GetSumGoodList(orgId, storeConfig.StorehouseOutInfo, good_id)
  6139. var flush_count int64
  6140. for _, it := range goodListOne {
  6141. flush_count += it.StockCount
  6142. }
  6143. service.UpdateSumGood(orgId, storeConfig.StorehouseOutInfo, good_id, flush_count)
  6144. this.ServeSuccessJSON(map[string]interface{}{
  6145. "inventory": inventory,
  6146. })
  6147. }
  6148. }
  6149. }
  6150. func (this *StockManagerApiController) GetDamageDetailByGoodId() {
  6151. good_id, _ := this.GetInt64("good_id")
  6152. warehousing_order := this.GetString("warehousing_order")
  6153. inventory_type, _ := this.GetInt64("type")
  6154. list, _ := service.GetDamageDetailByGoodId(good_id, warehousing_order, inventory_type)
  6155. orgId := this.GetAdminUserInfo().CurrentOrgId
  6156. damageList, _ := service.GetStockDamagedCountOne(orgId, warehousing_order, inventory_type)
  6157. this.ServeSuccessJSON(map[string]interface{}{
  6158. "list": list,
  6159. "damageList": damageList,
  6160. })
  6161. }
  6162. func (this *StockManagerApiController) GetInventoryExportList() {
  6163. orgId := this.GetAdminUserInfo().CurrentOrgId
  6164. list, _ := service.GetInventoryExportList(orgId)
  6165. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  6166. this.ServeSuccessJSON(map[string]interface{}{
  6167. "list": list,
  6168. "manufacturerList": manufacturerList,
  6169. })
  6170. }
  6171. func (this *StockManagerApiController) UpdateCancelStockOrder() {
  6172. type_id, _ := this.GetInt64("type_id")
  6173. //获取目前在使用的机构ID
  6174. list, _ := service.GetOrgIdList()
  6175. //耗材
  6176. if type_id == 1 {
  6177. for _, item := range list {
  6178. //查询该机构的所有耗材
  6179. goodList, _ := service.GetAllGoodList(item.OrgId)
  6180. for _, it := range goodList {
  6181. //查询该耗材的入库总数
  6182. info, _ := service.GetStockCountWarehouseInfoById(it.ID)
  6183. var total int64
  6184. for _, its := range info {
  6185. total += its.StockCount
  6186. }
  6187. //更新库存
  6188. service.ModifyGoodAddInformationSeven(it.ID, total, it.OrgId)
  6189. }
  6190. }
  6191. }
  6192. //药品
  6193. if type_id == 2 {
  6194. for _, item := range list {
  6195. fmt.Println(item)
  6196. //查询该机构的所有药品
  6197. drugList, _ := service.GetAllBaseDrugStockList(4)
  6198. for _, it := range drugList {
  6199. //查询该药品的入库总数
  6200. info, _ := service.GetDrugStockCountWarehoseInfoById(it.ID)
  6201. var sum_count int64
  6202. for _, its := range info {
  6203. if its.MaxUnit == it.MaxUnit {
  6204. its.StockMaxNumber = its.StockMaxNumber * it.MinNumber
  6205. }
  6206. sum_count += its.StockMaxNumber + its.StockMinNumber
  6207. }
  6208. service.UpdateModifyDrugInfoById(it.ID, sum_count, it.OrgId)
  6209. }
  6210. }
  6211. }
  6212. }
  6213. func (this *StockManagerApiController) GetDrugDetailSummary() {
  6214. timeLayout := "2006-01-02"
  6215. loc, _ := time.LoadLocation("Local")
  6216. start_time := this.GetString("start_time")
  6217. end_time := this.GetString("end_time")
  6218. var startTime int64
  6219. if len(start_time) > 0 {
  6220. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6221. if err != nil {
  6222. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6223. return
  6224. }
  6225. startTime = theTime.Unix()
  6226. fmt.Println("开始时间", startTime)
  6227. }
  6228. var endTime int64
  6229. if len(end_time) > 0 {
  6230. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6231. if err != nil {
  6232. utils.ErrorLog(err.Error())
  6233. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6234. return
  6235. }
  6236. endTime = theTime.Unix()
  6237. }
  6238. keyword := this.GetString("keyword")
  6239. limit, _ := this.GetInt64("limit")
  6240. page, _ := this.GetInt64("page")
  6241. orgId := this.GetAdminUserInfo().CurrentOrgId
  6242. list, total, err := service.GetDrugDetailSummary(startTime, endTime, keyword, limit, page, orgId)
  6243. druglist, _, _ := service.GetDrugDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
  6244. patients, _ := service.GetAllpatient(orgId)
  6245. var drugType = "药品类型"
  6246. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  6247. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  6248. for _, item := range list {
  6249. for _, it := range druglist {
  6250. if item.DrugId == it.DrugId {
  6251. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6252. }
  6253. }
  6254. }
  6255. drug, _ := service.GetAllDrugSummary(orgId)
  6256. if err == nil {
  6257. this.ServeSuccessJSON(map[string]interface{}{
  6258. "list": list,
  6259. "total": total,
  6260. "drug": drug,
  6261. "drugTypeList": drugTypeList,
  6262. "patients": patients,
  6263. })
  6264. }
  6265. }
  6266. func (this *StockManagerApiController) GetGoodDetailSummary() {
  6267. timeLayout := "2006-01-02"
  6268. loc, _ := time.LoadLocation("Local")
  6269. start_time := this.GetString("start_time")
  6270. end_time := this.GetString("end_time")
  6271. var startTime int64
  6272. if len(start_time) > 0 {
  6273. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6274. if err != nil {
  6275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6276. return
  6277. }
  6278. startTime = theTime.Unix()
  6279. }
  6280. var endTime int64
  6281. if len(end_time) > 0 {
  6282. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6283. if err != nil {
  6284. utils.ErrorLog(err.Error())
  6285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6286. return
  6287. }
  6288. endTime = theTime.Unix()
  6289. }
  6290. keyword := this.GetString("keyword")
  6291. limit, _ := this.GetInt64("limit")
  6292. page, _ := this.GetInt64("page")
  6293. orgId := this.GetAdminUserInfo().CurrentOrgId
  6294. list, total, err := service.GetGoodDetailSummary(startTime, endTime, keyword, limit, page, orgId)
  6295. goodlist, _, _ := service.GetGoodDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
  6296. for _, item := range list {
  6297. for _, it := range goodlist {
  6298. if item.ProjectId == it.ProjectId {
  6299. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6300. }
  6301. }
  6302. }
  6303. information, _ := service.GeAllGoodInformation(orgId)
  6304. patients, _ := service.GetAllpatient(orgId)
  6305. goodType, _ := service.GetAllGoodType(orgId)
  6306. if err == nil {
  6307. this.ServeSuccessJSON(map[string]interface{}{
  6308. "list": list,
  6309. "total": total,
  6310. "good": information,
  6311. "patients": patients,
  6312. "goodType": goodType,
  6313. })
  6314. }
  6315. }
  6316. func (this *StockManagerApiController) CheckWarehouseOut() {
  6317. id, _ := this.GetInt64("id")
  6318. orgId := this.GetAdminUserInfo().CurrentOrgId
  6319. creater := this.GetAdminUserInfo().AdminUser.Id
  6320. warehouseOut, errcode := service.GetWarehouseById(id)
  6321. if errcode != nil {
  6322. goodErrcode := models.XtGoodErrcode{
  6323. UserOrgId: orgId,
  6324. Errcode: "查询审核出库单报错",
  6325. GoodId: 0,
  6326. Status: 0,
  6327. Ctime: 0,
  6328. Mtime: 0,
  6329. Count: 0,
  6330. StockCount: 0,
  6331. Creater: creater,
  6332. BatchNumberId: 0,
  6333. WarehouseOutId: 0,
  6334. }
  6335. service.CreateGoodErrcode(goodErrcode)
  6336. }
  6337. //查询已审核的单据
  6338. warehousingOutInfo, erroce := service.GetWarehouseOutById(id, orgId)
  6339. if erroce != nil {
  6340. goodErrcode := models.XtGoodErrcode{
  6341. UserOrgId: orgId,
  6342. Errcode: "查询已审核出库详情单报错",
  6343. GoodId: 0,
  6344. Status: 0,
  6345. Ctime: 0,
  6346. Mtime: 0,
  6347. Count: 0,
  6348. StockCount: 0,
  6349. Creater: creater,
  6350. BatchNumberId: 0,
  6351. WarehouseOutId: 0,
  6352. }
  6353. service.CreateGoodErrcode(goodErrcode)
  6354. }
  6355. ////出库逻辑
  6356. for _, item := range warehousingOutInfo {
  6357. // 查询该耗材是否有库存
  6358. warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId, item.StorehouseId)
  6359. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseId, item.OrgId)
  6360. // 如果出库数量大于该批次剩余库存数量
  6361. if item.Count > warehouseOne.StockCount {
  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: warehouseOne.ID,
  6373. WarehouseOutId: item.ID,
  6374. }
  6375. service.CreateGoodErrcode(goodErrcode)
  6376. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6377. this.ServeSuccessJSON(map[string]interface{}{
  6378. "msg": "1",
  6379. "good_name": goodObj.GoodName,
  6380. "specification_name": goodObj.SpecificationName,
  6381. "storehose_name": storehouse.StorehouseName,
  6382. })
  6383. return
  6384. }
  6385. }
  6386. for _, item := range warehousingOutInfo {
  6387. creater := this.GetAdminUserInfo().AdminUser.Id
  6388. //出库
  6389. err := service.ConsumablesDeliveryThirty(orgId, item.SysRecordTime, item, &warehouseOut, item.Count, creater)
  6390. if err != nil {
  6391. goodErrcode := models.XtGoodErrcode{
  6392. UserOrgId: orgId,
  6393. Errcode: "调用出库接口报错",
  6394. GoodId: item.GoodId,
  6395. Status: 1,
  6396. Ctime: time.Now().Unix(),
  6397. Mtime: 0,
  6398. Count: 0,
  6399. StockCount: 0,
  6400. Creater: creater,
  6401. BatchNumberId: 0,
  6402. WarehouseOutId: 0,
  6403. }
  6404. service.CreateGoodErrcode(goodErrcode)
  6405. }
  6406. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6407. var flush_count int64
  6408. for _, it := range goodList {
  6409. flush_count += it.StockCount
  6410. }
  6411. errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6412. if errs != 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. orgId := this.GetAdminUserInfo().CurrentOrgId
  6429. //查询默认仓库
  6430. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6431. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
  6432. var total_count int64
  6433. for _, it := range stockList {
  6434. total_count += it.StockCount
  6435. }
  6436. //基础库扣减库存
  6437. errsum := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, orgId)
  6438. if errsum != nil {
  6439. goodErrcode := models.XtGoodErrcode{
  6440. UserOrgId: orgId,
  6441. Errcode: "基础库扣减库存报错",
  6442. GoodId: item.GoodId,
  6443. Status: 1,
  6444. Ctime: time.Now().Unix(),
  6445. Mtime: 0,
  6446. Count: 0,
  6447. StockCount: 0,
  6448. Creater: creater,
  6449. BatchNumberId: 0,
  6450. WarehouseOutId: 0,
  6451. }
  6452. service.CreateGoodErrcode(goodErrcode)
  6453. }
  6454. }
  6455. //审核单据
  6456. err := service.UpdatedWarehouseOut(id)
  6457. if err != nil {
  6458. goodErrcode := models.XtGoodErrcode{
  6459. UserOrgId: orgId,
  6460. Errcode: "审核单据报错",
  6461. GoodId: 0,
  6462. Status: 1,
  6463. Ctime: time.Now().Unix(),
  6464. Mtime: 0,
  6465. Count: 0,
  6466. StockCount: 0,
  6467. Creater: creater,
  6468. BatchNumberId: 0,
  6469. WarehouseOutId: 0,
  6470. }
  6471. service.CreateGoodErrcode(goodErrcode)
  6472. }
  6473. if err == nil {
  6474. this.ServeSuccessJSON(map[string]interface{}{
  6475. "msg": "2",
  6476. "good_name": "",
  6477. "specification_name": "",
  6478. "storehose_name": "",
  6479. })
  6480. }
  6481. }
  6482. func (this *StockManagerApiController) ReturnCheckWarehouseOut() {
  6483. id, _ := this.GetInt64("id")
  6484. orgId := this.GetAdminUserInfo().CurrentOrgId
  6485. creater := this.GetAdminUserInfo().AdminUser.Id
  6486. // 查询出库数据
  6487. list, err := service.GetWarehouseOutById(id, orgId)
  6488. if err != nil {
  6489. goodErrcode := models.XtGoodErrcode{
  6490. UserOrgId: orgId,
  6491. Errcode: "反审核查询出库单报错",
  6492. GoodId: 0,
  6493. Status: 1,
  6494. Ctime: time.Now().Unix(),
  6495. Mtime: 0,
  6496. Count: 0,
  6497. StockCount: 0,
  6498. Creater: creater,
  6499. BatchNumberId: 0,
  6500. WarehouseOutId: 0,
  6501. }
  6502. service.CreateGoodErrcode(goodErrcode)
  6503. }
  6504. for _, item := range list {
  6505. //回退库存
  6506. err := service.UpdateaGoodWarehouseInfo(item.Count, item.GoodId, item.OrgId, item.WarehouseInfotId)
  6507. if err != nil {
  6508. goodErrcode := models.XtGoodErrcode{
  6509. UserOrgId: orgId,
  6510. Errcode: "反审核回退库存报错",
  6511. GoodId: 0,
  6512. Status: 1,
  6513. Ctime: time.Now().Unix(),
  6514. Mtime: 0,
  6515. Count: 0,
  6516. StockCount: 0,
  6517. Creater: creater,
  6518. BatchNumberId: 0,
  6519. WarehouseOutId: 0,
  6520. }
  6521. service.CreateGoodErrcode(goodErrcode)
  6522. }
  6523. //查询默认仓库
  6524. storeHouseConfig, errs := service.GetAllStoreHouseConfig(orgId)
  6525. if errs != nil {
  6526. goodErrcode := models.XtGoodErrcode{
  6527. UserOrgId: orgId,
  6528. Errcode: "反审核查询默认仓库报错",
  6529. GoodId: 0,
  6530. Status: 1,
  6531. Ctime: time.Now().Unix(),
  6532. Mtime: 0,
  6533. Count: 0,
  6534. StockCount: 0,
  6535. Creater: creater,
  6536. BatchNumberId: 0,
  6537. WarehouseOutId: 0,
  6538. }
  6539. service.CreateGoodErrcode(goodErrcode)
  6540. }
  6541. stockList, errcodes := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
  6542. if errcodes != nil {
  6543. goodErrcode := models.XtGoodErrcode{
  6544. UserOrgId: orgId,
  6545. Errcode: "反审核查询默认仓库库存报错",
  6546. GoodId: 0,
  6547. Status: 1,
  6548. Ctime: time.Now().Unix(),
  6549. Mtime: 0,
  6550. Count: 0,
  6551. StockCount: 0,
  6552. Creater: creater,
  6553. BatchNumberId: 0,
  6554. WarehouseOutId: 0,
  6555. }
  6556. service.CreateGoodErrcode(goodErrcode)
  6557. }
  6558. var total_count int64
  6559. for _, it := range stockList {
  6560. total_count += it.StockCount
  6561. }
  6562. //基础库扣减库存
  6563. errs = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, orgId)
  6564. if errs != 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. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6581. var flush_count int64
  6582. for _, it := range goodList {
  6583. flush_count += it.StockCount
  6584. }
  6585. erros := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6586. if erros != 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. //扣减出库数据
  6603. errcoeds := service.ModifyReduceGoodSumCount(item.StorehouseId, item.Count, orgId, item.GoodId)
  6604. if errcoeds != nil {
  6605. goodErrcode := models.XtGoodErrcode{
  6606. UserOrgId: orgId,
  6607. Errcode: "反审核扣减出库数据报错",
  6608. GoodId: 0,
  6609. Status: 1,
  6610. Ctime: time.Now().Unix(),
  6611. Mtime: 0,
  6612. Count: 0,
  6613. StockCount: 0,
  6614. Creater: creater,
  6615. BatchNumberId: 0,
  6616. WarehouseOutId: 0,
  6617. }
  6618. service.CreateGoodErrcode(goodErrcode)
  6619. }
  6620. }
  6621. //删除流水,改变审核状态
  6622. errcos := service.ModifyGoodWarehouseOut(id)
  6623. if errcos != nil {
  6624. goodErrcode := models.XtGoodErrcode{
  6625. UserOrgId: orgId,
  6626. Errcode: "反审核删除流水,改变审核状态报错",
  6627. GoodId: 0,
  6628. Status: 1,
  6629. Ctime: time.Now().Unix(),
  6630. Mtime: 0,
  6631. Count: 0,
  6632. StockCount: 0,
  6633. Creater: creater,
  6634. BatchNumberId: 0,
  6635. WarehouseOutId: 0,
  6636. }
  6637. service.CreateGoodErrcode(goodErrcode)
  6638. }
  6639. if err == nil {
  6640. this.ServeSuccessJSON(map[string]interface{}{
  6641. "list": "list",
  6642. })
  6643. }
  6644. }
  6645. func (this *StockManagerApiController) CheckWarehouseInfo() {
  6646. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  6647. orgId := this.GetAdminUserInfo().CurrentOrgId
  6648. Creator := this.GetAdminUserInfo().AdminUser.Id
  6649. //查询默认仓库
  6650. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6651. //更改审核状态
  6652. err := service.UpdateCheckWarehouseInfo(warehousing_info_id)
  6653. if err == nil {
  6654. list, _ := service.GetWarehouseInfoList(warehousing_info_id, orgId)
  6655. for _, item := range list {
  6656. service.UpdateWarehouseInfoByIdList(item.WarehousingCount, item.ID)
  6657. //查询该耗材剩余库存库
  6658. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
  6659. var total_count int64
  6660. var sum_in_count int64
  6661. for _, it := range stockList {
  6662. total_count += it.StockCount
  6663. sum_in_count += it.WarehousingCount
  6664. }
  6665. //基础库插入数据
  6666. service.UpdateGoodInfoAddSumCount(item.GoodId, total_count, orgId, sum_in_count)
  6667. //查询该仓库是否有数据
  6668. _, errcode := service.GetGoodStockCount(orgId, item.StorehouseId, item.GoodId)
  6669. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6670. var flush_count int64
  6671. for _, it := range goodList {
  6672. flush_count += it.StockCount
  6673. }
  6674. stockFlow := models.VmStockFlow{
  6675. WarehousingId: item.WarehousingId,
  6676. GoodId: item.GoodId,
  6677. Number: item.Number,
  6678. LicenseNumber: item.LicenseNumber,
  6679. Count: item.WarehousingCount,
  6680. UserOrgId: item.OrgId,
  6681. PatientId: 0,
  6682. SystemTime: 0,
  6683. ConsumableType: 1,
  6684. IsSys: 1,
  6685. WarehousingOrder: item.WarehousingOrder,
  6686. WarehouseOutId: 0,
  6687. WarehouseOutOrderNumber: "",
  6688. IsEdit: 1,
  6689. CancelStockId: 0,
  6690. CancelOrderNumber: "",
  6691. Manufacturer: item.Manufacturer,
  6692. Dealer: item.Dealer,
  6693. Creator: Creator,
  6694. UpdateCreator: 0,
  6695. Status: 1,
  6696. Ctime: time.Now().Unix(),
  6697. Mtime: 0,
  6698. Price: item.PackingPrice,
  6699. WarehousingDetailId: item.ID,
  6700. WarehouseOutDetailId: 0,
  6701. CancelOutDetailId: 0,
  6702. ProductDate: item.ProductDate,
  6703. ExpireDate: item.ExpiryDate,
  6704. SupplyWarehouseId: item.SupplyWarehouseId,
  6705. StorehouseId: item.StorehouseId,
  6706. AdminUserId: 0,
  6707. BuyPrice: item.Price,
  6708. StockCount: "",
  6709. BatchNumberCount: item.WarehousingCount,
  6710. IsCheck: 1,
  6711. OverCount: flush_count,
  6712. }
  6713. //创建出库流水
  6714. service.CreateStockFlowOne(stockFlow)
  6715. if errcode == gorm.ErrRecordNotFound {
  6716. goodCount := models.XtGoodStockCount{
  6717. UserOrgId: orgId,
  6718. GoodId: item.GoodId,
  6719. StorehouseId: item.StorehouseId,
  6720. Status: 1,
  6721. Ctime: time.Now().Unix(),
  6722. Mtime: time.Now().Unix(),
  6723. StockInCount: item.WarehousingCount,
  6724. StockOutCount: 0,
  6725. StockCancelCount: 0,
  6726. FlushCount: flush_count,
  6727. StockActOutCount: 0,
  6728. }
  6729. service.CreateGoodCount(goodCount)
  6730. }
  6731. if errcode == nil {
  6732. service.UpdateGoodStockCount(orgId, item.StorehouseId, item.GoodId, item.WarehousingCount, flush_count)
  6733. }
  6734. }
  6735. }
  6736. if err == nil {
  6737. this.ServeSuccessJSON(map[string]interface{}{
  6738. "list": "list",
  6739. })
  6740. }
  6741. }
  6742. func (this *StockManagerApiController) ReturnCheckWarehouseInfo() {
  6743. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  6744. orgId := this.GetAdminUserInfo().CurrentOrgId
  6745. //查询入库数据
  6746. list, _ := service.GetWarehouseInfoList(warehousing_info_id, orgId)
  6747. for _, item := range list {
  6748. //查询该耗材 是否有出库数据
  6749. outlist, _ := service.GetWarehouseOutByWarehouseInfoId(item.ID, item.GoodId, item.OrgId)
  6750. if len(outlist) > 0 {
  6751. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
  6752. return
  6753. }
  6754. }
  6755. for _, item := range list {
  6756. //扣减数量
  6757. service.UpdateWarehouseInfoByIdListTwo(item.WarehousingCount, item.ID)
  6758. //删除流水
  6759. service.UpdateWarehouseInfoFlow(item.ID)
  6760. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6761. var flush_count int64
  6762. for _, it := range goodList {
  6763. flush_count += it.StockCount
  6764. }
  6765. //扣减数量
  6766. service.UpdateGoodInCount(item.WarehousingCount, item.OrgId, item.GoodId, item.StorehouseId, flush_count)
  6767. //查询默认仓库
  6768. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6769. //查询该耗材剩余多少库存
  6770. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
  6771. var sum_count int64
  6772. var sum_in_count int64
  6773. for _, it := range stockList {
  6774. sum_count += it.StockCount
  6775. sum_in_count += it.WarehousingCount
  6776. }
  6777. service.UpdateGoodInfoAddSumCount(item.GoodId, sum_count, orgId, sum_in_count)
  6778. }
  6779. err := service.ReturnCheckWarehouseInfo(warehousing_info_id)
  6780. if err == nil {
  6781. this.ServeSuccessJSON(map[string]interface{}{
  6782. "msg": "反审核成功!",
  6783. })
  6784. return
  6785. }
  6786. }
  6787. func (this *StockManagerApiController) CheckStockWarehouseInfo() {
  6788. cancel_stock_id, _ := this.GetInt64("cancel_stock_id")
  6789. orgId := this.GetAdminUserInfo().CurrentOrgId
  6790. list, _ := service.GetCancelStockInfoListById(cancel_stock_id, orgId)
  6791. creater := this.GetAdminUserInfo().AdminUser.Id
  6792. manufacturerlist, _ := service.GetAllManufacturerList(orgId)
  6793. dealerList, _ := service.GetAllDealerList(orgId)
  6794. var manufacturer_id int64
  6795. var cancel_total_count int64
  6796. var out_total_count int64
  6797. var dealer_id int64
  6798. for _, item := range list {
  6799. //查询该药品该批次的出库数量是否满足退库需求
  6800. outList, _ := service.GetWarehouseOutList(item.OrgId, item.GoodId, item.WarehouseInfoId)
  6801. for _, it := range outList {
  6802. out_total_count += it.Count
  6803. }
  6804. warehouseList, _ := service.GetCancelWarehouseList(item.OrgId, item.GoodId, item.WarehouseInfoId)
  6805. for _, it := range warehouseList {
  6806. cancel_total_count += it.Count
  6807. }
  6808. if cancel_total_count > out_total_count {
  6809. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6810. this.ServeSuccessJSON(map[string]interface{}{
  6811. "msg": "2",
  6812. "good_name": goodObj.GoodName,
  6813. "specification_name": goodObj.SpecificationName,
  6814. })
  6815. return
  6816. }
  6817. }
  6818. cancelStock := models.CancelStock{
  6819. IsCheck: 1,
  6820. }
  6821. service.CheckCancelStock(cancelStock, cancel_stock_id, orgId)
  6822. //回退库存
  6823. cancellist, _ := service.GetCancelStockInfoById(cancel_stock_id, orgId)
  6824. for _, item := range cancellist {
  6825. for _, items := range manufacturerlist {
  6826. if item.Manufacturer == items.ManufacturerName {
  6827. manufacturer_id = items.ID
  6828. }
  6829. }
  6830. for _, it := range dealerList {
  6831. if item.Dealer == it.DealerName {
  6832. dealer_id = it.ID
  6833. }
  6834. }
  6835. //回退库存
  6836. service.UpdateCancelStockNumber(item.Count, item.WarehouseInfoId, orgId)
  6837. //更新基础库库存
  6838. service.UpdateGoodSumCount(item.Count, item.GoodId, orgId)
  6839. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6840. //退库数量增加
  6841. service.UpdateSumAddCancelCount(orgId, item.GoodId, item.StorehouseId, item.Count)
  6842. var flush_count int64
  6843. for _, it := range goodList {
  6844. flush_count += it.StockCount
  6845. }
  6846. stockFlow := models.VmStockFlow{
  6847. ID: 0,
  6848. WarehousingId: item.WarehouseInfoId,
  6849. GoodId: item.GoodId,
  6850. Number: item.Number,
  6851. LicenseNumber: "",
  6852. Count: item.Count,
  6853. UserOrgId: item.OrgId,
  6854. PatientId: item.PatientId,
  6855. SystemTime: item.RecordDate,
  6856. ConsumableType: 4,
  6857. IsSys: 0,
  6858. WarehousingOrder: "",
  6859. WarehouseOutId: 0,
  6860. WarehouseOutOrderNumber: "",
  6861. IsEdit: 0,
  6862. CancelStockId: cancel_stock_id,
  6863. CancelOrderNumber: item.OrderNumber,
  6864. Manufacturer: manufacturer_id,
  6865. Dealer: dealer_id,
  6866. Creator: creater,
  6867. UpdateCreator: 0,
  6868. Status: 1,
  6869. Ctime: time.Now().Unix(),
  6870. Mtime: 0,
  6871. Price: item.Price,
  6872. WarehousingDetailId: item.WarehouseInfoId,
  6873. WarehouseOutDetailId: 0,
  6874. CancelOutDetailId: item.ID,
  6875. ProductDate: item.ProductDate,
  6876. ExpireDate: item.ExpiryDate,
  6877. ReturnCount: 0,
  6878. ProjectId: 0,
  6879. SupplyWarehouseId: 0,
  6880. SupplyCancelOutId: 0,
  6881. SupplyWarehouseDetailInfo: 0,
  6882. StorehouseId: item.StorehouseId,
  6883. SecondWarehouseInfoId: 0,
  6884. AdminUserId: 0,
  6885. BuyPrice: item.Price,
  6886. StockCount: "",
  6887. OverCount: flush_count,
  6888. }
  6889. //创建流水
  6890. service.CreateStockFlowOne(stockFlow)
  6891. //更新剩余库存
  6892. errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6893. //出库数量减少
  6894. service.ModifyAddGoodSumCount(item.StorehouseId, item.Count, orgId, item.GoodId)
  6895. if errs != nil {
  6896. goodErrcode := models.XtGoodErrcode{
  6897. UserOrgId: item.OrgId,
  6898. Errcode: "手动退库更新剩余出库失败",
  6899. GoodId: item.GoodId,
  6900. Status: 1,
  6901. Ctime: time.Now().Unix(),
  6902. Mtime: 0,
  6903. Count: 0,
  6904. StockCount: 0,
  6905. Creater: creater,
  6906. BatchNumberId: 0,
  6907. WarehouseOutId: 0,
  6908. }
  6909. service.CreateGoodErrcode(goodErrcode)
  6910. }
  6911. }
  6912. this.ServeSuccessJSON(map[string]interface{}{
  6913. "msg": "1",
  6914. "good_name": "",
  6915. "specification_name": "",
  6916. })
  6917. return
  6918. }
  6919. func (this *StockManagerApiController) CheckReturnStockWarehouseInfo() {
  6920. cancel_stock_id, _ := this.GetInt64("cancel_stock_id")
  6921. orgId := this.GetAdminUserInfo().CurrentOrgId
  6922. cancelStock := models.CancelStock{
  6923. IsCheck: 2,
  6924. }
  6925. list, _ := service.GetCancelStockInfoListById(cancel_stock_id, orgId)
  6926. creater := this.GetAdminUserInfo().AdminUser.Id
  6927. for _, item := range list {
  6928. //回退库存
  6929. service.UpdateStockNumberWarehouseInfo(item.WarehouseInfoId, item.GoodId, item.OrgId, item.Count)
  6930. service.UpdateStockWarehouseInfoStockFlow(item.ID, orgId, item.GoodId)
  6931. //退库数量增加
  6932. service.UpdateSumReduceCancelCount(orgId, item.GoodId, item.StorehouseId, item.Count)
  6933. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6934. var flush_count int64
  6935. for _, it := range goodList {
  6936. flush_count += it.StockCount
  6937. }
  6938. errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6939. //出库数量增加
  6940. service.UpdateSumAddOutCount(orgId, item.GoodId, item.StorehouseId, item.Count)
  6941. if errs != nil {
  6942. goodErrcode := models.XtGoodErrcode{
  6943. UserOrgId: item.OrgId,
  6944. Errcode: "手动退库反审核更新剩余出库失败",
  6945. GoodId: item.GoodId,
  6946. Status: 1,
  6947. Ctime: time.Now().Unix(),
  6948. Mtime: 0,
  6949. Count: 0,
  6950. StockCount: 0,
  6951. Creater: creater,
  6952. BatchNumberId: 0,
  6953. WarehouseOutId: 0,
  6954. }
  6955. service.CreateGoodErrcode(goodErrcode)
  6956. }
  6957. }
  6958. err := service.UpdateStockWarehouseInfo(cancel_stock_id, orgId, cancelStock)
  6959. if err == nil {
  6960. this.ServeSuccessJSON(map[string]interface{}{
  6961. "msg": "反审核成功!",
  6962. })
  6963. return
  6964. }
  6965. }
  6966. func (this *StockManagerApiController) GetPrintList() {
  6967. storehouse_id, _ := this.GetInt64("storehouse_id")
  6968. limit, _ := this.GetInt64("limit")
  6969. page, _ := this.GetInt64("page")
  6970. good_name := this.GetString("good_name")
  6971. fmt.Println(storehouse_id, good_name)
  6972. orgId := this.GetAdminUserInfo().CurrentOrgId
  6973. houseList, _ := service.GetAllStoreHouseList(orgId)
  6974. list, total, _ := service.GetInventoryDetailList(good_name, limit, page, orgId, storehouse_id)
  6975. this.ServeSuccessJSON(map[string]interface{}{
  6976. "list": list,
  6977. "total": total,
  6978. "houseList": houseList,
  6979. })
  6980. }
  6981. func (this *StockManagerApiController) GetInvetoryWarehouseInfoList() {
  6982. storehouse_id, _ := this.GetInt64("storehouse_id")
  6983. orgId := this.GetAdminUserInfo().CurrentOrgId
  6984. list, _ := service.GetInvetoryWarehouseInfoList(orgId, storehouse_id)
  6985. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  6986. dealerList, _ := service.GetAllDealerList(orgId)
  6987. this.ServeSuccessJSON(map[string]interface{}{
  6988. "list": list,
  6989. "manufacturerList": manufacturerList,
  6990. "dealerList": dealerList,
  6991. })
  6992. }