123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "reflect"
- "strconv"
- "strings"
- "time"
- )
-
- type StockDrugApiController struct {
- BaseAuthAPIController
- }
-
- func DrugStockManagerApiRegistRouters() {
-
- //入库管理和其他入库管理相关接口
- beego.Router("/api/drugwarehouse/create", &StockDrugApiController{}, "post:CreateDrugWarehouse")
- beego.Router("/api/drugwarehouse/list", &StockDrugApiController{}, "get:GetDrugWarehouseList")
- beego.Router("/api/drugwarehouse/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouse")
- beego.Router("/api/drugwarehouseinfo/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouseInfo")
- beego.Router("/api/drugwarehouseinfo/list", &StockDrugApiController{}, "get:GetDrugWarehouseInfoList")
- beego.Router("/api/drugwarehouse/edit", &StockDrugApiController{}, "post:EditDrugWarehouse")
-
- //退货管理和其他退货管理相关接口
- beego.Router("/api/drugsalesreturn/create", &StockDrugApiController{}, "post:CreateDrugSalesReturn")
- beego.Router("/api/drugsalesreturn/delete", &StockDrugApiController{}, "post:DeleteDrugSalesReturn")
- beego.Router("/api/drugsalesreturninfo/delete", &StockDrugApiController{}, "post:DeleteDrugSalesReturnInfo")
- beego.Router("/api/drugsalesreturninfo/list", &StockDrugApiController{}, "get:GetDrugSalesReturnInfoList")
- beego.Router("/api/drugsalesreturn/list", &StockDrugApiController{}, "get:GetDrugSalesReturnList")
- beego.Router("/api/drugsalesreturn/edit", &StockDrugApiController{}, "post:EditDrugReturnInfo")
-
- //出库管理和其他出库管理相关接口
- beego.Router("/api/drugwarehouseout/create", &StockDrugApiController{}, "post:CreateDrugWarehouseOut")
- beego.Router("/api/drugwarehouseout/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouseOut")
- beego.Router("/api/drugwarehouseoutinfo/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouseOutInfo")
- beego.Router("/api/drugwarehouseout/list", &StockDrugApiController{}, "get:GetDrugWarehouseOutList")
- beego.Router("/api/drugwarehouseout/edit", &StockDrugApiController{}, "post:EditDrugWarehouseOut")
- beego.Router("/api/drugwarehouseout/info", &StockDrugApiController{}, "get:GetDrugWarehouseOutInfoList")
-
- //出库退库管理和其他出库退库管理相关接口
- beego.Router("/api/drugcancelstock/create", &StockDrugApiController{}, "post:CreateDrugCancelStock")
- beego.Router("/api/drugcancelstock/list", &StockDrugApiController{}, "get:GetDrugCancelStockList")
- beego.Router("/api/drugcancelstock/info", &StockDrugApiController{}, "get:GetDrugCancelStockInfoList")
- beego.Router("/api/drugcancelstock/delete", &StockDrugApiController{}, "post:DeleteDrugCancelStock")
- beego.Router("/api/drugcancelstockinfo/delete", &StockDrugApiController{}, "post:DeleteDrugCancelStockInfo")
- beego.Router("/api/drugcancelstockinfo/edit", &StockDrugApiController{}, "post:EditDrugCancelStock")
-
- ////库存相关全局配置
- beego.Router("/api/drugstock/config", &StockDrugApiController{}, "get:GetAllConfig")
- //beego.Router("/api/drugreturn/config", &StockDrugApiController{}, "get:GetAllSalesReturnConfig")
- //
- ////库存查询
- beego.Router("/api/drugstock/query", &StockDrugApiController{}, "get:GetDrugQueryInfo")
- //
- //beego.Router("/api/drugstock/detail", &StockDrugApiController{}, "get:GetDetailInfo")
- //
- beego.Router("/api/drugwarehouseout/user", &StockDrugApiController{}, "get:GetUserDetailInfo")
-
- beego.Router("/api/drugstock/get", &StockDrugApiController{}, "get:GetAllDrugStock")
-
- beego.Router("/api/drug/getcanceldrugorderprint", &StockDrugApiController{}, "get:GetCancelDrugOrderPrint")
- beego.Router("/api/drug/drugcancelexportlist", &StockDrugApiController{}, "get:GetDrugCancelExportList")
- beego.Router("/api/drug/getdrugwarehouseinfoprint", &StockDrugApiController{}, "get:GetDrugWarehouseInfoPrint")
- beego.Router("/api/drug/getdrugoutorderprint", &StockDrugApiController{}, "get:GetDrugOutOrderPrint")
-
- beego.Router("/api/drugstock/config/list", &StockDrugApiController{}, "get:GetConfigList")
- beego.Router("/api/drug/checkwarehouseinginfo", &StockDrugApiController{}, "get:CheckWarehousingInfo")
- beego.Router("/api/drug/returncheckwarehouseinginfo", &StockDrugApiController{}, "get:ReturnCheckWarehouseingInfo")
- beego.Router("/api/drug/tocheckdrugout", &StockDrugApiController{}, "get:CheckDrugOut")
- beego.Router("/api/drug/toreturncheck", &StockDrugApiController{}, "get:ToReturnCheck")
- beego.Router("/api/drug/checkcanceldrugstock", &StockDrugApiController{}, "get:CheckCancelDrugStock")
- beego.Router("/api/drug/returndrugcancelstock", &StockDrugApiController{}, "get:ReturnDrugCancelStock")
- }
-
- func (c *StockDrugApiController) CreateDrugWarehouse() {
-
- warehousing_time := c.GetString("warehousing_time")
-
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- warehousing_id, _ := c.GetInt64("warehousing_id")
- ctime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
- total = total + 1
-
- warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- warehousing := models.DrugWarehouse{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehousingTime: warehousingDate.Unix(),
- Type: types,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- if warehousing_id == 0 {
- service.AddSigleDrugWarehouse(&warehousing)
- }
- if warehousing_id > 0 {
- service.UpdateSigleDrugWarehouse(warehousing_id, storehouse_id)
- }
- info, _ := service.FindLastWarehousingSeven(adminUserInfo.CurrentOrgId)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingInfo []*models.DrugWarehouseInfo
-
- if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockIn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
- utils.ErrorLog("warehousing_count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
-
- if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- utils.ErrorLog("last_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
- total := float64(warehousing_count) * last_price
-
- retail_price_total := float64(warehousing_count) * last_price
-
- var productDates int64
- var expiryDates int64
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- number, _ := items["number"].(string)
-
- batch_number, _ := items["batch_number"].(string)
-
- if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
- utils.ErrorLog("max_unit")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- max_unit, _ := items["max_unit"].(string)
-
- if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
- utils.ErrorLog("min_unit")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- min_unit, _ := items["min_unit"].(string)
-
- var remark string
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- remark = ""
- } else {
- remark = items["remark"].(string)
- }
-
- manufacturer := int64(items["manufacturer"].(float64))
-
- dealer := int64(items["dealer"].(float64))
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
-
- warehouseInfo := &models.DrugWarehouseInfo{
- ID: id,
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: info.ID,
- DrugId: drug_id,
- Number: number,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: last_price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- StockMaxNumber: 0,
- RetailTotalPrice: retail_price_total,
- BatchNumber: batch_number,
- MaxUnit: max_unit,
- MinUnit: min_unit,
- RetailPrice: retail_price,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- StockMinNumber: 0,
- }
- fmt.Println(warehouseInfo)
- warehousingInfo = append(warehousingInfo, warehouseInfo)
- }
- }
- }
-
- for _, item := range warehousingInfo {
- if item.ID == 0 {
- service.CreatedWarehouseing(item)
- }
- if item.ID > 0 {
- service.UpdateWarehouseing(item)
- }
- }
-
- list, _ := service.FindDrugWarehouseInfoListById(info.ID, adminUserInfo.CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "入库成功",
- "warehousing_order": warehousing_order,
- "info": info,
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "drugTypeList": drugTypeList,
- })
-
- }
- func (c *StockDrugApiController) GetDrugWarehouseList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- check_type, _ := c.GetInt64("check_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- //按药品名称搜索
- var ids []int64
- var idArray []int64
- list, _ := service.GetDrugNameByKeyword(keywords, adminUserInfo.CurrentOrgId)
- for _, item := range list {
- ids = append(ids, item.ID)
- }
-
- //查找入库单详情
- if len(ids) > 0 {
- info, _ := service.GetDrugWarehouseOrderDetailTwo(ids, adminUserInfo.CurrentOrgId, startTime, endTime, storehouse_id)
- for _, it := range info {
- idArray = append(idArray, it.WarehousingId)
- }
- }
-
- warehouseList, total, err := service.FindAllDrugWarehousingListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, idArray, storehouse_id, check_type)
- houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseList,
- "total": total,
- "houseList": houseList,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
- id, _ := c.GetInt64("id", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- admin := c.GetAdminUserInfo()
-
- warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
-
- manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- if warehousing.ID <= 0 {
- return
- }
-
- warehousingInfo, err := service.FindDrugWarehousingInfoByIdThree(id, admin.CurrentOrgId)
- list, _ := service.GetAllStoreHouseListThree(admin.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "info": warehousingInfo,
- "warehousing": warehousing,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "list": list,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (c *StockDrugApiController) EditDrugWarehouse() {
-
- warehousing_time := c.GetString("warehousing_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehouse, _ := service.FindDrugWarehousingById(id, adminUserInfo.CurrentOrgId)
-
- warehousing := models.DrugWarehouse{
- WarehousingOrder: warehouse.WarehousingOrder,
- OrgId: adminUserInfo.CurrentOrgId,
- Modifier: adminUserInfo.AdminUser.Id,
- Mtime: mtime,
- Status: 1,
- WarehousingTime: warehousingDate.Unix(),
- Type: warehouse.Type,
- StorehouseId: storehouse_id,
- }
-
- service.EditDrugWarehousingOne(warehousing, id)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingInfo []*models.DrugWarehouseInfo
- var upDateWarehousingInfo []*models.DrugWarehouseInfo
- var drugFlow []*models.DrugFlow
- if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockIn"].([]interface{})
-
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
- utils.ErrorLog("warehousing_count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(warehousing_count) * price
-
- if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- utils.ErrorLog("last_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
-
- retail_price_total := float64(warehousing_count) * last_price
-
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
-
- var productDates int64
- var expiryDates int64
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
- }
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- number, _ := items["number"].(string)
-
- batch_number, _ := items["batch_number"].(string)
-
- max_unit, _ := items["max_unit"].(string)
-
- min_unit, _ := items["min_unit"].(string)
-
- var remark string
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- remark = ""
- } else {
- remark = items["remark"].(string)
- }
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- manufacturer := int64(items["manufacturer"].(float64))
-
- dealer := int64(items["dealer"].(float64))
-
- medical, _ := service.GetBaseDrugMedical(drug_id)
- if id == 0 {
- warehouseInfo := &models.DrugWarehouseInfo{
- WarehousingOrder: warehouse.WarehousingOrder,
- WarehousingId: warehouse.ID,
- DrugId: drug_id,
- Number: number,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- BatchNumber: batch_number,
- MaxUnit: max_unit,
- MinUnit: min_unit,
- StockMaxNumber: 0,
- StorehouseId: storehouse_id,
- StockMinNumber: 0,
- }
-
- warehousingInfo = append(warehousingInfo, warehouseInfo)
-
- } else {
-
- warehouseInfo := &models.DrugWarehouseInfo{
- ID: id,
- WarehousingOrder: warehouse.WarehousingOrder,
- WarehousingId: warehouse.ID,
- DrugId: drug_id,
- Number: number,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- MaxUnit: max_unit,
- MinUnit: min_unit,
- BatchNumber: batch_number,
- StorehouseId: storehouse_id,
- }
- if medical.MaxUnit == medical.MinUnit {
- warehouseInfo.StockMaxNumber = warehousing_count
- warehouseInfo.StockMinNumber = 0
- warehouseInfo.MaxUnit = min_unit
- }
-
- if medical.MinUnit != medical.MaxUnit {
-
- if max_unit == medical.MaxUnit {
- warehouseInfo.StockMaxNumber = warehousing_count
- warehouseInfo.StockMinNumber = 0
- warehouseInfo.MaxUnit = max_unit
- warehouseInfo.MinUnit = medical.MinUnit
- }
- if max_unit == medical.MinUnit {
-
- warehouseInfo.StockMaxNumber = 0
- warehouseInfo.StockMinNumber = warehousing_count
- warehouseInfo.MaxUnit = medical.MinUnit
- warehouseInfo.MinUnit = medical.MinUnit
- }
- }
-
- upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
-
- drugflow := &models.DrugFlow{
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: warehouse.ID,
- DrugId: drug_id,
- Number: number,
- ProductDate: productDates,
- ExpireDate: expiryDates,
- Count: warehousing_count,
- Price: last_price,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: manufacturer,
- Dealer: dealer,
- BatchNumber: batch_number,
- MaxUnit: max_unit,
- MinUnit: min_unit,
- ConsumableType: 1,
- IsEdit: 1,
- Creator: adminUserInfo.AdminUser.Id,
- IsSys: 0,
- WarehousingDetailId: id,
- StorehouseId: storehouse_id,
- }
-
- if max_unit == min_unit {
- drugflow.MaxUnit = min_unit
- }
-
- drugFlow = append(drugFlow, drugflow)
- }
- }
- }
- }
- var errs error
- if len(warehousingInfo) > 0 {
- errs = service.CreateDrugWarehousingInfo(warehousingInfo)
- }
-
- if len(upDateWarehousingInfo) > 0 {
- for _, item := range upDateWarehousingInfo {
- service.UpdateDrugWarehouseInfoTwenty(item.ID, item)
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- list, _ := service.GetDrugWarehouseInfoList(id, adminUserInfo.CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "编辑成功",
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "drugTypeList": drugTypeList,
- })
-
- }
- func (c *StockDrugApiController) DeleteDrugWarehouse() {
- ids := c.GetString("ids")
-
- if len(ids) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- orgId := c.GetAdminUserInfo().CurrentOrgId
- err := service.DeleteDrugWarehouse(idArray)
- list, _ := service.GetLastDrugwarehouseInfoByIdTwenty(idArray, orgId)
-
- for _, it := range list {
- //查询默认仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(it.OrgId)
- //查询默认仓库剩余多少库存
- list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, it.OrgId, it.DrugId)
- var sum_count int64
- var sum_in_count int64
- for _, it := range list {
- baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- if it.MaxUnit == baseDrug.MaxUnit {
- it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- }
- sum_count += it.StockMaxNumber + it.StockMinNumber
- sum_in_count += it.WarehousingCount
- }
- service.UpdateMedicalSumCount(it.DrugId, sum_count, sum_in_count, it.OrgId)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (c *StockDrugApiController) DeleteDrugWarehouseInfo() {
- id, _ := c.GetInt64("id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- err := service.UpDateDrugWarehouseStatus(id)
- service.UpdateDrugFlowById(id)
- var sum_total int64
- list, _ := service.GetDrugWarehouseInfoByIdTwenty(id)
- medical, _ := service.GetBaseDrugMedical(list.DrugId)
- sum_total += list.StockMaxNumber*medical.MinNumber + list.StockMinNumber
- storeConfig, _ := service.GetAllStoreHouseConfig(list.OrgId)
- if storeConfig.DrugStorehouseInfo == list.StorehouseId {
- service.ModifyDrugReduceInformationTwo(list.DrugId, sum_total, list.OrgId)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
-
- func (c *StockDrugApiController) CreateDrugSalesReturn() {
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- sales_return_time := c.GetString("time")
- types, _ := c.GetInt64("type", 0)
-
- salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- ctime := time.Now().Unix()
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "YPTHD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- salesReturn := models.DrugSalesReturn{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: salesReturnDate.Unix(),
- Dealer: dealer_id,
- Manufacturer: manufacturer_id,
- Type: types,
- }
-
- service.AddSigleDrugSalesReturn(&salesReturn)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var salesReturnInfos []*models.DrugSalesReturnInfo
-
- if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["salesReturn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- return_count, _ := items["return_count"].(string)
- if len(return_count) == 0 {
- utils.ErrorLog("len(return_count) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
-
- return
- }
- count, _ := strconv.ParseInt(return_count, 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(count) * price
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
- retail_price_total := float64(count) * retail_price
-
- salesReturnInfo := &models.DrugSalesReturnInfo{
- OrderNumber: salesReturn.OrderNumber,
- SalesReturnId: salesReturn.ID,
- DrugId: drug_id,
- Count: count,
- Price: price,
- Total: total,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- }
-
- salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
-
- }
- }
- }
- errs := service.CreateDrugSalesReturnInfo(salesReturnInfos)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "退货成功",
- })
-
- }
- func (c *StockDrugApiController) GetDrugSalesReturnList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- returnList, total, err := service.FindAllDrugReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": returnList,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- func (this *StockDrugApiController) DeleteDrugSalesReturn() {
- ids := this.GetString("ids")
-
- if len(ids) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- err := service.DeleteDrugSalesReturn(idArray)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockDrugApiController) DeleteDrugSalesReturnInfo() {
- id, _ := this.GetInt64("id", 0)
- fmt.Println(id)
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- err := service.UpDateDrugSaleReturnStatus(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (this *StockDrugApiController) GetDrugSalesReturnInfoList() {
- id, _ := this.GetInt64("id", 0)
- adminUserInfo := this.GetAdminUserInfo()
-
- list, _ := service.FindAllDrugSalesReturnInfoById(id, adminUserInfo.CurrentOrgId)
- salesReturn, _ := service.FindAllDrugSalesReturnById(id, adminUserInfo.CurrentOrgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "salesReturn": salesReturn,
- })
-
- }
- func (c *StockDrugApiController) EditDrugReturnInfo() {
- return_time := c.GetString("return_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- dealer_id, _ := c.GetInt64("dealer_id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- salesReturns, _ := service.FindDrugSalesReturnById(id)
-
- sales := models.DrugSalesReturn{
- ID: salesReturns.ID,
- Mtime: mtime,
- ReturnTime: returnDate.Unix(),
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
-
- service.EditDrugSaleReturn(sales)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var returnInfos []*models.DrugSalesReturnInfo
- var upDateReturnInfos []*models.DrugSalesReturnInfo
-
- if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["salesReturn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(count) * price
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
- retail_price_total := float64(count) * retail_price
-
- if id == 0 {
- returnInfo := &models.DrugSalesReturnInfo{
- DrugId: drug_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: sales.OrderNumber,
- SalesReturnId: sales.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- Total: total,
- Price: price,
- }
- returnInfos = append(returnInfos, returnInfo)
-
- } else {
- returnInfo := &models.DrugSalesReturnInfo{
- ID: id,
- DrugId: drug_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: sales.OrderNumber,
- SalesReturnId: sales.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- Total: total,
- Price: price,
- }
- upDateReturnInfos = append(upDateReturnInfos, returnInfo)
- }
- }
- }
- }
- var errs error
- if len(returnInfos) > 0 {
- errs = service.CreateDrugSalesReturnInfo(returnInfos)
- }
-
- if len(upDateReturnInfos) > 0 {
- for _, item := range upDateReturnInfos {
- errs = service.UpDateDrugSalesReturnInfo(item)
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "编辑成功",
- })
-
- }
-
- func (c *StockDrugApiController) CreateDrugWarehouseOut() {
-
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
- ctime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousing_out_time := c.GetString("warehousing_out_time")
- warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- warehouseOut := models.DrugWarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehouseOutTime: warehousingOutDate.Unix(),
- Type: types,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- fmt.Println("warehouse_out_id232323322323232323233223", warehouse_out_id)
- if warehouse_out_id == 0 {
- service.AddSigleDrugWarehouseOut(&warehouseOut)
- }
- if warehouse_out_id > 0 {
- service.UpdateSingleDrugWarehouseOut(warehouse_out_id, storehouse_id)
- }
- lastWarehouseOut, _ := service.GetDrugLastWarehouseOut(adminUserInfo.CurrentOrgId)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingOutInfo []*models.DrugWarehouseOutInfo
-
- if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockOut"].([]interface{})
-
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
-
- items := item.(map[string]interface{})
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- total := float64(count) * price
- retail_price_total := float64(count) * price
- remark := items["remark"].(string)
- max_unit := items["max_unit"].(string)
- dealer := int64(items["dealer"].(float64))
-
- manufacturer := int64(items["manufacturer"].(float64))
-
- number := items["number"].(string)
- batch_number := items["batch_number"].(string)
-
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
- var productDates int64
- var expiryDates int64
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
- }
-
- admin_user_id := int64(items["admin_user_id"].(float64))
-
- //if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- // utils.ErrorLog("last_price")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
- //last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
-
- stock_count, _ := items["stock_count"].(string)
-
- id := int64(items["id"].(float64))
-
- warehouseOutInfo := &models.DrugWarehouseOutInfo{
- ID: id,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: lastWarehouseOut.ID,
- DrugId: drug_id,
- Count: count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- RetailPrice: price,
- RetailTotalPrice: retail_price_total,
- CountUnit: max_unit,
- ExpiryDate: expiryDates,
- ProductDate: productDates,
- Number: number,
- BatchNumber: batch_number,
- IsSys: 0,
- WarehouseInfoId: warehouse_info_id,
- StorehouseId: storehouse_id,
- AdminUserId: admin_user_id,
- StockCount: stock_count,
- IsCheck: 2,
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- }
- }
- }
-
- //var total_count int64 //总库存
- //var prescribing_number_total int64 //出库数据
-
- //调用出库逻辑
- for _, item := range warehousingOutInfo {
- if item.ID == 0 {
- errOne := service.AddSigleDrugWarehouseOutInfo(item)
- fmt.Println(errOne)
- }
- if item.ID > 0 {
- service.UpdatedDrugWarehouseInfo(item, item.ID)
- }
-
- }
-
- list, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
-
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
-
- warehousingOutInfoList, _ := service.GetDrugWarehouseOutListById(lastWarehouseOut.ID, adminUserInfo.CurrentOrgId)
-
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug_name": "",
- "dose": "",
- "dose_unit": "",
- "min_number": "",
- "min_unit": "",
- "max_unit": "",
- "dealerList": list,
- "manufacturerList": manufacturerList,
- "warehousingOutInfo": warehousingOutInfoList,
- "warehouseOut": lastWarehouseOut,
- "drugTypeList": drugTypeList,
- })
- return
- }
- func (c *StockDrugApiController) GetDrugWarehouseOutList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- way_type, _ := c.GetInt64("way_type")
- check_type, _ := c.GetInt64("check_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- var ids []int64
- var goodids []int64
- if len(keywords) > 0 {
- //查询商品名称
- list, _ := service.GetDrugNameByKeyword(keywords, adminUserInfo.CurrentOrgId)
- for _, item := range list {
- goodids = append(goodids, item.ID)
- }
-
- if len(goodids) > 0 {
- //出库详情但里面查询
- info, _ := service.GetDrugWarehouseOrderDetail(goodids, adminUserInfo.CurrentOrgId, startTime, endTime, storehouse_id)
- for _, it := range info {
- ids = append(ids, it.WarehouseOutId)
- }
- }
-
- }
-
- warehouseOutList, total, err := service.FindAllDrugWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id, way_type, check_type)
- fmt.Println("warehouseOutList232332323232323", warehouseOutList)
- houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- fmt.Println(err)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutList,
- "total": total,
- "houseList": houseList,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockDrugApiController) DeleteDrugWarehouseOut() {
- ids := c.GetString("ids")
-
- if len(ids) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- err := service.DeleteDrugWarehouseOut(idArray)
-
- //list, _ := service.GetDrugWarhouseOutByIds(idArray)
- //for _, item := range list {
- // medical, _ := service.GetBaseDrugMedical(item.DrugId)
- // if item.CountUnit == medical.MaxUnit {
- //
- // service.UpdateDrugInfoByIds(item.WarehouseInfoId, item.Count)
- //
- // }
- // if medical.MaxUnit != medical.MinUnit && item.CountUnit == medical.MinUnit {
- // service.UpdateDrugInfoByIdsOne(item.WarehouseInfoId, item.Count)
- // }
- //
- // //查询默认仓库
- // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询默认仓库剩余多少库存
- // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // }
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
- //}
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockDrugApiController) DeleteDrugWarehouseOutInfo() {
- id, _ := this.GetInt64("id", 0)
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- ////查询详情
- //info, _ := service.GetDrugWarehosueOutInfo(id)
- //
- ////查询默认仓库
- //houseConfig, _ := service.GetAllStoreHouseConfig(info.OrgId)
- ////查询默认仓库剩余多少库存
- //list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, info.OrgId, info.DrugId)
- //
- //for _, it := range list {
- //
- // //查询默认仓库
- // houseConfig, _ := service.GetAllStoreHouseConfig(it.OrgId)
- // //查询默认仓库剩余多少库存
- // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, it.OrgId, it.DrugId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // }
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateMedicalSumCount(it.DrugId, sum_count, sum_in_count, it.OrgId)
- //
- //}
-
- //删除流水
- //service.DeleteDrugWarehouseOutInfoById(info.ID)
- err := service.UpDateDrugWarehouseOutStatus(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (c *StockDrugApiController) GetDrugWarehouseOutInfoList() {
- id, _ := c.GetInt64("id", 0)
- adminInfo := c.GetAdminUserInfo()
- warehouseOutInfo, _ := service.FindDrugWarehouseOutInfoById(id, adminInfo.CurrentOrgId)
- warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminInfo.CurrentOrgId)
- manulist, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminInfo.CurrentOrgId)
- houstList, _ := service.GetAllStoreHouseList(adminInfo.CurrentOrgId)
- appId := c.GetAdminUserInfo().CurrentAppId
- doctorList, _ := service.GetAllDoctorListSix(adminInfo.CurrentOrgId, appId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutInfo,
- "info": warehouseOut,
- "manulist": manulist,
- "dealerList": dealerList,
- "houstList": houstList,
- "doctorList": doctorList,
- })
-
- }
- func (c *StockDrugApiController) EditDrugWarehouseOut() {
- warehouse_out_time := c.GetString("warehouse_out_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminUserInfo.CurrentOrgId)
-
- tempWarehouseOut := models.DrugWarehouseOut{
- ID: warehouseOut.ID,
- Mtime: mtime,
- WarehouseOutTime: warehouseOutDate.Unix(),
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- StorehouseId: storehouse_id,
- }
-
- service.EditDrugWarehouseOut(tempWarehouseOut)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingOutInfo []*models.DrugWarehouseOutInfo
- var upDateWarehouseOutInfos []*models.DrugWarehouseOutInfo
-
- var drugFlow []*models.DrugFlow
- if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
- thisStockOut, _ := dataBody["stockOut"].([]interface{})
- if len(thisStockOut) > 0 {
- for _, item := range thisStockOut {
- items := item.(map[string]interface{})
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- count_unit, _ := items["count_unit"].(string)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
-
- total := float64(count) * price
- retail_price_total := float64(count) * retail_price
-
- remark := items["remark"].(string)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- dealer := int64(items["dealer"].(float64))
- manufacturer := int64(items["manufacturer"].(float64))
-
- batch_number := items["batch_number"].(string)
- number := items["number"].(string)
- max_unit := items["count_unit"].(string)
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
- var productDates int64
- var expiryDates int64
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- admin_user_id := int64(items["admin_user_id"].(float64))
-
- //if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- // utils.ErrorLog("last_price")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
- //last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
-
- stock_count, _ := items["stock_count"].(string)
-
- if id == 0 {
- warehouseOutInfo := &models.DrugWarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- DrugId: drug_id,
- Count: count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- IsSys: 0,
- SysRecordTime: 0,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- BatchNumber: batch_number,
- Number: number,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- CountUnit: count_unit,
- WarehouseInfoId: warehouse_info_id,
- StorehouseId: storehouse_id,
- AdminUserId: admin_user_id,
- StockCount: stock_count,
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- drugflow := &models.DrugFlow{
- WarehousingOrder: "",
- WarehousingId: 0,
- DrugId: drug_id,
- Number: number,
- ProductDate: productDates,
- ExpireDate: expiryDates,
- Count: count,
- Price: price,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: manufacturer,
- Dealer: dealer,
- BatchNumber: batch_number,
- MaxUnit: max_unit,
- ConsumableType: 1,
- IsEdit: 1,
- Creator: adminUserInfo.AdminUser.Id,
- IsSys: 0,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: id,
- StorehouseId: storehouse_id,
- AdminUserId: admin_user_id,
- StockCount: stock_count,
- }
-
- drugFlow = append(drugFlow, drugflow)
-
- } else {
- if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
- utils.ErrorLog("is_sys")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- is_sys := int64(items["is_sys"].(float64))
-
- if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
- utils.ErrorLog("sys_record_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- sys_record_time := int64(items["sys_record_time"].(float64))
-
- warehouseOutInfo := &models.DrugWarehouseOutInfo{
- ID: id,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- DrugId: drug_id,
- Count: count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- IsSys: is_sys,
- SysRecordTime: sys_record_time,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- BatchNumber: batch_number,
- Number: number,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- CountUnit: count_unit,
- WarehouseInfoId: warehouse_info_id,
- StorehouseId: storehouse_id,
- AdminUserId: admin_user_id,
- StockCount: stock_count,
- }
- upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
-
- drugflow := &models.DrugFlow{
- WarehousingOrder: "",
- WarehousingId: 0,
- DrugId: drug_id,
- Number: number,
- ProductDate: productDates,
- ExpireDate: expiryDates,
- Count: count,
- Price: price,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: manufacturer,
- Dealer: dealer,
- BatchNumber: batch_number,
- MaxUnit: max_unit,
- ConsumableType: 1,
- IsEdit: 1,
- Creator: adminUserInfo.AdminUser.Id,
- IsSys: 0,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- StorehouseId: storehouse_id,
- AdminUserId: admin_user_id,
- StockCount: stock_count,
- }
-
- drugFlow = append(drugFlow, drugflow)
- }
- }
- }
- }
- var errs error
- if len(warehousingOutInfo) > 0 {
-
- //var total_count int64
- //var prescribing_number_total int64
- //调用出库逻辑
- for _, item := range warehousingOutInfo {
-
- errOnes := service.AddSigleDrugWarehouseOutInfo(item)
- fmt.Println("errone", errOnes)
-
- ////获取药品库存
- //info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId, storehouse_id)
- ////查询改药品信息
- //medical, _ := service.GetBaseDrugMedical(item.DrugId)
- ////判断单位是否相等
- //if medical.MaxUnit == item.CountUnit {
- // //转化为最小单位
- // total_count = info.Count * medical.MinNumber
- // prescribing_number_total = item.Count * medical.MinNumber
- //}
- //if medical.MinUnit == item.CountUnit {
- // total_count = info.Count
- // prescribing_number_total = item.Count
- //}
- //
- ////判断单位
- //if total_count == 0 {
- // goodObj, _ := service.GetDrugByGoodId(item.DrugId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // "drug_name": goodObj.DrugName,
- // "dose": goodObj.Dose,
- // "dose_unit": goodObj.DoseUnit,
- // "min_number": goodObj.MinNumber,
- // "min_unit": goodObj.MinUnit,
- // "max_unit": goodObj.MaxUnit,
- // })
- // return
- //}
- //if prescribing_number_total > total_count {
- //
- // goodObj, _ := service.GetDrugByGoodId(item.DrugId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // "drug_name": goodObj.DrugName,
- // "dose": goodObj.Dose,
- // "dose_unit": goodObj.DoseUnit,
- // "min_number": goodObj.MinNumber,
- // "min_unit": goodObj.MinUnit,
- // "max_unit": goodObj.MaxUnit,
- // })
- // return
- //} else {
- //
- // // 出库流程
- // // 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
- // drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
- // if drup.ID > 0 {
- // prescribingNumber := item.Count
- // service.AutoDrugDeliverInfoTwentyOne(item.OrgId, prescribingNumber, &tempWarehouseOut, &drup, item)
- // }
- //}
-
- }
- }
-
- if len(upDateWarehouseOutInfos) > 0 {
- for _, item := range upDateWarehouseOutInfos {
-
- service.UpdatedDrugWarehouseInfo(item, item.ID)
- ////获取药品库存
- //info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId, storehouse_id)
- ////查询改药品信息
- //medical, _ := service.GetBaseDrugMedical(item.DrugId)
- ////查询最后一次出库记录
- //outInfo, _ := service.GetLastDrugWarehouseOutInfo(item.DrugId, item.WarehouseOutId, item.OrgId)
- //var min_number int64 //最后一次出库数量
- //var max_number int64 //当前出库数量
- //var all_number int64 //总库存
- //var cha_number int64 //库存差
- //var maxNumber int64
- //var minNumber int64
- //
- //if medical.MaxUnit == outInfo.CountUnit {
- // //转为最小单位
- // min_number = outInfo.Count * medical.MinNumber
- //}
- //
- //if medical.MinUnit == outInfo.CountUnit {
- // min_number = outInfo.Count
- //}
- //
- //if medical.MaxUnit == item.CountUnit {
- // max_number = item.Count * medical.MinNumber
- //}
- //
- //if medical.MinUnit == item.CountUnit {
- // max_number = item.Count
- //}
- //
- //all_number = info.Count*medical.MinNumber + info.StockMinNumber
- //
- ////比较当前出库数量 小于等于 最后一次出库数量,则需要退库
- //if max_number <= min_number {
- // errs = service.UpDateDrugWarehouseOutInfo(item)
- // flow := models.DrugFlow{
- // Count: max_number,
- // ExpireDate: item.ExpiryDate,
- // ProductDate: item.ProductDate,
- // Price: item.Price,
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // Number: item.Number,
- // WarehouseOutId: item.WarehouseOutId,
- // StorehouseId: item.StorehouseId,
- // AdminUserId: item.AdminUserId,
- // StockCount: item.StockCount,
- // }
- // service.UpdateDrugFlowSix(item.WarehouseOutId, item.DrugId, item.WarehouseOutOrderNumber, flow)
- // cha_number = min_number - max_number
- //
- // if item.CountUnit == medical.MaxUnit {
- // maxNumber = cha_number / medical.MinNumber
- //
- // parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId, outInfo.WarehouseInfoId)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "drug_name": "",
- // "dose": "",
- // "dose_unit": "",
- // "min_number": "",
- // "min_unit": "",
- // "max_unit": "",
- // })
- // minNumber = cha_number % medical.MinNumber
- // if minNumber < 0 {
- // minNumber = 0
- // }
- // parseDateErr = service.UpdateWarehouseInfoOne(minNumber, item.DrugId, item.OrgId, outInfo.WarehouseInfoId)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "drug_name": "",
- // "dose": "",
- // "dose_unit": "",
- // "min_number": "",
- // "min_unit": "",
- // "max_unit": "",
- // })
- // }
- // if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- // parseDateErr := service.UpdateWarehouseInfoOne(cha_number, item.DrugId, item.OrgId, outInfo.WarehouseInfoId)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "drug_name": "",
- // "dose": "",
- // "dose_unit": "",
- // "min_number": "",
- // "min_unit": "",
- // "max_unit": "",
- // })
- // }
- //
- //}
- ////比较当前出库数量 大于 最后一次出库数量,则需要出库
- //if max_number > min_number {
- //
- // cha_number = max_number - min_number
- // //如果总库存大于差,正常出库
- // if all_number > cha_number {
- //
- // errs = service.UpDateDrugWarehouseOutInfo(item)
- // flow := models.DrugFlow{
- // Count: max_number,
- // ExpireDate: item.ExpiryDate,
- // ProductDate: item.ProductDate,
- // Price: item.Price,
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // Number: item.Number,
- // StorehouseId: item.StorehouseId,
- // AdminUserId: item.AdminUserId,
- // }
- // service.UpdateDrugFlowSix(item.WarehouseOutId, item.DrugId, item.WarehouseOutOrderNumber, flow)
- //
- // service.UpdateWarehouseInfoTwentyFive(cha_number, item.DrugId, item.OrgId, storehouse_id, &medical)
- //
- //
- // }
- //
- // if all_number == cha_number {
- // warehouseInfo := models.XtDrugWarehouseInfo{
- // Number: item.Number,
- // ProductDate: item.ProductDate,
- // ExpiryDate: item.ExpiryDate,
- // Price: item.Price,
- // TotalPrice: item.TotalPrice,
- // Dealer: item.Dealer,
- // Manufacturer: item.Manufacturer,
- // Remark: item.Remark,
- // BatchNumber: item.BatchNumber,
- // MaxUnit: item.CountUnit,
- // StorehouseId: item.StorehouseId,
- // }
- // parseDateErr := service.UpdateDrugWarehouseingInfoSix(item.ID, warehouseInfo)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- // fmt.Println("单位123223232323", item.CountUnit)
- // fmt.Println("单位232232323323232", medical.MaxUnit)
- //
- // errs = service.UpDateDrugWarehouseOutInfo(item)
- // flow := models.DrugFlow{
- // Count: item.Count,
- // ExpireDate: item.ExpiryDate,
- // ProductDate: item.ProductDate,
- // Price: item.Price,
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // Number: item.Number,
- // StorehouseId: item.StorehouseId,
- // AdminUserId: item.AdminUserId,
- // }
- // service.UpdateDrugFlowSix(item.WarehouseOutId, item.DrugId, item.WarehouseOutOrderNumber, flow)
- // if item.CountUnit == medical.MaxUnit {
- // maxNumber = cha_number / medical.MinNumber
- //
- // parseDateErr := service.UpdateWarehouseInfoTwo(maxNumber, item.DrugId, item.OrgId)
- //
- // fmt.Println("parseDateErr", parseDateErr)
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "drug_name": "",
- // "dose": "",
- // "dose_unit": "",
- // "min_number": "",
- // "min_unit": "",
- // "max_unit": "",
- // })
- // minNumber = cha_number % medical.MinNumber
- // if minNumber < 0 {
- // minNumber = 0
- // }
- // parseDateErr = service.UpdateWarehouseInfoFour(minNumber, item.DrugId, item.OrgId)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "drug_name": "",
- // "dose": "",
- // "dose_unit": "",
- // "min_number": "",
- // "min_unit": "",
- // "max_unit": "",
- // })
- // }
- // if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- // parseDateErr := service.UpdateWarehouseInfoFour(cha_number, item.DrugId, item.OrgId)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "drug_name": "",
- // "dose": "",
- // "dose_unit": "",
- // "min_number": "",
- // "min_unit": "",
- // "max_unit": "",
- // })
- // }
- //
- // }
- // if all_number < cha_number {
- // goodObj, _ := service.GetDrugByGoodId(item.DrugId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // "drug_name": goodObj.DrugName,
- // "dose": goodObj.Dose,
- // "dose_unit": goodObj.DoseUnit,
- // "min_number": goodObj.MinNumber,
- // "min_unit": goodObj.MinUnit,
- // "max_unit": goodObj.MaxUnit,
- // })
- // return
- // }
- //}
- //
- ////查询默认仓库
- //houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- ////查询默认仓库剩余多少库存
- //list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- //var sum_count int64
- //var sum_in_count int64
- //for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- //
- // }
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- //}
- //service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
-
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug_name": "",
- "dose": "",
- "dose_unit": "",
- "min_number": "",
- "min_unit": "",
- "max_unit": "",
- })
-
- }
-
- func (c *StockDrugApiController) CreateDrugCancelStock() {
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- cancel_stock_time := c.GetString("time")
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- cancelstock_id, _ := c.GetInt64("cancelstock_id")
- cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetAdminUserInfo()
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- ctime := time.Now().Unix()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.DrugCancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: cancelStockDate.Unix(),
- Dealer: dealer_id,
- Manufacturer: manufacturer_id,
- Type: types,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- if cancelstock_id == 0 {
- service.AddSigleDrugCancelStock(&cancelStock)
- }
- if cancelstock_id > 0 {
- service.UpdateSingleDrugCancelStock(cancelstock_id, storehouse_id)
- }
- cancelLastStock, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var cancelStockInfos []*models.DrugCancelStockInfo
- var drugFlow []*models.DrugFlow
-
- if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["cancelStock"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- return_count, _ := items["return_count"].(string)
- if len(return_count) == 0 {
- utils.ErrorLog("len(return_count) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
-
- return
- }
-
- count, _ := strconv.ParseInt(return_count, 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(count) * price
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
- retail_price_total := float64(count) * retail_price
-
- register_account, _ := items["register_account"].(string)
-
- remark, _ := items["remark"].(string)
-
- var productDates int64
- var expiryDates int64
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- manufacturer, _ := items["manufacturer"].(string)
-
- dealer, _ := items["dealer"].(string)
-
- batch_number := items["batch_number"].(string)
- max_unit := items["max_unit"].(string)
- batch_number_id := int64(items["batch_number_id"].(float64))
- var manufacturer_id int64
- var dealer_id int64
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- for _, item := range manufacturerList {
- if manufacturer == item.ManufacturerName {
- manufacturer_id = item.ID
- }
- }
- for _, item := range dealerList {
- if dealer == item.DealerName {
- dealer_id = item.ID
- }
- }
- cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
- cancelStockInfo := &models.DrugCancelStockInfo{
- ID: id,
- OrderNumber: cancelInfo.OrderNumber,
- CancelStockId: cancelInfo.ID,
- DrugId: drug_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Total: total,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- Price: price,
- RegisterAccount: register_account,
- Remark: remark,
- BatchNumber: batch_number,
- MaxUnit: max_unit,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- BatchNumberId: batch_number_id,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
-
- flow := &models.DrugFlow{
- WarehousingId: 0,
- DrugId: drug_id,
- Number: "",
- BatchNumber: batch_number,
- Count: count,
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: 0,
- SystemTime: ctime,
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- Creator: adminUserInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: expiryDates,
- ProductDate: productDates,
- MaxUnit: max_unit,
- MinUnit: "",
- StorehouseId: storehouse_id,
- }
- drugFlow = append(drugFlow, flow)
- }
- }
- }
-
- for _, item := range cancelStockInfos {
- if item.ID == 0 {
- service.CreateCancelStockInfoTwo(item)
- }
- if item.ID > 0 {
- service.ModifyDrugCancelStockInfo(item.ID, item)
- }
- }
-
- list, _ := service.GetLastCancelStockByList(cancelLastStock.ID, adminUserInfo.CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "cancelStock": cancelLastStock,
- "cancelLastStock": cancelLastStock,
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "drugTypeList": drugTypeList,
- "msg": "1",
- })
- //扣减库存逻辑
- //for _, item := range cancelStockInfos {
- //
- // var total_number int64
- // var out_number int64
- // var can_number int64
- // medical, _ := service.GetBaseDrugMedical(item.DrugId)
- // //将当前退库数转为最小单位
- // if item.MaxUnit == medical.MaxUnit {
- // total_number = item.Count * medical.MinNumber
- // }
- // if item.MaxUnit == medical.MinUnit {
- // total_number = item.Count
- // }
- // //查询当前药品退库的批次号的总入库数
- // infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
- // var total_count int64
- // total_count = infoWareInfo.WarehousingCount * medical.MinNumber
- //
- // //查询该批次的出库数量
- // outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
- //
- // //查询该批次总的退库数量
- // canInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
- //
- // for _, it := range canInfo {
- // if it.MaxUnit == medical.MaxUnit {
- // it.Count = it.Count * medical.MinNumber
- // }
- // if it.MaxUnit == medical.MinUnit {
- // it.Count = it.Count
- // }
- // }
- //
- // for _, it := range canInfo {
- // can_number += it.Count
- // }
- //
- // for _, it := range outInfo {
- // if it.CountUnit == medical.MaxUnit {
- // it.Count = it.Count * medical.MinNumber
- // }
- // if it.CountUnit == medical.MinUnit {
- // it.Count = it.Count
- // }
- // }
- // for _, it := range outInfo {
- // out_number += it.Count
- // }
- //
- // if out_number == 0 {
- // service.UpdateDrugCancel(item.CancelStockId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // })
- // return
- // }
- // fmt.Println("当前退库数", total_count)
- // fmt.Println("当前批次总库存", total_count)
- // fmt.Println("总出库数", out_number)
- // //判断退库数量是否大于总入库数量
- // if total_number > total_count {
- // service.UpdateDrugCancel(item.CancelStockId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // })
- // return
- // }
- //
- // //判断总退库数量是否大于出库数量
- //
- // if can_number+total_number > out_number {
- // //清空退库单
- // service.UpdateDrugCancel(item.CancelStockId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // })
- // return
- // }
- //
- // //正常退库
- // if total_number <= out_number {
- // //创建退库详情
- // errs := service.CreateCancelStockInfoTwo(item)
- // lastInfo, _ := service.GetLastStockInfoThree(item.DrugId)
- // //创建库存明细
- // flows := models.DrugFlow{
- // WarehousingId: 0,
- // DrugId: item.DrugId,
- // Number: "",
- // BatchNumber: item.BatchNumber,
- // Count: item.Count,
- // UserOrgId: adminUserInfo.CurrentOrgId,
- // PatientId: 0,
- // SystemTime: ctime,
- // ConsumableType: 4,
- // IsSys: 0,
- // WarehousingOrder: infoWareInfo.WarehousingOrder,
- // WarehouseOutId: 0,
- // WarehouseOutOrderNumber: "",
- // IsEdit: 0,
- // CancelStockId: cancelStock.ID,
- // CancelOrderNumber: cancelStock.OrderNumber,
- // Manufacturer: manufacturer_id,
- // Dealer: dealer_id,
- // Creator: adminUserInfo.AdminUser.Id,
- // UpdateCreator: 0,
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // Price: item.Price,
- // WarehousingDetailId: 0,
- // WarehouseOutDetailId: 0,
- // CancelOutDetailId: lastInfo.ID,
- // ExpireDate: item.ExpiryDate,
- // ProductDate: item.ProductDate,
- // MaxUnit: item.MaxUnit,
- // MinUnit: "",
- // StorehouseId: storehouse_id,
- // }
- // errs = service.CreateDrugFlowOne(flows)
- //
- // var total int64
- //
- // if medical.MaxUnit == item.MaxUnit {
- // total = item.Count
- //
- // warehouseInfo := models.XtDrugWarehouseInfo{
- // StockMaxNumber: total,
- // }
- //
- // errs = service.UpdateDrugWarehouseInfo(&warehouseInfo, item.BatchNumberId)
- // //查询默认仓库
- // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询默认仓库剩余多少库存
- // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // }
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
- // if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // })
- // }
- //
- // if medical.MinUnit == item.MaxUnit && medical.MaxUnit != medical.MinUnit {
- // total = item.Count
- // warehouseInfo := models.XtDrugWarehouseInfo{
- // StockMinNumber: total,
- // }
- //
- // errs = service.UpdateDrugWarehouseInfoOne(&warehouseInfo, item.BatchNumberId)
- // //查询默认仓库
- // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询默认仓库剩余多少库存
- // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // }
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
- // if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // })
- // }
- // }
- //
- //}
- }
- func (c *StockDrugApiController) GetDrugCancelStockInfoList() {
- id, _ := c.GetInt64("id", 0)
- adminUserInfo := c.GetAdminUserInfo()
-
- cancelStockInfoList, _ := service.FindDrugCancelStockInfoById(id, adminUserInfo.CurrentOrgId)
-
- info, _ := service.FindCancelDrugById(id, adminUserInfo.CurrentOrgId)
-
- list, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cancelStockInfoList,
- "info": info,
- "houselist": list,
- })
-
- }
- func (c *StockDrugApiController) GetDrugCancelStockList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- check_type, _ := c.GetInt64("check_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- returnList, total, err := service.FindAllDrugCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, storehouse_id, check_type)
- houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": returnList,
- "total": total,
- "houseList": houseList,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- func (this *StockDrugApiController) DeleteDrugCancelStock() {
- ids := this.GetString("ids")
-
- if len(ids) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- ////获取入库数据
- //list, _ := service.GetDrugWareInfoByCancelId(idArray)
- //for _, item := range list {
- // medical, _ := service.GetBaseDrugMedical(item.DrugId)
- // if item.MaxUnit == medical.MaxUnit {
- // //回退库存
- // service.ModifyDrugWarehouseByInfoId(item.BatchNumberId, item.Count)
- //
- // }
- // if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- // service.ModifyDrugWarehouseByStockMin(item.BatchNumberId, item.Count)
- // }
- //
- // //查询默认仓库
- // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询默认仓库剩余多少库存
- // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- // }
- // }
- // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
- //}
- err := service.DeleteDrugCancelStock(idArray)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockDrugApiController) DeleteDrugCancelStockInfo() {
- id, _ := this.GetInt64("id", 0)
-
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ////查询
- //cancelinfo, _ := service.GetDrugCancelById(id)
- //
- //drug, _ := service.GetBaseDrugMedical(cancelinfo.DrugId)
- //if drug.MaxUnit == cancelinfo.MaxUnit {
- // service.ModeFyDrugWareseInfo(cancelinfo.BatchNumberId, cancelinfo.Count)
- //
- //}
- //if drug.MinUnit == cancelinfo.MaxUnit && drug.MaxUnit != drug.MinUnit {
- // service.ModeFyDrugWarehouseMin(cancelinfo.BatchNumberId, cancelinfo.Count)
- //}
- //
- err := service.UpDateDrugCancleStockStatus(id)
-
- //删除流水
- // service.UpDateDrugCancelStockById(cancelinfo.ID)
-
- //查询默认仓库
- //houseConfig, _ := service.GetAllStoreHouseConfig(cancelinfo.OrgId)
- ////查询默认仓库剩余多少库存
- //list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, cancelinfo.OrgId, cancelinfo.DrugId)
- //var sum_count int64
- //var sum_in_count int64
- //for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // }
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- //}
- //service.UpdateMedicalSumCount(cancelinfo.DrugId, sum_count, sum_in_count, cancelinfo.OrgId)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (c *StockDrugApiController) EditDrugCancelStock() {
- cancel_time := c.GetString("cancel_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- cancelStock, _ := service.FindDrugCancelStockById(id)
-
- tempCancelStock := models.DrugCancelStock{
- ID: cancelStock.ID,
- Mtime: mtime,
- ReturnTime: cancelDate.Unix(),
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- StorehouseId: storehouse_id,
- IsCheck: 1,
- }
-
- service.EditDrugCancelStock(tempCancelStock)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var cancelStockInfos []*models.DrugCancelStockInfo
- var upDateCancelStockInfos []*models.DrugCancelStockInfo
- var drugFlow []*models.DrugFlow
- if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
- thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
- if len(thisCancelStock) > 0 {
- for _, item := range thisCancelStock {
- items := item.(map[string]interface{})
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(count) * price
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
- retail_price_total := float64(count) * retail_price
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- max_unit := items["max_unit"].(string)
- batch_number := items["batch_number"].(string)
-
- register_account := items["register_account"].(string)
-
- remark := items["remark"].(string)
-
- manufacturer := items["manufacturer"].(string)
-
- dealer := items["dealer"].(string)
-
- var productDates int64
- var expiryDates int64
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- batch_number_id := int64(items["batch_number_id"].(float64))
- if id == 0 {
- cancelStockInfo := &models.DrugCancelStockInfo{
- DrugId: drug_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- Price: price,
- Total: total,
- Manufacturer: manufacturer,
- Dealer: dealer,
- RegisterAccount: register_account,
- MaxUnit: max_unit,
- BatchNumber: batch_number,
- Remark: remark,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- BatchNumberId: batch_number_id,
- StorehouseId: storehouse_id,
- }
- cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
-
- } else {
- cancelStockInfo := &models.DrugCancelStockInfo{
- ID: id,
- DrugId: drug_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- Price: price,
- Total: total,
- Manufacturer: manufacturer,
- Dealer: dealer,
- RegisterAccount: register_account,
- MaxUnit: max_unit,
- BatchNumber: batch_number,
- Remark: remark,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- BatchNumberId: batch_number_id,
- StorehouseId: storehouse_id,
- }
- upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
- }
-
- flow := &models.DrugFlow{
- WarehousingId: 0,
- DrugId: drug_id,
- Number: "",
- BatchNumber: batch_number,
- Count: count,
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: 0,
- SystemTime: time.Now().Unix(),
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: 0,
- Dealer: 0,
- Creator: adminUserInfo.AdminUser.Id,
- UpdateCreator: adminUserInfo.AdminUser.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: expiryDates,
- ProductDate: productDates,
- MaxUnit: max_unit,
- MinUnit: "",
- StorehouseId: storehouse_id,
- }
- drugFlow = append(drugFlow, flow)
- }
- }
- }
-
- if len(cancelStockInfos) > 0 {
- service.CreateDrugCancelStockInfo(cancelStockInfos)
- }
- if len(upDateCancelStockInfos) > 0 {
- for _, item := range upDateCancelStockInfos {
- service.UpDateDrugCancelStockInfo(item)
- }
-
- }
-
- //var errs error
- //if len(cancelStockInfos) > 0 {
- //
- // //扣减库存逻辑
- // for _, item := range cancelStockInfos {
- // medical, _ := service.GetBaseDrugMedical(item.DrugId)
- // //查询当前药品退库的批次号的总入库数
- // infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
- //
- // var total_count int64
- // var cancel_count int64
- // var out_count int64
- // total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
- // //转化为最小单位
- // var total_number int64
- // if item.MaxUnit == medical.MaxUnit {
- // total_number = item.Count * medical.MinNumber
- // }
- // if item.MaxUnit == medical.MinUnit {
- // total_number = item.Count
- // }
- //
- // //统计该批次的总出库数
- // outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
- // for _, item := range outInfo {
- // if item.CountUnit == medical.MaxUnit {
- // item.Count = item.Count * medical.MinNumber
- // }
- // if item.CountUnit == medical.MinUnit {
- // item.Count = item.Count
- // }
- // }
- //
- // for _, item := range outInfo {
- // out_count += item.Count
- // }
- //
- // //判断退库数量是否大于出库数量
- // cancelInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
- // for _, item := range cancelInfo {
- // if item.MaxUnit == medical.MaxUnit {
- // item.Count = item.Count * medical.MinNumber
- // }
- // if item.MaxUnit == medical.MinUnit {
- // item.Count = item.Count
- // }
- // }
- //
- // for _, item := range cancelInfo {
- // cancel_count += item.Count
- // }
- //
- // if total_number+cancel_count > out_count {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "4",
- // })
- // return
- // }
- //
- // //判断退库数量是否大于总入库数量
- // if total_number > total_count {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // })
- // return
- // }
- //
- // //正常退库
- // if total_number <= total_count {
- // //创建退库详情
- // errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
- // //创建库存明细
- // //查询这个药品这个订单是否已存在流水
- // for _, items := range drugFlow {
- // drugwarehouseinfo, _ := service.GetLastDrugCancelStockInfoById(items.DrugId)
- // items.CancelOutDetailId = drugwarehouseinfo.ID
- // _, errsId := service.GetCancelStockId(items.CancelStockId, items.DrugId)
- // if errsId == gorm.ErrRecordNotFound {
- //
- // errs = service.CreateDrugFlowTwo(items)
- // }
- // }
- //
- // //获取该批次最后一条退库详情
- // lastCancel, _ := service.GetLastCancelStockInfo(id)
- // var cancel_number int64
- // if lastCancel.MaxUnit == medical.MaxUnit {
- // cancel_number = lastCancel.Count * medical.MinNumber
- // }
- //
- // if lastCancel.MaxUnit == medical.MinUnit {
- // cancel_number = lastCancel.Count
- // }
- //
- // var total int64
- //
- // if medical.MaxUnit == item.MaxUnit {
- // total = item.Count - cancel_number
- //
- // warehouseInfo := models.XtDrugWarehouseInfo{
- // StockMaxNumber: total,
- // }
- // errs = service.UpdateDrugWarehouseInfo(&warehouseInfo, item.BatchNumberId)
- //
- // if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // })
- // }
- // if medical.MinUnit == item.MaxUnit && medical.MaxUnit != medical.MinUnit {
- // total = item.Count - cancel_number
- // warehouseInfo := models.XtDrugWarehouseInfo{
- // StockMinNumber: total,
- // }
- //
- // errs = service.UpdateDrugWarehouseInfoOne(&warehouseInfo, item.BatchNumberId)
- //
- // //查询默认仓库
- // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询默认仓库剩余多少库存
- // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // }
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
- //
- // if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // })
- // }
- //
- // }
- //
- // }
- //}
- //if len(drugFlow) > 0 {
- // for _, items := range drugFlow {
- // _, errsId := service.GetCancelStockId(items.CancelStockId, items.DrugId)
- // if errsId == gorm.ErrRecordNotFound {
- // errs = service.CreateDrugFlowTwo(items)
- // }
- // }
- //}
- //
- //if len(upDateCancelStockInfos) > 0 {
- // var total int64
- // var out_count int64
- // var cancel_count int64
- // var now_count int64
- // var all_count int64
- // for _, item := range upDateCancelStockInfos {
- //
- // //查询最后一条退库记录
- // info, _ := service.GetLastCancelStockInfoOne(id, item.DrugId)
- //
- // errs = service.UpDateDrugCancelStockInfo(item)
- //
- // //查询该药品的信息
- // medical, _ := service.GetBaseDrugMedical(item.DrugId)
- // //统计该批次的总出库数
- // outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
- // //查询该批次的总退库数量
- // cancelInfo, _ := service.GetTotalDrugCancelInfo(item.BatchNumberId, item.DrugId, item.ID)
- // for _, item := range outInfo {
- // if item.CountUnit == medical.MaxUnit {
- // item.Count = item.Count * medical.MinNumber
- // }
- // if item.CountUnit == medical.MinUnit {
- // item.Count = item.Count
- // }
- // }
- //
- // for _, item := range outInfo {
- // out_count += item.Count
- // }
- //
- // for _, item := range cancelInfo {
- // if item.MaxUnit == medical.MaxUnit {
- // item.Count = item.Count * medical.MinNumber
- // }
- // if item.MaxUnit == medical.MinUnit {
- // item.Count = item.Count
- // }
- // }
- //
- // for _, item := range cancelInfo {
- // cancel_count += item.Count
- // }
- //
- // fmt.Println("out_count232233332232323223", out_count)
- //
- // if item.MaxUnit == medical.MaxUnit {
- // now_count = item.Count * medical.MinNumber
- // }
- // if item.MaxUnit == medical.MinUnit {
- // now_count = item.Count
- // }
- // fmt.Println("hhhhhh2323322323", now_count+cancel_count)
- // //总退库批次
- // all_count = now_count + cancel_count
- //
- // //该批次的总出库数小与退库数报错返回
- // if all_count > out_count {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "4",
- // })
- // return
- // }
- //
- // if item.MaxUnit == medical.MaxUnit {
- // //更新库存
- // total = item.Count - info.Count
- // parseDateErr := service.UpdatedDrugInfo(item.BatchNumberId, total)
- // fmt.Println("parseDateErr", parseDateErr)
- //
- // flow := models.DrugFlow{
- // Count: item.Count,
- // }
- // service.UpdatedDrugFlow(info.CancelStockId, item.DrugId, flow)
- // }
- //
- // if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- // item.Count = item.Count
- // total = item.Count - info.Count
- // service.UpdatedDrugInfoOne(item.BatchNumberId, total)
- //
- // flow := models.DrugFlow{
- // Count: item.Count,
- // }
- // service.UpdatedDrugFlow(info.CancelStockId, item.DrugId, flow)
- // }
- //
- // //查询默认仓库
- // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询默认仓库剩余多少库存
- // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- // }
- // }
- // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
- //
- // }
- //}
-
- //if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateCancelStockFail)
- // return
- //}
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
-
- }
-
- func (c *StockDrugApiController) GetAllConfig() {
- adminUserInfo := c.GetAdminUserInfo()
- manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
- dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
- stockIns, _ := service.FindStockInNumber(adminUserInfo.CurrentOrgId)
- drugs, _ := service.GetDrugs(adminUserInfo.CurrentOrgId)
- list, _ := service.GetAllStoreHouseListThree(adminUserInfo.CurrentOrgId)
- configlist, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- appId := c.GetAdminUserInfo().CurrentAppId
- doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
- c.ServeSuccessJSON(map[string]interface{}{
- "manufacturer": manufacturer,
- "dealer": dealer,
- "drugs": drugs,
- "numbers": stockIns,
- "list": list,
- "configlist": configlist,
- "doctorList": doctorList,
- })
- }
-
- func (c *StockDrugApiController) GetAllDrugStock() {
- adminUserInfo := c.GetAdminUserInfo()
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- drugs, err := service.FindAllDrugByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "drugs": drugs,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (c *StockDrugApiController) GetDrugQueryInfo() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- keyword := c.GetString("keyword")
- drug_category, _ := c.GetInt64("drug_category")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- adminUserInfo := c.GetAdminUserInfo()
- list, total, err := service.FindAllDrugStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, drug_category, startTime, endTime)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (this *StockDrugApiController) GetUserDetailInfo() {
- order_id, _ := this.GetInt64("id")
- if order_id <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := this.GetAdminUserInfo()
- userDetails, err, total := service.FindDrugStockUserDetailById(adminUserInfo.CurrentOrgId, order_id)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": userDetails,
- "total": total,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func (this *StockDrugApiController) GetCancelDrugOrderPrint() {
-
- orderId := this.GetString("order_id")
- ids := strings.Split(orderId, ",")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetCancelDrugOrderPrint(ids, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockDrugApiController) GetDrugCancelExportList() {
-
- orderId := this.GetString("order_id")
- ids := strings.Split(orderId, ",")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetDrugCancelExportList(ids, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (c *StockDrugApiController) GetDrugWarehouseInfoPrint() {
-
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
-
- order_type, _ := c.GetInt64("order_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- adminUserInfo := c.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- if order_type == 1 {
- list, err := service.GetDrugWarehouseInfoPrint(startTime, endTime, orgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
- }
- }
-
- func (c *StockDrugApiController) GetDrugOutOrderPrint() {
-
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- order_type, _ := c.GetInt64("order_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- adminUserInfo := c.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- if order_type == 2 {
- list, err := service.GetDrugOutOrderInfoPrintList(startTime, endTime, orgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
- }
-
- }
-
- func (c *StockDrugApiController) GetConfigList() {
- adminUserInfo := c.GetAdminUserInfo()
- manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
- dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
- stockIns, _ := service.FindStockInNumber(adminUserInfo.CurrentOrgId)
- list, _ := service.GetAllStoreHouseListThree(adminUserInfo.CurrentOrgId)
- configlist, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- appId := c.GetAdminUserInfo().CurrentAppId
- doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
- c.ServeSuccessJSON(map[string]interface{}{
- "manufacturer": manufacturer,
- "dealer": dealer,
- "numbers": stockIns,
- "list": list,
- "configlist": configlist,
- "doctorList": doctorList,
- })
- }
-
- func (c *StockDrugApiController) CheckWarehousingInfo() {
-
- warehousing_id, _ := c.GetInt64("warehousing_id")
- orgId := c.GetAdminUserInfo().CurrentOrgId
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- //更改核对状态
- err := service.CheckWarehousingInfo(warehousing_id, orgId)
-
- if err == nil {
- list, _ := service.GetWarehousingInfoByList(warehousing_id, orgId)
- for _, item := range list {
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- //新增库存
- service.AddDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID)
-
- }
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- //新增库存
- service.AddDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID)
-
- }
-
- if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
-
- //新增库存
- service.AddDrugWarehouseStockMinNumber(item.WarehousingCount, item.ID)
-
- }
-
- Creator := c.GetAdminUserInfo().AdminUser.Id
- flow := &models.DrugFlow{
- WarehousingId: 0,
- DrugId: item.DrugId,
- Number: item.Number,
- BatchNumber: item.BatchNumber,
- Count: item.WarehousingCount,
- UserOrgId: item.OrgId,
- PatientId: 0,
- SystemTime: time.Now().Unix(),
- ConsumableType: 1,
- IsSys: 0,
- WarehousingOrder: item.WarehousingOrder,
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: 0,
- Dealer: 0,
- Creator: Creator,
- UpdateCreator: Creator,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: item.Price,
- WarehousingDetailId: item.ID,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: item.ExpiryDate,
- ProductDate: item.ProductDate,
- MaxUnit: item.MaxUnit,
- MinUnit: item.MinUnit,
- StorehouseId: item.StorehouseId,
- }
- service.CreateDrugFlowTwo(flow)
-
- //查询默认仓库
-
- //查询默认仓库剩余多少库存
- list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- var sum_count int64
- var sum_in_count int64
- for _, it := range list {
- baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- if it.MaxUnit == baseDrug.MaxUnit {
- it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- }
- sum_count += it.StockMaxNumber + it.StockMinNumber
- sum_in_count += it.WarehousingCount
- }
- service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
- }
-
- func (c *StockDrugApiController) ReturnCheckWarehouseingInfo() {
-
- warehousing_id, _ := c.GetInt64("warehousing_id")
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- list, _ := service.GetWarehousingInfoByList(warehousing_id, orgId)
- for _, item := range list {
- //查询该药品是否有出库数据
- outInfo, _ := service.GetDrugWarehouseOutByWarehouseInfoId(item.ID, item.DrugId, item.OrgId)
- if len(outInfo) > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
- return
- }
-
- }
- for _, item := range list {
- //删除流水
- service.UpdateWarehousingInfoFlow(item.ID, orgId)
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- //新增库存
- service.AddDrugReturnWarehouseStockMaxNumber(item.WarehousingCount, item.ID)
- }
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- //新增库存
- service.AddDrugReturnWarehouseStockMaxNumber(item.WarehousingCount, item.ID)
- }
- if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- //新增库存
- service.AddDrugReturnWarehouseStockMinNumber(item.WarehousingCount, item.ID)
- }
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
-
- stockInfoList, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, orgId, item.DrugId)
- var sum_count int64
- var sum_in_count int64
- for _, its := range stockInfoList {
- if its.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- sum_count += its.StockMaxNumber * medical.MinNumber
- sum_in_count += its.WarehousingCount * medical.MinNumber
- }
- if its.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- sum_count += its.StockMaxNumber
- sum_in_count += its.WarehousingCount
- }
- if its.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- sum_count += its.StockMaxNumber
- sum_in_count += its.WarehousingCount
- }
- }
- service.UpdateBaseDrugSumInfo(sum_count, item.DrugId, item.OrgId, sum_in_count)
- }
- //更新审核
- err := service.ReturnCheckWarehouseingInfo(warehousing_id, orgId)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "反审核成功!",
- })
- return
- }
- }
-
- func (c *StockDrugApiController) CheckDrugOut() {
-
- warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
- orgId := c.GetAdminUserInfo().CurrentOrgId
- warehousingOutInfoList, _ := service.GetDrugWarehouseOutListById(warehouse_out_id, orgId)
- drugWarehouseOut, _ := service.GetDrugWarehouseOutByLastId(warehouse_out_id)
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
-
- for _, it := range warehousingOutInfoList {
- var total_count int64
- var out_count int64
- //查询剩余库存
- stockInfo, _ := service.GetDrugAllStockInfo(it.StorehouseId, it.OrgId, it.DrugId)
- drup, _ := service.FindBaseDrugLibRecord(it.OrgId, it.DrugId)
-
- for _, item := range stockInfo {
- if item.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
- item.StockMaxNumber = item.StockMaxNumber * drup.MinNumber
- }
-
- total_count += item.StockMaxNumber + item.StockMinNumber
- }
-
- if it.CountUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
- it.Count = it.Count * drup.MinNumber
- }
- out_count += it.Count
- fmt.Println("出库数量23232323232我", out_count)
- fmt.Println("总库存", total_count)
- if out_count > total_count {
- c.ServeSuccessJSON(map[string]interface{}{
- "warehousingOutInfoList": warehousingOutInfoList,
- "drug_name": drup.DrugName,
- "dose": drup.Dose,
- "dose_unit": drup.DoseUnit,
- "min_number": drup.MinNumber,
- "min_unit": drup.MinUnit,
- "max_unit": drup.MaxUnit,
- "msg": 2,
- })
- return
- }
- }
- for _, it := range warehousingOutInfoList {
-
- drup, _ := service.FindBaseDrugLibRecord(it.OrgId, it.DrugId)
- //出库逻辑
- service.AutoDrugDeliverInfoFourtyOne(orgId, it.Count, &drugWarehouseOut, &drup, it)
-
- medical, _ := service.GetBaseDrugMedical(it.DrugId)
- //查询剩余库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, it.OrgId, it.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- sum_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(it.DrugId, sum_count, it.OrgId)
- }
-
- out := models.DrugWarehouseOut{
- IsCheck: 1,
- }
-
- service.UpdateCheckDrugOut(out, warehouse_out_id)
- info := models.DrugWarehouseOutInfo{
- IsCheck: 1,
- }
- service.UpdateCheckDrugOutInfo(info, warehouse_out_id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "warehousingOutInfoList": warehousingOutInfoList,
- "drug_name": "",
- "dose": "",
- "dose_unit": "",
- "min_number": "",
- "min_unit": "",
- "max_unit": "",
- "msg": 1,
- })
- }
-
- func (c *StockDrugApiController) ToReturnCheck() {
-
- warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
-
- out := models.DrugWarehouseOut{
- IsCheck: 2,
- }
- service.UpdateCheckDrugOut(out, warehouse_out_id)
-
- outInfo := models.DrugWarehouseOutInfo{
- IsCheck: 2,
- }
- service.UpdateCheckDrugOutInfoList(outInfo, warehouse_out_id)
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetDrugWarehouseOutListById(warehouse_out_id, orgId)
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- //调用出库逻辑
- for _, item := range list {
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- service.UpdateDrugMaxNumber(item.Count, item.WarehouseInfoId)
- service.DeleteDrugOutFlow(item.ID, item.OrgId)
- }
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- service.UpdateDrugMaxNumber(item.Count, item.WarehouseInfoId)
- service.DeleteDrugOutFlow(item.ID, item.OrgId)
- }
- if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- service.UpdateDrugMinNumber(item.Count, item.WarehouseInfoId)
- service.DeleteDrugOutFlow(item.ID, item.OrgId)
- }
-
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- sum_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.OrgId)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "out": out,
- })
- }
-
- func (c *StockDrugApiController) CheckCancelDrugStock() {
-
- cancelstock_id, _ := c.GetInt64("cancelstock_id")
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- cancelDrugStock, _ := service.GetCancelDrugStock(cancelstock_id, orgId)
- list, _ := service.GetCancelDrugStockList(cancelstock_id, orgId)
- cancelStock := models.DrugCancelStock{
- IsCheck: 1,
- }
- var manufacturer_id int64
- var dealer_id int64
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- creater := c.GetAdminUserInfo().AdminUser.Id
-
- //查询退库单据
- cancelList, _ := service.GetDrugCancelCheckByIdTwenty(cancelstock_id, orgId)
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- var cancel_total_count int64
- var out_count int64
- for _, its := range cancelList {
- medical, _ := service.GetBaseDrugMedical(its.DrugId)
- //查询该批次的出库数据
- outList, _ := service.GetDrugWarehouseOutList(its.BatchNumberId, its.DrugId, its.OrgId)
- for _, item := range outList {
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- out_count += item.Count * medical.MinNumber
- }
- if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- out_count += item.Count
- }
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- out_count += item.Count
- }
- }
- if its.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- cancel_total_count += its.Count * medical.MinNumber
- }
- if its.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- cancel_total_count += its.Count
- }
- if its.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- cancel_total_count += its.Count
- }
- if cancel_total_count > out_count {
- c.ServeSuccessJSON(map[string]interface{}{
- "drug_name": medical.DrugName,
- "dose": medical.Dose,
- "dose_unit": medical.DoseUnit,
- "min_number": medical.MinNumber,
- "min_unit": medical.MinUnit,
- "max_unit": medical.MaxUnit,
- "msg": "2",
- })
- return
- }
- }
- for _, its := range list {
- for _, item := range manufacturerList {
- if its.Manufacturer == item.ManufacturerName {
- manufacturer_id = item.ID
- }
- }
- for _, item := range dealerList {
- if its.Dealer == item.DealerName {
- dealer_id = item.ID
- }
- }
-
- //查询该批次的退库数量
- drugFlow := models.DrugFlow{
- ID: 0,
- WarehousingId: 0,
- DrugId: its.DrugId,
- Number: its.Number,
- BatchNumber: "",
- Count: its.Count,
- UserOrgId: its.OrgId,
- PatientId: 0,
- SystemTime: cancelDrugStock.ReturnTime,
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: its.OrderNumber,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- Creator: creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: its.Price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: its.ID,
- ExpireDate: its.ExpiryDate,
- ProductDate: its.ProductDate,
- MaxUnit: its.MaxUnit,
- MinUnit: "",
- StockMaxNumber: 0,
- StockMinNumber: 0,
- LastStockMaxNumber: 0,
- LastStockMinNumber: 0,
- AdviceId: 0,
- SupplyWarehouseId: 0,
- SupplyCancelOutId: 0,
- SupplyWarehouseDetailInfo: 0,
- StorehouseId: its.StorehouseId,
- SecondWarehouseInfoId: 0,
- AdminUserId: 0,
- LastPrice: 0,
- StockCount: "",
- PharmacyId: 0,
- }
- service.CreateDrugFlowOne(drugFlow)
- }
- for _, its := range cancelList {
- medical, _ := service.GetBaseDrugMedical(its.DrugId)
- //扣减库存
- if its.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
-
- service.ModifyDrugWarehouseInfoStockMaxNumber(its.Count, its.DrugId, its.OrgId, its.BatchNumberId)
- }
- if its.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
-
- service.ModifyDrugWarehouseInfoStockMinNumber(its.Count, its.DrugId, its.OrgId, its.BatchNumberId)
- }
- if its.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
-
- service.ModifyDrugWarehouseInfoStockMaxNumber(its.Count, its.DrugId, its.OrgId, its.BatchNumberId)
- }
-
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, its.OrgId, its.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- sum_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(its.DrugId, sum_count, its.OrgId)
- }
- service.ModifyCancelStock(cancelstock_id, cancelStock, orgId)
-
- //新增库存
- c.ServeSuccessJSON(map[string]interface{}{
- "drug_name": "",
- "dose": "",
- "dose_unit": "",
- "min_number": "",
- "min_unit": "",
- "max_unit": "",
- "msg": "1",
- })
- return
- }
-
- func (c *StockDrugApiController) ReturnDrugCancelStock() {
-
- cancelstock_id, _ := c.GetInt64("cancelstock_id")
- orgId := c.GetAdminUserInfo().CurrentOrgId
- drugStock := models.DrugCancelStock{
- IsCheck: 2,
- }
- err := service.ReturnDrugCancelStock(cancelstock_id, drugStock)
- list, err := service.GetDrugCancelStockInfo(cancelstock_id, orgId)
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- for _, item := range list {
- //删除流水
- service.ModifyDrugFlowByCancelId(item.ID, item.DrugId, item.OrgId)
-
- //扣减库存
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
-
- service.ModifyDrugMaxNumberWarehouseInfo(item.BatchNumberId, item.Count, item.OrgId)
- }
- if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
-
- service.ModifyDrugMinNumberWarehouseInfo(item.BatchNumberId, item.Count, item.OrgId)
- }
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- service.ModifyDrugMaxNumberWarehouseInfo(item.BatchNumberId, item.Count, item.OrgId)
- }
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- sum_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.OrgId)
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "反审核成功!",
- })
- return
- }
- }
|