stock_in_api_controller.go 129KB

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