stock_in_api_controller.go 199KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type StockManagerApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func StockManagerApiRegistRouters() {
  20. //入库管理和其他入库管理相关接口
  21. beego.Router("/api/warehouse/create", &StockManagerApiController{}, "post:CreateWarehouse")
  22. beego.Router("/api/warehouse/list", &StockManagerApiController{}, "get:GetWarehouseList")
  23. beego.Router("/api/warehouse/delete", &StockManagerApiController{}, "post:DeleteWarehouse")
  24. beego.Router("/api/warehouseinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseInfo")
  25. beego.Router("/api/warehouseinfo/list", &StockManagerApiController{}, "get:GetWarehouseInfoList")
  26. beego.Router("/api/warehouse/edit", &StockManagerApiController{}, "post:EditWarehouse")
  27. //退货管理和其他退货管理相关接口
  28. beego.Router("/api/salesreturn/create", &StockManagerApiController{}, "post:CreateSalesReturn")
  29. beego.Router("/api/salesreturn/delete", &StockManagerApiController{}, "post:DeleteSalesReturn")
  30. beego.Router("/api/salesreturninfo/delete", &StockManagerApiController{}, "post:DeleteSalesReturnInfo")
  31. beego.Router("/api/salesreturninfo/list", &StockManagerApiController{}, "get:GetSalesReturnInfoList")
  32. beego.Router("/api/salesreturn/list", &StockManagerApiController{}, "get:GetSalesReturnList")
  33. beego.Router("/api/salesreturn/edit", &StockManagerApiController{}, "post:EditReturnInfo")
  34. //出库管理和其他出库管理相关接口
  35. beego.Router("/api/warehouseout/create", &StockManagerApiController{}, "post:CreateWarehouseOut")
  36. beego.Router("/api/warehouseout/delete", &StockManagerApiController{}, "post:DeleteWarehouseOut")
  37. beego.Router("/api/warehouseoutinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseOutInfo")
  38. beego.Router("/api/warehouseout/list", &StockManagerApiController{}, "get:GetWarehouseOutList")
  39. beego.Router("/api/warehouseout/edit", &StockManagerApiController{}, "post:EditWarehouseOut")
  40. beego.Router("/api/warehouseout/info", &StockManagerApiController{}, "get:GetWarehouseOutInfoList")
  41. //出库退库管理和其他出库退库管理相关接口
  42. beego.Router("/api/cancelstock/create", &StockManagerApiController{}, "post:CreateCancelStock")
  43. beego.Router("/api/cancelstock/list", &StockManagerApiController{}, "get:GetCancelStockList")
  44. beego.Router("/api/cancelstock/info", &StockManagerApiController{}, "get:GetCancelStockInfoList")
  45. beego.Router("/api/cancelstock/delete", &StockManagerApiController{}, "post:DeleteCancelStock")
  46. beego.Router("/api/cancelstockinfo/delete", &StockManagerApiController{}, "post:DeleteCancelStockInfo")
  47. beego.Router("/api/cancelstockinfo/edit", &StockManagerApiController{}, "post:EditCancelStock")
  48. beego.Router("/api/cancelstockinfo/config", &StockManagerApiController{}, "get:GetCancelStockConfig")
  49. //库存相关全局配置
  50. beego.Router("/api/stock/config", &StockManagerApiController{}, "get:GetAllConfig")
  51. beego.Router("/api/return/config", &StockManagerApiController{}, "get:GetAllSalesReturnConfig")
  52. //库存查询
  53. beego.Router("/api/stock/query", &StockManagerApiController{}, "get:GetQueryInfo")
  54. beego.Router("/api/stock/detail", &StockManagerApiController{}, "get:GetDetailInfo")
  55. beego.Router("/api/warehouseout/user", &StockManagerApiController{}, "get:GetUserDetailInfo")
  56. beego.Router("/api/warehouseout/postsearchstock", &StockManagerApiController{}, "Get:PostSearchStock")
  57. beego.Router("/api/warehouseout/getoutstocktotalcount", &StockManagerApiController{}, "Get:GetOutStockTotalCount")
  58. beego.Router("/api/good/postgoodinformation", &StockManagerApiController{}, "Post:AddGoodInformation")
  59. beego.Router("/api/good/postdruginformation", &StockManagerApiController{}, "Post:AddDrugInformation")
  60. beego.Router("/api/good/initializtion", &StockManagerApiController{}, "Get:GetInitializtion")
  61. beego.Router("/api/good/getwarehouseorderinfolist", &StockManagerApiController{}, "Get:GetWarehouseOrderInfolist")
  62. beego.Router("/api/good/postsearchgoodlist", &StockManagerApiController{}, "Get:PostSearchGoodList")
  63. beego.Router("/api/good/getallstocklist", &StockManagerApiController{}, "Get:GetAllStockList")
  64. beego.Router("/api/stock/getstocklistbyid", &StockManagerApiController{}, "Get:GetStockListById")
  65. beego.Router("/api/stock/getstockoutlist", &StockManagerApiController{}, "Get:GetStockOutList")
  66. beego.Router("/api/good/getstockdrugcount", &StockManagerApiController{}, "Get:GetStockDrugCount")
  67. beego.Router("/api/good/getorderdetialbyorderid", &StockManagerApiController{}, "Get:GetOrderDetialByOrderId")
  68. beego.Router("/api/good/getorderdetaibyid", &StockManagerApiController{}, "Get:GetOrderDetailById")
  69. beego.Router("/api/good/getsingleoutorderdetail", &StockManagerApiController{}, "Get:GetSingleOutOrderDetail")
  70. beego.Router("/api/stock/getexportstocklist", &StockManagerApiController{}, "Get:GetExprotStockList")
  71. beego.Router("/api/stock/getoutexprotlist", &StockManagerApiController{}, "Get:GetOutExprotList")
  72. beego.Router("/api/stock/getsinglecancelorder", &StockManagerApiController{}, "Get:GetSingleCancelOrder")
  73. beego.Router("/api/stock/getcancelstockorderprint", &StockManagerApiController{}, "Get:GetCancelStockOrderPrint")
  74. beego.Router("/api/stock/getstockbatchnumber", &StockManagerApiController{}, "Get:GetStockBatchNumber")
  75. beego.Router("/api/stock/getstockflow", &StockManagerApiController{}, "Get:GetStockFlow")
  76. beego.Router("/api/cancel/getcancelexportlist", &StockManagerApiController{}, "Get:GetCancelExportList")
  77. //耗材调价
  78. beego.Router("/api/stock/postsearchgoodwarehouselist", &StockManagerApiController{}, "Get:GetSearchGoodWarehouseList")
  79. beego.Router("/api/stock/saveadjustprice", &StockManagerApiController{}, "Post:SaveAdjuestPrice")
  80. beego.Router("/api/stock/getallstockprice", &StockManagerApiController{}, "Get:GetAllStockPrice")
  81. beego.Router("/api/stock/savecheckedprice", &StockManagerApiController{}, "Get:SaveCheckPrice")
  82. beego.Router("/api/stock/getadjustpriceinfo", &StockManagerApiController{}, "Get:GetAdjustPriceById")
  83. beego.Router("/api/stock/savereportstock", &StockManagerApiController{}, "Post:SaveReportStock")
  84. beego.Router("/api/stock/getreportstocklist", &StockManagerApiController{}, "Get:GetReportStockList")
  85. beego.Router("/api/stock/savecheckdamage", &StockManagerApiController{}, "Get:SaveCheckDamage")
  86. beego.Router("/api/stock/saveinventory", &StockManagerApiController{}, "Post:SaveInventory")
  87. beego.Router("/api/stock/getinventorylist", &StockManagerApiController{}, "Get:GetInventorylist")
  88. beego.Router("/api/stock/savecheckinventory", &StockManagerApiController{}, "Get:SaveCheckInventory")
  89. beego.Router("/api/stock/getmodifypriceDetail", &StockManagerApiController{}, "Get:GetModifyPriceDetail")
  90. beego.Router("/api/stock/updatestockprice", &StockManagerApiController{}, "Get:UpdateStockPrice")
  91. beego.Router("/api/stock/deletestockprice", &StockManagerApiController{}, "Get:DeleteStockPrice")
  92. beego.Router("/api/stock/getstockdamagedetal", &StockManagerApiController{}, "Get:GetStockDamageDetail")
  93. beego.Router("/api/sotck/modifyprice", &StockManagerApiController{}, "Get:ModifyPrice")
  94. beego.Router("/api/stock/deletestockdamage", &StockManagerApiController{}, "Get:DeleteDamage")
  95. beego.Router("/api/stock/getstockdamagebyid", &StockManagerApiController{}, "Get:GetStockDamageById")
  96. beego.Router("api/sotck/getinventorydetail", &StockManagerApiController{}, "Get:GetInventoryDetail")
  97. beego.Router("/api/stock/modifyinventory", &StockManagerApiController{}, "Get:ModifyInventory")
  98. beego.Router("/api/stock/deleteinventory", &StockManagerApiController{}, "Get:DeleteInventory")
  99. beego.Router("/api/stock/getinventorydetaillist", &StockManagerApiController{}, "Get:GetInventoryDetailList")
  100. beego.Router("/api/stock/getinventoryprintlist", &StockManagerApiController{}, "Get:GetInventoryPrintList")
  101. beego.Router("/api/stock/getinventorydetailprintlist", &StockManagerApiController{}, "Get:GetInventoryDetailPrintList")
  102. beego.Router("/api/drug/deletedrugprice", &StockManagerApiController{}, "Get:DeleteDrugPrice")
  103. beego.Router("/api/stock/getgoodwarehouselist", &StockManagerApiController{}, "Get:GetGoodWarehouseList")
  104. beego.Router("/api/stock/proofinventory", &StockManagerApiController{}, "Get:ProofInventory")
  105. beego.Router("/api/stock/getwarehousetotal", &StockManagerApiController{}, "Get:GetWarehouseTotal")
  106. }
  107. func (c *StockManagerApiController) CreateWarehouse() {
  108. warehousing_time := c.GetString("warehousing_time")
  109. types, _ := c.GetInt64("type", 0)
  110. ctime := time.Now().Unix()
  111. adminUserInfo := c.GetAdminUserInfo()
  112. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  113. if parseDateErr != nil {
  114. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  116. return
  117. }
  118. timeStr := time.Now().Format("2006-01-02")
  119. timeArr := strings.Split(timeStr, "-")
  120. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  121. total = total + 1
  122. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  123. operation_time := time.Now().Unix()
  124. creater := adminUserInfo.AdminUser.Id
  125. warehousing := models.Warehousing{
  126. WarehousingOrder: warehousing_order,
  127. OperationTime: operation_time,
  128. OrgId: adminUserInfo.CurrentOrgId,
  129. Creater: creater,
  130. Ctime: ctime,
  131. Status: 1,
  132. WarehousingTime: warehousingDate.Unix(),
  133. Type: types,
  134. }
  135. service.AddSigleWarehouse(&warehousing)
  136. dataBody := make(map[string]interface{}, 0)
  137. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  138. if err != nil {
  139. utils.ErrorLog(err.Error())
  140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  141. return
  142. }
  143. var warehousingInfo []*models.WarehousingInfo
  144. var stockFlow []*models.VmStockFlow
  145. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  146. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  147. if len(thisStockIn) > 0 {
  148. for _, item := range thisStockIn {
  149. items := item.(map[string]interface{})
  150. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  151. utils.ErrorLog("good_id")
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  153. return
  154. }
  155. good_id := int64(items["good_id"].(float64))
  156. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  157. utils.ErrorLog("good_type_id")
  158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  159. return
  160. }
  161. good_type_id := int64(items["good_type_id"].(float64))
  162. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  163. utils.ErrorLog("warehousing_count")
  164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  165. return
  166. }
  167. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  168. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  169. utils.ErrorLog("price")
  170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  171. return
  172. }
  173. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  174. total := float64(warehousing_count) * price
  175. var productDates int64
  176. var expiryDates int64
  177. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  178. expiryDates = 0
  179. } else {
  180. if len(items["expiry_date"].(string)) == 0 {
  181. expiryDates = 0
  182. } else {
  183. expiryDate, _ := items["expiry_date"].(string)
  184. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  185. expiryDates = expiry_date.Unix()
  186. }
  187. }
  188. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  189. productDates = 0
  190. } else {
  191. if len(items["product_date"].(string)) == 0 {
  192. productDates = 0
  193. } else {
  194. productDate, _ := items["product_date"].(string)
  195. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  196. productDates = product_date.Unix()
  197. }
  198. }
  199. number, _ := items["number"].(string)
  200. remark, _ := items["remark"].(string)
  201. manufacturer := int64(items["manufacturer"].(float64))
  202. dealer := int64(items["dealer"].(float64))
  203. license_number, _ := items["license_number"].(string)
  204. //入库单表格
  205. warehouseInfo := &models.WarehousingInfo{
  206. WarehousingOrder: warehousing.WarehousingOrder,
  207. WarehousingId: warehousing.ID,
  208. GoodId: good_id,
  209. Number: number,
  210. GoodTypeId: good_type_id,
  211. ProductDate: productDates,
  212. ExpiryDate: expiryDates,
  213. WarehousingCount: warehousing_count,
  214. Price: price,
  215. TotalPrice: total,
  216. Status: 1,
  217. Ctime: ctime,
  218. Remark: remark,
  219. OrgId: adminUserInfo.CurrentOrgId,
  220. Type: types,
  221. Manufacturer: manufacturer,
  222. StockCount: warehousing_count,
  223. Dealer: dealer,
  224. LicenseNumber: license_number,
  225. }
  226. warehousingInfo = append(warehousingInfo, warehouseInfo)
  227. flow := &models.VmStockFlow{
  228. WarehousingOrder: warehousing.WarehousingOrder,
  229. WarehousingId: warehousing.ID,
  230. GoodId: good_id,
  231. Number: number,
  232. ProductDate: productDates,
  233. ExpireDate: expiryDates,
  234. Count: warehousing_count,
  235. Price: price,
  236. Status: 1,
  237. Ctime: ctime,
  238. UserOrgId: adminUserInfo.CurrentOrgId,
  239. Manufacturer: manufacturer,
  240. Dealer: dealer,
  241. LicenseNumber: license_number,
  242. IsEdit: 1,
  243. Creator: adminUserInfo.AdminUser.Id,
  244. SystemTime: operation_time,
  245. ConsumableType: 1,
  246. WarehousingDetailId: warehouseInfo.ID,
  247. }
  248. stockFlow = append(stockFlow, flow)
  249. }
  250. }
  251. }
  252. //入库单创建成功
  253. errs := service.CreateWarehousingInfo(warehousingInfo)
  254. //创建入库单流水
  255. service.CreateStockFlow(stockFlow)
  256. info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
  257. for _, item := range warehousingInfo {
  258. goodInfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  259. str := strconv.FormatInt(item.WarehousingCount, 10)
  260. minFloat, _ := strconv.ParseFloat(str, 64)
  261. good := models.GoodInfo{
  262. Total: minFloat + goodInfo.Total,
  263. }
  264. //更该库存
  265. parseDateErr := service.UpdateGoodInfoList(good, goodInfo.ID)
  266. break
  267. fmt.Println(parseDateErr)
  268. }
  269. if errs != nil {
  270. utils.ErrorLog(errs.Error())
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  272. return
  273. }
  274. c.ServeSuccessJSON(map[string]interface{}{
  275. "msg": "入库成功",
  276. "warehousing_order": warehousing_order,
  277. "info": info,
  278. })
  279. }
  280. func (c *StockManagerApiController) GetWarehouseList() {
  281. page, _ := c.GetInt64("page", -1)
  282. limit, _ := c.GetInt64("limit", -1)
  283. start_time := c.GetString("start_time")
  284. end_time := c.GetString("end_time")
  285. types, _ := c.GetInt64("type", 0)
  286. keywords := c.GetString("keywords")
  287. timeLayout := "2006-01-02"
  288. loc, _ := time.LoadLocation("Local")
  289. var startTime int64
  290. if len(start_time) > 0 {
  291. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  292. if err != nil {
  293. fmt.Println(err)
  294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  295. return
  296. }
  297. startTime = theTime.Unix()
  298. }
  299. var endTime int64
  300. if len(end_time) > 0 {
  301. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  302. if err != nil {
  303. utils.ErrorLog(err.Error())
  304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  305. return
  306. }
  307. endTime = theTime.Unix()
  308. }
  309. adminUserInfo := c.GetAdminUserInfo()
  310. var ids []int64
  311. var goodids []int64
  312. //查询商品名称
  313. if len(keywords) > 0 {
  314. //查询商品名称
  315. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  316. for _, item := range list {
  317. goodids = append(goodids, item.ID)
  318. //入库详情但里面查询
  319. }
  320. if len(goodids) > 0 {
  321. info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  322. for _, it := range info {
  323. ids = append(ids, it.WarehousingId)
  324. }
  325. }
  326. }
  327. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  328. if err == nil {
  329. c.ServeSuccessJSON(map[string]interface{}{
  330. "list": warehouseList,
  331. "total": total,
  332. })
  333. } else {
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  335. }
  336. }
  337. func (c *StockManagerApiController) GetWarehouseInfoList() {
  338. id := c.GetString("id")
  339. idArray := strings.Split(id, ",")
  340. warehousing, err := service.FindWarehousingByIdOne(idArray)
  341. if err != nil {
  342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  343. return
  344. }
  345. var ids []int64
  346. for _, item := range warehousing {
  347. ids = append(ids, item.ID)
  348. }
  349. warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
  350. if err == nil {
  351. c.ServeSuccessJSON(map[string]interface{}{
  352. "info": warehousingInfo,
  353. "warehousing": warehousing,
  354. })
  355. } else {
  356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  357. }
  358. }
  359. func (c *StockManagerApiController) EditWarehouse() {
  360. warehousing_time := c.GetString("warehousing_time")
  361. id, _ := c.GetInt64("id", 0)
  362. types, _ := c.GetInt64("type", 0)
  363. if id == 0 {
  364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  365. return
  366. }
  367. ctime := time.Now().Unix()
  368. mtime := time.Now().Unix()
  369. adminUserInfo := c.GetAdminUserInfo()
  370. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  371. if parseDateErr != nil {
  372. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  374. return
  375. }
  376. warehouse, _ := service.FindWarehousingById(id)
  377. warehousing := models.Warehousing{
  378. WarehousingOrder: warehouse.WarehousingOrder,
  379. OrgId: adminUserInfo.CurrentOrgId,
  380. Modifier: adminUserInfo.AdminUser.Id,
  381. Mtime: mtime,
  382. Status: 1,
  383. WarehousingTime: warehousingDate.Unix(),
  384. Type: warehouse.Type,
  385. }
  386. service.EditWarehousing(warehousing)
  387. dataBody := make(map[string]interface{}, 0)
  388. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  389. if err != nil {
  390. utils.ErrorLog(err.Error())
  391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  392. return
  393. }
  394. var warehousingInfo []*models.WarehousingInfo
  395. var upDateWarehousingInfo []*models.WarehousingInfo
  396. var stockFlow []*models.VmStockFlow
  397. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  398. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  399. if len(thisStockIn) > 0 {
  400. for _, item := range thisStockIn {
  401. items := item.(map[string]interface{})
  402. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  403. utils.ErrorLog("good_id")
  404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  405. return
  406. }
  407. good_id := int64(items["good_id"].(float64))
  408. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  409. utils.ErrorLog("good_type_id")
  410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  411. return
  412. }
  413. good_type_id := int64(items["good_type_id"].(float64))
  414. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  415. utils.ErrorLog("warehousing_count")
  416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  417. return
  418. }
  419. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  420. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  421. utils.ErrorLog("price")
  422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  423. return
  424. }
  425. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  426. total := float64(warehousing_count) * price
  427. var productDates int64
  428. var expiryDates int64
  429. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  430. expiryDates = 0
  431. } else {
  432. if len(items["expiry_date"].(string)) == 0 {
  433. expiryDates = 0
  434. } else {
  435. expiryDate, _ := items["expiry_date"].(string)
  436. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  437. expiryDates = expiry_date.Unix()
  438. }
  439. }
  440. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  441. productDates = 0
  442. } else {
  443. if len(items["product_date"].(string)) == 0 {
  444. productDates = 0
  445. } else {
  446. productDate, _ := items["product_date"].(string)
  447. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  448. productDates = product_date.Unix()
  449. }
  450. }
  451. number, _ := items["number"].(string)
  452. remark, _ := items["remark"].(string)
  453. manufacturer := int64(items["manufacturer"].(float64))
  454. dealer := int64(items["dealer"].(float64))
  455. license_number, _ := items["license_number"].(string)
  456. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  457. utils.ErrorLog("id")
  458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  459. return
  460. }
  461. id := int64(items["id"].(float64))
  462. if id == 0 {
  463. warehouseInfo := &models.WarehousingInfo{
  464. WarehousingOrder: warehouse.WarehousingOrder,
  465. WarehousingId: warehouse.ID,
  466. GoodId: good_id,
  467. Number: number,
  468. GoodTypeId: good_type_id,
  469. ProductDate: productDates,
  470. ExpiryDate: expiryDates,
  471. WarehousingCount: warehousing_count,
  472. Price: price,
  473. TotalPrice: total,
  474. Status: 1,
  475. Ctime: ctime,
  476. Remark: remark,
  477. OrgId: adminUserInfo.CurrentOrgId,
  478. Type: types,
  479. Manufacturer: manufacturer,
  480. Dealer: dealer,
  481. StockCount: warehousing_count,
  482. LicenseNumber: license_number,
  483. }
  484. warehousingInfo = append(warehousingInfo, warehouseInfo)
  485. flow := &models.VmStockFlow{
  486. WarehousingOrder: warehousing.WarehousingOrder,
  487. WarehousingId: warehousing.ID,
  488. GoodId: good_id,
  489. Number: number,
  490. ProductDate: productDates,
  491. ExpireDate: expiryDates,
  492. Count: warehousing_count,
  493. Price: price,
  494. Status: 1,
  495. Ctime: ctime,
  496. UserOrgId: adminUserInfo.CurrentOrgId,
  497. Manufacturer: manufacturer,
  498. Dealer: dealer,
  499. LicenseNumber: license_number,
  500. IsEdit: 1,
  501. Creator: adminUserInfo.AdminUser.Id,
  502. SystemTime: ctime,
  503. ConsumableType: 1,
  504. WarehousingDetailId: warehouseInfo.ID,
  505. }
  506. stockFlow = append(stockFlow, flow)
  507. } else {
  508. fmt.Println("id23233232323232323232323223", id)
  509. warehouseInfo := &models.WarehousingInfo{
  510. ID: id,
  511. WarehousingOrder: warehouse.WarehousingOrder,
  512. WarehousingId: warehouse.ID,
  513. GoodId: good_id,
  514. Number: number,
  515. GoodTypeId: good_type_id,
  516. ProductDate: productDates,
  517. ExpiryDate: expiryDates,
  518. WarehousingCount: warehousing_count,
  519. Price: price,
  520. TotalPrice: total,
  521. Status: 1,
  522. Ctime: ctime,
  523. Remark: remark,
  524. OrgId: adminUserInfo.CurrentOrgId,
  525. Type: types,
  526. Manufacturer: manufacturer,
  527. Dealer: dealer,
  528. LicenseNumber: license_number,
  529. }
  530. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  531. flow := &models.VmStockFlow{
  532. WarehousingOrder: warehousing.WarehousingOrder,
  533. WarehousingId: id,
  534. GoodId: good_id,
  535. Number: number,
  536. ProductDate: productDates,
  537. ExpireDate: expiryDates,
  538. Count: warehousing_count,
  539. Price: price,
  540. Status: 1,
  541. Ctime: ctime,
  542. UserOrgId: adminUserInfo.CurrentOrgId,
  543. Manufacturer: manufacturer,
  544. Dealer: dealer,
  545. LicenseNumber: license_number,
  546. IsEdit: 2,
  547. Creator: adminUserInfo.AdminUser.Id,
  548. SystemTime: ctime,
  549. ConsumableType: 1,
  550. WarehousingDetailId: warehouseInfo.ID,
  551. }
  552. stockFlow = append(stockFlow, flow)
  553. }
  554. }
  555. }
  556. }
  557. var errs error
  558. if len(warehousingInfo) > 0 {
  559. errs = service.CreateWarehousingInfo(warehousingInfo)
  560. service.CreateStockFlow(stockFlow)
  561. }
  562. if len(upDateWarehousingInfo) > 0 {
  563. for _, item := range upDateWarehousingInfo {
  564. var total int64
  565. var all_total int64
  566. //获取该批次该型号的库存
  567. info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
  568. fmt.Println("oooooooooo", info.WarehousingCount)
  569. //判断 该批次的入库数量
  570. total = item.WarehousingCount - info.WarehousingCount
  571. fmt.Println("total232323322332232332", total)
  572. all_total = info.StockCount + total
  573. item.StockCount = all_total
  574. fmt.Println("hhhhhhhhhhhhh", item.StockCount)
  575. errs = service.UpDateWarehousingInfo(item)
  576. }
  577. }
  578. if len(stockFlow) > 0 {
  579. for _, item := range stockFlow {
  580. flow := models.VmStockFlow{
  581. Count: item.Count,
  582. }
  583. parseDateErr := service.UpdateStockFlow(flow, item.GoodId, item.WarehousingId)
  584. fmt.Println(parseDateErr)
  585. }
  586. }
  587. if errs != nil {
  588. utils.ErrorLog(errs.Error())
  589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  590. return
  591. }
  592. c.ServeSuccessJSON(map[string]interface{}{
  593. "msg": "编辑成功",
  594. })
  595. }
  596. func (c *StockManagerApiController) DeleteWarehouse() {
  597. ids := c.GetString("ids")
  598. if len(ids) == 0 {
  599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  600. return
  601. }
  602. idArray := strings.Split(ids, ",")
  603. err := service.DeleteWarehouse(idArray)
  604. if err != nil {
  605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  606. } else {
  607. c.ServeSuccessJSON(map[string]interface{}{
  608. "msg": "删除成功",
  609. })
  610. }
  611. }
  612. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  613. id, _ := c.GetInt64("id", 0)
  614. if id == 0 {
  615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  616. return
  617. }
  618. err := service.UpDateWarehouseStatus(id)
  619. if err != nil {
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  621. } else {
  622. c.ServeSuccessJSON(map[string]interface{}{
  623. "msg": "删除成功",
  624. })
  625. }
  626. }
  627. func (c *StockManagerApiController) CreateSalesReturn() {
  628. dealer_id, _ := c.GetInt64("dealer_id", 0)
  629. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  630. sales_return_time := c.GetString("time")
  631. types, _ := c.GetInt64("type", 0)
  632. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  633. if parseDateErr != nil {
  634. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  636. return
  637. }
  638. adminUserInfo := c.GetAdminUserInfo()
  639. operation_time := time.Now().Unix()
  640. creater := adminUserInfo.AdminUser.Id
  641. ctime := time.Now().Unix()
  642. timeStr := time.Now().Format("2006-01-02")
  643. timeArr := strings.Split(timeStr, "-")
  644. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  645. total = total + 1
  646. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  647. salesReturn := models.SalesReturn{
  648. OrderNumber: orderNumber,
  649. OperaTime: operation_time,
  650. OrgId: adminUserInfo.CurrentOrgId,
  651. Creater: creater,
  652. Ctime: ctime,
  653. Status: 1,
  654. ReturnTime: salesReturnDate.Unix(),
  655. Dealer: dealer_id,
  656. Manufacturer: manufacturer_id,
  657. Type: types,
  658. }
  659. service.AddSigleSalesReturn(&salesReturn)
  660. dataBody := make(map[string]interface{}, 0)
  661. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  662. if err != nil {
  663. utils.ErrorLog(err.Error())
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  665. return
  666. }
  667. var salesReturnInfos []*models.SalesReturnInfo
  668. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  669. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  670. if len(thisStockIn) > 0 {
  671. for _, item := range thisStockIn {
  672. items := item.(map[string]interface{})
  673. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  674. utils.ErrorLog("good_id")
  675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  676. return
  677. }
  678. good_id := int64(items["good_id"].(float64))
  679. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  680. utils.ErrorLog("good_type_id")
  681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  682. return
  683. }
  684. good_type_id := int64(items["good_type_id"].(float64))
  685. return_count, _ := items["return_count"].(string)
  686. if len(return_count) == 0 {
  687. utils.ErrorLog("len(return_count) == 0")
  688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  689. return
  690. }
  691. count, _ := strconv.ParseInt(return_count, 10, 64)
  692. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  693. total := float64(count) * price
  694. salesReturnInfo := &models.SalesReturnInfo{
  695. OrderNumber: salesReturn.OrderNumber,
  696. SalesReturnId: salesReturn.ID,
  697. GoodId: good_id,
  698. GoodTypeId: good_type_id,
  699. Count: count,
  700. Price: price,
  701. Total: total,
  702. Status: 1,
  703. Ctime: ctime,
  704. OrgId: adminUserInfo.CurrentOrgId,
  705. Type: types,
  706. Manufacturer: manufacturer_id,
  707. Dealer: dealer_id,
  708. }
  709. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  710. }
  711. }
  712. }
  713. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  714. if errs != nil {
  715. utils.ErrorLog(errs.Error())
  716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  717. return
  718. }
  719. c.ServeSuccessJSON(map[string]interface{}{
  720. "msg": "退货成功",
  721. })
  722. }
  723. func (c *StockManagerApiController) GetSalesReturnList() {
  724. page, _ := c.GetInt64("page", -1)
  725. limit, _ := c.GetInt64("limit", -1)
  726. start_time := c.GetString("start_time")
  727. end_time := c.GetString("end_time")
  728. types, _ := c.GetInt64("type", 0)
  729. keywords := c.GetString("keywords")
  730. timeLayout := "2006-01-02"
  731. loc, _ := time.LoadLocation("Local")
  732. var startTime int64
  733. if len(start_time) > 0 {
  734. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  735. if err != nil {
  736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  737. return
  738. }
  739. startTime = theTime.Unix()
  740. }
  741. var endTime int64
  742. if len(end_time) > 0 {
  743. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  744. if err != nil {
  745. utils.ErrorLog(err.Error())
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  747. return
  748. }
  749. endTime = theTime.Unix()
  750. }
  751. adminUserInfo := c.GetAdminUserInfo()
  752. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  753. if err == nil {
  754. c.ServeSuccessJSON(map[string]interface{}{
  755. "list": returnList,
  756. "total": total,
  757. })
  758. } else {
  759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  760. }
  761. }
  762. func (this *StockManagerApiController) DeleteSalesReturn() {
  763. ids := this.GetString("ids")
  764. if len(ids) == 0 {
  765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  766. return
  767. }
  768. idArray := strings.Split(ids, ",")
  769. err := service.DeleteSalesReturn(idArray)
  770. if err != nil {
  771. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  772. } else {
  773. this.ServeSuccessJSON(map[string]interface{}{
  774. "msg": "删除成功",
  775. })
  776. }
  777. }
  778. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  779. id, _ := this.GetInt64("id", 0)
  780. fmt.Println(id)
  781. if id == 0 {
  782. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  783. return
  784. }
  785. err := service.UpDateSaleReturnStatus(id)
  786. if err != nil {
  787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  788. } else {
  789. this.ServeSuccessJSON(map[string]interface{}{
  790. "msg": "删除成功",
  791. })
  792. }
  793. }
  794. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  795. id, _ := this.GetInt64("id", 0)
  796. list, _ := service.FindAllSalesReturnInfoById(id)
  797. salesReturn, _ := service.FindAllSalesReturnById(id)
  798. this.ServeSuccessJSON(map[string]interface{}{
  799. "list": list,
  800. "salesReturn": salesReturn,
  801. })
  802. }
  803. func (c *StockManagerApiController) EditReturnInfo() {
  804. return_time := c.GetString("return_time")
  805. id, _ := c.GetInt64("id", 0)
  806. types, _ := c.GetInt64("type", 0)
  807. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  808. dealer_id, _ := c.GetInt64("dealer_id", 0)
  809. if id == 0 {
  810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  811. return
  812. }
  813. ctime := time.Now().Unix()
  814. mtime := time.Now().Unix()
  815. adminUserInfo := c.GetAdminUserInfo()
  816. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  817. if parseDateErr != nil {
  818. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  820. return
  821. }
  822. salesReturns, _ := service.FindSalesReturnById(id)
  823. sales := models.SalesReturn{
  824. ID: salesReturns.ID,
  825. Mtime: mtime,
  826. ReturnTime: returnDate.Unix(),
  827. Manufacturer: manufacturer_id,
  828. Dealer: dealer_id,
  829. }
  830. service.EditSaleReturn(sales)
  831. dataBody := make(map[string]interface{}, 0)
  832. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  833. if err != nil {
  834. utils.ErrorLog(err.Error())
  835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  836. return
  837. }
  838. var returnInfos []*models.SalesReturnInfo
  839. var upDateReturnInfos []*models.SalesReturnInfo
  840. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  841. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  842. if len(thisStockIn) > 0 {
  843. for _, item := range thisStockIn {
  844. items := item.(map[string]interface{})
  845. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  846. utils.ErrorLog("good_id")
  847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  848. return
  849. }
  850. good_id := int64(items["good_id"].(float64))
  851. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  852. utils.ErrorLog("good_type_id")
  853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  854. return
  855. }
  856. good_type_id := int64(items["good_type_id"].(float64))
  857. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  858. utils.ErrorLog("count")
  859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  860. return
  861. }
  862. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  863. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  864. utils.ErrorLog("id")
  865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  866. return
  867. }
  868. id := int64(items["id"].(float64))
  869. if id == 0 {
  870. returnInfo := &models.SalesReturnInfo{
  871. GoodId: good_id,
  872. GoodTypeId: good_type_id,
  873. Count: count,
  874. Status: 1,
  875. Ctime: ctime,
  876. OrgId: adminUserInfo.CurrentOrgId,
  877. OrderNumber: sales.OrderNumber,
  878. SalesReturnId: sales.ID,
  879. Mtime: time.Now().Unix(),
  880. Type: types,
  881. Manufacturer: manufacturer_id,
  882. Dealer: dealer_id,
  883. }
  884. returnInfos = append(returnInfos, returnInfo)
  885. } else {
  886. returnInfo := &models.SalesReturnInfo{
  887. ID: id,
  888. GoodId: good_id,
  889. GoodTypeId: good_type_id,
  890. Count: count,
  891. Status: 1,
  892. Ctime: ctime,
  893. OrgId: adminUserInfo.CurrentOrgId,
  894. OrderNumber: sales.OrderNumber,
  895. SalesReturnId: sales.ID,
  896. Mtime: time.Now().Unix(),
  897. Type: types,
  898. Manufacturer: manufacturer_id,
  899. Dealer: dealer_id,
  900. }
  901. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  902. }
  903. }
  904. }
  905. }
  906. var errs error
  907. if len(returnInfos) > 0 {
  908. errs = service.CreateSalesReturnInfo(returnInfos)
  909. }
  910. if len(upDateReturnInfos) > 0 {
  911. for _, item := range upDateReturnInfos {
  912. errs = service.UpDateSalesReturnInfo(item)
  913. }
  914. }
  915. if errs != nil {
  916. utils.ErrorLog(errs.Error())
  917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  918. return
  919. }
  920. c.ServeSuccessJSON(map[string]interface{}{
  921. "msg": "编辑成功",
  922. })
  923. }
  924. func (c *StockManagerApiController) CreateWarehouseOut() {
  925. types, _ := c.GetInt64("type", 0)
  926. ctime := time.Now().Unix()
  927. adminUserInfo := c.GetAdminUserInfo()
  928. warehousing_out_time := c.GetString("warehousing_out_time")
  929. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  930. if parseDateErr != nil {
  931. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  933. return
  934. }
  935. timeStr := time.Now().Format("2006-01-02")
  936. timeArr := strings.Split(timeStr, "-")
  937. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  938. total = total + 1
  939. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  940. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  941. number = number + total
  942. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  943. operation_time := time.Now().Unix()
  944. creater := adminUserInfo.AdminUser.Id
  945. warehouseOut := models.WarehouseOut{
  946. WarehouseOutOrderNumber: warehousing_out_order,
  947. OperationTime: operation_time,
  948. OrgId: adminUserInfo.CurrentOrgId,
  949. Creater: creater,
  950. Ctime: ctime,
  951. Status: 1,
  952. WarehouseOutTime: warehousingOutDate.Unix(),
  953. Type: types,
  954. }
  955. dataBody := make(map[string]interface{}, 0)
  956. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  957. if err != nil {
  958. utils.ErrorLog(err.Error())
  959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  960. return
  961. }
  962. var warehousingOutInfo []*models.WarehouseOutInfo
  963. var beforePrepares []*models.DialysisBeforePrepareGoods
  964. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  965. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  966. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  967. if len(thisStockIn) > 0 {
  968. for _, item := range thisStockIn {
  969. items := item.(map[string]interface{})
  970. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  971. utils.ErrorLog("good_id")
  972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  973. return
  974. }
  975. good_id := int64(items["good_id"].(float64))
  976. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  977. utils.ErrorLog("good_type_id")
  978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  979. return
  980. }
  981. good_type_id := int64(items["good_type_id"].(float64))
  982. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  983. utils.ErrorLog("count")
  984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  985. return
  986. }
  987. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  988. utils.ErrorLog("price")
  989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  990. return
  991. }
  992. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  993. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  994. total := float64(count) * price
  995. remark := items["remark"].(string)
  996. manufacturer := int64(items["manufacturer"].(float64))
  997. dealer := int64(items["dealer"].(float64))
  998. number := items["number"].(string)
  999. expiry_date := items["expiry_date"].(string)
  1000. timeLayout := "2006-01-02"
  1001. loc, _ := time.LoadLocation("Local")
  1002. var expiryDate int64
  1003. if len(expiry_date) > 0 {
  1004. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1005. if err != nil {
  1006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1007. return
  1008. }
  1009. expiryDate = theTime.Unix()
  1010. }
  1011. product_date := items["product_date"].(string)
  1012. var productDate int64
  1013. if len(product_date) > 0 {
  1014. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1015. if err != nil {
  1016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1017. return
  1018. }
  1019. productDate = theTime.Unix()
  1020. }
  1021. license_number := items["license_number"].(string)
  1022. warehouseOutInfo := &models.WarehouseOutInfo{
  1023. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1024. WarehouseOutId: warehouseOut.ID,
  1025. GoodId: good_id,
  1026. GoodTypeId: good_type_id,
  1027. Count: count,
  1028. Price: price,
  1029. TotalPrice: total,
  1030. Status: 1,
  1031. Ctime: ctime,
  1032. Remark: remark,
  1033. OrgId: adminUserInfo.CurrentOrgId,
  1034. Type: types,
  1035. Manufacturer: manufacturer,
  1036. Number: number,
  1037. ExpiryDate: expiryDate,
  1038. ProductDate: productDate,
  1039. Dealer: dealer,
  1040. LicenseNumber: license_number,
  1041. }
  1042. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1043. prepareGoods := &models.DialysisBeforePrepareGoods{
  1044. GoodTypeId: good_type_id,
  1045. GoodId: good_id,
  1046. Count: count,
  1047. }
  1048. beforePrepares = append(beforePrepares, prepareGoods)
  1049. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  1050. GoodTypeId: good_type_id,
  1051. GoodId: good_id,
  1052. Count: count,
  1053. }
  1054. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  1055. }
  1056. }
  1057. }
  1058. //出库逻辑
  1059. for _, item := range warehousingOutInfo {
  1060. //查询库存
  1061. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
  1062. fmt.Println("库存数量组吗", warehouse.Count)
  1063. if item.Count > warehouse.Count {
  1064. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1065. c.ServeSuccessJSON(map[string]interface{}{
  1066. "msg": "1",
  1067. "good_name": goodObj.GoodName,
  1068. "specification_name": goodObj.SpecificationName,
  1069. })
  1070. return
  1071. } else {
  1072. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  1073. if errcodes == gorm.ErrRecordNotFound {
  1074. service.AddSigleWarehouseOut(&warehouseOut)
  1075. }
  1076. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
  1077. if parseDateErr != nil {
  1078. utils.ErrorLog(parseDateErr.Error())
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1080. return
  1081. }
  1082. c.ServeSuccessJSON(map[string]interface{}{
  1083. "msg": "2",
  1084. "good_name": "",
  1085. "specification_name": "",
  1086. })
  1087. }
  1088. }
  1089. //errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
  1090. //info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
  1091. }
  1092. func (c *StockManagerApiController) GetWarehouseOutList() {
  1093. page, _ := c.GetInt64("page", -1)
  1094. limit, _ := c.GetInt64("limit", -1)
  1095. start_time := c.GetString("start_time")
  1096. end_time := c.GetString("end_time")
  1097. types, _ := c.GetInt64("type", 0)
  1098. keywords := c.GetString("keywords")
  1099. timeLayout := "2006-01-02"
  1100. loc, _ := time.LoadLocation("Local")
  1101. var startTime int64
  1102. if len(start_time) > 0 {
  1103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1104. if err != nil {
  1105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1106. return
  1107. }
  1108. startTime = theTime.Unix()
  1109. }
  1110. var endTime int64
  1111. if len(end_time) > 0 {
  1112. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1113. if err != nil {
  1114. utils.ErrorLog(err.Error())
  1115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1116. return
  1117. }
  1118. endTime = theTime.Unix()
  1119. }
  1120. adminUserInfo := c.GetAdminUserInfo()
  1121. var ids []int64
  1122. var goodids []int64
  1123. if len(keywords) > 0 {
  1124. //查询商品名称
  1125. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  1126. for _, item := range list {
  1127. goodids = append(goodids, item.ID)
  1128. }
  1129. if len(goodids) > 0 {
  1130. //出库详情但里面查询
  1131. info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  1132. for _, it := range info {
  1133. ids = append(ids, it.WarehouseOutId)
  1134. }
  1135. }
  1136. }
  1137. warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  1138. fmt.Println(err)
  1139. if err == nil {
  1140. c.ServeSuccessJSON(map[string]interface{}{
  1141. "list": warehouseOutList,
  1142. "total": total,
  1143. })
  1144. } else {
  1145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1146. }
  1147. }
  1148. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1149. ids := c.GetString("ids")
  1150. if len(ids) == 0 {
  1151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1152. return
  1153. }
  1154. idArray := strings.Split(ids, ",")
  1155. err := service.DeleteWarehouseOut(idArray)
  1156. if err != nil {
  1157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1158. } else {
  1159. c.ServeSuccessJSON(map[string]interface{}{
  1160. "msg": "删除成功",
  1161. })
  1162. }
  1163. }
  1164. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1165. id, _ := this.GetInt64("id", 0)
  1166. fmt.Println(id)
  1167. if id == 0 {
  1168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1169. return
  1170. }
  1171. err := service.UpDateWarehouseOutStatus(id)
  1172. if err != nil {
  1173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1174. } else {
  1175. this.ServeSuccessJSON(map[string]interface{}{
  1176. "msg": "删除成功",
  1177. })
  1178. }
  1179. }
  1180. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1181. id, _ := c.GetInt64("id", 0)
  1182. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1183. warehouseOut, _ := service.FindWareHouseOutById(id)
  1184. adminUserInfo := c.GetAdminUserInfo()
  1185. orgId := adminUserInfo.CurrentOrgId
  1186. wareoutList, _ := service.GetWareOutInfoById(id, orgId)
  1187. c.ServeSuccessJSON(map[string]interface{}{
  1188. "list": warehouseOutInfo,
  1189. "info": warehouseOut,
  1190. "wareoutList": wareoutList,
  1191. })
  1192. }
  1193. func (c *StockManagerApiController) EditWarehouseOut() {
  1194. warehouse_out_time := c.GetString("warehouse_out_time")
  1195. id, _ := c.GetInt64("id", 0)
  1196. types, _ := c.GetInt64("type", 0)
  1197. if id == 0 {
  1198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1199. return
  1200. }
  1201. ctime := time.Now().Unix()
  1202. mtime := time.Now().Unix()
  1203. adminUserInfo := c.GetAdminUserInfo()
  1204. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1205. if parseDateErr != nil {
  1206. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1208. return
  1209. }
  1210. warehouseOut, _ := service.FindWareHouseOutById(id)
  1211. tempWarehouseOut := models.WarehouseOut{
  1212. ID: warehouseOut.ID,
  1213. Mtime: mtime,
  1214. WarehouseOutTime: warehouseOutDate.Unix(),
  1215. }
  1216. service.EditWarehouseOut(tempWarehouseOut)
  1217. dataBody := make(map[string]interface{}, 0)
  1218. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1219. if err != nil {
  1220. utils.ErrorLog(err.Error())
  1221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1222. return
  1223. }
  1224. var warehousingOutInfo []*models.WarehouseOutInfo
  1225. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1226. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1227. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1228. if len(thisStockOut) > 0 {
  1229. for _, item := range thisStockOut {
  1230. items := item.(map[string]interface{})
  1231. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1232. utils.ErrorLog("good_id")
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1234. return
  1235. }
  1236. good_id := int64(items["good_id"].(float64))
  1237. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1238. utils.ErrorLog("good_type_id")
  1239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1240. return
  1241. }
  1242. good_type_id := int64(items["good_type_id"].(float64))
  1243. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1244. utils.ErrorLog("count")
  1245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1246. return
  1247. }
  1248. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1249. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1250. utils.ErrorLog("price")
  1251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1252. return
  1253. }
  1254. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1255. total := float64(count) * price
  1256. remark := items["remark"].(string)
  1257. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1258. utils.ErrorLog("id")
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1260. return
  1261. }
  1262. id := int64(items["id"].(float64))
  1263. manufacturer := int64(items["manufacturer"].(float64))
  1264. dealer := int64(items["dealer"].(float64))
  1265. number := items["number"].(string)
  1266. license_number := items["license_number"].(string)
  1267. timeLayout := "2006-01-02"
  1268. loc, _ := time.LoadLocation("Local")
  1269. expiry_date := items["expiry_date"].(string)
  1270. var expiryDate int64
  1271. if len(expiry_date) > 0 {
  1272. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1273. if err != nil {
  1274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1275. return
  1276. }
  1277. expiryDate = theTime.Unix()
  1278. }
  1279. product_date := items["product_date"].(string)
  1280. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1281. var productDate int64
  1282. if len(product_date) > 0 {
  1283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1284. if err != nil {
  1285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1286. return
  1287. }
  1288. productDate = theTime.Unix()
  1289. }
  1290. if id == 0 {
  1291. warehouseOutInfo := &models.WarehouseOutInfo{
  1292. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1293. WarehouseOutId: warehouseOut.ID,
  1294. GoodId: good_id,
  1295. GoodTypeId: good_type_id,
  1296. Count: count,
  1297. Price: price,
  1298. TotalPrice: total,
  1299. Status: 1,
  1300. Ctime: ctime,
  1301. Remark: remark,
  1302. OrgId: adminUserInfo.CurrentOrgId,
  1303. Type: types,
  1304. IsSys: 0,
  1305. SysRecordTime: 0,
  1306. Number: number,
  1307. ExpiryDate: expiryDate,
  1308. ProductDate: productDate,
  1309. Dealer: dealer,
  1310. Manufacturer: manufacturer,
  1311. LicenseNumber: license_number,
  1312. ConsumableType: 1,
  1313. WarehouseInfotId: warehouse_info_id,
  1314. }
  1315. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1316. } else {
  1317. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1318. utils.ErrorLog("is_sys")
  1319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1320. return
  1321. }
  1322. is_sys := int64(items["is_sys"].(float64))
  1323. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1324. utils.ErrorLog("sys_record_time")
  1325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1326. return
  1327. }
  1328. sys_record_time := int64(items["sys_record_time"].(float64))
  1329. warehouseOutInfo := &models.WarehouseOutInfo{
  1330. ID: id,
  1331. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1332. WarehouseOutId: warehouseOut.ID,
  1333. GoodId: good_id,
  1334. GoodTypeId: good_type_id,
  1335. Count: count,
  1336. Price: price,
  1337. TotalPrice: total,
  1338. Status: 1,
  1339. Ctime: ctime,
  1340. Remark: remark,
  1341. OrgId: adminUserInfo.CurrentOrgId,
  1342. Mtime: time.Now().Unix(),
  1343. Type: types,
  1344. Manufacturer: manufacturer,
  1345. IsSys: is_sys,
  1346. SysRecordTime: sys_record_time,
  1347. Number: number,
  1348. ExpiryDate: expiryDate,
  1349. ProductDate: productDate,
  1350. Dealer: dealer,
  1351. LicenseNumber: license_number,
  1352. ConsumableType: 2,
  1353. WarehouseInfotId: warehouse_info_id,
  1354. }
  1355. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1356. }
  1357. }
  1358. }
  1359. }
  1360. var errs error
  1361. if len(warehousingOutInfo) > 0 {
  1362. errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
  1363. }
  1364. if len(upDateWarehouseOutInfos) > 0 {
  1365. for _, item := range upDateWarehouseOutInfos {
  1366. //1.查询该耗材该批次的最后一次出库记录
  1367. lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, adminUserInfo.CurrentOrgId)
  1368. fmt.Println("lastGood", lastGood.Count)
  1369. fmt.Println("item2323232", item.Count)
  1370. // 退库的库存和该耗材该批次最后一次出库数量进行比较
  1371. //如果退库数量大于 最后一次批次的数量(要么要进行出库)
  1372. if item.Count > lastGood.Count {
  1373. //查询该耗材是否还有库存
  1374. warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
  1375. fmt.Println("hhhhhh23h2323232", warehouseinfo.StockCount)
  1376. //无库存
  1377. if warehouseinfo.StockCount <= 0 {
  1378. c.ServeSuccessJSON(map[string]interface{}{
  1379. "msg": "5",
  1380. })
  1381. return
  1382. }
  1383. //有库存,进行出库,调用出库接口
  1384. if warehouseinfo.StockCount > 0 {
  1385. var total int64
  1386. var stock_cout int64
  1387. var total_count int64
  1388. //计算和最后一次出库数据的差
  1389. total = item.Count - lastGood.Count
  1390. fmt.Println("total22323232", total)
  1391. //获取该耗材该批次的剩余库存量
  1392. info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1393. fmt.Println("info2232323232323", info)
  1394. //判断该批次的剩余库存 和出库的库存进行比较
  1395. //如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
  1396. if item.Count > info.StockCount {
  1397. //计算出库和该批次相差的库存
  1398. total_count = item.Count - info.StockCount
  1399. //清空本批次次库存
  1400. service.DeleteWarehouseInfo(item.WarehouseInfotId)
  1401. //调用出库逻辑
  1402. service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
  1403. }
  1404. //如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
  1405. if item.Count <= info.StockCount {
  1406. stock_cout = lastGood.Count + total
  1407. fmt.Println("232323223232323232323232", stock_cout)
  1408. //扣减库存
  1409. warehouse := models.WarehousingInfo{
  1410. StockCount: info.StockCount - total,
  1411. }
  1412. errs := service.UpdateWarehousingInfo(warehouse, info.ID)
  1413. warehouseOutInfo := &models.WarehouseOutInfo{
  1414. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1415. WarehouseOutId: id,
  1416. WarehouseInfotId: item.WarehouseInfotId,
  1417. Status: 1,
  1418. Ctime: time.Now().Unix(),
  1419. Remark: item.Remark,
  1420. OrgId: item.OrgId,
  1421. Type: 1,
  1422. Manufacturer: item.Manufacturer,
  1423. Dealer: item.Dealer,
  1424. IsSys: 0,
  1425. SysRecordTime: item.SysRecordTime,
  1426. GoodTypeId: item.GoodTypeId,
  1427. GoodId: item.GoodId,
  1428. ExpiryDate: item.ExpiryDate,
  1429. ProductDate: item.ProductDate,
  1430. Number: item.Number,
  1431. Price: item.Price,
  1432. LicenseNumber: item.LicenseNumber,
  1433. Count: item.Count,
  1434. ConsumableType: 2,
  1435. }
  1436. //查询是否存在
  1437. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1438. if errcode == gorm.ErrRecordNotFound {
  1439. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1440. if errOne != nil {
  1441. utils.ErrorLog(errs.Error())
  1442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1443. return
  1444. }
  1445. c.ServeSuccessJSON(map[string]interface{}{
  1446. "msg": "1",
  1447. })
  1448. } else if errcode == nil {
  1449. service.UpDateWarehouseOutInfo(item)
  1450. }
  1451. }
  1452. }
  1453. }
  1454. var last_count int64
  1455. var all_total int64
  1456. var stock_total int64
  1457. //如果退库数量小于最后一次批次的数量(要么要进行退库)
  1458. if item.Count < lastGood.Count {
  1459. fmt.Println("hh232323h2h3hh23hh23hh2h3h23")
  1460. //退库数量和最后一次出库数据进行计算
  1461. last_count = lastGood.Count - item.Count
  1462. fmt.Println("last_count", last_count)
  1463. //获取该耗材该批次的剩余库存量
  1464. infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1465. //退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
  1466. all_total = last_count + infoInfo.StockCount
  1467. fmt.Println("all_total", all_total)
  1468. //如果库存大于总数量,则退回到这个批次
  1469. fmt.Println("inf232323", infoInfo.WarehousingCount)
  1470. if infoInfo.WarehousingCount > all_total {
  1471. stock_total = last_count + infoInfo.StockCount
  1472. fmt.Println("经历323232323232232", last_count, stock_total)
  1473. //退回该批次,计算数量
  1474. warehousingInfoOne := models.WarehousingInfo{
  1475. StockCount: stock_total,
  1476. ID: item.WarehouseInfotId,
  1477. OrgId: item.OrgId,
  1478. }
  1479. fmt.Println("********************", warehousingInfoOne, item.WarehouseInfotId)
  1480. parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
  1481. fmt.Println("parseDateErr2323232322323", parseDateErr)
  1482. //插入一条新纪录
  1483. warehouseOutInfoThree := &models.WarehouseOutInfo{
  1484. WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  1485. WarehouseOutId: id,
  1486. WarehouseInfotId: item.WarehouseInfotId,
  1487. Status: 1,
  1488. Ctime: time.Now().Unix(),
  1489. Remark: item.Remark,
  1490. OrgId: item.OrgId,
  1491. Type: 1,
  1492. Manufacturer: item.Manufacturer,
  1493. Dealer: item.Dealer,
  1494. IsSys: 0,
  1495. GoodTypeId: item.GoodTypeId,
  1496. GoodId: item.GoodId,
  1497. ExpiryDate: item.ExpiryDate,
  1498. ProductDate: item.ProductDate,
  1499. Number: item.Number,
  1500. Price: item.Price,
  1501. LicenseNumber: item.LicenseNumber,
  1502. ConsumableType: 2,
  1503. Count: item.Count,
  1504. }
  1505. //查询是否存在
  1506. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1507. if errcode == gorm.ErrRecordNotFound {
  1508. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
  1509. if errOne != nil {
  1510. utils.ErrorLog(errs.Error())
  1511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1512. return
  1513. }
  1514. c.ServeSuccessJSON(map[string]interface{}{
  1515. "msg": "1",
  1516. })
  1517. } else if errcode == nil {
  1518. service.UpDateWarehouseOutInfo(item)
  1519. }
  1520. }
  1521. //如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
  1522. if infoInfo.WarehousingCount < all_total {
  1523. c.ServeSuccessJSON(map[string]interface{}{
  1524. "msg": "6",
  1525. })
  1526. return
  1527. }
  1528. }
  1529. if item.Count == lastGood.Count {
  1530. errs = service.UpDateWarehouseOutInfo(item)
  1531. if errs != nil {
  1532. utils.ErrorLog(errs.Error())
  1533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1534. return
  1535. }
  1536. c.ServeSuccessJSON(map[string]interface{}{
  1537. "msg": "1",
  1538. })
  1539. }
  1540. }
  1541. }
  1542. if errs != nil {
  1543. utils.ErrorLog(errs.Error())
  1544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1545. return
  1546. }
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "msg": "1",
  1549. })
  1550. }
  1551. func (c *StockManagerApiController) CreateCancelStock() {
  1552. cancel_stock_time := c.GetString("time")
  1553. types, _ := c.GetInt64("type", 0)
  1554. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1555. if parseDateErr != nil {
  1556. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1558. return
  1559. }
  1560. adminUserInfo := c.GetAdminUserInfo()
  1561. operation_time := time.Now().Unix()
  1562. creater := adminUserInfo.AdminUser.Id
  1563. ctime := time.Now().Unix()
  1564. timeStr := time.Now().Format("2006-01-02")
  1565. timeArr := strings.Split(timeStr, "-")
  1566. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1567. total = total + 1
  1568. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1569. cancelStock := models.CancelStock{
  1570. OrderNumber: orderNumber,
  1571. OperaTime: operation_time,
  1572. OrgId: adminUserInfo.CurrentOrgId,
  1573. Creater: creater,
  1574. Ctime: ctime,
  1575. Status: 1,
  1576. ReturnTime: cancelStockDate.Unix(),
  1577. Type: types,
  1578. }
  1579. dataBody := make(map[string]interface{}, 0)
  1580. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1581. if err != nil {
  1582. utils.ErrorLog(err.Error())
  1583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1584. return
  1585. }
  1586. var cancelStockInfos []*models.CancelStockInfo
  1587. var stockFLow []*models.VmStockFlow
  1588. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1589. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1590. if len(thisStockIn) > 0 {
  1591. for _, item := range thisStockIn {
  1592. items := item.(map[string]interface{})
  1593. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1594. utils.ErrorLog("good_id")
  1595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1596. return
  1597. }
  1598. good_id := int64(items["good_id"].(float64))
  1599. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1600. utils.ErrorLog("good_type_id")
  1601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1602. return
  1603. }
  1604. good_type_id := int64(items["good_type_id"].(float64))
  1605. return_count, _ := items["return_count"].(string)
  1606. if len(return_count) == 0 {
  1607. utils.ErrorLog("len(return_count) == 0")
  1608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1609. return
  1610. }
  1611. count, _ := strconv.ParseInt(return_count, 10, 64)
  1612. number := items["number"].(string)
  1613. register_account := items["register_account"].(string)
  1614. manufacturer, _ := items["manufacturer"].(string)
  1615. dealer, _ := items["dealer"].(string)
  1616. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1617. var expiryDates int64
  1618. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1619. expiryDates = 0
  1620. } else {
  1621. if len(items["expiry_date"].(string)) == 0 {
  1622. expiryDates = 0
  1623. } else {
  1624. expiryDate, _ := items["expiry_date"].(string)
  1625. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1626. expiryDates = expiry_date.Unix()
  1627. }
  1628. }
  1629. var productDates int64
  1630. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1631. productDates = 0
  1632. } else {
  1633. if len(items["product_date"].(string)) == 0 {
  1634. productDates = 0
  1635. } else {
  1636. productDate, _ := items["product_date"].(string)
  1637. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1638. productDates = product_date.Unix()
  1639. }
  1640. }
  1641. remark := items["remark"].(string)
  1642. retail_prices := items["price"].(string)
  1643. price, _ := strconv.ParseFloat(retail_prices, 64)
  1644. cancelStockInfo := &models.CancelStockInfo{
  1645. OrderNumber: cancelStock.OrderNumber,
  1646. CancelStockId: cancelStock.ID,
  1647. GoodId: good_id,
  1648. GoodTypeId: good_type_id,
  1649. Count: count,
  1650. Status: 1,
  1651. Ctime: ctime,
  1652. OrgId: adminUserInfo.CurrentOrgId,
  1653. Type: types,
  1654. Manufacturer: manufacturer,
  1655. Dealer: dealer,
  1656. Number: number,
  1657. ProductDate: productDates,
  1658. ExpiryDate: expiryDates,
  1659. RegisterAccount: register_account,
  1660. Remark: remark,
  1661. Price: price,
  1662. WarehouseInfoId: warehouse_info_id,
  1663. }
  1664. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1665. flow := &models.VmStockFlow{
  1666. WarehousingId: 0,
  1667. GoodId: good_id,
  1668. Number: number,
  1669. LicenseNumber: "",
  1670. Count: count,
  1671. UserOrgId: adminUserInfo.CurrentOrgId,
  1672. PatientId: 0,
  1673. SystemTime: time.Now().Unix(),
  1674. ConsumableType: 4,
  1675. IsSys: 0,
  1676. WarehousingOrder: "",
  1677. WarehouseOutId: 0,
  1678. WarehouseOutOrderNumber: "",
  1679. IsEdit: 0,
  1680. CancelStockId: cancelStock.ID,
  1681. CancelOrderNumber: cancelStock.OrderNumber,
  1682. Manufacturer: 0,
  1683. Dealer: 0,
  1684. Creator: adminUserInfo.AdminUser.Id,
  1685. UpdateCreator: 0,
  1686. Status: 1,
  1687. Ctime: time.Now().Unix(),
  1688. Mtime: 0,
  1689. Price: price,
  1690. WarehousingDetailId: 0,
  1691. WarehouseOutDetailId: 0,
  1692. CancelOutDetailId: 0,
  1693. ProductDate: productDates,
  1694. ExpireDate: expiryDates,
  1695. }
  1696. stockFLow = append(stockFLow, flow)
  1697. }
  1698. }
  1699. }
  1700. for _, item := range cancelStockInfos {
  1701. //统计该批次耗材的出库数量
  1702. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId, item.WarehouseInfoId)
  1703. fmt.Println("2333223323322332233223322323", item.Count, info.Count)
  1704. if item.Count > info.Count {
  1705. service.UpdateCancelInfo(item.CancelStockId)
  1706. c.ServeSuccessJSON(map[string]interface{}{
  1707. "msg": "2",
  1708. })
  1709. return
  1710. }
  1711. //查询该批次入库的值
  1712. infolist, _ := service.GetWarehouseInfoByIdSeven(item.WarehouseInfoId)
  1713. if item.Count > infolist.WarehousingCount {
  1714. c.ServeSuccessJSON(map[string]interface{}{
  1715. "msg": "4",
  1716. })
  1717. return
  1718. }
  1719. if item.Count <= infolist.WarehousingCount {
  1720. _, msgerrkonde := service.GetCancelStockDetailByOrderNumber(orderNumber, adminUserInfo.CurrentOrgId)
  1721. if msgerrkonde == gorm.ErrRecordNotFound {
  1722. service.AddSigleCancelStock(&cancelStock)
  1723. }
  1724. listcancel, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
  1725. for _, it := range cancelStockInfos {
  1726. it.CancelStockId = listcancel.ID
  1727. }
  1728. errs := service.CreateCancelStockInfo(cancelStockInfos)
  1729. if len(stockFLow) > 0 {
  1730. service.CreateStockFlow(stockFLow)
  1731. }
  1732. if errs != nil {
  1733. utils.ErrorLog(errs.Error())
  1734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1735. return
  1736. }
  1737. //查询该批次的剩余库存
  1738. wareouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  1739. if (wareouseinfo.StockCount + item.Count) > wareouseinfo.WarehousingCount {
  1740. c.ServeSuccessJSON(map[string]interface{}{
  1741. "msg": "5",
  1742. })
  1743. return
  1744. }
  1745. //更改入库数量
  1746. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  1747. break
  1748. }
  1749. }
  1750. c.ServeSuccessJSON(map[string]interface{}{
  1751. "msg": "3",
  1752. })
  1753. return
  1754. }
  1755. func (c *StockManagerApiController) GetCancelStockInfoList() {
  1756. id, _ := c.GetInt64("id", 0)
  1757. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  1758. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1759. manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
  1760. dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
  1761. c.ServeSuccessJSON(map[string]interface{}{
  1762. "list": cancelStockInfoList,
  1763. "info": info,
  1764. "manufacturerList": manufacturerList,
  1765. "dealerList": dealerList,
  1766. })
  1767. }
  1768. func (c *StockManagerApiController) GetCancelStockList() {
  1769. page, _ := c.GetInt64("page", -1)
  1770. limit, _ := c.GetInt64("limit", -1)
  1771. start_time := c.GetString("start_time")
  1772. end_time := c.GetString("end_time")
  1773. types, _ := c.GetInt64("type", 0)
  1774. keywords := c.GetString("keywords")
  1775. timeLayout := "2006-01-02"
  1776. loc, _ := time.LoadLocation("Local")
  1777. var startTime int64
  1778. if len(start_time) > 0 {
  1779. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1780. if err != nil {
  1781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1782. return
  1783. }
  1784. startTime = theTime.Unix()
  1785. }
  1786. var endTime int64
  1787. if len(end_time) > 0 {
  1788. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1789. if err != nil {
  1790. utils.ErrorLog(err.Error())
  1791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1792. return
  1793. }
  1794. endTime = theTime.Unix()
  1795. }
  1796. adminUserInfo := c.GetAdminUserInfo()
  1797. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1798. if err == nil {
  1799. c.ServeSuccessJSON(map[string]interface{}{
  1800. "list": returnList,
  1801. "total": total,
  1802. })
  1803. } else {
  1804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1805. }
  1806. }
  1807. func (this *StockManagerApiController) DeleteCancelStock() {
  1808. ids := this.GetString("ids")
  1809. if len(ids) == 0 {
  1810. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1811. return
  1812. }
  1813. idArray := strings.Split(ids, ",")
  1814. err := service.DeleteCancelStock(idArray)
  1815. if err != nil {
  1816. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1817. } else {
  1818. this.ServeSuccessJSON(map[string]interface{}{
  1819. "msg": "删除成功",
  1820. })
  1821. }
  1822. }
  1823. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  1824. id, _ := this.GetInt64("id", 0)
  1825. fmt.Println(id)
  1826. if id == 0 {
  1827. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1828. return
  1829. }
  1830. err := service.UpDateCancleStockStatus(id)
  1831. if err != nil {
  1832. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1833. } else {
  1834. this.ServeSuccessJSON(map[string]interface{}{
  1835. "msg": "删除成功",
  1836. })
  1837. }
  1838. }
  1839. func (c *StockManagerApiController) EditCancelStock() {
  1840. cancel_time := c.GetString("cancel_time")
  1841. id, _ := c.GetInt64("id", 0)
  1842. if id == 0 {
  1843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1844. return
  1845. }
  1846. ctime := time.Now().Unix()
  1847. mtime := time.Now().Unix()
  1848. adminUserInfo := c.GetAdminUserInfo()
  1849. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1850. if parseDateErr != nil {
  1851. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1853. return
  1854. }
  1855. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1856. tempCancelStock := models.CancelStock{
  1857. ID: cancelStock.ID,
  1858. Mtime: mtime,
  1859. ReturnTime: cancelDate.Unix(),
  1860. }
  1861. service.EditCancelStock(tempCancelStock)
  1862. dataBody := make(map[string]interface{}, 0)
  1863. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1864. if err != nil {
  1865. utils.ErrorLog(err.Error())
  1866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1867. return
  1868. }
  1869. var cancelStockInfos []*models.CancelStockInfo
  1870. var upDateCancelStockInfos []*models.CancelStockInfo
  1871. var stockFlow []*models.VmStockFlow
  1872. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1873. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1874. if len(thisCancelStock) > 0 {
  1875. for _, item := range thisCancelStock {
  1876. items := item.(map[string]interface{})
  1877. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1878. utils.ErrorLog("good_id")
  1879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1880. return
  1881. }
  1882. good_id := int64(items["good_id"].(float64))
  1883. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1884. utils.ErrorLog("good_type_id")
  1885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1886. return
  1887. }
  1888. good_type_id := int64(items["good_type_id"].(float64))
  1889. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1890. utils.ErrorLog("count")
  1891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1892. return
  1893. }
  1894. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1895. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1896. utils.ErrorLog("id")
  1897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1898. return
  1899. }
  1900. id := int64(items["id"].(float64))
  1901. number := items["number"].(string)
  1902. register_account := items["register_account"].(string)
  1903. manufacturer, _ := items["manufacturer"].(string)
  1904. dealer, _ := items["dealer"].(string)
  1905. remark := items["remark"].(string)
  1906. var productDates int64
  1907. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1908. productDates = 0
  1909. } else {
  1910. if len(items["product_date"].(string)) == 0 {
  1911. productDates = 0
  1912. } else {
  1913. productDate, _ := items["product_date"].(string)
  1914. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1915. productDates = product_date.Unix()
  1916. }
  1917. }
  1918. var expiryDates int64
  1919. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1920. expiryDates = 0
  1921. } else {
  1922. if len(items["expiry_date"].(string)) == 0 {
  1923. expiryDates = 0
  1924. } else {
  1925. expiryDate, _ := items["expiry_date"].(string)
  1926. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1927. expiryDates = expiry_date.Unix()
  1928. }
  1929. }
  1930. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1931. utils.ErrorLog("price")
  1932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1933. return
  1934. }
  1935. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1936. if id == 0 {
  1937. cancelStockInfo := &models.CancelStockInfo{
  1938. GoodId: good_id,
  1939. GoodTypeId: good_type_id,
  1940. Count: count,
  1941. Status: 1,
  1942. Ctime: ctime,
  1943. OrgId: adminUserInfo.CurrentOrgId,
  1944. OrderNumber: cancelStock.OrderNumber,
  1945. CancelStockId: cancelStock.ID,
  1946. Mtime: time.Now().Unix(),
  1947. Number: number,
  1948. RegisterAccount: register_account,
  1949. Manufacturer: manufacturer,
  1950. Dealer: dealer,
  1951. ProductDate: productDates,
  1952. ExpiryDate: expiryDates,
  1953. Remark: remark,
  1954. Price: price,
  1955. }
  1956. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1957. flow := &models.VmStockFlow{
  1958. WarehousingId: 0,
  1959. GoodId: good_id,
  1960. Number: number,
  1961. LicenseNumber: "",
  1962. Count: count,
  1963. UserOrgId: adminUserInfo.CurrentOrgId,
  1964. PatientId: 0,
  1965. SystemTime: time.Now().Unix(),
  1966. ConsumableType: 4,
  1967. IsSys: 0,
  1968. WarehousingOrder: "",
  1969. WarehouseOutId: 0,
  1970. WarehouseOutOrderNumber: "",
  1971. IsEdit: 2,
  1972. CancelStockId: cancelStock.ID,
  1973. CancelOrderNumber: cancelStock.OrderNumber,
  1974. Manufacturer: 0,
  1975. Dealer: 0,
  1976. Creator: adminUserInfo.AdminUser.Id,
  1977. UpdateCreator: 0,
  1978. Status: 1,
  1979. Ctime: time.Now().Unix(),
  1980. Mtime: 0,
  1981. Price: price,
  1982. WarehousingDetailId: 0,
  1983. WarehouseOutDetailId: 0,
  1984. CancelOutDetailId: 0,
  1985. ProductDate: productDates,
  1986. ExpireDate: expiryDates,
  1987. }
  1988. stockFlow = append(stockFlow, flow)
  1989. } else {
  1990. cancelStockInfo := &models.CancelStockInfo{
  1991. ID: id,
  1992. GoodId: good_id,
  1993. GoodTypeId: good_type_id,
  1994. Count: count,
  1995. Status: 1,
  1996. Ctime: ctime,
  1997. OrgId: adminUserInfo.CurrentOrgId,
  1998. OrderNumber: cancelStock.OrderNumber,
  1999. CancelStockId: cancelStock.ID,
  2000. Mtime: time.Now().Unix(),
  2001. Number: number,
  2002. RegisterAccount: register_account,
  2003. Manufacturer: manufacturer,
  2004. Dealer: dealer,
  2005. ProductDate: productDates,
  2006. ExpiryDate: expiryDates,
  2007. Remark: remark,
  2008. Price: price,
  2009. }
  2010. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  2011. flow := &models.VmStockFlow{
  2012. WarehousingId: 0,
  2013. GoodId: good_id,
  2014. Number: number,
  2015. LicenseNumber: "",
  2016. Count: count,
  2017. UserOrgId: adminUserInfo.CurrentOrgId,
  2018. PatientId: 0,
  2019. SystemTime: time.Now().Unix(),
  2020. ConsumableType: 4,
  2021. IsSys: 0,
  2022. WarehousingOrder: "",
  2023. WarehouseOutId: 0,
  2024. WarehouseOutOrderNumber: "",
  2025. IsEdit: 2,
  2026. CancelStockId: cancelStock.ID,
  2027. CancelOrderNumber: cancelStock.OrderNumber,
  2028. Manufacturer: 0,
  2029. Dealer: 0,
  2030. Creator: adminUserInfo.AdminUser.Id,
  2031. UpdateCreator: 0,
  2032. Status: 1,
  2033. Ctime: time.Now().Unix(),
  2034. Mtime: 0,
  2035. Price: price,
  2036. WarehousingDetailId: 0,
  2037. WarehouseOutDetailId: 0,
  2038. CancelOutDetailId: 0,
  2039. ProductDate: productDates,
  2040. ExpireDate: expiryDates,
  2041. }
  2042. stockFlow = append(stockFlow, flow)
  2043. }
  2044. }
  2045. }
  2046. }
  2047. var errs error
  2048. fmt.Println("出库22322333223", cancelStockInfos)
  2049. fmt.Println("更新23232323232323233", upDateCancelStockInfos)
  2050. if len(cancelStockInfos) > 0 {
  2051. for _, item := range cancelStockInfos {
  2052. //统计该耗材的出库数量
  2053. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId, item.WarehouseInfoId)
  2054. if item.Count > info.Count {
  2055. c.ServeSuccessJSON(map[string]interface{}{
  2056. "msg": "2",
  2057. })
  2058. return
  2059. }
  2060. //查询该批次入库的值
  2061. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2062. if item.Count > infolist.WarehousingCount {
  2063. c.ServeSuccessJSON(map[string]interface{}{
  2064. "msg": "4",
  2065. })
  2066. return
  2067. }
  2068. if item.Count <= infolist.WarehousingCount {
  2069. errs := service.CreateCancelStockInfo(cancelStockInfos)
  2070. if len(stockFlow) > 0 {
  2071. service.CreateStockFlow(stockFlow)
  2072. }
  2073. if errs != nil {
  2074. utils.ErrorLog(errs.Error())
  2075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2076. return
  2077. }
  2078. //更改入库数量
  2079. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  2080. break
  2081. }
  2082. }
  2083. }
  2084. if len(upDateCancelStockInfos) > 0 {
  2085. for _, item := range upDateCancelStockInfos {
  2086. //获取该批次最后一套出库记录
  2087. info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
  2088. fmt.Println("info232332322332233223", info.Count, item.Count)
  2089. //比较出库数量和最后一次出库数据大小
  2090. //退库(加)
  2091. if item.Count < info.Count {
  2092. var total = info.Count - item.Count
  2093. errs = service.UpDateCancelStockInfo(item)
  2094. service.CreateStockFlow(stockFlow)
  2095. warehouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2096. if (warehouseinfo.StockCount + total) > warehouseinfo.StockCount {
  2097. c.ServeSuccessJSON(map[string]interface{}{
  2098. "msg": "5",
  2099. })
  2100. return
  2101. }
  2102. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
  2103. if parseDateErr != nil {
  2104. utils.ErrorLog(errs.Error())
  2105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2106. break
  2107. }
  2108. }
  2109. //(减)
  2110. if item.Count > info.Count {
  2111. errs = service.UpDateCancelStockInfo(item)
  2112. service.CreateStockFlow(stockFlow)
  2113. //查询该批次入库的值
  2114. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2115. if item.Count > infolist.WarehousingCount {
  2116. c.ServeSuccessJSON(map[string]interface{}{
  2117. "msg": "4",
  2118. })
  2119. return
  2120. }
  2121. if item.Count <= infolist.WarehousingCount {
  2122. var total_count = info.Count - item.Count
  2123. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total_count)
  2124. if parseDateErr != nil {
  2125. utils.ErrorLog(errs.Error())
  2126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2127. return
  2128. }
  2129. }
  2130. }
  2131. }
  2132. if errs != nil {
  2133. utils.ErrorLog(errs.Error())
  2134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2135. return
  2136. }
  2137. c.ServeSuccessJSON(map[string]interface{}{
  2138. "msg": "3",
  2139. })
  2140. }
  2141. if errs != nil {
  2142. utils.ErrorLog(errs.Error())
  2143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2144. return
  2145. }
  2146. c.ServeSuccessJSON(map[string]interface{}{
  2147. "msg": "3",
  2148. })
  2149. }
  2150. func (this *StockManagerApiController) GetCancelStockConfig() {
  2151. types, _ := this.GetInt64("type", 0)
  2152. adminUserInfo := this.GetAdminUserInfo()
  2153. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  2154. this.ServeSuccessJSON(map[string]interface{}{
  2155. "warehouseOutInfoList": warehouseOutInfoList,
  2156. })
  2157. }
  2158. func (c *StockManagerApiController) GetQueryInfo() {
  2159. page, _ := c.GetInt64("page", -1)
  2160. limit, _ := c.GetInt64("limit", -1)
  2161. keyword := c.GetString("keyword")
  2162. start_time := c.GetString("start_time")
  2163. end_time := c.GetString("end_time")
  2164. type_name, _ := c.GetInt64("type_name")
  2165. timeLayout := "2006-01-02"
  2166. loc, _ := time.LoadLocation("Local")
  2167. var startTime int64
  2168. if len(start_time) > 0 {
  2169. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2170. if err != nil {
  2171. fmt.Println(err)
  2172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2173. return
  2174. }
  2175. startTime = theTime.Unix()
  2176. }
  2177. var endTime int64
  2178. if len(end_time) > 0 {
  2179. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2180. if err != nil {
  2181. utils.ErrorLog(err.Error())
  2182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2183. return
  2184. }
  2185. endTime = theTime.Unix()
  2186. }
  2187. adminUserInfo := c.GetAdminUserInfo()
  2188. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  2189. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  2190. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
  2191. if err == nil {
  2192. c.ServeSuccessJSON(map[string]interface{}{
  2193. "list": list,
  2194. "total": total,
  2195. "info": info,
  2196. "infomationList": infomationList,
  2197. "orgid": adminUserInfo.CurrentOrgId,
  2198. })
  2199. } else {
  2200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2201. }
  2202. }
  2203. func (c *StockManagerApiController) SearchWarehouse() {
  2204. keywords := c.GetString("keywords")
  2205. adminUserInfo := c.GetAdminUserInfo()
  2206. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  2207. if err == nil {
  2208. c.ServeSuccessJSON(map[string]interface{}{
  2209. "list": warehouseList,
  2210. "total": total,
  2211. })
  2212. } else {
  2213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2214. }
  2215. }
  2216. func (c *StockManagerApiController) GetAllConfig() {
  2217. adminUserInfo := c.GetAdminUserInfo()
  2218. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  2219. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  2220. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  2221. goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  2222. c.ServeSuccessJSON(map[string]interface{}{
  2223. "manufacturer": manufacturer,
  2224. "dealer": dealer,
  2225. "goodType": goodType,
  2226. "goodInfo": goodInfo,
  2227. })
  2228. }
  2229. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  2230. types, _ := this.GetInt64("type", 0)
  2231. adminUserInfo := this.GetAdminUserInfo()
  2232. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  2233. this.ServeSuccessJSON(map[string]interface{}{
  2234. "warehouseInfoList": warehouseInfoList,
  2235. })
  2236. }
  2237. func (this *StockManagerApiController) GetDetailInfo() {
  2238. page, _ := this.GetInt64("page", 0)
  2239. limit, _ := this.GetInt64("limit", 0)
  2240. start_time := this.GetString("start_time")
  2241. end_time := this.GetString("end_time")
  2242. types, _ := this.GetInt64("type", 0)
  2243. keywords := this.GetString("keywords")
  2244. manufacturer, _ := this.GetInt64("manufacturer", 0)
  2245. order_type, _ := this.GetInt64("order_type", 0)
  2246. dealer, _ := this.GetInt64("dealer", 0)
  2247. timeLayout := "2006-01-02"
  2248. loc, _ := time.LoadLocation("Local")
  2249. var startTime int64
  2250. if len(start_time) > 0 {
  2251. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2252. if err != nil {
  2253. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2254. return
  2255. }
  2256. startTime = theTime.Unix()
  2257. }
  2258. var endTime int64
  2259. if len(end_time) > 0 {
  2260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2261. if err != nil {
  2262. utils.ErrorLog(err.Error())
  2263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2264. return
  2265. }
  2266. endTime = theTime.Unix()
  2267. }
  2268. adminUserInfo := this.GetAdminUserInfo()
  2269. var list []*models.WarehousingInfo
  2270. var list1 []*models.WarehouseOutInfo
  2271. var list2 []*models.SalesReturnInfo
  2272. var list3 []*models.CancelStockInfo
  2273. var total int64
  2274. var err error
  2275. var total_price float64
  2276. if types == 1 {
  2277. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2278. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2279. if err == nil {
  2280. this.ServeSuccessJSON(map[string]interface{}{
  2281. "list": list,
  2282. "total": total,
  2283. "total_price": total_price,
  2284. })
  2285. } else {
  2286. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2287. }
  2288. } else if types == 2 {
  2289. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2290. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2291. if err == nil {
  2292. this.ServeSuccessJSON(map[string]interface{}{
  2293. "list": list1,
  2294. "total": total,
  2295. "total_price": total_price,
  2296. })
  2297. } else {
  2298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2299. }
  2300. } else if types == 3 {
  2301. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2302. if err == nil {
  2303. this.ServeSuccessJSON(map[string]interface{}{
  2304. "list": list2,
  2305. "total": total,
  2306. })
  2307. } else {
  2308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2309. }
  2310. } else if types == 4 {
  2311. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2312. listGroup, err := service.FindeCancelGroup(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2313. if err == nil {
  2314. this.ServeSuccessJSON(map[string]interface{}{
  2315. "list": list3,
  2316. "total": total,
  2317. "listgroup": listGroup,
  2318. })
  2319. } else {
  2320. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2321. }
  2322. }
  2323. }
  2324. func (this *StockManagerApiController) GetUserDetailInfo() {
  2325. order_id, _ := this.GetInt64("id")
  2326. if order_id <= 0 {
  2327. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2328. return
  2329. }
  2330. adminUserInfo := this.GetAdminUserInfo()
  2331. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2332. if err == nil {
  2333. this.ServeSuccessJSON(map[string]interface{}{
  2334. "list": userDetails,
  2335. "total": total,
  2336. })
  2337. } else {
  2338. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2339. return
  2340. }
  2341. }
  2342. func (this *StockManagerApiController) PostSearchStock() {
  2343. keyword := this.GetString("keyword")
  2344. adminUserInfo := this.GetAdminUserInfo()
  2345. orgId := adminUserInfo.CurrentOrgId
  2346. stock, err := service.PostSearchStock(keyword, orgId)
  2347. if err != nil {
  2348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2349. }
  2350. this.ServeSuccessJSON(map[string]interface{}{
  2351. "stock": stock,
  2352. })
  2353. }
  2354. func (this *StockManagerApiController) GetOutStockTotalCount() {
  2355. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  2356. adminUserInfo := this.GetAdminUserInfo()
  2357. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  2358. if err != nil {
  2359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2360. }
  2361. this.ServeSuccessJSON(map[string]interface{}{
  2362. "stockCount": stockCount,
  2363. })
  2364. }
  2365. func (this *StockManagerApiController) AddGoodInformation() {
  2366. adminUserInfo := this.GetAdminUserInfo()
  2367. orgId := adminUserInfo.CurrentOrgId
  2368. dataBody := make(map[string]interface{}, 0)
  2369. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2370. if err != nil {
  2371. utils.ErrorLog(err.Error())
  2372. return
  2373. }
  2374. utils.ErrorLog("%v", dataBody)
  2375. var goods []*models.GoodInfo
  2376. var total_goods []interface{}
  2377. tempGoods := dataBody["goods"].([]interface{})
  2378. total_goods = tempGoods
  2379. for index, goodMap := range tempGoods {
  2380. goodNameM := goodMap.(map[string]interface{})
  2381. var good models.GoodInfo
  2382. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  2383. utils.ErrorLog("good_name")
  2384. return
  2385. }
  2386. good_name, _ := goodNameM["good_name"].(string)
  2387. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  2388. err_log := models.ExportErrLog{
  2389. LogType: 5,
  2390. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2391. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  2392. Status: 1,
  2393. CreateTime: time.Now().Unix(),
  2394. UpdateTime: time.Now().Unix(),
  2395. ExportTime: time.Now().Unix(),
  2396. }
  2397. service.CreateExportErrLog(&err_log)
  2398. continue
  2399. }
  2400. good.GoodName = good_name
  2401. // 获取数据字典数据
  2402. var good_kind_id int64
  2403. var name = "耗材种类"
  2404. config, _ := service.GetDrugDataConfig(0, name)
  2405. good_kind := goodNameM["good_kind"].(string)
  2406. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  2407. err_log := models.ExportErrLog{
  2408. LogType: 5,
  2409. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2410. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  2411. Status: 1,
  2412. CreateTime: time.Now().Unix(),
  2413. UpdateTime: time.Now().Unix(),
  2414. ExportTime: time.Now().Unix(),
  2415. }
  2416. service.CreateExportErrLog(&err_log)
  2417. continue
  2418. }
  2419. if len(good_kind) != 0 {
  2420. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  2421. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  2422. dataconfig := models.DictDataconfig{
  2423. ParentId: config.ID,
  2424. Module: "system",
  2425. OrgId: orgId,
  2426. Name: good_kind,
  2427. FieldName: "",
  2428. Value: lastConfig.Value + 1,
  2429. CreatedTime: "",
  2430. UpdatedTime: "",
  2431. CreateUserId: adminUserInfo.AdminUser.Id,
  2432. Status: 1,
  2433. Remark: "",
  2434. DeleteIdSystem: 0,
  2435. Title: "",
  2436. Content: "",
  2437. Order: 0,
  2438. Code: "",
  2439. }
  2440. if errcodegoodkind == gorm.ErrRecordNotFound {
  2441. service.CreatedDicConfig(&dataconfig)
  2442. }
  2443. }
  2444. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  2445. for _, it := range dataConfig {
  2446. if good_kind == it.Name {
  2447. fmt.Println(it.Name)
  2448. good_kind_id = int64(it.Value)
  2449. }
  2450. }
  2451. good.GoodKind = good_kind_id
  2452. good_type := goodNameM["type_name"].(string)
  2453. if len(good_type) == 0 {
  2454. err_log := models.ExportErrLog{
  2455. LogType: 5,
  2456. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2457. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  2458. Status: 1,
  2459. CreateTime: time.Now().Unix(),
  2460. UpdateTime: time.Now().Unix(),
  2461. ExportTime: time.Now().Unix(),
  2462. }
  2463. service.CreateExportErrLog(&err_log)
  2464. continue
  2465. }
  2466. if len(good_type) != 0 {
  2467. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  2468. if errcodegoodtype == gorm.ErrRecordNotFound {
  2469. goodsType := models.GoodsType{
  2470. TypeName: good_type,
  2471. Remark: "",
  2472. Ctime: time.Now().Unix(),
  2473. Mtime: 0,
  2474. Creater: adminUserInfo.AdminUser.Id,
  2475. Modifier: 0,
  2476. OrgId: adminUserInfo.CurrentOrgId,
  2477. Status: 1,
  2478. Type: 0,
  2479. Number: 0,
  2480. OutStock: 0,
  2481. StockAttribute: 1,
  2482. }
  2483. service.CreatedGoodType(&goodsType)
  2484. }
  2485. }
  2486. goodType, _ := service.GetAllGoodType(orgId)
  2487. var good_type_id int64
  2488. for _, it := range goodType {
  2489. if good_type == it.TypeName {
  2490. good_type_id = it.ID
  2491. }
  2492. }
  2493. good.GoodTypeId = good_type_id
  2494. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  2495. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  2496. err_log := models.ExportErrLog{
  2497. LogType: 5,
  2498. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2499. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  2500. Status: 1,
  2501. CreateTime: time.Now().Unix(),
  2502. UpdateTime: time.Now().Unix(),
  2503. ExportTime: time.Now().Unix(),
  2504. }
  2505. service.CreateExportErrLog(&err_log)
  2506. continue
  2507. }
  2508. var medical_insurance_id int64
  2509. var medicalInsurance = "医保等级"
  2510. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  2511. if len(medical_insurance_level) != 0 {
  2512. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  2513. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  2514. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  2515. dataconfig := models.DictDataconfig{
  2516. ParentId: medicalInsuranceDataConfig.ID,
  2517. Module: "system",
  2518. OrgId: orgId,
  2519. Name: medical_insurance_level,
  2520. FieldName: "",
  2521. Value: mediConfigOne.Value + 1,
  2522. CreatedTime: "",
  2523. UpdatedTime: "",
  2524. CreateUserId: adminUserInfo.AdminUser.Id,
  2525. Status: 1,
  2526. Remark: "",
  2527. DeleteIdSystem: 0,
  2528. Title: "",
  2529. Content: "",
  2530. Order: 0,
  2531. Code: "",
  2532. }
  2533. service.CreatedDicConfig(&dataconfig)
  2534. }
  2535. }
  2536. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  2537. for _, it := range medicalInsuranceList {
  2538. if medical_insurance_level == it.Name {
  2539. medical_insurance_id = int64(it.Value)
  2540. }
  2541. }
  2542. good.MedicalInsuranceLevel = medical_insurance_id
  2543. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  2544. utils.ErrorLog("specification_name")
  2545. return
  2546. }
  2547. specification_name := goodNameM["specification_name"].(string)
  2548. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  2549. err_log := models.ExportErrLog{
  2550. LogType: 5,
  2551. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2552. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  2553. Status: 1,
  2554. CreateTime: time.Now().Unix(),
  2555. UpdateTime: time.Now().Unix(),
  2556. ExportTime: time.Now().Unix(),
  2557. }
  2558. service.CreateExportErrLog(&err_log)
  2559. continue
  2560. }
  2561. good.SpecificationName = specification_name
  2562. var manufacturer_id int64
  2563. manufacturer := goodNameM["manufacturer"].(string)
  2564. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  2565. err_log := models.ExportErrLog{
  2566. LogType: 5,
  2567. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2568. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  2569. Status: 1,
  2570. CreateTime: time.Now().Unix(),
  2571. UpdateTime: time.Now().Unix(),
  2572. ExportTime: time.Now().Unix(),
  2573. }
  2574. service.CreateExportErrLog(&err_log)
  2575. continue
  2576. }
  2577. if len(manufacturer) != 0 {
  2578. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  2579. manu := models.Manufacturer{
  2580. ManufacturerName: manufacturer,
  2581. Status: 1,
  2582. OrgId: orgId,
  2583. Creater: adminUserInfo.AdminUser.Id,
  2584. }
  2585. if errcodes == gorm.ErrRecordNotFound {
  2586. service.CreateManufacturer(&manu)
  2587. }
  2588. }
  2589. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2590. for _, it := range manufacturerList {
  2591. if manufacturer == it.ManufacturerName {
  2592. manufacturer_id = it.ID
  2593. }
  2594. }
  2595. good.Manufacturer = manufacturer_id
  2596. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  2597. utils.ErrorLog("unit_id")
  2598. return
  2599. }
  2600. unit_id := int64(goodNameM["unit_id"].(float64))
  2601. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  2602. err_log := models.ExportErrLog{
  2603. LogType: 5,
  2604. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2605. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  2606. Status: 1,
  2607. CreateTime: time.Now().Unix(),
  2608. UpdateTime: time.Now().Unix(),
  2609. ExportTime: time.Now().Unix(),
  2610. }
  2611. service.CreateExportErrLog(&err_log)
  2612. continue
  2613. }
  2614. good.GoodUnit = unit_id
  2615. retail_prices := goodNameM["retail_price"].(string)
  2616. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2617. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  2618. err_log := models.ExportErrLog{
  2619. LogType: 5,
  2620. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2621. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
  2622. Status: 1,
  2623. CreateTime: time.Now().Unix(),
  2624. UpdateTime: time.Now().Unix(),
  2625. ExportTime: time.Now().Unix(),
  2626. }
  2627. service.CreateExportErrLog(&err_log)
  2628. continue
  2629. }
  2630. good.RetailPrice = retail_price
  2631. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  2632. utils.ErrorLog("stock_warn_count")
  2633. return
  2634. }
  2635. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  2636. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  2637. err_log := models.ExportErrLog{
  2638. LogType: 5,
  2639. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2640. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  2641. Status: 1,
  2642. CreateTime: time.Now().Unix(),
  2643. UpdateTime: time.Now().Unix(),
  2644. ExportTime: time.Now().Unix(),
  2645. }
  2646. service.CreateExportErrLog(&err_log)
  2647. continue
  2648. }
  2649. good.StockWarnCount = stock_warn_count
  2650. var dealer_id int64
  2651. dealerName := goodNameM["dealer"].(string)
  2652. fmt.Println("经销商", dealerName)
  2653. dealer := models.Dealer{
  2654. OrgId: orgId,
  2655. Status: 1,
  2656. DealerName: dealerName,
  2657. Creater: adminUserInfo.AdminUser.Id,
  2658. Ctime: time.Now().Unix(),
  2659. }
  2660. if len(dealerName) != 0 {
  2661. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  2662. if errcodedealer == gorm.ErrRecordNotFound {
  2663. service.CreateDealer(&dealer)
  2664. }
  2665. }
  2666. dealerList, _ := service.GetAllDealerList(orgId)
  2667. for _, it := range dealerList {
  2668. if dealerName == it.DealerName {
  2669. dealer_id = it.ID
  2670. }
  2671. }
  2672. good.Dealer = dealer_id
  2673. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  2674. utils.ErrorLog("pinyin")
  2675. return
  2676. }
  2677. pinyin := goodNameM["pinyin"].(string)
  2678. good.Pinyin = pinyin
  2679. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  2680. utils.ErrorLog("wubi")
  2681. return
  2682. }
  2683. wubi := goodNameM["wubi"].(string)
  2684. good.Wubi = wubi
  2685. buy_prices := goodNameM["buy_price"].(string)
  2686. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  2687. good.BuyPrice = buy_price
  2688. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  2689. utils.ErrorLog("social_security_directory_code")
  2690. return
  2691. }
  2692. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2693. good.SocialSecurityDirectoryCode = social_security_directory_code
  2694. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  2695. utils.ErrorLog("is_special_diseases")
  2696. return
  2697. }
  2698. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2699. good.IsSpecialDiseases = is_special_diseases
  2700. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  2701. utils.ErrorLog("is_record")
  2702. return
  2703. }
  2704. is_record := int64(goodNameM["is_record"].(float64))
  2705. good.IsRecord = is_record
  2706. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  2707. utils.ErrorLog("good_status")
  2708. return
  2709. }
  2710. good_status := goodNameM["good_status"].(string)
  2711. good.GoodStatus = good_status
  2712. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  2713. utils.ErrorLog("medical_insurance_number")
  2714. return
  2715. }
  2716. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2717. good.MedicalInsuranceNumber = medical_insurance_number
  2718. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  2719. utils.ErrorLog("production_type")
  2720. return
  2721. }
  2722. production_type := goodNameM["production_type"].(string)
  2723. good.ProductionType = production_type
  2724. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  2725. utils.ErrorLog("remark")
  2726. return
  2727. }
  2728. remark := goodNameM["remark"].(string)
  2729. good.Remark = remark
  2730. statistics_category := goodNameM["statistics_category"].(string)
  2731. var categoryName = "统计分类"
  2732. var statistic_id int64
  2733. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  2734. if len(statistics_category) != 0 {
  2735. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  2736. if errcodecagegory == gorm.ErrRecordNotFound {
  2737. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  2738. dataconfig := models.DictDataconfig{
  2739. ParentId: drugDataConfig.ID,
  2740. Module: "system",
  2741. OrgId: orgId,
  2742. Name: statistics_category,
  2743. FieldName: "",
  2744. Value: dicConfigThree.Value + 1,
  2745. CreatedTime: "",
  2746. UpdatedTime: "",
  2747. CreateUserId: adminUserInfo.AdminUser.Id,
  2748. Status: 1,
  2749. Remark: "",
  2750. DeleteIdSystem: 0,
  2751. Title: "",
  2752. Content: "",
  2753. Order: 0,
  2754. Code: "",
  2755. }
  2756. service.CreatedDicConfig(&dataconfig)
  2757. }
  2758. }
  2759. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  2760. for _, it := range parentDataConfig {
  2761. if statistics_category == it.Name {
  2762. statistic_id = int64(it.Value)
  2763. }
  2764. }
  2765. good.StatisticsCategory = statistic_id
  2766. special_medical := goodNameM["special_medical"].(string)
  2767. good.SpecialMedical = special_medical
  2768. goods = append(goods, &good)
  2769. }
  2770. export_time := time.Now().Unix()
  2771. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2772. if len(goods) > 0 {
  2773. for _, item := range goods {
  2774. goodInfo := models.GoodInfo{
  2775. GoodName: item.GoodName,
  2776. SpecificationName: item.SpecificationName,
  2777. GoodKind: item.GoodKind,
  2778. GoodTypeId: item.GoodTypeId,
  2779. Dealer: item.Dealer,
  2780. GoodUnit: item.GoodUnit,
  2781. IsRecord: item.IsRecord,
  2782. IsSpecialDiseases: item.IsSpecialDiseases,
  2783. Manufacturer: item.Manufacturer,
  2784. Pinyin: item.Pinyin,
  2785. GoodStatus: item.GoodStatus,
  2786. ProductionType: item.ProductionType,
  2787. Remark: item.Remark,
  2788. RetailPrice: item.RetailPrice,
  2789. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  2790. SpecialMedical: item.SpecialMedical,
  2791. Wubi: item.Wubi,
  2792. StockWarnCount: item.StockWarnCount,
  2793. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  2794. OrgId: orgId,
  2795. Status: 1,
  2796. Ctime: time.Now().Unix(),
  2797. StatisticsCategory: item.StatisticsCategory,
  2798. GoodCode: item.GoodCode,
  2799. BuyPrice: item.BuyPrice,
  2800. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  2801. }
  2802. //查询同种耗材名称同种类型同种规格的耗材是否存在
  2803. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2804. if errcodegood == gorm.ErrRecordNotFound {
  2805. service.CreateGoodsInfomation(&goodInfo)
  2806. } else if errcodegood == nil {
  2807. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2808. }
  2809. log := models.ExportLog{
  2810. LogType: 5,
  2811. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2812. TotalNum: int64(len(total_goods)),
  2813. FailNum: int64(len(errLogs)),
  2814. SuccessNum: int64(len(goods)),
  2815. CreateTime: time.Now().Unix(),
  2816. UpdateTime: time.Now().Unix(),
  2817. ExportTime: export_time,
  2818. Status: 1,
  2819. }
  2820. service.CreateExportLog(&log)
  2821. this.ServeSuccessJSON(map[string]interface{}{
  2822. "msg": "导入成功",
  2823. "total_num": len(total_goods),
  2824. "success_num": len(goods),
  2825. "fail_num": int64(len(errLogs)),
  2826. })
  2827. }
  2828. } else {
  2829. log := models.ExportLog{
  2830. LogType: 5,
  2831. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2832. TotalNum: int64(len(total_goods)),
  2833. FailNum: int64(len(errLogs)),
  2834. SuccessNum: int64(len(goods)),
  2835. CreateTime: time.Now().Unix(),
  2836. UpdateTime: time.Now().Unix(),
  2837. ExportTime: export_time,
  2838. Status: 1,
  2839. }
  2840. service.CreateExportLog(&log)
  2841. this.ServeSuccessJSON(map[string]interface{}{
  2842. "msg": "导入成功",
  2843. "total_num": len(total_goods),
  2844. "success_num": len(goods),
  2845. "fail_num": int64(len(errLogs)),
  2846. })
  2847. }
  2848. }
  2849. func (this *StockManagerApiController) AddDrugInformation() {
  2850. adminUser := this.GetAdminUserInfo()
  2851. orgId := adminUser.CurrentOrgId
  2852. dataBody := make(map[string]interface{}, 0)
  2853. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2854. if err != nil {
  2855. utils.ErrorLog(err.Error())
  2856. return
  2857. }
  2858. utils.ErrorLog("%v", dataBody)
  2859. var drugList []*models.BaseDrugLib
  2860. var total_goods []interface{}
  2861. tempDrugs := dataBody["drugs"].([]interface{})
  2862. total_goods = tempDrugs
  2863. for index, drugMap := range tempDrugs {
  2864. goodNameM := drugMap.(map[string]interface{})
  2865. var drug models.BaseDrugLib
  2866. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  2867. utils.ErrorLog("drug_name")
  2868. return
  2869. }
  2870. drug_name, _ := goodNameM["drug_name"].(string)
  2871. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2872. err_log := models.ExportErrLog{
  2873. LogType: 4,
  2874. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2875. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  2876. Status: 1,
  2877. CreateTime: time.Now().Unix(),
  2878. UpdateTime: time.Now().Unix(),
  2879. ExportTime: time.Now().Unix(),
  2880. }
  2881. service.CreateExportErrLog(&err_log)
  2882. continue
  2883. }
  2884. drug.DrugName = drug_name
  2885. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  2886. utils.ErrorLog("min_number")
  2887. return
  2888. }
  2889. min_number, _ := goodNameM["min_number"].(string)
  2890. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  2891. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2892. err_log := models.ExportErrLog{
  2893. LogType: 4,
  2894. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2895. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  2896. Status: 1,
  2897. CreateTime: time.Now().Unix(),
  2898. UpdateTime: time.Now().Unix(),
  2899. ExportTime: time.Now().Unix(),
  2900. }
  2901. service.CreateExportErrLog(&err_log)
  2902. continue
  2903. }
  2904. drug.MinNumber = minNumber
  2905. min_unit := goodNameM["min_unit"].(string)
  2906. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  2907. err_log := models.ExportErrLog{
  2908. LogType: 4,
  2909. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2910. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  2911. Status: 1,
  2912. CreateTime: time.Now().Unix(),
  2913. UpdateTime: time.Now().Unix(),
  2914. ExportTime: time.Now().Unix(),
  2915. }
  2916. service.CreateExportErrLog(&err_log)
  2917. continue
  2918. }
  2919. drug.MinUnit = min_unit
  2920. dose := goodNameM["dose"].(float64)
  2921. if dose < 0 { //名字为空则生成一条导入错误日志
  2922. err_log := models.ExportErrLog{
  2923. LogType: 4,
  2924. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2925. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  2926. Status: 1,
  2927. CreateTime: time.Now().Unix(),
  2928. UpdateTime: time.Now().Unix(),
  2929. ExportTime: time.Now().Unix(),
  2930. }
  2931. service.CreateExportErrLog(&err_log)
  2932. continue
  2933. }
  2934. drug.Dose = dose
  2935. max_unit_id := goodNameM["max_unit"].(string)
  2936. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  2937. err_log := models.ExportErrLog{
  2938. LogType: 4,
  2939. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2940. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  2941. Status: 1,
  2942. CreateTime: time.Now().Unix(),
  2943. UpdateTime: time.Now().Unix(),
  2944. ExportTime: time.Now().Unix(),
  2945. }
  2946. service.CreateExportErrLog(&err_log)
  2947. continue
  2948. }
  2949. drug.MaxUnit = max_unit_id
  2950. max_unit := goodNameM["max_unit"].(string)
  2951. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  2952. err_log := models.ExportErrLog{
  2953. LogType: 4,
  2954. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2955. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  2956. Status: 1,
  2957. CreateTime: time.Now().Unix(),
  2958. UpdateTime: time.Now().Unix(),
  2959. ExportTime: time.Now().Unix(),
  2960. }
  2961. service.CreateExportErrLog(&err_log)
  2962. continue
  2963. }
  2964. drug.MaxUnit = max_unit
  2965. delivery_way := goodNameM["delivery_way"].(string)
  2966. if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
  2967. err_log := models.ExportErrLog{
  2968. LogType: 4,
  2969. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2970. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  2971. Status: 1,
  2972. CreateTime: time.Now().Unix(),
  2973. UpdateTime: time.Now().Unix(),
  2974. ExportTime: time.Now().Unix(),
  2975. }
  2976. service.CreateExportErrLog(&err_log)
  2977. continue
  2978. }
  2979. drug.DeliveryWay = delivery_way
  2980. execution_frequency := goodNameM["execution_frequency"].(string)
  2981. if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
  2982. err_log := models.ExportErrLog{
  2983. LogType: 4,
  2984. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2985. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  2986. Status: 1,
  2987. CreateTime: time.Now().Unix(),
  2988. UpdateTime: time.Now().Unix(),
  2989. ExportTime: time.Now().Unix(),
  2990. }
  2991. service.CreateExportErrLog(&err_log)
  2992. continue
  2993. }
  2994. drug.ExecutionFrequency = execution_frequency
  2995. drug_day := goodNameM["drug_day"].(string)
  2996. if len(drug_day) == 0 { //名字为空则生成一条导入错误日志
  2997. err_log := models.ExportErrLog{
  2998. LogType: 4,
  2999. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3000. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  3001. Status: 1,
  3002. CreateTime: time.Now().Unix(),
  3003. UpdateTime: time.Now().Unix(),
  3004. ExportTime: time.Now().Unix(),
  3005. }
  3006. service.CreateExportErrLog(&err_log)
  3007. continue
  3008. }
  3009. drug.DrugDay = drug_day
  3010. drug_type := goodNameM["drug_type"].(string)
  3011. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  3012. err_log := models.ExportErrLog{
  3013. LogType: 4,
  3014. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3015. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  3016. Status: 1,
  3017. CreateTime: time.Now().Unix(),
  3018. UpdateTime: time.Now().Unix(),
  3019. ExportTime: time.Now().Unix(),
  3020. }
  3021. service.CreateExportErrLog(&err_log)
  3022. continue
  3023. }
  3024. var drug_type_id int64
  3025. var drugType = "药品类型"
  3026. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  3027. if len(drug_type) != 0 {
  3028. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  3029. if errcodes == gorm.ErrRecordNotFound {
  3030. //获取该型号最后一条数据型号
  3031. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  3032. dataconfig := models.DictDataconfig{
  3033. ParentId: drugconfig.ID,
  3034. Module: "system",
  3035. OrgId: orgId,
  3036. Name: drug_type,
  3037. FieldName: "",
  3038. Value: config.Value + 1,
  3039. CreatedTime: "",
  3040. UpdatedTime: "",
  3041. CreateUserId: adminUser.AdminUser.Id,
  3042. Status: 1,
  3043. Remark: "",
  3044. DeleteIdSystem: 0,
  3045. Title: "",
  3046. Content: "",
  3047. Order: 0,
  3048. Code: "",
  3049. }
  3050. service.CreatedDicConfig(&dataconfig)
  3051. }
  3052. }
  3053. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  3054. for _, it := range drugTypeList {
  3055. if drug_type == it.Name {
  3056. drug_type_id = int64(it.Value)
  3057. }
  3058. }
  3059. drug.DrugType = drug_type_id
  3060. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  3061. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  3062. err_log := models.ExportErrLog{
  3063. LogType: 4,
  3064. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3065. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  3066. Status: 1,
  3067. CreateTime: time.Now().Unix(),
  3068. UpdateTime: time.Now().Unix(),
  3069. ExportTime: time.Now().Unix(),
  3070. }
  3071. service.CreateExportErrLog(&err_log)
  3072. continue
  3073. }
  3074. drug.DrugStockLimit = drug_stock_limit
  3075. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  3076. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  3077. err_log := models.ExportErrLog{
  3078. LogType: 4,
  3079. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3080. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  3081. Status: 1,
  3082. CreateTime: time.Now().Unix(),
  3083. UpdateTime: time.Now().Unix(),
  3084. ExportTime: time.Now().Unix(),
  3085. }
  3086. service.CreateExportErrLog(&err_log)
  3087. continue
  3088. }
  3089. drug.DrugOriginPlace = drug_origin_place
  3090. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  3091. if len(drug_dosage_form) == 0 {
  3092. err_log := models.ExportErrLog{
  3093. LogType: 4,
  3094. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3095. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  3096. Status: 1,
  3097. CreateTime: time.Now().Unix(),
  3098. UpdateTime: time.Now().Unix(),
  3099. ExportTime: time.Now().Unix(),
  3100. }
  3101. service.CreateExportErrLog(&err_log)
  3102. continue
  3103. }
  3104. var drug_dosage = "药品剂型"
  3105. var drug_dosage_form_id int64
  3106. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  3107. if len(drug_dosage_form) != 0 {
  3108. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  3109. if errcodess == gorm.ErrRecordNotFound {
  3110. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  3111. dataconfig := models.DictDataconfig{
  3112. ParentId: drugDosageconfig.ID,
  3113. Module: "system",
  3114. OrgId: orgId,
  3115. Name: drug_dosage_form,
  3116. FieldName: "",
  3117. Value: configOne.Value + 1,
  3118. CreatedTime: "",
  3119. UpdatedTime: "",
  3120. CreateUserId: adminUser.AdminUser.Id,
  3121. Status: 1,
  3122. Remark: "",
  3123. DeleteIdSystem: 0,
  3124. Title: "",
  3125. Content: "",
  3126. Order: 0,
  3127. Code: "",
  3128. }
  3129. service.CreatedDicConfig(&dataconfig)
  3130. }
  3131. }
  3132. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  3133. for _, it := range drugDosageList {
  3134. if drug_dosage_form == it.Name {
  3135. drug_dosage_form_id = int64(it.Value)
  3136. }
  3137. }
  3138. drug.DrugDosageForm = drug_dosage_form_id
  3139. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  3140. var medical_insurance_level_id int64
  3141. if len(medical_insurance_level) == 0 { //名字为空则生成一条导入错误日志
  3142. err_log := models.ExportErrLog{
  3143. LogType: 4,
  3144. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3145. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  3146. Status: 1,
  3147. CreateTime: time.Now().Unix(),
  3148. UpdateTime: time.Now().Unix(),
  3149. ExportTime: time.Now().Unix(),
  3150. }
  3151. service.CreateExportErrLog(&err_log)
  3152. continue
  3153. }
  3154. var medicalInsuranceName = "医保等级"
  3155. medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
  3156. if len(medical_insurance_level) != 0 {
  3157. _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
  3158. if errcodemedical == gorm.ErrRecordNotFound {
  3159. medConfig, _ := service.GetLastDicConfig(medicalInsuranceConfig.ID, orgId)
  3160. dataconfig := models.DictDataconfig{
  3161. ParentId: medicalInsuranceConfig.ID,
  3162. Module: "system",
  3163. OrgId: orgId,
  3164. Name: medical_insurance_level,
  3165. FieldName: "",
  3166. Value: medConfig.Value + 1,
  3167. CreatedTime: "",
  3168. UpdatedTime: "",
  3169. CreateUserId: adminUser.AdminUser.Id,
  3170. Status: 1,
  3171. Remark: "",
  3172. DeleteIdSystem: 0,
  3173. Title: "",
  3174. Content: "",
  3175. Order: 0,
  3176. Code: "",
  3177. }
  3178. service.CreatedDicConfig(&dataconfig)
  3179. }
  3180. }
  3181. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
  3182. for _, it := range medicalInsuranceList {
  3183. if medical_insurance_level == it.Name {
  3184. medical_insurance_level_id = int64(it.Value)
  3185. }
  3186. }
  3187. drug.MedicalInsuranceLevel = medical_insurance_level_id
  3188. unit_matrixing := goodNameM["unit_matrixing"].(string)
  3189. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3190. err_log := models.ExportErrLog{
  3191. LogType: 4,
  3192. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3193. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
  3194. Status: 1,
  3195. CreateTime: time.Now().Unix(),
  3196. UpdateTime: time.Now().Unix(),
  3197. ExportTime: time.Now().Unix(),
  3198. }
  3199. service.CreateExportErrLog(&err_log)
  3200. continue
  3201. }
  3202. drug.UnitMatrixing = unit_matrixing
  3203. retail_prices := goodNameM["retail_price"].(string)
  3204. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3205. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3206. err_log := models.ExportErrLog{
  3207. LogType: 4,
  3208. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3209. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  3210. Status: 1,
  3211. CreateTime: time.Now().Unix(),
  3212. UpdateTime: time.Now().Unix(),
  3213. ExportTime: time.Now().Unix(),
  3214. }
  3215. service.CreateExportErrLog(&err_log)
  3216. continue
  3217. }
  3218. drug.RetailPrice = retail_price
  3219. packing_prices := goodNameM["packing_price"].(string)
  3220. packing_price, _ := strconv.ParseFloat(packing_prices, 64)
  3221. if packing_price <= 0 { //名字为空则生成一条导入错误日志
  3222. err_log := models.ExportErrLog{
  3223. LogType: 4,
  3224. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3225. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装零售价不能为空",
  3226. Status: 1,
  3227. CreateTime: time.Now().Unix(),
  3228. UpdateTime: time.Now().Unix(),
  3229. ExportTime: time.Now().Unix(),
  3230. }
  3231. service.CreateExportErrLog(&err_log)
  3232. continue
  3233. }
  3234. drug.RetailPrice = retail_price
  3235. last_prices := goodNameM["last_price"].(string)
  3236. last_price, _ := strconv.ParseFloat(last_prices, 64)
  3237. if last_price <= 0 { //名字为空则生成一条导入错误日志
  3238. err_log := models.ExportErrLog{
  3239. LogType: 4,
  3240. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3241. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  3242. Status: 1,
  3243. CreateTime: time.Now().Unix(),
  3244. UpdateTime: time.Now().Unix(),
  3245. ExportTime: time.Now().Unix(),
  3246. }
  3247. service.CreateExportErrLog(&err_log)
  3248. continue
  3249. }
  3250. drug.LastPrice = last_price
  3251. drug_classify := goodNameM["drug_classify"].(string)
  3252. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  3253. err_log := models.ExportErrLog{
  3254. LogType: 4,
  3255. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3256. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  3257. Status: 1,
  3258. CreateTime: time.Now().Unix(),
  3259. UpdateTime: time.Now().Unix(),
  3260. ExportTime: time.Now().Unix(),
  3261. }
  3262. service.CreateExportErrLog(&err_log)
  3263. continue
  3264. }
  3265. var drugClassify = "药物分类"
  3266. var drug_classify_id int64
  3267. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  3268. if len(drug_classify) != 0 {
  3269. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  3270. if errcodesClass == gorm.ErrRecordNotFound {
  3271. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  3272. dataconfig := models.DictDataconfig{
  3273. ParentId: drugClassifyConfig.ID,
  3274. Module: "system",
  3275. OrgId: orgId,
  3276. Name: drug_classify,
  3277. FieldName: "",
  3278. Value: drugClassConfig.Value + 1,
  3279. CreatedTime: "",
  3280. UpdatedTime: "",
  3281. CreateUserId: adminUser.AdminUser.Id,
  3282. Status: 1,
  3283. Remark: "",
  3284. DeleteIdSystem: 0,
  3285. Title: "",
  3286. Content: "",
  3287. Order: 0,
  3288. Code: "",
  3289. }
  3290. service.CreatedDicConfig(&dataconfig)
  3291. }
  3292. }
  3293. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  3294. for _, it := range drugClassList {
  3295. if drug_classify == it.Name {
  3296. drug_classify_id = int64(it.Value)
  3297. }
  3298. }
  3299. drug_dose := goodNameM["drug_dose"].(string)
  3300. if len(drug_dose) == 0 {
  3301. err_log := models.ExportErrLog{
  3302. LogType: 4,
  3303. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3304. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  3305. Status: 1,
  3306. CreateTime: time.Now().Unix(),
  3307. UpdateTime: time.Now().Unix(),
  3308. ExportTime: time.Now().Unix(),
  3309. }
  3310. service.CreateExportErrLog(&err_log)
  3311. continue
  3312. }
  3313. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  3314. drug.DrugDose = drugDoses
  3315. var units = "单位"
  3316. var unit_id int64
  3317. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  3318. if len(drugDoseUnit) == 0 {
  3319. err_log := models.ExportErrLog{
  3320. LogType: 4,
  3321. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3322. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  3323. Status: 1,
  3324. CreateTime: time.Now().Unix(),
  3325. UpdateTime: time.Now().Unix(),
  3326. ExportTime: time.Now().Unix(),
  3327. }
  3328. service.CreateExportErrLog(&err_log)
  3329. continue
  3330. }
  3331. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  3332. if len(drugDoseUnit) != 0 {
  3333. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  3334. if errcodedataconfig == gorm.ErrRecordNotFound {
  3335. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  3336. dataconfig := models.Dataconfig{
  3337. ParentId: dataConfig.ID,
  3338. Module: "hemodialysis",
  3339. OrgId: orgId,
  3340. Name: drugDoseUnit,
  3341. FieldName: "",
  3342. Value: childConfig.Value + 1,
  3343. CreatedTime: "",
  3344. UpdatedTime: "",
  3345. CreateUserId: adminUser.AdminUser.Id,
  3346. Status: 1,
  3347. Remark: "",
  3348. DeleteIdSystem: 0,
  3349. Title: "",
  3350. Content: "",
  3351. Order: 0,
  3352. Code: "",
  3353. FieldType: 0,
  3354. }
  3355. service.CreateDataConfig(&dataconfig)
  3356. }
  3357. }
  3358. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  3359. for _, it := range list {
  3360. if drugDoseUnit == it.Name {
  3361. unit_id = int64(it.Value)
  3362. }
  3363. }
  3364. drug.DrugDoseUnit = unit_id
  3365. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  3366. manufacturer := goodNameM["manufacturer"].(string)
  3367. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3368. err_log := models.ExportErrLog{
  3369. LogType: 4,
  3370. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3371. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  3372. Status: 1,
  3373. CreateTime: time.Now().Unix(),
  3374. UpdateTime: time.Now().Unix(),
  3375. ExportTime: time.Now().Unix(),
  3376. }
  3377. service.CreateExportErrLog(&err_log)
  3378. continue
  3379. }
  3380. if len(manufacturer) != 0 {
  3381. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  3382. if errcodema == gorm.ErrRecordNotFound {
  3383. manufactur := models.Manufacturer{
  3384. OrgId: orgId,
  3385. Status: 1,
  3386. ManufacturerName: manufacturer,
  3387. Ctime: time.Now().Unix(),
  3388. Creater: adminUser.AdminUser.Id,
  3389. }
  3390. service.CreateManufacturer(&manufactur)
  3391. }
  3392. }
  3393. var manufacturer_id int64
  3394. manufacturList, _ := service.GetAllManufacturerList(orgId)
  3395. for _, it := range manufacturList {
  3396. if manufacturer == it.ManufacturerName {
  3397. manufacturer_id = it.ID
  3398. }
  3399. }
  3400. drug.Manufacturer = manufacturer_id
  3401. dealer := goodNameM["dealer"].(string)
  3402. if len(dealer) != 0 {
  3403. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  3404. if errcodesdealer == gorm.ErrRecordNotFound {
  3405. dealerconfig := models.Dealer{
  3406. DealerName: dealer,
  3407. Status: 1,
  3408. OrgId: orgId,
  3409. Ctime: time.Now().Unix(),
  3410. Creater: adminUser.AdminUser.Id,
  3411. }
  3412. service.CreateDealer(&dealerconfig)
  3413. }
  3414. }
  3415. var dealer_id int64
  3416. dealerList, _ := service.GetAllDealerList(orgId)
  3417. for _, it := range dealerList {
  3418. if dealer == it.DealerName {
  3419. dealer_id = it.ID
  3420. }
  3421. }
  3422. drug.Dealer = dealer_id
  3423. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  3424. drug.LmtUsedFlag = lmt_used_flags
  3425. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  3426. utils.ErrorLog("drug_alias")
  3427. return
  3428. }
  3429. drug_alias, _ := goodNameM["drug_alias"].(string)
  3430. drug.DrugAlias = drug_alias
  3431. drug_category := goodNameM["drug_category"].(string)
  3432. var drugCategory = "药品类别"
  3433. var drug_category_id int64
  3434. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  3435. if len(drug_category) != 0 {
  3436. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  3437. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  3438. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  3439. dataconfig := models.DictDataconfig{
  3440. ParentId: drugCategoryConfig.ID,
  3441. Module: "system",
  3442. OrgId: orgId,
  3443. Name: drug_category,
  3444. FieldName: "",
  3445. Value: drugCategoryConfigSix.Value + 1,
  3446. CreatedTime: "",
  3447. UpdatedTime: "",
  3448. CreateUserId: adminUser.AdminUser.Id,
  3449. Status: 1,
  3450. Remark: "",
  3451. DeleteIdSystem: 0,
  3452. Title: "",
  3453. Content: "",
  3454. Order: 0,
  3455. Code: "",
  3456. }
  3457. service.CreatedDicConfig(&dataconfig)
  3458. }
  3459. }
  3460. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  3461. fmt.Println("drugCategoryList", drugCategoryList)
  3462. for _, it := range drugCategoryList {
  3463. if drug_category == it.Name {
  3464. drug_category_id = int64(it.Value)
  3465. }
  3466. }
  3467. drug.DrugCategory = drug_category_id
  3468. statistics_category := goodNameM["statistics_category"].(string)
  3469. var statisticsCategory = "统计分类"
  3470. var statistics_category_id int64
  3471. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3472. if len(statistics_category) != 0 {
  3473. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  3474. if errcodestatistc == gorm.ErrRecordNotFound {
  3475. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  3476. dataconfig := models.DictDataconfig{
  3477. ParentId: statistcConfig.ID,
  3478. Module: "system",
  3479. OrgId: orgId,
  3480. Name: statistics_category,
  3481. FieldName: "",
  3482. Value: staConfig.Value + 1,
  3483. CreatedTime: "",
  3484. UpdatedTime: "",
  3485. CreateUserId: adminUser.AdminUser.Id,
  3486. Status: 1,
  3487. Remark: "",
  3488. DeleteIdSystem: 0,
  3489. Title: "",
  3490. Content: "",
  3491. Order: 0,
  3492. Code: "",
  3493. }
  3494. service.CreatedDicConfig(&dataconfig)
  3495. }
  3496. }
  3497. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  3498. for _, it := range statisticsCategoryList {
  3499. if statistics_category == it.Name {
  3500. statistics_category_id = int64(it.Value)
  3501. }
  3502. }
  3503. drug.StatisticsCategory = statistics_category_id
  3504. number := goodNameM["number"].(string)
  3505. drug.Number = number
  3506. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  3507. drug.HospApprFlag = hosp_appr_flag
  3508. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3509. drug.MedicalInsuranceNumber = medical_insurance_number
  3510. pharmacology_category := goodNameM["pharmacology_category"].(string)
  3511. var pharmacology = "药理分类"
  3512. var pharmacology_category_id int64
  3513. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  3514. if len(pharmacology_category) != 0 {
  3515. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  3516. if errcodespharmacology == gorm.ErrRecordNotFound {
  3517. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  3518. dataconfig := models.DictDataconfig{
  3519. ParentId: pharmacologyConfig.ID,
  3520. Module: "system",
  3521. OrgId: orgId,
  3522. Name: pharmacology_category,
  3523. FieldName: "",
  3524. Value: dicConfig.Value + 1,
  3525. CreatedTime: "",
  3526. UpdatedTime: "",
  3527. CreateUserId: adminUser.AdminUser.Id,
  3528. Status: 1,
  3529. Remark: "",
  3530. DeleteIdSystem: 0,
  3531. Title: "",
  3532. Content: "",
  3533. Order: 0,
  3534. Code: "",
  3535. }
  3536. service.CreatedDicConfig(&dataconfig)
  3537. }
  3538. }
  3539. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  3540. for _, it := range pharmacologyList {
  3541. if pharmacology_category == it.Name {
  3542. pharmacology_category_id = int64(it.Value)
  3543. }
  3544. }
  3545. drug.PharmacologyCategory = pharmacology_category_id
  3546. code := goodNameM["code"].(string)
  3547. drug.Code = code
  3548. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3549. drug.IsSpecialDiseases = is_special_diseases
  3550. is_record := int64(goodNameM["is_record"].(float64))
  3551. drug.IsRecord = is_record
  3552. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  3553. drug.PrescriptionMark = prescription_mark
  3554. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3555. drug.SocialSecurityDirectoryCode = social_security_directory_code
  3556. record_date := goodNameM["record_date"].(string)
  3557. timeLayout := "2006-01-02"
  3558. loc, _ := time.LoadLocation("Local")
  3559. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3560. drug.RecordDate = theTime.Unix()
  3561. drug_remark := goodNameM["drug_remark"].(string)
  3562. drug.DrugRemark = drug_remark
  3563. drug_status := goodNameM["drug_status"].(string)
  3564. drug.DrugStatus = drug_status
  3565. limit_remark := goodNameM["limit_remark"].(string)
  3566. drug.LimitRemark = limit_remark
  3567. drug_control := goodNameM["drug_control"].(string)
  3568. var drugControl = "开药控制"
  3569. var drug_control_id int64
  3570. drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
  3571. if len(drug_control) != 0 {
  3572. _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
  3573. if errcodesdrugcontrol == gorm.ErrRecordNotFound {
  3574. drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
  3575. dataconfig := models.DictDataconfig{
  3576. ParentId: drugContorlConfig.ID,
  3577. Module: "system",
  3578. OrgId: orgId,
  3579. Name: drug_control,
  3580. FieldName: "",
  3581. Value: drugContorlConfigOne.Value + 1,
  3582. CreatedTime: "",
  3583. UpdatedTime: "",
  3584. CreateUserId: adminUser.AdminUser.Id,
  3585. Status: 1,
  3586. Remark: "",
  3587. DeleteIdSystem: 0,
  3588. Title: "",
  3589. Content: "",
  3590. Order: 0,
  3591. Code: "",
  3592. }
  3593. service.CreatedDicConfig(&dataconfig)
  3594. }
  3595. }
  3596. drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
  3597. for _, it := range drugContorlList {
  3598. if drug_control == it.Name {
  3599. drug_control_id = int64(it.Value)
  3600. }
  3601. }
  3602. drug.DrugControl = drug_control_id
  3603. drugList = append(drugList, &drug)
  3604. }
  3605. export_time := time.Now().Unix()
  3606. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3607. if len(drugList) > 0 {
  3608. for _, item := range drugList {
  3609. goodInfo := models.BaseDrugLib{
  3610. DrugName: item.DrugName,
  3611. DrugAlias: item.DrugAlias,
  3612. DrugSpec: item.DrugSpec,
  3613. DrugType: item.DrugType,
  3614. DrugStockLimit: item.DrugStockLimit,
  3615. DrugOriginPlace: item.DrugOriginPlace,
  3616. DrugDosageForm: item.DrugDosageForm,
  3617. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3618. MaxUnit: item.MaxUnit,
  3619. MinUnit: item.MinUnit,
  3620. UnitMatrixing: item.UnitMatrixing,
  3621. RetailPrice: item.RetailPrice,
  3622. LastPrice: item.LastPrice,
  3623. DrugClassify: item.DrugClassify,
  3624. Manufacturer: item.Manufacturer,
  3625. Dealer: item.Dealer,
  3626. OrgId: orgId,
  3627. Status: 1,
  3628. Ctime: time.Now().Unix(),
  3629. Pinyin: item.Pinyin,
  3630. Wubi: item.Wubi,
  3631. DrugAliasPinyin: item.DrugAliasPinyin,
  3632. DrugAliasWubi: item.DrugAliasWubi,
  3633. DrugControl: item.DrugControl,
  3634. Number: item.Number,
  3635. HospApprFlag: item.HospApprFlag,
  3636. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3637. PharmacologyCategory: item.PharmacologyCategory,
  3638. StatisticsCategory: item.StatisticsCategory,
  3639. Code: item.Code,
  3640. IsSpecialDiseases: item.IsSpecialDiseases,
  3641. IsRecord: item.IsRecord,
  3642. PrescriptionMark: item.PrescriptionMark,
  3643. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3644. RecordDate: item.RecordDate,
  3645. DrugRemark: item.DrugRemark,
  3646. DrugStatus: item.DrugStatus,
  3647. LimitRemark: item.LimitRemark,
  3648. DrugCategory: item.DrugCategory,
  3649. DrugDose: item.DrugDose,
  3650. DrugDoseUnit: item.DrugDoseUnit,
  3651. LmtUsedFlag: item.LmtUsedFlag,
  3652. DrugDay: item.DrugDay,
  3653. DeliveryWay: item.DeliveryWay,
  3654. ExecutionFrequency: item.ExecutionFrequency,
  3655. DoseUnit: item.DoseUnit,
  3656. }
  3657. //查询同种药品同种规格是否存在
  3658. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.MaxUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  3659. if drugerror == gorm.ErrRecordNotFound {
  3660. service.CreateDrugsInfomation(&goodInfo)
  3661. } else if drugerror == nil {
  3662. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  3663. }
  3664. log := models.ExportLog{
  3665. LogType: 4,
  3666. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3667. TotalNum: int64(len(total_goods)),
  3668. FailNum: int64(len(errLogs)),
  3669. SuccessNum: int64(len(drugList)),
  3670. CreateTime: time.Now().Unix(),
  3671. UpdateTime: time.Now().Unix(),
  3672. ExportTime: export_time,
  3673. Status: 1,
  3674. }
  3675. service.CreateExportLog(&log)
  3676. this.ServeSuccessJSON(map[string]interface{}{
  3677. "msg": "导入成功",
  3678. "total_num": len(total_goods),
  3679. "success_num": len(drugList),
  3680. "fail_num": int64(len(errLogs)),
  3681. })
  3682. }
  3683. } else {
  3684. log := models.ExportLog{
  3685. LogType: 4,
  3686. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3687. TotalNum: int64(len(total_goods)),
  3688. FailNum: int64(len(errLogs)),
  3689. SuccessNum: int64(len(drugList)),
  3690. CreateTime: time.Now().Unix(),
  3691. UpdateTime: time.Now().Unix(),
  3692. ExportTime: export_time,
  3693. Status: 1,
  3694. }
  3695. service.CreateExportLog(&log)
  3696. this.ServeSuccessJSON(map[string]interface{}{
  3697. "msg": "导入成功",
  3698. "total_num": len(total_goods),
  3699. "success_num": len(drugList),
  3700. "fail_num": int64(len(errLogs)),
  3701. })
  3702. }
  3703. }
  3704. func (this *StockManagerApiController) GetInitializtion() {
  3705. orgId := this.GetAdminUserInfo().CurrentOrgId
  3706. var drugCategory = "药品类别"
  3707. var drugType = "药品类型"
  3708. var drugDosageForm = "药品剂型"
  3709. var medicalInsuranceLevel = "医保等级"
  3710. var drugControl = "开药控制"
  3711. var drugClassify = "药物分类"
  3712. var statisticsCategory = "统计分类"
  3713. var pharmacologyCategory = "药理分类"
  3714. var goodKind = "耗材种类"
  3715. var tubeColor = "试管颜色"
  3716. var costClassify = "费用类别"
  3717. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3718. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3719. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  3720. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  3721. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  3722. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  3723. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  3724. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  3725. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  3726. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  3727. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  3728. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  3729. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3730. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  3731. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  3732. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  3733. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  3734. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  3735. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  3736. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  3737. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  3738. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  3739. this.ServeSuccessJSON(map[string]interface{}{
  3740. "drugCategoryList": drugCategoryList,
  3741. "drugTypeList": drugTypeList,
  3742. "drugDosageFormList": drugDosageFormList,
  3743. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  3744. "drugControlList": drugControlList,
  3745. "drugClassifyList": drugClassifyList,
  3746. "statisticsCategoryList": statisticsCategoryList,
  3747. "pharmacologyCategoryList": pharmacologyCategoryList,
  3748. "goodKindList": goodKindList,
  3749. "tubeColorList": tubeColorList,
  3750. "costClassifyList": costClassifyList,
  3751. })
  3752. }
  3753. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  3754. adminUserInfo := this.GetAdminUserInfo()
  3755. orgId := adminUserInfo.CurrentOrgId
  3756. list, _ := service.GetWarehouseOrderInfoList(orgId)
  3757. this.ServeSuccessJSON(map[string]interface{}{
  3758. "list": list,
  3759. })
  3760. }
  3761. func (this *StockManagerApiController) PostSearchGoodList() {
  3762. keyword := this.GetString("keyword")
  3763. adminUserInfo := this.GetAdminUserInfo()
  3764. orgId := adminUserInfo.CurrentOrgId
  3765. list, _ := service.GetSearchGoodList(keyword, orgId)
  3766. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3767. dealerList, _ := service.GetAllDealerList(orgId)
  3768. this.ServeSuccessJSON(map[string]interface{}{
  3769. "list": list,
  3770. "manufacturerList": manufacturerList,
  3771. "dealerList": dealerList,
  3772. })
  3773. }
  3774. func (this *StockManagerApiController) GetAllStockList() {
  3775. page, _ := this.GetInt64("page", -1)
  3776. limit, _ := this.GetInt64("limit", -1)
  3777. start_time := this.GetString("start_time")
  3778. end_time := this.GetString("end_time")
  3779. types, _ := this.GetInt64("type", 0)
  3780. keywords := this.GetString("keywords")
  3781. timeLayout := "2006-01-02"
  3782. loc, _ := time.LoadLocation("Local")
  3783. var startTime int64
  3784. if len(start_time) > 0 {
  3785. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3786. if err != nil {
  3787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3788. return
  3789. }
  3790. startTime = theTime.Unix()
  3791. }
  3792. var endTime int64
  3793. if len(end_time) > 0 {
  3794. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3795. if err != nil {
  3796. utils.ErrorLog(err.Error())
  3797. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3798. return
  3799. }
  3800. endTime = theTime.Unix()
  3801. }
  3802. adminUserInfo := this.GetAdminUserInfo()
  3803. orgId := adminUserInfo.CurrentOrgId
  3804. list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId)
  3805. fmt.Println("耗材总计23323232232323232323", total)
  3806. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3807. this.ServeSuccessJSON(map[string]interface{}{
  3808. "list": list,
  3809. "total": total,
  3810. "manufacturerList": manufacturerList,
  3811. })
  3812. }
  3813. func (this *StockManagerApiController) GetStockListById() {
  3814. id, _ := this.GetInt64("id")
  3815. adminUserInfo := this.GetAdminUserInfo()
  3816. orgId := adminUserInfo.CurrentOrgId
  3817. limit, _ := this.GetInt64("limit")
  3818. page, _ := this.GetInt64("page")
  3819. timeLayout := "2006-01-02"
  3820. loc, _ := time.LoadLocation("Local")
  3821. start_time := this.GetString("start_time")
  3822. end_time := this.GetString("end_time")
  3823. var startTime int64
  3824. if len(start_time) > 0 {
  3825. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3826. if err != nil {
  3827. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3828. return
  3829. }
  3830. startTime = theTime.Unix()
  3831. }
  3832. var endTime int64
  3833. if len(end_time) > 0 {
  3834. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3835. if err != nil {
  3836. utils.ErrorLog(err.Error())
  3837. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3838. return
  3839. }
  3840. endTime = theTime.Unix()
  3841. }
  3842. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3843. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime)
  3844. this.ServeSuccessJSON(map[string]interface{}{
  3845. "list": list,
  3846. "total": total,
  3847. "manufacturerList": manufacturerList,
  3848. })
  3849. }
  3850. func (this *StockManagerApiController) GetStockOutList() {
  3851. id, _ := this.GetInt64("id")
  3852. adminUserInfo := this.GetAdminUserInfo()
  3853. orgId := adminUserInfo.CurrentOrgId
  3854. limit, _ := this.GetInt64("limit")
  3855. page, _ := this.GetInt64("page")
  3856. timeLayout := "2006-01-02"
  3857. loc, _ := time.LoadLocation("Local")
  3858. start_time := this.GetString("start_time")
  3859. end_time := this.GetString("end_time")
  3860. is_sys, _ := this.GetInt64("is_sys")
  3861. var startTime int64
  3862. if len(start_time) > 0 {
  3863. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3864. if err != nil {
  3865. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3866. return
  3867. }
  3868. startTime = theTime.Unix()
  3869. }
  3870. var endTime int64
  3871. if len(end_time) > 0 {
  3872. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3873. if err != nil {
  3874. utils.ErrorLog(err.Error())
  3875. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3876. return
  3877. }
  3878. endTime = theTime.Unix()
  3879. }
  3880. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  3881. this.ServeSuccessJSON(map[string]interface{}{
  3882. "outList": outList,
  3883. "total": total,
  3884. })
  3885. }
  3886. func (this *StockManagerApiController) GetStockDrugCount() {
  3887. adminUserInfo := this.GetAdminUserInfo()
  3888. orgId := adminUserInfo.CurrentOrgId
  3889. fmt.Println(orgId)
  3890. timeLayout := "2006-01-02"
  3891. loc, _ := time.LoadLocation("Local")
  3892. start_time := this.GetString("start_time")
  3893. end_time := this.GetString("end_time")
  3894. var startTime int64
  3895. if len(start_time) > 0 {
  3896. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3897. if err != nil {
  3898. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3899. return
  3900. }
  3901. startTime = theTime.Unix()
  3902. }
  3903. var endTime int64
  3904. if len(end_time) > 0 {
  3905. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3906. if err != nil {
  3907. utils.ErrorLog(err.Error())
  3908. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3909. return
  3910. }
  3911. endTime = theTime.Unix()
  3912. }
  3913. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  3914. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  3915. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  3916. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  3917. this.ServeSuccessJSON(map[string]interface{}{
  3918. "count": count,
  3919. "outList": outList,
  3920. "autoCount": autoCount,
  3921. "totalCount": totalCount,
  3922. })
  3923. }
  3924. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  3925. ids := this.GetString("id")
  3926. idsArray := strings.Split(ids, ",")
  3927. orgId := this.GetAdminUserInfo().CurrentOrgId
  3928. order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
  3929. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  3930. //获取该耗材的最后一条数据
  3931. info, _ := service.GetLastWarehouseOutInfo(idsArray, orgId)
  3932. fmt.Println("info323e2342342342432342342432", info)
  3933. this.ServeSuccessJSON(map[string]interface{}{
  3934. "order": order,
  3935. "list": list,
  3936. "info": info,
  3937. })
  3938. }
  3939. func (this *StockManagerApiController) GetOrderDetailById() {
  3940. id, _ := this.GetInt64("id")
  3941. good_id, _ := this.GetInt64("good_id")
  3942. record_time, _ := this.GetInt64("record_time")
  3943. orgId := this.GetAdminUserInfo().CurrentOrgId
  3944. //自动出库
  3945. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  3946. //手动出库
  3947. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  3948. stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
  3949. if err == nil {
  3950. this.ServeSuccessJSON(map[string]interface{}{
  3951. "list": userDetails,
  3952. "total": total,
  3953. "info": info,
  3954. "stockFlowList": stockFlowList,
  3955. })
  3956. } else {
  3957. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3958. return
  3959. }
  3960. }
  3961. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  3962. id, _ := this.GetInt64("id", 0)
  3963. orgId := this.GetAdminUserInfo().CurrentOrgId
  3964. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  3965. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3966. dealerList, _ := service.GetAllDealerList(orgId)
  3967. goodType, _ := service.GetAllGoodType(orgId)
  3968. this.ServeSuccessJSON(map[string]interface{}{
  3969. "list": warehouseOutInfo,
  3970. "dealerList": dealerList,
  3971. "manufacturerList": manufacturerList,
  3972. "goodType": goodType,
  3973. })
  3974. }
  3975. func (this *StockManagerApiController) GetExprotStockList() {
  3976. adminUserInfo := this.GetAdminUserInfo()
  3977. orgId := adminUserInfo.CurrentOrgId
  3978. timeLayout := "2006-01-02"
  3979. loc, _ := time.LoadLocation("Local")
  3980. start_time := this.GetString("start_time")
  3981. end_time := this.GetString("end_time")
  3982. idArray := this.GetString("id")
  3983. ids := strings.Split(idArray, ",")
  3984. var startTime int64
  3985. if len(start_time) > 0 {
  3986. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3987. if err != nil {
  3988. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3989. return
  3990. }
  3991. startTime = theTime.Unix()
  3992. }
  3993. var endTime int64
  3994. if len(end_time) > 0 {
  3995. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3996. if err != nil {
  3997. utils.ErrorLog(err.Error())
  3998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3999. return
  4000. }
  4001. endTime = theTime.Unix()
  4002. }
  4003. fmt.Println("ids2222222222222222", ids)
  4004. list, _ := service.GetExprotStockList(orgId, ids, startTime, endTime)
  4005. this.ServeSuccessJSON(map[string]interface{}{
  4006. "list": list,
  4007. })
  4008. }
  4009. func (this *StockManagerApiController) GetOutExprotList() {
  4010. adminUserInfo := this.GetAdminUserInfo()
  4011. orgId := adminUserInfo.CurrentOrgId
  4012. timeLayout := "2006-01-02"
  4013. loc, _ := time.LoadLocation("Local")
  4014. start_time := this.GetString("start_time")
  4015. end_time := this.GetString("end_time")
  4016. idArray := this.GetString("id")
  4017. ids := strings.Split(idArray, ",")
  4018. fmt.Println("ids2222222222", ids)
  4019. var startTime int64
  4020. if len(start_time) > 0 {
  4021. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4022. if err != nil {
  4023. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4024. return
  4025. }
  4026. startTime = theTime.Unix()
  4027. }
  4028. var endTime int64
  4029. if len(end_time) > 0 {
  4030. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4031. if err != nil {
  4032. utils.ErrorLog(err.Error())
  4033. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4034. return
  4035. }
  4036. endTime = theTime.Unix()
  4037. }
  4038. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  4039. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  4040. this.ServeSuccessJSON(map[string]interface{}{
  4041. "list": list,
  4042. "count": outCount,
  4043. })
  4044. }
  4045. func (this *StockManagerApiController) GetSingleCancelOrder() {
  4046. id, _ := this.GetInt64("id")
  4047. adminUserInfo := this.GetAdminUserInfo()
  4048. orgId := adminUserInfo.CurrentOrgId
  4049. order, _ := service.GetSingleCancelOrder(id, orgId)
  4050. this.ServeSuccessJSON(map[string]interface{}{
  4051. "list": order,
  4052. })
  4053. }
  4054. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  4055. id := this.GetString("id")
  4056. idStr := strings.Split(id, ",")
  4057. orgId := this.GetAdminUserInfo().CurrentOrgId
  4058. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  4059. this.ServeSuccessJSON(map[string]interface{}{
  4060. "list": list,
  4061. })
  4062. }
  4063. func (this *StockManagerApiController) GetStockBatchNumber() {
  4064. id, _ := this.GetInt64("id")
  4065. orgId := this.GetAdminUserInfo().CurrentOrgId
  4066. list, _ := service.GetStockBatchNumber(id, orgId)
  4067. this.ServeSuccessJSON(map[string]interface{}{
  4068. "list": list,
  4069. })
  4070. }
  4071. func (this *StockManagerApiController) GetStockFlow() {
  4072. limit, _ := this.GetInt64("limit")
  4073. page, _ := this.GetInt64("page")
  4074. good_id, _ := this.GetInt64("good_id")
  4075. consumable_type, _ := this.GetInt64("is_sys")
  4076. adminUserInfo := this.GetAdminUserInfo()
  4077. orgId := adminUserInfo.CurrentOrgId
  4078. timeLayout := "2006-01-02"
  4079. loc, _ := time.LoadLocation("Local")
  4080. start_time := this.GetString("start_time")
  4081. end_time := this.GetString("end_time")
  4082. var startTime int64
  4083. if len(start_time) > 0 {
  4084. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4085. if err != nil {
  4086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4087. return
  4088. }
  4089. startTime = theTime.Unix()
  4090. }
  4091. var endTime int64
  4092. if len(end_time) > 0 {
  4093. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4094. if err != nil {
  4095. utils.ErrorLog(err.Error())
  4096. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4097. return
  4098. }
  4099. endTime = theTime.Unix()
  4100. }
  4101. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  4102. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4103. this.ServeSuccessJSON(map[string]interface{}{
  4104. "list": list,
  4105. "total": total,
  4106. "manufacturerList": manufacturerList,
  4107. })
  4108. }
  4109. func (this *StockManagerApiController) GetCancelExportList() {
  4110. adminUserInfo := this.GetAdminUserInfo()
  4111. orgId := adminUserInfo.CurrentOrgId
  4112. timeLayout := "2006-01-02"
  4113. loc, _ := time.LoadLocation("Local")
  4114. start_time := this.GetString("start_time")
  4115. end_time := this.GetString("end_time")
  4116. idArray := this.GetString("order_id")
  4117. fmt.Println("232323232323232232", idArray)
  4118. ids := strings.Split(idArray, ",")
  4119. var startTime int64
  4120. if len(start_time) > 0 {
  4121. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4122. if err != nil {
  4123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4124. return
  4125. }
  4126. startTime = theTime.Unix()
  4127. }
  4128. var endTime int64
  4129. if len(end_time) > 0 {
  4130. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4131. if err != nil {
  4132. utils.ErrorLog(err.Error())
  4133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4134. return
  4135. }
  4136. endTime = theTime.Unix()
  4137. }
  4138. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  4139. this.ServeSuccessJSON(map[string]interface{}{
  4140. "list": list,
  4141. })
  4142. }
  4143. func (this *StockManagerApiController) GetSearchGoodWarehouseList() {
  4144. keyword := this.GetString("keyword")
  4145. orgId := this.GetAdminUserInfo().CurrentOrgId
  4146. list, _ := service.GetSearchGoodWarehouseList(keyword, orgId)
  4147. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4148. dealerList, _ := service.GetAllDealerList(orgId)
  4149. this.ServeSuccessJSON(map[string]interface{}{
  4150. "list": list,
  4151. "manufacturerList": manufacturerList,
  4152. "dealerList": dealerList,
  4153. })
  4154. }
  4155. func (this *StockManagerApiController) SaveAdjuestPrice() {
  4156. timeLayout := "2006-01-02"
  4157. loc, _ := time.LoadLocation("Local")
  4158. dataBody := make(map[string]interface{}, 0)
  4159. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4160. if err != nil {
  4161. utils.ErrorLog(err.Error())
  4162. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4163. return
  4164. }
  4165. tableData, _ := dataBody["tableData"].([]interface{})
  4166. if len(tableData) > 0 {
  4167. for _, item := range tableData {
  4168. items := item.(map[string]interface{})
  4169. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4170. utils.ErrorLog("good_name")
  4171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4172. return
  4173. }
  4174. good_name := items["good_name"].(string)
  4175. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4176. utils.ErrorLog("good_name")
  4177. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4178. return
  4179. }
  4180. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4181. utils.ErrorLog("packing_price")
  4182. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4183. return
  4184. }
  4185. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4186. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4187. utils.ErrorLog("warehousing_order")
  4188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4189. return
  4190. }
  4191. warehousing_order := items["warehousing_order"].(string)
  4192. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4193. utils.ErrorLog("license_number")
  4194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4195. return
  4196. }
  4197. license_number := items["license_number"].(string)
  4198. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4199. utils.ErrorLog("dealer")
  4200. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4201. return
  4202. }
  4203. dealer := items["dealer"].(string)
  4204. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4205. utils.ErrorLog("manufacturer")
  4206. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4207. return
  4208. }
  4209. manufacturer := items["manufacturer"].(string)
  4210. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4211. utils.ErrorLog("specification_name")
  4212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4213. return
  4214. }
  4215. specification_name := items["specification_name"].(string)
  4216. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4217. utils.ErrorLog("remark")
  4218. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4219. return
  4220. }
  4221. remark := items["remark"].(string)
  4222. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4223. utils.ErrorLog("warehousing_unit")
  4224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4225. return
  4226. }
  4227. warehousing_unit := items["warehousing_unit"].(string)
  4228. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4229. utils.ErrorLog("buy_price")
  4230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4231. return
  4232. }
  4233. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4234. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4235. utils.ErrorLog("count")
  4236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4237. return
  4238. }
  4239. count := int64(items["count"].(float64))
  4240. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  4241. utils.ErrorLog("new_price")
  4242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4243. return
  4244. }
  4245. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  4246. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4247. utils.ErrorLog("good_id")
  4248. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4249. return
  4250. }
  4251. good_id := int64(items["good_id"].(float64))
  4252. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4253. utils.ErrorLog("start_time")
  4254. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4255. return
  4256. }
  4257. var startTime int64
  4258. start_time := items["start_time"].(string)
  4259. if len(start_time) > 0 {
  4260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4261. if err != nil {
  4262. fmt.Println(err)
  4263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4264. return
  4265. }
  4266. startTime = theTime.Unix()
  4267. }
  4268. orgId := this.GetAdminUserInfo().CurrentOrgId
  4269. adjustprice := models.XtStockAdjustPrice{
  4270. GoodName: good_name,
  4271. SpecificationName: specification_name,
  4272. WarehousingUnit: warehousing_unit,
  4273. Count: count,
  4274. BuyPrice: buy_price,
  4275. PackingPrice: packing_price,
  4276. NewPrice: new_price,
  4277. Manufacturer: manufacturer,
  4278. Dealer: dealer,
  4279. Remark: remark,
  4280. GoodId: good_id,
  4281. UserOrgId: orgId,
  4282. Ctime: time.Now().Unix(),
  4283. Mtime: 0,
  4284. Status: 1,
  4285. WarehousingOrder: warehousing_order,
  4286. LicenseNumber: license_number,
  4287. StartTime: startTime,
  4288. Creater: this.GetAdminUserInfo().AdminUser.Id,
  4289. CheckerStatus: 2,
  4290. }
  4291. service.CreateAdjustPrice(&adjustprice)
  4292. }
  4293. }
  4294. this.ServeSuccessJSON(map[string]interface{}{
  4295. "msg": "保存成功!",
  4296. })
  4297. }
  4298. func (this *StockManagerApiController) GetAllStockPrice() {
  4299. timeLayout := "2006-01-02"
  4300. loc, _ := time.LoadLocation("Local")
  4301. dataBody := make(map[string]interface{}, 0)
  4302. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4303. fmt.Println(err)
  4304. orgId := this.GetAdminUserInfo().CurrentOrgId
  4305. keyword := this.GetString("keyword")
  4306. start_time := this.GetString("start_time")
  4307. end_time := this.GetString("end_time")
  4308. limit, _ := this.GetInt64("limit")
  4309. page, _ := this.GetInt64("page")
  4310. var startTime int64
  4311. if len(start_time) > 0 {
  4312. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4313. if err != nil {
  4314. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4315. return
  4316. }
  4317. startTime = theTime.Unix()
  4318. }
  4319. var endTime int64
  4320. if len(end_time) > 0 {
  4321. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4322. if err != nil {
  4323. utils.ErrorLog(err.Error())
  4324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4325. return
  4326. }
  4327. endTime = theTime.Unix()
  4328. }
  4329. list, total, _ := service.GetAllStockPrice(orgId, startTime, endTime, keyword, limit, page)
  4330. doctor, _ := service.GetAllDoctorThree(orgId)
  4331. this.ServeSuccessJSON(map[string]interface{}{
  4332. "list": list,
  4333. "doctor": doctor,
  4334. "total": total,
  4335. })
  4336. }
  4337. func (this *StockManagerApiController) SaveCheckPrice() {
  4338. timeLayout := "2006-01-02"
  4339. loc, _ := time.LoadLocation("Local")
  4340. dataBody := make(map[string]interface{}, 0)
  4341. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4342. fmt.Println(err)
  4343. idstr := this.GetString("ids")
  4344. ids := strings.Split(idstr, ",")
  4345. check_time := this.GetString("check_time")
  4346. var checkTime int64
  4347. if len(check_time) > 0 {
  4348. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4349. if err != nil {
  4350. fmt.Println(err)
  4351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4352. return
  4353. }
  4354. checkTime = theTime.Unix()
  4355. }
  4356. checker, _ := this.GetInt64("checker")
  4357. adjustPrice := models.XtStockAdjustPrice{
  4358. Checker: checker,
  4359. CheckerStatus: 1,
  4360. CheckerTime: checkTime,
  4361. }
  4362. err = service.UpdateAdjustPrice(ids, adjustPrice)
  4363. fmt.Println(err)
  4364. list, _ := service.GetAdjustCheckPriceList(ids)
  4365. fmt.Println("list2333223323232323232323", list)
  4366. for _, item := range list {
  4367. info := models.GoodInfo{
  4368. PackingPrice: item.NewPrice,
  4369. BuyPrice: item.NewPrice,
  4370. }
  4371. err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
  4372. fmt.Println(err)
  4373. }
  4374. this.ServeSuccessJSON(map[string]interface{}{
  4375. "adjustPrice": adjustPrice,
  4376. })
  4377. }
  4378. func (this *StockManagerApiController) GetAdjustPriceById() {
  4379. ids := this.GetString("ids")
  4380. fmt.Println("ids23232233223233232", ids)
  4381. splitIds := strings.Split(ids, ",")
  4382. list, _ := service.GetAdjustPricebyIdOne(splitIds)
  4383. fmt.Println("list2322322323", list)
  4384. this.ServeSuccessJSON(map[string]interface{}{
  4385. "list": list,
  4386. })
  4387. }
  4388. func (this *StockManagerApiController) SaveReportStock() {
  4389. timeLayout := "2006-01-02"
  4390. loc, _ := time.LoadLocation("Local")
  4391. dataBody := make(map[string]interface{}, 0)
  4392. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4393. if err != nil {
  4394. utils.ErrorLog(err.Error())
  4395. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4396. return
  4397. }
  4398. tableData, _ := dataBody["tableData"].([]interface{})
  4399. if len(tableData) > 0 {
  4400. for _, item := range tableData {
  4401. items := item.(map[string]interface{})
  4402. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4403. utils.ErrorLog("good_name")
  4404. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4405. return
  4406. }
  4407. good_name := items["good_name"].(string)
  4408. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4409. utils.ErrorLog("good_name")
  4410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4411. return
  4412. }
  4413. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4414. utils.ErrorLog("packing_price")
  4415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4416. return
  4417. }
  4418. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4419. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4420. utils.ErrorLog("warehousing_order")
  4421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4422. return
  4423. }
  4424. warehousing_order := items["warehousing_order"].(string)
  4425. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4426. utils.ErrorLog("license_number")
  4427. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4428. return
  4429. }
  4430. license_number := items["license_number"].(string)
  4431. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4432. utils.ErrorLog("dealer")
  4433. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4434. return
  4435. }
  4436. dealer := items["dealer"].(string)
  4437. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4438. utils.ErrorLog("manufacturer")
  4439. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4440. return
  4441. }
  4442. manufacturer := items["manufacturer"].(string)
  4443. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4444. utils.ErrorLog("specification_name")
  4445. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4446. return
  4447. }
  4448. specification_name := items["specification_name"].(string)
  4449. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4450. utils.ErrorLog("remark")
  4451. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4452. return
  4453. }
  4454. remark := items["remark"].(string)
  4455. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4456. utils.ErrorLog("warehousing_unit")
  4457. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4458. return
  4459. }
  4460. warehousing_unit := items["warehousing_unit"].(string)
  4461. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4462. utils.ErrorLog("buy_price")
  4463. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4464. return
  4465. }
  4466. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4467. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4468. utils.ErrorLog("count")
  4469. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4470. return
  4471. }
  4472. count := int64(items["count"].(float64))
  4473. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4474. utils.ErrorLog("good_id")
  4475. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4476. return
  4477. }
  4478. good_id := int64(items["good_id"].(float64))
  4479. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4480. utils.ErrorLog("start_time")
  4481. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4482. return
  4483. }
  4484. var startTime int64
  4485. start_time := items["start_time"].(string)
  4486. if len(start_time) > 0 {
  4487. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4488. if err != nil {
  4489. fmt.Println(err)
  4490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4491. return
  4492. }
  4493. startTime = theTime.Unix()
  4494. }
  4495. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4496. utils.ErrorLog("number")
  4497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4498. return
  4499. }
  4500. number := items["number"].(string)
  4501. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4502. utils.ErrorLog("warehousing_info_id")
  4503. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4504. return
  4505. }
  4506. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4507. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4508. utils.ErrorLog("expiry_date")
  4509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4510. return
  4511. }
  4512. expiry_date := int64(items["expiry_date"].(float64))
  4513. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4514. utils.ErrorLog("product_date")
  4515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4516. return
  4517. }
  4518. product_date := int64(items["product_date"].(float64))
  4519. orgId := this.GetAdminUserInfo().CurrentOrgId
  4520. Creater := this.GetAdminUserInfo().AdminUser.Id
  4521. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4522. utils.ErrorLog("total")
  4523. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4524. return
  4525. }
  4526. total := int64(items["total"].(float64))
  4527. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  4528. utils.ErrorLog("good_origin_place")
  4529. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4530. return
  4531. }
  4532. good_origin_place := items["good_origin_place"].(string)
  4533. reportPrice := models.XtStockReportPrice{
  4534. GoodName: good_name,
  4535. SpecificationName: specification_name,
  4536. WarehousingUnit: warehousing_unit,
  4537. Count: count,
  4538. BuyPrice: buy_price,
  4539. PackingPrice: packing_price,
  4540. Manufacturer: manufacturer,
  4541. Dealer: dealer,
  4542. Remark: remark,
  4543. GoodId: good_id,
  4544. UserOrgId: orgId,
  4545. Ctime: time.Now().Unix(),
  4546. Mtime: 0,
  4547. Status: 1,
  4548. WarehousingOrder: warehousing_order,
  4549. LicenseNumber: license_number,
  4550. StartTime: startTime,
  4551. Creater: Creater,
  4552. Checker: 0,
  4553. CheckerStatus: 2,
  4554. CheckerTime: 0,
  4555. Number: number,
  4556. WarehousingInfoId: warehousing_info_id,
  4557. ExpiryDate: expiry_date,
  4558. ProductDate: product_date,
  4559. Total: total,
  4560. GoodOriginPlace: good_origin_place,
  4561. }
  4562. err := service.CreateReportPrice(&reportPrice)
  4563. fmt.Println(err)
  4564. }
  4565. }
  4566. this.ServeSuccessJSON(map[string]interface{}{
  4567. "msg": "保存成功!",
  4568. })
  4569. }
  4570. func (this *StockManagerApiController) GetReportStockList() {
  4571. timeLayout := "2006-01-02"
  4572. loc, _ := time.LoadLocation("Local")
  4573. start_time := this.GetString("start_time")
  4574. end_time := this.GetString("end_time")
  4575. page, _ := this.GetInt64("page")
  4576. limit, _ := this.GetInt64("limit")
  4577. var startTime int64
  4578. if len(start_time) > 0 {
  4579. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4580. if err != nil {
  4581. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4582. return
  4583. }
  4584. startTime = theTime.Unix()
  4585. fmt.Println("开始时间", startTime)
  4586. }
  4587. var endTime int64
  4588. if len(end_time) > 0 {
  4589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4590. if err != nil {
  4591. utils.ErrorLog(err.Error())
  4592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4593. return
  4594. }
  4595. endTime = theTime.Unix()
  4596. }
  4597. orgId := this.GetAdminUserInfo().CurrentOrgId
  4598. keyword := this.GetString("keyword")
  4599. fmt.Println("startTime", startTime, "endTime", endTime)
  4600. list, total, _ := service.GetReportStockList(startTime, endTime, orgId, keyword, page, limit)
  4601. doctorlist, _ := service.GetAllDoctorThree(orgId)
  4602. this.ServeSuccessJSON(map[string]interface{}{
  4603. "list": list,
  4604. "total": total,
  4605. "doctorlist": doctorlist,
  4606. })
  4607. }
  4608. func (this *StockManagerApiController) SaveCheckDamage() {
  4609. timeLayout := "2006-01-02"
  4610. loc, _ := time.LoadLocation("Local")
  4611. idstr := this.GetString("ids")
  4612. ids := strings.Split(idstr, ",")
  4613. check_time := this.GetString("check_time")
  4614. var checkTime int64
  4615. if len(check_time) > 0 {
  4616. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4617. if err != nil {
  4618. fmt.Println(err)
  4619. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4620. return
  4621. }
  4622. checkTime = theTime.Unix()
  4623. }
  4624. checker, _ := this.GetInt64("checker")
  4625. reportprice := models.XtStockReportPrice{
  4626. Checker: checker,
  4627. CheckerStatus: 1,
  4628. CheckerTime: checkTime,
  4629. }
  4630. err := service.UpdateCheckDamage(ids, reportprice)
  4631. fmt.Println(err)
  4632. //获取当前核对的数据
  4633. list, _ := service.GetCheckDamageList(ids)
  4634. ctime := time.Now().Unix()
  4635. adminUserInfo := this.GetAdminUserInfo()
  4636. timeStr := time.Now().Format("2006-01-02")
  4637. timeArr := strings.Split(timeStr, "-")
  4638. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  4639. total = total + 1
  4640. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4641. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4642. number = number + total
  4643. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4644. operation_time := time.Now().Unix()
  4645. creater := adminUserInfo.AdminUser.Id
  4646. warehouseOut := models.WarehouseOut{
  4647. WarehouseOutOrderNumber: warehousing_out_order,
  4648. OperationTime: operation_time,
  4649. OrgId: adminUserInfo.CurrentOrgId,
  4650. Creater: creater,
  4651. Ctime: ctime,
  4652. Status: 1,
  4653. WarehouseOutTime: ctime,
  4654. Type: 1,
  4655. }
  4656. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  4657. if errcodes == gorm.ErrRecordNotFound {
  4658. service.AddSigleWarehouseOut(&warehouseOut)
  4659. }
  4660. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  4661. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  4662. var manufacturer_id int64
  4663. var dealer_id int64
  4664. for _, item := range list {
  4665. for _, it := range manufacturerList {
  4666. if item.Manufacturer == it.ManufacturerName {
  4667. manufacturer_id = it.ID
  4668. }
  4669. }
  4670. for _, its := range dealerList {
  4671. if item.Dealer == its.DealerName {
  4672. dealer_id = its.ID
  4673. }
  4674. }
  4675. //插入出库单
  4676. warehouseOutInfo := &models.WarehouseOutInfo{
  4677. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4678. WarehouseOutId: warehouseOut.ID,
  4679. GoodId: item.GoodId,
  4680. Count: item.Count,
  4681. Price: item.PackingPrice,
  4682. Status: 1,
  4683. Ctime: ctime,
  4684. Remark: item.Remark,
  4685. OrgId: adminUserInfo.CurrentOrgId,
  4686. Type: 2,
  4687. Manufacturer: manufacturer_id,
  4688. Number: item.Number,
  4689. ExpiryDate: item.ExpiryDate,
  4690. ProductDate: item.ProductDate,
  4691. Dealer: dealer_id,
  4692. LicenseNumber: item.LicenseNumber,
  4693. }
  4694. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4695. fmt.Println("99999999999999", errOne)
  4696. //更改库存
  4697. info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  4698. warehousingInfo := models.WarehousingInfo{
  4699. StockCount: info.StockCount - item.Count,
  4700. }
  4701. errOne = service.UpdateGoodWarehouseInfo(item.WarehousingInfoId, warehousingInfo)
  4702. fmt.Println(errOne)
  4703. flow := models.VmStockFlow{
  4704. WarehousingId: 0,
  4705. GoodId: item.GoodId,
  4706. Number: item.Number,
  4707. LicenseNumber: item.LicenseNumber,
  4708. Count: item.Count,
  4709. UserOrgId: adminUserInfo.CurrentOrgId,
  4710. PatientId: 0,
  4711. SystemTime: time.Now().Unix(),
  4712. ConsumableType: 5,
  4713. IsSys: 0,
  4714. WarehousingOrder: "",
  4715. WarehouseOutId: warehouseOutInfo.ID,
  4716. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4717. IsEdit: 0,
  4718. CancelStockId: 0,
  4719. CancelOrderNumber: "",
  4720. Manufacturer: 0,
  4721. Dealer: 0,
  4722. Creator: adminUserInfo.AdminUser.Id,
  4723. UpdateCreator: 0,
  4724. Status: 1,
  4725. Ctime: time.Now().Unix(),
  4726. Mtime: 0,
  4727. Price: item.PackingPrice,
  4728. WarehousingDetailId: 0,
  4729. WarehouseOutDetailId: 0,
  4730. CancelOutDetailId: 0,
  4731. ProductDate: item.ProductDate,
  4732. ExpireDate: item.ExpiryDate,
  4733. }
  4734. service.CreateStockFlowOne(flow)
  4735. }
  4736. this.ServeSuccessJSON(map[string]interface{}{
  4737. "reportPrice": reportprice,
  4738. })
  4739. }
  4740. func (this *StockManagerApiController) SaveInventory() {
  4741. timeLayout := "2006-01-02"
  4742. loc, _ := time.LoadLocation("Local")
  4743. dataBody := make(map[string]interface{}, 0)
  4744. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4745. if err != nil {
  4746. utils.ErrorLog(err.Error())
  4747. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4748. return
  4749. }
  4750. tableData, _ := dataBody["tableData"].([]interface{})
  4751. if len(tableData) > 0 {
  4752. for _, item := range tableData {
  4753. items := item.(map[string]interface{})
  4754. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4755. utils.ErrorLog("good_name")
  4756. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4757. return
  4758. }
  4759. good_name := items["good_name"].(string)
  4760. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4761. utils.ErrorLog("good_name")
  4762. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4763. return
  4764. }
  4765. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4766. utils.ErrorLog("packing_price")
  4767. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4768. return
  4769. }
  4770. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4771. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4772. utils.ErrorLog("warehousing_order")
  4773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4774. return
  4775. }
  4776. warehousing_order := items["warehousing_order"].(string)
  4777. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4778. utils.ErrorLog("license_number")
  4779. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4780. return
  4781. }
  4782. license_number := items["license_number"].(string)
  4783. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4784. utils.ErrorLog("dealer")
  4785. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4786. return
  4787. }
  4788. dealer := items["dealer"].(string)
  4789. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4790. utils.ErrorLog("manufacturer")
  4791. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4792. return
  4793. }
  4794. manufacturer := items["manufacturer"].(string)
  4795. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4796. utils.ErrorLog("specification_name")
  4797. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4798. return
  4799. }
  4800. specification_name := items["specification_name"].(string)
  4801. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4802. utils.ErrorLog("remark")
  4803. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4804. return
  4805. }
  4806. remark := items["remark"].(string)
  4807. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4808. utils.ErrorLog("warehousing_unit")
  4809. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4810. return
  4811. }
  4812. warehousing_unit := items["warehousing_unit"].(string)
  4813. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4814. utils.ErrorLog("buy_price")
  4815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4816. return
  4817. }
  4818. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4819. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4820. utils.ErrorLog("count")
  4821. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4822. return
  4823. }
  4824. count := int64(items["count"].(float64))
  4825. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4826. utils.ErrorLog("good_id")
  4827. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4828. return
  4829. }
  4830. good_id := int64(items["good_id"].(float64))
  4831. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4832. utils.ErrorLog("start_time")
  4833. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4834. return
  4835. }
  4836. var startTime int64
  4837. start_time := items["start_time"].(string)
  4838. if len(start_time) > 0 {
  4839. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4840. if err != nil {
  4841. fmt.Println(err)
  4842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4843. return
  4844. }
  4845. startTime = theTime.Unix()
  4846. }
  4847. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4848. utils.ErrorLog("total")
  4849. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4850. return
  4851. }
  4852. total := int64(items["total"].(float64))
  4853. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4854. utils.ErrorLog("expiry_date")
  4855. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4856. return
  4857. }
  4858. expiry_date := int64(items["expiry_date"].(float64))
  4859. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4860. utils.ErrorLog("product_date")
  4861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4862. return
  4863. }
  4864. product_date := int64(items["product_date"].(float64))
  4865. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4866. utils.ErrorLog("number")
  4867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4868. return
  4869. }
  4870. number := items["number"].(string)
  4871. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4872. utils.ErrorLog("warehousing_info_id")
  4873. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4874. return
  4875. }
  4876. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4877. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  4878. utils.ErrorLog("good_origin_place")
  4879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4880. return
  4881. }
  4882. good_origin_place := items["good_origin_place"].(string)
  4883. orgId := this.GetAdminUserInfo().CurrentOrgId
  4884. Creater := this.GetAdminUserInfo().AdminUser.Id
  4885. inventory := models.XtStockInventory{
  4886. GoodName: good_name,
  4887. SpecificationName: specification_name,
  4888. WarehousingUnit: warehousing_unit,
  4889. Count: count,
  4890. BuyPrice: buy_price,
  4891. PackingPrice: packing_price,
  4892. NewPrice: 0,
  4893. Manufacturer: manufacturer,
  4894. Dealer: dealer,
  4895. Remark: remark,
  4896. GoodId: good_id,
  4897. UserOrgId: orgId,
  4898. Ctime: time.Now().Unix(),
  4899. Mtime: 0,
  4900. Status: 1,
  4901. WarehousingOrder: warehousing_order,
  4902. LicenseNumber: license_number,
  4903. StartTime: startTime,
  4904. Creater: Creater,
  4905. Checker: 0,
  4906. CheckerStatus: 2,
  4907. CheckerTime: 0,
  4908. Total: total,
  4909. ExpireDate: expiry_date,
  4910. ProductDate: product_date,
  4911. Number: number,
  4912. WarehousingInfoId: warehousing_info_id,
  4913. GoodOriginPlace: good_origin_place,
  4914. }
  4915. err = service.CreateInentory(inventory)
  4916. fmt.Println(err)
  4917. }
  4918. }
  4919. this.ServeSuccessJSON(map[string]interface{}{
  4920. "msg": "保存成功!",
  4921. })
  4922. }
  4923. func (this *StockManagerApiController) GetInventorylist() {
  4924. timeLayout := "2006-01-02"
  4925. loc, _ := time.LoadLocation("Local")
  4926. start_time := this.GetString("start_time")
  4927. end_time := this.GetString("end_time")
  4928. page, _ := this.GetInt64("page")
  4929. limit, _ := this.GetInt64("limit")
  4930. keyword := this.GetString("keyword")
  4931. inventory_status, _ := this.GetInt64("inventory_status")
  4932. var startTime int64
  4933. if len(start_time) > 0 {
  4934. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4935. if err != nil {
  4936. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4937. return
  4938. }
  4939. startTime = theTime.Unix()
  4940. fmt.Println("开始时间", startTime)
  4941. }
  4942. var endTime int64
  4943. if len(end_time) > 0 {
  4944. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4945. if err != nil {
  4946. utils.ErrorLog(err.Error())
  4947. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4948. return
  4949. }
  4950. endTime = theTime.Unix()
  4951. }
  4952. orgId := this.GetAdminUserInfo().CurrentOrgId
  4953. list, total, _ := service.GetInventorylist(startTime, endTime, page, limit, inventory_status, keyword, orgId)
  4954. doctorlist, _ := service.GetAllDoctorThree(orgId)
  4955. this.ServeSuccessJSON(map[string]interface{}{
  4956. "list": list,
  4957. "total": total,
  4958. "doctorlist": doctorlist,
  4959. })
  4960. }
  4961. func (this *StockManagerApiController) SaveCheckInventory() {
  4962. timeLayout := "2006-01-02"
  4963. loc, _ := time.LoadLocation("Local")
  4964. dataBody := make(map[string]interface{}, 0)
  4965. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4966. fmt.Println(err)
  4967. idstr := this.GetString("ids")
  4968. ids := strings.Split(idstr, ",")
  4969. check_time := this.GetString("check_time")
  4970. var checkTime int64
  4971. if len(check_time) > 0 {
  4972. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4973. if err != nil {
  4974. fmt.Println(err)
  4975. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4976. return
  4977. }
  4978. checkTime = theTime.Unix()
  4979. }
  4980. checker, _ := this.GetInt64("checker")
  4981. inventory := models.XtStockInventory{
  4982. Checker: checker,
  4983. CheckerStatus: 1,
  4984. CheckerTime: checkTime,
  4985. }
  4986. adminUserInfo := this.GetAdminUserInfo()
  4987. err = service.UpdateCheckInventory(ids, inventory)
  4988. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  4989. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  4990. var manufactuer_id int64
  4991. var dealer_id int64
  4992. //查询耗材信息
  4993. list, _ := service.GetInventoryDetailById(ids)
  4994. for _, item := range list {
  4995. for _, it := range manufacturerList {
  4996. if item.Manufacturer == it.ManufacturerName {
  4997. manufactuer_id = it.ID
  4998. }
  4999. }
  5000. for _, its := range dealerList {
  5001. if item.Dealer == its.DealerName {
  5002. dealer_id = its.ID
  5003. }
  5004. }
  5005. //查寻该批次的库存量
  5006. list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5007. //查询该耗材最后1条批次
  5008. info, _ := service.GetLastWarehouseInfo(item.GoodId)
  5009. fmt.Println("总共", item.Count)
  5010. fmt.Println("数据", list.StockCount)
  5011. //盘点盘点库存和et实际库存的大小
  5012. // 如果盘点库存大于实际库存,怎需要入库
  5013. if item.Count > list.StockCount {
  5014. ctime := time.Now().Unix()
  5015. timeStr := time.Now().Format("2006-01-02")
  5016. timeArr := strings.Split(timeStr, "-")
  5017. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  5018. total = total + 1
  5019. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5020. operation_time := time.Now().Unix()
  5021. creater := adminUserInfo.AdminUser.Id
  5022. warehousing := models.Warehousing{
  5023. WarehousingOrder: warehousing_order,
  5024. OperationTime: operation_time,
  5025. OrgId: adminUserInfo.CurrentOrgId,
  5026. Creater: creater,
  5027. Ctime: ctime,
  5028. Status: 1,
  5029. WarehousingTime: ctime,
  5030. Type: 1,
  5031. }
  5032. service.AddSigleWarehouse(&warehousing)
  5033. //获取最
  5034. //入库单表格
  5035. warehouseInfo := models.WarehousingInfo{
  5036. WarehousingOrder: warehousing.WarehousingOrder,
  5037. WarehousingId: warehousing.ID,
  5038. GoodId: item.GoodId,
  5039. Number: info.Number,
  5040. ProductDate: info.ProductDate,
  5041. ExpiryDate: info.ExpiryDate,
  5042. WarehousingCount: item.Count - list.StockCount,
  5043. Price: info.Price,
  5044. Status: 1,
  5045. Ctime: ctime,
  5046. Remark: item.Remark,
  5047. OrgId: adminUserInfo.CurrentOrgId,
  5048. Type: 1,
  5049. Manufacturer: manufactuer_id,
  5050. StockCount: item.Count - list.StockCount,
  5051. Dealer: dealer_id,
  5052. LicenseNumber: info.LicenseNumber,
  5053. WarehouseInfoId: item.WarehousingInfoId,
  5054. }
  5055. flow := models.VmStockFlow{
  5056. WarehousingOrder: warehousing.WarehousingOrder,
  5057. WarehousingId: warehousing.ID,
  5058. GoodId: item.GoodId,
  5059. Number: info.Number,
  5060. ProductDate: info.ProductDate,
  5061. ExpireDate: info.ExpiryDate,
  5062. Count: item.Count - list.StockCount,
  5063. Price: item.BuyPrice,
  5064. Status: 1,
  5065. Ctime: ctime,
  5066. UserOrgId: adminUserInfo.CurrentOrgId,
  5067. Manufacturer: info.Manufacturer,
  5068. Dealer: info.Dealer,
  5069. LicenseNumber: info.LicenseNumber,
  5070. IsEdit: 1,
  5071. Creator: adminUserInfo.AdminUser.Id,
  5072. SystemTime: operation_time,
  5073. ConsumableType: 1,
  5074. WarehousingDetailId: warehouseInfo.ID,
  5075. }
  5076. service.CreateWarehouseInfo(warehouseInfo)
  5077. service.CreateStockFlowOne(flow)
  5078. }
  5079. //如果盘点库存小于实际库存,需要出库
  5080. if item.Count < list.StockCount {
  5081. timeStr := time.Now().Format("2006-01-02")
  5082. timeArr := strings.Split(timeStr, "-")
  5083. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5084. total = total + 1
  5085. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5086. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5087. number = number + total
  5088. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5089. operation_time := time.Now().Unix()
  5090. creater := adminUserInfo.AdminUser.Id
  5091. //查询最早的1条批次
  5092. warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
  5093. warehouseOut := models.WarehouseOut{
  5094. WarehouseOutOrderNumber: warehousing_out_order,
  5095. OperationTime: operation_time,
  5096. OrgId: adminUserInfo.CurrentOrgId,
  5097. Creater: creater,
  5098. Ctime: time.Now().Unix(),
  5099. Status: 1,
  5100. WarehouseOutTime: time.Now().Unix(),
  5101. Type: 1,
  5102. }
  5103. err = service.CreateWarehouseOut(warehouseOut)
  5104. fmt.Println(err)
  5105. warehouseOutInfo := &models.WarehouseOutInfo{
  5106. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5107. WarehouseOutId: warehouseOut.ID,
  5108. GoodId: warehouseInfo.GoodId,
  5109. Count: list.StockCount - item.Count,
  5110. Price: warehouseInfo.Price,
  5111. Status: 1,
  5112. Ctime: time.Now().Unix(),
  5113. Remark: item.Remark,
  5114. OrgId: adminUserInfo.CurrentOrgId,
  5115. Type: 1,
  5116. Manufacturer: manufactuer_id,
  5117. Number: warehouseInfo.Number,
  5118. ExpiryDate: warehouseInfo.ExpiryDate,
  5119. ProductDate: warehouseInfo.ProductDate,
  5120. Dealer: dealer_id,
  5121. LicenseNumber: warehouseInfo.LicenseNumber,
  5122. }
  5123. stockFlow := models.VmStockFlow{
  5124. WarehousingId: item.WarehousingInfoId,
  5125. GoodId: warehouseInfo.GoodId,
  5126. Number: warehouseInfo.Number,
  5127. LicenseNumber: warehouseInfo.LicenseNumber,
  5128. Count: list.StockCount - item.Count,
  5129. UserOrgId: warehouseInfo.OrgId,
  5130. PatientId: 0,
  5131. SystemTime: 0,
  5132. ConsumableType: 2,
  5133. IsSys: 2,
  5134. WarehousingOrder: "",
  5135. WarehouseOutId: warehouseOut.ID,
  5136. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5137. IsEdit: 1,
  5138. CancelStockId: 0,
  5139. CancelOrderNumber: "",
  5140. Manufacturer: manufactuer_id,
  5141. Dealer: dealer_id,
  5142. Creator: adminUserInfo.AdminUser.Id,
  5143. UpdateCreator: 0,
  5144. Status: 1,
  5145. Ctime: time.Now().Unix(),
  5146. Mtime: 0,
  5147. Price: warehouseInfo.Price,
  5148. WarehousingDetailId: 0,
  5149. WarehouseOutDetailId: warehouseOutInfo.ID,
  5150. CancelOutDetailId: 0,
  5151. ProductDate: warehouseInfo.ProductDate,
  5152. ExpireDate: warehouseInfo.ExpiryDate,
  5153. }
  5154. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5155. fmt.Println(errOne)
  5156. //创建出库明细
  5157. service.CreateStockFlowOne(stockFlow)
  5158. //更改库存
  5159. warehousingInfos := models.WarehousingInfo{
  5160. StockCount: item.Count,
  5161. }
  5162. service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
  5163. }
  5164. }
  5165. fmt.Println(err)
  5166. this.ServeSuccessJSON(map[string]interface{}{
  5167. "inventory": inventory,
  5168. })
  5169. }
  5170. func (this *StockManagerApiController) GetModifyPriceDetail() {
  5171. id, _ := this.GetInt64("id")
  5172. detail, _ := service.GetModifyPriceDetail(id)
  5173. this.ServeSuccessJSON(map[string]interface{}{
  5174. "detail": detail,
  5175. })
  5176. }
  5177. func (this *StockManagerApiController) UpdateStockPrice() {
  5178. id, _ := this.GetInt64("id")
  5179. newPrice := this.GetString("new_price")
  5180. new_price, _ := strconv.ParseFloat(newPrice, 64)
  5181. good_name := this.GetString("good_name")
  5182. packingPrice := this.GetString("packing_price")
  5183. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5184. remark := this.GetString("remark")
  5185. good_id, _ := this.GetInt64("good_id")
  5186. manufacturer := this.GetString("manufacturer")
  5187. dealer := this.GetString("dealer")
  5188. adjust := models.XtStockAdjustPrice{
  5189. NewPrice: new_price,
  5190. GoodName: good_name,
  5191. PackingPrice: packing_price,
  5192. Remark: remark,
  5193. GoodId: good_id,
  5194. Manufacturer: manufacturer,
  5195. Dealer: dealer,
  5196. }
  5197. err := service.UpdateStockPrice(adjust, id)
  5198. fmt.Println(err)
  5199. this.ServeSuccessJSON(map[string]interface{}{
  5200. "adjust": adjust,
  5201. })
  5202. }
  5203. func (this *StockManagerApiController) DeleteStockPrice() {
  5204. id, _ := this.GetInt64("id")
  5205. err := service.DeleteStockPrice(id)
  5206. fmt.Println(err)
  5207. returnData := make(map[string]interface{}, 0)
  5208. returnData["msg"] = "ok"
  5209. this.ServeSuccessJSON(returnData)
  5210. return
  5211. }
  5212. func (this *StockManagerApiController) GetStockDamageDetail() {
  5213. id, _ := this.GetInt64("id")
  5214. detail, err := service.GetStockDamageDetail(id)
  5215. fmt.Println(err)
  5216. this.ServeSuccessJSON(map[string]interface{}{
  5217. "detail": detail,
  5218. })
  5219. }
  5220. func (this *StockManagerApiController) ModifyPrice() {
  5221. count, _ := this.GetInt64("count")
  5222. id, _ := this.GetInt64("id")
  5223. good_name := this.GetString("good_name")
  5224. specification_name := this.GetString("specification_name")
  5225. number := this.GetString("number")
  5226. warehousing_unit := this.GetString("warehousing_unit")
  5227. buyPrice := this.GetString("buy_price")
  5228. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5229. packingPrice := this.GetString("packing_price")
  5230. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5231. good_origin_place := this.GetString("good_origin_place")
  5232. manufacturer := this.GetString("manufacturer")
  5233. dealer := this.GetString("dealer")
  5234. total, _ := this.GetInt64("total")
  5235. remark := this.GetString("remark")
  5236. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5237. good_id, _ := this.GetInt64("good_id")
  5238. adjust := models.XtStockReportPrice{
  5239. Count: count,
  5240. SpecificationName: specification_name,
  5241. Number: number,
  5242. GoodName: good_name,
  5243. WarehousingUnit: warehousing_unit,
  5244. BuyPrice: buy_price,
  5245. PackingPrice: packing_price,
  5246. GoodOriginPlace: good_origin_place,
  5247. Manufacturer: manufacturer,
  5248. Dealer: dealer,
  5249. Total: total,
  5250. Remark: remark,
  5251. WarehousingInfoId: warehousing_info_id,
  5252. GoodId: good_id,
  5253. }
  5254. err := service.ModifyPrice(id, adjust)
  5255. fmt.Println(err)
  5256. this.ServeSuccessJSON(map[string]interface{}{
  5257. "adjust": adjust,
  5258. })
  5259. }
  5260. func (this *StockManagerApiController) DeleteDamage() {
  5261. id, _ := this.GetInt64("id")
  5262. err := service.DeleteDamage(id)
  5263. fmt.Println(err)
  5264. returnData := make(map[string]interface{}, 0)
  5265. returnData["msg"] = "ok"
  5266. this.ServeSuccessJSON(returnData)
  5267. return
  5268. }
  5269. func (this *StockManagerApiController) GetStockDamageById() {
  5270. ids := this.GetString("ids")
  5271. splitIds := strings.Split(ids, ",")
  5272. list, _ := service.GetStockDamageById(splitIds)
  5273. this.ServeSuccessJSON(map[string]interface{}{
  5274. "list": list,
  5275. })
  5276. }
  5277. func (this *StockManagerApiController) GetInventoryDetail() {
  5278. id, _ := this.GetInt64("id")
  5279. detail, _ := service.GetInventoryDetail(id)
  5280. this.ServeSuccessJSON(map[string]interface{}{
  5281. "detail": detail,
  5282. })
  5283. }
  5284. func (this *StockManagerApiController) ModifyInventory() {
  5285. id, _ := this.GetInt64("id")
  5286. good_id, _ := this.GetInt64("good_id")
  5287. good_name := this.GetString("good_name")
  5288. specification_name := this.GetString("specification_name")
  5289. number := this.GetString("number")
  5290. warehousing_unit := this.GetString("warehousing_unit")
  5291. buyPrice := this.GetString("buy_price")
  5292. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5293. packingPrice := this.GetString("packing_price")
  5294. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5295. total, _ := this.GetInt64("total")
  5296. good_origin_place := this.GetString("good_origin_place")
  5297. license_number := this.GetString("license_number")
  5298. dealer := this.GetString("dealer")
  5299. manufacturer := this.GetString("manufacturer")
  5300. count, _ := this.GetInt64("count")
  5301. remark := this.GetString("remark")
  5302. inventory := models.XtStockInventory{
  5303. GoodId: good_id,
  5304. GoodName: good_name,
  5305. SpecificationName: specification_name,
  5306. Number: number,
  5307. WarehousingUnit: warehousing_unit,
  5308. BuyPrice: buy_price,
  5309. PackingPrice: packing_price,
  5310. Total: total,
  5311. GoodOriginPlace: good_origin_place,
  5312. LicenseNumber: license_number,
  5313. Dealer: dealer,
  5314. Manufacturer: manufacturer,
  5315. Count: count,
  5316. Remark: remark,
  5317. }
  5318. err := service.ModifyInventory(id, inventory)
  5319. fmt.Println(err)
  5320. this.ServeSuccessJSON(map[string]interface{}{
  5321. "inventory": inventory,
  5322. })
  5323. }
  5324. func (this *StockManagerApiController) DeleteInventory() {
  5325. id, _ := this.GetInt64("id")
  5326. err := service.DeleteInventory(id)
  5327. fmt.Println(err)
  5328. returnData := make(map[string]interface{}, 0)
  5329. returnData["msg"] = "ok"
  5330. this.ServeSuccessJSON(returnData)
  5331. return
  5332. }
  5333. func (this *StockManagerApiController) GetInventoryDetailList() {
  5334. keyword := this.GetString("keyword")
  5335. limit, _ := this.GetInt64("limit")
  5336. page, _ := this.GetInt64("page")
  5337. orgId := this.GetAdminUserInfo().CurrentOrgId
  5338. list, total, _ := service.GetInventoryDetailList(keyword, limit, page, orgId)
  5339. this.ServeSuccessJSON(map[string]interface{}{
  5340. "list": list,
  5341. "total": total,
  5342. })
  5343. }
  5344. func (this *StockManagerApiController) GetInventoryPrintList() {
  5345. ids := this.GetString("ids")
  5346. splitIds := strings.Split(ids, ",")
  5347. list, _ := service.GetInventoryPrintList(splitIds)
  5348. this.ServeSuccessJSON(map[string]interface{}{
  5349. "list": list,
  5350. })
  5351. }
  5352. func (this *StockManagerApiController) GetInventoryDetailPrintList() {
  5353. ids := this.GetString("ids")
  5354. splitIds := strings.Split(ids, ",")
  5355. list, _ := service.GetInventoryDetailPrintList(splitIds)
  5356. this.ServeSuccessJSON(map[string]interface{}{
  5357. "list": list,
  5358. })
  5359. }
  5360. func (this *StockManagerApiController) DeleteDrugPrice() {
  5361. id, _ := this.GetInt64("id")
  5362. err := service.DeleteDrugPrice(id)
  5363. fmt.Println(err)
  5364. returnData := make(map[string]interface{}, 0)
  5365. returnData["msg"] = "ok"
  5366. this.ServeSuccessJSON(returnData)
  5367. return
  5368. }
  5369. func (this *StockManagerApiController) GetGoodWarehouseList() {
  5370. id, _ := this.GetInt64("id")
  5371. list, _ := service.GetGoodWarehouseList(id)
  5372. this.ServeSuccessJSON(map[string]interface{}{
  5373. "list": list,
  5374. })
  5375. }
  5376. func (this *StockManagerApiController) ProofInventory() {
  5377. id, _ := this.GetInt64("id")
  5378. good_id, _ := this.GetInt64("good_id")
  5379. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5380. proof_count, _ := this.GetInt64("proof_count")
  5381. total, _ := this.GetInt64("total")
  5382. orgId := this.GetAdminUserInfo().CurrentOrgId
  5383. creater := this.GetAdminUserInfo().AdminUser.Id
  5384. info := models.WarehousingInfo{
  5385. GoodId: good_id,
  5386. StockCount: proof_count,
  5387. }
  5388. err := service.UpdateProofInventory(warehousing_info_id, info)
  5389. inventory := models.XtStockInventory{
  5390. Total: proof_count,
  5391. }
  5392. err = service.UpdateStockInventory(inventory, id)
  5393. fmt.Println(err)
  5394. record := models.XtStockCorrectRecord{
  5395. GoodId: good_id,
  5396. OrdCount: total,
  5397. WarehousingInfoId: warehousing_info_id,
  5398. NewCount: proof_count,
  5399. UserOrgId: orgId,
  5400. Status: 1,
  5401. Creater: creater,
  5402. Ctime: time.Now().Unix(),
  5403. Mtime: 0,
  5404. }
  5405. service.CeateStockCorrectRecord(record)
  5406. this.ServeSuccessJSON(map[string]interface{}{
  5407. "list": info,
  5408. })
  5409. }
  5410. func (this *StockManagerApiController) GetWarehouseTotal() {
  5411. id, _ := this.GetInt64("id")
  5412. list, _ := service.GetWarehouseTotal(id)
  5413. this.ServeSuccessJSON(map[string]interface{}{
  5414. "list": list,
  5415. })
  5416. }