stock_in_api_controller.go 200KB

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