sync.order.cs 711 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using NHibernate.Linq;
  5. using NHibernate.Mapping;
  6. using NPOI.OpenXmlFormats.Dml.Diagram;
  7. using NPOI.OpenXmlFormats.Shared;
  8. using NPOI.SS.Formula.Eval;
  9. using NPOI.SS.Formula.Functions;
  10. using NPOI.SS.Formula.Udf;
  11. using SiteCore.Redis;
  12. using SiteCore.taobao;
  13. using SiteCore.taoObj;
  14. using SQLData;
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.ComponentModel.Design;
  19. using System.Data;
  20. using System.Data.SqlClient;
  21. using System.Data.SqlTypes;
  22. using System.Diagnostics;
  23. using System.Drawing;
  24. using System.Drawing.Drawing2D;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Net;
  28. using System.Net.Security;
  29. using System.Reflection.Emit;
  30. using System.Security.Cryptography;
  31. using System.Security.Cryptography.X509Certificates;
  32. using System.Security.Policy;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Threading;
  36. using System.Web.UI;
  37. using System.Web;
  38. using System.Web.UI.WebControls;
  39. using Utils;
  40. using Utils.Serialization;
  41. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  42. using static SiteCore.taoObj.Api_trade_info;
  43. using static SiteCore.taoObj.Api_waybill_code_response_Obj;
  44. using static SiteCore.taoObj.work_core_vo;
  45. using static System.Net.Mime.MediaTypeNames;
  46. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  47. using NPOI.Util;
  48. using static NPOI.HSSF.Util.HSSFColor;
  49. using BizCom.Enum;
  50. using NPOI.POIFS.Properties;
  51. using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
  52. using static SiteCore.taoObj.Api_tmc_refund_info_Obj;
  53. using System.Threading.Tasks;
  54. using SiteCore.taoObj.WebApi;
  55. namespace SiteCore.Handler
  56. {
  57. public partial class sync
  58. {
  59. public void get_erp_orderlist()
  60. {
  61. string poscode = CurrentUser.UserPost.Post.Code;
  62. DataStruct dStruct = GetPostStruct();
  63. //commonHelper.sendSpuData(CeErpTradeCell.GetByCtid("C1_2701711344045006369"),CeErpTradeCellExtend.getByTid("C1_2701711344045006369"));
  64. //commonHelper.setDeliveryUnusualOrder2();
  65. //string a = SecurityHelper.DecryptSymmetric("kncY+n90QZs=");
  66. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  67. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  68. //banniuApiHelper.sendLogisticsInfo(null);
  69. //commonHelper.autoDistributeToSupplier(CeErpTradeCell.GetByCode("260112211259328680"));
  70. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  71. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2811249339088067154");
  72. //int sid = commonHelper.autoDistributeToSupplier(entity);
  73. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  74. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1773204794000,\"deliveryType\":\"OFFLINE\",\"discountFee\":25.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1773377590000,\"lines\":[{\"dividePostFee\":0.0,\"latestDeliveryTime\":1773377590000,\"mark2\":[],\"num\":1,\"outerId\":\"\",\"payment\":16.9,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i2/2209098428402/O1CN01OJHS5g2BwAoeYt4MQ_!!4611686018427383794-0-item_pic.jpg\",\"platServiceFee\":0.0,\"price\":25.0,\"refOlId\":\"32888864676072908631\",\"refSkuId\":\"0\",\"refSpuId\":\"949075455874\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":17.65,\"singleFee\":17.65,\"spuOuterId\":\"\",\"standards\":\"\",\"status\":\"NOT_SHIPPED\",\"title\":\"奶茶冰箱贴背卡定制饮品徽章背景卡纸设计咖啡店钥匙扣卡头工艺品磁吸贴logo明信片制作城市文创包装卡片印刷\",\"totalFee\":17.65,\"totalPrice\":25.0,\"totalSellPrice\":17.65},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1773377590000,\"mark2\":[],\"num\":2,\"outerId\":\"HK_1\",\"payment\":40.55,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i4/2209098428402/O1CN01G0Hfdv2BwAefvSIIX_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":30.0,\"refOlId\":\"32888864676082908631\",\"refSkuId\":\"5456421894709\",\"refSpuId\":\"692264041089\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":21.175,\"singleFee\":21.18,\"spuOuterId\":\"HK_1\",\"standards\":\"售后卡内容尺寸定制请咨询客服\",\"status\":\"NOT_SHIPPED\",\"title\":\"售后服务卡片定制客户引流好礼评论卡印刷饰品服装包裹高级明信片外卖广告宣传小名片设计淘宝电商感谢卡订制\",\"totalFee\":42.35,\"totalPrice\":60.0,\"totalSellPrice\":42.35}],\"logisticsOrderNo\":\"\",\"mark2\":[],\"modifyTime\":1773204791000,\"openBuyerId\":\"AAFERHraABkUZRPgSx26I-MH\",\"openBuyerNick\":\"y**\",\"openSellerNick\":\"鼎怡旗舰店\",\"orderSource\":\"SYNC\",\"orderTime\":1773204786000,\"payTime\":1773204790000,\"payment\":57.45,\"platServiceFee\":0.0,\"posCode\":\"dingyi\",\"posId\":598810,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0},\"receivedPayment\":0.0,\"receiverCity\":\"湖州市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"吴兴区\",\"receiverId\":\"6d2ffbc239c2f933f426355b00f71991$\",\"receiverState\":\"浙江省\",\"receiverTown\":\"龙溪街道\",\"refOid\":\"32888864676062908631\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"配件-80x80mm-200张-卡片-yxmrebekah-甘露\",\"serviceFee\":0.0,\"status\":\"NOT_SHIPPED\",\"sysTags\":[],\"totalFee\":60.0,\"totalPrice\":85.0,\"totalSellPrice\":60.0,\"type\":\"SALE\"}}");
  75. //refundTmcHelper.Api_TmcRefundMsg("{\"content\":{\"afterStatus\":\"SUCCESS\",\"createTime\":1735287446000,\"desc\":\"\",\"interceptInvestor\":\"NONE\",\"interceptStatus\":\"NONE\",\"interceptType\":\"NONE\",\"lines\":[{\"num\":2,\"outerId\":\"\",\"price\":50.0,\"refAid\":\"313001208133750610\",\"refAlId\":\"313001208133750610\",\"refBoughtSkuId\":\"\",\"refOid\":\"4181722704291751006\",\"refOlId\":\"4181722704291751006\",\"refSkuId\":\"0\",\"refSpuId\":\"865893808768\",\"refundFee\":98.86,\"refundStatus\":\"SUCCESS\",\"title\":\"新年会抽奖券定制2025蛇年公司活动正副可撕代金券打印纪念票根奖品兑换尾牙晚宴邀请卡号码牌创意入场券设计\",\"totalFee\":98.86,\"type\":1}],\"logisticsCompany\":\"\",\"logisticsOrderNo\":\"\",\"mark2\":[],\"openBuyerNick\":\"0**\",\"openSellerNick\":\"万慕办公旗舰店\",\"posCode\":\"wanmu\",\"posId\":598798,\"reason\":\"订单信息拍错(规格/尺码/颜色等)\",\"receiverCity\":\"\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"\",\"receiverId\":\"\",\"receiverState\":\"\",\"receiverTown\":\"\",\"receiverZip\":\"\",\"refAid\":\"313001208133750610\",\"refOid\":\"4181722704291751006\",\"refPlatform\":\"TB\",\"refType\":\"TMALL\",\"refundCreateTime\":1735287358000,\"refundFee\":\"98.86\",\"refundPhase\":\"ON_SALE\",\"refundTime\":1735289443000,\"refundUpdateTime\":1735289443000,\"refundVersion\":1735287358100,\"senderAddress\":\"\",\"senderCity\":\"\",\"senderCountry\":\"中国\",\"senderDistrict\":\"\",\"senderMobile\":\"\",\"senderName\":\"\",\"senderPhone\":\"\",\"senderState\":\"\",\"senderTown\":\"\",\"senderZip\":\"\",\"status\":\"SUCCESS\",\"statusCode\":\"SUCCESS\",\"statusName\":\"退款成功\",\"totalFee\":\"98.86\",\"type\":\"REFUND\",\"updateTime\":1735289479000}}");
  76. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  77. //string res = apiHelper.API_GetWaybill("YTO-PDD-CYT", "250703-469248284251412");
  78. //preSalesHelper.dealMessageInfo("{\"bizOrder\":{\"id\":235819,\"parentId\":null,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderNo\":\"4624034580248409502\",\"shopId\":4,\"shopCode\":\"aolifu\",\"customerId\":345874,\"customerServiceId\":3184,\"thirdOrderId\":\"4624034580248409502\",\"orderPlatform\":\"TMALL\",\"openBuyerId\":\"AAEORHraABkUZRHgSx6ksuhU\",\"openBuyerNick\":\"tb278604202340\",\"openSellerNick\":\"奥丽芙旗舰店\",\"productUrl\":null,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"payAmount\":125.0,\"unrefundedAmount\":125.0,\"discountAmount\":5.0,\"csDiscountAmount\":-35.0,\"num\":13,\"province\":\"山西省\",\"city\":\"吕梁市\",\"area\":\"孝义市\",\"receiverTown\":\"孝义市\",\"address\":null,\"thirdReceiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"receiverName\":null,\"receiverMobile\":null,\"weChatId\":null,\"phone\":null,\"designContent\":\"\",\"designPics\":\"[]\",\"weChatQrPics\":\"[]\",\"addressFileUrl\":\"\",\"thirdFlag\":\"NONE\",\"remark\":null,\"sellerRemark\":\"\",\"buyerRemark\":\"\",\"timeoutRemark\":null,\"discountRemark\":null,\"status\":\"NOT_SHIPPED\",\"refundStatus\":0,\"internalStatus\":2,\"auditStatus\":null,\"auditUserId\":null,\"auditor\":null,\"customTag\":null,\"isRepurchase\":false,\"isOffline\":false,\"paymentFile\":null,\"orderTime\":\"2025-07-10 14:46:13\",\"modifyTime\":\"2025-07-10 14:46:37\",\"payTime\":\"2025-07-10 14:46:37\",\"confirmTime\":\"2025-07-10 14:51:23\",\"auditTime\":null,\"shippingTime\":null,\"finishTime\":null,\"erpCustomerServiceId\":3319,\"openBuyerID\":\"AAEORHraABkUZRHgSx6ksuhU\",\"orderFrom\":\"10\",\"receiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"bizOrderItems\":[{\"id\":310334,\"orderId\":235819,\"thirdOrderItemId\":\"4624034580248409502\",\"thirdSpuId\":\"740203900330\",\"thirdSkuId\":\"0\",\"title\":\"pvc贴纸定制防水不干胶圆形贴标自粘商标logo广告二维码标签印刷\",\"specification\":\"\",\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2433960672/O1CN01D0ZzzR1GppCHSoBjD_!!4611686018427382496-0-item_pic.jpg\",\"price\":10.0,\"sellPrice\":9.62,\"amount\":9.62,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"totalAmount\":125.0,\"num\":13,\"refundStatus\":\"NO_REFUND\"}],\"bizOrderSplits\":[{\"id\":151557,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328848\",\"splitNo\":\"C1_4624034580248409502\",\"splitInfoNo\":\"C2+1\",\"splitAmount\":52.64,\"quoteRecordId\":520208,\"quoteAmount\":40.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328848)-[C2+1]-80x20mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328848\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":40.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":80.00,\"width\":20.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"80x20mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":40.00,\"numberType\":\"\",\"isDianziOrder\":0},{\"id\":151558,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328853\",\"splitNo\":\"C2_4624034580248409502\",\"splitInfoNo\":\"C2+2\",\"splitAmount\":72.36,\"quoteRecordId\":520209,\"quoteAmount\":55.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328853)-[C2+2]-90x50mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328853\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":55.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":90.00,\"width\":50.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"90x50mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":55.00,\"numberType\":\"\",\"isDianziOrder\":0}]}}");
  79. /*string path = "C:\\Users\\231010\\Downloads\\tids.txt";
  80. string path1 = "C:\\Users\\231010\\Downloads\\tid.txt";
  81. string tids = File.ReadAllText(path);
  82. List<string> list = tids.Split(',').ToList();
  83. int index = 0;
  84. foreach (string item in list)
  85. {
  86. CeErpTrade ceErpTrade = CeErpTrade.Get(item.Replace("'", ""));
  87. try
  88. {
  89. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_nick = '{0}' or buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  90. if (string.IsNullOrEmpty(ceErpTrade.buyer_nick))
  91. {
  92. sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  93. }
  94. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  95. List<string> tidList = new List<string>();
  96. if (dataTable != null && dataTable.Rows.Count > 0)
  97. {
  98. foreach (DataRow row in dataTable.Rows)
  99. {
  100. tidList.Add("'" + row["tid"].ToString() + "'");
  101. }
  102. }
  103. if (tidList.Count > 0)
  104. {
  105. sql = string.Format("SELECT count(*) as number FROM [dbo].[CE_ErpTradeCell] WITH(NOLOCK) WHERE tid in ({0}) AND IsSample = 0 ", string.Join(",", tidList));
  106. dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  107. if (dataTable != null && dataTable.Rows.Count > 0)
  108. {
  109. int count = Convert.ToInt32(dataTable.Rows[0]["number"]);
  110. if (count > 0)
  111. {
  112. Debug.WriteLine(index++);
  113. continue;
  114. }
  115. }
  116. }
  117. File.AppendAllText(path1, ceErpTrade.tid + "\n");
  118. }
  119. catch (Exception e)
  120. {
  121. File.AppendAllText(path1, "e:" + ceErpTrade.tid + "\n");
  122. }
  123. Debug.WriteLine(index++);
  124. }*/
  125. //string a = commonHelper.convertQNMemo("48x61mm-4款各40个-铜版纸-不干胶-覆膜模切-tb963561715-金陵-顺丰到付.粘成品.6.5cm牙签-老客户改稿找金陵拉群-16发", CeErpTradeCell.GetByCtid("2879265072537265386"));
  126. List<string> lw = new List<string>();
  127. string tid = GetPostString("ctid");
  128. string date1 = GetPostString("date1");
  129. //12-1 修改
  130. string urgent = GetPostString("urgent");
  131. string back = GetPostString("back");
  132. string offlineSearch = GetPostString("offlineSearch");
  133. int paramsCount = 0;
  134. if (!string.IsNullOrWhiteSpace(urgent))
  135. {
  136. if (urgent.Equals("true"))
  137. {
  138. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  139. }
  140. }
  141. if (!string.IsNullOrWhiteSpace(back))
  142. {
  143. if (back.Equals("true"))
  144. {
  145. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  146. }
  147. }
  148. if (!string.IsNullOrWhiteSpace(offlineSearch))
  149. {
  150. if (offlineSearch.Equals("true"))
  151. {
  152. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  153. }
  154. }
  155. //end
  156. string date2 = GetPostString("date2");
  157. string buyernick = GetPostString("buyer_nick");
  158. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  159. {
  160. if (tid.Length <= 0 && buyernick.Length <= 0)
  161. {
  162. return;
  163. }
  164. }
  165. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  166. {
  167. if (tid.Length > 0)
  168. {
  169. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  170. if (ceErpTradeCell != null)
  171. {
  172. tid = ceErpTradeCell.tid;
  173. }
  174. List<string> select_tid = getTidByCtidMore(tid);
  175. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  176. }
  177. if (buyernick.Length > 0)
  178. {
  179. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  180. }
  181. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  182. if (dw.Length > 0)
  183. {
  184. lw.Add(dw);
  185. }
  186. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  187. {
  188. string usershop = "0," + CurrentUser.User.pemShop;
  189. lw.Add(string.Format("ShopId in ({0})", usershop));
  190. }
  191. }
  192. else
  193. {
  194. if (ex_psize == 0)
  195. {
  196. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  197. }
  198. if (PKey != "admin" && poscode != "SysAdmin")
  199. {
  200. string usershop = "0," + CurrentUser.User.pemShop;
  201. lw.Add(string.Format("ShopId in ({0})", usershop));
  202. paramsCount++;
  203. }
  204. }
  205. string uploaddate1 = GetPostString("uploaddate1");
  206. string uploaddate2 = GetPostString("uploaddate2");
  207. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  208. if (update.Length > 0) lw.Add(update);
  209. string deliverydate1 = GetPostString("deliverydate1");
  210. string deliverydate2 = GetPostString("deliverydate2");
  211. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  212. if (deliverydate.Length > 0)
  213. {
  214. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  215. };
  216. string shopname = GetPostString("shopname");
  217. if (shopname.Length > 0)
  218. {
  219. CeErpShop ceErpShop = CeErpShop.GetShopIdByName(shopname);
  220. if (ceErpShop != null)
  221. {
  222. lw.Add(string.Format("shopId = {0}", ceErpShop.ID));
  223. }
  224. }
  225. string addwechat = GetPostString("addwechat");
  226. if (addwechat.Length > 0)
  227. {
  228. int addWt = Convert.ToInt32(addwechat);
  229. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  230. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  231. }
  232. string customer = GetPostString("customer");
  233. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  234. string design = GetPostString("design");
  235. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  236. string orderState = GetPostString("orderState");
  237. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  238. string address = GetPostString("address");
  239. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  240. string sellermemo = GetPostString("seller_memo");
  241. if (sellermemo.Length > 0)
  242. {
  243. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  244. }
  245. string otherMemo = GetPostString("otherMemo");
  246. if (otherMemo.Length > 0)
  247. {
  248. lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  249. }
  250. string backReason = GetPostString("backReason");
  251. if (backReason.Length > 0)
  252. {
  253. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  254. }
  255. string apdate1 = GetPostString("apdate1");
  256. string apdate2 = GetPostString("apdate2");
  257. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  258. if (dwap.Length > 0) lw.Add(dwap);
  259. string price1 = GetPostString("price1");
  260. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  261. string price2 = GetPostString("price2");
  262. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  263. string isoldcustomer = GetPostString("isoldcus");
  264. string buyer_id = GetPostString("buyer_id");
  265. if (buyer_id.Length > 0) lw.Add(string.Format("buyer_id = '{0}'", buyer_id));
  266. string spudata = GetPostString("spudata");
  267. if ("0".Equals(spudata))
  268. {
  269. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  270. }
  271. if ("1".Equals(spudata))
  272. {
  273. lw.Add(string.Format("spu_id <> ''"));
  274. }
  275. string finishdate1 = GetPostString("finishdate1");
  276. string finishdate2 = GetPostString("finishdate2");
  277. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  278. bool isFinish = false;
  279. if (finishdate.Length > 0)
  280. {
  281. lw.Add(finishdate);
  282. isFinish = true;
  283. paramsCount++;
  284. }
  285. if (isoldcustomer.Length > 0)
  286. {
  287. if ("2".Equals(isoldcustomer))
  288. {
  289. lw.Add(string.Format("VipCustomer=1"));
  290. }
  291. else
  292. {
  293. lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  294. }
  295. }
  296. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  297. if (ex_psize > 0)
  298. {
  299. int UserID = CurrentUser.UserID;
  300. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  301. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  302. {
  303. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  304. }
  305. dStruct.Order = "pay_time desc";
  306. }
  307. string isNew = GetPostString("isNew");
  308. if (isNew == "true")
  309. {
  310. lw.Add(string.Format("IsNew = {0}", 1));
  311. }
  312. string overtime = GetPostString("overtime");
  313. if (overtime == "1")
  314. {
  315. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  316. }
  317. String usePost = CurrentUser.UserPost.Post.Code;
  318. if (usePost.Equals("Operation") == true)
  319. {
  320. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  321. }
  322. else
  323. {
  324. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  325. }
  326. //dStruct.Fileds = "tid,ctid,SplitTag,pay_time,seller_nick,buyer_nick,payment,seller_memo,OrderState,status,CustomerTb,DesignUserName,DesignPrice,end_time,WaitDesignTime,FinishDesignTime,FinishDeliveryTime,buyer_message,SupplierName,OutSid,receiver_name,receiver_mobile,receiver_state,receiver_city,receiver_address,isRefund,IsUrgency";
  327. if (dStruct.PageSize == 100000)
  328. {
  329. dStruct.Order = "";
  330. }
  331. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  332. DataTable dt = null;
  333. string tablename = "view_orderlist";
  334. if (isFinish)
  335. {
  336. tablename = "view_orderlist_end";
  337. }
  338. dt = WebCache.GetData(tablename, dStruct);
  339. if (dt != null && dt.Rows.Count > 0)
  340. {
  341. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  342. foreach (DataRow dr in dt.Rows)
  343. {
  344. try
  345. {
  346. if (dr["refund_fees"] != null)
  347. {
  348. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  349. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  350. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  351. if (payment == refund_fees)
  352. {
  353. dr["refund_fees"] = Math.Round(refund_fees, 2);
  354. }
  355. else if (refund_fees == total_fee)
  356. {
  357. dr["refund_fees"] = payment;
  358. }
  359. else
  360. {
  361. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  362. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  363. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  364. }
  365. }
  366. // 对象操作
  367. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  368. ceErpTradeCell.ctid = dr["ctid"].ToString();
  369. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  370. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  371. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  372. if (dStruct.PageSize != 100000)
  373. {
  374. if (dr["DispatchSort"].ToString() == "2")
  375. {
  376. dr["gongchuang"] = 200;
  377. }
  378. else if ("外协".Equals(dr["ToType"].ToString()))
  379. {
  380. dr["gongchuang"] = 200;
  381. }
  382. else if ("内部".Equals(dr["ToType"].ToString()))
  383. {
  384. dr["gongchuang"] = -1;
  385. }
  386. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  387. {
  388. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  389. dr["gongchuang"] = response.code;
  390. }
  391. }
  392. }
  393. catch (NullReferenceException ex)
  394. {
  395. // 处理空引用异常
  396. dr["refund_fees"] = "0.00";
  397. }
  398. }
  399. }
  400. writeGridDataTableJson(dStruct.TotalCount, dt);
  401. }
  402. public void get_erp_orderlist_sumprice()
  403. {
  404. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  405. return;
  406. List<string> lw = new List<string>();
  407. string tid = GetPostString("ctid");
  408. string date1 = GetPostString("date1");
  409. string date2 = GetPostString("date2");
  410. if (tid.Length > 0 || date1.Length > 0)
  411. {
  412. lw.Add(string.Format("ctid like '%{0}%'", tid));
  413. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  414. if (dw.Length > 0) lw.Add(dw);
  415. }
  416. else
  417. {
  418. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  419. }
  420. string shopname = GetPostString("shopname");
  421. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  422. string buyernick = GetPostString("buyer_nick");
  423. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  424. string customer = GetPostString("customer");
  425. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  426. string design = GetPostString("design");
  427. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  428. string orderState = GetPostString("orderState");
  429. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  430. string address = GetPostString("address");
  431. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  432. string sellermemo = GetPostString("seller_memo");
  433. if (sellermemo.Length > 0)
  434. {
  435. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  436. }
  437. string apdate1 = GetPostString("apdate1");
  438. string apdate2 = GetPostString("apdate2");
  439. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  440. if (dwap.Length > 0) lw.Add(dwap);
  441. string price1 = GetPostString("price1");
  442. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  443. string price2 = GetPostString("price2");
  444. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  445. string isoldcustomer = GetPostString("isoldcus");
  446. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  447. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  448. if (PKey != "admin")
  449. {
  450. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  451. lw.Add(string.Format("shopId in ({0})", usershop));
  452. }
  453. //dStruct.Fileds = "tid,ctid,SplitTag,pay_time,seller_nick,buyer_nick,payment,seller_memo,OrderState,status,CustomerTb,DesignUserName,DesignPrice,end_time,WaitDesignTime,FinishDesignTime,FinishDeliveryTime,buyer_message,SupplierName,OutSid,receiver_name,receiver_mobile,receiver_state,receiver_city,receiver_address,isRefund,IsUrgency";
  454. string mainWhere = string.Join(" and ", lw.ToArray());
  455. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  456. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  457. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  458. decimal total = 0;
  459. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  460. {
  461. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  462. }
  463. var res = new
  464. {
  465. data = total
  466. };
  467. string ro_jsond = JsonConvert.SerializeObject(res);
  468. returnSuccess(ro_jsond);
  469. return;
  470. }
  471. public void get_erp_CustomerServiceGather()
  472. {
  473. string userWhere = "", orderWhere = "";
  474. List<string> lw = new List<string>();
  475. string customer = GetPostString("customer");
  476. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  477. string shopname = GetPostString("shopname");
  478. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  479. string date1 = GetPostString("date1");
  480. string date2 = GetPostString("date2");
  481. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  482. if (dw.Length > 0) lw.Add(dw);
  483. orderWhere = string.Join(" and ", lw.ToArray());
  484. string sql = string.Format("select a.Name CusName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitRelease,0) WaitRelease, isnull(e.WaitRob,0) WaitRob, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  485. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  486. "left join " +
  487. "( " +
  488. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  489. ") as b on a.ID = b.CustomerUserId " +
  490. "left join " +
  491. "( " +
  492. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  493. ") as d on a.ID = d.CustomerUserId " +
  494. "left join " +
  495. "( " +
  496. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  497. ") as e on a.ID = e.CustomerUserId " +
  498. "left join " +
  499. "( " +
  500. " select CustomerUserId, RefundCount, RefundSum from " +
  501. " ( " +
  502. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  503. " from CE_ErpTradeRefund a " +
  504. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  505. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  506. " group by CustomerUserId " +
  507. " ) as a " +
  508. ") as f on a.ID = f.CustomerUserId " +
  509. "where a.PostCode = 'CustomerService'",
  510. userWhere, orderWhere);
  511. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  512. writeGridDataTableJson(dt.Rows.Count, dt);
  513. //writeGridDataTableJson(dt.Rows.Count, dt);
  514. }
  515. //设计汇总
  516. public void get_erp_DesignerGather()
  517. {
  518. string userWhere = "", orderWhere = "";
  519. List<string> lw = new List<string>();
  520. string Designer = GetPostString("designer");
  521. int org = GetPostInt("org");
  522. if (Designer.Length > 0)
  523. {
  524. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  525. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  526. }
  527. else if (org > 0)
  528. {
  529. userWhere = string.Format(" where OrgID ={0}", org);
  530. }
  531. string shopname = GetPostString("shopname");
  532. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  533. string state = GetPostString("state");
  534. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  535. string OrderArea = GetPostString("order_area");
  536. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  537. string date1 = GetPostString("date1");
  538. string date2 = GetPostString("date2");
  539. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  540. if (dw.Length > 0) lw.Add(dw);
  541. string UpDate1 = GetPostString("UpDate1");
  542. string UpDate2 = GetPostString("UpDate2");
  543. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  544. if (dw.Length > 0) lw.Add(dw);
  545. orderWhere = string.Join(" and ", lw.ToArray());
  546. string sql = string.Format("select *,cast(cast(z.DesignFinish as float) / (case z.AllOrder when 0 then 1 else z.AllOrder end) * 100 as numeric(18,2)) as FinalizationRate from (" +
  547. "select a.Name DesignerName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitDesign,0) WaitDesign, isnull(e.Designing,0) Designing, isnull(g.DesignFinish,0) DesignFinish, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  548. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  549. "left join " +
  550. "( " +
  551. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  552. ") as b on a.ID = b.DesignUserId " +
  553. "left join " +
  554. "( " +
  555. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  556. ") as d on a.ID = d.DesignUserId " +
  557. "left join " +
  558. "( " +
  559. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  560. ") as e on a.ID = e.DesignUserId " +
  561. "left join " +
  562. "( " +
  563. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  564. ") as g on a.ID = g.DesignUserId " +
  565. "left join " +
  566. "( " +
  567. " select CustomerUserId, RefundCount, RefundSum from " +
  568. " ( " +
  569. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  570. " from CE_ErpTradeRefund a " +
  571. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  572. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  573. " group by CustomerUserId " +
  574. " ) as a " +
  575. ") as f on a.ID = f.CustomerUserId " +
  576. "where a.PostCode = 'Designer') as z",
  577. userWhere, orderWhere);
  578. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  579. writeGridDataTableJson(dt.Rows.Count, dt);
  580. }
  581. //删除tradecell的订单
  582. public void del_erp_cellorder()
  583. {
  584. if (UrlPostParmsCheck("ctid"))
  585. {
  586. string eid = GetPostString("ctid");
  587. CeErpTradeCell.DelByCtid(eid);
  588. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  589. returnSuccessMsg("删除成功");
  590. }
  591. }
  592. public void clear_erp_refundstate()
  593. {
  594. if (UrlPostParmsCheck("ids"))
  595. {
  596. string eids = GetPostString("ids");
  597. string[] ctidList = eids.Split(',');
  598. foreach (string ctid in ctidList)
  599. {
  600. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  601. if (entity != null)
  602. {
  603. entity.IsRefund = 0;
  604. entity.Update();
  605. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  606. }
  607. else
  608. continue;
  609. }
  610. returnSuccessMsg("操作成功");
  611. return;
  612. }
  613. returnErrorMsg("缺少必要参数");
  614. }
  615. public void set_erp_urgency()
  616. {
  617. if (UrlPostParmsCheck("ctid"))
  618. {
  619. string eid = GetPostString("ctid");
  620. CeErpTradeCell entity = null;
  621. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  622. if (entity != null)
  623. {
  624. double prices = commonHelper.calculationPrice(entity);
  625. if (prices <= 100)
  626. {
  627. returnErrorMsg("此订单金额不足100元,无法加急。");
  628. return;
  629. }
  630. string utime = GetPostString("urgencytime");
  631. if (utime.Length > 0)
  632. {
  633. entity.UrgencyTime = Convert.ToDateTime(utime);
  634. }
  635. else
  636. {
  637. returnErrorMsg("请选择加急时间");
  638. return;
  639. }
  640. if (entity.OrderState <= 4)
  641. {
  642. //entity.seller_memo = entity.seller_memo + "-加急";
  643. string smemo = entity.seller_memo;
  644. int kindex = smemo.IndexOf(")");
  645. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  646. if (lastoneStr != "-")
  647. {
  648. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  649. }
  650. string prememo = smemo.Substring(0, kindex + 2);
  651. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  652. int lastkindex = lastmemo.IndexOf("(");
  653. DateTime urgtime = Convert.ToDateTime(utime);
  654. string newlastmemo = "";
  655. if (lastkindex == 0)
  656. {
  657. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  658. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  659. }
  660. else
  661. {
  662. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  663. }
  664. entity.seller_memo = prememo + newlastmemo;
  665. }
  666. entity.IsUrgency = true;
  667. entity.UpdateTime = DateTime.Now;
  668. entity.Update();
  669. ApiVo apiVo = new ApiVo();
  670. apiVo.orderNumber = entity.ctid;
  671. apiVo.actionName = "changeDesign";
  672. apiVo.orderRemarks = entity.seller_memo;
  673. apiVo.remarkSign = 3;
  674. designHelper.API_WorkCore(apiVo); //changeDesign
  675. CeErpSukuraData.createInfo(entity.ctid, 7);
  676. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  677. returnSuccessMsg("设置成功!");
  678. return;
  679. }
  680. returnErrorMsg("找不到记录");
  681. }
  682. }
  683. public void set_erp_reset()
  684. {
  685. if (UrlPostParmsCheck("ctid"))
  686. {
  687. string eid = GetPostString("ctid");
  688. CeErpTradeCell entity = null;
  689. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  690. if (entity != null)
  691. {
  692. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  693. {
  694. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  695. {
  696. returnErrorMsg("财务要求已下单已发货无法重置");
  697. return;
  698. }
  699. }
  700. entity.IsUrgency = false;
  701. entity.seller_memo = "";
  702. entity.OtherMemo = "";
  703. entity.OrderState = 0;
  704. entity.IsReturn = 0;
  705. //entity.IsRefund = 0;
  706. entity.MemoOpt = 0;
  707. entity.AfterSaleState = 0;
  708. entity.AfterSaleResponsible = "";
  709. entity.AfterSaleUserId = 0;
  710. entity.IsNeedBill = 0;
  711. entity.CustomerUserId = 0;
  712. entity.DesignUserId = 0;
  713. entity.SupplierId = 0;
  714. entity.PlaceUserId = 0;
  715. entity.ptid = "";
  716. entity.IsSample = 0;
  717. entity.IsXianHuo = 0;
  718. entity.isDianziOrder = 0;
  719. entity.DispatchSort = 0;
  720. entity.IsVerifyToSupplier = false;
  721. entity.FinishPlaceTime = null;
  722. entity.Update();
  723. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  724. if (trade != null)
  725. {
  726. trade.seller_memo = "";
  727. trade.Update();
  728. }
  729. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  730. returnSuccessMsg("重置成功!");
  731. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  732. if (desginBill != null)
  733. {
  734. desginBill.isDel = 1;
  735. desginBill.Update();
  736. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  737. }
  738. ApiVo apiVo = new ApiVo();
  739. apiVo.orderNumber = entity.ctid;
  740. apiVo.actionName = "resetDesign";
  741. designHelper.API_WorkCore(apiVo);//resetDesign
  742. return;
  743. }
  744. returnErrorMsg("找不到记录");
  745. }
  746. }
  747. public void save_erp_sellermemo()
  748. {
  749. if (UrlPostParmsCheck("ctid"))
  750. {
  751. string ctid = GetPostString("ctid");
  752. CeErpTradeCell entity = null;
  753. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  754. if (entity != null)
  755. {
  756. string memo = GetPostString("seller_memo");
  757. string qn_memo = GetPostString("qn_memo");
  758. memo = memo.Replace(" ", "");
  759. if (memo.Contains("补差"))
  760. {
  761. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  762. return;
  763. }
  764. List<string> bitList = new List<string>
  765. {
  766. "\\","/",":","*","?", "\"","<" ,">","|"
  767. };
  768. bool isIn = false;
  769. foreach (string bit in bitList)
  770. {
  771. if (memo.Contains(bit))
  772. {
  773. isIn = true;
  774. }
  775. }
  776. if (isIn)
  777. {
  778. returnErrorMsg("不能使用 一些符合作为文件名");
  779. return;
  780. }
  781. if (entity.seller_memo != memo)
  782. {
  783. if (entity.IsSample == 2)
  784. {
  785. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  786. return;
  787. }
  788. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  789. {
  790. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  791. {
  792. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  793. return;
  794. }
  795. /*if (CurrentUser.UserPost.Post.Code != "Place")
  796. {
  797. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  798. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  799. {
  800. returnErrorMsg("售前系统订单无法再此修改!");
  801. return;
  802. }
  803. }*/
  804. }
  805. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  806. }
  807. if (!string.IsNullOrEmpty(qn_memo) && !(entity.IsSample > 0 || entity.ctid.Contains("N_") || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物")))
  808. {
  809. if (entity.OrderState >= 5)
  810. {
  811. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  812. return;
  813. }
  814. string delMemo = commonHelper.convertQNMemo(qn_memo, ref entity);
  815. if (string.IsNullOrEmpty(delMemo))
  816. {
  817. returnErrorMsg("备注不规范,无法识别");
  818. return;
  819. }
  820. memo = delMemo;
  821. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统千牛修改为:" + memo, entity.OrderState, 1);
  822. }
  823. //commonHelper.getCytPrice(entity);
  824. int memoopt = GetPostInt("MemoOpt");
  825. Boolean ismemoopt = false;
  826. if (memoopt > 0)
  827. {
  828. string stropt = "";
  829. if (memoopt == 1)
  830. {
  831. stropt = "“改稿”";
  832. ismemoopt = true;
  833. }
  834. else if (memoopt == 2)
  835. {
  836. stropt = "“定稿”";
  837. }
  838. else if (memoopt == 3)
  839. {
  840. stropt = "“查货”";
  841. CeErpSukuraData.createInfo(entity.ctid, 6);
  842. }
  843. entity.MemoOpt = Convert.ToInt32(memoopt);
  844. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  845. }
  846. if (entity.OrderState < 5)
  847. {
  848. memo = memo.Replace("(", "(");
  849. memo = memo.Replace(")", ")");
  850. }
  851. /* if (entity.OrderState < 3)
  852. {
  853. entity.DispatchSort = 0;
  854. }*/
  855. entity.seller_memo = memo;
  856. entity.UpdateTime = DateTime.Now;
  857. entity.Update();
  858. ApiVo apiVo = new ApiVo();
  859. apiVo.orderNumber = entity.ctid;
  860. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  861. apiVo.orderRemarks = memo;
  862. apiVo.remarkSign = memoopt;
  863. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  864. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  865. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  866. {
  867. //dataHelper.api_orderBack(entity.ctid, "0", "");
  868. }
  869. if (entity.seller_memo.Contains("改稿"))
  870. {
  871. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  872. }
  873. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  874. returnSuccessMsg("保存成功!");
  875. return;
  876. }
  877. returnErrorMsg("找不到记录");
  878. }
  879. }
  880. public void ins_erp_checkorder()
  881. {
  882. if (UrlPostParmsCheck("ctid"))
  883. {
  884. string ctid = GetPostString("ctid");
  885. CeErpTradeCell entity = null;
  886. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  887. if (entity != null)
  888. {
  889. if (entity.OrderState < 6)
  890. {
  891. returnErrorMsg("下单完成后才可查货");
  892. return;
  893. }
  894. /*if (entity.OrderState > 6)
  895. {
  896. returnErrorMsg("订单已发货");
  897. return;
  898. }*/
  899. if (entity.FinishPlaceTime != null)
  900. {
  901. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  902. {
  903. returnErrorMsg("下单时间不足,无法查货");
  904. return;
  905. }
  906. }
  907. entity.MemoOpt = 3;
  908. entity.CheckOrderTime = DateTime.Now;
  909. entity.UpdateTime = DateTime.Now;
  910. entity.Update();
  911. CeErpSukuraData.createInfo(entity.ctid, 6);
  912. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  913. returnSuccessMsg("操作成功!");
  914. return;
  915. }
  916. returnErrorMsg("找不到记录");
  917. }
  918. }
  919. public void save_erp_othermemo()
  920. {
  921. if (UrlPostParmsCheck("ctid"))
  922. {
  923. string ctid = GetPostString("ctid");
  924. CeErpTradeCell entity = null;
  925. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  926. if (entity != null)
  927. {
  928. entity.OtherMemo = GetPostString("otherMemo");
  929. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  930. {
  931. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  932. StringBuilder sql = new StringBuilder();
  933. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  934. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  935. if (dt != null && dt.Rows.Count > 0)
  936. {
  937. foreach (DataRow dr in dt.Rows)
  938. {
  939. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  940. {
  941. //品类一直
  942. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  943. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  944. if (ceErpSampleCustomer == null)
  945. {
  946. ceErpSampleCustomer = new CeErpSampleCustomer();
  947. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  948. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  949. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  950. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  951. ceErpSampleCustomer.shopId = entity.ShopId;
  952. }
  953. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  954. ceErpSampleCustomer.lastTid = entity.tid;
  955. if (ceErpSampleCustomer.ID > 0)
  956. {
  957. ceErpSampleCustomer.Update();
  958. }
  959. else
  960. {
  961. ceErpSampleCustomer.Create();
  962. }
  963. }
  964. }
  965. }
  966. }
  967. //if (entity.IsOldCustomer == 1)
  968. //{
  969. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  970. //{
  971. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  972. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  973. //}
  974. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  975. //{
  976. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  977. // {
  978. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  979. // {
  980. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  981. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  982. // }
  983. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  984. // {
  985. // entity.OrderState = 2;
  986. // entity.DesignUserId = 0;
  987. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  988. // }
  989. // else
  990. // {
  991. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  992. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  993. // }
  994. // }
  995. //}
  996. //}
  997. entity.UpdateTime = DateTime.Now;
  998. entity.Update();
  999. returnSuccessMsg("保存成功!");
  1000. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  1001. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  1002. if (entity.OtherMemo.Contains("改稿"))
  1003. {
  1004. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  1005. }
  1006. return;
  1007. }
  1008. returnErrorMsg("找不到记录");
  1009. }
  1010. }
  1011. public void save_erp_customermemo()
  1012. {
  1013. if (UrlPostParmsCheck("ctid"))
  1014. {
  1015. string ctid = GetPostString("ctid");
  1016. CeErpTradeCell entity = null;
  1017. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1018. if (entity != null)
  1019. {
  1020. entity.UpdateTime = DateTime.Now;
  1021. entity.CustomerMemo = GetPostString("CustomerMemo");
  1022. entity.Update();
  1023. ApiVo apiVo = new ApiVo();
  1024. apiVo.orderNumber = entity.ctid;
  1025. apiVo.actionName = "followRemarks";
  1026. apiVo.orderRemarks = entity.CustomerMemo;
  1027. designHelper.API_WorkCore(apiVo);//followRemarks
  1028. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  1029. returnSuccessMsg("保存成功!");
  1030. return;
  1031. }
  1032. returnErrorMsg("找不到记录");
  1033. }
  1034. }
  1035. public void upd_erp_addmemotag()
  1036. {
  1037. if (UrlPostParmsCheck("ctid"))
  1038. {
  1039. ;
  1040. string eid = GetPostString("ctid");
  1041. string sfTagstr = GetPostString("memotag");
  1042. CeErpTradeCell entity = null;
  1043. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1044. if (entity != null)
  1045. {
  1046. ApiVo apiVo = new ApiVo();
  1047. if (entity.OrderState == 0)
  1048. {
  1049. returnErrorMsg("请先领单");
  1050. return;
  1051. }
  1052. //撤销顺丰
  1053. if (sfTagstr == "撤销顺丰")
  1054. {
  1055. entity.IsSF = 0;
  1056. string reMsg = "";
  1057. string oldmemo = entity.seller_memo;
  1058. if (entity.OrderState < 5)
  1059. {
  1060. oldmemo = oldmemo.Replace("顺丰到付", "");
  1061. oldmemo = oldmemo.Replace("顺丰寄付", "");
  1062. entity.seller_memo = oldmemo;
  1063. }
  1064. else
  1065. {
  1066. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  1067. {
  1068. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  1069. }
  1070. }
  1071. entity.Update();
  1072. apiVo.orderNumber = entity.ctid;
  1073. apiVo.actionName = "orderRemarks";
  1074. apiVo.orderRemarks = entity.seller_memo;
  1075. apiVo.isSf = entity.IsSF.ToString();
  1076. designHelper.API_WorkCore(apiVo);//orderRemarks
  1077. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  1078. returnSuccessMsg("撤销成功!" + reMsg);
  1079. return;
  1080. }
  1081. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  1082. {
  1083. //string oldmemo = entity.seller_memo;
  1084. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  1085. string sfStr = GetPostString("memotag");
  1086. string smemo = entity.seller_memo;
  1087. int kindex = smemo.IndexOf(")");
  1088. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  1089. if (lastoneStr != "-")
  1090. {
  1091. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  1092. }
  1093. string prememo = smemo.Substring(0, kindex + 2);
  1094. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  1095. int lastkindex = lastmemo.IndexOf("(");
  1096. string newlastmemo = "";
  1097. if (lastkindex == 0)
  1098. {
  1099. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1100. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1101. }
  1102. else
  1103. {
  1104. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1105. }
  1106. entity.seller_memo = prememo + newlastmemo;
  1107. }
  1108. string sfTagMSg = "";
  1109. if (sfTagstr == "顺丰寄付")
  1110. {
  1111. entity.IsSF = 1;
  1112. sfTagMSg = "顺丰寄付";
  1113. }
  1114. else if (sfTagstr == "顺丰到付")
  1115. {
  1116. entity.IsSF = 2;
  1117. sfTagMSg = "顺丰到付";
  1118. }
  1119. if (entity.SupplierId == 19 && entity.OrderState == 6)
  1120. {
  1121. string deliveryWayName = "";
  1122. if (sfTagstr == "撤销顺丰")
  1123. {
  1124. sfTagstr = "普通快递";
  1125. }
  1126. if (sfTagstr == "顺丰寄付")
  1127. {
  1128. sfTagstr = "顺丰特快寄付";
  1129. }
  1130. if (sfTagstr == "顺丰到付")
  1131. {
  1132. sfTagstr = "顺丰特快到付";
  1133. }
  1134. string result = apichyHelper.updateExpressMark(entity.tid, sfTagstr);
  1135. if ("修改失败".Equals(result))
  1136. {
  1137. returnErrorMsg("修改失败");
  1138. return;
  1139. }
  1140. }
  1141. entity.Update();
  1142. apiVo = new ApiVo();
  1143. apiVo.orderNumber = entity.ctid;
  1144. apiVo.actionName = "orderRemarks";
  1145. apiVo.orderRemarks = entity.seller_memo;
  1146. apiVo.isSf = entity.IsSF.ToString();
  1147. designHelper.API_WorkCore(apiVo);//orderRemarks
  1148. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1149. returnSuccessMsg("标记成功!");
  1150. return;
  1151. }
  1152. returnErrorMsg("找不到记录");
  1153. }
  1154. }
  1155. public void upd_erp_ordertag()
  1156. {
  1157. if (UrlPostParmsCheck("ctid"))
  1158. {
  1159. string eid = GetPostString("ctid");
  1160. CeErpTradeCell entity = null;
  1161. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1162. if (entity != null)
  1163. {
  1164. int tag = GetPostInt("wechattag");
  1165. //if(tag==4 && entity.IsSample == 2)
  1166. //{
  1167. // returnErrorMsg("补差价单不能标记微信单");
  1168. // return;
  1169. //}
  1170. entity.wechatTag = tag;
  1171. entity.Update();
  1172. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1173. if (tag == 1)
  1174. {
  1175. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1176. if (cash == null)
  1177. {
  1178. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1179. cash = new CeErpReturnCash();
  1180. cash.tid = entity.tid;
  1181. cash.seller_nick = main.seller_nick;
  1182. cash.payment = trade.payment;
  1183. cash.buyer_nick = main.buyer_nick;
  1184. cash.cashstate = 0;
  1185. cash.rtype = "微信返现";
  1186. cash.returnprice = 0;
  1187. cash.created = DateTime.Now;
  1188. cash.con = "订单标记微信单";
  1189. cash.img = "";
  1190. cash.applyuserid = CurrentUser.UserID;
  1191. cash.Create();
  1192. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1193. }
  1194. else
  1195. {
  1196. cash.cashstate = 0;
  1197. cash.Update();
  1198. }
  1199. CeErpSukuraData.createInfo(entity.ctid, 9);
  1200. }
  1201. else if (tag == 2)
  1202. {
  1203. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1204. if (cash == null)
  1205. {
  1206. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1207. cash = new CeErpReturnCash();
  1208. cash.tid = entity.tid;
  1209. cash.seller_nick = main.seller_nick;
  1210. cash.payment = trade.payment;
  1211. cash.buyer_nick = main.buyer_nick;
  1212. cash.cashstate = 0;
  1213. cash.rtype = "推购返现";
  1214. cash.returnprice = 5;
  1215. cash.created = DateTime.Now;
  1216. cash.con = "订单标记推购单";
  1217. cash.img = "";
  1218. cash.applyuserid = CurrentUser.UserID;
  1219. cash.Create();
  1220. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1221. }
  1222. else
  1223. {
  1224. cash.cashstate = 0;
  1225. cash.Update();
  1226. }
  1227. CeErpSukuraData.createInfo(entity.ctid, 9);
  1228. }
  1229. else if (tag == 3)
  1230. {
  1231. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1232. if (pers == null)
  1233. {
  1234. pers = new CeErpPersuade();
  1235. pers.ctid = entity.ctid;
  1236. pers.pstate = 0;
  1237. pers.created = DateTime.Now;
  1238. pers.applyuserid = CurrentUser.UserID;
  1239. pers.Create();
  1240. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1241. }
  1242. else
  1243. {
  1244. pers.pstate = 0;
  1245. pers.Update();
  1246. }
  1247. }
  1248. else if (tag == 4 || tag == 5)
  1249. {
  1250. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1251. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1252. if (pers == null)
  1253. {
  1254. pers = CeErpStayGoods.GetByTid(entity.tid);
  1255. }
  1256. if (pers == null)
  1257. {
  1258. pers = new CeErpStayGoods();
  1259. pers.t_id = entity.tid;
  1260. pers.ctid = entity.ctid;
  1261. pers.status = "待审核";
  1262. pers.audit_type = 0;
  1263. if (tag == 4)
  1264. {
  1265. pers.stay_type = "微信推购";
  1266. }
  1267. else
  1268. {
  1269. pers.stay_type = "旺旺推购";
  1270. }
  1271. if (entity.IsXianHuo == 0)
  1272. {
  1273. pers.product_id = entity.ProductId;
  1274. }
  1275. pers.wangwang = main.buyer_nick;
  1276. pers.shop_name = main.seller_nick;
  1277. pers.creata_time = DateTime.Now;
  1278. pers.create_u_id = CurrentUser.UserID;
  1279. pers.create_u_name = CurrentUser.UserName;
  1280. pers.Create();
  1281. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1282. }
  1283. else
  1284. {
  1285. pers.ctid = entity.ctid;
  1286. pers.audit_type = 0;
  1287. pers.Update();
  1288. }
  1289. CeErpSukuraData.createInfo(entity.ctid, 10);
  1290. }
  1291. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1292. returnSuccessMsg("标记成功!");
  1293. return;
  1294. }
  1295. returnErrorMsg("找不到记录");
  1296. }
  1297. }
  1298. public void upd_erp_ordertag_cancel()
  1299. {
  1300. if (UrlPostParmsCheck("ctid"))
  1301. {
  1302. string eid = GetPostString("ctid");
  1303. CeErpTradeCell entity = null;
  1304. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1305. if (entity != null)
  1306. {
  1307. entity.wechatTag = 0;
  1308. entity.Update();
  1309. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1310. if (pers != null)
  1311. {
  1312. pers.status = "取消推购";
  1313. pers.audit_type = 3;
  1314. pers.Update();
  1315. }
  1316. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1317. returnSuccessMsg("标记成功!");
  1318. return;
  1319. }
  1320. returnErrorMsg("找不到记录");
  1321. }
  1322. }
  1323. public void upd_erp_addweichattag()
  1324. {
  1325. if (UrlPostParmsCheck("ctid"))
  1326. {
  1327. ;
  1328. string eid = GetPostString("ctid");
  1329. CeErpTradeCell entity = null;
  1330. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1331. if (entity != null)
  1332. {
  1333. if (entity.IsAddWechat > 0)
  1334. {
  1335. returnErrorMsg("此单已经标记过了");
  1336. return;
  1337. }
  1338. string sql = string.Format("select * from view_erptradecell where IsAddWechat>0 and buyer_nick=(select buyer_nick from ce_erptrade where tid='{0}')", entity.tid);
  1339. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1340. if (dt.Rows.Count > 0)
  1341. {
  1342. entity.IsAddWechat = 2;
  1343. }
  1344. else
  1345. {
  1346. entity.IsAddWechat = 1;
  1347. }
  1348. entity.Update();
  1349. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1350. returnSuccessMsg("标记成功!");
  1351. return;
  1352. }
  1353. returnErrorMsg("找不到记录");
  1354. }
  1355. }
  1356. public void upd_erp_getmyorder()
  1357. {
  1358. if (UrlPostParmsCheck("ctid"))
  1359. {
  1360. string eid = GetPostString("ctid");
  1361. CeErpTradeCell entity = null;
  1362. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1363. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1364. if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1365. {
  1366. returnErrorMsg("台湾客户需填写身份证号!");
  1367. return;
  1368. }
  1369. if (commonHelper.isFarAddress(father.receiver_state) && father.delivery_paymant == 0)
  1370. {
  1371. returnErrorMsg("偏远地区需要填写物流费!");
  1372. return;
  1373. }
  1374. if (entity != null)
  1375. {
  1376. if (entity.ctid.IndexOf("C") != -1)
  1377. {
  1378. StringBuilder sql = new StringBuilder();
  1379. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1380. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1381. if (dt.Rows.Count > 0)
  1382. {
  1383. decimal total = 0;
  1384. foreach (DataRow dr in dt.Rows)
  1385. {
  1386. total += Convert.ToDecimal(dr["payment"]);
  1387. }
  1388. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1389. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1390. {
  1391. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1392. return;
  1393. }
  1394. }
  1395. }
  1396. if (entity.OrderState == -1)
  1397. {
  1398. returnErrorMsg("待审核订单无法领取!");
  1399. return;
  1400. }
  1401. entity.CustomerUserId = CurrentUser.UserID;
  1402. if (entity.OrderState < 2)
  1403. {
  1404. entity.OrderState = 2;
  1405. if (entity.ShopId != 0)
  1406. {
  1407. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1408. }
  1409. }
  1410. entity.UpdateTime = DateTime.Now;
  1411. entity.Update();
  1412. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1413. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1414. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1415. {
  1416. //dataHelper.api_orderBack(entity.ctid, "0", "");
  1417. }
  1418. returnSuccessMsg("领单成功!");
  1419. return;
  1420. }
  1421. returnErrorMsg("找不到记录");
  1422. }
  1423. }
  1424. public void getmyorder_from_init()
  1425. {
  1426. if (UrlPostParmsCheck("ctid"))
  1427. {
  1428. string eid = GetPostString("ctid");
  1429. CeErpTradeCell entity = null;
  1430. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1431. if (entity != null)
  1432. {
  1433. string sellerMemo = GetPostString("sellerMemo");
  1434. if (sellerMemo.Length > 0)
  1435. {
  1436. entity.seller_memo = sellerMemo;
  1437. }
  1438. string oterhMemo = GetPostString("otherMemo");
  1439. if (oterhMemo.Length > 0)
  1440. {
  1441. entity.OtherMemo = oterhMemo;
  1442. }
  1443. int urg = GetPostInt("urgency");
  1444. entity.IsUrgency = (urg == 1 ? true : false);
  1445. int wechat = GetPostInt("wechat");
  1446. int command = GetPostInt("command");
  1447. if (wechat == 1)
  1448. {
  1449. entity.wechatTag = 1;
  1450. }
  1451. if (command == 1)
  1452. {
  1453. entity.wechatTag = 2;
  1454. }
  1455. string pPro = GetPostString("pprofession");
  1456. if (pPro.Length > 0)
  1457. {
  1458. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1459. string spro = GetPostString("profession");
  1460. if (spro.Length > 0)
  1461. {
  1462. entity.ProfessionId = Convert.ToInt32(spro);
  1463. }
  1464. }
  1465. string proId = GetPostString("productId");
  1466. if (proId.Length > 0)
  1467. {
  1468. entity.ProductId = Convert.ToInt32(proId);
  1469. }
  1470. entity.Material = GetPostString("material");
  1471. entity.Craft = GetPostString("craft");
  1472. entity.CustomerUserId = CurrentUser.UserID;
  1473. if (entity.OrderState < 2)
  1474. {
  1475. entity.OrderState = 2;
  1476. if (entity.ShopId != 0)
  1477. {
  1478. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1479. }
  1480. }
  1481. entity.Update();
  1482. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1483. returnSuccessMsg("领单成功!");
  1484. return;
  1485. }
  1486. returnErrorMsg("找不到记录");
  1487. }
  1488. }
  1489. public void upd_erp_setrelationorder()
  1490. {
  1491. if (UrlPostParmsCheck("ctid"))
  1492. {
  1493. ;
  1494. string eid = GetPostString("ctid");
  1495. string ftid = GetPostString("ftid");
  1496. CeErpTradeCell entity = null;
  1497. CeErpTradeCell fentity = null;
  1498. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1499. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1500. if (fentity == null)
  1501. {
  1502. returnErrorMsg("找不到关联的主订单");
  1503. return;
  1504. }
  1505. if (entity != null)
  1506. {
  1507. if (entity.OrderState >= 5)
  1508. {
  1509. returnErrorMsg("本单已经设计完成无法关联");
  1510. return;
  1511. }
  1512. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1513. {
  1514. returnErrorMsg("线下单续审核后才能关联!");
  1515. return;
  1516. }
  1517. entity.ptid = ftid;
  1518. entity.OrderState = fentity.OrderState;
  1519. //entity.status = fentity.status;
  1520. entity.CustomerUserId = fentity.CustomerUserId;
  1521. entity.DesignUserId = fentity.DesignUserId;
  1522. entity.seller_memo = "补差价单:" + ftid;
  1523. entity.IsSample = 2;
  1524. entity.Update();
  1525. ApiVo apiVo = new ApiVo();
  1526. apiVo.orderNumber = ftid;
  1527. apiVo.payment = entity.payment;
  1528. apiVo.actionName = "repairDesign";
  1529. designHelper.API_WorkCore(apiVo);//repairDesign
  1530. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1531. returnSuccessMsg("关联成功!");
  1532. return;
  1533. }
  1534. else
  1535. returnErrorMsg("找不到记录");
  1536. }
  1537. }
  1538. public void download_erp_neworder()
  1539. {
  1540. string seller = GetPostString("seller_nick");
  1541. string tid = GetPostString("tid");
  1542. if (seller.Length <= 0 || tid.Length <= 0)
  1543. {
  1544. returnErrorMsg("数据错误");
  1545. }
  1546. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1547. //{
  1548. // returnErrorMsg("找不到店铺Sessionkey");
  1549. //}
  1550. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1551. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1552. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1553. if (res.IndexOf("refOid") == -1)
  1554. {
  1555. returnErrorMsg("下载订单数据失败");
  1556. return;
  1557. }
  1558. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1559. returnSuccessMsg("下载完成");
  1560. //tmcHelper.createNewOrder(res);
  1561. //CeErpTrade entr = null;
  1562. //entr = CeErpTrade.Get(tid);
  1563. //if (entr != null)
  1564. //{
  1565. // returnSuccess("下载成功");
  1566. // //下载成功之后,Cell表生成对应的订单;
  1567. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1568. //}
  1569. //else
  1570. //{
  1571. // returnErrorMsg("下载失败或者创建订单失败");
  1572. //}
  1573. }
  1574. public void set_erp_atersale()
  1575. {
  1576. if (UrlPostParmsCheck("ctid"))
  1577. {
  1578. string eid = GetPostString("ctid");
  1579. string reason = GetPostString("AfterSaleReason");
  1580. CeErpTradeCell entity = null;
  1581. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1582. if (entity != null)
  1583. {
  1584. /*if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1585. {
  1586. returnErrorMsg("此订单已经在售后");
  1587. return;
  1588. }*/
  1589. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1590. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1591. entity.AfterSaleTime = DateTime.Now;
  1592. entity.HandleTime = null;
  1593. entity.Update();
  1594. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1595. returnSuccessMsg("转售后成功!");
  1596. return;
  1597. }
  1598. returnErrorMsg("找不到记录");
  1599. }
  1600. }
  1601. public void set_erp_withdraw()
  1602. {
  1603. if (UrlPostParmsCheck("ctid"))
  1604. {
  1605. try
  1606. {
  1607. string eid = GetPostString("ctid");//商品id
  1608. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1609. CeWithdraw ceWithdrawSelect = null;
  1610. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1611. if (ceWithdrawSelect != null)
  1612. {
  1613. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1614. {
  1615. ceWithdrawSelect.status = -1;
  1616. ceWithdrawSelect.Update();
  1617. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1618. returnSuccessMsg("重新发起审核成功");
  1619. return;
  1620. }
  1621. else
  1622. {
  1623. returnSuccessMsg("请勿重复申请!");
  1624. return;
  1625. }
  1626. }
  1627. else
  1628. {
  1629. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1630. if (string.IsNullOrEmpty(CustomerUserId))
  1631. {
  1632. CustomerUserId = "-1";
  1633. }
  1634. int Userid = CurrentUser.UserID;//用户id
  1635. CeWithdraw ceWithdraw = new CeWithdraw();
  1636. ceWithdraw.tid = eid;
  1637. ceWithdraw.userid = Userid;
  1638. ceWithdraw.providerid = CustomerUserId;
  1639. ceWithdraw.status = 3;
  1640. ceWithdraw.creationtime = DateTime.Now;
  1641. ceWithdraw.Create();
  1642. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1643. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1644. return;
  1645. }
  1646. }
  1647. catch
  1648. {
  1649. returnErrorMsg("申请撤回订单失败");
  1650. return;
  1651. }
  1652. }
  1653. }
  1654. public void ins_erp_billinfo()
  1655. {
  1656. if (UrlPostParmsCheck("ctid"))
  1657. {
  1658. string eid = GetPostString("ctid");
  1659. CeErpTradeCell entity = null;
  1660. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1661. if (entity != null)
  1662. {
  1663. CeErpBill bill = CeErpBill.GetByTid(eid);
  1664. bool isHave = false;
  1665. if (bill != null)
  1666. {
  1667. isHave = true;
  1668. if (bill.state != 4)
  1669. {
  1670. returnErrorMsg("此单已经申请过发票了");
  1671. return;
  1672. }
  1673. }
  1674. if (entity.IsNeedBill == 0)
  1675. {
  1676. entity.IsNeedBill = 1;
  1677. }
  1678. entity.Update();
  1679. string errjson = "";
  1680. try
  1681. {
  1682. CeErpBill bill_entity = new CeErpBill();
  1683. bill_entity.tid = entity.tid;
  1684. bill_entity.title = GetPostString("title");
  1685. string taxstr = GetPostString("tax");
  1686. taxstr = taxstr.Replace(" ", "");
  1687. bill_entity.tax = taxstr;
  1688. bill_entity.bank = GetPostString("bank");
  1689. string bankacstr = GetPostString("bankac");
  1690. bankacstr = bankacstr.Replace(" ", "");
  1691. bill_entity.bankac = bankacstr;
  1692. bill_entity.address = GetPostString("address");
  1693. bill_entity.phone = GetPostString("phone");
  1694. bill_entity.price = GetPostString("price");
  1695. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1696. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1697. {
  1698. billCount += 1;
  1699. }
  1700. string prebill = "ltb";
  1701. for (int idx = 1; idx <= 1; idx++)
  1702. {
  1703. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1704. string billoid = prebill + idx + dtstr;
  1705. bill_entity.billOrderId += billoid;
  1706. if (idx < billCount)
  1707. {
  1708. bill_entity.billOrderId += ",";
  1709. }
  1710. }
  1711. bill_entity.productId = GetPostInt("ProductName");
  1712. bill_entity.num = GetPostInt("num");
  1713. bill_entity.unit = GetPostString("unit");
  1714. bill_entity.type = GetPostString("type");
  1715. bill_entity.sendType = GetPostString("SendType");
  1716. bill_entity.email = GetPostString("email");
  1717. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1718. bill_entity.shopName = GetPostString("ShopName");
  1719. bill_entity.applymemo = GetPostString("applyMemo");
  1720. bill_entity.createTime = DateTime.Now;
  1721. bill_entity.state = 0;
  1722. bill_entity.userId = CurrentUser.UserID;
  1723. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1724. bill_entity.Create();
  1725. }
  1726. catch (Exception ex)
  1727. {
  1728. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1729. returnErrorMsg("创建发票出错!");
  1730. return;
  1731. }
  1732. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1733. returnSuccessMsg("发票申请成功!");
  1734. return;
  1735. }
  1736. returnErrorMsg("找不到记录");
  1737. }
  1738. }
  1739. public void ins_erp_neworder()
  1740. {
  1741. if (UrlPostParmsCheck("receiver_name"))
  1742. {
  1743. CeErpTrade entity = new CeErpTrade();
  1744. string plat_form = GetPostString("platform");
  1745. string preStr = "N_";
  1746. if (plat_form == "拼多多")
  1747. {
  1748. preStr = "P_";
  1749. }
  1750. else if (plat_form == "阿里巴巴")
  1751. {
  1752. preStr = "A_";
  1753. }
  1754. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1755. entity.seller_nick = GetPostString("seller_nick");
  1756. entity.buyer_nick = GetPostString("buyer_nick");
  1757. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1758. entity.total_fee = entity.payment;
  1759. entity.pay_time = DateTime.Now;
  1760. entity.status = "NOT_SHIPPED";
  1761. entity.receiver_name = GetPostString("receiver_name");
  1762. entity.receiver_mobile = GetPostString("receiver_mobile");
  1763. entity.receiver_state = GetPostString("receiver_state");
  1764. entity.receiver_city = GetPostString("receiver_city");
  1765. entity.receiver_district = GetPostString("receiver_district");
  1766. entity.receiver_address = GetPostString("receiver_address");
  1767. if (entity.receiver_state == "" || entity.receiver_city == "")
  1768. {
  1769. returnErrorMsg("收件地址不能为空");
  1770. return;
  1771. }
  1772. int shopId = 0;
  1773. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1774. if (nShop != null)
  1775. {
  1776. shopId = nShop.ID;
  1777. }
  1778. if (shopId != 34 && entity.payment == 0)
  1779. {
  1780. returnErrorMsg("公司自用的单金额才能为0");
  1781. return;
  1782. }
  1783. entity.Create();
  1784. CeErpTradeCell entitycell = new CeErpTradeCell();
  1785. entitycell.ctid = entity.tid;
  1786. entitycell.tid = entity.tid;
  1787. entitycell.ShopId = shopId;
  1788. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1789. entitycell.OrderState = 0;
  1790. entitycell.pay_time = entity.pay_time;
  1791. entitycell.IsOffLineOrder = 1;
  1792. entitycell.Create();
  1793. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1794. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1795. return;
  1796. }
  1797. }
  1798. public void ins_erp_neworder2()
  1799. {
  1800. if (UrlPostParmsCheck("receiver_name"))
  1801. {
  1802. //string plat_form = GetPostString("platform");
  1803. string preStr = "X_";
  1804. string memo = GetPostString("memo");
  1805. string productId = GetPostString("productId");
  1806. string primg = GetPostString("proofimg");
  1807. string sellerNick = GetPostString("seller_nick");
  1808. string addFrom = GetPostString("addfrom");
  1809. if (addFrom == "1")
  1810. {
  1811. preStr = "N_";
  1812. }
  1813. int shopId = 0;
  1814. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1815. if (nShop != null)
  1816. {
  1817. shopId = nShop.ID;
  1818. }
  1819. else
  1820. {
  1821. returnErrorMsg("找不到对应店铺");
  1822. return;
  1823. }
  1824. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1825. {
  1826. returnErrorMsg("必须上传付款凭证");
  1827. return;
  1828. }
  1829. CeErpTrade entity = new CeErpTrade();
  1830. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1831. entity.seller_nick = sellerNick;
  1832. entity.buyer_nick = GetPostString("buyer_nick");
  1833. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1834. entity.total_fee = entity.payment;
  1835. entity.pay_time = DateTime.Now;
  1836. entity.status = "NOT_SHIPPED";
  1837. entity.receiver_name = GetPostString("receiver_name");
  1838. entity.receiver_mobile = GetPostString("receiver_mobile");
  1839. entity.receiver_state = GetPostString("receiver_state");
  1840. entity.receiver_city = GetPostString("receiver_city");
  1841. entity.receiver_district = GetPostString("receiver_district");
  1842. entity.receiver_address = GetPostString("receiver_address");
  1843. entity.seller_memo = memo;
  1844. entity.orderFrom = 20;
  1845. entity.orderType = 15;
  1846. if (entity.receiver_state == "" || entity.receiver_city == "")
  1847. {
  1848. returnErrorMsg("收件地址不能为空");
  1849. return;
  1850. }
  1851. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1852. {
  1853. returnErrorMsg("公司自用的单金额才能为0");
  1854. return;
  1855. }
  1856. entity.Create();
  1857. string toWhere = GetPostString("towhere");
  1858. string oldOrder = GetPostString("oldOrder");
  1859. CeErpTradeCell entitycell = new CeErpTradeCell();
  1860. entitycell.ctid = entity.tid;
  1861. //唯一标识
  1862. entitycell.OrderSn = entity.tid;
  1863. string orderSn = commonHelper.generateDateTimeRandomNos();
  1864. if (orderSn != "")
  1865. {
  1866. entitycell.OrderSn = orderSn;
  1867. }
  1868. entitycell.tid = entity.tid;
  1869. //if (preStr == "X_")
  1870. //{
  1871. entitycell.IsOffLineOrder = 1;
  1872. if ("1".Equals(oldOrder))
  1873. {
  1874. entitycell.IsOldCustomer = 1;
  1875. }
  1876. //}
  1877. entitycell.CustomerUserId = CurrentUser.UserID;
  1878. entitycell.PayProofImg = primg;
  1879. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1880. entitycell.ProductId = Convert.ToInt32(productId);
  1881. entitycell.ShopId = shopId;
  1882. entitycell.UpdateTime = DateTime.Now;
  1883. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1884. if (entitycell.ProductId > 0)
  1885. {
  1886. CeErpProduct ceErpProduct = CeErpProduct.GetById(entitycell.ProductId);
  1887. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  1888. {
  1889. entitycell.NewProduct = 1;
  1890. }
  1891. }
  1892. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1893. {
  1894. entitycell.IsXianHuo = 1;
  1895. }
  1896. entitycell.pay_time = entity.pay_time;
  1897. if (toWhere == "1")
  1898. {
  1899. entitycell.OrderState = 2;
  1900. }
  1901. else
  1902. {
  1903. entitycell.OrderState = 6;
  1904. entitycell.FinishPlaceTime = entitycell.pay_time;
  1905. }
  1906. if (shopId == 94)
  1907. {
  1908. entitycell.OrderState = 4;
  1909. entitycell.WaitDesignTime = entitycell.pay_time;
  1910. entitycell.StartDesignTime = entitycell.pay_time;
  1911. entitycell.DesignUserId = 218;
  1912. }
  1913. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114 && shopId != 158))
  1914. {
  1915. entitycell.OrderState = -1;//修改12-5
  1916. CeWithdraw ceWithdraw = new CeWithdraw();
  1917. ceWithdraw.tid = entity.tid;
  1918. ceWithdraw.providerid = "-1";
  1919. ceWithdraw.status = -1;
  1920. ceWithdraw.creationtime = DateTime.Now;
  1921. ceWithdraw.userid = 4634;
  1922. ceWithdraw.Create();
  1923. }
  1924. entitycell.Create();
  1925. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1926. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1927. {
  1928. addPlaceRegist(entitycell, CurrentUser.UserID);
  1929. }
  1930. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1931. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1932. return;
  1933. }
  1934. }
  1935. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1936. {
  1937. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1938. entity.PlactTime = tradecell.pay_time;
  1939. entity.AddUserId = userid;
  1940. entity.FileName = tradecell.seller_memo;
  1941. entity.Supplier = 24;
  1942. entity.CreateTime = DateTime.Now;
  1943. entity.Did = tradecell.ctid;
  1944. entity.tid = tradecell.tid;
  1945. entity.splitTag = tradecell.SplitTag;
  1946. entity.CurState = "未完成";
  1947. entity.Create();
  1948. }
  1949. public void get_erp_offlinelist()
  1950. {
  1951. DataStruct dStruct = GetPostStruct();
  1952. List<string> lw = new List<string>();
  1953. string tid = GetPostString("ctid");
  1954. string date1 = GetPostString("date1");
  1955. string date2 = GetPostString("date2");
  1956. if (tid.Length > 0 || date1.Length > 0)
  1957. {
  1958. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1959. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1960. if (dw.Length > 0) lw.Add(dw);
  1961. }
  1962. else
  1963. {
  1964. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1965. }
  1966. string shopname = GetPostString("shopname");
  1967. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1968. string buyernick = GetPostString("buyer_nick");
  1969. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1970. string customer = GetPostString("customer");
  1971. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1972. string design = GetPostString("design");
  1973. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1974. string orderState = GetPostString("orderState");
  1975. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1976. string address = GetPostString("address");
  1977. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  1978. string sellermemo = GetPostString("seller_memo");
  1979. if (sellermemo.Length > 0)
  1980. {
  1981. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1982. }
  1983. string price1 = GetPostString("price1");
  1984. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1985. string price2 = GetPostString("price2");
  1986. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1987. //if (PKey != "admin")
  1988. //{
  1989. // string usershop = CurrentUser.User.pemShop;
  1990. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1991. //}
  1992. //if (ex_psize > 0)
  1993. //{
  1994. dStruct.Order = "pay_time desc";
  1995. //}
  1996. //else
  1997. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1998. lw.Add(string.Format("IsOffLineOrder=1"));
  1999. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2000. DataTable dt = null;
  2001. dt = WebCache.GetData("view_erptradecell", dStruct);
  2002. writeGridDataTableJson(dStruct.TotalCount, dt);
  2003. }
  2004. public void get_erp_returncashrecord()
  2005. {
  2006. DataStruct dStruct = GetPostStruct();
  2007. List<string> lw = new List<string>();
  2008. string tid = GetPostString("ctid");
  2009. if (tid.Length > 0)
  2010. {
  2011. lw.Add(string.Format("tid like '%{0}%'", tid));
  2012. dStruct.Order = "id desc";
  2013. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2014. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  2015. //writeGridDataTableJson(dStruct.TotalCount, dt);
  2016. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2017. return;
  2018. }
  2019. returnErrorMsg("id数据错误!");
  2020. }
  2021. public void ins_erp_returncashrecord()
  2022. {
  2023. if (UrlPostParmsCheck("tid"))
  2024. {
  2025. string tid = GetPostString("tid");
  2026. string retype = GetPostString("type");
  2027. StringBuilder sql = new StringBuilder();
  2028. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  2029. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2030. if (dt.Rows.Count > 0)
  2031. {
  2032. returnErrorMsg("相同返现类型记录已存在");
  2033. return;
  2034. }
  2035. CeErpReturnCash entity = new CeErpReturnCash();
  2036. entity.tid = tid;
  2037. entity.seller_nick = GetPostString("seller_nick");
  2038. string pment = GetPostString("payment");
  2039. if (pment.Length > 0)
  2040. {
  2041. entity.payment = Convert.ToDouble(pment);
  2042. }
  2043. entity.buyer_nick = GetPostString("buyer_nick");
  2044. entity.cashstate = 0;
  2045. entity.rtype = retype;
  2046. string rPrice = GetPostString("returnprice");
  2047. if (rPrice.Length > 0)
  2048. {
  2049. entity.returnprice = Convert.ToDouble(rPrice);
  2050. }
  2051. entity.created = DateTime.Now;
  2052. entity.con = GetPostString("con");
  2053. entity.img = GetPostString("img");
  2054. entity.applyuserid = CurrentUser.UserID;
  2055. entity.Create();
  2056. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  2057. returnSuccessMsg("操作成功!");
  2058. return;
  2059. }
  2060. }
  2061. public void set_erp_predelivery()
  2062. {
  2063. if (UrlPostParmsCheck("ctid"))
  2064. {
  2065. string eid = GetPostString("ctid");
  2066. CeErpTradeCell entity = null;
  2067. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2068. if (entity != null)
  2069. {
  2070. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  2071. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  2072. //{
  2073. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  2074. // return;
  2075. //}
  2076. entity.IsPreDelivery = 1;
  2077. entity.Update();
  2078. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2079. returnSuccessMsg("预发货成功!");
  2080. return;
  2081. //string shop = GetPostString("seller_nick");
  2082. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  2083. //string comName = GetPostString("comName");
  2084. //string comCode = GetPostString("comCode");
  2085. //string outSid = GetPostString("outSid");//运单号
  2086. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  2087. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  2088. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  2089. //string apires = "";
  2090. //if (deliveryType == "虚拟发货")
  2091. //{
  2092. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  2093. //}
  2094. //else
  2095. //{
  2096. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  2097. //}
  2098. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  2099. ////{
  2100. //if (apires.IndexOf("发货成功") != -1)
  2101. //{
  2102. // if (deliveryType != "虚拟发货")
  2103. // {
  2104. // //还要插入快递信息到 快递信息表
  2105. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  2106. // exinfo.tid = eid;
  2107. // exinfo.out_sid = outSid;
  2108. // exinfo.company_code = comCode;
  2109. // exinfo.company_name = comName;
  2110. // exinfo.delivery_memo = deliveryMemo;
  2111. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  2112. // exinfo.deliveryType = deliveryType;
  2113. // exinfo.Create();
  2114. // }
  2115. // returnSuccessMsg("发货成功!");
  2116. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2117. //}
  2118. //else
  2119. //{
  2120. // returnErrorMsg("淘宝发货失败!!");
  2121. //}
  2122. //return;
  2123. }
  2124. returnErrorMsg("找不到订单记录");
  2125. }
  2126. }
  2127. public void get_erp_unusuallist()
  2128. {
  2129. DataStruct dStruct = GetPostStruct();
  2130. List<string> lw = new List<string>();
  2131. string tid = GetPostString("ctid");
  2132. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  2133. string shopname = GetPostString("shopname");
  2134. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2135. string buyernick = GetPostString("buyer_nick");
  2136. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2137. string ResponsibleMan = GetPostString("responsible");
  2138. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2139. string date1 = GetPostString("date1");
  2140. string date2 = GetPostString("date2");
  2141. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2142. if (dw.Length > 0) lw.Add(dw);
  2143. string price1 = GetPostString("price1");
  2144. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2145. string price2 = GetPostString("price2");
  2146. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2147. string orderState = GetPostString("orderState");
  2148. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2149. string sellermemo = GetPostString("seller_memo");
  2150. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2151. lw.Add(string.Format("UnusualTag > 0"));
  2152. lw.Add(string.Format("IsRefund<={0}", 1));
  2153. dStruct.Order = "pay_time desc";
  2154. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2155. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2156. writeGridDataTableJson(dStruct.TotalCount, dt);
  2157. }
  2158. public void set_erp_unusualtonomal()
  2159. {
  2160. if (UrlPostParmsCheck("ctid"))
  2161. {
  2162. string eid = GetPostString("ctid");
  2163. CeErpTradeCell entity = null;
  2164. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2165. if (entity != null)
  2166. {
  2167. entity.UnusualTag = -1;
  2168. entity.Update();
  2169. returnSuccessMsg("忽略成功!");
  2170. return;
  2171. }
  2172. returnErrorMsg("找不到记录");
  2173. }
  2174. }
  2175. public void ins_erp_unusualreason()
  2176. {
  2177. if (UrlPostParmsCheck("ctid"))
  2178. {
  2179. string eid = GetPostString("ctid");
  2180. CeErpTradeCell entity = null;
  2181. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2182. if (entity != null)
  2183. {
  2184. entity.MemoOpt = 4;
  2185. entity.UnusualCon = GetPostString("con");
  2186. entity.Update();
  2187. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2188. if (trade != null)
  2189. {
  2190. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2191. }
  2192. //查货是否超时
  2193. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2194. if (ceErpTradeCellExtend == null)
  2195. {
  2196. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2197. ceErpTradeCellExtend.ctid = entity.ctid;
  2198. }
  2199. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2200. {
  2201. ceErpTradeCellExtend.CheckOut += 1;
  2202. }
  2203. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2204. if (ceErpTradeCellExtend.ID > 0)
  2205. {
  2206. ceErpTradeCellExtend.Update();
  2207. }
  2208. else
  2209. {
  2210. ceErpTradeCellExtend.Create();
  2211. }
  2212. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2213. returnSuccessMsg("操作成功!");
  2214. return;
  2215. }
  2216. returnErrorMsg("找不到记录");
  2217. }
  2218. }
  2219. public void upd_erp_sampleorder()
  2220. {
  2221. if (UrlPostParmsCheck("ctid"))
  2222. {
  2223. string eid = GetPostString("ctid");
  2224. string[] eArr = eid.Split(',');
  2225. if (eArr.Length > 1)
  2226. {
  2227. List<string> eLst = new List<string>();
  2228. for (int i = 0; i < eArr.Length; i++)
  2229. {
  2230. eLst.Add("'" + eArr[i] + "'");
  2231. }
  2232. eid = string.Join(",", eLst.ToArray());
  2233. }
  2234. else
  2235. {
  2236. eid = "'" + eid + "'";
  2237. }
  2238. StringBuilder sql = new StringBuilder();
  2239. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2240. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2241. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2242. if (dt.Rows.Count > 0)
  2243. {
  2244. string errmsg = "";
  2245. foreach (DataRow dr in dt.Rows)
  2246. {
  2247. StringBuilder sqlsb = new StringBuilder();
  2248. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2249. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2250. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2251. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2252. //string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2253. /*if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2254. {
  2255. continue;
  2256. }
  2257. else
  2258. {
  2259. string emsg = commonHelper.KeepChinese(apires);
  2260. errmsg += emsg;
  2261. }*/
  2262. }
  2263. if (errmsg.Length > 0)
  2264. {
  2265. returnErrorMsg(errmsg);
  2266. return;
  2267. }
  2268. returnSuccessMsg("操作成功");
  2269. return;
  2270. }
  2271. returnErrorMsg("找不到记录");
  2272. }
  2273. }
  2274. public void upd_erp_transcustomer()
  2275. {
  2276. if (UrlPostParmsCheck("ctid"))
  2277. {
  2278. string eid = GetPostString("ctid");
  2279. int userid = GetPostInt("CustomerUserId");
  2280. CeErpTradeCell entity = null;
  2281. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2282. if (entity != null)
  2283. {
  2284. //string[] mlist = entity.seller_memo.Split('-');
  2285. //string sql = "select * from view_erpuser where id=" + userid;
  2286. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2287. //if (dt != null && dt.Rows.Count > 0)
  2288. //{
  2289. // string nmemo = "";
  2290. // for(int i = 0; i < mlist.Length - 1; i++)
  2291. // {
  2292. // nmemo += mlist[i];
  2293. // nmemo += "-";
  2294. // }
  2295. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2296. // entity.seller_memo = nmemo;
  2297. //}
  2298. entity.CustomerUserId = userid;
  2299. entity.Update();
  2300. returnSuccessMsg("操作成功!");
  2301. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2302. return;
  2303. }
  2304. returnErrorMsg("找不到记录");
  2305. }
  2306. }
  2307. public void upd_erp_transdesigner()
  2308. {
  2309. if (UrlPostParmsCheck("ctid"))
  2310. {
  2311. string eids = GetPostString("ctid");
  2312. string[] ctidList = eids.Split(',');
  2313. int userid = GetPostInt("DesignUserId");
  2314. foreach (string ctid in ctidList)
  2315. {
  2316. CeErpTradeCell entity = null;
  2317. CeErpDesignerBill entitys = null;
  2318. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2319. entitys = CeErpDesignerBill.GetByTid(ctid);
  2320. if (entity != null)
  2321. {
  2322. if (entity.OrderState > 4)
  2323. {
  2324. continue;
  2325. }
  2326. //存在退款不能流转
  2327. if (entity.IsRefund > 0)
  2328. {
  2329. continue;
  2330. }
  2331. entity.DesignUserId = userid;
  2332. entity.WaitDesignTime = DateTime.Now;
  2333. entity.Update();
  2334. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2335. }
  2336. }
  2337. returnSuccessMsg("操作成功!");
  2338. }
  2339. }
  2340. public void upd_erp_distributedesigner()
  2341. {
  2342. if (UrlPostParmsCheck("ctid"))
  2343. {
  2344. string eid = GetPostString("ctid");
  2345. int userid = GetPostInt("DesignUserId");
  2346. string[] idlist = eid.Split(',');
  2347. if (idlist.Length <= 0)
  2348. {
  2349. returnErrorMsg("订单不能为空");
  2350. return;
  2351. }
  2352. foreach (string ctid in idlist)
  2353. {
  2354. CeErpTradeCell entity = null;
  2355. CeErpDesignerBill entitys = null;
  2356. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2357. else continue;
  2358. if (entity != null)
  2359. {
  2360. if (userid == 2125 || userid == 3542)
  2361. { }
  2362. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2363. {
  2364. returnErrorMsg("金额错误的订单无法指派");
  2365. return;
  2366. }
  2367. if (entity.OrderState >= 5)
  2368. {
  2369. returnErrorMsg("已经设计完成无法指派");
  2370. return;
  2371. }
  2372. if (entity.OrderState == -1)
  2373. {
  2374. returnErrorMsg("审核中的订单无法指派");
  2375. return;
  2376. }
  2377. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2378. {
  2379. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2380. return;
  2381. }
  2382. //157赖橙帆 159林晨 73 静之颖
  2383. if (entity.OrderState > 3 && entity.DispatchSort == 2 && userid != 3542 && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Summarize" && CurrentUser.UserID != 157 && CurrentUser.UserID != 159 && CurrentUser.UserID != 1479)
  2384. {
  2385. returnErrorMsg("指派设计共创无法再次指派!");
  2386. return;
  2387. }
  2388. entity.OrderState = 3;
  2389. if (entity.SupplierId == 0)
  2390. {
  2391. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2392. entity.SupplierId = suid;
  2393. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2394. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2395. }
  2396. if (userid == 2125 && entity.seller_memo != "")
  2397. {
  2398. //apiDesign.API_GetPrintData_CreateOrder(entity);
  2399. }
  2400. List<int> shopIds = new List<int>() { 17, 21, 52, 54, 64, 63, 66, 49, 67, 105, 35, 57, 53, 65, 87, 140, 26, 45, 2, 77, 122, 121, 153, 154, 158 };
  2401. if (userid == 3542 && entity.seller_memo != "")
  2402. {
  2403. string userPost = CurrentUser.UserPost.Post.Code;
  2404. if (CurrentUser.UserID == 4516 || CurrentUser.UserID == 73 || shopIds.Contains(entity.ShopId))
  2405. {
  2406. userPost = "SysAdmin";
  2407. }
  2408. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2409. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2410. if (response.msg != "设计共创:成功")
  2411. {
  2412. returnErrorMsg(response.msg);
  2413. return;
  2414. }
  2415. entity.DispatchSort = 2;
  2416. }
  2417. else
  2418. {
  2419. if (entity.DispatchSort == 2)
  2420. {
  2421. ApiVo apiVo = new ApiVo();
  2422. apiVo.actionName = "closeDesign";
  2423. apiVo.orderNumber = entity.ctid;
  2424. designHelper.API_WorkCore(apiVo);//closeDesign
  2425. }
  2426. entity.DispatchSort = 0;
  2427. }
  2428. entity.DesignUserId = userid;
  2429. entity.WaitDesignTime = DateTime.Now;
  2430. entity.UpdateTime = DateTime.Now;
  2431. entity.Update();
  2432. string name = commonHelper.getUserNameById(userid);
  2433. commonHelper.UpdateRelationOrder(entity.ctid);
  2434. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2435. }
  2436. }
  2437. returnSuccessMsg("操作成功!");
  2438. return;
  2439. }
  2440. }
  2441. public string getTidByCtid(string ctid)
  2442. {
  2443. string tid = "";
  2444. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2445. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2446. if (dataTable != null && dataTable.Rows.Count > 0)
  2447. {
  2448. tid = dataTable.Rows[0]["tid"].ToString();
  2449. }
  2450. return tid;
  2451. }
  2452. public List<string> getTidByCtidMore(string ctid)
  2453. {
  2454. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or tid = '{0}' or orderSn = '{0}' or ( ParentSplitNo = '{0}' and IsSample =2) or (ptid = '{0}' and IsSample =2 ))", ctid);
  2455. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2456. List<string> list = new List<string>();
  2457. if (dataTable != null && dataTable.Rows.Count > 0)
  2458. {
  2459. foreach (DataRow item in dataTable.Rows)
  2460. {
  2461. list.Add("'" + item["tid"].ToString() + "'");
  2462. }
  2463. }
  2464. return list;
  2465. }
  2466. public List<string> getTidByCtidLike(string ctid)
  2467. {
  2468. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2469. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2470. List<string> list = new List<string>();
  2471. if (dataTable != null && dataTable.Rows.Count > 0)
  2472. {
  2473. foreach (DataRow item in dataTable.Rows)
  2474. {
  2475. list.Add("'" + item["tid"].ToString() + "'");
  2476. }
  2477. }
  2478. return list;
  2479. }
  2480. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2481. {
  2482. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2483. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2484. List<string> list = new List<string>();
  2485. if (dataTable != null && dataTable.Rows.Count > 0)
  2486. {
  2487. foreach (DataRow item in dataTable.Rows)
  2488. {
  2489. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2490. {
  2491. continue;
  2492. }
  2493. list.Add("'" + item["receiverId"].ToString() + "'");
  2494. }
  2495. }
  2496. return list;
  2497. }
  2498. public void get_erp_myorderlist()
  2499. {
  2500. DataStruct dStruct = GetPostStruct();
  2501. List<string> lw = new List<string>();
  2502. string tid = GetPostString("ctid");
  2503. if (tid.Length > 0)
  2504. {
  2505. string select_tid = getTidByCtid(tid);
  2506. lw.Add(string.Format("tid='{0}'", select_tid));
  2507. }
  2508. else
  2509. {
  2510. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2511. }
  2512. //12-1 修改
  2513. string urgent = GetPostString("urgent");
  2514. string back = GetPostString("back");
  2515. string offlineSearch = GetPostString("offlineSearch");
  2516. if (!string.IsNullOrWhiteSpace(urgent))
  2517. {
  2518. if (urgent.Equals("true"))
  2519. {
  2520. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2521. }
  2522. }
  2523. if (!string.IsNullOrWhiteSpace(back))
  2524. {
  2525. if (back.Equals("true"))
  2526. {
  2527. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2528. }
  2529. }
  2530. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2531. {
  2532. if (offlineSearch.Equals("true"))
  2533. {
  2534. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2535. }
  2536. }
  2537. //end
  2538. string shopname = GetPostString("shopname");
  2539. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2540. string buyernick = GetPostString("buyer_nick");
  2541. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2542. string design = GetPostString("design");
  2543. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2544. string orderState = GetPostString("orderState");
  2545. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2546. string sellermemo = GetPostString("seller_memo");
  2547. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2548. string date1 = GetPostString("date1");
  2549. string date2 = GetPostString("date2");
  2550. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2551. if (dw.Length > 0) lw.Add(dw);
  2552. string price1 = GetPostString("price1");
  2553. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2554. string price2 = GetPostString("price2");
  2555. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2556. string urgency = GetPostString("urgency");
  2557. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2558. string after = GetPostString("after");
  2559. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2560. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2561. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2562. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2563. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2564. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2565. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2566. if (dt != null && dt.Rows.Count > 0)
  2567. {
  2568. foreach (DataRow dr in dt.Rows)
  2569. {
  2570. try
  2571. {
  2572. // 对象操作
  2573. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2574. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2575. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2576. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2577. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2578. if (dStruct.PageSize != 100000)
  2579. {
  2580. if (dr["DispatchSort"].ToString() == "2")
  2581. {
  2582. dr["gongchuang"] = 200;
  2583. }
  2584. else if ("外协".Equals(dr["ToType"].ToString()))
  2585. {
  2586. dr["gongchuang"] = 200;
  2587. }
  2588. else if ("内部".Equals(dr["ToType"].ToString()))
  2589. {
  2590. dr["gongchuang"] = -1;
  2591. }
  2592. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2593. {
  2594. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2595. dr["gongchuang"] = response.code;
  2596. }
  2597. }
  2598. }
  2599. catch (NullReferenceException ex)
  2600. {
  2601. }
  2602. }
  2603. }
  2604. writeGridDataTableJson(dStruct.TotalCount, dt);
  2605. }
  2606. public void get_erp_myreturnorderlist()
  2607. {
  2608. DataStruct dStruct = GetPostStruct();
  2609. List<string> lw = new List<string>();
  2610. string tid = GetPostString("ctid");
  2611. if (tid.Length > 0)
  2612. {
  2613. string select_tid = getTidByCtid(tid);
  2614. lw.Add(string.Format("tid='{0}'", select_tid));
  2615. }
  2616. else
  2617. {
  2618. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2619. }
  2620. string shopname = GetPostString("shopname");
  2621. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2622. string buyernick = GetPostString("buyer_nick");
  2623. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2624. string design = GetPostString("design");
  2625. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2626. string orderState = GetPostString("orderState");
  2627. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2628. string sellermemo = GetPostString("seller_memo");
  2629. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2630. string date1 = GetPostString("date1");
  2631. string date2 = GetPostString("date2");
  2632. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2633. if (dw.Length > 0) lw.Add(dw);
  2634. string price1 = GetPostString("price1");
  2635. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2636. string price2 = GetPostString("price2");
  2637. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2638. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2639. {
  2640. lw.Add(string.Format("CusOrgID = 94"));
  2641. }
  2642. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2643. {
  2644. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2645. }
  2646. else
  2647. {
  2648. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2649. }
  2650. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2651. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2652. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2653. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2654. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2655. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2656. if (dt != null && dt.Rows.Count > 0)
  2657. {
  2658. foreach (DataRow dr in dt.Rows)
  2659. {
  2660. try
  2661. {
  2662. // 对象操作
  2663. if (dStruct.PageSize != 100000)
  2664. {
  2665. if (dr["DispatchSort"].ToString() == "2")
  2666. {
  2667. dr["gongchuang"] = 200;
  2668. }
  2669. else if ("外协".Equals(dr["ToType"].ToString()))
  2670. {
  2671. dr["gongchuang"] = 200;
  2672. }
  2673. else if ("内部".Equals(dr["ToType"].ToString()))
  2674. {
  2675. dr["gongchuang"] = -1;
  2676. }
  2677. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2678. {
  2679. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2680. dr["gongchuang"] = response.code;
  2681. }
  2682. }
  2683. }
  2684. catch (NullReferenceException ex)
  2685. {
  2686. // 处理空引用异常
  2687. }
  2688. }
  2689. }
  2690. writeGridDataTableJson(dStruct.TotalCount, dt);
  2691. }
  2692. public void get_erp_myorderlist_pregather()
  2693. {
  2694. string date1 = GetPostString("date1");
  2695. string date2 = GetPostString("date2");
  2696. int userId = CurrentUser.UserID; //客服id
  2697. string orderWhere = "";
  2698. List<string> lw = new List<string>();
  2699. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2700. if (dw.Length > 0) lw.Add(dw);
  2701. lw.Add(string.Format("CustomerUserId={0}", userId));
  2702. lw.Add(string.Format("OrderState<9"));
  2703. orderWhere = string.Join(" and ", lw.ToArray());
  2704. string orderWhere2 = "";
  2705. List<string> lw2 = new List<string>();
  2706. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2707. if (dw2.Length > 0) lw2.Add(dw2);
  2708. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2709. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2710. string sql = string.Format("select *" +
  2711. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2712. "left join(select CustomerUserId, count(ctid) as dCount from View_ErpTradeCell where OrderState = 6 and " + orderWhere2 + " group by CustomerUserId) b on a.CustomerUserId = b.CustomerUserId " +
  2713. "left join(select CustomerUserId, count(ctid) as jCount from View_ErpTradeCell where IsUrgency = 1 and " + orderWhere + " group by CustomerUserId) c on a.CustomerUserId = c.CustomerUserId " +
  2714. "left join(select CustomerUserId, count(ctid) as sCount from View_ErpTradeCell where AfterSaleState > 0 and CHARINDEX(','+CONVERT(varchar," + userId + ")+'_k,',','+ResponsibleUserId+',')>0 and " + orderWhere + " group by CustomerUserId) d on a.CustomerUserId = d.CustomerUserId");
  2715. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2716. //writeGridDataTableJson(dt.Rows.Count, dt);
  2717. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2718. }
  2719. public void upd_erp_publishorder()
  2720. {
  2721. if (UrlPostParmsCheck("ctid"))
  2722. {
  2723. string eid = GetPostString("ctid");
  2724. CeErpTradeCell entity = null;
  2725. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2726. if (entity != null)
  2727. {
  2728. entity.OrderState = 0; //发布后,变为待抢单
  2729. entity.Update();
  2730. commonHelper.UpdateRelationOrder(entity.ctid);
  2731. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2732. returnSuccessMsg("发布成功!");
  2733. return;
  2734. }
  2735. returnErrorMsg("找不到记录");
  2736. }
  2737. }
  2738. public void get_erp_my_tiporder()
  2739. {
  2740. StringBuilder sql = new StringBuilder();
  2741. int userId = 0;
  2742. if (CurrentUser != null) userId = CurrentUser.UserID;
  2743. string posCode = CurrentUser.UserPost.Post.Code;
  2744. string isTipedAfterSaleVerify = GetPostString("af");
  2745. DataTable dt = new DataTable();
  2746. if (posCode != "Supplier")
  2747. {
  2748. if (posCode == "CustomerService" || posCode == "Director")
  2749. {
  2750. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2751. }
  2752. else if (posCode == "Place" || posCode == "PlaceMr")
  2753. {
  2754. }
  2755. else
  2756. {
  2757. string teamIds = CurrentUser.User.TeamIds;
  2758. if (teamIds == "")
  2759. {
  2760. teamIds = "0";
  2761. }
  2762. sql.AppendFormat("select * from ce_erptradecell where (DesignUserId={0} or DesignUserId in (select ID from view_erpuser where OnDuty=0 and ID in ({1}))) and OrderState in (3,4) and IsReadTag>0 ", userId, teamIds);
  2763. }
  2764. if (sql.Length > 0)
  2765. {
  2766. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2767. }
  2768. }
  2769. if (dt.Rows.Count <= 0)
  2770. {
  2771. string key = "aftersale_order_" + userId;
  2772. if (RedisHelper.HasKey(key))
  2773. {
  2774. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2775. dt.Columns.Add("ctid", typeof(string));
  2776. dt.Columns.Add("IsReadTag", typeof(int));
  2777. foreach (var i in list)
  2778. {
  2779. DataRow data = dt.NewRow();
  2780. data["ctid"] = i;
  2781. data["IsReadTag"] = 4;
  2782. dt.Rows.Add(data);
  2783. }
  2784. RedisHelper.StringDelete(key);
  2785. }
  2786. }
  2787. if (dt.Rows.Count <= 0)
  2788. {
  2789. sql = new StringBuilder();
  2790. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2791. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2792. }
  2793. if (posCode == "Supplier")
  2794. {
  2795. string ids = CurrentUser.User.pemVend;
  2796. if (ids != null && ids.Length > 0)
  2797. {
  2798. string[] ids_list = ids.Split(',');
  2799. foreach (var item in ids_list)
  2800. {
  2801. string key = "return_order_" + item;
  2802. if (RedisHelper.HasKey(key))
  2803. {
  2804. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2805. dt.Columns.Add("ctid", typeof(string));
  2806. dt.Columns.Add("IsReadTag", typeof(int));
  2807. foreach (var i in list)
  2808. {
  2809. DataRow data = dt.NewRow();
  2810. data["ctid"] = i;
  2811. data["IsReadTag"] = 1;
  2812. dt.Rows.Add(data);
  2813. }
  2814. RedisHelper.StringDelete(key);
  2815. }
  2816. }
  2817. }
  2818. if (dt.Rows.Count <= 0)
  2819. {
  2820. sql = new StringBuilder();
  2821. sql.AppendFormat("select MemoOpt,SupplierId,ctid from ce_erptradecell where SupplierId in ({0}) and MemoOpt=3 and DATEDIFF(MINUTE,CheckOrderTime,GETDATE())<=3", CurrentUser.User.pemVend);
  2822. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2823. }
  2824. }
  2825. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2826. }
  2827. public void reset_erp_tiporder()
  2828. {
  2829. string ids = GetPostString("ids");
  2830. string[] ctidList = ids.Split(',');
  2831. foreach (string ctid in ctidList)
  2832. {
  2833. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2834. if (enty != null)
  2835. {
  2836. enty.IsReadTag = 0;
  2837. enty.Update();
  2838. }
  2839. }
  2840. returnSuccessMsg("成功!");
  2841. return;
  2842. }
  2843. public void get_erp_designlist()
  2844. {
  2845. DataStruct dStruct = GetPostStruct();
  2846. List<string> lw = new List<string>();
  2847. string tid = GetPostString("ctid");
  2848. if (tid.Length > 0)
  2849. {
  2850. string select_tid = getTidByCtid(tid);
  2851. lw.Add(string.Format("tid='{0}'", select_tid));
  2852. }
  2853. string shopname = GetPostString("shopname");
  2854. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2855. string buyernick = GetPostString("buyer_nick");
  2856. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2857. string customer = GetPostString("customer");
  2858. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2859. string design = GetPostString("design");
  2860. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2861. string orderState = GetPostString("orderState");
  2862. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2863. lw.Add(string.Format("OrderState<6"));
  2864. string address = GetPostString("address");
  2865. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2866. string sellermemo = GetPostString("seller_memo");
  2867. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2868. string date1 = GetPostString("date1");
  2869. string date2 = GetPostString("date2");
  2870. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2871. if (dw.Length > 0) lw.Add(dw);
  2872. string apdate1 = GetPostString("apdate1");
  2873. string apdate2 = GetPostString("apdate2");
  2874. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2875. if (dwap.Length > 0) lw.Add(dwap);
  2876. string price1 = GetPostString("price1");
  2877. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2878. string price2 = GetPostString("price2");
  2879. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2880. string designTime = GetPostString("designtime");
  2881. if (designTime.Length > 0)
  2882. {
  2883. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2884. }
  2885. string usershop = CurrentUser.User.pemShop;
  2886. if (usershop.Length > 0)
  2887. {
  2888. lw.Add(string.Format("shopId in ({0})", usershop));
  2889. }
  2890. int myOrgid = CurrentUser.UserPost.OrgID;
  2891. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2892. if (myOrgCode.IndexOf("Designer") != -1)
  2893. {
  2894. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2895. {
  2896. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2897. }
  2898. else
  2899. {
  2900. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2901. }
  2902. }
  2903. else
  2904. {
  2905. string orgId = GetPostString("designerhd");
  2906. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2907. }
  2908. if (tid.Length > 0 || buyernick.Length > 0)
  2909. {
  2910. lw.Add(string.Format("OrderState >= 3"));
  2911. }
  2912. else
  2913. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2914. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2915. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2916. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2917. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2918. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2919. if (dt != null && dt.Rows.Count > 0)
  2920. {
  2921. foreach (DataRow dr in dt.Rows)
  2922. {
  2923. try
  2924. {
  2925. // 对象操作
  2926. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2927. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2928. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2929. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2930. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2931. if (dStruct.PageSize != 100000)
  2932. {
  2933. if (dr["DispatchSort"].ToString() == "2")
  2934. {
  2935. dr["gongchuang"] = 200;
  2936. }
  2937. else if ("外协".Equals(dr["ToType"].ToString()))
  2938. {
  2939. dr["gongchuang"] = 200;
  2940. }
  2941. else if ("内部".Equals(dr["ToType"].ToString()))
  2942. {
  2943. dr["gongchuang"] = -1;
  2944. }
  2945. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2946. {
  2947. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2948. dr["gongchuang"] = response.code;
  2949. }
  2950. }
  2951. }
  2952. catch (NullReferenceException ex)
  2953. {
  2954. }
  2955. }
  2956. }
  2957. writeGridDataTableJson(dStruct.TotalCount, dt);
  2958. }
  2959. public void get_erp_mydesignlist()
  2960. {
  2961. DataStruct dStruct = GetPostStruct();
  2962. List<string> lw = new List<string>();
  2963. string tid = GetPostString("ctid");
  2964. if (tid.Length > 0)
  2965. {
  2966. string select_tid = getTidByCtid(tid);
  2967. lw.Add(string.Format("tid='{0}'", select_tid));
  2968. }
  2969. string shopname = GetPostString("shopname");
  2970. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2971. string buyernick = GetPostString("buyer_nick");
  2972. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2973. string customer = GetPostString("customer");
  2974. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2975. string orderState = GetPostString("orderState");
  2976. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2977. //lw.Add(string.Format("OrderState<6"));
  2978. string date1 = GetPostString("date1");
  2979. string date2 = GetPostString("date2");
  2980. string dw = GetDateWhere("pay_time", date1, date2);
  2981. if (dw.Length > 0) lw.Add(dw);
  2982. string apdate1 = GetPostString("apdate1");
  2983. string apdate2 = GetPostString("apdate2");
  2984. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2985. if (dwap.Length > 0) lw.Add(dwap);
  2986. string price1 = GetPostString("price1");
  2987. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2988. string price2 = GetPostString("price2");
  2989. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2990. string olddownload = GetPostString("olddown");
  2991. if (olddownload == "1")
  2992. {
  2993. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2994. }
  2995. else if (olddownload == "2")
  2996. {
  2997. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2998. }
  2999. string sellermemo = GetPostString("seller_memo");
  3000. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3001. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  3002. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  3003. {
  3004. if (CurrentUser.User.TeamIds.Length > 0)
  3005. {
  3006. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  3007. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3008. else
  3009. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3010. }
  3011. else
  3012. {
  3013. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  3014. }
  3015. }
  3016. if (tid.Length <= 0)
  3017. {
  3018. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  3019. }
  3020. lw.Add(string.Format("IsReturn!=3"));
  3021. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  3022. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3023. string teamids = CurrentUser.User.TeamIds.ToString();
  3024. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3025. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  3026. if (dt != null && dt.Rows.Count > 0)
  3027. {
  3028. foreach (DataRow dr in dt.Rows)
  3029. {
  3030. try
  3031. {
  3032. // 对象操作
  3033. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  3034. ceErpTradeCell.ctid = dr["ctid"].ToString();
  3035. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  3036. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  3037. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  3038. if (dStruct.PageSize != 100000)
  3039. {
  3040. if (dr["DispatchSort"].ToString() == "2")
  3041. {
  3042. dr["gongchuang"] = 200;
  3043. }
  3044. else if ("外协".Equals(dr["ToType"].ToString()))
  3045. {
  3046. dr["gongchuang"] = 200;
  3047. }
  3048. else if ("内部".Equals(dr["ToType"].ToString()))
  3049. {
  3050. dr["gongchuang"] = -1;
  3051. }
  3052. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  3053. {
  3054. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  3055. dr["gongchuang"] = response.code;
  3056. }
  3057. }
  3058. }
  3059. catch (NullReferenceException ex)
  3060. {
  3061. }
  3062. }
  3063. }
  3064. writeGridDataTableJson(dStruct.TotalCount, dt);
  3065. }
  3066. public void set_erp_startdesign()
  3067. {
  3068. if (UrlPostParmsCheck("ctid"))
  3069. {
  3070. string eid = GetPostString("ctid");
  3071. CeErpTradeCell entity = null;
  3072. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3073. if (entity != null)
  3074. {
  3075. if (entity.OrderState != 3)
  3076. {
  3077. returnErrorMsg("请刷新,订单已经设计了");
  3078. return;
  3079. }
  3080. entity.StartDesignTime = DateTime.Now;
  3081. entity.OrderState = 4;
  3082. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  3083. {
  3084. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3085. entity.SupplierId = suid;
  3086. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3087. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3088. }
  3089. entity.UpdateTime = DateTime.Now;
  3090. //entity.MakeSupplier = suname;
  3091. entity.Update();
  3092. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3093. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3094. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  3095. commonHelper.getCytPrice(entity);
  3096. returnSuccessMsg("操作成功!");
  3097. return;
  3098. }
  3099. returnErrorMsg("找不到记录");
  3100. }
  3101. }
  3102. public void ins_erp_designselfmemo()
  3103. {
  3104. if (UrlPostParmsCheck("ctid"))
  3105. {
  3106. string eid = GetPostString("ctid");
  3107. string con = GetPostString("con");
  3108. CeErpTradeCell entity = null;
  3109. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3110. if (entity != null)
  3111. {
  3112. entity.DesignSelfMemo = con;
  3113. entity.Update();
  3114. returnSuccessMsg("操作成功!");
  3115. return;
  3116. }
  3117. returnErrorMsg("找不到记录");
  3118. }
  3119. }
  3120. public void ins_erp_designprice()
  3121. {
  3122. if (UrlPostParmsCheck("ctid"))
  3123. {
  3124. string eid = GetPostString("ctid");
  3125. int uid = CurrentUser.UserID;
  3126. string userName = CurrentUser.UserName;
  3127. CeErpTradeCell entity = null;
  3128. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  3129. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3130. if (entitys == null)
  3131. {
  3132. entitys = new CeErpDesignerBill();
  3133. }
  3134. if (entity != null)
  3135. {
  3136. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3137. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3138. entity.StartDesignTime = DateTime.Now;
  3139. entity.OrderState = 4;
  3140. string suname = "";
  3141. if (entity.SupplierId == 0)
  3142. {
  3143. int sid = commonHelper.autoDistributeToSupplier(entity);
  3144. entity.SupplierId = sid;
  3145. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3146. }
  3147. entity.Update();
  3148. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3149. if (ceErpUserPost != null)
  3150. {
  3151. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3152. if (ceErpPost != null)
  3153. {
  3154. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3155. {
  3156. entitys.tid = entity.ctid;
  3157. entitys.oid = entity.tid;
  3158. entitys.uid = uid;
  3159. entitys.userName = userName;
  3160. entitys.designerType = 1;
  3161. entitys.designerTypeText = "内部设计师";
  3162. entitys.price = Convert.ToDouble(GetPostString("price"));
  3163. entitys.designNum = GetPostInt("designNum");
  3164. entitys.modifyNum = GetPostInt("modifyNum");
  3165. entitys.designSize = GetPostString("designSize");
  3166. entitys.modifySize = GetPostString("modifySize");
  3167. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3168. {
  3169. entitys.create_time = DateTime.Now;
  3170. entitys.create_u_id = uid;
  3171. entitys.create_u_name = userName;
  3172. entitys.Save();
  3173. }
  3174. else
  3175. {
  3176. entitys.update_time = DateTime.Now;
  3177. entitys.update_u_id = uid;
  3178. entitys.update_u_name = userName;
  3179. entitys.Update();
  3180. }
  3181. }
  3182. }
  3183. }
  3184. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3185. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3186. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3187. if (suname != "")
  3188. {
  3189. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3190. }
  3191. commonHelper.getCytPrice(entity);
  3192. returnSuccessMsg("操作成功!");
  3193. return;
  3194. }
  3195. returnErrorMsg("找不到记录");
  3196. }
  3197. }
  3198. public void upload_erp_filecomplete()
  3199. {
  3200. if (UrlPostParmsCheck("ctid"))
  3201. {
  3202. string eid = GetPostString("ctid");
  3203. CeErpTradeCell entity = null;
  3204. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3205. if (entity != null)
  3206. {
  3207. entity.OrderState = 5; //设计完成
  3208. entity.Update();
  3209. returnSuccessMsg(eid + "上传成功,设计完成!");
  3210. return;
  3211. }
  3212. returnErrorMsg("找不到订单记录");
  3213. }
  3214. }
  3215. public void get_erp_designovertimelist()
  3216. {
  3217. DataStruct dStruct = GetPostStruct();
  3218. List<string> lw = new List<string>();
  3219. string tid = GetPostString("ctid");
  3220. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3221. string shopname = GetPostString("shopname");
  3222. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3223. string buyernick = GetPostString("buyer_nick");
  3224. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3225. string ResponsibleMan = GetPostString("responsible");
  3226. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3227. string date1 = GetPostString("date1");
  3228. string date2 = GetPostString("date2");
  3229. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3230. if (dw.Length > 0) lw.Add(dw);
  3231. string price1 = GetPostString("price1");
  3232. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3233. string price2 = GetPostString("price2");
  3234. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3235. string orderState = GetPostString("orderState");
  3236. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3237. string sellermemo = GetPostString("seller_memo");
  3238. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3239. lw.Add(string.Format("UnusualTag=3"));
  3240. lw.Add(string.Format("IsRefund<={0}", 1));
  3241. dStruct.Order = "WaitDesignTime desc";
  3242. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3243. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3244. writeGridDataTableJson(dStruct.TotalCount, dt);
  3245. }
  3246. //设计管理 获取抢单大厅列表
  3247. public void get_erp_grabinglist()
  3248. {
  3249. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3250. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3251. bool oldOrder = false;
  3252. if (org != null)
  3253. {
  3254. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3255. }
  3256. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3257. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3258. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3259. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3260. //先处理订单数据
  3261. if (dt.Rows.Count > 0)
  3262. {
  3263. Dictionary<string, int> design = null;
  3264. int count = 0;
  3265. foreach (DataRow row in dt.Rows)
  3266. {
  3267. if (map.ContainsKey(row["ShopId"].ToString()))
  3268. {
  3269. map.TryGetValue(row["ShopId"].ToString(), out design);
  3270. }
  3271. else
  3272. {
  3273. design = new Dictionary<string, int>();
  3274. }
  3275. if (design.ContainsKey(row["ProductId"].ToString()))
  3276. {
  3277. design.TryGetValue(row["ProductId"].ToString(), out count);
  3278. }
  3279. count++;
  3280. design[row["ProductId"].ToString()] = count;
  3281. map[row["ShopId"].ToString()] = design;
  3282. }
  3283. }
  3284. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3285. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3286. //把店铺排序和技能排序分类
  3287. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3288. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3289. if (design_dt.Rows.Count > 0)
  3290. {
  3291. Dictionary<string, string> design = null;
  3292. List<string> shopIds = null;
  3293. foreach (DataRow row in design_dt.Rows)
  3294. {
  3295. if ("0".Equals(row["designId"].ToString()))
  3296. {
  3297. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3298. {
  3299. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3300. }
  3301. else
  3302. {
  3303. shopIds = new List<string>();
  3304. }
  3305. shopIds.Add(row["shopId"].ToString());
  3306. shop_orders[row["orders"].ToString()] = shopIds;
  3307. }
  3308. else
  3309. {
  3310. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3311. {
  3312. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3313. }
  3314. else
  3315. {
  3316. design = new Dictionary<string, string>();
  3317. }
  3318. design[row["orders"].ToString()] = row["designId"].ToString();
  3319. design_orders[row["shopId"].ToString()] = design;
  3320. }
  3321. }
  3322. //处理成key value后根据key排序
  3323. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3324. foreach (List<string> val in shop_orders.Values)
  3325. {
  3326. if (val != null)
  3327. {
  3328. foreach (string key in val)
  3329. {
  3330. if (design_orders.ContainsKey(key.ToString()))
  3331. {
  3332. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3333. }
  3334. }
  3335. }
  3336. }
  3337. }
  3338. //校验哪个优先级有订单
  3339. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3340. foreach (string key in shop_orders.Keys)
  3341. {
  3342. List<string> ids = null;
  3343. shop_orders.TryGetValue(key, out ids);
  3344. //id为shopid
  3345. foreach (string id in ids)
  3346. {
  3347. Dictionary<string, int> list = null;
  3348. Dictionary<string, string> desing = null;
  3349. map.TryGetValue(id, out list);
  3350. design_orders.TryGetValue(id, out desing);
  3351. if (list != null && desing != null)
  3352. {
  3353. foreach (var item in desing)
  3354. {
  3355. int count = 0;
  3356. if (list.ContainsKey(item.Value))
  3357. {
  3358. list.TryGetValue(item.Value, out count);
  3359. if (count > 0)
  3360. {
  3361. designIds[id] = item.Value;
  3362. break;
  3363. }
  3364. }
  3365. }
  3366. }
  3367. }
  3368. if (designIds.Count > 0)
  3369. {
  3370. break;
  3371. }
  3372. }
  3373. DataTable table = new DataTable();
  3374. table.Columns.Add("tid", typeof(string));
  3375. table.Columns.Add("ctid", typeof(string));
  3376. table.Columns.Add("seller_nick", typeof(string));
  3377. table.Columns.Add("productName", typeof(string));
  3378. table.Columns.Add("pay_time", typeof(string));
  3379. table.Columns.Add("seller_memo", typeof(string));
  3380. if (designIds.Count > 0)
  3381. {
  3382. string shopId = "";
  3383. string productId = "";
  3384. foreach (var designInfo in designIds)
  3385. {
  3386. shopId = designInfo.Key;
  3387. productId = designInfo.Value;
  3388. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3389. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3390. if (dt.Rows.Count > 0)
  3391. {
  3392. foreach (DataRow row in dt.Rows)
  3393. {
  3394. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3395. {
  3396. DataRow data = table.NewRow();
  3397. data["ctid"] = row["ctid"].ToString();
  3398. data["tid"] = row["tid"].ToString();
  3399. data["seller_nick"] = ceErpShop.ShopName;
  3400. data["pay_time"] = row["pay_time"].ToString();
  3401. data["seller_memo"] = row["seller_memo"].ToString();
  3402. data["productName"] = ceErpProduct.PType;
  3403. table.Rows.Add(data);
  3404. }
  3405. }
  3406. }
  3407. }
  3408. }
  3409. writeGridDataTableJson(table.Rows.Count, table);
  3410. }
  3411. private object rushLockObject = new object();
  3412. public void set_erp_grabingorder()
  3413. {
  3414. if (UrlPostParmsCheck("ctid"))
  3415. {
  3416. int total = CurrentUser.User.Person.Total;
  3417. int userId = CurrentUser.User.ID;
  3418. int noFinish = CurrentUser.User.Person.NoFinish;
  3419. int finalization = CurrentUser.User.Person.Finalization;
  3420. string eids = GetPostString("ctid");
  3421. string key = "RushKey_" + userId;
  3422. int count = 0;
  3423. if (erpRedis.RedisHelper.KeyExists(key))
  3424. {
  3425. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3426. if (redisCount != null)
  3427. {
  3428. count = Convert.ToInt32(redisCount);
  3429. }
  3430. }
  3431. if (count >= total)
  3432. {
  3433. returnErrorMsg("半小时内已经抢" + total + "单");
  3434. return;
  3435. }
  3436. string[] ctidlist = eids.Split(',');
  3437. if (count + ctidlist.Length > total)
  3438. {
  3439. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3440. return;
  3441. }
  3442. int itag = 0;
  3443. lock (rushLockObject)
  3444. {
  3445. if (ctidlist.Length > 0)
  3446. {
  3447. string[] dtList = new string[ctidlist.Length];
  3448. for (int i = 0; i < ctidlist.Length; i++)
  3449. {
  3450. dtList[i] = "'" + ctidlist[i] + "'";
  3451. }
  3452. string sql_user = string.Format("select OrderState from CE_ErpTradeCell where DesignUserId = {0} and WaitDesignTime BETWEEN '{1}' and '{2}'", userId, DateTime.Now.ToString("yyyy-MM-dd 00:00:00"), DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
  3453. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3454. if (dt_user.Rows.Count > 0)
  3455. {
  3456. int doing = 0;//未定稿
  3457. int finish = 0;//已完成
  3458. foreach (DataRow dr in dt_user.Rows)
  3459. {
  3460. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3461. {
  3462. doing++;
  3463. }
  3464. else
  3465. {
  3466. finish++;
  3467. }
  3468. }
  3469. if (doing >= noFinish)
  3470. {
  3471. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3472. return;
  3473. }
  3474. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3475. {
  3476. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3477. return;
  3478. }
  3479. }
  3480. //校验选择单子状态
  3481. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3482. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3483. if (dt.Rows.Count > 0)
  3484. {
  3485. List<string> list = new List<string>();
  3486. foreach (DataRow dr in dt.Rows)
  3487. {
  3488. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3489. {
  3490. list.Add(dr["ctid"].ToString());
  3491. }
  3492. }
  3493. if (list.Count > 0)
  3494. {
  3495. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3496. return;
  3497. }
  3498. }
  3499. foreach (string ctid in ctidlist)
  3500. {
  3501. CeErpTradeCell entity = null;
  3502. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3503. if (entity != null)
  3504. {
  3505. entity.OrderState = 3;
  3506. entity.DesignUserId = CurrentUser.UserID;
  3507. entity.WaitDesignTime = DateTime.Now;
  3508. entity.StartDesignTime = DateTime.Now;
  3509. entity.Update();
  3510. commonHelper.UpdateRelationOrder(entity.ctid);
  3511. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3512. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3513. itag++;
  3514. }
  3515. }
  3516. }
  3517. }
  3518. count += ctidlist.Length;
  3519. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3520. if (itag == 0)
  3521. returnErrorMsg("没有找到相关订单");
  3522. else
  3523. returnSuccessMsg("抢单成功!");
  3524. return;
  3525. }
  3526. }
  3527. public void get_erp_waitorderlist()
  3528. {
  3529. DataStruct dStruct = GetPostStruct();
  3530. List<string> lw = new List<string>();
  3531. string tid = GetPostString("ctid");
  3532. if (tid.Length > 0)
  3533. {
  3534. string select_tid = getTidByCtid(tid);
  3535. lw.Add(string.Format("tid='{0}'", select_tid));
  3536. }
  3537. string shopname = GetPostString("shopname");
  3538. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3539. string buyernick = GetPostString("buyer_nick");
  3540. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3541. string customer = GetPostString("customer");
  3542. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3543. string design = GetPostString("design");
  3544. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3545. string orderState = GetPostString("orderState");
  3546. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3547. string supplier = GetPostString("supplier");
  3548. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3549. string sellermemo = GetPostString("seller_memo");
  3550. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3551. string otherMemo = GetPostString("otherMemo");
  3552. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3553. string address = GetPostString("address");
  3554. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  3555. string date1 = GetPostString("date1");
  3556. string date2 = GetPostString("date2");
  3557. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3558. if (dw.Length > 0) lw.Add(dw);
  3559. string price1 = GetPostString("price1");
  3560. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3561. string price2 = GetPostString("price2");
  3562. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3563. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3564. lw.Add(string.Format("IsSample != 2 "));
  3565. lw.Add(string.Format("OrderState = 5 "));
  3566. lw.Add(string.Format("IsRefund<={0}", 1));
  3567. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3568. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3569. string pagesize = GetPostString("pagesize");
  3570. if (pagesize != null)
  3571. {
  3572. dStruct.PageSize = 200;
  3573. }
  3574. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3575. List<string> tids = new List<string>();
  3576. if (dt != null)
  3577. {
  3578. dt.Columns.Add("compenPrice", typeof(double));
  3579. foreach (DataRow dr in dt.Rows)
  3580. {
  3581. if (Convert.IsDBNull(dr["compenPrice"]))
  3582. {
  3583. dr["compenPrice"] = 0;
  3584. }
  3585. tids.Add("'" + dr["tid"].ToString() + "'");
  3586. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  3587. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3588. {
  3589. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3590. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3591. entity.SupplierId = suid;
  3592. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3593. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3594. entity.Update();
  3595. }
  3596. }
  3597. }
  3598. if (tids.Count > 0)
  3599. {
  3600. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3601. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3602. if (dt_price != null && dt_price.Rows.Count > 0)
  3603. {
  3604. foreach (DataRow dr in dt_price.Rows)
  3605. {
  3606. foreach (DataRow row in dt.Rows)
  3607. {
  3608. if (row["tid"].Equals(dr["ptid"]))
  3609. {
  3610. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3611. break;
  3612. }
  3613. }
  3614. }
  3615. }
  3616. }
  3617. writeGridDataTableJson(dStruct.TotalCount, dt);
  3618. }
  3619. public void get_erp_supplierwaitorderlist()
  3620. {
  3621. DataStruct dStruct = GetPostStruct();
  3622. List<string> lw = new List<string>();
  3623. string tid = GetPostString("ctid");
  3624. if (tid.Length > 0)
  3625. {
  3626. string select_tid = getTidByCtid(tid);
  3627. lw.Add(string.Format("tid='{0}'", select_tid));
  3628. }
  3629. string shopname = GetPostString("shopname");
  3630. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3631. string sellermemo = GetPostString("seller_memo");
  3632. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3633. string date1 = GetPostString("date1");
  3634. string date2 = GetPostString("date2");
  3635. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3636. if (dw.Length > 0) lw.Add(dw);
  3637. lw.Add(string.Format("OrderState = 5 "));
  3638. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3639. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3640. {
  3641. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3642. }
  3643. string supplier = GetPostString("supplier");
  3644. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3645. {
  3646. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3647. }
  3648. lw.Add(string.Format("IsRefund<={0}", 1));
  3649. dStruct.Order = "FinishDesignTime desc";
  3650. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3651. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3652. if (dt != null)
  3653. {
  3654. foreach (DataRow dr in dt.Rows)
  3655. {
  3656. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  3657. }
  3658. }
  3659. writeGridDataTableJson(dStruct.TotalCount, dt);
  3660. }
  3661. public void upd_erp_verifytosupplier()
  3662. {
  3663. if (UrlPostParmsCheck("ctid"))
  3664. {
  3665. string eids = GetPostString("ctid");
  3666. CeErpTradeCell entity = null;
  3667. string[] eidsList = eids.Split(',');
  3668. if (eidsList.Length <= 0)
  3669. {
  3670. returnErrorMsg("订单号不能空");
  3671. return;
  3672. }
  3673. List<string> tLst = new List<string>();
  3674. foreach (string ctidstr in eidsList)
  3675. {
  3676. tLst.Add("'" + ctidstr + "'");
  3677. CeErpDataSendOrderInfo.createObject(ctidstr);
  3678. }
  3679. string needtids = string.Join(",", tLst.ToArray());
  3680. StringBuilder sql = new StringBuilder();
  3681. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3682. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1},IsHaveNewOrder=0 where SupplierId!=0 AND OrderState = 5 and ctid in ({0});", needtids, CurrentUser.UserID);
  3683. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3684. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3685. returnSuccessMsg("操作成功!");
  3686. return;
  3687. /**foreach (string ctidstr in eidsList)
  3688. {
  3689. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3690. if (entity != null)
  3691. {
  3692. if (entity.SupplierId == 0)
  3693. {
  3694. continue;
  3695. }
  3696. entity.IsVerifyToSupplier = true;
  3697. if (entity.IsReturn == 1) //1是供应商打回
  3698. {
  3699. entity.IsReturn = 0;
  3700. }
  3701. entity.FinishPlaceTime = DateTime.Now;
  3702. entity.PlaceUserId = CurrentUser.UserID;
  3703. entity.Update();
  3704. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3705. }
  3706. }
  3707. returnSuccessMsg("操作成功!");
  3708. return;**/
  3709. }
  3710. }
  3711. public void upd_erp_supplierback()
  3712. {
  3713. if (UrlPostParmsCheck("ctid"))
  3714. {
  3715. string eid = GetPostString("ctid");
  3716. string reason = GetPostString("returnreason");
  3717. CeErpTradeCell entity = null;
  3718. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3719. if (entity != null)
  3720. {
  3721. string message = "操作成功!";
  3722. string isDown = "";
  3723. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3724. {
  3725. message = "订单有被点击下载。请注意沟通是否已下载完!";
  3726. isDown = "被点击下载";
  3727. }
  3728. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3729. {
  3730. string key = "return_order_" + entity.SupplierId;
  3731. List<string> list = new List<string>();
  3732. if (RedisHelper.HasKey(key))
  3733. {
  3734. object data = RedisHelper.StringGet(key);
  3735. list = Convert.ToString(data).Split(',').ToList();
  3736. }
  3737. list.Add(eid);
  3738. RedisHelper.StringSet(key, string.Join(",", list));
  3739. }
  3740. entity.IsVerifyToSupplier = false;
  3741. entity.IsReturn = 1;
  3742. entity.IsHaveNewOrder = 0;
  3743. entity.ReturnTime = DateTime.Now;
  3744. entity.ReturnReason = reason;
  3745. if (entity.OrderState == 6)
  3746. {
  3747. entity.OrderState = 5;
  3748. }
  3749. entity.Update();
  3750. CeErpSukuraData.createInfo(entity.ctid, 5);
  3751. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3752. returnSuccessMsg(message);
  3753. return;
  3754. }
  3755. returnErrorMsg("找不到订单记录");
  3756. }
  3757. }
  3758. public void upd_erp_toaftersaleorder()
  3759. {
  3760. if (UrlPostParmsCheck("ctid"))
  3761. {
  3762. string eid = GetPostString("ctid");
  3763. string reason = GetPostString("returnreason");
  3764. CeErpTradeCell entity = null;
  3765. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3766. if (entity != null)
  3767. {
  3768. if (entity.isAfterSaleOrder != 1)
  3769. {
  3770. returnErrorMsg("带S的售后单才能打回给售后");
  3771. return;
  3772. }
  3773. if (entity.OrderState >= 5)
  3774. {
  3775. returnErrorMsg("已经设计完成了不能打回给售后");
  3776. return;
  3777. }
  3778. entity.OrderState = 0;
  3779. entity.IsReturn = 3;
  3780. entity.ReturnTime = DateTime.Now;
  3781. entity.UpdateTime = DateTime.Now;
  3782. entity.ReturnReason = reason;
  3783. entity.Update();
  3784. CeErpSukuraData.createInfo(entity.ctid, 5);
  3785. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3786. returnSuccessMsg("操作成功!");
  3787. return;
  3788. }
  3789. returnErrorMsg("找不到订单记录");
  3790. }
  3791. }
  3792. public void upd_erp_aftersaletodesign()
  3793. {
  3794. if (UrlPostParmsCheck("ctid"))
  3795. {
  3796. string eid = GetPostString("ctid");
  3797. CeErpTradeCell entity = null;
  3798. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3799. if (entity != null)
  3800. {
  3801. entity.OrderState = 3;
  3802. entity.IsReturn = 0;
  3803. entity.UpdateTime = DateTime.Now;
  3804. entity.Update();
  3805. CeErpSukuraData.createInfo(entity.ctid, 5);
  3806. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3807. returnSuccessMsg("操作成功!");
  3808. return;
  3809. }
  3810. returnErrorMsg("找不到订单记录");
  3811. }
  3812. }
  3813. public void assign_erp_supplier()
  3814. {
  3815. if (UrlPostParmsCheck("ctid"))
  3816. {
  3817. string eids = GetPostString("ctid");
  3818. int sid = GetPostInt("SupplierName");
  3819. string fromTag = GetPostString("tag");
  3820. string[] eidList = eids.Split(',');
  3821. if (eidList.Length <= 0)
  3822. {
  3823. returnErrorMsg("指派不能为空");
  3824. return;
  3825. }
  3826. string errMsg = "";
  3827. string suname = commonHelper.getSupplierNameById(sid);
  3828. foreach (string ctid in eidList)
  3829. {
  3830. CeErpTradeCell entity = null;
  3831. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3832. if (entity != null)
  3833. {
  3834. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3835. {
  3836. errMsg += (ctid + "指派失败!!!");
  3837. continue;
  3838. }
  3839. entity.SupplierId = sid;
  3840. entity.Update();
  3841. commonHelper.UpdateRelationOrder(entity.ctid);
  3842. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3843. if (entity.OrderState >= 6)
  3844. {
  3845. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3846. //{
  3847. // string msl = entity.MakeSupplier;
  3848. // string[] mslist = msl.Split(',');
  3849. // sql.AppendFormat("update ce_erptradecell2 with(rowlock) set SupplierId={2} where ID in (select top {1} ID from ce_erptradecell2 where ctid='{0}' order by ID desc)", entity.ctid, mslist.Length,sid);
  3850. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3851. //}
  3852. //else
  3853. //{
  3854. StringBuilder sql = new StringBuilder();
  3855. sql.AppendFormat("update ce_erptradecell2 with(rowlock) set SupplierId={1},MakeSupplier='{2}' where ID in (select top 1 ID from ce_erptradecell2 where ctid='{0}' order by ID desc)", entity.ctid, sid, entity.MakeSupplier);
  3856. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3857. //}
  3858. }
  3859. }
  3860. else
  3861. {
  3862. continue;
  3863. }
  3864. }
  3865. if (errMsg.Length > 0)
  3866. {
  3867. returnErrorMsg(errMsg);
  3868. return;
  3869. }
  3870. returnSuccessMsg("操作成功!");
  3871. return;
  3872. }
  3873. }
  3874. public void assign_erp_makesupplier()
  3875. {
  3876. if (UrlPostParmsCheck("ctid"))
  3877. {
  3878. string eids = GetPostString("ctid");
  3879. string sname = GetPostString("SupplierName");
  3880. string[] eidList = eids.Split(',');
  3881. if (eidList.Length <= 0)
  3882. {
  3883. returnErrorMsg("指派不能为空");
  3884. return;
  3885. }
  3886. List<string> tLst = new List<string>();
  3887. foreach (string ctid in eidList)
  3888. {
  3889. CeErpTradeCell entity = null;
  3890. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3891. if (entity != null)
  3892. {
  3893. entity.MakeSupplier = sname;
  3894. entity.Update();
  3895. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3896. tLst.Add("'" + ctid + "'");
  3897. }
  3898. else
  3899. {
  3900. continue;
  3901. }
  3902. }
  3903. string ctids = string.Join(",", tLst.ToArray());
  3904. StringBuilder sql2 = new StringBuilder();
  3905. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3906. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3907. returnSuccessMsg("操作成功!");
  3908. return;
  3909. }
  3910. }
  3911. public void ins_erp_returnreason()
  3912. {
  3913. if (UrlPostParmsCheck("ctid"))
  3914. {
  3915. string eid = GetPostString("ctid");
  3916. CeErpTradeCell entity = null;
  3917. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3918. string userpost = CurrentUser.UserPost.Post.Code;
  3919. if (entity != null)
  3920. {
  3921. bool isPlace = false;
  3922. if (entity.OrderState > 6)
  3923. {
  3924. returnErrorMsg("已发货无法打回!");
  3925. return;
  3926. }
  3927. if (entity.OrderState == 6)
  3928. {
  3929. isPlace = true;
  3930. }
  3931. bool isNeedUpdateCell2 = false;
  3932. if (entity.OrderState >= 6)
  3933. {
  3934. isNeedUpdateCell2 = true;
  3935. }
  3936. int returnTag = 2;
  3937. if (userpost == "Supplier")
  3938. {
  3939. returnTag = 1;
  3940. }
  3941. int toType = GetPostInt("totype");
  3942. string fromType = "3";
  3943. if (entity.OrderState < 5)
  3944. {
  3945. fromType = "3";
  3946. }
  3947. else
  3948. {
  3949. fromType = "4";
  3950. }
  3951. if (entity.IsXianHuo == 0)
  3952. {
  3953. if (returnTag == 2)
  3954. {
  3955. if (toType == 1)
  3956. {
  3957. entity.OrderState = 0;
  3958. entity.ReturnUserType = 1;
  3959. string clearman = GetPostString("clearman");
  3960. if (!string.IsNullOrEmpty(clearman))
  3961. {
  3962. entity.DesignUserId = 0;
  3963. }
  3964. }
  3965. else
  3966. {
  3967. entity.OrderState = 3;
  3968. entity.ReturnUserType = 2;
  3969. }
  3970. entity.IsReadTag = 1;
  3971. }
  3972. else if (returnTag == 1)
  3973. {
  3974. entity.OrderState = 5;
  3975. }
  3976. entity.IsVerifyToSupplier = false;
  3977. }
  3978. if (entity.IsXianHuo == 1)
  3979. {
  3980. entity.OrderState = 5;
  3981. }
  3982. entity.UnusualTag = 0;
  3983. entity.UnusualTime = null;
  3984. entity.UnusualCon = "";
  3985. entity.IsReturn = returnTag;
  3986. entity.ReturnTime = DateTime.Now;
  3987. entity.UpdateTime = DateTime.Now;
  3988. entity.ReturnReason = GetPostString("returnreason");
  3989. entity.Update();
  3990. if (entity.OrderState == 3)
  3991. {
  3992. ApiVo apiVo = new ApiVo();
  3993. apiVo.orderNumber = entity.ctid;
  3994. apiVo.actionName = "rebutDesign";
  3995. apiVo.orderRemarks = entity.ReturnReason;
  3996. designHelper.API_WorkCore(apiVo);//rebutDesign
  3997. }
  3998. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3999. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  4000. {
  4001. //dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  4002. }
  4003. //CeErpSukuraData.createInfo(entity.ctid, 5);
  4004. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4005. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4006. if (isPlace)
  4007. {
  4008. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  4009. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4010. if (dth != null && dth.Rows.Count > 0)
  4011. {
  4012. dataSendOrderBean dataSendOrderBean = null;
  4013. foreach (DataRow item in dth.Rows)
  4014. {
  4015. try
  4016. {
  4017. dataSendOrderBean = new dataSendOrderBean();
  4018. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  4019. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  4020. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  4021. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  4022. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  4023. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  4024. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  4025. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  4026. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  4027. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  4028. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  4029. dataSendOrderBean.Radio1723534706288 = "打回";
  4030. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  4031. if (result != null)
  4032. {
  4033. if ("0".Equals(result.errcode))
  4034. {
  4035. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  4036. }
  4037. else
  4038. {
  4039. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  4040. }
  4041. }
  4042. }
  4043. catch (Exception ex)
  4044. {
  4045. }
  4046. }
  4047. }
  4048. }
  4049. returnSuccessMsg("操作成功!");
  4050. return;
  4051. }
  4052. returnErrorMsg("找不到订单记录");
  4053. }
  4054. }
  4055. public void cyt_erp_returnreason()
  4056. {
  4057. if (UrlPostParmsCheck("ctid"))
  4058. {
  4059. string eid = GetPostString("ctid");
  4060. CeErpTradeCell entity = null;
  4061. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4062. string userpost = CurrentUser.UserPost.Post.Code;
  4063. if (entity != null)
  4064. {
  4065. if (entity.OrderState > 6)
  4066. {
  4067. returnErrorMsg("已发货无法打回!");
  4068. return;
  4069. }
  4070. JObject jsonObject = new JObject
  4071. {
  4072. { "Userid", "77886" },
  4073. { "Pwd", "lt666888" },
  4074. { "LTOrderId",eid }
  4075. };
  4076. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  4077. JObject jsonObjects = JObject.Parse(response);
  4078. string msg = (string)jsonObjects["msg"];
  4079. if (msg != "取消成功")
  4080. {
  4081. returnErrorMsg(msg);
  4082. return;
  4083. }
  4084. bool isNeedUpdateCell2 = false;
  4085. if (entity.OrderState >= 6)
  4086. {
  4087. isNeedUpdateCell2 = true;
  4088. }
  4089. int returnTag = 2;
  4090. if (userpost == "Supplier")
  4091. {
  4092. returnTag = 1;
  4093. }
  4094. if (entity.IsXianHuo == 0)
  4095. {
  4096. if (returnTag == 2)
  4097. {
  4098. int toType = GetPostInt("totype");
  4099. if (toType == 1)
  4100. {
  4101. entity.OrderState = 0;
  4102. entity.ReturnUserType = 1;
  4103. }
  4104. else
  4105. {
  4106. entity.OrderState = 4;
  4107. entity.ReturnUserType = 2;
  4108. }
  4109. entity.IsReadTag = 1;
  4110. }
  4111. else if (returnTag == 1)
  4112. {
  4113. entity.OrderState = 5;
  4114. }
  4115. entity.IsVerifyToSupplier = false;
  4116. }
  4117. entity.UnusualTag = 0;
  4118. entity.UnusualTime = null;
  4119. entity.UnusualCon = "";
  4120. entity.IsReturn = returnTag;
  4121. entity.ReturnTime = DateTime.Now;
  4122. entity.ReturnReason = GetPostString("returnreason");
  4123. entity.Update();
  4124. if (entity.OrderState == 4)
  4125. {
  4126. ApiVo apiVo = new ApiVo();
  4127. apiVo.orderNumber = entity.ctid;
  4128. apiVo.actionName = "rebutDesign";
  4129. apiVo.orderRemarks = entity.ReturnReason;
  4130. designHelper.API_WorkCore(apiVo);//rebutDesign
  4131. }
  4132. CeErpSukuraData.createInfo(entity.ctid, 5);
  4133. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4134. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4135. if (isNeedUpdateCell2)
  4136. {
  4137. if (entity.MakeSupplier.IndexOf(",") != -1)
  4138. {
  4139. StringBuilder sql2 = new StringBuilder();
  4140. sql2.AppendFormat("update ce_erptradecell2 WITH(ROWLOCK) set BackState='已打回',ReturnReason='{0}',IsReturn={2} where ID in (select top 2 ID from ce_erptradecell2 where ctid='{1}' order by ID desc) ", entity.ReturnReason, entity.ctid, returnTag);
  4141. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4142. }
  4143. else
  4144. {
  4145. StringBuilder sql2 = new StringBuilder();
  4146. sql2.AppendFormat("update ce_erptradecell2 WITH(ROWLOCK) set BackState='已打回',ReturnReason='{0}',IsReturn={2} where ID in (select top 1 ID from ce_erptradecell2 where ctid='{1}' order by ID desc)", entity.ReturnReason, entity.ctid, returnTag);
  4147. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4148. }
  4149. }
  4150. returnSuccessMsg("操作成功!");
  4151. return;
  4152. }
  4153. returnErrorMsg("找不到订单记录");
  4154. }
  4155. }
  4156. public void upd_erp_xianhuoreturntag()
  4157. {
  4158. if (UrlPostParmsCheck("ctid"))
  4159. {
  4160. string eids = GetPostString("ctid");
  4161. string[] ctids = eids.Split(',');
  4162. foreach (string ctid in ctids)
  4163. {
  4164. CeErpTradeCell entity = null;
  4165. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4166. if (entity != null)
  4167. {
  4168. entity.IsReturn = 0;
  4169. entity.Update();
  4170. CeErpSukuraData.createInfo(entity.ctid, 5);
  4171. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4172. }
  4173. }
  4174. returnSuccessMsg("操作成功!");
  4175. return;
  4176. }
  4177. }
  4178. public void get_erp_waitdeliverylist()
  4179. {
  4180. DataStruct dStruct = GetPostStruct();
  4181. List<string> lw = new List<string>();
  4182. string tid = GetPostString("ctid");
  4183. if (tid.Length > 0)
  4184. {
  4185. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4186. if (tid.Length > 5)
  4187. {
  4188. List<string> tids = getTidByCtidLike(tid);
  4189. if (tids.Count > 0 && tids.Count < 10)
  4190. {
  4191. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4192. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4193. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4194. {
  4195. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4196. }*/
  4197. }
  4198. }
  4199. lw.Add(tid_sql);
  4200. }
  4201. string shopname = GetPostString("shopname");
  4202. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4203. string buyernick = GetPostString("buyer_nick");
  4204. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4205. //if (tid.Length == 0 && buyernick.Length == 0)
  4206. //{
  4207. // lw.Add(string.Format("IsRefund<={0}", 1));
  4208. //}
  4209. string customer = GetPostString("customer");
  4210. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4211. string design = GetPostString("design");
  4212. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4213. string orderState = GetPostString("orderState");
  4214. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4215. string address = GetPostString("address");
  4216. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4217. string sellermemo = GetPostString("seller_memo");
  4218. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4219. string supplier = GetPostString("supplier");
  4220. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4221. string OrderArea = GetPostString("order_area");
  4222. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4223. string placedate1 = GetPostString("placedate1");
  4224. string placedate2 = GetPostString("placedate2");
  4225. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4226. if (fdw.Length > 0) lw.Add(fdw);
  4227. string price1 = GetPostString("price1");
  4228. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4229. string price2 = GetPostString("price2");
  4230. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4231. string unusualCon = GetPostString("unusualcon");
  4232. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4233. string otherMemo = GetPostString("otherMemo");
  4234. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4235. string posTag = CurrentUser.UserPost.Post.Code;
  4236. if (posTag == "Supplier")
  4237. {
  4238. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4239. }
  4240. else
  4241. {
  4242. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4243. {
  4244. string usershop = CurrentUser.User.pemShop;
  4245. lw.Add(string.Format("ShopId in ({0})", usershop));
  4246. }
  4247. }
  4248. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4249. lw.Add(string.Format("type != 'PDD' "));
  4250. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4251. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4252. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4253. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4254. writeGridDataTableJson(dStruct.TotalCount, dt);
  4255. }
  4256. public void get_erp_changedeliverylist()
  4257. {
  4258. DataStruct dStruct = GetPostStruct();
  4259. List<string> lw = new List<string>();
  4260. string tid = GetPostString("ctid");
  4261. if (tid.Length > 0)
  4262. {
  4263. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4264. if (tid.Length > 5)
  4265. {
  4266. List<string> tids = getTidByCtidLike(tid);
  4267. if (tids.Count > 0 && tids.Count < 10)
  4268. {
  4269. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4270. }
  4271. }
  4272. lw.Add(tid_sql);
  4273. }
  4274. string shopname = GetPostString("shopname");
  4275. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4276. string buyernick = GetPostString("buyer_nick");
  4277. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4278. //if (tid.Length == 0 && buyernick.Length == 0)
  4279. //{
  4280. // lw.Add(string.Format("IsRefund<={0}", 1));
  4281. //}
  4282. string customer = GetPostString("customer");
  4283. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4284. string design = GetPostString("design");
  4285. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4286. string orderState = GetPostString("orderState");
  4287. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4288. string address = GetPostString("address");
  4289. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4290. string sellermemo = GetPostString("seller_memo");
  4291. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4292. string supplier = GetPostString("supplier");
  4293. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4294. string OrderArea = GetPostString("order_area");
  4295. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4296. string placedate1 = GetPostString("placedate1");
  4297. string placedate2 = GetPostString("placedate2");
  4298. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4299. if (fdw.Length > 0) lw.Add(fdw);
  4300. string price1 = GetPostString("price1");
  4301. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4302. string price2 = GetPostString("price2");
  4303. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4304. string unusualCon = GetPostString("unusualcon");
  4305. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4306. string otherMemo = GetPostString("otherMemo");
  4307. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4308. string posTag = CurrentUser.UserPost.Post.Code;
  4309. if (posTag == "Supplier")
  4310. {
  4311. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4312. }
  4313. else
  4314. {
  4315. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4316. {
  4317. string usershop = CurrentUser.User.pemShop;
  4318. lw.Add(string.Format("ShopId in ({0})", usershop));
  4319. }
  4320. }
  4321. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4322. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4323. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4324. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4325. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4326. /*if (tid.Length > 0)
  4327. {
  4328. List<string> tids = new List<string>();
  4329. if (dt != null && dt.Rows.Count > 0)
  4330. {
  4331. foreach (DataRow item in dt.Rows)
  4332. {
  4333. tids.Add("'" + item["tid"] + "'");
  4334. }
  4335. }
  4336. if (tids.Count > 0)
  4337. {
  4338. lw.RemoveAt(0);
  4339. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4340. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4341. dt = WebCache.GetData("view_erptradecell", dStruct);
  4342. }
  4343. }*/
  4344. writeGridDataTableJson(dStruct.TotalCount, dt);
  4345. }
  4346. public void get_erp_pddderiving()
  4347. {
  4348. DataStruct dStruct = GetPostStruct();
  4349. List<string> lw = new List<string>();
  4350. string tid = GetPostString("ctid");
  4351. if (tid.Length > 0)
  4352. {
  4353. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4354. if (tid.Length > 5)
  4355. {
  4356. List<string> tids = getTidByCtidLike(tid);
  4357. if (tids.Count > 0 && tids.Count < 10)
  4358. {
  4359. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4360. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4361. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4362. {
  4363. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4364. }*/
  4365. }
  4366. }
  4367. lw.Add(tid_sql);
  4368. }
  4369. string shopname = GetPostString("shopname");
  4370. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4371. string buyernick = GetPostString("buyer_nick");
  4372. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4373. //if (tid.Length == 0 && buyernick.Length == 0)
  4374. //{
  4375. // lw.Add(string.Format("IsRefund<={0}", 1));
  4376. //}
  4377. string customer = GetPostString("customer");
  4378. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4379. string design = GetPostString("design");
  4380. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4381. string orderState = GetPostString("orderState");
  4382. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4383. string address = GetPostString("address");
  4384. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4385. string sellermemo = GetPostString("seller_memo");
  4386. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4387. string supplier = GetPostString("supplier");
  4388. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4389. string OrderArea = GetPostString("order_area");
  4390. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4391. string placedate1 = GetPostString("placedate1");
  4392. string placedate2 = GetPostString("placedate2");
  4393. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4394. if (fdw.Length > 0) lw.Add(fdw);
  4395. string price1 = GetPostString("price1");
  4396. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4397. string price2 = GetPostString("price2");
  4398. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4399. string unusualCon = GetPostString("unusualcon");
  4400. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4401. string posTag = CurrentUser.UserPost.Post.Code;
  4402. if (posTag == "Supplier")
  4403. {
  4404. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4405. }
  4406. else
  4407. {
  4408. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4409. {
  4410. string usershop = CurrentUser.User.pemShop;
  4411. lw.Add(string.Format("ShopId in ({0})", usershop));
  4412. }
  4413. }
  4414. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4415. lw.Add(string.Format("type = 'PDD' "));
  4416. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4417. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4418. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4419. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4420. /*if (tid.Length > 0)
  4421. {
  4422. List<string> tids = new List<string>();
  4423. if (dt != null && dt.Rows.Count > 0)
  4424. {
  4425. foreach (DataRow item in dt.Rows)
  4426. {
  4427. tids.Add("'" + item["tid"] + "'");
  4428. }
  4429. }
  4430. if (tids.Count > 0)
  4431. {
  4432. lw.RemoveAt(0);
  4433. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4434. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4435. dt = WebCache.GetData("view_erptradecell", dStruct);
  4436. }
  4437. }*/
  4438. writeGridDataTableJson(dStruct.TotalCount, dt);
  4439. }
  4440. public void get_erp_jdderiving()
  4441. {
  4442. DataStruct dStruct = GetPostStruct();
  4443. List<string> lw = new List<string>();
  4444. string tid = GetPostString("ctid");
  4445. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4446. string shopname = GetPostString("shopname");
  4447. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4448. string buyernick = GetPostString("buyer_nick");
  4449. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4450. //if (tid.Length == 0 && buyernick.Length == 0)
  4451. //{
  4452. // lw.Add(string.Format("IsRefund<={0}", 1));
  4453. //}
  4454. string customer = GetPostString("customer");
  4455. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4456. string design = GetPostString("design");
  4457. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4458. string orderState = GetPostString("orderState");
  4459. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4460. string address = GetPostString("address");
  4461. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4462. string sellermemo = GetPostString("seller_memo");
  4463. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4464. string supplier = GetPostString("supplier");
  4465. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4466. string OrderArea = GetPostString("order_area");
  4467. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4468. string placedate1 = GetPostString("placedate1");
  4469. string placedate2 = GetPostString("placedate2");
  4470. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4471. if (fdw.Length > 0) lw.Add(fdw);
  4472. string price1 = GetPostString("price1");
  4473. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4474. string price2 = GetPostString("price2");
  4475. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4476. string unusualCon = GetPostString("unusualcon");
  4477. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4478. string posTag = CurrentUser.UserPost.Post.Code;
  4479. if (posTag == "Supplier")
  4480. {
  4481. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4482. }
  4483. lw.Add(string.Format("OrderState = 6 "));
  4484. lw.Add(string.Format("type = 'JD' "));
  4485. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4486. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4487. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4488. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4489. writeGridDataTableJson(dStruct.TotalCount, dt);
  4490. }
  4491. public void get_erp_demoorderlist()
  4492. {
  4493. DataStruct dStruct = GetPostStruct();
  4494. List<string> lw = new List<string>();
  4495. string tid = GetPostString("ctid");
  4496. if (tid.Length > 0)
  4497. {
  4498. string select_tid = getTidByCtid(tid);
  4499. lw.Add(string.Format("tid='{0}'", select_tid));
  4500. }
  4501. string shopname = GetPostString("shopname");
  4502. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4503. string buyernick = GetPostString("buyer_nick");
  4504. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4505. string customer = GetPostString("customer");
  4506. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4507. string design = GetPostString("design");
  4508. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4509. string orderState = GetPostString("orderState");
  4510. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4511. string address = GetPostString("address");
  4512. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4513. string sellermemo = GetPostString("seller_memo");
  4514. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4515. string supplier = GetPostString("supplier");
  4516. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4517. string OrderArea = GetPostString("order_area");
  4518. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4519. string date1 = GetPostString("date1");
  4520. string date2 = GetPostString("date2");
  4521. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4522. if (dw.Length > 0) lw.Add(dw);
  4523. string price1 = GetPostString("price1");
  4524. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4525. string price2 = GetPostString("price2");
  4526. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4527. string posTag = CurrentUser.UserPost.Post.Code;
  4528. if (posTag == "Supplier")
  4529. {
  4530. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4531. }
  4532. //lw.Add(string.Format("OrderState = 6 "));
  4533. lw.Add(string.Format("IsSample={0}", 3));
  4534. lw.Add(string.Format("IsRefund<={0}", 1));
  4535. dStruct.Order = "pay_time desc";
  4536. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4537. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4538. writeGridDataTableJson(dStruct.TotalCount, dt);
  4539. }
  4540. public void save_erp_checkmemo()
  4541. {
  4542. if (UrlPostParmsCheck("ctid"))
  4543. {
  4544. string ctid = GetPostString("ctid");
  4545. CeErpTradeCell entity = null;
  4546. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4547. if (entity != null)
  4548. {
  4549. entity.CheckMemo = GetPostString("CheckMemo");
  4550. entity.Update();
  4551. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4552. if (trade != null)
  4553. {
  4554. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4555. }
  4556. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4557. returnSuccessMsg("保存成功!");
  4558. return;
  4559. }
  4560. returnErrorMsg("找不到记录");
  4561. }
  4562. }
  4563. public void get_erp_returnlist()
  4564. {
  4565. DataStruct dStruct = GetPostStruct();
  4566. List<string> lw = new List<string>();
  4567. string tid = GetPostString("ctid");
  4568. if (tid.Length > 0)
  4569. {
  4570. string select_tid = getTidByCtid(tid);
  4571. lw.Add(string.Format("tid='{0}'", select_tid));
  4572. }
  4573. string shopname = GetPostString("shopname");
  4574. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4575. string buyernick = GetPostString("buyer_nick");
  4576. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4577. string customer = GetPostString("customer");
  4578. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4579. string design = GetPostString("design");
  4580. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4581. string orderState = GetPostString("orderState");
  4582. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4583. string address = GetPostString("address");
  4584. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4585. string sellermemo = GetPostString("seller_memo");
  4586. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4587. string supplier = GetPostString("supplier");
  4588. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4589. string date1 = GetPostString("date1");
  4590. string date2 = GetPostString("date2");
  4591. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4592. if (dw.Length > 0) lw.Add(dw);
  4593. string bdate1 = GetPostString("backdate1");
  4594. string bdate2 = GetPostString("backdate2");
  4595. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4596. if (dw_back.Length > 0) lw.Add(dw_back);
  4597. string price1 = GetPostString("price1");
  4598. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4599. string price2 = GetPostString("price2");
  4600. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4601. lw.Add(string.Format("IsReturn>0"));
  4602. lw.Add(string.Format("IsXianHuo=0"));
  4603. lw.Add(string.Format("IsReturn!=3"));
  4604. string backtype = GetPostString("backtype");
  4605. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4606. dStruct.Order = "FinishDesignTime desc";
  4607. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4608. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4609. writeGridDataTableJson(dStruct.TotalCount, dt);
  4610. }
  4611. public void get_erp_today_sumreturn()
  4612. {
  4613. DataStruct dStruct = GetPostStruct();
  4614. List<string> lw = new List<string>();
  4615. string bdate1 = GetPostString("returnTimeS");
  4616. string bdate2 = GetPostString("returnTimeE");
  4617. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4618. if (dw_back.Length > 0) lw.Add(dw_back);
  4619. lw.Add(string.Format("IsReturn=0"));
  4620. lw.Add(string.Format("IsXianHuo=0"));
  4621. string mainWhere = string.Join(" and ", lw.ToArray());
  4622. string sql = "";
  4623. if (dw_back.Length > 0)
  4624. {
  4625. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4626. }
  4627. else
  4628. {
  4629. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + " and ReturnTime >= '" + DateTime.Now.Date + "') as today_finish from view_erptradecell where ReturnTime >= '" + DateTime.Now.Date + "'";
  4630. }
  4631. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4632. decimal total = 0, today_finish = 0;
  4633. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4634. {
  4635. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4636. }
  4637. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4638. {
  4639. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4640. }
  4641. var res = new
  4642. {
  4643. data = total,
  4644. data1 = today_finish,
  4645. };
  4646. string ro_jsond = JsonConvert.SerializeObject(res);
  4647. returnSuccess(ro_jsond);
  4648. return;
  4649. }
  4650. public void get_erp_allreturnlist()
  4651. {
  4652. DataStruct dStruct = GetPostStruct();
  4653. List<string> lw = new List<string>();
  4654. string tid = GetPostString("ctid");
  4655. if (tid.Length > 0)
  4656. {
  4657. string select_tid = getTidByCtid(tid);
  4658. lw.Add(string.Format("tid='{0}'", select_tid));
  4659. }
  4660. string shopname = GetPostString("shopname");
  4661. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4662. string buyernick = GetPostString("buyer_nick");
  4663. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4664. string customer = GetPostString("customer");
  4665. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4666. string design = GetPostString("design");
  4667. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4668. string orderState = GetPostString("orderState");
  4669. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4670. string address = GetPostString("address");
  4671. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4672. string sellermemo = GetPostString("seller_memo");
  4673. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4674. string supplier = GetPostString("supplier");
  4675. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4676. string date1 = GetPostString("date1");
  4677. string date2 = GetPostString("date2");
  4678. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4679. if (dw.Length > 0) lw.Add(dw);
  4680. string bdate1 = GetPostString("backdate1");
  4681. string bdate2 = GetPostString("backdate2");
  4682. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4683. if (dw_back.Length > 0) lw.Add(dw_back);
  4684. string price1 = GetPostString("price1");
  4685. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4686. string price2 = GetPostString("price2");
  4687. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4688. string backreason = GetPostString("backreason");
  4689. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4690. lw.Add(string.Format("IsXianHuo=0"));
  4691. lw.Add(string.Format("ReturnTime != ''"));
  4692. string backtype = GetPostString("backtype");
  4693. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4694. string posTag = CurrentUser.UserPost.Post.Code;
  4695. if (posTag == "Supplier")
  4696. {
  4697. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4698. }
  4699. else
  4700. {
  4701. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4702. {
  4703. string usershop = CurrentUser.User.pemShop;
  4704. lw.Add(string.Format("ShopId in ({0})", usershop));
  4705. }
  4706. }
  4707. dStruct.Order = "FinishDesignTime desc";
  4708. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4709. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4710. writeGridDataTableJson(dStruct.TotalCount, dt);
  4711. }
  4712. public void get_erp_aftersalereturnlist()
  4713. {
  4714. DataStruct dStruct = GetPostStruct();
  4715. List<string> lw = new List<string>();
  4716. string tid = GetPostString("ctid");
  4717. if (tid.Length > 0)
  4718. {
  4719. string select_tid = getTidByCtid(tid);
  4720. lw.Add(string.Format("tid='{0}'", select_tid));
  4721. }
  4722. string shopname = GetPostString("shopname");
  4723. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4724. string buyernick = GetPostString("buyer_nick");
  4725. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4726. string customer = GetPostString("customer");
  4727. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4728. string design = GetPostString("design");
  4729. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4730. string orderState = GetPostString("orderState");
  4731. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4732. string address = GetPostString("address");
  4733. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4734. string sellermemo = GetPostString("seller_memo");
  4735. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4736. string supplier = GetPostString("supplier");
  4737. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4738. string date1 = GetPostString("date1");
  4739. string date2 = GetPostString("date2");
  4740. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4741. if (dw.Length > 0) lw.Add(dw);
  4742. string bdate1 = GetPostString("backdate1");
  4743. string bdate2 = GetPostString("backdate2");
  4744. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4745. if (dw_back.Length > 0) lw.Add(dw_back);
  4746. string price1 = GetPostString("price1");
  4747. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4748. string price2 = GetPostString("price2");
  4749. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4750. lw.Add(string.Format("IsReturn=3"));
  4751. string backtype = GetPostString("backtype");
  4752. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4753. string backreason = GetPostString("backreason");
  4754. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4755. dStruct.Order = "ReturnTime desc";
  4756. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4757. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4758. writeGridDataTableJson(dStruct.TotalCount, dt);
  4759. }
  4760. public void get_erp_xianhuoreturnlist()
  4761. {
  4762. DataStruct dStruct = GetPostStruct();
  4763. List<string> lw = new List<string>();
  4764. string tid = GetPostString("ctid");
  4765. if (tid.Length > 0)
  4766. {
  4767. string select_tid = getTidByCtid(tid);
  4768. lw.Add(string.Format("tid='{0}'", select_tid));
  4769. }
  4770. string shopname = GetPostString("shopname");
  4771. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4772. string buyernick = GetPostString("buyer_nick");
  4773. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4774. string customer = GetPostString("customer");
  4775. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4776. string design = GetPostString("design");
  4777. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4778. string orderState = GetPostString("orderState");
  4779. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4780. string address = GetPostString("address");
  4781. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4782. string sellermemo = GetPostString("seller_memo");
  4783. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4784. string supplier = GetPostString("supplier");
  4785. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4786. string OrderArea = GetPostString("order_area");
  4787. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4788. string date1 = GetPostString("date1");
  4789. string date2 = GetPostString("date2");
  4790. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4791. if (dw.Length > 0) lw.Add(dw);
  4792. string price1 = GetPostString("price1");
  4793. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4794. string price2 = GetPostString("price2");
  4795. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4796. string posTag = CurrentUser.UserPost.Post.Code;
  4797. if (posTag == "Supplier")
  4798. {
  4799. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4800. }
  4801. lw.Add(string.Format("OrderState=6 "));
  4802. lw.Add(string.Format("IsXianHuo=1 "));
  4803. lw.Add(string.Format("IsReturn>0 "));
  4804. lw.Add(string.Format("IsReturn < 3"));
  4805. lw.Add(string.Format("IsRefund<={0}", 1));
  4806. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4807. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4808. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4809. writeGridDataTableJson(dStruct.TotalCount, dt);
  4810. }
  4811. public void set_erp_orderdelivery()
  4812. {
  4813. if (UrlPostParmsCheck("ctid"))
  4814. {
  4815. string eid = GetPostString("ctid");
  4816. CeErpTradeCell entity = null;
  4817. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4818. if (entity != null)
  4819. {
  4820. if (entity.OrderState >= 7)
  4821. {
  4822. returnErrorMsg("此单已发货,无需重复发货");
  4823. return;
  4824. }
  4825. if (entity.OrderState != 6)
  4826. {
  4827. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4828. return;
  4829. }
  4830. string shop = GetPostString("seller_nick");
  4831. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4832. string comName = GetPostString("comName");
  4833. string comCode = GetPostString("comCode");
  4834. string outSid = GetPostString("outSid");
  4835. string deliveryType = GetPostString("deliveryType");
  4836. string deliveryMemo = GetPostString("deliveryMemo");
  4837. outSid = outSid.Trim();
  4838. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4839. if (mainEn == null)
  4840. {
  4841. returnErrorMsg("找不到原始订单记录");
  4842. return;
  4843. }
  4844. bool isInitOrderDeliv = false;
  4845. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4846. {
  4847. isInitOrderDeliv = true;
  4848. }
  4849. string apires = "";
  4850. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4851. if (entity.ctid.IndexOf("N") != -1 || entity.ctid.IndexOf("P") != -1 || entity.ctid.IndexOf("A") != -1 || entity.ctid.IndexOf("X") != -1 || entity.ctid.IndexOf("S") != -1)
  4852. {
  4853. apires = "发货成功true";
  4854. }
  4855. else
  4856. {
  4857. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4858. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid, entity.ctid);
  4859. }
  4860. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4861. {
  4862. entity.OrderState = 7;//发货后订单已发货
  4863. entity.OutSid = outSid;
  4864. entity.MemoOpt = 0;
  4865. entity.UpdateTime = DateTime.Now;
  4866. entity.FinishDeliveryTime = DateTime.Now;
  4867. entity.Update();
  4868. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4869. commonHelper.UpdateRelationOrder(entity.ctid);
  4870. //还要插入快递信息到 快递信息表
  4871. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4872. exinfo.tid = eid;
  4873. exinfo.out_sid = outSid;
  4874. exinfo.company_code = comCode;
  4875. exinfo.company_name = comName;
  4876. exinfo.delivery_memo = deliveryMemo;
  4877. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4878. exinfo.deliveryType = deliveryType;
  4879. exinfo.printUser = CurrentUser.UserName;
  4880. exinfo.print_time = DateTime.Now;
  4881. exinfo.Create();
  4882. returnSuccessMsg("发货操作成功!");
  4883. commonHelper.UpdateRelationOrder(entity.ctid);
  4884. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4885. CeErpSukuraData.createInfo(entity.ctid, 4);
  4886. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  4887. {
  4888. commonHelper.sendCytExpress(exinfo);
  4889. }
  4890. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4891. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid + ",备注:" + deliveryMemo, entity.OrderState);
  4892. }
  4893. else
  4894. {
  4895. string errmsg = commonHelper.KeepChinese(apires);
  4896. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4897. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4898. }
  4899. return;
  4900. }
  4901. returnErrorMsg("找不到订单记录");
  4902. }
  4903. }
  4904. public void set_erp_multidelivery()
  4905. {
  4906. string eids = GetPostString("tids");
  4907. string[] eidList = eids.Split(',');
  4908. if (eidList.Length <= 0)
  4909. {
  4910. returnErrorMsg("发货不能为空");
  4911. return;
  4912. }
  4913. foreach (string ctid in eidList)
  4914. {
  4915. if (ctid.Length <= 0) continue;
  4916. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4917. if (expInfo != null)
  4918. {
  4919. StringBuilder sql = new StringBuilder();
  4920. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4921. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4922. if (dt.Rows.Count > 0)
  4923. {
  4924. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4925. {
  4926. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4927. expInfo.state = "异常";
  4928. expInfo.isMultiDelivery = 1;
  4929. expInfo.Update();
  4930. continue;
  4931. }
  4932. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4933. {
  4934. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4935. expInfo.state = "异常";
  4936. expInfo.Update();
  4937. continue;
  4938. }
  4939. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4940. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4941. bool isInitOrderDeliv = false;
  4942. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4943. {
  4944. isInitOrderDeliv = true;
  4945. expInfo.isMultiDelivery = 1;
  4946. }
  4947. if (ctid.IndexOf("N") != -1)
  4948. {
  4949. StringBuilder sqlbucha = new StringBuilder();
  4950. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4951. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4952. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4953. commonHelper.UpdateRelationOrder(ctid);
  4954. expInfo.delivery_memo = "发货成功";
  4955. expInfo.state = "发货成功";
  4956. expInfo.isMultiDelivery = 1;
  4957. expInfo.Update();
  4958. }
  4959. else
  4960. {
  4961. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4962. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid, ctid);
  4963. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4964. {
  4965. expInfo.delivery_memo = "发货成功";
  4966. expInfo.state = "发货成功";
  4967. expInfo.isMultiDelivery = 1;
  4968. expInfo.Update();
  4969. commonHelper.UpdateRelationOrder(ctid);
  4970. CeErpSukuraData.createInfo(ctid, 4);
  4971. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4972. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4973. }
  4974. else
  4975. {
  4976. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4977. expInfo.state = "异常";
  4978. expInfo.Update();
  4979. }
  4980. }
  4981. }
  4982. }
  4983. }
  4984. returnSuccessMsg("操作完成");
  4985. }
  4986. public void reset_erp_memoopt()
  4987. {
  4988. if (UrlPostParmsCheck("ctid"))
  4989. {
  4990. string eid = GetPostString("ctid");
  4991. CeErpTradeCell entity = null;
  4992. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4993. if (entity != null)
  4994. {
  4995. string stropt = "";
  4996. if (entity.MemoOpt == 1)
  4997. {
  4998. stropt = "“改稿”";
  4999. }
  5000. else if (entity.MemoOpt == 2)
  5001. {
  5002. stropt = "“定稿”";
  5003. }
  5004. else if (entity.MemoOpt == 3)
  5005. {
  5006. stropt = "“完成查货”";
  5007. CeErpSukuraData.createInfo(entity.ctid, 6);
  5008. }
  5009. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  5010. entity.UpdateTime = DateTime.Now;
  5011. entity.MemoOpt = 0;
  5012. entity.Update();
  5013. returnSuccessMsg("操作成功!");
  5014. return;
  5015. }
  5016. returnErrorMsg("找不到记录");
  5017. }
  5018. }
  5019. public void get_erp_deliveryunusual()
  5020. {
  5021. DataStruct dStruct = GetPostStruct();
  5022. List<string> lw = new List<string>();
  5023. string tid = GetPostString("ctid");
  5024. if (tid.Length > 0)
  5025. {
  5026. string select_tid = getTidByCtid(tid);
  5027. lw.Add(string.Format("tid='{0}'", select_tid));
  5028. }
  5029. string shopname = GetPostString("shopname");
  5030. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5031. string buyernick = GetPostString("buyer_nick");
  5032. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5033. string customer = GetPostString("customer");
  5034. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5035. string design = GetPostString("design");
  5036. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5037. string sellermemo = GetPostString("seller_memo");
  5038. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5039. string supplier = GetPostString("supplier");
  5040. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5041. string date1 = GetPostString("date1");
  5042. string date2 = GetPostString("date2");
  5043. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5044. if (dw.Length > 0) lw.Add(dw);
  5045. string placedate1 = GetPostString("placedate1");
  5046. string placedate2 = GetPostString("placedate2");
  5047. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5048. if (dw_place.Length > 0) lw.Add(dw_place);
  5049. string price1 = GetPostString("price1");
  5050. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5051. string price2 = GetPostString("price2");
  5052. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5053. string unusualCon = GetPostString("unusualcon");
  5054. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  5055. string posTag = CurrentUser.UserPost.Post.Code;
  5056. if (posTag == "Supplier")
  5057. {
  5058. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5059. }
  5060. lw.Add(string.Format("OrderState = 6"));
  5061. lw.Add(string.Format("UnusualTag = 5"));
  5062. lw.Add(string.Format("IsRefund<={0}", 1));
  5063. dStruct.Order = "FinishPlaceTime desc";
  5064. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5065. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5066. writeGridDataTableJson(dStruct.TotalCount, dt);
  5067. }
  5068. public void get_erp_deliveryedlist()
  5069. {
  5070. DataStruct dStruct = GetPostStruct();
  5071. List<string> lw = new List<string>();
  5072. string tid = GetPostString("ctid");
  5073. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5074. string shopname = GetPostString("shopname");
  5075. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5076. string buyernick = GetPostString("buyer_nick");
  5077. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5078. string customer = GetPostString("customer");
  5079. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5080. string design = GetPostString("design");
  5081. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5082. string sellermemo = GetPostString("seller_memo");
  5083. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5084. string logistics = GetPostString("logistics");
  5085. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5086. string date1 = GetPostString("date1");
  5087. string date2 = GetPostString("date2");
  5088. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5089. //if (dw.Length > 0) lw.Add(dw);
  5090. string placedate1 = GetPostString("placedate1");
  5091. string placedate2 = GetPostString("placedate2");
  5092. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5093. if (fdw.Length > 0) lw.Add(fdw);
  5094. string devdate1 = GetPostString("deliverydate1");
  5095. string devdate2 = GetPostString("deliverydate2");
  5096. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5097. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5098. string price1 = GetPostString("price1");
  5099. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5100. string price2 = GetPostString("price2");
  5101. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5102. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5103. {
  5104. if (tid.Length > 0)
  5105. {
  5106. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5107. if (tid.Length > 5)
  5108. {
  5109. List<string> tids = getTidByCtidLike(tid);
  5110. if (tids.Count > 0 && tids.Count < 10)
  5111. {
  5112. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5113. }
  5114. }
  5115. lw.Add(tid_sql);
  5116. }
  5117. if (buyernick.Length > 0)
  5118. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5119. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5120. if (dw.Length > 0) lw.Add(dw);
  5121. }
  5122. else
  5123. {
  5124. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  5125. }
  5126. string posTag = CurrentUser.UserPost.Post.Code;
  5127. if (posTag == "Supplier")
  5128. {
  5129. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5130. }
  5131. else
  5132. {
  5133. string supplier = GetPostString("supplier");
  5134. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5135. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  5136. {
  5137. string usershop = CurrentUser.User.pemShop;
  5138. lw.Add(string.Format("ShopId in ({0})", usershop));
  5139. }
  5140. }
  5141. lw.Add(string.Format(" OrderState IN (7, 8)"));
  5142. lw.Add(string.Format("type != 'PDD' "));
  5143. lw.Add(string.Format("IsRefund!={0}", 2));
  5144. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5145. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5146. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5147. /*if (tid.Length > 0)
  5148. {
  5149. List<string> tids = new List<string>();
  5150. if (dt != null && dt.Rows.Count > 0)
  5151. {
  5152. foreach (DataRow item in dt.Rows)
  5153. {
  5154. tids.Add("'" + item["tid"] + "'");
  5155. }
  5156. }
  5157. if (tids.Count > 0)
  5158. {
  5159. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5160. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5161. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5162. dt = WebCache.GetData("view_erptradecell", dStruct);
  5163. }
  5164. }*/
  5165. if (dt != null)
  5166. {
  5167. foreach (DataRow dr in dt.Rows)
  5168. {
  5169. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5170. }
  5171. }
  5172. writeGridDataTableJson(dStruct.TotalCount, dt);
  5173. }
  5174. public void get_erp_pdddeliveryed()
  5175. {
  5176. DataStruct dStruct = GetPostStruct();
  5177. List<string> lw = new List<string>();
  5178. string tid = GetPostString("ctid");
  5179. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5180. string shopname = GetPostString("shopname");
  5181. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5182. string buyernick = GetPostString("buyer_nick");
  5183. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5184. string customer = GetPostString("customer");
  5185. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5186. string design = GetPostString("design");
  5187. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5188. string sellermemo = GetPostString("seller_memo");
  5189. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5190. string logistics = GetPostString("logistics");
  5191. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5192. string date1 = GetPostString("date1");
  5193. string date2 = GetPostString("date2");
  5194. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5195. //if (dw.Length > 0) lw.Add(dw);
  5196. string placedate1 = GetPostString("placedate1");
  5197. string placedate2 = GetPostString("placedate2");
  5198. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5199. if (fdw.Length > 0) lw.Add(fdw);
  5200. string devdate1 = GetPostString("deliverydate1");
  5201. string devdate2 = GetPostString("deliverydate2");
  5202. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5203. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5204. string price1 = GetPostString("price1");
  5205. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5206. string price2 = GetPostString("price2");
  5207. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5208. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5209. {
  5210. if (tid.Length > 0)
  5211. {
  5212. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5213. if (tid.Length > 5)
  5214. {
  5215. List<string> tids = getTidByCtidLike(tid);
  5216. if (tids.Count > 0 && tids.Count < 10)
  5217. {
  5218. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5219. }
  5220. }
  5221. lw.Add(tid_sql);
  5222. }
  5223. if (buyernick.Length > 0)
  5224. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5225. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5226. if (dw.Length > 0) lw.Add(dw);
  5227. }
  5228. else
  5229. {
  5230. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5231. }
  5232. string posTag = CurrentUser.UserPost.Post.Code;
  5233. if (posTag == "Supplier")
  5234. {
  5235. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5236. }
  5237. else
  5238. {
  5239. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  5240. {
  5241. string usershop = CurrentUser.User.pemShop;
  5242. lw.Add(string.Format("ShopId in ({0})", usershop));
  5243. }
  5244. string supplier = GetPostString("supplier");
  5245. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5246. }
  5247. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5248. lw.Add(string.Format("type = 'PDD' "));
  5249. lw.Add(string.Format("IsRefund!={0}", 2));
  5250. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5251. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5252. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5253. /* if (tid.Length > 0)
  5254. {
  5255. List<string> tids = new List<string>();
  5256. if (dt != null && dt.Rows.Count > 0)
  5257. {
  5258. foreach (DataRow item in dt.Rows)
  5259. {
  5260. tids.Add("'" + item["tid"] + "'");
  5261. }
  5262. }
  5263. if (tids.Count > 0)
  5264. {
  5265. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5266. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5267. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5268. dt = WebCache.GetData("view_erptradecell", dStruct);
  5269. }
  5270. }*/
  5271. foreach (DataRow dr in dt.Rows)
  5272. {
  5273. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5274. }
  5275. writeGridDataTableJson(dStruct.TotalCount, dt);
  5276. }
  5277. public void get_erp_jddeliveryed()
  5278. {
  5279. DataStruct dStruct = GetPostStruct();
  5280. List<string> lw = new List<string>();
  5281. string tid = GetPostString("ctid");
  5282. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5283. string shopname = GetPostString("shopname");
  5284. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5285. string buyernick = GetPostString("buyer_nick");
  5286. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5287. string customer = GetPostString("customer");
  5288. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5289. string design = GetPostString("design");
  5290. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5291. string sellermemo = GetPostString("seller_memo");
  5292. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5293. string date1 = GetPostString("date1");
  5294. string date2 = GetPostString("date2");
  5295. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5296. //if (dw.Length > 0) lw.Add(dw);
  5297. string placedate1 = GetPostString("placedate1");
  5298. string placedate2 = GetPostString("placedate2");
  5299. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5300. if (fdw.Length > 0) lw.Add(fdw);
  5301. string devdate1 = GetPostString("deliverydate1");
  5302. string devdate2 = GetPostString("deliverydate2");
  5303. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5304. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5305. string price1 = GetPostString("price1");
  5306. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5307. string price2 = GetPostString("price2");
  5308. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5309. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5310. {
  5311. if (tid.Length > 0)
  5312. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5313. if (buyernick.Length > 0)
  5314. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5315. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5316. if (dw.Length > 0) lw.Add(dw);
  5317. }
  5318. else
  5319. {
  5320. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5321. }
  5322. string posTag = CurrentUser.UserPost.Post.Code;
  5323. if (posTag == "Supplier")
  5324. {
  5325. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5326. }
  5327. else
  5328. {
  5329. string supplier = GetPostString("supplier");
  5330. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5331. }
  5332. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5333. lw.Add(string.Format("type = 'JD' "));
  5334. lw.Add(string.Format("IsRefund!={0}", 2));
  5335. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5336. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5337. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5338. foreach (DataRow dr in dt.Rows)
  5339. {
  5340. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5341. }
  5342. writeGridDataTableJson(dStruct.TotalCount, dt);
  5343. }
  5344. public void get_erp_allplacelist()
  5345. {
  5346. DataStruct dStruct = GetPostStruct();
  5347. List<string> lw = new List<string>();
  5348. string tid = GetPostString("ctid");
  5349. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5350. string shopname = GetPostString("shopname");
  5351. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5352. string buyernick = GetPostString("buyer_nick");
  5353. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5354. string customer = GetPostString("customer");
  5355. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5356. string design = GetPostString("design");
  5357. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5358. string sellermemo = GetPostString("seller_memo");
  5359. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5360. string supplier = GetPostString("supplier");
  5361. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5362. string date1 = GetPostString("date1");
  5363. string date2 = GetPostString("date2");
  5364. string pldate1 = GetPostString("placedate1");
  5365. string pldate2 = GetPostString("placedate2");
  5366. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5367. //if (dw.Length > 0) lw.Add(dw);
  5368. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5369. {
  5370. if (tid.Length > 0)
  5371. {
  5372. string select_tid = getTidByCtid(tid);
  5373. lw.Add(string.Format("tid='{0}'", select_tid));
  5374. }
  5375. if (buyernick.Length > 0)
  5376. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5377. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5378. if (dw.Length > 0) lw.Add(dw);
  5379. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5380. if (dw_place.Length > 0) lw.Add(dw_place);
  5381. }
  5382. else
  5383. {
  5384. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5385. {
  5386. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5387. }
  5388. }
  5389. string price1 = GetPostString("price1");
  5390. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5391. string price2 = GetPostString("price2");
  5392. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5393. string posTag = CurrentUser.UserPost.Post.Code;
  5394. if (posTag == "Supplier")
  5395. {
  5396. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5397. }
  5398. lw.Add(string.Format("OrderState >= 6"));
  5399. lw.Add(string.Format("IsSample != 2 "));
  5400. //lw.Add(string.Format("isDianziOrder = 0 "));
  5401. lw.Add(string.Format("SupplierId > 0 "));
  5402. //lw.Add(string.Format("IsRefund<={0}", 1));
  5403. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5404. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5405. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5406. foreach (DataRow dr in dt.Rows)
  5407. {
  5408. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5409. }
  5410. writeGridDataTableJson(dStruct.TotalCount, dt);
  5411. }
  5412. public void get_erp_financeallplacelist()
  5413. {
  5414. DataStruct dStruct = GetPostStruct();
  5415. List<string> lw = new List<string>();
  5416. string tid = GetPostString("ctid");
  5417. string shopname = GetPostString("shopname");
  5418. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5419. string buyernick = GetPostString("buyer_nick");
  5420. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5421. string customer = GetPostString("customer");
  5422. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5423. string design = GetPostString("design");
  5424. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5425. string sellermemo = GetPostString("seller_memo");
  5426. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5427. string supplier = GetPostString("supplier");
  5428. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5429. string date1 = GetPostString("date1");
  5430. string date2 = GetPostString("date2");
  5431. string pldate1 = GetPostString("placedate1");
  5432. string pldate2 = GetPostString("placedate2");
  5433. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5434. {
  5435. if (tid.Length > 0)
  5436. {
  5437. string select_tid = getTidByCtid(tid);
  5438. lw.Add(string.Format("tid='{0}'", select_tid));
  5439. }
  5440. if (buyernick.Length > 0)
  5441. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5442. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5443. if (dw.Length > 0) lw.Add(dw);
  5444. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5445. if (dw_place.Length > 0) lw.Add(dw_place);
  5446. }
  5447. else
  5448. {
  5449. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5450. {
  5451. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5452. }
  5453. }
  5454. string price1 = GetPostString("price1");
  5455. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5456. string price2 = GetPostString("price2");
  5457. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5458. string posTag = CurrentUser.UserPost.Post.Code;
  5459. if (posTag == "Supplier")
  5460. {
  5461. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5462. }
  5463. //lw.Add(string.Format("OrderState >= 6"));
  5464. lw.Add(string.Format("IsSample != 2 "));
  5465. lw.Add(string.Format("isDianziOrder = 0 "));
  5466. //lw.Add(string.Format("IsRefund<={0}", 1));
  5467. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5468. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5469. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5470. foreach (DataRow dr in dt.Rows)
  5471. {
  5472. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5473. }
  5474. writeGridDataTableJson(dStruct.TotalCount, dt);
  5475. }
  5476. public void get_erp_expresslist()
  5477. {
  5478. int listtype = GetInt("ltype");
  5479. DataStruct dStruct = GetPostStruct();
  5480. List<string> lw = new List<string>();
  5481. string tid = GetPostString("tid");
  5482. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5483. string outsid = GetPostString("out_sid");
  5484. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5485. string importer = GetPostString("ImportUserName");
  5486. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5487. string file = GetPostString("import_file");
  5488. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5489. string printman = GetPostString("printman");
  5490. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5491. string date1 = GetPostString("date1");
  5492. string date2 = GetPostString("date2");
  5493. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5494. if (dw.Length > 0) lw.Add(dw);
  5495. string fdate1 = GetPostString("finishdate1");
  5496. string fdate2 = GetPostString("finishdate2");
  5497. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5498. if (fdw.Length > 0) lw.Add(fdw);
  5499. string supplierId = GetPostString("supplierId");
  5500. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5501. if (listtype == 1)
  5502. {
  5503. lw.Add(string.Format("importUserId !=0"));
  5504. }
  5505. string posTag = CurrentUser.UserPost.Post.Code;
  5506. if (posTag == "Supplier")
  5507. {
  5508. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5509. }
  5510. if (dStruct.PageSize != 100000)
  5511. {
  5512. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5513. }
  5514. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5515. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5516. writeGridDataTableJson(dStruct.TotalCount, dt);
  5517. }
  5518. public void set_erp_buchaorderdelivery()
  5519. {
  5520. if (UrlPostParmsCheck("ctid"))
  5521. {
  5522. string eid = GetPostString("ctid");
  5523. CeErpTradeCell entity = null;
  5524. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5525. if (entity != null)
  5526. {
  5527. if (entity.IsSample != 2)
  5528. {
  5529. returnErrorMsg("补差价单才能标记为已发货");
  5530. return;
  5531. }
  5532. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5533. entity.OrderState = 7;
  5534. entity.Update();
  5535. returnSuccessMsg("操作成功!");
  5536. return;
  5537. }
  5538. returnErrorMsg("找不到记录");
  5539. }
  5540. }
  5541. public void get_stdtemplates()
  5542. {
  5543. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5544. //string res = taobaoHelper.test();
  5545. string res = apiHelper.API_PrintTemplate();
  5546. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5547. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5548. {
  5549. int sidx = res.IndexOf("error_code");
  5550. int eidx = res.IndexOf("success");
  5551. string msg = res.Substring(sidx, eidx - sidx);
  5552. returnErrorMsg(msg);
  5553. return;
  5554. }
  5555. if (res.Length <= 0)
  5556. {
  5557. returnErrorMsg("模板数据为空!");
  5558. return;
  5559. }
  5560. ReturnSuccess(res);
  5561. }
  5562. public void cancel_print_order()
  5563. {
  5564. if (UrlPostParmsCheck("ctid"))
  5565. {
  5566. string ctid = GetPostString("ctid");
  5567. CeErpTradeCell entity = null;
  5568. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5569. if (entity != null)
  5570. {
  5571. string res = "";
  5572. string code = entity.LastBillWaybillCode;
  5573. if (code == "")
  5574. {
  5575. code = entity.OutSid;
  5576. }
  5577. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5578. XLog.SaveLog(0, "取消面单" + res);
  5579. }
  5580. }
  5581. }
  5582. public void set_erp_printwaybill()
  5583. {
  5584. if (UrlPostParmsCheck("ctid"))
  5585. {
  5586. string ctid = GetPostString("ctid");
  5587. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5588. string cpName = GetPostString("cpname");
  5589. string isTogether = GetPostString("together");
  5590. string printType = GetPostString("printType");
  5591. //var res_obj = new
  5592. //{
  5593. // restype = 1,
  5594. // data = "{\"response\":{\"data\":{\"content\":[{\"openOrderSubId\":\"\",\"parentWaybillCode\":\"\",\"platformType\":\"WB_PDD\",\"updateTime\":1686537867000,\"orderPlatform\":\"PDD\",\"openOrderId\":\"230611-632307127861975\",\"merchId\":1,\"props\":{\"ver\":\"8\",\"signature\":\"lYwcylRHKaeMOxfUvBg7ySYTGGur75biVxO5LTXxM3KeTpMaf6rIvIUFG0HtW4m7+JynVGS83sdGaIAYK3Rrr4QZZTKskIXWKGHKES7lmCP1yM7xD8Cm50aBAfelZo390L1PBb5WSn3EQB40vNIuV2itH2ajXqHtr93Mk2mDnno=\",\"dataVerification\":\"c609dcf70cf85832458adffe1aec3933\",\"encryptedData\":\"50830ac2124673c1abf81fc49c845bd5c55e9e4d1b2d03cd5f7b5445b79a95d763c60072c76649bec3effe329c02bc8c0a6ef3b43603bcfe31fd83dea03352a019cd2ab261c89b883168484f512c03f3fd586e2d487f2b612ed74ffd7d00ccc933739947ca46579f6187e4e23417a7b4f5b09faeb3045aa995fc177d9cc854ba6c1f0f345ad92320e1ed2bbdabc285b86f92b1e705e70bf2d3472b375a0bff031b385a1d2365865b0723d1fd0ecafd45ef01cb1cbf70613d83aa09d5a8c381d2099f5badee8c39e757159f86d6162e1f4bda68723eabb70526c2c0671df7463b281c43bca1b1a4f47b8b59ed666e76353eb4bb5e0be1223c150c8ebd6c623bb2b2448a8c818a76da9fbf1bcc5c3ec45545439f9d4d508fd72b2b127a478cf42b81300fae885c06a0459006bf6fe95db21fab2d7ba9a9a5d635df5eae7ec96248e067dd9ee3fb86b6c93f85a4eb91a290474495cd82b345aa977427946ae6f4034c14fc9b62252657fc03aae9d13d58380affce3c3138690391f1b895da3413d764258aeb26a94ffacec8ab511693462c2bc039a6674b18f7a1bf82abfaf9ebbfd40b2ed77fc7ea95db5ef34c24ee93fc5107cfa13de5ff674f259df1817276ab05f1716c276bd517719a164ab0c4490250f5bd10b6fe1e8b2212fc91a99bc1c42fd6273ef3a68f9c7fc900dc0b2792c2810d361aa054db691ac4c6b578b146f31b9413d43b3af8b8b54ff606b500891e0cbac7d4c4fed8398ccf63ce952e1babe6dbb5deb469ad5f791f2f8df175c6bcfb2c2659441b1e3f4752ef3e727b80587b8a354abe6230263bf4f6e4460154342737ead1f7520f18570ecc633575f7c9d5c23f1c1fe578b5a495398bd14b641d76df38a36f6c6db025258cf02e59e04fa931c00a077bf91aa74ec3d2c03a5b83ded3ff73942699006b36390bed0372683e49cc06a5e906350dcc9ea96f42be381be814c3b9035b8385cdc6f1195b124bfbe42d05406dc7b5d76e096d938e31b5255532271fbc1786459c9081cc068c2f62ffc1a901686b55cd1e712e4bdcfe2a83c324366f8ea734c15332365a9f738746252472e44995d75c2114fbf804bf0769bda4310df5ee95cc94ccd965661cb446af66e048db112bad54dccdc650fa723761baa9449ee6af9196ef936f209310117b4b74aaf955bc1d279d00fe74e3ef9aa96023b714a710cf7e820437106eb10f0d17a4ad7fd100241c56d387e4c4caefbd9d4b438ba0b5799bec54da643f91a65c8fcc0c7dde39e7eca708e237b92a99133c48c9e2a0aaa616acfc0d7336abec25314628ae778e84b35a4319ad6f2ef87f271fd60eba53811ea02a4d5e023216e1dee04fc8960a2bfcaba873ba204cdc675f66f8230818f84e9d7e893867088469ec90e54b96fa78cde6a51e2a2ab4611dfbf4aa8f8c802547a5f24fbc2912786cfb045ef821aa277797211012c28fd836921dba83e1829325bbdf17ad0302e16455b4defbe5a5fadbdc3677505f1d4901531e1db7b13981f31556d743ad3d48eaf2c000be18d5b036837f979240fa3afee74790e82f01dcbd434ff129ecbfed3a0dabaa2a615bac9487a1197323476556eb05469ad8bf75ba95e82a527b93115b360a5920cc23c1f5cf885022dd65e1bd430ffa3d1baf6592b3d6a226c53161a11be8133d3f254ac845e69ed02dd3758cc9adccf42985d8695f8942e08d08d0b27ee49b4bacd4954fe6804e202318f9143feaec7569c7a0759d0d0ee7b537f95b21f4c8ba9743c12da95802ab2600bdecd7bb3c676207e624a35711287afaeeec6ca2be07eebbc4bf1a56c3615ad6830f3e7dd28ed88a6f9ce8b80727316f959b5f09d9a7545ce2609309e71662910fa702b59f8fc07b55c24a254a1e3237dbd054569832111658f3e747aaa619124e2c2467e241d30c1e756a1338a89bad3ce6b8c7fccbd656b1cfbd1cec8bb46e05a5f5f8d87c1f43058389bc64f1f4cbb3fefe5b427892a4064ed83855cdab9f645810170bdee8d8d0e2c5f1cea3732d4699071803a62f3bb056cdd019ac74ce899cc653b76765c0bafee7cfc17521cc3162e01efe25497fe04af1f91fe7033b66f34b08a9451149e4be0ab5b6ce0e2b236626eec93b1e645515fd98b781dceef19b299c692def81095d3114e091c0fb4d6f37d83bb47c1282efd0361716aaebf8b837cc8a17b7ade3305cedcc7736062ac8b4619eb7ee48d6ee954ae977ef4f393ceefe50117874556c30f892f522f0bdb94fa3faceef691579397c1666d21c3264e58eded67f95f6f5b17bf8737ef73d4fd6f66168a148be89368d262807d0817fb67c9580b8d03ea8009951754722?v=8&pv=1\",\"templateUrl\":\"https://file-link.pinduoduo.com/yto_one\"},\"updateBy\":0,\"tenantId\":34,\"waybillCode\":\"YT8910742640842\",\"id\":989598,\"partnerId\":794928,\"mark\":[],\"status\":\"USED\"}]},\"success\":true},\"_req_id\":\"W4Yffp19yC\"}"
  5595. //};
  5596. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5597. //ReturnSuccess(ro_json);
  5598. //return;
  5599. bool isUseLastWayBillCode = false;
  5600. CeErpTradeCell entity = null;
  5601. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5602. if (entity != null)
  5603. {
  5604. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5605. {
  5606. isUseLastWayBillCode = true;
  5607. }
  5608. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5609. {
  5610. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5611. return;
  5612. }
  5613. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5614. {
  5615. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5616. return;
  5617. }
  5618. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5619. {
  5620. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5621. return;
  5622. }
  5623. }
  5624. string res = "";
  5625. Api_waybill_code_response_Obj fullObj = null;
  5626. string pData_str = "";
  5627. string curUseWayBillCode = "";
  5628. if (isUseLastWayBillCode == false)
  5629. {
  5630. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5631. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5632. if (res.IndexOf("failure") != -1)
  5633. {
  5634. //int idx = res.IndexOf("sub_message");
  5635. //int idx2 = res.IndexOf("flag");
  5636. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5637. string errMsgNeed = commonHelper.KeepChinese(res);
  5638. var res_objd = new
  5639. {
  5640. restype = 0,
  5641. data = "获取面单失败" + errMsgNeed
  5642. };
  5643. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5644. returnSuccess(ro_jsond);
  5645. if (res.IndexOf("停发") != -1)
  5646. {
  5647. entity.UnusualCon = "物流停发";
  5648. entity.Update();
  5649. }
  5650. //returnErrorMsg("获取面单失败,"+emsg);
  5651. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5652. return;
  5653. }
  5654. else if (res.IndexOf("errorMsg") != -1)
  5655. {
  5656. //int idx = res.IndexOf("errorMsg");
  5657. //int idx2 = res.IndexOf("}]}");
  5658. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5659. string errMsgNeed = commonHelper.KeepChinese(res);
  5660. var res_objf = new
  5661. {
  5662. restype = 0,
  5663. data = "获取面单失败2" + errMsgNeed
  5664. };
  5665. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5666. if (res.IndexOf("停发") != -1)
  5667. {
  5668. entity.UnusualCon = "物流停发";
  5669. entity.Update();
  5670. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5671. if (trade != null)
  5672. {
  5673. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5674. }
  5675. }
  5676. returnSuccess(ro_jsonf);
  5677. //returnErrorMsg("获取面单失败," + emsg);
  5678. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5679. return;
  5680. }
  5681. try
  5682. {
  5683. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5684. //res = res.Replace(" ", "");
  5685. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5686. }
  5687. catch (Exception ex)
  5688. {
  5689. XLog.SaveLog(0, "生成fullObj" + res);
  5690. var res_objf = new
  5691. {
  5692. restype = 0,
  5693. data = "生成fullObj发生错误" + ex.Message
  5694. };
  5695. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5696. returnSuccess(ro_jsonf);
  5697. return;
  5698. }
  5699. if (fullObj.response.data.content.Count > 0)
  5700. {
  5701. ContentItem codeObj = fullObj.response.data.content[0];
  5702. if (cpCode.IndexOf("SFFQ-") != -1)
  5703. {
  5704. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5705. }
  5706. else
  5707. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5708. curUseWayBillCode = codeObj.waybillCode;
  5709. }
  5710. else
  5711. {
  5712. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5713. var res_objf = new
  5714. {
  5715. restype = 0,
  5716. data = "生成fullObj找不到快递单号waybillCode"
  5717. };
  5718. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5719. returnSuccess(ro_jsonf);
  5720. return;
  5721. }
  5722. }
  5723. else
  5724. {
  5725. //使用上次打印的快递单号
  5726. if (cpCode == "SFFQ-LY")
  5727. {
  5728. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5729. }
  5730. else
  5731. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5732. curUseWayBillCode = entity.LastBillWaybillCode;
  5733. }
  5734. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5735. {
  5736. var res_obje = new
  5737. {
  5738. restype = 0,
  5739. data = "获取加密打印数据失败"
  5740. };
  5741. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5742. returnSuccess(ro_jsone);
  5743. entity.LastBillCpCode = cpCode;
  5744. entity.LastBillWaybillCode = curUseWayBillCode;
  5745. entity.Update();
  5746. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5747. //returnErrorMsg("获取加密打印数据失败");
  5748. return;
  5749. }
  5750. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5751. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5752. string btnType = "";
  5753. string errorMsg = "";
  5754. if (entity != null)
  5755. {
  5756. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5757. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5758. //cpcode是 YTO-CAINIAO
  5759. //string comCode = cpCode.Split('-')[0].ToString();
  5760. string apires = "";
  5761. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5762. //isTogether=2是新的合包弹窗
  5763. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5764. {
  5765. if (ctid.IndexOf("N") != -1)
  5766. {
  5767. apires = "发货成功";
  5768. }
  5769. else
  5770. {
  5771. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode, entity.ctid);
  5772. }
  5773. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5774. //打单后发货
  5775. StringBuilder sql = new StringBuilder();
  5776. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5777. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5778. {
  5779. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5780. }
  5781. else
  5782. {
  5783. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5784. }
  5785. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5786. foreach (DataRow row in dt.Rows)
  5787. {
  5788. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5789. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5790. {
  5791. try
  5792. {
  5793. btnType = "待发货";
  5794. entity.OutSid = curUseWayBillCode;
  5795. entity.OrderState = 7;
  5796. entity.IsUrgency = false;
  5797. entity.LastBillCpCode = "";
  5798. entity.LastBillWaybillCode = "";
  5799. entity.FinishDeliveryTime = DateTime.Now;
  5800. entity.IsReturn = 0;
  5801. entity.MemoOpt = 0;
  5802. entity.UpdateTime = DateTime.Now;
  5803. entity.Update();
  5804. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5805. //还要插入快递信息到 快递信息表
  5806. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5807. exinfo.tid = entity.ctid;
  5808. exinfo.out_sid = curUseWayBillCode;
  5809. exinfo.company_code = cpCode;
  5810. exinfo.company_name = cpName;
  5811. exinfo.supplierUserName = supplierName;
  5812. exinfo.deliveryType = "发货成功";
  5813. exinfo.print_time = DateTime.Now;
  5814. exinfo.printUser = CurrentUser.UserName;
  5815. exinfo.postData = pData_str;
  5816. exinfo.Create();
  5817. commonHelper.UpdateRelationOrder(entity.ctid);
  5818. CeErpSukuraData.createInfo(ctid, 4);
  5819. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5820. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  5821. {
  5822. commonHelper.sendCytExpress(exinfo);
  5823. }
  5824. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5825. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5826. }
  5827. catch (Exception ex)
  5828. {
  5829. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5830. }
  5831. }
  5832. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5833. {
  5834. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5835. if (entity.OrderState == 6)
  5836. {
  5837. entity.OrderState = 7;
  5838. }
  5839. entity.UpdateTime = DateTime.Now;
  5840. entity.FinishDeliveryTime = DateTime.Now;
  5841. btnType = "已发货";
  5842. entity.Update();
  5843. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5844. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5845. exinfo.tid = entity.ctid;
  5846. exinfo.out_sid = curUseWayBillCode;
  5847. exinfo.company_code = cpCode;
  5848. exinfo.company_name = cpName;
  5849. exinfo.supplierUserName = supplierName;
  5850. exinfo.deliveryType = "发货成功";
  5851. exinfo.print_time = DateTime.Now;
  5852. exinfo.printUser = CurrentUser.UserName;
  5853. exinfo.postData = pData_str;
  5854. exinfo.Create();
  5855. commonHelper.UpdateRelationOrder(entity.ctid);
  5856. CeErpSukuraData.createInfo(entity.ctid, 4);
  5857. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  5858. {
  5859. commonHelper.sendCytExpress(exinfo);
  5860. }
  5861. //不处理
  5862. }
  5863. else
  5864. {
  5865. entity.UpdateTime = DateTime.Now;
  5866. entity.LastBillCpCode = cpCode;
  5867. entity.LastBillWaybillCode = curUseWayBillCode;
  5868. entity.Update();
  5869. string errmsg = commonHelper.KeepChinese(apires);
  5870. var res_objz = new
  5871. {
  5872. restype = 0,
  5873. data = "打单后发货失败"
  5874. };
  5875. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5876. returnSuccess(ro_jsonz);
  5877. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5878. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5879. return;
  5880. }
  5881. }
  5882. }
  5883. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5884. {
  5885. string ctids = GetPostString("ctids");
  5886. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5887. List<string> list = new List<string>();
  5888. List<string> send_list = new List<string>();
  5889. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5890. CeErpTrade ceErpTrade = new CeErpTrade();
  5891. //可合包的合并一起发货
  5892. if (dt == null && string.IsNullOrEmpty(ctids))
  5893. {
  5894. var res_objz = new
  5895. {
  5896. restype = 0,
  5897. data = "打单后发货失败"
  5898. };
  5899. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5900. returnSuccess(ro_jsonz);
  5901. return;
  5902. }
  5903. if (!string.IsNullOrEmpty(ctids))
  5904. {
  5905. StringBuilder sql = new StringBuilder();
  5906. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5907. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5908. }
  5909. foreach (DataRow row in dt.Rows)
  5910. {
  5911. list.Add("'" + row["ctid"] + "'");
  5912. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5913. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5914. if (ctid.IndexOf("N") != -1)
  5915. {
  5916. apires = "发货成功";
  5917. }
  5918. else
  5919. {
  5920. if (!send_list.Contains(ceErpTrade.tid))
  5921. {
  5922. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode, ctid);
  5923. }
  5924. else
  5925. {
  5926. apires = "发货成功";
  5927. }
  5928. }
  5929. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5930. {
  5931. send_list.Add(ceErpTrade.tid);
  5932. try
  5933. {
  5934. btnType = "待发货";
  5935. ceErpTradeCell.OutSid = curUseWayBillCode;
  5936. ceErpTradeCell.OrderState = 7;
  5937. ceErpTradeCell.IsUrgency = false;
  5938. ceErpTradeCell.LastBillCpCode = "";
  5939. ceErpTradeCell.LastBillWaybillCode = "";
  5940. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5941. ceErpTradeCell.IsReturn = 0;
  5942. ceErpTradeCell.MemoOpt = 0;
  5943. ceErpTradeCell.UpdateTime = DateTime.Now;
  5944. ceErpTradeCell.Update();
  5945. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5946. //还要插入快递信息到 快递信息表
  5947. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5948. exinfo.tid = ceErpTradeCell.ctid;
  5949. exinfo.out_sid = curUseWayBillCode;
  5950. exinfo.company_code = cpCode;
  5951. exinfo.company_name = cpName;
  5952. exinfo.supplierUserName = supplierName;
  5953. exinfo.deliveryType = "发货成功";
  5954. exinfo.print_time = DateTime.Now;
  5955. exinfo.printUser = CurrentUser.UserName;
  5956. exinfo.postData = pData_str;
  5957. exinfo.Create();
  5958. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5959. CeErpSukuraData.createInfo(ctid, 4);
  5960. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5961. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80 || entity.SupplierId == 126)
  5962. {
  5963. commonHelper.sendCytExpress(exinfo);
  5964. }
  5965. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5966. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5967. }
  5968. catch (Exception ex)
  5969. {
  5970. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5971. }
  5972. }
  5973. else
  5974. {
  5975. ceErpTradeCell.UpdateTime = DateTime.Now;
  5976. ceErpTradeCell.LastBillCpCode = cpCode;
  5977. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5978. ceErpTradeCell.Update();
  5979. string errmsg = commonHelper.KeepChinese(apires);
  5980. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5981. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5982. }
  5983. }
  5984. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5985. }
  5986. }
  5987. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5988. var res_obj = new
  5989. {
  5990. restype = 1,
  5991. data = pData_str,
  5992. errorMsg
  5993. };
  5994. string ro_json = JsonConvert.SerializeObject(res_obj);
  5995. ReturnSuccess(ro_json);
  5996. return;
  5997. }
  5998. }
  5999. private string GetUTF8String(byte[] vs)
  6000. {
  6001. throw new NotImplementedException();
  6002. }
  6003. public void set_erp_printwaybill_cn()
  6004. {
  6005. if (UrlPostParmsCheck("ctid"))
  6006. {
  6007. string ctid = GetPostString("ctid");
  6008. string cpCode = GetPostString("cpcode");
  6009. string cpName = GetPostString("cpname");
  6010. string tempUrl = GetPostString("tempurl");
  6011. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  6012. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  6013. //string res = taobaoHelper.test();
  6014. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  6015. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  6016. {
  6017. int sidx = res.IndexOf("errorMsg");
  6018. int eidx = res.IndexOf("}");
  6019. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  6020. var res_objzxx = new
  6021. {
  6022. restype = 0,
  6023. data = msg
  6024. };
  6025. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  6026. returnSuccess(ro_jsonzxx);
  6027. //returnErrorMsg(msg);
  6028. return;
  6029. }
  6030. int idx = res.IndexOf("waybillCode");
  6031. int idx2 = res.IndexOf("printData");
  6032. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  6033. string eid = GetPostString("ctid");
  6034. CeErpTradeCell entity = null;
  6035. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6036. if (entity != null)
  6037. {
  6038. string osid = entity.OutSid;
  6039. entity.OutSid = osid + "," + outsid;
  6040. entity.FinishDeliveryTime = DateTime.Now;
  6041. entity.OrderState = 7;
  6042. entity.UpdateTime = DateTime.Now;
  6043. entity.IsReturn = 0;
  6044. entity.Update();
  6045. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  6046. exinfo.tid = entity.ctid;
  6047. exinfo.out_sid = outsid;
  6048. exinfo.company_code = cpCode;
  6049. exinfo.company_name = cpName;
  6050. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  6051. exinfo.deliveryType = "发货成功";
  6052. exinfo.print_time = DateTime.Now;
  6053. exinfo.printUser = CurrentUser.UserName;
  6054. exinfo.Create();
  6055. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  6056. {
  6057. commonHelper.sendCytExpress(exinfo);
  6058. }
  6059. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  6060. }
  6061. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  6062. var res_objz = new
  6063. {
  6064. restype = 1,
  6065. data = res
  6066. };
  6067. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  6068. returnSuccess(ro_jsonz);
  6069. //ReturnSuccess(res);
  6070. }
  6071. }
  6072. ////打单,打印面单 获取面单号
  6073. //public void set_erp_printwaybill()
  6074. //{
  6075. // if (UrlPostParmsCheck("ctid"))
  6076. // {
  6077. // string ctid = GetPostString("ctid");
  6078. // string cpCode = GetPostString("cpcode");
  6079. // string tempUrl = GetPostString("tempurl");
  6080. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  6081. // //string res = taobaoHelper.test();
  6082. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  6083. // if (res.IndexOf("error_response") != -1)
  6084. // {
  6085. // int sidx = res.IndexOf("sub_msg");
  6086. // int eidx = res.IndexOf("request_id");
  6087. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  6088. // returnErrorMsg(msg);
  6089. // return;
  6090. // }
  6091. // int idx = res.IndexOf("waybill_code");
  6092. // int idx2 = res.IndexOf("}]}");
  6093. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  6094. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  6095. // ReturnSuccess(res);
  6096. // }
  6097. //}
  6098. public void cancel_erp_aftersale()
  6099. {
  6100. if (UrlPostParmsCheck("ctid"))
  6101. {
  6102. string eid = GetPostString("ctid");
  6103. CeErpTradeCell entity = null;
  6104. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6105. if (entity != null)
  6106. {
  6107. //有过处理的售后,取消也不能删除 售 字,保留
  6108. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  6109. {
  6110. entity.AfterSaleState = 4;
  6111. }
  6112. else
  6113. entity.AfterSaleState = 0;
  6114. entity.UpdateTime = DateTime.Now;
  6115. entity.Update();
  6116. returnSuccessMsg("操作成功!");
  6117. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  6118. return;
  6119. }
  6120. returnErrorMsg("找不到订单记录");
  6121. }
  6122. }
  6123. public void get_erp_aftersalelist()
  6124. {
  6125. DataStruct dStruct = GetPostStruct();
  6126. List<string> lw = new List<string>();
  6127. int st = GetInt("st");
  6128. string tid = GetPostString("ctid");
  6129. if (st == 3)
  6130. {
  6131. if (tid.Length > 0)
  6132. {
  6133. string select_tid = getTidByCtid(tid);
  6134. lw.Add(string.Format("tid='{0}'", select_tid));
  6135. }
  6136. }
  6137. else
  6138. {
  6139. if (tid.Length > 0)
  6140. {
  6141. string select_tid = getTidByCtid(tid);
  6142. lw.Add(string.Format("tid='{0}'", select_tid));
  6143. }
  6144. }
  6145. string shopname = GetPostString("shopname");
  6146. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6147. string buyernick = GetPostString("buyer_nick");
  6148. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  6149. string sellermemo = GetPostString("seller_memo");
  6150. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6151. string orderState = GetPostString("orderState");
  6152. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  6153. string afterState = GetPostString("afterstate");
  6154. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6155. string date1 = GetPostString("date1");
  6156. string date2 = GetPostString("date2");
  6157. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6158. if (dw.Length > 0) lw.Add(dw);
  6159. string price1 = GetPostString("price1");
  6160. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6161. string price2 = GetPostString("price2");
  6162. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6163. //lw.Add(string.Format("IsRefund!={0}", 1));
  6164. string reason = GetPostString("reason");
  6165. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6166. string method = GetPostString("method");
  6167. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6168. string handler = GetPostString("handler");
  6169. if (handler.Length > 0)
  6170. {
  6171. lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6172. }
  6173. string handledate1 = GetPostString("handledate1");
  6174. string handledate2 = GetPostString("handledate2");
  6175. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6176. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6177. string finish1 = GetPostString("finishdate1");
  6178. string finish2 = GetPostString("finishdate2");
  6179. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6180. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6181. string afterdate1 = GetPostString("afterdate1");
  6182. string afterdate2 = GetPostString("afterdate2");
  6183. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6184. if (afterDate.Length > 0) lw.Add(afterDate);
  6185. string supplier = GetPostString("supplier");
  6186. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6187. string responsible = GetPostString("responsibleman");
  6188. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6189. string customer = GetPostString("customer");
  6190. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6191. string design = GetPostString("design");
  6192. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6193. string afterMemoType = GetPostString("aftermemotype");
  6194. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6195. string posCode = CurrentUser.UserPost.Post.Code;
  6196. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6197. //{
  6198. // string vstate = GetPostString("vstate");
  6199. // if (vstate.Length > 0)
  6200. // {
  6201. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6202. // }
  6203. // if (posCode == "Supplier")
  6204. // {
  6205. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6206. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6207. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6208. // }
  6209. // else
  6210. // {
  6211. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6212. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6213. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6214. // {
  6215. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6216. // }
  6217. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6218. // {
  6219. // int orgid = CurrentUser.UserPost.OrgID;
  6220. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6221. // }
  6222. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6223. // {
  6224. // string shopid = CurrentUser.User.pemShop;
  6225. // lw.Add(string.Format("shopId in ({0})", shopid));
  6226. // }
  6227. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6228. // //{
  6229. // // int org_id = CurrentUser.UserPost.OrgID;
  6230. // // lw.Add(string.Format("OrgID={0}", org_id));
  6231. // //}
  6232. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6233. // }
  6234. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6235. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6236. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6237. //}
  6238. if (st == 5)
  6239. {
  6240. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6241. {
  6242. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6243. {
  6244. string shopid = CurrentUser.User.pemShop;
  6245. lw.Add(string.Format("shopId in ({0})", shopid));
  6246. }
  6247. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6248. {
  6249. int mrOrgid = CurrentUser.UserPost.OrgID;
  6250. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6251. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6252. }
  6253. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6254. //{
  6255. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6256. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6257. //}
  6258. else
  6259. {
  6260. string userIdStr = "";
  6261. if (posCode == "CustomerService")
  6262. {
  6263. userIdStr = CurrentUser.UserID + "_k";
  6264. }
  6265. else if (posCode == "Designer" || posCode == "wxDesigner")
  6266. {
  6267. userIdStr = CurrentUser.UserID + "_s";
  6268. }
  6269. else if (posCode == "Place")
  6270. {
  6271. userIdStr = CurrentUser.UserID + "_x";
  6272. }
  6273. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6274. }
  6275. }
  6276. string placedate1 = GetPostString("placedate1");
  6277. string placedate2 = GetPostString("placedate2");
  6278. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6279. if (dwplace.Length > 0) lw.Add(dwplace);
  6280. string supState = GetPostString("supState");
  6281. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6282. string searchType = GetPostString("searchType");
  6283. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6284. {
  6285. lw.Add(string.Format("BackNum>1"));
  6286. }
  6287. lw.Add(string.Format("AfterSaleState>0"));
  6288. if (ex_psize > 0)
  6289. {
  6290. if (CurrentUser.UserPost.Post.Code == "Finance")
  6291. dStruct.Order = "pay_time desc";
  6292. else
  6293. dStruct.Order = "HandleTime desc";
  6294. }
  6295. else
  6296. dStruct.Order = "HandleTime desc";
  6297. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6298. DataTable dt = WebCache.GetData("view_test", dStruct);
  6299. writeGridDataTableJson(dStruct.TotalCount, dt);
  6300. }
  6301. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6302. //{
  6303. // lw.Add(string.Format("AfterSaleState=4"));
  6304. // string code = CurrentUser.UserPost.Post.Code;
  6305. // if (code == "CustomerService")
  6306. // {
  6307. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6308. // }
  6309. // else if (code == "Designer" || code == "DesignerMr")
  6310. // {
  6311. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6312. // }
  6313. // else if (code == "Place" || code == "PlaceMr")
  6314. // {
  6315. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6316. // }
  6317. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6318. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6319. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6320. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6321. //}
  6322. //else //处理中的售后,待处理和处理中合并
  6323. //{
  6324. // if (afterState.Length <= 0)
  6325. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6326. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6327. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6328. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6329. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6330. //}
  6331. }
  6332. public void get_erp_disagreeftersalelist()
  6333. {
  6334. DataStruct dStruct = GetPostStruct();
  6335. List<string> lw = new List<string>();
  6336. int st = 2;
  6337. string tid = GetPostString("ctid");
  6338. if (tid.Length > 0)
  6339. {
  6340. string select_tid = getTidByCtid(tid);
  6341. lw.Add(string.Format("tid='{0}'", select_tid));
  6342. }
  6343. string shopname = GetPostString("shopname");
  6344. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6345. string buyernick = GetPostString("buyer_nick");
  6346. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6347. string sellermemo = GetPostString("seller_memo");
  6348. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6349. string orderState = GetPostString("orderState");
  6350. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6351. string afterState = GetPostString("afterstate");
  6352. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6353. string date1 = GetPostString("date1");
  6354. string date2 = GetPostString("date2");
  6355. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6356. if (dw.Length > 0) lw.Add(dw);
  6357. string price1 = GetPostString("price1");
  6358. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6359. string price2 = GetPostString("price2");
  6360. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6361. //lw.Add(string.Format("IsRefund!={0}", 1));
  6362. string reason = GetPostString("reason");
  6363. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6364. string method = GetPostString("method");
  6365. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6366. string handler = GetPostString("handler");
  6367. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6368. string handledate1 = GetPostString("handledate1");
  6369. string handledate2 = GetPostString("handledate2");
  6370. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6371. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6372. string afterdate1 = GetPostString("afterdate1");
  6373. string afterdate2 = GetPostString("afterdate2");
  6374. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6375. if (afterDate.Length > 0) lw.Add(afterDate);
  6376. string backdate1 = GetPostString("backdate1");
  6377. string backdate2 = GetPostString("backdate2");
  6378. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6379. if (backDate.Length > 0) lw.Add(backDate);
  6380. string supplier = GetPostString("supplier");
  6381. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6382. string responsible = GetPostString("responsibleman");
  6383. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6384. string customer = GetPostString("customer");
  6385. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6386. string design = GetPostString("design");
  6387. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6388. string afterSaleMemo = GetPostString("afterSaleMemo");
  6389. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6390. string afterMemoType = GetPostString("aftermemotype");
  6391. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6392. string aftersakereason = GetPostString("aftersakereason");
  6393. if (aftersakereason.Length > 0)
  6394. {
  6395. if (aftersakereason == "1")
  6396. {
  6397. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6398. }
  6399. if (aftersakereason == "2")
  6400. {
  6401. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6402. }
  6403. }
  6404. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6405. string poscode = CurrentUser.UserPost.Post.Code;
  6406. if (poscode != "SysAdmin")
  6407. {
  6408. string shopid = CurrentUser.User.pemShop;
  6409. lw.Add(string.Format("shopId in ({0})", shopid));
  6410. }
  6411. string searchType = GetPostString("searchType");
  6412. if (searchType == "wait")
  6413. {
  6414. lw.Add(string.Format("HandleTime is null"));
  6415. }
  6416. if (searchType == "handling")
  6417. {
  6418. lw.Add(string.Format("HandleTime is not null "));
  6419. }
  6420. if (searchType == "back" || searchType == "puBack")
  6421. {
  6422. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6423. }
  6424. if (searchType == "reBack")
  6425. {
  6426. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6427. }
  6428. if (searchType == "moreBack")
  6429. {
  6430. lw.Add(string.Format("backNum > 1"));
  6431. }
  6432. lw.Add(string.Format("(AfterSaleState=5)"));
  6433. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6434. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6435. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6436. writeGridDataTableJson(dStruct.TotalCount, dt);
  6437. }
  6438. public void get_erp_handlingaftersalelist()
  6439. {
  6440. DataStruct dStruct = GetPostStruct();
  6441. List<string> lw = new List<string>();
  6442. int st = 2;
  6443. string tid = GetPostString("ctid");
  6444. if (tid.Length > 0)
  6445. {
  6446. string select_tid = getTidByCtid(tid);
  6447. lw.Add(string.Format("tid='{0}'", select_tid));
  6448. }
  6449. string shopname = GetPostString("shopname");
  6450. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6451. string buyernick = GetPostString("buyer_nick");
  6452. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6453. string sellermemo = GetPostString("seller_memo");
  6454. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6455. string orderState = GetPostString("orderState");
  6456. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6457. string searchType = GetPostString("searchType");
  6458. string afterState = GetPostString("afterstate");
  6459. if (searchType != "documentary")
  6460. {
  6461. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6462. }
  6463. string date1 = GetPostString("date1");
  6464. string date2 = GetPostString("date2");
  6465. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6466. if (dw.Length > 0) lw.Add(dw);
  6467. string price1 = GetPostString("price1");
  6468. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6469. string price2 = GetPostString("price2");
  6470. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6471. //lw.Add(string.Format("IsRefund!={0}", 1));
  6472. string reason = GetPostString("reason");
  6473. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6474. string method = GetPostString("method");
  6475. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6476. string handler = GetPostString("handler");
  6477. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6478. string handledate1 = GetPostString("handledate1");
  6479. string handledate2 = GetPostString("handledate2");
  6480. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6481. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6482. string afterdate1 = GetPostString("afterdate1");
  6483. string afterdate2 = GetPostString("afterdate2");
  6484. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6485. if (afterDate.Length > 0) lw.Add(afterDate);
  6486. string supplier = GetPostString("supplier");
  6487. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6488. string responsible = GetPostString("responsibleman");
  6489. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6490. string customer = GetPostString("customer");
  6491. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6492. string design = GetPostString("design");
  6493. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6494. string afterSaleMemo = GetPostString("afterSaleMemo");
  6495. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6496. string afterMemoType = GetPostString("aftermemotype");
  6497. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6498. string afterresult = GetPostString("afterresult");
  6499. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6500. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6501. string poscode = CurrentUser.UserPost.Post.Code;
  6502. if (poscode != "SysAdmin")
  6503. {
  6504. string shopid = CurrentUser.User.pemShop;
  6505. lw.Add(string.Format("shopId in ({0})", shopid));
  6506. }
  6507. if (searchType == "wait")
  6508. {
  6509. lw.Add(string.Format("HandleTime is null"));
  6510. }
  6511. if (searchType == "documentary")
  6512. {
  6513. lw.Add(string.Format(" AfterSaleState > 2 AND HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' AND AfterSalSend = 0 "));
  6514. afterState = "2";
  6515. }
  6516. if (searchType == "handling")
  6517. {
  6518. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6519. }
  6520. if (searchType == "back" || searchType == "puBack")
  6521. {
  6522. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6523. }
  6524. if (searchType == "reBack")
  6525. {
  6526. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6527. }
  6528. if (afterState.Length <= 0)
  6529. {
  6530. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6531. }
  6532. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6533. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6534. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6535. writeGridDataTableJson(dStruct.TotalCount, dt);
  6536. }
  6537. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6538. //public void get_erp_back_handlingaftersalelist()
  6539. //{
  6540. // DataStruct dStruct = GetPostStruct();
  6541. // List<string> lw = new List<string>();
  6542. // string tid = GetPostString("ctid");
  6543. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6544. // string shopname = GetPostString("shopname");
  6545. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6546. // string buyernick = GetPostString("buyer_nick");
  6547. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6548. // string sellermemo = GetPostString("seller_memo");
  6549. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6550. // string orderState = GetPostString("orderState");
  6551. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6552. // string afterState = GetPostString("afterstate");
  6553. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6554. // string date1 = GetPostString("date1");
  6555. // string date2 = GetPostString("date2");
  6556. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6557. // if (dw.Length > 0) lw.Add(dw);
  6558. // string price1 = GetPostString("price1");
  6559. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6560. // string price2 = GetPostString("price2");
  6561. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6562. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6563. // string reason = GetPostString("reason");
  6564. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6565. // string method = GetPostString("method");
  6566. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6567. // string handler = GetPostString("handler");
  6568. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6569. // string handledate1 = GetPostString("handledate1");
  6570. // string handledate2 = GetPostString("handledate2");
  6571. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6572. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6573. // string afterdate1 = GetPostString("afterdate1");
  6574. // string afterdate2 = GetPostString("afterdate2");
  6575. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6576. // if (afterDate.Length > 0) lw.Add(afterDate);
  6577. // string supplier = GetPostString("supplier");
  6578. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6579. // string responsible = GetPostString("responsibleman");
  6580. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6581. // string customer = GetPostString("customer");
  6582. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6583. // string design = GetPostString("design");
  6584. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6585. // string afterMemoType = GetPostString("aftermemotype");
  6586. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6587. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6588. // if (afterState.Length <= 0)
  6589. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6590. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6591. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6592. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6593. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6594. //}
  6595. public void get_erp_aftersaleverifylist()
  6596. {
  6597. DataStruct dStruct = GetPostStruct();
  6598. List<string> lw = new List<string>();
  6599. string tid = GetPostString("ctid");
  6600. if (tid.Length > 0)
  6601. {
  6602. string select_tid = getTidByCtid(tid);
  6603. lw.Add(string.Format("otid='{0}'", select_tid));
  6604. }
  6605. string shopname = GetPostString("shopname");
  6606. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6607. string buyernick = GetPostString("buyer_nick");
  6608. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6609. string sellermemo = GetPostString("seller_memo");
  6610. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6611. string orderState = GetPostString("orderState");
  6612. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6613. //lw.Add(string.Format("IsRefund!={0}", 1));
  6614. string reason = GetPostString("reason");
  6615. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6616. string method = GetPostString("method");
  6617. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6618. string handler = GetPostString("handler");
  6619. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6620. string handledate1 = GetPostString("handledate1");
  6621. string handledate2 = GetPostString("handledate2");
  6622. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6623. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6624. string finish1 = GetPostString("finishdate1");
  6625. string finish2 = GetPostString("finishdate2");
  6626. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6627. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6628. string supplier = GetPostString("supplier");
  6629. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6630. string responsible = GetPostString("responsibleman");
  6631. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6632. string posCode = CurrentUser.UserPost.Post.Code;
  6633. string vstate = GetPostString("vstate");
  6634. if (vstate.Length > 0)
  6635. {
  6636. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6637. }
  6638. if (posCode == "Supplier")
  6639. {
  6640. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6641. lw.Add(string.Format("VerifyState = 0"));
  6642. lw.Add("type = 1");
  6643. lw.Add(string.Format("AfterSaleState={0}", 3));
  6644. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6645. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6646. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6647. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6648. writeGridDataTableJson(dStruct.TotalCount, dt);
  6649. }
  6650. else if (posCode == "logistics")
  6651. {
  6652. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6653. lw.Add(string.Format("VerifyState = 0"));
  6654. lw.Add("type = 2");
  6655. lw.Add(string.Format("AfterSaleState={0}", 3));
  6656. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6657. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6658. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6659. writeGridDataTableJson(dStruct.TotalCount, dt);
  6660. }
  6661. else
  6662. {
  6663. lw.Add(string.Format("(AfterSaleState = 3)"));
  6664. lw.Add("type = 0");
  6665. string reasonState = GetPostString("reasonState");
  6666. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "Summarize" || posCode == "Finance")
  6667. {
  6668. if (reasonState == "2")
  6669. {
  6670. lw.Add("VerifyState = 3");
  6671. }
  6672. else if (reasonState == "1")
  6673. {
  6674. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6675. }
  6676. else
  6677. {
  6678. lw.Add("VerifyState in (0,3)");
  6679. }
  6680. //不加条件,可以看全部
  6681. }
  6682. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMaster" || CurrentUser.UserPost.Post.Code == "CustomerMr" || CurrentUser.UserPost.Post.Code == "DesignerMr" || CurrentUser.UserPost.Post.Code == "wxDesignerMr" || CurrentUser.UserPost.Post.Code == "Designerhd" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  6683. {
  6684. int orgid = CurrentUser.UserPost.OrgID;
  6685. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6686. if (string.IsNullOrEmpty(manageOrgId))
  6687. {
  6688. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6689. }
  6690. else
  6691. {
  6692. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6693. }
  6694. if (reasonState == "1")
  6695. {
  6696. lw.Add("VerifyState = 3");
  6697. }
  6698. else if (reasonState == "2")
  6699. {
  6700. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6701. }
  6702. else
  6703. {
  6704. }
  6705. }
  6706. else
  6707. {
  6708. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6709. }
  6710. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6711. //{
  6712. // int org_id = CurrentUser.UserPost.OrgID;
  6713. // lw.Add(string.Format("OrgID={0}", org_id));
  6714. //}
  6715. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6716. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6717. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6718. writeGridDataTableJson(dStruct.TotalCount, dt);
  6719. }
  6720. }
  6721. public void get_erp_finishaftersalelist()
  6722. {
  6723. DataStruct dStruct = GetPostStruct();
  6724. List<string> lw = new List<string>();
  6725. int st = 4;
  6726. string tid = GetPostString("ctid");
  6727. if (tid.Length > 0)
  6728. {
  6729. string select_tid = getTidByCtid(tid);
  6730. lw.Add(string.Format("otid='{0}'", select_tid));
  6731. }
  6732. string shopname = GetPostString("shopname");
  6733. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6734. //lw.Add(string.Format("IsRefund!={0}", 1));
  6735. string reason = GetPostString("reason");
  6736. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6737. string method = GetPostString("method");
  6738. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6739. string buyernick = GetPostString("buyer_nick");
  6740. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6741. string handler = GetPostString("handler");
  6742. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6743. string handledate1 = GetPostString("handledate1");
  6744. string handledate2 = GetPostString("handledate2");
  6745. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6746. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6747. string finish1 = GetPostString("finishdate1");
  6748. string finish2 = GetPostString("finishdate2");
  6749. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6750. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6751. string supplier = GetPostString("supplier");
  6752. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6753. string responsible = GetPostString("responsibleman");
  6754. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6755. string vstate = GetPostString("vstate");
  6756. if (vstate.Length > 0)
  6757. {
  6758. if ("3".Equals(vstate))
  6759. {
  6760. lw.Add(string.Format("IsTem=1"));
  6761. }
  6762. else
  6763. {
  6764. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6765. }
  6766. }
  6767. lw.Add(string.Format("AfterSaleState=4"));
  6768. string code = CurrentUser.UserPost.Post.Code;
  6769. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6770. {
  6771. //不加条件,可以看全部
  6772. }
  6773. else if (code == "Supplier")
  6774. {
  6775. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6776. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6777. lw.Add("type = 1");
  6778. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6779. }
  6780. else if (code == "logistics")
  6781. {
  6782. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6783. lw.Add("type = 2");
  6784. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6785. }
  6786. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMaster" || CurrentUser.UserPost.Post.Code == "CustomerMr" || CurrentUser.UserPost.Post.Code == "DesignerMr" || CurrentUser.UserPost.Post.Code == "wxDesignerMr" || CurrentUser.UserPost.Post.Code == "Designerhd" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  6787. {
  6788. lw.Add("type = 0");
  6789. int orgid = CurrentUser.UserPost.OrgID;
  6790. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6791. if (string.IsNullOrEmpty(manageOrgIds))
  6792. {
  6793. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6794. }
  6795. else
  6796. {
  6797. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6798. }
  6799. }
  6800. else
  6801. {
  6802. lw.Add("type = 0");
  6803. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6804. }
  6805. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6806. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6807. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6808. writeGridDataTableJson(dStruct.TotalCount, dt);
  6809. }
  6810. public void handle_erp_aftersale()
  6811. {
  6812. if (UrlPostParmsCheck("ctid"))
  6813. {
  6814. string eid = GetPostString("ctid");
  6815. string responStr = GetPostString("AfterSaleResponsible");
  6816. if (responStr.Length <= 0)
  6817. {
  6818. returnErrorMsg("售后责任人不能为空");
  6819. return;
  6820. }
  6821. bool isDesign = false;
  6822. double designFree = 0.00;
  6823. int responsibleId = 0;
  6824. CeErpTradeCell entity = null;
  6825. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6826. if (entity != null)
  6827. {
  6828. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6829. string afterMethod = GetPostString("AfterSaleMethod");
  6830. if (isNeedNewOrder == 1)
  6831. {
  6832. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6833. bool ishav = true;
  6834. if (newentity == null)
  6835. {
  6836. newentity = entity.Clone() as CeErpTradeCell;
  6837. ishav = false;
  6838. newentity.ctid = "S_" + entity.ctid;
  6839. newentity.OrderState = 0;
  6840. //唯一标识
  6841. newentity.OrderSn = newentity.ctid;
  6842. string orderSn = commonHelper.generateDateTimeRandomNos();
  6843. if (orderSn != "")
  6844. {
  6845. newentity.OrderSn = orderSn;
  6846. }
  6847. }
  6848. newentity.UpdateTime = DateTime.Now;
  6849. newentity.AfterSaleState = 0;
  6850. newentity.AfterSaleMethod = afterMethod;
  6851. if (!ishav)
  6852. {
  6853. string memo_str = newentity.seller_memo;
  6854. memo_str = memo_str.Replace("(", "(");
  6855. memo_str = memo_str.Replace(")", ")");
  6856. int sIndex = memo_str.IndexOf("(");
  6857. int eIndex = memo_str.IndexOf(")");
  6858. if (sIndex == -1 || eIndex == -1)
  6859. {
  6860. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6861. return;
  6862. }
  6863. string first = memo_str.Substring(0, sIndex + 1);
  6864. string memoCtid = newentity.OrderSn;
  6865. //if (memoCtid.IndexOf("C") != -1)
  6866. //{
  6867. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6868. //if (CIdx.IndexOf("+") != -1)
  6869. //{
  6870. //CIdx = "C" + CIdx.Split('+')[1];
  6871. //}
  6872. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6873. //}
  6874. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6875. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6876. string newMemo = first + memoCtid + last;
  6877. newentity.seller_memo = newMemo;
  6878. newentity.FinishPlaceTime = null;
  6879. newentity.UnusualTag = 0;
  6880. newentity.UnusualCon = "";
  6881. newentity.UnusualTime = null;
  6882. newentity.AfterSaleMemo = "";
  6883. newentity.AfterSaleMethod = afterMethod;
  6884. newentity.AfterSalePreTime = null;
  6885. newentity.AfterSaleReason = "";
  6886. newentity.AfterSaleResponsible = "";
  6887. newentity.AfterSaleState = 0;
  6888. newentity.AfterSaleTime = null;
  6889. newentity.AfterSaleUserId = 0;
  6890. newentity.AfterSaleSupplierState = 0;
  6891. newentity.LastBillWaybillCode = "";
  6892. newentity.LastBillCpCode = "";
  6893. newentity.FinishAfterSaleTime = null;
  6894. newentity.HandleTime = null;
  6895. newentity.IsSF = 0;
  6896. newentity.IsOldCustomer = 0;
  6897. newentity.UrgencyTime = null;
  6898. newentity.ResponsibleUserId = "";
  6899. newentity.IsVerifyToSupplier = false;
  6900. newentity.payment = 0;
  6901. newentity.CheckMemo = "";
  6902. newentity.OutSid = "";
  6903. newentity.CheckOrderTime = null;
  6904. newentity.MemoOpt = 0;
  6905. newentity.IsReturn = 0;
  6906. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6907. }
  6908. newentity.isAfterSaleOrder = 1;
  6909. newentity.IsRefund = 0;
  6910. string receiveMobile = GetPostString("receiver_mobile");
  6911. if (receiveMobile.Length > 0)
  6912. {
  6913. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6914. if (trade != null)
  6915. {
  6916. trade.receiver_name = GetPostString("receiver_name");
  6917. trade.receiver_mobile = receiveMobile;
  6918. trade.receiver_state = GetPostString("receiver_state");
  6919. trade.receiver_city = GetPostString("receiver_city");
  6920. trade.receiver_district = GetPostString("receiver_district");
  6921. trade.receiver_address = GetPostString("receiver_address");
  6922. newentity.IsOffLineOrder = 1;
  6923. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6924. }
  6925. }
  6926. string st = GetPostString("ToState");
  6927. if (st.Length > 0)
  6928. {
  6929. if (newentity.OrderState <= 3)
  6930. {
  6931. newentity.WaitDesignTime = DateTime.Now;
  6932. newentity.StartDesignTime = null;
  6933. newentity.FinishDesignTime = null;
  6934. newentity.OrderState = 3;
  6935. if (st == "下单员")
  6936. {
  6937. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6938. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6939. {
  6940. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6941. }
  6942. }
  6943. else
  6944. {
  6945. newentity.WaitDesignTime = DateTime.Now;
  6946. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6947. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6948. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6949. {
  6950. DataRow user = dt1.Rows[0];
  6951. //找主管
  6952. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6953. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6954. if (dt != null && dt.Rows.Count > 0)
  6955. {
  6956. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6957. newentity.DesignUserId = designMr;
  6958. string key = "aftersale_order_" + designMr;
  6959. if (RedisHelper.HasKey(key))
  6960. {
  6961. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6962. list.Add(newentity.ctid);
  6963. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6964. }
  6965. }
  6966. //账号正常
  6967. if (user["State"].ToString() == "0")
  6968. {
  6969. newentity.DesignUserId = entity.DesignUserId;
  6970. string key = "aftersale_order_" + entity.DesignUserId;
  6971. if (RedisHelper.HasKey(key))
  6972. {
  6973. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6974. list.Add(newentity.ctid);
  6975. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6976. }
  6977. }
  6978. }
  6979. }
  6980. }
  6981. if (entity.IsXianHuo == 1)
  6982. {
  6983. newentity.OrderState = 6;
  6984. entity.FinishPlaceTime = DateTime.Now;
  6985. }
  6986. }
  6987. if (ishav)
  6988. {
  6989. newentity.Update();
  6990. }
  6991. else
  6992. {
  6993. newentity.Create();
  6994. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6995. newCellExtend.ctid = newentity.ctid;
  6996. newCellExtend.orderFrom = 20;
  6997. newCellExtend.orderType = 30;
  6998. if (st == "下单员")
  6999. {
  7000. }
  7001. else
  7002. {
  7003. newCellExtend.ReprintTime = DateTime.Now;
  7004. }
  7005. newCellExtend.Create();
  7006. }
  7007. if (st != "下单员")
  7008. {
  7009. if (entity.DispatchSort == 2)
  7010. {
  7011. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  7012. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  7013. }
  7014. }
  7015. }
  7016. //处理售后扩展
  7017. string resIdStr = GetPostString("ResponsibleUserId");
  7018. string refundFees = GetPostString("refundFrees");
  7019. int IsComplain = GetPostInt("isComplain");
  7020. int IsBad = GetPostInt("isBad");
  7021. string IsOriginal = GetPostString("isOriginal");
  7022. double diffResultPrice = GetPostDouble("diffResultPrice");
  7023. string textResult = GetPostString("textResult");
  7024. string supplierResponsible = GetPostString("supplierResponsible");
  7025. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  7026. if (ceErpTradeAfterSaleExtend == null)
  7027. {
  7028. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7029. ceErpTradeAfterSaleExtend.tid = eid;
  7030. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  7031. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  7032. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  7033. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  7034. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  7035. ceErpTradeAfterSaleExtend.TextResult = textResult;
  7036. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  7037. ceErpTradeAfterSaleExtend.Create();
  7038. }
  7039. else
  7040. {
  7041. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  7042. {
  7043. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  7044. }
  7045. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  7046. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  7047. ceErpTradeAfterSaleExtend.TextResult = textResult;
  7048. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  7049. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  7050. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  7051. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  7052. ceErpTradeAfterSaleExtend.Update();
  7053. }
  7054. int gysid = GetPostInt("ResponsibleSupId");
  7055. if (entity.AfterSaleUserId == 0)
  7056. {
  7057. entity.AfterSaleUserId = CurrentUser.UserID;
  7058. }
  7059. entity.ResponsibleUserId = resIdStr;
  7060. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  7061. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  7062. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  7063. {
  7064. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7065. int backNum = 0;
  7066. if (number != null)
  7067. {
  7068. backNum = number.BackNum;
  7069. }
  7070. char[] separator = { ',' };
  7071. string[] sArray = resIdStr.Split(separator);
  7072. string[] refundFreeList = { };
  7073. if (refundFees.Length > 0)
  7074. {
  7075. refundFreeList = refundFees.Split(separator);
  7076. }
  7077. int index = -1;
  7078. List<int> responsibleIds = new List<int>();
  7079. foreach (string i in sArray)
  7080. {
  7081. index++;
  7082. if (i.Length <= 0) continue;
  7083. char[] separator2 = { '_' };
  7084. string idstr = i.Split(separator2)[0];
  7085. string idtype = i.Split(separator2)[1];
  7086. double refudFree = 0;
  7087. if (refundFreeList.Length > 0)
  7088. {
  7089. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  7090. }
  7091. if (idtype == "s")
  7092. {
  7093. isDesign = true;
  7094. designFree = refudFree;
  7095. }
  7096. int userId = Convert.ToInt32(idstr);
  7097. int type = 0;
  7098. if (idtype == "g")
  7099. {
  7100. type = 1;
  7101. }
  7102. if (idtype == "w")
  7103. {
  7104. type = 2;
  7105. }
  7106. if (idtype == "t")
  7107. {
  7108. type = 3;
  7109. }
  7110. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  7111. if (ceErpTradeResponsible == null)
  7112. {
  7113. ceErpTradeResponsible = new CeErpTradeResponsible();
  7114. ceErpTradeResponsible.tid = eid;
  7115. ceErpTradeResponsible.UserId = userId;
  7116. ceErpTradeResponsible.createdTime = DateTime.Now;
  7117. ceErpTradeResponsible.type = type;
  7118. if (type == 1)
  7119. {
  7120. ceErpTradeResponsible.IsSup = 1;
  7121. }
  7122. if (type == 2)
  7123. {
  7124. ceErpTradeResponsible.IsFlow = 1;
  7125. }
  7126. }
  7127. int state = 0;
  7128. //已认可的不需要再次认可
  7129. if (sArray.Length > 1 && ceErpTradeResponsible.VerifyState == 1)
  7130. {
  7131. state = 1;
  7132. }
  7133. ceErpTradeResponsible.RefundFee = refudFree;
  7134. ceErpTradeResponsible.VerifyState = state;
  7135. if (userId == 2125 || idtype == "w")
  7136. {
  7137. ceErpTradeResponsible.VerifyState = 1;
  7138. }
  7139. if (idtype == "w" && userId == 101)
  7140. {
  7141. ceErpTradeResponsible.VerifyState = state;
  7142. }
  7143. if (ceErpTradeResponsible.ID > 0)
  7144. {
  7145. ceErpTradeResponsible.Update();
  7146. }
  7147. else
  7148. {
  7149. ceErpTradeResponsible.Create();
  7150. }
  7151. if (isDesign)
  7152. {
  7153. responsibleId = ceErpTradeResponsible.ID;
  7154. }
  7155. responsibleIds.Add(ceErpTradeResponsible.ID);
  7156. }
  7157. CeErpTradeResponsible.ExecuteNonQuery(string.Format("update CE_ErpTradeResponsible set VerifyState =-1 where tid='" + eid + "' and ID NOT IN (" + string.Join(",", responsibleIds) + ")"));
  7158. CeErpTradeResponsible.NumByTid(backNum, eid);
  7159. }
  7160. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  7161. if (ceErpTradeCellExtend != null)
  7162. {
  7163. ceErpTradeCellExtend.returnVisit = 0;
  7164. ceErpTradeCellExtend.Update();
  7165. }
  7166. if (entity.HandleTime != null)
  7167. {
  7168. if (entity.AfterSaleState == 1)
  7169. {
  7170. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  7171. }
  7172. else
  7173. {
  7174. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  7175. }
  7176. }
  7177. else
  7178. {
  7179. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  7180. entity.HandleTime = DateTime.Now;
  7181. }
  7182. bool isCompale = false;
  7183. if (entity.AfterSaleState == 5)
  7184. {
  7185. isCompale = true;
  7186. entity.AfterSaleState = 3;
  7187. }
  7188. entity.AfterSaleSupplierState = 0;
  7189. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7190. {
  7191. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7192. }
  7193. string sImgs = GetPostString("img");
  7194. entity.AfterSaleSupplierImg = sImgs;
  7195. entity.supRefundType = GetPostString("supRefundType");
  7196. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7197. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7198. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7199. entity.AfterSaleMemoType = GetPostString("MemoType");
  7200. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7201. {
  7202. //entity.AfterSaleSupplierState = 2;
  7203. }
  7204. string df = GetPostString("DeductFee");
  7205. if (df == "")
  7206. {
  7207. df = "0";
  7208. }
  7209. string rf = GetPostString("RefundFee");
  7210. if (rf == "")
  7211. {
  7212. rf = "0";
  7213. }
  7214. string pm = GetPostString("AfterSalePayment");
  7215. if (pm == "")
  7216. {
  7217. pm = "0";
  7218. }
  7219. entity.AfterSalePayment = Convert.ToDouble(pm);
  7220. entity.DeductFee = Convert.ToDouble(df);
  7221. entity.RefundFee = Convert.ToDouble(rf);
  7222. entity.UpdateTime = DateTime.Now;
  7223. entity.Update();
  7224. string toState = GetPostString("ToState");
  7225. string original = GetPostString("isOriginal");
  7226. ApiVo apiVo = new ApiVo();
  7227. apiVo.orderNumber = entity.ctid;
  7228. apiVo.actionName = "afterDesign";
  7229. apiVo.orderRemarks = entity.AfterSaleMethod;
  7230. apiVo.reasonRemarks = entity.AfterSaleReason;
  7231. apiVo.isDesign = isDesign;
  7232. apiVo.designFree = designFree;
  7233. apiVo.responsibleId = responsibleId;
  7234. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7235. if (toState == "设计师")
  7236. {
  7237. apiVo.isOriginal = Convert.ToBoolean(original);
  7238. }
  7239. designHelper.API_WorkCore(apiVo);//afterDesign
  7240. CeErpMethod methodSql = new CeErpMethod();
  7241. methodSql.con = entity.AfterSaleMethod;
  7242. methodSql.addTime = DateTime.Now;
  7243. methodSql.Create();
  7244. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7245. CeErpMethod.ExecuteNonQuery(delsql);
  7246. if (isCompale)
  7247. {
  7248. aftersale_data_change(entity.ctid);
  7249. }
  7250. returnSuccessMsg("操作成功!");
  7251. return;
  7252. }
  7253. returnErrorMsg("找不到订单记录");
  7254. }
  7255. }
  7256. public void ins_erp_toresponsible()
  7257. {
  7258. if (UrlPostParmsCheck("ctid"))
  7259. {
  7260. string eid = GetPostString("ctid");
  7261. CeErpTradeCell entity = null;
  7262. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7263. if (entity != null)
  7264. {
  7265. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7266. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7267. {
  7268. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7269. return;
  7270. }
  7271. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7272. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7273. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7274. if (entity.AfterSalePreTime == null)
  7275. {
  7276. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7277. {
  7278. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7279. }
  7280. }
  7281. entity.AfterSalePreTime = DateTime.Now;
  7282. //预完成给售后主管审核客户问题直接完成
  7283. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7284. {
  7285. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7286. {
  7287. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7288. }
  7289. }
  7290. ceErpTradeAfterSaleExtend.DisagreeTime = null;
  7291. ceErpTradeAfterSaleExtend.Update();
  7292. entity.AfterSaleUserId = CurrentUser.UserID;
  7293. entity.AfterSaleState = 2;
  7294. entity.UpdateTime = DateTime.Now;
  7295. entity.Update();
  7296. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7297. aftersale_data_change(entity.ctid);
  7298. returnSuccessMsg("操作成功!");
  7299. return;
  7300. }
  7301. returnErrorMsg("找不到订单记录");
  7302. }
  7303. }
  7304. public void cancel_erp_aftersaleanddelnew()
  7305. {
  7306. if (UrlPostParmsCheck("ctid"))
  7307. {
  7308. string eid = GetPostString("ctid");
  7309. CeErpTradeCell entity = null;
  7310. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7311. if (entity != null)
  7312. {
  7313. entity.AfterSaleState = 0;
  7314. entity.AfterSaleReason = "";
  7315. entity.AfterSaleMethod = "";
  7316. entity.AfterSaleMemo = "";
  7317. entity.AfterSaleResponsible = "";
  7318. entity.ResponsibleUserId = "";
  7319. entity.DeductFee = 0;
  7320. entity.RefundFee = 0;
  7321. entity.IsArbitrate = 0;
  7322. CeErpTradeResponsible.DelByTid(eid, -1);
  7323. entity.Update();
  7324. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7325. if (after != null)
  7326. {
  7327. if (after.OrderState < 5)
  7328. CeErpTradeCell.DelByCtid("S_" + eid);
  7329. }
  7330. returnSuccessMsg("操作成功!");
  7331. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7332. return;
  7333. }
  7334. returnErrorMsg("找不到订单记录");
  7335. }
  7336. }
  7337. public void get_erp_aftersale_pregather()
  7338. {
  7339. List<string> lw = new List<string>();
  7340. int st = GetInt("st");
  7341. string tid = GetPostString("ctid");
  7342. if (tid.Length > 0)
  7343. {
  7344. string select_tid = getTidByCtid(tid);
  7345. lw.Add(string.Format("tid='{0}'", select_tid));
  7346. }
  7347. string shopname = GetPostString("shopname");
  7348. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7349. string buyernick = GetPostString("buyer_nick");
  7350. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7351. string sellermemo = GetPostString("seller_memo");
  7352. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7353. string orderState = GetPostString("orderState");
  7354. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7355. string reason = GetPostString("reason");
  7356. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7357. string method = GetPostString("method");
  7358. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7359. string handler = GetPostString("handler");
  7360. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7361. string handledate1 = GetPostString("handledate1");
  7362. string handledate2 = GetPostString("handledate2");
  7363. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7364. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7365. string supplier = GetPostString("supplier");
  7366. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7367. string responsible = GetPostString("responsibleman");
  7368. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7369. string customer = GetPostString("customer");
  7370. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7371. string design = GetPostString("design");
  7372. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7373. string afterMemoType = GetPostString("aftermemotype");
  7374. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7375. string afterSaleMemo = GetPostString("afterSaleMemo");
  7376. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7377. string afterresult = GetPostString("afterresult");
  7378. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7379. string poscode = CurrentUser.UserPost.Post.Code;
  7380. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7381. {
  7382. string shopid = CurrentUser.User.pemShop;
  7383. lw.Add(string.Format("shopId in ({0})", shopid));
  7384. }
  7385. var mainwhere = string.Join(" and ", lw.ToArray());
  7386. string ro_json = "";
  7387. string type = GetPostString("gather_type");
  7388. int number = 0;
  7389. if (poscode == "AfterSale")
  7390. {
  7391. //处理中
  7392. if (type == "Handling")
  7393. {
  7394. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7395. DataTable dt = null;
  7396. try
  7397. {
  7398. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7399. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7400. }
  7401. catch (Exception e)
  7402. {
  7403. dt = new DataTable();
  7404. }
  7405. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7406. return;
  7407. }
  7408. if (type == "Wait")
  7409. {
  7410. //待处理
  7411. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7412. DataTable dt1 = null;
  7413. try
  7414. {
  7415. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7416. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7417. }
  7418. catch (Exception e)
  7419. {
  7420. dt1 = new DataTable();
  7421. }
  7422. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7423. return;
  7424. }
  7425. if (type == "back")
  7426. {
  7427. //打回
  7428. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7429. DataTable dt2 = null;
  7430. try
  7431. {
  7432. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7433. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7434. }
  7435. catch (Exception e)
  7436. {
  7437. dt2 = new DataTable();
  7438. }
  7439. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7440. return;
  7441. }
  7442. if (type == "preCompletion")
  7443. {
  7444. //预完成
  7445. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7446. DataTable dt3 = null;
  7447. try
  7448. {
  7449. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7450. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7451. }
  7452. catch (Exception e)
  7453. {
  7454. dt3 = new DataTable();
  7455. }
  7456. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7457. return;
  7458. }
  7459. if (type == "documentary")
  7460. {
  7461. //跟单中
  7462. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate > 2 and HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSalSend = 0 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7463. DataTable dt4 = null;
  7464. try
  7465. {
  7466. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7467. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7468. }
  7469. catch (Exception e)
  7470. {
  7471. dt4 = new DataTable();
  7472. }
  7473. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7474. return;
  7475. }
  7476. if (type == "reBack")
  7477. {
  7478. //被打回
  7479. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7480. DataTable dt1 = null;
  7481. try
  7482. {
  7483. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7484. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7485. }
  7486. catch (Exception e)
  7487. {
  7488. dt1 = new DataTable();
  7489. }
  7490. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7491. return;
  7492. }
  7493. }
  7494. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7495. {
  7496. if (type == "puBack")
  7497. {
  7498. //退回
  7499. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7500. DataTable dt = null;
  7501. try
  7502. {
  7503. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7504. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7505. }
  7506. catch (Exception e)
  7507. {
  7508. dt = new DataTable();
  7509. }
  7510. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7511. return;
  7512. }
  7513. if (type == "reBack")
  7514. {
  7515. //打回
  7516. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7517. DataTable dt1 = null;
  7518. try
  7519. {
  7520. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7521. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7522. }
  7523. catch (Exception e)
  7524. {
  7525. dt1 = new DataTable();
  7526. }
  7527. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7528. return;
  7529. }
  7530. if (type == "examEd")
  7531. {
  7532. //已审核
  7533. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7534. DataTable dt2 = null;
  7535. try
  7536. {
  7537. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7538. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7539. }
  7540. catch (Exception e)
  7541. {
  7542. dt2 = new DataTable();
  7543. }
  7544. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7545. return;
  7546. }
  7547. if (type == "waitExam")
  7548. {
  7549. //待审核
  7550. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7551. DataTable dt3 = null;
  7552. try
  7553. {
  7554. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7555. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7556. }
  7557. catch (Exception e)
  7558. {
  7559. dt3 = new DataTable();
  7560. }
  7561. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7562. return;
  7563. }
  7564. if (type == "Handling")
  7565. {
  7566. //处理中
  7567. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7568. DataTable dt4 = null;
  7569. try
  7570. {
  7571. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7572. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7573. }
  7574. catch (Exception e)
  7575. {
  7576. dt4 = new DataTable();
  7577. }
  7578. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7579. return;
  7580. }
  7581. if (type == "Wait")
  7582. {
  7583. //待处理
  7584. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7585. DataTable dt5 = null;
  7586. try
  7587. {
  7588. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7589. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7590. }
  7591. catch (Exception e)
  7592. {
  7593. dt5 = new DataTable();
  7594. }
  7595. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7596. return;
  7597. }
  7598. if (type == "documentary")
  7599. {
  7600. //跟单中
  7601. string sql6 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate > 2 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSalSend = 0 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7602. DataTable dt6 = null;
  7603. try
  7604. {
  7605. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7606. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7607. }
  7608. catch (Exception e)
  7609. {
  7610. dt6 = new DataTable();
  7611. }
  7612. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7613. return;
  7614. }
  7615. }
  7616. returnSuccess(ro_json);
  7617. }
  7618. public void end_erp_aftersale()
  7619. {
  7620. if (UrlPostParmsCheck("ctid"))
  7621. {
  7622. string eid = GetPostString("ctid");
  7623. CeErpTradeCell entity = null;
  7624. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7625. if (entity != null)
  7626. {
  7627. string stype = GetPostString("stype");
  7628. string typeStr = stype;
  7629. entity.AfterSaleState = 4;
  7630. entity.FinishAfterSaleTime = DateTime.Now;
  7631. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7632. entity.Update();
  7633. ApiVo apiVo = new ApiVo();
  7634. apiVo.orderNumber = entity.ctid;
  7635. apiVo.actionName = "afterOver";
  7636. designHelper.API_WorkCore(apiVo); //afterOver
  7637. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7638. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7639. CeErpSukuraData.createInfo(entity.ctid, 8);
  7640. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7641. returnSuccessMsg("操作成功!");
  7642. return;
  7643. }
  7644. returnErrorMsg("找不到订单记录");
  7645. }
  7646. }
  7647. public void ins_erp_finishaftersale()
  7648. {
  7649. if (UrlPostParmsCheck("id"))
  7650. {
  7651. string eid = GetPostString("id");
  7652. CeErpTradeResponsible entity = null;
  7653. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7654. if (entity != null)
  7655. {
  7656. entity.VerifyState = 1;
  7657. entity.VerifyTime = DateTime.Now;
  7658. entity.Update();
  7659. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7660. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7661. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7662. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7663. if (dt.Rows.Count <= 0)
  7664. {
  7665. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7666. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7667. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7668. CeErpSukuraData.createInfo(entity.tid, 8);
  7669. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7670. {
  7671. CeErpDesignerBill.Del(entity.tid);
  7672. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7673. }
  7674. }
  7675. returnSuccessMsg("操作成功!");
  7676. return;
  7677. }
  7678. returnErrorMsg("找不到订单记录");
  7679. }
  7680. }
  7681. public void upd_erp_arbitrateaftersale()
  7682. {
  7683. if (UrlPostParmsCheck("id"))
  7684. {
  7685. string eid = GetPostString("id");
  7686. CeErpTradeResponsible entity = null;
  7687. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7688. if (entity != null)
  7689. {
  7690. entity.IsArbitrate = 1;
  7691. entity.ArbitradeMemo = GetPostString("reason");
  7692. entity.VerifyState = 2;
  7693. entity.Update();
  7694. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7695. if (tradecell != null)
  7696. {
  7697. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7698. tradecell.IsArbitrate = 1;
  7699. tradecell.Update();
  7700. }
  7701. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7702. returnSuccessMsg("操作成功!");
  7703. return;
  7704. }
  7705. returnErrorMsg("找不到订单记录");
  7706. }
  7707. }
  7708. public void upd_erp_backaftersale()
  7709. {
  7710. if (UrlPostParmsCheck("tid"))
  7711. {
  7712. string eid = GetPostString("tid");
  7713. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7714. int backNum = 0;
  7715. if (number != null)
  7716. {
  7717. backNum = number.BackNum;
  7718. }
  7719. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7720. CeErpTradeCell entity = null;
  7721. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7722. if (entity != null)
  7723. {
  7724. entity.AfterSaleBackReason = GetPostString("backreason");
  7725. entity.AfterSaleState = 1;
  7726. entity.AfterSaleSupplierState = 0;
  7727. entity.UpdateTime = DateTime.Now;
  7728. entity.Update();
  7729. returnSuccessMsg("操作成功!");
  7730. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7731. return;
  7732. }
  7733. returnErrorMsg("找不到订单记录");
  7734. }
  7735. }
  7736. public void get_erp_supplieraftersalelist()
  7737. {
  7738. DataStruct dStruct = GetPostStruct();
  7739. List<string> lw = new List<string>();
  7740. string tid = GetPostString("ctid");
  7741. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7742. string shopname = GetPostString("shopname");
  7743. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7744. string buyernick = GetPostString("buyer_nick");
  7745. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7746. string sellermemo = GetPostString("seller_memo");
  7747. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7748. string orderState = GetPostString("orderState");
  7749. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7750. string afterState = GetPostString("afterstate");
  7751. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7752. string date1 = GetPostString("date1");
  7753. string date2 = GetPostString("date2");
  7754. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7755. if (dw.Length > 0) lw.Add(dw);
  7756. string price1 = GetPostString("price1");
  7757. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7758. string price2 = GetPostString("price2");
  7759. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7760. string reason = GetPostString("reason");
  7761. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7762. string method = GetPostString("method");
  7763. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7764. string handledate1 = GetPostString("handledate1");
  7765. string handledate2 = GetPostString("handledate2");
  7766. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7767. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7768. string handler = GetPostString("handler");
  7769. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7770. string afterdate1 = GetPostString("afterdate1");
  7771. string afterdate2 = GetPostString("afterdate2");
  7772. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7773. if (afterDate.Length > 0) lw.Add(afterDate);
  7774. string customer = GetPostString("customer");
  7775. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7776. string design = GetPostString("design");
  7777. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7778. string afterMemoType = GetPostString("aftermemotype");
  7779. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7780. string vstate = GetPostString("vstate");
  7781. if (vstate.Length > 0)
  7782. {
  7783. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7784. }
  7785. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7786. string supplier = GetPostString("supplier");
  7787. int supid = commonHelper.getSupplierIDByName(supplier);
  7788. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7789. string posCode = CurrentUser.UserPost.Post.Code;
  7790. if (posCode == "Supplier")
  7791. {
  7792. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7793. }
  7794. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7795. {
  7796. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7797. }
  7798. else
  7799. {
  7800. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7801. }
  7802. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7803. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7804. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7805. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7806. writeGridDataTableJson(dStruct.TotalCount, dt);
  7807. }
  7808. public void upd_erp_supverifyaftersale()
  7809. {
  7810. if (UrlPostParmsCheck("id"))
  7811. {
  7812. string id = GetPostString("id");
  7813. int st = GetPostInt("afterstate");
  7814. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7815. CeErpTradeCell entity = null;
  7816. if (ceErpTradeResponsible != null)
  7817. {
  7818. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7819. }
  7820. string afmemo = GetPostString("supmemo");
  7821. string image = GetPostString("image");
  7822. if (entity != null)
  7823. {
  7824. entity.AfterSaleSupplierState = st;
  7825. entity.AfterSaleSupplierMemo = afmemo;
  7826. if (st == 1)
  7827. {
  7828. ceErpTradeResponsible.VerifyState = 1;
  7829. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7830. ceErpTradeResponsible.Update();
  7831. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7832. if (isAll)
  7833. {
  7834. entity.AfterSaleState = 4;
  7835. entity.FinishAfterSaleTime = DateTime.Now;
  7836. }
  7837. }
  7838. else
  7839. {
  7840. CeErpTradeResponsible.dateByTid(entity.ctid);
  7841. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7842. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7843. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7844. if (num <= 1)
  7845. {
  7846. entity.AfterSaleState = 1;
  7847. }
  7848. else
  7849. {
  7850. entity.AfterSaleState = 5;
  7851. }
  7852. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7853. if (ceErpTradeAfterSaleExtend != null)
  7854. {
  7855. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7856. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7857. ceErpTradeAfterSaleExtend.Update();
  7858. }
  7859. else
  7860. {
  7861. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7862. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7863. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7864. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7865. ceErpTradeAfterSaleExtend.Create();
  7866. }
  7867. }
  7868. if (entity.AfterSaleState == 4)
  7869. {
  7870. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7871. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7872. {
  7873. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7874. }
  7875. ApiVo apiVo = new ApiVo();
  7876. apiVo.orderNumber = entity.ctid;
  7877. apiVo.actionName = "afterOver";
  7878. designHelper.API_WorkCore(apiVo); //afterOver
  7879. }
  7880. entity.UpdateTime = DateTime.Now;
  7881. entity.Update();
  7882. returnSuccessMsg("操作成功!");
  7883. CeErpSukuraData.createInfo(entity.ctid, 8);
  7884. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7885. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7886. return;
  7887. }
  7888. returnErrorMsg("找不到订单记录");
  7889. }
  7890. }
  7891. public void upd_erp_masteraftersale()
  7892. {
  7893. if (UrlPostParmsCheck("id"))
  7894. {
  7895. string id = GetPostString("id");
  7896. int st = GetPostInt("afterstate");
  7897. string afmemo = GetPostString("supmemo");
  7898. string image = GetPostString("image");
  7899. string textResult = GetPostString("textResult");
  7900. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7901. if (ceErpTradeResponsible != null)
  7902. {
  7903. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7904. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7905. ceErpTradeResponsible.Update();
  7906. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7907. if (entity != null)
  7908. {
  7909. entity.AfterSaleSupplierState = st;
  7910. entity.AfterSaleSupplierMemo = afmemo;
  7911. if (st == 1)
  7912. {
  7913. }
  7914. else
  7915. {
  7916. CeErpTradeResponsible.dateByTid(entity.ctid);
  7917. //退回到售后
  7918. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7919. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7920. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7921. if (num <= 1)
  7922. {
  7923. entity.AfterSaleState = 1;
  7924. }
  7925. else
  7926. {
  7927. entity.AfterSaleState = 5;
  7928. }
  7929. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7930. if (ceErpTradeAfterSaleExtend != null)
  7931. {
  7932. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7933. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7934. ceErpTradeAfterSaleExtend.Update();
  7935. }
  7936. else
  7937. {
  7938. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7939. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7940. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7941. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7942. ceErpTradeAfterSaleExtend.Create();
  7943. }
  7944. }
  7945. entity.UpdateTime = DateTime.Now;
  7946. entity.Update();
  7947. returnSuccessMsg("操作成功!");
  7948. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7949. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7950. return;
  7951. }
  7952. }
  7953. returnErrorMsg("找不到订单记录");
  7954. }
  7955. }
  7956. public void upd_erp_personaftersale()
  7957. {
  7958. if (UrlPostParmsCheck("id"))
  7959. {
  7960. //林小连
  7961. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7962. {
  7963. upd_erp_masteraftersale();
  7964. return;
  7965. }
  7966. string id = GetPostString("id");
  7967. int st = GetPostInt("afterstate");
  7968. string afmemo = GetPostString("supmemo");
  7969. string image = GetPostString("image");
  7970. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7971. if (ceErpTradeResponsible != null)
  7972. {
  7973. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7974. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7975. ceErpTradeResponsible.Update();
  7976. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7977. if (entity != null)
  7978. {
  7979. entity.AfterSaleSupplierMemo = afmemo;
  7980. entity.AfterSaleSupplierState = st;
  7981. if (st == 1)
  7982. {
  7983. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7984. if (isAll)
  7985. {
  7986. entity.AfterSaleState = 4;
  7987. entity.FinishAfterSaleTime = DateTime.Now;
  7988. }
  7989. }
  7990. else
  7991. {
  7992. CeErpTradeResponsible.dateByTid(entity.ctid);
  7993. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7994. if (ceErpTradeAfterSaleExtend != null)
  7995. {
  7996. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7997. ceErpTradeAfterSaleExtend.Update();
  7998. }
  7999. else
  8000. {
  8001. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  8002. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  8003. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  8004. ceErpTradeAfterSaleExtend.Create();
  8005. }
  8006. //退回到主管
  8007. //entity.AfterSaleState = 2;
  8008. }
  8009. if (entity.AfterSaleState == 4)
  8010. {
  8011. ApiVo apiVo = new ApiVo();
  8012. apiVo.orderNumber = entity.ctid;
  8013. apiVo.actionName = "afterOver";
  8014. designHelper.API_WorkCore(apiVo); //afterOver
  8015. }
  8016. entity.UpdateTime = DateTime.Now;
  8017. entity.Update();
  8018. returnSuccessMsg("操作成功!");
  8019. CeErpSukuraData.createInfo(entity.ctid, 8);
  8020. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  8021. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  8022. return;
  8023. }
  8024. }
  8025. returnErrorMsg("找不到订单记录");
  8026. }
  8027. }
  8028. public void set_erp_supplierrefundtag()
  8029. {
  8030. if (UrlPostParmsCheck("ctid"))
  8031. {
  8032. string eid = GetPostString("ctid");
  8033. CeErpTradeCell entity = null;
  8034. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  8035. if (entity != null)
  8036. {
  8037. entity.IsSupplierRefund = GetPostInt("tag");
  8038. entity.Update();
  8039. returnSuccessMsg("操作成功!");
  8040. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  8041. return;
  8042. }
  8043. returnErrorMsg("找不到订单记录");
  8044. }
  8045. }
  8046. public void get_erp_refundlist()
  8047. {
  8048. DataStruct dStruct = GetPostStruct();
  8049. List<string> lw = new List<string>();
  8050. string tid = GetPostString("tid");
  8051. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8052. //string rid = GetPostString("refund_id");
  8053. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  8054. string shopname = GetPostString("shopname");
  8055. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8056. string buyernick = GetPostString("buyer_nick");
  8057. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8058. string customer = GetPostString("customer");
  8059. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8060. string design = GetPostString("design");
  8061. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8062. string sellermemo = GetPostString("seller_memo");
  8063. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8064. //string date1 = GetPostString("date1");
  8065. //string date2 = GetPostString("date2");
  8066. //string dateType = GetPostString("dateType");
  8067. //if (dateType.Length > 0)
  8068. //{
  8069. // if (dateType == "1001") dateType = "0";
  8070. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  8071. // if (searchDT.Count == 2)
  8072. // {
  8073. // date1 = searchDT[0].ToString();
  8074. // date2 = searchDT[1].ToString();
  8075. // }
  8076. //}
  8077. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8078. //if (dw.Length > 0) lw.Add(dw);
  8079. string redate1 = GetPostString("refunddate1");
  8080. string redate2 = GetPostString("refunddate2");
  8081. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8082. if (dwdate.Length > 0) lw.Add(dwdate);
  8083. string price1 = GetPostString("price1");
  8084. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8085. string price2 = GetPostString("price2");
  8086. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8087. string ispartrefund = GetPostString("ispartrefund");
  8088. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8089. string refundState = GetPostString("refundvstate");
  8090. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  8091. int st = GetInt("st");
  8092. if (st == 2) //待确认列表中,把state=3已确认的也显示
  8093. {
  8094. string responsible = GetPostString("responsibleman");
  8095. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8096. lw.Add(string.Format("RefundState>={0}", st));
  8097. string code = CurrentUser.UserPost.Post.Code;
  8098. if (code == "CustomerService")
  8099. {
  8100. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  8101. }
  8102. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  8103. {
  8104. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  8105. }
  8106. else if (code == "Place" || code == "PlaceMr")
  8107. {
  8108. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  8109. }
  8110. dStruct.Order = "RefundState asc,created desc";
  8111. }
  8112. else if (st == 10)
  8113. {
  8114. string responsible = GetPostString("responsibleman");
  8115. if (responsible == "空白")
  8116. {
  8117. lw.Add(string.Format("ResponsibleUserName = ''"));
  8118. }
  8119. else if (responsible.Length > 0)
  8120. {
  8121. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8122. }
  8123. lw.Add(string.Format("RefundState>=0"));
  8124. dStruct.Order = "created desc";
  8125. }
  8126. else
  8127. {
  8128. string responsible = GetPostString("responsibleman");
  8129. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8130. lw.Add(string.Format("RefundState={0}", st));
  8131. dStruct.Order = "created desc";
  8132. }
  8133. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8134. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  8135. dt.Columns.Add("refund_fees");
  8136. foreach (DataRow dr in dt.Rows)
  8137. {
  8138. String status = dr["status"].ToString();
  8139. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8140. {
  8141. dr["refund_fees"] = dr["refund_fee"];
  8142. }
  8143. else
  8144. {
  8145. dr["refund_fees"] = "0.0";
  8146. }
  8147. }
  8148. writeGridDataTableJson(dStruct.TotalCount, dt);
  8149. }
  8150. public void get_erp_refunddesignlist()
  8151. {
  8152. DataStruct dStruct = GetPostStruct();
  8153. List<string> lw = new List<string>();
  8154. string tid = GetPostString("tid");
  8155. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8156. string shopname = GetPostString("shopname");
  8157. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8158. string buyernick = GetPostString("buyer_nick");
  8159. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8160. string customer = GetPostString("customer");
  8161. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8162. string design = GetPostString("design");
  8163. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8164. string sellermemo = GetPostString("seller_memo");
  8165. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8166. string redate1 = GetPostString("refunddate1");
  8167. string redate2 = GetPostString("refunddate2");
  8168. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8169. if (dwdate.Length > 0) lw.Add(dwdate);
  8170. string price1 = GetPostString("price1");
  8171. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8172. string price2 = GetPostString("price2");
  8173. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8174. string ispartrefund = GetPostString("ispartrefund");
  8175. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8176. string designerorg = GetPostString("designerorg");
  8177. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  8178. string refundState = GetPostString("refundState");
  8179. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  8180. int myOrgid = CurrentUser.UserPost.OrgID;
  8181. string myOrgCode = CurrentUser.UserPost.Post.Code;
  8182. if ("Designer".Equals(myOrgCode))//设计师能看到的
  8183. {
  8184. if (CurrentUser.User.TeamIds.Length > 0)
  8185. {
  8186. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  8187. }
  8188. else
  8189. {
  8190. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8191. }
  8192. }
  8193. else if ("SysAdmin".Equals(myOrgCode))
  8194. {
  8195. }
  8196. else
  8197. {
  8198. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8199. {
  8200. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8201. }
  8202. else
  8203. {
  8204. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8205. }
  8206. }
  8207. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8208. dStruct.Order = "created desc";
  8209. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8210. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8211. dt.Columns.Add("refund_fees");
  8212. foreach (DataRow dr in dt.Rows)
  8213. {
  8214. String status = dr["status"].ToString();
  8215. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8216. {
  8217. dr["refund_fees"] = dr["refund_fee"];
  8218. }
  8219. else
  8220. {
  8221. dr["refund_fees"] = "0.0";
  8222. }
  8223. }
  8224. writeGridDataTableJson(dStruct.TotalCount, dt);
  8225. }
  8226. public void handle_erp_refundtag()
  8227. {
  8228. if (UrlPostParmsCheck("refund_id"))
  8229. {
  8230. string eid = GetPostString("refund_id");
  8231. string respMan = GetPostString("ResponsibleName");
  8232. if (respMan.Length <= 0)
  8233. {
  8234. returnErrorMsg("责任人不能为空");
  8235. return;
  8236. }
  8237. CeErpTradeRefund entity = null;
  8238. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8239. if (entity != null)
  8240. {
  8241. entity.ResponsibleUserName = respMan;
  8242. string userid = GetPostString("ResponsibleUserId");
  8243. if (userid.Length > 0)
  8244. {
  8245. entity.ResponsibleUserId = userid;
  8246. }
  8247. entity.Memo = GetPostString("Memo");
  8248. if (respMan.IndexOf("客服") != -1 ||
  8249. respMan.IndexOf("设计师") != -1 ||
  8250. respMan.IndexOf("下单员") != -1)
  8251. {
  8252. entity.RefundState = 2;
  8253. }
  8254. else
  8255. {
  8256. entity.RefundState = 3;
  8257. }
  8258. entity.modified = DateTime.Now;
  8259. entity.Update();
  8260. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8261. returnSuccessMsg("操作成功!");
  8262. return;
  8263. }
  8264. returnErrorMsg("找不到订单记录");
  8265. }
  8266. }
  8267. public void handle_erp_designrefundtag()
  8268. {
  8269. if (UrlPostParmsCheck("refund_id"))
  8270. {
  8271. string eid = GetPostString("refund_id");
  8272. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8273. if (ceErpTradeCellExtend == null)
  8274. {
  8275. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8276. ceErpTradeCellExtend.ctid = eid;
  8277. }
  8278. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8279. if (ceErpTradeCellExtend.ID > 0)
  8280. {
  8281. ceErpTradeCellExtend.Update();
  8282. }
  8283. else
  8284. {
  8285. ceErpTradeCellExtend.Create();
  8286. }
  8287. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8288. returnSuccessMsg("操作成功!");
  8289. return;
  8290. }
  8291. returnErrorMsg("找不到订单记录");
  8292. }
  8293. public void upd_erp_refundverify()
  8294. {
  8295. if (UrlPostParmsCheck("refund_id"))
  8296. {
  8297. string eid = GetPostString("refund_id");
  8298. CeErpTradeRefund entity = null;
  8299. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8300. if (entity != null)
  8301. {
  8302. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8303. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8304. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8305. {
  8306. entity.RefundState = 2;
  8307. }
  8308. else
  8309. {
  8310. entity.RefundState = 3;
  8311. }
  8312. entity.Update();
  8313. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8314. returnSuccessMsg("操作成功!");
  8315. return;
  8316. }
  8317. returnErrorMsg("找不到订单记录");
  8318. }
  8319. }
  8320. public void upd_erp_refundapprove()
  8321. {
  8322. if (UrlPostParmsCheck("refund_id"))
  8323. {
  8324. string eid = GetPostString("refund_id");
  8325. CeErpTradeRefund entity = null;
  8326. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8327. if (entity != null)
  8328. {
  8329. int apr = GetPostInt("approve");
  8330. if (apr == 0)
  8331. {
  8332. entity.RefundState = 1;
  8333. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8334. }
  8335. else if (apr == 1)
  8336. {
  8337. entity.RefundState = 3;
  8338. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8339. }
  8340. entity.modified = DateTime.Now;
  8341. entity.Update();
  8342. returnSuccessMsg("操作成功!");
  8343. return;
  8344. }
  8345. returnErrorMsg("找不到订单记录");
  8346. }
  8347. }
  8348. public void get_erp_billlist()
  8349. {
  8350. DataStruct dStruct = GetPostStruct();
  8351. List<string> lw = new List<string>();
  8352. string title = GetPostString("title");
  8353. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8354. string tid = GetPostString("tid");
  8355. string tids = GetPostString("tids");
  8356. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8357. if (tids.Length > 0)
  8358. {
  8359. tids = "'" + tids + "'";
  8360. tids = tids.Replace(",", "','");
  8361. lw.Add(string.Format("tid in ({0})", tids));
  8362. }
  8363. string shopname = GetPostString("shopname");
  8364. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8365. string buyernick = GetPostString("buyer_nick");
  8366. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8367. string customer = GetPostString("customer");
  8368. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8369. string date1 = GetPostString("date1");
  8370. string date2 = GetPostString("date2");
  8371. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8372. if (dw.Length > 0) lw.Add(dw);
  8373. string price1 = GetPostString("price1");
  8374. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8375. string price2 = GetPostString("price2");
  8376. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8377. string returndate1 = GetPostString("returndate1");
  8378. string returndate2 = GetPostString("returndate2");
  8379. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8380. if (dw1.Length > 0) lw.Add(dw1);
  8381. string billtype = GetPostString("billtype");
  8382. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8383. string billstate = GetPostString("billstate");
  8384. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8385. string usershop = CurrentUser.User.pemShop;
  8386. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8387. dStruct.Order = "createTime desc";
  8388. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8389. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8390. //foreach (DataRow dr in dt.Rows)
  8391. //{
  8392. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8393. //}
  8394. writeGridDataTableJson(dStruct.TotalCount, dt);
  8395. }
  8396. public void modify_erp_billinfo()
  8397. {
  8398. if (UrlPostParmsCheck("ID"))
  8399. {
  8400. string eid = GetPostString("ID");
  8401. CeErpBill bill_entity = null;
  8402. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8403. if (bill_entity != null)
  8404. {
  8405. bill_entity.tid = GetPostString("tid");
  8406. bill_entity.title = GetPostString("title");
  8407. bill_entity.tax = GetPostString("tax");
  8408. bill_entity.bank = GetPostString("bank");
  8409. bill_entity.bankac = GetPostString("bankac");
  8410. bill_entity.address = GetPostString("address");
  8411. bill_entity.phone = GetPostString("phone");
  8412. bill_entity.price = GetPostString("price");
  8413. bill_entity.productId = GetPostInt("ProductName");
  8414. bill_entity.num = GetPostInt("num");
  8415. bill_entity.unit = GetPostString("unit");
  8416. bill_entity.type = GetPostString("type");
  8417. bill_entity.sendType = GetPostString("SendType");
  8418. bill_entity.email = GetPostString("email");
  8419. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8420. bill_entity.shopName = GetPostString("ShopName");
  8421. bill_entity.applymemo = GetPostString("applymemo");
  8422. bill_entity.modifyTime = DateTime.Now;
  8423. bill_entity.createTime = DateTime.Now;
  8424. bill_entity.state = 0;
  8425. bill_entity.Update();
  8426. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8427. returnSuccessMsg("发票修改成功!");
  8428. return;
  8429. }
  8430. returnErrorMsg("找不到对应记录");
  8431. }
  8432. }
  8433. public void set_erp_invoicing()
  8434. {
  8435. if (UrlPostParmsCheck("id"))
  8436. {
  8437. try
  8438. {
  8439. string eid = GetPostString("id");
  8440. CeErpBill bill_entity = null;
  8441. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8442. if (bill_entity != null)
  8443. {
  8444. int ComId = GetPostInt("ComId");
  8445. //string memo = GetPostString("Memo");
  8446. int allInfo = GetPostInt("allinfo");
  8447. string clert = CurrentUser.User.Name;
  8448. //string detailValue = GetPostString("detailvalue");
  8449. string billId = bill_entity.billOrderId;
  8450. string[] billIdList = billId.Split(',');
  8451. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8452. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8453. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8454. {
  8455. billCount += 1;
  8456. }
  8457. if (billId.Length <= 0 || billIdList.Length != billCount)
  8458. {
  8459. bill_entity.billOrderId = "";
  8460. string prebill = "ltb";
  8461. for (int idx = 1; idx <= billCount; idx++)
  8462. {
  8463. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8464. string billoid = prebill + idx + dtstr;
  8465. bill_entity.billOrderId += billoid;
  8466. if (idx < billCount)
  8467. {
  8468. bill_entity.billOrderId += ",";
  8469. }
  8470. }
  8471. }
  8472. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8473. if (bill_entity.state == 5)
  8474. {
  8475. string errMsg = bill_entity.failerror;
  8476. string[] errlist = errMsg.Split('|');
  8477. string[] errTags = new string[errlist.Length];
  8478. for (int itag = 0; itag < errlist.Length; itag++)
  8479. {
  8480. if (errlist[itag].Length <= 0) continue;
  8481. errTags[itag] = errlist[itag].Split('&')[0];
  8482. }
  8483. for (int iii = 0; iii < errTags.Length; iii++)
  8484. {
  8485. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8486. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8487. if (billOrderList.Length >= erroBillOrderTag)
  8488. {
  8489. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8490. if (needModifyBillId.Length <= 19)
  8491. {
  8492. needModifyBillId = needModifyBillId + "1";
  8493. }
  8494. else
  8495. {
  8496. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8497. last = last + 1;
  8498. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8499. }
  8500. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8501. }
  8502. }
  8503. }
  8504. bool isHaveBillSucces = false;
  8505. string totalRes = "";
  8506. bill_entity.failerror = "";
  8507. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8508. {
  8509. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8510. totalRes += res;
  8511. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8512. {
  8513. isHaveBillSucces = true;
  8514. bill_entity.comId = ComId;
  8515. bill_entity.state = 1;
  8516. bill_entity.executeTime = DateTime.Now;
  8517. bill_entity.executeUser = clert;
  8518. }
  8519. else
  8520. {
  8521. bill_entity.state = 5;
  8522. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8523. }
  8524. }
  8525. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8526. bill_entity.Update();
  8527. if (isHaveBillSucces)
  8528. {
  8529. StringBuilder sql = new StringBuilder();
  8530. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8531. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8532. }
  8533. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8534. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8535. {
  8536. returnErrorMsg("开票失败");
  8537. }
  8538. else
  8539. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8540. return;
  8541. }
  8542. returnErrorMsg("找不到对应记录");
  8543. }
  8544. catch (Exception ex)
  8545. {
  8546. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8547. returnErrorMsg("操作失败");
  8548. }
  8549. }
  8550. }
  8551. public void get_erp_invoicing_back()
  8552. {
  8553. if (UrlPostParmsCheck("id"))
  8554. {
  8555. try
  8556. {
  8557. string id = GetPostString("id");
  8558. CeErpBill entiy = CeErpBill.Get(id);
  8559. if (entiy != null)
  8560. {
  8561. if (entiy.state == 0)
  8562. {
  8563. returnErrorMsg("发票还未开具");
  8564. return;
  8565. }
  8566. string[] billOrderList = entiy.billOrderId.Split(',');
  8567. int iTag = 0;
  8568. entiy.fplsh = "";
  8569. entiy.fpdm = "";
  8570. entiy.fphm = "";
  8571. foreach (string billOrderId in billOrderList)
  8572. {
  8573. iTag++;
  8574. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8575. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8576. {
  8577. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8578. try
  8579. {
  8580. Invoicing_get_response_Obj iObj = null;
  8581. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8582. if (iObj != null)
  8583. {
  8584. entiy.state = 2;
  8585. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8586. entiy.fpdm += iObj.list[0].c_fpdm;
  8587. entiy.fphm += iObj.list[0].c_fphm;
  8588. if (iTag < billOrderList.Length)
  8589. {
  8590. entiy.fplsh += ",";
  8591. entiy.fpdm += ",";
  8592. entiy.fphm += ",";
  8593. }
  8594. entiy.Update();
  8595. }
  8596. StringBuilder sql = new StringBuilder();
  8597. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8598. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8599. returnSuccessMsg("开票成功");
  8600. }
  8601. catch (Exception ex)
  8602. {
  8603. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8604. }
  8605. return;
  8606. }
  8607. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8608. {
  8609. var res_obj = new
  8610. {
  8611. data = "开票中"
  8612. };
  8613. string ro_json = JsonConvert.SerializeObject(res_obj);
  8614. returnSuccess(ro_json);
  8615. return;
  8616. }
  8617. else
  8618. {
  8619. int eidx = res.IndexOf("c_resultmsg");
  8620. int lidx = res.IndexOf("c_status");
  8621. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8622. entiy.state = 5;
  8623. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8624. entiy.Update();
  8625. returnErrorMsg("开票失败");
  8626. return;
  8627. }
  8628. }
  8629. }
  8630. }
  8631. catch (Exception ex)
  8632. {
  8633. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8634. }
  8635. return;
  8636. }
  8637. }
  8638. public void get_erp_invoicing()
  8639. {
  8640. if (UrlPostParmsCheck("id"))
  8641. {
  8642. try
  8643. {
  8644. string id = GetPostString("id");
  8645. CeErpBill entiy = CeErpBill.Get(id);
  8646. if (entiy != null)
  8647. {
  8648. if (entiy.state == 0)
  8649. {
  8650. returnErrorMsg("发票还未开具");
  8651. return;
  8652. }
  8653. if (entiy.sendType == "纸质发票")
  8654. {
  8655. if (entiy.img.Length <= 0)
  8656. {
  8657. returnErrorMsg("查无纸质发票");
  8658. return;
  8659. }
  8660. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8661. returnSuccess(returnres);
  8662. return;
  8663. }
  8664. string[] billOrderList = entiy.billOrderId.Split(',');
  8665. int iTag = 0;
  8666. string fpUrl = "";
  8667. entiy.fplsh = "";
  8668. entiy.fpdm = "";
  8669. entiy.fphm = "";
  8670. foreach (string billOrderId in billOrderList)
  8671. {
  8672. iTag++;
  8673. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8674. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8675. {
  8676. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8677. Invoicing_get_response_Obj iObj = null;
  8678. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8679. if (iObj != null)
  8680. {
  8681. //entiy.state = 2;
  8682. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8683. entiy.fpdm += iObj.list[0].c_fpdm;
  8684. entiy.fphm += iObj.list[0].c_fphm;
  8685. if (iTag < billOrderList.Length)
  8686. {
  8687. entiy.fplsh += ",";
  8688. entiy.fpdm += ",";
  8689. entiy.fphm += ",";
  8690. }
  8691. entiy.Update();
  8692. fpUrl += iObj.list[0].c_url + ",";
  8693. }
  8694. //returnSuccess(res);
  8695. StringBuilder sql = new StringBuilder();
  8696. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8697. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8698. }
  8699. else
  8700. {
  8701. int eidx = res.IndexOf("c_resultmsg");
  8702. //int lidx = res.IndexOf("c_status");
  8703. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8704. //开票失败
  8705. entiy.state = 5;
  8706. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8707. entiy.Update();
  8708. returnErrorMsg("开票失败");
  8709. return;
  8710. }
  8711. }
  8712. var returnObj = new
  8713. {
  8714. data = fpUrl
  8715. };
  8716. string ro_json = JsonConvert.SerializeObject(returnObj);
  8717. returnSuccess(ro_json);
  8718. }
  8719. }
  8720. catch (Exception ex)
  8721. {
  8722. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8723. }
  8724. return;
  8725. }
  8726. }
  8727. public void save_erp_billimg()
  8728. {
  8729. if (UrlPostParmsCheck("id"))
  8730. {
  8731. string eid = GetPostString("id");
  8732. CeErpBill bill_entity = null;
  8733. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8734. if (bill_entity != null)
  8735. {
  8736. bill_entity.img = GetPostString("img");
  8737. bill_entity.executeTime = DateTime.Now;
  8738. bill_entity.state = 2;
  8739. bill_entity.Update();
  8740. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8741. returnSuccessMsg("保存成功");
  8742. }
  8743. return;
  8744. }
  8745. }
  8746. public void upd_erp_billreturnback()
  8747. {
  8748. if (UrlPostParmsCheck("id"))
  8749. {
  8750. int eid = GetPostInt("id");
  8751. CeErpBill bill_entity = null;
  8752. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8753. if (bill_entity != null)
  8754. {
  8755. bill_entity.state = 3;
  8756. bill_entity.returnReason = GetPostString("reason");
  8757. bill_entity.Update();
  8758. returnSuccessMsg("驳回成功!");
  8759. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8760. }
  8761. return;
  8762. }
  8763. }
  8764. public void cancel_erp_bill()
  8765. {
  8766. if (UrlPostParmsCheck("id"))
  8767. {
  8768. int eid = GetPostInt("id");
  8769. int detailValue = GetPostInt("detailvalue");
  8770. CeErpBill bill_entity = null;
  8771. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8772. string cres = "";
  8773. string gres = "";
  8774. if (bill_entity != null)
  8775. {
  8776. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8777. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8778. {
  8779. int iTag = 0;
  8780. bill_entity.fplsh = "";
  8781. bill_entity.fpdm = "";
  8782. bill_entity.fphm = "";
  8783. foreach (string billOrderId in billOrderList)
  8784. {
  8785. iTag++;
  8786. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8787. if (gres.IndexOf("success") != -1)
  8788. {
  8789. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8790. Invoicing_get_response_Obj iObj = null;
  8791. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8792. if (iObj != null)
  8793. {
  8794. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8795. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8796. bill_entity.fphm += iObj.list[0].c_fphm;
  8797. if (iTag < billOrderList.Length)
  8798. {
  8799. bill_entity.fplsh += ",";
  8800. bill_entity.fpdm += ",";
  8801. bill_entity.fphm += ",";
  8802. }
  8803. bill_entity.Update();
  8804. }
  8805. }
  8806. else
  8807. {
  8808. returnErrorMsg(gres);
  8809. return;
  8810. }
  8811. }
  8812. }
  8813. if (bill_entity.sendType == "纸质发票")
  8814. {
  8815. //作废
  8816. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8817. //if (DateTime.Now.Month == extime.Month)
  8818. //{
  8819. //cres = taobaoHelper.cancel_invoicing(eid);
  8820. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8821. //{
  8822. bill_entity.state = 4;//已作废
  8823. bill_entity.Update();
  8824. returnSuccessMsg("发票已作废");
  8825. return;
  8826. //}
  8827. //else
  8828. //{
  8829. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8830. // bill_entity.Update();
  8831. // returnErrorMsg(cres);
  8832. // return;
  8833. //}
  8834. //}
  8835. //else
  8836. //{
  8837. // returnErrorMsg("纸质发票只能作废本月的发票");
  8838. // return;
  8839. //}
  8840. }
  8841. //红冲
  8842. int redTag = 0;
  8843. string[] fpdmList = bill_entity.fpdm.Split(',');
  8844. string[] fphmList = bill_entity.fphm.Split(',');
  8845. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8846. {
  8847. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8848. return;
  8849. }
  8850. foreach (string billOrderId in billOrderList)
  8851. {
  8852. redTag++;
  8853. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8854. cres += onecres;
  8855. cres += ",";
  8856. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8857. {
  8858. bill_entity.state = 4;//已作废
  8859. //bill_entity.Update();
  8860. //returnSuccessMsg("发票已红冲");
  8861. }
  8862. else if (onecres.IndexOf("重复冲红") != -1)
  8863. {
  8864. bill_entity.state = 4;//已作废
  8865. //bill_entity.Update();
  8866. //returnSuccessMsg("发票已红冲");
  8867. }
  8868. else
  8869. {
  8870. string errmsg = commonHelper.KeepChinese(onecres);
  8871. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8872. }
  8873. }
  8874. bill_entity.Update();
  8875. if (cres.IndexOf("失败") != -1)
  8876. returnErrorMsg("红冲失败");
  8877. else
  8878. returnSuccessMsg("发票已红冲");
  8879. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8880. return;
  8881. }
  8882. return;
  8883. }
  8884. }
  8885. public void del_erp_billorder()
  8886. {
  8887. if (UrlPostParmsCheck("id"))
  8888. {
  8889. string eid = GetPostString("id");
  8890. CeErpBill.Del(eid);
  8891. CeErpBill bill = CeErpBill.Get(eid);
  8892. if (bill != null)
  8893. {
  8894. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8895. }
  8896. returnSuccessMsg("删除成功");
  8897. }
  8898. }
  8899. public void finish_erp_bill()
  8900. {
  8901. if (UrlPostParmsCheck("ids"))
  8902. {
  8903. string eids = GetPostString("ids");
  8904. string[] list = eids.Split(',');
  8905. foreach (string eid in list)
  8906. {
  8907. CeErpBill bill = CeErpBill.Get(eid);
  8908. if (bill != null)
  8909. {
  8910. bill.state = 2;
  8911. bill.Update();
  8912. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8913. }
  8914. }
  8915. returnSuccessMsg("操作成功");
  8916. }
  8917. }
  8918. public void get_erp_returncash()
  8919. {
  8920. DataStruct dStruct = GetPostStruct();
  8921. List<string> lw = new List<string>();
  8922. string tid = GetPostString("tid");
  8923. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8924. string shopname = GetPostString("shopname");
  8925. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8926. string buyernick = GetPostString("buyer_nick");
  8927. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8928. string customer = GetPostString("customer");
  8929. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8930. string returndate1 = GetPostString("returndate1");
  8931. string returndate2 = GetPostString("returndate2");
  8932. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8933. if (dw.Length > 0) lw.Add(dw);
  8934. string finishDate1 = GetPostString("finishdate1");
  8935. string finishDate2 = GetPostString("finishdate2");
  8936. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8937. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8938. string returntype = GetPostString("returntype");
  8939. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8940. string returnvstate = GetPostString("returnvstate");
  8941. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8942. dStruct.Order = "created desc";
  8943. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8944. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8945. writeGridDataTableJson(dStruct.TotalCount, dt);
  8946. }
  8947. public void get_erp_staygoods()
  8948. {
  8949. DataStruct dStruct = GetPostStruct();
  8950. List<string> lw = new List<string>();
  8951. string tid = GetPostString("tid");
  8952. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8953. string shopname = GetPostString("shopname");
  8954. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8955. string wangwang = GetPostString("wangwang");
  8956. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8957. string customer = GetPostString("customer");
  8958. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8959. string returndate1 = GetPostString("returndate1");
  8960. string returndate2 = GetPostString("returndate2");
  8961. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8962. if (dw.Length > 0) lw.Add(dw);
  8963. string finishDate1 = GetPostString("finishdate1");
  8964. string finishDate2 = GetPostString("finishdate2");
  8965. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8966. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8967. string returnvstate = GetPostString("returnvstate");
  8968. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8969. string persuadetype = GetPostString("persuadetype");
  8970. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8971. string customerOrg = GetPostString("customerOrg");
  8972. if (customerOrg.Length > 0)
  8973. {
  8974. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8975. }
  8976. string designerorg = GetPostString("designerorg");
  8977. if (designerorg.Length > 0)
  8978. {
  8979. lw.Add(string.Format("OrgID = {0}", designerorg));
  8980. }
  8981. dStruct.Order = "creata_time desc";
  8982. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8983. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8984. writeGridDataTableJson(dStruct.TotalCount, dt);
  8985. }
  8986. public void upd_erp_staygoods()
  8987. {
  8988. if (UrlPostParmsCheck("id"))
  8989. {
  8990. int eid = GetPostInt("id");
  8991. CeErpStayGoods entity = null;
  8992. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8993. if (entity != null)
  8994. {
  8995. entity.audit_type = 1;
  8996. entity.audit_time = DateTime.Now;
  8997. entity.audit_u_id = CurrentUser.UserID;
  8998. entity.audit_u_name = CurrentUser.UserName;
  8999. entity.Update();
  9000. returnSuccessMsg("审核成功!");
  9001. return;
  9002. }
  9003. returnErrorMsg("找不到订单记录");
  9004. }
  9005. }
  9006. public void upd_erp_stayGoodsback()
  9007. {
  9008. if (UrlPostParmsCheck("id"))
  9009. {
  9010. int eid = GetPostInt("id");
  9011. CeErpStayGoods entity = null;
  9012. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  9013. if (entity != null)
  9014. {
  9015. entity.audit_text = GetPostString("reason");
  9016. entity.audit_type = 2;
  9017. entity.audit_time = DateTime.Now;
  9018. entity.audit_u_id = CurrentUser.UserID;
  9019. entity.audit_u_name = CurrentUser.UserName;
  9020. entity.Update();
  9021. returnSuccessMsg("退回成功!");
  9022. return;
  9023. }
  9024. returnErrorMsg("找不到订单记录");
  9025. }
  9026. }
  9027. public void upd_erp_returncashverify()
  9028. {
  9029. if (UrlPostParmsCheck("ID"))
  9030. {
  9031. int eid = GetPostInt("ID");
  9032. CeErpReturnCash entity = null;
  9033. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9034. if (entity != null)
  9035. {
  9036. entity.cashstate = 1;
  9037. entity.verifytime = DateTime.Now;
  9038. entity.verifyuserid = CurrentUser.UserID;
  9039. entity.Update();
  9040. returnSuccessMsg("审核成功!");
  9041. return;
  9042. }
  9043. returnErrorMsg("找不到订单记录");
  9044. }
  9045. }
  9046. public void upd_all_erp_returncashverify()
  9047. {
  9048. if (UrlPostParmsCheck("ID"))
  9049. {
  9050. String[] list = GetPostString("ID").Split(',');
  9051. CeErpReturnCash entity = null;
  9052. for (int i = 0; i < list.Length; i++)
  9053. {
  9054. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  9055. if (entity != null)
  9056. {
  9057. if (entity.cashstate == 1)
  9058. {
  9059. returnErrorMsg("已审核过的订单不需要在审核!");
  9060. return;
  9061. }
  9062. entity.cashstate = 1;
  9063. entity.verifytime = DateTime.Now;
  9064. entity.verifyuserid = CurrentUser.UserID;
  9065. entity.Update();
  9066. }
  9067. }
  9068. returnSuccessMsg("审核成功!");
  9069. return;
  9070. }
  9071. }
  9072. public void upd_erp_returncashback()
  9073. {
  9074. if (UrlPostParmsCheck("ID"))
  9075. {
  9076. int eid = GetPostInt("ID");
  9077. CeErpReturnCash entity = null;
  9078. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9079. if (entity != null)
  9080. {
  9081. entity.backreason = GetPostString("reason");
  9082. entity.cashstate = 2;
  9083. entity.verifytime = DateTime.Now;
  9084. entity.verifyuserid = CurrentUser.UserID;
  9085. entity.Update();
  9086. returnSuccessMsg("退回成功!");
  9087. return;
  9088. }
  9089. returnErrorMsg("找不到订单记录");
  9090. }
  9091. }
  9092. public void upd_erp_returnprice()
  9093. {
  9094. if (UrlPostParmsCheck("ID"))
  9095. {
  9096. int eid = GetPostInt("ID");
  9097. CeErpReturnCash entity = null;
  9098. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9099. if (entity != null)
  9100. {
  9101. if (entity.cashstate == 1)
  9102. {
  9103. returnErrorMsg("审核通过了不能改");
  9104. return;
  9105. }
  9106. entity.returnprice = GetPostDouble("returnprice");
  9107. entity.Update();
  9108. returnSuccessMsg("修改成功!");
  9109. return;
  9110. }
  9111. returnErrorMsg("找不到订单记录");
  9112. }
  9113. }
  9114. public void del_erp_returncash()
  9115. {
  9116. if (UrlPostParmsCheck("ID"))
  9117. {
  9118. int eid = GetPostInt("ID");
  9119. CeErpReturnCash.Del(eid);
  9120. returnSuccessMsg("操作成功");
  9121. return;
  9122. }
  9123. }
  9124. public void test_for_do_sql()
  9125. {
  9126. string sql = GetPostString("sqlstr");
  9127. if (sql.Length > 0)
  9128. {
  9129. try
  9130. {
  9131. DbHelper.DbConn.ExecuteNonQuery(sql);
  9132. var res_obj = new
  9133. {
  9134. data = "成功",
  9135. };
  9136. string ro_json = JsonConvert.SerializeObject(res_obj);
  9137. returnSuccess(ro_json);
  9138. }
  9139. catch (Exception ex)
  9140. {
  9141. var res_obj = new
  9142. {
  9143. data = ex.Message,
  9144. };
  9145. string ro_json = JsonConvert.SerializeObject(res_obj);
  9146. returnSuccess(ro_json);
  9147. }
  9148. }
  9149. }
  9150. public void get_user_info()
  9151. {
  9152. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  9153. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  9154. }
  9155. public void get_total_data()
  9156. {
  9157. int userId = CurrentUser.UserID;
  9158. string sql = "";
  9159. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9160. {
  9161. sql = string.Format("SELECT c.ID, COALESCE(SUM(CASE WHEN OrderState = 8 THEN payment ELSE 0 END), 0) AS orderAmount, COALESCE(SUM(CASE WHEN OrderState = 8 THEN 1 ELSE 0 END), 0) AS orderCount, COALESCE(SUM(CASE WHEN OrderState = 3 THEN payment ELSE 0 END), 0) AS orderBeginAmount, COALESCE(SUM(CASE WHEN OrderState = 3 THEN 1 ELSE 0 END), 0) AS orderBeginCount, COALESCE(SUM(CASE WHEN OrderState = 4 THEN payment ELSE 0 END), 0) AS orderFinishAmount, COALESCE(SUM(CASE WHEN OrderState = 4 THEN 1 ELSE 0 END), 0) AS orderFinishCount, COALESCE(SUM(CASE WHEN IsRefund > 1 THEN 1 ELSE 0 END), 0) AS refundCount, COALESCE(SUM(CASE WHEN IsRefund > 1 THEN payment ELSE 0 END), 0) AS refundAmount FROM CE_ErpUser c LEFT JOIN view_ErpTradeCell v ON c.ID = v.DesignUserId WHERE c.ID = {0} GROUP BY c.ID;", userId);
  9162. }
  9163. else
  9164. {
  9165. sql = string.Format("select d.id,isnull(a.orderAmount,0) as orderAmount,isnull(a.orderCount,0) as orderCount,isnull(b.refundCount,0) as refundCount, isnull(b.refundAmount,0) as refundAmount,isnull(c.afterAmount,0) as afterAmount,isnull(c.afterCount,0) as afterCount from " +
  9166. "(select ID from CE_ErpUser where ID = {0}) d " +
  9167. "left join " +
  9168. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  9169. ") a on d.ID = a.id left join " +
  9170. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  9171. ") b on a.id = b.id1 left join" +
  9172. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  9173. ") c on a.id = c.id2;", userId);
  9174. }
  9175. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9176. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9177. }
  9178. public void get_date_area_total_data2()
  9179. {
  9180. int userId = CurrentUser.UserID;
  9181. string date_type = GetPostString("timetype");
  9182. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9183. string sql = "";
  9184. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9185. {
  9186. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  9187. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  9188. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9189. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9190. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9191. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  9192. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9193. ") a on e.ID = a.id left join " +
  9194. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9195. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9196. ") b on a.id = b.id1 " +
  9197. "left join " +
  9198. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9199. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9200. ") c on a.id = c.id2 " +
  9201. "left join " +
  9202. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9203. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9204. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9205. }
  9206. else
  9207. {
  9208. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9209. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9210. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9211. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9212. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9213. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9214. ") a on e.ID = a.id left join " +
  9215. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9216. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9217. ") c on a.id = c.id2 " +
  9218. "left join " +
  9219. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9220. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9221. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9222. }
  9223. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9224. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9225. }
  9226. public void get_date_area_total_data()
  9227. {
  9228. int userId = CurrentUser.UserID;
  9229. string date_type = GetPostString("timetype");
  9230. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9231. string date1 = searchDT[0].ToString();
  9232. string date2 = searchDT[1].ToString();
  9233. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9234. {
  9235. SqlParameter[] sqlParameter ={
  9236. new SqlParameter("@userId", SqlDbType.Int,4),
  9237. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9238. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9239. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9240. };
  9241. sqlParameter[0].Value = userId;
  9242. sqlParameter[1].Value = date1;
  9243. sqlParameter[2].Value = date2;
  9244. sqlParameter[3].Direction = ParameterDirection.Output;
  9245. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9246. string res = sqlParameter[3].Value.ToString();
  9247. var res_obj = new
  9248. {
  9249. data = res
  9250. };
  9251. string ro_json = JsonConvert.SerializeObject(res_obj);
  9252. returnSuccess(ro_json);
  9253. }
  9254. else
  9255. {
  9256. SqlParameter[] sqlParameter ={
  9257. new SqlParameter("@userId", SqlDbType.Int,4),
  9258. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9259. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9260. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9261. };
  9262. sqlParameter[0].Value = userId;
  9263. sqlParameter[1].Value = date1;
  9264. sqlParameter[2].Value = date2;
  9265. sqlParameter[3].Direction = ParameterDirection.Output;
  9266. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9267. string res = sqlParameter[3].Value.ToString();
  9268. var res_obj = new
  9269. {
  9270. data = res
  9271. };
  9272. string ro_json = JsonConvert.SerializeObject(res_obj);
  9273. returnSuccess(ro_json);
  9274. }
  9275. //writeGridDataViewJson(dt.Rows.Count, dv);
  9276. }
  9277. public void get_order_list()
  9278. {
  9279. string strFields = GetPostString("paraFields");
  9280. string strOrder = GetPostString("paraOrder");
  9281. string strWhere = GetPostString("paraWhere");
  9282. string strPageSize = GetPostString("paraPageSize");
  9283. DataStruct dStruct = GetPostStruct();
  9284. dStruct.PageSize = int.Parse(strPageSize);
  9285. dStruct.Fileds = strFields;
  9286. dStruct.Order = strOrder;
  9287. dStruct.MainWhere = strWhere;
  9288. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9289. writeGridDataTableJson(dStruct.TotalCount, dt);
  9290. }
  9291. ////获取待开始订单列表
  9292. //public void get_wait_design_order_list()
  9293. //{
  9294. // string date_type = GetPostString("date_type");
  9295. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9296. // DataStruct dStruct = GetPostStruct();
  9297. // dStruct.PageSize = 1000;
  9298. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9299. // List<string> lw = new List<string>();
  9300. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9301. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9302. // dStruct.Order = "WaitDesignTime asc";
  9303. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9304. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9305. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9306. //}
  9307. //获取完成单量排名
  9308. public void get_finish_order_count_ranking()
  9309. {
  9310. /* string date_type = GetPostString("date_type");
  9311. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9312. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9313. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9314. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9315. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9316. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9317. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9318. writeGridDataTableJson(0, new DataTable());
  9319. }
  9320. public void get_finish_order_amount_ranking()
  9321. {
  9322. /*string date_type = GetPostString("date_type");
  9323. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9324. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9325. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9326. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9327. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9328. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9329. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9330. writeGridDataTableJson(0, new DataTable());
  9331. }
  9332. public void get_finish_refund_count_ranking()
  9333. {
  9334. string date_type = GetPostString("date_type");
  9335. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9336. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9337. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9338. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9339. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9340. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9341. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9342. writeGridDataTableJson(dt.Rows.Count, dt);
  9343. }
  9344. public void get_finish_refund_amount_ranking()
  9345. {
  9346. string date_type = GetPostString("date_type");
  9347. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9348. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9349. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9350. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9351. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9352. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9353. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9354. writeGridDataTableJson(dt.Rows.Count, dt);
  9355. }
  9356. public void set_erp_finishorder_director()
  9357. {
  9358. if (UrlPostParmsCheck("ctid"))
  9359. {
  9360. string eid = GetPostString("ctid");
  9361. CeErpTradeCell entity = null;
  9362. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9363. if (entity != null)
  9364. {
  9365. entity.OrderState = 8;
  9366. entity.Update();
  9367. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9368. returnSuccessMsg("操作成功!");
  9369. return;
  9370. }
  9371. returnErrorMsg("找不到记录");
  9372. }
  9373. }
  9374. public void get_erp_placeregistlist()
  9375. {
  9376. DataStruct dStruct = GetPostStruct();
  9377. List<string> lw = new List<string>();
  9378. string outsid = GetPostString("outsid");
  9379. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9380. string memo = GetPostString("memo");
  9381. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9382. string filename = GetPostString("filename");
  9383. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9384. string islate = GetPostString("islate");
  9385. if (islate.Length > 0)
  9386. {
  9387. if (islate == "1")
  9388. lw.Add(string.Format("OutLate>0"));
  9389. else
  9390. lw.Add(string.Format("OutLate=0"));
  9391. }
  9392. string placedate1 = GetPostString("placedate1");
  9393. string placedate2 = GetPostString("placedate2");
  9394. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9395. if (dw.Length > 0) lw.Add(dw);
  9396. string deliveryDate1 = GetPostString("deliverydate1");
  9397. string deliveryDate2 = GetPostString("deliverydate2");
  9398. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9399. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9400. dStruct.Order = "ID desc";
  9401. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9402. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9403. writeGridDataTableJson(dStruct.TotalCount, dt);
  9404. }
  9405. public void ins_erp_placeregist()
  9406. {
  9407. if (UrlPostParmsCheck("id"))
  9408. {
  9409. string eid = GetPostString("id");
  9410. CeErpPlaceRegister entity = null;
  9411. if (eid == "0")//新增
  9412. {
  9413. entity = new CeErpPlaceRegister();
  9414. string xdTime = GetPostString("placeTime");
  9415. if (xdTime.Length > 0)
  9416. {
  9417. entity.PlactTime = Convert.ToDateTime(xdTime);
  9418. }
  9419. string fhTime = GetPostString("deliveryTime");
  9420. if (fhTime.Length > 0)
  9421. {
  9422. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9423. }
  9424. string preTime = GetPostString("preOutTime");
  9425. if (preTime.Length > 0)
  9426. {
  9427. entity.PreOutTime = Convert.ToDateTime(preTime);
  9428. }
  9429. entity.DeliveryCount = GetPostInt("deliveryCount");
  9430. entity.ReceiveCount = GetPostInt("receiveCount");
  9431. entity.OutSid = GetPostString("outSid");
  9432. entity.FileName = GetPostString("fileName");
  9433. entity.Memo = GetPostString("memo");
  9434. entity.AddUserId = CurrentUser.UserID;
  9435. entity.CreateTime = DateTime.Now;
  9436. entity.Img = GetPostString("img");
  9437. entity.Supplier = GetPostInt("supplier");
  9438. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9439. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9440. {
  9441. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9442. DateTime dt2 = (DateTime)entity.PreOutTime;
  9443. TimeSpan span = dt1.Subtract(dt2);
  9444. if (span.Days > 0)
  9445. {
  9446. entity.OutLate = span.Days;
  9447. }
  9448. }
  9449. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9450. entity.Create();
  9451. returnSuccessMsg("添加成功!");
  9452. return;
  9453. }
  9454. else //修改
  9455. {
  9456. entity = CeErpPlaceRegister.Get(eid);
  9457. if (entity != null)
  9458. {
  9459. string xdTime = GetPostString("placeTime");
  9460. if (xdTime.Length > 0)
  9461. {
  9462. entity.PlactTime = Convert.ToDateTime(xdTime);
  9463. }
  9464. string fhTime = GetPostString("deliveryTime");
  9465. if (fhTime.Length > 0)
  9466. {
  9467. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9468. }
  9469. string preTime = GetPostString("preOutTime");
  9470. if (preTime.Length > 0)
  9471. {
  9472. entity.PreOutTime = Convert.ToDateTime(preTime);
  9473. }
  9474. entity.DeliveryCount = GetPostInt("deliveryCount");
  9475. entity.ReceiveCount = GetPostInt("receiveCount");
  9476. if (entity.DeliveryCount == entity.ReceiveCount)
  9477. {
  9478. entity.CurState = "已完成";
  9479. }
  9480. else
  9481. {
  9482. entity.CurState = "未完成";
  9483. }
  9484. entity.OutSid = GetPostString("outSid");
  9485. entity.FileName = GetPostString("fileName");
  9486. entity.Memo = GetPostString("memo");
  9487. entity.Img = GetPostString("img");
  9488. entity.Supplier = GetPostInt("supplier");
  9489. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9490. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9491. {
  9492. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9493. DateTime dt2 = (DateTime)entity.PreOutTime;
  9494. TimeSpan span = dt1.Subtract(dt2);
  9495. if (span.Days > 0)
  9496. {
  9497. entity.OutLate = span.Days;
  9498. }
  9499. }
  9500. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9501. entity.Update();
  9502. returnSuccessMsg("修改成功");
  9503. return;
  9504. }
  9505. returnErrorMsg("找不到对应的记录");
  9506. return;
  9507. }
  9508. }
  9509. returnErrorMsg("缺少必要参数");
  9510. }
  9511. public void del_erp_placeregist()
  9512. {
  9513. string eid = GetPostString("id");
  9514. CeErpPlaceRegister.Del(eid);
  9515. returnSuccessMsg("删除成功!");
  9516. return;
  9517. }
  9518. public void ins_erp_placeregistbyorder()
  9519. {
  9520. string ctid = GetPostString("ctid");
  9521. if (ctid.Length > 0)
  9522. {
  9523. StringBuilder sql = new StringBuilder();
  9524. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9525. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9526. if (dt.Rows.Count > 0)
  9527. {
  9528. foreach (DataRow dr in dt.Rows)
  9529. {
  9530. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9531. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9532. entity.AddUserId = CurrentUser.UserID;
  9533. entity.tid = dr["tid"].ToString();
  9534. entity.Did = Convert.ToString(dr["ctid"]);
  9535. entity.splitTag = dr["SplitTag"].ToString();
  9536. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9537. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9538. if (pre_ctid.Length > 0)
  9539. {
  9540. sellmemo = sellmemo.Replace(pre_ctid, "");
  9541. }
  9542. sellmemo = sellmemo.Replace("[", "");
  9543. sellmemo = sellmemo.Replace("]", "");
  9544. entity.FileName = sellmemo;
  9545. string count = dr["ProductCount"].ToString();
  9546. int usecount = commonHelper.getIntCountFromString(count);
  9547. entity.DeliveryCount = usecount;
  9548. entity.CurState = "未完成";
  9549. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9550. {
  9551. entity.Supplier = 24;//dl手提袋定制
  9552. }
  9553. else
  9554. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9555. entity.CreateTime = DateTime.Now;
  9556. entity.Create();
  9557. }
  9558. returnSuccessMsg("操作成功");
  9559. return;
  9560. }
  9561. returnErrorMsg("没有找到对应订单");
  9562. return;
  9563. }
  9564. returnErrorMsg("缺少订单编号");
  9565. return;
  9566. }
  9567. public void get_erp_persuadelist()
  9568. {
  9569. DataStruct dStruct = GetPostStruct();
  9570. List<string> lw = new List<string>();
  9571. string ctid = GetPostString("ctid");
  9572. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9573. string shopname = GetPostString("shopname");
  9574. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9575. string buyernick = GetPostString("buyer_nick");
  9576. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9577. string customer = GetPostString("customer");
  9578. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9579. string returndate1 = GetPostString("returndate1");
  9580. string returndate2 = GetPostString("returndate2");
  9581. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9582. if (dw.Length > 0) lw.Add(dw);
  9583. string finishDate1 = GetPostString("finishdate1");
  9584. string finishDate2 = GetPostString("finishdate2");
  9585. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9586. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9587. string persuadetype = GetPostString("persuadetype");
  9588. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9589. string returnvstate = GetPostString("returnvstate");
  9590. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9591. dStruct.Order = "created desc";
  9592. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9593. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9594. writeGridDataTableJson(dStruct.TotalCount, dt);
  9595. }
  9596. public void upd_erp_returnpersuadeback()
  9597. {
  9598. if (UrlPostParmsCheck("ID"))
  9599. {
  9600. int eid = GetPostInt("ID");
  9601. CeErpPersuade entity = null;
  9602. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9603. if (entity != null)
  9604. {
  9605. entity.backreason = GetPostString("reason");
  9606. entity.pstate = 2;
  9607. entity.verifytime = DateTime.Now;
  9608. entity.verifyuserid = CurrentUser.UserID;
  9609. entity.Update();
  9610. returnSuccessMsg("退回成功!");
  9611. return;
  9612. }
  9613. returnErrorMsg("找不到订单记录");
  9614. }
  9615. }
  9616. public void upd_erp_returnpersuadeverify()
  9617. {
  9618. if (UrlPostParmsCheck("ID"))
  9619. {
  9620. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9621. {
  9622. returnErrorMsg("暂无权限审核");
  9623. return;
  9624. }
  9625. int eid = GetPostInt("ID");
  9626. CeErpPersuade entity = null;
  9627. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9628. if (entity != null)
  9629. {
  9630. entity.pstate = 1;
  9631. entity.verifytime = DateTime.Now;
  9632. entity.verifyuserid = CurrentUser.UserID;
  9633. entity.Update();
  9634. returnSuccessMsg("审核成功!");
  9635. return;
  9636. }
  9637. returnErrorMsg("找不到订单记录");
  9638. }
  9639. }
  9640. public void del_erp_persuade()
  9641. {
  9642. if (UrlPostParmsCheck("ID"))
  9643. {
  9644. int eid = GetPostInt("ID");
  9645. CeErpPersuade.Del(eid);
  9646. returnSuccessMsg("操作成功");
  9647. return;
  9648. }
  9649. }
  9650. public void get_erp_oldcustoupload()
  9651. {
  9652. DataStruct dStruct = GetPostStruct();
  9653. List<string> lw = new List<string>();
  9654. string buyernick = GetPostString("buyer_nick");
  9655. if (buyernick.Length > 0)
  9656. {
  9657. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9658. }
  9659. else
  9660. return;
  9661. dStruct.Order = "pay_time desc";
  9662. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9663. DataTable dt = null;
  9664. dt = WebCache.GetData("view_erptradecell", dStruct);
  9665. writeGridDataTableJson(dStruct.TotalCount, dt);
  9666. }
  9667. public void get_erp_checkorderlist()
  9668. {
  9669. DataStruct dStruct = GetPostStruct();
  9670. List<string> lw = new List<string>();
  9671. string tid = GetPostString("ctid");
  9672. if (tid.Length > 0)
  9673. {
  9674. string select_tid = getTidByCtid(tid);
  9675. lw.Add(string.Format("tid='{0}'", select_tid));
  9676. }
  9677. string shopname = GetPostString("shopname");
  9678. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9679. string buyernick = GetPostString("buyer_nick");
  9680. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9681. string customer = GetPostString("customer");
  9682. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9683. string design = GetPostString("design");
  9684. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9685. string orderState = GetPostString("orderState");
  9686. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9687. string address = GetPostString("address");
  9688. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9689. string sellermemo = GetPostString("seller_memo");
  9690. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9691. string supplier = GetPostString("supplier");
  9692. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9693. {
  9694. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9695. }
  9696. else
  9697. {
  9698. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9699. }
  9700. string date1 = GetPostString("date1");
  9701. string date2 = GetPostString("date2");
  9702. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9703. if (dw.Length > 0) lw.Add(dw);
  9704. string placedate1 = GetPostString("placedate1");
  9705. string placedate2 = GetPostString("placedate2");
  9706. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9707. if (fdw.Length > 0) lw.Add(fdw);
  9708. string price1 = GetPostString("price1");
  9709. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9710. string price2 = GetPostString("price2");
  9711. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9712. string checkst = GetPostString("checkstate");
  9713. if (checkst.Length > 0 && "10".Equals(checkst))
  9714. {
  9715. lw.Add(string.Format("CheckOut>0"));
  9716. }
  9717. else
  9718. {
  9719. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9720. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9721. }
  9722. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9723. {
  9724. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9725. }
  9726. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9727. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9728. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9729. writeGridDataTableJson(dStruct.TotalCount, dt);
  9730. }
  9731. public void ins_erp_startCheck()
  9732. {
  9733. if (UrlPostParmsCheck("ctid"))
  9734. {
  9735. string eid = GetPostString("ctid");
  9736. CeErpTradeCell entity = null;
  9737. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9738. if (entity != null)
  9739. {
  9740. entity.MemoOpt = 4;
  9741. entity.UpdateTime = DateTime.Now;
  9742. entity.Update();
  9743. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9744. CeErpSukuraData.createInfo(entity.ctid, 6);
  9745. returnSuccessMsg("操作成功!");
  9746. return;
  9747. }
  9748. returnErrorMsg("找不到记录");
  9749. }
  9750. }
  9751. public void upd_erp_sendXlw()
  9752. {
  9753. if (UrlPostParmsCheck("ctid"))
  9754. {
  9755. string eid = GetPostString("ctid");
  9756. CeErpTradeCell entity = null;
  9757. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9758. if (entity != null)
  9759. {
  9760. if (entity.IsSendGift == 1)
  9761. {
  9762. returnErrorMsg("请勿重复标记");
  9763. return;
  9764. }
  9765. entity.IsSendGift = 1;
  9766. entity.Update();
  9767. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9768. returnSuccessMsg("操作成功!");
  9769. return;
  9770. }
  9771. returnErrorMsg("找不到记录");
  9772. }
  9773. }
  9774. public void cancel_sendXlw()
  9775. {
  9776. if (UrlPostParmsCheck("ctid"))
  9777. {
  9778. string eid = GetPostString("ctid");
  9779. CeErpTradeCell entity = null;
  9780. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9781. if (entity != null)
  9782. {
  9783. if (entity.IsSendGift == 0)
  9784. {
  9785. returnErrorMsg("未标记小礼物");
  9786. return;
  9787. }
  9788. entity.IsSendGift = 0;
  9789. entity.Update();
  9790. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9791. returnSuccessMsg("操作成功!");
  9792. return;
  9793. }
  9794. returnErrorMsg("找不到记录");
  9795. }
  9796. }
  9797. public void get_erp_designbill()
  9798. {
  9799. DataStruct dStruct = GetPostStruct();
  9800. List<string> lw = new List<string>();
  9801. int isMy = GetInt("my");
  9802. if (isMy == 1)
  9803. {
  9804. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9805. }
  9806. string tid = GetPostString("tid");
  9807. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9808. string userName = GetPostString("design");
  9809. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9810. string price1 = GetPostString("price1");
  9811. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9812. string price2 = GetPostString("price2");
  9813. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9814. string rePrice1 = GetPostString("rePrice1");
  9815. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9816. string rePrice2 = GetPostString("rePrice2");
  9817. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9818. string designerType = GetPostString("designerType");
  9819. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9820. string orderState = GetPostString("orderState");
  9821. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9822. string endTime1 = GetPostString("endTime1");
  9823. string endTime2 = GetPostString("endTime2");
  9824. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9825. if (dw.Length > 0) lw.Add(dw);
  9826. string isDk = GetPostString("isDk");
  9827. if (isDk == "1")
  9828. {
  9829. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9830. }
  9831. else if (isDk == "0")
  9832. {
  9833. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9834. }
  9835. dStruct.Order = "oid, create_time desc";
  9836. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9837. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9838. writeGridDataTableJson(dStruct.TotalCount, dt);
  9839. }
  9840. public void upd_erp_designerbill()
  9841. {
  9842. if (UrlPostParmsCheck("ID"))
  9843. {
  9844. string eid = GetPostString("ID");
  9845. CeErpDesignerBill entity = null;
  9846. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9847. if (entity != null)
  9848. {
  9849. if (GetPostDouble("designerpirce") > 0)
  9850. {
  9851. entity.realPrice = GetPostDouble("designerpirce");
  9852. entity.update_time = DateTime.Now;
  9853. entity.update_u_id = CurrentUser.UserID;
  9854. entity.update_u_name = CurrentUser.UserName;
  9855. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9856. entity.Update();
  9857. returnSuccessMsg("操作成功!");
  9858. return;
  9859. }
  9860. else
  9861. {
  9862. entity.price = GetPostDouble("price");
  9863. entity.update_time = DateTime.Now;
  9864. entity.update_u_id = CurrentUser.UserID;
  9865. entity.update_u_name = CurrentUser.UserName;
  9866. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9867. entity.Update();
  9868. returnSuccessMsg("操作成功!");
  9869. return;
  9870. }
  9871. }
  9872. returnErrorMsg("找不到记录");
  9873. }
  9874. }
  9875. public void audit_erp_designerbill()
  9876. {
  9877. if (UrlPostParmsCheck("ID"))
  9878. {
  9879. string eid = GetPostString("ID");
  9880. CeErpDesignerBill entity = null;
  9881. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9882. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9883. if (entity != null)
  9884. {
  9885. entity.realPrice = GetPostDouble("designerpirce");
  9886. entity.update_time = DateTime.Now;
  9887. entity.update_u_id = CurrentUser.UserID;
  9888. entity.update_u_name = CurrentUser.UserName;
  9889. entity.isAudit = 1;
  9890. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9891. entity.Update();
  9892. if (orderEntity != null)
  9893. {
  9894. orderEntity.IsReadTag = 3;
  9895. orderEntity.Update();
  9896. }
  9897. returnSuccessMsg("操作成功!");
  9898. return;
  9899. }
  9900. returnErrorMsg("找不到记录");
  9901. }
  9902. }
  9903. public void all_audit_erp_designerbill()
  9904. {
  9905. if (UrlPostParmsCheck("idList"))
  9906. {
  9907. string[] list = GetPostString("idList").Split(',');
  9908. CeErpDesignerBill entity = null;
  9909. for (int i = 0; i < list.Length; i++)
  9910. {
  9911. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9912. if (entity == null) return;
  9913. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9914. if (orderEntity == null) return;
  9915. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9916. entity.update_time = DateTime.Now;
  9917. entity.update_u_id = CurrentUser.UserID;
  9918. entity.update_u_name = CurrentUser.UserName;
  9919. entity.isAudit = 1;
  9920. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9921. entity.Update();
  9922. orderEntity.IsReadTag = 3;
  9923. orderEntity.Update();
  9924. }
  9925. returnSuccessMsg("操作成功!");
  9926. return;
  9927. }
  9928. }
  9929. public void get_erp_sameorders()
  9930. {
  9931. if (UrlPostParmsCheck("ctid"))
  9932. {
  9933. string eid = GetPostString("ctid");
  9934. CeErpTradeCell entity = null;
  9935. entity = CeErpTradeCell.GetByCtid(eid);
  9936. if (entity != null)
  9937. {
  9938. StringBuilder sql = new StringBuilder();
  9939. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9940. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9941. var res = new
  9942. {
  9943. data = dt.Rows.Count
  9944. };
  9945. string ro_jsond = JsonConvert.SerializeObject(res);
  9946. returnSuccess(ro_jsond);
  9947. return;
  9948. }
  9949. returnErrorMsg("未找到订单");
  9950. return;
  9951. }
  9952. returnErrorMsg("缺少必要的参数");
  9953. }
  9954. public void get_erp_islasthavesameorder()
  9955. {
  9956. if (UrlPostParmsCheck("ctid"))
  9957. {
  9958. string eid = GetPostString("ctid");
  9959. string[] ctidList = eid.Split(',');
  9960. StringBuilder sql = new StringBuilder();
  9961. string tisCtid = "";
  9962. foreach (string ctid in ctidList)
  9963. {
  9964. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9965. if (entity != null)
  9966. {
  9967. sql = new StringBuilder();
  9968. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9969. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9970. if (dth.Rows.Count > 0)
  9971. {
  9972. tisCtid += entity.ctid;
  9973. tisCtid += ",";
  9974. }
  9975. }
  9976. }
  9977. if (tisCtid.Length > 0)
  9978. {
  9979. var res = new
  9980. {
  9981. data = tisCtid
  9982. };
  9983. string ro_jsond = JsonConvert.SerializeObject(res);
  9984. returnSuccess(ro_jsond);
  9985. }
  9986. else
  9987. {
  9988. var res = new
  9989. {
  9990. data = ""
  9991. };
  9992. string ro_jsond = JsonConvert.SerializeObject(res);
  9993. returnSuccess(ro_jsond);
  9994. }
  9995. return;
  9996. }
  9997. returnErrorMsg("缺少必要的参数");
  9998. }
  9999. public void file_client_down_url()
  10000. {
  10001. if (!UrlPostParmsCheck("userId"))
  10002. {
  10003. returnErrorMsg("缺少必要的参数");
  10004. }
  10005. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  10006. }
  10007. public void checkout_form_data()
  10008. {
  10009. if (!UrlPostParmsCheck("tid"))
  10010. {
  10011. returnErrorMsg("缺少必要的参数");
  10012. }
  10013. string tid = GetPostString("tid");
  10014. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  10015. if (ceErpOrderFormData != null)
  10016. {
  10017. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  10018. returnSuccess(ro_jsond);
  10019. return;
  10020. }
  10021. returnErrorMsg("尚未有文件!");
  10022. }
  10023. public void back_supplier_audit()
  10024. {
  10025. int userId = CurrentUser.UserID;
  10026. StringBuilder sql = new StringBuilder();
  10027. sql.AppendFormat("SELECT D.tid FROM CE_ErpUser A LEFT JOIN view_ErpUserPost B ON A.ID = B.UserID LEFT JOIN CE_ErpUserInfo C ON A.InfoID = C.ID LEFT JOIN CE_Withdraw D ON A.pemVend = D.providerid WHERE a.ID ='{0}' and d.status = 3;", userId);
  10028. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10029. if (dt.Rows.Count > 0)
  10030. {
  10031. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10032. }
  10033. else
  10034. {
  10035. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10036. }
  10037. }
  10038. public void back_supplier_query()
  10039. {
  10040. string eid = GetPostString("ctid");
  10041. if (eid != "")
  10042. {
  10043. StringBuilder sql = new StringBuilder();
  10044. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  10045. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10046. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10047. }
  10048. else
  10049. {
  10050. returnErrorMsg("找不到订单记录");
  10051. return;
  10052. }
  10053. }
  10054. public void verified_to_order()
  10055. {
  10056. int userId = CurrentUser.UserID;
  10057. StringBuilder sql = new StringBuilder();
  10058. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  10059. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10060. if (dt.Rows.Count > 0)
  10061. {
  10062. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10063. }
  10064. else
  10065. {
  10066. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10067. }
  10068. }
  10069. public void upd_supplier_audit()
  10070. {
  10071. if (UrlPostParmsCheck("ctid"))
  10072. {
  10073. string eid = GetPostString("ctid");
  10074. string reason = GetPostString("returnreason");
  10075. CeErpTradeCell entity = null;
  10076. CeWithdraw withdraw = null;
  10077. withdraw = CeWithdraw.GetByTid(eid);
  10078. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  10079. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  10080. {
  10081. if (withdraw != null)
  10082. {
  10083. if (!withdraw.userid.Equals(CurrentUser.UserID))
  10084. {
  10085. returnSuccessMsg("您没有权限操作!");
  10086. return;
  10087. }
  10088. else
  10089. {
  10090. if (reason.Equals("1"))
  10091. {
  10092. if (entity.OrderState == -1)
  10093. {
  10094. if (entity.FinishPlaceTime == null)
  10095. {
  10096. entity.OrderState = 2;
  10097. }
  10098. else
  10099. {
  10100. entity.OrderState = 6;
  10101. }
  10102. //配件单直接到下单部
  10103. if(entity.IsSample == 4)
  10104. {
  10105. entity.OrderState = 5;
  10106. }
  10107. }
  10108. entity.Update();
  10109. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10110. if (withdraw != null)
  10111. {
  10112. withdraw.status = int.Parse(reason);
  10113. withdraw.Update();
  10114. }
  10115. returnSuccessMsg("操作成功!");
  10116. return;
  10117. }
  10118. else
  10119. {
  10120. withdraw.status = int.Parse(reason);
  10121. withdraw.acknowledgingtime = DateTime.Now;
  10122. withdraw.Update();
  10123. returnSuccessMsg("查看详细请点击线下订单查询");
  10124. return;
  10125. }
  10126. }
  10127. }
  10128. // 第一个字符是 'N'
  10129. }
  10130. if (eid[0] != 'N')
  10131. {
  10132. }
  10133. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  10134. {
  10135. entity.IsVerifyToSupplier = false;
  10136. entity.IsReturn = 1;
  10137. entity.ReturnTime = DateTime.Now;
  10138. entity.ReturnReason = reason;
  10139. if (entity.OrderState == 6)
  10140. {
  10141. entity.OrderState = 5;
  10142. }
  10143. entity.Update();
  10144. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  10145. if (withdraw != null)
  10146. {
  10147. withdraw.status = int.Parse(reason);
  10148. withdraw.Update();
  10149. }
  10150. returnSuccessMsg("操作成功!");
  10151. return;
  10152. }
  10153. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  10154. {
  10155. ;
  10156. if (withdraw != null)
  10157. {
  10158. withdraw.status = int.Parse(reason);
  10159. withdraw.acknowledgingtime = DateTime.Now;
  10160. withdraw.Update();
  10161. returnSuccessMsg("供应商取消撤回!");
  10162. return;
  10163. }
  10164. }
  10165. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  10166. {
  10167. if (entity.OrderState == -1)
  10168. {
  10169. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  10170. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10171. if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  10172. {
  10173. returnErrorMsg("台湾客户需填写身份证!");
  10174. return;
  10175. }
  10176. if (commonHelper.isFarAddress(ceErpTrade.receiver_state) && ceErpTrade.delivery_paymant == 0 && entity.IsSF != 2)
  10177. {
  10178. returnErrorMsg("偏远地区需要填写物流费!");
  10179. return;
  10180. }
  10181. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  10182. {
  10183. returnErrorMsg("订单spu没有确认无法通过审核!");
  10184. return;
  10185. }
  10186. if (entity.FinishPlaceTime == null)
  10187. {
  10188. entity.OrderState = 2;
  10189. }
  10190. else
  10191. {
  10192. entity.OrderState = 3;
  10193. }
  10194. commonHelper.getCytPrice(entity);
  10195. if ((entity.OtherMemo.Contains("老客户") || entity.OtherMemo.Contains("老顾客")) && entity.OtherMemo.Contains("改稿"))
  10196. {
  10197. tmcHelper.dealOldCustomerEntityTag(ref entity, ceErpTrade);
  10198. }
  10199. if (entity.IsSample > 1 || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物"))
  10200. {
  10201. entity.OrderState = 6;
  10202. }
  10203. if (entity.IsSample == 4)
  10204. {
  10205. entity.OrderState = 5;
  10206. }
  10207. }
  10208. entity.Update();
  10209. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10210. if (withdraw != null)
  10211. {
  10212. withdraw.status = int.Parse(reason);
  10213. withdraw.Update();
  10214. }
  10215. returnSuccessMsg("操作成功!");
  10216. return;
  10217. }
  10218. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10219. {
  10220. if (withdraw == null)
  10221. {
  10222. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10223. return;
  10224. }
  10225. }
  10226. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10227. {
  10228. if (withdraw != null)
  10229. {
  10230. withdraw.status = int.Parse(reason);
  10231. withdraw.acknowledgingtime = DateTime.Now;
  10232. withdraw.Update();
  10233. returnSuccessMsg("查看详细请点击线下订单查询");
  10234. return;
  10235. }
  10236. }
  10237. return;
  10238. }
  10239. }
  10240. //校验报价
  10241. public void refund_order_tip()
  10242. {
  10243. int userid = CurrentUser.UserID;
  10244. int sectionId = CurrentUser.UserPost.OrgID;
  10245. StringBuilder sql = new StringBuilder();
  10246. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10247. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10248. List<string> ids = new List<string>();
  10249. if (dth.Rows.Count > 0)
  10250. {
  10251. foreach (DataRow dr in dth.Rows)
  10252. {
  10253. ids.Add(dr["ID"].ToString());
  10254. }
  10255. try
  10256. {
  10257. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10258. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10259. }
  10260. catch (Exception ex)
  10261. {
  10262. }
  10263. }
  10264. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10265. }
  10266. public void refund_order_Design()
  10267. {
  10268. int userid = CurrentUser.UserID;
  10269. int sectionId = CurrentUser.UserPost.OrgID;
  10270. StringBuilder sql = new StringBuilder();
  10271. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10272. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10273. List<string> ids = new List<string>();
  10274. if (dth.Rows.Count > 0)
  10275. {
  10276. foreach (DataRow dr in dth.Rows)
  10277. {
  10278. ids.Add(dr["ID"].ToString());
  10279. }
  10280. try
  10281. {
  10282. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10283. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10284. }
  10285. catch (Exception ex)
  10286. {
  10287. }
  10288. }
  10289. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10290. }
  10291. public void change_order_info()
  10292. {
  10293. int userid = CurrentUser.UserID;
  10294. StringBuilder sql = new StringBuilder();
  10295. sql.AppendFormat("select top 1 c.*,o.seller_memo as seller_memo from CE_ErpMessageTip c left join CE_ErpTradeCell o on o.ctid = c.tid where (c.userId = '{0}' ) and c.isVisit = 0 and c.type = 2;", userid);
  10296. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10297. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10298. }
  10299. public void size_order_tip()
  10300. {
  10301. int userid = CurrentUser.UserID;
  10302. StringBuilder sql = new StringBuilder();
  10303. sql.AppendFormat("select top 1 * from CE_ErpMessageTip c where (c.userId = '{0}' ) and c.isVisit = 0 and c.type in (3,4);", userid);
  10304. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10305. List<string> ids = new List<string>();
  10306. if (dth.Rows.Count > 0)
  10307. {
  10308. foreach (DataRow dr in dth.Rows)
  10309. {
  10310. ids.Add(dr["ID"].ToString());
  10311. }
  10312. try
  10313. {
  10314. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10315. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10316. }
  10317. catch (Exception ex)
  10318. {
  10319. }
  10320. }
  10321. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10322. }
  10323. public void change_win_mome()
  10324. {
  10325. if (UrlPostParmsCheck("id,ctid"))
  10326. {
  10327. string id = GetPostString("id");
  10328. string ctid = GetPostString("ctid");
  10329. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10330. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10331. if (ce == null || ceErpMessageTip == null)
  10332. {
  10333. returnSuccessMsg("未找到对应的订单!");
  10334. return;
  10335. }
  10336. if (ce.OrderState >= 5)
  10337. {
  10338. ceErpMessageTip.isVisit = true;
  10339. ceErpMessageTip.Update();
  10340. returnSuccessMsg("已上传文件无法修改!");
  10341. return;
  10342. }
  10343. int type = GetPostInt("type");
  10344. string content = GetPostString("content");
  10345. if (type == 0)
  10346. {
  10347. content = content.Replace("(", "(");
  10348. content = content.Replace(")", ")");
  10349. string check = MidStrEx(content, "(", ")").Trim();
  10350. if (string.IsNullOrEmpty(check))
  10351. {
  10352. returnSuccessMsg("文件名格式不正确");
  10353. return;
  10354. }
  10355. }
  10356. ce.seller_memo = content;
  10357. ce.Update();
  10358. ceErpMessageTip.isVisit = true;
  10359. ceErpMessageTip.Update();
  10360. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10361. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10362. ApiVo apiVo = new ApiVo();
  10363. apiVo.orderNumber = ce.ctid;
  10364. apiVo.actionName = "demandDesign";
  10365. apiVo.orderRemarks = content;
  10366. apiVo.demandExamine = type + 1;
  10367. designHelper.API_WorkCore(apiVo);//demandDesign
  10368. returnSuccessMsg("修改成功!");
  10369. }
  10370. }
  10371. public static string MidStrEx(string sourse, string startstr, string endstr)
  10372. {
  10373. string result = string.Empty;
  10374. int startindex, endindex;
  10375. try
  10376. {
  10377. startindex = sourse.IndexOf(startstr);
  10378. if (startindex == -1)
  10379. return result;
  10380. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10381. endindex = tmpstr.IndexOf(endstr);
  10382. if (endindex == -1)
  10383. return result;
  10384. result = tmpstr.Remove(endindex);
  10385. }
  10386. catch (Exception ex)
  10387. {
  10388. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10389. }
  10390. return result;
  10391. }
  10392. public void refund_order_list()
  10393. {
  10394. int userid = CurrentUser.UserID;
  10395. int sectionId = CurrentUser.UserPost.OrgID;
  10396. StringBuilder sql = new StringBuilder();
  10397. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10398. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10399. DataStruct dStruct = GetPostStruct();
  10400. DataTable dt = null;
  10401. List<string> ids = new List<string>();
  10402. List<string> tids = new List<string>();
  10403. if (dth.Rows.Count > 0)
  10404. {
  10405. foreach (DataRow dr in dth.Rows)
  10406. {
  10407. tids.Add("'" + dr["tid"].ToString() + "'");
  10408. ids.Add(dr["id"].ToString());
  10409. }
  10410. try
  10411. {
  10412. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10413. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10414. List<string> lw = new List<string>();
  10415. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10416. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10417. dt = WebCache.GetData("view_orderlist", dStruct);
  10418. }
  10419. catch (Exception ex)
  10420. {
  10421. }
  10422. }
  10423. writeGridDataTableJson(dStruct.TotalCount, dt);
  10424. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10425. }
  10426. //新增
  10427. public void order_batch_downloads()
  10428. {
  10429. string ceid = GetPostString("tid");
  10430. String[] tid = ceid.Split(',');
  10431. order_batch_caiyingtong(tid);
  10432. /* (string success, string errors) = UploadFiles(tid);
  10433. returnSuccessMsg(success + errors);*/
  10434. return;
  10435. }
  10436. //报价接口
  10437. public void Get_To_Quote()
  10438. {
  10439. string ceid = GetPostString("ctid");
  10440. if (ceid != null)
  10441. {
  10442. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10443. if (entity != null)
  10444. {
  10445. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10446. {
  10447. return;
  10448. }
  10449. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10450. double price = 0;
  10451. if (cp == null)
  10452. {
  10453. JObject jsonObject12 = new JObject
  10454. {
  10455. { "UserId", "77886" },
  10456. { "Pwd", "lt666888" },
  10457. { "Filename", entity.seller_memo }
  10458. };
  10459. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10460. JObject jsonObjects1 = JObject.Parse(response1);
  10461. string ms1g = (string)jsonObjects1["msg"];
  10462. if (ms1g == "报价成功")
  10463. {
  10464. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10465. string data = (string)jsonObject1["price"];
  10466. string sql_pay = "INSERT INTO CE_CaiYingTongLog (ctid, ctime,type,msg) VALUES ('" + entity.ctid + "', '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + 2 + ",'" + data + "');";
  10467. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10468. returnSuccessMsg("获取报价成功:" + data);
  10469. price = Convert.ToDouble(data);
  10470. }
  10471. else
  10472. {
  10473. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10474. return;
  10475. }
  10476. }
  10477. String[] beizhu = entity.seller_memo.Split('-');
  10478. String chanp = "";
  10479. if (beizhu.Length > 0)
  10480. {
  10481. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10482. }
  10483. else
  10484. {
  10485. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10486. }
  10487. JObject jsonObject = new JObject
  10488. {
  10489. { "UserId", "77886" },
  10490. { "Pwd", "lt666888" },
  10491. { "Filename", chanp }
  10492. };
  10493. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10494. JObject jsonObjects = JObject.Parse(response);
  10495. string msg = (string)jsonObjects["msg"];
  10496. if (msg == "报价成功")
  10497. {
  10498. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10499. string data = (string)jsonObject1["price"];
  10500. string sql_pay = "INSERT INTO CE_CaiYingTongLog (ctid, ctime,type,msg) VALUES ('" + entity.ctid + "', '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + 2 + ",'" + data + "');";
  10501. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10502. returnSuccessMsg("获取报价成功:" + data);
  10503. price = Convert.ToDouble(data);
  10504. }
  10505. else
  10506. {
  10507. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10508. return;
  10509. }
  10510. if (price > 0)
  10511. {
  10512. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10513. if (ceErpTradeCellExtend == null)
  10514. {
  10515. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10516. ceErpTradeCellExtend.ctid = entity.ctid;
  10517. ceErpTradeCellExtend.payment_cyt = price;
  10518. ceErpTradeCellExtend.Create();
  10519. }
  10520. else
  10521. {
  10522. ceErpTradeCellExtend.payment_cyt = price;
  10523. ceErpTradeCellExtend.Update();
  10524. }
  10525. }
  10526. return;
  10527. }
  10528. }
  10529. else
  10530. {
  10531. returnErrorMsg("请至少选择一条数据");
  10532. return;
  10533. }
  10534. }
  10535. //新增
  10536. public void order_To_Supplier()
  10537. {
  10538. string ceid = GetPostString("tid");
  10539. String[] tid = ceid.Split(',');
  10540. if (tid.Length > 0)
  10541. {
  10542. try
  10543. {
  10544. for (int i = 0; i < tid.Length; i++)
  10545. {
  10546. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10547. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10548. entity.SupplierId = suid;
  10549. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10550. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10551. entity.Update();
  10552. }
  10553. }
  10554. catch (Exception ex)
  10555. {
  10556. returnErrorMsg("自动匹配供应商失败");
  10557. return;
  10558. }
  10559. }
  10560. else
  10561. {
  10562. returnErrorMsg("请至少选择一条数据");
  10563. return;
  10564. }
  10565. returnSuccessMsg("自动匹配供应商成功");
  10566. return;
  10567. }
  10568. public (string, string) UploadFiles(string[] urls)
  10569. {
  10570. string success = "";
  10571. string errors = "";
  10572. int userid = CurrentUser.UserID;
  10573. foreach (string url in urls)
  10574. {
  10575. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10576. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10577. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10578. {
  10579. JObject jsonObject = new JObject
  10580. {
  10581. { "Userid", "77886" },
  10582. { "pwd", "cyt86435015" },
  10583. { "content", base64FileContent },
  10584. { "ext", Path.GetExtension(fileName) }
  10585. };
  10586. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10587. JObject jsonObjects = JObject.Parse(response);
  10588. string msg = (string)jsonObjects["msg"];
  10589. if (msg.Equals("上传成功"))
  10590. {
  10591. success += url + " 上传成功";
  10592. }
  10593. else
  10594. {
  10595. errors += url + " 上传失败";
  10596. }
  10597. }
  10598. else
  10599. {
  10600. errors += url + " 格式出现问题";
  10601. }
  10602. }
  10603. if (urls.Length == 0)
  10604. {
  10605. return (success, errors);
  10606. }
  10607. return (success, errors);
  10608. }
  10609. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10610. {
  10611. return true; //总是接受
  10612. }
  10613. public static string HttpPost(string url, string param = null)
  10614. {
  10615. HttpWebRequest request;
  10616. //如果是发送HTTPS请求
  10617. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10618. {
  10619. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10620. request = WebRequest.Create(url) as HttpWebRequest;
  10621. request.ProtocolVersion = HttpVersion.Version10;
  10622. }
  10623. else
  10624. {
  10625. request = WebRequest.Create(url) as HttpWebRequest;
  10626. }
  10627. request.Method = "POST";
  10628. request.ContentType = "application/json";
  10629. request.Accept = "*/*";
  10630. request.Timeout = 120000;
  10631. request.AllowAutoRedirect = false;
  10632. StreamWriter requestStream = null;
  10633. WebResponse response = null;
  10634. string responseStr = null;
  10635. try
  10636. {
  10637. requestStream = new StreamWriter(request.GetRequestStream());
  10638. requestStream.Write(param);
  10639. requestStream.Close();
  10640. response = request.GetResponse();
  10641. if (response != null)
  10642. {
  10643. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10644. responseStr = reader.ReadToEnd();
  10645. reader.Close();
  10646. }
  10647. }
  10648. catch (Exception ex)
  10649. {
  10650. return ex.Message;
  10651. }
  10652. finally
  10653. {
  10654. request = null;
  10655. requestStream = null;
  10656. response = null;
  10657. }
  10658. return responseStr;
  10659. }
  10660. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10661. {
  10662. string base64FileContent;
  10663. string fileName;
  10664. using (WebClient webClient = new WebClient())
  10665. {
  10666. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10667. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10668. {
  10669. using (Stream stream = response.GetResponseStream())
  10670. {
  10671. using (MemoryStream memoryStream = new MemoryStream())
  10672. {
  10673. stream.CopyTo(memoryStream);
  10674. byte[] fileBytes = memoryStream.ToArray();
  10675. base64FileContent = Convert.ToBase64String(fileBytes);
  10676. fileName = response.Headers["Content-Disposition"];
  10677. if (!string.IsNullOrEmpty(fileName))
  10678. {
  10679. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10680. if (index >= 0)
  10681. {
  10682. fileName = fileName.Substring(index + 9).Trim('\"');
  10683. }
  10684. }
  10685. else
  10686. {
  10687. fileName = Path.GetFileName(downloadUrl);
  10688. }
  10689. }
  10690. }
  10691. }
  10692. }
  10693. return (fileName, base64FileContent);
  10694. }
  10695. //新增
  10696. public void order_batch_caiyingtong(string[] downloadUrls)
  10697. {
  10698. try
  10699. {
  10700. //遍历文件
  10701. DataStruct dStruct = GetPostStruct();
  10702. DataTable dt = null;
  10703. int userid = CurrentUser.UserID;
  10704. List<string> ids = new List<string>();//失败组
  10705. List<string> tids = new List<string>();
  10706. using (WebClient webClient = new WebClient())
  10707. {
  10708. foreach (var url in downloadUrls)
  10709. {
  10710. try
  10711. {
  10712. tids.Add("'" + url + "'");
  10713. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10714. if (entity != null)
  10715. {
  10716. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10717. if (cp == null)
  10718. {
  10719. JObject jsonObject = new JObject
  10720. {
  10721. { "Userid", "77886" },
  10722. { "pwd", "lt666888" },
  10723. { "Filename",entity.seller_memo }
  10724. };
  10725. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10726. JObject jsonObjects = JObject.Parse(response);
  10727. string msg = (string)jsonObjects["msg"];
  10728. if (msg == "报价成功")
  10729. {
  10730. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10731. DownloadAndConvertToBase64(url1);
  10732. }
  10733. else
  10734. {
  10735. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10736. }
  10737. }
  10738. else
  10739. {
  10740. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10741. JObject jsonObject = new JObject
  10742. {
  10743. { "Userid", "77886" },
  10744. { "pwd", "lt666888" },
  10745. { "Filename",chanp }
  10746. };
  10747. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10748. JObject jsonObjects = JObject.Parse(response);
  10749. string msg = (string)jsonObjects["msg"];
  10750. if (msg == "报价成功")
  10751. {
  10752. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10753. DownloadAndConvertToBase64(url1);
  10754. }
  10755. else
  10756. {
  10757. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10758. }
  10759. }
  10760. }
  10761. // 上传文件到FTP
  10762. }
  10763. catch (Exception ex)
  10764. {
  10765. Console.WriteLine($"An error occurred: {ex.Message}");
  10766. }
  10767. }
  10768. List<string> lw = new List<string>();
  10769. lw.Add(string.Format("( OrderState < 6 )"));
  10770. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10771. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10772. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10773. if (dt.Rows.Count > 0)
  10774. {
  10775. foreach (DataRow dr in dt.Rows)
  10776. {
  10777. ids.Add(dr["ctid"].ToString());
  10778. }
  10779. }
  10780. String ErrorMsgs = "";
  10781. foreach (String id in ids)
  10782. {
  10783. ErrorMsgs += id + ",";
  10784. }
  10785. if (ErrorMsgs.Length > 1)
  10786. {
  10787. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10788. }
  10789. if (ErrorMsgs.Length < 1)
  10790. {
  10791. ErrorMsgs = "上传成功";
  10792. returnSuccessMsg(ErrorMsgs);
  10793. }
  10794. else
  10795. {
  10796. returnErrorMsg("以下订单" + ErrorMsgs);
  10797. }
  10798. }
  10799. // 删除文件夹及其内容
  10800. /* Directory.Delete(localDirectory, true);*/
  10801. }
  10802. catch { }
  10803. }
  10804. public void get_center_data()
  10805. {
  10806. int userId = CurrentUser.UserID;
  10807. string postCode = CurrentUser.UserPost.Post.Code;
  10808. List<string> lw = new List<string>();
  10809. List<string> ww = new List<string>();
  10810. DateTime currentTime = DateTime.Now;
  10811. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10812. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10813. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10814. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10815. string sql = " SELECT ";
  10816. string startTime = "2023-10-01 11:22:31";
  10817. //设计
  10818. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10819. {
  10820. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10821. ww.Add(string.Format("( SELECT COUNT ( * ) AS designCount FROM CE_ErpTradeCell WHERE pay_time < '{2}' AND OrderState < 5 AND IsReturn = 0 AND pay_time > '{0}' AND DesignUserId = {1} ) AS dc", startTime, userId, payTime));
  10822. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10823. ww.Add(string.Format("( SELECT COUNT ( * ) AS backCount FROM CE_ErpTradeCell WHERE OrderState = 4 AND ReturnTime IS NOT NULL AND pay_time > '{0}' AND DesignUserId = {1} ) AS bc", startTime, userId));
  10824. }
  10825. //客服
  10826. else if (postCode == "CustomerService" || postCode == "Director")
  10827. {
  10828. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10829. ww.Add(string.Format("( SELECT COUNT ( * ) AS designCount FROM CE_ErpTradeCell WHERE pay_time < '{2}' AND OrderState < 5 AND IsReturn = 0 AND pay_time > '{0}' AND CustomerUserId = {1} ) AS dc", startTime, userId, payTime));
  10830. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10831. ww.Add(string.Format("( SELECT COUNT ( * ) AS orderCount FROM CE_ErpTradeCell WHERE FinishDesignTime < '{2}' AND OrderState = 5 AND IsReturn = 0 AND pay_time > '{0}' AND CustomerUserId = {1} ) AS oc", startTime, userId, finishDesignTime));
  10832. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10833. ww.Add(string.Format("( SELECT COUNT ( * ) AS sendCount FROM CE_ErpTradeCell WHERE FinishPlaceTime < '{2}' AND OrderState = 6 AND IsReturn = 0 AND pay_time > '{0}' AND CustomerUserId = {1} ) AS sc", startTime, userId, finishPlaceTime));
  10834. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10835. ww.Add(string.Format("( SELECT COUNT ( * ) AS backCount FROM CE_ErpTradeCell WHERE OrderState = 0 AND ReturnTime IS NOT NULL AND pay_time > '{0}' AND CustomerUserId = {1} ) AS bc", startTime, userId));
  10836. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10837. ww.Add(string.Format("( SELECT COUNT ( * ) AS refundCount FROM CE_ErpTradeCell WHERE IsRefund > 0 AND OrderState NOT IN ( 8, 9 ) AND pay_time > '{0}' AND CustomerUserId = {1} ) AS rc", startTime, userId));
  10838. }
  10839. //售后
  10840. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10841. {
  10842. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10843. ww.Add(string.Format("( SELECT COUNT ( * ) AS sendCount FROM CE_ErpTradeCell WHERE FinishPlaceTime < '{1}' AND OrderState = 6 AND IsReturn = 0 AND pay_time > '{0}' ) AS sc", startTime, finishPlaceTime));
  10844. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10845. ww.Add(string.Format("( SELECT COUNT ( * ) AS refundCount FROM CE_ErpTradeCell WHERE IsRefund > 0 AND OrderState NOT IN ( 8, 9 ) AND pay_time > '{0}' ) AS rc", startTime));
  10846. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10847. ww.Add(string.Format("( SELECT COUNT ( * ) AS checkCount FROM CE_ErpTradeCell WHERE CheckOrderTime < '{1}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND pay_time > '{0}' ) AS cc", startTime, checkOrderTime));
  10848. }
  10849. //下单部
  10850. else if (postCode == "Place" || postCode == "PlaceMr")
  10851. {
  10852. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10853. ww.Add(string.Format("( SELECT COUNT ( * ) AS orderCount FROM CE_ErpTradeCell WHERE FinishDesignTime < '{1}' AND OrderState = 5 AND IsReturn = 0 AND pay_time > '{0}' ) AS oc", startTime, finishDesignTime));
  10854. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10855. ww.Add(string.Format("( SELECT COUNT ( * ) AS sendCount FROM CE_ErpTradeCell WHERE FinishPlaceTime < '{1}' AND OrderState = 6 AND IsReturn = 0 AND pay_time > '{0}' ) AS sc", startTime, finishPlaceTime));
  10856. }
  10857. //车间
  10858. else if (postCode == "Supplier")
  10859. {
  10860. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10861. ww.Add(string.Format("( SELECT COUNT ( * ) AS checkCount FROM CE_ErpTradeCell WHERE CheckOrderTime < '{1}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND pay_time > '{0}' AND SupplierId = {2} ) AS cc", startTime, checkOrderTime, userId));
  10862. }
  10863. DataTable dt = new DataTable();
  10864. if (lw.Count > 0)
  10865. {
  10866. sql += string.Join(" , ", lw);
  10867. sql += " FROM ";
  10868. sql += string.Join(" , ", ww);
  10869. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10870. }
  10871. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10872. }
  10873. public void get_center_data_list()
  10874. {
  10875. int userId = CurrentUser.UserID;
  10876. string postCode = CurrentUser.UserPost.Post.Code;
  10877. string shopIds = CurrentUser.User.pemShop;
  10878. DataStruct dStruct = GetPostStruct();
  10879. List<string> lw = new List<string>();
  10880. DateTime currentTime = DateTime.Now;
  10881. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10882. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10883. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10884. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10885. string startTime = "2023-10-01 11:22:31";
  10886. int order_type = GetPostInt("order_type");
  10887. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10888. {
  10889. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10890. if (order_type == 0)
  10891. {
  10892. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10893. }
  10894. else if (order_type == 3)
  10895. {
  10896. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10897. }
  10898. else
  10899. {
  10900. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10901. }
  10902. }
  10903. //客服
  10904. if (postCode == "CustomerService" || postCode == "Director")
  10905. {
  10906. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10907. if (order_type == 0)
  10908. {
  10909. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10910. }
  10911. else if (order_type == 1)
  10912. {
  10913. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10914. }
  10915. else if (order_type == 2)
  10916. {
  10917. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10918. }
  10919. else if (order_type == 3)
  10920. {
  10921. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10922. }
  10923. else if (order_type == 4)
  10924. {
  10925. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10926. }
  10927. else
  10928. {
  10929. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10930. }
  10931. }
  10932. //售后
  10933. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10934. {
  10935. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10936. if (shopIds != "")
  10937. {
  10938. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10939. }
  10940. if (order_type == 2)
  10941. {
  10942. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10943. }
  10944. else if (order_type == 4)
  10945. {
  10946. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10947. }
  10948. else if (order_type == 5)
  10949. {
  10950. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10951. }
  10952. else
  10953. {
  10954. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10955. }
  10956. }
  10957. //下单部
  10958. if (postCode == "Place" || postCode == "PlaceMr")
  10959. {
  10960. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10961. if (shopIds != "")
  10962. {
  10963. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10964. }
  10965. else if (order_type == 1)
  10966. {
  10967. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10968. }
  10969. else if (order_type == 2)
  10970. {
  10971. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10972. }
  10973. else
  10974. {
  10975. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10976. }
  10977. }
  10978. //车间
  10979. if (postCode == "Supplier")
  10980. {
  10981. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10982. if (order_type == 5)
  10983. {
  10984. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10985. }
  10986. else
  10987. {
  10988. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10989. }
  10990. }
  10991. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10992. dStruct.Fileds = "tid,ctid";
  10993. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10994. writeGridDataTableJson(dStruct.TotalCount, dt);
  10995. }
  10996. public void aftersale_audit_master()
  10997. {
  10998. if (UrlPostParmsCheck("ctid"))
  10999. {
  11000. string ctid = GetPostString("ctid");
  11001. if (ctid.Length > 0)
  11002. {
  11003. bool result = aftersale_data_change(ctid);
  11004. if (result)
  11005. {
  11006. returnSuccessMsg("修改成功!");
  11007. return;
  11008. }
  11009. }
  11010. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11011. }
  11012. }
  11013. public void aftersale_documentary_finish()
  11014. {
  11015. if (UrlPostParmsCheck("ctid"))
  11016. {
  11017. string ctid = GetPostString("ctid");
  11018. if (ctid.Length > 0)
  11019. {
  11020. List<string> list = new List<string>();
  11021. string[] ctid_list = ctid.Split(',');
  11022. foreach (var item in ctid_list)
  11023. {
  11024. try
  11025. {
  11026. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(item);
  11027. if (ceErpTradeAfterSaleExtend == null)
  11028. {
  11029. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11030. ceErpTradeAfterSaleExtend.tid = item;
  11031. }
  11032. ceErpTradeAfterSaleExtend.AfterSalSend = 1;
  11033. if (ceErpTradeAfterSaleExtend.ID > 0)
  11034. {
  11035. ceErpTradeAfterSaleExtend.Update();
  11036. }
  11037. else
  11038. {
  11039. ceErpTradeAfterSaleExtend.Create();
  11040. }
  11041. LogHelper.addLog(item, CurrentUser.UserID, "跟单完成", 6, 4);
  11042. }
  11043. catch (Exception ex)
  11044. {
  11045. list.Add(item);
  11046. }
  11047. }
  11048. if (list.Count > 0)
  11049. {
  11050. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  11051. return;
  11052. }
  11053. returnSuccessMsg("修改成功!");
  11054. return;
  11055. }
  11056. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11057. }
  11058. }
  11059. public void aftersale_batch_audit_master()
  11060. {
  11061. if (UrlPostParmsCheck("ctids"))
  11062. {
  11063. string ctids = GetPostString("ctids");
  11064. if (ctids.Length > 0)
  11065. {
  11066. List<string> list = new List<string>();
  11067. string[] ctid_list = ctids.Split(',');
  11068. foreach (var item in ctid_list)
  11069. {
  11070. bool result = aftersale_data_change(item);
  11071. if (!result)
  11072. {
  11073. list.Add(item);
  11074. }
  11075. }
  11076. if (list.Count > 0)
  11077. {
  11078. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  11079. return;
  11080. }
  11081. returnSuccessMsg("修改成功!");
  11082. return;
  11083. }
  11084. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11085. }
  11086. }
  11087. public bool aftersale_data_change(string ctid)
  11088. {
  11089. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11090. if (ceErpTradeCell != null)
  11091. {
  11092. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  11093. ceErpTradeCell.AfterSaleSupplierState = 0;
  11094. StringBuilder sql = new StringBuilder();
  11095. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  11096. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11097. CeErpTradeResponsible.DelByTid(ctid, 0);
  11098. if ((ceErpTradeCell.AfterSaleResponsible.IndexOf("客户问题") != -1 && ceErpTradeCell.AfterSaleResponsible.IndexOf(",客户问题") == -1) || (ceErpTradeCell.AfterSaleResponsible.IndexOf("系统问题") != -1 && ceErpTradeCell.AfterSaleResponsible.IndexOf(",系统问题") == -1) || ceErpTradeCell.supRefundType == "正常损耗" || ceErpTradeCell.supRefundType == "车间不售后" || ceErpTradeCell.supRefundType == "不售后" || ceErpTradeCell.supRefundType == "不理赔")
  11099. {
  11100. CeErpTradeResponsible.DelByTid(ctid, -1);
  11101. ceErpTradeCell.AfterSaleSupplierState = 1;
  11102. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11103. ceErpTradeCell.AfterSaleState = 4;
  11104. }
  11105. else
  11106. {
  11107. ceErpTradeCell.AfterSaleState = 3;
  11108. }
  11109. bool needCyt = false;
  11110. if (dt != null)
  11111. {
  11112. if (dt.Rows.Count == 1)
  11113. {
  11114. bool isEnd = false;
  11115. foreach (DataRow dr in dt.Rows)
  11116. {
  11117. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  11118. {
  11119. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11120. isEnd = true;
  11121. }
  11122. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  11123. {
  11124. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11125. isEnd = true;
  11126. }
  11127. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11128. {
  11129. needCyt = true;
  11130. }
  11131. }
  11132. if (isEnd)
  11133. {
  11134. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11135. ceErpTradeCell.AfterSaleState = 4;
  11136. ceErpTradeCell.AfterSaleSupplierState = 1;
  11137. }
  11138. }
  11139. else
  11140. {
  11141. bool isAll = true;
  11142. foreach (DataRow dr in dt.Rows)
  11143. {
  11144. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  11145. {
  11146. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11147. continue;
  11148. }
  11149. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  11150. {
  11151. string path = "";
  11152. int OrgID = 0;
  11153. if (!Convert.IsDBNull(dr["OrgPath"]))
  11154. {
  11155. path = dr["OrgPath"].ToString();
  11156. }
  11157. if (!Convert.IsDBNull(dr["OrgID"]))
  11158. {
  11159. OrgID = Convert.ToInt32(dr["OrgID"]);
  11160. }
  11161. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  11162. {
  11163. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11164. continue;
  11165. }
  11166. }
  11167. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11168. {
  11169. needCyt = true;
  11170. }
  11171. isAll = false;
  11172. }
  11173. if (isAll)
  11174. {
  11175. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11176. ceErpTradeCell.AfterSaleState = 4;
  11177. ceErpTradeCell.AfterSaleSupplierState = 1;
  11178. }
  11179. }
  11180. }
  11181. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  11182. {
  11183. commonHelper.sendCytAfterSale(ceErpTradeCell);
  11184. }
  11185. if (ceErpTradeCell.AfterSaleState == 4)
  11186. {
  11187. ApiVo apiVo = new ApiVo();
  11188. apiVo.orderNumber = ceErpTradeCell.ctid;
  11189. apiVo.actionName = "afterOver";
  11190. designHelper.API_WorkCore(apiVo); //afterOver
  11191. }
  11192. ceErpTradeCell.Update();
  11193. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  11194. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  11195. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  11196. return true;
  11197. }
  11198. return false;
  11199. }
  11200. public void get_erp_wechatorder()
  11201. {
  11202. DataStruct dStruct = GetPostStruct();
  11203. List<string> lw = new List<string>();
  11204. string tid = GetPostString("tid");
  11205. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11206. string shopname = GetPostString("shopname");
  11207. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11208. string buyernick = GetPostString("buyer_nick");
  11209. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11210. string customer = GetPostString("customer");
  11211. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11212. string returndate1 = GetPostString("returndate1");
  11213. string returndate2 = GetPostString("returndate2");
  11214. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11215. if (dw.Length > 0) lw.Add(dw);
  11216. string finishDate1 = GetPostString("finishdate1");
  11217. string finishDate2 = GetPostString("finishdate2");
  11218. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11219. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11220. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11221. dStruct.Order = "created desc";
  11222. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11223. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  11224. writeGridDataTableJson(dStruct.TotalCount, dt);
  11225. }
  11226. public void get_erp_wechatlist_sumprice()
  11227. {
  11228. DataStruct dStruct = GetPostStruct();
  11229. List<string> lw = new List<string>();
  11230. string tid = GetPostString("tid");
  11231. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11232. string shopname = GetPostString("shopname");
  11233. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11234. string buyernick = GetPostString("buyer_nick");
  11235. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11236. string customer = GetPostString("customer");
  11237. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11238. string returndate1 = GetPostString("returndate1");
  11239. string returndate2 = GetPostString("returndate2");
  11240. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11241. if (dw.Length > 0) lw.Add(dw);
  11242. string finishDate1 = GetPostString("finishdate1");
  11243. string finishDate2 = GetPostString("finishdate2");
  11244. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11245. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11246. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11247. string mainWhere = string.Join(" and ", lw.ToArray());
  11248. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  11249. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  11250. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  11251. decimal total = 0;
  11252. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  11253. {
  11254. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  11255. }
  11256. var res = new
  11257. {
  11258. data = total
  11259. };
  11260. string ro_jsond = JsonConvert.SerializeObject(res);
  11261. returnSuccess(ro_jsond);
  11262. return;
  11263. }
  11264. public void get_erp_qr_waitdeliverylist()
  11265. {
  11266. DataStruct dStruct = GetPostStruct();
  11267. List<string> lw = new List<string>();
  11268. string tid = GetPostString("ctid");
  11269. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  11270. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11271. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  11272. var res_objz = new
  11273. {
  11274. restype = 1,
  11275. data = dt
  11276. };
  11277. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  11278. returnSuccess(ro_jsonz);
  11279. }
  11280. public void get_erp_yield_list()
  11281. {
  11282. DataStruct dStruct = GetPostStruct();
  11283. List<string> lw = new List<string>();
  11284. string tid = GetPostString("ctid");
  11285. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11286. string shopname = GetPostString("shopname");
  11287. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11288. string buyernick = GetPostString("buyer_nick");
  11289. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11290. //if (tid.Length == 0 && buyernick.Length == 0)
  11291. //{
  11292. // lw.Add(string.Format("IsRefund<={0}", 1));
  11293. //}
  11294. string customer = GetPostString("customer");
  11295. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11296. string design = GetPostString("design");
  11297. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11298. string orderState = GetPostString("orderState");
  11299. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11300. string address = GetPostString("address");
  11301. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  11302. string sellermemo = GetPostString("seller_memo");
  11303. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11304. string supplier = GetPostString("supplier");
  11305. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11306. string OrderArea = GetPostString("order_area");
  11307. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11308. string placedate1 = GetPostString("placedate1");
  11309. string placedate2 = GetPostString("placedate2");
  11310. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11311. if (fdw.Length > 0) lw.Add(fdw);
  11312. string price1 = GetPostString("price1");
  11313. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11314. string price2 = GetPostString("price2");
  11315. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11316. string unusualCon = GetPostString("unusualcon");
  11317. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11318. string posTag = CurrentUser.UserPost.Post.Code;
  11319. if (posTag == "Supplier")
  11320. {
  11321. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11322. }
  11323. lw.Add(string.Format("OrderState = 6 "));
  11324. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11325. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11326. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11327. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11328. writeGridDataTableJson(dStruct.TotalCount, dt);
  11329. }
  11330. public void change_erp_sup_state()
  11331. {
  11332. if (UrlPostParmsCheck("ctid"))
  11333. {
  11334. string ctid = GetPostString("ctid");
  11335. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11336. if (ceErpTradeCell != null)
  11337. {
  11338. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11339. if (ceErpTradeCellExtend == null)
  11340. {
  11341. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11342. ceErpTradeCellExtend.ctid = ctid;
  11343. ceErpTradeCellExtend.SupState = 1;
  11344. ceErpTradeCellExtend.Create();
  11345. }
  11346. else
  11347. {
  11348. ceErpTradeCellExtend.SupState = 1;
  11349. ceErpTradeCellExtend.Update();
  11350. }
  11351. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11352. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11353. return;
  11354. }
  11355. returnErrorMsg("找不到订单");
  11356. }
  11357. }
  11358. public void supplier_all_downs()
  11359. {
  11360. if (UrlPostParmsCheck("tids"))
  11361. {
  11362. string tids = GetPostString("tids");
  11363. if (tids != null && tids.Length > 0)
  11364. {
  11365. StringBuilder sql = new StringBuilder();
  11366. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11367. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11368. sql = new StringBuilder();
  11369. sql.AppendFormat("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"), (int)OrderState.下单完成, CurrentUser.UserID, "下载设计文件");
  11370. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11371. string[] list = tids.Split(',');
  11372. foreach (string ctid in list)
  11373. {
  11374. CeErpSukuraData.createInfo(ctid, 3);
  11375. }
  11376. designHelper.api_approveDesign(tids); //approveDesign
  11377. returnSuccessMsg("下载成功!");
  11378. return;
  11379. }
  11380. returnErrorMsg("下载订单更新失败");
  11381. }
  11382. }
  11383. public void uploaderFileSuccess()
  11384. {
  11385. if (UrlPostParmsCheck("fileName"))
  11386. {
  11387. string fileName = GetPostString("fileName");
  11388. ApiVo apiVo = new ApiVo();
  11389. apiVo.orderNumber = fileName;
  11390. apiVo.actionName = "finishDesign";
  11391. designHelper.API_WorkCore(apiVo);//finishDesign
  11392. returnSuccessMsg("");
  11393. }
  11394. }
  11395. public void get_sample2_order()
  11396. {
  11397. if (UrlPostParmsCheck("ctid"))
  11398. {
  11399. string ctid = GetPostString("ctid");
  11400. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11401. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11402. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11403. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11404. double total = 0.0;
  11405. double order_price = 0.0;
  11406. if (dt_bu.Rows.Count > 0)
  11407. {
  11408. foreach (DataRow dr in dt_bu.Rows)
  11409. {
  11410. total += Convert.ToDouble(dr["payment"]);
  11411. }
  11412. }
  11413. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11414. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11415. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11416. string tid = ctid.Replace("S_", "");
  11417. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11418. double paymant = 0.0;
  11419. if (entity != null)
  11420. {
  11421. paymant = entity.payment;
  11422. }
  11423. string return_reason = "";
  11424. if (dt_after != null && dt_after.Rows.Count > 0)
  11425. {
  11426. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11427. }
  11428. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11429. }
  11430. }
  11431. public void get_erp_design_status()
  11432. {
  11433. string designName = GetPostString("designName");
  11434. DataStruct dStruct = GetPostStruct();
  11435. if (designName.Length > 0)
  11436. {
  11437. string sql_user = "select id,Name,TeamIds from view_ErpUser where (PostCode='Designer' or PostCode='DesignerMr' or PostCode='Designerhd' or PostCode='wxDesigner' or PostCode='wxDesignerMr') and isopen = 1";
  11438. sql_user += " and Name like '%" + designName + "%'";
  11439. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11440. List<string> ids_list = new List<string>();
  11441. if (user_table.Rows.Count > 0)
  11442. {
  11443. foreach (DataRow item in user_table.Rows)
  11444. {
  11445. ids_list.Add(item["id"].ToString());
  11446. string ids_s = item["TeamIds"].ToString();
  11447. if (ids_s.Length > 0)
  11448. {
  11449. ids_list.AddRange(ids_s.Split(','));
  11450. }
  11451. }
  11452. }
  11453. HashSet<string> set = new HashSet<string>(ids_list);
  11454. ids_list = set.ToList();
  11455. if (ids_list.Count > 0)
  11456. {
  11457. string sql = string.Format(" (PostCode='Designer' or PostCode='DesignerMr' or PostCode='Designerhd' or PostCode='wxDesigner' or PostCode='wxDesignerMr') and isopen = 1 and id in ({0})", string.Join(",", ids_list));
  11458. dStruct.MainWhere = sql;
  11459. DataTable dt = null;
  11460. dt = WebCache.GetData("view_ErpUser", dStruct);
  11461. writeGridDataTableJson(dStruct.TotalCount, dt);
  11462. }
  11463. }
  11464. }
  11465. public void change_erp_order_price()
  11466. {
  11467. string ctid = GetPostString("ctid");
  11468. double price = GetPostDouble("price");
  11469. if (ctid.Length > 0)
  11470. {
  11471. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11472. if (ceErpTradeCellExtend == null)
  11473. {
  11474. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11475. ceErpTradeCellExtend.ctid = ctid;
  11476. ceErpTradeCellExtend.payment_cyt = price;
  11477. ceErpTradeCellExtend.Create();
  11478. }
  11479. else
  11480. {
  11481. ceErpTradeCellExtend.payment_cyt = price;
  11482. ceErpTradeCellExtend.Update();
  11483. }
  11484. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11485. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11486. {
  11487. ceErpDataSendOrderInfo.isSync = false;
  11488. ceErpDataSendOrderInfo.Update();
  11489. }
  11490. if (ceErpDataSendOrderInfo == null)
  11491. {
  11492. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11493. ceErpDataSendOrderInfo.isSync = false;
  11494. ceErpDataSendOrderInfo.ctid = ctid;
  11495. ceErpDataSendOrderInfo.Create();
  11496. }
  11497. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11498. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11499. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11500. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11501. {
  11502. dataSendOrderBean dataSendOrderBean = null;
  11503. foreach (DataRow item in dth.Rows)
  11504. {
  11505. try
  11506. {
  11507. dataSendOrderBean = new dataSendOrderBean();
  11508. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11509. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11510. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11511. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11512. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11513. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11514. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11515. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11516. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11517. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11518. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11519. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11520. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11521. if (result != null)
  11522. {
  11523. if ("0".Equals(result.errcode))
  11524. {
  11525. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11526. }
  11527. else
  11528. {
  11529. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11530. }
  11531. }
  11532. }
  11533. catch (Exception ex)
  11534. {
  11535. }
  11536. }
  11537. }
  11538. returnSuccessMsg("修改成功!");
  11539. return;
  11540. }
  11541. returnErrorMsg("找不到订单");
  11542. }
  11543. public void find_he_together()
  11544. {
  11545. string ctid = GetPostString("ctid");
  11546. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11547. List<string> list = new List<string>();
  11548. if (ceErpTradeCell != null)
  11549. {
  11550. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11551. {
  11552. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where tid='{0}' and ctid <> '{1}' and SupplierId = {2}", ceErpTradeCell.tid, ceErpTradeCell.ctid, ceErpTradeCell.SupplierId);
  11553. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11554. if (table != null && table.Rows.Count > 0)
  11555. {
  11556. foreach (TableRow row in table.Rows)
  11557. {
  11558. }
  11559. }
  11560. }
  11561. }
  11562. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11563. }
  11564. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11565. {
  11566. //chy----19
  11567. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11568. //GD-CYT-----64
  11569. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11570. //ZHX----3
  11571. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11572. //JK----97
  11573. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11574. //ZT----70
  11575. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11576. //GD-CYTUV---126
  11577. {126, new Dictionary<string, string> {{"uv", "uv"}}},
  11578. //LHCY-----98
  11579. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11580. //XD-----90
  11581. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11582. //CYCY-----14
  11583. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}},
  11584. //THLZY----122
  11585. {122, new Dictionary<string, string> {{ "烫画", "烫画" }, { "冷转印", "冷转印" }}}
  11586. };
  11587. //其他改名
  11588. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11589. {
  11590. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11591. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11592. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11593. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11594. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11595. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11596. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11597. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" },{ 129,"种子纸"},{ 125,"胶带"},{ 127,"PET透卡"}
  11598. };
  11599. //不统计
  11600. List<int> no_suppliers = new List<int>()
  11601. {
  11602. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11603. };
  11604. //配件单
  11605. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11606. {
  11607. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11608. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11609. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11610. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11611. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11612. {"旗杆",new List<string>(){ "班旗" } },
  11613. {"牙签",new List<string>(){ "不干胶" } }
  11614. };
  11615. public void get_place_order_data()
  11616. {
  11617. string date1 = GetPostString("date1");
  11618. string date2 = GetPostString("date2");
  11619. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11620. DateTime start = DateTime.Parse(starttime);
  11621. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11622. DateTime end = DateTime.Parse(endtime);
  11623. if (date1 != null && date1.Length > 0)
  11624. {
  11625. DateTime dateTime = DateTime.Parse(date1);
  11626. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11627. start = DateTime.Parse(starttime);
  11628. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11629. end = DateTime.Parse(endtime);
  11630. }
  11631. if (date2 != null && date2.Length > 0)
  11632. {
  11633. DateTime dateTime = DateTime.Parse(date2);
  11634. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11635. end = DateTime.Parse(endtime);
  11636. }
  11637. List<int> smSupplier = new List<int>() { 97, 121, 119, 80 };
  11638. string startMonthDate = commonHelper.FirstDayOfMonth(DateTime.Now).ToString("yyyy-MM-dd 00:00:00");
  11639. string endMonthDate = commonHelper.LastDayOfMonth(DateTime.Now).ToString("yyyy-MM-dd 23:59:59");
  11640. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,UnusualTime,FinishPlaceTime,OrderState,FinishDeliveryTime,AfterSaleState=0,AfterSaleReason = '',delivery=0 from view_ErpTradeCell where ( ( FinishPlaceTime BETWEEN '{0}' AND '{1}' ) OR ( OrderState = 6 AND UnusualTag = 5 AND IsRefund <= 1 ) ) AND IsSample = 0 and SupplierId > 0 ", starttime, endtime);
  11641. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11642. sql = string.Format("SELECT SupplierId, ProductId, seller_memo, ProductCount, ProductName, payment, SupplierName, UnusualTime, FinishPlaceTime, OrderState, FinishDeliveryTime, AfterSaleState,AfterSaleReason,delivery=0 FROM view_ErpTradeCell WHERE ( AfterSalePreTime BETWEEN '{0}' AND '{1}' ) AND IsSample = 0 AND SupplierId > 0 AND FinishPlaceTime IS NOT NULL", startMonthDate, endMonthDate);
  11643. DataTable afterSaleData = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11644. data.Merge(afterSaleData);
  11645. sql = string.Format("SELECT SupplierId, ProductId, seller_memo, ProductCount, ProductName, payment, SupplierName, UnusualTime, FinishPlaceTime, OrderState, FinishDeliveryTime, AfterSaleState=0,AfterSaleReason = '',delivery=1 FROM view_ErpTradeCell WHERE orderstate = 6 AND IsSample = 0 AND SupplierId > 0 AND FinishPlaceTime > '2025-11-01 00:00:31.000' AND IsRefund <= 1 AND status = 'NOT_SHIPPED' AND LEN( ProductName ) > 0 AND SupplierId not in (86,10,105,86)", startMonthDate, endMonthDate);
  11646. DataTable deliveryData = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11647. data.Merge(deliveryData);
  11648. //获取商品发货时间
  11649. string timer_sql = string.Format("select * from CE_ErpSupplierProductTime");
  11650. DataTable timer_data = DbHelper.DbConn.ExecuteDataset(timer_sql).Tables[0];
  11651. Dictionary<int, List<CeErpSupplierProductTime>> timer_map = new Dictionary<int, List<CeErpSupplierProductTime>>();
  11652. foreach (DataRow datarow in timer_data.Rows)
  11653. {
  11654. List<CeErpSupplierProductTime> list = null;
  11655. int supplierId = Convert.ToInt32(datarow["SupplierId"]);
  11656. if (timer_map.ContainsKey(supplierId))
  11657. {
  11658. timer_map.TryGetValue(supplierId, out list);
  11659. }
  11660. else
  11661. {
  11662. list = new List<CeErpSupplierProductTime>();
  11663. timer_map.Add(supplierId, list);
  11664. timer_map.TryGetValue(supplierId, out list);
  11665. }
  11666. CeErpSupplierProductTime ceErpSupplierProductTime = new CeErpSupplierProductTime();
  11667. ceErpSupplierProductTime.quantity = Convert.ToInt32(datarow["quantity"]);
  11668. ceErpSupplierProductTime.dayDeadLine = datarow["dayDeadLine"].ToString();
  11669. ceErpSupplierProductTime.deadLine = datarow["deadLine"].ToString();
  11670. ceErpSupplierProductTime.productId = datarow["productId"].ToString();
  11671. ceErpSupplierProductTime.craft = datarow["craft"].ToString();
  11672. ceErpSupplierProductTime.sendDay = Convert.ToInt32(datarow["sendDay"]);
  11673. list.Add(ceErpSupplierProductTime);
  11674. }
  11675. //不干胶-----1,卡片-----29
  11676. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11677. foreach (DataRow row in data.Rows)
  11678. {
  11679. int productId = Convert.ToInt32(row["ProductId"]);
  11680. string ProductName = row["ProductName"].ToString();
  11681. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11682. if (no_suppliers.Contains(supplierId))
  11683. {
  11684. continue;
  11685. }
  11686. string seller_memo = row["seller_memo"].ToString();
  11687. bool ispj = false;//是否配件单
  11688. bool isfirst = true;//第一个配
  11689. maps.Keys.ForEach(key =>
  11690. {
  11691. //备注包含配件
  11692. if (seller_memo.Contains(key) && isfirst)
  11693. {
  11694. List<string> list = maps[key];
  11695. ispj = true;
  11696. isfirst = false;
  11697. for (int i = 0; i < list.Count; i++)
  11698. {
  11699. if (seller_memo.Contains(list[i]))
  11700. {
  11701. ispj = false;
  11702. break;
  11703. }
  11704. }
  11705. }
  11706. });
  11707. if (ispj)
  11708. {
  11709. continue;
  11710. }
  11711. seller_memo = seller_memo.Replace("UV", "uv");
  11712. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11713. //吊牌归到卡片
  11714. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11715. seller_memo = seller_memo.Replace("卡套", "卡片");
  11716. seller_memo = seller_memo.Replace("封套", "卡片");
  11717. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11718. seller_memo = seller_memo.Replace("腰封", "卡片");
  11719. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11720. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11721. seller_memo = seller_memo.Replace("横幅", "条幅");
  11722. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11723. string map_key = "";
  11724. string type = "";
  11725. if (supplierMap.ContainsKey(supplierId))
  11726. {
  11727. foreach (var kvp in supplierMap[supplierId])
  11728. {
  11729. if (seller_memo.Contains(kvp.Key))
  11730. {
  11731. map_key = kvp.Value;
  11732. type = kvp.Value;
  11733. break;
  11734. }
  11735. }
  11736. }
  11737. if (map_key == "")
  11738. {
  11739. type = ProductName;
  11740. map_key = ProductName;
  11741. if (smSupplier.Contains(supplierId))
  11742. {
  11743. type = "数码";
  11744. map_key = "数码";
  11745. }
  11746. }
  11747. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11748. {
  11749. map_key = suppliers[supplierId];
  11750. }
  11751. map_key += "_" + row["SupplierName"].ToString();
  11752. Dictionary<string, int> map = null;
  11753. if (other_map.ContainsKey(map_key))
  11754. {
  11755. other_map.TryGetValue(map_key, out map);
  11756. }
  11757. else
  11758. {
  11759. map = new Dictionary<string, int>();
  11760. map.Add("dayDev", 0);//当天出货
  11761. map.Add("dayTotal", 0);//下单总数
  11762. map.Add("payTotal", 0);//500以上
  11763. map.Add("today", 0);//当天出货数量
  11764. map.Add("unusua", 0);//异常数
  11765. map.Add("aftersale", 0);//异常数
  11766. map.Add("deliveryNum", 0);//待发货数
  11767. other_map.Add(map_key, map);
  11768. other_map.TryGetValue(map_key, out map);
  11769. }
  11770. int afterSaleState = Convert.ToInt32(row["AfterSaleState"]);
  11771. int delivery = Convert.ToInt32(row["delivery"]);
  11772. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11773. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11774. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11775. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11776. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11777. //GD-CYT-----64
  11778. DateTime two = palceTimeStart.AddHours(14);
  11779. DateTime three = palceTimeStart.AddHours(15);
  11780. DateTime four = palceTimeStart.AddHours(16);
  11781. DateTime six = palceTimeStart.AddHours(18);
  11782. bool istoday = false;
  11783. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11784. {
  11785. //下午四点前 500-1000
  11786. string count = row["ProductCount"].ToString();
  11787. if (count != null && count.Length > 0)
  11788. {
  11789. int productCount = commonHelper.getPlaceProductCount(count);
  11790. if (productCount >= 500 && productCount <= 1000)
  11791. {
  11792. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11793. {
  11794. istoday = true;
  11795. }
  11796. }
  11797. }
  11798. }
  11799. //UV
  11800. else if ("uv".Equals(type))
  11801. {
  11802. //ZT----70
  11803. //ZHX----3
  11804. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11805. {
  11806. istoday = true;
  11807. }
  11808. //JK----97
  11809. //HZX----105
  11810. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11811. {
  11812. istoday = true;
  11813. }
  11814. if (DateTime.Compare(FinishPlaceTime, six) < 0 && (supplierId == 126))
  11815. {
  11816. istoday = true;
  11817. }
  11818. }
  11819. //帆布---52|条幅---27
  11820. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11821. {
  11822. //LHCY-----98
  11823. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11824. {
  11825. istoday = true;
  11826. }
  11827. }
  11828. //条幅
  11829. else if ("条幅".Equals(type))
  11830. {
  11831. //XD-----90
  11832. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11833. {
  11834. istoday = true;
  11835. }
  11836. }
  11837. //桌布
  11838. else if ("桌布".Equals(type))
  11839. {
  11840. //XD-----90
  11841. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11842. {
  11843. istoday = true;
  11844. }
  11845. }
  11846. //DL---10
  11847. //AYTW---119
  11848. //FS-CYT-DY ----80
  11849. //JK----97
  11850. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11851. {
  11852. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11853. {
  11854. istoday = true;
  11855. }
  11856. }
  11857. // QC---121
  11858. else if (supplierId == 121)
  11859. {
  11860. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  11861. {
  11862. istoday = true;
  11863. }
  11864. }
  11865. if (afterSaleState == 0 && delivery == 0)
  11866. {
  11867. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11868. {
  11869. map["dayTotal"]++;
  11870. if (supplierId == 97)
  11871. {
  11872. supplierId = 97;
  11873. }
  11874. }
  11875. if (Convert.ToDecimal(row["payment"]) >= 500)
  11876. {
  11877. map["payTotal"]++;
  11878. }
  11879. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11880. {
  11881. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11882. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11883. {
  11884. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11885. {
  11886. map["today"]++;
  11887. }
  11888. }
  11889. else
  11890. {
  11891. if (supplierId == 80 || supplierId == 126)
  11892. {
  11893. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11894. {
  11895. map["today"]++;
  11896. }
  11897. }
  11898. else if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11899. {
  11900. map["today"]++;
  11901. }
  11902. }
  11903. }
  11904. if (istoday)
  11905. {
  11906. map["dayDev"]++;
  11907. }
  11908. }
  11909. else if (delivery == 0)
  11910. {
  11911. if (row["AfterSaleReason"].ToString().Contains("车间责任"))
  11912. {
  11913. map["aftersale"]++;
  11914. }
  11915. }
  11916. else
  11917. {
  11918. map["deliveryNum"]++;
  11919. try
  11920. {
  11921. if (istoday)
  11922. {
  11923. map["unusua"]++;
  11924. continue;
  11925. }
  11926. if (supplierId == 0 || productId == 0)
  11927. {
  11928. continue;
  11929. }
  11930. //没配置时间
  11931. if (!timer_map.ContainsKey(supplierId))
  11932. {
  11933. continue;
  11934. }
  11935. List<CeErpSupplierProductTime> timmerList = timer_map[supplierId];
  11936. if (timmerList.Count == 0)
  11937. {
  11938. continue;
  11939. }
  11940. string[] productIds = null;
  11941. string finishPlaceTime = row["FinishPlaceTime"].ToString();
  11942. string sellmer_mome = row["seller_memo"].ToString();
  11943. string txtCount = row["ProductCount"].ToString();
  11944. DateTime placeTime = DateTime.Now;
  11945. if (string.IsNullOrEmpty(finishPlaceTime))
  11946. {
  11947. continue;
  11948. }
  11949. placeTime = DateTime.Parse(finishPlaceTime);
  11950. bool isSendTime = false;
  11951. foreach (CeErpSupplierProductTime productTime in timmerList)
  11952. {
  11953. string txtIds = productTime.productId;
  11954. string[] crafts = { };
  11955. int count = productTime.quantity;
  11956. if (string.IsNullOrEmpty(txtIds))
  11957. {
  11958. continue;
  11959. }
  11960. if (count > 0)
  11961. {
  11962. int quantity = commonHelper.handleProductCount(txtCount, true);
  11963. //订单数量大于写入的数量则跳过
  11964. if (quantity > count)
  11965. {
  11966. continue;
  11967. }
  11968. }
  11969. productIds = txtIds.Split(',');
  11970. if (productIds.Contains(productId.ToString()))
  11971. {
  11972. string textCraft = productTime.craft;
  11973. textCraft = textCraft.Replace(",", ",");//统一格式
  11974. if (!string.IsNullOrEmpty(textCraft))
  11975. {
  11976. crafts = textCraft.Split(',');
  11977. }
  11978. if (crafts.Length > 0)
  11979. {
  11980. bool isinCraft = false;
  11981. for (int i = 0; i < crafts.Length; i++)
  11982. {
  11983. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  11984. {
  11985. isinCraft = true;
  11986. break;
  11987. }
  11988. }
  11989. //有写工艺并且备注中没匹配中则跳过
  11990. if (!isinCraft)
  11991. {
  11992. continue;
  11993. }
  11994. }
  11995. DateTime deadLine = DateTime.Parse(productTime.deadLine);
  11996. DateTime dayDeadLine = DateTime.Parse(productTime.dayDeadLine);
  11997. int sendDay = productTime.sendDay;
  11998. //订单发货时间
  11999. DateTime sendtime = placeTime;
  12000. //下单时间小于当日发货时间则不用判断
  12001. //当日发货必须发货
  12002. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  12003. {
  12004. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59"));
  12005. }
  12006. else if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  12007. {
  12008. //在截稿时间之前下单的可以减去一天时间
  12009. sendDay = Math.Max(1, sendDay - 1);
  12010. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 00:00:00")).AddDays(sendDay);
  12011. }
  12012. else
  12013. {
  12014. sendDay = Math.Max(1, sendDay - 1);
  12015. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59")).AddDays(sendDay);
  12016. }
  12017. //判断有没有到发货日期大于0还没到发货时间
  12018. if (DateTime.Compare(sendtime.Date, DateTime.Now.Date) < 0)
  12019. {
  12020. //匹配到就不要继续匹配了
  12021. isSendTime = true;
  12022. break;
  12023. }
  12024. }
  12025. }
  12026. if (isSendTime)
  12027. {
  12028. map["unusua"]++;
  12029. }
  12030. }
  12031. catch (Exception ex)
  12032. {
  12033. XLog.SaveLog(0, row["ctid"].ToString() + "更新发货异常订单错误:" + ex);
  12034. }
  12035. }
  12036. }
  12037. DataTable dt = new DataTable();
  12038. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  12039. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  12040. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  12041. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  12042. dt.Columns.Add(new DataColumn("today", typeof(string)));
  12043. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  12044. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  12045. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  12046. dt.Columns.Add(new DataColumn("aftersale", typeof(string)));
  12047. dt.Columns.Add(new DataColumn("deliveryNum", typeof(string)));
  12048. other_map.Keys.ForEach(key =>
  12049. {
  12050. DataRow dr = dt.NewRow();
  12051. Dictionary<string, int> map = other_map[key];
  12052. string[] key_list = key.Split('_');
  12053. dr[0] = key_list[0];
  12054. dr[1] = key_list[1];
  12055. if (key_list.Length > 2)
  12056. {
  12057. dr[1] += "(" + key_list[2] + ")";
  12058. }
  12059. dr[2] = map["dayTotal"];
  12060. dr[3] = map["payTotal"];
  12061. dr[4] = map["today"];
  12062. dr[5] = map["unusua"];
  12063. dr[6] = map["dayDev"];
  12064. double rate = 0.00;
  12065. if (map["dayDev"] > 0)
  12066. {
  12067. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  12068. }
  12069. dr[7] = rate.ToString();
  12070. dr[8] = map["aftersale"];
  12071. dr[9] = map["deliveryNum"];
  12072. dt.Rows.Add(dr);
  12073. });
  12074. DataView dv = new DataView(dt);
  12075. dv.Sort = "SupplierName";
  12076. //dv.Sort = "ProductName desc";
  12077. DataTable dtNew = dv.ToTable();
  12078. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  12079. }
  12080. public void get_place_all_order_data()
  12081. {
  12082. string date1 = GetPostString("date1");
  12083. string date2 = GetPostString("date2");
  12084. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  12085. DateTime start = DateTime.Parse(starttime);
  12086. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  12087. DateTime end = DateTime.Parse(endtime);
  12088. if (date1 != null && date1.Length > 0)
  12089. {
  12090. DateTime dateTime = DateTime.Parse(date1);
  12091. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  12092. start = DateTime.Parse(starttime);
  12093. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  12094. end = DateTime.Parse(endtime);
  12095. }
  12096. if (date2 != null && date2.Length > 0)
  12097. {
  12098. DateTime dateTime = DateTime.Parse(date2);
  12099. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  12100. end = DateTime.Parse(endtime);
  12101. }
  12102. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  12103. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,FinishPlaceTime,OrderState,FinishDeliveryTime from view_ErpTradeCell where ( FinishDeliveryTime BETWEEN '{0}' AND '{1}' ) AND IsSample = 0 and SupplierId > 0 ", starttime, endtime);
  12104. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12105. string timer_sql = string.Format("select * from CE_ErpSupplierProductTime");
  12106. DataTable timer_data = DbHelper.DbConn.ExecuteDataset(timer_sql).Tables[0];
  12107. Dictionary<int, List<CeErpSupplierProductTime>> timer_map = new Dictionary<int, List<CeErpSupplierProductTime>>();
  12108. foreach (DataRow datarow in timer_data.Rows)
  12109. {
  12110. List<CeErpSupplierProductTime> list = null;
  12111. int supplierId = Convert.ToInt32(datarow["SupplierId"]);
  12112. if (timer_map.ContainsKey(supplierId))
  12113. {
  12114. timer_map.TryGetValue(supplierId, out list);
  12115. }
  12116. else
  12117. {
  12118. list = new List<CeErpSupplierProductTime>();
  12119. timer_map.Add(supplierId, list);
  12120. timer_map.TryGetValue(supplierId, out list);
  12121. }
  12122. CeErpSupplierProductTime ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12123. ceErpSupplierProductTime.quantity = Convert.ToInt32(datarow["quantity"]);
  12124. ceErpSupplierProductTime.dayDeadLine = datarow["dayDeadLine"].ToString();
  12125. ceErpSupplierProductTime.deadLine = datarow["deadLine"].ToString();
  12126. ceErpSupplierProductTime.productId = datarow["productId"].ToString();
  12127. ceErpSupplierProductTime.craft = datarow["craft"].ToString();
  12128. ceErpSupplierProductTime.sendDay = Convert.ToInt32(datarow["sendDay"]);
  12129. list.Add(ceErpSupplierProductTime);
  12130. }
  12131. List<int> smSupplier = new List<int>() { 97, 121, 119, 80 };
  12132. foreach (DataRow row in data.Rows)
  12133. {
  12134. //存储数据
  12135. int productId = Convert.ToInt32(row["ProductId"]);
  12136. string ProductName = row["ProductName"].ToString();
  12137. int supplierId = Convert.ToInt32(row["SupplierId"]);
  12138. if (no_suppliers.Contains(supplierId))
  12139. {
  12140. continue;
  12141. }
  12142. string seller_memo = row["seller_memo"].ToString();
  12143. bool ispj = false;//是否配件单
  12144. bool isfirst = true;//第一个配
  12145. maps.Keys.ForEach(key =>
  12146. {
  12147. //备注包含配件
  12148. if (seller_memo.Contains(key) && isfirst)
  12149. {
  12150. List<string> list = maps[key];
  12151. ispj = true;
  12152. isfirst = false;
  12153. for (int i = 0; i < list.Count; i++)
  12154. {
  12155. if (seller_memo.Contains(list[i]))
  12156. {
  12157. ispj = false;
  12158. break;
  12159. }
  12160. }
  12161. }
  12162. });
  12163. if (ispj)
  12164. {
  12165. continue;
  12166. }
  12167. seller_memo = seller_memo.Replace("UV", "uv");
  12168. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  12169. //吊牌归到卡片
  12170. seller_memo = seller_memo.Replace("吊牌", "卡片");
  12171. seller_memo = seller_memo.Replace("卡套", "卡片");
  12172. seller_memo = seller_memo.Replace("封套", "卡片");
  12173. seller_memo = seller_memo.Replace("吸管套", "卡片");
  12174. seller_memo = seller_memo.Replace("腰封", "卡片");
  12175. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  12176. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  12177. seller_memo = seller_memo.Replace("横幅", "条幅");
  12178. seller_memo = seller_memo.Replace("锦旗", "条幅");
  12179. string map_key = "";
  12180. string type = "";
  12181. if (supplierMap.ContainsKey(supplierId))
  12182. {
  12183. foreach (var kvp in supplierMap[supplierId])
  12184. {
  12185. if (seller_memo.Contains(kvp.Key))
  12186. {
  12187. map_key = kvp.Value;
  12188. type = kvp.Value;
  12189. break;
  12190. }
  12191. }
  12192. }
  12193. if (map_key == "")
  12194. {
  12195. type = ProductName;
  12196. map_key = ProductName;
  12197. if (smSupplier.Contains(supplierId))
  12198. {
  12199. type = "数码";
  12200. map_key = "数码";
  12201. }
  12202. }
  12203. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  12204. {
  12205. map_key = suppliers[supplierId];
  12206. }
  12207. map_key += "_" + row["SupplierName"].ToString();
  12208. Dictionary<string, int> map = null;
  12209. if (other_map.ContainsKey(map_key))
  12210. {
  12211. other_map.TryGetValue(map_key, out map);
  12212. }
  12213. else
  12214. {
  12215. map = new Dictionary<string, int>();
  12216. map.Add("all", 0);//全部
  12217. map.Add("unusua", 0);//异常数
  12218. map.Add("normal", 0);//正常数
  12219. map.Add("noMatch", 0);//未匹配
  12220. other_map.Add(map_key, map);
  12221. other_map.TryGetValue(map_key, out map);
  12222. }
  12223. //处理是否超时
  12224. string finishPlaceTime = row["FinishPlaceTime"].ToString();
  12225. string sellmer_mome = row["seller_memo"].ToString();
  12226. string txtCount = row["ProductCount"].ToString();
  12227. string FinishDeliveryTime = row["FinishDeliveryTime"].ToString();
  12228. map["all"]++;
  12229. if (string.IsNullOrEmpty(finishPlaceTime))
  12230. {
  12231. map["noMatch"]++;
  12232. continue;
  12233. }
  12234. if (string.IsNullOrEmpty(FinishDeliveryTime))
  12235. {
  12236. map["noMatch"]++;
  12237. continue;
  12238. }
  12239. if (!timer_map.ContainsKey(supplierId))
  12240. {
  12241. map["noMatch"]++;
  12242. continue;
  12243. }
  12244. List<CeErpSupplierProductTime> lists = timer_map[supplierId];
  12245. if (lists.Count > 0)
  12246. {
  12247. bool isComplate = false;
  12248. string[] productIds = null;
  12249. foreach (CeErpSupplierProductTime ceErpSupplierProductTime in lists)
  12250. {
  12251. string[] crafts = { };
  12252. if (string.IsNullOrEmpty(ceErpSupplierProductTime.productId))
  12253. {
  12254. continue;
  12255. }
  12256. if (ceErpSupplierProductTime.quantity > 0)
  12257. {
  12258. int quantity = commonHelper.handleProductCount(txtCount, true);
  12259. //订单数量大于写入的数量则跳过
  12260. if (quantity > ceErpSupplierProductTime.quantity)
  12261. {
  12262. continue;
  12263. }
  12264. }
  12265. productIds = ceErpSupplierProductTime.productId.Split(',');
  12266. if (productIds.Contains(productId.ToString()))
  12267. {
  12268. string textCraft = ceErpSupplierProductTime.craft;
  12269. textCraft = textCraft.Replace(",", ",");//统一格式
  12270. if (!string.IsNullOrEmpty(textCraft))
  12271. {
  12272. crafts = textCraft.Split(',');
  12273. }
  12274. if (crafts.Length > 0)
  12275. {
  12276. bool isinCraft = false;
  12277. for (int i = 0; i < crafts.Length; i++)
  12278. {
  12279. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  12280. {
  12281. isinCraft = true;
  12282. break;
  12283. }
  12284. }
  12285. //有写工艺并且备注中没匹配中则跳过
  12286. if (!isinCraft)
  12287. {
  12288. continue;
  12289. }
  12290. }
  12291. DateTime deadLine = DateTime.Parse(ceErpSupplierProductTime.deadLine);
  12292. DateTime dayDeadLine = DateTime.Parse(ceErpSupplierProductTime.dayDeadLine);
  12293. int sendDay = ceErpSupplierProductTime.sendDay;
  12294. //订单发货时间
  12295. DateTime placeTime = DateTime.Parse(finishPlaceTime);
  12296. DateTime sendtime = DateTime.Now;//预计发货时间
  12297. DateTime dateTime = DateTime.Parse(FinishDeliveryTime);//实际发货时间
  12298. //下单时间小于当日发货时间则不用判断
  12299. //当日发货必须发货
  12300. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  12301. {
  12302. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59"));
  12303. }
  12304. else if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  12305. {
  12306. //在截稿时间之前下单的可以减去一天时间
  12307. sendDay = Math.Max(1, sendDay - 1);
  12308. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 00:00:00")).AddDays(sendDay);
  12309. }
  12310. else
  12311. {
  12312. sendDay = Math.Max(1, sendDay - 1);
  12313. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59")).AddDays(sendDay);
  12314. }
  12315. isComplate = true;
  12316. //判断有没有到发货日期大于0还没到发货时间
  12317. if (DateTime.Compare(sendtime.Date, dateTime.Date) < 0)
  12318. {
  12319. //匹配到就不要继续匹配了
  12320. map["unusua"]++;
  12321. break;
  12322. }
  12323. else
  12324. {
  12325. map["normal"]++;
  12326. break;
  12327. }
  12328. }
  12329. }
  12330. if (!isComplate)
  12331. {
  12332. map["noMatch"]++;
  12333. continue;
  12334. }
  12335. }
  12336. else
  12337. {
  12338. map["noMatch"]++;
  12339. }
  12340. }
  12341. DataTable dt = new DataTable();
  12342. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  12343. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  12344. dt.Columns.Add(new DataColumn("all", typeof(string)));
  12345. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  12346. dt.Columns.Add(new DataColumn("normal", typeof(string)));
  12347. dt.Columns.Add(new DataColumn("noMatch", typeof(string)));
  12348. dt.Columns.Add(new DataColumn("shipmentRate", typeof(string)));
  12349. other_map.Keys.ForEach(key =>
  12350. {
  12351. DataRow dr = dt.NewRow();
  12352. Dictionary<string, int> map = other_map[key];
  12353. string[] key_list = key.Split('_');
  12354. dr[0] = key_list[0];
  12355. dr[1] = key_list[1];
  12356. if (key_list.Length > 2)
  12357. {
  12358. dr[1] += "(" + key_list[2] + ")";
  12359. }
  12360. dr[2] = map["all"];
  12361. dr[3] = map["unusua"];
  12362. dr[4] = map["normal"];
  12363. dr[5] = map["noMatch"];
  12364. double rate = 0.00;
  12365. if (map["all"] > 0)
  12366. {
  12367. rate = Math.Round(((Convert.ToDouble(map["normal"]) + Convert.ToDouble(map["noMatch"])) / Convert.ToDouble(map["all"])), 2) * 100;
  12368. }
  12369. dr[6] = rate.ToString();
  12370. dt.Rows.Add(dr);
  12371. });
  12372. DataView dv = new DataView(dt);
  12373. dv.Sort = "SupplierName";
  12374. //dv.Sort = "ProductName desc";
  12375. DataTable dtNew = dv.ToTable();
  12376. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  12377. }
  12378. public void check_order_desing_info()
  12379. {
  12380. string ctid = GetPostString("ctid");
  12381. if (!string.IsNullOrEmpty(ctid))
  12382. {
  12383. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12384. if (ceErpTradeCell != null)
  12385. {
  12386. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  12387. returnSuccess(JsonConvert.SerializeObject(new { response }));
  12388. return;
  12389. }
  12390. returnErrorMsg("找不到订单");
  12391. return;
  12392. }
  12393. returnErrorMsg("找不到订单");
  12394. }
  12395. public void get_timeout_detail()
  12396. {
  12397. string poscode = CurrentUser.UserPost.Post.Code;
  12398. DataStruct dStruct = GetPostStruct();
  12399. List<string> lw = new List<string>();
  12400. string id = GetPostString("id");
  12401. string pay_date1 = GetPostString("pay_date1");
  12402. string pay_date2 = GetPostString("pay_date2");
  12403. int type = GetPostInt("type");
  12404. if (type == 0)
  12405. {
  12406. if (pay_date1.Length > 0)
  12407. {
  12408. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  12409. }
  12410. if (pay_date2.Length > 0)
  12411. {
  12412. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  12413. }
  12414. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  12415. }
  12416. if (type == 1)
  12417. {
  12418. if (pay_date1.Length > 0)
  12419. {
  12420. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  12421. }
  12422. if (pay_date2.Length > 0)
  12423. {
  12424. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  12425. }
  12426. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  12427. }
  12428. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12429. DataTable dt = null;
  12430. dt = WebCache.GetData("view_orderlist", dStruct);
  12431. writeGridDataTableJson(dStruct.TotalCount, dt);
  12432. }
  12433. public void saveUrgentChargePrice()
  12434. {
  12435. string ctid = GetPostString("ctid");
  12436. if (!string.IsNullOrEmpty(ctid))
  12437. {
  12438. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12439. if (ceErpTradeCell != null)
  12440. {
  12441. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  12442. if (prices <= 100)
  12443. {
  12444. returnErrorMsg("此订单金额不足100元,无法加急。");
  12445. return;
  12446. }
  12447. double price = GetPostDouble("price");
  12448. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  12449. if (ceErpTradeCellExtend == null)
  12450. {
  12451. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12452. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  12453. }
  12454. ceErpTradeCellExtend.urgentCharge = price;
  12455. if (ceErpTradeCellExtend.ID > 0)
  12456. {
  12457. ceErpTradeCellExtend.Update();
  12458. }
  12459. else
  12460. {
  12461. ceErpTradeCellExtend.Save();
  12462. }
  12463. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  12464. returnSuccessMsg("修改成功!");
  12465. return;
  12466. }
  12467. returnErrorMsg("找不到订单");
  12468. return;
  12469. }
  12470. returnErrorMsg("找不到订单");
  12471. }
  12472. public void finish_erp_order()
  12473. {
  12474. string ctid = GetPostString("ctid");
  12475. if (!string.IsNullOrEmpty(ctid))
  12476. {
  12477. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  12478. {
  12479. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12480. if (ceErpTradeCell != null)
  12481. {
  12482. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  12483. ceErpTradeCell.Update();
  12484. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  12485. returnSuccessMsg("修改成功!");
  12486. return;
  12487. }
  12488. }
  12489. }
  12490. returnErrorMsg("找不到订单");
  12491. }
  12492. public void get_trade_order_list()
  12493. {
  12494. string tid = GetPostString("tid");
  12495. if (!string.IsNullOrEmpty(tid))
  12496. {
  12497. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  12498. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12499. writeGridDataTableJson(data.Rows.Count, data);
  12500. return;
  12501. }
  12502. returnErrorMsg("找不到订单");
  12503. }
  12504. public void save_cell_spu()
  12505. {
  12506. string ctid = GetPostString("ctid");
  12507. string spu_id = GetPostString("spu_id");
  12508. if (!string.IsNullOrEmpty(ctid))
  12509. {
  12510. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12511. if (ceErpTradeCellExtend == null)
  12512. {
  12513. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12514. ceErpTradeCellExtend.ctid = ctid;
  12515. }
  12516. ceErpTradeCellExtend.spu_id = spu_id;
  12517. if (!string.IsNullOrEmpty(spu_id))
  12518. {
  12519. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12520. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  12521. }
  12522. if (ceErpTradeCellExtend.ID == 0)
  12523. {
  12524. ceErpTradeCellExtend.Create();
  12525. }
  12526. else
  12527. {
  12528. ceErpTradeCellExtend.Update();
  12529. }
  12530. returnSuccessMsg("修改成功!");
  12531. return;
  12532. }
  12533. returnErrorMsg("找不到订单");
  12534. }
  12535. public void change_express_info()
  12536. {
  12537. string ctid = GetPostString("ctid");
  12538. string transNo = GetPostString("transNo");
  12539. string transCom = GetPostString("transCom");
  12540. if (!string.IsNullOrEmpty(ctid))
  12541. {
  12542. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12543. if (ceErpTradeCellExtend == null)
  12544. {
  12545. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12546. ceErpTradeCellExtend.ctid = ctid;
  12547. }
  12548. ceErpTradeCellExtend.modExpressNo = transNo;
  12549. ceErpTradeCellExtend.modExpressCom = transCom;
  12550. ceErpTradeCellExtend.readMod = 2;
  12551. if (ceErpTradeCellExtend.ID == 0)
  12552. {
  12553. ceErpTradeCellExtend.Create();
  12554. }
  12555. else
  12556. {
  12557. ceErpTradeCellExtend.Update();
  12558. }
  12559. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  12560. returnSuccessMsg("修改成功!");
  12561. return;
  12562. }
  12563. returnErrorMsg("找不到订单");
  12564. }
  12565. public void get_change_express_list()
  12566. {
  12567. DataStruct dStruct = GetPostStruct();
  12568. List<string> lw = new List<string>();
  12569. int st = 2;
  12570. string tid = GetPostString("ctid");
  12571. if (tid.Length > 0)
  12572. {
  12573. string select_tid = getTidByCtid(tid);
  12574. lw.Add(string.Format("tid='{0}'", select_tid));
  12575. }
  12576. string shopname = GetPostString("shopname");
  12577. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12578. string buyernick = GetPostString("buyer_nick");
  12579. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12580. string sellermemo = GetPostString("seller_memo");
  12581. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12582. string supplier = GetPostString("supplier");
  12583. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12584. string customer = GetPostString("customer");
  12585. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12586. string design = GetPostString("design");
  12587. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12588. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12589. string poscode = CurrentUser.UserPost.Post.Code;
  12590. if (poscode != "SysAdmin")
  12591. {
  12592. string shopid = CurrentUser.User.pemShop;
  12593. lw.Add(string.Format("shopId in ({0})", shopid));
  12594. }
  12595. lw.Add("readMod = 2");
  12596. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12597. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  12598. writeGridDataTableJson(dStruct.TotalCount, dt);
  12599. }
  12600. public void deal_express_complete()
  12601. {
  12602. string ctid = GetPostString("ctid");
  12603. if (!string.IsNullOrEmpty(ctid))
  12604. {
  12605. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12606. if (ceErpTradeCellExtend == null)
  12607. {
  12608. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12609. ceErpTradeCellExtend.ctid = ctid;
  12610. }
  12611. ceErpTradeCellExtend.readMod = 1;
  12612. if (ceErpTradeCellExtend.ID == 0)
  12613. {
  12614. ceErpTradeCellExtend.Create();
  12615. }
  12616. else
  12617. {
  12618. ceErpTradeCellExtend.Update();
  12619. }
  12620. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  12621. returnSuccessMsg("修改成功!");
  12622. return;
  12623. }
  12624. returnErrorMsg("找不到订单");
  12625. }
  12626. public void aftersale_return_visit()
  12627. {
  12628. string ctid = GetPostString("ctid");
  12629. if (!string.IsNullOrEmpty(ctid))
  12630. {
  12631. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12632. if (ceErpTradeCellExtend == null)
  12633. {
  12634. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12635. ceErpTradeCellExtend.ctid = ctid;
  12636. }
  12637. ceErpTradeCellExtend.returnVisit = 1;
  12638. if (ceErpTradeCellExtend.ID == 0)
  12639. {
  12640. ceErpTradeCellExtend.Create();
  12641. }
  12642. else
  12643. {
  12644. ceErpTradeCellExtend.Update();
  12645. }
  12646. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12647. if (ceErpTradeAfterSaleExtend != null)
  12648. {
  12649. ceErpTradeAfterSaleExtend.TextResult = "";
  12650. ceErpTradeAfterSaleExtend.Update();
  12651. }
  12652. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  12653. returnSuccessMsg("修改成功!");
  12654. return;
  12655. }
  12656. returnErrorMsg("找不到订单");
  12657. }
  12658. public void orderPlaceInfo()
  12659. {
  12660. string ctids = GetPostString("ctids");
  12661. string[] list = ctids.Split(',');
  12662. foreach (string ctid in list)
  12663. {
  12664. CeErpSukuraData.createInfo(ctid, 3);
  12665. }
  12666. StringBuilder sql = new StringBuilder();
  12667. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  12668. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  12669. designHelper.api_approveDesign(ctids); //approveDesign
  12670. returnSuccessMsg("");
  12671. }
  12672. public void get_issue_list()
  12673. {
  12674. DataStruct dStruct = GetPostStruct();
  12675. List<string> lw = new List<string>();
  12676. int st = 2;
  12677. string tid = GetPostString("ctid");
  12678. if (tid.Length > 0)
  12679. {
  12680. string select_tid = getTidByCtid(tid);
  12681. lw.Add(string.Format("tid='{0}'", select_tid));
  12682. }
  12683. string shopname = GetPostString("shopname");
  12684. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12685. string buyernick = GetPostString("buyer_nick");
  12686. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12687. string sellermemo = GetPostString("seller_memo");
  12688. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12689. string supplier = GetPostString("supplier");
  12690. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12691. string customer = GetPostString("customer");
  12692. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12693. string design = GetPostString("design");
  12694. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12695. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12696. string poscode = CurrentUser.UserPost.Post.Code;
  12697. if (poscode != "SysAdmin")
  12698. {
  12699. string shopid = CurrentUser.User.pemShop;
  12700. lw.Add(string.Format("shopId in ({0})", shopid));
  12701. }
  12702. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  12703. {
  12704. lw.Add("IssueState = 1");
  12705. }
  12706. else
  12707. {
  12708. string iisstate = GetPostString("iisstate");
  12709. if ("1".Equals(iisstate))
  12710. {
  12711. lw.Add("IssueState =1");
  12712. }
  12713. else if ("2".Equals(iisstate))
  12714. {
  12715. lw.Add("IssueState = 2");
  12716. }
  12717. else
  12718. {
  12719. lw.Add("IssueState > 0");
  12720. }
  12721. }
  12722. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12723. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  12724. writeGridDataTableJson(dStruct.TotalCount, dt);
  12725. }
  12726. public void saveIssueContent()
  12727. {
  12728. string ctid = GetPostString("ctid");
  12729. if (!string.IsNullOrEmpty(ctid))
  12730. {
  12731. string content = GetPostString("content");
  12732. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12733. if (ceErpTradeAfterSaleExtend == null)
  12734. {
  12735. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  12736. ceErpTradeAfterSaleExtend.tid = ctid;
  12737. }
  12738. ceErpTradeAfterSaleExtend.IssueContent = content;
  12739. ceErpTradeAfterSaleExtend.IssueState = 1;
  12740. if (ceErpTradeAfterSaleExtend.ID > 0)
  12741. {
  12742. ceErpTradeAfterSaleExtend.Update();
  12743. }
  12744. else
  12745. {
  12746. ceErpTradeAfterSaleExtend.Create();
  12747. }
  12748. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  12749. returnSuccessMsg("添加成功!");
  12750. return;
  12751. }
  12752. returnErrorMsg("找不到订单");
  12753. }
  12754. public void dealIssueContent()
  12755. {
  12756. string ctid = GetPostString("ctid");
  12757. if (!string.IsNullOrEmpty(ctid))
  12758. {
  12759. string content = GetPostString("content");
  12760. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12761. if (ceErpTradeAfterSaleExtend != null)
  12762. {
  12763. ceErpTradeAfterSaleExtend.IssueState = 2;
  12764. ceErpTradeAfterSaleExtend.Update();
  12765. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  12766. returnSuccessMsg("修改完成!");
  12767. return;
  12768. }
  12769. }
  12770. returnErrorMsg("找不到订单");
  12771. }
  12772. public void set_tid_attachments()
  12773. {
  12774. string tid = GetPostString("tid");
  12775. string atta = GetPostString("atta");
  12776. if (!string.IsNullOrEmpty(tid))
  12777. {
  12778. if (string.IsNullOrEmpty(atta))
  12779. {
  12780. returnErrorMsg("文件地址为空");
  12781. return;
  12782. }
  12783. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12784. if (ceErpTradeCell != null)
  12785. {
  12786. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12787. if (ceErpTrade == null)
  12788. {
  12789. returnErrorMsg("找不到订单");
  12790. return;
  12791. }
  12792. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12793. bool isSend = false;
  12794. if (dt != null && dt.Rows.Count > 0)
  12795. {
  12796. foreach (DataRow row in dt.Rows)
  12797. {
  12798. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12799. {
  12800. isSend = true;
  12801. }
  12802. }
  12803. if (isSend)
  12804. {
  12805. returnErrorMsg("已发货无法修改");
  12806. return;
  12807. }
  12808. ceErpTrade.Attachments = atta;
  12809. ceErpTrade.Update();
  12810. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12811. returnSuccessMsg("上传成功!");
  12812. return;
  12813. }
  12814. }
  12815. }
  12816. returnErrorMsg("找不到订单");
  12817. }
  12818. public void get_tid_attachments()
  12819. {
  12820. string tid = GetPostString("tid");
  12821. if (!string.IsNullOrEmpty(tid))
  12822. {
  12823. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12824. if (ceErpTradeCell != null)
  12825. {
  12826. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12827. if (ceErpTrade == null)
  12828. {
  12829. returnErrorMsg("找不到订单");
  12830. return;
  12831. }
  12832. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12833. return;
  12834. }
  12835. }
  12836. returnErrorMsg("找不到订单");
  12837. }
  12838. public void check_erp_sameorders()
  12839. {
  12840. if (UrlPostParmsCheck("ctid"))
  12841. {
  12842. string eid = GetPostString("ctid");
  12843. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12844. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12845. if (entity != null && ceErpTrade != null)
  12846. {
  12847. if (entity.OrderState > 6)
  12848. {
  12849. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12850. return;
  12851. }
  12852. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12853. List<string> ids = new List<string>();
  12854. if (dt != null && dt.Rows.Count > 1)
  12855. {
  12856. bool needhe = true;
  12857. foreach (DataRow dr in dt.Rows)
  12858. {
  12859. ids.Add("'" + dr["ctid"] + "'");
  12860. /* //备注有合包
  12861. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12862. {
  12863. needhe = true;
  12864. }
  12865. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12866. {
  12867. needhe = true;
  12868. }
  12869. //顺丰快递
  12870. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12871. {
  12872. needhe = true;
  12873. }*/
  12874. }
  12875. if (!needhe)
  12876. {
  12877. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12878. return;
  12879. }
  12880. StringBuilder sql = new StringBuilder();
  12881. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12882. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12883. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12884. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12885. foreach (DataRow dr in dt.Rows)
  12886. {
  12887. dr["dstate"] = 0;
  12888. dr["dnumber"] = 0;
  12889. foreach (DataRow row in dt1.Rows)
  12890. {
  12891. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12892. {
  12893. dr["dstate"] = 2;
  12894. dr["default"] = 1;
  12895. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12896. }
  12897. }
  12898. if (eid.Equals(dr["ctid"].ToString()))
  12899. {
  12900. dr["dstate"] = 1;
  12901. dr["default"] = 1;
  12902. }
  12903. }
  12904. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12905. return;
  12906. }
  12907. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12908. return;
  12909. }
  12910. returnErrorMsg("未找到订单");
  12911. return;
  12912. }
  12913. returnErrorMsg("缺少必要的参数");
  12914. }
  12915. public void get_mark_number()
  12916. {
  12917. string eid = GetPostString("ctid");
  12918. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12919. if (entity != null)
  12920. {
  12921. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12922. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12923. int current = 1;
  12924. if (ceErpDeliverMark == null)
  12925. {
  12926. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12927. List<string> ids = new List<string>();
  12928. if (dt != null && dt.Rows.Count > 1)
  12929. {
  12930. foreach (DataRow dr in dt.Rows)
  12931. {
  12932. ids.Add("'" + dr["ctid"] + "'");
  12933. }
  12934. //查询已有的编号
  12935. StringBuilder sql = new StringBuilder();
  12936. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12937. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12938. if (dt1 == null || dt1.Rows.Count == 0)
  12939. {
  12940. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12941. List<int> list_number = new List<int>();
  12942. foreach (DataRow row in numbers.Rows)
  12943. {
  12944. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12945. }
  12946. //查询空余编号
  12947. for (int i = 0; i < list_number.Count + 2; i++)
  12948. {
  12949. if (!list_number.Contains(current))
  12950. {
  12951. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12952. //防止查询过程中有新数据生成
  12953. if (ceErpDeliverMark1 == null)
  12954. {
  12955. break;
  12956. }
  12957. }
  12958. current++;
  12959. }
  12960. }
  12961. else
  12962. {
  12963. foreach (DataRow row in dt1.Rows)
  12964. {
  12965. current = Convert.ToInt32(row["markNumber"]);
  12966. }
  12967. }
  12968. ceErpDeliverMark = new CeErpDeliverMark();
  12969. ceErpDeliverMark.ctid = eid;
  12970. ceErpDeliverMark.createtime = DateTime.Now;
  12971. if (ceErpTrade != null)
  12972. {
  12973. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12974. }
  12975. ceErpDeliverMark.markNumber = current;
  12976. ceErpDeliverMark.Create();
  12977. }
  12978. }
  12979. else
  12980. {
  12981. current = ceErpDeliverMark.markNumber;
  12982. }
  12983. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12984. return;
  12985. }
  12986. }
  12987. public void aftersaleCytSend()
  12988. {
  12989. string ctid = GetPostString("ctid");
  12990. if (!string.IsNullOrEmpty(ctid))
  12991. {
  12992. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12993. if (ceErpTradeCell != null)
  12994. {
  12995. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12996. }
  12997. returnSuccessMsg("推送成功");
  12998. return;
  12999. }
  13000. returnErrorMsg("缺少必要的参数");
  13001. }
  13002. public void packOrderInfo()
  13003. {
  13004. string ctids = GetPostString("ctids");
  13005. if (!string.IsNullOrEmpty(ctids))
  13006. {
  13007. string[] ctid_list = ctids.Split(',');
  13008. if (ctid_list.Length > 100)
  13009. {
  13010. returnErrorMsg("单次下载次数不能超过100个");
  13011. return;
  13012. }
  13013. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  13014. StringBuilder sql = new StringBuilder();
  13015. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  13016. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  13017. int supplierId = 0;
  13018. StringBuilder insterSql = new StringBuilder();
  13019. for (int i = 0; i < dt.Rows.Count; i++)
  13020. {
  13021. DataRow row = dt.Rows[i];
  13022. if (i == 0)
  13023. {
  13024. supplierId = Convert.ToInt32(row["SupplierId"]);
  13025. }
  13026. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  13027. {
  13028. returnErrorMsg("同车间的订单才能一起打包");
  13029. return;
  13030. }
  13031. int orderState = Convert.ToInt32(row["OrderState"]);
  13032. if (orderState != 5)
  13033. {
  13034. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  13035. return;
  13036. }
  13037. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  13038. }
  13039. CeErpPackData ceErpPackData = new CeErpPackData();
  13040. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  13041. ceErpPackData.supplierId = supplierId;
  13042. ceErpPackData.createtime = DateTime.Now;
  13043. ceErpPackData.createBy = CurrentUser.UserID;
  13044. ceErpPackData.createName = CurrentUser.UserName;
  13045. ceErpPackData.Create();
  13046. if (ceErpPackData.ID > 0)
  13047. {
  13048. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  13049. DbHelper.DbConn.ExecuteNonQuery(inSql);
  13050. }
  13051. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  13052. returnSuccessMsg("打包成功");
  13053. return;
  13054. }
  13055. returnErrorMsg("缺少必要的参数");
  13056. }
  13057. public void rePackOrderInfo()
  13058. {
  13059. string id = GetPostString("id");
  13060. if (!string.IsNullOrEmpty(id))
  13061. {
  13062. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  13063. if (ceErpPackData == null)
  13064. {
  13065. returnSuccessMsg("查无数据");
  13066. return;
  13067. }
  13068. ceErpPackData.upStatus = 0;
  13069. ceErpPackData.message = "";
  13070. ceErpPackData.Update();
  13071. returnSuccessMsg("打包成功");
  13072. return;
  13073. }
  13074. returnErrorMsg("缺少必要的参数");
  13075. }
  13076. public void backPackOrderInfo()
  13077. {
  13078. string id = GetPostString("id");
  13079. if (!string.IsNullOrEmpty(id))
  13080. {
  13081. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  13082. if (ceErpPackData == null)
  13083. {
  13084. returnSuccessMsg("查无数据");
  13085. return;
  13086. }
  13087. ceErpPackData.upStatus = 4;
  13088. ceErpPackData.Update();
  13089. List<string> list = new List<string>();
  13090. StringBuilder sql = new StringBuilder();
  13091. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  13092. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  13093. for (int i = 0; i < dt.Rows.Count; i++)
  13094. {
  13095. DataRow row = dt.Rows[i];
  13096. list.Add("'" + row["ctid"].ToString() + "'");
  13097. }
  13098. string textCtids = string.Join(",", list);
  13099. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=5,IsVerifyToSupplier=0,IsReturn=1,ReturnTime=GETDATE(),ReturnReason='无法打包' where ctid in ({0}) and OrderState=6", textCtids));
  13100. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", textCtids, (int)OrderState.下单完成, 0, "无法打包退回"));
  13101. returnSuccessMsg("退回成功");
  13102. return;
  13103. }
  13104. returnErrorMsg("缺少必要的参数");
  13105. }
  13106. public void addPackDownNum()
  13107. {
  13108. string id = GetPostString("id");
  13109. if (!string.IsNullOrEmpty(id))
  13110. {
  13111. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  13112. returnSuccessMsg("下载成功");
  13113. return;
  13114. }
  13115. returnErrorMsg("缺少必要的参数");
  13116. }
  13117. public void get_pack_list()
  13118. {
  13119. DataStruct dStruct = GetPostStruct();
  13120. List<string> lw = new List<string>();
  13121. string supplier = GetPostString("supplier");
  13122. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  13123. string posTag = CurrentUser.UserPost.Post.Code;
  13124. if (posTag == "Supplier")
  13125. {
  13126. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  13127. }
  13128. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  13129. dStruct.Order = "createtime desc";
  13130. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  13131. writeGridDataTableJson(dStruct.TotalCount, dt);
  13132. }
  13133. public void get_pack_order_list()
  13134. {
  13135. string packId = GetPostString("packId");
  13136. if (string.IsNullOrEmpty(packId))
  13137. {
  13138. returnErrorMsg("缺少必要的参数");
  13139. return;
  13140. }
  13141. StringBuilder sql = new StringBuilder();
  13142. sql.AppendFormat("select c.ctid,c.seller_memo,i.message from CE_ErpPackDataItem i left join CE_ErpTradeCell c on i.ctid=c.ctid where i.packId = {0}", packId);
  13143. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  13144. if (dt == null || dt.Rows.Count == 0)
  13145. {
  13146. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  13147. return;
  13148. }
  13149. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  13150. return;
  13151. }
  13152. public void get_supplier_product_time_list()
  13153. {
  13154. DataStruct dStruct = GetPostStruct();
  13155. List<string> lw = new List<string>();
  13156. string txtKey = GetPostString("txtKey");
  13157. if (txtKey.Length > 0)
  13158. {
  13159. lw.Add(string.Format("(supplierName = '{0}' or productName like '%{0}%')", txtKey));
  13160. }
  13161. string posTag = CurrentUser.UserPost.Post.Code;
  13162. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  13163. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  13164. writeGridDataTableJson(dStruct.TotalCount, dt);
  13165. }
  13166. public void saveSupplierProductTime()
  13167. {
  13168. string productId = GetPostString("productId");
  13169. if (string.IsNullOrEmpty(productId))
  13170. {
  13171. returnErrorMsg("缺少必要的参数");
  13172. return;
  13173. }
  13174. string productName = GetPostString("productName");
  13175. int supplierId = GetPostInt("supplierId");
  13176. if (supplierId == 0)
  13177. {
  13178. returnErrorMsg("缺少必要的参数");
  13179. return;
  13180. }
  13181. int quantity = GetPostInt("quantity");
  13182. int sendDay = GetPostInt("sendTime");
  13183. string supplierName = GetPostString("supplierName");
  13184. string craft = GetPostString("craft");
  13185. string deadLine = GetPostString("deadLine");
  13186. string dayDeadLine = GetPostString("dayDeadLine");
  13187. try
  13188. {
  13189. int eid = GetPostInt("eid");
  13190. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  13191. if (ceErpSupplierProductTime == null)
  13192. {
  13193. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  13194. }
  13195. ceErpSupplierProductTime.productId = productId;
  13196. ceErpSupplierProductTime.productName = productName;
  13197. ceErpSupplierProductTime.supplierId = supplierId;
  13198. ceErpSupplierProductTime.supplierName = supplierName;
  13199. ceErpSupplierProductTime.craft = craft;
  13200. ceErpSupplierProductTime.sendDay = sendDay;
  13201. ceErpSupplierProductTime.quantity = quantity;
  13202. if (!string.IsNullOrEmpty(deadLine))
  13203. {
  13204. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  13205. }
  13206. if (!string.IsNullOrEmpty(dayDeadLine))
  13207. {
  13208. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  13209. }
  13210. if (ceErpSupplierProductTime.ID == 0)
  13211. {
  13212. ceErpSupplierProductTime.Save();
  13213. }
  13214. else
  13215. {
  13216. ceErpSupplierProductTime.Update();
  13217. }
  13218. }
  13219. catch (Exception e)
  13220. {
  13221. }
  13222. returnSuccessMsg("保存成功");
  13223. return;
  13224. }
  13225. public void delSupplierProductTime()
  13226. {
  13227. int eid = GetPostInt("eid");
  13228. if (eid > 0)
  13229. {
  13230. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  13231. if (ceErpSupplierProductTime == null)
  13232. {
  13233. returnErrorMsg("查无数据");
  13234. return;
  13235. }
  13236. ceErpSupplierProductTime.Delete();
  13237. returnSuccessMsg("保存成功");
  13238. return;
  13239. }
  13240. returnErrorMsg("缺少必要的参数");
  13241. }
  13242. public void getExpressInfo()
  13243. {
  13244. string ctid = GetPostString("ctid");
  13245. if (!string.IsNullOrEmpty(ctid))
  13246. {
  13247. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13248. if (ceErpTradeCell != null)
  13249. {
  13250. string outSid = ceErpTradeCell.OutSid;
  13251. if (outSid.Length > 0)
  13252. {
  13253. string sql = string.Format("SELECT out_sid FROM [dbo].[CE_ErpExpressInfo] WHERE (out_sid in ({0}) or tid = '{1}') and ISNULL(DATALENGTH(postData), 0)>0;", "'" + outSid.Replace(",", "','") + "'", ceErpTradeCell.tid);
  13254. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13255. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  13256. return;
  13257. }
  13258. }
  13259. returnErrorMsg("查无记录");
  13260. return;
  13261. }
  13262. returnErrorMsg("缺少必要的参数");
  13263. }
  13264. public void getExpressPostData()
  13265. {
  13266. string express = GetPostString("express");
  13267. if (!string.IsNullOrEmpty(express))
  13268. {
  13269. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  13270. if (ceErpExpressInfo != null)
  13271. {
  13272. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  13273. return;
  13274. }
  13275. }
  13276. returnErrorMsg("缺少必要的参数");
  13277. }
  13278. public void checkSupplierOrder()
  13279. {
  13280. string ctids = GetPostString("ctids");
  13281. if (ctids != null)
  13282. {
  13283. List<string> list = new List<string>();
  13284. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  13285. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13286. for (int i = 0; i < dt.Rows.Count; i++)
  13287. {
  13288. DataRow row = dt.Rows[i];
  13289. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  13290. {
  13291. continue;
  13292. }
  13293. list.Add(row["seller_memo"].ToString());
  13294. }
  13295. if (list.Count > 0)
  13296. {
  13297. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", "'" + ctids.Replace(",", "','") + "'", (int)OrderState.下单完成, CurrentUser.UserID, "点击下载按钮"));
  13298. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  13299. return;
  13300. }
  13301. }
  13302. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  13303. return;
  13304. }
  13305. public void addPersonId()
  13306. {
  13307. string tid = GetPostString("tid");
  13308. string personId = GetPostString("personId");
  13309. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  13310. if (ceErpTrade != null)
  13311. {
  13312. ceErpTrade.receiver_zip = personId;
  13313. ceErpTrade.Update();
  13314. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  13315. returnSuccessMsg("保存成功");
  13316. return;
  13317. }
  13318. returnErrorMsg("缺少必要的参数");
  13319. }
  13320. public void addDeliveryPaymant()
  13321. {
  13322. string tid = GetPostString("tid");
  13323. string paymant = GetPostString("paymant");
  13324. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  13325. if (ceErpTrade != null)
  13326. {
  13327. if (!string.IsNullOrEmpty(paymant))
  13328. {
  13329. ceErpTrade.delivery_paymant = Convert.ToDouble(paymant);
  13330. }
  13331. ceErpTrade.Update();
  13332. LogHelper.addLog(tid, CurrentUser.UserID, "偏远物流费:" + paymant, 6);
  13333. returnSuccessMsg("保存成功");
  13334. return;
  13335. }
  13336. returnErrorMsg("缺少必要的参数");
  13337. }
  13338. public void saveCellFile()
  13339. {
  13340. string tid = GetPostString("tid");
  13341. string ctid = GetPostString("ctid");
  13342. string urls = GetPostString("urls");
  13343. string type = GetPostString("type");
  13344. string del = GetPostString("del");
  13345. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  13346. {
  13347. if (tradeCellFile == TradeCellFile.AUTH_FILE)
  13348. {
  13349. ctid = tid;
  13350. }
  13351. if ("1".Equals(del))
  13352. {
  13353. CeErpTradeCellFile.delByCtid(tid, ctid, tradeCellFile.ToString());
  13354. }
  13355. string[] list = urls.Split(',');
  13356. if (!string.IsNullOrEmpty(urls) && list.Length > 0)
  13357. {
  13358. foreach (string item in list)
  13359. {
  13360. CeErpTradeCellFile ceErpTradeCellFile = new CeErpTradeCellFile(tid, ctid, item, tradeCellFile.ToString());
  13361. ceErpTradeCellFile.Create();
  13362. LogHelper.addLog(ctid, CurrentUser.UserID, "上传客户文件:" + item, 6);
  13363. }
  13364. }
  13365. returnSuccessMsg("保存成功");
  13366. return;
  13367. }
  13368. returnErrorMsg("缺少必要的参数");
  13369. }
  13370. public void getCellFile()
  13371. {
  13372. string tid = GetPostString("tid");
  13373. string ctid = GetPostString("ctid");
  13374. string type = GetPostString("type");
  13375. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  13376. {
  13377. if (tradeCellFile == TradeCellFile.AUTH_FILE)
  13378. {
  13379. ctid = tid;
  13380. }
  13381. string sql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeCellFile] WHERE isDel=0 and tid='{0}' and ctid='{1}' and type='{2}';", tid, ctid, tradeCellFile);
  13382. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13383. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  13384. return;
  13385. }
  13386. returnErrorMsg("缺少必要的参数");
  13387. }
  13388. public void delCellFile()
  13389. {
  13390. string id = GetPostString("id");
  13391. if (string.IsNullOrEmpty(id))
  13392. {
  13393. returnErrorMsg("缺少必要的参数");
  13394. return;
  13395. }
  13396. CeErpTradeCellFile ceErpTradeCellFile = CeErpTradeCellFile.Get(id);
  13397. CeErpTradeCellFile.delByID(id);
  13398. LogHelper.addLog(ceErpTradeCellFile.ctid, CurrentUser.UserID, "删除客户文件", 6);
  13399. returnSuccessMsg("保存成功");
  13400. }
  13401. public void getInvoiceOrder()
  13402. {
  13403. string tid = GetPostString("tid");
  13404. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  13405. List<string> tids = new List<string>();
  13406. if (!string.IsNullOrEmpty(ceErpTrade.buyer_nick) && !string.IsNullOrEmpty(ceErpTrade.buyer_id))
  13407. {
  13408. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WHERE buyer_id = '{0}' AND seller_nick = '{1}' order by pay_time desc;", ceErpTrade.buyer_id, ceErpTrade.seller_nick);
  13409. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13410. foreach (DataRow dr in dt.Rows)
  13411. {
  13412. tids.Add("'" + dr["tid"].ToString() + "'");
  13413. }
  13414. }
  13415. else
  13416. {
  13417. tids.Add("'" + ceErpTrade.tid + "'");
  13418. }
  13419. DataTable cell_dt = new DataTable();
  13420. if (tids.Count > 0)
  13421. {
  13422. cell_dt = DbHelper.DbConn.ExecuteDataset(string.Format("SELECT * FROM [dbo].[CE_ErpTradeCell] WHERE tid in ({0});", string.Join(",", tids))).Tables[0];
  13423. }
  13424. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(cell_dt));
  13425. return;
  13426. }
  13427. public void getOrderLogInfo()
  13428. {
  13429. string ctid = GetPostString("ctid");
  13430. if (!string.IsNullOrEmpty(ctid))
  13431. {
  13432. StringBuilder sql = new StringBuilder();
  13433. sql.AppendFormat("select * from view_erptradelog where tid='{0}' order by id;", ctid);
  13434. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  13435. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(ds.Tables[0])) + "}");
  13436. return;
  13437. }
  13438. returnErrorMsg("缺少必要的参数");
  13439. }
  13440. public void setCellTeampId()
  13441. {
  13442. string ctid = GetPostString("ctid");
  13443. string tempId = GetPostString("tempId");
  13444. if (!string.IsNullOrEmpty(ctid))
  13445. {
  13446. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  13447. if (ceErpTradeCellExtend == null)
  13448. {
  13449. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  13450. ceErpTradeCellExtend.ctid = ctid;
  13451. }
  13452. ceErpTradeCellExtend.tempId = tempId;
  13453. if (ceErpTradeCellExtend.ID > 0)
  13454. {
  13455. ceErpTradeCellExtend.Update();
  13456. }
  13457. else
  13458. {
  13459. ceErpTradeCellExtend.Create();
  13460. }
  13461. designHelper.API_sendTempInfo(ctid, tempId);
  13462. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "修改模板id" + tempId, 6);
  13463. returnSuccessMsg("保存成功");
  13464. return;
  13465. }
  13466. returnErrorMsg("缺少必要的参数");
  13467. }
  13468. public void saveJointorder()
  13469. {
  13470. string ctid = GetPostString("ctid");
  13471. if (!string.IsNullOrEmpty(ctid))
  13472. {
  13473. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  13474. if (ceErpTradeCellExtend == null)
  13475. {
  13476. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  13477. ceErpTradeCellExtend.ctid = ctid;
  13478. }
  13479. if (ceErpTradeCellExtend.IsJoint == 1)
  13480. {
  13481. ceErpTradeCellExtend.IsJoint = 0;
  13482. }
  13483. else
  13484. {
  13485. ceErpTradeCellExtend.IsJoint = 1;
  13486. }
  13487. if (ceErpTradeCellExtend.ID > 0)
  13488. {
  13489. ceErpTradeCellExtend.Update();
  13490. }
  13491. else
  13492. {
  13493. ceErpTradeCellExtend.Create();
  13494. }
  13495. returnSuccessMsg("保存成功");
  13496. return;
  13497. }
  13498. returnErrorMsg("缺少必要的参数");
  13499. }
  13500. public void applyOrderBack()
  13501. {
  13502. string ctid = GetPostString("ctid");
  13503. string reason = GetPostString("reason");
  13504. if (!string.IsNullOrEmpty(ctid))
  13505. {
  13506. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13507. if (ceErpTradeCell == null)
  13508. {
  13509. returnErrorMsg("找不到订单");
  13510. return;
  13511. }
  13512. if (ceErpTradeCell.OrderState != 5 && ceErpTradeCell.OrderState != 6)
  13513. {
  13514. returnErrorMsg("待下单已下单才能申请");
  13515. return;
  13516. }
  13517. //下单后24小时后无法申请
  13518. if (ceErpTradeCell.OrderState == 6 && ceErpTradeCell.FinishPlaceTime != null)
  13519. {
  13520. DateTime now = DateTime.Now;
  13521. if (!string.IsNullOrEmpty(ceErpTradeCell.FinishPlaceTime.ToString()) && DateTime.Compare(DateTime.Parse(ceErpTradeCell.FinishPlaceTime.ToString()), now.AddHours(-24)) < 0)
  13522. {
  13523. returnErrorMsg("下单后24小时后无法申请");
  13524. return;
  13525. }
  13526. }
  13527. string sql = string.Format("select Con,UserId from CE_ErpTradeLog where tid = '{0}'", ceErpTradeCell.ctid);
  13528. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13529. if (dataTable != null && dataTable.Rows.Count > 0)
  13530. {
  13531. foreach (DataRow row in dataTable.Rows)
  13532. {
  13533. if (row["Con"].ToString().Contains("拒绝打回"))
  13534. {
  13535. returnErrorMsg("被拒绝过无法继续申请");
  13536. return;
  13537. }
  13538. }
  13539. }
  13540. ceErpTradeCell.IsReturn = 4;
  13541. ceErpTradeCell.Update();
  13542. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请打回:" + reason, ceErpTradeCell.OrderState);
  13543. returnSuccessMsg("保存成功");
  13544. return;
  13545. }
  13546. returnErrorMsg("缺少必要的参数");
  13547. }
  13548. public void cancelApplyOrderBack()
  13549. {
  13550. string ctid = GetPostString("ctid");
  13551. if (!string.IsNullOrEmpty(ctid))
  13552. {
  13553. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13554. if (ceErpTradeCell == null)
  13555. {
  13556. returnErrorMsg("找不到订单");
  13557. return;
  13558. }
  13559. if (ceErpTradeCell.IsReturn != 4)
  13560. {
  13561. returnErrorMsg("订单未在申请阶段");
  13562. return;
  13563. }
  13564. ceErpTradeCell.IsReturn = 0;
  13565. ceErpTradeCell.Update();
  13566. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "取消申请打回", ceErpTradeCell.OrderState);
  13567. returnSuccessMsg("保存成功");
  13568. return;
  13569. }
  13570. returnErrorMsg("缺少必要的参数");
  13571. }
  13572. public void get_erp_applybackorderlist()
  13573. {
  13574. DataStruct dStruct = GetPostStruct();
  13575. List<string> lw = new List<string>();
  13576. string tid = GetPostString("ctid");
  13577. if (tid.Length > 0)
  13578. {
  13579. string select_tid = getTidByCtid(tid);
  13580. lw.Add(string.Format("tid='{0}'", select_tid));
  13581. }
  13582. string shopname = GetPostString("shopname");
  13583. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  13584. string buyernick = GetPostString("buyer_nick");
  13585. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  13586. string customer = GetPostString("customer");
  13587. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  13588. string design = GetPostString("design");
  13589. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  13590. string orderState = GetPostString("orderState");
  13591. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  13592. string supplier = GetPostString("supplier");
  13593. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  13594. string sellermemo = GetPostString("seller_memo");
  13595. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  13596. string otherMemo = GetPostString("otherMemo");
  13597. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  13598. string address = GetPostString("address");
  13599. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  13600. string date1 = GetPostString("date1");
  13601. string date2 = GetPostString("date2");
  13602. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  13603. if (dw.Length > 0) lw.Add(dw);
  13604. string price1 = GetPostString("price1");
  13605. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  13606. string price2 = GetPostString("price2");
  13607. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  13608. if (CurrentUser.UserPost.Post.Code == "Supplier")
  13609. {
  13610. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  13611. lw.Add(string.Format("OrderState = 6"));
  13612. }
  13613. else if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  13614. {
  13615. lw.Add("OrderState in (5,6) ");
  13616. }
  13617. lw.Add(string.Format("IsReturn = 4"));
  13618. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  13619. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  13620. string pagesize = GetPostString("pagesize");
  13621. if (pagesize != null)
  13622. {
  13623. dStruct.PageSize = 200;
  13624. }
  13625. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  13626. writeGridDataTableJson(dStruct.TotalCount, dt);
  13627. }
  13628. public void refuseBackOrder()
  13629. {
  13630. string ctid = GetPostString("ctid");
  13631. if (!string.IsNullOrEmpty(ctid))
  13632. {
  13633. string reason = GetPostString("returnreason");
  13634. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13635. if (ceErpTradeCell == null)
  13636. {
  13637. returnErrorMsg("找不到订单");
  13638. return;
  13639. }
  13640. string sql = string.Format("select Con,UserId from CE_ErpTradeLog where tid = '{0}' order by ID desc", ceErpTradeCell.ctid);
  13641. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13642. int userId = 0;
  13643. if (dataTable != null && dataTable.Rows.Count > 0)
  13644. {
  13645. foreach (DataRow row in dataTable.Rows)
  13646. {
  13647. if (row["Con"].ToString().Contains("申请打回:"))
  13648. {
  13649. userId = Convert.ToInt32(row["UserId"]);
  13650. }
  13651. }
  13652. }
  13653. if (userId > 0)
  13654. {
  13655. CeErpMessageTip ct = new CeErpMessageTip();
  13656. ct.tid = ceErpTradeCell.ctid;
  13657. ct.sectionId = 0;
  13658. ct.userId = userId;
  13659. ct.type = 4;
  13660. ct.isVisit = false;
  13661. ct.content = ceErpTradeCell.ctid + ",申请打回被拒绝:" + reason;
  13662. ct.Create();
  13663. }
  13664. ceErpTradeCell.IsReturn = 0;
  13665. ceErpTradeCell.Update();
  13666. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "拒绝打回:" + reason, ceErpTradeCell.OrderState);
  13667. returnSuccessMsg("保存成功");
  13668. return;
  13669. }
  13670. returnErrorMsg("缺少必要的参数");
  13671. }
  13672. public void passApplyBack()
  13673. {
  13674. if (UrlPostParmsCheck("ctid"))
  13675. {
  13676. string eid = GetPostString("ctid");
  13677. CeErpTradeCell entity = null;
  13678. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  13679. string userpost = CurrentUser.UserPost.Post.Code;
  13680. if (entity != null)
  13681. {
  13682. string message = "操作成功!";
  13683. string isDown = "";
  13684. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  13685. {
  13686. message = "订单有被点击下载。请注意沟通是否已下载完!";
  13687. isDown = "被点击下载";
  13688. }
  13689. bool isPlace = false;
  13690. if (entity.OrderState > 6)
  13691. {
  13692. returnErrorMsg("已发货无法打回!");
  13693. return;
  13694. }
  13695. if (entity.OrderState == 6)
  13696. {
  13697. isPlace = true;
  13698. }
  13699. bool isNeedUpdateCell2 = false;
  13700. if (entity.OrderState >= 6)
  13701. {
  13702. isNeedUpdateCell2 = true;
  13703. }
  13704. int returnTag = 2;
  13705. if (userpost == "Supplier")
  13706. {
  13707. returnTag = 1;
  13708. }
  13709. int toType = GetPostInt("totype");
  13710. string fromType = "3";
  13711. if (entity.OrderState < 5)
  13712. {
  13713. fromType = "3";
  13714. }
  13715. else
  13716. {
  13717. fromType = "4";
  13718. }
  13719. if (entity.IsXianHuo == 0)
  13720. {
  13721. if (returnTag == 2)
  13722. {
  13723. if (toType == 1)
  13724. {
  13725. entity.OrderState = 0;
  13726. entity.ReturnUserType = 1;
  13727. string clearman = GetPostString("clearman");
  13728. if (!string.IsNullOrEmpty(clearman))
  13729. {
  13730. entity.DesignUserId = 0;
  13731. }
  13732. }
  13733. else
  13734. {
  13735. entity.OrderState = 3;
  13736. entity.ReturnUserType = 2;
  13737. }
  13738. entity.IsReadTag = 1;
  13739. }
  13740. else if (returnTag == 1)
  13741. {
  13742. entity.OrderState = 5;
  13743. }
  13744. entity.IsVerifyToSupplier = false;
  13745. }
  13746. if (entity.IsXianHuo == 1)
  13747. {
  13748. entity.OrderState = 5;
  13749. }
  13750. entity.IsVerifyToSupplier = false;
  13751. entity.IsHaveNewOrder = 0;
  13752. entity.UnusualTag = 0;
  13753. entity.UnusualTime = null;
  13754. entity.UnusualCon = "";
  13755. entity.IsReturn = returnTag;
  13756. entity.ReturnTime = DateTime.Now;
  13757. entity.UpdateTime = DateTime.Now;
  13758. entity.ReturnReason = GetPostString("returnreason");
  13759. entity.Update();
  13760. if (entity.OrderState == 3)
  13761. {
  13762. ApiVo apiVo = new ApiVo();
  13763. apiVo.orderNumber = entity.ctid;
  13764. apiVo.actionName = "rebutDesign";
  13765. apiVo.orderRemarks = entity.ReturnReason;
  13766. designHelper.API_WorkCore(apiVo);//rebutDesign
  13767. }
  13768. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason + isDown, entity.OrderState);
  13769. if (isPlace)
  13770. {
  13771. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  13772. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  13773. if (dth != null && dth.Rows.Count > 0)
  13774. {
  13775. dataSendOrderBean dataSendOrderBean = null;
  13776. foreach (DataRow item in dth.Rows)
  13777. {
  13778. try
  13779. {
  13780. dataSendOrderBean = new dataSendOrderBean();
  13781. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  13782. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  13783. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  13784. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  13785. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  13786. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  13787. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  13788. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  13789. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  13790. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  13791. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  13792. dataSendOrderBean.Radio1723534706288 = "打回";
  13793. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  13794. if (result != null)
  13795. {
  13796. if ("0".Equals(result.errcode))
  13797. {
  13798. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  13799. }
  13800. else
  13801. {
  13802. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  13803. }
  13804. }
  13805. }
  13806. catch (Exception ex)
  13807. {
  13808. }
  13809. }
  13810. }
  13811. }
  13812. returnSuccessMsg(message);
  13813. return;
  13814. }
  13815. returnErrorMsg("找不到订单记录");
  13816. }
  13817. }
  13818. public void getApplyBackCount()
  13819. {
  13820. string sql = string.Format("SELECT top 1 ctid FROM [dbo].[CE_ErpTradeCell]");
  13821. List<string> lw = new List<string>();
  13822. lw.Add("IsReturn = 4");
  13823. if (CurrentUser.UserPost.Post.Code == "Supplier")
  13824. {
  13825. lw.Add("OrderState = 6");
  13826. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  13827. }
  13828. else if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  13829. {
  13830. lw.Add("OrderState = 5");
  13831. }
  13832. else
  13833. {
  13834. ReturnSuccess("{" + string.Format("\"data\":{0}", "0") + "}");
  13835. return;
  13836. }
  13837. sql += " where " + string.Join(" and ", lw.ToArray());
  13838. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13839. List<string> list = new List<string>();
  13840. if (dataTable != null && dataTable.Rows.Count > 0)
  13841. {
  13842. foreach (DataRow row in dataTable.Rows)
  13843. {
  13844. list.Add(row["ctid"].ToString());
  13845. }
  13846. }
  13847. ReturnSuccess("{" + string.Format("\"data\":{0}", "\"" + string.Join(",", list) + "\"") + "}");
  13848. return;
  13849. }
  13850. public void getSysPrice()
  13851. {
  13852. string ctid = GetPostString("ctid");
  13853. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13854. if (ceErpTradeCell.ProductId == 0)
  13855. {
  13856. returnSuccessMsg("没有产品id");
  13857. }
  13858. dataHelper.get_sys_price(ceErpTradeCell);
  13859. returnSuccessMsg("保存成功");
  13860. }
  13861. }
  13862. }