stock_in_api_controller.go 128KB

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