stock_in_api_controller.go 200KB

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