stock_in_api_controller.go 186KB

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