stock_in_api_controller.go 150KB

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