stock_in_api_controller.go 257KB

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