1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084 |
- package controllers
-
- import (
- "encoding/json"
- "fmt"
- "reflect"
- "strconv"
- "strings"
- "time"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- )
-
- 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()
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- 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.FindNewAllWarehouseTotalOne(adminUserInfo.CurrentOrgId, tx)
- 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.AddNewSigleDrugWarehouse(&warehousing, tx)
- }
- if warehousing_id > 0 {
- service.UpdateNewSigleDrugWarehouse(warehousing_id, storehouse_id, tx)
- }
- info, _ := service.FindNewLastWarehousingSeven(adminUserInfo.CurrentOrgId, tx)
- 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)
-
- drug_code := items["drug_code"].(string)
-
- warehouseInfo := &models.DrugWarehouseInfo{
- ID: id,
- WarehousingOrder: info.WarehousingOrder,
- WarehousingId: info.ID,
- DrugId: drug_id,
- Number: number,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: last_price,
- TotalPrice: total,
- Status: 1,
- Ctime: warehousingDate.Unix(),
- 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,
- DrugCode: drug_code,
- }
- warehousingInfo = append(warehousingInfo, warehouseInfo)
- }
- }
- }
-
- for _, item := range warehousingInfo {
- if item.ID == 0 {
- service.CreatedNewWarehouseing(item, tx)
- }
- if item.ID > 0 {
- service.UpdateNewWarehouseing(item, tx)
- }
- }
-
- list, _ := service.FindNewDrugWarehouseInfoListById(info.ID, adminUserInfo.CurrentOrgId, tx)
-
- tx.Commit()
- 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
- }
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- 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.FindNewDrugWarehousingById(id, adminUserInfo.CurrentOrgId, tx)
-
- 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.EditNewDrugWarehousingOne(warehousing, id, tx)
-
- 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
- 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))
-
- drug_code, _ := items["drug_code"].(string)
- 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,
- DrugCode: drug_code,
- }
-
- 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,
- DrugCode: drug_code,
- }
- 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)
-
- }
- }
- }
- }
- var errs error
- if len(warehousingInfo) > 0 {
- errs = service.CreateNewDrugWarehousingInfo(warehousingInfo, tx)
- }
-
- if len(upDateWarehousingInfo) > 0 {
- for _, item := range upDateWarehousingInfo {
- if item.ID > 0 {
- service.UpdateNewDrugWarehouseInfoTwenty(item.ID, item, tx)
- }
-
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- list, _ := service.GetNewDrugWarehouseInfoList(id, adminUserInfo.CurrentOrgId, tx)
- tx.Commit()
- 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, "-")
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.CurrentOrgId, tx)
-
- 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,
- }
-
- if warehouse_out_id == 0 {
- //查询是否生成出库单
- outIsExit, _ := service.GetNewDrugWarehouseOutIsExit(adminUserInfo.CurrentOrgId, 0, operation_time, warehousing_out_order, tx)
- if outIsExit.ID == 0 {
- service.AddNewSigleDrugWarehouseOut(&warehouseOut, tx)
- }
-
- }
- if warehouse_out_id > 0 {
- service.UpdateNewSingleDrugWarehouseOut(warehouse_out_id, storehouse_id, tx)
- }
- lastWarehouseOut, _ := service.GetNewDrugLastWarehouseOut(adminUserInfo.CurrentOrgId, tx)
- 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)
-
- patient_id := int64(items["patient_id"].(float64))
-
- id := int64(items["id"].(float64))
-
- class_type, _ := items["class_type"].(string)
-
- warehouseOutInfo := &models.DrugWarehouseOutInfo{
- ID: id,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: lastWarehouseOut.ID,
- DrugId: drug_id,
- Count: count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: warehousingOutDate.Unix(),
- Mtime: 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,
- SysRecordTime: warehousingOutDate.Unix(),
- PatientId: patient_id,
- ClassType: class_type,
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- }
- }
- }
-
- //var total_count int64 //总库存
- //var prescribing_number_total int64 //出库数据
-
- //调用出库逻辑
- for _, item := range warehousingOutInfo {
- if item.ID == 0 {
- //查询改耗材是否出库
- outInfo, _ := service.GetNewDrugsIsExsit(item.DrugId, item.SysRecordTime, item.OrgId, lastWarehouseOut.ID, tx)
- if outInfo.ID == 0 {
- errOne := service.AddNewSigleDrugWarehouseOutInfo(item, tx)
- fmt.Println(errOne)
- }
-
- }
- if item.ID > 0 {
- service.UpdatedNewDrugWarehouseInfo(item, item.ID, tx)
- }
-
- }
-
- list, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
-
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
-
- warehousingOutInfoList, _ := service.GetNewDrugWarehouseOutListById(lastWarehouseOut.ID, adminUserInfo.CurrentOrgId, tx)
-
- tx.Commit()
- 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)
-
- houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
-
- patients, _ := service.GetAllpatient(adminUserInfo.CurrentOrgId)
- fmt.Println(err)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutList,
- "total": total,
- "houseList": houseList,
- "patients": patients,
- })
- } 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)
- patients, _ := service.GetAllpatientTwenty(adminInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutInfo,
- "info": warehouseOut,
- "manulist": manulist,
- "dealerList": dealerList,
- "houstList": houstList,
- "doctorList": doctorList,
- "patients": patients,
- })
-
- }
- 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
- }
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- warehouseOut, _ := service.FindNewDrugWareHouseOutById(id, adminUserInfo.CurrentOrgId, tx)
-
- tempWarehouseOut := models.DrugWarehouseOut{
- ID: warehouseOut.ID,
- Mtime: mtime,
- WarehouseOutTime: warehouseOutDate.Unix(),
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- StorehouseId: storehouse_id,
- }
-
- service.EditNewDrugWarehouseOut(tempWarehouseOut, tx)
-
- 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))
-
- patient_id := int64(items["patient_id"].(float64))
-
- stock_count, _ := items["stock_count"].(string)
-
- class_type, _ := items["class_type"].(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: warehouseOut.WarehouseOutTime,
- Mtime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- IsSys: 0,
- SysRecordTime: warehouseOut.WarehouseOutTime,
- 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,
- PatientId: patient_id,
- ClassType: class_type,
- }
- 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: warehouseOut.WarehouseOutTime,
- Mtime: 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,
- PatientId: patient_id,
- }
-
- 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: warehouseOut.WarehouseOutTime,
- 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,
- PatientId: patient_id,
- ClassType: class_type,
- }
- 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: warehouseOut.WarehouseOutTime,
- Mtime: time.Now().Unix(),
- 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,
- PatientId: patient_id,
- }
-
- drugFlow = append(drugFlow, drugflow)
- }
- }
- }
- }
- var errs error
- if len(warehousingOutInfo) > 0 {
-
- //调用出库逻辑
- for _, item := range warehousingOutInfo {
-
- errOnes := service.AddNewSigleDrugWarehouseOutInfo(item, tx)
- fmt.Println("errone", errOnes)
-
- }
- }
-
- if len(upDateWarehouseOutInfos) > 0 {
- for _, item := range upDateWarehouseOutInfos {
- if item.ID > 0 {
- service.UpdatedNewDrugWarehouseInfo(item, item.ID, tx)
- }
-
- }
- }
-
- tx.Commit()
-
- 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)
- patients, _ := service.GetAllpatientTwenty(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "manufacturer": manufacturer,
- "dealer": dealer,
- "drugs": drugs,
- "numbers": stockIns,
- "list": list,
- "configlist": configlist,
- "doctorList": doctorList,
- "patients": patients,
- })
- }
-
- 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")
-
- storehouse_id, _ := c.GetInt64("storehouse_id")
- 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, storehouse_id)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
- return
- }
- }
- }
-
- func (c *StockDrugApiController) GetDrugOutOrderPrint() {
-
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- order_type, _ := c.GetInt64("order_type")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- 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
- dealerList, _ := service.GetAllDealerList(orgId)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- if order_type == 2 {
- list, err := service.GetDrugOutOrderInfoPrintList(startTime, endTime, orgId, storehouse_id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "dealerList": dealerList,
- "manufacturerList": manufacturerList,
- })
- 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)
-
- checker := c.GetAdminUserInfo().AdminUser.Id
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- //更改核对状态
- service.CheckNewWarehousingInfo(warehousing_id, orgId, checker, tx)
-
- list, _ := service.GetNewWarehousingInfoByList(warehousing_id, orgId, tx)
- for _, item := range list {
- medical, _ := service.GetNewBaseDrugMedical(item.DrugId, tx)
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- //新增库存
- service.AddNewDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID, tx)
-
- }
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- //新增库存
- service.AddNewDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID, tx)
-
- }
-
- if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
-
- //新增库存
- service.AddNewDrugWarehouseStockMinNumber(item.WarehousingCount, item.ID, tx)
-
- }
-
- Creator := c.GetAdminUserInfo().AdminUser.Id
-
- //查询默认仓库
-
- //查询默认仓库剩余多少库存
- list, _ := service.GetNewDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId, tx)
- var sum_count int64
- var sum_in_count int64
- for _, it := range list {
- baseDrug, _ := service.GetNewBaseDrugMedical(it.DrugId, tx)
- 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
- }
- 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: item.Ctime,
- 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,
- OverCount: sum_count,
- OperateTime: time.Now().Unix(),
- DrugCode: item.DrugCode,
- }
- service.CreateNewDrugFlowTwo(flow, tx)
- //更新基础库剩余库存
- service.UpdateNewMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId, tx)
-
- drugInfolist, _ := service.GetNewDrugSumCountByStorehouseId(item.StorehouseId, item.OrgId, item.DrugId, tx)
- var total_count int64 // 入库总数量
- var over_count int64 //剩余库存
- for _, it := range drugInfolist {
- baseDrug, _ := service.GetNewBaseDrugMedical(it.DrugId, tx)
- if it.MaxUnit == baseDrug.MaxUnit {
- it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- }
- }
- for _, it := range drugInfolist {
- total_count += it.WarehousingCount
- over_count += it.StockMaxNumber + it.StockMinNumber
- }
- //查询该仓库是否有默认数据
- _, errcode := service.GetNewDrugStockCount(item.StorehouseId, item.DrugId, item.OrgId, tx)
- if errcode == gorm.ErrRecordNotFound {
- drugStock := models.XtDrugStockCount{
- UserOrgId: item.OrgId,
- StorehouseId: item.StorehouseId,
- SumInCount: total_count,
- SumOutCount: 0,
- SumCancelCount: 0,
- DrugId: item.DrugId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- FlushCount: over_count,
- SumActOutCount: 0,
- }
- service.CreateNewDrugStockSum(drugStock, tx)
-
- } else if errcode == nil {
- service.UpdateNewDrugStockSum(item.StorehouseId, item.DrugId, item.OrgId, total_count, over_count, tx)
- }
- }
-
- tx.Commit()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
-
- }
-
- func (c *StockDrugApiController) ReturnCheckWarehouseingInfo() {
-
- warehousing_id, _ := c.GetInt64("warehousing_id")
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- list, _ := service.GetNewWarehousingInfoByList(warehousing_id, orgId, tx)
- for _, item := range list {
- //查询该药品是否有出库数据
- outInfo, _ := service.GetNewDrugWarehouseOutByWarehouseInfoId(item.ID, item.DrugId, item.OrgId, tx)
- if len(outInfo) > 0 {
- tx.Rollback()
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
- return
- }
-
- }
- for _, item := range list {
- //删除流水
- service.UpdateNewWarehousingInfoFlow(item.ID, orgId, tx)
- medical, _ := service.GetNewBaseDrugMedical(item.DrugId, tx)
-
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- //新增库存
- service.AddNewDrugReturnWarehouseStockMaxNumber(item.WarehousingCount, item.ID, tx)
- }
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- //新增库存
- service.AddNewDrugReturnWarehouseStockMaxNumber(item.WarehousingCount, item.ID, tx)
- }
- if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- //新增库存
- service.AddNewDrugReturnWarehouseStockMinNumber(item.WarehousingCount, item.ID, tx)
- }
-
- storeHouseConfig, _ := service.GetNewAllStoreHouseConfig(orgId, tx)
-
- stockInfoList, _ := service.GetNewDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, orgId, item.DrugId, tx)
- 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.UpdateNewBaseDrugSumInfo(sum_count, item.DrugId, item.OrgId, sum_in_count, tx)
-
- var total_count int64
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- total_count = item.WarehousingCount * medical.MinNumber
- }
- if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- total_count = item.WarehousingCount
- }
- if item.MaxUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
- total_count = item.WarehousingCount * medical.MinNumber
- }
- drugInfolist, _ := service.GetNewDrugSumCountByStorehouseId(item.StorehouseId, item.OrgId, item.DrugId, tx)
- var over_count int64 //剩余库存
- for _, it := range drugInfolist {
- if it.MaxUnit == medical.MaxUnit {
- it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
- }
- }
- for _, it := range drugInfolist {
- over_count += it.StockMaxNumber*medical.MinNumber + it.StockMinNumber
- }
- //扣减库存
- service.ReduceNewDrugStockCount(item.StorehouseId, item.DrugId, item.OrgId, total_count, over_count, tx)
-
- }
- //更新审核
- err := service.ReturnNewCheckWarehouseingInfo(warehousing_id, orgId, tx)
-
- tx.Commit()
- 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
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- warehousingOutInfoList, _ := service.GetNewDrugWarehouseOutListById(warehouse_out_id, orgId, tx)
- drugWarehouseOut, _ := service.GetNewDrugWarehouseOutByLastId(warehouse_out_id, tx)
-
- for _, it := range warehousingOutInfoList {
- var total_count int64
- var out_count int64
- //查询剩余库存
- stockInfo, _ := service.GetNewDrugAllStockInfo(it.StorehouseId, it.OrgId, it.DrugId, tx)
- drup, _ := service.FindNewBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
-
- 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 {
- out_count = it.Count * drup.MinNumber
- }
-
- if it.CountUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
- out_count = it.Count
- }
-
- if it.CountUnit == drup.MinUnit && drup.MaxUnit == drup.MinUnit {
- out_count = it.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
- }
- }
- warehousingOutInfoListTwo, _ := service.GetNewDrugWarehouseOutListById(warehouse_out_id, orgId, tx)
-
- for _, it := range warehousingOutInfoListTwo {
- medical, _ := service.GetBaseDrugMedical(it.DrugId)
- ////出库数量累加
- var out_count_one int64
-
- if it.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- out_count_one = it.Count * medical.MinNumber
- }
-
- if it.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- out_count_one = it.Count
- }
-
- if it.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- out_count_one = it.Count
- }
-
- service.AddNewDrugCount(it.DrugId, it.OrgId, it.StorehouseId, out_count_one, tx)
-
- }
- warehousingOutInfoListThree, _ := service.GetNewDrugWarehouseOutListById(warehouse_out_id, orgId, tx)
- for _, it := range warehousingOutInfoListThree {
- medical, _ := service.GetNewBaseDrugMedical(it.DrugId, tx)
- drup, _ := service.FindNewBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
- //出库逻辑
- service.AutoNewDrugDeliverInfoFourtyOne(orgId, it.Count, &drugWarehouseOut, &drup, it, it.CountUnit, tx)
-
- //查询剩余库存
- stockInfo, _ := service.GetNewDrugAllStockInfo(it.StorehouseId, it.OrgId, it.DrugId, tx)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateNewDrugStockCount(it.DrugId, it.OrgId, it.StorehouseId, sum_count, tx)
-
- storeHouseConfig, _ := service.GetNewAllStoreHouseConfig(orgId, tx)
- stockInfoOne, _ := service.GetNewDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, it.OrgId, it.DrugId, tx)
- var sum_count_one int64
- for _, its := range stockInfoOne {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count_one += its.StockMaxNumber + its.StockMinNumber
- }
- //更新基础库库存
- service.UpdateNewBaseDrugSumTwo(it.DrugId, sum_count_one, it.OrgId, tx)
- }
-
- out := models.DrugWarehouseOut{
- IsCheck: 1,
- }
- //更新审核状态
- service.UpdateNewCheckDrugOut(out, warehouse_out_id, tx)
-
- tx.Commit()
-
- 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,
- }
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- service.UpdateNewCheckDrugOutInfoList(outInfo, warehouse_out_id, tx)
- creater := c.GetAdminUserInfo().AdminUser.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.UpdateNewDrugMaxNumber(item.Count, item.WarehouseInfoId, tx)
- var sum_out_count int64
- sum_out_count = item.Count * medical.MinNumber
- service.ModifyNewReduceDrugInformation(item.DrugId, sum_out_count, item.OrgId, tx)
- drugInfoList, _ := service.FindNewDrugWarehouseInfoList(item.DrugId, item.OrgId, tx)
- var drug_max_number int64
- var drug_min_number int64
- for _, item := range drugInfoList {
- drug_max_number += item.StockMaxNumber
- drug_min_number += item.StockMinNumber
- }
- drugFlushInfo := models.XtDrugWarehouseFlushInfo{
- DrugMaxNumber: drug_max_number,
- UserOrgId: item.OrgId,
- WarehouseOutId: item.ID,
- Type: 2,
- SystemTime: item.SysRecordTime,
- PatientId: 0,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- BatchNumberId: item.WarehouseInfoId,
- DrugId: item.DrugId,
- Count: item.Count,
- WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
- Creater: creater,
- DrugMinNumber: drug_min_number,
- Unit: item.CountUnit,
- Status: 1,
- }
- service.CreatedNewDrugFlushInfo(drugFlushInfo, tx)
- service.DeleteNewDrugOutFlow(item.ID, item.OrgId, tx)
- }
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- service.UpdateDrugMaxNumber(item.Count, item.WarehouseInfoId)
- var sum_out_count int64
- sum_out_count = item.Count * medical.MinNumber
- service.ModifyReduceDrugInformation(item.DrugId, sum_out_count, item.OrgId)
-
- service.DeleteDrugOutFlow(item.ID, item.OrgId)
- }
-
- if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- service.UpdateNewDrugMinNumber(item.Count, item.WarehouseInfoId, tx)
- var sum_out_count int64
- sum_out_count = item.Count
- service.ModifyNewReduceDrugInformation(item.DrugId, sum_out_count, item.OrgId, tx)
-
- service.DeleteNewDrugOutFlow(item.ID, item.OrgId, tx)
- }
-
- stockInfo, _ := service.GetNewDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.OrgId, item.DrugId, tx)
- var sum_count int64
- for _, its := range stockInfo {
- baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
- if its.MaxUnit == baseDrug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.OrgId, tx)
-
- //出库数量累加
- var out_count int64
- 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.MinUnit && medical.MaxUnit == medical.MinUnit {
- out_count = item.Count
- }
- //增加出库数量
- service.ReduceNewDrugCount(item.DrugId, item.OrgId, item.StorehouseId, out_count, tx)
-
- //查询该药品剩余库存
- infolist, _ := service.FindNewDrugWarehouseInfoFlushCountByStorehouse(item.DrugId, item.OrgId, item.StorehouseId, tx)
- var over_count int64
- for _, its := range infolist {
- baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
-
- if its.MaxUnit == baseDrug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
- }
-
- over_count += its.StockMaxNumber + its.StockMinNumber
- }
-
- service.UpdateNewDrugStockCount(item.DrugId, item.OrgId, item.StorehouseId, over_count, tx)
-
- }
- tx.Commit()
- 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
- }
- }
-
- medical, _ := service.GetBaseDrugMedical(its.DrugId)
- if its.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- var sum_cancel_count int64
- sum_cancel_count += its.Count * medical.MinNumber
- //出库数量减少
- service.ModifyAddDrugOutReduceInfomation(its.DrugId, sum_cancel_count, its.OrgId, its.StorehouseId)
- }
-
- if its.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- //出库数量减少
- service.ModifyAddDrugOutReduceInfomation(its.DrugId, its.Count, its.OrgId, its.StorehouseId)
- }
-
- if its.MaxUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
- //出库数量减少
- service.ModifyAddDrugOutReduceInfomation(its.DrugId, its.Count, its.OrgId, its.StorehouseId)
- }
-
- }
- 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 {
- baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
- if its.MaxUnit == baseDrug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- //更新剩余库存
- service.UpdateBaseDrugSumTwo(its.DrugId, sum_count, its.OrgId)
-
- var cancel_count int64
- if its.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- cancel_count = its.Count * medical.MinNumber
- }
- if its.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- cancel_count = its.Count
- }
-
- if its.MaxUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
- cancel_count = its.Count * medical.MinNumber
- }
- cancelInfo, _ := service.GetDrugAllStockInfo(its.StorehouseId, its.OrgId, its.DrugId)
- var over_count int64
- for _, its := range cancelInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- over_count += its.StockMaxNumber + its.StockMinNumber
- }
- //查询该批次的退库数量
- drugFlow := models.DrugFlow{
- ID: 0,
- WarehousingId: its.BatchNumberId,
- 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: its.BatchNumberId,
- 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,
- OverCount: over_count,
- }
- service.CreateDrugFlowOne(drugFlow)
- //增加退库数量 更新剩余库存
- service.AddCancelSumCount(its.StorehouseId, its.DrugId, its.OrgId, cancel_count, over_count)
- //更改审核状态
- 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 {
- var sum_cancel_count int64
- sum_cancel_count += item.Count * medical.MinNumber
- service.ModifyDrugMaxNumberWarehouseInfo(item.BatchNumberId, item.Count, item.OrgId)
- //退库数量减少
- //service.ModifyDrugCancelWarehouseInfo(item.DrugId,sum_cancel_count,item.OrgId,item.StorehouseId)
- //出库数量增加
- service.ModifyAddDrugOutAddInfomation(item.DrugId, sum_cancel_count, item.OrgId, item.StorehouseId)
-
- }
- if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
-
- service.ModifyDrugMinNumberWarehouseInfo(item.BatchNumberId, item.Count, item.OrgId)
- //退库数量减少
- //service.ModifyDrugCancelWarehouseInfo(item.DrugId,item.Count,item.OrgId,item.StorehouseId)
- //出库数量增加
- service.ModifyAddDrugOutAddInfomation(item.DrugId, item.Count, item.OrgId, item.StorehouseId)
- }
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- service.ModifyDrugMaxNumberWarehouseInfo(item.BatchNumberId, item.Count, item.OrgId)
- //退库数量减少
- //service.ModifyDrugCancelWarehouseInfo(item.DrugId,item.Count,item.OrgId,item.StorehouseId)
- //出库数量增加
- service.ModifyAddDrugOutAddInfomation(item.DrugId, item.Count, item.OrgId, item.StorehouseId)
- }
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
-
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.OrgId)
-
- var cancel_count int64
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- cancel_count = item.Count * medical.MinNumber
- }
- if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- cancel_count = item.Count
- }
-
- if item.MaxUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
- cancel_count = item.Count * medical.MinNumber
- }
- cancelInfo, _ := service.GetDrugAllStockInfo(item.StorehouseId, item.OrgId, item.DrugId)
- var over_count int64
- for _, its := range cancelInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- over_count += its.StockMaxNumber + its.StockMinNumber
- }
-
- //退库数量减少,更新剩余库存
- service.ReduceCancelSumCount(item.StorehouseId, item.DrugId, item.OrgId, cancel_count, over_count)
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "反审核成功!",
- })
- return
- }
- }
|