sync.order.cs 572 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324
  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.WebControls;
  37. using Utils;
  38. using Utils.Serialization;
  39. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  40. using static SiteCore.taoObj.Api_trade_info;
  41. using static SiteCore.taoObj.Api_waybill_code_response_Obj;
  42. using static SiteCore.taoObj.work_core_vo;
  43. using static System.Net.Mime.MediaTypeNames;
  44. namespace SiteCore.Handler
  45. {
  46. public partial class sync
  47. {
  48. public void get_erp_orderlist()
  49. {
  50. string poscode = CurrentUser.UserPost.Post.Code;
  51. DataStruct dStruct = GetPostStruct();
  52. //apiHelper.Api_SyncOrderByTime("598825");
  53. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  54. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  55. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  56. //banniuApiHelper.sendLogisticsInfo(null);
  57. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  58. //commonHelper.checkOrderListDesignInfo("4042031616863358615");
  59. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2484048723252587257");
  60. //int sid = commonHelper.autoDistributeToSupplier(entity);
  61. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  62. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1740972223000,\"deliveryType\":\"OFFLINE\",\"discountFee\":0.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1741145016000,\"lines\":[{\"mark2\":[],\"num\":1,\"outerId\":\"\",\"payment\":10.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2208932202028/O1CN01SQkhPk1QqsBIMPegn_!!0-item_pic.jpg\",\"platServiceFee\":0.0,\"price\":10.0,\"refOlId\":\"2484480075794418199\",\"refSkuId\":\"0\",\"refSpuId\":\"787248116865\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":10.0,\"singleFee\":10.0,\"spuOuterId\":\"\",\"standards\":\"\",\"status\":\"NOT_SHIPPED\",\"title\":\"饰品售后卡片定制珠宝项链购后感谢卡硬卡设计金银保养留言卡纸制作电商包裹贺卡高级明信片首饰好平小卡印刷\",\"totalFee\":10.0,\"totalPrice\":10.0,\"totalSellPrice\":10.0}],\"logisticsOrderNo\":\"\",\"mark2\":[],\"modifyTime\":1740995566000,\"openBuyerId\":\"AAFoRHraABkUZRPgSx0XdWH-\",\"openBuyerNick\":\"t**\",\"openSellerNick\":\"麦郁旗舰店\",\"orderSource\":\"SYNC\",\"orderTime\":1740972209000,\"payTime\":1740972216000,\"payment\":10.0,\"platServiceFee\":0.0,\"posCode\":\"maiyu\",\"posId\":598808,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0},\"receivedPayment\":0.0,\"receiverCity\":\"湖州市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"吴兴区\",\"receiverId\":\"82b7afe37a7abf32c5a68285642bc6c7$\",\"receiverState\":\"浙江省\",\"receiverTown\":\"织里镇\",\"refOid\":\"2484480075794418199\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"寄样-卡片-300克铜版纸-tb90589912-小元-2,寄样-卡片-300克雅柔纸-tb90589912-小元-2,寄样-卡片-300克蛋壳纸-tb90589912-小元-2,寄样-卡片-300克刚古水纹纸-tb90589912-小元-2,寄样-卡片-300克荷兰白卡纸-tb90589912-小元-2\",\"serviceFee\":0.0,\"status\":\"NOT_SHIPPED\",\"totalFee\":10.0,\"totalPrice\":10.0,\"totalSellPrice\":10.0,\"type\":\"SALE\"}}");
  63. //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}}");
  64. List<string> lw = new List<string>();
  65. string tid = GetPostString("ctid");
  66. string date1 = GetPostString("date1");
  67. //12-1 修改
  68. string urgent = GetPostString("urgent");
  69. string back = GetPostString("back");
  70. string offlineSearch = GetPostString("offlineSearch");
  71. int paramsCount = 0;
  72. if (!string.IsNullOrWhiteSpace(urgent))
  73. {
  74. if (urgent.Equals("true"))
  75. {
  76. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  77. }
  78. }
  79. if (!string.IsNullOrWhiteSpace(back))
  80. {
  81. if (back.Equals("true"))
  82. {
  83. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  84. }
  85. }
  86. if (!string.IsNullOrWhiteSpace(offlineSearch))
  87. {
  88. if (offlineSearch.Equals("true"))
  89. {
  90. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  91. }
  92. }
  93. //end
  94. string date2 = GetPostString("date2");
  95. string buyernick = GetPostString("buyer_nick");
  96. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  97. {
  98. if (tid.Length <= 0 && buyernick.Length <= 0)
  99. {
  100. return;
  101. }
  102. }
  103. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  104. {
  105. if (tid.Length > 0)
  106. {
  107. lw.Add(string.Format("(ctid='{0}' or tid='{0}' or OrderSn='{0}')", tid));
  108. }
  109. if (buyernick.Length > 0)
  110. {
  111. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  112. }
  113. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  114. if (dw.Length > 0)
  115. {
  116. lw.Add(dw);
  117. }
  118. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  119. {
  120. string usershop = CurrentUser.User.pemShop;
  121. lw.Add(string.Format("ShopId in ({0})", usershop));
  122. }
  123. }
  124. else
  125. {
  126. if (ex_psize == 0)
  127. {
  128. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  129. }
  130. if (PKey != "admin")
  131. {
  132. string usershop = CurrentUser.User.pemShop;
  133. lw.Add(string.Format("ShopId in ({0})", usershop));
  134. paramsCount++;
  135. }
  136. }
  137. string uploaddate1 = GetPostString("uploaddate1");
  138. string uploaddate2 = GetPostString("uploaddate2");
  139. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  140. if (update.Length > 0) lw.Add(update);
  141. string deliverydate1 = GetPostString("deliverydate1");
  142. string deliverydate2 = GetPostString("deliverydate2");
  143. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  144. if (deliverydate.Length > 0)
  145. {
  146. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  147. };
  148. string shopname = GetPostString("shopname");
  149. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  150. string addwechat = GetPostString("addwechat");
  151. if (addwechat.Length > 0)
  152. {
  153. int addWt = Convert.ToInt32(addwechat);
  154. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  155. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  156. }
  157. string customer = GetPostString("customer");
  158. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  159. string design = GetPostString("design");
  160. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  161. string orderState = GetPostString("orderState");
  162. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  163. string address = GetPostString("address");
  164. 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));
  165. string sellermemo = GetPostString("seller_memo");
  166. if (sellermemo.Length > 0)
  167. {
  168. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  169. }
  170. string backReason = GetPostString("backReason");
  171. if (backReason.Length > 0)
  172. {
  173. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  174. }
  175. string apdate1 = GetPostString("apdate1");
  176. string apdate2 = GetPostString("apdate2");
  177. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  178. if (dwap.Length > 0) lw.Add(dwap);
  179. string price1 = GetPostString("price1");
  180. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  181. string price2 = GetPostString("price2");
  182. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  183. string isoldcustomer = GetPostString("isoldcus");
  184. string finishdate1 = GetPostString("finishdate1");
  185. string finishdate2 = GetPostString("finishdate2");
  186. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  187. bool isFinish = false;
  188. if (finishdate.Length > 0)
  189. {
  190. lw.Add(finishdate);
  191. isFinish = true;
  192. paramsCount++;
  193. }
  194. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  195. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  196. if (ex_psize > 0)
  197. {
  198. int UserID = CurrentUser.UserID;
  199. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  200. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  201. {
  202. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  203. }
  204. dStruct.Order = "pay_time desc";
  205. }
  206. string isNew = GetPostString("isNew");
  207. if (isNew == "true")
  208. {
  209. lw.Add(string.Format("IsNew = {0}", 1));
  210. }
  211. string overtime = GetPostString("overtime");
  212. if (overtime == "1")
  213. {
  214. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  215. }
  216. String usePost = CurrentUser.UserPost.Post.Code;
  217. if (usePost.Equals("Operation") == true)
  218. {
  219. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  220. }
  221. else
  222. {
  223. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  224. }
  225. //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";
  226. if (dStruct.PageSize == 100000)
  227. {
  228. dStruct.Order = "";
  229. }
  230. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  231. DataTable dt = null;
  232. string tablename = "view_orderlist";
  233. if (isFinish)
  234. {
  235. tablename = "view_orderlist_end";
  236. }
  237. dt = WebCache.GetData(tablename, dStruct);
  238. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  239. if (dt != null && dt.Rows.Count > 0)
  240. {
  241. foreach (DataRow dr in dt.Rows)
  242. {
  243. try
  244. {
  245. if (dr["refund_fees"] != null)
  246. {
  247. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  248. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  249. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  250. if (payment == refund_fees)
  251. {
  252. dr["refund_fees"] = Math.Round(refund_fees, 2);
  253. }
  254. else if (refund_fees == total_fee)
  255. {
  256. dr["refund_fees"] = payment;
  257. }
  258. else
  259. {
  260. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  261. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  262. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  263. }
  264. }
  265. // 对象操作
  266. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  267. ceErpTradeCell.ctid = dr["ctid"].ToString();
  268. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  269. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  270. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  271. if (dStruct.PageSize != 100000)
  272. {
  273. if (dr["DispatchSort"].ToString() == "2")
  274. {
  275. dr["gongchuang"] = 200;
  276. }
  277. else
  278. {
  279. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  280. dr["gongchuang"] = response.code;
  281. }
  282. }
  283. }
  284. catch (NullReferenceException ex)
  285. {
  286. // 处理空引用异常
  287. dr["refund_fees"] = "0.00";
  288. }
  289. }
  290. }
  291. writeGridDataTableJson(dStruct.TotalCount, dt);
  292. }
  293. public void get_erp_orderlist_sumprice()
  294. {
  295. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  296. return;
  297. List<string> lw = new List<string>();
  298. string tid = GetPostString("ctid");
  299. string date1 = GetPostString("date1");
  300. string date2 = GetPostString("date2");
  301. if (tid.Length > 0 || date1.Length > 0)
  302. {
  303. lw.Add(string.Format("ctid like '%{0}%'", tid));
  304. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  305. if (dw.Length > 0) lw.Add(dw);
  306. }
  307. else
  308. {
  309. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  310. }
  311. string shopname = GetPostString("shopname");
  312. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  313. string buyernick = GetPostString("buyer_nick");
  314. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  315. string customer = GetPostString("customer");
  316. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  317. string design = GetPostString("design");
  318. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  319. string orderState = GetPostString("orderState");
  320. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  321. string address = GetPostString("address");
  322. 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));
  323. string sellermemo = GetPostString("seller_memo");
  324. if (sellermemo.Length > 0)
  325. {
  326. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  327. }
  328. string apdate1 = GetPostString("apdate1");
  329. string apdate2 = GetPostString("apdate2");
  330. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  331. if (dwap.Length > 0) lw.Add(dwap);
  332. string price1 = GetPostString("price1");
  333. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  334. string price2 = GetPostString("price2");
  335. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  336. string isoldcustomer = GetPostString("isoldcus");
  337. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  338. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  339. if (PKey != "admin")
  340. {
  341. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  342. lw.Add(string.Format("shopId in ({0})", usershop));
  343. }
  344. //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";
  345. string mainWhere = string.Join(" and ", lw.ToArray());
  346. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  347. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  348. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  349. decimal total = 0;
  350. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  351. {
  352. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  353. }
  354. var res = new
  355. {
  356. data = total
  357. };
  358. string ro_jsond = JsonConvert.SerializeObject(res);
  359. returnSuccess(ro_jsond);
  360. return;
  361. }
  362. public void get_erp_CustomerServiceGather()
  363. {
  364. string userWhere = "", orderWhere = "";
  365. List<string> lw = new List<string>();
  366. string customer = GetPostString("customer");
  367. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  368. string shopname = GetPostString("shopname");
  369. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  370. string date1 = GetPostString("date1");
  371. string date2 = GetPostString("date2");
  372. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  373. if (dw.Length > 0) lw.Add(dw);
  374. orderWhere = string.Join(" and ", lw.ToArray());
  375. 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 " +
  376. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  377. "left join " +
  378. "( " +
  379. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  380. ") as b on a.ID = b.CustomerUserId " +
  381. "left join " +
  382. "( " +
  383. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  384. ") as d on a.ID = d.CustomerUserId " +
  385. "left join " +
  386. "( " +
  387. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  388. ") as e on a.ID = e.CustomerUserId " +
  389. "left join " +
  390. "( " +
  391. " select CustomerUserId, RefundCount, RefundSum from " +
  392. " ( " +
  393. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  394. " from CE_ErpTradeRefund a " +
  395. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  396. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  397. " group by CustomerUserId " +
  398. " ) as a " +
  399. ") as f on a.ID = f.CustomerUserId " +
  400. "where a.PostCode = 'CustomerService'",
  401. userWhere, orderWhere);
  402. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  403. writeGridDataTableJson(dt.Rows.Count, dt);
  404. //writeGridDataTableJson(dt.Rows.Count, dt);
  405. }
  406. //设计汇总
  407. public void get_erp_DesignerGather()
  408. {
  409. string userWhere = "", orderWhere = "";
  410. List<string> lw = new List<string>();
  411. string Designer = GetPostString("designer");
  412. int org = GetPostInt("org");
  413. if (Designer.Length > 0)
  414. {
  415. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  416. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  417. }
  418. else if (org > 0)
  419. {
  420. userWhere = string.Format(" where OrgID ={0}", org);
  421. }
  422. string shopname = GetPostString("shopname");
  423. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  424. string state = GetPostString("state");
  425. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  426. string OrderArea = GetPostString("order_area");
  427. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  428. string date1 = GetPostString("date1");
  429. string date2 = GetPostString("date2");
  430. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  431. if (dw.Length > 0) lw.Add(dw);
  432. string UpDate1 = GetPostString("UpDate1");
  433. string UpDate2 = GetPostString("UpDate2");
  434. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  435. if (dw.Length > 0) lw.Add(dw);
  436. orderWhere = string.Join(" and ", lw.ToArray());
  437. 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 (" +
  438. "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 " +
  439. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  440. "left join " +
  441. "( " +
  442. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  443. ") as b on a.ID = b.DesignUserId " +
  444. "left join " +
  445. "( " +
  446. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  447. ") as d on a.ID = d.DesignUserId " +
  448. "left join " +
  449. "( " +
  450. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  451. ") as e on a.ID = e.DesignUserId " +
  452. "left join " +
  453. "( " +
  454. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  455. ") as g on a.ID = g.DesignUserId " +
  456. "left join " +
  457. "( " +
  458. " select CustomerUserId, RefundCount, RefundSum from " +
  459. " ( " +
  460. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  461. " from CE_ErpTradeRefund a " +
  462. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  463. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  464. " group by CustomerUserId " +
  465. " ) as a " +
  466. ") as f on a.ID = f.CustomerUserId " +
  467. "where a.PostCode = 'Designer') as z",
  468. userWhere, orderWhere);
  469. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  470. writeGridDataTableJson(dt.Rows.Count, dt);
  471. }
  472. //删除tradecell的订单
  473. public void del_erp_cellorder()
  474. {
  475. if (UrlPostParmsCheck("ctid"))
  476. {
  477. string eid = GetPostString("ctid");
  478. CeErpTradeCell.DelByCtid(eid);
  479. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  480. returnSuccessMsg("删除成功");
  481. }
  482. }
  483. public void clear_erp_refundstate()
  484. {
  485. if (UrlPostParmsCheck("ids"))
  486. {
  487. string eids = GetPostString("ids");
  488. string[] ctidList = eids.Split(',');
  489. foreach (string ctid in ctidList)
  490. {
  491. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  492. if (entity != null)
  493. {
  494. entity.IsRefund = 0;
  495. entity.Update();
  496. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  497. }
  498. else
  499. continue;
  500. }
  501. returnSuccessMsg("操作成功");
  502. return;
  503. }
  504. returnErrorMsg("缺少必要参数");
  505. }
  506. public void set_erp_urgency()
  507. {
  508. if (UrlPostParmsCheck("ctid"))
  509. {
  510. string eid = GetPostString("ctid");
  511. CeErpTradeCell entity = null;
  512. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  513. if (entity != null)
  514. {
  515. string utime = GetPostString("urgencytime");
  516. if (utime.Length > 0)
  517. {
  518. entity.UrgencyTime = Convert.ToDateTime(utime);
  519. }
  520. else
  521. {
  522. returnErrorMsg("请选择加急时间");
  523. return;
  524. }
  525. if (entity.OrderState <= 4)
  526. {
  527. //entity.seller_memo = entity.seller_memo + "-加急";
  528. string smemo = entity.seller_memo;
  529. int kindex = smemo.IndexOf(")");
  530. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  531. if (lastoneStr != "-")
  532. {
  533. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  534. }
  535. string prememo = smemo.Substring(0, kindex + 2);
  536. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  537. int lastkindex = lastmemo.IndexOf("(");
  538. DateTime urgtime = Convert.ToDateTime(utime);
  539. string newlastmemo = "";
  540. if (lastkindex == 0)
  541. {
  542. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  543. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  544. }
  545. else
  546. {
  547. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  548. }
  549. entity.seller_memo = prememo + newlastmemo;
  550. }
  551. entity.IsUrgency = true;
  552. entity.Update();
  553. ApiVo apiVo = new ApiVo();
  554. apiVo.orderNumber = entity.ctid;
  555. apiVo.actionName = "changeDesign";
  556. apiVo.orderRemarks = entity.seller_memo;
  557. apiVo.remarkSign = 3;
  558. designHelper.API_WorkCore(apiVo); //changeDesign
  559. CeErpSukuraData.createInfo(entity.ctid, 7);
  560. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  561. returnSuccessMsg("设置成功!");
  562. return;
  563. }
  564. returnErrorMsg("找不到记录");
  565. }
  566. }
  567. public void set_erp_reset()
  568. {
  569. if (UrlPostParmsCheck("ctid"))
  570. {
  571. string eid = GetPostString("ctid");
  572. CeErpTradeCell entity = null;
  573. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  574. if (entity != null)
  575. {
  576. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  577. {
  578. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  579. {
  580. returnErrorMsg("财务要求已下单已发货无法重置");
  581. return;
  582. }
  583. }
  584. entity.IsUrgency = false;
  585. entity.seller_memo = "";
  586. entity.OtherMemo = "";
  587. entity.OrderState = 0;
  588. entity.IsReturn = 0;
  589. //entity.IsRefund = 0;
  590. entity.MemoOpt = 0;
  591. entity.AfterSaleState = 0;
  592. entity.AfterSaleResponsible = "";
  593. entity.AfterSaleUserId = 0;
  594. entity.IsNeedBill = 0;
  595. entity.CustomerUserId = 0;
  596. entity.DesignUserId = 0;
  597. entity.SupplierId = 0;
  598. entity.PlaceUserId = 0;
  599. entity.ptid = "";
  600. entity.IsSample = 0;
  601. entity.IsXianHuo = 0;
  602. entity.isDianziOrder = 0;
  603. entity.DispatchSort = 0;
  604. entity.FinishPlaceTime = null;
  605. entity.Update();
  606. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  607. if (trade != null)
  608. {
  609. trade.seller_memo = "";
  610. trade.Update();
  611. }
  612. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  613. returnSuccessMsg("重置成功!");
  614. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  615. if (desginBill != null)
  616. {
  617. desginBill.isDel = 1;
  618. desginBill.Update();
  619. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  620. }
  621. ApiVo apiVo = new ApiVo();
  622. apiVo.orderNumber = entity.ctid;
  623. apiVo.actionName = "resetDesign";
  624. designHelper.API_WorkCore(apiVo);//resetDesign
  625. return;
  626. }
  627. returnErrorMsg("找不到记录");
  628. }
  629. }
  630. public void save_erp_sellermemo()
  631. {
  632. if (UrlPostParmsCheck("ctid"))
  633. {
  634. string ctid = GetPostString("ctid");
  635. CeErpTradeCell entity = null;
  636. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  637. if (entity != null)
  638. {
  639. string memo = GetPostString("seller_memo");
  640. memo = memo.Replace(" ", "");
  641. if (memo.Contains("补差"))
  642. {
  643. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  644. return;
  645. }
  646. if (entity.seller_memo != memo)
  647. {
  648. if (entity.IsSample == 2)
  649. {
  650. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  651. return;
  652. }
  653. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  654. {
  655. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  656. {
  657. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  658. return;
  659. }
  660. }
  661. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  662. }
  663. commonHelper.getCytPrice(entity);
  664. int memoopt = GetPostInt("MemoOpt");
  665. Boolean ismemoopt = false;
  666. if (memoopt > 0)
  667. {
  668. string stropt = "";
  669. if (memoopt == 1)
  670. {
  671. stropt = "“改稿”";
  672. ismemoopt = true;
  673. }
  674. else if (memoopt == 2)
  675. {
  676. stropt = "“定稿”";
  677. }
  678. else if (memoopt == 3)
  679. {
  680. stropt = "“查货”";
  681. CeErpSukuraData.createInfo(entity.ctid, 6);
  682. }
  683. entity.MemoOpt = Convert.ToInt32(memoopt);
  684. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  685. }
  686. if (entity.OrderState < 5)
  687. {
  688. memo = memo.Replace("(", "(");
  689. memo = memo.Replace(")", ")");
  690. }
  691. entity.seller_memo = memo;
  692. entity.Update();
  693. ApiVo apiVo = new ApiVo();
  694. apiVo.orderNumber = entity.ctid;
  695. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  696. apiVo.orderRemarks = memo;
  697. apiVo.remarkSign = memoopt;
  698. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  699. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  700. returnSuccessMsg("保存成功!");
  701. return;
  702. }
  703. returnErrorMsg("找不到记录");
  704. }
  705. }
  706. public void ins_erp_checkorder()
  707. {
  708. if (UrlPostParmsCheck("ctid"))
  709. {
  710. string ctid = GetPostString("ctid");
  711. CeErpTradeCell entity = null;
  712. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  713. if (entity != null)
  714. {
  715. if (entity.OrderState < 6)
  716. {
  717. returnErrorMsg("下单完成后才可查货");
  718. return;
  719. }
  720. /*if (entity.OrderState > 6)
  721. {
  722. returnErrorMsg("订单已发货");
  723. return;
  724. }*/
  725. if (entity.FinishPlaceTime != null)
  726. {
  727. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  728. {
  729. returnErrorMsg("下单时间不足,无法查货");
  730. return;
  731. }
  732. }
  733. entity.MemoOpt = 3;
  734. entity.CheckOrderTime = DateTime.Now;
  735. entity.Update();
  736. CeErpSukuraData.createInfo(entity.ctid, 6);
  737. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  738. returnSuccessMsg("操作成功!");
  739. return;
  740. }
  741. returnErrorMsg("找不到记录");
  742. }
  743. }
  744. public void save_erp_othermemo()
  745. {
  746. if (UrlPostParmsCheck("ctid"))
  747. {
  748. string ctid = GetPostString("ctid");
  749. CeErpTradeCell entity = null;
  750. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  751. if (entity != null)
  752. {
  753. entity.OtherMemo = GetPostString("otherMemo");
  754. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  755. {
  756. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  757. StringBuilder sql = new StringBuilder();
  758. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  759. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  760. if (dt != null && dt.Rows.Count > 0)
  761. {
  762. foreach (DataRow dr in dt.Rows)
  763. {
  764. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  765. {
  766. //品类一直
  767. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  768. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  769. if (ceErpSampleCustomer == null)
  770. {
  771. ceErpSampleCustomer = new CeErpSampleCustomer();
  772. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  773. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  774. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  775. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  776. ceErpSampleCustomer.shopId = entity.ShopId;
  777. }
  778. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  779. ceErpSampleCustomer.lastTid = entity.tid;
  780. if (ceErpSampleCustomer.ID > 0)
  781. {
  782. ceErpSampleCustomer.Update();
  783. }
  784. else
  785. {
  786. ceErpSampleCustomer.Create();
  787. }
  788. }
  789. }
  790. }
  791. }
  792. //if (entity.IsOldCustomer == 1)
  793. //{
  794. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  795. //{
  796. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  797. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  798. //}
  799. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  800. //{
  801. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  802. // {
  803. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  804. // {
  805. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  806. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  807. // }
  808. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  809. // {
  810. // entity.OrderState = 2;
  811. // entity.DesignUserId = 0;
  812. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  813. // }
  814. // else
  815. // {
  816. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  817. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  818. // }
  819. // }
  820. //}
  821. //}
  822. entity.Update();
  823. returnSuccessMsg("保存成功!");
  824. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  825. return;
  826. }
  827. returnErrorMsg("找不到记录");
  828. }
  829. }
  830. public void save_erp_customermemo()
  831. {
  832. if (UrlPostParmsCheck("ctid"))
  833. {
  834. string ctid = GetPostString("ctid");
  835. CeErpTradeCell entity = null;
  836. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  837. if (entity != null)
  838. {
  839. entity.CustomerMemo = GetPostString("CustomerMemo");
  840. entity.Update();
  841. ApiVo apiVo = new ApiVo();
  842. apiVo.orderNumber = entity.ctid;
  843. apiVo.actionName = "followRemarks";
  844. apiVo.orderRemarks = entity.CustomerMemo;
  845. designHelper.API_WorkCore(apiVo);//followRemarks
  846. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  847. returnSuccessMsg("保存成功!");
  848. return;
  849. }
  850. returnErrorMsg("找不到记录");
  851. }
  852. }
  853. public void upd_erp_addmemotag()
  854. {
  855. if (UrlPostParmsCheck("ctid"))
  856. {
  857. ;
  858. string eid = GetPostString("ctid");
  859. string sfTagstr = GetPostString("memotag");
  860. CeErpTradeCell entity = null;
  861. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  862. if (entity != null)
  863. {
  864. if (entity.OrderState == 0)
  865. {
  866. returnErrorMsg("请先领单");
  867. return;
  868. }
  869. //撤销顺丰
  870. if (sfTagstr == "撤销顺丰")
  871. {
  872. entity.IsSF = 0;
  873. string reMsg = "";
  874. string oldmemo = entity.seller_memo;
  875. if (entity.OrderState < 5)
  876. {
  877. oldmemo = oldmemo.Replace("顺丰到付", "");
  878. oldmemo = oldmemo.Replace("顺丰寄付", "");
  879. entity.seller_memo = oldmemo;
  880. }
  881. else
  882. {
  883. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  884. {
  885. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  886. }
  887. }
  888. entity.Update();
  889. work_core_vo.ApiVo api = new work_core_vo.ApiVo();
  890. api.orderNumber = entity.ctid;
  891. api.actionName = "followRemarks";
  892. api.orderRemarks = entity.seller_memo;
  893. api.isSf = entity.IsSF.ToString();
  894. designHelper.API_WorkCore(api);//followRemarks
  895. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  896. returnSuccessMsg("撤销成功!" + reMsg);
  897. return;
  898. }
  899. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  900. {
  901. //string oldmemo = entity.seller_memo;
  902. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  903. string sfStr = GetPostString("memotag");
  904. string smemo = entity.seller_memo;
  905. int kindex = smemo.IndexOf(")");
  906. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  907. if (lastoneStr != "-")
  908. {
  909. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  910. }
  911. string prememo = smemo.Substring(0, kindex + 2);
  912. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  913. int lastkindex = lastmemo.IndexOf("(");
  914. string newlastmemo = "";
  915. if (lastkindex == 0)
  916. {
  917. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  918. newlastmemo = "(" + sfStr + "." + useLastmemo;
  919. }
  920. else
  921. {
  922. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  923. }
  924. entity.seller_memo = prememo + newlastmemo;
  925. }
  926. string sfTagMSg = "";
  927. if (sfTagstr == "顺丰寄付")
  928. {
  929. entity.IsSF = 1;
  930. sfTagMSg = "顺丰寄付";
  931. }
  932. else if (sfTagstr == "顺丰到付")
  933. {
  934. entity.IsSF = 2;
  935. sfTagMSg = "顺丰到付";
  936. }
  937. entity.Update();
  938. ApiVo apiVo = new ApiVo();
  939. apiVo.orderNumber = entity.ctid;
  940. apiVo.actionName = "orderRemarks";
  941. apiVo.orderRemarks = entity.seller_memo;
  942. apiVo.isSf = entity.IsSF.ToString();
  943. designHelper.API_WorkCore(apiVo);//orderRemarks
  944. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  945. returnSuccessMsg("标记成功!");
  946. return;
  947. }
  948. returnErrorMsg("找不到记录");
  949. }
  950. }
  951. public void upd_erp_ordertag()
  952. {
  953. if (UrlPostParmsCheck("ctid"))
  954. {
  955. string eid = GetPostString("ctid");
  956. CeErpTradeCell entity = null;
  957. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  958. if (entity != null)
  959. {
  960. int tag = GetPostInt("wechattag");
  961. //if(tag==4 && entity.IsSample == 2)
  962. //{
  963. // returnErrorMsg("补差价单不能标记微信单");
  964. // return;
  965. //}
  966. entity.wechatTag = tag;
  967. entity.Update();
  968. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  969. if (tag == 1)
  970. {
  971. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  972. if (cash == null)
  973. {
  974. CeErpTrade main = CeErpTrade.Get(entity.tid);
  975. cash = new CeErpReturnCash();
  976. cash.tid = entity.tid;
  977. cash.seller_nick = main.seller_nick;
  978. cash.payment = trade.payment;
  979. cash.buyer_nick = main.buyer_nick;
  980. cash.cashstate = 0;
  981. cash.rtype = "微信返现";
  982. cash.returnprice = 0;
  983. cash.created = DateTime.Now;
  984. cash.con = "订单标记微信单";
  985. cash.img = "";
  986. cash.applyuserid = CurrentUser.UserID;
  987. cash.Create();
  988. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  989. }
  990. else
  991. {
  992. cash.cashstate = 0;
  993. cash.Update();
  994. }
  995. CeErpSukuraData.createInfo(entity.ctid, 9);
  996. }
  997. else if (tag == 2)
  998. {
  999. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1000. if (cash == null)
  1001. {
  1002. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1003. cash = new CeErpReturnCash();
  1004. cash.tid = entity.tid;
  1005. cash.seller_nick = main.seller_nick;
  1006. cash.payment = trade.payment;
  1007. cash.buyer_nick = main.buyer_nick;
  1008. cash.cashstate = 0;
  1009. cash.rtype = "推购返现";
  1010. cash.returnprice = 5;
  1011. cash.created = DateTime.Now;
  1012. cash.con = "订单标记推购单";
  1013. cash.img = "";
  1014. cash.applyuserid = CurrentUser.UserID;
  1015. cash.Create();
  1016. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1017. }
  1018. else
  1019. {
  1020. cash.cashstate = 0;
  1021. cash.Update();
  1022. }
  1023. CeErpSukuraData.createInfo(entity.ctid, 9);
  1024. }
  1025. else if (tag == 3)
  1026. {
  1027. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1028. if (pers == null)
  1029. {
  1030. pers = new CeErpPersuade();
  1031. pers.ctid = entity.ctid;
  1032. pers.pstate = 0;
  1033. pers.created = DateTime.Now;
  1034. pers.applyuserid = CurrentUser.UserID;
  1035. pers.Create();
  1036. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1037. }
  1038. else
  1039. {
  1040. pers.pstate = 0;
  1041. pers.Update();
  1042. }
  1043. }
  1044. else if (tag == 4 || tag == 5)
  1045. {
  1046. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1047. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1048. if (pers == null)
  1049. {
  1050. pers = new CeErpStayGoods();
  1051. pers.t_id = entity.tid;
  1052. pers.status = "待审核";
  1053. pers.audit_type = 0;
  1054. if (tag == 4)
  1055. {
  1056. pers.stay_type = "微信推购";
  1057. }
  1058. else
  1059. {
  1060. pers.stay_type = "旺旺推购";
  1061. }
  1062. if (entity.IsXianHuo == 0)
  1063. {
  1064. pers.product_id = entity.ProductId;
  1065. }
  1066. pers.wangwang = main.buyer_nick;
  1067. pers.shop_name = main.seller_nick;
  1068. pers.creata_time = DateTime.Now;
  1069. pers.create_u_id = CurrentUser.UserID;
  1070. pers.create_u_name = CurrentUser.UserName;
  1071. pers.Create();
  1072. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1073. }
  1074. else
  1075. {
  1076. pers.audit_type = 0;
  1077. pers.Update();
  1078. }
  1079. CeErpSukuraData.createInfo(entity.ctid, 10);
  1080. }
  1081. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1082. returnSuccessMsg("标记成功!");
  1083. return;
  1084. }
  1085. returnErrorMsg("找不到记录");
  1086. }
  1087. }
  1088. public void upd_erp_ordertag_cancel()
  1089. {
  1090. if (UrlPostParmsCheck("ctid"))
  1091. {
  1092. string eid = GetPostString("ctid");
  1093. CeErpTradeCell entity = null;
  1094. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1095. if (entity != null)
  1096. {
  1097. entity.wechatTag = 0;
  1098. entity.Update();
  1099. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1100. if (pers != null)
  1101. {
  1102. pers.status = "取消推购";
  1103. pers.audit_type = 3;
  1104. pers.Update();
  1105. }
  1106. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1107. returnSuccessMsg("标记成功!");
  1108. return;
  1109. }
  1110. returnErrorMsg("找不到记录");
  1111. }
  1112. }
  1113. public void upd_erp_addweichattag()
  1114. {
  1115. if (UrlPostParmsCheck("ctid"))
  1116. {
  1117. ;
  1118. string eid = GetPostString("ctid");
  1119. CeErpTradeCell entity = null;
  1120. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1121. if (entity != null)
  1122. {
  1123. if (entity.IsAddWechat > 0)
  1124. {
  1125. returnErrorMsg("此单已经标记过了");
  1126. return;
  1127. }
  1128. 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);
  1129. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1130. if (dt.Rows.Count > 0)
  1131. {
  1132. entity.IsAddWechat = 2;
  1133. }
  1134. else
  1135. {
  1136. entity.IsAddWechat = 1;
  1137. }
  1138. entity.Update();
  1139. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1140. returnSuccessMsg("标记成功!");
  1141. return;
  1142. }
  1143. returnErrorMsg("找不到记录");
  1144. }
  1145. }
  1146. public void upd_erp_getmyorder()
  1147. {
  1148. if (UrlPostParmsCheck("ctid"))
  1149. {
  1150. ;
  1151. string eid = GetPostString("ctid");
  1152. CeErpTradeCell entity = null;
  1153. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1154. if (entity != null)
  1155. {
  1156. if (entity.ctid.IndexOf("C") != -1)
  1157. {
  1158. StringBuilder sql = new StringBuilder();
  1159. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1160. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1161. if (dt.Rows.Count > 0)
  1162. {
  1163. decimal total = 0;
  1164. foreach (DataRow dr in dt.Rows)
  1165. {
  1166. total += Convert.ToDecimal(dr["payment"]);
  1167. }
  1168. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1169. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1170. {
  1171. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1172. return;
  1173. }
  1174. }
  1175. }
  1176. entity.CustomerUserId = CurrentUser.UserID;
  1177. if (entity.OrderState < 2)
  1178. {
  1179. entity.OrderState = 2;
  1180. if (entity.ShopId != 0)
  1181. {
  1182. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1183. }
  1184. }
  1185. entity.Update();
  1186. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1187. returnSuccessMsg("领单成功!");
  1188. return;
  1189. }
  1190. returnErrorMsg("找不到记录");
  1191. }
  1192. }
  1193. public void getmyorder_from_init()
  1194. {
  1195. if (UrlPostParmsCheck("ctid"))
  1196. {
  1197. string eid = GetPostString("ctid");
  1198. CeErpTradeCell entity = null;
  1199. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1200. if (entity != null)
  1201. {
  1202. string sellerMemo = GetPostString("sellerMemo");
  1203. if (sellerMemo.Length > 0)
  1204. {
  1205. entity.seller_memo = sellerMemo;
  1206. }
  1207. string oterhMemo = GetPostString("otherMemo");
  1208. if (oterhMemo.Length > 0)
  1209. {
  1210. entity.OtherMemo = oterhMemo;
  1211. }
  1212. int urg = GetPostInt("urgency");
  1213. entity.IsUrgency = (urg == 1 ? true : false);
  1214. int wechat = GetPostInt("wechat");
  1215. int command = GetPostInt("command");
  1216. if (wechat == 1)
  1217. {
  1218. entity.wechatTag = 1;
  1219. }
  1220. if (command == 1)
  1221. {
  1222. entity.wechatTag = 2;
  1223. }
  1224. string pPro = GetPostString("pprofession");
  1225. if (pPro.Length > 0)
  1226. {
  1227. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1228. string spro = GetPostString("profession");
  1229. if (spro.Length > 0)
  1230. {
  1231. entity.ProfessionId = Convert.ToInt32(spro);
  1232. }
  1233. }
  1234. string proId = GetPostString("productId");
  1235. if (proId.Length > 0)
  1236. {
  1237. entity.ProductId = Convert.ToInt32(proId);
  1238. }
  1239. entity.Material = GetPostString("material");
  1240. entity.Craft = GetPostString("craft");
  1241. entity.CustomerUserId = CurrentUser.UserID;
  1242. if (entity.OrderState < 2)
  1243. {
  1244. entity.OrderState = 2;
  1245. if (entity.ShopId != 0)
  1246. {
  1247. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1248. }
  1249. }
  1250. entity.Update();
  1251. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1252. returnSuccessMsg("领单成功!");
  1253. return;
  1254. }
  1255. returnErrorMsg("找不到记录");
  1256. }
  1257. }
  1258. public void upd_erp_setrelationorder()
  1259. {
  1260. if (UrlPostParmsCheck("ctid"))
  1261. {
  1262. ;
  1263. string eid = GetPostString("ctid");
  1264. string ftid = GetPostString("ftid");
  1265. CeErpTradeCell entity = null;
  1266. CeErpTradeCell fentity = null;
  1267. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1268. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1269. if (fentity == null)
  1270. {
  1271. returnErrorMsg("找不到关联的主订单");
  1272. return;
  1273. }
  1274. if (entity != null)
  1275. {
  1276. if (entity.OrderState >= 5)
  1277. {
  1278. returnErrorMsg("本单已经设计完成无法关联");
  1279. return;
  1280. }
  1281. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1282. {
  1283. returnErrorMsg("线下单续审核后才能关联!");
  1284. return;
  1285. }
  1286. entity.ptid = ftid;
  1287. entity.OrderState = fentity.OrderState;
  1288. //entity.status = fentity.status;
  1289. entity.CustomerUserId = fentity.CustomerUserId;
  1290. entity.DesignUserId = fentity.DesignUserId;
  1291. entity.seller_memo = "补差价单:" + ftid;
  1292. entity.IsSample = 2;
  1293. entity.Update();
  1294. ApiVo apiVo = new ApiVo();
  1295. apiVo.orderNumber = ftid;
  1296. apiVo.payment = entity.payment;
  1297. apiVo.actionName = "repairDesign";
  1298. designHelper.API_WorkCore(apiVo);//repairDesign
  1299. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1300. returnSuccessMsg("关联成功!");
  1301. return;
  1302. }
  1303. else
  1304. returnErrorMsg("找不到记录");
  1305. }
  1306. }
  1307. public void download_erp_neworder()
  1308. {
  1309. string seller = GetPostString("seller_nick");
  1310. string tid = GetPostString("tid");
  1311. if (seller.Length <= 0 || tid.Length <= 0)
  1312. {
  1313. returnErrorMsg("数据错误");
  1314. }
  1315. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1316. //{
  1317. // returnErrorMsg("找不到店铺Sessionkey");
  1318. //}
  1319. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1320. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1321. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1322. if (res.IndexOf("refOid") == -1)
  1323. {
  1324. returnErrorMsg("下载订单数据失败");
  1325. return;
  1326. }
  1327. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1328. returnSuccessMsg("下载完成");
  1329. //tmcHelper.createNewOrder(res);
  1330. //CeErpTrade entr = null;
  1331. //entr = CeErpTrade.Get(tid);
  1332. //if (entr != null)
  1333. //{
  1334. // returnSuccess("下载成功");
  1335. // //下载成功之后,Cell表生成对应的订单;
  1336. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1337. //}
  1338. //else
  1339. //{
  1340. // returnErrorMsg("下载失败或者创建订单失败");
  1341. //}
  1342. }
  1343. public void set_erp_atersale()
  1344. {
  1345. if (UrlPostParmsCheck("ctid"))
  1346. {
  1347. string eid = GetPostString("ctid");
  1348. string reason = GetPostString("AfterSaleReason");
  1349. CeErpTradeCell entity = null;
  1350. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1351. if (entity != null)
  1352. {
  1353. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1354. {
  1355. returnErrorMsg("此订单已经在售后");
  1356. return;
  1357. }
  1358. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1359. //entity.AfterSaleReason = reason;
  1360. entity.AfterSaleTime = DateTime.Now;
  1361. entity.Update();
  1362. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1363. returnSuccessMsg("转售后成功!");
  1364. return;
  1365. }
  1366. returnErrorMsg("找不到记录");
  1367. }
  1368. }
  1369. public void set_erp_withdraw()
  1370. {
  1371. if (UrlPostParmsCheck("ctid"))
  1372. {
  1373. try
  1374. {
  1375. string eid = GetPostString("ctid");//商品id
  1376. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1377. CeWithdraw ceWithdrawSelect = null;
  1378. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1379. if (ceWithdrawSelect != null)
  1380. {
  1381. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1382. {
  1383. ceWithdrawSelect.status = -1;
  1384. ceWithdrawSelect.Update();
  1385. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1386. returnSuccessMsg("重新发起审核成功");
  1387. return;
  1388. }
  1389. else
  1390. {
  1391. returnSuccessMsg("请勿重复申请!");
  1392. return;
  1393. }
  1394. }
  1395. else
  1396. {
  1397. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1398. if (string.IsNullOrEmpty(CustomerUserId))
  1399. {
  1400. CustomerUserId = "-1";
  1401. }
  1402. int Userid = CurrentUser.UserID;//用户id
  1403. CeWithdraw ceWithdraw = new CeWithdraw();
  1404. ceWithdraw.tid = eid;
  1405. ceWithdraw.userid = Userid;
  1406. ceWithdraw.providerid = CustomerUserId;
  1407. ceWithdraw.status = 3;
  1408. ceWithdraw.creationtime = DateTime.Now;
  1409. ceWithdraw.Create();
  1410. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1411. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1412. return;
  1413. }
  1414. }
  1415. catch
  1416. {
  1417. returnErrorMsg("申请撤回订单失败");
  1418. return;
  1419. }
  1420. }
  1421. }
  1422. public void ins_erp_billinfo()
  1423. {
  1424. if (UrlPostParmsCheck("ctid"))
  1425. {
  1426. string eid = GetPostString("ctid");
  1427. CeErpTradeCell entity = null;
  1428. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1429. if (entity != null)
  1430. {
  1431. CeErpBill bill = CeErpBill.GetByTid(eid);
  1432. bool isHave = false;
  1433. if (bill != null)
  1434. {
  1435. isHave = true;
  1436. if (bill.state != 4)
  1437. {
  1438. returnErrorMsg("此单已经申请过发票了");
  1439. return;
  1440. }
  1441. }
  1442. if (entity.IsNeedBill == 0)
  1443. {
  1444. entity.IsNeedBill = 1;
  1445. }
  1446. entity.Update();
  1447. string errjson = "";
  1448. try
  1449. {
  1450. CeErpBill bill_entity = new CeErpBill();
  1451. bill_entity.tid = entity.tid;
  1452. bill_entity.title = GetPostString("title");
  1453. string taxstr = GetPostString("tax");
  1454. taxstr = taxstr.Replace(" ", "");
  1455. bill_entity.tax = taxstr;
  1456. bill_entity.bank = GetPostString("bank");
  1457. string bankacstr = GetPostString("bankac");
  1458. bankacstr = bankacstr.Replace(" ", "");
  1459. bill_entity.bankac = bankacstr;
  1460. bill_entity.address = GetPostString("address");
  1461. bill_entity.phone = GetPostString("phone");
  1462. bill_entity.price = GetPostString("price");
  1463. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1464. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1465. {
  1466. billCount += 1;
  1467. }
  1468. string prebill = "ltb";
  1469. for (int idx = 1; idx <= billCount; idx++)
  1470. {
  1471. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1472. string billoid = prebill + idx + dtstr;
  1473. bill_entity.billOrderId += billoid;
  1474. if (idx < billCount)
  1475. {
  1476. bill_entity.billOrderId += ",";
  1477. }
  1478. }
  1479. bill_entity.productId = GetPostInt("ProductName");
  1480. bill_entity.num = GetPostInt("num");
  1481. bill_entity.unit = GetPostString("unit");
  1482. bill_entity.type = GetPostString("type");
  1483. bill_entity.sendType = GetPostString("SendType");
  1484. bill_entity.email = GetPostString("email");
  1485. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1486. bill_entity.shopName = GetPostString("ShopName");
  1487. bill_entity.applymemo = GetPostString("applyMemo");
  1488. bill_entity.createTime = DateTime.Now;
  1489. bill_entity.state = 0;
  1490. bill_entity.userId = CurrentUser.UserID;
  1491. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1492. bill_entity.Create();
  1493. }
  1494. catch (Exception ex)
  1495. {
  1496. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1497. returnErrorMsg("创建发票出错!");
  1498. return;
  1499. }
  1500. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1501. returnSuccessMsg("发票申请成功!");
  1502. return;
  1503. }
  1504. returnErrorMsg("找不到记录");
  1505. }
  1506. }
  1507. public void ins_erp_neworder()
  1508. {
  1509. if (UrlPostParmsCheck("receiver_name"))
  1510. {
  1511. CeErpTrade entity = new CeErpTrade();
  1512. string plat_form = GetPostString("platform");
  1513. string preStr = "N_";
  1514. if (plat_form == "拼多多")
  1515. {
  1516. preStr = "P_";
  1517. }
  1518. else if (plat_form == "阿里巴巴")
  1519. {
  1520. preStr = "A_";
  1521. }
  1522. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1523. entity.seller_nick = GetPostString("seller_nick");
  1524. entity.buyer_nick = GetPostString("buyer_nick");
  1525. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1526. entity.total_fee = entity.payment;
  1527. entity.pay_time = DateTime.Now;
  1528. entity.status = "NOT_SHIPPED";
  1529. entity.receiver_name = GetPostString("receiver_name");
  1530. entity.receiver_mobile = GetPostString("receiver_mobile");
  1531. entity.receiver_state = GetPostString("receiver_state");
  1532. entity.receiver_city = GetPostString("receiver_city");
  1533. entity.receiver_district = GetPostString("receiver_district");
  1534. entity.receiver_address = GetPostString("receiver_address");
  1535. if (entity.receiver_state == "" || entity.receiver_city == "")
  1536. {
  1537. returnErrorMsg("收件地址不能为空");
  1538. return;
  1539. }
  1540. int shopId = 0;
  1541. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1542. if (nShop != null)
  1543. {
  1544. shopId = nShop.ID;
  1545. }
  1546. if (shopId != 34 && entity.payment == 0)
  1547. {
  1548. returnErrorMsg("公司自用的单金额才能为0");
  1549. return;
  1550. }
  1551. entity.Create();
  1552. CeErpTradeCell entitycell = new CeErpTradeCell();
  1553. entitycell.ctid = entity.tid;
  1554. entitycell.tid = entity.tid;
  1555. entitycell.ShopId = shopId;
  1556. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1557. entitycell.OrderState = 0;
  1558. entitycell.pay_time = entity.pay_time;
  1559. entitycell.IsOffLineOrder = 1;
  1560. entitycell.Create();
  1561. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1562. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1563. return;
  1564. }
  1565. }
  1566. public void ins_erp_neworder2()
  1567. {
  1568. if (UrlPostParmsCheck("receiver_name"))
  1569. {
  1570. //string plat_form = GetPostString("platform");
  1571. string preStr = "X_";
  1572. string memo = GetPostString("memo");
  1573. string productId = GetPostString("productId");
  1574. string primg = GetPostString("proofimg");
  1575. string sellerNick = GetPostString("seller_nick");
  1576. string addFrom = GetPostString("addfrom");
  1577. if (addFrom == "1")
  1578. {
  1579. preStr = "N_";
  1580. }
  1581. int shopId = 0;
  1582. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1583. if (nShop != null)
  1584. {
  1585. shopId = nShop.ID;
  1586. }
  1587. else
  1588. {
  1589. returnErrorMsg("找不到对应店铺");
  1590. return;
  1591. }
  1592. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1593. {
  1594. returnErrorMsg("必须上传付款凭证");
  1595. return;
  1596. }
  1597. CeErpTrade entity = new CeErpTrade();
  1598. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1599. entity.seller_nick = sellerNick;
  1600. entity.buyer_nick = GetPostString("buyer_nick");
  1601. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1602. entity.total_fee = entity.payment;
  1603. entity.pay_time = DateTime.Now;
  1604. entity.status = "NOT_SHIPPED";
  1605. entity.receiver_name = GetPostString("receiver_name");
  1606. entity.receiver_mobile = GetPostString("receiver_mobile");
  1607. entity.receiver_state = GetPostString("receiver_state");
  1608. entity.receiver_city = GetPostString("receiver_city");
  1609. entity.receiver_district = GetPostString("receiver_district");
  1610. entity.receiver_address = GetPostString("receiver_address");
  1611. entity.seller_memo = memo;
  1612. entity.orderFrom = 20;
  1613. entity.orderType = 15;
  1614. if (entity.receiver_state == "" || entity.receiver_city == "")
  1615. {
  1616. returnErrorMsg("收件地址不能为空");
  1617. return;
  1618. }
  1619. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1620. {
  1621. returnErrorMsg("公司自用的单金额才能为0");
  1622. return;
  1623. }
  1624. entity.Create();
  1625. string toWhere = GetPostString("towhere");
  1626. CeErpTradeCell entitycell = new CeErpTradeCell();
  1627. entitycell.ctid = entity.tid;
  1628. //唯一标识
  1629. entitycell.OrderSn = entity.tid;
  1630. //string orderSn = dataHelper.getSaleOrderSn();
  1631. //if (orderSn != "")
  1632. // {
  1633. // entitycell.OrderSn = orderSn;
  1634. // }
  1635. entitycell.tid = entity.tid;
  1636. //if (preStr == "X_")
  1637. //{
  1638. entitycell.IsOffLineOrder = 1;
  1639. //}
  1640. entitycell.CustomerUserId = CurrentUser.UserID;
  1641. entitycell.PayProofImg = primg;
  1642. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1643. entitycell.ProductId = Convert.ToInt32(productId);
  1644. entitycell.ShopId = shopId;
  1645. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1646. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1647. {
  1648. entitycell.IsXianHuo = 1;
  1649. }
  1650. entitycell.pay_time = entity.pay_time;
  1651. if (toWhere == "1")
  1652. {
  1653. entitycell.OrderState = 2;
  1654. }
  1655. else
  1656. {
  1657. entitycell.OrderState = 6;
  1658. entitycell.FinishPlaceTime = entitycell.pay_time;
  1659. }
  1660. if (shopId == 94)
  1661. {
  1662. entitycell.OrderState = 4;
  1663. entitycell.WaitDesignTime = entitycell.pay_time;
  1664. entitycell.StartDesignTime = entitycell.pay_time;
  1665. entitycell.DesignUserId = 218;
  1666. }
  1667. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1668. {
  1669. entitycell.OrderState = -1;//修改12-5
  1670. CeWithdraw ceWithdraw = new CeWithdraw();
  1671. ceWithdraw.tid = entity.tid;
  1672. ceWithdraw.providerid = "-1";
  1673. ceWithdraw.status = -1;
  1674. ceWithdraw.creationtime = DateTime.Now;
  1675. ceWithdraw.userid = 1337;
  1676. ceWithdraw.Create();
  1677. }
  1678. entitycell.Create();
  1679. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1680. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1681. {
  1682. addPlaceRegist(entitycell, CurrentUser.UserID);
  1683. }
  1684. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1685. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1686. return;
  1687. }
  1688. }
  1689. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1690. {
  1691. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1692. entity.PlactTime = tradecell.pay_time;
  1693. entity.AddUserId = userid;
  1694. entity.FileName = tradecell.seller_memo;
  1695. entity.Supplier = 24;
  1696. entity.CreateTime = DateTime.Now;
  1697. entity.Did = tradecell.ctid;
  1698. entity.tid = tradecell.tid;
  1699. entity.splitTag = tradecell.SplitTag;
  1700. entity.CurState = "未完成";
  1701. entity.Create();
  1702. }
  1703. public void get_erp_offlinelist()
  1704. {
  1705. DataStruct dStruct = GetPostStruct();
  1706. List<string> lw = new List<string>();
  1707. string tid = GetPostString("ctid");
  1708. string date1 = GetPostString("date1");
  1709. string date2 = GetPostString("date2");
  1710. if (tid.Length > 0 || date1.Length > 0)
  1711. {
  1712. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1713. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1714. if (dw.Length > 0) lw.Add(dw);
  1715. }
  1716. else
  1717. {
  1718. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1719. }
  1720. string shopname = GetPostString("shopname");
  1721. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1722. string buyernick = GetPostString("buyer_nick");
  1723. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1724. string customer = GetPostString("customer");
  1725. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1726. string design = GetPostString("design");
  1727. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1728. string orderState = GetPostString("orderState");
  1729. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1730. string address = GetPostString("address");
  1731. 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));
  1732. string sellermemo = GetPostString("seller_memo");
  1733. if (sellermemo.Length > 0)
  1734. {
  1735. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1736. }
  1737. string price1 = GetPostString("price1");
  1738. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1739. string price2 = GetPostString("price2");
  1740. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1741. //if (PKey != "admin")
  1742. //{
  1743. // string usershop = CurrentUser.User.pemShop;
  1744. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1745. //}
  1746. //if (ex_psize > 0)
  1747. //{
  1748. dStruct.Order = "pay_time desc";
  1749. //}
  1750. //else
  1751. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1752. lw.Add(string.Format("IsOffLineOrder=1"));
  1753. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1754. DataTable dt = null;
  1755. dt = WebCache.GetData("view_erptradecell", dStruct);
  1756. writeGridDataTableJson(dStruct.TotalCount, dt);
  1757. }
  1758. public void get_erp_returncashrecord()
  1759. {
  1760. DataStruct dStruct = GetPostStruct();
  1761. List<string> lw = new List<string>();
  1762. string tid = GetPostString("ctid");
  1763. if (tid.Length > 0)
  1764. {
  1765. lw.Add(string.Format("tid like '%{0}%'", tid));
  1766. dStruct.Order = "id desc";
  1767. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1768. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1769. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1770. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1771. return;
  1772. }
  1773. returnErrorMsg("id数据错误!");
  1774. }
  1775. public void ins_erp_returncashrecord()
  1776. {
  1777. if (UrlPostParmsCheck("tid"))
  1778. {
  1779. string tid = GetPostString("tid");
  1780. string retype = GetPostString("type");
  1781. StringBuilder sql = new StringBuilder();
  1782. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1783. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1784. if (dt.Rows.Count > 0)
  1785. {
  1786. returnErrorMsg("相同返现类型记录已存在");
  1787. return;
  1788. }
  1789. CeErpReturnCash entity = new CeErpReturnCash();
  1790. entity.tid = tid;
  1791. entity.seller_nick = GetPostString("seller_nick");
  1792. string pment = GetPostString("payment");
  1793. if (pment.Length > 0)
  1794. {
  1795. entity.payment = Convert.ToDouble(pment);
  1796. }
  1797. entity.buyer_nick = GetPostString("buyer_nick");
  1798. entity.cashstate = 0;
  1799. entity.rtype = retype;
  1800. string rPrice = GetPostString("returnprice");
  1801. if (rPrice.Length > 0)
  1802. {
  1803. entity.returnprice = Convert.ToDouble(rPrice);
  1804. }
  1805. entity.created = DateTime.Now;
  1806. entity.con = GetPostString("con");
  1807. entity.img = GetPostString("img");
  1808. entity.applyuserid = CurrentUser.UserID;
  1809. entity.Create();
  1810. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1811. returnSuccessMsg("操作成功!");
  1812. return;
  1813. }
  1814. }
  1815. public void set_erp_predelivery()
  1816. {
  1817. if (UrlPostParmsCheck("ctid"))
  1818. {
  1819. string eid = GetPostString("ctid");
  1820. CeErpTradeCell entity = null;
  1821. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1822. if (entity != null)
  1823. {
  1824. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1825. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1826. //{
  1827. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1828. // return;
  1829. //}
  1830. entity.IsPreDelivery = 1;
  1831. entity.Update();
  1832. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1833. returnSuccessMsg("预发货成功!");
  1834. return;
  1835. //string shop = GetPostString("seller_nick");
  1836. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1837. //string comName = GetPostString("comName");
  1838. //string comCode = GetPostString("comCode");
  1839. //string outSid = GetPostString("outSid");//运单号
  1840. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1841. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1842. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1843. //string apires = "";
  1844. //if (deliveryType == "虚拟发货")
  1845. //{
  1846. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1847. //}
  1848. //else
  1849. //{
  1850. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1851. //}
  1852. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1853. ////{
  1854. //if (apires.IndexOf("发货成功") != -1)
  1855. //{
  1856. // if (deliveryType != "虚拟发货")
  1857. // {
  1858. // //还要插入快递信息到 快递信息表
  1859. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1860. // exinfo.tid = eid;
  1861. // exinfo.out_sid = outSid;
  1862. // exinfo.company_code = comCode;
  1863. // exinfo.company_name = comName;
  1864. // exinfo.delivery_memo = deliveryMemo;
  1865. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1866. // exinfo.deliveryType = deliveryType;
  1867. // exinfo.Create();
  1868. // }
  1869. // returnSuccessMsg("发货成功!");
  1870. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1871. //}
  1872. //else
  1873. //{
  1874. // returnErrorMsg("淘宝发货失败!!");
  1875. //}
  1876. //return;
  1877. }
  1878. returnErrorMsg("找不到订单记录");
  1879. }
  1880. }
  1881. public void get_erp_unusuallist()
  1882. {
  1883. DataStruct dStruct = GetPostStruct();
  1884. List<string> lw = new List<string>();
  1885. string tid = GetPostString("ctid");
  1886. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1887. string shopname = GetPostString("shopname");
  1888. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1889. string buyernick = GetPostString("buyer_nick");
  1890. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1891. string ResponsibleMan = GetPostString("responsible");
  1892. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1893. string date1 = GetPostString("date1");
  1894. string date2 = GetPostString("date2");
  1895. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1896. if (dw.Length > 0) lw.Add(dw);
  1897. string price1 = GetPostString("price1");
  1898. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1899. string price2 = GetPostString("price2");
  1900. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1901. string orderState = GetPostString("orderState");
  1902. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  1903. string sellermemo = GetPostString("seller_memo");
  1904. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1905. lw.Add(string.Format("UnusualTag > 0"));
  1906. lw.Add(string.Format("IsRefund<={0}", 1));
  1907. dStruct.Order = "pay_time desc";
  1908. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1909. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  1910. writeGridDataTableJson(dStruct.TotalCount, dt);
  1911. }
  1912. public void set_erp_unusualtonomal()
  1913. {
  1914. if (UrlPostParmsCheck("ctid"))
  1915. {
  1916. string eid = GetPostString("ctid");
  1917. CeErpTradeCell entity = null;
  1918. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1919. if (entity != null)
  1920. {
  1921. entity.UnusualTag = -1;
  1922. entity.Update();
  1923. returnSuccessMsg("忽略成功!");
  1924. return;
  1925. }
  1926. returnErrorMsg("找不到记录");
  1927. }
  1928. }
  1929. public void ins_erp_unusualreason()
  1930. {
  1931. if (UrlPostParmsCheck("ctid"))
  1932. {
  1933. string eid = GetPostString("ctid");
  1934. CeErpTradeCell entity = null;
  1935. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1936. if (entity != null)
  1937. {
  1938. entity.MemoOpt = 4;
  1939. entity.UnusualCon = GetPostString("con");
  1940. entity.Update();
  1941. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1942. if (trade != null)
  1943. {
  1944. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  1945. }
  1946. //查货是否超时
  1947. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1948. if (ceErpTradeCellExtend == null)
  1949. {
  1950. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  1951. ceErpTradeCellExtend.ctid = entity.ctid;
  1952. }
  1953. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  1954. {
  1955. ceErpTradeCellExtend.CheckOut += 1;
  1956. }
  1957. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  1958. if (ceErpTradeCellExtend.ID > 0)
  1959. {
  1960. ceErpTradeCellExtend.Update();
  1961. }
  1962. else
  1963. {
  1964. ceErpTradeCellExtend.Create();
  1965. }
  1966. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  1967. returnSuccessMsg("操作成功!");
  1968. return;
  1969. }
  1970. returnErrorMsg("找不到记录");
  1971. }
  1972. }
  1973. public void upd_erp_sampleorder()
  1974. {
  1975. if (UrlPostParmsCheck("ctid"))
  1976. {
  1977. string eid = GetPostString("ctid");
  1978. string[] eArr = eid.Split(',');
  1979. if (eArr.Length > 1)
  1980. {
  1981. List<string> eLst = new List<string>();
  1982. for (int i = 0; i < eArr.Length; i++)
  1983. {
  1984. eLst.Add("'" + eArr[i] + "'");
  1985. }
  1986. eid = string.Join(",", eLst.ToArray());
  1987. }
  1988. else
  1989. {
  1990. eid = "'" + eid + "'";
  1991. }
  1992. StringBuilder sql = new StringBuilder();
  1993. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  1994. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1995. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1996. if (dt.Rows.Count > 0)
  1997. {
  1998. string errmsg = "";
  1999. foreach (DataRow dr in dt.Rows)
  2000. {
  2001. StringBuilder sqlsb = new StringBuilder();
  2002. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2003. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2004. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2005. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2006. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2007. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2008. {
  2009. continue;
  2010. }
  2011. else
  2012. {
  2013. string emsg = commonHelper.KeepChinese(apires);
  2014. errmsg += emsg;
  2015. }
  2016. }
  2017. if (errmsg.Length > 0)
  2018. {
  2019. returnErrorMsg(errmsg);
  2020. return;
  2021. }
  2022. returnSuccessMsg("操作成功");
  2023. return;
  2024. }
  2025. returnErrorMsg("找不到记录");
  2026. }
  2027. }
  2028. public void upd_erp_transcustomer()
  2029. {
  2030. if (UrlPostParmsCheck("ctid"))
  2031. {
  2032. string eid = GetPostString("ctid");
  2033. int userid = GetPostInt("CustomerUserId");
  2034. CeErpTradeCell entity = null;
  2035. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2036. if (entity != null)
  2037. {
  2038. //string[] mlist = entity.seller_memo.Split('-');
  2039. //string sql = "select * from view_erpuser where id=" + userid;
  2040. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2041. //if (dt != null && dt.Rows.Count > 0)
  2042. //{
  2043. // string nmemo = "";
  2044. // for(int i = 0; i < mlist.Length - 1; i++)
  2045. // {
  2046. // nmemo += mlist[i];
  2047. // nmemo += "-";
  2048. // }
  2049. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2050. // entity.seller_memo = nmemo;
  2051. //}
  2052. entity.CustomerUserId = userid;
  2053. entity.Update();
  2054. returnSuccessMsg("操作成功!");
  2055. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2056. return;
  2057. }
  2058. returnErrorMsg("找不到记录");
  2059. }
  2060. }
  2061. public void upd_erp_transdesigner()
  2062. {
  2063. if (UrlPostParmsCheck("ctid"))
  2064. {
  2065. string eids = GetPostString("ctid");
  2066. string[] ctidList = eids.Split(',');
  2067. int userid = GetPostInt("DesignUserId");
  2068. foreach (string ctid in ctidList)
  2069. {
  2070. CeErpTradeCell entity = null;
  2071. CeErpDesignerBill entitys = null;
  2072. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2073. entitys = CeErpDesignerBill.GetByTid(ctid);
  2074. if (entity != null)
  2075. {
  2076. if (entity.OrderState > 4)
  2077. {
  2078. continue;
  2079. }
  2080. //存在退款不能流转
  2081. if (entity.IsRefund > 0)
  2082. {
  2083. continue;
  2084. }
  2085. entity.DesignUserId = userid;
  2086. entity.WaitDesignTime = DateTime.Now;
  2087. entity.Update();
  2088. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2089. }
  2090. }
  2091. returnSuccessMsg("操作成功!");
  2092. }
  2093. }
  2094. public void upd_erp_distributedesigner()
  2095. {
  2096. if (UrlPostParmsCheck("ctid"))
  2097. {
  2098. string eid = GetPostString("ctid");
  2099. int userid = GetPostInt("DesignUserId");
  2100. string[] idlist = eid.Split(',');
  2101. if (idlist.Length <= 0)
  2102. {
  2103. returnErrorMsg("订单不能为空");
  2104. return;
  2105. }
  2106. foreach (string ctid in idlist)
  2107. {
  2108. CeErpTradeCell entity = null;
  2109. CeErpDesignerBill entitys = null;
  2110. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2111. else continue;
  2112. if (entity != null)
  2113. {
  2114. if (userid == 2125 || userid == 3542)
  2115. { }
  2116. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2117. {
  2118. returnErrorMsg("金额错误的订单无法指派");
  2119. return;
  2120. }
  2121. if (entity.OrderState >= 5)
  2122. {
  2123. returnErrorMsg("已经设计完成无法指派");
  2124. return;
  2125. }
  2126. if (entity.OrderState == -1)
  2127. {
  2128. returnErrorMsg("审核中的订单无法指派");
  2129. return;
  2130. }
  2131. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2132. {
  2133. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2134. return;
  2135. }
  2136. //157赖橙帆 159林晨
  2137. 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)
  2138. {
  2139. returnErrorMsg("指派设计共创无法再次指派!");
  2140. return;
  2141. }
  2142. entity.OrderState = 3;
  2143. CeErpUserPost userEntity = CeErpUserPost.GetByUserID(userid);
  2144. if (entity.ctid.IndexOf("S_") == -1 && userEntity.OrgID == 10)
  2145. {
  2146. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2147. entity.SupplierId = suid;
  2148. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2149. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2150. }
  2151. if (userid == 2125 && entity.seller_memo != "")
  2152. {
  2153. apiDesign.API_GetPrintData_CreateOrder(entity);
  2154. }
  2155. if (userid == 3542 && entity.seller_memo != "")
  2156. {
  2157. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, CurrentUser.UserPost.Post.Code);
  2158. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2159. if (response.msg != "设计共创:成功")
  2160. {
  2161. returnErrorMsg(response.msg);
  2162. return;
  2163. }
  2164. entity.DispatchSort = 2;
  2165. }
  2166. else
  2167. {
  2168. if (entity.DispatchSort == 2)
  2169. {
  2170. ApiVo apiVo = new ApiVo();
  2171. apiVo.actionName = "closeDesign";
  2172. apiVo.orderNumber = entity.ctid;
  2173. designHelper.API_WorkCore(apiVo);//closeDesign
  2174. }
  2175. entity.DispatchSort = 0;
  2176. }
  2177. entity.DesignUserId = userid;
  2178. entity.WaitDesignTime = DateTime.Now;
  2179. entity.Update();
  2180. string name = commonHelper.getUserNameById(userid);
  2181. commonHelper.UpdateRelationOrder(entity.ctid);
  2182. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2183. }
  2184. }
  2185. returnSuccessMsg("操作成功!");
  2186. return;
  2187. }
  2188. }
  2189. public void get_erp_myorderlist()
  2190. {
  2191. DataStruct dStruct = GetPostStruct();
  2192. List<string> lw = new List<string>();
  2193. string tid = GetPostString("ctid");
  2194. if (tid.Length > 0)
  2195. {
  2196. lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  2197. }
  2198. else
  2199. {
  2200. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2201. }
  2202. //12-1 修改
  2203. string urgent = GetPostString("urgent");
  2204. string back = GetPostString("back");
  2205. string offlineSearch = GetPostString("offlineSearch");
  2206. if (!string.IsNullOrWhiteSpace(urgent))
  2207. {
  2208. if (urgent.Equals("true"))
  2209. {
  2210. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2211. }
  2212. }
  2213. if (!string.IsNullOrWhiteSpace(back))
  2214. {
  2215. if (back.Equals("true"))
  2216. {
  2217. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2218. }
  2219. }
  2220. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2221. {
  2222. if (offlineSearch.Equals("true"))
  2223. {
  2224. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2225. }
  2226. }
  2227. //end
  2228. string shopname = GetPostString("shopname");
  2229. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2230. string buyernick = GetPostString("buyer_nick");
  2231. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2232. string design = GetPostString("design");
  2233. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2234. string orderState = GetPostString("orderState");
  2235. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2236. string sellermemo = GetPostString("seller_memo");
  2237. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2238. string date1 = GetPostString("date1");
  2239. string date2 = GetPostString("date2");
  2240. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2241. if (dw.Length > 0) lw.Add(dw);
  2242. string price1 = GetPostString("price1");
  2243. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2244. string price2 = GetPostString("price2");
  2245. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2246. string urgency = GetPostString("urgency");
  2247. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2248. string after = GetPostString("after");
  2249. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2250. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2251. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2252. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2253. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2254. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2255. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2256. if (dt != null && dt.Rows.Count > 0)
  2257. {
  2258. foreach (DataRow dr in dt.Rows)
  2259. {
  2260. try
  2261. {
  2262. // 对象操作
  2263. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2264. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2265. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2266. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2267. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2268. if (dStruct.PageSize != 100000)
  2269. {
  2270. if (dr["DispatchSort"].ToString() == "2")
  2271. {
  2272. dr["gongchuang"] = 200;
  2273. }
  2274. else
  2275. {
  2276. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  2277. dr["gongchuang"] = response.code;
  2278. }
  2279. }
  2280. }
  2281. catch (NullReferenceException ex)
  2282. {
  2283. }
  2284. }
  2285. }
  2286. writeGridDataTableJson(dStruct.TotalCount, dt);
  2287. }
  2288. public void get_erp_myreturnorderlist()
  2289. {
  2290. DataStruct dStruct = GetPostStruct();
  2291. List<string> lw = new List<string>();
  2292. string tid = GetPostString("ctid");
  2293. if (tid.Length > 0)
  2294. {
  2295. lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", tid));
  2296. }
  2297. else
  2298. {
  2299. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2300. }
  2301. string shopname = GetPostString("shopname");
  2302. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2303. string buyernick = GetPostString("buyer_nick");
  2304. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2305. string design = GetPostString("design");
  2306. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2307. string orderState = GetPostString("orderState");
  2308. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2309. string sellermemo = GetPostString("seller_memo");
  2310. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2311. string date1 = GetPostString("date1");
  2312. string date2 = GetPostString("date2");
  2313. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2314. if (dw.Length > 0) lw.Add(dw);
  2315. string price1 = GetPostString("price1");
  2316. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2317. string price2 = GetPostString("price2");
  2318. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2319. if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2320. {
  2321. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2322. }
  2323. else
  2324. {
  2325. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2326. }
  2327. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2328. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2329. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2330. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2331. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2332. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2333. if (dt != null && dt.Rows.Count > 0)
  2334. {
  2335. foreach (DataRow dr in dt.Rows)
  2336. {
  2337. try
  2338. {
  2339. // 对象操作
  2340. if (dStruct.PageSize != 100000)
  2341. {
  2342. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  2343. dr["gongchuang"] = response.code;
  2344. }
  2345. }
  2346. catch (NullReferenceException ex)
  2347. {
  2348. // 处理空引用异常
  2349. }
  2350. }
  2351. }
  2352. writeGridDataTableJson(dStruct.TotalCount, dt);
  2353. }
  2354. public void get_erp_myorderlist_pregather()
  2355. {
  2356. string date1 = GetPostString("date1");
  2357. string date2 = GetPostString("date2");
  2358. int userId = CurrentUser.UserID; //客服id
  2359. string orderWhere = "";
  2360. List<string> lw = new List<string>();
  2361. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2362. if (dw.Length > 0) lw.Add(dw);
  2363. lw.Add(string.Format("CustomerUserId={0}", userId));
  2364. lw.Add(string.Format("OrderState<9"));
  2365. orderWhere = string.Join(" and ", lw.ToArray());
  2366. string orderWhere2 = "";
  2367. List<string> lw2 = new List<string>();
  2368. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2369. if (dw2.Length > 0) lw2.Add(dw2);
  2370. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2371. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2372. string sql = string.Format("select *" +
  2373. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2374. "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 " +
  2375. "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 " +
  2376. "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");
  2377. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2378. //writeGridDataTableJson(dt.Rows.Count, dt);
  2379. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2380. }
  2381. public void upd_erp_publishorder()
  2382. {
  2383. if (UrlPostParmsCheck("ctid"))
  2384. {
  2385. string eid = GetPostString("ctid");
  2386. CeErpTradeCell entity = null;
  2387. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2388. if (entity != null)
  2389. {
  2390. entity.OrderState = 0; //发布后,变为待抢单
  2391. entity.Update();
  2392. commonHelper.UpdateRelationOrder(entity.ctid);
  2393. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2394. returnSuccessMsg("发布成功!");
  2395. return;
  2396. }
  2397. returnErrorMsg("找不到记录");
  2398. }
  2399. }
  2400. public void get_erp_my_tiporder()
  2401. {
  2402. StringBuilder sql = new StringBuilder();
  2403. int userId = 0;
  2404. if (CurrentUser != null) userId = CurrentUser.UserID;
  2405. string posCode = CurrentUser.UserPost.Post.Code;
  2406. string isTipedAfterSaleVerify = GetPostString("af");
  2407. DataTable dt = new DataTable();
  2408. if (posCode != "Supplier")
  2409. {
  2410. if (posCode == "CustomerService" || posCode == "Director")
  2411. {
  2412. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2413. }
  2414. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2415. {
  2416. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2417. }
  2418. else
  2419. {
  2420. string teamIds = CurrentUser.User.TeamIds;
  2421. if (teamIds == "")
  2422. {
  2423. teamIds = "0";
  2424. }
  2425. 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);
  2426. }
  2427. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2428. }
  2429. if (dt.Rows.Count <= 0)
  2430. {
  2431. string key = "aftersale_order_" + userId;
  2432. if (RedisHelper.HasKey(key))
  2433. {
  2434. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2435. dt.Columns.Add("ctid", typeof(string));
  2436. dt.Columns.Add("IsReadTag", typeof(int));
  2437. foreach (var i in list)
  2438. {
  2439. DataRow data = dt.NewRow();
  2440. data["ctid"] = i;
  2441. data["IsReadTag"] = 4;
  2442. dt.Rows.Add(data);
  2443. }
  2444. RedisHelper.StringDelete(key);
  2445. }
  2446. }
  2447. if (dt.Rows.Count <= 0)
  2448. {
  2449. sql = new StringBuilder();
  2450. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2451. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2452. }
  2453. if (posCode == "Supplier")
  2454. {
  2455. string ids = CurrentUser.User.pemVend;
  2456. if (ids != null && ids.Length > 0)
  2457. {
  2458. string[] ids_list = ids.Split(',');
  2459. foreach (var item in ids_list)
  2460. {
  2461. string key = "return_order_" + item;
  2462. if (RedisHelper.HasKey(key))
  2463. {
  2464. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2465. dt.Columns.Add("ctid", typeof(string));
  2466. dt.Columns.Add("IsReadTag", typeof(int));
  2467. foreach (var i in list)
  2468. {
  2469. DataRow data = dt.NewRow();
  2470. data["ctid"] = i;
  2471. data["IsReadTag"] = 1;
  2472. dt.Rows.Add(data);
  2473. }
  2474. RedisHelper.StringDelete(key);
  2475. }
  2476. }
  2477. }
  2478. if (dt.Rows.Count <= 0)
  2479. {
  2480. sql = new StringBuilder();
  2481. 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);
  2482. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2483. }
  2484. }
  2485. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2486. }
  2487. public void reset_erp_tiporder()
  2488. {
  2489. string ids = GetPostString("ids");
  2490. string[] ctidList = ids.Split(',');
  2491. foreach (string ctid in ctidList)
  2492. {
  2493. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2494. if (enty != null)
  2495. {
  2496. enty.IsReadTag = 0;
  2497. enty.Update();
  2498. }
  2499. }
  2500. returnSuccessMsg("成功!");
  2501. return;
  2502. }
  2503. public void get_erp_designlist()
  2504. {
  2505. DataStruct dStruct = GetPostStruct();
  2506. List<string> lw = new List<string>();
  2507. string tid = GetPostString("ctid");
  2508. if (tid.Length > 0) lw.Add(string.Format("(ctid ='{0}' or orderSn ='{0}')", tid));
  2509. string shopname = GetPostString("shopname");
  2510. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2511. string buyernick = GetPostString("buyer_nick");
  2512. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2513. string customer = GetPostString("customer");
  2514. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2515. string design = GetPostString("design");
  2516. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2517. string orderState = GetPostString("orderState");
  2518. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2519. lw.Add(string.Format("OrderState<6"));
  2520. string address = GetPostString("address");
  2521. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2522. string sellermemo = GetPostString("seller_memo");
  2523. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2524. string date1 = GetPostString("date1");
  2525. string date2 = GetPostString("date2");
  2526. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2527. if (dw.Length > 0) lw.Add(dw);
  2528. string apdate1 = GetPostString("apdate1");
  2529. string apdate2 = GetPostString("apdate2");
  2530. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2531. if (dwap.Length > 0) lw.Add(dwap);
  2532. string price1 = GetPostString("price1");
  2533. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2534. string price2 = GetPostString("price2");
  2535. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2536. string designTime = GetPostString("designtime");
  2537. if (designTime.Length > 0)
  2538. {
  2539. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2540. }
  2541. string usershop = CurrentUser.User.pemShop;
  2542. if (usershop.Length > 0)
  2543. {
  2544. lw.Add(string.Format("shopId in ({0})", usershop));
  2545. }
  2546. int myOrgid = CurrentUser.UserPost.OrgID;
  2547. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2548. if (myOrgCode.IndexOf("Designer") != -1)
  2549. {
  2550. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2551. {
  2552. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2553. }
  2554. else
  2555. {
  2556. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2557. }
  2558. }
  2559. else
  2560. {
  2561. string orgId = GetPostString("designerhd");
  2562. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2563. }
  2564. if (tid.Length > 0 || buyernick.Length > 0)
  2565. {
  2566. lw.Add(string.Format("OrderState >= 3"));
  2567. }
  2568. else
  2569. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2570. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2571. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2572. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2573. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2574. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2575. if (dt != null && dt.Rows.Count > 0)
  2576. {
  2577. foreach (DataRow dr in dt.Rows)
  2578. {
  2579. try
  2580. {
  2581. // 对象操作
  2582. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2583. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2584. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2585. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2586. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2587. if (dStruct.PageSize != 100000)
  2588. {
  2589. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  2590. dr["gongchuang"] = response.code;
  2591. }
  2592. }
  2593. catch (NullReferenceException ex)
  2594. {
  2595. }
  2596. }
  2597. }
  2598. writeGridDataTableJson(dStruct.TotalCount, dt);
  2599. }
  2600. public void get_erp_mydesignlist()
  2601. {
  2602. DataStruct dStruct = GetPostStruct();
  2603. List<string> lw = new List<string>();
  2604. string tid = GetPostString("ctid");
  2605. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  2606. string shopname = GetPostString("shopname");
  2607. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2608. string buyernick = GetPostString("buyer_nick");
  2609. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2610. string customer = GetPostString("customer");
  2611. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2612. string orderState = GetPostString("orderState");
  2613. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2614. //lw.Add(string.Format("OrderState<6"));
  2615. string date1 = GetPostString("date1");
  2616. string date2 = GetPostString("date2");
  2617. string dw = GetDateWhere("pay_time", date1, date2);
  2618. if (dw.Length > 0) lw.Add(dw);
  2619. string apdate1 = GetPostString("apdate1");
  2620. string apdate2 = GetPostString("apdate2");
  2621. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2622. if (dwap.Length > 0) lw.Add(dwap);
  2623. string price1 = GetPostString("price1");
  2624. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2625. string price2 = GetPostString("price2");
  2626. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2627. string olddownload = GetPostString("olddown");
  2628. if (olddownload == "1")
  2629. {
  2630. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2631. }
  2632. else if (olddownload == "2")
  2633. {
  2634. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2635. }
  2636. string sellermemo = GetPostString("seller_memo");
  2637. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2638. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2639. if (CurrentUser.User.TeamIds.Length > 0)
  2640. {
  2641. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2642. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2643. else
  2644. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2645. }
  2646. else
  2647. {
  2648. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2649. }
  2650. if (tid.Length <= 0)
  2651. {
  2652. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2653. }
  2654. lw.Add(string.Format("IsReturn!=3"));
  2655. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2656. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2657. string teamids = CurrentUser.User.TeamIds.ToString();
  2658. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2659. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2660. if (dt != null && dt.Rows.Count > 0)
  2661. {
  2662. foreach (DataRow dr in dt.Rows)
  2663. {
  2664. try
  2665. {
  2666. // 对象操作
  2667. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2668. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2669. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2670. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2671. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2672. if (dStruct.PageSize != 100000)
  2673. {
  2674. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  2675. dr["gongchuang"] = response.code;
  2676. }
  2677. }
  2678. catch (NullReferenceException ex)
  2679. {
  2680. }
  2681. }
  2682. }
  2683. writeGridDataTableJson(dStruct.TotalCount, dt);
  2684. }
  2685. public void set_erp_startdesign()
  2686. {
  2687. if (UrlPostParmsCheck("ctid"))
  2688. {
  2689. string eid = GetPostString("ctid");
  2690. CeErpTradeCell entity = null;
  2691. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2692. if (entity != null)
  2693. {
  2694. if (entity.OrderState != 3)
  2695. {
  2696. returnErrorMsg("请刷新,订单已经设计了");
  2697. return;
  2698. }
  2699. entity.StartDesignTime = DateTime.Now;
  2700. entity.OrderState = 4;
  2701. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2702. {
  2703. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2704. entity.SupplierId = suid;
  2705. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2706. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2707. }
  2708. //entity.MakeSupplier = suname;
  2709. entity.Update();
  2710. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2711. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2712. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2713. commonHelper.getCytPrice(entity);
  2714. returnSuccessMsg("操作成功!");
  2715. return;
  2716. }
  2717. returnErrorMsg("找不到记录");
  2718. }
  2719. }
  2720. public void ins_erp_designselfmemo()
  2721. {
  2722. if (UrlPostParmsCheck("ctid"))
  2723. {
  2724. string eid = GetPostString("ctid");
  2725. string con = GetPostString("con");
  2726. CeErpTradeCell entity = null;
  2727. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2728. if (entity != null)
  2729. {
  2730. entity.DesignSelfMemo = con;
  2731. entity.Update();
  2732. returnSuccessMsg("操作成功!");
  2733. return;
  2734. }
  2735. returnErrorMsg("找不到记录");
  2736. }
  2737. }
  2738. public void ins_erp_designprice()
  2739. {
  2740. if (UrlPostParmsCheck("ctid"))
  2741. {
  2742. string eid = GetPostString("ctid");
  2743. int uid = CurrentUser.UserID;
  2744. string userName = CurrentUser.UserName;
  2745. CeErpTradeCell entity = null;
  2746. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2747. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2748. if (entitys == null)
  2749. {
  2750. entitys = new CeErpDesignerBill();
  2751. }
  2752. if (entity != null)
  2753. {
  2754. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2755. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2756. entity.StartDesignTime = DateTime.Now;
  2757. entity.OrderState = 4;
  2758. string suname = "";
  2759. if (entity.SupplierId == 0)
  2760. {
  2761. int sid = commonHelper.autoDistributeToSupplier(entity);
  2762. entity.SupplierId = sid;
  2763. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2764. }
  2765. entity.Update();
  2766. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  2767. if (ceErpUserPost != null)
  2768. {
  2769. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  2770. if (ceErpPost != null)
  2771. {
  2772. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  2773. {
  2774. entitys.tid = entity.ctid;
  2775. entitys.oid = entity.tid;
  2776. entitys.uid = uid;
  2777. entitys.userName = userName;
  2778. entitys.designerType = 1;
  2779. entitys.designerTypeText = "内部设计师";
  2780. entitys.price = Convert.ToDouble(GetPostString("price"));
  2781. entitys.designNum = GetPostInt("designNum");
  2782. entitys.modifyNum = GetPostInt("modifyNum");
  2783. entitys.designSize = GetPostString("designSize");
  2784. entitys.modifySize = GetPostString("modifySize");
  2785. if (CeErpDesignerBill.GetByTid("ctid") == null)
  2786. {
  2787. entitys.create_time = DateTime.Now;
  2788. entitys.create_u_id = uid;
  2789. entitys.create_u_name = userName;
  2790. entitys.Save();
  2791. }
  2792. else
  2793. {
  2794. entitys.update_time = DateTime.Now;
  2795. entitys.update_u_id = uid;
  2796. entitys.update_u_name = userName;
  2797. entitys.Update();
  2798. }
  2799. }
  2800. }
  2801. }
  2802. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2803. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2804. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  2805. if (suname != "")
  2806. {
  2807. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2808. }
  2809. commonHelper.getCytPrice(entity);
  2810. returnSuccessMsg("操作成功!");
  2811. return;
  2812. }
  2813. returnErrorMsg("找不到记录");
  2814. }
  2815. }
  2816. public void upload_erp_filecomplete()
  2817. {
  2818. if (UrlPostParmsCheck("ctid"))
  2819. {
  2820. string eid = GetPostString("ctid");
  2821. CeErpTradeCell entity = null;
  2822. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2823. if (entity != null)
  2824. {
  2825. entity.OrderState = 5; //设计完成
  2826. entity.Update();
  2827. returnSuccessMsg(eid + "上传成功,设计完成!");
  2828. return;
  2829. }
  2830. returnErrorMsg("找不到订单记录");
  2831. }
  2832. }
  2833. public void get_erp_designovertimelist()
  2834. {
  2835. DataStruct dStruct = GetPostStruct();
  2836. List<string> lw = new List<string>();
  2837. string tid = GetPostString("ctid");
  2838. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  2839. string shopname = GetPostString("shopname");
  2840. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2841. string buyernick = GetPostString("buyer_nick");
  2842. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2843. string ResponsibleMan = GetPostString("responsible");
  2844. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2845. string date1 = GetPostString("date1");
  2846. string date2 = GetPostString("date2");
  2847. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2848. if (dw.Length > 0) lw.Add(dw);
  2849. string price1 = GetPostString("price1");
  2850. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2851. string price2 = GetPostString("price2");
  2852. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2853. string orderState = GetPostString("orderState");
  2854. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2855. string sellermemo = GetPostString("seller_memo");
  2856. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2857. lw.Add(string.Format("UnusualTag=3"));
  2858. lw.Add(string.Format("IsRefund<={0}", 1));
  2859. dStruct.Order = "WaitDesignTime desc";
  2860. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2861. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2862. writeGridDataTableJson(dStruct.TotalCount, dt);
  2863. }
  2864. //设计管理 获取抢单大厅列表
  2865. public void get_erp_grabinglist()
  2866. {
  2867. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  2868. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  2869. bool oldOrder = false;
  2870. if (org != null)
  2871. {
  2872. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  2873. }
  2874. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  2875. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  2876. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2877. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  2878. //先处理订单数据
  2879. if (dt.Rows.Count > 0)
  2880. {
  2881. Dictionary<string, int> design = null;
  2882. int count = 0;
  2883. foreach (DataRow row in dt.Rows)
  2884. {
  2885. if (map.ContainsKey(row["ShopId"].ToString()))
  2886. {
  2887. map.TryGetValue(row["ShopId"].ToString(), out design);
  2888. }
  2889. else
  2890. {
  2891. design = new Dictionary<string, int>();
  2892. }
  2893. if (design.ContainsKey(row["ProductId"].ToString()))
  2894. {
  2895. design.TryGetValue(row["ProductId"].ToString(), out count);
  2896. }
  2897. count++;
  2898. design[row["ProductId"].ToString()] = count;
  2899. map[row["ShopId"].ToString()] = design;
  2900. }
  2901. }
  2902. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  2903. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2904. //把店铺排序和技能排序分类
  2905. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  2906. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  2907. if (design_dt.Rows.Count > 0)
  2908. {
  2909. Dictionary<string, string> design = null;
  2910. List<string> shopIds = null;
  2911. foreach (DataRow row in design_dt.Rows)
  2912. {
  2913. if ("0".Equals(row["designId"].ToString()))
  2914. {
  2915. if (shop_orders.ContainsKey(row["orders"].ToString()))
  2916. {
  2917. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  2918. }
  2919. else
  2920. {
  2921. shopIds = new List<string>();
  2922. }
  2923. shopIds.Add(row["shopId"].ToString());
  2924. shop_orders[row["orders"].ToString()] = shopIds;
  2925. }
  2926. else
  2927. {
  2928. if (design_orders.ContainsKey(row["shopId"].ToString()))
  2929. {
  2930. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  2931. }
  2932. else
  2933. {
  2934. design = new Dictionary<string, string>();
  2935. }
  2936. design[row["orders"].ToString()] = row["designId"].ToString();
  2937. design_orders[row["shopId"].ToString()] = design;
  2938. }
  2939. }
  2940. //处理成key value后根据key排序
  2941. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  2942. foreach (List<string> val in shop_orders.Values)
  2943. {
  2944. if (val != null)
  2945. {
  2946. foreach (string key in val)
  2947. {
  2948. if (design_orders.ContainsKey(key.ToString()))
  2949. {
  2950. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  2951. }
  2952. }
  2953. }
  2954. }
  2955. }
  2956. //校验哪个优先级有订单
  2957. Dictionary<string, string> designIds = new Dictionary<string, string>();
  2958. foreach (string key in shop_orders.Keys)
  2959. {
  2960. List<string> ids = null;
  2961. shop_orders.TryGetValue(key, out ids);
  2962. //id为shopid
  2963. foreach (string id in ids)
  2964. {
  2965. Dictionary<string, int> list = null;
  2966. Dictionary<string, string> desing = null;
  2967. map.TryGetValue(id, out list);
  2968. design_orders.TryGetValue(id, out desing);
  2969. if (list != null && desing != null)
  2970. {
  2971. foreach (var item in desing)
  2972. {
  2973. int count = 0;
  2974. if (list.ContainsKey(item.Value))
  2975. {
  2976. list.TryGetValue(item.Value, out count);
  2977. if (count > 0)
  2978. {
  2979. designIds[id] = item.Value;
  2980. break;
  2981. }
  2982. }
  2983. }
  2984. }
  2985. }
  2986. if (designIds.Count > 0)
  2987. {
  2988. break;
  2989. }
  2990. }
  2991. DataTable table = new DataTable();
  2992. table.Columns.Add("tid", typeof(string));
  2993. table.Columns.Add("ctid", typeof(string));
  2994. table.Columns.Add("seller_nick", typeof(string));
  2995. table.Columns.Add("productName", typeof(string));
  2996. table.Columns.Add("pay_time", typeof(string));
  2997. table.Columns.Add("seller_memo", typeof(string));
  2998. if (designIds.Count > 0)
  2999. {
  3000. string shopId = "";
  3001. string productId = "";
  3002. foreach (var designInfo in designIds)
  3003. {
  3004. shopId = designInfo.Key;
  3005. productId = designInfo.Value;
  3006. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3007. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3008. if (dt.Rows.Count > 0)
  3009. {
  3010. foreach (DataRow row in dt.Rows)
  3011. {
  3012. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3013. {
  3014. DataRow data = table.NewRow();
  3015. data["ctid"] = row["ctid"].ToString();
  3016. data["tid"] = row["tid"].ToString();
  3017. data["seller_nick"] = ceErpShop.ShopName;
  3018. data["pay_time"] = row["pay_time"].ToString();
  3019. data["seller_memo"] = row["seller_memo"].ToString();
  3020. data["productName"] = ceErpProduct.PType;
  3021. table.Rows.Add(data);
  3022. }
  3023. }
  3024. }
  3025. }
  3026. }
  3027. writeGridDataTableJson(table.Rows.Count, table);
  3028. }
  3029. private object rushLockObject = new object();
  3030. public void set_erp_grabingorder()
  3031. {
  3032. if (UrlPostParmsCheck("ctid"))
  3033. {
  3034. int total = CurrentUser.User.Person.Total;
  3035. int userId = CurrentUser.User.ID;
  3036. int noFinish = CurrentUser.User.Person.NoFinish;
  3037. int finalization = CurrentUser.User.Person.Finalization;
  3038. string eids = GetPostString("ctid");
  3039. string key = "RushKey_" + userId;
  3040. int count = 0;
  3041. if (erpRedis.RedisHelper.KeyExists(key))
  3042. {
  3043. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3044. if (redisCount != null)
  3045. {
  3046. count = Convert.ToInt32(redisCount);
  3047. }
  3048. }
  3049. if (count >= total)
  3050. {
  3051. returnErrorMsg("半小时内已经抢" + total + "单");
  3052. return;
  3053. }
  3054. string[] ctidlist = eids.Split(',');
  3055. if (count + ctidlist.Length > total)
  3056. {
  3057. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3058. return;
  3059. }
  3060. int itag = 0;
  3061. lock (rushLockObject)
  3062. {
  3063. if (ctidlist.Length > 0)
  3064. {
  3065. string[] dtList = new string[ctidlist.Length];
  3066. for (int i = 0; i < ctidlist.Length; i++)
  3067. {
  3068. dtList[i] = "'" + ctidlist[i] + "'";
  3069. }
  3070. 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"));
  3071. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3072. if (dt_user.Rows.Count > 0)
  3073. {
  3074. int doing = 0;//未定稿
  3075. int finish = 0;//已完成
  3076. foreach (DataRow dr in dt_user.Rows)
  3077. {
  3078. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3079. {
  3080. doing++;
  3081. }
  3082. else
  3083. {
  3084. finish++;
  3085. }
  3086. }
  3087. if (doing >= noFinish)
  3088. {
  3089. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3090. return;
  3091. }
  3092. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3093. {
  3094. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3095. return;
  3096. }
  3097. }
  3098. //校验选择单子状态
  3099. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3100. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3101. if (dt.Rows.Count > 0)
  3102. {
  3103. List<string> list = new List<string>();
  3104. foreach (DataRow dr in dt.Rows)
  3105. {
  3106. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3107. {
  3108. list.Add(dr["ctid"].ToString());
  3109. }
  3110. }
  3111. if (list.Count > 0)
  3112. {
  3113. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3114. return;
  3115. }
  3116. }
  3117. foreach (string ctid in ctidlist)
  3118. {
  3119. CeErpTradeCell entity = null;
  3120. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3121. if (entity != null)
  3122. {
  3123. entity.OrderState = 3;
  3124. entity.DesignUserId = CurrentUser.UserID;
  3125. entity.WaitDesignTime = DateTime.Now;
  3126. entity.StartDesignTime = DateTime.Now;
  3127. entity.Update();
  3128. commonHelper.UpdateRelationOrder(entity.ctid);
  3129. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3130. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3131. itag++;
  3132. }
  3133. }
  3134. }
  3135. }
  3136. count += ctidlist.Length;
  3137. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3138. if (itag == 0)
  3139. returnErrorMsg("没有找到相关订单");
  3140. else
  3141. returnSuccessMsg("抢单成功!");
  3142. return;
  3143. }
  3144. }
  3145. public void get_erp_waitorderlist()
  3146. {
  3147. DataStruct dStruct = GetPostStruct();
  3148. List<string> lw = new List<string>();
  3149. string tid = GetPostString("ctid");
  3150. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3151. string shopname = GetPostString("shopname");
  3152. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3153. string buyernick = GetPostString("buyer_nick");
  3154. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3155. string customer = GetPostString("customer");
  3156. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3157. string design = GetPostString("design");
  3158. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3159. string orderState = GetPostString("orderState");
  3160. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3161. string supplier = GetPostString("supplier");
  3162. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3163. string sellermemo = GetPostString("seller_memo");
  3164. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3165. string otherMemo = GetPostString("otherMemo");
  3166. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3167. string address = GetPostString("address");
  3168. 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));
  3169. string date1 = GetPostString("date1");
  3170. string date2 = GetPostString("date2");
  3171. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3172. if (dw.Length > 0) lw.Add(dw);
  3173. string price1 = GetPostString("price1");
  3174. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3175. string price2 = GetPostString("price2");
  3176. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3177. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3178. lw.Add(string.Format("IsSample != 2 "));
  3179. lw.Add(string.Format("OrderState = 5 "));
  3180. lw.Add(string.Format("IsRefund<={0}", 1));
  3181. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3182. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3183. string pagesize = GetPostString("pagesize");
  3184. if (pagesize != null)
  3185. {
  3186. dStruct.PageSize = 200;
  3187. }
  3188. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3189. foreach (DataRow dr in dt.Rows)
  3190. {
  3191. 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();
  3192. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3193. {
  3194. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3195. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3196. entity.SupplierId = suid;
  3197. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3198. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3199. entity.Update();
  3200. }
  3201. }
  3202. writeGridDataTableJson(dStruct.TotalCount, dt);
  3203. }
  3204. public void get_erp_supplierwaitorderlist()
  3205. {
  3206. DataStruct dStruct = GetPostStruct();
  3207. List<string> lw = new List<string>();
  3208. string tid = GetPostString("ctid");
  3209. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3210. string shopname = GetPostString("shopname");
  3211. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3212. string sellermemo = GetPostString("seller_memo");
  3213. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3214. string date1 = GetPostString("date1");
  3215. string date2 = GetPostString("date2");
  3216. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3217. if (dw.Length > 0) lw.Add(dw);
  3218. lw.Add(string.Format("OrderState = 5 "));
  3219. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3220. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3221. {
  3222. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3223. }
  3224. string supplier = GetPostString("supplier");
  3225. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3226. {
  3227. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3228. }
  3229. lw.Add(string.Format("IsRefund<={0}", 1));
  3230. dStruct.Order = "FinishDesignTime desc";
  3231. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3232. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3233. if (dt != null)
  3234. {
  3235. foreach (DataRow dr in dt.Rows)
  3236. {
  3237. 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();
  3238. }
  3239. }
  3240. writeGridDataTableJson(dStruct.TotalCount, dt);
  3241. }
  3242. public void upd_erp_verifytosupplier()
  3243. {
  3244. if (UrlPostParmsCheck("ctid"))
  3245. {
  3246. string eids = GetPostString("ctid");
  3247. CeErpTradeCell entity = null;
  3248. string[] eidsList = eids.Split(',');
  3249. if (eidsList.Length <= 0)
  3250. {
  3251. returnErrorMsg("订单号不能空");
  3252. return;
  3253. }
  3254. List<string> tLst = new List<string>();
  3255. foreach (string ctidstr in eidsList)
  3256. {
  3257. tLst.Add("'" + ctidstr + "'");
  3258. CeErpDataSendOrderInfo.createObject(ctidstr);
  3259. }
  3260. string needtids = string.Join(",", tLst.ToArray());
  3261. StringBuilder sql = new StringBuilder();
  3262. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3263. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1} where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3264. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3265. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3266. returnSuccessMsg("操作成功!");
  3267. return;
  3268. /**foreach (string ctidstr in eidsList)
  3269. {
  3270. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3271. if (entity != null)
  3272. {
  3273. if (entity.SupplierId == 0)
  3274. {
  3275. continue;
  3276. }
  3277. entity.IsVerifyToSupplier = true;
  3278. if (entity.IsReturn == 1) //1是供应商打回
  3279. {
  3280. entity.IsReturn = 0;
  3281. }
  3282. entity.FinishPlaceTime = DateTime.Now;
  3283. entity.PlaceUserId = CurrentUser.UserID;
  3284. entity.Update();
  3285. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3286. }
  3287. }
  3288. returnSuccessMsg("操作成功!");
  3289. return;**/
  3290. }
  3291. }
  3292. public void upd_erp_supplierback()
  3293. {
  3294. if (UrlPostParmsCheck("ctid"))
  3295. {
  3296. string eid = GetPostString("ctid");
  3297. string reason = GetPostString("returnreason");
  3298. CeErpTradeCell entity = null;
  3299. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3300. if (entity != null)
  3301. {
  3302. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3303. {
  3304. string key = "return_order_" + entity.SupplierId;
  3305. List<string> list = new List<string>();
  3306. if (RedisHelper.HasKey(key))
  3307. {
  3308. object data = RedisHelper.StringGet(key);
  3309. list = Convert.ToString(data).Split(',').ToList();
  3310. }
  3311. list.Add(eid);
  3312. RedisHelper.StringSet(key, string.Join(",", list));
  3313. }
  3314. entity.IsVerifyToSupplier = false;
  3315. entity.IsReturn = 1;
  3316. entity.ReturnTime = DateTime.Now;
  3317. entity.ReturnReason = reason;
  3318. if (entity.OrderState == 6)
  3319. {
  3320. entity.OrderState = 5;
  3321. }
  3322. entity.Update();
  3323. CeErpSukuraData.createInfo(entity.ctid, 5);
  3324. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3325. returnSuccessMsg("操作成功!");
  3326. return;
  3327. }
  3328. returnErrorMsg("找不到订单记录");
  3329. }
  3330. }
  3331. public void upd_erp_toaftersaleorder()
  3332. {
  3333. if (UrlPostParmsCheck("ctid"))
  3334. {
  3335. string eid = GetPostString("ctid");
  3336. string reason = GetPostString("returnreason");
  3337. CeErpTradeCell entity = null;
  3338. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3339. if (entity != null)
  3340. {
  3341. if (entity.isAfterSaleOrder != 1)
  3342. {
  3343. returnErrorMsg("带S的售后单才能打回给售后");
  3344. return;
  3345. }
  3346. if (entity.OrderState >= 5)
  3347. {
  3348. returnErrorMsg("已经设计完成了不能打回给售后");
  3349. return;
  3350. }
  3351. entity.OrderState = 0;
  3352. entity.IsReturn = 3;
  3353. entity.ReturnTime = DateTime.Now;
  3354. entity.ReturnReason = reason;
  3355. entity.Update();
  3356. CeErpSukuraData.createInfo(entity.ctid, 5);
  3357. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3358. returnSuccessMsg("操作成功!");
  3359. return;
  3360. }
  3361. returnErrorMsg("找不到订单记录");
  3362. }
  3363. }
  3364. public void upd_erp_aftersaletodesign()
  3365. {
  3366. if (UrlPostParmsCheck("ctid"))
  3367. {
  3368. string eid = GetPostString("ctid");
  3369. CeErpTradeCell entity = null;
  3370. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3371. if (entity != null)
  3372. {
  3373. entity.OrderState = 3;
  3374. entity.IsReturn = 0;
  3375. entity.Update();
  3376. CeErpSukuraData.createInfo(entity.ctid, 5);
  3377. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3378. returnSuccessMsg("操作成功!");
  3379. return;
  3380. }
  3381. returnErrorMsg("找不到订单记录");
  3382. }
  3383. }
  3384. public void assign_erp_supplier()
  3385. {
  3386. if (UrlPostParmsCheck("ctid"))
  3387. {
  3388. string eids = GetPostString("ctid");
  3389. int sid = GetPostInt("SupplierName");
  3390. string fromTag = GetPostString("tag");
  3391. string[] eidList = eids.Split(',');
  3392. if (eidList.Length <= 0)
  3393. {
  3394. returnErrorMsg("指派不能为空");
  3395. return;
  3396. }
  3397. string errMsg = "";
  3398. string suname = commonHelper.getSupplierNameById(sid);
  3399. foreach (string ctid in eidList)
  3400. {
  3401. CeErpTradeCell entity = null;
  3402. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3403. if (entity != null)
  3404. {
  3405. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3406. {
  3407. errMsg += (ctid + "指派失败!!!");
  3408. continue;
  3409. }
  3410. entity.SupplierId = sid;
  3411. entity.Update();
  3412. commonHelper.UpdateRelationOrder(entity.ctid);
  3413. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3414. if (entity.OrderState >= 6)
  3415. {
  3416. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3417. //{
  3418. // string msl = entity.MakeSupplier;
  3419. // string[] mslist = msl.Split(',');
  3420. // 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);
  3421. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3422. //}
  3423. //else
  3424. //{
  3425. StringBuilder sql = new StringBuilder();
  3426. 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);
  3427. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3428. //}
  3429. }
  3430. }
  3431. else
  3432. {
  3433. continue;
  3434. }
  3435. }
  3436. if (errMsg.Length > 0)
  3437. {
  3438. returnErrorMsg(errMsg);
  3439. return;
  3440. }
  3441. returnSuccessMsg("操作成功!");
  3442. return;
  3443. }
  3444. }
  3445. public void assign_erp_makesupplier()
  3446. {
  3447. if (UrlPostParmsCheck("ctid"))
  3448. {
  3449. string eids = GetPostString("ctid");
  3450. string sname = GetPostString("SupplierName");
  3451. string[] eidList = eids.Split(',');
  3452. if (eidList.Length <= 0)
  3453. {
  3454. returnErrorMsg("指派不能为空");
  3455. return;
  3456. }
  3457. List<string> tLst = new List<string>();
  3458. foreach (string ctid in eidList)
  3459. {
  3460. CeErpTradeCell entity = null;
  3461. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3462. if (entity != null)
  3463. {
  3464. entity.MakeSupplier = sname;
  3465. entity.Update();
  3466. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3467. tLst.Add("'" + ctid + "'");
  3468. }
  3469. else
  3470. {
  3471. continue;
  3472. }
  3473. }
  3474. string ctids = string.Join(",", tLst.ToArray());
  3475. StringBuilder sql2 = new StringBuilder();
  3476. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3477. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3478. returnSuccessMsg("操作成功!");
  3479. return;
  3480. }
  3481. }
  3482. public void ins_erp_returnreason()
  3483. {
  3484. if (UrlPostParmsCheck("ctid"))
  3485. {
  3486. string eid = GetPostString("ctid");
  3487. CeErpTradeCell entity = null;
  3488. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3489. string userpost = CurrentUser.UserPost.Post.Code;
  3490. if (entity != null)
  3491. {
  3492. bool isPlace = false;
  3493. if (entity.OrderState > 6)
  3494. {
  3495. returnErrorMsg("已发货无法打回!");
  3496. return;
  3497. }
  3498. if (entity.OrderState == 6)
  3499. {
  3500. isPlace = true;
  3501. }
  3502. bool isNeedUpdateCell2 = false;
  3503. if (entity.OrderState >= 6)
  3504. {
  3505. isNeedUpdateCell2 = true;
  3506. }
  3507. int returnTag = 2;
  3508. if (userpost == "Supplier")
  3509. {
  3510. returnTag = 1;
  3511. }
  3512. int toType = GetPostInt("totype");
  3513. string fromType = "3";
  3514. if (entity.OrderState < 5)
  3515. {
  3516. fromType = "3";
  3517. }
  3518. else
  3519. {
  3520. fromType = "4";
  3521. }
  3522. if (entity.IsXianHuo == 0)
  3523. {
  3524. if (returnTag == 2)
  3525. {
  3526. if (toType == 1)
  3527. {
  3528. entity.OrderState = 0;
  3529. entity.ReturnUserType = 1;
  3530. string clearman = GetPostString("clearman");
  3531. if (!string.IsNullOrEmpty(clearman))
  3532. {
  3533. entity.DesignUserId = 0;
  3534. }
  3535. }
  3536. else
  3537. {
  3538. entity.OrderState = 3;
  3539. entity.ReturnUserType = 2;
  3540. }
  3541. entity.IsReadTag = 1;
  3542. }
  3543. else if (returnTag == 1)
  3544. {
  3545. entity.OrderState = 5;
  3546. }
  3547. entity.IsVerifyToSupplier = false;
  3548. }
  3549. if (entity.IsXianHuo == 1)
  3550. {
  3551. entity.OrderState = 5;
  3552. }
  3553. entity.UnusualTag = 0;
  3554. entity.UnusualTime = null;
  3555. entity.UnusualCon = "";
  3556. entity.IsReturn = returnTag;
  3557. entity.ReturnTime = DateTime.Now;
  3558. entity.ReturnReason = GetPostString("returnreason");
  3559. entity.Update();
  3560. if (entity.OrderState == 3)
  3561. {
  3562. ApiVo apiVo = new ApiVo();
  3563. apiVo.orderNumber = entity.ctid;
  3564. apiVo.actionName = "rebutDesign";
  3565. apiVo.orderRemarks = entity.ReturnReason;
  3566. designHelper.API_WorkCore(apiVo);//rebutDesign
  3567. }
  3568. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3569. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3570. {
  3571. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3572. }
  3573. CeErpSukuraData.createInfo(entity.ctid, 5);
  3574. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3575. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3576. if (isPlace)
  3577. {
  3578. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3579. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3580. if (dth != null && dth.Rows.Count > 0)
  3581. {
  3582. dataSendOrderBean dataSendOrderBean = null;
  3583. foreach (DataRow item in dth.Rows)
  3584. {
  3585. try
  3586. {
  3587. dataSendOrderBean = new dataSendOrderBean();
  3588. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3589. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3590. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3591. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3592. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3593. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3594. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3595. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3596. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3597. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3598. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3599. dataSendOrderBean.Radio1723534706288 = "打回";
  3600. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3601. if (result != null)
  3602. {
  3603. if ("0".Equals(result.errcode))
  3604. {
  3605. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3606. }
  3607. else
  3608. {
  3609. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3610. }
  3611. }
  3612. }
  3613. catch (Exception ex)
  3614. {
  3615. }
  3616. }
  3617. }
  3618. }
  3619. if (isNeedUpdateCell2)
  3620. {
  3621. if (entity.MakeSupplier.IndexOf(",") != -1)
  3622. {
  3623. StringBuilder sql2 = new StringBuilder();
  3624. 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);
  3625. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3626. }
  3627. else
  3628. {
  3629. StringBuilder sql2 = new StringBuilder();
  3630. 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);
  3631. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3632. }
  3633. }
  3634. returnSuccessMsg("操作成功!");
  3635. return;
  3636. }
  3637. returnErrorMsg("找不到订单记录");
  3638. }
  3639. }
  3640. public void cyt_erp_returnreason()
  3641. {
  3642. if (UrlPostParmsCheck("ctid"))
  3643. {
  3644. string eid = GetPostString("ctid");
  3645. CeErpTradeCell entity = null;
  3646. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3647. string userpost = CurrentUser.UserPost.Post.Code;
  3648. if (entity != null)
  3649. {
  3650. if (entity.OrderState > 6)
  3651. {
  3652. returnErrorMsg("已发货无法打回!");
  3653. return;
  3654. }
  3655. JObject jsonObject = new JObject
  3656. {
  3657. { "Userid", "77886" },
  3658. { "Pwd", "lt666888" },
  3659. { "LTOrderId",eid }
  3660. };
  3661. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3662. JObject jsonObjects = JObject.Parse(response);
  3663. string msg = (string)jsonObjects["msg"];
  3664. if (msg != "取消成功")
  3665. {
  3666. returnErrorMsg(msg);
  3667. return;
  3668. }
  3669. bool isNeedUpdateCell2 = false;
  3670. if (entity.OrderState >= 6)
  3671. {
  3672. isNeedUpdateCell2 = true;
  3673. }
  3674. int returnTag = 2;
  3675. if (userpost == "Supplier")
  3676. {
  3677. returnTag = 1;
  3678. }
  3679. if (entity.IsXianHuo == 0)
  3680. {
  3681. if (returnTag == 2)
  3682. {
  3683. int toType = GetPostInt("totype");
  3684. if (toType == 1)
  3685. {
  3686. entity.OrderState = 0;
  3687. entity.ReturnUserType = 1;
  3688. }
  3689. else
  3690. {
  3691. entity.OrderState = 4;
  3692. entity.ReturnUserType = 2;
  3693. }
  3694. entity.IsReadTag = 1;
  3695. }
  3696. else if (returnTag == 1)
  3697. {
  3698. entity.OrderState = 5;
  3699. }
  3700. entity.IsVerifyToSupplier = false;
  3701. }
  3702. entity.UnusualTag = 0;
  3703. entity.UnusualTime = null;
  3704. entity.UnusualCon = "";
  3705. entity.IsReturn = returnTag;
  3706. entity.ReturnTime = DateTime.Now;
  3707. entity.ReturnReason = GetPostString("returnreason");
  3708. entity.Update();
  3709. if (entity.OrderState == 4)
  3710. {
  3711. ApiVo apiVo = new ApiVo();
  3712. apiVo.orderNumber = entity.ctid;
  3713. apiVo.actionName = "rebutDesign";
  3714. apiVo.orderRemarks = entity.ReturnReason;
  3715. designHelper.API_WorkCore(apiVo);//rebutDesign
  3716. }
  3717. CeErpSukuraData.createInfo(entity.ctid, 5);
  3718. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3719. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3720. if (isNeedUpdateCell2)
  3721. {
  3722. if (entity.MakeSupplier.IndexOf(",") != -1)
  3723. {
  3724. StringBuilder sql2 = new StringBuilder();
  3725. 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);
  3726. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3727. }
  3728. else
  3729. {
  3730. StringBuilder sql2 = new StringBuilder();
  3731. 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);
  3732. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3733. }
  3734. }
  3735. returnSuccessMsg("操作成功!");
  3736. return;
  3737. }
  3738. returnErrorMsg("找不到订单记录");
  3739. }
  3740. }
  3741. public void upd_erp_xianhuoreturntag()
  3742. {
  3743. if (UrlPostParmsCheck("ctid"))
  3744. {
  3745. string eids = GetPostString("ctid");
  3746. string[] ctids = eids.Split(',');
  3747. foreach (string ctid in ctids)
  3748. {
  3749. CeErpTradeCell entity = null;
  3750. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3751. if (entity != null)
  3752. {
  3753. entity.IsReturn = 0;
  3754. entity.Update();
  3755. CeErpSukuraData.createInfo(entity.ctid, 5);
  3756. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  3757. }
  3758. }
  3759. returnSuccessMsg("操作成功!");
  3760. return;
  3761. }
  3762. }
  3763. public void get_erp_waitdeliverylist()
  3764. {
  3765. DataStruct dStruct = GetPostStruct();
  3766. List<string> lw = new List<string>();
  3767. string tid = GetPostString("ctid");
  3768. if (tid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid));
  3769. string shopname = GetPostString("shopname");
  3770. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3771. string buyernick = GetPostString("buyer_nick");
  3772. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3773. //if (tid.Length == 0 && buyernick.Length == 0)
  3774. //{
  3775. // lw.Add(string.Format("IsRefund<={0}", 1));
  3776. //}
  3777. string customer = GetPostString("customer");
  3778. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3779. string design = GetPostString("design");
  3780. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3781. string orderState = GetPostString("orderState");
  3782. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3783. string address = GetPostString("address");
  3784. 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));
  3785. string sellermemo = GetPostString("seller_memo");
  3786. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3787. string supplier = GetPostString("supplier");
  3788. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3789. string OrderArea = GetPostString("order_area");
  3790. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3791. string placedate1 = GetPostString("placedate1");
  3792. string placedate2 = GetPostString("placedate2");
  3793. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  3794. if (fdw.Length > 0) lw.Add(fdw);
  3795. string price1 = GetPostString("price1");
  3796. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3797. string price2 = GetPostString("price2");
  3798. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3799. string unusualCon = GetPostString("unusualcon");
  3800. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  3801. string otherMemo = GetPostString("otherMemo");
  3802. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3803. string posTag = CurrentUser.UserPost.Post.Code;
  3804. if (posTag == "Supplier")
  3805. {
  3806. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3807. }
  3808. lw.Add(string.Format("OrderState = 6 "));
  3809. lw.Add(string.Format("type != 'PDD' "));
  3810. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  3811. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  3812. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3813. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3814. writeGridDataTableJson(dStruct.TotalCount, dt);
  3815. }
  3816. public void get_erp_pddderiving()
  3817. {
  3818. DataStruct dStruct = GetPostStruct();
  3819. List<string> lw = new List<string>();
  3820. string tid = GetPostString("ctid");
  3821. if (tid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid));
  3822. string shopname = GetPostString("shopname");
  3823. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3824. string buyernick = GetPostString("buyer_nick");
  3825. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3826. //if (tid.Length == 0 && buyernick.Length == 0)
  3827. //{
  3828. // lw.Add(string.Format("IsRefund<={0}", 1));
  3829. //}
  3830. string customer = GetPostString("customer");
  3831. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3832. string design = GetPostString("design");
  3833. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3834. string orderState = GetPostString("orderState");
  3835. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3836. string address = GetPostString("address");
  3837. 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));
  3838. string sellermemo = GetPostString("seller_memo");
  3839. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3840. string supplier = GetPostString("supplier");
  3841. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3842. string OrderArea = GetPostString("order_area");
  3843. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3844. string placedate1 = GetPostString("placedate1");
  3845. string placedate2 = GetPostString("placedate2");
  3846. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  3847. if (fdw.Length > 0) lw.Add(fdw);
  3848. string price1 = GetPostString("price1");
  3849. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3850. string price2 = GetPostString("price2");
  3851. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3852. string unusualCon = GetPostString("unusualcon");
  3853. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  3854. string posTag = CurrentUser.UserPost.Post.Code;
  3855. if (posTag == "Supplier")
  3856. {
  3857. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3858. }
  3859. lw.Add(string.Format("OrderState = 6 "));
  3860. lw.Add(string.Format("type = 'PDD' "));
  3861. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  3862. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  3863. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3864. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3865. writeGridDataTableJson(dStruct.TotalCount, dt);
  3866. }
  3867. public void get_erp_jdderiving()
  3868. {
  3869. DataStruct dStruct = GetPostStruct();
  3870. List<string> lw = new List<string>();
  3871. string tid = GetPostString("ctid");
  3872. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  3873. string shopname = GetPostString("shopname");
  3874. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3875. string buyernick = GetPostString("buyer_nick");
  3876. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3877. //if (tid.Length == 0 && buyernick.Length == 0)
  3878. //{
  3879. // lw.Add(string.Format("IsRefund<={0}", 1));
  3880. //}
  3881. string customer = GetPostString("customer");
  3882. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3883. string design = GetPostString("design");
  3884. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3885. string orderState = GetPostString("orderState");
  3886. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3887. string address = GetPostString("address");
  3888. 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));
  3889. string sellermemo = GetPostString("seller_memo");
  3890. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3891. string supplier = GetPostString("supplier");
  3892. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3893. string OrderArea = GetPostString("order_area");
  3894. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3895. string placedate1 = GetPostString("placedate1");
  3896. string placedate2 = GetPostString("placedate2");
  3897. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  3898. if (fdw.Length > 0) lw.Add(fdw);
  3899. string price1 = GetPostString("price1");
  3900. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3901. string price2 = GetPostString("price2");
  3902. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3903. string unusualCon = GetPostString("unusualcon");
  3904. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  3905. string posTag = CurrentUser.UserPost.Post.Code;
  3906. if (posTag == "Supplier")
  3907. {
  3908. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3909. }
  3910. lw.Add(string.Format("OrderState = 6 "));
  3911. lw.Add(string.Format("type = 'JD' "));
  3912. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  3913. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  3914. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3915. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3916. writeGridDataTableJson(dStruct.TotalCount, dt);
  3917. }
  3918. public void get_erp_demoorderlist()
  3919. {
  3920. DataStruct dStruct = GetPostStruct();
  3921. List<string> lw = new List<string>();
  3922. string tid = GetPostString("ctid");
  3923. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3924. string shopname = GetPostString("shopname");
  3925. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3926. string buyernick = GetPostString("buyer_nick");
  3927. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3928. string customer = GetPostString("customer");
  3929. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3930. string design = GetPostString("design");
  3931. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3932. string orderState = GetPostString("orderState");
  3933. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3934. string address = GetPostString("address");
  3935. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  3936. string sellermemo = GetPostString("seller_memo");
  3937. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3938. string supplier = GetPostString("supplier");
  3939. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3940. string OrderArea = GetPostString("order_area");
  3941. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3942. string date1 = GetPostString("date1");
  3943. string date2 = GetPostString("date2");
  3944. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3945. if (dw.Length > 0) lw.Add(dw);
  3946. string price1 = GetPostString("price1");
  3947. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3948. string price2 = GetPostString("price2");
  3949. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3950. string posTag = CurrentUser.UserPost.Post.Code;
  3951. if (posTag == "Supplier")
  3952. {
  3953. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3954. }
  3955. //lw.Add(string.Format("OrderState = 6 "));
  3956. lw.Add(string.Format("IsSample={0}", 3));
  3957. lw.Add(string.Format("IsRefund<={0}", 1));
  3958. dStruct.Order = "pay_time desc";
  3959. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3960. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3961. writeGridDataTableJson(dStruct.TotalCount, dt);
  3962. }
  3963. public void save_erp_checkmemo()
  3964. {
  3965. if (UrlPostParmsCheck("ctid"))
  3966. {
  3967. string ctid = GetPostString("ctid");
  3968. CeErpTradeCell entity = null;
  3969. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3970. if (entity != null)
  3971. {
  3972. entity.CheckMemo = GetPostString("CheckMemo");
  3973. entity.Update();
  3974. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  3975. if (trade != null)
  3976. {
  3977. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  3978. }
  3979. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  3980. returnSuccessMsg("保存成功!");
  3981. return;
  3982. }
  3983. returnErrorMsg("找不到记录");
  3984. }
  3985. }
  3986. public void get_erp_returnlist()
  3987. {
  3988. DataStruct dStruct = GetPostStruct();
  3989. List<string> lw = new List<string>();
  3990. string tid = GetPostString("ctid");
  3991. if (tid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", tid));
  3992. string shopname = GetPostString("shopname");
  3993. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3994. string buyernick = GetPostString("buyer_nick");
  3995. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3996. string customer = GetPostString("customer");
  3997. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3998. string design = GetPostString("design");
  3999. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4000. string orderState = GetPostString("orderState");
  4001. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4002. string address = GetPostString("address");
  4003. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4004. string sellermemo = GetPostString("seller_memo");
  4005. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4006. string supplier = GetPostString("supplier");
  4007. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4008. string date1 = GetPostString("date1");
  4009. string date2 = GetPostString("date2");
  4010. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4011. if (dw.Length > 0) lw.Add(dw);
  4012. string bdate1 = GetPostString("backdate1");
  4013. string bdate2 = GetPostString("backdate2");
  4014. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4015. if (dw_back.Length > 0) lw.Add(dw_back);
  4016. string price1 = GetPostString("price1");
  4017. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4018. string price2 = GetPostString("price2");
  4019. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4020. lw.Add(string.Format("IsReturn>0"));
  4021. lw.Add(string.Format("IsXianHuo=0"));
  4022. lw.Add(string.Format("IsReturn!=3"));
  4023. string backtype = GetPostString("backtype");
  4024. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4025. dStruct.Order = "FinishDesignTime desc";
  4026. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4027. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4028. writeGridDataTableJson(dStruct.TotalCount, dt);
  4029. }
  4030. public void get_erp_today_sumreturn()
  4031. {
  4032. DataStruct dStruct = GetPostStruct();
  4033. List<string> lw = new List<string>();
  4034. string bdate1 = GetPostString("returnTimeS");
  4035. string bdate2 = GetPostString("returnTimeE");
  4036. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4037. if (dw_back.Length > 0) lw.Add(dw_back);
  4038. lw.Add(string.Format("IsReturn=0"));
  4039. lw.Add(string.Format("IsXianHuo=0"));
  4040. string mainWhere = string.Join(" and ", lw.ToArray());
  4041. string sql = "";
  4042. if (dw_back.Length > 0)
  4043. {
  4044. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4045. }
  4046. else
  4047. {
  4048. 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 + "'";
  4049. }
  4050. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4051. decimal total = 0, today_finish = 0;
  4052. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4053. {
  4054. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4055. }
  4056. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4057. {
  4058. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4059. }
  4060. var res = new
  4061. {
  4062. data = total,
  4063. data1 = today_finish,
  4064. };
  4065. string ro_jsond = JsonConvert.SerializeObject(res);
  4066. returnSuccess(ro_jsond);
  4067. return;
  4068. }
  4069. public void get_erp_allreturnlist()
  4070. {
  4071. DataStruct dStruct = GetPostStruct();
  4072. List<string> lw = new List<string>();
  4073. string tid = GetPostString("ctid");
  4074. if (tid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", tid));
  4075. string shopname = GetPostString("shopname");
  4076. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4077. string buyernick = GetPostString("buyer_nick");
  4078. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4079. string customer = GetPostString("customer");
  4080. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4081. string design = GetPostString("design");
  4082. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4083. string orderState = GetPostString("orderState");
  4084. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4085. string address = GetPostString("address");
  4086. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4087. string sellermemo = GetPostString("seller_memo");
  4088. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4089. string supplier = GetPostString("supplier");
  4090. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4091. string date1 = GetPostString("date1");
  4092. string date2 = GetPostString("date2");
  4093. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4094. if (dw.Length > 0) lw.Add(dw);
  4095. string bdate1 = GetPostString("backdate1");
  4096. string bdate2 = GetPostString("backdate2");
  4097. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4098. if (dw_back.Length > 0) lw.Add(dw_back);
  4099. string price1 = GetPostString("price1");
  4100. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4101. string price2 = GetPostString("price2");
  4102. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4103. string backreason = GetPostString("backreason");
  4104. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4105. lw.Add(string.Format("IsXianHuo=0"));
  4106. lw.Add(string.Format("ReturnTime != ''"));
  4107. string backtype = GetPostString("backtype");
  4108. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4109. dStruct.Order = "FinishDesignTime desc";
  4110. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4111. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4112. writeGridDataTableJson(dStruct.TotalCount, dt);
  4113. }
  4114. public void get_erp_aftersalereturnlist()
  4115. {
  4116. DataStruct dStruct = GetPostStruct();
  4117. List<string> lw = new List<string>();
  4118. string tid = GetPostString("ctid");
  4119. if (tid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", tid));
  4120. string shopname = GetPostString("shopname");
  4121. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4122. string buyernick = GetPostString("buyer_nick");
  4123. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4124. string customer = GetPostString("customer");
  4125. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4126. string design = GetPostString("design");
  4127. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4128. string orderState = GetPostString("orderState");
  4129. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4130. string address = GetPostString("address");
  4131. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4132. string sellermemo = GetPostString("seller_memo");
  4133. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4134. string supplier = GetPostString("supplier");
  4135. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4136. string date1 = GetPostString("date1");
  4137. string date2 = GetPostString("date2");
  4138. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4139. if (dw.Length > 0) lw.Add(dw);
  4140. string bdate1 = GetPostString("backdate1");
  4141. string bdate2 = GetPostString("backdate2");
  4142. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4143. if (dw_back.Length > 0) lw.Add(dw_back);
  4144. string price1 = GetPostString("price1");
  4145. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4146. string price2 = GetPostString("price2");
  4147. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4148. lw.Add(string.Format("IsReturn=3"));
  4149. string backtype = GetPostString("backtype");
  4150. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4151. string backreason = GetPostString("backreason");
  4152. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4153. dStruct.Order = "ReturnTime desc";
  4154. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4155. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4156. writeGridDataTableJson(dStruct.TotalCount, dt);
  4157. }
  4158. public void get_erp_xianhuoreturnlist()
  4159. {
  4160. DataStruct dStruct = GetPostStruct();
  4161. List<string> lw = new List<string>();
  4162. string tid = GetPostString("ctid");
  4163. if (tid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", tid));
  4164. string shopname = GetPostString("shopname");
  4165. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4166. string buyernick = GetPostString("buyer_nick");
  4167. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4168. string customer = GetPostString("customer");
  4169. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4170. string design = GetPostString("design");
  4171. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4172. string orderState = GetPostString("orderState");
  4173. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4174. string address = GetPostString("address");
  4175. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4176. string sellermemo = GetPostString("seller_memo");
  4177. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4178. string supplier = GetPostString("supplier");
  4179. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4180. string OrderArea = GetPostString("order_area");
  4181. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4182. string date1 = GetPostString("date1");
  4183. string date2 = GetPostString("date2");
  4184. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4185. if (dw.Length > 0) lw.Add(dw);
  4186. string price1 = GetPostString("price1");
  4187. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4188. string price2 = GetPostString("price2");
  4189. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4190. string posTag = CurrentUser.UserPost.Post.Code;
  4191. if (posTag == "Supplier")
  4192. {
  4193. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4194. }
  4195. lw.Add(string.Format("OrderState=6 "));
  4196. lw.Add(string.Format("IsXianHuo=1 "));
  4197. lw.Add(string.Format("IsReturn>0 "));
  4198. lw.Add(string.Format("IsReturn!=3"));
  4199. lw.Add(string.Format("IsRefund<={0}", 1));
  4200. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4201. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4202. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4203. writeGridDataTableJson(dStruct.TotalCount, dt);
  4204. }
  4205. public void set_erp_orderdelivery()
  4206. {
  4207. if (UrlPostParmsCheck("ctid"))
  4208. {
  4209. string eid = GetPostString("ctid");
  4210. CeErpTradeCell entity = null;
  4211. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4212. if (entity != null)
  4213. {
  4214. if (entity.OrderState >= 7)
  4215. {
  4216. returnErrorMsg("此单已发货,无需重复发货");
  4217. return;
  4218. }
  4219. if (entity.OrderState != 6)
  4220. {
  4221. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4222. return;
  4223. }
  4224. string shop = GetPostString("seller_nick");
  4225. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4226. string comName = GetPostString("comName");
  4227. string comCode = GetPostString("comCode");
  4228. string outSid = GetPostString("outSid");
  4229. string deliveryType = GetPostString("deliveryType");
  4230. string deliveryMemo = GetPostString("deliveryMemo");
  4231. outSid = outSid.Trim();
  4232. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4233. if (mainEn == null)
  4234. {
  4235. returnErrorMsg("找不到原始订单记录");
  4236. return;
  4237. }
  4238. bool isInitOrderDeliv = false;
  4239. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4240. {
  4241. isInitOrderDeliv = true;
  4242. }
  4243. string apires = "";
  4244. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4245. 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)
  4246. {
  4247. apires = "发货成功true";
  4248. }
  4249. else
  4250. {
  4251. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4252. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4253. }
  4254. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4255. {
  4256. entity.OrderState = 7;//发货后订单已发货
  4257. entity.OutSid = outSid;
  4258. entity.MemoOpt = 0;
  4259. entity.FinishDeliveryTime = DateTime.Now;
  4260. entity.Update();
  4261. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4262. commonHelper.UpdateRelationOrder(entity.ctid);
  4263. //还要插入快递信息到 快递信息表
  4264. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4265. exinfo.tid = eid;
  4266. exinfo.out_sid = outSid;
  4267. exinfo.company_code = comCode;
  4268. exinfo.company_name = comName;
  4269. exinfo.delivery_memo = deliveryMemo;
  4270. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4271. exinfo.deliveryType = deliveryType;
  4272. exinfo.Create();
  4273. returnSuccessMsg("发货操作成功!");
  4274. commonHelper.UpdateRelationOrder(entity.ctid);
  4275. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4276. CeErpSukuraData.createInfo(entity.ctid, 4);
  4277. if (entity.SupplierId == 64)
  4278. {
  4279. commonHelper.sendCytExpress(exinfo);
  4280. }
  4281. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4282. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4283. }
  4284. else
  4285. {
  4286. string errmsg = commonHelper.KeepChinese(apires);
  4287. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4288. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4289. }
  4290. return;
  4291. }
  4292. returnErrorMsg("找不到订单记录");
  4293. }
  4294. }
  4295. public void set_erp_multidelivery()
  4296. {
  4297. string eids = GetPostString("tids");
  4298. string[] eidList = eids.Split(',');
  4299. if (eidList.Length <= 0)
  4300. {
  4301. returnErrorMsg("发货不能为空");
  4302. return;
  4303. }
  4304. foreach (string ctid in eidList)
  4305. {
  4306. if (ctid.Length <= 0) continue;
  4307. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4308. if (expInfo != null)
  4309. {
  4310. StringBuilder sql = new StringBuilder();
  4311. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4312. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4313. if (dt.Rows.Count > 0)
  4314. {
  4315. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4316. {
  4317. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4318. expInfo.state = "异常";
  4319. expInfo.isMultiDelivery = 1;
  4320. expInfo.Update();
  4321. continue;
  4322. }
  4323. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4324. {
  4325. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4326. expInfo.state = "异常";
  4327. expInfo.Update();
  4328. continue;
  4329. }
  4330. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4331. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4332. bool isInitOrderDeliv = false;
  4333. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4334. {
  4335. isInitOrderDeliv = true;
  4336. expInfo.isMultiDelivery = 1;
  4337. }
  4338. if (ctid.IndexOf("N") != -1)
  4339. {
  4340. StringBuilder sqlbucha = new StringBuilder();
  4341. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4342. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4343. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4344. commonHelper.UpdateRelationOrder(ctid);
  4345. expInfo.delivery_memo = "发货成功";
  4346. expInfo.state = "发货成功";
  4347. expInfo.isMultiDelivery = 1;
  4348. expInfo.Update();
  4349. }
  4350. else
  4351. {
  4352. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4353. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4354. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4355. {
  4356. expInfo.delivery_memo = "发货成功";
  4357. expInfo.state = "发货成功";
  4358. expInfo.isMultiDelivery = 1;
  4359. expInfo.Update();
  4360. commonHelper.UpdateRelationOrder(ctid);
  4361. CeErpSukuraData.createInfo(ctid, 4);
  4362. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4363. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4364. }
  4365. else
  4366. {
  4367. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4368. expInfo.state = "异常";
  4369. expInfo.Update();
  4370. }
  4371. }
  4372. }
  4373. }
  4374. }
  4375. returnSuccessMsg("操作完成");
  4376. }
  4377. public void reset_erp_memoopt()
  4378. {
  4379. if (UrlPostParmsCheck("ctid"))
  4380. {
  4381. string eid = GetPostString("ctid");
  4382. CeErpTradeCell entity = null;
  4383. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4384. if (entity != null)
  4385. {
  4386. string stropt = "";
  4387. if (entity.MemoOpt == 1)
  4388. {
  4389. stropt = "“改稿”";
  4390. }
  4391. else if (entity.MemoOpt == 2)
  4392. {
  4393. stropt = "“定稿”";
  4394. }
  4395. else if (entity.MemoOpt == 3)
  4396. {
  4397. stropt = "“完成查货”";
  4398. CeErpSukuraData.createInfo(entity.ctid, 6);
  4399. }
  4400. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4401. entity.MemoOpt = 0;
  4402. entity.Update();
  4403. returnSuccessMsg("操作成功!");
  4404. return;
  4405. }
  4406. returnErrorMsg("找不到记录");
  4407. }
  4408. }
  4409. public void get_erp_deliveryunusual()
  4410. {
  4411. DataStruct dStruct = GetPostStruct();
  4412. List<string> lw = new List<string>();
  4413. string tid = GetPostString("ctid");
  4414. if (tid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", tid));
  4415. string shopname = GetPostString("shopname");
  4416. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4417. string buyernick = GetPostString("buyer_nick");
  4418. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4419. string customer = GetPostString("customer");
  4420. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4421. string design = GetPostString("design");
  4422. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4423. string sellermemo = GetPostString("seller_memo");
  4424. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4425. string supplier = GetPostString("supplier");
  4426. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4427. string date1 = GetPostString("date1");
  4428. string date2 = GetPostString("date2");
  4429. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4430. if (dw.Length > 0) lw.Add(dw);
  4431. string placedate1 = GetPostString("placedate1");
  4432. string placedate2 = GetPostString("placedate2");
  4433. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4434. if (dw_place.Length > 0) lw.Add(dw_place);
  4435. string price1 = GetPostString("price1");
  4436. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4437. string price2 = GetPostString("price2");
  4438. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4439. string unusualCon = GetPostString("unusualcon");
  4440. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4441. string posTag = CurrentUser.UserPost.Post.Code;
  4442. if (posTag == "Supplier")
  4443. {
  4444. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4445. }
  4446. lw.Add(string.Format("OrderState = 6"));
  4447. lw.Add(string.Format("UnusualTag = 5"));
  4448. lw.Add(string.Format("IsRefund<={0}", 1));
  4449. dStruct.Order = "FinishPlaceTime desc";
  4450. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4451. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4452. writeGridDataTableJson(dStruct.TotalCount, dt);
  4453. }
  4454. public void get_erp_deliveryedlist()
  4455. {
  4456. DataStruct dStruct = GetPostStruct();
  4457. List<string> lw = new List<string>();
  4458. string tid = GetPostString("ctid");
  4459. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4460. string shopname = GetPostString("shopname");
  4461. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4462. string buyernick = GetPostString("buyer_nick");
  4463. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4464. string customer = GetPostString("customer");
  4465. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4466. string design = GetPostString("design");
  4467. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4468. string sellermemo = GetPostString("seller_memo");
  4469. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4470. string logistics = GetPostString("logistics");
  4471. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4472. string date1 = GetPostString("date1");
  4473. string date2 = GetPostString("date2");
  4474. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4475. //if (dw.Length > 0) lw.Add(dw);
  4476. string placedate1 = GetPostString("placedate1");
  4477. string placedate2 = GetPostString("placedate2");
  4478. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4479. if (fdw.Length > 0) lw.Add(fdw);
  4480. string devdate1 = GetPostString("deliverydate1");
  4481. string devdate2 = GetPostString("deliverydate2");
  4482. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4483. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4484. string price1 = GetPostString("price1");
  4485. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4486. string price2 = GetPostString("price2");
  4487. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4488. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4489. {
  4490. if (tid.Length > 0)
  4491. lw.Add(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4492. if (buyernick.Length > 0)
  4493. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4494. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4495. if (dw.Length > 0) lw.Add(dw);
  4496. }
  4497. else
  4498. {
  4499. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4500. }
  4501. string posTag = CurrentUser.UserPost.Post.Code;
  4502. if (posTag == "Supplier")
  4503. {
  4504. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4505. }
  4506. else
  4507. {
  4508. string supplier = GetPostString("supplier");
  4509. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4510. }
  4511. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4512. lw.Add(string.Format("IsRefund!={0}", 2));
  4513. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4514. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4515. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4516. if (dt != null)
  4517. {
  4518. foreach (DataRow dr in dt.Rows)
  4519. {
  4520. 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();
  4521. }
  4522. }
  4523. writeGridDataTableJson(dStruct.TotalCount, dt);
  4524. }
  4525. public void get_erp_pdddeliveryed()
  4526. {
  4527. DataStruct dStruct = GetPostStruct();
  4528. List<string> lw = new List<string>();
  4529. string tid = GetPostString("ctid");
  4530. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4531. string shopname = GetPostString("shopname");
  4532. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4533. string buyernick = GetPostString("buyer_nick");
  4534. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4535. string customer = GetPostString("customer");
  4536. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4537. string design = GetPostString("design");
  4538. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4539. string sellermemo = GetPostString("seller_memo");
  4540. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4541. string logistics = GetPostString("logistics");
  4542. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4543. string date1 = GetPostString("date1");
  4544. string date2 = GetPostString("date2");
  4545. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4546. //if (dw.Length > 0) lw.Add(dw);
  4547. string placedate1 = GetPostString("placedate1");
  4548. string placedate2 = GetPostString("placedate2");
  4549. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4550. if (fdw.Length > 0) lw.Add(fdw);
  4551. string devdate1 = GetPostString("deliverydate1");
  4552. string devdate2 = GetPostString("deliverydate2");
  4553. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4554. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4555. string price1 = GetPostString("price1");
  4556. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4557. string price2 = GetPostString("price2");
  4558. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4559. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4560. {
  4561. if (tid.Length > 0)
  4562. lw.Add(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4563. if (buyernick.Length > 0)
  4564. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4565. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4566. if (dw.Length > 0) lw.Add(dw);
  4567. }
  4568. else
  4569. {
  4570. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4571. }
  4572. string posTag = CurrentUser.UserPost.Post.Code;
  4573. if (posTag == "Supplier")
  4574. {
  4575. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4576. }
  4577. else
  4578. {
  4579. string supplier = GetPostString("supplier");
  4580. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4581. }
  4582. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4583. lw.Add(string.Format("type = 'PDD' "));
  4584. lw.Add(string.Format("IsRefund!={0}", 2));
  4585. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4586. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4587. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4588. foreach (DataRow dr in dt.Rows)
  4589. {
  4590. 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();
  4591. }
  4592. writeGridDataTableJson(dStruct.TotalCount, dt);
  4593. }
  4594. public void get_erp_jddeliveryed()
  4595. {
  4596. DataStruct dStruct = GetPostStruct();
  4597. List<string> lw = new List<string>();
  4598. string tid = GetPostString("ctid");
  4599. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4600. string shopname = GetPostString("shopname");
  4601. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4602. string buyernick = GetPostString("buyer_nick");
  4603. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4604. string customer = GetPostString("customer");
  4605. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4606. string design = GetPostString("design");
  4607. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4608. string sellermemo = GetPostString("seller_memo");
  4609. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4610. string date1 = GetPostString("date1");
  4611. string date2 = GetPostString("date2");
  4612. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4613. //if (dw.Length > 0) lw.Add(dw);
  4614. string placedate1 = GetPostString("placedate1");
  4615. string placedate2 = GetPostString("placedate2");
  4616. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4617. if (fdw.Length > 0) lw.Add(fdw);
  4618. string devdate1 = GetPostString("deliverydate1");
  4619. string devdate2 = GetPostString("deliverydate2");
  4620. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4621. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4622. string price1 = GetPostString("price1");
  4623. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4624. string price2 = GetPostString("price2");
  4625. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4626. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4627. {
  4628. if (tid.Length > 0)
  4629. lw.Add(string.Format("ctid like '%{0}%'", tid));
  4630. if (buyernick.Length > 0)
  4631. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4632. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4633. if (dw.Length > 0) lw.Add(dw);
  4634. }
  4635. else
  4636. {
  4637. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4638. }
  4639. string posTag = CurrentUser.UserPost.Post.Code;
  4640. if (posTag == "Supplier")
  4641. {
  4642. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4643. }
  4644. else
  4645. {
  4646. string supplier = GetPostString("supplier");
  4647. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4648. }
  4649. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4650. lw.Add(string.Format("type = 'JD' "));
  4651. lw.Add(string.Format("IsRefund!={0}", 2));
  4652. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4653. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4654. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4655. foreach (DataRow dr in dt.Rows)
  4656. {
  4657. 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();
  4658. }
  4659. writeGridDataTableJson(dStruct.TotalCount, dt);
  4660. }
  4661. public void get_erp_allplacelist()
  4662. {
  4663. DataStruct dStruct = GetPostStruct();
  4664. List<string> lw = new List<string>();
  4665. string tid = GetPostString("ctid");
  4666. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  4667. string shopname = GetPostString("shopname");
  4668. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4669. string buyernick = GetPostString("buyer_nick");
  4670. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4671. string customer = GetPostString("customer");
  4672. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4673. string design = GetPostString("design");
  4674. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4675. string sellermemo = GetPostString("seller_memo");
  4676. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4677. string supplier = GetPostString("supplier");
  4678. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  4679. string date1 = GetPostString("date1");
  4680. string date2 = GetPostString("date2");
  4681. string pldate1 = GetPostString("placedate1");
  4682. string pldate2 = GetPostString("placedate2");
  4683. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4684. //if (dw.Length > 0) lw.Add(dw);
  4685. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  4686. {
  4687. if (tid.Length > 0)
  4688. lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", tid));
  4689. if (buyernick.Length > 0)
  4690. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4691. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4692. if (dw.Length > 0) lw.Add(dw);
  4693. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  4694. if (dw_place.Length > 0) lw.Add(dw_place);
  4695. }
  4696. else
  4697. {
  4698. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  4699. {
  4700. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4701. }
  4702. }
  4703. string price1 = GetPostString("price1");
  4704. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4705. string price2 = GetPostString("price2");
  4706. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4707. string posTag = CurrentUser.UserPost.Post.Code;
  4708. if (posTag == "Supplier")
  4709. {
  4710. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4711. }
  4712. lw.Add(string.Format("OrderState >= 6"));
  4713. lw.Add(string.Format("IsSample != 2 "));
  4714. lw.Add(string.Format("isDianziOrder = 0 "));
  4715. //lw.Add(string.Format("IsRefund<={0}", 1));
  4716. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4717. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4718. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  4719. foreach (DataRow dr in dt.Rows)
  4720. {
  4721. 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();
  4722. }
  4723. writeGridDataTableJson(dStruct.TotalCount, dt);
  4724. }
  4725. public void get_erp_financeallplacelist()
  4726. {
  4727. DataStruct dStruct = GetPostStruct();
  4728. List<string> lw = new List<string>();
  4729. string tid = GetPostString("ctid");
  4730. if (tid.Length > 0) lw.Add(string.Format("(ctid ='{0}' or orderSn ='{0}')", tid));
  4731. string shopname = GetPostString("shopname");
  4732. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4733. string buyernick = GetPostString("buyer_nick");
  4734. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4735. string customer = GetPostString("customer");
  4736. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4737. string design = GetPostString("design");
  4738. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4739. string sellermemo = GetPostString("seller_memo");
  4740. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4741. string supplier = GetPostString("supplier");
  4742. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4743. string date1 = GetPostString("date1");
  4744. string date2 = GetPostString("date2");
  4745. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4746. if (dw.Length > 0) lw.Add(dw);
  4747. string pldate1 = GetPostString("placedate1");
  4748. string pldate2 = GetPostString("placedate2");
  4749. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  4750. if (dw_place.Length > 0) lw.Add(dw_place);
  4751. string price1 = GetPostString("price1");
  4752. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4753. string price2 = GetPostString("price2");
  4754. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4755. string posTag = CurrentUser.UserPost.Post.Code;
  4756. if (posTag == "Supplier")
  4757. {
  4758. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4759. }
  4760. //lw.Add(string.Format("OrderState >= 6"));
  4761. lw.Add(string.Format("IsSample != 2 "));
  4762. lw.Add(string.Format("isDianziOrder = 0 "));
  4763. //lw.Add(string.Format("IsRefund<={0}", 1));
  4764. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4765. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4766. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  4767. foreach (DataRow dr in dt.Rows)
  4768. {
  4769. 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();
  4770. }
  4771. writeGridDataTableJson(dStruct.TotalCount, dt);
  4772. }
  4773. public void get_erp_expresslist()
  4774. {
  4775. int listtype = GetInt("ltype");
  4776. DataStruct dStruct = GetPostStruct();
  4777. List<string> lw = new List<string>();
  4778. string tid = GetPostString("tid");
  4779. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  4780. string outsid = GetPostString("out_sid");
  4781. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  4782. string importer = GetPostString("ImportUserName");
  4783. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  4784. string file = GetPostString("import_file");
  4785. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  4786. string printman = GetPostString("printman");
  4787. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  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 fdate1 = GetPostString("finishdate1");
  4793. string fdate2 = GetPostString("finishdate2");
  4794. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  4795. if (fdw.Length > 0) lw.Add(fdw);
  4796. string supplierId = GetPostString("supplierId");
  4797. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  4798. if (listtype == 1)
  4799. {
  4800. lw.Add(string.Format("importUserId !=0"));
  4801. }
  4802. string posTag = CurrentUser.UserPost.Post.Code;
  4803. if (posTag == "Supplier")
  4804. {
  4805. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4806. }
  4807. if (dStruct.PageSize != 100000)
  4808. {
  4809. dStruct.Order = "isMultiDelivery asc, import_time desc";
  4810. }
  4811. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4812. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  4813. writeGridDataTableJson(dStruct.TotalCount, dt);
  4814. }
  4815. public void set_erp_buchaorderdelivery()
  4816. {
  4817. if (UrlPostParmsCheck("ctid"))
  4818. {
  4819. string eid = GetPostString("ctid");
  4820. CeErpTradeCell entity = null;
  4821. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4822. if (entity != null)
  4823. {
  4824. if (entity.IsSample != 2)
  4825. {
  4826. returnErrorMsg("补差价单才能标记为已发货");
  4827. return;
  4828. }
  4829. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  4830. entity.OrderState = 7;
  4831. entity.Update();
  4832. returnSuccessMsg("操作成功!");
  4833. return;
  4834. }
  4835. returnErrorMsg("找不到记录");
  4836. }
  4837. }
  4838. public void get_stdtemplates()
  4839. {
  4840. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  4841. //string res = taobaoHelper.test();
  4842. string res = apiHelper.API_PrintTemplate();
  4843. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  4844. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  4845. {
  4846. int sidx = res.IndexOf("error_code");
  4847. int eidx = res.IndexOf("success");
  4848. string msg = res.Substring(sidx, eidx - sidx);
  4849. returnErrorMsg(msg);
  4850. return;
  4851. }
  4852. if (res.Length <= 0)
  4853. {
  4854. returnErrorMsg("模板数据为空!");
  4855. return;
  4856. }
  4857. ReturnSuccess(res);
  4858. }
  4859. public void cancel_print_order()
  4860. {
  4861. if (UrlPostParmsCheck("ctid"))
  4862. {
  4863. string ctid = GetPostString("ctid");
  4864. CeErpTradeCell entity = null;
  4865. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4866. if (entity != null)
  4867. {
  4868. string res = "";
  4869. string code = entity.LastBillWaybillCode;
  4870. if (code == "")
  4871. {
  4872. code = entity.OutSid;
  4873. }
  4874. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  4875. XLog.SaveLog(0, "取消面单" + res);
  4876. }
  4877. }
  4878. }
  4879. public void set_erp_printwaybill()
  4880. {
  4881. if (UrlPostParmsCheck("ctid"))
  4882. {
  4883. string ctid = GetPostString("ctid");
  4884. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  4885. string cpName = GetPostString("cpname");
  4886. string isTogether = GetPostString("together");
  4887. //var res_obj = new
  4888. //{
  4889. // restype = 1,
  4890. // 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\"}"
  4891. //};
  4892. //string ro_json = JsonConvert.SerializeObject(res_obj);
  4893. //ReturnSuccess(ro_json);
  4894. //return;
  4895. bool isUseLastWayBillCode = false;
  4896. CeErpTradeCell entity = null;
  4897. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4898. if (entity != null)
  4899. {
  4900. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  4901. {
  4902. isUseLastWayBillCode = true;
  4903. }
  4904. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  4905. {
  4906. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  4907. return;
  4908. }
  4909. }
  4910. string res = "";
  4911. Api_waybill_code_response_Obj fullObj = null;
  4912. string pData_str = "";
  4913. string curUseWayBillCode = "";
  4914. if (isUseLastWayBillCode == false)
  4915. {
  4916. res = apiHelper.API_GetWaybill(cpCode, ctid);
  4917. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  4918. if (res.IndexOf("failure") != -1)
  4919. {
  4920. //int idx = res.IndexOf("sub_message");
  4921. //int idx2 = res.IndexOf("flag");
  4922. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  4923. string errMsgNeed = commonHelper.KeepChinese(res);
  4924. var res_objd = new
  4925. {
  4926. restype = 0,
  4927. data = "获取面单失败" + errMsgNeed
  4928. };
  4929. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  4930. returnSuccess(ro_jsond);
  4931. if (res.IndexOf("停发") != -1)
  4932. {
  4933. entity.UnusualCon = "物流停发";
  4934. entity.Update();
  4935. }
  4936. //returnErrorMsg("获取面单失败,"+emsg);
  4937. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  4938. return;
  4939. }
  4940. else if (res.IndexOf("errorMsg") != -1)
  4941. {
  4942. //int idx = res.IndexOf("errorMsg");
  4943. //int idx2 = res.IndexOf("}]}");
  4944. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  4945. string errMsgNeed = commonHelper.KeepChinese(res);
  4946. var res_objf = new
  4947. {
  4948. restype = 0,
  4949. data = "获取面单失败2" + errMsgNeed
  4950. };
  4951. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  4952. if (res.IndexOf("停发") != -1)
  4953. {
  4954. entity.UnusualCon = "物流停发";
  4955. entity.Update();
  4956. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4957. if (trade != null)
  4958. {
  4959. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  4960. }
  4961. }
  4962. returnSuccess(ro_jsonf);
  4963. //returnErrorMsg("获取面单失败," + emsg);
  4964. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  4965. return;
  4966. }
  4967. try
  4968. {
  4969. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  4970. //res = res.Replace(" ", "");
  4971. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  4972. }
  4973. catch (Exception ex)
  4974. {
  4975. XLog.SaveLog(0, "生成fullObj" + res);
  4976. var res_objf = new
  4977. {
  4978. restype = 0,
  4979. data = "生成fullObj发生错误" + ex.Message
  4980. };
  4981. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  4982. returnSuccess(ro_jsonf);
  4983. return;
  4984. }
  4985. if (fullObj.response.data.content.Count > 0)
  4986. {
  4987. ContentItem codeObj = fullObj.response.data.content[0];
  4988. if (cpCode.IndexOf("SFFQ-") != -1)
  4989. {
  4990. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  4991. }
  4992. else
  4993. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  4994. curUseWayBillCode = codeObj.waybillCode;
  4995. }
  4996. else
  4997. {
  4998. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  4999. var res_objf = new
  5000. {
  5001. restype = 0,
  5002. data = "生成fullObj找不到快递单号waybillCode"
  5003. };
  5004. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5005. returnSuccess(ro_jsonf);
  5006. return;
  5007. }
  5008. }
  5009. else
  5010. {
  5011. //使用上次打印的快递单号
  5012. if (cpCode == "SFFQ-LY")
  5013. {
  5014. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5015. }
  5016. else
  5017. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5018. curUseWayBillCode = entity.LastBillWaybillCode;
  5019. }
  5020. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5021. {
  5022. var res_obje = new
  5023. {
  5024. restype = 0,
  5025. data = "获取加密打印数据失败"
  5026. };
  5027. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5028. returnSuccess(ro_jsone);
  5029. entity.LastBillCpCode = cpCode;
  5030. entity.LastBillWaybillCode = curUseWayBillCode;
  5031. entity.Update();
  5032. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5033. //returnErrorMsg("获取加密打印数据失败");
  5034. return;
  5035. }
  5036. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5037. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5038. string btnType = "";
  5039. if (entity != null)
  5040. {
  5041. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5042. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5043. //cpcode是 YTO-CAINIAO
  5044. //string comCode = cpCode.Split('-')[0].ToString();
  5045. string apires = "";
  5046. if (ctid.IndexOf("N") != -1)
  5047. {
  5048. apires = "发货成功";
  5049. }
  5050. else
  5051. {
  5052. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5053. }
  5054. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5055. //打单后发货
  5056. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5057. {
  5058. try
  5059. {
  5060. btnType = "待发货";
  5061. entity.OutSid = curUseWayBillCode;
  5062. entity.OrderState = 7;
  5063. entity.IsUrgency = false;
  5064. entity.LastBillCpCode = "";
  5065. entity.LastBillWaybillCode = "";
  5066. entity.FinishDeliveryTime = DateTime.Now;
  5067. entity.IsReturn = 0;
  5068. entity.MemoOpt = 0;
  5069. entity.Update();
  5070. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5071. //还要插入快递信息到 快递信息表
  5072. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5073. exinfo.tid = entity.ctid;
  5074. exinfo.out_sid = entity.OutSid;
  5075. exinfo.company_code = cpCode;
  5076. exinfo.company_name = cpName;
  5077. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5078. exinfo.deliveryType = "发货成功";
  5079. exinfo.print_time = DateTime.Now;
  5080. exinfo.printUser = CurrentUser.UserName;
  5081. exinfo.Create();
  5082. commonHelper.UpdateRelationOrder(entity.ctid);
  5083. CeErpSukuraData.createInfo(ctid, 4);
  5084. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5085. if (entity.SupplierId == 64)
  5086. {
  5087. commonHelper.sendCytExpress(exinfo);
  5088. }
  5089. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5090. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5091. if (isTogether == "1")
  5092. {
  5093. StringBuilder sqlsb = new StringBuilder();
  5094. sqlsb.AppendFormat("update ce_erptradecell with(rowlock) set OrderState=7,OutSid='{2}' where tid='{0}' and OrderState=6 and SupplierId={1}", entity.tid, entity.SupplierId, curUseWayBillCode);
  5095. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5096. }
  5097. }
  5098. catch (Exception ex)
  5099. {
  5100. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5101. }
  5102. }
  5103. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5104. {
  5105. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5106. if (entity.OrderState == 6)
  5107. {
  5108. entity.OrderState = 7;
  5109. }
  5110. entity.FinishDeliveryTime = DateTime.Now;
  5111. btnType = "已发货";
  5112. entity.Update();
  5113. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5114. exinfo.tid = entity.ctid;
  5115. exinfo.out_sid = entity.OutSid;
  5116. exinfo.company_code = cpCode;
  5117. exinfo.company_name = cpName;
  5118. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5119. exinfo.deliveryType = "发货成功";
  5120. exinfo.print_time = DateTime.Now;
  5121. exinfo.printUser = CurrentUser.UserName;
  5122. exinfo.Create();
  5123. commonHelper.UpdateRelationOrder(entity.ctid);
  5124. CeErpSukuraData.createInfo(entity.ctid, 4);
  5125. if (entity.SupplierId == 64)
  5126. {
  5127. commonHelper.sendCytExpress(exinfo);
  5128. }
  5129. if (isTogether == "1")
  5130. {
  5131. StringBuilder sqlsb = new StringBuilder();
  5132. sqlsb.AppendFormat("update ce_erptradecell with(rowlock) set OrderState=7,OutSid='{2}' where tid='{0}' and OrderState=6 and SupplierId={1}", entity.tid, entity.SupplierId, curUseWayBillCode);
  5133. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5134. }
  5135. //不处理
  5136. }
  5137. else
  5138. {
  5139. entity.LastBillCpCode = cpCode;
  5140. entity.LastBillWaybillCode = curUseWayBillCode;
  5141. entity.Update();
  5142. string errmsg = commonHelper.KeepChinese(apires);
  5143. var res_objz = new
  5144. {
  5145. restype = 0,
  5146. data = "打单后发货失败"
  5147. };
  5148. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5149. returnSuccess(ro_jsonz);
  5150. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5151. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5152. return;
  5153. }
  5154. }
  5155. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5156. var res_obj = new
  5157. {
  5158. restype = 1,
  5159. data = pData_str
  5160. };
  5161. string ro_json = JsonConvert.SerializeObject(res_obj);
  5162. ReturnSuccess(ro_json);
  5163. return;
  5164. }
  5165. }
  5166. private string GetUTF8String(byte[] vs)
  5167. {
  5168. throw new NotImplementedException();
  5169. }
  5170. public void set_erp_printwaybill_cn()
  5171. {
  5172. if (UrlPostParmsCheck("ctid"))
  5173. {
  5174. string ctid = GetPostString("ctid");
  5175. string cpCode = GetPostString("cpcode");
  5176. string cpName = GetPostString("cpname");
  5177. string tempUrl = GetPostString("tempurl");
  5178. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5179. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5180. //string res = taobaoHelper.test();
  5181. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5182. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5183. {
  5184. int sidx = res.IndexOf("errorMsg");
  5185. int eidx = res.IndexOf("}");
  5186. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5187. var res_objzxx = new
  5188. {
  5189. restype = 0,
  5190. data = msg
  5191. };
  5192. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5193. returnSuccess(ro_jsonzxx);
  5194. //returnErrorMsg(msg);
  5195. return;
  5196. }
  5197. int idx = res.IndexOf("waybillCode");
  5198. int idx2 = res.IndexOf("printData");
  5199. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5200. string eid = GetPostString("ctid");
  5201. CeErpTradeCell entity = null;
  5202. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5203. if (entity != null)
  5204. {
  5205. string osid = entity.OutSid;
  5206. entity.OutSid = osid + "," + outsid;
  5207. entity.FinishDeliveryTime = DateTime.Now;
  5208. entity.OrderState = 7;
  5209. entity.IsReturn = 0;
  5210. entity.Update();
  5211. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5212. exinfo.tid = entity.ctid;
  5213. exinfo.out_sid = outsid;
  5214. exinfo.company_code = cpCode;
  5215. exinfo.company_name = cpName;
  5216. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5217. exinfo.deliveryType = "发货成功";
  5218. exinfo.print_time = DateTime.Now;
  5219. exinfo.printUser = CurrentUser.UserName;
  5220. exinfo.Create();
  5221. if (entity.SupplierId == 64)
  5222. {
  5223. commonHelper.sendCytExpress(exinfo);
  5224. }
  5225. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5226. }
  5227. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5228. var res_objz = new
  5229. {
  5230. restype = 1,
  5231. data = res
  5232. };
  5233. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5234. returnSuccess(ro_jsonz);
  5235. //ReturnSuccess(res);
  5236. }
  5237. }
  5238. ////打单,打印面单 获取面单号
  5239. //public void set_erp_printwaybill()
  5240. //{
  5241. // if (UrlPostParmsCheck("ctid"))
  5242. // {
  5243. // string ctid = GetPostString("ctid");
  5244. // string cpCode = GetPostString("cpcode");
  5245. // string tempUrl = GetPostString("tempurl");
  5246. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5247. // //string res = taobaoHelper.test();
  5248. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5249. // if (res.IndexOf("error_response") != -1)
  5250. // {
  5251. // int sidx = res.IndexOf("sub_msg");
  5252. // int eidx = res.IndexOf("request_id");
  5253. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5254. // returnErrorMsg(msg);
  5255. // return;
  5256. // }
  5257. // int idx = res.IndexOf("waybill_code");
  5258. // int idx2 = res.IndexOf("}]}");
  5259. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5260. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5261. // ReturnSuccess(res);
  5262. // }
  5263. //}
  5264. public void cancel_erp_aftersale()
  5265. {
  5266. if (UrlPostParmsCheck("ctid"))
  5267. {
  5268. string eid = GetPostString("ctid");
  5269. CeErpTradeCell entity = null;
  5270. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5271. if (entity != null)
  5272. {
  5273. //有过处理的售后,取消也不能删除 售 字,保留
  5274. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5275. {
  5276. entity.AfterSaleState = 4;
  5277. }
  5278. else
  5279. entity.AfterSaleState = 0;
  5280. entity.Update();
  5281. returnSuccessMsg("操作成功!");
  5282. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5283. return;
  5284. }
  5285. returnErrorMsg("找不到订单记录");
  5286. }
  5287. }
  5288. public void get_erp_aftersalelist()
  5289. {
  5290. DataStruct dStruct = GetPostStruct();
  5291. List<string> lw = new List<string>();
  5292. int st = GetInt("st");
  5293. string tid = GetPostString("ctid");
  5294. if (st == 3)
  5295. {
  5296. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}'", tid));
  5297. }
  5298. else
  5299. {
  5300. if (tid.Length > 0) lw.Add(string.Format("(ctid = '{0}' or tid = '{0}' or orderSn = '{0}')", tid));
  5301. }
  5302. string shopname = GetPostString("shopname");
  5303. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5304. string buyernick = GetPostString("buyer_nick");
  5305. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5306. string sellermemo = GetPostString("seller_memo");
  5307. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5308. string orderState = GetPostString("orderState");
  5309. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5310. string afterState = GetPostString("afterstate");
  5311. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5312. string date1 = GetPostString("date1");
  5313. string date2 = GetPostString("date2");
  5314. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5315. if (dw.Length > 0) lw.Add(dw);
  5316. string price1 = GetPostString("price1");
  5317. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5318. string price2 = GetPostString("price2");
  5319. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5320. //lw.Add(string.Format("IsRefund!={0}", 1));
  5321. string reason = GetPostString("reason");
  5322. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5323. string method = GetPostString("method");
  5324. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5325. string handler = GetPostString("handler");
  5326. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5327. string handledate1 = GetPostString("handledate1");
  5328. string handledate2 = GetPostString("handledate2");
  5329. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5330. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5331. string finish1 = GetPostString("finishdate1");
  5332. string finish2 = GetPostString("finishdate2");
  5333. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5334. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5335. string afterdate1 = GetPostString("afterdate1");
  5336. string afterdate2 = GetPostString("afterdate2");
  5337. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5338. if (afterDate.Length > 0) lw.Add(afterDate);
  5339. string supplier = GetPostString("supplier");
  5340. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5341. string responsible = GetPostString("responsibleman");
  5342. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5343. string customer = GetPostString("customer");
  5344. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5345. string design = GetPostString("design");
  5346. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5347. string afterMemoType = GetPostString("aftermemotype");
  5348. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5349. string posCode = CurrentUser.UserPost.Post.Code;
  5350. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  5351. //{
  5352. // string vstate = GetPostString("vstate");
  5353. // if (vstate.Length > 0)
  5354. // {
  5355. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5356. // }
  5357. // if (posCode == "Supplier")
  5358. // {
  5359. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5360. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5361. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5362. // }
  5363. // else
  5364. // {
  5365. // lw.Add(string.Format("AfterSaleState = {0}", st));
  5366. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  5367. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  5368. // {
  5369. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  5370. // }
  5371. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  5372. // {
  5373. // int orgid = CurrentUser.UserPost.OrgID;
  5374. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  5375. // }
  5376. // else if (CurrentUser.UserPost.Post.Code == "Director")
  5377. // {
  5378. // string shopid = CurrentUser.User.pemShop;
  5379. // lw.Add(string.Format("shopId in ({0})", shopid));
  5380. // }
  5381. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5382. // //{
  5383. // // int org_id = CurrentUser.UserPost.OrgID;
  5384. // // lw.Add(string.Format("OrgID={0}", org_id));
  5385. // //}
  5386. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  5387. // }
  5388. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5389. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5390. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5391. //}
  5392. if (st == 5)
  5393. {
  5394. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  5395. {
  5396. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  5397. {
  5398. string shopid = CurrentUser.User.pemShop;
  5399. lw.Add(string.Format("shopId in ({0})", shopid));
  5400. }
  5401. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  5402. {
  5403. int mrOrgid = CurrentUser.UserPost.OrgID;
  5404. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  5405. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  5406. }
  5407. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  5408. //{
  5409. // int mrOrgid = CurrentUser.UserPost.OrgID;
  5410. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  5411. //}
  5412. else
  5413. {
  5414. string userIdStr = "";
  5415. if (posCode == "CustomerService")
  5416. {
  5417. userIdStr = CurrentUser.UserID + "_k";
  5418. }
  5419. else if (posCode == "Designer" || posCode == "wxDesigner")
  5420. {
  5421. userIdStr = CurrentUser.UserID + "_s";
  5422. }
  5423. else if (posCode == "Place")
  5424. {
  5425. userIdStr = CurrentUser.UserID + "_x";
  5426. }
  5427. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  5428. }
  5429. }
  5430. string placedate1 = GetPostString("placedate1");
  5431. string placedate2 = GetPostString("placedate2");
  5432. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5433. if (dwplace.Length > 0) lw.Add(dwplace);
  5434. string supState = GetPostString("supState");
  5435. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  5436. string searchType = GetPostString("searchType");
  5437. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  5438. {
  5439. lw.Add(string.Format("BackNum>1"));
  5440. }
  5441. lw.Add(string.Format("AfterSaleState>0"));
  5442. if (ex_psize > 0)
  5443. {
  5444. if (CurrentUser.UserPost.Post.Code == "Finance")
  5445. dStruct.Order = "pay_time desc";
  5446. else
  5447. dStruct.Order = "HandleTime desc";
  5448. }
  5449. else
  5450. dStruct.Order = "HandleTime desc";
  5451. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5452. DataTable dt = WebCache.GetData("view_test", dStruct);
  5453. writeGridDataTableJson(dStruct.TotalCount, dt);
  5454. }
  5455. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  5456. //{
  5457. // lw.Add(string.Format("AfterSaleState=4"));
  5458. // string code = CurrentUser.UserPost.Post.Code;
  5459. // if (code == "CustomerService")
  5460. // {
  5461. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  5462. // }
  5463. // else if (code == "Designer" || code == "DesignerMr")
  5464. // {
  5465. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  5466. // }
  5467. // else if (code == "Place" || code == "PlaceMr")
  5468. // {
  5469. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  5470. // }
  5471. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  5472. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5473. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5474. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5475. //}
  5476. //else //处理中的售后,待处理和处理中合并
  5477. //{
  5478. // if (afterState.Length <= 0)
  5479. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  5480. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  5481. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5482. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5483. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5484. //}
  5485. }
  5486. public void get_erp_disagreeftersalelist()
  5487. {
  5488. DataStruct dStruct = GetPostStruct();
  5489. List<string> lw = new List<string>();
  5490. int st = 2;
  5491. string tid = GetPostString("ctid");
  5492. if (tid.Length > 0) lw.Add(string.Format("(ctid = '{0}' or tid = '{0}' or orderSn = '{0}')", tid));
  5493. string shopname = GetPostString("shopname");
  5494. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5495. string buyernick = GetPostString("buyer_nick");
  5496. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5497. string sellermemo = GetPostString("seller_memo");
  5498. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5499. string orderState = GetPostString("orderState");
  5500. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  5501. string afterState = GetPostString("afterstate");
  5502. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5503. string date1 = GetPostString("date1");
  5504. string date2 = GetPostString("date2");
  5505. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5506. if (dw.Length > 0) lw.Add(dw);
  5507. string price1 = GetPostString("price1");
  5508. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5509. string price2 = GetPostString("price2");
  5510. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5511. //lw.Add(string.Format("IsRefund!={0}", 1));
  5512. string reason = GetPostString("reason");
  5513. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5514. string method = GetPostString("method");
  5515. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5516. string handler = GetPostString("handler");
  5517. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5518. string handledate1 = GetPostString("handledate1");
  5519. string handledate2 = GetPostString("handledate2");
  5520. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5521. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5522. string afterdate1 = GetPostString("afterdate1");
  5523. string afterdate2 = GetPostString("afterdate2");
  5524. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5525. if (afterDate.Length > 0) lw.Add(afterDate);
  5526. string backdate1 = GetPostString("backdate1");
  5527. string backdate2 = GetPostString("backdate2");
  5528. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  5529. if (backDate.Length > 0) lw.Add(backDate);
  5530. string supplier = GetPostString("supplier");
  5531. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5532. string responsible = GetPostString("responsibleman");
  5533. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5534. string customer = GetPostString("customer");
  5535. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5536. string design = GetPostString("design");
  5537. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5538. string afterSaleMemo = GetPostString("afterSaleMemo");
  5539. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  5540. string afterMemoType = GetPostString("aftermemotype");
  5541. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5542. string aftersakereason = GetPostString("aftersakereason");
  5543. if (aftersakereason.Length > 0)
  5544. {
  5545. if (aftersakereason == "1")
  5546. {
  5547. lw.Add(string.Format("AfterSaleResSupId > 0"));
  5548. }
  5549. if (aftersakereason == "2")
  5550. {
  5551. lw.Add(string.Format("AfterSaleResSupId = 0"));
  5552. }
  5553. }
  5554. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  5555. string poscode = CurrentUser.UserPost.Post.Code;
  5556. if (poscode != "SysAdmin")
  5557. {
  5558. string shopid = CurrentUser.User.pemShop;
  5559. lw.Add(string.Format("shopId in ({0})", shopid));
  5560. }
  5561. string searchType = GetPostString("searchType");
  5562. if (searchType == "wait")
  5563. {
  5564. lw.Add(string.Format("HandleTime is null"));
  5565. }
  5566. if (searchType == "handling")
  5567. {
  5568. lw.Add(string.Format("HandleTime is not null "));
  5569. }
  5570. if (searchType == "back" || searchType == "puBack")
  5571. {
  5572. lw.Add(string.Format("AfterSaleBackReason != ''"));
  5573. }
  5574. if (searchType == "reBack")
  5575. {
  5576. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  5577. }
  5578. if (searchType == "moreBack")
  5579. {
  5580. lw.Add(string.Format("backNum > 1"));
  5581. }
  5582. lw.Add(string.Format("(AfterSaleState=5)"));
  5583. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  5584. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5585. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  5586. writeGridDataTableJson(dStruct.TotalCount, dt);
  5587. }
  5588. public void get_erp_handlingaftersalelist()
  5589. {
  5590. DataStruct dStruct = GetPostStruct();
  5591. List<string> lw = new List<string>();
  5592. int st = 2;
  5593. string tid = GetPostString("ctid");
  5594. if (tid.Length > 0) lw.Add(string.Format("(ctid = '{0}' or tid = '{0}' or orderSn = '{0}')", tid));
  5595. string shopname = GetPostString("shopname");
  5596. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5597. string buyernick = GetPostString("buyer_nick");
  5598. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5599. string sellermemo = GetPostString("seller_memo");
  5600. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5601. string orderState = GetPostString("orderState");
  5602. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  5603. string afterState = GetPostString("afterstate");
  5604. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5605. string date1 = GetPostString("date1");
  5606. string date2 = GetPostString("date2");
  5607. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5608. if (dw.Length > 0) lw.Add(dw);
  5609. string price1 = GetPostString("price1");
  5610. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5611. string price2 = GetPostString("price2");
  5612. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5613. //lw.Add(string.Format("IsRefund!={0}", 1));
  5614. string reason = GetPostString("reason");
  5615. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5616. string method = GetPostString("method");
  5617. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5618. string handler = GetPostString("handler");
  5619. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5620. string handledate1 = GetPostString("handledate1");
  5621. string handledate2 = GetPostString("handledate2");
  5622. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5623. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5624. string afterdate1 = GetPostString("afterdate1");
  5625. string afterdate2 = GetPostString("afterdate2");
  5626. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5627. if (afterDate.Length > 0) lw.Add(afterDate);
  5628. string supplier = GetPostString("supplier");
  5629. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5630. string responsible = GetPostString("responsibleman");
  5631. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5632. string customer = GetPostString("customer");
  5633. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5634. string design = GetPostString("design");
  5635. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5636. string afterSaleMemo = GetPostString("afterSaleMemo");
  5637. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  5638. string afterMemoType = GetPostString("aftermemotype");
  5639. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5640. string afterresult = GetPostString("afterresult");
  5641. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  5642. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  5643. string poscode = CurrentUser.UserPost.Post.Code;
  5644. if (poscode != "SysAdmin")
  5645. {
  5646. string shopid = CurrentUser.User.pemShop;
  5647. lw.Add(string.Format("shopId in ({0})", shopid));
  5648. }
  5649. string searchType = GetPostString("searchType");
  5650. if (searchType == "wait")
  5651. {
  5652. lw.Add(string.Format("HandleTime is null"));
  5653. }
  5654. if (searchType == "documentary")
  5655. {
  5656. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  5657. }
  5658. if (searchType == "handling")
  5659. {
  5660. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  5661. }
  5662. if (searchType == "back" || searchType == "puBack")
  5663. {
  5664. lw.Add(string.Format("AfterSaleBackReason != ''"));
  5665. }
  5666. if (searchType == "reBack")
  5667. {
  5668. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  5669. }
  5670. if (afterState.Length <= 0)
  5671. {
  5672. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  5673. }
  5674. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  5675. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5676. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  5677. writeGridDataTableJson(dStruct.TotalCount, dt);
  5678. }
  5679. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  5680. //public void get_erp_back_handlingaftersalelist()
  5681. //{
  5682. // DataStruct dStruct = GetPostStruct();
  5683. // List<string> lw = new List<string>();
  5684. // string tid = GetPostString("ctid");
  5685. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5686. // string shopname = GetPostString("shopname");
  5687. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5688. // string buyernick = GetPostString("buyer_nick");
  5689. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5690. // string sellermemo = GetPostString("seller_memo");
  5691. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5692. // string orderState = GetPostString("orderState");
  5693. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  5694. // string afterState = GetPostString("afterstate");
  5695. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5696. // string date1 = GetPostString("date1");
  5697. // string date2 = GetPostString("date2");
  5698. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5699. // if (dw.Length > 0) lw.Add(dw);
  5700. // string price1 = GetPostString("price1");
  5701. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5702. // string price2 = GetPostString("price2");
  5703. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5704. // //lw.Add(string.Format("IsRefund!={0}", 1));
  5705. // string reason = GetPostString("reason");
  5706. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5707. // string method = GetPostString("method");
  5708. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5709. // string handler = GetPostString("handler");
  5710. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5711. // string handledate1 = GetPostString("handledate1");
  5712. // string handledate2 = GetPostString("handledate2");
  5713. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5714. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5715. // string afterdate1 = GetPostString("afterdate1");
  5716. // string afterdate2 = GetPostString("afterdate2");
  5717. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5718. // if (afterDate.Length > 0) lw.Add(afterDate);
  5719. // string supplier = GetPostString("supplier");
  5720. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5721. // string responsible = GetPostString("responsibleman");
  5722. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5723. // string customer = GetPostString("customer");
  5724. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5725. // string design = GetPostString("design");
  5726. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5727. // string afterMemoType = GetPostString("aftermemotype");
  5728. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5729. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  5730. // if (afterState.Length <= 0)
  5731. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  5732. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  5733. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5734. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5735. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5736. //}
  5737. public void get_erp_aftersaleverifylist()
  5738. {
  5739. DataStruct dStruct = GetPostStruct();
  5740. List<string> lw = new List<string>();
  5741. string tid = GetPostString("ctid");
  5742. if (tid.Length > 0) lw.Add(string.Format("(tid like '%{0}%' or orderSn like '%{0}%')", tid));
  5743. string shopname = GetPostString("shopname");
  5744. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5745. string buyernick = GetPostString("buyer_nick");
  5746. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5747. string sellermemo = GetPostString("seller_memo");
  5748. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5749. string orderState = GetPostString("orderState");
  5750. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  5751. //lw.Add(string.Format("IsRefund!={0}", 1));
  5752. string reason = GetPostString("reason");
  5753. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5754. string method = GetPostString("method");
  5755. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5756. string handler = GetPostString("handler");
  5757. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5758. string handledate1 = GetPostString("handledate1");
  5759. string handledate2 = GetPostString("handledate2");
  5760. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5761. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5762. string finish1 = GetPostString("finishdate1");
  5763. string finish2 = GetPostString("finishdate2");
  5764. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5765. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5766. string supplier = GetPostString("supplier");
  5767. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5768. string responsible = GetPostString("responsibleman");
  5769. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5770. string posCode = CurrentUser.UserPost.Post.Code;
  5771. string vstate = GetPostString("vstate");
  5772. if (vstate.Length > 0)
  5773. {
  5774. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5775. }
  5776. if (posCode == "Supplier")
  5777. {
  5778. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5779. lw.Add(string.Format("VerifyState = 0"));
  5780. lw.Add("type = 1");
  5781. lw.Add(string.Format("AfterSaleState={0}", 3));
  5782. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5783. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  5784. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5785. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5786. writeGridDataTableJson(dStruct.TotalCount, dt);
  5787. }
  5788. else if (posCode == "logistics")
  5789. {
  5790. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  5791. lw.Add(string.Format("VerifyState = 0"));
  5792. lw.Add("type = 2");
  5793. lw.Add(string.Format("AfterSaleState={0}", 3));
  5794. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  5795. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5796. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5797. writeGridDataTableJson(dStruct.TotalCount, dt);
  5798. }
  5799. else
  5800. {
  5801. lw.Add(string.Format("(AfterSaleState = 3)"));
  5802. string reasonState = GetPostString("reasonState");
  5803. lw.Add("type = 0");
  5804. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  5805. || posCode == "Summarize" || posCode == "Finance")
  5806. {
  5807. if (reasonState == "2")
  5808. {
  5809. lw.Add("VerifyState = 3");
  5810. }
  5811. else if (reasonState == "1")
  5812. {
  5813. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  5814. }
  5815. else
  5816. {
  5817. lw.Add("VerifyState in (0,3)");
  5818. }
  5819. //不加条件,可以看全部
  5820. }
  5821. 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")
  5822. {
  5823. int orgid = CurrentUser.UserPost.OrgID;
  5824. string manageOrgId = CurrentUser.User.ManageOrgIds;
  5825. if (string.IsNullOrEmpty(manageOrgId))
  5826. {
  5827. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  5828. }
  5829. else
  5830. {
  5831. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  5832. }
  5833. if (reasonState == "1")
  5834. {
  5835. lw.Add("VerifyState = 3");
  5836. }
  5837. else if (reasonState == "2")
  5838. {
  5839. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  5840. }
  5841. else
  5842. {
  5843. }
  5844. }
  5845. else
  5846. {
  5847. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  5848. }
  5849. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5850. //{
  5851. // int org_id = CurrentUser.UserPost.OrgID;
  5852. // lw.Add(string.Format("OrgID={0}", org_id));
  5853. //}
  5854. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  5855. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5856. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5857. writeGridDataTableJson(dStruct.TotalCount, dt);
  5858. }
  5859. }
  5860. public void get_erp_finishaftersalelist()
  5861. {
  5862. DataStruct dStruct = GetPostStruct();
  5863. List<string> lw = new List<string>();
  5864. int st = 4;
  5865. string tid = GetPostString("ctid");
  5866. if (tid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", tid));
  5867. string shopname = GetPostString("shopname");
  5868. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5869. //lw.Add(string.Format("IsRefund!={0}", 1));
  5870. string reason = GetPostString("reason");
  5871. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5872. string method = GetPostString("method");
  5873. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5874. string buyernick = GetPostString("buyer_nick");
  5875. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5876. string handler = GetPostString("handler");
  5877. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5878. string handledate1 = GetPostString("handledate1");
  5879. string handledate2 = GetPostString("handledate2");
  5880. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5881. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5882. string finish1 = GetPostString("finishdate1");
  5883. string finish2 = GetPostString("finishdate2");
  5884. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5885. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5886. string supplier = GetPostString("supplier");
  5887. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5888. string responsible = GetPostString("responsibleman");
  5889. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5890. string vstate = GetPostString("vstate");
  5891. if (vstate.Length > 0)
  5892. {
  5893. if ("3".Equals(vstate))
  5894. {
  5895. lw.Add(string.Format("IsTem=1"));
  5896. }
  5897. else
  5898. {
  5899. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5900. }
  5901. }
  5902. lw.Add(string.Format("AfterSaleState=4"));
  5903. string code = CurrentUser.UserPost.Post.Code;
  5904. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  5905. {
  5906. //不加条件,可以看全部
  5907. }
  5908. else if (code == "Supplier")
  5909. {
  5910. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5911. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5912. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5913. }
  5914. else if (code == "logistics")
  5915. {
  5916. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  5917. lw.Add("type = 2");
  5918. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5919. }
  5920. 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")
  5921. {
  5922. int orgid = CurrentUser.UserPost.OrgID;
  5923. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  5924. if (string.IsNullOrEmpty(manageOrgIds))
  5925. {
  5926. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  5927. }
  5928. else
  5929. {
  5930. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  5931. }
  5932. }
  5933. else
  5934. {
  5935. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  5936. }
  5937. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  5938. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5939. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5940. writeGridDataTableJson(dStruct.TotalCount, dt);
  5941. }
  5942. public void handle_erp_aftersale()
  5943. {
  5944. if (UrlPostParmsCheck("ctid"))
  5945. {
  5946. string eid = GetPostString("ctid");
  5947. string responStr = GetPostString("AfterSaleResponsible");
  5948. if (responStr.Length <= 0)
  5949. {
  5950. returnErrorMsg("售后责任人不能为空");
  5951. return;
  5952. }
  5953. bool isDesign = false;
  5954. double designFree = 0.00;
  5955. int responsibleId = 0;
  5956. CeErpTradeCell entity = null;
  5957. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5958. if (entity != null)
  5959. {
  5960. int isNeedNewOrder = GetPostInt("IsNewOrder");
  5961. string afterMethod = GetPostString("AfterSaleMethod");
  5962. if (isNeedNewOrder == 1)
  5963. {
  5964. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  5965. bool ishav = true;
  5966. if (newentity == null)
  5967. {
  5968. newentity = entity.Clone() as CeErpTradeCell;
  5969. ishav = false;
  5970. newentity.ctid = "S_" + entity.ctid;
  5971. newentity.OrderState = 0;
  5972. }
  5973. //唯一标识
  5974. newentity.OrderSn = newentity.ctid;
  5975. /* string orderSn = dataHelper.getSaleOrderSn();
  5976. if (orderSn != "")
  5977. {
  5978. newentity.OrderSn = orderSn;
  5979. }*/
  5980. newentity.AfterSaleState = 0;
  5981. newentity.AfterSaleMethod = afterMethod;
  5982. if (!ishav)
  5983. {
  5984. string memo_str = newentity.seller_memo;
  5985. memo_str = memo_str.Replace("(", "(");
  5986. memo_str = memo_str.Replace(")", ")");
  5987. int sIndex = memo_str.IndexOf("(");
  5988. int eIndex = memo_str.IndexOf(")");
  5989. if (sIndex == -1 || eIndex == -1)
  5990. {
  5991. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  5992. return;
  5993. }
  5994. string first = memo_str.Substring(0, sIndex + 1);
  5995. string memoCtid = newentity.OrderSn;
  5996. //if (memoCtid.IndexOf("C") != -1)
  5997. //{
  5998. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  5999. //if (CIdx.IndexOf("+") != -1)
  6000. //{
  6001. //CIdx = "C" + CIdx.Split('+')[1];
  6002. //}
  6003. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6004. //}
  6005. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6006. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6007. string newMemo = first + memoCtid + last;
  6008. newentity.seller_memo = newMemo;
  6009. newentity.FinishPlaceTime = null;
  6010. newentity.UnusualTag = 0;
  6011. newentity.UnusualCon = "";
  6012. newentity.UnusualTime = null;
  6013. newentity.AfterSaleMemo = "";
  6014. newentity.AfterSaleMethod = afterMethod;
  6015. newentity.AfterSalePreTime = null;
  6016. newentity.AfterSaleReason = "";
  6017. newentity.AfterSaleResponsible = "";
  6018. newentity.AfterSaleState = 0;
  6019. newentity.AfterSaleTime = null;
  6020. newentity.AfterSaleUserId = 0;
  6021. newentity.AfterSaleSupplierState = 0;
  6022. newentity.LastBillWaybillCode = "";
  6023. newentity.LastBillCpCode = "";
  6024. newentity.FinishAfterSaleTime = null;
  6025. newentity.HandleTime = null;
  6026. newentity.IsSF = 0;
  6027. newentity.IsOldCustomer = 0;
  6028. newentity.UrgencyTime = null;
  6029. newentity.ResponsibleUserId = "";
  6030. newentity.IsVerifyToSupplier = false;
  6031. newentity.payment = 0;
  6032. newentity.CheckMemo = "";
  6033. newentity.OutSid = "";
  6034. newentity.CheckOrderTime = null;
  6035. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6036. }
  6037. newentity.isAfterSaleOrder = 1;
  6038. newentity.IsRefund = 0;
  6039. string receiveMobile = GetPostString("receiver_mobile");
  6040. if (receiveMobile.Length > 0)
  6041. {
  6042. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6043. if (trade != null)
  6044. {
  6045. trade.receiver_name = GetPostString("receiver_name");
  6046. trade.receiver_mobile = receiveMobile;
  6047. trade.receiver_state = GetPostString("receiver_state");
  6048. trade.receiver_city = GetPostString("receiver_city");
  6049. trade.receiver_district = GetPostString("receiver_district");
  6050. trade.receiver_address = GetPostString("receiver_address");
  6051. newentity.IsOffLineOrder = 1;
  6052. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6053. }
  6054. }
  6055. string st = GetPostString("ToState");
  6056. if (st.Length > 0)
  6057. {
  6058. if (newentity.OrderState <= 3)
  6059. {
  6060. newentity.WaitDesignTime = DateTime.Now;
  6061. newentity.StartDesignTime = null;
  6062. newentity.FinishDesignTime = null;
  6063. newentity.OrderState = 3;
  6064. if (st == "下单员")
  6065. {
  6066. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6067. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6068. {
  6069. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6070. }
  6071. }
  6072. else
  6073. {
  6074. newentity.WaitDesignTime = DateTime.Now;
  6075. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6076. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6077. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6078. {
  6079. DataRow user = dt1.Rows[0];
  6080. //找主管
  6081. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6082. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6083. if (dt != null && dt.Rows.Count > 0)
  6084. {
  6085. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6086. newentity.DesignUserId = designMr;
  6087. string key = "aftersale_order_" + designMr;
  6088. if (RedisHelper.HasKey(key))
  6089. {
  6090. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6091. list.Add(newentity.ctid);
  6092. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6093. }
  6094. }
  6095. //账号正常
  6096. if (user["State"].ToString() == "0")
  6097. {
  6098. newentity.DesignUserId = entity.DesignUserId;
  6099. string key = "aftersale_order_" + entity.DesignUserId;
  6100. if (RedisHelper.HasKey(key))
  6101. {
  6102. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6103. list.Add(newentity.ctid);
  6104. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6105. }
  6106. }
  6107. }
  6108. }
  6109. }
  6110. if (entity.IsXianHuo == 1)
  6111. {
  6112. newentity.OrderState = 6;
  6113. entity.FinishPlaceTime = DateTime.Now;
  6114. }
  6115. }
  6116. if (ishav)
  6117. {
  6118. newentity.Update();
  6119. }
  6120. else
  6121. {
  6122. newentity.Create();
  6123. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6124. newCellExtend.ctid = newentity.ctid;
  6125. newCellExtend.orderFrom = 20;
  6126. newCellExtend.orderType = 30;
  6127. if (st == "下单员")
  6128. {
  6129. }
  6130. else
  6131. {
  6132. newCellExtend.ReprintTime = DateTime.Now;
  6133. }
  6134. newCellExtend.Create();
  6135. }
  6136. if (st != "下单员")
  6137. {
  6138. designHelper.API_GetPrintData_CreateOrder(newentity);
  6139. }
  6140. }
  6141. //处理售后扩展
  6142. string resIdStr = GetPostString("ResponsibleUserId");
  6143. string refundFees = GetPostString("refundFrees");
  6144. int IsComplain = GetPostInt("isComplain");
  6145. int IsBad = GetPostInt("isBad");
  6146. string IsOriginal = GetPostString("isOriginal");
  6147. double diffResultPrice = GetPostDouble("diffResultPrice");
  6148. string textResult = GetPostString("textResult");
  6149. string supplierResponsible = GetPostString("supplierResponsible");
  6150. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6151. if (ceErpTradeAfterSaleExtend == null)
  6152. {
  6153. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6154. ceErpTradeAfterSaleExtend.tid = eid;
  6155. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6156. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6157. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6158. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6159. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6160. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6161. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6162. ceErpTradeAfterSaleExtend.Create();
  6163. }
  6164. else
  6165. {
  6166. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6167. {
  6168. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6169. }
  6170. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6171. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6172. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6173. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6174. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6175. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6176. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6177. ceErpTradeAfterSaleExtend.Update();
  6178. }
  6179. int gysid = GetPostInt("ResponsibleSupId");
  6180. if (entity.AfterSaleUserId == 0)
  6181. {
  6182. entity.AfterSaleUserId = CurrentUser.UserID;
  6183. }
  6184. entity.ResponsibleUserId = resIdStr;
  6185. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6186. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6187. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6188. {
  6189. CeErpTradeResponsible.DelByTid(eid, -1);
  6190. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6191. int backNum = 0;
  6192. if (number != null)
  6193. {
  6194. backNum = number.BackNum;
  6195. }
  6196. char[] separator = { ',' };
  6197. string[] sArray = resIdStr.Split(separator);
  6198. string[] refundFreeList = { };
  6199. if (refundFees.Length > 0)
  6200. {
  6201. refundFreeList = refundFees.Split(separator);
  6202. }
  6203. int index = -1;
  6204. foreach (string i in sArray)
  6205. {
  6206. index++;
  6207. if (i.Length <= 0) continue;
  6208. char[] separator2 = { '_' };
  6209. string idstr = i.Split(separator2)[0];
  6210. string idtype = i.Split(separator2)[1];
  6211. double refudFree = 0;
  6212. if (refundFreeList.Length > 0)
  6213. {
  6214. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6215. }
  6216. if (idtype == "s")
  6217. {
  6218. isDesign = true;
  6219. designFree = refudFree;
  6220. }
  6221. int userId = Convert.ToInt32(idstr);
  6222. int type = 0;
  6223. if (idtype == "g")
  6224. {
  6225. type = 1;
  6226. }
  6227. if (idtype == "w")
  6228. {
  6229. type = 2;
  6230. }
  6231. if (idtype == "t")
  6232. {
  6233. type = 3;
  6234. }
  6235. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6236. if (ceErpTradeResponsible == null)
  6237. {
  6238. ceErpTradeResponsible = new CeErpTradeResponsible();
  6239. ceErpTradeResponsible.tid = eid;
  6240. ceErpTradeResponsible.UserId = userId;
  6241. ceErpTradeResponsible.createdTime = DateTime.Now;
  6242. ceErpTradeResponsible.type = type;
  6243. if (type == 1)
  6244. {
  6245. ceErpTradeResponsible.IsSup = 1;
  6246. }
  6247. if (type == 2)
  6248. {
  6249. ceErpTradeResponsible.IsFlow = 1;
  6250. }
  6251. }
  6252. ceErpTradeResponsible.RefundFee = refudFree;
  6253. ceErpTradeResponsible.VerifyState = 0;
  6254. if (userId == 2125 || idtype == "w")
  6255. {
  6256. ceErpTradeResponsible.VerifyState = 1;
  6257. }
  6258. if (idtype == "w" && userId == 101)
  6259. {
  6260. ceErpTradeResponsible.VerifyState = 0;
  6261. }
  6262. if (ceErpTradeResponsible.ID > 0)
  6263. {
  6264. ceErpTradeResponsible.Update();
  6265. }
  6266. else
  6267. {
  6268. ceErpTradeResponsible.Create();
  6269. }
  6270. if (isDesign)
  6271. {
  6272. responsibleId = ceErpTradeResponsible.ID;
  6273. }
  6274. }
  6275. CeErpTradeResponsible.NumByTid(backNum, eid);
  6276. }
  6277. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6278. if (ceErpTradeCellExtend != null)
  6279. {
  6280. ceErpTradeCellExtend.returnVisit = 0;
  6281. ceErpTradeCellExtend.Update();
  6282. }
  6283. if (entity.HandleTime != null)
  6284. {
  6285. if (entity.AfterSaleState == 1)
  6286. {
  6287. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6288. }
  6289. else
  6290. {
  6291. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6292. }
  6293. }
  6294. else
  6295. {
  6296. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6297. entity.HandleTime = DateTime.Now;
  6298. }
  6299. bool isCompale = false;
  6300. if (entity.AfterSaleState == 5)
  6301. {
  6302. isCompale = true;
  6303. entity.AfterSaleState = 3;
  6304. }
  6305. entity.AfterSaleSupplierState = 0;
  6306. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6307. {
  6308. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6309. }
  6310. string sImgs = GetPostString("img");
  6311. entity.AfterSaleSupplierImg = sImgs;
  6312. entity.supRefundType = GetPostString("supRefundType");
  6313. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6314. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6315. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6316. entity.AfterSaleMemoType = GetPostString("MemoType");
  6317. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6318. {
  6319. //entity.AfterSaleSupplierState = 2;
  6320. }
  6321. string df = GetPostString("DeductFee");
  6322. if (df == "")
  6323. {
  6324. df = "0";
  6325. }
  6326. string rf = GetPostString("RefundFee");
  6327. if (rf == "")
  6328. {
  6329. rf = "0";
  6330. }
  6331. string pm = GetPostString("AfterSalePayment");
  6332. if (pm == "")
  6333. {
  6334. pm = "0";
  6335. }
  6336. entity.AfterSalePayment = Convert.ToDouble(pm);
  6337. entity.DeductFee = Convert.ToDouble(df);
  6338. entity.RefundFee = Convert.ToDouble(rf);
  6339. entity.Update();
  6340. string toState = GetPostString("ToState");
  6341. string original = GetPostString("isOriginal");
  6342. ApiVo apiVo = new ApiVo();
  6343. apiVo.orderNumber = entity.ctid;
  6344. apiVo.actionName = "afterDesign";
  6345. apiVo.orderRemarks = entity.AfterSaleMethod;
  6346. apiVo.reasonRemarks = entity.AfterSaleReason;
  6347. apiVo.isDesign = isDesign;
  6348. apiVo.designFree = designFree;
  6349. apiVo.responsibleId = responsibleId;
  6350. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6351. if (toState == "设计师")
  6352. {
  6353. apiVo.isOriginal = Convert.ToBoolean(original);
  6354. }
  6355. designHelper.API_WorkCore(apiVo);//afterDesign
  6356. CeErpMethod methodSql = new CeErpMethod();
  6357. methodSql.con = entity.AfterSaleMethod;
  6358. methodSql.addTime = DateTime.Now;
  6359. methodSql.Create();
  6360. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  6361. CeErpMethod.ExecuteNonQuery(delsql);
  6362. if (isCompale)
  6363. {
  6364. aftersale_data_change(entity.ctid);
  6365. }
  6366. returnSuccessMsg("操作成功!");
  6367. return;
  6368. }
  6369. returnErrorMsg("找不到订单记录");
  6370. }
  6371. }
  6372. public void ins_erp_toresponsible()
  6373. {
  6374. if (UrlPostParmsCheck("ctid"))
  6375. {
  6376. string eid = GetPostString("ctid");
  6377. CeErpTradeCell entity = null;
  6378. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6379. if (entity != null)
  6380. {
  6381. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  6382. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  6383. {
  6384. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  6385. return;
  6386. }
  6387. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  6388. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  6389. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  6390. if (entity.AfterSalePreTime == null)
  6391. {
  6392. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  6393. {
  6394. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  6395. }
  6396. }
  6397. entity.AfterSalePreTime = DateTime.Now;
  6398. //预完成给售后主管审核客户问题直接完成
  6399. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  6400. {
  6401. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  6402. {
  6403. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  6404. }
  6405. }
  6406. ceErpTradeAfterSaleExtend.Update();
  6407. entity.AfterSaleState = 2;
  6408. entity.Update();
  6409. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  6410. aftersale_data_change(entity.ctid);
  6411. returnSuccessMsg("操作成功!");
  6412. return;
  6413. }
  6414. returnErrorMsg("找不到订单记录");
  6415. }
  6416. }
  6417. public void cancel_erp_aftersaleanddelnew()
  6418. {
  6419. if (UrlPostParmsCheck("ctid"))
  6420. {
  6421. string eid = GetPostString("ctid");
  6422. CeErpTradeCell entity = null;
  6423. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6424. if (entity != null)
  6425. {
  6426. entity.AfterSaleState = 0;
  6427. entity.AfterSaleReason = "";
  6428. entity.AfterSaleMethod = "";
  6429. entity.AfterSaleMemo = "";
  6430. entity.AfterSaleResponsible = "";
  6431. entity.ResponsibleUserId = "";
  6432. entity.DeductFee = 0;
  6433. entity.RefundFee = 0;
  6434. entity.IsArbitrate = 0;
  6435. CeErpTradeResponsible.DelByTid(eid, -1);
  6436. entity.Update();
  6437. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  6438. if (after != null)
  6439. {
  6440. if (after.OrderState < 5)
  6441. CeErpTradeCell.DelByCtid("S_" + eid);
  6442. }
  6443. returnSuccessMsg("操作成功!");
  6444. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  6445. return;
  6446. }
  6447. returnErrorMsg("找不到订单记录");
  6448. }
  6449. }
  6450. public void get_erp_aftersale_pregather()
  6451. {
  6452. List<string> lw = new List<string>();
  6453. int st = GetInt("st");
  6454. string tid = GetPostString("ctid");
  6455. if (tid.Length > 0) lw.Add(string.Format("(tid = '{0}' or ctid = '{0}' or orderSn = '{0}')", tid));
  6456. string shopname = GetPostString("shopname");
  6457. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6458. string buyernick = GetPostString("buyer_nick");
  6459. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6460. string sellermemo = GetPostString("seller_memo");
  6461. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6462. string orderState = GetPostString("orderState");
  6463. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6464. string reason = GetPostString("reason");
  6465. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6466. string method = GetPostString("method");
  6467. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6468. string handler = GetPostString("handler");
  6469. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6470. string handledate1 = GetPostString("handledate1");
  6471. string handledate2 = GetPostString("handledate2");
  6472. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6473. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6474. string supplier = GetPostString("supplier");
  6475. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6476. string responsible = GetPostString("responsibleman");
  6477. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6478. string customer = GetPostString("customer");
  6479. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6480. string design = GetPostString("design");
  6481. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6482. string afterMemoType = GetPostString("aftermemotype");
  6483. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6484. string afterSaleMemo = GetPostString("afterSaleMemo");
  6485. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6486. string afterresult = GetPostString("afterresult");
  6487. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  6488. string poscode = CurrentUser.UserPost.Post.Code;
  6489. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  6490. {
  6491. string shopid = CurrentUser.User.pemShop;
  6492. lw.Add(string.Format("shopId in ({0})", shopid));
  6493. }
  6494. var mainwhere = string.Join(" and ", lw.ToArray());
  6495. string ro_json = "";
  6496. string type = GetPostString("gather_type");
  6497. if (poscode == "AfterSale")
  6498. {
  6499. //处理中
  6500. if (type == "Handling")
  6501. {
  6502. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6503. DataTable dt = null;
  6504. try
  6505. {
  6506. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6507. }
  6508. catch (Exception e)
  6509. {
  6510. dt = new DataTable();
  6511. }
  6512. returnSuccess(JsonConvert.SerializeObject(new { Handling = dt.Rows[0]["number"] }));
  6513. return;
  6514. }
  6515. if (type == "Wait")
  6516. {
  6517. //待处理
  6518. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6519. DataTable dt1 = null;
  6520. try
  6521. {
  6522. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6523. }
  6524. catch (Exception e)
  6525. {
  6526. dt1 = new DataTable();
  6527. }
  6528. returnSuccess(JsonConvert.SerializeObject(new { Wait = dt1.Rows[0]["number"] }));
  6529. return;
  6530. }
  6531. if (type == "back")
  6532. {
  6533. //打回
  6534. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6535. DataTable dt2 = null;
  6536. try
  6537. {
  6538. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  6539. }
  6540. catch (Exception e)
  6541. {
  6542. dt2 = new DataTable();
  6543. }
  6544. returnSuccess(JsonConvert.SerializeObject(new { back = dt2.Rows[0]["number"] }));
  6545. return;
  6546. }
  6547. if (type == "preCompletion")
  6548. {
  6549. //预完成
  6550. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6551. DataTable dt3 = null;
  6552. try
  6553. {
  6554. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  6555. }
  6556. catch (Exception e)
  6557. {
  6558. dt3 = new DataTable();
  6559. }
  6560. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = dt3.Rows[0]["number"] }));
  6561. return;
  6562. }
  6563. if (type == "documentary")
  6564. {
  6565. //跟单中
  6566. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('重印-转设计师','重印-转下单员') " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6567. DataTable dt4 = null;
  6568. try
  6569. {
  6570. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  6571. }
  6572. catch (Exception e)
  6573. {
  6574. dt4 = new DataTable();
  6575. }
  6576. returnSuccess(JsonConvert.SerializeObject(new { documentary = dt4.Rows[0]["number"] }));
  6577. return;
  6578. }
  6579. if (type == "reBack")
  6580. {
  6581. //被打回
  6582. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6583. DataTable dt1 = null;
  6584. try
  6585. {
  6586. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6587. }
  6588. catch (Exception e)
  6589. {
  6590. dt1 = new DataTable();
  6591. }
  6592. returnSuccess(JsonConvert.SerializeObject(new { reBack = dt1.Rows[0]["number"] }));
  6593. return;
  6594. }
  6595. }
  6596. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  6597. {
  6598. if (type == "puBack")
  6599. {
  6600. //退回
  6601. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6602. DataTable dt = null;
  6603. try
  6604. {
  6605. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6606. }
  6607. catch (Exception e)
  6608. {
  6609. dt = new DataTable();
  6610. }
  6611. returnSuccess(JsonConvert.SerializeObject(new { puBack = dt.Rows[0]["number"] }));
  6612. return;
  6613. }
  6614. if (type == "reBack")
  6615. {
  6616. //打回
  6617. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6618. DataTable dt1 = null;
  6619. try
  6620. {
  6621. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6622. }
  6623. catch (Exception e)
  6624. {
  6625. dt1 = new DataTable();
  6626. }
  6627. returnSuccess(JsonConvert.SerializeObject(new { reBack = dt1.Rows[0]["number"] }));
  6628. return;
  6629. }
  6630. if (type == "examEd")
  6631. {
  6632. //已审核
  6633. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6634. DataTable dt2 = null;
  6635. try
  6636. {
  6637. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  6638. }
  6639. catch (Exception e)
  6640. {
  6641. dt2 = new DataTable();
  6642. }
  6643. returnSuccess(JsonConvert.SerializeObject(new { examEd = dt2.Rows[0]["number"] }));
  6644. return;
  6645. }
  6646. if (type == "waitExam")
  6647. {
  6648. //待审核
  6649. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6650. DataTable dt3 = null;
  6651. try
  6652. {
  6653. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  6654. }
  6655. catch (Exception e)
  6656. {
  6657. dt3 = new DataTable();
  6658. }
  6659. returnSuccess(JsonConvert.SerializeObject(new { waitExam = dt3.Rows[0]["number"] }));
  6660. return;
  6661. }
  6662. if (type == "Handling")
  6663. {
  6664. //处理中
  6665. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6666. DataTable dt4 = null;
  6667. try
  6668. {
  6669. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  6670. }
  6671. catch (Exception e)
  6672. {
  6673. dt4 = new DataTable();
  6674. }
  6675. returnSuccess(JsonConvert.SerializeObject(new { Handling = dt4.Rows[0]["number"] }));
  6676. return;
  6677. }
  6678. if (type == "Wait")
  6679. {
  6680. //待处理
  6681. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6682. DataTable dt5 = null;
  6683. try
  6684. {
  6685. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  6686. }
  6687. catch (Exception e)
  6688. {
  6689. dt5 = new DataTable();
  6690. }
  6691. returnSuccess(JsonConvert.SerializeObject(new { Wait = dt5.Rows[0]["number"] }));
  6692. return;
  6693. }
  6694. if (type == "documentary")
  6695. {
  6696. //跟单中
  6697. string sql6 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6698. DataTable dt6 = null;
  6699. try
  6700. {
  6701. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  6702. }
  6703. catch (Exception e)
  6704. {
  6705. dt6 = new DataTable();
  6706. }
  6707. returnSuccess(JsonConvert.SerializeObject(new { documentary = dt6.Rows[0]["number"] }));
  6708. return;
  6709. }
  6710. }
  6711. returnSuccess(ro_json);
  6712. }
  6713. public void end_erp_aftersale()
  6714. {
  6715. if (UrlPostParmsCheck("ctid"))
  6716. {
  6717. string eid = GetPostString("ctid");
  6718. CeErpTradeCell entity = null;
  6719. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6720. if (entity != null)
  6721. {
  6722. string stype = GetPostString("stype");
  6723. string typeStr = stype;
  6724. entity.AfterSaleState = 4;
  6725. entity.FinishAfterSaleTime = DateTime.Now;
  6726. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  6727. entity.Update();
  6728. ApiVo apiVo = new ApiVo();
  6729. apiVo.orderNumber = entity.ctid;
  6730. apiVo.actionName = "afterOver";
  6731. designHelper.API_WorkCore(apiVo); //afterOver
  6732. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  6733. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  6734. CeErpSukuraData.createInfo(entity.ctid, 8);
  6735. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  6736. returnSuccessMsg("操作成功!");
  6737. return;
  6738. }
  6739. returnErrorMsg("找不到订单记录");
  6740. }
  6741. }
  6742. public void ins_erp_finishaftersale()
  6743. {
  6744. if (UrlPostParmsCheck("id"))
  6745. {
  6746. string eid = GetPostString("id");
  6747. CeErpTradeResponsible entity = null;
  6748. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  6749. if (entity != null)
  6750. {
  6751. entity.VerifyState = 1;
  6752. entity.VerifyTime = DateTime.Now;
  6753. entity.Update();
  6754. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  6755. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  6756. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6757. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  6758. if (dt.Rows.Count <= 0)
  6759. {
  6760. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate() where ctid='" + entity.tid + "'";
  6761. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  6762. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  6763. CeErpSukuraData.createInfo(entity.tid, 8);
  6764. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  6765. {
  6766. CeErpDesignerBill.Del(entity.tid);
  6767. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  6768. }
  6769. }
  6770. returnSuccessMsg("操作成功!");
  6771. return;
  6772. }
  6773. returnErrorMsg("找不到订单记录");
  6774. }
  6775. }
  6776. public void upd_erp_arbitrateaftersale()
  6777. {
  6778. if (UrlPostParmsCheck("id"))
  6779. {
  6780. string eid = GetPostString("id");
  6781. CeErpTradeResponsible entity = null;
  6782. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  6783. if (entity != null)
  6784. {
  6785. entity.IsArbitrate = 1;
  6786. entity.ArbitradeMemo = GetPostString("reason");
  6787. entity.VerifyState = 2;
  6788. entity.Update();
  6789. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  6790. if (tradecell != null)
  6791. {
  6792. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  6793. tradecell.IsArbitrate = 1;
  6794. tradecell.Update();
  6795. }
  6796. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  6797. returnSuccessMsg("操作成功!");
  6798. return;
  6799. }
  6800. returnErrorMsg("找不到订单记录");
  6801. }
  6802. }
  6803. public void upd_erp_backaftersale()
  6804. {
  6805. if (UrlPostParmsCheck("tid"))
  6806. {
  6807. string eid = GetPostString("tid");
  6808. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6809. int backNum = 0;
  6810. if (number != null)
  6811. {
  6812. backNum = number.BackNum;
  6813. }
  6814. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  6815. CeErpTradeCell entity = null;
  6816. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6817. if (entity != null)
  6818. {
  6819. entity.AfterSaleBackReason = GetPostString("backreason");
  6820. entity.AfterSaleState = 1;
  6821. entity.AfterSaleSupplierState = 0;
  6822. entity.Update();
  6823. returnSuccessMsg("操作成功!");
  6824. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  6825. return;
  6826. }
  6827. returnErrorMsg("找不到订单记录");
  6828. }
  6829. }
  6830. public void get_erp_supplieraftersalelist()
  6831. {
  6832. DataStruct dStruct = GetPostStruct();
  6833. List<string> lw = new List<string>();
  6834. string tid = GetPostString("ctid");
  6835. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6836. string shopname = GetPostString("shopname");
  6837. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6838. string buyernick = GetPostString("buyer_nick");
  6839. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6840. string sellermemo = GetPostString("seller_memo");
  6841. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6842. string orderState = GetPostString("orderState");
  6843. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6844. string afterState = GetPostString("afterstate");
  6845. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6846. string date1 = GetPostString("date1");
  6847. string date2 = GetPostString("date2");
  6848. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6849. if (dw.Length > 0) lw.Add(dw);
  6850. string price1 = GetPostString("price1");
  6851. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6852. string price2 = GetPostString("price2");
  6853. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6854. string reason = GetPostString("reason");
  6855. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6856. string method = GetPostString("method");
  6857. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6858. string handledate1 = GetPostString("handledate1");
  6859. string handledate2 = GetPostString("handledate2");
  6860. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6861. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6862. string handler = GetPostString("handler");
  6863. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6864. string afterdate1 = GetPostString("afterdate1");
  6865. string afterdate2 = GetPostString("afterdate2");
  6866. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6867. if (afterDate.Length > 0) lw.Add(afterDate);
  6868. string customer = GetPostString("customer");
  6869. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6870. string design = GetPostString("design");
  6871. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6872. string afterMemoType = GetPostString("aftermemotype");
  6873. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6874. string vstate = GetPostString("vstate");
  6875. if (vstate.Length > 0)
  6876. {
  6877. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6878. }
  6879. lw.Add(string.Format("AfterSaleState>={0}", 2));
  6880. string supplier = GetPostString("supplier");
  6881. int supid = commonHelper.getSupplierIDByName(supplier);
  6882. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  6883. string posCode = CurrentUser.UserPost.Post.Code;
  6884. if (posCode == "Supplier")
  6885. {
  6886. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6887. }
  6888. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  6889. {
  6890. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  6891. }
  6892. else
  6893. {
  6894. lw.Add(string.Format("AfterSaleResSupId != 0"));
  6895. }
  6896. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6897. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6898. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6899. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6900. writeGridDataTableJson(dStruct.TotalCount, dt);
  6901. }
  6902. public void upd_erp_supverifyaftersale()
  6903. {
  6904. if (UrlPostParmsCheck("id"))
  6905. {
  6906. string id = GetPostString("id");
  6907. int st = GetPostInt("afterstate");
  6908. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  6909. CeErpTradeCell entity = null;
  6910. if (ceErpTradeResponsible != null)
  6911. {
  6912. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  6913. }
  6914. string afmemo = GetPostString("supmemo");
  6915. string image = GetPostString("image");
  6916. if (entity != null)
  6917. {
  6918. entity.AfterSaleSupplierState = st;
  6919. entity.AfterSaleSupplierMemo = afmemo;
  6920. if (st == 1)
  6921. {
  6922. ceErpTradeResponsible.VerifyState = 1;
  6923. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  6924. ceErpTradeResponsible.Update();
  6925. bool isAll = commonHelper.tradeResponsibleAll(entity);
  6926. if (isAll)
  6927. {
  6928. entity.AfterSaleState = 4;
  6929. entity.FinishAfterSaleTime = DateTime.Now;
  6930. }
  6931. }
  6932. else
  6933. {
  6934. CeErpTradeResponsible.dateByTid(entity.ctid);
  6935. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  6936. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  6937. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  6938. if (num <= 1)
  6939. {
  6940. entity.AfterSaleState = 1;
  6941. }
  6942. else
  6943. {
  6944. entity.AfterSaleState = 5;
  6945. }
  6946. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  6947. if (ceErpTradeAfterSaleExtend != null)
  6948. {
  6949. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  6950. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  6951. ceErpTradeAfterSaleExtend.Update();
  6952. }
  6953. else
  6954. {
  6955. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6956. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  6957. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  6958. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  6959. ceErpTradeAfterSaleExtend.Create();
  6960. }
  6961. }
  6962. if (entity.AfterSaleState == 4)
  6963. {
  6964. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  6965. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  6966. {
  6967. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  6968. }
  6969. ApiVo apiVo = new ApiVo();
  6970. apiVo.orderNumber = entity.ctid;
  6971. apiVo.actionName = "afterOver";
  6972. designHelper.API_WorkCore(apiVo); //afterOver
  6973. }
  6974. entity.Update();
  6975. returnSuccessMsg("操作成功!");
  6976. CeErpSukuraData.createInfo(entity.ctid, 8);
  6977. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  6978. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  6979. return;
  6980. }
  6981. returnErrorMsg("找不到订单记录");
  6982. }
  6983. }
  6984. public void upd_erp_masteraftersale()
  6985. {
  6986. if (UrlPostParmsCheck("id"))
  6987. {
  6988. string id = GetPostString("id");
  6989. int st = GetPostInt("afterstate");
  6990. string afmemo = GetPostString("supmemo");
  6991. string image = GetPostString("image");
  6992. string textResult = GetPostString("textResult");
  6993. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  6994. if (ceErpTradeResponsible != null)
  6995. {
  6996. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  6997. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  6998. ceErpTradeResponsible.Update();
  6999. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7000. if (entity != null)
  7001. {
  7002. entity.AfterSaleSupplierState = st;
  7003. entity.AfterSaleSupplierMemo = afmemo;
  7004. if (st == 1)
  7005. {
  7006. }
  7007. else
  7008. {
  7009. CeErpTradeResponsible.dateByTid(entity.ctid);
  7010. //退回到售后
  7011. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7012. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7013. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7014. if (num <= 1)
  7015. {
  7016. entity.AfterSaleState = 1;
  7017. }
  7018. else
  7019. {
  7020. entity.AfterSaleState = 5;
  7021. }
  7022. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7023. if (ceErpTradeAfterSaleExtend != null)
  7024. {
  7025. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7026. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7027. ceErpTradeAfterSaleExtend.Update();
  7028. }
  7029. else
  7030. {
  7031. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7032. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7033. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7034. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7035. ceErpTradeAfterSaleExtend.Create();
  7036. }
  7037. }
  7038. entity.Update();
  7039. returnSuccessMsg("操作成功!");
  7040. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7041. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7042. return;
  7043. }
  7044. }
  7045. returnErrorMsg("找不到订单记录");
  7046. }
  7047. }
  7048. public void upd_erp_personaftersale()
  7049. {
  7050. if (UrlPostParmsCheck("id"))
  7051. {
  7052. string id = GetPostString("id");
  7053. int st = GetPostInt("afterstate");
  7054. string afmemo = GetPostString("supmemo");
  7055. string image = GetPostString("image");
  7056. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7057. if (ceErpTradeResponsible != null)
  7058. {
  7059. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7060. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7061. ceErpTradeResponsible.Update();
  7062. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7063. if (entity != null)
  7064. {
  7065. entity.AfterSaleSupplierMemo = afmemo;
  7066. entity.AfterSaleSupplierState = st;
  7067. if (st == 1)
  7068. {
  7069. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7070. if (isAll)
  7071. {
  7072. entity.AfterSaleState = 4;
  7073. entity.FinishAfterSaleTime = DateTime.Now;
  7074. }
  7075. }
  7076. else
  7077. {
  7078. CeErpTradeResponsible.dateByTid(entity.ctid);
  7079. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7080. if (ceErpTradeAfterSaleExtend != null)
  7081. {
  7082. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7083. ceErpTradeAfterSaleExtend.Update();
  7084. }
  7085. else
  7086. {
  7087. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7088. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7089. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7090. ceErpTradeAfterSaleExtend.Create();
  7091. }
  7092. //退回到主管
  7093. //entity.AfterSaleState = 2;
  7094. }
  7095. if (entity.AfterSaleState == 4)
  7096. {
  7097. ApiVo apiVo = new ApiVo();
  7098. apiVo.orderNumber = entity.ctid;
  7099. apiVo.actionName = "afterOver";
  7100. designHelper.API_WorkCore(apiVo); //afterOver
  7101. }
  7102. entity.Update();
  7103. returnSuccessMsg("操作成功!");
  7104. CeErpSukuraData.createInfo(entity.ctid, 8);
  7105. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7106. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7107. return;
  7108. }
  7109. }
  7110. returnErrorMsg("找不到订单记录");
  7111. }
  7112. }
  7113. public void set_erp_supplierrefundtag()
  7114. {
  7115. if (UrlPostParmsCheck("ctid"))
  7116. {
  7117. string eid = GetPostString("ctid");
  7118. CeErpTradeCell entity = null;
  7119. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7120. if (entity != null)
  7121. {
  7122. entity.IsSupplierRefund = GetPostInt("tag");
  7123. entity.Update();
  7124. returnSuccessMsg("操作成功!");
  7125. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7126. return;
  7127. }
  7128. returnErrorMsg("找不到订单记录");
  7129. }
  7130. }
  7131. public void get_erp_refundlist()
  7132. {
  7133. DataStruct dStruct = GetPostStruct();
  7134. List<string> lw = new List<string>();
  7135. string tid = GetPostString("tid");
  7136. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7137. //string rid = GetPostString("refund_id");
  7138. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7139. string shopname = GetPostString("shopname");
  7140. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7141. string buyernick = GetPostString("buyer_nick");
  7142. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7143. string customer = GetPostString("customer");
  7144. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7145. string design = GetPostString("design");
  7146. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7147. string sellermemo = GetPostString("seller_memo");
  7148. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7149. //string date1 = GetPostString("date1");
  7150. //string date2 = GetPostString("date2");
  7151. //string dateType = GetPostString("dateType");
  7152. //if (dateType.Length > 0)
  7153. //{
  7154. // if (dateType == "1001") dateType = "0";
  7155. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7156. // if (searchDT.Count == 2)
  7157. // {
  7158. // date1 = searchDT[0].ToString();
  7159. // date2 = searchDT[1].ToString();
  7160. // }
  7161. //}
  7162. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7163. //if (dw.Length > 0) lw.Add(dw);
  7164. string redate1 = GetPostString("refunddate1");
  7165. string redate2 = GetPostString("refunddate2");
  7166. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7167. if (dwdate.Length > 0) lw.Add(dwdate);
  7168. string price1 = GetPostString("price1");
  7169. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7170. string price2 = GetPostString("price2");
  7171. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7172. string ispartrefund = GetPostString("ispartrefund");
  7173. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7174. string refundState = GetPostString("refundvstate");
  7175. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7176. int st = GetInt("st");
  7177. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7178. {
  7179. string responsible = GetPostString("responsibleman");
  7180. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7181. lw.Add(string.Format("RefundState>={0}", st));
  7182. string code = CurrentUser.UserPost.Post.Code;
  7183. if (code == "CustomerService")
  7184. {
  7185. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7186. }
  7187. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7188. {
  7189. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7190. }
  7191. else if (code == "Place" || code == "PlaceMr")
  7192. {
  7193. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7194. }
  7195. dStruct.Order = "RefundState asc,created desc";
  7196. }
  7197. else if (st == 10)
  7198. {
  7199. string responsible = GetPostString("responsibleman");
  7200. if (responsible == "空白")
  7201. {
  7202. lw.Add(string.Format("ResponsibleUserName = ''"));
  7203. }
  7204. else if (responsible.Length > 0)
  7205. {
  7206. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7207. }
  7208. lw.Add(string.Format("RefundState>=0"));
  7209. dStruct.Order = "created desc";
  7210. }
  7211. else
  7212. {
  7213. string responsible = GetPostString("responsibleman");
  7214. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7215. lw.Add(string.Format("RefundState={0}", st));
  7216. dStruct.Order = "created desc";
  7217. }
  7218. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7219. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7220. dt.Columns.Add("refund_fees");
  7221. foreach (DataRow dr in dt.Rows)
  7222. {
  7223. String status = dr["status"].ToString();
  7224. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7225. {
  7226. dr["refund_fees"] = dr["refund_fee"];
  7227. }
  7228. else
  7229. {
  7230. dr["refund_fees"] = "0.0";
  7231. }
  7232. }
  7233. writeGridDataTableJson(dStruct.TotalCount, dt);
  7234. }
  7235. public void get_erp_refunddesignlist()
  7236. {
  7237. DataStruct dStruct = GetPostStruct();
  7238. List<string> lw = new List<string>();
  7239. string tid = GetPostString("tid");
  7240. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7241. string shopname = GetPostString("shopname");
  7242. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7243. string buyernick = GetPostString("buyer_nick");
  7244. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7245. string customer = GetPostString("customer");
  7246. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7247. string design = GetPostString("design");
  7248. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7249. string sellermemo = GetPostString("seller_memo");
  7250. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7251. string redate1 = GetPostString("refunddate1");
  7252. string redate2 = GetPostString("refunddate2");
  7253. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7254. if (dwdate.Length > 0) lw.Add(dwdate);
  7255. string price1 = GetPostString("price1");
  7256. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7257. string price2 = GetPostString("price2");
  7258. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7259. string ispartrefund = GetPostString("ispartrefund");
  7260. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7261. string designerorg = GetPostString("designerorg");
  7262. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7263. string refundState = GetPostString("refundState");
  7264. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7265. int myOrgid = CurrentUser.UserPost.OrgID;
  7266. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7267. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7268. {
  7269. if (CurrentUser.User.TeamIds.Length > 0)
  7270. {
  7271. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7272. }
  7273. else
  7274. {
  7275. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7276. }
  7277. }
  7278. else if ("SysAdmin".Equals(myOrgCode))
  7279. {
  7280. }
  7281. else
  7282. {
  7283. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7284. {
  7285. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7286. }
  7287. else
  7288. {
  7289. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7290. }
  7291. }
  7292. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7293. dStruct.Order = "created desc";
  7294. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7295. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7296. dt.Columns.Add("refund_fees");
  7297. foreach (DataRow dr in dt.Rows)
  7298. {
  7299. String status = dr["status"].ToString();
  7300. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7301. {
  7302. dr["refund_fees"] = dr["refund_fee"];
  7303. }
  7304. else
  7305. {
  7306. dr["refund_fees"] = "0.0";
  7307. }
  7308. }
  7309. writeGridDataTableJson(dStruct.TotalCount, dt);
  7310. }
  7311. public void handle_erp_refundtag()
  7312. {
  7313. if (UrlPostParmsCheck("refund_id"))
  7314. {
  7315. string eid = GetPostString("refund_id");
  7316. string respMan = GetPostString("ResponsibleName");
  7317. if (respMan.Length <= 0)
  7318. {
  7319. returnErrorMsg("责任人不能为空");
  7320. return;
  7321. }
  7322. CeErpTradeRefund entity = null;
  7323. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7324. if (entity != null)
  7325. {
  7326. entity.ResponsibleUserName = respMan;
  7327. string userid = GetPostString("ResponsibleUserId");
  7328. if (userid.Length > 0)
  7329. {
  7330. entity.ResponsibleUserId = userid;
  7331. }
  7332. entity.Memo = GetPostString("Memo");
  7333. if (respMan.IndexOf("客服") != -1 ||
  7334. respMan.IndexOf("设计师") != -1 ||
  7335. respMan.IndexOf("下单员") != -1)
  7336. {
  7337. entity.RefundState = 2;
  7338. }
  7339. else
  7340. {
  7341. entity.RefundState = 3;
  7342. }
  7343. entity.modified = DateTime.Now;
  7344. entity.Update();
  7345. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  7346. returnSuccessMsg("操作成功!");
  7347. return;
  7348. }
  7349. returnErrorMsg("找不到订单记录");
  7350. }
  7351. }
  7352. public void handle_erp_designrefundtag()
  7353. {
  7354. if (UrlPostParmsCheck("refund_id"))
  7355. {
  7356. string eid = GetPostString("refund_id");
  7357. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  7358. if (ceErpTradeCellExtend == null)
  7359. {
  7360. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  7361. ceErpTradeCellExtend.ctid = eid;
  7362. }
  7363. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  7364. if (ceErpTradeCellExtend.ID > 0)
  7365. {
  7366. ceErpTradeCellExtend.Update();
  7367. }
  7368. else
  7369. {
  7370. ceErpTradeCellExtend.Create();
  7371. }
  7372. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  7373. returnSuccessMsg("操作成功!");
  7374. return;
  7375. }
  7376. returnErrorMsg("找不到订单记录");
  7377. }
  7378. public void upd_erp_refundverify()
  7379. {
  7380. if (UrlPostParmsCheck("refund_id"))
  7381. {
  7382. string eid = GetPostString("refund_id");
  7383. CeErpTradeRefund entity = null;
  7384. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7385. if (entity != null)
  7386. {
  7387. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  7388. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  7389. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  7390. {
  7391. entity.RefundState = 2;
  7392. }
  7393. else
  7394. {
  7395. entity.RefundState = 3;
  7396. }
  7397. entity.Update();
  7398. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  7399. returnSuccessMsg("操作成功!");
  7400. return;
  7401. }
  7402. returnErrorMsg("找不到订单记录");
  7403. }
  7404. }
  7405. public void upd_erp_refundapprove()
  7406. {
  7407. if (UrlPostParmsCheck("refund_id"))
  7408. {
  7409. string eid = GetPostString("refund_id");
  7410. CeErpTradeRefund entity = null;
  7411. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7412. if (entity != null)
  7413. {
  7414. int apr = GetPostInt("approve");
  7415. if (apr == 0)
  7416. {
  7417. entity.RefundState = 1;
  7418. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  7419. }
  7420. else if (apr == 1)
  7421. {
  7422. entity.RefundState = 3;
  7423. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  7424. }
  7425. entity.modified = DateTime.Now;
  7426. entity.Update();
  7427. returnSuccessMsg("操作成功!");
  7428. return;
  7429. }
  7430. returnErrorMsg("找不到订单记录");
  7431. }
  7432. }
  7433. public void get_erp_billlist()
  7434. {
  7435. DataStruct dStruct = GetPostStruct();
  7436. List<string> lw = new List<string>();
  7437. string title = GetPostString("title");
  7438. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  7439. string tid = GetPostString("tid");
  7440. string tids = GetPostString("tids");
  7441. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7442. if (tids.Length > 0)
  7443. {
  7444. tids = "'" + tids + "'";
  7445. tids = tids.Replace(",", "','");
  7446. lw.Add(string.Format("tid in ({0})", tids));
  7447. }
  7448. string shopname = GetPostString("shopname");
  7449. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7450. string buyernick = GetPostString("buyer_nick");
  7451. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7452. string customer = GetPostString("customer");
  7453. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7454. string date1 = GetPostString("date1");
  7455. string date2 = GetPostString("date2");
  7456. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7457. if (dw.Length > 0) lw.Add(dw);
  7458. string price1 = GetPostString("price1");
  7459. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7460. string price2 = GetPostString("price2");
  7461. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7462. string returndate1 = GetPostString("returndate1");
  7463. string returndate2 = GetPostString("returndate2");
  7464. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  7465. if (dw1.Length > 0) lw.Add(dw1);
  7466. string billtype = GetPostString("billtype");
  7467. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  7468. string billstate = GetPostString("billstate");
  7469. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  7470. string usershop = CurrentUser.User.pemShop;
  7471. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  7472. dStruct.Order = "createTime desc";
  7473. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7474. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  7475. //foreach (DataRow dr in dt.Rows)
  7476. //{
  7477. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  7478. //}
  7479. writeGridDataTableJson(dStruct.TotalCount, dt);
  7480. }
  7481. public void modify_erp_billinfo()
  7482. {
  7483. if (UrlPostParmsCheck("ID"))
  7484. {
  7485. string eid = GetPostString("ID");
  7486. CeErpBill bill_entity = null;
  7487. if (eid != "") bill_entity = CeErpBill.Get(eid);
  7488. if (bill_entity != null)
  7489. {
  7490. bill_entity.tid = GetPostString("tid");
  7491. bill_entity.title = GetPostString("title");
  7492. bill_entity.tax = GetPostString("tax");
  7493. bill_entity.bank = GetPostString("bank");
  7494. bill_entity.bankac = GetPostString("bankac");
  7495. bill_entity.address = GetPostString("address");
  7496. bill_entity.phone = GetPostString("phone");
  7497. bill_entity.price = GetPostString("price");
  7498. bill_entity.productId = GetPostInt("ProductName");
  7499. bill_entity.num = GetPostInt("num");
  7500. bill_entity.unit = GetPostString("unit");
  7501. bill_entity.type = GetPostString("type");
  7502. bill_entity.sendType = GetPostString("SendType");
  7503. bill_entity.email = GetPostString("email");
  7504. bill_entity.buyer_nick = GetPostString("buyer_nick");
  7505. bill_entity.shopName = GetPostString("ShopName");
  7506. bill_entity.applymemo = GetPostString("applymemo");
  7507. bill_entity.modifyTime = DateTime.Now;
  7508. bill_entity.createTime = DateTime.Now;
  7509. bill_entity.state = 0;
  7510. bill_entity.Update();
  7511. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  7512. returnSuccessMsg("发票修改成功!");
  7513. return;
  7514. }
  7515. returnErrorMsg("找不到对应记录");
  7516. }
  7517. }
  7518. public void set_erp_invoicing()
  7519. {
  7520. if (UrlPostParmsCheck("id"))
  7521. {
  7522. try
  7523. {
  7524. string eid = GetPostString("id");
  7525. CeErpBill bill_entity = null;
  7526. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  7527. if (bill_entity != null)
  7528. {
  7529. int ComId = GetPostInt("ComId");
  7530. //string memo = GetPostString("Memo");
  7531. int allInfo = GetPostInt("allinfo");
  7532. string clert = CurrentUser.User.Name;
  7533. //string detailValue = GetPostString("detailvalue");
  7534. string billId = bill_entity.billOrderId;
  7535. string[] billIdList = billId.Split(',');
  7536. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  7537. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  7538. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  7539. {
  7540. billCount += 1;
  7541. }
  7542. if (billId.Length <= 0 || billIdList.Length != billCount)
  7543. {
  7544. bill_entity.billOrderId = "";
  7545. string prebill = "ltb";
  7546. for (int idx = 1; idx <= billCount; idx++)
  7547. {
  7548. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  7549. string billoid = prebill + idx + dtstr;
  7550. bill_entity.billOrderId += billoid;
  7551. if (idx < billCount)
  7552. {
  7553. bill_entity.billOrderId += ",";
  7554. }
  7555. }
  7556. }
  7557. string[] billOrderList = bill_entity.billOrderId.Split(',');
  7558. if (bill_entity.state == 5)
  7559. {
  7560. string errMsg = bill_entity.failerror;
  7561. string[] errlist = errMsg.Split('|');
  7562. string[] errTags = new string[errlist.Length];
  7563. for (int itag = 0; itag < errlist.Length; itag++)
  7564. {
  7565. if (errlist[itag].Length <= 0) continue;
  7566. errTags[itag] = errlist[itag].Split('&')[0];
  7567. }
  7568. for (int iii = 0; iii < errTags.Length; iii++)
  7569. {
  7570. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  7571. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  7572. if (billOrderList.Length >= erroBillOrderTag)
  7573. {
  7574. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  7575. if (needModifyBillId.Length <= 19)
  7576. {
  7577. needModifyBillId = needModifyBillId + "1";
  7578. }
  7579. else
  7580. {
  7581. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  7582. last = last + 1;
  7583. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  7584. }
  7585. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  7586. }
  7587. }
  7588. }
  7589. bool isHaveBillSucces = false;
  7590. string totalRes = "";
  7591. bill_entity.failerror = "";
  7592. for (int ii = 1; ii <= billOrderList.Length; ii++)
  7593. {
  7594. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  7595. totalRes += res;
  7596. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  7597. {
  7598. isHaveBillSucces = true;
  7599. bill_entity.comId = ComId;
  7600. bill_entity.state = 1;
  7601. bill_entity.executeTime = DateTime.Now;
  7602. bill_entity.executeUser = clert;
  7603. }
  7604. else
  7605. {
  7606. bill_entity.state = 5;
  7607. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  7608. }
  7609. }
  7610. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  7611. bill_entity.Update();
  7612. if (isHaveBillSucces)
  7613. {
  7614. StringBuilder sql = new StringBuilder();
  7615. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  7616. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  7617. }
  7618. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  7619. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  7620. {
  7621. returnErrorMsg("开票失败");
  7622. }
  7623. else
  7624. returnSuccessMsg("发票开具中,稍后刷新查看!");
  7625. return;
  7626. }
  7627. returnErrorMsg("找不到对应记录");
  7628. }
  7629. catch (Exception ex)
  7630. {
  7631. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  7632. returnErrorMsg("操作失败");
  7633. }
  7634. }
  7635. }
  7636. public void get_erp_invoicing_back()
  7637. {
  7638. if (UrlPostParmsCheck("id"))
  7639. {
  7640. try
  7641. {
  7642. string id = GetPostString("id");
  7643. CeErpBill entiy = CeErpBill.Get(id);
  7644. if (entiy != null)
  7645. {
  7646. if (entiy.state == 0)
  7647. {
  7648. returnErrorMsg("发票还未开具");
  7649. return;
  7650. }
  7651. string[] billOrderList = entiy.billOrderId.Split(',');
  7652. int iTag = 0;
  7653. entiy.fplsh = "";
  7654. entiy.fpdm = "";
  7655. entiy.fphm = "";
  7656. foreach (string billOrderId in billOrderList)
  7657. {
  7658. iTag++;
  7659. string res = taobaoHelper.get_invoicing(id, billOrderId);
  7660. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  7661. {
  7662. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  7663. try
  7664. {
  7665. Invoicing_get_response_Obj iObj = null;
  7666. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  7667. if (iObj != null)
  7668. {
  7669. entiy.state = 2;
  7670. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  7671. entiy.fpdm += iObj.list[0].c_fpdm;
  7672. entiy.fphm += iObj.list[0].c_fphm;
  7673. if (iTag < billOrderList.Length)
  7674. {
  7675. entiy.fplsh += ",";
  7676. entiy.fpdm += ",";
  7677. entiy.fphm += ",";
  7678. }
  7679. entiy.Update();
  7680. }
  7681. StringBuilder sql = new StringBuilder();
  7682. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  7683. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  7684. returnSuccessMsg("开票成功");
  7685. }
  7686. catch (Exception ex)
  7687. {
  7688. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  7689. }
  7690. return;
  7691. }
  7692. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  7693. {
  7694. var res_obj = new
  7695. {
  7696. data = "开票中"
  7697. };
  7698. string ro_json = JsonConvert.SerializeObject(res_obj);
  7699. returnSuccess(ro_json);
  7700. return;
  7701. }
  7702. else
  7703. {
  7704. int eidx = res.IndexOf("c_resultmsg");
  7705. int lidx = res.IndexOf("c_status");
  7706. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  7707. entiy.state = 5;
  7708. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  7709. entiy.Update();
  7710. returnErrorMsg("开票失败");
  7711. return;
  7712. }
  7713. }
  7714. }
  7715. }
  7716. catch (Exception ex)
  7717. {
  7718. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  7719. }
  7720. return;
  7721. }
  7722. }
  7723. public void get_erp_invoicing()
  7724. {
  7725. if (UrlPostParmsCheck("id"))
  7726. {
  7727. try
  7728. {
  7729. string id = GetPostString("id");
  7730. CeErpBill entiy = CeErpBill.Get(id);
  7731. if (entiy != null)
  7732. {
  7733. if (entiy.state == 0)
  7734. {
  7735. returnErrorMsg("发票还未开具");
  7736. return;
  7737. }
  7738. if (entiy.sendType == "纸质发票")
  7739. {
  7740. if (entiy.img.Length <= 0)
  7741. {
  7742. returnErrorMsg("查无纸质发票");
  7743. return;
  7744. }
  7745. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  7746. returnSuccess(returnres);
  7747. return;
  7748. }
  7749. string[] billOrderList = entiy.billOrderId.Split(',');
  7750. int iTag = 0;
  7751. string fpUrl = "";
  7752. entiy.fplsh = "";
  7753. entiy.fpdm = "";
  7754. entiy.fphm = "";
  7755. foreach (string billOrderId in billOrderList)
  7756. {
  7757. iTag++;
  7758. string res = taobaoHelper.get_invoicing(id, billOrderId);
  7759. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  7760. {
  7761. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  7762. Invoicing_get_response_Obj iObj = null;
  7763. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  7764. if (iObj != null)
  7765. {
  7766. //entiy.state = 2;
  7767. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  7768. entiy.fpdm += iObj.list[0].c_fpdm;
  7769. entiy.fphm += iObj.list[0].c_fphm;
  7770. if (iTag < billOrderList.Length)
  7771. {
  7772. entiy.fplsh += ",";
  7773. entiy.fpdm += ",";
  7774. entiy.fphm += ",";
  7775. }
  7776. entiy.Update();
  7777. fpUrl += iObj.list[0].c_url + ",";
  7778. }
  7779. //returnSuccess(res);
  7780. StringBuilder sql = new StringBuilder();
  7781. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  7782. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  7783. }
  7784. else
  7785. {
  7786. int eidx = res.IndexOf("c_resultmsg");
  7787. //int lidx = res.IndexOf("c_status");
  7788. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  7789. //开票失败
  7790. entiy.state = 5;
  7791. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  7792. entiy.Update();
  7793. returnErrorMsg("开票失败");
  7794. return;
  7795. }
  7796. }
  7797. var returnObj = new
  7798. {
  7799. data = fpUrl
  7800. };
  7801. string ro_json = JsonConvert.SerializeObject(returnObj);
  7802. returnSuccess(ro_json);
  7803. }
  7804. }
  7805. catch (Exception ex)
  7806. {
  7807. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  7808. }
  7809. return;
  7810. }
  7811. }
  7812. public void save_erp_billimg()
  7813. {
  7814. if (UrlPostParmsCheck("id"))
  7815. {
  7816. string eid = GetPostString("id");
  7817. CeErpBill bill_entity = null;
  7818. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  7819. if (bill_entity != null)
  7820. {
  7821. bill_entity.img = GetPostString("img");
  7822. bill_entity.executeTime = DateTime.Now;
  7823. bill_entity.state = 2;
  7824. bill_entity.Update();
  7825. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  7826. returnSuccessMsg("保存成功");
  7827. }
  7828. return;
  7829. }
  7830. }
  7831. public void upd_erp_billreturnback()
  7832. {
  7833. if (UrlPostParmsCheck("id"))
  7834. {
  7835. int eid = GetPostInt("id");
  7836. CeErpBill bill_entity = null;
  7837. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  7838. if (bill_entity != null)
  7839. {
  7840. bill_entity.state = 3;
  7841. bill_entity.returnReason = GetPostString("reason");
  7842. bill_entity.Update();
  7843. returnSuccessMsg("驳回成功!");
  7844. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  7845. }
  7846. return;
  7847. }
  7848. }
  7849. public void cancel_erp_bill()
  7850. {
  7851. if (UrlPostParmsCheck("id"))
  7852. {
  7853. int eid = GetPostInt("id");
  7854. int detailValue = GetPostInt("detailvalue");
  7855. CeErpBill bill_entity = null;
  7856. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  7857. string cres = "";
  7858. string gres = "";
  7859. if (bill_entity != null)
  7860. {
  7861. string[] billOrderList = bill_entity.billOrderId.Split(',');
  7862. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  7863. {
  7864. int iTag = 0;
  7865. bill_entity.fplsh = "";
  7866. bill_entity.fpdm = "";
  7867. bill_entity.fphm = "";
  7868. foreach (string billOrderId in billOrderList)
  7869. {
  7870. iTag++;
  7871. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  7872. if (gres.IndexOf("success") != -1)
  7873. {
  7874. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  7875. Invoicing_get_response_Obj iObj = null;
  7876. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  7877. if (iObj != null)
  7878. {
  7879. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  7880. bill_entity.fpdm += iObj.list[0].c_fpdm;
  7881. bill_entity.fphm += iObj.list[0].c_fphm;
  7882. if (iTag < billOrderList.Length)
  7883. {
  7884. bill_entity.fplsh += ",";
  7885. bill_entity.fpdm += ",";
  7886. bill_entity.fphm += ",";
  7887. }
  7888. bill_entity.Update();
  7889. }
  7890. }
  7891. else
  7892. {
  7893. returnErrorMsg(gres);
  7894. return;
  7895. }
  7896. }
  7897. }
  7898. if (bill_entity.sendType == "纸质发票")
  7899. {
  7900. //作废
  7901. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  7902. //if (DateTime.Now.Month == extime.Month)
  7903. //{
  7904. //cres = taobaoHelper.cancel_invoicing(eid);
  7905. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  7906. //{
  7907. bill_entity.state = 4;//已作废
  7908. bill_entity.Update();
  7909. returnSuccessMsg("发票已作废");
  7910. return;
  7911. //}
  7912. //else
  7913. //{
  7914. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  7915. // bill_entity.Update();
  7916. // returnErrorMsg(cres);
  7917. // return;
  7918. //}
  7919. //}
  7920. //else
  7921. //{
  7922. // returnErrorMsg("纸质发票只能作废本月的发票");
  7923. // return;
  7924. //}
  7925. }
  7926. //红冲
  7927. int redTag = 0;
  7928. string[] fpdmList = bill_entity.fpdm.Split(',');
  7929. string[] fphmList = bill_entity.fphm.Split(',');
  7930. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  7931. {
  7932. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  7933. return;
  7934. }
  7935. foreach (string billOrderId in billOrderList)
  7936. {
  7937. redTag++;
  7938. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  7939. cres += onecres;
  7940. cres += ",";
  7941. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  7942. {
  7943. bill_entity.state = 4;//已作废
  7944. //bill_entity.Update();
  7945. //returnSuccessMsg("发票已红冲");
  7946. }
  7947. else if (onecres.IndexOf("重复冲红") != -1)
  7948. {
  7949. bill_entity.state = 4;//已作废
  7950. //bill_entity.Update();
  7951. //returnSuccessMsg("发票已红冲");
  7952. }
  7953. else
  7954. {
  7955. string errmsg = commonHelper.KeepChinese(onecres);
  7956. bill_entity.failerror += redTag + "&" + errmsg + "|";
  7957. }
  7958. }
  7959. bill_entity.Update();
  7960. if (cres.IndexOf("失败") != -1)
  7961. returnErrorMsg("红冲失败");
  7962. else
  7963. returnSuccessMsg("发票已红冲");
  7964. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  7965. return;
  7966. }
  7967. return;
  7968. }
  7969. }
  7970. public void del_erp_billorder()
  7971. {
  7972. if (UrlPostParmsCheck("id"))
  7973. {
  7974. string eid = GetPostString("id");
  7975. CeErpBill.Del(eid);
  7976. CeErpBill bill = CeErpBill.Get(eid);
  7977. if (bill != null)
  7978. {
  7979. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  7980. }
  7981. returnSuccessMsg("删除成功");
  7982. }
  7983. }
  7984. public void finish_erp_bill()
  7985. {
  7986. if (UrlPostParmsCheck("ids"))
  7987. {
  7988. string eids = GetPostString("ids");
  7989. string[] list = eids.Split(',');
  7990. foreach (string eid in list)
  7991. {
  7992. CeErpBill bill = CeErpBill.Get(eid);
  7993. if (bill != null)
  7994. {
  7995. bill.state = 2;
  7996. bill.Update();
  7997. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  7998. }
  7999. }
  8000. returnSuccessMsg("操作成功");
  8001. }
  8002. }
  8003. public void get_erp_returncash()
  8004. {
  8005. DataStruct dStruct = GetPostStruct();
  8006. List<string> lw = new List<string>();
  8007. string tid = GetPostString("tid");
  8008. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8009. string shopname = GetPostString("shopname");
  8010. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8011. string buyernick = GetPostString("buyer_nick");
  8012. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8013. string customer = GetPostString("customer");
  8014. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8015. string returndate1 = GetPostString("returndate1");
  8016. string returndate2 = GetPostString("returndate2");
  8017. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8018. if (dw.Length > 0) lw.Add(dw);
  8019. string finishDate1 = GetPostString("finishdate1");
  8020. string finishDate2 = GetPostString("finishdate2");
  8021. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8022. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8023. string returntype = GetPostString("returntype");
  8024. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8025. string returnvstate = GetPostString("returnvstate");
  8026. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8027. dStruct.Order = "created desc";
  8028. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8029. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8030. writeGridDataTableJson(dStruct.TotalCount, dt);
  8031. }
  8032. public void get_erp_staygoods()
  8033. {
  8034. DataStruct dStruct = GetPostStruct();
  8035. List<string> lw = new List<string>();
  8036. string tid = GetPostString("tid");
  8037. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8038. string shopname = GetPostString("shopname");
  8039. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8040. string wangwang = GetPostString("wangwang");
  8041. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8042. string customer = GetPostString("customer");
  8043. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8044. string returndate1 = GetPostString("returndate1");
  8045. string returndate2 = GetPostString("returndate2");
  8046. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8047. if (dw.Length > 0) lw.Add(dw);
  8048. string finishDate1 = GetPostString("finishdate1");
  8049. string finishDate2 = GetPostString("finishdate2");
  8050. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8051. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8052. string returnvstate = GetPostString("returnvstate");
  8053. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8054. string persuadetype = GetPostString("persuadetype");
  8055. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8056. string customerOrg = GetPostString("customerOrg");
  8057. if (customerOrg.Length > 0)
  8058. {
  8059. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8060. }
  8061. dStruct.Order = "creata_time desc";
  8062. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8063. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8064. writeGridDataTableJson(dStruct.TotalCount, dt);
  8065. }
  8066. public void upd_erp_staygoods()
  8067. {
  8068. if (UrlPostParmsCheck("id"))
  8069. {
  8070. int eid = GetPostInt("id");
  8071. CeErpStayGoods entity = null;
  8072. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8073. if (entity != null)
  8074. {
  8075. entity.audit_type = 1;
  8076. entity.audit_time = DateTime.Now;
  8077. entity.audit_u_id = CurrentUser.UserID;
  8078. entity.audit_u_name = CurrentUser.UserName;
  8079. entity.Update();
  8080. returnSuccessMsg("审核成功!");
  8081. return;
  8082. }
  8083. returnErrorMsg("找不到订单记录");
  8084. }
  8085. }
  8086. public void upd_erp_stayGoodsback()
  8087. {
  8088. if (UrlPostParmsCheck("id"))
  8089. {
  8090. int eid = GetPostInt("id");
  8091. CeErpStayGoods entity = null;
  8092. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8093. if (entity != null)
  8094. {
  8095. entity.audit_text = GetPostString("reason");
  8096. entity.audit_type = 2;
  8097. entity.audit_time = DateTime.Now;
  8098. entity.audit_u_id = CurrentUser.UserID;
  8099. entity.audit_u_name = CurrentUser.UserName;
  8100. entity.Update();
  8101. returnSuccessMsg("退回成功!");
  8102. return;
  8103. }
  8104. returnErrorMsg("找不到订单记录");
  8105. }
  8106. }
  8107. public void upd_erp_returncashverify()
  8108. {
  8109. if (UrlPostParmsCheck("ID"))
  8110. {
  8111. int eid = GetPostInt("ID");
  8112. CeErpReturnCash entity = null;
  8113. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8114. if (entity != null)
  8115. {
  8116. entity.cashstate = 1;
  8117. entity.verifytime = DateTime.Now;
  8118. entity.verifyuserid = CurrentUser.UserID;
  8119. entity.Update();
  8120. returnSuccessMsg("审核成功!");
  8121. return;
  8122. }
  8123. returnErrorMsg("找不到订单记录");
  8124. }
  8125. }
  8126. public void upd_all_erp_returncashverify()
  8127. {
  8128. if (UrlPostParmsCheck("ID"))
  8129. {
  8130. String[] list = GetPostString("ID").Split(',');
  8131. CeErpReturnCash entity = null;
  8132. for (int i = 0; i < list.Length; i++)
  8133. {
  8134. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8135. if (entity != null)
  8136. {
  8137. if (entity.cashstate == 1)
  8138. {
  8139. returnErrorMsg("已审核过的订单不需要在审核!");
  8140. return;
  8141. }
  8142. entity.cashstate = 1;
  8143. entity.verifytime = DateTime.Now;
  8144. entity.verifyuserid = CurrentUser.UserID;
  8145. entity.Update();
  8146. }
  8147. }
  8148. returnSuccessMsg("审核成功!");
  8149. return;
  8150. }
  8151. }
  8152. public void upd_erp_returncashback()
  8153. {
  8154. if (UrlPostParmsCheck("ID"))
  8155. {
  8156. int eid = GetPostInt("ID");
  8157. CeErpReturnCash entity = null;
  8158. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8159. if (entity != null)
  8160. {
  8161. entity.backreason = GetPostString("reason");
  8162. entity.cashstate = 2;
  8163. entity.verifytime = DateTime.Now;
  8164. entity.verifyuserid = CurrentUser.UserID;
  8165. entity.Update();
  8166. returnSuccessMsg("退回成功!");
  8167. return;
  8168. }
  8169. returnErrorMsg("找不到订单记录");
  8170. }
  8171. }
  8172. public void upd_erp_returnprice()
  8173. {
  8174. if (UrlPostParmsCheck("ID"))
  8175. {
  8176. int eid = GetPostInt("ID");
  8177. CeErpReturnCash entity = null;
  8178. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8179. if (entity != null)
  8180. {
  8181. if (entity.cashstate == 1)
  8182. {
  8183. returnErrorMsg("审核通过了不能改");
  8184. return;
  8185. }
  8186. entity.returnprice = GetPostDouble("returnprice");
  8187. entity.Update();
  8188. returnSuccessMsg("修改成功!");
  8189. return;
  8190. }
  8191. returnErrorMsg("找不到订单记录");
  8192. }
  8193. }
  8194. public void del_erp_returncash()
  8195. {
  8196. if (UrlPostParmsCheck("ID"))
  8197. {
  8198. int eid = GetPostInt("ID");
  8199. CeErpReturnCash.Del(eid);
  8200. returnSuccessMsg("操作成功");
  8201. return;
  8202. }
  8203. }
  8204. public void test_for_do_sql()
  8205. {
  8206. string sql = GetPostString("sqlstr");
  8207. if (sql.Length > 0)
  8208. {
  8209. try
  8210. {
  8211. DbHelper.DbConn.ExecuteNonQuery(sql);
  8212. var res_obj = new
  8213. {
  8214. data = "成功",
  8215. };
  8216. string ro_json = JsonConvert.SerializeObject(res_obj);
  8217. returnSuccess(ro_json);
  8218. }
  8219. catch (Exception ex)
  8220. {
  8221. var res_obj = new
  8222. {
  8223. data = ex.Message,
  8224. };
  8225. string ro_json = JsonConvert.SerializeObject(res_obj);
  8226. returnSuccess(ro_json);
  8227. }
  8228. }
  8229. }
  8230. public void get_user_info()
  8231. {
  8232. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8233. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8234. }
  8235. public void get_total_data()
  8236. {
  8237. int userId = CurrentUser.UserID;
  8238. string sql = "";
  8239. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8240. {
  8241. 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);
  8242. }
  8243. else
  8244. {
  8245. 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 " +
  8246. "(select ID from CE_ErpUser where ID = {0}) d " +
  8247. "left join " +
  8248. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8249. ") a on d.ID = a.id left join " +
  8250. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8251. ") b on a.id = b.id1 left join" +
  8252. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8253. ") c on a.id = c.id2;", userId);
  8254. }
  8255. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8256. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8257. }
  8258. public void get_date_area_total_data2()
  8259. {
  8260. int userId = CurrentUser.UserID;
  8261. string date_type = GetPostString("timetype");
  8262. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8263. string sql = "";
  8264. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8265. {
  8266. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8267. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8268. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8269. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8270. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8271. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8272. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8273. ") a on e.ID = a.id left join " +
  8274. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8275. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8276. ") b on a.id = b.id1 " +
  8277. "left join " +
  8278. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8279. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8280. ") c on a.id = c.id2 " +
  8281. "left join " +
  8282. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8283. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8284. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8285. }
  8286. else
  8287. {
  8288. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8289. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8290. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8291. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8292. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8293. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8294. ") a on e.ID = a.id left join " +
  8295. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8296. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8297. ") c on a.id = c.id2 " +
  8298. "left join " +
  8299. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8300. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8301. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8302. }
  8303. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8304. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8305. }
  8306. public void get_date_area_total_data()
  8307. {
  8308. int userId = CurrentUser.UserID;
  8309. string date_type = GetPostString("timetype");
  8310. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8311. string date1 = searchDT[0].ToString();
  8312. string date2 = searchDT[1].ToString();
  8313. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8314. {
  8315. SqlParameter[] sqlParameter ={
  8316. new SqlParameter("@userId", SqlDbType.Int,4),
  8317. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8318. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8319. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8320. };
  8321. sqlParameter[0].Value = userId;
  8322. sqlParameter[1].Value = date1;
  8323. sqlParameter[2].Value = date2;
  8324. sqlParameter[3].Direction = ParameterDirection.Output;
  8325. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8326. string res = sqlParameter[3].Value.ToString();
  8327. var res_obj = new
  8328. {
  8329. data = res
  8330. };
  8331. string ro_json = JsonConvert.SerializeObject(res_obj);
  8332. returnSuccess(ro_json);
  8333. }
  8334. else
  8335. {
  8336. SqlParameter[] sqlParameter ={
  8337. new SqlParameter("@userId", SqlDbType.Int,4),
  8338. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8339. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8340. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8341. };
  8342. sqlParameter[0].Value = userId;
  8343. sqlParameter[1].Value = date1;
  8344. sqlParameter[2].Value = date2;
  8345. sqlParameter[3].Direction = ParameterDirection.Output;
  8346. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  8347. string res = sqlParameter[3].Value.ToString();
  8348. var res_obj = new
  8349. {
  8350. data = res
  8351. };
  8352. string ro_json = JsonConvert.SerializeObject(res_obj);
  8353. returnSuccess(ro_json);
  8354. }
  8355. //writeGridDataViewJson(dt.Rows.Count, dv);
  8356. }
  8357. public void get_order_list()
  8358. {
  8359. string strFields = GetPostString("paraFields");
  8360. string strOrder = GetPostString("paraOrder");
  8361. string strWhere = GetPostString("paraWhere");
  8362. string strPageSize = GetPostString("paraPageSize");
  8363. DataStruct dStruct = GetPostStruct();
  8364. dStruct.PageSize = int.Parse(strPageSize);
  8365. dStruct.Fileds = strFields;
  8366. dStruct.Order = strOrder;
  8367. dStruct.MainWhere = strWhere;
  8368. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8369. writeGridDataTableJson(dStruct.TotalCount, dt);
  8370. }
  8371. ////获取待开始订单列表
  8372. //public void get_wait_design_order_list()
  8373. //{
  8374. // string date_type = GetPostString("date_type");
  8375. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8376. // DataStruct dStruct = GetPostStruct();
  8377. // dStruct.PageSize = 1000;
  8378. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  8379. // List<string> lw = new List<string>();
  8380. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  8381. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  8382. // dStruct.Order = "WaitDesignTime asc";
  8383. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8384. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8385. // writeGridDataTableJson(dStruct.TotalCount, dt);
  8386. //}
  8387. //获取完成单量排名
  8388. public void get_finish_order_count_ranking()
  8389. {
  8390. /* string date_type = GetPostString("date_type");
  8391. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8392. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  8393. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8394. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  8395. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  8396. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8397. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  8398. writeGridDataTableJson(0, new DataTable());
  8399. }
  8400. public void get_finish_order_amount_ranking()
  8401. {
  8402. /*string date_type = GetPostString("date_type");
  8403. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8404. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  8405. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8406. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  8407. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  8408. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8409. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  8410. writeGridDataTableJson(0, new DataTable());
  8411. }
  8412. public void get_finish_refund_count_ranking()
  8413. {
  8414. string date_type = GetPostString("date_type");
  8415. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8416. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  8417. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8418. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  8419. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  8420. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8421. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8422. writeGridDataTableJson(dt.Rows.Count, dt);
  8423. }
  8424. public void get_finish_refund_amount_ranking()
  8425. {
  8426. string date_type = GetPostString("date_type");
  8427. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8428. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  8429. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8430. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  8431. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  8432. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8433. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8434. writeGridDataTableJson(dt.Rows.Count, dt);
  8435. }
  8436. public void set_erp_finishorder_director()
  8437. {
  8438. if (UrlPostParmsCheck("ctid"))
  8439. {
  8440. string eid = GetPostString("ctid");
  8441. CeErpTradeCell entity = null;
  8442. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  8443. if (entity != null)
  8444. {
  8445. entity.OrderState = 8;
  8446. entity.Update();
  8447. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  8448. returnSuccessMsg("操作成功!");
  8449. return;
  8450. }
  8451. returnErrorMsg("找不到记录");
  8452. }
  8453. }
  8454. public void get_erp_placeregistlist()
  8455. {
  8456. DataStruct dStruct = GetPostStruct();
  8457. List<string> lw = new List<string>();
  8458. string outsid = GetPostString("outsid");
  8459. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  8460. string memo = GetPostString("memo");
  8461. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  8462. string filename = GetPostString("filename");
  8463. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  8464. string islate = GetPostString("islate");
  8465. if (islate.Length > 0)
  8466. {
  8467. if (islate == "1")
  8468. lw.Add(string.Format("OutLate>0"));
  8469. else
  8470. lw.Add(string.Format("OutLate=0"));
  8471. }
  8472. string placedate1 = GetPostString("placedate1");
  8473. string placedate2 = GetPostString("placedate2");
  8474. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  8475. if (dw.Length > 0) lw.Add(dw);
  8476. string deliveryDate1 = GetPostString("deliverydate1");
  8477. string deliveryDate2 = GetPostString("deliverydate2");
  8478. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  8479. if (dw_deli.Length > 0) lw.Add(dw_deli);
  8480. dStruct.Order = "ID desc";
  8481. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8482. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  8483. writeGridDataTableJson(dStruct.TotalCount, dt);
  8484. }
  8485. public void ins_erp_placeregist()
  8486. {
  8487. if (UrlPostParmsCheck("id"))
  8488. {
  8489. string eid = GetPostString("id");
  8490. CeErpPlaceRegister entity = null;
  8491. if (eid == "0")//新增
  8492. {
  8493. entity = new CeErpPlaceRegister();
  8494. string xdTime = GetPostString("placeTime");
  8495. if (xdTime.Length > 0)
  8496. {
  8497. entity.PlactTime = Convert.ToDateTime(xdTime);
  8498. }
  8499. string fhTime = GetPostString("deliveryTime");
  8500. if (fhTime.Length > 0)
  8501. {
  8502. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  8503. }
  8504. string preTime = GetPostString("preOutTime");
  8505. if (preTime.Length > 0)
  8506. {
  8507. entity.PreOutTime = Convert.ToDateTime(preTime);
  8508. }
  8509. entity.DeliveryCount = GetPostInt("deliveryCount");
  8510. entity.ReceiveCount = GetPostInt("receiveCount");
  8511. entity.OutSid = GetPostString("outSid");
  8512. entity.FileName = GetPostString("fileName");
  8513. entity.Memo = GetPostString("memo");
  8514. entity.AddUserId = CurrentUser.UserID;
  8515. entity.CreateTime = DateTime.Now;
  8516. entity.Img = GetPostString("img");
  8517. entity.Supplier = GetPostInt("supplier");
  8518. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  8519. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  8520. {
  8521. DateTime dt1 = (DateTime)entity.DeliveryTime;
  8522. DateTime dt2 = (DateTime)entity.PreOutTime;
  8523. TimeSpan span = dt1.Subtract(dt2);
  8524. if (span.Days > 0)
  8525. {
  8526. entity.OutLate = span.Days;
  8527. }
  8528. }
  8529. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  8530. entity.Create();
  8531. returnSuccessMsg("添加成功!");
  8532. return;
  8533. }
  8534. else //修改
  8535. {
  8536. entity = CeErpPlaceRegister.Get(eid);
  8537. if (entity != null)
  8538. {
  8539. string xdTime = GetPostString("placeTime");
  8540. if (xdTime.Length > 0)
  8541. {
  8542. entity.PlactTime = Convert.ToDateTime(xdTime);
  8543. }
  8544. string fhTime = GetPostString("deliveryTime");
  8545. if (fhTime.Length > 0)
  8546. {
  8547. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  8548. }
  8549. string preTime = GetPostString("preOutTime");
  8550. if (preTime.Length > 0)
  8551. {
  8552. entity.PreOutTime = Convert.ToDateTime(preTime);
  8553. }
  8554. entity.DeliveryCount = GetPostInt("deliveryCount");
  8555. entity.ReceiveCount = GetPostInt("receiveCount");
  8556. if (entity.DeliveryCount == entity.ReceiveCount)
  8557. {
  8558. entity.CurState = "已完成";
  8559. }
  8560. else
  8561. {
  8562. entity.CurState = "未完成";
  8563. }
  8564. entity.OutSid = GetPostString("outSid");
  8565. entity.FileName = GetPostString("fileName");
  8566. entity.Memo = GetPostString("memo");
  8567. entity.Img = GetPostString("img");
  8568. entity.Supplier = GetPostInt("supplier");
  8569. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  8570. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  8571. {
  8572. DateTime dt1 = (DateTime)entity.DeliveryTime;
  8573. DateTime dt2 = (DateTime)entity.PreOutTime;
  8574. TimeSpan span = dt1.Subtract(dt2);
  8575. if (span.Days > 0)
  8576. {
  8577. entity.OutLate = span.Days;
  8578. }
  8579. }
  8580. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  8581. entity.Update();
  8582. returnSuccessMsg("修改成功");
  8583. return;
  8584. }
  8585. returnErrorMsg("找不到对应的记录");
  8586. return;
  8587. }
  8588. }
  8589. returnErrorMsg("缺少必要参数");
  8590. }
  8591. public void del_erp_placeregist()
  8592. {
  8593. string eid = GetPostString("id");
  8594. CeErpPlaceRegister.Del(eid);
  8595. returnSuccessMsg("删除成功!");
  8596. return;
  8597. }
  8598. public void ins_erp_placeregistbyorder()
  8599. {
  8600. string ctid = GetPostString("ctid");
  8601. if (ctid.Length > 0)
  8602. {
  8603. StringBuilder sql = new StringBuilder();
  8604. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  8605. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  8606. if (dt.Rows.Count > 0)
  8607. {
  8608. foreach (DataRow dr in dt.Rows)
  8609. {
  8610. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  8611. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  8612. entity.AddUserId = CurrentUser.UserID;
  8613. entity.tid = dr["tid"].ToString();
  8614. entity.Did = Convert.ToString(dr["ctid"]);
  8615. entity.splitTag = dr["SplitTag"].ToString();
  8616. string sellmemo = Convert.ToString(dr["seller_memo"]);
  8617. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  8618. if (pre_ctid.Length > 0)
  8619. {
  8620. sellmemo = sellmemo.Replace(pre_ctid, "");
  8621. }
  8622. sellmemo = sellmemo.Replace("[", "");
  8623. sellmemo = sellmemo.Replace("]", "");
  8624. entity.FileName = sellmemo;
  8625. string count = dr["ProductCount"].ToString();
  8626. int usecount = commonHelper.getIntCountFromString(count);
  8627. entity.DeliveryCount = usecount;
  8628. entity.CurState = "未完成";
  8629. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  8630. {
  8631. entity.Supplier = 24;//dl手提袋定制
  8632. }
  8633. else
  8634. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  8635. entity.CreateTime = DateTime.Now;
  8636. entity.Create();
  8637. }
  8638. returnSuccessMsg("操作成功");
  8639. return;
  8640. }
  8641. returnErrorMsg("没有找到对应订单");
  8642. return;
  8643. }
  8644. returnErrorMsg("缺少订单编号");
  8645. return;
  8646. }
  8647. public void get_erp_persuadelist()
  8648. {
  8649. DataStruct dStruct = GetPostStruct();
  8650. List<string> lw = new List<string>();
  8651. string ctid = GetPostString("ctid");
  8652. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  8653. string shopname = GetPostString("shopname");
  8654. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8655. string buyernick = GetPostString("buyer_nick");
  8656. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8657. string customer = GetPostString("customer");
  8658. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8659. string returndate1 = GetPostString("returndate1");
  8660. string returndate2 = GetPostString("returndate2");
  8661. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8662. if (dw.Length > 0) lw.Add(dw);
  8663. string finishDate1 = GetPostString("finishdate1");
  8664. string finishDate2 = GetPostString("finishdate2");
  8665. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8666. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8667. string persuadetype = GetPostString("persuadetype");
  8668. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  8669. string returnvstate = GetPostString("returnvstate");
  8670. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  8671. dStruct.Order = "created desc";
  8672. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8673. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  8674. writeGridDataTableJson(dStruct.TotalCount, dt);
  8675. }
  8676. public void upd_erp_returnpersuadeback()
  8677. {
  8678. if (UrlPostParmsCheck("ID"))
  8679. {
  8680. int eid = GetPostInt("ID");
  8681. CeErpPersuade entity = null;
  8682. if (eid != 0) entity = CeErpPersuade.Get(eid);
  8683. if (entity != null)
  8684. {
  8685. entity.backreason = GetPostString("reason");
  8686. entity.pstate = 2;
  8687. entity.verifytime = DateTime.Now;
  8688. entity.verifyuserid = CurrentUser.UserID;
  8689. entity.Update();
  8690. returnSuccessMsg("退回成功!");
  8691. return;
  8692. }
  8693. returnErrorMsg("找不到订单记录");
  8694. }
  8695. }
  8696. public void upd_erp_returnpersuadeverify()
  8697. {
  8698. if (UrlPostParmsCheck("ID"))
  8699. {
  8700. if (CurrentUser.UserPost.Post.Code != "Summarize")
  8701. {
  8702. returnErrorMsg("暂无权限审核");
  8703. return;
  8704. }
  8705. int eid = GetPostInt("ID");
  8706. CeErpPersuade entity = null;
  8707. if (eid != 0) entity = CeErpPersuade.Get(eid);
  8708. if (entity != null)
  8709. {
  8710. entity.pstate = 1;
  8711. entity.verifytime = DateTime.Now;
  8712. entity.verifyuserid = CurrentUser.UserID;
  8713. entity.Update();
  8714. returnSuccessMsg("审核成功!");
  8715. return;
  8716. }
  8717. returnErrorMsg("找不到订单记录");
  8718. }
  8719. }
  8720. public void del_erp_persuade()
  8721. {
  8722. if (UrlPostParmsCheck("ID"))
  8723. {
  8724. int eid = GetPostInt("ID");
  8725. CeErpPersuade.Del(eid);
  8726. returnSuccessMsg("操作成功");
  8727. return;
  8728. }
  8729. }
  8730. public void get_erp_oldcustoupload()
  8731. {
  8732. DataStruct dStruct = GetPostStruct();
  8733. List<string> lw = new List<string>();
  8734. string buyernick = GetPostString("buyer_nick");
  8735. if (buyernick.Length > 0)
  8736. {
  8737. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8738. }
  8739. else
  8740. return;
  8741. dStruct.Order = "pay_time desc";
  8742. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8743. DataTable dt = null;
  8744. dt = WebCache.GetData("view_erptradecell", dStruct);
  8745. writeGridDataTableJson(dStruct.TotalCount, dt);
  8746. }
  8747. public void get_erp_checkorderlist()
  8748. {
  8749. DataStruct dStruct = GetPostStruct();
  8750. List<string> lw = new List<string>();
  8751. string tid = GetPostString("ctid");
  8752. if (tid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", tid));
  8753. string shopname = GetPostString("shopname");
  8754. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8755. string buyernick = GetPostString("buyer_nick");
  8756. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  8757. string customer = GetPostString("customer");
  8758. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8759. string design = GetPostString("design");
  8760. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8761. string orderState = GetPostString("orderState");
  8762. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  8763. string address = GetPostString("address");
  8764. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  8765. string sellermemo = GetPostString("seller_memo");
  8766. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8767. string supplier = GetPostString("supplier");
  8768. if (CurrentUser.UserPost.Post.Code == "Supplier")
  8769. {
  8770. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  8771. }
  8772. else
  8773. {
  8774. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  8775. }
  8776. string date1 = GetPostString("date1");
  8777. string date2 = GetPostString("date2");
  8778. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8779. if (dw.Length > 0) lw.Add(dw);
  8780. string placedate1 = GetPostString("placedate1");
  8781. string placedate2 = GetPostString("placedate2");
  8782. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  8783. if (fdw.Length > 0) lw.Add(fdw);
  8784. string price1 = GetPostString("price1");
  8785. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8786. string price2 = GetPostString("price2");
  8787. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8788. string checkst = GetPostString("checkstate");
  8789. if (checkst.Length > 0 && "10".Equals(checkst))
  8790. {
  8791. lw.Add(string.Format("CheckOut>0"));
  8792. }
  8793. else
  8794. {
  8795. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  8796. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  8797. }
  8798. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  8799. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8800. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  8801. writeGridDataTableJson(dStruct.TotalCount, dt);
  8802. }
  8803. public void ins_erp_startCheck()
  8804. {
  8805. if (UrlPostParmsCheck("ctid"))
  8806. {
  8807. string eid = GetPostString("ctid");
  8808. CeErpTradeCell entity = null;
  8809. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  8810. if (entity != null)
  8811. {
  8812. entity.MemoOpt = 4;
  8813. entity.Update();
  8814. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  8815. CeErpSukuraData.createInfo(entity.ctid, 6);
  8816. returnSuccessMsg("操作成功!");
  8817. return;
  8818. }
  8819. returnErrorMsg("找不到记录");
  8820. }
  8821. }
  8822. public void upd_erp_sendXlw()
  8823. {
  8824. if (UrlPostParmsCheck("ctid"))
  8825. {
  8826. string eid = GetPostString("ctid");
  8827. CeErpTradeCell entity = null;
  8828. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  8829. if (entity != null)
  8830. {
  8831. if (entity.IsSendGift == 1)
  8832. {
  8833. returnErrorMsg("请勿重复标记");
  8834. return;
  8835. }
  8836. entity.IsSendGift = 1;
  8837. entity.Update();
  8838. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  8839. returnSuccessMsg("操作成功!");
  8840. return;
  8841. }
  8842. returnErrorMsg("找不到记录");
  8843. }
  8844. }
  8845. public void cancel_sendXlw()
  8846. {
  8847. if (UrlPostParmsCheck("ctid"))
  8848. {
  8849. string eid = GetPostString("ctid");
  8850. CeErpTradeCell entity = null;
  8851. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  8852. if (entity != null)
  8853. {
  8854. if (entity.IsSendGift == 0)
  8855. {
  8856. returnErrorMsg("未标记小礼物");
  8857. return;
  8858. }
  8859. entity.IsSendGift = 0;
  8860. entity.Update();
  8861. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  8862. returnSuccessMsg("操作成功!");
  8863. return;
  8864. }
  8865. returnErrorMsg("找不到记录");
  8866. }
  8867. }
  8868. public void get_erp_designbill()
  8869. {
  8870. DataStruct dStruct = GetPostStruct();
  8871. List<string> lw = new List<string>();
  8872. int isMy = GetInt("my");
  8873. if (isMy == 1)
  8874. {
  8875. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  8876. }
  8877. string tid = GetPostString("tid");
  8878. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8879. string userName = GetPostString("design");
  8880. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  8881. string price1 = GetPostString("price1");
  8882. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  8883. string price2 = GetPostString("price2");
  8884. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  8885. string rePrice1 = GetPostString("rePrice1");
  8886. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  8887. string rePrice2 = GetPostString("rePrice2");
  8888. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  8889. string designerType = GetPostString("designerType");
  8890. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  8891. string orderState = GetPostString("orderState");
  8892. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  8893. string endTime1 = GetPostString("endTime1");
  8894. string endTime2 = GetPostString("endTime2");
  8895. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  8896. if (dw.Length > 0) lw.Add(dw);
  8897. string isDk = GetPostString("isDk");
  8898. if (isDk == "1")
  8899. {
  8900. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  8901. }
  8902. else if (isDk == "0")
  8903. {
  8904. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  8905. }
  8906. dStruct.Order = "oid, create_time desc";
  8907. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8908. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  8909. writeGridDataTableJson(dStruct.TotalCount, dt);
  8910. }
  8911. public void upd_erp_designerbill()
  8912. {
  8913. if (UrlPostParmsCheck("ID"))
  8914. {
  8915. string eid = GetPostString("ID");
  8916. CeErpDesignerBill entity = null;
  8917. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  8918. if (entity != null)
  8919. {
  8920. if (GetPostDouble("designerpirce") > 0)
  8921. {
  8922. entity.realPrice = GetPostDouble("designerpirce");
  8923. entity.update_time = DateTime.Now;
  8924. entity.update_u_id = CurrentUser.UserID;
  8925. entity.update_u_name = CurrentUser.UserName;
  8926. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  8927. entity.Update();
  8928. returnSuccessMsg("操作成功!");
  8929. return;
  8930. }
  8931. else
  8932. {
  8933. entity.price = GetPostDouble("price");
  8934. entity.update_time = DateTime.Now;
  8935. entity.update_u_id = CurrentUser.UserID;
  8936. entity.update_u_name = CurrentUser.UserName;
  8937. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  8938. entity.Update();
  8939. returnSuccessMsg("操作成功!");
  8940. return;
  8941. }
  8942. }
  8943. returnErrorMsg("找不到记录");
  8944. }
  8945. }
  8946. public void audit_erp_designerbill()
  8947. {
  8948. if (UrlPostParmsCheck("ID"))
  8949. {
  8950. string eid = GetPostString("ID");
  8951. CeErpDesignerBill entity = null;
  8952. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  8953. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  8954. if (entity != null)
  8955. {
  8956. entity.realPrice = GetPostDouble("designerpirce");
  8957. entity.update_time = DateTime.Now;
  8958. entity.update_u_id = CurrentUser.UserID;
  8959. entity.update_u_name = CurrentUser.UserName;
  8960. entity.isAudit = 1;
  8961. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  8962. entity.Update();
  8963. if (orderEntity != null)
  8964. {
  8965. orderEntity.IsReadTag = 3;
  8966. orderEntity.Update();
  8967. }
  8968. returnSuccessMsg("操作成功!");
  8969. return;
  8970. }
  8971. returnErrorMsg("找不到记录");
  8972. }
  8973. }
  8974. public void all_audit_erp_designerbill()
  8975. {
  8976. if (UrlPostParmsCheck("idList"))
  8977. {
  8978. string[] list = GetPostString("idList").Split(',');
  8979. CeErpDesignerBill entity = null;
  8980. for (int i = 0; i < list.Length; i++)
  8981. {
  8982. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  8983. if (entity == null) return;
  8984. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  8985. if (orderEntity == null) return;
  8986. if (entity.realPrice == 0) entity.realPrice = entity.price;
  8987. entity.update_time = DateTime.Now;
  8988. entity.update_u_id = CurrentUser.UserID;
  8989. entity.update_u_name = CurrentUser.UserName;
  8990. entity.isAudit = 1;
  8991. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  8992. entity.Update();
  8993. orderEntity.IsReadTag = 3;
  8994. orderEntity.Update();
  8995. }
  8996. returnSuccessMsg("操作成功!");
  8997. return;
  8998. }
  8999. }
  9000. public void get_erp_sameorders()
  9001. {
  9002. if (UrlPostParmsCheck("ctid"))
  9003. {
  9004. string eid = GetPostString("ctid");
  9005. CeErpTradeCell entity = null;
  9006. entity = CeErpTradeCell.GetByCtid(eid);
  9007. if (entity != null)
  9008. {
  9009. StringBuilder sql = new StringBuilder();
  9010. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9011. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9012. var res = new
  9013. {
  9014. data = dt.Rows.Count
  9015. };
  9016. string ro_jsond = JsonConvert.SerializeObject(res);
  9017. returnSuccess(ro_jsond);
  9018. return;
  9019. }
  9020. returnErrorMsg("未找到订单");
  9021. return;
  9022. }
  9023. returnErrorMsg("缺少必要的参数");
  9024. }
  9025. public void get_erp_islasthavesameorder()
  9026. {
  9027. if (UrlPostParmsCheck("ctid"))
  9028. {
  9029. string eid = GetPostString("ctid");
  9030. string[] ctidList = eid.Split(',');
  9031. StringBuilder sql = new StringBuilder();
  9032. string tisCtid = "";
  9033. foreach (string ctid in ctidList)
  9034. {
  9035. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9036. if (entity != null)
  9037. {
  9038. sql = new StringBuilder();
  9039. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9040. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9041. if (dth.Rows.Count > 0)
  9042. {
  9043. tisCtid += entity.ctid;
  9044. tisCtid += ",";
  9045. }
  9046. }
  9047. }
  9048. if (tisCtid.Length > 0)
  9049. {
  9050. var res = new
  9051. {
  9052. data = tisCtid
  9053. };
  9054. string ro_jsond = JsonConvert.SerializeObject(res);
  9055. returnSuccess(ro_jsond);
  9056. }
  9057. else
  9058. {
  9059. var res = new
  9060. {
  9061. data = ""
  9062. };
  9063. string ro_jsond = JsonConvert.SerializeObject(res);
  9064. returnSuccess(ro_jsond);
  9065. }
  9066. return;
  9067. }
  9068. returnErrorMsg("缺少必要的参数");
  9069. }
  9070. public void file_client_down_url()
  9071. {
  9072. if (!UrlPostParmsCheck("userId"))
  9073. {
  9074. returnErrorMsg("缺少必要的参数");
  9075. }
  9076. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9077. }
  9078. public void checkout_form_data()
  9079. {
  9080. if (!UrlPostParmsCheck("tid"))
  9081. {
  9082. returnErrorMsg("缺少必要的参数");
  9083. }
  9084. string tid = GetPostString("tid");
  9085. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9086. if (ceErpOrderFormData != null)
  9087. {
  9088. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9089. returnSuccess(ro_jsond);
  9090. return;
  9091. }
  9092. returnErrorMsg("尚未有文件!");
  9093. }
  9094. public void back_supplier_audit()
  9095. {
  9096. int userId = CurrentUser.UserID;
  9097. StringBuilder sql = new StringBuilder();
  9098. 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);
  9099. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9100. if (dt.Rows.Count > 0)
  9101. {
  9102. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9103. }
  9104. else
  9105. {
  9106. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9107. }
  9108. }
  9109. public void back_supplier_query()
  9110. {
  9111. string eid = GetPostString("ctid");
  9112. if (eid != "")
  9113. {
  9114. StringBuilder sql = new StringBuilder();
  9115. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9116. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9117. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9118. }
  9119. else
  9120. {
  9121. returnErrorMsg("找不到订单记录");
  9122. return;
  9123. }
  9124. }
  9125. public void verified_to_order()
  9126. {
  9127. int userId = CurrentUser.UserID;
  9128. StringBuilder sql = new StringBuilder();
  9129. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9130. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9131. if (dt.Rows.Count > 0)
  9132. {
  9133. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9134. }
  9135. else
  9136. {
  9137. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9138. }
  9139. }
  9140. public void upd_supplier_audit()
  9141. {
  9142. if (UrlPostParmsCheck("ctid"))
  9143. {
  9144. string eid = GetPostString("ctid");
  9145. string reason = GetPostString("returnreason");
  9146. CeErpTradeCell entity = null;
  9147. CeWithdraw withdraw = null;
  9148. withdraw = CeWithdraw.GetByTid(eid);
  9149. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9150. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9151. {
  9152. if (withdraw != null)
  9153. {
  9154. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9155. {
  9156. returnSuccessMsg("您没有权限操作!");
  9157. return;
  9158. }
  9159. else
  9160. {
  9161. if (reason.Equals("1"))
  9162. {
  9163. if (entity.OrderState == -1)
  9164. {
  9165. if (entity.FinishPlaceTime == null)
  9166. {
  9167. entity.OrderState = 2;
  9168. }
  9169. else
  9170. {
  9171. entity.OrderState = 6;
  9172. }
  9173. }
  9174. entity.Update();
  9175. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9176. if (withdraw != null)
  9177. {
  9178. withdraw.status = int.Parse(reason);
  9179. withdraw.Update();
  9180. }
  9181. returnSuccessMsg("操作成功!");
  9182. return;
  9183. }
  9184. else
  9185. {
  9186. withdraw.status = int.Parse(reason);
  9187. withdraw.acknowledgingtime = DateTime.Now;
  9188. withdraw.Update();
  9189. returnSuccessMsg("查看详细请点击线下订单查询");
  9190. return;
  9191. }
  9192. }
  9193. }
  9194. // 第一个字符是 'N'
  9195. }
  9196. if (eid[0] != 'N')
  9197. {
  9198. }
  9199. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9200. {
  9201. entity.IsVerifyToSupplier = false;
  9202. entity.IsReturn = 1;
  9203. entity.ReturnTime = DateTime.Now;
  9204. entity.ReturnReason = reason;
  9205. if (entity.OrderState == 6)
  9206. {
  9207. entity.OrderState = 5;
  9208. }
  9209. entity.Update();
  9210. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9211. if (withdraw != null)
  9212. {
  9213. withdraw.status = int.Parse(reason);
  9214. withdraw.Update();
  9215. }
  9216. returnSuccessMsg("操作成功!");
  9217. return;
  9218. }
  9219. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9220. {
  9221. ;
  9222. if (withdraw != null)
  9223. {
  9224. withdraw.status = int.Parse(reason);
  9225. withdraw.acknowledgingtime = DateTime.Now;
  9226. withdraw.Update();
  9227. returnSuccessMsg("供应商取消撤回!");
  9228. return;
  9229. }
  9230. }
  9231. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9232. {
  9233. if (entity.OrderState == -1)
  9234. {
  9235. if (entity.FinishPlaceTime == null)
  9236. {
  9237. entity.OrderState = 2;
  9238. }
  9239. else
  9240. {
  9241. entity.OrderState = 3;
  9242. }
  9243. commonHelper.getCytPrice(entity);
  9244. }
  9245. entity.Update();
  9246. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9247. if (withdraw != null)
  9248. {
  9249. withdraw.status = int.Parse(reason);
  9250. withdraw.Update();
  9251. }
  9252. returnSuccessMsg("操作成功!");
  9253. return;
  9254. }
  9255. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9256. {
  9257. if (withdraw == null)
  9258. {
  9259. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9260. return;
  9261. }
  9262. }
  9263. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9264. {
  9265. if (withdraw != null)
  9266. {
  9267. withdraw.status = int.Parse(reason);
  9268. withdraw.acknowledgingtime = DateTime.Now;
  9269. withdraw.Update();
  9270. returnSuccessMsg("查看详细请点击线下订单查询");
  9271. return;
  9272. }
  9273. }
  9274. return;
  9275. }
  9276. }
  9277. //校验报价
  9278. public void refund_order_tip()
  9279. {
  9280. int userid = CurrentUser.UserID;
  9281. int sectionId = CurrentUser.UserPost.OrgID;
  9282. StringBuilder sql = new StringBuilder();
  9283. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9284. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9285. List<string> ids = new List<string>();
  9286. if (dth.Rows.Count > 0)
  9287. {
  9288. foreach (DataRow dr in dth.Rows)
  9289. {
  9290. ids.Add(dr["ID"].ToString());
  9291. }
  9292. try
  9293. {
  9294. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9295. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9296. }
  9297. catch (Exception ex)
  9298. {
  9299. }
  9300. }
  9301. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9302. }
  9303. public void refund_order_Design()
  9304. {
  9305. int userid = CurrentUser.UserID;
  9306. int sectionId = CurrentUser.UserPost.OrgID;
  9307. StringBuilder sql = new StringBuilder();
  9308. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9309. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9310. List<string> ids = new List<string>();
  9311. if (dth.Rows.Count > 0)
  9312. {
  9313. foreach (DataRow dr in dth.Rows)
  9314. {
  9315. ids.Add(dr["ID"].ToString());
  9316. }
  9317. try
  9318. {
  9319. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9320. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9321. }
  9322. catch (Exception ex)
  9323. {
  9324. }
  9325. }
  9326. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9327. }
  9328. public void change_order_info()
  9329. {
  9330. int userid = CurrentUser.UserID;
  9331. StringBuilder sql = new StringBuilder();
  9332. 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);
  9333. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9334. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  9335. }
  9336. public void change_win_mome()
  9337. {
  9338. if (UrlPostParmsCheck("id,ctid"))
  9339. {
  9340. string id = GetPostString("id");
  9341. string ctid = GetPostString("ctid");
  9342. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  9343. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  9344. if (ce == null || ceErpMessageTip == null)
  9345. {
  9346. returnSuccessMsg("未找到对应的订单!");
  9347. return;
  9348. }
  9349. int type = GetPostInt("type");
  9350. string content = GetPostString("content");
  9351. if (type == 0)
  9352. {
  9353. content = content.Replace("(", "(");
  9354. content = content.Replace(")", ")");
  9355. string check = MidStrEx(content, "(", ")").Trim();
  9356. if (string.IsNullOrEmpty(check))
  9357. {
  9358. returnSuccessMsg("文件名格式不正确");
  9359. return;
  9360. }
  9361. }
  9362. ce.seller_memo = content;
  9363. ce.Update();
  9364. ceErpMessageTip.isVisit = true;
  9365. ceErpMessageTip.Update();
  9366. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  9367. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  9368. ApiVo apiVo = new ApiVo();
  9369. apiVo.orderNumber = ce.ctid;
  9370. apiVo.actionName = "demandDesign";
  9371. apiVo.orderRemarks = content;
  9372. apiVo.demandExamine = type + 1;
  9373. designHelper.API_WorkCore(apiVo);//demandDesign
  9374. returnSuccessMsg("修改成功!");
  9375. }
  9376. }
  9377. public static string MidStrEx(string sourse, string startstr, string endstr)
  9378. {
  9379. string result = string.Empty;
  9380. int startindex, endindex;
  9381. try
  9382. {
  9383. startindex = sourse.IndexOf(startstr);
  9384. if (startindex == -1)
  9385. return result;
  9386. string tmpstr = sourse.Substring(startindex + startstr.Length);
  9387. endindex = tmpstr.IndexOf(endstr);
  9388. if (endindex == -1)
  9389. return result;
  9390. result = tmpstr.Remove(endindex);
  9391. }
  9392. catch (Exception ex)
  9393. {
  9394. Console.WriteLine("MidStrEx Err:" + ex.Message);
  9395. }
  9396. return result;
  9397. }
  9398. public void refund_order_list()
  9399. {
  9400. int userid = CurrentUser.UserID;
  9401. int sectionId = CurrentUser.UserPost.OrgID;
  9402. StringBuilder sql = new StringBuilder();
  9403. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  9404. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9405. DataStruct dStruct = GetPostStruct();
  9406. DataTable dt = null;
  9407. List<string> ids = new List<string>();
  9408. List<string> tids = new List<string>();
  9409. if (dth.Rows.Count > 0)
  9410. {
  9411. foreach (DataRow dr in dth.Rows)
  9412. {
  9413. tids.Add("'" + dr["tid"].ToString() + "'");
  9414. ids.Add(dr["id"].ToString());
  9415. }
  9416. try
  9417. {
  9418. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  9419. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9420. List<string> lw = new List<string>();
  9421. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  9422. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9423. dt = WebCache.GetData("view_orderlist", dStruct);
  9424. }
  9425. catch (Exception ex)
  9426. {
  9427. }
  9428. }
  9429. writeGridDataTableJson(dStruct.TotalCount, dt);
  9430. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  9431. }
  9432. //新增
  9433. public void order_batch_downloads()
  9434. {
  9435. string ceid = GetPostString("tid");
  9436. String[] tid = ceid.Split(',');
  9437. order_batch_caiyingtong(tid);
  9438. /* (string success, string errors) = UploadFiles(tid);
  9439. returnSuccessMsg(success + errors);*/
  9440. return;
  9441. }
  9442. //报价接口
  9443. public void Get_To_Quote()
  9444. {
  9445. string ceid = GetPostString("ctid");
  9446. if (ceid != null)
  9447. {
  9448. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  9449. if (entity != null)
  9450. {
  9451. if (entity.seller_memo.IndexOf("种子纸") > -1)
  9452. {
  9453. return;
  9454. }
  9455. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  9456. double price = 0;
  9457. if (cp == null)
  9458. {
  9459. JObject jsonObject12 = new JObject
  9460. {
  9461. { "UserId", "77886" },
  9462. { "Pwd", "lt666888" },
  9463. { "Filename", entity.seller_memo }
  9464. };
  9465. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  9466. JObject jsonObjects1 = JObject.Parse(response1);
  9467. string ms1g = (string)jsonObjects1["msg"];
  9468. if (ms1g == "报价成功")
  9469. {
  9470. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  9471. string data = (string)jsonObject1["price"];
  9472. 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 + "');";
  9473. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9474. returnSuccessMsg("获取报价成功:" + data);
  9475. price = Convert.ToDouble(data);
  9476. }
  9477. else
  9478. {
  9479. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  9480. return;
  9481. }
  9482. }
  9483. String[] beizhu = entity.seller_memo.Split('-');
  9484. String chanp = "";
  9485. if (beizhu.Length > 0)
  9486. {
  9487. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  9488. }
  9489. else
  9490. {
  9491. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  9492. }
  9493. JObject jsonObject = new JObject
  9494. {
  9495. { "UserId", "77886" },
  9496. { "Pwd", "lt666888" },
  9497. { "Filename", chanp }
  9498. };
  9499. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  9500. JObject jsonObjects = JObject.Parse(response);
  9501. string msg = (string)jsonObjects["msg"];
  9502. if (msg == "报价成功")
  9503. {
  9504. JObject jsonObject1 = (JObject)jsonObjects["data"];
  9505. string data = (string)jsonObject1["price"];
  9506. 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 + "');";
  9507. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9508. returnSuccessMsg("获取报价成功:" + data);
  9509. price = Convert.ToDouble(data);
  9510. }
  9511. else
  9512. {
  9513. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  9514. return;
  9515. }
  9516. if (price > 0)
  9517. {
  9518. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9519. if (ceErpTradeCellExtend == null)
  9520. {
  9521. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  9522. ceErpTradeCellExtend.ctid = entity.ctid;
  9523. ceErpTradeCellExtend.payment_cyt = price;
  9524. ceErpTradeCellExtend.Create();
  9525. }
  9526. else
  9527. {
  9528. ceErpTradeCellExtend.payment_cyt = price;
  9529. ceErpTradeCellExtend.Update();
  9530. }
  9531. }
  9532. return;
  9533. }
  9534. }
  9535. else
  9536. {
  9537. returnErrorMsg("请至少选择一条数据");
  9538. return;
  9539. }
  9540. }
  9541. //新增
  9542. public void order_To_Supplier()
  9543. {
  9544. string ceid = GetPostString("tid");
  9545. String[] tid = ceid.Split(',');
  9546. if (tid.Length > 0)
  9547. {
  9548. try
  9549. {
  9550. for (int i = 0; i < tid.Length; i++)
  9551. {
  9552. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  9553. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  9554. entity.SupplierId = suid;
  9555. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  9556. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  9557. entity.Update();
  9558. }
  9559. }
  9560. catch (Exception ex)
  9561. {
  9562. returnErrorMsg("自动匹配供应商失败");
  9563. return;
  9564. }
  9565. }
  9566. else
  9567. {
  9568. returnErrorMsg("请至少选择一条数据");
  9569. return;
  9570. }
  9571. returnSuccessMsg("自动匹配供应商成功");
  9572. return;
  9573. }
  9574. public (string, string) UploadFiles(string[] urls)
  9575. {
  9576. string success = "";
  9577. string errors = "";
  9578. int userid = CurrentUser.UserID;
  9579. foreach (string url in urls)
  9580. {
  9581. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  9582. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  9583. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  9584. {
  9585. JObject jsonObject = new JObject
  9586. {
  9587. { "Userid", "77886" },
  9588. { "pwd", "cyt86435015" },
  9589. { "content", base64FileContent },
  9590. { "ext", Path.GetExtension(fileName) }
  9591. };
  9592. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  9593. JObject jsonObjects = JObject.Parse(response);
  9594. string msg = (string)jsonObjects["msg"];
  9595. if (msg.Equals("上传成功"))
  9596. {
  9597. success += url + " 上传成功";
  9598. }
  9599. else
  9600. {
  9601. errors += url + " 上传失败";
  9602. }
  9603. }
  9604. else
  9605. {
  9606. errors += url + " 格式出现问题";
  9607. }
  9608. }
  9609. if (urls.Length == 0)
  9610. {
  9611. return (success, errors);
  9612. }
  9613. return (success, errors);
  9614. }
  9615. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  9616. {
  9617. return true; //总是接受
  9618. }
  9619. public static string HttpPost(string url, string param = null)
  9620. {
  9621. HttpWebRequest request;
  9622. //如果是发送HTTPS请求
  9623. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  9624. {
  9625. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  9626. request = WebRequest.Create(url) as HttpWebRequest;
  9627. request.ProtocolVersion = HttpVersion.Version10;
  9628. }
  9629. else
  9630. {
  9631. request = WebRequest.Create(url) as HttpWebRequest;
  9632. }
  9633. request.Method = "POST";
  9634. request.ContentType = "application/json";
  9635. request.Accept = "*/*";
  9636. request.Timeout = 120000;
  9637. request.AllowAutoRedirect = false;
  9638. StreamWriter requestStream = null;
  9639. WebResponse response = null;
  9640. string responseStr = null;
  9641. try
  9642. {
  9643. requestStream = new StreamWriter(request.GetRequestStream());
  9644. requestStream.Write(param);
  9645. requestStream.Close();
  9646. response = request.GetResponse();
  9647. if (response != null)
  9648. {
  9649. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  9650. responseStr = reader.ReadToEnd();
  9651. reader.Close();
  9652. }
  9653. }
  9654. catch (Exception ex)
  9655. {
  9656. return ex.Message;
  9657. }
  9658. finally
  9659. {
  9660. request = null;
  9661. requestStream = null;
  9662. response = null;
  9663. }
  9664. return responseStr;
  9665. }
  9666. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  9667. {
  9668. string base64FileContent;
  9669. string fileName;
  9670. using (WebClient webClient = new WebClient())
  9671. {
  9672. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  9673. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  9674. {
  9675. using (Stream stream = response.GetResponseStream())
  9676. {
  9677. using (MemoryStream memoryStream = new MemoryStream())
  9678. {
  9679. stream.CopyTo(memoryStream);
  9680. byte[] fileBytes = memoryStream.ToArray();
  9681. base64FileContent = Convert.ToBase64String(fileBytes);
  9682. fileName = response.Headers["Content-Disposition"];
  9683. if (!string.IsNullOrEmpty(fileName))
  9684. {
  9685. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  9686. if (index >= 0)
  9687. {
  9688. fileName = fileName.Substring(index + 9).Trim('\"');
  9689. }
  9690. }
  9691. else
  9692. {
  9693. fileName = Path.GetFileName(downloadUrl);
  9694. }
  9695. }
  9696. }
  9697. }
  9698. }
  9699. return (fileName, base64FileContent);
  9700. }
  9701. //新增
  9702. public void order_batch_caiyingtong(string[] downloadUrls)
  9703. {
  9704. try
  9705. {
  9706. //遍历文件
  9707. DataStruct dStruct = GetPostStruct();
  9708. DataTable dt = null;
  9709. int userid = CurrentUser.UserID;
  9710. List<string> ids = new List<string>();//失败组
  9711. List<string> tids = new List<string>();
  9712. using (WebClient webClient = new WebClient())
  9713. {
  9714. foreach (var url in downloadUrls)
  9715. {
  9716. try
  9717. {
  9718. tids.Add("'" + url + "'");
  9719. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  9720. if (entity != null)
  9721. {
  9722. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  9723. if (cp == null)
  9724. {
  9725. JObject jsonObject = new JObject
  9726. {
  9727. { "Userid", "77886" },
  9728. { "pwd", "lt666888" },
  9729. { "Filename",entity.seller_memo }
  9730. };
  9731. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  9732. JObject jsonObjects = JObject.Parse(response);
  9733. string msg = (string)jsonObjects["msg"];
  9734. if (msg == "报价成功")
  9735. {
  9736. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  9737. DownloadAndConvertToBase64(url1);
  9738. }
  9739. else
  9740. {
  9741. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  9742. }
  9743. }
  9744. else
  9745. {
  9746. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  9747. JObject jsonObject = new JObject
  9748. {
  9749. { "Userid", "77886" },
  9750. { "pwd", "lt666888" },
  9751. { "Filename",chanp }
  9752. };
  9753. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  9754. JObject jsonObjects = JObject.Parse(response);
  9755. string msg = (string)jsonObjects["msg"];
  9756. if (msg == "报价成功")
  9757. {
  9758. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  9759. DownloadAndConvertToBase64(url1);
  9760. }
  9761. else
  9762. {
  9763. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  9764. }
  9765. }
  9766. }
  9767. // 上传文件到FTP
  9768. }
  9769. catch (Exception ex)
  9770. {
  9771. Console.WriteLine($"An error occurred: {ex.Message}");
  9772. }
  9773. }
  9774. List<string> lw = new List<string>();
  9775. lw.Add(string.Format("( OrderState < 6 )"));
  9776. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  9777. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9778. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9779. if (dt.Rows.Count > 0)
  9780. {
  9781. foreach (DataRow dr in dt.Rows)
  9782. {
  9783. ids.Add(dr["ctid"].ToString());
  9784. }
  9785. }
  9786. String ErrorMsgs = "";
  9787. foreach (String id in ids)
  9788. {
  9789. ErrorMsgs += id + ",";
  9790. }
  9791. if (ErrorMsgs.Length > 1)
  9792. {
  9793. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  9794. }
  9795. if (ErrorMsgs.Length < 1)
  9796. {
  9797. ErrorMsgs = "上传成功";
  9798. returnSuccessMsg(ErrorMsgs);
  9799. }
  9800. else
  9801. {
  9802. returnErrorMsg("以下订单" + ErrorMsgs);
  9803. }
  9804. }
  9805. // 删除文件夹及其内容
  9806. /* Directory.Delete(localDirectory, true);*/
  9807. }
  9808. catch { }
  9809. }
  9810. public void get_center_data()
  9811. {
  9812. int userId = CurrentUser.UserID;
  9813. string postCode = CurrentUser.UserPost.Post.Code;
  9814. List<string> lw = new List<string>();
  9815. List<string> ww = new List<string>();
  9816. DateTime currentTime = DateTime.Now;
  9817. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  9818. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  9819. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  9820. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  9821. string sql = " SELECT ";
  9822. string startTime = "2023-10-01 11:22:31";
  9823. //设计
  9824. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  9825. {
  9826. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  9827. 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));
  9828. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  9829. 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));
  9830. }
  9831. //客服
  9832. else if (postCode == "CustomerService" || postCode == "Director")
  9833. {
  9834. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  9835. 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));
  9836. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  9837. 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));
  9838. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  9839. 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));
  9840. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  9841. 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));
  9842. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  9843. 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));
  9844. }
  9845. //售后
  9846. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  9847. {
  9848. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  9849. 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));
  9850. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  9851. 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));
  9852. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  9853. 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));
  9854. }
  9855. //下单部
  9856. else if (postCode == "Place" || postCode == "PlaceMr")
  9857. {
  9858. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  9859. 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));
  9860. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  9861. 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));
  9862. }
  9863. //车间
  9864. else if (postCode == "Supplier")
  9865. {
  9866. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  9867. 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));
  9868. }
  9869. DataTable dt = new DataTable();
  9870. if (lw.Count > 0)
  9871. {
  9872. sql += string.Join(" , ", lw);
  9873. sql += " FROM ";
  9874. sql += string.Join(" , ", ww);
  9875. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9876. }
  9877. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9878. }
  9879. public void get_center_data_list()
  9880. {
  9881. int userId = CurrentUser.UserID;
  9882. string postCode = CurrentUser.UserPost.Post.Code;
  9883. string shopIds = CurrentUser.User.pemShop;
  9884. DataStruct dStruct = GetPostStruct();
  9885. List<string> lw = new List<string>();
  9886. DateTime currentTime = DateTime.Now;
  9887. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  9888. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  9889. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  9890. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  9891. string startTime = "2023-10-01 11:22:31";
  9892. int order_type = GetPostInt("order_type");
  9893. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  9894. {
  9895. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  9896. if (order_type == 0)
  9897. {
  9898. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  9899. }
  9900. else if (order_type == 3)
  9901. {
  9902. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  9903. }
  9904. else
  9905. {
  9906. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  9907. }
  9908. }
  9909. //客服
  9910. if (postCode == "CustomerService" || postCode == "Director")
  9911. {
  9912. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  9913. if (order_type == 0)
  9914. {
  9915. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  9916. }
  9917. else if (order_type == 1)
  9918. {
  9919. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  9920. }
  9921. else if (order_type == 2)
  9922. {
  9923. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  9924. }
  9925. else if (order_type == 3)
  9926. {
  9927. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  9928. }
  9929. else if (order_type == 4)
  9930. {
  9931. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  9932. }
  9933. else
  9934. {
  9935. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  9936. }
  9937. }
  9938. //售后
  9939. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  9940. {
  9941. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  9942. if (shopIds != "")
  9943. {
  9944. lw.Add(string.Format("ShopId in ({0})", shopIds));
  9945. }
  9946. if (order_type == 2)
  9947. {
  9948. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  9949. }
  9950. else if (order_type == 4)
  9951. {
  9952. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  9953. }
  9954. else if (order_type == 5)
  9955. {
  9956. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  9957. }
  9958. else
  9959. {
  9960. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  9961. }
  9962. }
  9963. //下单部
  9964. if (postCode == "Place" || postCode == "PlaceMr")
  9965. {
  9966. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  9967. if (shopIds != "")
  9968. {
  9969. lw.Add(string.Format("ShopId in ({0})", shopIds));
  9970. }
  9971. else if (order_type == 1)
  9972. {
  9973. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  9974. }
  9975. else if (order_type == 2)
  9976. {
  9977. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  9978. }
  9979. else
  9980. {
  9981. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  9982. }
  9983. }
  9984. //车间
  9985. if (postCode == "Supplier")
  9986. {
  9987. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  9988. if (order_type == 5)
  9989. {
  9990. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  9991. }
  9992. else
  9993. {
  9994. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  9995. }
  9996. }
  9997. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9998. dStruct.Fileds = "tid,ctid";
  9999. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10000. writeGridDataTableJson(dStruct.TotalCount, dt);
  10001. }
  10002. public void aftersale_audit_master()
  10003. {
  10004. if (UrlPostParmsCheck("ctid"))
  10005. {
  10006. string ctid = GetPostString("ctid");
  10007. if (ctid.Length > 0)
  10008. {
  10009. bool result = aftersale_data_change(ctid);
  10010. if (result)
  10011. {
  10012. returnSuccessMsg("修改成功!");
  10013. return;
  10014. }
  10015. }
  10016. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10017. }
  10018. }
  10019. public void aftersale_batch_audit_master()
  10020. {
  10021. if (UrlPostParmsCheck("ctids"))
  10022. {
  10023. string ctids = GetPostString("ctids");
  10024. if (ctids.Length > 0)
  10025. {
  10026. List<string> list = new List<string>();
  10027. string[] ctid_list = ctids.Split(',');
  10028. foreach (var item in ctid_list)
  10029. {
  10030. bool result = aftersale_data_change(item);
  10031. if (!result)
  10032. {
  10033. list.Add(item);
  10034. }
  10035. }
  10036. if (list.Count > 0)
  10037. {
  10038. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10039. return;
  10040. }
  10041. returnSuccessMsg("修改成功!");
  10042. return;
  10043. }
  10044. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10045. }
  10046. }
  10047. public bool aftersale_data_change(string ctid)
  10048. {
  10049. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10050. if (ceErpTradeCell != null)
  10051. {
  10052. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10053. ceErpTradeCell.AfterSaleSupplierState = 0;
  10054. StringBuilder sql = new StringBuilder();
  10055. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10056. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10057. CeErpTradeResponsible.DelByTid(ctid, 0);
  10058. 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 == "不理赔")
  10059. {
  10060. CeErpTradeResponsible.DelByTid(ctid, 1);
  10061. ceErpTradeCell.AfterSaleSupplierState = 1;
  10062. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10063. ceErpTradeCell.AfterSaleState = 4;
  10064. }
  10065. else
  10066. {
  10067. ceErpTradeCell.AfterSaleState = 3;
  10068. }
  10069. bool needCyt = false;
  10070. if (dt != null)
  10071. {
  10072. if (dt.Rows.Count == 1)
  10073. {
  10074. bool isEnd = false;
  10075. foreach (DataRow dr in dt.Rows)
  10076. {
  10077. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10078. {
  10079. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10080. isEnd = true;
  10081. }
  10082. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10083. {
  10084. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10085. isEnd = true;
  10086. }
  10087. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10088. {
  10089. needCyt = true;
  10090. }
  10091. }
  10092. if (isEnd)
  10093. {
  10094. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10095. ceErpTradeCell.AfterSaleState = 4;
  10096. ceErpTradeCell.AfterSaleSupplierState = 1;
  10097. }
  10098. }
  10099. else
  10100. {
  10101. bool isAll = true;
  10102. foreach (DataRow dr in dt.Rows)
  10103. {
  10104. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10105. {
  10106. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10107. continue;
  10108. }
  10109. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10110. {
  10111. string path = "";
  10112. int OrgID = 0;
  10113. if (!Convert.IsDBNull(dr["OrgPath"]))
  10114. {
  10115. path = dr["OrgPath"].ToString();
  10116. }
  10117. if (!Convert.IsDBNull(dr["OrgID"]))
  10118. {
  10119. OrgID = Convert.ToInt32(dr["OrgID"]);
  10120. }
  10121. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10122. {
  10123. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10124. continue;
  10125. }
  10126. }
  10127. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10128. {
  10129. needCyt = true;
  10130. }
  10131. isAll = false;
  10132. }
  10133. if (isAll)
  10134. {
  10135. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10136. ceErpTradeCell.AfterSaleState = 4;
  10137. ceErpTradeCell.AfterSaleSupplierState = 1;
  10138. }
  10139. }
  10140. }
  10141. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10142. {
  10143. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10144. }
  10145. if (ceErpTradeCell.AfterSaleState == 4)
  10146. {
  10147. ApiVo apiVo = new ApiVo();
  10148. apiVo.orderNumber = ceErpTradeCell.ctid;
  10149. apiVo.actionName = "afterOver";
  10150. designHelper.API_WorkCore(apiVo); //afterOver
  10151. }
  10152. ceErpTradeCell.Update();
  10153. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10154. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10155. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10156. return true;
  10157. }
  10158. return false;
  10159. }
  10160. public void get_erp_wechatorder()
  10161. {
  10162. DataStruct dStruct = GetPostStruct();
  10163. List<string> lw = new List<string>();
  10164. string tid = GetPostString("tid");
  10165. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10166. string shopname = GetPostString("shopname");
  10167. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10168. string buyernick = GetPostString("buyer_nick");
  10169. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10170. string customer = GetPostString("customer");
  10171. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10172. string returndate1 = GetPostString("returndate1");
  10173. string returndate2 = GetPostString("returndate2");
  10174. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10175. if (dw.Length > 0) lw.Add(dw);
  10176. string finishDate1 = GetPostString("finishdate1");
  10177. string finishDate2 = GetPostString("finishdate2");
  10178. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10179. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10180. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10181. dStruct.Order = "created desc";
  10182. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10183. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10184. writeGridDataTableJson(dStruct.TotalCount, dt);
  10185. }
  10186. public void get_erp_wechatlist_sumprice()
  10187. {
  10188. DataStruct dStruct = GetPostStruct();
  10189. List<string> lw = new List<string>();
  10190. string tid = GetPostString("tid");
  10191. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10192. string shopname = GetPostString("shopname");
  10193. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10194. string buyernick = GetPostString("buyer_nick");
  10195. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10196. string customer = GetPostString("customer");
  10197. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10198. string returndate1 = GetPostString("returndate1");
  10199. string returndate2 = GetPostString("returndate2");
  10200. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10201. if (dw.Length > 0) lw.Add(dw);
  10202. string finishDate1 = GetPostString("finishdate1");
  10203. string finishDate2 = GetPostString("finishdate2");
  10204. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10205. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10206. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10207. string mainWhere = string.Join(" and ", lw.ToArray());
  10208. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10209. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10210. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10211. decimal total = 0;
  10212. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10213. {
  10214. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10215. }
  10216. var res = new
  10217. {
  10218. data = total
  10219. };
  10220. string ro_jsond = JsonConvert.SerializeObject(res);
  10221. returnSuccess(ro_jsond);
  10222. return;
  10223. }
  10224. public void get_erp_qr_waitdeliverylist()
  10225. {
  10226. DataStruct dStruct = GetPostStruct();
  10227. List<string> lw = new List<string>();
  10228. string tid = GetPostString("ctid");
  10229. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10230. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10231. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10232. var res_objz = new
  10233. {
  10234. restype = 1,
  10235. data = dt
  10236. };
  10237. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10238. returnSuccess(ro_jsonz);
  10239. }
  10240. public void get_erp_yield_list()
  10241. {
  10242. DataStruct dStruct = GetPostStruct();
  10243. List<string> lw = new List<string>();
  10244. string tid = GetPostString("ctid");
  10245. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10246. string shopname = GetPostString("shopname");
  10247. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10248. string buyernick = GetPostString("buyer_nick");
  10249. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10250. //if (tid.Length == 0 && buyernick.Length == 0)
  10251. //{
  10252. // lw.Add(string.Format("IsRefund<={0}", 1));
  10253. //}
  10254. string customer = GetPostString("customer");
  10255. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10256. string design = GetPostString("design");
  10257. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10258. string orderState = GetPostString("orderState");
  10259. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10260. string address = GetPostString("address");
  10261. 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));
  10262. string sellermemo = GetPostString("seller_memo");
  10263. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10264. string supplier = GetPostString("supplier");
  10265. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10266. string OrderArea = GetPostString("order_area");
  10267. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10268. string placedate1 = GetPostString("placedate1");
  10269. string placedate2 = GetPostString("placedate2");
  10270. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10271. if (fdw.Length > 0) lw.Add(fdw);
  10272. string price1 = GetPostString("price1");
  10273. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10274. string price2 = GetPostString("price2");
  10275. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10276. string unusualCon = GetPostString("unusualcon");
  10277. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10278. string posTag = CurrentUser.UserPost.Post.Code;
  10279. if (posTag == "Supplier")
  10280. {
  10281. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10282. }
  10283. lw.Add(string.Format("OrderState = 6 "));
  10284. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10285. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10286. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10287. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10288. writeGridDataTableJson(dStruct.TotalCount, dt);
  10289. }
  10290. public void change_erp_sup_state()
  10291. {
  10292. if (UrlPostParmsCheck("ctid"))
  10293. {
  10294. string ctid = GetPostString("ctid");
  10295. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10296. if (ceErpTradeCell != null)
  10297. {
  10298. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10299. if (ceErpTradeCellExtend == null)
  10300. {
  10301. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10302. ceErpTradeCellExtend.ctid = ctid;
  10303. ceErpTradeCellExtend.SupState = 1;
  10304. ceErpTradeCellExtend.Create();
  10305. }
  10306. else
  10307. {
  10308. ceErpTradeCellExtend.SupState = 1;
  10309. ceErpTradeCellExtend.Update();
  10310. }
  10311. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10312. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10313. return;
  10314. }
  10315. returnErrorMsg("找不到订单");
  10316. }
  10317. }
  10318. public void supplier_all_downs()
  10319. {
  10320. if (UrlPostParmsCheck("tids"))
  10321. {
  10322. string tids = GetPostString("tids");
  10323. if (tids != null && tids.Length > 0)
  10324. {
  10325. StringBuilder sql = new StringBuilder();
  10326. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6 where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  10327. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10328. sql = new StringBuilder();
  10329. 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, "下载设计文件");
  10330. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10331. string[] list = tids.Split(',');
  10332. foreach (string ctid in list)
  10333. {
  10334. CeErpSukuraData.createInfo(ctid, 3);
  10335. }
  10336. designHelper.api_approveDesign(tids); //approveDesign
  10337. returnSuccessMsg("下载成功!");
  10338. return;
  10339. }
  10340. returnErrorMsg("下载订单更新失败");
  10341. }
  10342. }
  10343. public void uploaderFileSuccess()
  10344. {
  10345. if (UrlPostParmsCheck("fileName"))
  10346. {
  10347. string fileName = GetPostString("fileName");
  10348. ApiVo apiVo = new ApiVo();
  10349. apiVo.orderNumber = fileName;
  10350. apiVo.actionName = "finishDesign";
  10351. designHelper.API_WorkCore(apiVo);//finishDesign
  10352. returnSuccessMsg("");
  10353. }
  10354. }
  10355. public void get_sample2_order()
  10356. {
  10357. if (UrlPostParmsCheck("ctid"))
  10358. {
  10359. string ctid = GetPostString("ctid");
  10360. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10361. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  10362. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  10363. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  10364. double total = 0.0;
  10365. double order_price = 0.0;
  10366. if (dt_bu.Rows.Count > 0)
  10367. {
  10368. foreach (DataRow dr in dt_bu.Rows)
  10369. {
  10370. total += Convert.ToDouble(dr["payment"]);
  10371. }
  10372. }
  10373. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  10374. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  10375. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  10376. string tid = ctid.Replace("S_", "");
  10377. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  10378. double paymant = 0.0;
  10379. if (entity != null)
  10380. {
  10381. paymant = entity.payment;
  10382. }
  10383. string return_reason = "";
  10384. if (dt_after != null && dt_after.Rows.Count > 0)
  10385. {
  10386. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  10387. }
  10388. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  10389. }
  10390. }
  10391. public void get_erp_design_status()
  10392. {
  10393. string designName = GetPostString("designName");
  10394. DataStruct dStruct = GetPostStruct();
  10395. if (designName.Length > 0)
  10396. {
  10397. 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";
  10398. sql_user += " and Name like '%" + designName + "%'";
  10399. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  10400. List<string> ids_list = new List<string>();
  10401. if (user_table.Rows.Count > 0)
  10402. {
  10403. foreach (DataRow item in user_table.Rows)
  10404. {
  10405. ids_list.Add(item["id"].ToString());
  10406. string ids_s = item["TeamIds"].ToString();
  10407. if (ids_s.Length > 0)
  10408. {
  10409. ids_list.AddRange(ids_s.Split(','));
  10410. }
  10411. }
  10412. }
  10413. HashSet<string> set = new HashSet<string>(ids_list);
  10414. ids_list = set.ToList();
  10415. if (ids_list.Count > 0)
  10416. {
  10417. 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));
  10418. dStruct.MainWhere = sql;
  10419. DataTable dt = null;
  10420. dt = WebCache.GetData("view_ErpUser", dStruct);
  10421. writeGridDataTableJson(dStruct.TotalCount, dt);
  10422. }
  10423. }
  10424. }
  10425. public void change_erp_order_price()
  10426. {
  10427. string ctid = GetPostString("ctid");
  10428. double price = GetPostDouble("price");
  10429. if (ctid.Length > 0)
  10430. {
  10431. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10432. if (ceErpTradeCellExtend == null)
  10433. {
  10434. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10435. ceErpTradeCellExtend.ctid = ctid;
  10436. ceErpTradeCellExtend.payment_cyt = price;
  10437. ceErpTradeCellExtend.Create();
  10438. }
  10439. else
  10440. {
  10441. ceErpTradeCellExtend.payment_cyt = price;
  10442. ceErpTradeCellExtend.Update();
  10443. }
  10444. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  10445. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  10446. {
  10447. ceErpDataSendOrderInfo.isSync = false;
  10448. ceErpDataSendOrderInfo.Update();
  10449. }
  10450. if (ceErpDataSendOrderInfo == null)
  10451. {
  10452. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  10453. ceErpDataSendOrderInfo.isSync = false;
  10454. ceErpDataSendOrderInfo.ctid = ctid;
  10455. ceErpDataSendOrderInfo.Create();
  10456. }
  10457. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  10458. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  10459. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10460. if (dth != null && dth.Rows.Count > 0)
  10461. {
  10462. dataSendOrderBean dataSendOrderBean = null;
  10463. foreach (DataRow item in dth.Rows)
  10464. {
  10465. try
  10466. {
  10467. dataSendOrderBean = new dataSendOrderBean();
  10468. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  10469. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  10470. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  10471. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  10472. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  10473. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  10474. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  10475. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  10476. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  10477. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  10478. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  10479. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  10480. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  10481. if (result != null)
  10482. {
  10483. if ("0".Equals(result.errcode))
  10484. {
  10485. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  10486. }
  10487. else
  10488. {
  10489. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  10490. }
  10491. }
  10492. }
  10493. catch (Exception ex)
  10494. {
  10495. }
  10496. }
  10497. }
  10498. returnSuccessMsg("修改成功!");
  10499. return;
  10500. }
  10501. returnErrorMsg("找不到订单");
  10502. }
  10503. public void find_he_together()
  10504. {
  10505. string ctid = GetPostString("ctid");
  10506. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10507. List<string> list = new List<string>();
  10508. if (ceErpTradeCell != null)
  10509. {
  10510. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  10511. {
  10512. 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);
  10513. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10514. if (table != null && table.Rows.Count > 0)
  10515. {
  10516. foreach (TableRow row in table.Rows)
  10517. {
  10518. }
  10519. }
  10520. }
  10521. }
  10522. returnSuccess(JsonConvert.SerializeObject(new { list }));
  10523. }
  10524. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  10525. {
  10526. //chy----19
  10527. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  10528. //GD-CYT-----64
  10529. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  10530. //ZHX----3
  10531. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  10532. //JK----97
  10533. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  10534. //ZT----70
  10535. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  10536. //LHCY-----98
  10537. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  10538. //XD-----90
  10539. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  10540. //CYCY-----14
  10541. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  10542. };
  10543. //其他改名
  10544. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  10545. {
  10546. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  10547. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  10548. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  10549. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  10550. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  10551. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  10552. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  10553. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  10554. };
  10555. //不统计
  10556. List<int> no_suppliers = new List<int>()
  10557. {
  10558. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  10559. };
  10560. //配件单
  10561. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  10562. {
  10563. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  10564. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  10565. {"别针",new List<string>(){ "卡片", "吊牌" } },
  10566. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  10567. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  10568. {"旗杆",new List<string>(){ "班旗" } },
  10569. {"牙签",new List<string>(){ "不干胶" } }
  10570. };
  10571. public void get_place_order_data()
  10572. {
  10573. string date1 = GetPostString("date1");
  10574. string date2 = GetPostString("date2");
  10575. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  10576. DateTime start = DateTime.Parse(starttime);
  10577. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  10578. DateTime end = DateTime.Parse(endtime);
  10579. if (date1 != null && date1.Length > 0)
  10580. {
  10581. DateTime dateTime = DateTime.Parse(date1);
  10582. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  10583. start = DateTime.Parse(starttime);
  10584. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  10585. end = DateTime.Parse(endtime);
  10586. }
  10587. if (date2 != null && date2.Length > 0)
  10588. {
  10589. DateTime dateTime = DateTime.Parse(date2);
  10590. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  10591. end = DateTime.Parse(endtime);
  10592. }
  10593. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,UnusualTime,FinishPlaceTime,OrderState,FinishDeliveryTime from view_ErpTradeCell where ( ( FinishPlaceTime BETWEEN '{0}' AND '{1}' ) OR ( OrderState = 6 AND UnusualTag = 5 AND IsRefund <= 1 ) ) AND IsSample = 0 and SupplierName is not null ", starttime, endtime);
  10594. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10595. //不干胶-----1,卡片-----29
  10596. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  10597. foreach (DataRow row in data.Rows)
  10598. {
  10599. int productId = Convert.ToInt32(row["ProductId"]);
  10600. int supplierId = Convert.ToInt32(row["SupplierId"]);
  10601. if (no_suppliers.Contains(supplierId))
  10602. {
  10603. continue;
  10604. }
  10605. string seller_memo = row["seller_memo"].ToString();
  10606. bool ispj = false;//是否配件单
  10607. bool isfirst = true;//第一个配
  10608. maps.Keys.ForEach(key =>
  10609. {
  10610. //备注包含配件
  10611. if (seller_memo.Contains(key) && isfirst)
  10612. {
  10613. List<string> list = maps[key];
  10614. ispj = true;
  10615. isfirst = false;
  10616. for (int i = 0; i < list.Count; i++)
  10617. {
  10618. if (seller_memo.Contains(list[i]))
  10619. {
  10620. ispj = false;
  10621. break;
  10622. }
  10623. }
  10624. }
  10625. });
  10626. if (ispj)
  10627. {
  10628. continue;
  10629. }
  10630. seller_memo = seller_memo.Replace("UV", "uv");
  10631. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  10632. //吊牌归到卡片
  10633. seller_memo = seller_memo.Replace("吊牌", "卡片");
  10634. seller_memo = seller_memo.Replace("卡套", "卡片");
  10635. seller_memo = seller_memo.Replace("封套", "卡片");
  10636. seller_memo = seller_memo.Replace("吸管套", "卡片");
  10637. seller_memo = seller_memo.Replace("腰封", "卡片");
  10638. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  10639. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  10640. seller_memo = seller_memo.Replace("横幅", "条幅");
  10641. seller_memo = seller_memo.Replace("锦旗", "条幅");
  10642. string map_key = "";
  10643. string type = "";
  10644. if (supplierMap.ContainsKey(supplierId))
  10645. {
  10646. foreach (var kvp in supplierMap[supplierId])
  10647. {
  10648. if (seller_memo.Contains(kvp.Key))
  10649. {
  10650. map_key = kvp.Value;
  10651. type = kvp.Value;
  10652. break;
  10653. }
  10654. }
  10655. }
  10656. if (map_key == "")
  10657. {
  10658. type = "其他";
  10659. map_key = "其他";
  10660. }
  10661. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  10662. {
  10663. map_key = suppliers[supplierId];
  10664. }
  10665. if (supplierId == 70)
  10666. {
  10667. supplierId = 70;
  10668. }
  10669. map_key += "_" + row["SupplierName"].ToString();
  10670. Dictionary<string, int> map = null;
  10671. if (other_map.ContainsKey(map_key))
  10672. {
  10673. other_map.TryGetValue(map_key, out map);
  10674. }
  10675. else
  10676. {
  10677. map = new Dictionary<string, int>();
  10678. map.Add("dayDev", 0);//当天出货
  10679. map.Add("dayTotal", 0);//下单总数
  10680. map.Add("payTotal", 0);//500以上
  10681. map.Add("today", 0);//当天出货数量
  10682. map.Add("unusua", 0);//异常数
  10683. other_map.Add(map_key, map);
  10684. other_map.TryGetValue(map_key, out map);
  10685. }
  10686. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  10687. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  10688. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  10689. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  10690. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  10691. {
  10692. map["dayTotal"]++;
  10693. if (supplierId == 97)
  10694. {
  10695. supplierId = 97;
  10696. }
  10697. }
  10698. if (Convert.ToDecimal(row["payment"]) >= 500)
  10699. {
  10700. map["payTotal"]++;
  10701. }
  10702. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  10703. {
  10704. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  10705. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  10706. {
  10707. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  10708. {
  10709. map["today"]++;
  10710. }
  10711. }
  10712. else
  10713. {
  10714. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  10715. {
  10716. map["today"]++;
  10717. }
  10718. }
  10719. }
  10720. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  10721. {
  10722. map["unusua"]++;
  10723. }
  10724. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  10725. //GD-CYT-----64
  10726. DateTime two = palceTimeStart.AddHours(14);
  10727. DateTime three = palceTimeStart.AddHours(15);
  10728. DateTime four = palceTimeStart.AddHours(16);
  10729. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  10730. {
  10731. //下午四点前 500-1000
  10732. string count = row["ProductCount"].ToString();
  10733. if (count != null && count.Length > 0)
  10734. {
  10735. int productCount = commonHelper.getPlaceProductCount(count);
  10736. if (productCount >= 500 && productCount <= 1000)
  10737. {
  10738. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  10739. {
  10740. map["dayDev"]++;
  10741. }
  10742. }
  10743. }
  10744. }
  10745. //UV
  10746. else if ("uv".Equals(type))
  10747. {
  10748. //ZT----70
  10749. //ZHX----3
  10750. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  10751. {
  10752. map["dayDev"]++;
  10753. }
  10754. //JK----97
  10755. //HZX----105
  10756. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  10757. {
  10758. map["dayDev"]++;
  10759. if (supplierId == 97)
  10760. {
  10761. supplierId = 97;
  10762. }
  10763. }
  10764. }
  10765. //帆布---52|条幅---27
  10766. else if ("帆布".Equals(type) || "条幅".Equals(type))
  10767. {
  10768. //LHCY-----98
  10769. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  10770. {
  10771. map["dayDev"]++;
  10772. }
  10773. }
  10774. //条幅
  10775. else if ("条幅".Equals(type))
  10776. {
  10777. //XD-----90
  10778. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  10779. {
  10780. map["dayDev"]++;
  10781. }
  10782. }
  10783. //桌布
  10784. else if ("桌布".Equals(type))
  10785. {
  10786. //XD-----90
  10787. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  10788. {
  10789. map["dayDev"]++;
  10790. }
  10791. }
  10792. //DL---10
  10793. //AYTW---119
  10794. //FS-CYT-DY ----80
  10795. //JK----97
  10796. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  10797. {
  10798. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  10799. {
  10800. map["dayDev"]++;
  10801. }
  10802. }
  10803. }
  10804. DataTable dt = new DataTable();
  10805. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  10806. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  10807. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  10808. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  10809. dt.Columns.Add(new DataColumn("today", typeof(string)));
  10810. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  10811. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  10812. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  10813. other_map.Keys.ForEach(key =>
  10814. {
  10815. DataRow dr = dt.NewRow();
  10816. Dictionary<string, int> map = other_map[key];
  10817. string[] key_list = key.Split('_');
  10818. dr[0] = key_list[0];
  10819. dr[1] = key_list[1];
  10820. if (key_list.Length > 2)
  10821. {
  10822. dr[1] += "(" + key_list[2] + ")";
  10823. }
  10824. dr[2] = map["dayTotal"];
  10825. dr[3] = map["payTotal"];
  10826. dr[4] = map["today"];
  10827. dr[5] = map["unusua"];
  10828. dr[6] = map["dayDev"];
  10829. double rate = 0.00;
  10830. if (map["dayDev"] > 0)
  10831. {
  10832. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  10833. }
  10834. dr[7] = rate.ToString();
  10835. dt.Rows.Add(dr);
  10836. });
  10837. DataView dv = new DataView(dt);
  10838. dv.Sort = "SupplierName";
  10839. //dv.Sort = "AllOrder desc";
  10840. DataTable dtNew = dv.ToTable();
  10841. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  10842. }
  10843. public void check_order_desing_info()
  10844. {
  10845. string ctid = GetPostString("ctid");
  10846. if (!string.IsNullOrEmpty(ctid))
  10847. {
  10848. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10849. if (ceErpTradeCell != null)
  10850. {
  10851. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  10852. returnSuccess(JsonConvert.SerializeObject(new { response }));
  10853. return;
  10854. }
  10855. returnErrorMsg("找不到订单");
  10856. return;
  10857. }
  10858. returnErrorMsg("找不到订单");
  10859. }
  10860. public void get_timeout_detail()
  10861. {
  10862. string poscode = CurrentUser.UserPost.Post.Code;
  10863. DataStruct dStruct = GetPostStruct();
  10864. List<string> lw = new List<string>();
  10865. string id = GetPostString("id");
  10866. string pay_date1 = GetPostString("pay_date1");
  10867. string pay_date2 = GetPostString("pay_date2");
  10868. int type = GetPostInt("type");
  10869. if (type == 0)
  10870. {
  10871. if (pay_date1.Length > 0)
  10872. {
  10873. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  10874. }
  10875. if (pay_date2.Length > 0)
  10876. {
  10877. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  10878. }
  10879. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  10880. }
  10881. if (type == 1)
  10882. {
  10883. if (pay_date1.Length > 0)
  10884. {
  10885. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  10886. }
  10887. if (pay_date2.Length > 0)
  10888. {
  10889. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  10890. }
  10891. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  10892. }
  10893. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10894. DataTable dt = null;
  10895. dt = WebCache.GetData("view_orderlist", dStruct);
  10896. writeGridDataTableJson(dStruct.TotalCount, dt);
  10897. }
  10898. public void saveUrgentChargePrice()
  10899. {
  10900. string ctid = GetPostString("ctid");
  10901. if (!string.IsNullOrEmpty(ctid))
  10902. {
  10903. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10904. if (ceErpTradeCell != null)
  10905. {
  10906. double price = GetPostDouble("price");
  10907. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  10908. if (ceErpTradeCellExtend == null)
  10909. {
  10910. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10911. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  10912. }
  10913. ceErpTradeCellExtend.urgentCharge = price;
  10914. if (ceErpTradeCellExtend.ID > 0)
  10915. {
  10916. ceErpTradeCellExtend.Update();
  10917. }
  10918. else
  10919. {
  10920. ceErpTradeCellExtend.Save();
  10921. }
  10922. returnSuccessMsg("修改成功!");
  10923. return;
  10924. }
  10925. returnErrorMsg("找不到订单");
  10926. return;
  10927. }
  10928. returnErrorMsg("找不到订单");
  10929. }
  10930. public void finish_erp_order()
  10931. {
  10932. string ctid = GetPostString("ctid");
  10933. if (!string.IsNullOrEmpty(ctid))
  10934. {
  10935. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  10936. {
  10937. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10938. if (ceErpTradeCell != null)
  10939. {
  10940. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  10941. ceErpTradeCell.Update();
  10942. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  10943. returnSuccessMsg("修改成功!");
  10944. return;
  10945. }
  10946. }
  10947. }
  10948. returnErrorMsg("找不到订单");
  10949. }
  10950. public void get_trade_order_list()
  10951. {
  10952. string tid = GetPostString("tid");
  10953. if (!string.IsNullOrEmpty(tid))
  10954. {
  10955. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  10956. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10957. writeGridDataTableJson(data.Rows.Count, data);
  10958. return;
  10959. }
  10960. returnErrorMsg("找不到订单");
  10961. }
  10962. public void save_cell_spu()
  10963. {
  10964. string ctid = GetPostString("ctid");
  10965. string spu_id = GetPostString("spu_id");
  10966. if (!string.IsNullOrEmpty(ctid))
  10967. {
  10968. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10969. if (ceErpTradeCellExtend == null)
  10970. {
  10971. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10972. ceErpTradeCellExtend.ctid = ctid;
  10973. }
  10974. ceErpTradeCellExtend.spu_id = spu_id;
  10975. if (ceErpTradeCellExtend.ID == 0)
  10976. {
  10977. ceErpTradeCellExtend.Create();
  10978. }
  10979. else
  10980. {
  10981. ceErpTradeCellExtend.Update();
  10982. }
  10983. returnSuccessMsg("修改成功!");
  10984. return;
  10985. }
  10986. returnErrorMsg("找不到订单");
  10987. }
  10988. public void change_express_info()
  10989. {
  10990. string ctid = GetPostString("ctid");
  10991. string transNo = GetPostString("transNo");
  10992. string transCom = GetPostString("transCom");
  10993. if (!string.IsNullOrEmpty(ctid))
  10994. {
  10995. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10996. if (ceErpTradeCellExtend == null)
  10997. {
  10998. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10999. ceErpTradeCellExtend.ctid = ctid;
  11000. }
  11001. ceErpTradeCellExtend.modExpressNo = transNo;
  11002. ceErpTradeCellExtend.modExpressCom = transCom;
  11003. ceErpTradeCellExtend.readMod = 2;
  11004. if (ceErpTradeCellExtend.ID == 0)
  11005. {
  11006. ceErpTradeCellExtend.Create();
  11007. }
  11008. else
  11009. {
  11010. ceErpTradeCellExtend.Update();
  11011. }
  11012. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11013. returnSuccessMsg("修改成功!");
  11014. return;
  11015. }
  11016. returnErrorMsg("找不到订单");
  11017. }
  11018. public void get_change_express_list()
  11019. {
  11020. DataStruct dStruct = GetPostStruct();
  11021. List<string> lw = new List<string>();
  11022. int st = 2;
  11023. string tid = GetPostString("ctid");
  11024. if (tid.Length > 0) lw.Add(string.Format("(ctid = '{0}' or tid = '{0}' or orderSn = '{0}')", tid));
  11025. string shopname = GetPostString("shopname");
  11026. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11027. string buyernick = GetPostString("buyer_nick");
  11028. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11029. string sellermemo = GetPostString("seller_memo");
  11030. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11031. string supplier = GetPostString("supplier");
  11032. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11033. string customer = GetPostString("customer");
  11034. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11035. string design = GetPostString("design");
  11036. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11037. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11038. string poscode = CurrentUser.UserPost.Post.Code;
  11039. if (poscode != "SysAdmin")
  11040. {
  11041. string shopid = CurrentUser.User.pemShop;
  11042. lw.Add(string.Format("shopId in ({0})", shopid));
  11043. }
  11044. lw.Add("readMod = 2");
  11045. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11046. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11047. writeGridDataTableJson(dStruct.TotalCount, dt);
  11048. }
  11049. public void deal_express_complete()
  11050. {
  11051. string ctid = GetPostString("ctid");
  11052. if (!string.IsNullOrEmpty(ctid))
  11053. {
  11054. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11055. if (ceErpTradeCellExtend == null)
  11056. {
  11057. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11058. ceErpTradeCellExtend.ctid = ctid;
  11059. }
  11060. ceErpTradeCellExtend.readMod = 1;
  11061. if (ceErpTradeCellExtend.ID == 0)
  11062. {
  11063. ceErpTradeCellExtend.Create();
  11064. }
  11065. else
  11066. {
  11067. ceErpTradeCellExtend.Update();
  11068. }
  11069. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11070. returnSuccessMsg("修改成功!");
  11071. return;
  11072. }
  11073. returnErrorMsg("找不到订单");
  11074. }
  11075. public void aftersale_return_visit()
  11076. {
  11077. string ctid = GetPostString("ctid");
  11078. if (!string.IsNullOrEmpty(ctid))
  11079. {
  11080. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11081. if (ceErpTradeCellExtend == null)
  11082. {
  11083. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11084. ceErpTradeCellExtend.ctid = ctid;
  11085. }
  11086. ceErpTradeCellExtend.returnVisit = 1;
  11087. if (ceErpTradeCellExtend.ID == 0)
  11088. {
  11089. ceErpTradeCellExtend.Create();
  11090. }
  11091. else
  11092. {
  11093. ceErpTradeCellExtend.Update();
  11094. }
  11095. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11096. if (ceErpTradeAfterSaleExtend != null)
  11097. {
  11098. ceErpTradeAfterSaleExtend.TextResult = "";
  11099. ceErpTradeAfterSaleExtend.Update();
  11100. }
  11101. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11102. returnSuccessMsg("修改成功!");
  11103. return;
  11104. }
  11105. returnErrorMsg("找不到订单");
  11106. }
  11107. public void orderPlaceInfo()
  11108. {
  11109. string ctids = GetPostString("ctids");
  11110. string[] list = ctids.Split(',');
  11111. foreach (string ctid in list)
  11112. {
  11113. CeErpSukuraData.createInfo(ctid, 3);
  11114. }
  11115. designHelper.api_approveDesign(ctids); //approveDesign
  11116. returnSuccessMsg("");
  11117. }
  11118. }
  11119. }