stock_in_api_controller.go 120KB

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