stock_in_api_controller.go 199KB

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