stock_in_api_controller.go 130KB

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