12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346 |
- 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()
-
- warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
- total = total + 1
-
- warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- warehousing := models.DrugWarehouse{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehousingTime: warehousingDate.Unix(),
- Type: types,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- if warehousing_id == 0 {
- service.AddSigleDrugWarehouse(&warehousing)
- }
- if warehousing_id > 0 {
- service.UpdateSigleDrugWarehouse(warehousing_id, storehouse_id)
- }
- info, _ := service.FindLastWarehousingSeven(adminUserInfo.CurrentOrgId)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingInfo []*models.DrugWarehouseInfo
-
- if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockIn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
- utils.ErrorLog("warehousing_count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
-
- if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- utils.ErrorLog("last_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
- total := float64(warehousing_count) * last_price
-
- retail_price_total := float64(warehousing_count) * last_price
-
- var productDates int64
- var expiryDates int64
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- number, _ := items["number"].(string)
-
- batch_number, _ := items["batch_number"].(string)
-
- if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
- utils.ErrorLog("max_unit")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- max_unit, _ := items["max_unit"].(string)
-
- if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
- utils.ErrorLog("min_unit")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- min_unit, _ := items["min_unit"].(string)
-
- var remark string
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- remark = ""
- } else {
- remark = items["remark"].(string)
- }
-
- manufacturer := int64(items["manufacturer"].(float64))
-
- dealer := int64(items["dealer"].(float64))
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
-
- 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.CreatedWarehouseing(item)
- }
- if item.ID > 0 {
- service.UpdateWarehouseing(item)
- }
- }
-
- list, _ := service.FindDrugWarehouseInfoListById(info.ID, adminUserInfo.CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "入库成功",
- "warehousing_order": warehousing_order,
- "info": info,
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "drugTypeList": drugTypeList,
- })
-
- }
- func (c *StockDrugApiController) GetDrugWarehouseList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- check_type, _ := c.GetInt64("check_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- //按药品名称搜索
- var ids []int64
- var idArray []int64
- list, _ := service.GetDrugNameByKeyword(keywords, adminUserInfo.CurrentOrgId)
- for _, item := range list {
- ids = append(ids, item.ID)
- }
-
- //查找入库单详情
- if len(ids) > 0 {
- info, _ := service.GetDrugWarehouseOrderDetailTwo(ids, adminUserInfo.CurrentOrgId, startTime, endTime, storehouse_id)
- for _, it := range info {
- idArray = append(idArray, it.WarehousingId)
- }
- }
-
- warehouseList, total, err := service.FindAllDrugWarehousingListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, idArray, storehouse_id, check_type)
- houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseList,
- "total": total,
- "houseList": houseList,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
- id, _ := c.GetInt64("id", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- admin := c.GetAdminUserInfo()
-
- warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
-
- manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- if warehousing.ID <= 0 {
- return
- }
-
- warehousingInfo, err := service.FindDrugWarehousingInfoByIdThree(id, admin.CurrentOrgId)
- list, _ := service.GetAllStoreHouseListThree(admin.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "info": warehousingInfo,
- "warehousing": warehousing,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "list": list,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (c *StockDrugApiController) EditDrugWarehouse() {
-
- warehousing_time := c.GetString("warehousing_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehouse, _ := service.FindDrugWarehousingById(id, adminUserInfo.CurrentOrgId)
-
- warehousing := models.DrugWarehouse{
- WarehousingOrder: warehouse.WarehousingOrder,
- OrgId: adminUserInfo.CurrentOrgId,
- Modifier: adminUserInfo.AdminUser.Id,
- Mtime: mtime,
- Status: 1,
- WarehousingTime: warehousingDate.Unix(),
- Type: warehouse.Type,
- StorehouseId: storehouse_id,
- }
-
- service.EditDrugWarehousingOne(warehousing, id)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingInfo []*models.DrugWarehouseInfo
- var upDateWarehousingInfo []*models.DrugWarehouseInfo
- var drugFlow []*models.DrugFlow
- if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockIn"].([]interface{})
-
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
- utils.ErrorLog("warehousing_count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(warehousing_count) * price
-
- if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- utils.ErrorLog("last_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
-
- retail_price_total := float64(warehousing_count) * last_price
-
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
-
- var productDates int64
- var expiryDates int64
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
- }
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- number, _ := items["number"].(string)
-
- batch_number, _ := items["batch_number"].(string)
-
- max_unit, _ := items["max_unit"].(string)
-
- min_unit, _ := items["min_unit"].(string)
-
- var remark string
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- remark = ""
- } else {
- remark = items["remark"].(string)
- }
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- manufacturer := int64(items["manufacturer"].(float64))
-
- dealer := int64(items["dealer"].(float64))
-
- 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)
-
- drugflow := &models.DrugFlow{
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: warehouse.ID,
- DrugId: drug_id,
- Number: number,
- ProductDate: productDates,
- ExpireDate: expiryDates,
- Count: warehousing_count,
- Price: last_price,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: manufacturer,
- Dealer: dealer,
- BatchNumber: batch_number,
- MaxUnit: max_unit,
- MinUnit: min_unit,
- ConsumableType: 1,
- IsEdit: 1,
- Creator: adminUserInfo.AdminUser.Id,
- IsSys: 0,
- WarehousingDetailId: id,
- StorehouseId: storehouse_id,
- DrugCode: drug_code,
- }
-
- if max_unit == min_unit {
- drugflow.MaxUnit = min_unit
- }
-
- drugFlow = append(drugFlow, drugflow)
- }
- }
- }
- }
- var errs error
- if len(warehousingInfo) > 0 {
- errs = service.CreateDrugWarehousingInfo(warehousingInfo)
- }
-
- if len(upDateWarehousingInfo) > 0 {
- for _, item := range upDateWarehousingInfo {
- service.UpdateDrugWarehouseInfoTwenty(item.ID, item)
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- list, _ := service.GetDrugWarehouseInfoList(id, adminUserInfo.CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "编辑成功",
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "drugTypeList": drugTypeList,
- })
-
- }
- func (c *StockDrugApiController) DeleteDrugWarehouse() {
- ids := c.GetString("ids")
-
- if len(ids) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- orgId := c.GetAdminUserInfo().CurrentOrgId
- err := service.DeleteDrugWarehouse(idArray)
- list, _ := service.GetLastDrugwarehouseInfoByIdTwenty(idArray, orgId)
-
- for _, it := range list {
- //查询默认仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(it.OrgId)
- //查询默认仓库剩余多少库存
- list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, it.OrgId, it.DrugId)
- var sum_count int64
- var sum_in_count int64
- for _, it := range list {
- baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- if it.MaxUnit == baseDrug.MaxUnit {
- it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- }
- sum_count += it.StockMaxNumber + it.StockMinNumber
- sum_in_count += it.WarehousingCount
- }
- service.UpdateMedicalSumCount(it.DrugId, sum_count, sum_in_count, it.OrgId)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (c *StockDrugApiController) DeleteDrugWarehouseInfo() {
- id, _ := c.GetInt64("id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- err := service.UpDateDrugWarehouseStatus(id)
- service.UpdateDrugFlowById(id)
- var sum_total int64
- list, _ := service.GetDrugWarehouseInfoByIdTwenty(id)
- medical, _ := service.GetBaseDrugMedical(list.DrugId)
- sum_total += list.StockMaxNumber*medical.MinNumber + list.StockMinNumber
- storeConfig, _ := service.GetAllStoreHouseConfig(list.OrgId)
- if storeConfig.DrugStorehouseInfo == list.StorehouseId {
- service.ModifyDrugReduceInformationTwo(list.DrugId, sum_total, list.OrgId)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
-
- func (c *StockDrugApiController) CreateDrugSalesReturn() {
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- sales_return_time := c.GetString("time")
- types, _ := c.GetInt64("type", 0)
-
- salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- ctime := time.Now().Unix()
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "YPTHD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- salesReturn := models.DrugSalesReturn{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: salesReturnDate.Unix(),
- Dealer: dealer_id,
- Manufacturer: manufacturer_id,
- Type: types,
- }
-
- service.AddSigleDrugSalesReturn(&salesReturn)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var salesReturnInfos []*models.DrugSalesReturnInfo
-
- if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["salesReturn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- return_count, _ := items["return_count"].(string)
- if len(return_count) == 0 {
- utils.ErrorLog("len(return_count) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
-
- return
- }
- count, _ := strconv.ParseInt(return_count, 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(count) * price
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
- retail_price_total := float64(count) * retail_price
-
- salesReturnInfo := &models.DrugSalesReturnInfo{
- OrderNumber: salesReturn.OrderNumber,
- SalesReturnId: salesReturn.ID,
- DrugId: drug_id,
- Count: count,
- Price: price,
- Total: total,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- }
-
- salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
-
- }
- }
- }
- errs := service.CreateDrugSalesReturnInfo(salesReturnInfos)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "退货成功",
- })
-
- }
- func (c *StockDrugApiController) GetDrugSalesReturnList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- returnList, total, err := service.FindAllDrugReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": returnList,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- func (this *StockDrugApiController) DeleteDrugSalesReturn() {
- ids := this.GetString("ids")
-
- if len(ids) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- err := service.DeleteDrugSalesReturn(idArray)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockDrugApiController) DeleteDrugSalesReturnInfo() {
- id, _ := this.GetInt64("id", 0)
- fmt.Println(id)
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- err := service.UpDateDrugSaleReturnStatus(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (this *StockDrugApiController) GetDrugSalesReturnInfoList() {
- id, _ := this.GetInt64("id", 0)
- adminUserInfo := this.GetAdminUserInfo()
-
- list, _ := service.FindAllDrugSalesReturnInfoById(id, adminUserInfo.CurrentOrgId)
- salesReturn, _ := service.FindAllDrugSalesReturnById(id, adminUserInfo.CurrentOrgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "salesReturn": salesReturn,
- })
-
- }
- func (c *StockDrugApiController) EditDrugReturnInfo() {
- return_time := c.GetString("return_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- dealer_id, _ := c.GetInt64("dealer_id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- salesReturns, _ := service.FindDrugSalesReturnById(id)
-
- sales := models.DrugSalesReturn{
- ID: salesReturns.ID,
- Mtime: mtime,
- ReturnTime: returnDate.Unix(),
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
-
- service.EditDrugSaleReturn(sales)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var returnInfos []*models.DrugSalesReturnInfo
- var upDateReturnInfos []*models.DrugSalesReturnInfo
-
- if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["salesReturn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(count) * price
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
- retail_price_total := float64(count) * retail_price
-
- if id == 0 {
- returnInfo := &models.DrugSalesReturnInfo{
- DrugId: drug_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: sales.OrderNumber,
- SalesReturnId: sales.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- Total: total,
- Price: price,
- }
- returnInfos = append(returnInfos, returnInfo)
-
- } else {
- returnInfo := &models.DrugSalesReturnInfo{
- ID: id,
- DrugId: drug_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: sales.OrderNumber,
- SalesReturnId: sales.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- Total: total,
- Price: price,
- }
- upDateReturnInfos = append(upDateReturnInfos, returnInfo)
- }
- }
- }
- }
- var errs error
- if len(returnInfos) > 0 {
- errs = service.CreateDrugSalesReturnInfo(returnInfos)
- }
-
- if len(upDateReturnInfos) > 0 {
- for _, item := range upDateReturnInfos {
- errs = service.UpDateDrugSalesReturnInfo(item)
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "编辑成功",
- })
-
- }
-
- func (c *StockDrugApiController) CreateDrugWarehouseOut() {
-
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
- ctime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousing_out_time := c.GetString("warehousing_out_time")
- warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- //创建一个出库单
- warehouseOut := models.DrugWarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehouseOutTime: warehousingOutDate.Unix(),
- Type: types,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
-
- if warehouse_out_id == 0 {
- //查询是否生成出库单
- outIsExit, _ := service.GetDrugWarehouseOutIsExit(adminUserInfo.CurrentOrgId, 0, operation_time, warehousing_out_order)
- if outIsExit.ID == 0 {
- service.AddSigleDrugWarehouseOut(&warehouseOut)
- }
-
- }
- if warehouse_out_id > 0 {
- service.UpdateSingleDrugWarehouseOut(warehouse_out_id, storehouse_id)
- }
- lastWarehouseOut, _ := service.GetDrugLastWarehouseOut(adminUserInfo.CurrentOrgId)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //出库单详情
- var warehousingOutInfo []*models.DrugWarehouseOutInfo
- //把前端的参数加工为出库单详情
- if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockOut"].([]interface{})
-
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
-
- items := item.(map[string]interface{})
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- total := float64(count) * price
- retail_price_total := float64(count) * price
- remark := items["remark"].(string)
- max_unit := items["max_unit"].(string)
- dealer := int64(items["dealer"].(float64))
-
- manufacturer := int64(items["manufacturer"].(float64))
-
- number := items["number"].(string)
- batch_number := items["batch_number"].(string)
-
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
- var productDates int64
- var expiryDates int64
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
- }
-
- admin_user_id := int64(items["admin_user_id"].(float64))
-
- //if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
- // utils.ErrorLog("last_price")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
- //last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
-
- stock_count, _ := items["stock_count"].(string)
-
- 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.GetDrugsIsExsit(item.DrugId, item.SysRecordTime, item.OrgId, lastWarehouseOut.ID)
- if outInfo.ID == 0 {
- errOne := service.AddSigleDrugWarehouseOutInfo(item)
- fmt.Println(errOne)
- }
-
- }
- if item.ID > 0 {
- service.UpdatedDrugWarehouseInfo(item, item.ID)
- }
-
- }
-
- list, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
-
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
-
- warehousingOutInfoList, _ := service.GetDrugWarehouseOutListById(lastWarehouseOut.ID, adminUserInfo.CurrentOrgId)
-
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug_name": "",
- "dose": "",
- "dose_unit": "",
- "min_number": "",
- "min_unit": "",
- "max_unit": "",
- "dealerList": list,
- "manufacturerList": manufacturerList,
- "warehousingOutInfo": warehousingOutInfoList,
- "warehouseOut": lastWarehouseOut,
- "drugTypeList": drugTypeList,
- })
- return
- }
- func (c *StockDrugApiController) GetDrugWarehouseOutList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- way_type, _ := c.GetInt64("way_type")
- check_type, _ := c.GetInt64("check_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- var ids []int64
- var goodids []int64
- if len(keywords) > 0 {
- //查询商品名称
- list, _ := service.GetDrugNameByKeyword(keywords, adminUserInfo.CurrentOrgId)
- for _, item := range list {
- goodids = append(goodids, item.ID)
- }
-
- if len(goodids) > 0 {
- //出库详情但里面查询
- info, _ := service.GetDrugWarehouseOrderDetail(goodids, adminUserInfo.CurrentOrgId, startTime, endTime, storehouse_id)
- for _, it := range info {
- ids = append(ids, it.WarehouseOutId)
- }
- }
-
- }
-
- warehouseOutList, total, err := service.FindAllDrugWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id, way_type, check_type)
-
- 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
- }
-
- warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminUserInfo.CurrentOrgId)
-
- tempWarehouseOut := models.DrugWarehouseOut{
- ID: warehouseOut.ID,
- Mtime: mtime,
- WarehouseOutTime: warehouseOutDate.Unix(),
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- StorehouseId: storehouse_id,
- }
-
- service.EditDrugWarehouseOut(tempWarehouseOut)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingOutInfo []*models.DrugWarehouseOutInfo
- var upDateWarehouseOutInfos []*models.DrugWarehouseOutInfo
-
- var drugFlow []*models.DrugFlow
- if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
- thisStockOut, _ := dataBody["stockOut"].([]interface{})
- if len(thisStockOut) > 0 {
- for _, item := range thisStockOut {
- items := item.(map[string]interface{})
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- count_unit, _ := items["count_unit"].(string)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
-
- total := float64(count) * price
- retail_price_total := float64(count) * retail_price
-
- remark := items["remark"].(string)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- dealer := int64(items["dealer"].(float64))
- manufacturer := int64(items["manufacturer"].(float64))
-
- batch_number := items["batch_number"].(string)
- number := items["number"].(string)
- max_unit := items["count_unit"].(string)
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
- var productDates int64
- var expiryDates int64
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- admin_user_id := int64(items["admin_user_id"].(float64))
-
- patient_id := int64(items["patient_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)
-
- 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 {
-
- //var total_count int64
- //var prescribing_number_total int64
- //调用出库逻辑
- for _, item := range warehousingOutInfo {
-
- errOnes := service.AddSigleDrugWarehouseOutInfo(item)
- fmt.Println("errone", errOnes)
-
- ////获取药品库存
- //info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId, storehouse_id)
- ////查询改药品信息
- //medical, _ := service.GetBaseDrugMedical(item.DrugId)
- ////判断单位是否相等
- //if medical.MaxUnit == item.CountUnit {
- // //转化为最小单位
- // total_count = info.Count * medical.MinNumber
- // prescribing_number_total = item.Count * medical.MinNumber
- //}
- //if medical.MinUnit == item.CountUnit {
- // total_count = info.Count
- // prescribing_number_total = item.Count
- //}
- //
- ////判断单位
- //if total_count == 0 {
- // goodObj, _ := service.GetDrugByGoodId(item.DrugId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // "drug_name": goodObj.DrugName,
- // "dose": goodObj.Dose,
- // "dose_unit": goodObj.DoseUnit,
- // "min_number": goodObj.MinNumber,
- // "min_unit": goodObj.MinUnit,
- // "max_unit": goodObj.MaxUnit,
- // })
- // return
- //}
- //if prescribing_number_total > total_count {
- //
- // goodObj, _ := service.GetDrugByGoodId(item.DrugId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // "drug_name": goodObj.DrugName,
- // "dose": goodObj.Dose,
- // "dose_unit": goodObj.DoseUnit,
- // "min_number": goodObj.MinNumber,
- // "min_unit": goodObj.MinUnit,
- // "max_unit": goodObj.MaxUnit,
- // })
- // return
- //} else {
- //
- // // 出库流程
- // // 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
- // drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
- // if drup.ID > 0 {
- // prescribingNumber := item.Count
- // service.AutoDrugDeliverInfoTwentyOne(item.OrgId, prescribingNumber, &tempWarehouseOut, &drup, item)
- // }
- //}
-
- }
- }
-
- if len(upDateWarehouseOutInfos) > 0 {
- for _, item := range upDateWarehouseOutInfos {
-
- service.UpdatedDrugWarehouseInfo(item, item.ID)
- ////获取药品库存
- //info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId, storehouse_id)
- ////查询改药品信息
- //medical, _ := service.GetBaseDrugMedical(item.DrugId)
- ////查询最后一次出库记录
- //outInfo, _ := service.GetLastDrugWarehouseOutInfo(item.DrugId, item.WarehouseOutId, item.OrgId)
- //var min_number int64 //最后一次出库数量
- //var max_number int64 //当前出库数量
- //var all_number int64 //总库存
- //var cha_number int64 //库存差
- //var maxNumber int64
- //var minNumber int64
- //
- //if medical.MaxUnit == outInfo.CountUnit {
- // //转为最小单位
- // min_number = outInfo.Count * medical.MinNumber
- //}
- //
- //if medical.MinUnit == outInfo.CountUnit {
- // min_number = outInfo.Count
- //}
- //
- //if medical.MaxUnit == item.CountUnit {
- // max_number = item.Count * medical.MinNumber
- //}
- //
- //if medical.MinUnit == item.CountUnit {
- // max_number = item.Count
- //}
- //
- //all_number = info.Count*medical.MinNumber + info.StockMinNumber
- //
- ////比较当前出库数量 小于等于 最后一次出库数量,则需要退库
- //if max_number <= min_number {
- // errs = service.UpDateDrugWarehouseOutInfo(item)
- // flow := models.DrugFlow{
- // Count: max_number,
- // ExpireDate: item.ExpiryDate,
- // ProductDate: item.ProductDate,
- // Price: item.Price,
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // Number: item.Number,
- // WarehouseOutId: item.WarehouseOutId,
- // StorehouseId: item.StorehouseId,
- // AdminUserId: item.AdminUserId,
- // StockCount: item.StockCount,
- // }
- // service.UpdateDrugFlowSix(item.WarehouseOutId, item.DrugId, item.WarehouseOutOrderNumber, flow)
- // cha_number = min_number - max_number
- //
- // if item.CountUnit == medical.MaxUnit {
- // maxNumber = cha_number / medical.MinNumber
- //
- // parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId, outInfo.WarehouseInfoId)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "drug_name": "",
- // "dose": "",
- // "dose_unit": "",
- // "min_number": "",
- // "min_unit": "",
- // "max_unit": "",
- // })
- // minNumber = cha_number % medical.MinNumber
- // if minNumber < 0 {
- // minNumber = 0
- // }
- // parseDateErr = service.UpdateWarehouseInfoOne(minNumber, item.DrugId, item.OrgId, outInfo.WarehouseInfoId)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "drug_name": "",
- // "dose": "",
- // "dose_unit": "",
- // "min_number": "",
- // "min_unit": "",
- // "max_unit": "",
- // })
- // }
- // if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- // parseDateErr := service.UpdateWarehouseInfoOne(cha_number, item.DrugId, item.OrgId, outInfo.WarehouseInfoId)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "drug_name": "",
- // "dose": "",
- // "dose_unit": "",
- // "min_number": "",
- // "min_unit": "",
- // "max_unit": "",
- // })
- // }
- //
- //}
- ////比较当前出库数量 大于 最后一次出库数量,则需要出库
- //if max_number > min_number {
- //
- // cha_number = max_number - min_number
- // //如果总库存大于差,正常出库
- // if all_number > cha_number {
- //
- // errs = service.UpDateDrugWarehouseOutInfo(item)
- // flow := models.DrugFlow{
- // Count: max_number,
- // ExpireDate: item.ExpiryDate,
- // ProductDate: item.ProductDate,
- // Price: item.Price,
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // Number: item.Number,
- // StorehouseId: item.StorehouseId,
- // AdminUserId: item.AdminUserId,
- // }
- // service.UpdateDrugFlowSix(item.WarehouseOutId, item.DrugId, item.WarehouseOutOrderNumber, flow)
- //
- // service.UpdateWarehouseInfoTwentyFive(cha_number, item.DrugId, item.OrgId, storehouse_id, &medical)
- //
- //
- // }
- //
- // if all_number == cha_number {
- // warehouseInfo := models.XtDrugWarehouseInfo{
- // Number: item.Number,
- // ProductDate: item.ProductDate,
- // ExpiryDate: item.ExpiryDate,
- // Price: item.Price,
- // TotalPrice: item.TotalPrice,
- // Dealer: item.Dealer,
- // Manufacturer: item.Manufacturer,
- // Remark: item.Remark,
- // BatchNumber: item.BatchNumber,
- // MaxUnit: item.CountUnit,
- // StorehouseId: item.StorehouseId,
- // }
- // parseDateErr := service.UpdateDrugWarehouseingInfoSix(item.ID, warehouseInfo)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- // fmt.Println("单位123223232323", item.CountUnit)
- // fmt.Println("单位232232323323232", medical.MaxUnit)
- //
- // errs = service.UpDateDrugWarehouseOutInfo(item)
- // flow := models.DrugFlow{
- // Count: item.Count,
- // ExpireDate: item.ExpiryDate,
- // ProductDate: item.ProductDate,
- // Price: item.Price,
- // Manufacturer: item.Manufacturer,
- // Dealer: item.Dealer,
- // Number: item.Number,
- // StorehouseId: item.StorehouseId,
- // AdminUserId: item.AdminUserId,
- // }
- // service.UpdateDrugFlowSix(item.WarehouseOutId, item.DrugId, item.WarehouseOutOrderNumber, flow)
- // if item.CountUnit == medical.MaxUnit {
- // maxNumber = cha_number / medical.MinNumber
- //
- // parseDateErr := service.UpdateWarehouseInfoTwo(maxNumber, item.DrugId, item.OrgId)
- //
- // fmt.Println("parseDateErr", parseDateErr)
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "drug_name": "",
- // "dose": "",
- // "dose_unit": "",
- // "min_number": "",
- // "min_unit": "",
- // "max_unit": "",
- // })
- // minNumber = cha_number % medical.MinNumber
- // if minNumber < 0 {
- // minNumber = 0
- // }
- // parseDateErr = service.UpdateWarehouseInfoFour(minNumber, item.DrugId, item.OrgId)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "drug_name": "",
- // "dose": "",
- // "dose_unit": "",
- // "min_number": "",
- // "min_unit": "",
- // "max_unit": "",
- // })
- // }
- // if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- // parseDateErr := service.UpdateWarehouseInfoFour(cha_number, item.DrugId, item.OrgId)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "drug_name": "",
- // "dose": "",
- // "dose_unit": "",
- // "min_number": "",
- // "min_unit": "",
- // "max_unit": "",
- // })
- // }
- //
- // }
- // if all_number < cha_number {
- // goodObj, _ := service.GetDrugByGoodId(item.DrugId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // "drug_name": goodObj.DrugName,
- // "dose": goodObj.Dose,
- // "dose_unit": goodObj.DoseUnit,
- // "min_number": goodObj.MinNumber,
- // "min_unit": goodObj.MinUnit,
- // "max_unit": goodObj.MaxUnit,
- // })
- // return
- // }
- //}
- //
- ////查询默认仓库
- //houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- ////查询默认仓库剩余多少库存
- //list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- //var sum_count int64
- //var sum_in_count int64
- //for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- //
- // }
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- //}
- //service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
-
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug_name": "",
- "dose": "",
- "dose_unit": "",
- "min_number": "",
- "min_unit": "",
- "max_unit": "",
- })
-
- }
-
- func (c *StockDrugApiController) CreateDrugCancelStock() {
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- cancel_stock_time := c.GetString("time")
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- cancelstock_id, _ := c.GetInt64("cancelstock_id")
- cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetAdminUserInfo()
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- ctime := time.Now().Unix()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.DrugCancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: cancelStockDate.Unix(),
- Dealer: dealer_id,
- Manufacturer: manufacturer_id,
- Type: types,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- if cancelstock_id == 0 {
- service.AddSigleDrugCancelStock(&cancelStock)
- }
- if cancelstock_id > 0 {
- service.UpdateSingleDrugCancelStock(cancelstock_id, storehouse_id)
- }
- cancelLastStock, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var cancelStockInfos []*models.DrugCancelStockInfo
- var drugFlow []*models.DrugFlow
-
- if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["cancelStock"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- return_count, _ := items["return_count"].(string)
- if len(return_count) == 0 {
- utils.ErrorLog("len(return_count) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
-
- return
- }
-
- count, _ := strconv.ParseInt(return_count, 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(count) * price
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
- retail_price_total := float64(count) * retail_price
-
- register_account, _ := items["register_account"].(string)
-
- remark, _ := items["remark"].(string)
-
- var productDates int64
- var expiryDates int64
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- manufacturer, _ := items["manufacturer"].(string)
-
- dealer, _ := items["dealer"].(string)
-
- batch_number := items["batch_number"].(string)
- max_unit := items["max_unit"].(string)
- batch_number_id := int64(items["batch_number_id"].(float64))
- var manufacturer_id int64
- var dealer_id int64
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- for _, item := range manufacturerList {
- if manufacturer == item.ManufacturerName {
- manufacturer_id = item.ID
- }
- }
- for _, item := range dealerList {
- if dealer == item.DealerName {
- dealer_id = item.ID
- }
- }
- cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
- cancelStockInfo := &models.DrugCancelStockInfo{
- ID: id,
- OrderNumber: cancelInfo.OrderNumber,
- CancelStockId: cancelInfo.ID,
- DrugId: drug_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Total: total,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- Price: price,
- RegisterAccount: register_account,
- Remark: remark,
- BatchNumber: batch_number,
- MaxUnit: max_unit,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- BatchNumberId: batch_number_id,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
-
- flow := &models.DrugFlow{
- WarehousingId: 0,
- DrugId: drug_id,
- Number: "",
- BatchNumber: batch_number,
- Count: count,
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: 0,
- SystemTime: ctime,
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- Creator: adminUserInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: expiryDates,
- ProductDate: productDates,
- MaxUnit: max_unit,
- MinUnit: "",
- StorehouseId: storehouse_id,
- }
- drugFlow = append(drugFlow, flow)
- }
- }
- }
-
- for _, item := range cancelStockInfos {
- if item.ID == 0 {
- service.CreateCancelStockInfoTwo(item)
- }
- if item.ID > 0 {
- service.ModifyDrugCancelStockInfo(item.ID, item)
- }
- }
-
- list, _ := service.GetLastCancelStockByList(cancelLastStock.ID, adminUserInfo.CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "cancelStock": cancelLastStock,
- "cancelLastStock": cancelLastStock,
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "drugTypeList": drugTypeList,
- "msg": "1",
- })
- //扣减库存逻辑
- //for _, item := range cancelStockInfos {
- //
- // var total_number int64
- // var out_number int64
- // var can_number int64
- // medical, _ := service.GetBaseDrugMedical(item.DrugId)
- // //将当前退库数转为最小单位
- // if item.MaxUnit == medical.MaxUnit {
- // total_number = item.Count * medical.MinNumber
- // }
- // if item.MaxUnit == medical.MinUnit {
- // total_number = item.Count
- // }
- // //查询当前药品退库的批次号的总入库数
- // infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
- // var total_count int64
- // total_count = infoWareInfo.WarehousingCount * medical.MinNumber
- //
- // //查询该批次的出库数量
- // outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
- //
- // //查询该批次总的退库数量
- // canInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
- //
- // for _, it := range canInfo {
- // if it.MaxUnit == medical.MaxUnit {
- // it.Count = it.Count * medical.MinNumber
- // }
- // if it.MaxUnit == medical.MinUnit {
- // it.Count = it.Count
- // }
- // }
- //
- // for _, it := range canInfo {
- // can_number += it.Count
- // }
- //
- // for _, it := range outInfo {
- // if it.CountUnit == medical.MaxUnit {
- // it.Count = it.Count * medical.MinNumber
- // }
- // if it.CountUnit == medical.MinUnit {
- // it.Count = it.Count
- // }
- // }
- // for _, it := range outInfo {
- // out_number += it.Count
- // }
- //
- // if out_number == 0 {
- // service.UpdateDrugCancel(item.CancelStockId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // })
- // return
- // }
- // fmt.Println("当前退库数", total_count)
- // fmt.Println("当前批次总库存", total_count)
- // fmt.Println("总出库数", out_number)
- // //判断退库数量是否大于总入库数量
- // if total_number > total_count {
- // service.UpdateDrugCancel(item.CancelStockId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // })
- // return
- // }
- //
- // //判断总退库数量是否大于出库数量
- //
- // if can_number+total_number > out_number {
- // //清空退库单
- // service.UpdateDrugCancel(item.CancelStockId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // })
- // return
- // }
- //
- // //正常退库
- // if total_number <= out_number {
- // //创建退库详情
- // errs := service.CreateCancelStockInfoTwo(item)
- // lastInfo, _ := service.GetLastStockInfoThree(item.DrugId)
- // //创建库存明细
- // flows := models.DrugFlow{
- // WarehousingId: 0,
- // DrugId: item.DrugId,
- // Number: "",
- // BatchNumber: item.BatchNumber,
- // Count: item.Count,
- // UserOrgId: adminUserInfo.CurrentOrgId,
- // PatientId: 0,
- // SystemTime: ctime,
- // ConsumableType: 4,
- // IsSys: 0,
- // WarehousingOrder: infoWareInfo.WarehousingOrder,
- // WarehouseOutId: 0,
- // WarehouseOutOrderNumber: "",
- // IsEdit: 0,
- // CancelStockId: cancelStock.ID,
- // CancelOrderNumber: cancelStock.OrderNumber,
- // Manufacturer: manufacturer_id,
- // Dealer: dealer_id,
- // Creator: adminUserInfo.AdminUser.Id,
- // UpdateCreator: 0,
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // Price: item.Price,
- // WarehousingDetailId: 0,
- // WarehouseOutDetailId: 0,
- // CancelOutDetailId: lastInfo.ID,
- // ExpireDate: item.ExpiryDate,
- // ProductDate: item.ProductDate,
- // MaxUnit: item.MaxUnit,
- // MinUnit: "",
- // StorehouseId: storehouse_id,
- // }
- // errs = service.CreateDrugFlowOne(flows)
- //
- // var total int64
- //
- // if medical.MaxUnit == item.MaxUnit {
- // total = item.Count
- //
- // warehouseInfo := models.XtDrugWarehouseInfo{
- // StockMaxNumber: total,
- // }
- //
- // errs = service.UpdateDrugWarehouseInfo(&warehouseInfo, item.BatchNumberId)
- // //查询默认仓库
- // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询默认仓库剩余多少库存
- // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // }
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
- // if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // })
- // }
- //
- // if medical.MinUnit == item.MaxUnit && medical.MaxUnit != medical.MinUnit {
- // total = item.Count
- // warehouseInfo := models.XtDrugWarehouseInfo{
- // StockMinNumber: total,
- // }
- //
- // errs = service.UpdateDrugWarehouseInfoOne(&warehouseInfo, item.BatchNumberId)
- // //查询默认仓库
- // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询默认仓库剩余多少库存
- // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // }
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
- // if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // })
- // }
- // }
- //
- //}
- }
- func (c *StockDrugApiController) GetDrugCancelStockInfoList() {
- id, _ := c.GetInt64("id", 0)
- adminUserInfo := c.GetAdminUserInfo()
-
- cancelStockInfoList, _ := service.FindDrugCancelStockInfoById(id, adminUserInfo.CurrentOrgId)
-
- info, _ := service.FindCancelDrugById(id, adminUserInfo.CurrentOrgId)
-
- list, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cancelStockInfoList,
- "info": info,
- "houselist": list,
- })
-
- }
- func (c *StockDrugApiController) GetDrugCancelStockList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- check_type, _ := c.GetInt64("check_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- returnList, total, err := service.FindAllDrugCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, storehouse_id, check_type)
- houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": returnList,
- "total": total,
- "houseList": houseList,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- func (this *StockDrugApiController) DeleteDrugCancelStock() {
- ids := this.GetString("ids")
-
- if len(ids) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- ////获取入库数据
- //list, _ := service.GetDrugWareInfoByCancelId(idArray)
- //for _, item := range list {
- // medical, _ := service.GetBaseDrugMedical(item.DrugId)
- // if item.MaxUnit == medical.MaxUnit {
- // //回退库存
- // service.ModifyDrugWarehouseByInfoId(item.BatchNumberId, item.Count)
- //
- // }
- // if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- // service.ModifyDrugWarehouseByStockMin(item.BatchNumberId, item.Count)
- // }
- //
- // //查询默认仓库
- // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询默认仓库剩余多少库存
- // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- // }
- // }
- // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
- //}
- err := service.DeleteDrugCancelStock(idArray)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockDrugApiController) DeleteDrugCancelStockInfo() {
- id, _ := this.GetInt64("id", 0)
-
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ////查询
- //cancelinfo, _ := service.GetDrugCancelById(id)
- //
- //drug, _ := service.GetBaseDrugMedical(cancelinfo.DrugId)
- //if drug.MaxUnit == cancelinfo.MaxUnit {
- // service.ModeFyDrugWareseInfo(cancelinfo.BatchNumberId, cancelinfo.Count)
- //
- //}
- //if drug.MinUnit == cancelinfo.MaxUnit && drug.MaxUnit != drug.MinUnit {
- // service.ModeFyDrugWarehouseMin(cancelinfo.BatchNumberId, cancelinfo.Count)
- //}
- //
- err := service.UpDateDrugCancleStockStatus(id)
-
- //删除流水
- // service.UpDateDrugCancelStockById(cancelinfo.ID)
-
- //查询默认仓库
- //houseConfig, _ := service.GetAllStoreHouseConfig(cancelinfo.OrgId)
- ////查询默认仓库剩余多少库存
- //list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, cancelinfo.OrgId, cancelinfo.DrugId)
- //var sum_count int64
- //var sum_in_count int64
- //for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // }
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- //}
- //service.UpdateMedicalSumCount(cancelinfo.DrugId, sum_count, sum_in_count, cancelinfo.OrgId)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (c *StockDrugApiController) EditDrugCancelStock() {
- cancel_time := c.GetString("cancel_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- cancelStock, _ := service.FindDrugCancelStockById(id)
-
- tempCancelStock := models.DrugCancelStock{
- ID: cancelStock.ID,
- Mtime: mtime,
- ReturnTime: cancelDate.Unix(),
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- StorehouseId: storehouse_id,
- IsCheck: 1,
- }
-
- service.EditDrugCancelStock(tempCancelStock)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var cancelStockInfos []*models.DrugCancelStockInfo
- var upDateCancelStockInfos []*models.DrugCancelStockInfo
- var drugFlow []*models.DrugFlow
- if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
- thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
- if len(thisCancelStock) > 0 {
- for _, item := range thisCancelStock {
- items := item.(map[string]interface{})
-
- if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
- utils.ErrorLog("drug_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drug_id := int64(items["drug_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(count) * price
-
- if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
- utils.ErrorLog("retail_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
- retail_price_total := float64(count) * retail_price
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- max_unit := items["max_unit"].(string)
- batch_number := items["batch_number"].(string)
-
- register_account := items["register_account"].(string)
-
- remark := items["remark"].(string)
-
- manufacturer := items["manufacturer"].(string)
-
- dealer := items["dealer"].(string)
-
- var productDates int64
- var expiryDates int64
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- batch_number_id := int64(items["batch_number_id"].(float64))
- if id == 0 {
- cancelStockInfo := &models.DrugCancelStockInfo{
- DrugId: drug_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- Price: price,
- Total: total,
- Manufacturer: manufacturer,
- Dealer: dealer,
- RegisterAccount: register_account,
- MaxUnit: max_unit,
- BatchNumber: batch_number,
- Remark: remark,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- BatchNumberId: batch_number_id,
- StorehouseId: storehouse_id,
- }
- cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
-
- } else {
- cancelStockInfo := &models.DrugCancelStockInfo{
- ID: id,
- DrugId: drug_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- RetailPrice: retail_price,
- RetailTotalPrice: retail_price_total,
- Price: price,
- Total: total,
- Manufacturer: manufacturer,
- Dealer: dealer,
- RegisterAccount: register_account,
- MaxUnit: max_unit,
- BatchNumber: batch_number,
- Remark: remark,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- BatchNumberId: batch_number_id,
- StorehouseId: storehouse_id,
- }
- upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
- }
-
- flow := &models.DrugFlow{
- WarehousingId: 0,
- DrugId: drug_id,
- Number: "",
- BatchNumber: batch_number,
- Count: count,
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: 0,
- SystemTime: time.Now().Unix(),
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: 0,
- Dealer: 0,
- Creator: adminUserInfo.AdminUser.Id,
- UpdateCreator: adminUserInfo.AdminUser.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: expiryDates,
- ProductDate: productDates,
- MaxUnit: max_unit,
- MinUnit: "",
- StorehouseId: storehouse_id,
- }
- drugFlow = append(drugFlow, flow)
- }
- }
- }
-
- if len(cancelStockInfos) > 0 {
- service.CreateDrugCancelStockInfo(cancelStockInfos)
- }
- if len(upDateCancelStockInfos) > 0 {
- for _, item := range upDateCancelStockInfos {
- service.UpDateDrugCancelStockInfo(item)
- }
-
- }
-
- //var errs error
- //if len(cancelStockInfos) > 0 {
- //
- // //扣减库存逻辑
- // for _, item := range cancelStockInfos {
- // medical, _ := service.GetBaseDrugMedical(item.DrugId)
- // //查询当前药品退库的批次号的总入库数
- // infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
- //
- // var total_count int64
- // var cancel_count int64
- // var out_count int64
- // total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
- // //转化为最小单位
- // var total_number int64
- // if item.MaxUnit == medical.MaxUnit {
- // total_number = item.Count * medical.MinNumber
- // }
- // if item.MaxUnit == medical.MinUnit {
- // total_number = item.Count
- // }
- //
- // //统计该批次的总出库数
- // outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
- // for _, item := range outInfo {
- // if item.CountUnit == medical.MaxUnit {
- // item.Count = item.Count * medical.MinNumber
- // }
- // if item.CountUnit == medical.MinUnit {
- // item.Count = item.Count
- // }
- // }
- //
- // for _, item := range outInfo {
- // out_count += item.Count
- // }
- //
- // //判断退库数量是否大于出库数量
- // cancelInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
- // for _, item := range cancelInfo {
- // if item.MaxUnit == medical.MaxUnit {
- // item.Count = item.Count * medical.MinNumber
- // }
- // if item.MaxUnit == medical.MinUnit {
- // item.Count = item.Count
- // }
- // }
- //
- // for _, item := range cancelInfo {
- // cancel_count += item.Count
- // }
- //
- // if total_number+cancel_count > out_count {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "4",
- // })
- // return
- // }
- //
- // //判断退库数量是否大于总入库数量
- // if total_number > total_count {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // })
- // return
- // }
- //
- // //正常退库
- // if total_number <= total_count {
- // //创建退库详情
- // errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
- // //创建库存明细
- // //查询这个药品这个订单是否已存在流水
- // for _, items := range drugFlow {
- // drugwarehouseinfo, _ := service.GetLastDrugCancelStockInfoById(items.DrugId)
- // items.CancelOutDetailId = drugwarehouseinfo.ID
- // _, errsId := service.GetCancelStockId(items.CancelStockId, items.DrugId)
- // if errsId == gorm.ErrRecordNotFound {
- //
- // errs = service.CreateDrugFlowTwo(items)
- // }
- // }
- //
- // //获取该批次最后一条退库详情
- // lastCancel, _ := service.GetLastCancelStockInfo(id)
- // var cancel_number int64
- // if lastCancel.MaxUnit == medical.MaxUnit {
- // cancel_number = lastCancel.Count * medical.MinNumber
- // }
- //
- // if lastCancel.MaxUnit == medical.MinUnit {
- // cancel_number = lastCancel.Count
- // }
- //
- // var total int64
- //
- // if medical.MaxUnit == item.MaxUnit {
- // total = item.Count - cancel_number
- //
- // warehouseInfo := models.XtDrugWarehouseInfo{
- // StockMaxNumber: total,
- // }
- // errs = service.UpdateDrugWarehouseInfo(&warehouseInfo, item.BatchNumberId)
- //
- // if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // })
- // }
- // if medical.MinUnit == item.MaxUnit && medical.MaxUnit != medical.MinUnit {
- // total = item.Count - cancel_number
- // warehouseInfo := models.XtDrugWarehouseInfo{
- // StockMinNumber: total,
- // }
- //
- // errs = service.UpdateDrugWarehouseInfoOne(&warehouseInfo, item.BatchNumberId)
- //
- // //查询默认仓库
- // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询默认仓库剩余多少库存
- // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // }
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
- //
- // if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // })
- // }
- //
- // }
- //
- // }
- //}
- //if len(drugFlow) > 0 {
- // for _, items := range drugFlow {
- // _, errsId := service.GetCancelStockId(items.CancelStockId, items.DrugId)
- // if errsId == gorm.ErrRecordNotFound {
- // errs = service.CreateDrugFlowTwo(items)
- // }
- // }
- //}
- //
- //if len(upDateCancelStockInfos) > 0 {
- // var total int64
- // var out_count int64
- // var cancel_count int64
- // var now_count int64
- // var all_count int64
- // for _, item := range upDateCancelStockInfos {
- //
- // //查询最后一条退库记录
- // info, _ := service.GetLastCancelStockInfoOne(id, item.DrugId)
- //
- // errs = service.UpDateDrugCancelStockInfo(item)
- //
- // //查询该药品的信息
- // medical, _ := service.GetBaseDrugMedical(item.DrugId)
- // //统计该批次的总出库数
- // outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
- // //查询该批次的总退库数量
- // cancelInfo, _ := service.GetTotalDrugCancelInfo(item.BatchNumberId, item.DrugId, item.ID)
- // for _, item := range outInfo {
- // if item.CountUnit == medical.MaxUnit {
- // item.Count = item.Count * medical.MinNumber
- // }
- // if item.CountUnit == medical.MinUnit {
- // item.Count = item.Count
- // }
- // }
- //
- // for _, item := range outInfo {
- // out_count += item.Count
- // }
- //
- // for _, item := range cancelInfo {
- // if item.MaxUnit == medical.MaxUnit {
- // item.Count = item.Count * medical.MinNumber
- // }
- // if item.MaxUnit == medical.MinUnit {
- // item.Count = item.Count
- // }
- // }
- //
- // for _, item := range cancelInfo {
- // cancel_count += item.Count
- // }
- //
- // fmt.Println("out_count232233332232323223", out_count)
- //
- // if item.MaxUnit == medical.MaxUnit {
- // now_count = item.Count * medical.MinNumber
- // }
- // if item.MaxUnit == medical.MinUnit {
- // now_count = item.Count
- // }
- // fmt.Println("hhhhhh2323322323", now_count+cancel_count)
- // //总退库批次
- // all_count = now_count + cancel_count
- //
- // //该批次的总出库数小与退库数报错返回
- // if all_count > out_count {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "4",
- // })
- // return
- // }
- //
- // if item.MaxUnit == medical.MaxUnit {
- // //更新库存
- // total = item.Count - info.Count
- // parseDateErr := service.UpdatedDrugInfo(item.BatchNumberId, total)
- // fmt.Println("parseDateErr", parseDateErr)
- //
- // flow := models.DrugFlow{
- // Count: item.Count,
- // }
- // service.UpdatedDrugFlow(info.CancelStockId, item.DrugId, flow)
- // }
- //
- // if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- // item.Count = item.Count
- // total = item.Count - info.Count
- // service.UpdatedDrugInfoOne(item.BatchNumberId, total)
- //
- // flow := models.DrugFlow{
- // Count: item.Count,
- // }
- // service.UpdatedDrugFlow(info.CancelStockId, item.DrugId, flow)
- // }
- //
- // //查询默认仓库
- // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询默认仓库剩余多少库存
- // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range list {
- // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- // if it.MaxUnit == baseDrug.MaxUnit {
- // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- // sum_count += it.StockMaxNumber + it.StockMinNumber
- // sum_in_count += it.WarehousingCount
- // }
- // }
- // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
- //
- // }
- //}
-
- //if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateCancelStockFail)
- // return
- //}
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
-
- }
-
- func (c *StockDrugApiController) GetAllConfig() {
- adminUserInfo := c.GetAdminUserInfo()
- manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
- dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
- stockIns, _ := service.FindStockInNumber(adminUserInfo.CurrentOrgId)
- drugs, _ := service.GetDrugs(adminUserInfo.CurrentOrgId)
- list, _ := service.GetAllStoreHouseListThree(adminUserInfo.CurrentOrgId)
- configlist, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- appId := c.GetAdminUserInfo().CurrentAppId
- doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
- 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
- //更改核对状态
- service.CheckWarehousingInfo(warehousing_id, orgId, checker)
-
- list, _ := service.GetWarehousingInfoByList(warehousing_id, orgId)
- for _, item := range list {
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- //新增库存
- service.AddDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID)
-
- }
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- //新增库存
- service.AddDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID)
-
- }
-
- if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
-
- //新增库存
- service.AddDrugWarehouseStockMinNumber(item.WarehousingCount, item.ID)
-
- }
-
- Creator := c.GetAdminUserInfo().AdminUser.Id
-
- //查询默认仓库
-
- //查询默认仓库剩余多少库存
- 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
- }
- 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.CreateDrugFlowTwo(flow)
- //更新基础库剩余库存
- service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
-
- drugInfolist, _ := service.GetDrugSumCountByStorehouseId(item.StorehouseId, item.OrgId, item.DrugId)
- var total_count int64 // 入库总数量
- var over_count int64 //剩余库存
- for _, it := range drugInfolist {
- baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- 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.GetDrugStockCount(item.StorehouseId, item.DrugId, item.OrgId)
- 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.CreateDrugStockSum(drugStock)
-
- } else if errcode == nil {
- service.UpdateDrugStockSum(item.StorehouseId, item.DrugId, item.OrgId, total_count, over_count)
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
-
- }
-
- func (c *StockDrugApiController) ReturnCheckWarehouseingInfo() {
-
- warehousing_id, _ := c.GetInt64("warehousing_id")
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- list, _ := service.GetWarehousingInfoByList(warehousing_id, orgId)
- for _, item := range list {
- //查询该药品是否有出库数据
- outInfo, _ := service.GetDrugWarehouseOutByWarehouseInfoId(item.ID, item.DrugId, item.OrgId)
- if len(outInfo) > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
- return
- }
-
- }
- for _, item := range list {
- //删除流水
- service.UpdateWarehousingInfoFlow(item.ID, orgId)
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- //新增库存
- service.AddDrugReturnWarehouseStockMaxNumber(item.WarehousingCount, item.ID)
- }
- if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- //新增库存
- service.AddDrugReturnWarehouseStockMaxNumber(item.WarehousingCount, item.ID)
- }
- if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- //新增库存
- service.AddDrugReturnWarehouseStockMinNumber(item.WarehousingCount, item.ID)
- }
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
-
- stockInfoList, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, orgId, item.DrugId)
- var sum_count int64
- var sum_in_count int64
- for _, its := range stockInfoList {
- if its.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- sum_count += its.StockMaxNumber * medical.MinNumber
- sum_in_count += its.WarehousingCount * medical.MinNumber
- }
- if its.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- sum_count += its.StockMaxNumber
- sum_in_count += its.WarehousingCount
- }
- if its.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- sum_count += its.StockMaxNumber
- sum_in_count += its.WarehousingCount
- }
- }
- service.UpdateBaseDrugSumInfo(sum_count, item.DrugId, item.OrgId, sum_in_count)
-
- 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.GetDrugSumCountByStorehouseId(item.StorehouseId, item.OrgId, item.DrugId)
- 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.ReduceDrugStockCount(item.StorehouseId, item.DrugId, item.OrgId, total_count, over_count)
-
- }
- //更新审核
- err := service.ReturnCheckWarehouseingInfo(warehousing_id, orgId)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "反审核成功!",
- })
- return
- }
- }
-
- func (c *StockDrugApiController) CheckDrugOut() {
-
- warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
- orgId := c.GetAdminUserInfo().CurrentOrgId
- warehousingOutInfoList, _ := service.GetDrugWarehouseOutListById(warehouse_out_id, orgId)
- drugWarehouseOut, _ := service.GetDrugWarehouseOutByLastId(warehouse_out_id)
-
- for _, it := range warehousingOutInfoList {
- var total_count int64
- var out_count int64
- //查询剩余库存
- stockInfo, _ := service.GetDrugAllStockInfo(it.StorehouseId, it.OrgId, it.DrugId)
- drup, _ := service.FindBaseDrugLibRecord(it.OrgId, it.DrugId)
-
- for _, item := range stockInfo {
- if item.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
- item.StockMaxNumber = item.StockMaxNumber * drup.MinNumber
- }
-
- total_count += item.StockMaxNumber + item.StockMinNumber
- }
-
- //出库数量累加
- if it.CountUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
- 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.GetDrugWarehouseOutListById(warehouse_out_id, orgId)
-
- 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.AddDrugCount(it.DrugId, it.OrgId, it.StorehouseId, out_count_one)
-
- }
- warehousingOutInfoListThree, _ := service.GetDrugWarehouseOutListById(warehouse_out_id, orgId)
- for _, it := range warehousingOutInfoListThree {
- medical, _ := service.GetBaseDrugMedical(it.DrugId)
- drup, _ := service.FindBaseDrugLibRecord(it.OrgId, it.DrugId)
- //出库逻辑
- service.AutoDrugDeliverInfoFourtyOne(orgId, it.Count, &drugWarehouseOut, &drup, it, it.CountUnit)
-
- //查询剩余库存
- stockInfo, _ := service.GetDrugAllStockInfo(it.StorehouseId, it.OrgId, it.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.UpdateDrugStockCount(it.DrugId, it.OrgId, it.StorehouseId, sum_count)
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- stockInfoOne, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, it.OrgId, it.DrugId)
- 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.UpdateBaseDrugSumTwo(it.DrugId, sum_count_one, it.OrgId)
- }
-
- out := models.DrugWarehouseOut{
- IsCheck: 1,
- }
- //更新审核状态
- service.UpdateCheckDrugOut(out, warehouse_out_id)
- //info := models.DrugWarehouseOutInfo{
- // IsCheck: 1,
- //}
- //service.UpdateCheckDrugOutInfo(info, warehouse_out_id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "warehousingOutInfoList": warehousingOutInfoList,
- "drug_name": "",
- "dose": "",
- "dose_unit": "",
- "min_number": "",
- "min_unit": "",
- "max_unit": "",
- "msg": 1,
- })
- }
-
- func (c *StockDrugApiController) ToReturnCheck() {
-
- warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
-
- out := models.DrugWarehouseOut{
- IsCheck: 2,
- }
- service.UpdateCheckDrugOut(out, warehouse_out_id)
-
- outInfo := models.DrugWarehouseOutInfo{
- IsCheck: 2,
- }
- service.UpdateCheckDrugOutInfoList(outInfo, warehouse_out_id)
- 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.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)
- drugInfoList, _ := service.FindDrugWarehouseInfoList(item.DrugId, item.OrgId)
- 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.CreatedDrugFlushInfo(drugFlushInfo)
- service.DeleteDrugOutFlow(item.ID, item.OrgId)
- }
- 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.UpdateDrugMinNumber(item.Count, item.WarehouseInfoId)
- var sum_out_count int64
- sum_out_count = item.Count
- service.ModifyReduceDrugInformation(item.DrugId, sum_out_count, item.OrgId)
-
- service.DeleteDrugOutFlow(item.ID, item.OrgId)
- }
-
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.OrgId, item.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(item.DrugId, sum_count, item.OrgId)
-
- //出库数量累加
- 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.ReduceDrugCount(item.DrugId, item.OrgId, item.StorehouseId, out_count)
-
- //查询该药品剩余库存
- infolist, _ := service.FindDrugWarehouseInfoFlushCountByStorehouse(item.DrugId, item.OrgId, item.StorehouseId)
- 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.UpdateDrugStockCount(item.DrugId, item.OrgId, item.StorehouseId, over_count)
-
- }
- 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
- }
- }
|