stock_in_api_controller.go 199KB

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