stock_in_api_controller.go 200KB

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