sync.order.cs 706 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using NHibernate.Linq;
  5. using NHibernate.Mapping;
  6. using NPOI.OpenXmlFormats.Dml.Diagram;
  7. using NPOI.OpenXmlFormats.Shared;
  8. using NPOI.SS.Formula.Eval;
  9. using NPOI.SS.Formula.Functions;
  10. using NPOI.SS.Formula.Udf;
  11. using SiteCore.Redis;
  12. using SiteCore.taobao;
  13. using SiteCore.taoObj;
  14. using SQLData;
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.ComponentModel.Design;
  19. using System.Data;
  20. using System.Data.SqlClient;
  21. using System.Data.SqlTypes;
  22. using System.Diagnostics;
  23. using System.Drawing;
  24. using System.Drawing.Drawing2D;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Net;
  28. using System.Net.Security;
  29. using System.Reflection.Emit;
  30. using System.Security.Cryptography;
  31. using System.Security.Cryptography.X509Certificates;
  32. using System.Security.Policy;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Threading;
  36. using System.Web.UI;
  37. using System.Web;
  38. using System.Web.UI.WebControls;
  39. using Utils;
  40. using Utils.Serialization;
  41. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  42. using static SiteCore.taoObj.Api_trade_info;
  43. using static SiteCore.taoObj.Api_waybill_code_response_Obj;
  44. using static SiteCore.taoObj.work_core_vo;
  45. using static System.Net.Mime.MediaTypeNames;
  46. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  47. using NPOI.Util;
  48. using static NPOI.HSSF.Util.HSSFColor;
  49. using BizCom.Enum;
  50. using NPOI.POIFS.Properties;
  51. using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
  52. using static SiteCore.taoObj.Api_tmc_refund_info_Obj;
  53. using System.Threading.Tasks;
  54. using SiteCore.taoObj.WebApi;
  55. using System.Web.UI.WebControls.WebParts;
  56. namespace SiteCore.Handler
  57. {
  58. public partial class sync
  59. {
  60. public void get_erp_orderlist()
  61. {
  62. string poscode = CurrentUser.UserPost.Post.Code;
  63. DataStruct dStruct = GetPostStruct();
  64. //commonHelper.sendSpuData(CeErpTradeCell.GetByCtid("C1_2701711344045006369"),CeErpTradeCellExtend.getByTid("C1_2701711344045006369"));
  65. //commonHelper.setDeliveryUnusualOrder2();
  66. //string a = SecurityHelper.DecryptSymmetric("kncY+n90QZs=");
  67. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  68. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  69. //banniuApiHelper.sendLogisticsInfo(null);
  70. //commonHelper.autoDistributeToSupplier(CeErpTradeCell.GetByCode("260112211259328680"));
  71. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  72. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2811249339088067154");
  73. //int sid = commonHelper.autoDistributeToSupplier(entity);
  74. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  75. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1776912122000,\"deliveryType\":\"OFFLINE\",\"discountFee\":5.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1777564800000,\"lines\":[{\"dividePostFee\":0.0,\"latestDeliveryTime\":1777564799999,\"mark2\":[],\"num\":7,\"outerId\":\"\",\"payment\":65.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i4/490100363/O1CN014sHEYw1EYItkQ1CXw_!!490100363.jpg\",\"platServiceFee\":0.0,\"price\":10.0,\"refOlId\":\"3297756000720015269\",\"refSkuId\":\"0\",\"refSpuId\":\"1013527964388\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":9.2857,\"singleFee\":9.29,\"spuOuterId\":\"\",\"standards\":\"\",\"status\":\"NOT_SHIPPED\",\"title\":\"车贴定制宠物logo图案转印贴纸小狗diy创意商标车窗萌宠水晶标签\",\"totalFee\":65.0,\"totalPrice\":70.0,\"totalSellPrice\":65.0}],\"logisticsOrderNo\":\"\",\"mark2\":[],\"modifyTime\":1776913673000,\"openBuyerId\":\"AAG5RHraABkUZRPgSx3AaocL\",\"openBuyerNick\":\"绿**\",\"openSellerNick\":\"琳19890725\",\"orderSource\":\"SYNC\",\"orderTime\":1776912119000,\"payTime\":1776912120000,\"payment\":65.0,\"platServiceFee\":0.0,\"posCode\":\"guliang\",\"posId\":598696,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0},\"receivedPayment\":0.0,\"receiverCity\":\"大连市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"甘井子区\",\"receiverId\":\"84b8064ffac769db909772facb5e84fb$\",\"receiverState\":\"辽宁省\",\"receiverTown\":\"凌水街道\",\"refOid\":\"3297756000720015269\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"120x120mm+120x150mm-2款各1个-UV转印贴-彩色-模切-绿葡萄妲己-龙井\",\"serviceFee\":0.0,\"status\":\"NOT_SHIPPED\",\"sysTags\":[],\"totalFee\":65.0,\"totalPrice\":70.0,\"totalSellPrice\":65.0,\"type\":\"SALE\"}}");
  76. //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}}");
  77. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  78. //string res = apiHelper.API_GetWaybill("YTO-PDD-CYT", "250703-469248284251412");
  79. //preSalesHelper.dealMessageInfo("{\"bizOrder\":{\"id\":235819,\"parentId\":null,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderNo\":\"4624034580248409502\",\"shopId\":4,\"shopCode\":\"aolifu\",\"customerId\":345874,\"customerServiceId\":3184,\"thirdOrderId\":\"4624034580248409502\",\"orderPlatform\":\"TMALL\",\"openBuyerId\":\"AAEORHraABkUZRHgSx6ksuhU\",\"openBuyerNick\":\"tb278604202340\",\"openSellerNick\":\"奥丽芙旗舰店\",\"productUrl\":null,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"payAmount\":125.0,\"unrefundedAmount\":125.0,\"discountAmount\":5.0,\"csDiscountAmount\":-35.0,\"num\":13,\"province\":\"山西省\",\"city\":\"吕梁市\",\"area\":\"孝义市\",\"receiverTown\":\"孝义市\",\"address\":null,\"thirdReceiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"receiverName\":null,\"receiverMobile\":null,\"weChatId\":null,\"phone\":null,\"designContent\":\"\",\"designPics\":\"[]\",\"weChatQrPics\":\"[]\",\"addressFileUrl\":\"\",\"thirdFlag\":\"NONE\",\"remark\":null,\"sellerRemark\":\"\",\"buyerRemark\":\"\",\"timeoutRemark\":null,\"discountRemark\":null,\"status\":\"NOT_SHIPPED\",\"refundStatus\":0,\"internalStatus\":2,\"auditStatus\":null,\"auditUserId\":null,\"auditor\":null,\"customTag\":null,\"isRepurchase\":false,\"isOffline\":false,\"paymentFile\":null,\"orderTime\":\"2025-07-10 14:46:13\",\"modifyTime\":\"2025-07-10 14:46:37\",\"payTime\":\"2025-07-10 14:46:37\",\"confirmTime\":\"2025-07-10 14:51:23\",\"auditTime\":null,\"shippingTime\":null,\"finishTime\":null,\"erpCustomerServiceId\":3319,\"openBuyerID\":\"AAEORHraABkUZRHgSx6ksuhU\",\"orderFrom\":\"10\",\"receiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"bizOrderItems\":[{\"id\":310334,\"orderId\":235819,\"thirdOrderItemId\":\"4624034580248409502\",\"thirdSpuId\":\"740203900330\",\"thirdSkuId\":\"0\",\"title\":\"pvc贴纸定制防水不干胶圆形贴标自粘商标logo广告二维码标签印刷\",\"specification\":\"\",\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2433960672/O1CN01D0ZzzR1GppCHSoBjD_!!4611686018427382496-0-item_pic.jpg\",\"price\":10.0,\"sellPrice\":9.62,\"amount\":9.62,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"totalAmount\":125.0,\"num\":13,\"refundStatus\":\"NO_REFUND\"}],\"bizOrderSplits\":[{\"id\":151557,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328848\",\"splitNo\":\"C1_4624034580248409502\",\"splitInfoNo\":\"C2+1\",\"splitAmount\":52.64,\"quoteRecordId\":520208,\"quoteAmount\":40.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328848)-[C2+1]-80x20mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328848\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":40.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":80.00,\"width\":20.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"80x20mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":40.00,\"numberType\":\"\",\"isDianziOrder\":0},{\"id\":151558,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328853\",\"splitNo\":\"C2_4624034580248409502\",\"splitInfoNo\":\"C2+2\",\"splitAmount\":72.36,\"quoteRecordId\":520209,\"quoteAmount\":55.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328853)-[C2+2]-90x50mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328853\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":55.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":90.00,\"width\":50.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"90x50mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":55.00,\"numberType\":\"\",\"isDianziOrder\":0}]}}");
  80. /*string path = "C:\\Users\\231010\\Downloads\\tids.txt";
  81. string path1 = "C:\\Users\\231010\\Downloads\\tid.txt";
  82. string tids = File.ReadAllText(path);
  83. List<string> list = tids.Split(',').ToList();
  84. int index = 0;
  85. foreach (string item in list)
  86. {
  87. CeErpTrade ceErpTrade = CeErpTrade.Get(item.Replace("'", ""));
  88. try
  89. {
  90. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_nick = '{0}' or buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  91. if (string.IsNullOrEmpty(ceErpTrade.buyer_nick))
  92. {
  93. sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  94. }
  95. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  96. List<string> tidList = new List<string>();
  97. if (dataTable != null && dataTable.Rows.Count > 0)
  98. {
  99. foreach (DataRow row in dataTable.Rows)
  100. {
  101. tidList.Add("'" + row["tid"].ToString() + "'");
  102. }
  103. }
  104. if (tidList.Count > 0)
  105. {
  106. sql = string.Format("SELECT count(*) as number FROM [dbo].[CE_ErpTradeCell] WITH(NOLOCK) WHERE tid in ({0}) AND IsSample = 0 ", string.Join(",", tidList));
  107. dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  108. if (dataTable != null && dataTable.Rows.Count > 0)
  109. {
  110. int count = Convert.ToInt32(dataTable.Rows[0]["number"]);
  111. if (count > 0)
  112. {
  113. Debug.WriteLine(index++);
  114. continue;
  115. }
  116. }
  117. }
  118. File.AppendAllText(path1, ceErpTrade.tid + "\n");
  119. }
  120. catch (Exception e)
  121. {
  122. File.AppendAllText(path1, "e:" + ceErpTrade.tid + "\n");
  123. }
  124. Debug.WriteLine(index++);
  125. }*/
  126. //string a = commonHelper.convertQNMemo("48x61mm-4款各40个-铜版纸-不干胶-覆膜模切-tb963561715-金陵-顺丰到付.粘成品.6.5cm牙签-老客户改稿找金陵拉群-16发", CeErpTradeCell.GetByCtid("2879265072537265386"));
  127. List<string> lw = new List<string>();
  128. string tid = GetPostString("ctid");
  129. string date1 = GetPostString("date1");
  130. //12-1 修改
  131. string urgent = GetPostString("urgent");
  132. string back = GetPostString("back");
  133. string offlineSearch = GetPostString("offlineSearch");
  134. int paramsCount = 0;
  135. if (!string.IsNullOrWhiteSpace(urgent))
  136. {
  137. if (urgent.Equals("true"))
  138. {
  139. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  140. }
  141. }
  142. if (!string.IsNullOrWhiteSpace(back))
  143. {
  144. if (back.Equals("true"))
  145. {
  146. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  147. }
  148. }
  149. if (!string.IsNullOrWhiteSpace(offlineSearch))
  150. {
  151. if (offlineSearch.Equals("true"))
  152. {
  153. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  154. }
  155. }
  156. //end
  157. string date2 = GetPostString("date2");
  158. string buyernick = GetPostString("buyer_nick");
  159. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  160. {
  161. if (tid.Length <= 0 && buyernick.Length <= 0)
  162. {
  163. return;
  164. }
  165. }
  166. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  167. {
  168. if (tid.Length > 0)
  169. {
  170. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  171. if (ceErpTradeCell != null)
  172. {
  173. tid = ceErpTradeCell.tid;
  174. }
  175. List<string> select_tid = getTidByCtidMore(tid);
  176. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  177. }
  178. if (buyernick.Length > 0)
  179. {
  180. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  181. }
  182. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  183. if (dw.Length > 0)
  184. {
  185. lw.Add(dw);
  186. }
  187. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  188. {
  189. string usershop = "0," + CurrentUser.User.pemShop;
  190. lw.Add(string.Format("ShopId in ({0})", usershop));
  191. }
  192. }
  193. else
  194. {
  195. if (ex_psize == 0)
  196. {
  197. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  198. }
  199. if (PKey != "admin" && poscode != "SysAdmin")
  200. {
  201. string usershop = "0," + CurrentUser.User.pemShop;
  202. lw.Add(string.Format("ShopId in ({0})", usershop));
  203. paramsCount++;
  204. }
  205. }
  206. string uploaddate1 = GetPostString("uploaddate1");
  207. string uploaddate2 = GetPostString("uploaddate2");
  208. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  209. if (update.Length > 0) lw.Add(update);
  210. string deliverydate1 = GetPostString("deliverydate1");
  211. string deliverydate2 = GetPostString("deliverydate2");
  212. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  213. if (deliverydate.Length > 0)
  214. {
  215. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  216. };
  217. string shopname = GetPostString("shopname");
  218. if (shopname.Length > 0)
  219. {
  220. CeErpShop ceErpShop = CeErpShop.GetShopIdByName(shopname);
  221. if (ceErpShop != null)
  222. {
  223. lw.Add(string.Format("shopId = {0}", ceErpShop.ID));
  224. }
  225. }
  226. string addwechat = GetPostString("addwechat");
  227. if (addwechat.Length > 0)
  228. {
  229. int addWt = Convert.ToInt32(addwechat);
  230. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  231. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  232. }
  233. string customer = GetPostString("customer");
  234. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  235. string design = GetPostString("design");
  236. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  237. string orderState = GetPostString("orderState");
  238. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  239. string address = GetPostString("address");
  240. 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));
  241. string sellermemo = GetPostString("seller_memo");
  242. if (sellermemo.Length > 0)
  243. {
  244. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  245. }
  246. string otherMemo = GetPostString("otherMemo");
  247. if (otherMemo.Length > 0)
  248. {
  249. lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  250. }
  251. string backReason = GetPostString("backReason");
  252. if (backReason.Length > 0)
  253. {
  254. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  255. }
  256. string apdate1 = GetPostString("apdate1");
  257. string apdate2 = GetPostString("apdate2");
  258. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  259. if (dwap.Length > 0) lw.Add(dwap);
  260. string price1 = GetPostString("price1");
  261. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  262. string price2 = GetPostString("price2");
  263. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  264. string isoldcustomer = GetPostString("isoldcus");
  265. string buyer_id = GetPostString("buyer_id");
  266. if (buyer_id.Length > 0) lw.Add(string.Format("buyer_id = '{0}'", buyer_id));
  267. string spudata = GetPostString("spudata");
  268. if ("0".Equals(spudata))
  269. {
  270. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  271. }
  272. if ("1".Equals(spudata))
  273. {
  274. lw.Add(string.Format("spu_id <> ''"));
  275. }
  276. string finishdate1 = GetPostString("finishdate1");
  277. string finishdate2 = GetPostString("finishdate2");
  278. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  279. bool isFinish = false;
  280. if (finishdate.Length > 0)
  281. {
  282. lw.Add(finishdate);
  283. isFinish = true;
  284. paramsCount++;
  285. }
  286. if (isoldcustomer.Length > 0)
  287. {
  288. if ("2".Equals(isoldcustomer))
  289. {
  290. lw.Add(string.Format("VipCustomer=1"));
  291. }
  292. else
  293. {
  294. lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  295. }
  296. }
  297. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  298. if (ex_psize > 0)
  299. {
  300. int UserID = CurrentUser.UserID;
  301. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  302. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  303. {
  304. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  305. }
  306. dStruct.Order = "pay_time desc";
  307. }
  308. string isNew = GetPostString("isNew");
  309. if (isNew == "true")
  310. {
  311. lw.Add(string.Format("IsNew = {0}", 1));
  312. }
  313. string overtime = GetPostString("overtime");
  314. if (overtime == "1")
  315. {
  316. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  317. }
  318. String usePost = CurrentUser.UserPost.Post.Code;
  319. if (usePost.Equals("Operation") == true)
  320. {
  321. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  322. }
  323. else
  324. {
  325. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  326. }
  327. //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";
  328. if (dStruct.PageSize == 100000)
  329. {
  330. dStruct.Order = "";
  331. }
  332. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  333. DataTable dt = null;
  334. string tablename = "view_orderlist";
  335. if (isFinish)
  336. {
  337. tablename = "view_orderlist_end";
  338. }
  339. dt = WebCache.GetData(tablename, dStruct);
  340. if (dt != null && dt.Rows.Count > 0)
  341. {
  342. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  343. foreach (DataRow dr in dt.Rows)
  344. {
  345. try
  346. {
  347. if (dr["refund_fees"] != null)
  348. {
  349. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  350. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  351. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  352. if (payment == refund_fees)
  353. {
  354. dr["refund_fees"] = Math.Round(refund_fees, 2);
  355. }
  356. else if (refund_fees == total_fee)
  357. {
  358. dr["refund_fees"] = payment;
  359. }
  360. else
  361. {
  362. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  363. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  364. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  365. }
  366. }
  367. // 对象操作
  368. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  369. ceErpTradeCell.ctid = dr["ctid"].ToString();
  370. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  371. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  372. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  373. if (dStruct.PageSize != 100000)
  374. {
  375. if (dr["DispatchSort"].ToString() == "2")
  376. {
  377. dr["gongchuang"] = 200;
  378. }
  379. else if ("外协".Equals(dr["ToType"].ToString()))
  380. {
  381. dr["gongchuang"] = 200;
  382. }
  383. else if ("内部".Equals(dr["ToType"].ToString()))
  384. {
  385. dr["gongchuang"] = -1;
  386. }
  387. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  388. {
  389. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  390. dr["gongchuang"] = response.code;
  391. }
  392. }
  393. }
  394. catch (NullReferenceException ex)
  395. {
  396. // 处理空引用异常
  397. dr["refund_fees"] = "0.00";
  398. }
  399. }
  400. }
  401. writeGridDataTableJson(dStruct.TotalCount, dt);
  402. }
  403. public void get_erp_orderlist_sumprice()
  404. {
  405. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  406. return;
  407. List<string> lw = new List<string>();
  408. string tid = GetPostString("ctid");
  409. string date1 = GetPostString("date1");
  410. string date2 = GetPostString("date2");
  411. if (tid.Length > 0 || date1.Length > 0)
  412. {
  413. lw.Add(string.Format("ctid like '%{0}%'", tid));
  414. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  415. if (dw.Length > 0) lw.Add(dw);
  416. }
  417. else
  418. {
  419. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  420. }
  421. string shopname = GetPostString("shopname");
  422. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  423. string buyernick = GetPostString("buyer_nick");
  424. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  425. string customer = GetPostString("customer");
  426. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  427. string design = GetPostString("design");
  428. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  429. string orderState = GetPostString("orderState");
  430. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  431. string address = GetPostString("address");
  432. 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));
  433. string sellermemo = GetPostString("seller_memo");
  434. if (sellermemo.Length > 0)
  435. {
  436. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  437. }
  438. string apdate1 = GetPostString("apdate1");
  439. string apdate2 = GetPostString("apdate2");
  440. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  441. if (dwap.Length > 0) lw.Add(dwap);
  442. string price1 = GetPostString("price1");
  443. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  444. string price2 = GetPostString("price2");
  445. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  446. string isoldcustomer = GetPostString("isoldcus");
  447. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  448. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  449. if (PKey != "admin")
  450. {
  451. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  452. lw.Add(string.Format("shopId in ({0})", usershop));
  453. }
  454. //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";
  455. string mainWhere = string.Join(" and ", lw.ToArray());
  456. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  457. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  458. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  459. decimal total = 0;
  460. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  461. {
  462. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  463. }
  464. var res = new
  465. {
  466. data = total
  467. };
  468. string ro_jsond = JsonConvert.SerializeObject(res);
  469. returnSuccess(ro_jsond);
  470. return;
  471. }
  472. public void get_erp_CustomerServiceGather()
  473. {
  474. string userWhere = "", orderWhere = "";
  475. List<string> lw = new List<string>();
  476. string customer = GetPostString("customer");
  477. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  478. string shopname = GetPostString("shopname");
  479. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  480. string date1 = GetPostString("date1");
  481. string date2 = GetPostString("date2");
  482. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  483. if (dw.Length > 0) lw.Add(dw);
  484. orderWhere = string.Join(" and ", lw.ToArray());
  485. 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 " +
  486. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  487. "left join " +
  488. "( " +
  489. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  490. ") as b on a.ID = b.CustomerUserId " +
  491. "left join " +
  492. "( " +
  493. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  494. ") as d on a.ID = d.CustomerUserId " +
  495. "left join " +
  496. "( " +
  497. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  498. ") as e on a.ID = e.CustomerUserId " +
  499. "left join " +
  500. "( " +
  501. " select CustomerUserId, RefundCount, RefundSum from " +
  502. " ( " +
  503. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  504. " from CE_ErpTradeRefund a " +
  505. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  506. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  507. " group by CustomerUserId " +
  508. " ) as a " +
  509. ") as f on a.ID = f.CustomerUserId " +
  510. "where a.PostCode = 'CustomerService'",
  511. userWhere, orderWhere);
  512. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  513. writeGridDataTableJson(dt.Rows.Count, dt);
  514. //writeGridDataTableJson(dt.Rows.Count, dt);
  515. }
  516. //设计汇总
  517. public void get_erp_DesignerGather()
  518. {
  519. string userWhere = "", orderWhere = "";
  520. List<string> lw = new List<string>();
  521. string Designer = GetPostString("designer");
  522. int org = GetPostInt("org");
  523. if (Designer.Length > 0)
  524. {
  525. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  526. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  527. }
  528. else if (org > 0)
  529. {
  530. userWhere = string.Format(" where OrgID ={0}", org);
  531. }
  532. string shopname = GetPostString("shopname");
  533. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  534. string state = GetPostString("state");
  535. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  536. string OrderArea = GetPostString("order_area");
  537. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  538. string date1 = GetPostString("date1");
  539. string date2 = GetPostString("date2");
  540. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  541. if (dw.Length > 0) lw.Add(dw);
  542. string UpDate1 = GetPostString("UpDate1");
  543. string UpDate2 = GetPostString("UpDate2");
  544. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  545. if (dw.Length > 0) lw.Add(dw);
  546. orderWhere = string.Join(" and ", lw.ToArray());
  547. 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 (" +
  548. "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 " +
  549. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  550. "left join " +
  551. "( " +
  552. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  553. ") as b on a.ID = b.DesignUserId " +
  554. "left join " +
  555. "( " +
  556. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  557. ") as d on a.ID = d.DesignUserId " +
  558. "left join " +
  559. "( " +
  560. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  561. ") as e on a.ID = e.DesignUserId " +
  562. "left join " +
  563. "( " +
  564. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  565. ") as g on a.ID = g.DesignUserId " +
  566. "left join " +
  567. "( " +
  568. " select CustomerUserId, RefundCount, RefundSum from " +
  569. " ( " +
  570. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  571. " from CE_ErpTradeRefund a " +
  572. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  573. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  574. " group by CustomerUserId " +
  575. " ) as a " +
  576. ") as f on a.ID = f.CustomerUserId " +
  577. "where a.PostCode = 'Designer') as z",
  578. userWhere, orderWhere);
  579. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  580. writeGridDataTableJson(dt.Rows.Count, dt);
  581. }
  582. //删除tradecell的订单
  583. public void del_erp_cellorder()
  584. {
  585. if (UrlPostParmsCheck("ctid"))
  586. {
  587. string eid = GetPostString("ctid");
  588. CeErpTradeCell.DelByCtid(eid);
  589. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  590. returnSuccessMsg("删除成功");
  591. }
  592. }
  593. public void clear_erp_refundstate()
  594. {
  595. if (UrlPostParmsCheck("ids"))
  596. {
  597. string eids = GetPostString("ids");
  598. string[] ctidList = eids.Split(',');
  599. foreach (string ctid in ctidList)
  600. {
  601. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  602. if (entity != null)
  603. {
  604. entity.IsRefund = 0;
  605. entity.Update();
  606. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  607. }
  608. else
  609. continue;
  610. }
  611. returnSuccessMsg("操作成功");
  612. return;
  613. }
  614. returnErrorMsg("缺少必要参数");
  615. }
  616. public void set_erp_urgency()
  617. {
  618. if (UrlPostParmsCheck("ctid"))
  619. {
  620. string eid = GetPostString("ctid");
  621. CeErpTradeCell entity = null;
  622. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  623. if (entity != null)
  624. {
  625. double prices = commonHelper.calculationPrice(entity);
  626. if (prices <= 100)
  627. {
  628. returnErrorMsg("此订单金额不足100元,无法加急。");
  629. return;
  630. }
  631. string utime = GetPostString("urgencytime");
  632. if (utime.Length > 0)
  633. {
  634. entity.UrgencyTime = Convert.ToDateTime(utime);
  635. }
  636. else
  637. {
  638. returnErrorMsg("请选择加急时间");
  639. return;
  640. }
  641. if (entity.OrderState <= 4)
  642. {
  643. //entity.seller_memo = entity.seller_memo + "-加急";
  644. string smemo = entity.seller_memo;
  645. int kindex = smemo.IndexOf(")");
  646. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  647. if (lastoneStr != "-")
  648. {
  649. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  650. }
  651. string prememo = smemo.Substring(0, kindex + 2);
  652. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  653. int lastkindex = lastmemo.IndexOf("(");
  654. DateTime urgtime = Convert.ToDateTime(utime);
  655. string newlastmemo = "";
  656. if (lastkindex == 0)
  657. {
  658. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  659. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  660. }
  661. else
  662. {
  663. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  664. }
  665. entity.seller_memo = prememo + newlastmemo;
  666. }
  667. entity.IsUrgency = true;
  668. entity.UpdateTime = DateTime.Now;
  669. entity.Update();
  670. ApiVo apiVo = new ApiVo();
  671. apiVo.orderNumber = entity.ctid;
  672. apiVo.actionName = "changeDesign";
  673. apiVo.orderRemarks = entity.seller_memo;
  674. apiVo.remarkSign = 3;
  675. designHelper.API_WorkCore(apiVo); //changeDesign
  676. CeErpSukuraData.createInfo(entity.ctid, 7);
  677. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  678. returnSuccessMsg("设置成功!");
  679. return;
  680. }
  681. returnErrorMsg("找不到记录");
  682. }
  683. }
  684. public void set_erp_reset()
  685. {
  686. if (UrlPostParmsCheck("ctid"))
  687. {
  688. string eid = GetPostString("ctid");
  689. CeErpTradeCell entity = null;
  690. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  691. if (entity != null)
  692. {
  693. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  694. {
  695. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  696. {
  697. returnErrorMsg("财务要求已下单已发货无法重置");
  698. return;
  699. }
  700. }
  701. entity.IsUrgency = false;
  702. entity.seller_memo = "";
  703. entity.OtherMemo = "";
  704. entity.OrderState = 0;
  705. entity.IsReturn = 0;
  706. //entity.IsRefund = 0;
  707. entity.MemoOpt = 0;
  708. entity.AfterSaleState = 0;
  709. entity.AfterSaleResponsible = "";
  710. entity.AfterSaleUserId = 0;
  711. entity.IsNeedBill = 0;
  712. entity.CustomerUserId = 0;
  713. entity.DesignUserId = 0;
  714. entity.SupplierId = 0;
  715. entity.PlaceUserId = 0;
  716. entity.ptid = "";
  717. entity.IsSample = 0;
  718. entity.IsXianHuo = 0;
  719. entity.isDianziOrder = 0;
  720. entity.DispatchSort = 0;
  721. entity.IsVerifyToSupplier = false;
  722. entity.FinishPlaceTime = null;
  723. entity.Update();
  724. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  725. if (trade != null)
  726. {
  727. trade.seller_memo = "";
  728. trade.Update();
  729. }
  730. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  731. returnSuccessMsg("重置成功!");
  732. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  733. if (desginBill != null)
  734. {
  735. desginBill.isDel = 1;
  736. desginBill.Update();
  737. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  738. }
  739. ApiVo apiVo = new ApiVo();
  740. apiVo.orderNumber = entity.ctid;
  741. apiVo.actionName = "resetDesign";
  742. designHelper.API_WorkCore(apiVo);//resetDesign
  743. return;
  744. }
  745. returnErrorMsg("找不到记录");
  746. }
  747. }
  748. public void save_erp_sellermemo()
  749. {
  750. if (UrlPostParmsCheck("ctid"))
  751. {
  752. string ctid = GetPostString("ctid");
  753. CeErpTradeCell entity = null;
  754. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  755. if (entity != null)
  756. {
  757. string memo = GetPostString("seller_memo");
  758. string qn_memo = GetPostString("qn_memo");
  759. memo = memo.Replace(" ", "");
  760. if (memo.Contains("补差"))
  761. {
  762. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  763. return;
  764. }
  765. List<string> bitList = new List<string>
  766. {
  767. "\\","/",":","*","?", "\"","<" ,">","|"
  768. };
  769. bool isIn = false;
  770. foreach (string bit in bitList)
  771. {
  772. if (memo.Contains(bit))
  773. {
  774. isIn = true;
  775. }
  776. }
  777. if (isIn)
  778. {
  779. returnErrorMsg("不能使用 一些符合作为文件名");
  780. return;
  781. }
  782. if (entity.seller_memo != memo)
  783. {
  784. if (entity.IsSample == 2)
  785. {
  786. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  787. return;
  788. }
  789. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  790. {
  791. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  792. {
  793. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  794. return;
  795. }
  796. /*if (CurrentUser.UserPost.Post.Code != "Place")
  797. {
  798. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  799. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  800. {
  801. returnErrorMsg("售前系统订单无法再此修改!");
  802. return;
  803. }
  804. }*/
  805. }
  806. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  807. }
  808. if (!string.IsNullOrEmpty(qn_memo) && !(entity.IsSample > 0 || entity.ctid.Contains("N_") || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物")))
  809. {
  810. if (entity.OrderState >= 5)
  811. {
  812. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  813. return;
  814. }
  815. string delMemo = commonHelper.convertQNMemo(qn_memo, ref entity);
  816. if (string.IsNullOrEmpty(delMemo))
  817. {
  818. returnErrorMsg("备注不规范,无法识别");
  819. return;
  820. }
  821. memo = delMemo;
  822. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统千牛修改为:" + memo, entity.OrderState, 1);
  823. }
  824. //commonHelper.getCytPrice(entity);
  825. int memoopt = GetPostInt("MemoOpt");
  826. Boolean ismemoopt = false;
  827. if (memoopt > 0)
  828. {
  829. string stropt = "";
  830. if (memoopt == 1)
  831. {
  832. stropt = "“改稿”";
  833. ismemoopt = true;
  834. }
  835. else if (memoopt == 2)
  836. {
  837. stropt = "“定稿”";
  838. }
  839. else if (memoopt == 3)
  840. {
  841. stropt = "“查货”";
  842. CeErpSukuraData.createInfo(entity.ctid, 6);
  843. }
  844. entity.MemoOpt = Convert.ToInt32(memoopt);
  845. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  846. }
  847. if (entity.OrderState < 5)
  848. {
  849. memo = memo.Replace("(", "(");
  850. memo = memo.Replace(")", ")");
  851. }
  852. /* if (entity.OrderState < 3)
  853. {
  854. entity.DispatchSort = 0;
  855. }*/
  856. entity.seller_memo = memo;
  857. entity.UpdateTime = DateTime.Now;
  858. entity.Update();
  859. ApiVo apiVo = new ApiVo();
  860. apiVo.orderNumber = entity.ctid;
  861. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  862. apiVo.orderRemarks = memo;
  863. apiVo.remarkSign = memoopt;
  864. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  865. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  866. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  867. {
  868. //dataHelper.api_orderBack(entity.ctid, "0", "");
  869. }
  870. if (entity.seller_memo.Contains("改稿"))
  871. {
  872. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  873. }
  874. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  875. returnSuccessMsg("保存成功!");
  876. return;
  877. }
  878. returnErrorMsg("找不到记录");
  879. }
  880. }
  881. public void ins_erp_checkorder()
  882. {
  883. if (UrlPostParmsCheck("ctid"))
  884. {
  885. string ctid = GetPostString("ctid");
  886. CeErpTradeCell entity = null;
  887. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  888. if (entity != null)
  889. {
  890. if (entity.OrderState < 6)
  891. {
  892. returnErrorMsg("下单完成后才可查货");
  893. return;
  894. }
  895. /*if (entity.OrderState > 6)
  896. {
  897. returnErrorMsg("订单已发货");
  898. return;
  899. }*/
  900. if (entity.FinishPlaceTime != null)
  901. {
  902. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  903. {
  904. returnErrorMsg("下单时间不足,无法查货");
  905. return;
  906. }
  907. }
  908. entity.MemoOpt = 3;
  909. entity.CheckOrderTime = DateTime.Now;
  910. entity.UpdateTime = DateTime.Now;
  911. entity.Update();
  912. CeErpSukuraData.createInfo(entity.ctid, 6);
  913. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  914. returnSuccessMsg("操作成功!");
  915. return;
  916. }
  917. returnErrorMsg("找不到记录");
  918. }
  919. }
  920. public void save_erp_othermemo()
  921. {
  922. if (UrlPostParmsCheck("ctid"))
  923. {
  924. string ctid = GetPostString("ctid");
  925. CeErpTradeCell entity = null;
  926. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  927. if (entity != null)
  928. {
  929. entity.OtherMemo = GetPostString("otherMemo");
  930. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  931. {
  932. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  933. StringBuilder sql = new StringBuilder();
  934. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  935. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  936. if (dt != null && dt.Rows.Count > 0)
  937. {
  938. foreach (DataRow dr in dt.Rows)
  939. {
  940. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  941. {
  942. //品类一直
  943. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  944. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  945. if (ceErpSampleCustomer == null)
  946. {
  947. ceErpSampleCustomer = new CeErpSampleCustomer();
  948. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  949. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  950. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  951. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  952. ceErpSampleCustomer.shopId = entity.ShopId;
  953. }
  954. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  955. ceErpSampleCustomer.lastTid = entity.tid;
  956. if (ceErpSampleCustomer.ID > 0)
  957. {
  958. ceErpSampleCustomer.Update();
  959. }
  960. else
  961. {
  962. ceErpSampleCustomer.Create();
  963. }
  964. }
  965. }
  966. }
  967. }
  968. //if (entity.IsOldCustomer == 1)
  969. //{
  970. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  971. //{
  972. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  973. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  974. //}
  975. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  976. //{
  977. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  978. // {
  979. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  980. // {
  981. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  982. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  983. // }
  984. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  985. // {
  986. // entity.OrderState = 2;
  987. // entity.DesignUserId = 0;
  988. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  989. // }
  990. // else
  991. // {
  992. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  993. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  994. // }
  995. // }
  996. //}
  997. //}
  998. entity.UpdateTime = DateTime.Now;
  999. entity.Update();
  1000. returnSuccessMsg("保存成功!");
  1001. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  1002. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  1003. if (entity.OtherMemo.Contains("改稿"))
  1004. {
  1005. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  1006. }
  1007. return;
  1008. }
  1009. returnErrorMsg("找不到记录");
  1010. }
  1011. }
  1012. public void save_erp_customermemo()
  1013. {
  1014. if (UrlPostParmsCheck("ctid"))
  1015. {
  1016. string ctid = GetPostString("ctid");
  1017. CeErpTradeCell entity = null;
  1018. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1019. if (entity != null)
  1020. {
  1021. entity.UpdateTime = DateTime.Now;
  1022. entity.CustomerMemo = GetPostString("CustomerMemo");
  1023. entity.Update();
  1024. ApiVo apiVo = new ApiVo();
  1025. apiVo.orderNumber = entity.ctid;
  1026. apiVo.actionName = "followRemarks";
  1027. apiVo.orderRemarks = entity.CustomerMemo;
  1028. designHelper.API_WorkCore(apiVo);//followRemarks
  1029. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  1030. returnSuccessMsg("保存成功!");
  1031. return;
  1032. }
  1033. returnErrorMsg("找不到记录");
  1034. }
  1035. }
  1036. public void upd_erp_addmemotag()
  1037. {
  1038. if (UrlPostParmsCheck("ctid"))
  1039. {
  1040. ;
  1041. string eid = GetPostString("ctid");
  1042. string sfTagstr = GetPostString("memotag");
  1043. CeErpTradeCell entity = null;
  1044. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1045. if (entity != null)
  1046. {
  1047. ApiVo apiVo = new ApiVo();
  1048. if (entity.OrderState == 0)
  1049. {
  1050. returnErrorMsg("请先领单");
  1051. return;
  1052. }
  1053. //撤销顺丰
  1054. if (sfTagstr == "撤销顺丰")
  1055. {
  1056. entity.IsSF = 0;
  1057. string reMsg = "";
  1058. string oldmemo = entity.seller_memo;
  1059. if (entity.OrderState < 5)
  1060. {
  1061. oldmemo = oldmemo.Replace("顺丰到付", "");
  1062. oldmemo = oldmemo.Replace("顺丰寄付", "");
  1063. entity.seller_memo = oldmemo;
  1064. }
  1065. else
  1066. {
  1067. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  1068. {
  1069. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  1070. }
  1071. }
  1072. entity.Update();
  1073. apiVo.orderNumber = entity.ctid;
  1074. apiVo.actionName = "orderRemarks";
  1075. apiVo.orderRemarks = entity.seller_memo;
  1076. apiVo.isSf = entity.IsSF.ToString();
  1077. designHelper.API_WorkCore(apiVo);//orderRemarks
  1078. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  1079. returnSuccessMsg("撤销成功!" + reMsg);
  1080. return;
  1081. }
  1082. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  1083. {
  1084. //string oldmemo = entity.seller_memo;
  1085. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  1086. string sfStr = GetPostString("memotag");
  1087. string smemo = entity.seller_memo;
  1088. int kindex = smemo.IndexOf(")");
  1089. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  1090. if (lastoneStr != "-")
  1091. {
  1092. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  1093. }
  1094. string prememo = smemo.Substring(0, kindex + 2);
  1095. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  1096. int lastkindex = lastmemo.IndexOf("(");
  1097. string newlastmemo = "";
  1098. if (lastkindex == 0)
  1099. {
  1100. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1101. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1102. }
  1103. else
  1104. {
  1105. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1106. }
  1107. entity.seller_memo = prememo + newlastmemo;
  1108. }
  1109. string sfTagMSg = "";
  1110. if (sfTagstr == "顺丰寄付")
  1111. {
  1112. entity.IsSF = 1;
  1113. sfTagMSg = "顺丰寄付";
  1114. }
  1115. else if (sfTagstr == "顺丰到付")
  1116. {
  1117. entity.IsSF = 2;
  1118. sfTagMSg = "顺丰到付";
  1119. }
  1120. if (entity.SupplierId == 19 && entity.OrderState == 6)
  1121. {
  1122. string deliveryWayName = "";
  1123. if (sfTagstr == "撤销顺丰")
  1124. {
  1125. sfTagstr = "普通快递";
  1126. }
  1127. if (sfTagstr == "顺丰寄付")
  1128. {
  1129. sfTagstr = "顺丰特快寄付";
  1130. }
  1131. if (sfTagstr == "顺丰到付")
  1132. {
  1133. sfTagstr = "顺丰特快到付";
  1134. }
  1135. string result = apichyHelper.updateExpressMark(entity.tid, sfTagstr);
  1136. if ("修改失败".Equals(result))
  1137. {
  1138. returnErrorMsg("修改失败");
  1139. return;
  1140. }
  1141. }
  1142. entity.Update();
  1143. apiVo = new ApiVo();
  1144. apiVo.orderNumber = entity.ctid;
  1145. apiVo.actionName = "orderRemarks";
  1146. apiVo.orderRemarks = entity.seller_memo;
  1147. apiVo.isSf = entity.IsSF.ToString();
  1148. designHelper.API_WorkCore(apiVo);//orderRemarks
  1149. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1150. returnSuccessMsg("标记成功!");
  1151. return;
  1152. }
  1153. returnErrorMsg("找不到记录");
  1154. }
  1155. }
  1156. public void upd_erp_ordertag()
  1157. {
  1158. if (UrlPostParmsCheck("ctid"))
  1159. {
  1160. string eid = GetPostString("ctid");
  1161. CeErpTradeCell entity = null;
  1162. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1163. if (entity != null)
  1164. {
  1165. int tag = GetPostInt("wechattag");
  1166. //if(tag==4 && entity.IsSample == 2)
  1167. //{
  1168. // returnErrorMsg("补差价单不能标记微信单");
  1169. // return;
  1170. //}
  1171. entity.wechatTag = tag;
  1172. entity.Update();
  1173. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1174. if (tag == 1)
  1175. {
  1176. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1177. if (cash == null)
  1178. {
  1179. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1180. cash = new CeErpReturnCash();
  1181. cash.tid = entity.tid;
  1182. cash.seller_nick = main.seller_nick;
  1183. cash.payment = trade.payment;
  1184. cash.buyer_nick = main.buyer_nick;
  1185. cash.cashstate = 0;
  1186. cash.rtype = "微信返现";
  1187. cash.returnprice = 0;
  1188. cash.created = DateTime.Now;
  1189. cash.con = "订单标记微信单";
  1190. cash.img = "";
  1191. cash.applyuserid = CurrentUser.UserID;
  1192. cash.Create();
  1193. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1194. }
  1195. else
  1196. {
  1197. cash.cashstate = 0;
  1198. cash.Update();
  1199. }
  1200. CeErpSukuraData.createInfo(entity.ctid, 9);
  1201. }
  1202. else if (tag == 2)
  1203. {
  1204. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1205. if (cash == null)
  1206. {
  1207. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1208. cash = new CeErpReturnCash();
  1209. cash.tid = entity.tid;
  1210. cash.seller_nick = main.seller_nick;
  1211. cash.payment = trade.payment;
  1212. cash.buyer_nick = main.buyer_nick;
  1213. cash.cashstate = 0;
  1214. cash.rtype = "推购返现";
  1215. cash.returnprice = 5;
  1216. cash.created = DateTime.Now;
  1217. cash.con = "订单标记推购单";
  1218. cash.img = "";
  1219. cash.applyuserid = CurrentUser.UserID;
  1220. cash.Create();
  1221. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1222. }
  1223. else
  1224. {
  1225. cash.cashstate = 0;
  1226. cash.Update();
  1227. }
  1228. CeErpSukuraData.createInfo(entity.ctid, 9);
  1229. }
  1230. else if (tag == 3)
  1231. {
  1232. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1233. if (pers == null)
  1234. {
  1235. pers = new CeErpPersuade();
  1236. pers.ctid = entity.ctid;
  1237. pers.pstate = 0;
  1238. pers.created = DateTime.Now;
  1239. pers.applyuserid = CurrentUser.UserID;
  1240. pers.Create();
  1241. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1242. }
  1243. else
  1244. {
  1245. pers.pstate = 0;
  1246. pers.Update();
  1247. }
  1248. }
  1249. else if (tag == 4 || tag == 5)
  1250. {
  1251. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1252. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1253. if (pers == null)
  1254. {
  1255. pers = CeErpStayGoods.GetByTid(entity.tid);
  1256. }
  1257. if (pers == null)
  1258. {
  1259. pers = new CeErpStayGoods();
  1260. pers.t_id = entity.tid;
  1261. pers.ctid = entity.ctid;
  1262. pers.status = "待审核";
  1263. pers.audit_type = 0;
  1264. if (tag == 4)
  1265. {
  1266. pers.stay_type = "微信推购";
  1267. }
  1268. else
  1269. {
  1270. pers.stay_type = "旺旺推购";
  1271. }
  1272. if (entity.IsXianHuo == 0)
  1273. {
  1274. pers.product_id = entity.ProductId;
  1275. }
  1276. pers.wangwang = main.buyer_nick;
  1277. pers.shop_name = main.seller_nick;
  1278. pers.creata_time = DateTime.Now;
  1279. pers.create_u_id = CurrentUser.UserID;
  1280. pers.create_u_name = CurrentUser.UserName;
  1281. pers.Create();
  1282. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1283. }
  1284. else
  1285. {
  1286. pers.ctid = entity.ctid;
  1287. pers.audit_type = 0;
  1288. pers.Update();
  1289. }
  1290. CeErpSukuraData.createInfo(entity.ctid, 10);
  1291. }
  1292. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1293. returnSuccessMsg("标记成功!");
  1294. return;
  1295. }
  1296. returnErrorMsg("找不到记录");
  1297. }
  1298. }
  1299. public void upd_erp_ordertag_cancel()
  1300. {
  1301. if (UrlPostParmsCheck("ctid"))
  1302. {
  1303. string eid = GetPostString("ctid");
  1304. CeErpTradeCell entity = null;
  1305. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1306. if (entity != null)
  1307. {
  1308. entity.wechatTag = 0;
  1309. entity.Update();
  1310. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1311. if (pers != null)
  1312. {
  1313. pers.status = "取消推购";
  1314. pers.audit_type = 3;
  1315. pers.Update();
  1316. }
  1317. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1318. returnSuccessMsg("标记成功!");
  1319. return;
  1320. }
  1321. returnErrorMsg("找不到记录");
  1322. }
  1323. }
  1324. public void upd_erp_addweichattag()
  1325. {
  1326. if (UrlPostParmsCheck("ctid"))
  1327. {
  1328. ;
  1329. string eid = GetPostString("ctid");
  1330. CeErpTradeCell entity = null;
  1331. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1332. if (entity != null)
  1333. {
  1334. if (entity.IsAddWechat > 0)
  1335. {
  1336. returnErrorMsg("此单已经标记过了");
  1337. return;
  1338. }
  1339. 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);
  1340. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1341. if (dt.Rows.Count > 0)
  1342. {
  1343. entity.IsAddWechat = 2;
  1344. }
  1345. else
  1346. {
  1347. entity.IsAddWechat = 1;
  1348. }
  1349. entity.Update();
  1350. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1351. returnSuccessMsg("标记成功!");
  1352. return;
  1353. }
  1354. returnErrorMsg("找不到记录");
  1355. }
  1356. }
  1357. public void upd_erp_getmyorder()
  1358. {
  1359. if (UrlPostParmsCheck("ctid"))
  1360. {
  1361. string eid = GetPostString("ctid");
  1362. CeErpTradeCell entity = null;
  1363. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1364. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1365. /*if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1366. {
  1367. returnErrorMsg("台湾客户需填写身份证号!");
  1368. return;
  1369. }*/
  1370. if (commonHelper.isFarAddress(father.receiver_state) && father.delivery_paymant == 0)
  1371. {
  1372. returnErrorMsg("偏远地区需要填写物流费!");
  1373. return;
  1374. }
  1375. if (entity != null)
  1376. {
  1377. if (entity.ctid.IndexOf("C") != -1)
  1378. {
  1379. StringBuilder sql = new StringBuilder();
  1380. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1381. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1382. if (dt.Rows.Count > 0)
  1383. {
  1384. decimal total = 0;
  1385. foreach (DataRow dr in dt.Rows)
  1386. {
  1387. total += Convert.ToDecimal(dr["payment"]);
  1388. }
  1389. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1390. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1391. {
  1392. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1393. return;
  1394. }
  1395. }
  1396. }
  1397. if (entity.OrderState == -1)
  1398. {
  1399. returnErrorMsg("待审核订单无法领取!");
  1400. return;
  1401. }
  1402. entity.CustomerUserId = CurrentUser.UserID;
  1403. if (entity.OrderState < 2)
  1404. {
  1405. entity.OrderState = 2;
  1406. if (entity.ShopId != 0)
  1407. {
  1408. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1409. }
  1410. }
  1411. entity.UpdateTime = DateTime.Now;
  1412. entity.Update();
  1413. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1414. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1415. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1416. {
  1417. //dataHelper.api_orderBack(entity.ctid, "0", "");
  1418. }
  1419. returnSuccessMsg("领单成功!");
  1420. return;
  1421. }
  1422. returnErrorMsg("找不到记录");
  1423. }
  1424. }
  1425. public void getmyorder_from_init()
  1426. {
  1427. if (UrlPostParmsCheck("ctid"))
  1428. {
  1429. string eid = GetPostString("ctid");
  1430. CeErpTradeCell entity = null;
  1431. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1432. if (entity != null)
  1433. {
  1434. string sellerMemo = GetPostString("sellerMemo");
  1435. if (sellerMemo.Length > 0)
  1436. {
  1437. entity.seller_memo = sellerMemo;
  1438. }
  1439. string oterhMemo = GetPostString("otherMemo");
  1440. if (oterhMemo.Length > 0)
  1441. {
  1442. entity.OtherMemo = oterhMemo;
  1443. }
  1444. int urg = GetPostInt("urgency");
  1445. entity.IsUrgency = (urg == 1 ? true : false);
  1446. int wechat = GetPostInt("wechat");
  1447. int command = GetPostInt("command");
  1448. if (wechat == 1)
  1449. {
  1450. entity.wechatTag = 1;
  1451. }
  1452. if (command == 1)
  1453. {
  1454. entity.wechatTag = 2;
  1455. }
  1456. string pPro = GetPostString("pprofession");
  1457. if (pPro.Length > 0)
  1458. {
  1459. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1460. string spro = GetPostString("profession");
  1461. if (spro.Length > 0)
  1462. {
  1463. entity.ProfessionId = Convert.ToInt32(spro);
  1464. }
  1465. }
  1466. string proId = GetPostString("productId");
  1467. if (proId.Length > 0)
  1468. {
  1469. entity.ProductId = Convert.ToInt32(proId);
  1470. }
  1471. entity.Material = GetPostString("material");
  1472. entity.Craft = GetPostString("craft");
  1473. entity.CustomerUserId = CurrentUser.UserID;
  1474. if (entity.OrderState < 2)
  1475. {
  1476. entity.OrderState = 2;
  1477. if (entity.ShopId != 0)
  1478. {
  1479. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1480. }
  1481. }
  1482. entity.Update();
  1483. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1484. returnSuccessMsg("领单成功!");
  1485. return;
  1486. }
  1487. returnErrorMsg("找不到记录");
  1488. }
  1489. }
  1490. public void upd_erp_setrelationorder()
  1491. {
  1492. if (UrlPostParmsCheck("ctid"))
  1493. {
  1494. ;
  1495. string eid = GetPostString("ctid");
  1496. string ftid = GetPostString("ftid");
  1497. CeErpTradeCell entity = null;
  1498. CeErpTradeCell fentity = null;
  1499. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1500. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1501. if (fentity == null)
  1502. {
  1503. returnErrorMsg("找不到关联的主订单");
  1504. return;
  1505. }
  1506. if (entity != null)
  1507. {
  1508. if (entity.OrderState >= 5)
  1509. {
  1510. returnErrorMsg("本单已经设计完成无法关联");
  1511. return;
  1512. }
  1513. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1514. {
  1515. returnErrorMsg("线下单续审核后才能关联!");
  1516. return;
  1517. }
  1518. entity.ptid = ftid;
  1519. entity.OrderState = fentity.OrderState;
  1520. //entity.status = fentity.status;
  1521. entity.CustomerUserId = fentity.CustomerUserId;
  1522. entity.DesignUserId = fentity.DesignUserId;
  1523. entity.seller_memo = "补差价单:" + ftid;
  1524. entity.IsSample = 2;
  1525. entity.Update();
  1526. ApiVo apiVo = new ApiVo();
  1527. apiVo.orderNumber = ftid;
  1528. apiVo.payment = entity.payment;
  1529. apiVo.actionName = "repairDesign";
  1530. designHelper.API_WorkCore(apiVo);//repairDesign
  1531. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1532. returnSuccessMsg("关联成功!");
  1533. return;
  1534. }
  1535. else
  1536. returnErrorMsg("找不到记录");
  1537. }
  1538. }
  1539. public void download_erp_neworder()
  1540. {
  1541. string seller = GetPostString("seller_nick");
  1542. string tid = GetPostString("tid");
  1543. if (seller.Length <= 0 || tid.Length <= 0)
  1544. {
  1545. returnErrorMsg("数据错误");
  1546. }
  1547. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1548. //{
  1549. // returnErrorMsg("找不到店铺Sessionkey");
  1550. //}
  1551. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1552. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1553. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1554. if (res.IndexOf("refOid") == -1)
  1555. {
  1556. returnErrorMsg("下载订单数据失败");
  1557. return;
  1558. }
  1559. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1560. returnSuccessMsg("下载完成");
  1561. //tmcHelper.createNewOrder(res);
  1562. //CeErpTrade entr = null;
  1563. //entr = CeErpTrade.Get(tid);
  1564. //if (entr != null)
  1565. //{
  1566. // returnSuccess("下载成功");
  1567. // //下载成功之后,Cell表生成对应的订单;
  1568. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1569. //}
  1570. //else
  1571. //{
  1572. // returnErrorMsg("下载失败或者创建订单失败");
  1573. //}
  1574. }
  1575. public void set_erp_atersale()
  1576. {
  1577. if (UrlPostParmsCheck("ctid"))
  1578. {
  1579. string eid = GetPostString("ctid");
  1580. string reason = GetPostString("AfterSaleReason");
  1581. CeErpTradeCell entity = null;
  1582. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1583. if (entity != null)
  1584. {
  1585. /*if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1586. {
  1587. returnErrorMsg("此订单已经在售后");
  1588. return;
  1589. }*/
  1590. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1591. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1592. entity.AfterSaleTime = DateTime.Now;
  1593. entity.HandleTime = null;
  1594. entity.Update();
  1595. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1596. returnSuccessMsg("转售后成功!");
  1597. return;
  1598. }
  1599. returnErrorMsg("找不到记录");
  1600. }
  1601. }
  1602. public void set_erp_withdraw()
  1603. {
  1604. if (UrlPostParmsCheck("ctid"))
  1605. {
  1606. try
  1607. {
  1608. string eid = GetPostString("ctid");//商品id
  1609. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1610. CeWithdraw ceWithdrawSelect = null;
  1611. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1612. if (ceWithdrawSelect != null)
  1613. {
  1614. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1615. {
  1616. ceWithdrawSelect.status = -1;
  1617. ceWithdrawSelect.Update();
  1618. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1619. returnSuccessMsg("重新发起审核成功");
  1620. return;
  1621. }
  1622. else
  1623. {
  1624. returnSuccessMsg("请勿重复申请!");
  1625. return;
  1626. }
  1627. }
  1628. else
  1629. {
  1630. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1631. if (string.IsNullOrEmpty(CustomerUserId))
  1632. {
  1633. CustomerUserId = "-1";
  1634. }
  1635. int Userid = CurrentUser.UserID;//用户id
  1636. CeWithdraw ceWithdraw = new CeWithdraw();
  1637. ceWithdraw.tid = eid;
  1638. ceWithdraw.userid = Userid;
  1639. ceWithdraw.providerid = CustomerUserId;
  1640. ceWithdraw.status = 3;
  1641. ceWithdraw.creationtime = DateTime.Now;
  1642. ceWithdraw.Create();
  1643. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1644. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1645. return;
  1646. }
  1647. }
  1648. catch
  1649. {
  1650. returnErrorMsg("申请撤回订单失败");
  1651. return;
  1652. }
  1653. }
  1654. }
  1655. public void ins_erp_billinfo()
  1656. {
  1657. if (UrlPostParmsCheck("ctid"))
  1658. {
  1659. string eid = GetPostString("ctid");
  1660. CeErpTradeCell entity = null;
  1661. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1662. if (entity != null)
  1663. {
  1664. CeErpBill bill = CeErpBill.GetByTid(eid);
  1665. bool isHave = false;
  1666. if (bill != null)
  1667. {
  1668. isHave = true;
  1669. if (bill.state != 4)
  1670. {
  1671. returnErrorMsg("此单已经申请过发票了");
  1672. return;
  1673. }
  1674. }
  1675. if (entity.IsNeedBill == 0)
  1676. {
  1677. entity.IsNeedBill = 1;
  1678. }
  1679. entity.Update();
  1680. string errjson = "";
  1681. try
  1682. {
  1683. CeErpBill bill_entity = new CeErpBill();
  1684. bill_entity.tid = entity.tid;
  1685. bill_entity.title = GetPostString("title");
  1686. string taxstr = GetPostString("tax");
  1687. taxstr = taxstr.Replace(" ", "");
  1688. bill_entity.tax = taxstr;
  1689. bill_entity.bank = GetPostString("bank");
  1690. string bankacstr = GetPostString("bankac");
  1691. bankacstr = bankacstr.Replace(" ", "");
  1692. bill_entity.bankac = bankacstr;
  1693. bill_entity.address = GetPostString("address");
  1694. bill_entity.phone = GetPostString("phone");
  1695. bill_entity.price = GetPostString("price");
  1696. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1697. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1698. {
  1699. billCount += 1;
  1700. }
  1701. string prebill = "ltb";
  1702. for (int idx = 1; idx <= 1; idx++)
  1703. {
  1704. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1705. string billoid = prebill + idx + dtstr;
  1706. bill_entity.billOrderId += billoid;
  1707. if (idx < billCount)
  1708. {
  1709. bill_entity.billOrderId += ",";
  1710. }
  1711. }
  1712. bill_entity.productId = GetPostInt("ProductName");
  1713. bill_entity.num = GetPostInt("num");
  1714. bill_entity.unit = GetPostString("unit");
  1715. bill_entity.type = GetPostString("type");
  1716. bill_entity.sendType = GetPostString("SendType");
  1717. bill_entity.email = GetPostString("email");
  1718. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1719. bill_entity.shopName = GetPostString("ShopName");
  1720. bill_entity.applymemo = GetPostString("applyMemo");
  1721. bill_entity.createTime = DateTime.Now;
  1722. bill_entity.state = 0;
  1723. bill_entity.userId = CurrentUser.UserID;
  1724. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1725. bill_entity.Create();
  1726. }
  1727. catch (Exception ex)
  1728. {
  1729. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1730. returnErrorMsg("创建发票出错!");
  1731. return;
  1732. }
  1733. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1734. returnSuccessMsg("发票申请成功!");
  1735. return;
  1736. }
  1737. returnErrorMsg("找不到记录");
  1738. }
  1739. }
  1740. public void ins_erp_neworder()
  1741. {
  1742. if (UrlPostParmsCheck("receiver_name"))
  1743. {
  1744. CeErpTrade entity = new CeErpTrade();
  1745. string plat_form = GetPostString("platform");
  1746. string preStr = "N_";
  1747. if (plat_form == "拼多多")
  1748. {
  1749. preStr = "P_";
  1750. }
  1751. else if (plat_form == "阿里巴巴")
  1752. {
  1753. preStr = "A_";
  1754. }
  1755. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1756. entity.seller_nick = GetPostString("seller_nick");
  1757. entity.buyer_nick = GetPostString("buyer_nick");
  1758. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1759. entity.total_fee = entity.payment;
  1760. entity.pay_time = DateTime.Now;
  1761. entity.status = "NOT_SHIPPED";
  1762. entity.receiver_name = GetPostString("receiver_name");
  1763. entity.receiver_mobile = GetPostString("receiver_mobile");
  1764. entity.receiver_state = GetPostString("receiver_state");
  1765. entity.receiver_city = GetPostString("receiver_city");
  1766. entity.receiver_district = GetPostString("receiver_district");
  1767. entity.receiver_address = GetPostString("receiver_address");
  1768. if (entity.receiver_state == "" || entity.receiver_city == "")
  1769. {
  1770. returnErrorMsg("收件地址不能为空");
  1771. return;
  1772. }
  1773. int shopId = 0;
  1774. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1775. if (nShop != null)
  1776. {
  1777. shopId = nShop.ID;
  1778. }
  1779. if (shopId != 34 && entity.payment == 0)
  1780. {
  1781. returnErrorMsg("公司自用的单金额才能为0");
  1782. return;
  1783. }
  1784. entity.Create();
  1785. CeErpTradeCell entitycell = new CeErpTradeCell();
  1786. entitycell.ctid = entity.tid;
  1787. entitycell.tid = entity.tid;
  1788. entitycell.ShopId = shopId;
  1789. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1790. entitycell.OrderState = 0;
  1791. entitycell.pay_time = entity.pay_time;
  1792. entitycell.IsOffLineOrder = 1;
  1793. entitycell.Create();
  1794. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1795. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1796. return;
  1797. }
  1798. }
  1799. public void ins_erp_neworder2()
  1800. {
  1801. if (UrlPostParmsCheck("receiver_name"))
  1802. {
  1803. //string plat_form = GetPostString("platform");
  1804. string preStr = "X_";
  1805. string memo = GetPostString("memo");
  1806. string productId = GetPostString("productId");
  1807. string primg = GetPostString("proofimg");
  1808. string sellerNick = GetPostString("seller_nick");
  1809. string addFrom = GetPostString("addfrom");
  1810. if (addFrom == "1")
  1811. {
  1812. preStr = "N_";
  1813. }
  1814. int shopId = 0;
  1815. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1816. if (nShop != null)
  1817. {
  1818. shopId = nShop.ID;
  1819. }
  1820. else
  1821. {
  1822. returnErrorMsg("找不到对应店铺");
  1823. return;
  1824. }
  1825. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1826. {
  1827. returnErrorMsg("必须上传付款凭证");
  1828. return;
  1829. }
  1830. CeErpTrade entity = new CeErpTrade();
  1831. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1832. entity.seller_nick = sellerNick;
  1833. entity.buyer_nick = GetPostString("buyer_nick");
  1834. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1835. entity.total_fee = entity.payment;
  1836. entity.pay_time = DateTime.Now;
  1837. entity.status = "NOT_SHIPPED";
  1838. entity.receiver_name = GetPostString("receiver_name");
  1839. entity.receiver_mobile = GetPostString("receiver_mobile");
  1840. entity.receiver_state = GetPostString("receiver_state");
  1841. entity.receiver_city = GetPostString("receiver_city");
  1842. entity.receiver_district = GetPostString("receiver_district");
  1843. entity.receiver_address = GetPostString("receiver_address");
  1844. entity.seller_memo = memo;
  1845. entity.orderFrom = 20;
  1846. entity.orderType = 15;
  1847. if (entity.receiver_state == "" || entity.receiver_city == "")
  1848. {
  1849. returnErrorMsg("收件地址不能为空");
  1850. return;
  1851. }
  1852. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1853. {
  1854. returnErrorMsg("公司自用的单金额才能为0");
  1855. return;
  1856. }
  1857. entity.Create();
  1858. string toWhere = GetPostString("towhere");
  1859. string oldOrder = GetPostString("oldOrder");
  1860. CeErpTradeCell entitycell = new CeErpTradeCell();
  1861. entitycell.ctid = entity.tid;
  1862. //唯一标识
  1863. entitycell.OrderSn = entity.tid;
  1864. string orderSn = commonHelper.generateDateTimeRandomNos();
  1865. if (orderSn != "")
  1866. {
  1867. entitycell.OrderSn = orderSn;
  1868. }
  1869. entitycell.tid = entity.tid;
  1870. //if (preStr == "X_")
  1871. //{
  1872. entitycell.IsOffLineOrder = 1;
  1873. if ("1".Equals(oldOrder))
  1874. {
  1875. entitycell.IsOldCustomer = 1;
  1876. }
  1877. //}
  1878. entitycell.CustomerUserId = CurrentUser.UserID;
  1879. entitycell.PayProofImg = primg;
  1880. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1881. entitycell.ProductId = Convert.ToInt32(productId);
  1882. entitycell.ShopId = shopId;
  1883. entitycell.UpdateTime = DateTime.Now;
  1884. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1885. if (entitycell.ProductId > 0)
  1886. {
  1887. CeErpProduct ceErpProduct = CeErpProduct.GetById(entitycell.ProductId);
  1888. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  1889. {
  1890. entitycell.NewProduct = 1;
  1891. }
  1892. }
  1893. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1894. {
  1895. entitycell.IsXianHuo = 1;
  1896. }
  1897. entitycell.pay_time = entity.pay_time;
  1898. if (toWhere == "1")
  1899. {
  1900. entitycell.OrderState = 2;
  1901. }
  1902. else
  1903. {
  1904. entitycell.OrderState = 6;
  1905. entitycell.FinishPlaceTime = entitycell.pay_time;
  1906. }
  1907. if (shopId == 94)
  1908. {
  1909. entitycell.OrderState = 4;
  1910. entitycell.WaitDesignTime = entitycell.pay_time;
  1911. entitycell.StartDesignTime = entitycell.pay_time;
  1912. entitycell.DesignUserId = 218;
  1913. }
  1914. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114 && shopId != 158))
  1915. {
  1916. entitycell.OrderState = -1;//修改12-5
  1917. CeWithdraw ceWithdraw = new CeWithdraw();
  1918. ceWithdraw.tid = entity.tid;
  1919. ceWithdraw.providerid = "-1";
  1920. ceWithdraw.status = -1;
  1921. ceWithdraw.creationtime = DateTime.Now;
  1922. ceWithdraw.userid = 4634;
  1923. ceWithdraw.Create();
  1924. }
  1925. entitycell.Create();
  1926. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1927. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1928. {
  1929. addPlaceRegist(entitycell, CurrentUser.UserID);
  1930. }
  1931. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1932. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1933. return;
  1934. }
  1935. }
  1936. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1937. {
  1938. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1939. entity.PlactTime = tradecell.pay_time;
  1940. entity.AddUserId = userid;
  1941. entity.FileName = tradecell.seller_memo;
  1942. entity.Supplier = 24;
  1943. entity.CreateTime = DateTime.Now;
  1944. entity.Did = tradecell.ctid;
  1945. entity.tid = tradecell.tid;
  1946. entity.splitTag = tradecell.SplitTag;
  1947. entity.CurState = "未完成";
  1948. entity.Create();
  1949. }
  1950. public void get_erp_offlinelist()
  1951. {
  1952. DataStruct dStruct = GetPostStruct();
  1953. List<string> lw = new List<string>();
  1954. string tid = GetPostString("ctid");
  1955. string date1 = GetPostString("date1");
  1956. string date2 = GetPostString("date2");
  1957. if (tid.Length > 0 || date1.Length > 0)
  1958. {
  1959. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1960. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1961. if (dw.Length > 0) lw.Add(dw);
  1962. }
  1963. else
  1964. {
  1965. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1966. }
  1967. string shopname = GetPostString("shopname");
  1968. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1969. string buyernick = GetPostString("buyer_nick");
  1970. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1971. string customer = GetPostString("customer");
  1972. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1973. string design = GetPostString("design");
  1974. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1975. string orderState = GetPostString("orderState");
  1976. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1977. string address = GetPostString("address");
  1978. 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));
  1979. string sellermemo = GetPostString("seller_memo");
  1980. if (sellermemo.Length > 0)
  1981. {
  1982. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1983. }
  1984. string price1 = GetPostString("price1");
  1985. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1986. string price2 = GetPostString("price2");
  1987. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1988. //if (PKey != "admin")
  1989. //{
  1990. // string usershop = CurrentUser.User.pemShop;
  1991. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1992. //}
  1993. //if (ex_psize > 0)
  1994. //{
  1995. dStruct.Order = "pay_time desc";
  1996. //}
  1997. //else
  1998. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1999. lw.Add(string.Format("IsOffLineOrder=1"));
  2000. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2001. DataTable dt = null;
  2002. dt = WebCache.GetData("view_erptradecell", dStruct);
  2003. writeGridDataTableJson(dStruct.TotalCount, dt);
  2004. }
  2005. public void get_erp_returncashrecord()
  2006. {
  2007. DataStruct dStruct = GetPostStruct();
  2008. List<string> lw = new List<string>();
  2009. string tid = GetPostString("ctid");
  2010. if (tid.Length > 0)
  2011. {
  2012. lw.Add(string.Format("tid like '%{0}%'", tid));
  2013. dStruct.Order = "id desc";
  2014. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2015. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  2016. //writeGridDataTableJson(dStruct.TotalCount, dt);
  2017. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2018. return;
  2019. }
  2020. returnErrorMsg("id数据错误!");
  2021. }
  2022. public void ins_erp_returncashrecord()
  2023. {
  2024. if (UrlPostParmsCheck("tid"))
  2025. {
  2026. string tid = GetPostString("tid");
  2027. string retype = GetPostString("type");
  2028. StringBuilder sql = new StringBuilder();
  2029. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  2030. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2031. if (dt.Rows.Count > 0)
  2032. {
  2033. returnErrorMsg("相同返现类型记录已存在");
  2034. return;
  2035. }
  2036. CeErpReturnCash entity = new CeErpReturnCash();
  2037. entity.tid = tid;
  2038. entity.seller_nick = GetPostString("seller_nick");
  2039. string pment = GetPostString("payment");
  2040. if (pment.Length > 0)
  2041. {
  2042. entity.payment = Convert.ToDouble(pment);
  2043. }
  2044. entity.buyer_nick = GetPostString("buyer_nick");
  2045. entity.cashstate = 0;
  2046. entity.rtype = retype;
  2047. string rPrice = GetPostString("returnprice");
  2048. if (rPrice.Length > 0)
  2049. {
  2050. entity.returnprice = Convert.ToDouble(rPrice);
  2051. }
  2052. entity.created = DateTime.Now;
  2053. entity.con = GetPostString("con");
  2054. entity.img = GetPostString("img");
  2055. entity.applyuserid = CurrentUser.UserID;
  2056. entity.Create();
  2057. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  2058. returnSuccessMsg("操作成功!");
  2059. return;
  2060. }
  2061. }
  2062. public void set_erp_predelivery()
  2063. {
  2064. if (UrlPostParmsCheck("ctid"))
  2065. {
  2066. string eid = GetPostString("ctid");
  2067. CeErpTradeCell entity = null;
  2068. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2069. if (entity != null)
  2070. {
  2071. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  2072. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  2073. //{
  2074. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  2075. // return;
  2076. //}
  2077. entity.IsPreDelivery = 1;
  2078. entity.Update();
  2079. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2080. returnSuccessMsg("预发货成功!");
  2081. return;
  2082. //string shop = GetPostString("seller_nick");
  2083. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  2084. //string comName = GetPostString("comName");
  2085. //string comCode = GetPostString("comCode");
  2086. //string outSid = GetPostString("outSid");//运单号
  2087. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  2088. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  2089. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  2090. //string apires = "";
  2091. //if (deliveryType == "虚拟发货")
  2092. //{
  2093. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  2094. //}
  2095. //else
  2096. //{
  2097. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  2098. //}
  2099. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  2100. ////{
  2101. //if (apires.IndexOf("发货成功") != -1)
  2102. //{
  2103. // if (deliveryType != "虚拟发货")
  2104. // {
  2105. // //还要插入快递信息到 快递信息表
  2106. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  2107. // exinfo.tid = eid;
  2108. // exinfo.out_sid = outSid;
  2109. // exinfo.company_code = comCode;
  2110. // exinfo.company_name = comName;
  2111. // exinfo.delivery_memo = deliveryMemo;
  2112. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  2113. // exinfo.deliveryType = deliveryType;
  2114. // exinfo.Create();
  2115. // }
  2116. // returnSuccessMsg("发货成功!");
  2117. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2118. //}
  2119. //else
  2120. //{
  2121. // returnErrorMsg("淘宝发货失败!!");
  2122. //}
  2123. //return;
  2124. }
  2125. returnErrorMsg("找不到订单记录");
  2126. }
  2127. }
  2128. public void get_erp_unusuallist()
  2129. {
  2130. DataStruct dStruct = GetPostStruct();
  2131. List<string> lw = new List<string>();
  2132. string tid = GetPostString("ctid");
  2133. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  2134. string shopname = GetPostString("shopname");
  2135. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2136. string buyernick = GetPostString("buyer_nick");
  2137. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2138. string ResponsibleMan = GetPostString("responsible");
  2139. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2140. string date1 = GetPostString("date1");
  2141. string date2 = GetPostString("date2");
  2142. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2143. if (dw.Length > 0) lw.Add(dw);
  2144. string price1 = GetPostString("price1");
  2145. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2146. string price2 = GetPostString("price2");
  2147. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2148. string orderState = GetPostString("orderState");
  2149. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2150. string sellermemo = GetPostString("seller_memo");
  2151. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2152. lw.Add(string.Format("UnusualTag > 0"));
  2153. lw.Add(string.Format("IsRefund<={0}", 1));
  2154. dStruct.Order = "pay_time desc";
  2155. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2156. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2157. writeGridDataTableJson(dStruct.TotalCount, dt);
  2158. }
  2159. public void set_erp_unusualtonomal()
  2160. {
  2161. if (UrlPostParmsCheck("ctid"))
  2162. {
  2163. string eid = GetPostString("ctid");
  2164. CeErpTradeCell entity = null;
  2165. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2166. if (entity != null)
  2167. {
  2168. entity.UnusualTag = -1;
  2169. entity.Update();
  2170. returnSuccessMsg("忽略成功!");
  2171. return;
  2172. }
  2173. returnErrorMsg("找不到记录");
  2174. }
  2175. }
  2176. public void ins_erp_unusualreason()
  2177. {
  2178. if (UrlPostParmsCheck("ctid"))
  2179. {
  2180. string eid = GetPostString("ctid");
  2181. CeErpTradeCell entity = null;
  2182. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2183. if (entity != null)
  2184. {
  2185. entity.MemoOpt = 4;
  2186. entity.UnusualCon = GetPostString("con");
  2187. entity.Update();
  2188. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2189. if (trade != null)
  2190. {
  2191. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2192. }
  2193. //查货是否超时
  2194. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2195. if (ceErpTradeCellExtend == null)
  2196. {
  2197. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2198. ceErpTradeCellExtend.ctid = entity.ctid;
  2199. }
  2200. if (ceErpTradeCellExtend.CheckTime != null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2201. {
  2202. ceErpTradeCellExtend.CheckOut += 1;
  2203. }
  2204. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2205. if (ceErpTradeCellExtend.ID > 0)
  2206. {
  2207. ceErpTradeCellExtend.Update();
  2208. }
  2209. else
  2210. {
  2211. ceErpTradeCellExtend.Create();
  2212. }
  2213. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2214. returnSuccessMsg("操作成功!");
  2215. return;
  2216. }
  2217. returnErrorMsg("找不到记录");
  2218. }
  2219. }
  2220. public void upd_erp_sampleorder()
  2221. {
  2222. if (UrlPostParmsCheck("ctid"))
  2223. {
  2224. string eid = GetPostString("ctid");
  2225. string[] eArr = eid.Split(',');
  2226. if (eArr.Length > 1)
  2227. {
  2228. List<string> eLst = new List<string>();
  2229. for (int i = 0; i < eArr.Length; i++)
  2230. {
  2231. eLst.Add("'" + eArr[i] + "'");
  2232. }
  2233. eid = string.Join(",", eLst.ToArray());
  2234. }
  2235. else
  2236. {
  2237. eid = "'" + eid + "'";
  2238. }
  2239. StringBuilder sql = new StringBuilder();
  2240. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2241. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2242. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2243. if (dt.Rows.Count > 0)
  2244. {
  2245. string errmsg = "";
  2246. foreach (DataRow dr in dt.Rows)
  2247. {
  2248. StringBuilder sqlsb = new StringBuilder();
  2249. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2250. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2251. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2252. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2253. //string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2254. /*if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2255. {
  2256. continue;
  2257. }
  2258. else
  2259. {
  2260. string emsg = commonHelper.KeepChinese(apires);
  2261. errmsg += emsg;
  2262. }*/
  2263. }
  2264. if (errmsg.Length > 0)
  2265. {
  2266. returnErrorMsg(errmsg);
  2267. return;
  2268. }
  2269. returnSuccessMsg("操作成功");
  2270. return;
  2271. }
  2272. returnErrorMsg("找不到记录");
  2273. }
  2274. }
  2275. public void upd_erp_transcustomer()
  2276. {
  2277. if (UrlPostParmsCheck("ctid"))
  2278. {
  2279. string eid = GetPostString("ctid");
  2280. int userid = GetPostInt("CustomerUserId");
  2281. CeErpTradeCell entity = null;
  2282. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2283. if (entity != null)
  2284. {
  2285. //string[] mlist = entity.seller_memo.Split('-');
  2286. //string sql = "select * from view_erpuser where id=" + userid;
  2287. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2288. //if (dt != null && dt.Rows.Count > 0)
  2289. //{
  2290. // string nmemo = "";
  2291. // for(int i = 0; i < mlist.Length - 1; i++)
  2292. // {
  2293. // nmemo += mlist[i];
  2294. // nmemo += "-";
  2295. // }
  2296. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2297. // entity.seller_memo = nmemo;
  2298. //}
  2299. entity.CustomerUserId = userid;
  2300. entity.Update();
  2301. returnSuccessMsg("操作成功!");
  2302. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2303. return;
  2304. }
  2305. returnErrorMsg("找不到记录");
  2306. }
  2307. }
  2308. public void upd_erp_transdesigner()
  2309. {
  2310. if (UrlPostParmsCheck("ctid"))
  2311. {
  2312. string eids = GetPostString("ctid");
  2313. string[] ctidList = eids.Split(',');
  2314. int userid = GetPostInt("DesignUserId");
  2315. foreach (string ctid in ctidList)
  2316. {
  2317. CeErpTradeCell entity = null;
  2318. CeErpDesignerBill entitys = null;
  2319. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2320. entitys = CeErpDesignerBill.GetByTid(ctid);
  2321. if (entity != null)
  2322. {
  2323. if (entity.OrderState > 4)
  2324. {
  2325. continue;
  2326. }
  2327. //存在退款不能流转
  2328. if (entity.IsRefund > 0)
  2329. {
  2330. continue;
  2331. }
  2332. entity.DesignUserId = userid;
  2333. entity.WaitDesignTime = DateTime.Now;
  2334. entity.Update();
  2335. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2336. }
  2337. }
  2338. returnSuccessMsg("操作成功!");
  2339. }
  2340. }
  2341. public void upd_erp_distributedesigner()
  2342. {
  2343. if (UrlPostParmsCheck("ctid"))
  2344. {
  2345. string eid = GetPostString("ctid");
  2346. int userid = GetPostInt("DesignUserId");
  2347. string reason = GetPostString("reason");
  2348. string[] idlist = eid.Split(',');
  2349. if (idlist.Length <= 0)
  2350. {
  2351. returnErrorMsg("订单不能为空");
  2352. return;
  2353. }
  2354. foreach (string ctid in idlist)
  2355. {
  2356. CeErpTradeCell entity = null;
  2357. CeErpDesignerBill entitys = null;
  2358. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2359. else continue;
  2360. if (entity != null)
  2361. {
  2362. if (userid == 2125 || userid == 3542)
  2363. { }
  2364. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2365. {
  2366. returnErrorMsg("金额错误的订单无法指派");
  2367. return;
  2368. }
  2369. if (entity.OrderState >= 5)
  2370. {
  2371. returnErrorMsg("已经设计完成无法指派");
  2372. return;
  2373. }
  2374. if (entity.OrderState == -1)
  2375. {
  2376. returnErrorMsg("审核中的订单无法指派");
  2377. return;
  2378. }
  2379. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2380. {
  2381. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2382. return;
  2383. }
  2384. List<int> userIds = new List<int>()
  2385. {
  2386. 157 ,159 ,1479 ,73
  2387. };
  2388. //157赖橙帆 159林晨 73 静之颖
  2389. if (entity.OrderState > 3 && entity.DispatchSort == 2 && userid != 3542 && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Summarize" && !userIds.Contains(CurrentUser.UserID))
  2390. {
  2391. returnErrorMsg("指派设计共创无法再次指派!");
  2392. return;
  2393. }
  2394. entity.OrderState = 3;
  2395. if (entity.SupplierId == 0)
  2396. {
  2397. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2398. entity.SupplierId = suid;
  2399. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2400. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2401. }
  2402. if (userid == 2125 && entity.seller_memo != "")
  2403. {
  2404. //apiDesign.API_GetPrintData_CreateOrder(entity);
  2405. }
  2406. List<int> shopIds = new List<int>() { 17, 21, 52, 54, 64, 63, 66, 49, 67, 105, 35, 57, 53, 65, 87, 140, 26, 45, 2, 77, 122, 121, 153, 154, 158 };
  2407. if (userid == 3542 && entity.seller_memo != "")
  2408. {
  2409. string userPost = CurrentUser.UserPost.Post.Code;
  2410. if (CurrentUser.UserID == 4516 || CurrentUser.UserID == 159 || CurrentUser.UserID == 157 || shopIds.Contains(entity.ShopId))
  2411. {
  2412. userPost = "SysAdmin";
  2413. }
  2414. if (CurrentUser.UserID == 159 || CurrentUser.UserID == 157)
  2415. {
  2416. saveAssignLog(reason, entity);
  2417. }
  2418. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2419. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2420. if (response.msg != "设计共创:成功")
  2421. {
  2422. returnErrorMsg(response.msg);
  2423. return;
  2424. }
  2425. entity.DispatchSort = 2;
  2426. }
  2427. else
  2428. {
  2429. if (entity.DispatchSort == 2)
  2430. {
  2431. ApiVo apiVo = new ApiVo();
  2432. apiVo.actionName = "closeDesign";
  2433. apiVo.orderNumber = entity.ctid;
  2434. designHelper.API_WorkCore(apiVo);//closeDesign
  2435. }
  2436. entity.DispatchSort = 0;
  2437. }
  2438. entity.DesignUserId = userid;
  2439. entity.WaitDesignTime = DateTime.Now;
  2440. entity.UpdateTime = DateTime.Now;
  2441. entity.Update();
  2442. string name = commonHelper.getUserNameById(userid);
  2443. commonHelper.UpdateRelationOrder(entity.ctid);
  2444. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2445. }
  2446. }
  2447. returnSuccessMsg("操作成功!");
  2448. return;
  2449. }
  2450. }
  2451. public string getTidByCtid(string ctid)
  2452. {
  2453. string tid = "";
  2454. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2455. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2456. if (dataTable != null && dataTable.Rows.Count > 0)
  2457. {
  2458. tid = dataTable.Rows[0]["tid"].ToString();
  2459. }
  2460. return tid;
  2461. }
  2462. public List<string> getTidByCtidMore(string ctid)
  2463. {
  2464. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or tid = '{0}' or orderSn = '{0}' or ( ParentSplitNo = '{0}' and IsSample =2) or (ptid = '{0}' and IsSample =2 ))", ctid);
  2465. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2466. List<string> list = new List<string>();
  2467. if (dataTable != null && dataTable.Rows.Count > 0)
  2468. {
  2469. foreach (DataRow item in dataTable.Rows)
  2470. {
  2471. list.Add("'" + item["tid"].ToString() + "'");
  2472. }
  2473. }
  2474. return list;
  2475. }
  2476. public List<string> getTidByCtidLike(string ctid)
  2477. {
  2478. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2479. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2480. List<string> list = new List<string>();
  2481. if (dataTable != null && dataTable.Rows.Count > 0)
  2482. {
  2483. foreach (DataRow item in dataTable.Rows)
  2484. {
  2485. list.Add("'" + item["tid"].ToString() + "'");
  2486. }
  2487. }
  2488. return list;
  2489. }
  2490. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2491. {
  2492. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2493. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2494. List<string> list = new List<string>();
  2495. if (dataTable != null && dataTable.Rows.Count > 0)
  2496. {
  2497. foreach (DataRow item in dataTable.Rows)
  2498. {
  2499. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2500. {
  2501. continue;
  2502. }
  2503. list.Add("'" + item["receiverId"].ToString() + "'");
  2504. }
  2505. }
  2506. return list;
  2507. }
  2508. public void get_erp_myorderlist()
  2509. {
  2510. DataStruct dStruct = GetPostStruct();
  2511. List<string> lw = new List<string>();
  2512. string tid = GetPostString("ctid");
  2513. if (tid.Length > 0)
  2514. {
  2515. string select_tid = getTidByCtid(tid);
  2516. lw.Add(string.Format("tid='{0}'", select_tid));
  2517. }
  2518. else
  2519. {
  2520. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2521. }
  2522. //12-1 修改
  2523. string urgent = GetPostString("urgent");
  2524. string back = GetPostString("back");
  2525. string offlineSearch = GetPostString("offlineSearch");
  2526. if (!string.IsNullOrWhiteSpace(urgent))
  2527. {
  2528. if (urgent.Equals("true"))
  2529. {
  2530. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2531. }
  2532. }
  2533. if (!string.IsNullOrWhiteSpace(back))
  2534. {
  2535. if (back.Equals("true"))
  2536. {
  2537. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2538. }
  2539. }
  2540. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2541. {
  2542. if (offlineSearch.Equals("true"))
  2543. {
  2544. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2545. }
  2546. }
  2547. //end
  2548. string shopname = GetPostString("shopname");
  2549. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2550. string buyernick = GetPostString("buyer_nick");
  2551. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2552. string design = GetPostString("design");
  2553. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2554. string orderState = GetPostString("orderState");
  2555. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2556. string sellermemo = GetPostString("seller_memo");
  2557. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2558. string date1 = GetPostString("date1");
  2559. string date2 = GetPostString("date2");
  2560. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2561. if (dw.Length > 0) lw.Add(dw);
  2562. string price1 = GetPostString("price1");
  2563. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2564. string price2 = GetPostString("price2");
  2565. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2566. string urgency = GetPostString("urgency");
  2567. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2568. string after = GetPostString("after");
  2569. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2570. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2571. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2572. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2573. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2574. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2575. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2576. if (dt != null && dt.Rows.Count > 0)
  2577. {
  2578. foreach (DataRow dr in dt.Rows)
  2579. {
  2580. try
  2581. {
  2582. // 对象操作
  2583. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2584. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2585. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2586. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2587. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2588. if (dStruct.PageSize != 100000)
  2589. {
  2590. if (dr["DispatchSort"].ToString() == "2")
  2591. {
  2592. dr["gongchuang"] = 200;
  2593. }
  2594. else if ("外协".Equals(dr["ToType"].ToString()))
  2595. {
  2596. dr["gongchuang"] = 200;
  2597. }
  2598. else if ("内部".Equals(dr["ToType"].ToString()))
  2599. {
  2600. dr["gongchuang"] = -1;
  2601. }
  2602. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2603. {
  2604. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2605. dr["gongchuang"] = response.code;
  2606. }
  2607. }
  2608. }
  2609. catch (NullReferenceException ex)
  2610. {
  2611. }
  2612. }
  2613. }
  2614. writeGridDataTableJson(dStruct.TotalCount, dt);
  2615. }
  2616. public void get_erp_myreturnorderlist()
  2617. {
  2618. DataStruct dStruct = GetPostStruct();
  2619. List<string> lw = new List<string>();
  2620. string tid = GetPostString("ctid");
  2621. if (tid.Length > 0)
  2622. {
  2623. string select_tid = getTidByCtid(tid);
  2624. lw.Add(string.Format("tid='{0}'", select_tid));
  2625. }
  2626. else
  2627. {
  2628. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2629. }
  2630. string shopname = GetPostString("shopname");
  2631. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2632. string buyernick = GetPostString("buyer_nick");
  2633. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2634. string design = GetPostString("design");
  2635. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2636. string orderState = GetPostString("orderState");
  2637. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2638. string sellermemo = GetPostString("seller_memo");
  2639. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2640. string date1 = GetPostString("date1");
  2641. string date2 = GetPostString("date2");
  2642. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2643. if (dw.Length > 0) lw.Add(dw);
  2644. string price1 = GetPostString("price1");
  2645. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2646. string price2 = GetPostString("price2");
  2647. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2648. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2649. {
  2650. lw.Add(string.Format("CusOrgID = 94"));
  2651. }
  2652. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2653. {
  2654. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2655. }
  2656. else
  2657. {
  2658. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2659. }
  2660. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2661. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2662. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2663. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2664. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2665. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2666. if (dt != null && dt.Rows.Count > 0)
  2667. {
  2668. foreach (DataRow dr in dt.Rows)
  2669. {
  2670. try
  2671. {
  2672. // 对象操作
  2673. if (dStruct.PageSize != 100000)
  2674. {
  2675. if (dr["DispatchSort"].ToString() == "2")
  2676. {
  2677. dr["gongchuang"] = 200;
  2678. }
  2679. else if ("外协".Equals(dr["ToType"].ToString()))
  2680. {
  2681. dr["gongchuang"] = 200;
  2682. }
  2683. else if ("内部".Equals(dr["ToType"].ToString()))
  2684. {
  2685. dr["gongchuang"] = -1;
  2686. }
  2687. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2688. {
  2689. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2690. dr["gongchuang"] = response.code;
  2691. }
  2692. }
  2693. }
  2694. catch (NullReferenceException ex)
  2695. {
  2696. // 处理空引用异常
  2697. }
  2698. }
  2699. }
  2700. writeGridDataTableJson(dStruct.TotalCount, dt);
  2701. }
  2702. public void get_erp_myorderlist_pregather()
  2703. {
  2704. string date1 = GetPostString("date1");
  2705. string date2 = GetPostString("date2");
  2706. int userId = CurrentUser.UserID; //客服id
  2707. string orderWhere = "";
  2708. List<string> lw = new List<string>();
  2709. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2710. if (dw.Length > 0) lw.Add(dw);
  2711. lw.Add(string.Format("CustomerUserId={0}", userId));
  2712. lw.Add(string.Format("OrderState<9"));
  2713. orderWhere = string.Join(" and ", lw.ToArray());
  2714. string orderWhere2 = "";
  2715. List<string> lw2 = new List<string>();
  2716. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2717. if (dw2.Length > 0) lw2.Add(dw2);
  2718. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2719. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2720. string sql = string.Format("select *" +
  2721. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2722. "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 " +
  2723. "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 " +
  2724. "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");
  2725. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2726. //writeGridDataTableJson(dt.Rows.Count, dt);
  2727. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2728. }
  2729. public void upd_erp_publishorder()
  2730. {
  2731. if (UrlPostParmsCheck("ctid"))
  2732. {
  2733. string eid = GetPostString("ctid");
  2734. CeErpTradeCell entity = null;
  2735. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2736. if (entity != null)
  2737. {
  2738. entity.OrderState = 0; //发布后,变为待抢单
  2739. entity.Update();
  2740. commonHelper.UpdateRelationOrder(entity.ctid);
  2741. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2742. returnSuccessMsg("发布成功!");
  2743. return;
  2744. }
  2745. returnErrorMsg("找不到记录");
  2746. }
  2747. }
  2748. public void get_erp_my_tiporder()
  2749. {
  2750. StringBuilder sql = new StringBuilder();
  2751. int userId = 0;
  2752. if (CurrentUser != null) userId = CurrentUser.UserID;
  2753. string posCode = CurrentUser.UserPost.Post.Code;
  2754. string isTipedAfterSaleVerify = GetPostString("af");
  2755. DataTable dt = new DataTable();
  2756. if (posCode != "Supplier")
  2757. {
  2758. if (posCode == "CustomerService" || posCode == "Director")
  2759. {
  2760. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2761. }
  2762. else if (posCode == "Place" || posCode == "PlaceMr")
  2763. {
  2764. }
  2765. else
  2766. {
  2767. string teamIds = CurrentUser.User.TeamIds;
  2768. if (teamIds == "")
  2769. {
  2770. teamIds = "0";
  2771. }
  2772. 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);
  2773. }
  2774. if (sql.Length > 0)
  2775. {
  2776. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2777. }
  2778. }
  2779. if (dt.Rows.Count <= 0)
  2780. {
  2781. string key = "aftersale_order_" + userId;
  2782. if (RedisHelper.HasKey(key))
  2783. {
  2784. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2785. dt.Columns.Add("ctid", typeof(string));
  2786. dt.Columns.Add("IsReadTag", typeof(int));
  2787. foreach (var i in list)
  2788. {
  2789. DataRow data = dt.NewRow();
  2790. data["ctid"] = i;
  2791. data["IsReadTag"] = 4;
  2792. dt.Rows.Add(data);
  2793. }
  2794. RedisHelper.StringDelete(key);
  2795. }
  2796. }
  2797. if (dt.Rows.Count <= 0)
  2798. {
  2799. sql = new StringBuilder();
  2800. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2801. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2802. }
  2803. if (posCode == "Supplier")
  2804. {
  2805. string ids = CurrentUser.User.pemVend;
  2806. if (ids != null && ids.Length > 0)
  2807. {
  2808. string[] ids_list = ids.Split(',');
  2809. foreach (var item in ids_list)
  2810. {
  2811. string key = "return_order_" + item;
  2812. if (RedisHelper.HasKey(key))
  2813. {
  2814. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2815. dt.Columns.Add("ctid", typeof(string));
  2816. dt.Columns.Add("IsReadTag", typeof(int));
  2817. foreach (var i in list)
  2818. {
  2819. DataRow data = dt.NewRow();
  2820. data["ctid"] = i;
  2821. data["IsReadTag"] = 1;
  2822. dt.Rows.Add(data);
  2823. }
  2824. RedisHelper.StringDelete(key);
  2825. }
  2826. }
  2827. }
  2828. if (dt.Rows.Count <= 0)
  2829. {
  2830. sql = new StringBuilder();
  2831. 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);
  2832. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2833. }
  2834. }
  2835. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2836. }
  2837. public void reset_erp_tiporder()
  2838. {
  2839. string ids = GetPostString("ids");
  2840. string[] ctidList = ids.Split(',');
  2841. foreach (string ctid in ctidList)
  2842. {
  2843. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2844. if (enty != null)
  2845. {
  2846. enty.IsReadTag = 0;
  2847. enty.Update();
  2848. }
  2849. }
  2850. returnSuccessMsg("成功!");
  2851. return;
  2852. }
  2853. public void get_erp_designlist()
  2854. {
  2855. DataStruct dStruct = GetPostStruct();
  2856. List<string> lw = new List<string>();
  2857. string tid = GetPostString("ctid");
  2858. if (tid.Length > 0)
  2859. {
  2860. string select_tid = getTidByCtid(tid);
  2861. lw.Add(string.Format("tid='{0}'", select_tid));
  2862. }
  2863. string shopname = GetPostString("shopname");
  2864. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2865. string buyernick = GetPostString("buyer_nick");
  2866. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2867. string customer = GetPostString("customer");
  2868. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2869. string design = GetPostString("design");
  2870. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2871. string orderState = GetPostString("orderState");
  2872. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2873. lw.Add(string.Format("OrderState<6"));
  2874. string address = GetPostString("address");
  2875. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2876. string sellermemo = GetPostString("seller_memo");
  2877. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2878. string date1 = GetPostString("date1");
  2879. string date2 = GetPostString("date2");
  2880. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2881. if (dw.Length > 0) lw.Add(dw);
  2882. string apdate1 = GetPostString("apdate1");
  2883. string apdate2 = GetPostString("apdate2");
  2884. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2885. if (dwap.Length > 0) lw.Add(dwap);
  2886. string price1 = GetPostString("price1");
  2887. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2888. string price2 = GetPostString("price2");
  2889. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2890. string designTime = GetPostString("designtime");
  2891. if (designTime.Length > 0)
  2892. {
  2893. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2894. }
  2895. string usershop = CurrentUser.User.pemShop;
  2896. if (usershop.Length > 0)
  2897. {
  2898. lw.Add(string.Format("shopId in ({0})", usershop));
  2899. }
  2900. int myOrgid = CurrentUser.UserPost.OrgID;
  2901. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2902. if (myOrgCode.IndexOf("Designer") != -1)
  2903. {
  2904. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2905. {
  2906. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2907. }
  2908. else
  2909. {
  2910. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2911. }
  2912. }
  2913. else
  2914. {
  2915. string orgId = GetPostString("designerhd");
  2916. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2917. }
  2918. if (tid.Length > 0 || buyernick.Length > 0)
  2919. {
  2920. lw.Add(string.Format("OrderState >= 3"));
  2921. }
  2922. else
  2923. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2924. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2925. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2926. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2927. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2928. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2929. if (dt != null && dt.Rows.Count > 0)
  2930. {
  2931. foreach (DataRow dr in dt.Rows)
  2932. {
  2933. try
  2934. {
  2935. // 对象操作
  2936. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2937. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2938. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2939. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2940. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2941. if (dStruct.PageSize != 100000)
  2942. {
  2943. if (dr["DispatchSort"].ToString() == "2")
  2944. {
  2945. dr["gongchuang"] = 200;
  2946. }
  2947. else if ("外协".Equals(dr["ToType"].ToString()))
  2948. {
  2949. dr["gongchuang"] = 200;
  2950. }
  2951. else if ("内部".Equals(dr["ToType"].ToString()))
  2952. {
  2953. dr["gongchuang"] = -1;
  2954. }
  2955. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2956. {
  2957. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2958. dr["gongchuang"] = response.code;
  2959. }
  2960. }
  2961. }
  2962. catch (NullReferenceException ex)
  2963. {
  2964. }
  2965. }
  2966. }
  2967. writeGridDataTableJson(dStruct.TotalCount, dt);
  2968. }
  2969. public void get_erp_mydesignlist()
  2970. {
  2971. DataStruct dStruct = GetPostStruct();
  2972. List<string> lw = new List<string>();
  2973. string tid = GetPostString("ctid");
  2974. if (tid.Length > 0)
  2975. {
  2976. string select_tid = getTidByCtid(tid);
  2977. lw.Add(string.Format("tid='{0}'", select_tid));
  2978. }
  2979. string shopname = GetPostString("shopname");
  2980. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2981. string buyernick = GetPostString("buyer_nick");
  2982. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2983. string customer = GetPostString("customer");
  2984. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2985. string orderState = GetPostString("orderState");
  2986. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2987. //lw.Add(string.Format("OrderState<6"));
  2988. string date1 = GetPostString("date1");
  2989. string date2 = GetPostString("date2");
  2990. string dw = GetDateWhere("pay_time", date1, date2);
  2991. if (dw.Length > 0) lw.Add(dw);
  2992. string apdate1 = GetPostString("apdate1");
  2993. string apdate2 = GetPostString("apdate2");
  2994. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2995. if (dwap.Length > 0) lw.Add(dwap);
  2996. string price1 = GetPostString("price1");
  2997. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2998. string price2 = GetPostString("price2");
  2999. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3000. string olddownload = GetPostString("olddown");
  3001. if (olddownload == "1")
  3002. {
  3003. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  3004. }
  3005. else if (olddownload == "2")
  3006. {
  3007. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  3008. }
  3009. string sellermemo = GetPostString("seller_memo");
  3010. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3011. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  3012. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  3013. {
  3014. if (CurrentUser.User.TeamIds.Length > 0)
  3015. {
  3016. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  3017. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3018. else
  3019. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3020. }
  3021. else
  3022. {
  3023. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  3024. }
  3025. }
  3026. if (tid.Length <= 0)
  3027. {
  3028. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  3029. }
  3030. lw.Add(string.Format("IsReturn!=3"));
  3031. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  3032. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3033. string teamids = CurrentUser.User.TeamIds.ToString();
  3034. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3035. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  3036. if (dt != null && dt.Rows.Count > 0)
  3037. {
  3038. foreach (DataRow dr in dt.Rows)
  3039. {
  3040. try
  3041. {
  3042. // 对象操作
  3043. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  3044. ceErpTradeCell.ctid = dr["ctid"].ToString();
  3045. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  3046. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  3047. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  3048. if (dStruct.PageSize != 100000)
  3049. {
  3050. if (dr["DispatchSort"].ToString() == "2")
  3051. {
  3052. dr["gongchuang"] = 200;
  3053. }
  3054. else if ("外协".Equals(dr["ToType"].ToString()))
  3055. {
  3056. dr["gongchuang"] = 200;
  3057. }
  3058. else if ("内部".Equals(dr["ToType"].ToString()))
  3059. {
  3060. dr["gongchuang"] = -1;
  3061. }
  3062. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  3063. {
  3064. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  3065. dr["gongchuang"] = response.code;
  3066. }
  3067. }
  3068. }
  3069. catch (NullReferenceException ex)
  3070. {
  3071. }
  3072. }
  3073. }
  3074. writeGridDataTableJson(dStruct.TotalCount, dt);
  3075. }
  3076. public void set_erp_startdesign()
  3077. {
  3078. if (UrlPostParmsCheck("ctid"))
  3079. {
  3080. string eid = GetPostString("ctid");
  3081. CeErpTradeCell entity = null;
  3082. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3083. if (entity != null)
  3084. {
  3085. if (entity.OrderState != 3)
  3086. {
  3087. returnErrorMsg("请刷新,订单已经设计了");
  3088. return;
  3089. }
  3090. entity.StartDesignTime = DateTime.Now;
  3091. entity.OrderState = 4;
  3092. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  3093. {
  3094. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3095. entity.SupplierId = suid;
  3096. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3097. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3098. }
  3099. entity.UpdateTime = DateTime.Now;
  3100. //entity.MakeSupplier = suname;
  3101. entity.Update();
  3102. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3103. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3104. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  3105. commonHelper.getCytPrice(entity);
  3106. returnSuccessMsg("操作成功!");
  3107. return;
  3108. }
  3109. returnErrorMsg("找不到记录");
  3110. }
  3111. }
  3112. public void ins_erp_designselfmemo()
  3113. {
  3114. if (UrlPostParmsCheck("ctid"))
  3115. {
  3116. string eid = GetPostString("ctid");
  3117. string con = GetPostString("con");
  3118. CeErpTradeCell entity = null;
  3119. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3120. if (entity != null)
  3121. {
  3122. entity.DesignSelfMemo = con;
  3123. entity.Update();
  3124. returnSuccessMsg("操作成功!");
  3125. return;
  3126. }
  3127. returnErrorMsg("找不到记录");
  3128. }
  3129. }
  3130. public void ins_erp_designprice()
  3131. {
  3132. if (UrlPostParmsCheck("ctid"))
  3133. {
  3134. string eid = GetPostString("ctid");
  3135. int uid = CurrentUser.UserID;
  3136. string userName = CurrentUser.UserName;
  3137. CeErpTradeCell entity = null;
  3138. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  3139. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3140. if (entitys == null)
  3141. {
  3142. entitys = new CeErpDesignerBill();
  3143. }
  3144. if (entity != null)
  3145. {
  3146. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3147. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3148. entity.StartDesignTime = DateTime.Now;
  3149. entity.OrderState = 4;
  3150. string suname = "";
  3151. if (entity.SupplierId == 0)
  3152. {
  3153. int sid = commonHelper.autoDistributeToSupplier(entity);
  3154. entity.SupplierId = sid;
  3155. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3156. }
  3157. entity.Update();
  3158. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3159. if (ceErpUserPost != null)
  3160. {
  3161. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3162. if (ceErpPost != null)
  3163. {
  3164. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3165. {
  3166. entitys.tid = entity.ctid;
  3167. entitys.oid = entity.tid;
  3168. entitys.uid = uid;
  3169. entitys.userName = userName;
  3170. entitys.designerType = 1;
  3171. entitys.designerTypeText = "内部设计师";
  3172. entitys.price = Convert.ToDouble(GetPostString("price"));
  3173. entitys.designNum = GetPostInt("designNum");
  3174. entitys.modifyNum = GetPostInt("modifyNum");
  3175. entitys.designSize = GetPostString("designSize");
  3176. entitys.modifySize = GetPostString("modifySize");
  3177. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3178. {
  3179. entitys.create_time = DateTime.Now;
  3180. entitys.create_u_id = uid;
  3181. entitys.create_u_name = userName;
  3182. entitys.Save();
  3183. }
  3184. else
  3185. {
  3186. entitys.update_time = DateTime.Now;
  3187. entitys.update_u_id = uid;
  3188. entitys.update_u_name = userName;
  3189. entitys.Update();
  3190. }
  3191. }
  3192. }
  3193. }
  3194. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3195. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3196. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3197. if (suname != "")
  3198. {
  3199. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3200. }
  3201. commonHelper.getCytPrice(entity);
  3202. returnSuccessMsg("操作成功!");
  3203. return;
  3204. }
  3205. returnErrorMsg("找不到记录");
  3206. }
  3207. }
  3208. public void upload_erp_filecomplete()
  3209. {
  3210. if (UrlPostParmsCheck("ctid"))
  3211. {
  3212. string eid = GetPostString("ctid");
  3213. CeErpTradeCell entity = null;
  3214. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3215. if (entity != null)
  3216. {
  3217. entity.OrderState = 5; //设计完成
  3218. entity.Update();
  3219. returnSuccessMsg(eid + "上传成功,设计完成!");
  3220. return;
  3221. }
  3222. returnErrorMsg("找不到订单记录");
  3223. }
  3224. }
  3225. public void get_erp_designovertimelist()
  3226. {
  3227. DataStruct dStruct = GetPostStruct();
  3228. List<string> lw = new List<string>();
  3229. string tid = GetPostString("ctid");
  3230. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3231. string shopname = GetPostString("shopname");
  3232. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3233. string buyernick = GetPostString("buyer_nick");
  3234. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3235. string ResponsibleMan = GetPostString("responsible");
  3236. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3237. string date1 = GetPostString("date1");
  3238. string date2 = GetPostString("date2");
  3239. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3240. if (dw.Length > 0) lw.Add(dw);
  3241. string price1 = GetPostString("price1");
  3242. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3243. string price2 = GetPostString("price2");
  3244. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3245. string orderState = GetPostString("orderState");
  3246. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3247. string sellermemo = GetPostString("seller_memo");
  3248. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3249. lw.Add(string.Format("UnusualTag=3"));
  3250. lw.Add(string.Format("IsRefund<={0}", 1));
  3251. dStruct.Order = "WaitDesignTime desc";
  3252. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3253. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3254. writeGridDataTableJson(dStruct.TotalCount, dt);
  3255. }
  3256. //设计管理 获取抢单大厅列表
  3257. public void get_erp_grabinglist()
  3258. {
  3259. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3260. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3261. bool oldOrder = false;
  3262. if (org != null)
  3263. {
  3264. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3265. }
  3266. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3267. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3268. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3269. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3270. //先处理订单数据
  3271. if (dt.Rows.Count > 0)
  3272. {
  3273. Dictionary<string, int> design = null;
  3274. int count = 0;
  3275. foreach (DataRow row in dt.Rows)
  3276. {
  3277. if (map.ContainsKey(row["ShopId"].ToString()))
  3278. {
  3279. map.TryGetValue(row["ShopId"].ToString(), out design);
  3280. }
  3281. else
  3282. {
  3283. design = new Dictionary<string, int>();
  3284. }
  3285. if (design.ContainsKey(row["ProductId"].ToString()))
  3286. {
  3287. design.TryGetValue(row["ProductId"].ToString(), out count);
  3288. }
  3289. count++;
  3290. design[row["ProductId"].ToString()] = count;
  3291. map[row["ShopId"].ToString()] = design;
  3292. }
  3293. }
  3294. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3295. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3296. //把店铺排序和技能排序分类
  3297. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3298. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3299. if (design_dt.Rows.Count > 0)
  3300. {
  3301. Dictionary<string, string> design = null;
  3302. List<string> shopIds = null;
  3303. foreach (DataRow row in design_dt.Rows)
  3304. {
  3305. if ("0".Equals(row["designId"].ToString()))
  3306. {
  3307. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3308. {
  3309. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3310. }
  3311. else
  3312. {
  3313. shopIds = new List<string>();
  3314. }
  3315. shopIds.Add(row["shopId"].ToString());
  3316. shop_orders[row["orders"].ToString()] = shopIds;
  3317. }
  3318. else
  3319. {
  3320. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3321. {
  3322. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3323. }
  3324. else
  3325. {
  3326. design = new Dictionary<string, string>();
  3327. }
  3328. design[row["orders"].ToString()] = row["designId"].ToString();
  3329. design_orders[row["shopId"].ToString()] = design;
  3330. }
  3331. }
  3332. //处理成key value后根据key排序
  3333. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3334. foreach (List<string> val in shop_orders.Values)
  3335. {
  3336. if (val != null)
  3337. {
  3338. foreach (string key in val)
  3339. {
  3340. if (design_orders.ContainsKey(key.ToString()))
  3341. {
  3342. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3343. }
  3344. }
  3345. }
  3346. }
  3347. }
  3348. //校验哪个优先级有订单
  3349. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3350. foreach (string key in shop_orders.Keys)
  3351. {
  3352. List<string> ids = null;
  3353. shop_orders.TryGetValue(key, out ids);
  3354. //id为shopid
  3355. foreach (string id in ids)
  3356. {
  3357. Dictionary<string, int> list = null;
  3358. Dictionary<string, string> desing = null;
  3359. map.TryGetValue(id, out list);
  3360. design_orders.TryGetValue(id, out desing);
  3361. if (list != null && desing != null)
  3362. {
  3363. foreach (var item in desing)
  3364. {
  3365. int count = 0;
  3366. if (list.ContainsKey(item.Value))
  3367. {
  3368. list.TryGetValue(item.Value, out count);
  3369. if (count > 0)
  3370. {
  3371. designIds[id] = item.Value;
  3372. break;
  3373. }
  3374. }
  3375. }
  3376. }
  3377. }
  3378. if (designIds.Count > 0)
  3379. {
  3380. break;
  3381. }
  3382. }
  3383. DataTable table = new DataTable();
  3384. table.Columns.Add("tid", typeof(string));
  3385. table.Columns.Add("ctid", typeof(string));
  3386. table.Columns.Add("seller_nick", typeof(string));
  3387. table.Columns.Add("productName", typeof(string));
  3388. table.Columns.Add("pay_time", typeof(string));
  3389. table.Columns.Add("seller_memo", typeof(string));
  3390. if (designIds.Count > 0)
  3391. {
  3392. string shopId = "";
  3393. string productId = "";
  3394. foreach (var designInfo in designIds)
  3395. {
  3396. shopId = designInfo.Key;
  3397. productId = designInfo.Value;
  3398. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3399. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3400. if (dt.Rows.Count > 0)
  3401. {
  3402. foreach (DataRow row in dt.Rows)
  3403. {
  3404. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3405. {
  3406. DataRow data = table.NewRow();
  3407. data["ctid"] = row["ctid"].ToString();
  3408. data["tid"] = row["tid"].ToString();
  3409. data["seller_nick"] = ceErpShop.ShopName;
  3410. data["pay_time"] = row["pay_time"].ToString();
  3411. data["seller_memo"] = row["seller_memo"].ToString();
  3412. data["productName"] = ceErpProduct.PType;
  3413. table.Rows.Add(data);
  3414. }
  3415. }
  3416. }
  3417. }
  3418. }
  3419. writeGridDataTableJson(table.Rows.Count, table);
  3420. }
  3421. private object rushLockObject = new object();
  3422. public void set_erp_grabingorder()
  3423. {
  3424. if (UrlPostParmsCheck("ctid"))
  3425. {
  3426. int total = CurrentUser.User.Person.Total;
  3427. int userId = CurrentUser.User.ID;
  3428. int noFinish = CurrentUser.User.Person.NoFinish;
  3429. int finalization = CurrentUser.User.Person.Finalization;
  3430. string eids = GetPostString("ctid");
  3431. string key = "RushKey_" + userId;
  3432. int count = 0;
  3433. if (erpRedis.RedisHelper.KeyExists(key))
  3434. {
  3435. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3436. if (redisCount != null)
  3437. {
  3438. count = Convert.ToInt32(redisCount);
  3439. }
  3440. }
  3441. if (count >= total)
  3442. {
  3443. returnErrorMsg("半小时内已经抢" + total + "单");
  3444. return;
  3445. }
  3446. string[] ctidlist = eids.Split(',');
  3447. if (count + ctidlist.Length > total)
  3448. {
  3449. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3450. return;
  3451. }
  3452. int itag = 0;
  3453. lock (rushLockObject)
  3454. {
  3455. if (ctidlist.Length > 0)
  3456. {
  3457. string[] dtList = new string[ctidlist.Length];
  3458. for (int i = 0; i < ctidlist.Length; i++)
  3459. {
  3460. dtList[i] = "'" + ctidlist[i] + "'";
  3461. }
  3462. 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"));
  3463. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3464. if (dt_user.Rows.Count > 0)
  3465. {
  3466. int doing = 0;//未定稿
  3467. int finish = 0;//已完成
  3468. foreach (DataRow dr in dt_user.Rows)
  3469. {
  3470. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3471. {
  3472. doing++;
  3473. }
  3474. else
  3475. {
  3476. finish++;
  3477. }
  3478. }
  3479. if (doing >= noFinish)
  3480. {
  3481. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3482. return;
  3483. }
  3484. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3485. {
  3486. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3487. return;
  3488. }
  3489. }
  3490. //校验选择单子状态
  3491. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3492. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3493. if (dt.Rows.Count > 0)
  3494. {
  3495. List<string> list = new List<string>();
  3496. foreach (DataRow dr in dt.Rows)
  3497. {
  3498. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3499. {
  3500. list.Add(dr["ctid"].ToString());
  3501. }
  3502. }
  3503. if (list.Count > 0)
  3504. {
  3505. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3506. return;
  3507. }
  3508. }
  3509. foreach (string ctid in ctidlist)
  3510. {
  3511. CeErpTradeCell entity = null;
  3512. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3513. if (entity != null)
  3514. {
  3515. entity.OrderState = 3;
  3516. entity.DesignUserId = CurrentUser.UserID;
  3517. entity.WaitDesignTime = DateTime.Now;
  3518. entity.StartDesignTime = DateTime.Now;
  3519. entity.Update();
  3520. commonHelper.UpdateRelationOrder(entity.ctid);
  3521. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3522. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3523. itag++;
  3524. }
  3525. }
  3526. }
  3527. }
  3528. count += ctidlist.Length;
  3529. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3530. if (itag == 0)
  3531. returnErrorMsg("没有找到相关订单");
  3532. else
  3533. returnSuccessMsg("抢单成功!");
  3534. return;
  3535. }
  3536. }
  3537. public void get_erp_waitorderlist()
  3538. {
  3539. DataStruct dStruct = GetPostStruct();
  3540. List<string> lw = new List<string>();
  3541. string tid = GetPostString("ctid");
  3542. if (tid.Length > 0)
  3543. {
  3544. string select_tid = getTidByCtid(tid);
  3545. lw.Add(string.Format("tid='{0}'", select_tid));
  3546. }
  3547. string shopname = GetPostString("shopname");
  3548. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3549. string buyernick = GetPostString("buyer_nick");
  3550. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3551. string customer = GetPostString("customer");
  3552. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3553. string design = GetPostString("design");
  3554. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3555. string orderState = GetPostString("orderState");
  3556. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3557. string supplier = GetPostString("supplier");
  3558. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3559. string sellermemo = GetPostString("seller_memo");
  3560. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3561. string otherMemo = GetPostString("otherMemo");
  3562. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3563. string address = GetPostString("address");
  3564. 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));
  3565. string date1 = GetPostString("date1");
  3566. string date2 = GetPostString("date2");
  3567. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3568. if (dw.Length > 0) lw.Add(dw);
  3569. string price1 = GetPostString("price1");
  3570. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3571. string price2 = GetPostString("price2");
  3572. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3573. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3574. lw.Add(string.Format("IsSample != 2 "));
  3575. lw.Add(string.Format("OrderState = 5 "));
  3576. lw.Add(string.Format("IsRefund<={0}", 1));
  3577. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3578. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3579. string pagesize = GetPostString("pagesize");
  3580. if (pagesize != null)
  3581. {
  3582. dStruct.PageSize = 200;
  3583. }
  3584. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3585. List<string> tids = new List<string>();
  3586. if (dt != null)
  3587. {
  3588. dt.Columns.Add("compenPrice", typeof(double));
  3589. foreach (DataRow dr in dt.Rows)
  3590. {
  3591. if (Convert.IsDBNull(dr["compenPrice"]))
  3592. {
  3593. dr["compenPrice"] = 0;
  3594. }
  3595. tids.Add("'" + dr["tid"].ToString() + "'");
  3596. 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();
  3597. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3598. {
  3599. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3600. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3601. entity.SupplierId = suid;
  3602. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3603. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3604. entity.Update();
  3605. }
  3606. }
  3607. }
  3608. if (tids.Count > 0)
  3609. {
  3610. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3611. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3612. if (dt_price != null && dt_price.Rows.Count > 0)
  3613. {
  3614. foreach (DataRow dr in dt_price.Rows)
  3615. {
  3616. foreach (DataRow row in dt.Rows)
  3617. {
  3618. if (row["tid"].Equals(dr["ptid"]))
  3619. {
  3620. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3621. break;
  3622. }
  3623. }
  3624. }
  3625. }
  3626. }
  3627. writeGridDataTableJson(dStruct.TotalCount, dt);
  3628. }
  3629. public void get_erp_supplierwaitorderlist()
  3630. {
  3631. DataStruct dStruct = GetPostStruct();
  3632. List<string> lw = new List<string>();
  3633. string tid = GetPostString("ctid");
  3634. if (tid.Length > 0)
  3635. {
  3636. string select_tid = getTidByCtid(tid);
  3637. lw.Add(string.Format("tid='{0}'", select_tid));
  3638. }
  3639. string shopname = GetPostString("shopname");
  3640. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3641. string sellermemo = GetPostString("seller_memo");
  3642. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3643. string date1 = GetPostString("date1");
  3644. string date2 = GetPostString("date2");
  3645. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3646. if (dw.Length > 0) lw.Add(dw);
  3647. lw.Add(string.Format("OrderState = 5 "));
  3648. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3649. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3650. {
  3651. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3652. }
  3653. string supplier = GetPostString("supplier");
  3654. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3655. {
  3656. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3657. }
  3658. lw.Add(string.Format("IsRefund<={0}", 1));
  3659. dStruct.Order = "FinishDesignTime desc";
  3660. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3661. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3662. if (dt != null)
  3663. {
  3664. foreach (DataRow dr in dt.Rows)
  3665. {
  3666. 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();
  3667. }
  3668. }
  3669. writeGridDataTableJson(dStruct.TotalCount, dt);
  3670. }
  3671. public void upd_erp_verifytosupplier()
  3672. {
  3673. if (UrlPostParmsCheck("ctid"))
  3674. {
  3675. string eids = GetPostString("ctid");
  3676. CeErpTradeCell entity = null;
  3677. string[] eidsList = eids.Split(',');
  3678. if (eidsList.Length <= 0)
  3679. {
  3680. returnErrorMsg("订单号不能空");
  3681. return;
  3682. }
  3683. List<string> tLst = new List<string>();
  3684. foreach (string ctidstr in eidsList)
  3685. {
  3686. tLst.Add("'" + ctidstr + "'");
  3687. CeErpDataSendOrderInfo.createObject(ctidstr);
  3688. }
  3689. string needtids = string.Join(",", tLst.ToArray());
  3690. StringBuilder sql = new StringBuilder();
  3691. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3692. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1},IsHaveNewOrder=0 where SupplierId!=0 AND OrderState = 5 and ctid in ({0});", needtids, CurrentUser.UserID);
  3693. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3694. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3695. returnSuccessMsg("操作成功!");
  3696. return;
  3697. /**foreach (string ctidstr in eidsList)
  3698. {
  3699. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3700. if (entity != null)
  3701. {
  3702. if (entity.SupplierId == 0)
  3703. {
  3704. continue;
  3705. }
  3706. entity.IsVerifyToSupplier = true;
  3707. if (entity.IsReturn == 1) //1是供应商打回
  3708. {
  3709. entity.IsReturn = 0;
  3710. }
  3711. entity.FinishPlaceTime = DateTime.Now;
  3712. entity.PlaceUserId = CurrentUser.UserID;
  3713. entity.Update();
  3714. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3715. }
  3716. }
  3717. returnSuccessMsg("操作成功!");
  3718. return;**/
  3719. }
  3720. }
  3721. public void upd_erp_supplierback()
  3722. {
  3723. if (UrlPostParmsCheck("ctid"))
  3724. {
  3725. string eid = GetPostString("ctid");
  3726. string reason = GetPostString("returnreason");
  3727. CeErpTradeCell entity = null;
  3728. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3729. if (entity != null)
  3730. {
  3731. string message = "操作成功!";
  3732. string isDown = "";
  3733. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3734. {
  3735. message = eid + "订单有被点击下载。请注意沟通是否已下载完!";
  3736. isDown = "被点击下载";
  3737. }
  3738. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3739. {
  3740. string key = "return_order_" + entity.SupplierId;
  3741. List<string> list = new List<string>();
  3742. if (RedisHelper.HasKey(key))
  3743. {
  3744. object data = RedisHelper.StringGet(key);
  3745. list = Convert.ToString(data).Split(',').ToList();
  3746. }
  3747. list.Add(eid);
  3748. RedisHelper.StringSet(key, string.Join(",", list));
  3749. }
  3750. entity.IsVerifyToSupplier = false;
  3751. entity.IsReturn = 1;
  3752. entity.IsHaveNewOrder = 0;
  3753. entity.ReturnTime = DateTime.Now;
  3754. entity.ReturnReason = reason;
  3755. if (entity.OrderState == 6)
  3756. {
  3757. entity.OrderState = 5;
  3758. }
  3759. entity.Update();
  3760. CeErpSukuraData.createInfo(entity.ctid, 5);
  3761. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3762. returnSuccessMsg(message);
  3763. return;
  3764. }
  3765. returnErrorMsg("找不到订单记录");
  3766. }
  3767. }
  3768. public void upd_erp_toaftersaleorder()
  3769. {
  3770. if (UrlPostParmsCheck("ctid"))
  3771. {
  3772. string eid = GetPostString("ctid");
  3773. string reason = GetPostString("returnreason");
  3774. CeErpTradeCell entity = null;
  3775. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3776. if (entity != null)
  3777. {
  3778. if (entity.isAfterSaleOrder != 1)
  3779. {
  3780. returnErrorMsg("带S的售后单才能打回给售后");
  3781. return;
  3782. }
  3783. if (entity.OrderState >= 5)
  3784. {
  3785. returnErrorMsg("已经设计完成了不能打回给售后");
  3786. return;
  3787. }
  3788. entity.OrderState = 0;
  3789. entity.IsReturn = 3;
  3790. entity.ReturnTime = DateTime.Now;
  3791. entity.UpdateTime = DateTime.Now;
  3792. entity.ReturnReason = reason;
  3793. entity.Update();
  3794. CeErpSukuraData.createInfo(entity.ctid, 5);
  3795. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3796. returnSuccessMsg("操作成功!");
  3797. return;
  3798. }
  3799. returnErrorMsg("找不到订单记录");
  3800. }
  3801. }
  3802. public void upd_erp_aftersaletodesign()
  3803. {
  3804. if (UrlPostParmsCheck("ctid"))
  3805. {
  3806. string eid = GetPostString("ctid");
  3807. CeErpTradeCell entity = null;
  3808. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3809. if (entity != null)
  3810. {
  3811. entity.OrderState = 3;
  3812. entity.IsReturn = 0;
  3813. entity.UpdateTime = DateTime.Now;
  3814. entity.Update();
  3815. CeErpSukuraData.createInfo(entity.ctid, 5);
  3816. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3817. returnSuccessMsg("操作成功!");
  3818. return;
  3819. }
  3820. returnErrorMsg("找不到订单记录");
  3821. }
  3822. }
  3823. public void assign_erp_supplier()
  3824. {
  3825. if (UrlPostParmsCheck("ctid"))
  3826. {
  3827. string eids = GetPostString("ctid");
  3828. int sid = GetPostInt("SupplierName");
  3829. string fromTag = GetPostString("tag");
  3830. string[] eidList = eids.Split(',');
  3831. if (eidList.Length <= 0)
  3832. {
  3833. returnErrorMsg("指派不能为空");
  3834. return;
  3835. }
  3836. string errMsg = "";
  3837. string suname = commonHelper.getSupplierNameById(sid);
  3838. foreach (string ctid in eidList)
  3839. {
  3840. CeErpTradeCell entity = null;
  3841. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3842. if (entity != null)
  3843. {
  3844. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3845. {
  3846. errMsg += (ctid + "指派失败!!!");
  3847. continue;
  3848. }
  3849. entity.SupplierId = sid;
  3850. entity.Update();
  3851. commonHelper.UpdateRelationOrder(entity.ctid);
  3852. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3853. if (entity.OrderState >= 6)
  3854. {
  3855. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3856. //{
  3857. // string msl = entity.MakeSupplier;
  3858. // string[] mslist = msl.Split(',');
  3859. // 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);
  3860. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3861. //}
  3862. //else
  3863. //{
  3864. StringBuilder sql = new StringBuilder();
  3865. 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);
  3866. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3867. //}
  3868. }
  3869. }
  3870. else
  3871. {
  3872. continue;
  3873. }
  3874. }
  3875. if (errMsg.Length > 0)
  3876. {
  3877. returnErrorMsg(errMsg);
  3878. return;
  3879. }
  3880. returnSuccessMsg("操作成功!");
  3881. return;
  3882. }
  3883. }
  3884. public void assign_erp_makesupplier()
  3885. {
  3886. if (UrlPostParmsCheck("ctid"))
  3887. {
  3888. string eids = GetPostString("ctid");
  3889. string sname = GetPostString("SupplierName");
  3890. string[] eidList = eids.Split(',');
  3891. if (eidList.Length <= 0)
  3892. {
  3893. returnErrorMsg("指派不能为空");
  3894. return;
  3895. }
  3896. List<string> tLst = new List<string>();
  3897. foreach (string ctid in eidList)
  3898. {
  3899. CeErpTradeCell entity = null;
  3900. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3901. if (entity != null)
  3902. {
  3903. entity.MakeSupplier = sname;
  3904. entity.Update();
  3905. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3906. tLst.Add("'" + ctid + "'");
  3907. }
  3908. else
  3909. {
  3910. continue;
  3911. }
  3912. }
  3913. string ctids = string.Join(",", tLst.ToArray());
  3914. StringBuilder sql2 = new StringBuilder();
  3915. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3916. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3917. returnSuccessMsg("操作成功!");
  3918. return;
  3919. }
  3920. }
  3921. public void ins_erp_returnreason()
  3922. {
  3923. if (UrlPostParmsCheck("ctid"))
  3924. {
  3925. string eid = GetPostString("ctid");
  3926. CeErpTradeCell entity = null;
  3927. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3928. string userpost = CurrentUser.UserPost.Post.Code;
  3929. if (entity != null)
  3930. {
  3931. bool isPlace = false;
  3932. if (entity.OrderState > 6)
  3933. {
  3934. returnErrorMsg("已发货无法打回!");
  3935. return;
  3936. }
  3937. if (entity.OrderState == 6)
  3938. {
  3939. isPlace = true;
  3940. }
  3941. bool isNeedUpdateCell2 = false;
  3942. if (entity.OrderState >= 6)
  3943. {
  3944. isNeedUpdateCell2 = true;
  3945. }
  3946. int returnTag = 2;
  3947. if (userpost == "Supplier")
  3948. {
  3949. returnTag = 1;
  3950. }
  3951. int toType = GetPostInt("totype");
  3952. string fromType = "3";
  3953. if (entity.OrderState < 5)
  3954. {
  3955. fromType = "3";
  3956. }
  3957. else
  3958. {
  3959. fromType = "4";
  3960. }
  3961. if (entity.IsXianHuo == 0)
  3962. {
  3963. if (returnTag == 2)
  3964. {
  3965. if (toType == 1)
  3966. {
  3967. entity.OrderState = 0;
  3968. entity.ReturnUserType = 1;
  3969. string clearman = GetPostString("clearman");
  3970. if (!string.IsNullOrEmpty(clearman))
  3971. {
  3972. entity.DesignUserId = 0;
  3973. }
  3974. }
  3975. else
  3976. {
  3977. entity.OrderState = 3;
  3978. entity.ReturnUserType = 2;
  3979. }
  3980. entity.IsReadTag = 1;
  3981. }
  3982. else if (returnTag == 1)
  3983. {
  3984. entity.OrderState = 5;
  3985. }
  3986. entity.IsVerifyToSupplier = false;
  3987. }
  3988. if (entity.IsXianHuo == 1)
  3989. {
  3990. entity.OrderState = 5;
  3991. }
  3992. entity.UnusualTag = 0;
  3993. entity.UnusualTime = null;
  3994. entity.UnusualCon = "";
  3995. entity.IsReturn = returnTag;
  3996. entity.ReturnTime = DateTime.Now;
  3997. entity.UpdateTime = DateTime.Now;
  3998. entity.ReturnReason = GetPostString("returnreason");
  3999. entity.Update();
  4000. if (entity.OrderState == 3)
  4001. {
  4002. ApiVo apiVo = new ApiVo();
  4003. apiVo.orderNumber = entity.ctid;
  4004. apiVo.actionName = "rebutDesign";
  4005. apiVo.orderRemarks = entity.ReturnReason;
  4006. designHelper.API_WorkCore(apiVo);//rebutDesign
  4007. }
  4008. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  4009. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  4010. {
  4011. //dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  4012. }
  4013. //CeErpSukuraData.createInfo(entity.ctid, 5);
  4014. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4015. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4016. if (isPlace)
  4017. {
  4018. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  4019. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4020. if (dth != null && dth.Rows.Count > 0)
  4021. {
  4022. dataSendOrderBean dataSendOrderBean = null;
  4023. foreach (DataRow item in dth.Rows)
  4024. {
  4025. try
  4026. {
  4027. dataSendOrderBean = new dataSendOrderBean();
  4028. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  4029. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  4030. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  4031. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  4032. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  4033. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  4034. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  4035. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  4036. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  4037. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  4038. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  4039. dataSendOrderBean.Radio1723534706288 = "打回";
  4040. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  4041. if (result != null)
  4042. {
  4043. if ("0".Equals(result.errcode))
  4044. {
  4045. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  4046. }
  4047. else
  4048. {
  4049. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  4050. }
  4051. }
  4052. }
  4053. catch (Exception ex)
  4054. {
  4055. }
  4056. }
  4057. }
  4058. }
  4059. returnSuccessMsg("操作成功!");
  4060. return;
  4061. }
  4062. returnErrorMsg("找不到订单记录");
  4063. }
  4064. }
  4065. public void cyt_erp_returnreason()
  4066. {
  4067. if (UrlPostParmsCheck("ctid"))
  4068. {
  4069. string eid = GetPostString("ctid");
  4070. CeErpTradeCell entity = null;
  4071. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4072. string userpost = CurrentUser.UserPost.Post.Code;
  4073. if (entity != null)
  4074. {
  4075. if (entity.OrderState > 6)
  4076. {
  4077. returnErrorMsg("已发货无法打回!");
  4078. return;
  4079. }
  4080. JObject jsonObject = new JObject
  4081. {
  4082. { "Userid", "77886" },
  4083. { "Pwd", "lt666888" },
  4084. { "LTOrderId",eid }
  4085. };
  4086. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  4087. JObject jsonObjects = JObject.Parse(response);
  4088. string msg = (string)jsonObjects["msg"];
  4089. if (msg != "取消成功")
  4090. {
  4091. returnErrorMsg(msg);
  4092. return;
  4093. }
  4094. bool isNeedUpdateCell2 = false;
  4095. if (entity.OrderState >= 6)
  4096. {
  4097. isNeedUpdateCell2 = true;
  4098. }
  4099. int returnTag = 2;
  4100. if (userpost == "Supplier")
  4101. {
  4102. returnTag = 1;
  4103. }
  4104. if (entity.IsXianHuo == 0)
  4105. {
  4106. if (returnTag == 2)
  4107. {
  4108. int toType = GetPostInt("totype");
  4109. if (toType == 1)
  4110. {
  4111. entity.OrderState = 0;
  4112. entity.ReturnUserType = 1;
  4113. }
  4114. else
  4115. {
  4116. entity.OrderState = 4;
  4117. entity.ReturnUserType = 2;
  4118. }
  4119. entity.IsReadTag = 1;
  4120. }
  4121. else if (returnTag == 1)
  4122. {
  4123. entity.OrderState = 5;
  4124. }
  4125. entity.IsVerifyToSupplier = false;
  4126. }
  4127. entity.UnusualTag = 0;
  4128. entity.UnusualTime = null;
  4129. entity.UnusualCon = "";
  4130. entity.IsReturn = returnTag;
  4131. entity.ReturnTime = DateTime.Now;
  4132. entity.ReturnReason = GetPostString("returnreason");
  4133. entity.Update();
  4134. if (entity.OrderState == 4)
  4135. {
  4136. ApiVo apiVo = new ApiVo();
  4137. apiVo.orderNumber = entity.ctid;
  4138. apiVo.actionName = "rebutDesign";
  4139. apiVo.orderRemarks = entity.ReturnReason;
  4140. designHelper.API_WorkCore(apiVo);//rebutDesign
  4141. }
  4142. CeErpSukuraData.createInfo(entity.ctid, 5);
  4143. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4144. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4145. if (isNeedUpdateCell2)
  4146. {
  4147. if (entity.MakeSupplier.IndexOf(",") != -1)
  4148. {
  4149. StringBuilder sql2 = new StringBuilder();
  4150. 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);
  4151. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4152. }
  4153. else
  4154. {
  4155. StringBuilder sql2 = new StringBuilder();
  4156. 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);
  4157. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4158. }
  4159. }
  4160. returnSuccessMsg("操作成功!");
  4161. return;
  4162. }
  4163. returnErrorMsg("找不到订单记录");
  4164. }
  4165. }
  4166. public void upd_erp_xianhuoreturntag()
  4167. {
  4168. if (UrlPostParmsCheck("ctid"))
  4169. {
  4170. string eids = GetPostString("ctid");
  4171. string[] ctids = eids.Split(',');
  4172. foreach (string ctid in ctids)
  4173. {
  4174. CeErpTradeCell entity = null;
  4175. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4176. if (entity != null)
  4177. {
  4178. entity.IsReturn = 0;
  4179. entity.Update();
  4180. CeErpSukuraData.createInfo(entity.ctid, 5);
  4181. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4182. }
  4183. }
  4184. returnSuccessMsg("操作成功!");
  4185. return;
  4186. }
  4187. }
  4188. public void get_erp_waitdeliverylist()
  4189. {
  4190. DataStruct dStruct = GetPostStruct();
  4191. List<string> lw = new List<string>();
  4192. string tid = GetPostString("ctid");
  4193. if (tid.Length > 0)
  4194. {
  4195. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4196. if (tid.Length > 5)
  4197. {
  4198. List<string> tids = getTidByCtidLike(tid);
  4199. if (tids.Count > 0 && tids.Count < 10)
  4200. {
  4201. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4202. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4203. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4204. {
  4205. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4206. }*/
  4207. }
  4208. }
  4209. lw.Add(tid_sql);
  4210. }
  4211. string shopname = GetPostString("shopname");
  4212. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4213. string buyernick = GetPostString("buyer_nick");
  4214. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4215. //if (tid.Length == 0 && buyernick.Length == 0)
  4216. //{
  4217. // lw.Add(string.Format("IsRefund<={0}", 1));
  4218. //}
  4219. string customer = GetPostString("customer");
  4220. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4221. string design = GetPostString("design");
  4222. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4223. string orderState = GetPostString("orderState");
  4224. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4225. string address = GetPostString("address");
  4226. 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));
  4227. string sellermemo = GetPostString("seller_memo");
  4228. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4229. string supplier = GetPostString("supplier");
  4230. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4231. string OrderArea = GetPostString("order_area");
  4232. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4233. string placedate1 = GetPostString("placedate1");
  4234. string placedate2 = GetPostString("placedate2");
  4235. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4236. if (fdw.Length > 0) lw.Add(fdw);
  4237. string price1 = GetPostString("price1");
  4238. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4239. string price2 = GetPostString("price2");
  4240. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4241. string unusualCon = GetPostString("unusualcon");
  4242. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4243. string otherMemo = GetPostString("otherMemo");
  4244. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4245. string posTag = CurrentUser.UserPost.Post.Code;
  4246. if (posTag == "Supplier")
  4247. {
  4248. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4249. }
  4250. else
  4251. {
  4252. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4253. {
  4254. string usershop = CurrentUser.User.pemShop;
  4255. lw.Add(string.Format("ShopId in ({0})", usershop));
  4256. }
  4257. }
  4258. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4259. lw.Add(string.Format("type != 'PDD' "));
  4260. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4261. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4262. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4263. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4264. writeGridDataTableJson(dStruct.TotalCount, dt);
  4265. }
  4266. public void get_erp_changedeliverylist()
  4267. {
  4268. DataStruct dStruct = GetPostStruct();
  4269. List<string> lw = new List<string>();
  4270. string tid = GetPostString("ctid");
  4271. if (tid.Length > 0)
  4272. {
  4273. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4274. if (tid.Length > 5)
  4275. {
  4276. List<string> tids = getTidByCtidLike(tid);
  4277. if (tids.Count > 0 && tids.Count < 10)
  4278. {
  4279. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4280. }
  4281. }
  4282. lw.Add(tid_sql);
  4283. }
  4284. string shopname = GetPostString("shopname");
  4285. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4286. string buyernick = GetPostString("buyer_nick");
  4287. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4288. //if (tid.Length == 0 && buyernick.Length == 0)
  4289. //{
  4290. // lw.Add(string.Format("IsRefund<={0}", 1));
  4291. //}
  4292. string customer = GetPostString("customer");
  4293. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4294. string design = GetPostString("design");
  4295. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4296. string orderState = GetPostString("orderState");
  4297. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4298. string address = GetPostString("address");
  4299. 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));
  4300. string sellermemo = GetPostString("seller_memo");
  4301. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4302. string supplier = GetPostString("supplier");
  4303. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4304. string OrderArea = GetPostString("order_area");
  4305. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4306. string placedate1 = GetPostString("placedate1");
  4307. string placedate2 = GetPostString("placedate2");
  4308. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4309. if (fdw.Length > 0) lw.Add(fdw);
  4310. string price1 = GetPostString("price1");
  4311. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4312. string price2 = GetPostString("price2");
  4313. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4314. string unusualCon = GetPostString("unusualcon");
  4315. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4316. string otherMemo = GetPostString("otherMemo");
  4317. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4318. string posTag = CurrentUser.UserPost.Post.Code;
  4319. if (posTag == "Supplier")
  4320. {
  4321. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4322. }
  4323. else
  4324. {
  4325. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4326. {
  4327. string usershop = CurrentUser.User.pemShop;
  4328. lw.Add(string.Format("ShopId in ({0})", usershop));
  4329. }
  4330. }
  4331. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4332. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4333. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4334. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4335. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4336. /*if (tid.Length > 0)
  4337. {
  4338. List<string> tids = new List<string>();
  4339. if (dt != null && dt.Rows.Count > 0)
  4340. {
  4341. foreach (DataRow item in dt.Rows)
  4342. {
  4343. tids.Add("'" + item["tid"] + "'");
  4344. }
  4345. }
  4346. if (tids.Count > 0)
  4347. {
  4348. lw.RemoveAt(0);
  4349. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4350. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4351. dt = WebCache.GetData("view_erptradecell", dStruct);
  4352. }
  4353. }*/
  4354. writeGridDataTableJson(dStruct.TotalCount, dt);
  4355. }
  4356. public void get_erp_pddderiving()
  4357. {
  4358. DataStruct dStruct = GetPostStruct();
  4359. List<string> lw = new List<string>();
  4360. string tid = GetPostString("ctid");
  4361. if (tid.Length > 0)
  4362. {
  4363. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4364. if (tid.Length > 5)
  4365. {
  4366. List<string> tids = getTidByCtidLike(tid);
  4367. if (tids.Count > 0 && tids.Count < 10)
  4368. {
  4369. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4370. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4371. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4372. {
  4373. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4374. }*/
  4375. }
  4376. }
  4377. lw.Add(tid_sql);
  4378. }
  4379. string shopname = GetPostString("shopname");
  4380. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4381. string buyernick = GetPostString("buyer_nick");
  4382. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4383. //if (tid.Length == 0 && buyernick.Length == 0)
  4384. //{
  4385. // lw.Add(string.Format("IsRefund<={0}", 1));
  4386. //}
  4387. string customer = GetPostString("customer");
  4388. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4389. string design = GetPostString("design");
  4390. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4391. string orderState = GetPostString("orderState");
  4392. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4393. string address = GetPostString("address");
  4394. 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));
  4395. string sellermemo = GetPostString("seller_memo");
  4396. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4397. string supplier = GetPostString("supplier");
  4398. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4399. string OrderArea = GetPostString("order_area");
  4400. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4401. string placedate1 = GetPostString("placedate1");
  4402. string placedate2 = GetPostString("placedate2");
  4403. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4404. if (fdw.Length > 0) lw.Add(fdw);
  4405. string price1 = GetPostString("price1");
  4406. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4407. string price2 = GetPostString("price2");
  4408. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4409. string unusualCon = GetPostString("unusualcon");
  4410. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4411. string posTag = CurrentUser.UserPost.Post.Code;
  4412. if (posTag == "Supplier")
  4413. {
  4414. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4415. }
  4416. else
  4417. {
  4418. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4419. {
  4420. string usershop = CurrentUser.User.pemShop;
  4421. lw.Add(string.Format("ShopId in ({0})", usershop));
  4422. }
  4423. }
  4424. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4425. lw.Add(string.Format("type = 'PDD' "));
  4426. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4427. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4428. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4429. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4430. /*if (tid.Length > 0)
  4431. {
  4432. List<string> tids = new List<string>();
  4433. if (dt != null && dt.Rows.Count > 0)
  4434. {
  4435. foreach (DataRow item in dt.Rows)
  4436. {
  4437. tids.Add("'" + item["tid"] + "'");
  4438. }
  4439. }
  4440. if (tids.Count > 0)
  4441. {
  4442. lw.RemoveAt(0);
  4443. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4444. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4445. dt = WebCache.GetData("view_erptradecell", dStruct);
  4446. }
  4447. }*/
  4448. writeGridDataTableJson(dStruct.TotalCount, dt);
  4449. }
  4450. public void get_erp_jdderiving()
  4451. {
  4452. DataStruct dStruct = GetPostStruct();
  4453. List<string> lw = new List<string>();
  4454. string tid = GetPostString("ctid");
  4455. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4456. string shopname = GetPostString("shopname");
  4457. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4458. string buyernick = GetPostString("buyer_nick");
  4459. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4460. //if (tid.Length == 0 && buyernick.Length == 0)
  4461. //{
  4462. // lw.Add(string.Format("IsRefund<={0}", 1));
  4463. //}
  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 orderState = GetPostString("orderState");
  4469. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4470. string address = GetPostString("address");
  4471. 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));
  4472. string sellermemo = GetPostString("seller_memo");
  4473. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4474. string supplier = GetPostString("supplier");
  4475. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4476. string OrderArea = GetPostString("order_area");
  4477. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4478. string placedate1 = GetPostString("placedate1");
  4479. string placedate2 = GetPostString("placedate2");
  4480. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4481. if (fdw.Length > 0) lw.Add(fdw);
  4482. string price1 = GetPostString("price1");
  4483. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4484. string price2 = GetPostString("price2");
  4485. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4486. string unusualCon = GetPostString("unusualcon");
  4487. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4488. string posTag = CurrentUser.UserPost.Post.Code;
  4489. if (posTag == "Supplier")
  4490. {
  4491. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4492. }
  4493. lw.Add(string.Format("OrderState = 6 "));
  4494. lw.Add(string.Format("type = 'JD' "));
  4495. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4496. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4497. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4498. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4499. writeGridDataTableJson(dStruct.TotalCount, dt);
  4500. }
  4501. public void get_erp_demoorderlist()
  4502. {
  4503. DataStruct dStruct = GetPostStruct();
  4504. List<string> lw = new List<string>();
  4505. string tid = GetPostString("ctid");
  4506. if (tid.Length > 0)
  4507. {
  4508. string select_tid = getTidByCtid(tid);
  4509. lw.Add(string.Format("tid='{0}'", select_tid));
  4510. }
  4511. string shopname = GetPostString("shopname");
  4512. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4513. string buyernick = GetPostString("buyer_nick");
  4514. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4515. string customer = GetPostString("customer");
  4516. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4517. string design = GetPostString("design");
  4518. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4519. string orderState = GetPostString("orderState");
  4520. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4521. string address = GetPostString("address");
  4522. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4523. string sellermemo = GetPostString("seller_memo");
  4524. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4525. string supplier = GetPostString("supplier");
  4526. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4527. string OrderArea = GetPostString("order_area");
  4528. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4529. string date1 = GetPostString("date1");
  4530. string date2 = GetPostString("date2");
  4531. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4532. if (dw.Length > 0) lw.Add(dw);
  4533. string price1 = GetPostString("price1");
  4534. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4535. string price2 = GetPostString("price2");
  4536. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4537. string posTag = CurrentUser.UserPost.Post.Code;
  4538. if (posTag == "Supplier")
  4539. {
  4540. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4541. }
  4542. //lw.Add(string.Format("OrderState = 6 "));
  4543. lw.Add(string.Format("IsSample={0}", 3));
  4544. lw.Add(string.Format("IsRefund<={0}", 1));
  4545. dStruct.Order = "pay_time desc";
  4546. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4547. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4548. writeGridDataTableJson(dStruct.TotalCount, dt);
  4549. }
  4550. public void save_erp_checkmemo()
  4551. {
  4552. if (UrlPostParmsCheck("ctid"))
  4553. {
  4554. string ctid = GetPostString("ctid");
  4555. CeErpTradeCell entity = null;
  4556. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4557. if (entity != null)
  4558. {
  4559. entity.CheckMemo = GetPostString("CheckMemo");
  4560. entity.Update();
  4561. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4562. if (trade != null)
  4563. {
  4564. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4565. }
  4566. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4567. returnSuccessMsg("保存成功!");
  4568. return;
  4569. }
  4570. returnErrorMsg("找不到记录");
  4571. }
  4572. }
  4573. public void get_erp_returnlist()
  4574. {
  4575. DataStruct dStruct = GetPostStruct();
  4576. List<string> lw = new List<string>();
  4577. string tid = GetPostString("ctid");
  4578. if (tid.Length > 0)
  4579. {
  4580. string select_tid = getTidByCtid(tid);
  4581. lw.Add(string.Format("tid='{0}'", select_tid));
  4582. }
  4583. string shopname = GetPostString("shopname");
  4584. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4585. string buyernick = GetPostString("buyer_nick");
  4586. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4587. string customer = GetPostString("customer");
  4588. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4589. string design = GetPostString("design");
  4590. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4591. string orderState = GetPostString("orderState");
  4592. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4593. string address = GetPostString("address");
  4594. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4595. string sellermemo = GetPostString("seller_memo");
  4596. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4597. string supplier = GetPostString("supplier");
  4598. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4599. string date1 = GetPostString("date1");
  4600. string date2 = GetPostString("date2");
  4601. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4602. if (dw.Length > 0) lw.Add(dw);
  4603. string bdate1 = GetPostString("backdate1");
  4604. string bdate2 = GetPostString("backdate2");
  4605. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4606. if (dw_back.Length > 0) lw.Add(dw_back);
  4607. string price1 = GetPostString("price1");
  4608. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4609. string price2 = GetPostString("price2");
  4610. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4611. lw.Add(string.Format("IsReturn>0"));
  4612. lw.Add(string.Format("IsXianHuo=0"));
  4613. lw.Add(string.Format("IsReturn!=3"));
  4614. string backtype = GetPostString("backtype");
  4615. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4616. dStruct.Order = "FinishDesignTime desc";
  4617. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4618. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4619. writeGridDataTableJson(dStruct.TotalCount, dt);
  4620. }
  4621. public void get_erp_today_sumreturn()
  4622. {
  4623. DataStruct dStruct = GetPostStruct();
  4624. List<string> lw = new List<string>();
  4625. string bdate1 = GetPostString("returnTimeS");
  4626. string bdate2 = GetPostString("returnTimeE");
  4627. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4628. if (dw_back.Length > 0) lw.Add(dw_back);
  4629. lw.Add(string.Format("IsReturn=0"));
  4630. lw.Add(string.Format("IsXianHuo=0"));
  4631. string mainWhere = string.Join(" and ", lw.ToArray());
  4632. string sql = "";
  4633. if (dw_back.Length > 0)
  4634. {
  4635. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4636. }
  4637. else
  4638. {
  4639. 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 + "'";
  4640. }
  4641. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4642. decimal total = 0, today_finish = 0;
  4643. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4644. {
  4645. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4646. }
  4647. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4648. {
  4649. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4650. }
  4651. var res = new
  4652. {
  4653. data = total,
  4654. data1 = today_finish,
  4655. };
  4656. string ro_jsond = JsonConvert.SerializeObject(res);
  4657. returnSuccess(ro_jsond);
  4658. return;
  4659. }
  4660. public void get_erp_allreturnlist()
  4661. {
  4662. DataStruct dStruct = GetPostStruct();
  4663. List<string> lw = new List<string>();
  4664. string tid = GetPostString("ctid");
  4665. if (tid.Length > 0)
  4666. {
  4667. string select_tid = getTidByCtid(tid);
  4668. lw.Add(string.Format("tid='{0}'", select_tid));
  4669. }
  4670. string shopname = GetPostString("shopname");
  4671. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4672. string buyernick = GetPostString("buyer_nick");
  4673. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4674. string customer = GetPostString("customer");
  4675. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4676. string design = GetPostString("design");
  4677. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4678. string orderState = GetPostString("orderState");
  4679. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4680. string address = GetPostString("address");
  4681. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4682. string sellermemo = GetPostString("seller_memo");
  4683. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4684. string supplier = GetPostString("supplier");
  4685. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4686. string date1 = GetPostString("date1");
  4687. string date2 = GetPostString("date2");
  4688. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4689. if (dw.Length > 0) lw.Add(dw);
  4690. string bdate1 = GetPostString("backdate1");
  4691. string bdate2 = GetPostString("backdate2");
  4692. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4693. if (dw_back.Length > 0) lw.Add(dw_back);
  4694. string price1 = GetPostString("price1");
  4695. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4696. string price2 = GetPostString("price2");
  4697. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4698. string backreason = GetPostString("backreason");
  4699. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4700. lw.Add(string.Format("IsXianHuo=0"));
  4701. lw.Add(string.Format("ReturnTime != ''"));
  4702. string backtype = GetPostString("backtype");
  4703. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4704. string posTag = CurrentUser.UserPost.Post.Code;
  4705. if (posTag == "Supplier")
  4706. {
  4707. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4708. }
  4709. else
  4710. {
  4711. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4712. {
  4713. string usershop = CurrentUser.User.pemShop;
  4714. lw.Add(string.Format("ShopId in ({0})", usershop));
  4715. }
  4716. }
  4717. dStruct.Order = "FinishDesignTime desc";
  4718. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4719. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4720. writeGridDataTableJson(dStruct.TotalCount, dt);
  4721. }
  4722. public void get_erp_aftersalereturnlist()
  4723. {
  4724. DataStruct dStruct = GetPostStruct();
  4725. List<string> lw = new List<string>();
  4726. string tid = GetPostString("ctid");
  4727. if (tid.Length > 0)
  4728. {
  4729. string select_tid = getTidByCtid(tid);
  4730. lw.Add(string.Format("tid='{0}'", select_tid));
  4731. }
  4732. string shopname = GetPostString("shopname");
  4733. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4734. string buyernick = GetPostString("buyer_nick");
  4735. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4736. string customer = GetPostString("customer");
  4737. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4738. string design = GetPostString("design");
  4739. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4740. string orderState = GetPostString("orderState");
  4741. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4742. string address = GetPostString("address");
  4743. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4744. string sellermemo = GetPostString("seller_memo");
  4745. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4746. string supplier = GetPostString("supplier");
  4747. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4748. string date1 = GetPostString("date1");
  4749. string date2 = GetPostString("date2");
  4750. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4751. if (dw.Length > 0) lw.Add(dw);
  4752. string bdate1 = GetPostString("backdate1");
  4753. string bdate2 = GetPostString("backdate2");
  4754. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4755. if (dw_back.Length > 0) lw.Add(dw_back);
  4756. string price1 = GetPostString("price1");
  4757. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4758. string price2 = GetPostString("price2");
  4759. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4760. lw.Add(string.Format("IsReturn=3"));
  4761. string backtype = GetPostString("backtype");
  4762. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4763. string backreason = GetPostString("backreason");
  4764. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4765. dStruct.Order = "ReturnTime desc";
  4766. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4767. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4768. writeGridDataTableJson(dStruct.TotalCount, dt);
  4769. }
  4770. public void get_erp_xianhuoreturnlist()
  4771. {
  4772. DataStruct dStruct = GetPostStruct();
  4773. List<string> lw = new List<string>();
  4774. string tid = GetPostString("ctid");
  4775. if (tid.Length > 0)
  4776. {
  4777. string select_tid = getTidByCtid(tid);
  4778. lw.Add(string.Format("tid='{0}'", select_tid));
  4779. }
  4780. string shopname = GetPostString("shopname");
  4781. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4782. string buyernick = GetPostString("buyer_nick");
  4783. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4784. string customer = GetPostString("customer");
  4785. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4786. string design = GetPostString("design");
  4787. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4788. string orderState = GetPostString("orderState");
  4789. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4790. string address = GetPostString("address");
  4791. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4792. string sellermemo = GetPostString("seller_memo");
  4793. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4794. string supplier = GetPostString("supplier");
  4795. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4796. string OrderArea = GetPostString("order_area");
  4797. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4798. string date1 = GetPostString("date1");
  4799. string date2 = GetPostString("date2");
  4800. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4801. if (dw.Length > 0) lw.Add(dw);
  4802. string price1 = GetPostString("price1");
  4803. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4804. string price2 = GetPostString("price2");
  4805. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4806. string posTag = CurrentUser.UserPost.Post.Code;
  4807. if (posTag == "Supplier")
  4808. {
  4809. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4810. }
  4811. lw.Add(string.Format("OrderState=6 "));
  4812. lw.Add(string.Format("IsXianHuo=1 "));
  4813. lw.Add(string.Format("IsReturn>0 "));
  4814. lw.Add(string.Format("IsReturn < 3"));
  4815. lw.Add(string.Format("IsRefund<={0}", 1));
  4816. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4817. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4818. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4819. writeGridDataTableJson(dStruct.TotalCount, dt);
  4820. }
  4821. public void set_erp_orderdelivery()
  4822. {
  4823. if (UrlPostParmsCheck("ctid"))
  4824. {
  4825. string eid = GetPostString("ctid");
  4826. CeErpTradeCell entity = null;
  4827. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4828. if (entity != null)
  4829. {
  4830. if (entity.OrderState >= 7)
  4831. {
  4832. returnErrorMsg("此单已发货,无需重复发货");
  4833. return;
  4834. }
  4835. if (entity.OrderState != 6)
  4836. {
  4837. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4838. return;
  4839. }
  4840. string shop = GetPostString("seller_nick");
  4841. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4842. string comName = GetPostString("comName");
  4843. string comCode = GetPostString("comCode");
  4844. string outSid = GetPostString("outSid");
  4845. string deliveryType = GetPostString("deliveryType");
  4846. string deliveryMemo = GetPostString("deliveryMemo");
  4847. outSid = outSid.Trim();
  4848. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4849. if (mainEn == null)
  4850. {
  4851. returnErrorMsg("找不到原始订单记录");
  4852. return;
  4853. }
  4854. bool isInitOrderDeliv = false;
  4855. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4856. {
  4857. isInitOrderDeliv = true;
  4858. }
  4859. string apires = "";
  4860. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4861. 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)
  4862. {
  4863. apires = "发货成功true";
  4864. }
  4865. else
  4866. {
  4867. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4868. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid, entity.ctid);
  4869. }
  4870. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4871. {
  4872. entity.OrderState = 7;//发货后订单已发货
  4873. entity.OutSid = outSid;
  4874. entity.MemoOpt = 0;
  4875. entity.UpdateTime = DateTime.Now;
  4876. entity.FinishDeliveryTime = DateTime.Now;
  4877. entity.Update();
  4878. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4879. commonHelper.UpdateRelationOrder(entity.ctid);
  4880. //还要插入快递信息到 快递信息表
  4881. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4882. exinfo.tid = eid;
  4883. exinfo.out_sid = outSid;
  4884. exinfo.company_code = comCode;
  4885. exinfo.company_name = comName;
  4886. exinfo.delivery_memo = deliveryMemo;
  4887. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4888. exinfo.deliveryType = deliveryType;
  4889. exinfo.printUser = CurrentUser.UserName;
  4890. exinfo.print_time = DateTime.Now;
  4891. exinfo.Create();
  4892. returnSuccessMsg("发货操作成功!");
  4893. commonHelper.UpdateRelationOrder(entity.ctid);
  4894. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4895. CeErpSukuraData.createInfo(entity.ctid, 4);
  4896. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126 || entity.SupplierId == 96)
  4897. {
  4898. commonHelper.sendCytExpress(exinfo);
  4899. }
  4900. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4901. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid + ",备注:" + deliveryMemo, entity.OrderState);
  4902. }
  4903. else
  4904. {
  4905. string errmsg = commonHelper.KeepChinese(apires);
  4906. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4907. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4908. }
  4909. return;
  4910. }
  4911. returnErrorMsg("找不到订单记录");
  4912. }
  4913. }
  4914. public void set_erp_multidelivery()
  4915. {
  4916. string eids = GetPostString("tids");
  4917. string[] eidList = eids.Split(',');
  4918. if (eidList.Length <= 0)
  4919. {
  4920. returnErrorMsg("发货不能为空");
  4921. return;
  4922. }
  4923. foreach (string ctid in eidList)
  4924. {
  4925. if (ctid.Length <= 0) continue;
  4926. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4927. if (expInfo != null)
  4928. {
  4929. StringBuilder sql = new StringBuilder();
  4930. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4931. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4932. if (dt.Rows.Count > 0)
  4933. {
  4934. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4935. {
  4936. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4937. expInfo.state = "异常";
  4938. expInfo.isMultiDelivery = 1;
  4939. expInfo.Update();
  4940. continue;
  4941. }
  4942. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4943. {
  4944. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4945. expInfo.state = "异常";
  4946. expInfo.Update();
  4947. continue;
  4948. }
  4949. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4950. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4951. bool isInitOrderDeliv = false;
  4952. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4953. {
  4954. isInitOrderDeliv = true;
  4955. expInfo.isMultiDelivery = 1;
  4956. }
  4957. if (ctid.IndexOf("N") != -1)
  4958. {
  4959. StringBuilder sqlbucha = new StringBuilder();
  4960. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4961. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4962. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4963. commonHelper.UpdateRelationOrder(ctid);
  4964. expInfo.delivery_memo = "发货成功";
  4965. expInfo.state = "发货成功";
  4966. expInfo.isMultiDelivery = 1;
  4967. expInfo.Update();
  4968. }
  4969. else
  4970. {
  4971. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4972. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid, ctid);
  4973. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4974. {
  4975. expInfo.delivery_memo = "发货成功";
  4976. expInfo.state = "发货成功";
  4977. expInfo.isMultiDelivery = 1;
  4978. expInfo.Update();
  4979. commonHelper.UpdateRelationOrder(ctid);
  4980. CeErpSukuraData.createInfo(ctid, 4);
  4981. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4982. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4983. }
  4984. else
  4985. {
  4986. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4987. expInfo.state = "异常";
  4988. expInfo.Update();
  4989. }
  4990. }
  4991. }
  4992. }
  4993. }
  4994. returnSuccessMsg("操作完成");
  4995. }
  4996. public void reset_erp_memoopt()
  4997. {
  4998. if (UrlPostParmsCheck("ctid"))
  4999. {
  5000. string eid = GetPostString("ctid");
  5001. CeErpTradeCell entity = null;
  5002. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5003. if (entity != null)
  5004. {
  5005. string stropt = "";
  5006. if (entity.MemoOpt == 1)
  5007. {
  5008. stropt = "“改稿”";
  5009. }
  5010. else if (entity.MemoOpt == 2)
  5011. {
  5012. stropt = "“定稿”";
  5013. }
  5014. else if (entity.MemoOpt == 3)
  5015. {
  5016. stropt = "“完成查货”";
  5017. CeErpSukuraData.createInfo(entity.ctid, 6);
  5018. }
  5019. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  5020. entity.UpdateTime = DateTime.Now;
  5021. entity.MemoOpt = 0;
  5022. entity.Update();
  5023. returnSuccessMsg("操作成功!");
  5024. return;
  5025. }
  5026. returnErrorMsg("找不到记录");
  5027. }
  5028. }
  5029. public void get_erp_deliveryunusual()
  5030. {
  5031. DataStruct dStruct = GetPostStruct();
  5032. List<string> lw = new List<string>();
  5033. string tid = GetPostString("ctid");
  5034. if (tid.Length > 0)
  5035. {
  5036. string select_tid = getTidByCtid(tid);
  5037. lw.Add(string.Format("tid='{0}'", select_tid));
  5038. }
  5039. string shopname = GetPostString("shopname");
  5040. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5041. string buyernick = GetPostString("buyer_nick");
  5042. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5043. string customer = GetPostString("customer");
  5044. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5045. string design = GetPostString("design");
  5046. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5047. string sellermemo = GetPostString("seller_memo");
  5048. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5049. string supplier = GetPostString("supplier");
  5050. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5051. string date1 = GetPostString("date1");
  5052. string date2 = GetPostString("date2");
  5053. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5054. if (dw.Length > 0) lw.Add(dw);
  5055. string placedate1 = GetPostString("placedate1");
  5056. string placedate2 = GetPostString("placedate2");
  5057. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5058. if (dw_place.Length > 0) lw.Add(dw_place);
  5059. string price1 = GetPostString("price1");
  5060. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5061. string price2 = GetPostString("price2");
  5062. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5063. string unusualCon = GetPostString("unusualcon");
  5064. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  5065. string posTag = CurrentUser.UserPost.Post.Code;
  5066. if (posTag == "Supplier")
  5067. {
  5068. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5069. }
  5070. lw.Add(string.Format("OrderState = 6"));
  5071. lw.Add(string.Format("UnusualTag = 5"));
  5072. lw.Add(string.Format("IsRefund<={0}", 1));
  5073. dStruct.Order = "FinishPlaceTime desc";
  5074. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5075. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5076. writeGridDataTableJson(dStruct.TotalCount, dt);
  5077. }
  5078. public void get_erp_deliveryedlist()
  5079. {
  5080. DataStruct dStruct = GetPostStruct();
  5081. List<string> lw = new List<string>();
  5082. string tid = GetPostString("ctid");
  5083. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5084. string shopname = GetPostString("shopname");
  5085. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5086. string buyernick = GetPostString("buyer_nick");
  5087. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5088. string customer = GetPostString("customer");
  5089. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5090. string design = GetPostString("design");
  5091. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5092. string sellermemo = GetPostString("seller_memo");
  5093. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5094. string logistics = GetPostString("logistics");
  5095. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5096. string date1 = GetPostString("date1");
  5097. string date2 = GetPostString("date2");
  5098. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5099. //if (dw.Length > 0) lw.Add(dw);
  5100. string placedate1 = GetPostString("placedate1");
  5101. string placedate2 = GetPostString("placedate2");
  5102. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5103. if (fdw.Length > 0) lw.Add(fdw);
  5104. string devdate1 = GetPostString("deliverydate1");
  5105. string devdate2 = GetPostString("deliverydate2");
  5106. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5107. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5108. string price1 = GetPostString("price1");
  5109. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5110. string price2 = GetPostString("price2");
  5111. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5112. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5113. {
  5114. if (tid.Length > 0)
  5115. {
  5116. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5117. if (tid.Length > 5)
  5118. {
  5119. List<string> tids = getTidByCtidLike(tid);
  5120. if (tids.Count > 0 && tids.Count < 10)
  5121. {
  5122. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5123. }
  5124. }
  5125. lw.Add(tid_sql);
  5126. }
  5127. if (buyernick.Length > 0)
  5128. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5129. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5130. if (dw.Length > 0) lw.Add(dw);
  5131. }
  5132. else
  5133. {
  5134. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  5135. }
  5136. string posTag = CurrentUser.UserPost.Post.Code;
  5137. if (posTag == "Supplier")
  5138. {
  5139. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5140. }
  5141. else
  5142. {
  5143. string supplier = GetPostString("supplier");
  5144. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5145. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  5146. {
  5147. string usershop = CurrentUser.User.pemShop;
  5148. lw.Add(string.Format("ShopId in ({0})", usershop));
  5149. }
  5150. }
  5151. lw.Add(string.Format(" OrderState IN (7, 8)"));
  5152. lw.Add(string.Format("type != 'PDD' "));
  5153. lw.Add(string.Format("IsRefund!={0}", 2));
  5154. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5155. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5156. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5157. /*if (tid.Length > 0)
  5158. {
  5159. List<string> tids = new List<string>();
  5160. if (dt != null && dt.Rows.Count > 0)
  5161. {
  5162. foreach (DataRow item in dt.Rows)
  5163. {
  5164. tids.Add("'" + item["tid"] + "'");
  5165. }
  5166. }
  5167. if (tids.Count > 0)
  5168. {
  5169. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5170. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5171. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5172. dt = WebCache.GetData("view_erptradecell", dStruct);
  5173. }
  5174. }*/
  5175. if (dt != null)
  5176. {
  5177. foreach (DataRow dr in dt.Rows)
  5178. {
  5179. 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();
  5180. }
  5181. }
  5182. writeGridDataTableJson(dStruct.TotalCount, dt);
  5183. }
  5184. public void get_erp_pdddeliveryed()
  5185. {
  5186. DataStruct dStruct = GetPostStruct();
  5187. List<string> lw = new List<string>();
  5188. string tid = GetPostString("ctid");
  5189. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5190. string shopname = GetPostString("shopname");
  5191. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5192. string buyernick = GetPostString("buyer_nick");
  5193. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5194. string customer = GetPostString("customer");
  5195. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5196. string design = GetPostString("design");
  5197. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5198. string sellermemo = GetPostString("seller_memo");
  5199. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5200. string logistics = GetPostString("logistics");
  5201. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5202. string date1 = GetPostString("date1");
  5203. string date2 = GetPostString("date2");
  5204. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5205. //if (dw.Length > 0) lw.Add(dw);
  5206. string placedate1 = GetPostString("placedate1");
  5207. string placedate2 = GetPostString("placedate2");
  5208. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5209. if (fdw.Length > 0) lw.Add(fdw);
  5210. string devdate1 = GetPostString("deliverydate1");
  5211. string devdate2 = GetPostString("deliverydate2");
  5212. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5213. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5214. string price1 = GetPostString("price1");
  5215. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5216. string price2 = GetPostString("price2");
  5217. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5218. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5219. {
  5220. if (tid.Length > 0)
  5221. {
  5222. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5223. if (tid.Length > 5)
  5224. {
  5225. List<string> tids = getTidByCtidLike(tid);
  5226. if (tids.Count > 0 && tids.Count < 10)
  5227. {
  5228. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5229. }
  5230. }
  5231. lw.Add(tid_sql);
  5232. }
  5233. if (buyernick.Length > 0)
  5234. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5235. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5236. if (dw.Length > 0) lw.Add(dw);
  5237. }
  5238. else
  5239. {
  5240. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5241. }
  5242. string posTag = CurrentUser.UserPost.Post.Code;
  5243. if (posTag == "Supplier")
  5244. {
  5245. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5246. }
  5247. else
  5248. {
  5249. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  5250. {
  5251. string usershop = CurrentUser.User.pemShop;
  5252. lw.Add(string.Format("ShopId in ({0})", usershop));
  5253. }
  5254. string supplier = GetPostString("supplier");
  5255. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5256. }
  5257. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5258. lw.Add(string.Format("type = 'PDD' "));
  5259. lw.Add(string.Format("IsRefund!={0}", 2));
  5260. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5261. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5262. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5263. /* if (tid.Length > 0)
  5264. {
  5265. List<string> tids = new List<string>();
  5266. if (dt != null && dt.Rows.Count > 0)
  5267. {
  5268. foreach (DataRow item in dt.Rows)
  5269. {
  5270. tids.Add("'" + item["tid"] + "'");
  5271. }
  5272. }
  5273. if (tids.Count > 0)
  5274. {
  5275. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5276. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5277. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5278. dt = WebCache.GetData("view_erptradecell", dStruct);
  5279. }
  5280. }*/
  5281. foreach (DataRow dr in dt.Rows)
  5282. {
  5283. 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();
  5284. }
  5285. writeGridDataTableJson(dStruct.TotalCount, dt);
  5286. }
  5287. public void get_erp_jddeliveryed()
  5288. {
  5289. DataStruct dStruct = GetPostStruct();
  5290. List<string> lw = new List<string>();
  5291. string tid = GetPostString("ctid");
  5292. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5293. string shopname = GetPostString("shopname");
  5294. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5295. string buyernick = GetPostString("buyer_nick");
  5296. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5297. string customer = GetPostString("customer");
  5298. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5299. string design = GetPostString("design");
  5300. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5301. string sellermemo = GetPostString("seller_memo");
  5302. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5303. string date1 = GetPostString("date1");
  5304. string date2 = GetPostString("date2");
  5305. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5306. //if (dw.Length > 0) lw.Add(dw);
  5307. string placedate1 = GetPostString("placedate1");
  5308. string placedate2 = GetPostString("placedate2");
  5309. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5310. if (fdw.Length > 0) lw.Add(fdw);
  5311. string devdate1 = GetPostString("deliverydate1");
  5312. string devdate2 = GetPostString("deliverydate2");
  5313. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5314. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5315. string price1 = GetPostString("price1");
  5316. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5317. string price2 = GetPostString("price2");
  5318. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5319. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5320. {
  5321. if (tid.Length > 0)
  5322. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5323. if (buyernick.Length > 0)
  5324. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5325. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5326. if (dw.Length > 0) lw.Add(dw);
  5327. }
  5328. else
  5329. {
  5330. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5331. }
  5332. string posTag = CurrentUser.UserPost.Post.Code;
  5333. if (posTag == "Supplier")
  5334. {
  5335. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5336. }
  5337. else
  5338. {
  5339. string supplier = GetPostString("supplier");
  5340. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5341. }
  5342. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5343. lw.Add(string.Format("type = 'JD' "));
  5344. lw.Add(string.Format("IsRefund!={0}", 2));
  5345. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5346. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5347. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5348. foreach (DataRow dr in dt.Rows)
  5349. {
  5350. 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();
  5351. }
  5352. writeGridDataTableJson(dStruct.TotalCount, dt);
  5353. }
  5354. public void get_erp_allplacelist()
  5355. {
  5356. DataStruct dStruct = GetPostStruct();
  5357. List<string> lw = new List<string>();
  5358. string tid = GetPostString("ctid");
  5359. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5360. string shopname = GetPostString("shopname");
  5361. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5362. string buyernick = GetPostString("buyer_nick");
  5363. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5364. string customer = GetPostString("customer");
  5365. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5366. string design = GetPostString("design");
  5367. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5368. string sellermemo = GetPostString("seller_memo");
  5369. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5370. string supplier = GetPostString("supplier");
  5371. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5372. string date1 = GetPostString("date1");
  5373. string date2 = GetPostString("date2");
  5374. string pldate1 = GetPostString("placedate1");
  5375. string pldate2 = GetPostString("placedate2");
  5376. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5377. //if (dw.Length > 0) lw.Add(dw);
  5378. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5379. {
  5380. if (tid.Length > 0)
  5381. {
  5382. string select_tid = getTidByCtid(tid);
  5383. lw.Add(string.Format("tid='{0}'", select_tid));
  5384. }
  5385. if (buyernick.Length > 0)
  5386. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5387. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5388. if (dw.Length > 0) lw.Add(dw);
  5389. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5390. if (dw_place.Length > 0) lw.Add(dw_place);
  5391. }
  5392. else
  5393. {
  5394. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5395. {
  5396. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5397. }
  5398. }
  5399. string price1 = GetPostString("price1");
  5400. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5401. string price2 = GetPostString("price2");
  5402. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5403. string posTag = CurrentUser.UserPost.Post.Code;
  5404. if (posTag == "Supplier")
  5405. {
  5406. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5407. }
  5408. lw.Add(string.Format("OrderState >= 6"));
  5409. lw.Add(string.Format("IsSample != 2 "));
  5410. //lw.Add(string.Format("isDianziOrder = 0 "));
  5411. lw.Add(string.Format("SupplierId > 0 "));
  5412. //lw.Add(string.Format("IsRefund<={0}", 1));
  5413. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5414. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5415. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5416. foreach (DataRow dr in dt.Rows)
  5417. {
  5418. 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();
  5419. }
  5420. writeGridDataTableJson(dStruct.TotalCount, dt);
  5421. }
  5422. public void get_erp_financeallplacelist()
  5423. {
  5424. DataStruct dStruct = GetPostStruct();
  5425. List<string> lw = new List<string>();
  5426. string tid = GetPostString("ctid");
  5427. string shopname = GetPostString("shopname");
  5428. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5429. string buyernick = GetPostString("buyer_nick");
  5430. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5431. string customer = GetPostString("customer");
  5432. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5433. string design = GetPostString("design");
  5434. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5435. string sellermemo = GetPostString("seller_memo");
  5436. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5437. string supplier = GetPostString("supplier");
  5438. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5439. string date1 = GetPostString("date1");
  5440. string date2 = GetPostString("date2");
  5441. string pldate1 = GetPostString("placedate1");
  5442. string pldate2 = GetPostString("placedate2");
  5443. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5444. {
  5445. if (tid.Length > 0)
  5446. {
  5447. string select_tid = getTidByCtid(tid);
  5448. lw.Add(string.Format("tid='{0}'", select_tid));
  5449. }
  5450. if (buyernick.Length > 0)
  5451. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5452. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5453. if (dw.Length > 0) lw.Add(dw);
  5454. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5455. if (dw_place.Length > 0) lw.Add(dw_place);
  5456. }
  5457. else
  5458. {
  5459. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5460. {
  5461. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5462. }
  5463. }
  5464. string price1 = GetPostString("price1");
  5465. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5466. string price2 = GetPostString("price2");
  5467. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5468. string posTag = CurrentUser.UserPost.Post.Code;
  5469. if (posTag == "Supplier")
  5470. {
  5471. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5472. }
  5473. //lw.Add(string.Format("OrderState >= 6"));
  5474. lw.Add(string.Format("IsSample != 2 "));
  5475. lw.Add(string.Format("isDianziOrder = 0 "));
  5476. //lw.Add(string.Format("IsRefund<={0}", 1));
  5477. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5478. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5479. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5480. foreach (DataRow dr in dt.Rows)
  5481. {
  5482. 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();
  5483. }
  5484. writeGridDataTableJson(dStruct.TotalCount, dt);
  5485. }
  5486. public void get_erp_expresslist()
  5487. {
  5488. int listtype = GetInt("ltype");
  5489. DataStruct dStruct = GetPostStruct();
  5490. List<string> lw = new List<string>();
  5491. string tid = GetPostString("tid");
  5492. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5493. string outsid = GetPostString("out_sid");
  5494. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5495. string importer = GetPostString("ImportUserName");
  5496. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5497. string file = GetPostString("import_file");
  5498. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5499. string printman = GetPostString("printman");
  5500. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5501. string date1 = GetPostString("date1");
  5502. string date2 = GetPostString("date2");
  5503. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5504. if (dw.Length > 0) lw.Add(dw);
  5505. string fdate1 = GetPostString("finishdate1");
  5506. string fdate2 = GetPostString("finishdate2");
  5507. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5508. if (fdw.Length > 0) lw.Add(fdw);
  5509. string supplierId = GetPostString("supplierId");
  5510. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5511. if (listtype == 1)
  5512. {
  5513. lw.Add(string.Format("importUserId !=0"));
  5514. }
  5515. string posTag = CurrentUser.UserPost.Post.Code;
  5516. if (posTag == "Supplier")
  5517. {
  5518. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5519. }
  5520. if (dStruct.PageSize != 100000)
  5521. {
  5522. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5523. }
  5524. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5525. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5526. writeGridDataTableJson(dStruct.TotalCount, dt);
  5527. }
  5528. public void set_erp_buchaorderdelivery()
  5529. {
  5530. if (UrlPostParmsCheck("ctid"))
  5531. {
  5532. string eid = GetPostString("ctid");
  5533. CeErpTradeCell entity = null;
  5534. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5535. if (entity != null)
  5536. {
  5537. if (entity.IsSample != 2)
  5538. {
  5539. returnErrorMsg("补差价单才能标记为已发货");
  5540. return;
  5541. }
  5542. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5543. entity.OrderState = 7;
  5544. entity.Update();
  5545. returnSuccessMsg("操作成功!");
  5546. return;
  5547. }
  5548. returnErrorMsg("找不到记录");
  5549. }
  5550. }
  5551. public void get_stdtemplates()
  5552. {
  5553. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5554. //string res = taobaoHelper.test();
  5555. string res = apiHelper.API_PrintTemplate();
  5556. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5557. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5558. {
  5559. int sidx = res.IndexOf("error_code");
  5560. int eidx = res.IndexOf("success");
  5561. string msg = res.Substring(sidx, eidx - sidx);
  5562. returnErrorMsg(msg);
  5563. return;
  5564. }
  5565. if (res.Length <= 0)
  5566. {
  5567. returnErrorMsg("模板数据为空!");
  5568. return;
  5569. }
  5570. ReturnSuccess(res);
  5571. }
  5572. public void cancel_print_order()
  5573. {
  5574. if (UrlPostParmsCheck("ctid"))
  5575. {
  5576. string ctid = GetPostString("ctid");
  5577. CeErpTradeCell entity = null;
  5578. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5579. if (entity != null)
  5580. {
  5581. string res = "";
  5582. string code = entity.LastBillWaybillCode;
  5583. if (code == "")
  5584. {
  5585. code = entity.OutSid;
  5586. }
  5587. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5588. XLog.SaveLog(0, "取消面单" + res);
  5589. }
  5590. }
  5591. }
  5592. public void set_erp_printwaybill()
  5593. {
  5594. if (UrlPostParmsCheck("ctid"))
  5595. {
  5596. string ctid = GetPostString("ctid");
  5597. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5598. string cpName = GetPostString("cpname");
  5599. string isTogether = GetPostString("together");
  5600. string printType = GetPostString("printType");
  5601. //var res_obj = new
  5602. //{
  5603. // restype = 1,
  5604. // 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\"}"
  5605. //};
  5606. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5607. //ReturnSuccess(ro_json);
  5608. //return;
  5609. bool isUseLastWayBillCode = false;
  5610. CeErpTradeCell entity = null;
  5611. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5612. if (entity != null)
  5613. {
  5614. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5615. {
  5616. isUseLastWayBillCode = true;
  5617. }
  5618. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5619. {
  5620. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5621. return;
  5622. }
  5623. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5624. {
  5625. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5626. return;
  5627. }
  5628. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5629. {
  5630. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5631. return;
  5632. }
  5633. }
  5634. string res = "";
  5635. Api_waybill_code_response_Obj fullObj = null;
  5636. string pData_str = "";
  5637. string curUseWayBillCode = "";
  5638. if (isUseLastWayBillCode == false)
  5639. {
  5640. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5641. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5642. if (res.IndexOf("failure") != -1)
  5643. {
  5644. //int idx = res.IndexOf("sub_message");
  5645. //int idx2 = res.IndexOf("flag");
  5646. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5647. string errMsgNeed = commonHelper.KeepChinese(res);
  5648. var res_objd = new
  5649. {
  5650. restype = 0,
  5651. data = "获取面单失败" + errMsgNeed
  5652. };
  5653. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5654. returnSuccess(ro_jsond);
  5655. if (res.IndexOf("停发") != -1)
  5656. {
  5657. entity.UnusualCon = "物流停发";
  5658. entity.Update();
  5659. }
  5660. //returnErrorMsg("获取面单失败,"+emsg);
  5661. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5662. return;
  5663. }
  5664. else if (res.IndexOf("errorMsg") != -1)
  5665. {
  5666. //int idx = res.IndexOf("errorMsg");
  5667. //int idx2 = res.IndexOf("}]}");
  5668. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5669. string errMsgNeed = commonHelper.KeepChinese(res);
  5670. var res_objf = new
  5671. {
  5672. restype = 0,
  5673. data = "获取面单失败2" + errMsgNeed
  5674. };
  5675. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5676. if (res.IndexOf("停发") != -1)
  5677. {
  5678. entity.UnusualCon = "物流停发";
  5679. entity.Update();
  5680. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5681. if (trade != null)
  5682. {
  5683. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5684. }
  5685. }
  5686. returnSuccess(ro_jsonf);
  5687. //returnErrorMsg("获取面单失败," + emsg);
  5688. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5689. return;
  5690. }
  5691. try
  5692. {
  5693. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5694. //res = res.Replace(" ", "");
  5695. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5696. }
  5697. catch (Exception ex)
  5698. {
  5699. XLog.SaveLog(0, "生成fullObj" + res);
  5700. var res_objf = new
  5701. {
  5702. restype = 0,
  5703. data = "生成fullObj发生错误" + ex.Message
  5704. };
  5705. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5706. returnSuccess(ro_jsonf);
  5707. return;
  5708. }
  5709. if (fullObj.response.data.content.Count > 0)
  5710. {
  5711. ContentItem codeObj = fullObj.response.data.content[0];
  5712. if (cpCode.IndexOf("SFFQ-") != -1)
  5713. {
  5714. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5715. }
  5716. else
  5717. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5718. curUseWayBillCode = codeObj.waybillCode;
  5719. }
  5720. else
  5721. {
  5722. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5723. var res_objf = new
  5724. {
  5725. restype = 0,
  5726. data = "生成fullObj找不到快递单号waybillCode"
  5727. };
  5728. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5729. returnSuccess(ro_jsonf);
  5730. return;
  5731. }
  5732. }
  5733. else
  5734. {
  5735. //使用上次打印的快递单号
  5736. if (cpCode == "SFFQ-LY")
  5737. {
  5738. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5739. }
  5740. else
  5741. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5742. curUseWayBillCode = entity.LastBillWaybillCode;
  5743. }
  5744. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5745. {
  5746. var res_obje = new
  5747. {
  5748. restype = 0,
  5749. data = "获取加密打印数据失败"
  5750. };
  5751. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5752. returnSuccess(ro_jsone);
  5753. entity.LastBillCpCode = cpCode;
  5754. entity.LastBillWaybillCode = curUseWayBillCode;
  5755. entity.Update();
  5756. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5757. //returnErrorMsg("获取加密打印数据失败");
  5758. return;
  5759. }
  5760. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5761. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5762. string btnType = "";
  5763. string errorMsg = "";
  5764. if (entity != null)
  5765. {
  5766. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5767. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5768. //cpcode是 YTO-CAINIAO
  5769. //string comCode = cpCode.Split('-')[0].ToString();
  5770. string apires = "";
  5771. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5772. //isTogether=2是新的合包弹窗
  5773. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5774. {
  5775. if (ctid.IndexOf("N") != -1)
  5776. {
  5777. apires = "发货成功";
  5778. }
  5779. else
  5780. {
  5781. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode, entity.ctid);
  5782. }
  5783. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5784. //打单后发货
  5785. StringBuilder sql = new StringBuilder();
  5786. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5787. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5788. {
  5789. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5790. }
  5791. else
  5792. {
  5793. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5794. }
  5795. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5796. foreach (DataRow row in dt.Rows)
  5797. {
  5798. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5799. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5800. {
  5801. try
  5802. {
  5803. btnType = "待发货";
  5804. entity.OutSid = curUseWayBillCode;
  5805. entity.OrderState = 7;
  5806. entity.IsUrgency = false;
  5807. entity.LastBillCpCode = "";
  5808. entity.LastBillWaybillCode = "";
  5809. entity.FinishDeliveryTime = DateTime.Now;
  5810. entity.IsReturn = 0;
  5811. entity.MemoOpt = 0;
  5812. entity.UpdateTime = DateTime.Now;
  5813. entity.Update();
  5814. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5815. //还要插入快递信息到 快递信息表
  5816. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5817. exinfo.tid = entity.ctid;
  5818. exinfo.out_sid = curUseWayBillCode;
  5819. exinfo.company_code = cpCode;
  5820. exinfo.company_name = cpName;
  5821. exinfo.supplierUserName = supplierName;
  5822. exinfo.deliveryType = "发货成功";
  5823. exinfo.print_time = DateTime.Now;
  5824. exinfo.printUser = CurrentUser.UserName;
  5825. exinfo.postData = pData_str;
  5826. exinfo.Create();
  5827. commonHelper.UpdateRelationOrder(entity.ctid);
  5828. CeErpSukuraData.createInfo(ctid, 4);
  5829. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5830. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126 || entity.SupplierId == 96)
  5831. {
  5832. commonHelper.sendCytExpress(exinfo);
  5833. }
  5834. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5835. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5836. }
  5837. catch (Exception ex)
  5838. {
  5839. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5840. }
  5841. }
  5842. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5843. {
  5844. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5845. if (entity.OrderState == 6)
  5846. {
  5847. entity.OrderState = 7;
  5848. }
  5849. entity.UpdateTime = DateTime.Now;
  5850. entity.FinishDeliveryTime = DateTime.Now;
  5851. btnType = "已发货";
  5852. entity.Update();
  5853. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5854. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5855. exinfo.tid = entity.ctid;
  5856. exinfo.out_sid = curUseWayBillCode;
  5857. exinfo.company_code = cpCode;
  5858. exinfo.company_name = cpName;
  5859. exinfo.supplierUserName = supplierName;
  5860. exinfo.deliveryType = "发货成功";
  5861. exinfo.print_time = DateTime.Now;
  5862. exinfo.printUser = CurrentUser.UserName;
  5863. exinfo.postData = pData_str;
  5864. exinfo.Create();
  5865. commonHelper.UpdateRelationOrder(entity.ctid);
  5866. CeErpSukuraData.createInfo(entity.ctid, 4);
  5867. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126 || entity.SupplierId == 96)
  5868. {
  5869. commonHelper.sendCytExpress(exinfo);
  5870. }
  5871. //不处理
  5872. }
  5873. else
  5874. {
  5875. entity.UpdateTime = DateTime.Now;
  5876. entity.LastBillCpCode = cpCode;
  5877. entity.LastBillWaybillCode = curUseWayBillCode;
  5878. entity.Update();
  5879. string errmsg = commonHelper.KeepChinese(apires);
  5880. var res_objz = new
  5881. {
  5882. restype = 0,
  5883. data = "打单后发货失败"
  5884. };
  5885. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5886. returnSuccess(ro_jsonz);
  5887. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5888. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5889. return;
  5890. }
  5891. }
  5892. }
  5893. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5894. {
  5895. string ctids = GetPostString("ctids");
  5896. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5897. List<string> list = new List<string>();
  5898. List<string> send_list = new List<string>();
  5899. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5900. CeErpTrade ceErpTrade = new CeErpTrade();
  5901. //可合包的合并一起发货
  5902. if (dt == null && string.IsNullOrEmpty(ctids))
  5903. {
  5904. var res_objz = new
  5905. {
  5906. restype = 0,
  5907. data = "打单后发货失败"
  5908. };
  5909. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5910. returnSuccess(ro_jsonz);
  5911. return;
  5912. }
  5913. if (!string.IsNullOrEmpty(ctids))
  5914. {
  5915. StringBuilder sql = new StringBuilder();
  5916. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5917. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5918. }
  5919. foreach (DataRow row in dt.Rows)
  5920. {
  5921. list.Add("'" + row["ctid"] + "'");
  5922. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5923. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5924. if (ctid.IndexOf("N") != -1)
  5925. {
  5926. apires = "发货成功";
  5927. }
  5928. else
  5929. {
  5930. if (!send_list.Contains(ceErpTrade.tid))
  5931. {
  5932. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode, ctid);
  5933. }
  5934. else
  5935. {
  5936. apires = "发货成功";
  5937. }
  5938. }
  5939. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5940. {
  5941. send_list.Add(ceErpTrade.tid);
  5942. try
  5943. {
  5944. btnType = "待发货";
  5945. ceErpTradeCell.OutSid = curUseWayBillCode;
  5946. ceErpTradeCell.OrderState = 7;
  5947. ceErpTradeCell.IsUrgency = false;
  5948. ceErpTradeCell.LastBillCpCode = "";
  5949. ceErpTradeCell.LastBillWaybillCode = "";
  5950. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5951. ceErpTradeCell.IsReturn = 0;
  5952. ceErpTradeCell.MemoOpt = 0;
  5953. ceErpTradeCell.UpdateTime = DateTime.Now;
  5954. ceErpTradeCell.Update();
  5955. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5956. //还要插入快递信息到 快递信息表
  5957. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5958. exinfo.tid = ceErpTradeCell.ctid;
  5959. exinfo.out_sid = curUseWayBillCode;
  5960. exinfo.company_code = cpCode;
  5961. exinfo.company_name = cpName;
  5962. exinfo.supplierUserName = supplierName;
  5963. exinfo.deliveryType = "发货成功";
  5964. exinfo.print_time = DateTime.Now;
  5965. exinfo.printUser = CurrentUser.UserName;
  5966. exinfo.postData = pData_str;
  5967. exinfo.Create();
  5968. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5969. CeErpSukuraData.createInfo(ctid, 4);
  5970. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5971. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80 || entity.SupplierId == 126 || entity.SupplierId == 96)
  5972. {
  5973. commonHelper.sendCytExpress(exinfo);
  5974. }
  5975. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5976. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5977. }
  5978. catch (Exception ex)
  5979. {
  5980. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5981. }
  5982. }
  5983. else
  5984. {
  5985. ceErpTradeCell.UpdateTime = DateTime.Now;
  5986. ceErpTradeCell.LastBillCpCode = cpCode;
  5987. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5988. ceErpTradeCell.Update();
  5989. string errmsg = commonHelper.KeepChinese(apires);
  5990. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5991. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5992. }
  5993. }
  5994. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5995. }
  5996. }
  5997. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5998. var res_obj = new
  5999. {
  6000. restype = 1,
  6001. data = pData_str,
  6002. errorMsg
  6003. };
  6004. string ro_json = JsonConvert.SerializeObject(res_obj);
  6005. ReturnSuccess(ro_json);
  6006. return;
  6007. }
  6008. }
  6009. private string GetUTF8String(byte[] vs)
  6010. {
  6011. throw new NotImplementedException();
  6012. }
  6013. public void set_erp_printwaybill_cn()
  6014. {
  6015. if (UrlPostParmsCheck("ctid"))
  6016. {
  6017. string ctid = GetPostString("ctid");
  6018. string cpCode = GetPostString("cpcode");
  6019. string cpName = GetPostString("cpname");
  6020. string tempUrl = GetPostString("tempurl");
  6021. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  6022. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  6023. //string res = taobaoHelper.test();
  6024. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  6025. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  6026. {
  6027. int sidx = res.IndexOf("errorMsg");
  6028. int eidx = res.IndexOf("}");
  6029. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  6030. var res_objzxx = new
  6031. {
  6032. restype = 0,
  6033. data = msg
  6034. };
  6035. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  6036. returnSuccess(ro_jsonzxx);
  6037. //returnErrorMsg(msg);
  6038. return;
  6039. }
  6040. int idx = res.IndexOf("waybillCode");
  6041. int idx2 = res.IndexOf("printData");
  6042. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  6043. string eid = GetPostString("ctid");
  6044. CeErpTradeCell entity = null;
  6045. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6046. if (entity != null)
  6047. {
  6048. string osid = entity.OutSid;
  6049. entity.OutSid = osid + "," + outsid;
  6050. entity.FinishDeliveryTime = DateTime.Now;
  6051. entity.OrderState = 7;
  6052. entity.UpdateTime = DateTime.Now;
  6053. entity.IsReturn = 0;
  6054. entity.Update();
  6055. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  6056. exinfo.tid = entity.ctid;
  6057. exinfo.out_sid = outsid;
  6058. exinfo.company_code = cpCode;
  6059. exinfo.company_name = cpName;
  6060. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  6061. exinfo.deliveryType = "发货成功";
  6062. exinfo.print_time = DateTime.Now;
  6063. exinfo.printUser = CurrentUser.UserName;
  6064. exinfo.Create();
  6065. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126 || entity.SupplierId == 96)
  6066. {
  6067. commonHelper.sendCytExpress(exinfo);
  6068. }
  6069. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  6070. }
  6071. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  6072. var res_objz = new
  6073. {
  6074. restype = 1,
  6075. data = res
  6076. };
  6077. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  6078. returnSuccess(ro_jsonz);
  6079. //ReturnSuccess(res);
  6080. }
  6081. }
  6082. ////打单,打印面单 获取面单号
  6083. //public void set_erp_printwaybill()
  6084. //{
  6085. // if (UrlPostParmsCheck("ctid"))
  6086. // {
  6087. // string ctid = GetPostString("ctid");
  6088. // string cpCode = GetPostString("cpcode");
  6089. // string tempUrl = GetPostString("tempurl");
  6090. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  6091. // //string res = taobaoHelper.test();
  6092. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  6093. // if (res.IndexOf("error_response") != -1)
  6094. // {
  6095. // int sidx = res.IndexOf("sub_msg");
  6096. // int eidx = res.IndexOf("request_id");
  6097. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  6098. // returnErrorMsg(msg);
  6099. // return;
  6100. // }
  6101. // int idx = res.IndexOf("waybill_code");
  6102. // int idx2 = res.IndexOf("}]}");
  6103. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  6104. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  6105. // ReturnSuccess(res);
  6106. // }
  6107. //}
  6108. public void cancel_erp_aftersale()
  6109. {
  6110. if (UrlPostParmsCheck("ctid"))
  6111. {
  6112. string eid = GetPostString("ctid");
  6113. CeErpTradeCell entity = null;
  6114. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6115. if (entity != null)
  6116. {
  6117. //有过处理的售后,取消也不能删除 售 字,保留
  6118. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  6119. {
  6120. entity.AfterSaleState = 4;
  6121. }
  6122. else
  6123. entity.AfterSaleState = 0;
  6124. entity.UpdateTime = DateTime.Now;
  6125. entity.Update();
  6126. returnSuccessMsg("操作成功!");
  6127. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  6128. return;
  6129. }
  6130. returnErrorMsg("找不到订单记录");
  6131. }
  6132. }
  6133. public void get_erp_aftersalelist()
  6134. {
  6135. DataStruct dStruct = GetPostStruct();
  6136. List<string> lw = new List<string>();
  6137. int st = GetInt("st");
  6138. string tid = GetPostString("ctid");
  6139. if (st == 3)
  6140. {
  6141. if (tid.Length > 0)
  6142. {
  6143. string select_tid = getTidByCtid(tid);
  6144. lw.Add(string.Format("tid='{0}'", select_tid));
  6145. }
  6146. }
  6147. else
  6148. {
  6149. if (tid.Length > 0)
  6150. {
  6151. string select_tid = getTidByCtid(tid);
  6152. lw.Add(string.Format("tid='{0}'", select_tid));
  6153. }
  6154. }
  6155. string shopname = GetPostString("shopname");
  6156. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6157. string buyernick = GetPostString("buyer_nick");
  6158. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  6159. string sellermemo = GetPostString("seller_memo");
  6160. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6161. string orderState = GetPostString("orderState");
  6162. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  6163. string afterState = GetPostString("afterstate");
  6164. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6165. string date1 = GetPostString("date1");
  6166. string date2 = GetPostString("date2");
  6167. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6168. if (dw.Length > 0) lw.Add(dw);
  6169. string price1 = GetPostString("price1");
  6170. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6171. string price2 = GetPostString("price2");
  6172. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6173. //lw.Add(string.Format("IsRefund!={0}", 1));
  6174. string reason = GetPostString("reason");
  6175. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6176. string method = GetPostString("method");
  6177. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6178. string handler = GetPostString("handler");
  6179. if (handler.Length > 0)
  6180. {
  6181. lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6182. }
  6183. string handledate1 = GetPostString("handledate1");
  6184. string handledate2 = GetPostString("handledate2");
  6185. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6186. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6187. string finish1 = GetPostString("finishdate1");
  6188. string finish2 = GetPostString("finishdate2");
  6189. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6190. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6191. string afterdate1 = GetPostString("afterdate1");
  6192. string afterdate2 = GetPostString("afterdate2");
  6193. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6194. if (afterDate.Length > 0) lw.Add(afterDate);
  6195. string supplier = GetPostString("supplier");
  6196. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6197. string responsible = GetPostString("responsibleman");
  6198. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6199. string customer = GetPostString("customer");
  6200. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6201. string design = GetPostString("design");
  6202. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6203. string afterMemoType = GetPostString("aftermemotype");
  6204. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6205. string posCode = CurrentUser.UserPost.Post.Code;
  6206. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6207. //{
  6208. // string vstate = GetPostString("vstate");
  6209. // if (vstate.Length > 0)
  6210. // {
  6211. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6212. // }
  6213. // if (posCode == "Supplier")
  6214. // {
  6215. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6216. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6217. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6218. // }
  6219. // else
  6220. // {
  6221. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6222. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6223. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6224. // {
  6225. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6226. // }
  6227. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6228. // {
  6229. // int orgid = CurrentUser.UserPost.OrgID;
  6230. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6231. // }
  6232. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6233. // {
  6234. // string shopid = CurrentUser.User.pemShop;
  6235. // lw.Add(string.Format("shopId in ({0})", shopid));
  6236. // }
  6237. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6238. // //{
  6239. // // int org_id = CurrentUser.UserPost.OrgID;
  6240. // // lw.Add(string.Format("OrgID={0}", org_id));
  6241. // //}
  6242. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6243. // }
  6244. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6245. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6246. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6247. //}
  6248. if (st == 5)
  6249. {
  6250. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6251. {
  6252. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6253. {
  6254. string shopid = CurrentUser.User.pemShop;
  6255. lw.Add(string.Format("shopId in ({0})", shopid));
  6256. }
  6257. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6258. {
  6259. int mrOrgid = CurrentUser.UserPost.OrgID;
  6260. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6261. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6262. }
  6263. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6264. //{
  6265. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6266. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6267. //}
  6268. else
  6269. {
  6270. string userIdStr = "";
  6271. if (posCode == "CustomerService")
  6272. {
  6273. userIdStr = CurrentUser.UserID + "_k";
  6274. }
  6275. else if (posCode == "Designer" || posCode == "wxDesigner")
  6276. {
  6277. userIdStr = CurrentUser.UserID + "_s";
  6278. }
  6279. else if (posCode == "Place")
  6280. {
  6281. userIdStr = CurrentUser.UserID + "_x";
  6282. }
  6283. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6284. }
  6285. }
  6286. string placedate1 = GetPostString("placedate1");
  6287. string placedate2 = GetPostString("placedate2");
  6288. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6289. if (dwplace.Length > 0) lw.Add(dwplace);
  6290. string supState = GetPostString("supState");
  6291. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6292. string searchType = GetPostString("searchType");
  6293. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6294. {
  6295. lw.Add(string.Format("BackNum>1"));
  6296. }
  6297. lw.Add(string.Format("AfterSaleState>0"));
  6298. if (ex_psize > 0)
  6299. {
  6300. if (CurrentUser.UserPost.Post.Code == "Finance")
  6301. dStruct.Order = "pay_time desc";
  6302. else
  6303. dStruct.Order = "HandleTime desc";
  6304. }
  6305. else
  6306. dStruct.Order = "HandleTime desc";
  6307. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6308. DataTable dt = WebCache.GetData("view_test", dStruct);
  6309. writeGridDataTableJson(dStruct.TotalCount, dt);
  6310. }
  6311. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6312. //{
  6313. // lw.Add(string.Format("AfterSaleState=4"));
  6314. // string code = CurrentUser.UserPost.Post.Code;
  6315. // if (code == "CustomerService")
  6316. // {
  6317. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6318. // }
  6319. // else if (code == "Designer" || code == "DesignerMr")
  6320. // {
  6321. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6322. // }
  6323. // else if (code == "Place" || code == "PlaceMr")
  6324. // {
  6325. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6326. // }
  6327. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6328. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6329. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6330. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6331. //}
  6332. //else //处理中的售后,待处理和处理中合并
  6333. //{
  6334. // if (afterState.Length <= 0)
  6335. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6336. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6337. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6338. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6339. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6340. //}
  6341. }
  6342. public void get_erp_disagreeftersalelist()
  6343. {
  6344. DataStruct dStruct = GetPostStruct();
  6345. List<string> lw = new List<string>();
  6346. int st = 2;
  6347. string tid = GetPostString("ctid");
  6348. if (tid.Length > 0)
  6349. {
  6350. string select_tid = getTidByCtid(tid);
  6351. lw.Add(string.Format("tid='{0}'", select_tid));
  6352. }
  6353. string shopname = GetPostString("shopname");
  6354. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6355. string buyernick = GetPostString("buyer_nick");
  6356. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6357. string sellermemo = GetPostString("seller_memo");
  6358. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6359. string orderState = GetPostString("orderState");
  6360. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6361. string afterState = GetPostString("afterstate");
  6362. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6363. string date1 = GetPostString("date1");
  6364. string date2 = GetPostString("date2");
  6365. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6366. if (dw.Length > 0) lw.Add(dw);
  6367. string price1 = GetPostString("price1");
  6368. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6369. string price2 = GetPostString("price2");
  6370. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6371. //lw.Add(string.Format("IsRefund!={0}", 1));
  6372. string reason = GetPostString("reason");
  6373. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6374. string method = GetPostString("method");
  6375. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6376. string handler = GetPostString("handler");
  6377. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6378. string handledate1 = GetPostString("handledate1");
  6379. string handledate2 = GetPostString("handledate2");
  6380. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6381. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6382. string afterdate1 = GetPostString("afterdate1");
  6383. string afterdate2 = GetPostString("afterdate2");
  6384. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6385. if (afterDate.Length > 0) lw.Add(afterDate);
  6386. string backdate1 = GetPostString("backdate1");
  6387. string backdate2 = GetPostString("backdate2");
  6388. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6389. if (backDate.Length > 0) lw.Add(backDate);
  6390. string supplier = GetPostString("supplier");
  6391. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6392. string responsible = GetPostString("responsibleman");
  6393. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6394. string customer = GetPostString("customer");
  6395. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6396. string design = GetPostString("design");
  6397. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6398. string afterSaleMemo = GetPostString("afterSaleMemo");
  6399. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6400. string afterMemoType = GetPostString("aftermemotype");
  6401. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6402. string aftersakereason = GetPostString("aftersakereason");
  6403. if (aftersakereason.Length > 0)
  6404. {
  6405. if (aftersakereason == "1")
  6406. {
  6407. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6408. }
  6409. if (aftersakereason == "2")
  6410. {
  6411. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6412. }
  6413. }
  6414. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6415. string poscode = CurrentUser.UserPost.Post.Code;
  6416. if (poscode != "SysAdmin")
  6417. {
  6418. string shopid = CurrentUser.User.pemShop;
  6419. lw.Add(string.Format("shopId in ({0})", shopid));
  6420. }
  6421. string searchType = GetPostString("searchType");
  6422. if (searchType == "wait")
  6423. {
  6424. lw.Add(string.Format("HandleTime is null"));
  6425. }
  6426. if (searchType == "handling")
  6427. {
  6428. lw.Add(string.Format("HandleTime is not null "));
  6429. }
  6430. if (searchType == "back" || searchType == "puBack")
  6431. {
  6432. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6433. }
  6434. if (searchType == "reBack")
  6435. {
  6436. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6437. }
  6438. if (searchType == "moreBack")
  6439. {
  6440. lw.Add(string.Format("backNum > 1"));
  6441. }
  6442. lw.Add(string.Format("(AfterSaleState=5)"));
  6443. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6444. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6445. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6446. writeGridDataTableJson(dStruct.TotalCount, dt);
  6447. }
  6448. public void get_erp_handlingaftersalelist()
  6449. {
  6450. DataStruct dStruct = GetPostStruct();
  6451. List<string> lw = new List<string>();
  6452. int st = 2;
  6453. string tid = GetPostString("ctid");
  6454. if (tid.Length > 0)
  6455. {
  6456. string select_tid = getTidByCtid(tid);
  6457. lw.Add(string.Format("tid='{0}'", select_tid));
  6458. }
  6459. string shopname = GetPostString("shopname");
  6460. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6461. string buyernick = GetPostString("buyer_nick");
  6462. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6463. string sellermemo = GetPostString("seller_memo");
  6464. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6465. string orderState = GetPostString("orderState");
  6466. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6467. string searchType = GetPostString("searchType");
  6468. string afterState = GetPostString("afterstate");
  6469. if (searchType != "documentary")
  6470. {
  6471. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6472. }
  6473. string date1 = GetPostString("date1");
  6474. string date2 = GetPostString("date2");
  6475. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6476. if (dw.Length > 0) lw.Add(dw);
  6477. string price1 = GetPostString("price1");
  6478. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6479. string price2 = GetPostString("price2");
  6480. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6481. //lw.Add(string.Format("IsRefund!={0}", 1));
  6482. string reason = GetPostString("reason");
  6483. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6484. string method = GetPostString("method");
  6485. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6486. string handler = GetPostString("handler");
  6487. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6488. string handledate1 = GetPostString("handledate1");
  6489. string handledate2 = GetPostString("handledate2");
  6490. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6491. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6492. string afterdate1 = GetPostString("afterdate1");
  6493. string afterdate2 = GetPostString("afterdate2");
  6494. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6495. if (afterDate.Length > 0) lw.Add(afterDate);
  6496. string supplier = GetPostString("supplier");
  6497. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6498. string responsible = GetPostString("responsibleman");
  6499. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6500. string customer = GetPostString("customer");
  6501. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6502. string design = GetPostString("design");
  6503. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6504. string afterSaleMemo = GetPostString("afterSaleMemo");
  6505. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6506. string afterMemoType = GetPostString("aftermemotype");
  6507. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6508. string afterresult = GetPostString("afterresult");
  6509. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6510. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6511. string poscode = CurrentUser.UserPost.Post.Code;
  6512. if (poscode != "SysAdmin")
  6513. {
  6514. string shopid = CurrentUser.User.pemShop;
  6515. lw.Add(string.Format("shopId in ({0})", shopid));
  6516. }
  6517. if (searchType == "wait")
  6518. {
  6519. lw.Add(string.Format("HandleTime is null"));
  6520. }
  6521. if (searchType == "documentary")
  6522. {
  6523. lw.Add(string.Format(" AfterSaleState > 2 AND HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' AND AfterSalSend = 0 "));
  6524. afterState = "2";
  6525. }
  6526. if (searchType == "handling")
  6527. {
  6528. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6529. }
  6530. if (searchType == "back" || searchType == "puBack")
  6531. {
  6532. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6533. }
  6534. if (searchType == "reBack")
  6535. {
  6536. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6537. }
  6538. if (afterState.Length <= 0)
  6539. {
  6540. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6541. }
  6542. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6543. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6544. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6545. writeGridDataTableJson(dStruct.TotalCount, dt);
  6546. }
  6547. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6548. //public void get_erp_back_handlingaftersalelist()
  6549. //{
  6550. // DataStruct dStruct = GetPostStruct();
  6551. // List<string> lw = new List<string>();
  6552. // string tid = GetPostString("ctid");
  6553. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6554. // string shopname = GetPostString("shopname");
  6555. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6556. // string buyernick = GetPostString("buyer_nick");
  6557. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6558. // string sellermemo = GetPostString("seller_memo");
  6559. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6560. // string orderState = GetPostString("orderState");
  6561. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6562. // string afterState = GetPostString("afterstate");
  6563. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6564. // string date1 = GetPostString("date1");
  6565. // string date2 = GetPostString("date2");
  6566. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6567. // if (dw.Length > 0) lw.Add(dw);
  6568. // string price1 = GetPostString("price1");
  6569. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6570. // string price2 = GetPostString("price2");
  6571. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6572. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6573. // string reason = GetPostString("reason");
  6574. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6575. // string method = GetPostString("method");
  6576. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6577. // string handler = GetPostString("handler");
  6578. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6579. // string handledate1 = GetPostString("handledate1");
  6580. // string handledate2 = GetPostString("handledate2");
  6581. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6582. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6583. // string afterdate1 = GetPostString("afterdate1");
  6584. // string afterdate2 = GetPostString("afterdate2");
  6585. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6586. // if (afterDate.Length > 0) lw.Add(afterDate);
  6587. // string supplier = GetPostString("supplier");
  6588. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6589. // string responsible = GetPostString("responsibleman");
  6590. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6591. // string customer = GetPostString("customer");
  6592. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6593. // string design = GetPostString("design");
  6594. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6595. // string afterMemoType = GetPostString("aftermemotype");
  6596. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6597. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6598. // if (afterState.Length <= 0)
  6599. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6600. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6601. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6602. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6603. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6604. //}
  6605. public void get_erp_aftersaleverifylist()
  6606. {
  6607. DataStruct dStruct = GetPostStruct();
  6608. List<string> lw = new List<string>();
  6609. string tid = GetPostString("ctid");
  6610. if (tid.Length > 0)
  6611. {
  6612. string select_tid = getTidByCtid(tid);
  6613. lw.Add(string.Format("otid='{0}'", select_tid));
  6614. }
  6615. string shopname = GetPostString("shopname");
  6616. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6617. string buyernick = GetPostString("buyer_nick");
  6618. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6619. string sellermemo = GetPostString("seller_memo");
  6620. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6621. string orderState = GetPostString("orderState");
  6622. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6623. //lw.Add(string.Format("IsRefund!={0}", 1));
  6624. string reason = GetPostString("reason");
  6625. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6626. string method = GetPostString("method");
  6627. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6628. string handler = GetPostString("handler");
  6629. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6630. string handledate1 = GetPostString("handledate1");
  6631. string handledate2 = GetPostString("handledate2");
  6632. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6633. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6634. string finish1 = GetPostString("finishdate1");
  6635. string finish2 = GetPostString("finishdate2");
  6636. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6637. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6638. string supplier = GetPostString("supplier");
  6639. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6640. string responsible = GetPostString("responsibleman");
  6641. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6642. string posCode = CurrentUser.UserPost.Post.Code;
  6643. string vstate = GetPostString("vstate");
  6644. if (vstate.Length > 0)
  6645. {
  6646. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6647. }
  6648. if (posCode == "Supplier")
  6649. {
  6650. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6651. lw.Add(string.Format("VerifyState = 0"));
  6652. lw.Add("type = 1");
  6653. lw.Add(string.Format("AfterSaleState={0}", 3));
  6654. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6655. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6656. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6657. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6658. writeGridDataTableJson(dStruct.TotalCount, dt);
  6659. }
  6660. else if (posCode == "logistics")
  6661. {
  6662. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6663. lw.Add(string.Format("VerifyState = 0"));
  6664. lw.Add("type = 2");
  6665. lw.Add(string.Format("AfterSaleState={0}", 3));
  6666. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6667. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6668. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6669. writeGridDataTableJson(dStruct.TotalCount, dt);
  6670. }
  6671. else
  6672. {
  6673. lw.Add(string.Format("(AfterSaleState = 3)"));
  6674. lw.Add("type = 0");
  6675. string reasonState = GetPostString("reasonState");
  6676. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "Summarize" || posCode == "Finance")
  6677. {
  6678. if (reasonState == "2")
  6679. {
  6680. lw.Add("VerifyState = 3");
  6681. }
  6682. else if (reasonState == "1")
  6683. {
  6684. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6685. }
  6686. else
  6687. {
  6688. lw.Add("VerifyState in (0,3)");
  6689. }
  6690. //不加条件,可以看全部
  6691. }
  6692. 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")
  6693. {
  6694. int orgid = CurrentUser.UserPost.OrgID;
  6695. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6696. if (string.IsNullOrEmpty(manageOrgId))
  6697. {
  6698. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6699. }
  6700. else
  6701. {
  6702. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6703. }
  6704. if (reasonState == "1")
  6705. {
  6706. lw.Add("VerifyState = 3");
  6707. }
  6708. else if (reasonState == "2")
  6709. {
  6710. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6711. }
  6712. else
  6713. {
  6714. }
  6715. }
  6716. else
  6717. {
  6718. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6719. }
  6720. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6721. //{
  6722. // int org_id = CurrentUser.UserPost.OrgID;
  6723. // lw.Add(string.Format("OrgID={0}", org_id));
  6724. //}
  6725. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6726. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6727. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6728. writeGridDataTableJson(dStruct.TotalCount, dt);
  6729. }
  6730. }
  6731. public void get_erp_finishaftersalelist()
  6732. {
  6733. DataStruct dStruct = GetPostStruct();
  6734. List<string> lw = new List<string>();
  6735. int st = 4;
  6736. string tid = GetPostString("ctid");
  6737. if (tid.Length > 0)
  6738. {
  6739. string select_tid = getTidByCtid(tid);
  6740. lw.Add(string.Format("otid='{0}'", select_tid));
  6741. }
  6742. string shopname = GetPostString("shopname");
  6743. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6744. //lw.Add(string.Format("IsRefund!={0}", 1));
  6745. string reason = GetPostString("reason");
  6746. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6747. string method = GetPostString("method");
  6748. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6749. string buyernick = GetPostString("buyer_nick");
  6750. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6751. string handler = GetPostString("handler");
  6752. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6753. string handledate1 = GetPostString("handledate1");
  6754. string handledate2 = GetPostString("handledate2");
  6755. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6756. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6757. string finish1 = GetPostString("finishdate1");
  6758. string finish2 = GetPostString("finishdate2");
  6759. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6760. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6761. string supplier = GetPostString("supplier");
  6762. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6763. string responsible = GetPostString("responsibleman");
  6764. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6765. string vstate = GetPostString("vstate");
  6766. if (vstate.Length > 0)
  6767. {
  6768. if ("3".Equals(vstate))
  6769. {
  6770. lw.Add(string.Format("IsTem=1"));
  6771. }
  6772. else
  6773. {
  6774. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6775. }
  6776. }
  6777. lw.Add(string.Format("AfterSaleState=4"));
  6778. string code = CurrentUser.UserPost.Post.Code;
  6779. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6780. {
  6781. //不加条件,可以看全部
  6782. }
  6783. else if (code == "Supplier")
  6784. {
  6785. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6786. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6787. lw.Add("type = 1");
  6788. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6789. }
  6790. else if (code == "logistics")
  6791. {
  6792. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6793. lw.Add("type = 2");
  6794. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6795. }
  6796. 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")
  6797. {
  6798. lw.Add("type = 0");
  6799. int orgid = CurrentUser.UserPost.OrgID;
  6800. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6801. if (string.IsNullOrEmpty(manageOrgIds))
  6802. {
  6803. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6804. }
  6805. else
  6806. {
  6807. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6808. }
  6809. }
  6810. else
  6811. {
  6812. lw.Add("type = 0");
  6813. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6814. }
  6815. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6816. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6817. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6818. writeGridDataTableJson(dStruct.TotalCount, dt);
  6819. }
  6820. public void handle_erp_aftersale()
  6821. {
  6822. if (UrlPostParmsCheck("ctid"))
  6823. {
  6824. string eid = GetPostString("ctid");
  6825. string responStr = GetPostString("AfterSaleResponsible");
  6826. if (responStr.Length <= 0)
  6827. {
  6828. returnErrorMsg("售后责任人不能为空");
  6829. return;
  6830. }
  6831. bool isDesign = false;
  6832. double designFree = 0.00;
  6833. int responsibleId = 0;
  6834. CeErpTradeCell entity = null;
  6835. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6836. if (entity != null)
  6837. {
  6838. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6839. string afterMethod = GetPostString("AfterSaleMethod");
  6840. if (isNeedNewOrder == 1)
  6841. {
  6842. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6843. bool ishav = true;
  6844. if (newentity == null)
  6845. {
  6846. newentity = entity.Clone() as CeErpTradeCell;
  6847. ishav = false;
  6848. newentity.ctid = "S_" + entity.ctid;
  6849. newentity.OrderState = 0;
  6850. //唯一标识
  6851. newentity.OrderSn = newentity.ctid;
  6852. string orderSn = commonHelper.generateDateTimeRandomNos();
  6853. if (orderSn != "")
  6854. {
  6855. newentity.OrderSn = orderSn;
  6856. }
  6857. }
  6858. newentity.UpdateTime = DateTime.Now;
  6859. newentity.AfterSaleState = 0;
  6860. newentity.AfterSaleMethod = afterMethod;
  6861. if (!ishav)
  6862. {
  6863. string memo_str = newentity.seller_memo;
  6864. memo_str = memo_str.Replace("(", "(");
  6865. memo_str = memo_str.Replace(")", ")");
  6866. int sIndex = memo_str.IndexOf("(");
  6867. int eIndex = memo_str.IndexOf(")");
  6868. if (sIndex == -1 || eIndex == -1)
  6869. {
  6870. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6871. return;
  6872. }
  6873. string first = memo_str.Substring(0, sIndex + 1);
  6874. string memoCtid = newentity.OrderSn;
  6875. //if (memoCtid.IndexOf("C") != -1)
  6876. //{
  6877. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6878. //if (CIdx.IndexOf("+") != -1)
  6879. //{
  6880. //CIdx = "C" + CIdx.Split('+')[1];
  6881. //}
  6882. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6883. //}
  6884. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6885. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6886. string newMemo = first + memoCtid + last;
  6887. newentity.seller_memo = newMemo;
  6888. newentity.FinishPlaceTime = null;
  6889. newentity.UnusualTag = 0;
  6890. newentity.UnusualCon = "";
  6891. newentity.UnusualTime = null;
  6892. newentity.AfterSaleMemo = "";
  6893. newentity.AfterSaleMethod = afterMethod;
  6894. newentity.AfterSalePreTime = null;
  6895. newentity.AfterSaleReason = "";
  6896. newentity.AfterSaleResponsible = "";
  6897. newentity.AfterSaleState = 0;
  6898. newentity.AfterSaleTime = null;
  6899. newentity.AfterSaleUserId = 0;
  6900. newentity.AfterSaleSupplierState = 0;
  6901. newentity.LastBillWaybillCode = "";
  6902. newentity.LastBillCpCode = "";
  6903. newentity.FinishAfterSaleTime = null;
  6904. newentity.HandleTime = null;
  6905. newentity.IsSF = 0;
  6906. newentity.IsOldCustomer = 0;
  6907. newentity.UrgencyTime = null;
  6908. newentity.ResponsibleUserId = "";
  6909. newentity.IsVerifyToSupplier = false;
  6910. newentity.payment = 0;
  6911. newentity.CheckMemo = "";
  6912. newentity.OutSid = "";
  6913. newentity.CheckOrderTime = null;
  6914. newentity.MemoOpt = 0;
  6915. newentity.IsReturn = 0;
  6916. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6917. }
  6918. newentity.isAfterSaleOrder = 1;
  6919. newentity.IsRefund = 0;
  6920. string receiveMobile = GetPostString("receiver_mobile");
  6921. if (receiveMobile.Length > 0)
  6922. {
  6923. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6924. if (trade != null)
  6925. {
  6926. trade.receiver_name = GetPostString("receiver_name");
  6927. trade.receiver_mobile = receiveMobile;
  6928. trade.receiver_state = GetPostString("receiver_state");
  6929. trade.receiver_city = GetPostString("receiver_city");
  6930. trade.receiver_district = GetPostString("receiver_district");
  6931. trade.receiver_address = GetPostString("receiver_address");
  6932. newentity.IsOffLineOrder = 1;
  6933. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6934. }
  6935. }
  6936. string st = GetPostString("ToState");
  6937. if (st.Length > 0)
  6938. {
  6939. if (newentity.OrderState <= 3)
  6940. {
  6941. newentity.WaitDesignTime = DateTime.Now;
  6942. newentity.StartDesignTime = null;
  6943. newentity.FinishDesignTime = null;
  6944. newentity.OrderState = 3;
  6945. if (st == "下单员")
  6946. {
  6947. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6948. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6949. {
  6950. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6951. }
  6952. }
  6953. else
  6954. {
  6955. newentity.WaitDesignTime = DateTime.Now;
  6956. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6957. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6958. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6959. {
  6960. DataRow user = dt1.Rows[0];
  6961. //找主管
  6962. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6963. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6964. if (dt != null && dt.Rows.Count > 0)
  6965. {
  6966. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6967. newentity.DesignUserId = designMr;
  6968. string key = "aftersale_order_" + designMr;
  6969. if (RedisHelper.HasKey(key))
  6970. {
  6971. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6972. list.Add(newentity.ctid);
  6973. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6974. }
  6975. }
  6976. //账号正常
  6977. if (user["State"].ToString() == "0")
  6978. {
  6979. newentity.DesignUserId = entity.DesignUserId;
  6980. string key = "aftersale_order_" + entity.DesignUserId;
  6981. if (RedisHelper.HasKey(key))
  6982. {
  6983. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6984. list.Add(newentity.ctid);
  6985. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6986. }
  6987. }
  6988. }
  6989. }
  6990. }
  6991. if (entity.IsXianHuo == 1)
  6992. {
  6993. newentity.OrderState = 6;
  6994. entity.FinishPlaceTime = DateTime.Now;
  6995. }
  6996. }
  6997. if (ishav)
  6998. {
  6999. newentity.Update();
  7000. }
  7001. else
  7002. {
  7003. newentity.Create();
  7004. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  7005. newCellExtend.ctid = newentity.ctid;
  7006. newCellExtend.orderFrom = 20;
  7007. newCellExtend.orderType = 30;
  7008. if (st == "下单员")
  7009. {
  7010. }
  7011. else
  7012. {
  7013. newCellExtend.ReprintTime = DateTime.Now;
  7014. }
  7015. newCellExtend.Create();
  7016. }
  7017. if (st != "下单员")
  7018. {
  7019. if (entity.DispatchSort == 2)
  7020. {
  7021. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  7022. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  7023. }
  7024. }
  7025. }
  7026. //处理售后扩展
  7027. string resIdStr = GetPostString("ResponsibleUserId");
  7028. string refundFees = GetPostString("refundFrees");
  7029. int IsComplain = GetPostInt("isComplain");
  7030. int IsBad = GetPostInt("isBad");
  7031. string IsOriginal = GetPostString("isOriginal");
  7032. double diffResultPrice = GetPostDouble("diffResultPrice");
  7033. string textResult = GetPostString("textResult");
  7034. string supplierResponsible = GetPostString("supplierResponsible");
  7035. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  7036. if (ceErpTradeAfterSaleExtend == null)
  7037. {
  7038. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7039. ceErpTradeAfterSaleExtend.tid = eid;
  7040. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  7041. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  7042. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  7043. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  7044. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  7045. ceErpTradeAfterSaleExtend.TextResult = textResult;
  7046. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  7047. ceErpTradeAfterSaleExtend.Create();
  7048. }
  7049. else
  7050. {
  7051. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  7052. {
  7053. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  7054. }
  7055. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  7056. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  7057. ceErpTradeAfterSaleExtend.TextResult = textResult;
  7058. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  7059. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  7060. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  7061. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  7062. ceErpTradeAfterSaleExtend.Update();
  7063. }
  7064. int gysid = GetPostInt("ResponsibleSupId");
  7065. if (entity.AfterSaleUserId == 0)
  7066. {
  7067. entity.AfterSaleUserId = CurrentUser.UserID;
  7068. }
  7069. entity.ResponsibleUserId = resIdStr;
  7070. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  7071. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  7072. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  7073. {
  7074. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7075. int backNum = 0;
  7076. if (number != null)
  7077. {
  7078. backNum = number.BackNum;
  7079. }
  7080. char[] separator = { ',' };
  7081. string[] sArray = resIdStr.Split(separator);
  7082. string[] refundFreeList = { };
  7083. if (refundFees.Length > 0)
  7084. {
  7085. refundFreeList = refundFees.Split(separator);
  7086. }
  7087. int index = -1;
  7088. List<int> responsibleIds = new List<int>();
  7089. foreach (string i in sArray)
  7090. {
  7091. index++;
  7092. if (i.Length <= 0) continue;
  7093. char[] separator2 = { '_' };
  7094. string idstr = i.Split(separator2)[0];
  7095. string idtype = i.Split(separator2)[1];
  7096. double refudFree = 0;
  7097. if (refundFreeList.Length > 0)
  7098. {
  7099. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  7100. }
  7101. if (idtype == "s")
  7102. {
  7103. isDesign = true;
  7104. designFree = refudFree;
  7105. }
  7106. int userId = Convert.ToInt32(idstr);
  7107. int type = 0;
  7108. if (idtype == "g")
  7109. {
  7110. type = 1;
  7111. }
  7112. if (idtype == "w")
  7113. {
  7114. type = 2;
  7115. }
  7116. if (idtype == "t")
  7117. {
  7118. type = 3;
  7119. }
  7120. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  7121. if (ceErpTradeResponsible == null)
  7122. {
  7123. ceErpTradeResponsible = new CeErpTradeResponsible();
  7124. ceErpTradeResponsible.tid = eid;
  7125. ceErpTradeResponsible.UserId = userId;
  7126. ceErpTradeResponsible.createdTime = DateTime.Now;
  7127. ceErpTradeResponsible.type = type;
  7128. if (type == 1)
  7129. {
  7130. ceErpTradeResponsible.IsSup = 1;
  7131. }
  7132. if (type == 2)
  7133. {
  7134. ceErpTradeResponsible.IsFlow = 1;
  7135. }
  7136. }
  7137. int state = 0;
  7138. //已认可的不需要再次认可
  7139. if (sArray.Length > 1 && ceErpTradeResponsible.VerifyState == 1)
  7140. {
  7141. state = 1;
  7142. }
  7143. ceErpTradeResponsible.RefundFee = refudFree;
  7144. ceErpTradeResponsible.VerifyState = state;
  7145. if (userId == 2125 || idtype == "w")
  7146. {
  7147. ceErpTradeResponsible.VerifyState = 1;
  7148. }
  7149. if (idtype == "w" && userId == 101)
  7150. {
  7151. ceErpTradeResponsible.VerifyState = state;
  7152. }
  7153. if (ceErpTradeResponsible.ID > 0)
  7154. {
  7155. ceErpTradeResponsible.Update();
  7156. }
  7157. else
  7158. {
  7159. ceErpTradeResponsible.Create();
  7160. }
  7161. if (isDesign)
  7162. {
  7163. responsibleId = ceErpTradeResponsible.ID;
  7164. }
  7165. responsibleIds.Add(ceErpTradeResponsible.ID);
  7166. }
  7167. CeErpTradeResponsible.ExecuteNonQuery(string.Format("update CE_ErpTradeResponsible set VerifyState =-1 where tid='" + eid + "' and ID NOT IN (" + string.Join(",", responsibleIds) + ")"));
  7168. CeErpTradeResponsible.NumByTid(backNum, eid);
  7169. }
  7170. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  7171. if (ceErpTradeCellExtend != null)
  7172. {
  7173. ceErpTradeCellExtend.returnVisit = 0;
  7174. ceErpTradeCellExtend.Update();
  7175. }
  7176. if (entity.HandleTime != null)
  7177. {
  7178. if (entity.AfterSaleState == 1)
  7179. {
  7180. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  7181. }
  7182. else
  7183. {
  7184. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  7185. }
  7186. }
  7187. else
  7188. {
  7189. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  7190. entity.HandleTime = DateTime.Now;
  7191. }
  7192. bool isCompale = false;
  7193. if (entity.AfterSaleState == 5)
  7194. {
  7195. isCompale = true;
  7196. entity.AfterSaleState = 3;
  7197. }
  7198. entity.AfterSaleSupplierState = 0;
  7199. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7200. {
  7201. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7202. }
  7203. string sImgs = GetPostString("img");
  7204. entity.AfterSaleSupplierImg = sImgs;
  7205. entity.supRefundType = GetPostString("supRefundType");
  7206. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7207. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7208. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7209. entity.AfterSaleMemoType = GetPostString("MemoType");
  7210. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7211. {
  7212. //entity.AfterSaleSupplierState = 2;
  7213. }
  7214. string df = GetPostString("DeductFee");
  7215. if (df == "")
  7216. {
  7217. df = "0";
  7218. }
  7219. string rf = GetPostString("RefundFee");
  7220. if (rf == "")
  7221. {
  7222. rf = "0";
  7223. }
  7224. string pm = GetPostString("AfterSalePayment");
  7225. if (pm == "")
  7226. {
  7227. pm = "0";
  7228. }
  7229. entity.AfterSalePayment = Convert.ToDouble(pm);
  7230. entity.DeductFee = Convert.ToDouble(df);
  7231. entity.RefundFee = Convert.ToDouble(rf);
  7232. entity.UpdateTime = DateTime.Now;
  7233. entity.Update();
  7234. string toState = GetPostString("ToState");
  7235. string original = GetPostString("isOriginal");
  7236. ApiVo apiVo = new ApiVo();
  7237. apiVo.orderNumber = entity.ctid;
  7238. apiVo.actionName = "afterDesign";
  7239. apiVo.orderRemarks = entity.AfterSaleMethod;
  7240. apiVo.reasonRemarks = entity.AfterSaleReason;
  7241. apiVo.isDesign = isDesign;
  7242. apiVo.designFree = designFree;
  7243. apiVo.responsibleId = responsibleId;
  7244. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7245. if (toState == "设计师")
  7246. {
  7247. apiVo.isOriginal = Convert.ToBoolean(original);
  7248. }
  7249. designHelper.API_WorkCore(apiVo);//afterDesign
  7250. CeErpMethod methodSql = new CeErpMethod();
  7251. methodSql.con = entity.AfterSaleMethod;
  7252. methodSql.addTime = DateTime.Now;
  7253. methodSql.Create();
  7254. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7255. CeErpMethod.ExecuteNonQuery(delsql);
  7256. if (isCompale)
  7257. {
  7258. aftersale_data_change(entity.ctid);
  7259. }
  7260. returnSuccessMsg("操作成功!");
  7261. return;
  7262. }
  7263. returnErrorMsg("找不到订单记录");
  7264. }
  7265. }
  7266. public void ins_erp_toresponsible()
  7267. {
  7268. if (UrlPostParmsCheck("ctid"))
  7269. {
  7270. string eid = GetPostString("ctid");
  7271. CeErpTradeCell entity = null;
  7272. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7273. if (entity != null)
  7274. {
  7275. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7276. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7277. {
  7278. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7279. return;
  7280. }
  7281. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7282. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7283. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7284. if (entity.AfterSalePreTime == null)
  7285. {
  7286. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7287. {
  7288. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7289. }
  7290. }
  7291. entity.AfterSalePreTime = DateTime.Now;
  7292. //预完成给售后主管审核客户问题直接完成
  7293. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7294. {
  7295. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7296. {
  7297. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7298. }
  7299. }
  7300. ceErpTradeAfterSaleExtend.DisagreeTime = null;
  7301. ceErpTradeAfterSaleExtend.Update();
  7302. entity.AfterSaleUserId = CurrentUser.UserID;
  7303. entity.AfterSaleState = 2;
  7304. entity.UpdateTime = DateTime.Now;
  7305. entity.Update();
  7306. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7307. aftersale_data_change(entity.ctid);
  7308. returnSuccessMsg("操作成功!");
  7309. return;
  7310. }
  7311. returnErrorMsg("找不到订单记录");
  7312. }
  7313. }
  7314. public void cancel_erp_aftersaleanddelnew()
  7315. {
  7316. if (UrlPostParmsCheck("ctid"))
  7317. {
  7318. string eid = GetPostString("ctid");
  7319. CeErpTradeCell entity = null;
  7320. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7321. if (entity != null)
  7322. {
  7323. entity.AfterSaleState = 0;
  7324. entity.AfterSaleReason = "";
  7325. entity.AfterSaleMethod = "";
  7326. entity.AfterSaleMemo = "";
  7327. entity.AfterSaleResponsible = "";
  7328. entity.ResponsibleUserId = "";
  7329. entity.DeductFee = 0;
  7330. entity.RefundFee = 0;
  7331. entity.IsArbitrate = 0;
  7332. CeErpTradeResponsible.DelByTid(eid, -1);
  7333. entity.Update();
  7334. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7335. if (after != null)
  7336. {
  7337. if (after.OrderState < 5)
  7338. CeErpTradeCell.DelByCtid("S_" + eid);
  7339. }
  7340. returnSuccessMsg("操作成功!");
  7341. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7342. return;
  7343. }
  7344. returnErrorMsg("找不到订单记录");
  7345. }
  7346. }
  7347. public void get_erp_aftersale_pregather()
  7348. {
  7349. List<string> lw = new List<string>();
  7350. int st = GetInt("st");
  7351. string tid = GetPostString("ctid");
  7352. if (tid.Length > 0)
  7353. {
  7354. string select_tid = getTidByCtid(tid);
  7355. lw.Add(string.Format("tid='{0}'", select_tid));
  7356. }
  7357. string shopname = GetPostString("shopname");
  7358. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7359. string buyernick = GetPostString("buyer_nick");
  7360. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7361. string sellermemo = GetPostString("seller_memo");
  7362. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7363. string orderState = GetPostString("orderState");
  7364. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7365. string reason = GetPostString("reason");
  7366. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7367. string method = GetPostString("method");
  7368. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7369. string handler = GetPostString("handler");
  7370. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7371. string handledate1 = GetPostString("handledate1");
  7372. string handledate2 = GetPostString("handledate2");
  7373. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7374. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7375. string supplier = GetPostString("supplier");
  7376. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7377. string responsible = GetPostString("responsibleman");
  7378. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7379. string customer = GetPostString("customer");
  7380. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7381. string design = GetPostString("design");
  7382. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7383. string afterMemoType = GetPostString("aftermemotype");
  7384. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7385. string afterSaleMemo = GetPostString("afterSaleMemo");
  7386. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7387. string afterresult = GetPostString("afterresult");
  7388. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7389. string poscode = CurrentUser.UserPost.Post.Code;
  7390. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7391. {
  7392. string shopid = CurrentUser.User.pemShop;
  7393. lw.Add(string.Format("shopId in ({0})", shopid));
  7394. }
  7395. var mainwhere = string.Join(" and ", lw.ToArray());
  7396. string ro_json = "";
  7397. string type = GetPostString("gather_type");
  7398. int number = 0;
  7399. if (poscode == "AfterSale")
  7400. {
  7401. //处理中
  7402. if (type == "Handling")
  7403. {
  7404. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7405. DataTable dt = null;
  7406. try
  7407. {
  7408. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7409. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7410. }
  7411. catch (Exception e)
  7412. {
  7413. dt = new DataTable();
  7414. }
  7415. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7416. return;
  7417. }
  7418. if (type == "Wait")
  7419. {
  7420. //待处理
  7421. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7422. DataTable dt1 = null;
  7423. try
  7424. {
  7425. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7426. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7427. }
  7428. catch (Exception e)
  7429. {
  7430. dt1 = new DataTable();
  7431. }
  7432. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7433. return;
  7434. }
  7435. if (type == "back")
  7436. {
  7437. //打回
  7438. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7439. DataTable dt2 = null;
  7440. try
  7441. {
  7442. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7443. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7444. }
  7445. catch (Exception e)
  7446. {
  7447. dt2 = new DataTable();
  7448. }
  7449. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7450. return;
  7451. }
  7452. if (type == "preCompletion")
  7453. {
  7454. //预完成
  7455. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7456. DataTable dt3 = null;
  7457. try
  7458. {
  7459. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7460. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7461. }
  7462. catch (Exception e)
  7463. {
  7464. dt3 = new DataTable();
  7465. }
  7466. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7467. return;
  7468. }
  7469. if (type == "documentary")
  7470. {
  7471. //跟单中
  7472. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate > 2 and HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSalSend = 0 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7473. DataTable dt4 = null;
  7474. try
  7475. {
  7476. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7477. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7478. }
  7479. catch (Exception e)
  7480. {
  7481. dt4 = new DataTable();
  7482. }
  7483. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7484. return;
  7485. }
  7486. if (type == "reBack")
  7487. {
  7488. //被打回
  7489. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7490. DataTable dt1 = null;
  7491. try
  7492. {
  7493. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7494. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7495. }
  7496. catch (Exception e)
  7497. {
  7498. dt1 = new DataTable();
  7499. }
  7500. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7501. return;
  7502. }
  7503. }
  7504. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7505. {
  7506. if (type == "puBack")
  7507. {
  7508. //退回
  7509. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7510. DataTable dt = null;
  7511. try
  7512. {
  7513. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7514. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7515. }
  7516. catch (Exception e)
  7517. {
  7518. dt = new DataTable();
  7519. }
  7520. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7521. return;
  7522. }
  7523. if (type == "reBack")
  7524. {
  7525. //打回
  7526. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7527. DataTable dt1 = null;
  7528. try
  7529. {
  7530. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7531. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7532. }
  7533. catch (Exception e)
  7534. {
  7535. dt1 = new DataTable();
  7536. }
  7537. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7538. return;
  7539. }
  7540. if (type == "examEd")
  7541. {
  7542. //已审核
  7543. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7544. DataTable dt2 = null;
  7545. try
  7546. {
  7547. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7548. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7549. }
  7550. catch (Exception e)
  7551. {
  7552. dt2 = new DataTable();
  7553. }
  7554. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7555. return;
  7556. }
  7557. if (type == "waitExam")
  7558. {
  7559. //待审核
  7560. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7561. DataTable dt3 = null;
  7562. try
  7563. {
  7564. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7565. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7566. }
  7567. catch (Exception e)
  7568. {
  7569. dt3 = new DataTable();
  7570. }
  7571. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7572. return;
  7573. }
  7574. if (type == "Handling")
  7575. {
  7576. //处理中
  7577. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7578. DataTable dt4 = null;
  7579. try
  7580. {
  7581. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7582. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7583. }
  7584. catch (Exception e)
  7585. {
  7586. dt4 = new DataTable();
  7587. }
  7588. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7589. return;
  7590. }
  7591. if (type == "Wait")
  7592. {
  7593. //待处理
  7594. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7595. DataTable dt5 = null;
  7596. try
  7597. {
  7598. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7599. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7600. }
  7601. catch (Exception e)
  7602. {
  7603. dt5 = new DataTable();
  7604. }
  7605. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7606. return;
  7607. }
  7608. if (type == "documentary")
  7609. {
  7610. //跟单中
  7611. string sql6 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate > 2 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSalSend = 0 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7612. DataTable dt6 = null;
  7613. try
  7614. {
  7615. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7616. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7617. }
  7618. catch (Exception e)
  7619. {
  7620. dt6 = new DataTable();
  7621. }
  7622. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7623. return;
  7624. }
  7625. }
  7626. returnSuccess(ro_json);
  7627. }
  7628. public void end_erp_aftersale()
  7629. {
  7630. if (UrlPostParmsCheck("ctid"))
  7631. {
  7632. string eid = GetPostString("ctid");
  7633. CeErpTradeCell entity = null;
  7634. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7635. if (entity != null)
  7636. {
  7637. string stype = GetPostString("stype");
  7638. string typeStr = stype;
  7639. entity.AfterSaleState = 4;
  7640. entity.FinishAfterSaleTime = DateTime.Now;
  7641. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7642. entity.Update();
  7643. ApiVo apiVo = new ApiVo();
  7644. apiVo.orderNumber = entity.ctid;
  7645. apiVo.actionName = "afterOver";
  7646. designHelper.API_WorkCore(apiVo); //afterOver
  7647. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7648. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7649. CeErpSukuraData.createInfo(entity.ctid, 8);
  7650. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7651. returnSuccessMsg("操作成功!");
  7652. return;
  7653. }
  7654. returnErrorMsg("找不到订单记录");
  7655. }
  7656. }
  7657. public void ins_erp_finishaftersale()
  7658. {
  7659. if (UrlPostParmsCheck("id"))
  7660. {
  7661. string eid = GetPostString("id");
  7662. CeErpTradeResponsible entity = null;
  7663. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7664. if (entity != null)
  7665. {
  7666. entity.VerifyState = 1;
  7667. entity.VerifyTime = DateTime.Now;
  7668. entity.Update();
  7669. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7670. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7671. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7672. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7673. if (dt.Rows.Count <= 0)
  7674. {
  7675. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7676. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7677. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7678. CeErpSukuraData.createInfo(entity.tid, 8);
  7679. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7680. {
  7681. CeErpDesignerBill.Del(entity.tid);
  7682. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7683. }
  7684. }
  7685. returnSuccessMsg("操作成功!");
  7686. return;
  7687. }
  7688. returnErrorMsg("找不到订单记录");
  7689. }
  7690. }
  7691. public void upd_erp_arbitrateaftersale()
  7692. {
  7693. if (UrlPostParmsCheck("id"))
  7694. {
  7695. string eid = GetPostString("id");
  7696. CeErpTradeResponsible entity = null;
  7697. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7698. if (entity != null)
  7699. {
  7700. entity.IsArbitrate = 1;
  7701. entity.ArbitradeMemo = GetPostString("reason");
  7702. entity.VerifyState = 2;
  7703. entity.Update();
  7704. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7705. if (tradecell != null)
  7706. {
  7707. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7708. tradecell.IsArbitrate = 1;
  7709. tradecell.Update();
  7710. }
  7711. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7712. returnSuccessMsg("操作成功!");
  7713. return;
  7714. }
  7715. returnErrorMsg("找不到订单记录");
  7716. }
  7717. }
  7718. public void upd_erp_backaftersale()
  7719. {
  7720. if (UrlPostParmsCheck("tid"))
  7721. {
  7722. string eid = GetPostString("tid");
  7723. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7724. int backNum = 0;
  7725. if (number != null)
  7726. {
  7727. backNum = number.BackNum;
  7728. }
  7729. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7730. CeErpTradeCell entity = null;
  7731. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7732. if (entity != null)
  7733. {
  7734. entity.AfterSaleBackReason = GetPostString("backreason");
  7735. entity.AfterSaleState = 1;
  7736. entity.AfterSaleSupplierState = 0;
  7737. entity.UpdateTime = DateTime.Now;
  7738. entity.Update();
  7739. returnSuccessMsg("操作成功!");
  7740. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7741. return;
  7742. }
  7743. returnErrorMsg("找不到订单记录");
  7744. }
  7745. }
  7746. public void get_erp_supplieraftersalelist()
  7747. {
  7748. DataStruct dStruct = GetPostStruct();
  7749. List<string> lw = new List<string>();
  7750. string tid = GetPostString("ctid");
  7751. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7752. string shopname = GetPostString("shopname");
  7753. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7754. string buyernick = GetPostString("buyer_nick");
  7755. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7756. string sellermemo = GetPostString("seller_memo");
  7757. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7758. string orderState = GetPostString("orderState");
  7759. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7760. string afterState = GetPostString("afterstate");
  7761. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7762. string date1 = GetPostString("date1");
  7763. string date2 = GetPostString("date2");
  7764. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7765. if (dw.Length > 0) lw.Add(dw);
  7766. string price1 = GetPostString("price1");
  7767. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7768. string price2 = GetPostString("price2");
  7769. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7770. string reason = GetPostString("reason");
  7771. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7772. string method = GetPostString("method");
  7773. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7774. string handledate1 = GetPostString("handledate1");
  7775. string handledate2 = GetPostString("handledate2");
  7776. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7777. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7778. string handler = GetPostString("handler");
  7779. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7780. string afterdate1 = GetPostString("afterdate1");
  7781. string afterdate2 = GetPostString("afterdate2");
  7782. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7783. if (afterDate.Length > 0) lw.Add(afterDate);
  7784. string customer = GetPostString("customer");
  7785. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7786. string design = GetPostString("design");
  7787. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7788. string afterMemoType = GetPostString("aftermemotype");
  7789. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7790. string vstate = GetPostString("vstate");
  7791. if (vstate.Length > 0)
  7792. {
  7793. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7794. }
  7795. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7796. string supplier = GetPostString("supplier");
  7797. int supid = commonHelper.getSupplierIDByName(supplier);
  7798. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7799. string posCode = CurrentUser.UserPost.Post.Code;
  7800. if (posCode == "Supplier")
  7801. {
  7802. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7803. }
  7804. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7805. {
  7806. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7807. }
  7808. else
  7809. {
  7810. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7811. }
  7812. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7813. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7814. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7815. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7816. writeGridDataTableJson(dStruct.TotalCount, dt);
  7817. }
  7818. public void upd_erp_supverifyaftersale()
  7819. {
  7820. if (UrlPostParmsCheck("id"))
  7821. {
  7822. string id = GetPostString("id");
  7823. int st = GetPostInt("afterstate");
  7824. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7825. CeErpTradeCell entity = null;
  7826. if (ceErpTradeResponsible != null)
  7827. {
  7828. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7829. }
  7830. string afmemo = GetPostString("supmemo");
  7831. string image = GetPostString("image");
  7832. if (entity != null)
  7833. {
  7834. entity.AfterSaleSupplierState = st;
  7835. entity.AfterSaleSupplierMemo = afmemo;
  7836. if (st == 1)
  7837. {
  7838. ceErpTradeResponsible.VerifyState = 1;
  7839. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7840. ceErpTradeResponsible.Update();
  7841. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7842. if (isAll)
  7843. {
  7844. entity.AfterSaleState = 4;
  7845. entity.FinishAfterSaleTime = DateTime.Now;
  7846. }
  7847. }
  7848. else
  7849. {
  7850. CeErpTradeResponsible.dateByTid(entity.ctid);
  7851. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7852. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7853. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7854. if (num < 1)
  7855. {
  7856. entity.AfterSaleState = 1;
  7857. }
  7858. else
  7859. {
  7860. entity.AfterSaleState = 5;
  7861. }
  7862. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7863. if (ceErpTradeAfterSaleExtend != null)
  7864. {
  7865. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7866. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7867. ceErpTradeAfterSaleExtend.Update();
  7868. }
  7869. else
  7870. {
  7871. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7872. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7873. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7874. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7875. ceErpTradeAfterSaleExtend.Create();
  7876. }
  7877. }
  7878. if (entity.AfterSaleState == 4)
  7879. {
  7880. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7881. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7882. {
  7883. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7884. }
  7885. ApiVo apiVo = new ApiVo();
  7886. apiVo.orderNumber = entity.ctid;
  7887. apiVo.actionName = "afterOver";
  7888. designHelper.API_WorkCore(apiVo); //afterOver
  7889. }
  7890. entity.UpdateTime = DateTime.Now;
  7891. entity.Update();
  7892. returnSuccessMsg("操作成功!");
  7893. CeErpSukuraData.createInfo(entity.ctid, 8);
  7894. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7895. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7896. return;
  7897. }
  7898. returnErrorMsg("找不到订单记录");
  7899. }
  7900. }
  7901. public void upd_erp_masteraftersale()
  7902. {
  7903. if (UrlPostParmsCheck("id"))
  7904. {
  7905. string id = GetPostString("id");
  7906. int st = GetPostInt("afterstate");
  7907. string afmemo = GetPostString("supmemo");
  7908. string image = GetPostString("image");
  7909. string textResult = GetPostString("textResult");
  7910. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7911. if (ceErpTradeResponsible != null)
  7912. {
  7913. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7914. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7915. ceErpTradeResponsible.Update();
  7916. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7917. if (entity != null)
  7918. {
  7919. entity.AfterSaleSupplierState = st;
  7920. entity.AfterSaleSupplierMemo = afmemo;
  7921. if (st == 1)
  7922. {
  7923. }
  7924. else
  7925. {
  7926. CeErpTradeResponsible.dateByTid(entity.ctid);
  7927. //退回到售后
  7928. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7929. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7930. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7931. if (num <= 1)
  7932. {
  7933. entity.AfterSaleState = 1;
  7934. }
  7935. else
  7936. {
  7937. entity.AfterSaleState = 5;
  7938. }
  7939. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7940. if (ceErpTradeAfterSaleExtend != null)
  7941. {
  7942. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7943. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7944. ceErpTradeAfterSaleExtend.Update();
  7945. }
  7946. else
  7947. {
  7948. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7949. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7950. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7951. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7952. ceErpTradeAfterSaleExtend.Create();
  7953. }
  7954. }
  7955. entity.UpdateTime = DateTime.Now;
  7956. entity.Update();
  7957. returnSuccessMsg("操作成功!");
  7958. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7959. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7960. return;
  7961. }
  7962. }
  7963. returnErrorMsg("找不到订单记录");
  7964. }
  7965. }
  7966. public void upd_erp_personaftersale()
  7967. {
  7968. if (UrlPostParmsCheck("id"))
  7969. {
  7970. //林小连
  7971. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7972. {
  7973. upd_erp_masteraftersale();
  7974. return;
  7975. }
  7976. string id = GetPostString("id");
  7977. int st = GetPostInt("afterstate");
  7978. string afmemo = GetPostString("supmemo");
  7979. string image = GetPostString("image");
  7980. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7981. if (ceErpTradeResponsible != null)
  7982. {
  7983. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7984. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7985. ceErpTradeResponsible.Update();
  7986. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7987. if (entity != null)
  7988. {
  7989. entity.AfterSaleSupplierMemo = afmemo;
  7990. entity.AfterSaleSupplierState = st;
  7991. if (st == 1)
  7992. {
  7993. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7994. if (isAll)
  7995. {
  7996. entity.AfterSaleState = 4;
  7997. entity.FinishAfterSaleTime = DateTime.Now;
  7998. }
  7999. }
  8000. else
  8001. {
  8002. CeErpTradeResponsible.dateByTid(entity.ctid);
  8003. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  8004. if (ceErpTradeAfterSaleExtend != null)
  8005. {
  8006. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  8007. ceErpTradeAfterSaleExtend.Update();
  8008. }
  8009. else
  8010. {
  8011. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  8012. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  8013. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  8014. ceErpTradeAfterSaleExtend.Create();
  8015. }
  8016. //退回到主管
  8017. //entity.AfterSaleState = 2;
  8018. }
  8019. if (entity.AfterSaleState == 4)
  8020. {
  8021. ApiVo apiVo = new ApiVo();
  8022. apiVo.orderNumber = entity.ctid;
  8023. apiVo.actionName = "afterOver";
  8024. designHelper.API_WorkCore(apiVo); //afterOver
  8025. }
  8026. entity.UpdateTime = DateTime.Now;
  8027. entity.Update();
  8028. returnSuccessMsg("操作成功!");
  8029. CeErpSukuraData.createInfo(entity.ctid, 8);
  8030. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  8031. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  8032. return;
  8033. }
  8034. }
  8035. returnErrorMsg("找不到订单记录");
  8036. }
  8037. }
  8038. public void set_erp_supplierrefundtag()
  8039. {
  8040. if (UrlPostParmsCheck("ctid"))
  8041. {
  8042. string eid = GetPostString("ctid");
  8043. CeErpTradeCell entity = null;
  8044. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  8045. if (entity != null)
  8046. {
  8047. entity.IsSupplierRefund = GetPostInt("tag");
  8048. entity.Update();
  8049. returnSuccessMsg("操作成功!");
  8050. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  8051. return;
  8052. }
  8053. returnErrorMsg("找不到订单记录");
  8054. }
  8055. }
  8056. public void get_erp_refundlist()
  8057. {
  8058. DataStruct dStruct = GetPostStruct();
  8059. List<string> lw = new List<string>();
  8060. string tid = GetPostString("tid");
  8061. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8062. //string rid = GetPostString("refund_id");
  8063. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  8064. string shopname = GetPostString("shopname");
  8065. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8066. string buyernick = GetPostString("buyer_nick");
  8067. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8068. string customer = GetPostString("customer");
  8069. if (customer.Length > 0) lw.Add(string.Format("CustomerUserName = '{0}'", customer));
  8070. string design = GetPostString("design");
  8071. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8072. string sellermemo = GetPostString("seller_memo");
  8073. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8074. //string date1 = GetPostString("date1");
  8075. //string date2 = GetPostString("date2");
  8076. //string dateType = GetPostString("dateType");
  8077. //if (dateType.Length > 0)
  8078. //{
  8079. // if (dateType == "1001") dateType = "0";
  8080. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  8081. // if (searchDT.Count == 2)
  8082. // {
  8083. // date1 = searchDT[0].ToString();
  8084. // date2 = searchDT[1].ToString();
  8085. // }
  8086. //}
  8087. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8088. //if (dw.Length > 0) lw.Add(dw);
  8089. string redate1 = GetPostString("refunddate1");
  8090. string redate2 = GetPostString("refunddate2");
  8091. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8092. if (dwdate.Length > 0) lw.Add(dwdate);
  8093. string price1 = GetPostString("price1");
  8094. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8095. string price2 = GetPostString("price2");
  8096. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8097. string ispartrefund = GetPostString("ispartrefund");
  8098. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8099. string refundState = GetPostString("refundvstate");
  8100. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  8101. int st = GetInt("st");
  8102. if (st == 2) //待确认列表中,把state=3已确认的也显示
  8103. {
  8104. string responsible = GetPostString("responsibleman");
  8105. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8106. lw.Add(string.Format("RefundState>={0}", st));
  8107. string code = CurrentUser.UserPost.Post.Code;
  8108. if (code == "CustomerService")
  8109. {
  8110. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  8111. }
  8112. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  8113. {
  8114. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  8115. }
  8116. else if (code == "Place" || code == "PlaceMr")
  8117. {
  8118. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  8119. }
  8120. dStruct.Order = "RefundState asc,created desc";
  8121. }
  8122. else if (st == 10)
  8123. {
  8124. string responsible = GetPostString("responsibleman");
  8125. if (responsible == "空白")
  8126. {
  8127. lw.Add(string.Format("ResponsibleUserName = ''"));
  8128. }
  8129. else if (responsible.Length > 0)
  8130. {
  8131. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8132. }
  8133. lw.Add(string.Format("RefundState>=0"));
  8134. dStruct.Order = "created desc";
  8135. }
  8136. else
  8137. {
  8138. string responsible = GetPostString("responsibleman");
  8139. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8140. lw.Add(string.Format("RefundState={0}", st));
  8141. dStruct.Order = "created desc";
  8142. }
  8143. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8144. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  8145. if (dt != null)
  8146. {
  8147. dt.Columns.Add("refund_fees");
  8148. foreach (DataRow dr in dt.Rows)
  8149. {
  8150. String status = dr["status"].ToString();
  8151. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8152. {
  8153. dr["refund_fees"] = dr["refund_fee"];
  8154. }
  8155. else
  8156. {
  8157. dr["refund_fees"] = "0.0";
  8158. }
  8159. }
  8160. }
  8161. writeGridDataTableJson(dStruct.TotalCount, dt);
  8162. }
  8163. public void get_erp_refunddesignlist()
  8164. {
  8165. DataStruct dStruct = GetPostStruct();
  8166. List<string> lw = new List<string>();
  8167. string tid = GetPostString("tid");
  8168. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8169. string shopname = GetPostString("shopname");
  8170. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8171. string buyernick = GetPostString("buyer_nick");
  8172. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8173. string customer = GetPostString("customer");
  8174. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8175. string design = GetPostString("design");
  8176. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8177. string sellermemo = GetPostString("seller_memo");
  8178. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8179. string redate1 = GetPostString("refunddate1");
  8180. string redate2 = GetPostString("refunddate2");
  8181. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8182. if (dwdate.Length > 0) lw.Add(dwdate);
  8183. string price1 = GetPostString("price1");
  8184. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8185. string price2 = GetPostString("price2");
  8186. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8187. string ispartrefund = GetPostString("ispartrefund");
  8188. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8189. string designerorg = GetPostString("designerorg");
  8190. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  8191. string refundState = GetPostString("refundState");
  8192. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  8193. int myOrgid = CurrentUser.UserPost.OrgID;
  8194. string myOrgCode = CurrentUser.UserPost.Post.Code;
  8195. if ("Designer".Equals(myOrgCode))//设计师能看到的
  8196. {
  8197. if (CurrentUser.User.TeamIds.Length > 0)
  8198. {
  8199. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  8200. }
  8201. else
  8202. {
  8203. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8204. }
  8205. }
  8206. else if ("SysAdmin".Equals(myOrgCode))
  8207. {
  8208. }
  8209. else
  8210. {
  8211. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8212. {
  8213. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8214. }
  8215. else
  8216. {
  8217. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8218. }
  8219. }
  8220. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8221. dStruct.Order = "created desc";
  8222. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8223. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8224. dt.Columns.Add("refund_fees");
  8225. foreach (DataRow dr in dt.Rows)
  8226. {
  8227. String status = dr["status"].ToString();
  8228. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8229. {
  8230. dr["refund_fees"] = dr["refund_fee"];
  8231. }
  8232. else
  8233. {
  8234. dr["refund_fees"] = "0.0";
  8235. }
  8236. }
  8237. writeGridDataTableJson(dStruct.TotalCount, dt);
  8238. }
  8239. public void handle_erp_refundtag()
  8240. {
  8241. if (UrlPostParmsCheck("refund_id"))
  8242. {
  8243. string eid = GetPostString("refund_id");
  8244. string respMan = GetPostString("ResponsibleName");
  8245. if (respMan.Length <= 0)
  8246. {
  8247. returnErrorMsg("责任人不能为空");
  8248. return;
  8249. }
  8250. CeErpTradeRefund entity = null;
  8251. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8252. if (entity != null)
  8253. {
  8254. entity.ResponsibleUserName = respMan;
  8255. string userid = GetPostString("ResponsibleUserId");
  8256. if (userid.Length > 0)
  8257. {
  8258. entity.ResponsibleUserId = userid;
  8259. }
  8260. entity.Memo = GetPostString("Memo");
  8261. if (respMan.IndexOf("客服") != -1 ||
  8262. respMan.IndexOf("设计师") != -1 ||
  8263. respMan.IndexOf("下单员") != -1)
  8264. {
  8265. entity.RefundState = 2;
  8266. }
  8267. else
  8268. {
  8269. entity.RefundState = 3;
  8270. }
  8271. entity.modified = DateTime.Now;
  8272. entity.Update();
  8273. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8274. returnSuccessMsg("操作成功!");
  8275. return;
  8276. }
  8277. returnErrorMsg("找不到订单记录");
  8278. }
  8279. }
  8280. public void handle_erp_designrefundtag()
  8281. {
  8282. if (UrlPostParmsCheck("refund_id"))
  8283. {
  8284. string eid = GetPostString("refund_id");
  8285. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8286. if (ceErpTradeCellExtend == null)
  8287. {
  8288. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8289. ceErpTradeCellExtend.ctid = eid;
  8290. }
  8291. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8292. if (ceErpTradeCellExtend.ID > 0)
  8293. {
  8294. ceErpTradeCellExtend.Update();
  8295. }
  8296. else
  8297. {
  8298. ceErpTradeCellExtend.Create();
  8299. }
  8300. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8301. returnSuccessMsg("操作成功!");
  8302. return;
  8303. }
  8304. returnErrorMsg("找不到订单记录");
  8305. }
  8306. public void upd_erp_refundverify()
  8307. {
  8308. if (UrlPostParmsCheck("refund_id"))
  8309. {
  8310. string eid = GetPostString("refund_id");
  8311. CeErpTradeRefund entity = null;
  8312. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8313. if (entity != null)
  8314. {
  8315. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8316. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8317. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8318. {
  8319. entity.RefundState = 2;
  8320. }
  8321. else
  8322. {
  8323. entity.RefundState = 3;
  8324. }
  8325. entity.Update();
  8326. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8327. returnSuccessMsg("操作成功!");
  8328. return;
  8329. }
  8330. returnErrorMsg("找不到订单记录");
  8331. }
  8332. }
  8333. public void upd_erp_refundapprove()
  8334. {
  8335. if (UrlPostParmsCheck("refund_id"))
  8336. {
  8337. string eid = GetPostString("refund_id");
  8338. CeErpTradeRefund entity = null;
  8339. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8340. if (entity != null)
  8341. {
  8342. int apr = GetPostInt("approve");
  8343. if (apr == 0)
  8344. {
  8345. entity.RefundState = 1;
  8346. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8347. }
  8348. else if (apr == 1)
  8349. {
  8350. entity.RefundState = 3;
  8351. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8352. }
  8353. entity.modified = DateTime.Now;
  8354. entity.Update();
  8355. returnSuccessMsg("操作成功!");
  8356. return;
  8357. }
  8358. returnErrorMsg("找不到订单记录");
  8359. }
  8360. }
  8361. public void get_erp_billlist()
  8362. {
  8363. DataStruct dStruct = GetPostStruct();
  8364. List<string> lw = new List<string>();
  8365. string title = GetPostString("title");
  8366. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8367. string tid = GetPostString("tid");
  8368. string tids = GetPostString("tids");
  8369. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8370. if (tids.Length > 0)
  8371. {
  8372. tids = "'" + tids + "'";
  8373. tids = tids.Replace(",", "','");
  8374. lw.Add(string.Format("tid in ({0})", tids));
  8375. }
  8376. string shopname = GetPostString("shopname");
  8377. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8378. string buyernick = GetPostString("buyer_nick");
  8379. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8380. string customer = GetPostString("customer");
  8381. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8382. string date1 = GetPostString("date1");
  8383. string date2 = GetPostString("date2");
  8384. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8385. if (dw.Length > 0) lw.Add(dw);
  8386. string price1 = GetPostString("price1");
  8387. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8388. string price2 = GetPostString("price2");
  8389. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8390. string returndate1 = GetPostString("returndate1");
  8391. string returndate2 = GetPostString("returndate2");
  8392. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8393. if (dw1.Length > 0) lw.Add(dw1);
  8394. string billtype = GetPostString("billtype");
  8395. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8396. string billstate = GetPostString("billstate");
  8397. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8398. string usershop = CurrentUser.User.pemShop;
  8399. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8400. dStruct.Order = "createTime desc";
  8401. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8402. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8403. //foreach (DataRow dr in dt.Rows)
  8404. //{
  8405. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8406. //}
  8407. writeGridDataTableJson(dStruct.TotalCount, dt);
  8408. }
  8409. public void modify_erp_billinfo()
  8410. {
  8411. if (UrlPostParmsCheck("ID"))
  8412. {
  8413. string eid = GetPostString("ID");
  8414. CeErpBill bill_entity = null;
  8415. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8416. if (bill_entity != null)
  8417. {
  8418. bill_entity.tid = GetPostString("tid");
  8419. bill_entity.title = GetPostString("title");
  8420. bill_entity.tax = GetPostString("tax");
  8421. bill_entity.bank = GetPostString("bank");
  8422. bill_entity.bankac = GetPostString("bankac");
  8423. bill_entity.address = GetPostString("address");
  8424. bill_entity.phone = GetPostString("phone");
  8425. bill_entity.price = GetPostString("price");
  8426. bill_entity.productId = GetPostInt("ProductName");
  8427. bill_entity.num = GetPostInt("num");
  8428. bill_entity.unit = GetPostString("unit");
  8429. bill_entity.type = GetPostString("type");
  8430. bill_entity.sendType = GetPostString("SendType");
  8431. bill_entity.email = GetPostString("email");
  8432. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8433. bill_entity.shopName = GetPostString("ShopName");
  8434. bill_entity.applymemo = GetPostString("applymemo");
  8435. bill_entity.modifyTime = DateTime.Now;
  8436. bill_entity.createTime = DateTime.Now;
  8437. bill_entity.state = 0;
  8438. bill_entity.Update();
  8439. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8440. returnSuccessMsg("发票修改成功!");
  8441. return;
  8442. }
  8443. returnErrorMsg("找不到对应记录");
  8444. }
  8445. }
  8446. public void set_erp_invoicing()
  8447. {
  8448. if (UrlPostParmsCheck("id"))
  8449. {
  8450. try
  8451. {
  8452. string eid = GetPostString("id");
  8453. CeErpBill bill_entity = null;
  8454. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8455. if (bill_entity != null)
  8456. {
  8457. int ComId = GetPostInt("ComId");
  8458. //string memo = GetPostString("Memo");
  8459. int allInfo = GetPostInt("allinfo");
  8460. string clert = CurrentUser.User.Name;
  8461. //string detailValue = GetPostString("detailvalue");
  8462. string billId = bill_entity.billOrderId;
  8463. string[] billIdList = billId.Split(',');
  8464. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8465. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8466. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8467. {
  8468. billCount += 1;
  8469. }
  8470. if (billId.Length <= 0 || billIdList.Length != billCount)
  8471. {
  8472. bill_entity.billOrderId = "";
  8473. string prebill = "ltb";
  8474. for (int idx = 1; idx <= billCount; idx++)
  8475. {
  8476. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8477. string billoid = prebill + idx + dtstr;
  8478. bill_entity.billOrderId += billoid;
  8479. if (idx < billCount)
  8480. {
  8481. bill_entity.billOrderId += ",";
  8482. }
  8483. }
  8484. }
  8485. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8486. if (bill_entity.state == 5)
  8487. {
  8488. string errMsg = bill_entity.failerror;
  8489. string[] errlist = errMsg.Split('|');
  8490. string[] errTags = new string[errlist.Length];
  8491. for (int itag = 0; itag < errlist.Length; itag++)
  8492. {
  8493. if (errlist[itag].Length <= 0) continue;
  8494. errTags[itag] = errlist[itag].Split('&')[0];
  8495. }
  8496. for (int iii = 0; iii < errTags.Length; iii++)
  8497. {
  8498. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8499. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8500. if (billOrderList.Length >= erroBillOrderTag)
  8501. {
  8502. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8503. if (needModifyBillId.Length <= 19)
  8504. {
  8505. needModifyBillId = needModifyBillId + "1";
  8506. }
  8507. else
  8508. {
  8509. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8510. last = last + 1;
  8511. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8512. }
  8513. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8514. }
  8515. }
  8516. }
  8517. bool isHaveBillSucces = false;
  8518. string totalRes = "";
  8519. bill_entity.failerror = "";
  8520. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8521. {
  8522. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8523. totalRes += res;
  8524. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8525. {
  8526. isHaveBillSucces = true;
  8527. bill_entity.comId = ComId;
  8528. bill_entity.state = 1;
  8529. bill_entity.executeTime = DateTime.Now;
  8530. bill_entity.executeUser = clert;
  8531. }
  8532. else
  8533. {
  8534. bill_entity.state = 5;
  8535. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8536. }
  8537. }
  8538. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8539. bill_entity.Update();
  8540. if (isHaveBillSucces)
  8541. {
  8542. StringBuilder sql = new StringBuilder();
  8543. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8544. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8545. }
  8546. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8547. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8548. {
  8549. returnErrorMsg("开票失败");
  8550. }
  8551. else
  8552. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8553. return;
  8554. }
  8555. returnErrorMsg("找不到对应记录");
  8556. }
  8557. catch (Exception ex)
  8558. {
  8559. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8560. returnErrorMsg("操作失败");
  8561. }
  8562. }
  8563. }
  8564. public void get_erp_invoicing_back()
  8565. {
  8566. if (UrlPostParmsCheck("id"))
  8567. {
  8568. try
  8569. {
  8570. string id = GetPostString("id");
  8571. CeErpBill entiy = CeErpBill.Get(id);
  8572. if (entiy != null)
  8573. {
  8574. if (entiy.state == 0)
  8575. {
  8576. returnErrorMsg("发票还未开具");
  8577. return;
  8578. }
  8579. string[] billOrderList = entiy.billOrderId.Split(',');
  8580. int iTag = 0;
  8581. entiy.fplsh = "";
  8582. entiy.fpdm = "";
  8583. entiy.fphm = "";
  8584. foreach (string billOrderId in billOrderList)
  8585. {
  8586. iTag++;
  8587. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8588. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8589. {
  8590. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8591. try
  8592. {
  8593. Invoicing_get_response_Obj iObj = null;
  8594. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8595. if (iObj != null)
  8596. {
  8597. entiy.state = 2;
  8598. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8599. entiy.fpdm += iObj.list[0].c_fpdm;
  8600. entiy.fphm += iObj.list[0].c_fphm;
  8601. if (iTag < billOrderList.Length)
  8602. {
  8603. entiy.fplsh += ",";
  8604. entiy.fpdm += ",";
  8605. entiy.fphm += ",";
  8606. }
  8607. entiy.Update();
  8608. }
  8609. StringBuilder sql = new StringBuilder();
  8610. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8611. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8612. returnSuccessMsg("开票成功");
  8613. }
  8614. catch (Exception ex)
  8615. {
  8616. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8617. }
  8618. return;
  8619. }
  8620. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8621. {
  8622. var res_obj = new
  8623. {
  8624. data = "开票中"
  8625. };
  8626. string ro_json = JsonConvert.SerializeObject(res_obj);
  8627. returnSuccess(ro_json);
  8628. return;
  8629. }
  8630. else
  8631. {
  8632. int eidx = res.IndexOf("c_resultmsg");
  8633. int lidx = res.IndexOf("c_status");
  8634. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8635. entiy.state = 5;
  8636. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8637. entiy.Update();
  8638. returnErrorMsg("开票失败");
  8639. return;
  8640. }
  8641. }
  8642. }
  8643. }
  8644. catch (Exception ex)
  8645. {
  8646. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8647. }
  8648. return;
  8649. }
  8650. }
  8651. public void get_erp_invoicing()
  8652. {
  8653. if (UrlPostParmsCheck("id"))
  8654. {
  8655. try
  8656. {
  8657. string id = GetPostString("id");
  8658. CeErpBill entiy = CeErpBill.Get(id);
  8659. if (entiy != null)
  8660. {
  8661. if (entiy.state == 0)
  8662. {
  8663. returnErrorMsg("发票还未开具");
  8664. return;
  8665. }
  8666. if (entiy.sendType == "纸质发票")
  8667. {
  8668. if (entiy.img.Length <= 0)
  8669. {
  8670. returnErrorMsg("查无纸质发票");
  8671. return;
  8672. }
  8673. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8674. returnSuccess(returnres);
  8675. return;
  8676. }
  8677. string[] billOrderList = entiy.billOrderId.Split(',');
  8678. int iTag = 0;
  8679. string fpUrl = "";
  8680. entiy.fplsh = "";
  8681. entiy.fpdm = "";
  8682. entiy.fphm = "";
  8683. foreach (string billOrderId in billOrderList)
  8684. {
  8685. iTag++;
  8686. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8687. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8688. {
  8689. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8690. Invoicing_get_response_Obj iObj = null;
  8691. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8692. if (iObj != null)
  8693. {
  8694. //entiy.state = 2;
  8695. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8696. entiy.fpdm += iObj.list[0].c_fpdm;
  8697. entiy.fphm += iObj.list[0].c_fphm;
  8698. if (iTag < billOrderList.Length)
  8699. {
  8700. entiy.fplsh += ",";
  8701. entiy.fpdm += ",";
  8702. entiy.fphm += ",";
  8703. }
  8704. entiy.Update();
  8705. fpUrl += iObj.list[0].c_url + ",";
  8706. }
  8707. //returnSuccess(res);
  8708. StringBuilder sql = new StringBuilder();
  8709. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8710. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8711. }
  8712. else
  8713. {
  8714. int eidx = res.IndexOf("c_resultmsg");
  8715. //int lidx = res.IndexOf("c_status");
  8716. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8717. //开票失败
  8718. entiy.state = 5;
  8719. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8720. entiy.Update();
  8721. returnErrorMsg("开票失败");
  8722. return;
  8723. }
  8724. }
  8725. var returnObj = new
  8726. {
  8727. data = fpUrl
  8728. };
  8729. string ro_json = JsonConvert.SerializeObject(returnObj);
  8730. returnSuccess(ro_json);
  8731. }
  8732. }
  8733. catch (Exception ex)
  8734. {
  8735. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8736. }
  8737. return;
  8738. }
  8739. }
  8740. public void save_erp_billimg()
  8741. {
  8742. if (UrlPostParmsCheck("id"))
  8743. {
  8744. string eid = GetPostString("id");
  8745. CeErpBill bill_entity = null;
  8746. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8747. if (bill_entity != null)
  8748. {
  8749. bill_entity.img = GetPostString("img");
  8750. bill_entity.executeTime = DateTime.Now;
  8751. bill_entity.state = 2;
  8752. bill_entity.Update();
  8753. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8754. returnSuccessMsg("保存成功");
  8755. }
  8756. return;
  8757. }
  8758. }
  8759. public void upd_erp_billreturnback()
  8760. {
  8761. if (UrlPostParmsCheck("id"))
  8762. {
  8763. int eid = GetPostInt("id");
  8764. CeErpBill bill_entity = null;
  8765. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8766. if (bill_entity != null)
  8767. {
  8768. bill_entity.state = 3;
  8769. bill_entity.returnReason = GetPostString("reason");
  8770. bill_entity.Update();
  8771. returnSuccessMsg("驳回成功!");
  8772. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8773. }
  8774. return;
  8775. }
  8776. }
  8777. public void cancel_erp_bill()
  8778. {
  8779. if (UrlPostParmsCheck("id"))
  8780. {
  8781. int eid = GetPostInt("id");
  8782. int detailValue = GetPostInt("detailvalue");
  8783. CeErpBill bill_entity = null;
  8784. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8785. string cres = "";
  8786. string gres = "";
  8787. if (bill_entity != null)
  8788. {
  8789. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8790. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8791. {
  8792. int iTag = 0;
  8793. bill_entity.fplsh = "";
  8794. bill_entity.fpdm = "";
  8795. bill_entity.fphm = "";
  8796. foreach (string billOrderId in billOrderList)
  8797. {
  8798. iTag++;
  8799. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8800. if (gres.IndexOf("success") != -1)
  8801. {
  8802. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8803. Invoicing_get_response_Obj iObj = null;
  8804. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8805. if (iObj != null)
  8806. {
  8807. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8808. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8809. bill_entity.fphm += iObj.list[0].c_fphm;
  8810. if (iTag < billOrderList.Length)
  8811. {
  8812. bill_entity.fplsh += ",";
  8813. bill_entity.fpdm += ",";
  8814. bill_entity.fphm += ",";
  8815. }
  8816. bill_entity.Update();
  8817. }
  8818. }
  8819. else
  8820. {
  8821. returnErrorMsg(gres);
  8822. return;
  8823. }
  8824. }
  8825. }
  8826. if (bill_entity.sendType == "纸质发票")
  8827. {
  8828. //作废
  8829. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8830. //if (DateTime.Now.Month == extime.Month)
  8831. //{
  8832. //cres = taobaoHelper.cancel_invoicing(eid);
  8833. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8834. //{
  8835. bill_entity.state = 4;//已作废
  8836. bill_entity.Update();
  8837. returnSuccessMsg("发票已作废");
  8838. return;
  8839. //}
  8840. //else
  8841. //{
  8842. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8843. // bill_entity.Update();
  8844. // returnErrorMsg(cres);
  8845. // return;
  8846. //}
  8847. //}
  8848. //else
  8849. //{
  8850. // returnErrorMsg("纸质发票只能作废本月的发票");
  8851. // return;
  8852. //}
  8853. }
  8854. //红冲
  8855. int redTag = 0;
  8856. string[] fpdmList = bill_entity.fpdm.Split(',');
  8857. string[] fphmList = bill_entity.fphm.Split(',');
  8858. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8859. {
  8860. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8861. return;
  8862. }
  8863. foreach (string billOrderId in billOrderList)
  8864. {
  8865. redTag++;
  8866. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8867. cres += onecres;
  8868. cres += ",";
  8869. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8870. {
  8871. bill_entity.state = 4;//已作废
  8872. //bill_entity.Update();
  8873. //returnSuccessMsg("发票已红冲");
  8874. }
  8875. else if (onecres.IndexOf("重复冲红") != -1)
  8876. {
  8877. bill_entity.state = 4;//已作废
  8878. //bill_entity.Update();
  8879. //returnSuccessMsg("发票已红冲");
  8880. }
  8881. else
  8882. {
  8883. string errmsg = commonHelper.KeepChinese(onecres);
  8884. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8885. }
  8886. }
  8887. bill_entity.Update();
  8888. if (cres.IndexOf("失败") != -1)
  8889. returnErrorMsg("红冲失败");
  8890. else
  8891. returnSuccessMsg("发票已红冲");
  8892. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8893. return;
  8894. }
  8895. return;
  8896. }
  8897. }
  8898. public void del_erp_billorder()
  8899. {
  8900. if (UrlPostParmsCheck("id"))
  8901. {
  8902. string eid = GetPostString("id");
  8903. CeErpBill.Del(eid);
  8904. CeErpBill bill = CeErpBill.Get(eid);
  8905. if (bill != null)
  8906. {
  8907. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8908. }
  8909. returnSuccessMsg("删除成功");
  8910. }
  8911. }
  8912. public void finish_erp_bill()
  8913. {
  8914. if (UrlPostParmsCheck("ids"))
  8915. {
  8916. string eids = GetPostString("ids");
  8917. string[] list = eids.Split(',');
  8918. foreach (string eid in list)
  8919. {
  8920. CeErpBill bill = CeErpBill.Get(eid);
  8921. if (bill != null)
  8922. {
  8923. bill.state = 2;
  8924. bill.Update();
  8925. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8926. }
  8927. }
  8928. returnSuccessMsg("操作成功");
  8929. }
  8930. }
  8931. public void get_erp_returncash()
  8932. {
  8933. DataStruct dStruct = GetPostStruct();
  8934. List<string> lw = new List<string>();
  8935. string tid = GetPostString("tid");
  8936. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8937. string shopname = GetPostString("shopname");
  8938. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8939. string buyernick = GetPostString("buyer_nick");
  8940. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8941. string customer = GetPostString("customer");
  8942. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8943. string returndate1 = GetPostString("returndate1");
  8944. string returndate2 = GetPostString("returndate2");
  8945. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8946. if (dw.Length > 0) lw.Add(dw);
  8947. string finishDate1 = GetPostString("finishdate1");
  8948. string finishDate2 = GetPostString("finishdate2");
  8949. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8950. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8951. string returntype = GetPostString("returntype");
  8952. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8953. string returnvstate = GetPostString("returnvstate");
  8954. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8955. dStruct.Order = "created desc";
  8956. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8957. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8958. writeGridDataTableJson(dStruct.TotalCount, dt);
  8959. }
  8960. public void get_erp_staygoods()
  8961. {
  8962. DataStruct dStruct = GetPostStruct();
  8963. List<string> lw = new List<string>();
  8964. string tid = GetPostString("tid");
  8965. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8966. string shopname = GetPostString("shopname");
  8967. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8968. string wangwang = GetPostString("wangwang");
  8969. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8970. string customer = GetPostString("customer");
  8971. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8972. string returndate1 = GetPostString("returndate1");
  8973. string returndate2 = GetPostString("returndate2");
  8974. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8975. if (dw.Length > 0) lw.Add(dw);
  8976. string finishDate1 = GetPostString("finishdate1");
  8977. string finishDate2 = GetPostString("finishdate2");
  8978. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8979. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8980. string returnvstate = GetPostString("returnvstate");
  8981. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8982. string persuadetype = GetPostString("persuadetype");
  8983. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8984. string customerOrg = GetPostString("customerOrg");
  8985. if (customerOrg.Length > 0)
  8986. {
  8987. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8988. }
  8989. string designerorg = GetPostString("designerorg");
  8990. if (designerorg.Length > 0)
  8991. {
  8992. lw.Add(string.Format("OrgID = {0}", designerorg));
  8993. }
  8994. dStruct.Order = "creata_time desc";
  8995. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8996. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8997. writeGridDataTableJson(dStruct.TotalCount, dt);
  8998. }
  8999. public void upd_erp_staygoods()
  9000. {
  9001. if (UrlPostParmsCheck("id"))
  9002. {
  9003. int eid = GetPostInt("id");
  9004. CeErpStayGoods entity = null;
  9005. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  9006. if (entity != null)
  9007. {
  9008. entity.audit_type = 1;
  9009. entity.audit_time = DateTime.Now;
  9010. entity.audit_u_id = CurrentUser.UserID;
  9011. entity.audit_u_name = CurrentUser.UserName;
  9012. entity.Update();
  9013. returnSuccessMsg("审核成功!");
  9014. return;
  9015. }
  9016. returnErrorMsg("找不到订单记录");
  9017. }
  9018. }
  9019. public void upd_erp_stayGoodsback()
  9020. {
  9021. if (UrlPostParmsCheck("id"))
  9022. {
  9023. int eid = GetPostInt("id");
  9024. CeErpStayGoods entity = null;
  9025. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  9026. if (entity != null)
  9027. {
  9028. entity.audit_text = GetPostString("reason");
  9029. entity.audit_type = 2;
  9030. entity.audit_time = DateTime.Now;
  9031. entity.audit_u_id = CurrentUser.UserID;
  9032. entity.audit_u_name = CurrentUser.UserName;
  9033. entity.Update();
  9034. returnSuccessMsg("退回成功!");
  9035. return;
  9036. }
  9037. returnErrorMsg("找不到订单记录");
  9038. }
  9039. }
  9040. public void upd_erp_returncashverify()
  9041. {
  9042. if (UrlPostParmsCheck("ID"))
  9043. {
  9044. int eid = GetPostInt("ID");
  9045. CeErpReturnCash entity = null;
  9046. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9047. if (entity != null)
  9048. {
  9049. entity.cashstate = 1;
  9050. entity.verifytime = DateTime.Now;
  9051. entity.verifyuserid = CurrentUser.UserID;
  9052. entity.Update();
  9053. returnSuccessMsg("审核成功!");
  9054. return;
  9055. }
  9056. returnErrorMsg("找不到订单记录");
  9057. }
  9058. }
  9059. public void upd_all_erp_returncashverify()
  9060. {
  9061. if (UrlPostParmsCheck("ID"))
  9062. {
  9063. String[] list = GetPostString("ID").Split(',');
  9064. CeErpReturnCash entity = null;
  9065. for (int i = 0; i < list.Length; i++)
  9066. {
  9067. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  9068. if (entity != null)
  9069. {
  9070. if (entity.cashstate == 1)
  9071. {
  9072. returnErrorMsg("已审核过的订单不需要在审核!");
  9073. return;
  9074. }
  9075. entity.cashstate = 1;
  9076. entity.verifytime = DateTime.Now;
  9077. entity.verifyuserid = CurrentUser.UserID;
  9078. entity.Update();
  9079. }
  9080. }
  9081. returnSuccessMsg("审核成功!");
  9082. return;
  9083. }
  9084. }
  9085. public void upd_erp_returncashback()
  9086. {
  9087. if (UrlPostParmsCheck("ID"))
  9088. {
  9089. int eid = GetPostInt("ID");
  9090. CeErpReturnCash entity = null;
  9091. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9092. if (entity != null)
  9093. {
  9094. entity.backreason = GetPostString("reason");
  9095. entity.cashstate = 2;
  9096. entity.verifytime = DateTime.Now;
  9097. entity.verifyuserid = CurrentUser.UserID;
  9098. entity.Update();
  9099. returnSuccessMsg("退回成功!");
  9100. return;
  9101. }
  9102. returnErrorMsg("找不到订单记录");
  9103. }
  9104. }
  9105. public void upd_erp_returnprice()
  9106. {
  9107. if (UrlPostParmsCheck("ID"))
  9108. {
  9109. int eid = GetPostInt("ID");
  9110. CeErpReturnCash entity = null;
  9111. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9112. if (entity != null)
  9113. {
  9114. if (entity.cashstate == 1)
  9115. {
  9116. returnErrorMsg("审核通过了不能改");
  9117. return;
  9118. }
  9119. entity.returnprice = GetPostDouble("returnprice");
  9120. entity.Update();
  9121. returnSuccessMsg("修改成功!");
  9122. return;
  9123. }
  9124. returnErrorMsg("找不到订单记录");
  9125. }
  9126. }
  9127. public void del_erp_returncash()
  9128. {
  9129. if (UrlPostParmsCheck("ID"))
  9130. {
  9131. int eid = GetPostInt("ID");
  9132. CeErpReturnCash.Del(eid);
  9133. returnSuccessMsg("操作成功");
  9134. return;
  9135. }
  9136. }
  9137. public void test_for_do_sql()
  9138. {
  9139. string sql = GetPostString("sqlstr");
  9140. if (sql.Length > 0)
  9141. {
  9142. try
  9143. {
  9144. DbHelper.DbConn.ExecuteNonQuery(sql);
  9145. var res_obj = new
  9146. {
  9147. data = "成功",
  9148. };
  9149. string ro_json = JsonConvert.SerializeObject(res_obj);
  9150. returnSuccess(ro_json);
  9151. }
  9152. catch (Exception ex)
  9153. {
  9154. var res_obj = new
  9155. {
  9156. data = ex.Message,
  9157. };
  9158. string ro_json = JsonConvert.SerializeObject(res_obj);
  9159. returnSuccess(ro_json);
  9160. }
  9161. }
  9162. }
  9163. public void get_user_info()
  9164. {
  9165. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  9166. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  9167. }
  9168. public void get_total_data()
  9169. {
  9170. int userId = CurrentUser.UserID;
  9171. string sql = "";
  9172. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9173. {
  9174. 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);
  9175. }
  9176. else
  9177. {
  9178. 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 " +
  9179. "(select ID from CE_ErpUser where ID = {0}) d " +
  9180. "left join " +
  9181. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  9182. ") a on d.ID = a.id left join " +
  9183. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  9184. ") b on a.id = b.id1 left join" +
  9185. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  9186. ") c on a.id = c.id2;", userId);
  9187. }
  9188. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9189. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9190. }
  9191. public void get_date_area_total_data2()
  9192. {
  9193. int userId = CurrentUser.UserID;
  9194. string date_type = GetPostString("timetype");
  9195. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9196. string sql = "";
  9197. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9198. {
  9199. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  9200. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  9201. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9202. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9203. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9204. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  9205. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9206. ") a on e.ID = a.id left join " +
  9207. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9208. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9209. ") b on a.id = b.id1 " +
  9210. "left join " +
  9211. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9212. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9213. ") c on a.id = c.id2 " +
  9214. "left join " +
  9215. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9216. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9217. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9218. }
  9219. else
  9220. {
  9221. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9222. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9223. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9224. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9225. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9226. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9227. ") a on e.ID = a.id left join " +
  9228. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9229. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9230. ") c on a.id = c.id2 " +
  9231. "left join " +
  9232. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9233. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9234. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9235. }
  9236. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9237. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9238. }
  9239. public void get_date_area_total_data()
  9240. {
  9241. int userId = CurrentUser.UserID;
  9242. string date_type = GetPostString("timetype");
  9243. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9244. string date1 = searchDT[0].ToString();
  9245. string date2 = searchDT[1].ToString();
  9246. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9247. {
  9248. SqlParameter[] sqlParameter ={
  9249. new SqlParameter("@userId", SqlDbType.Int,4),
  9250. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9251. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9252. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9253. };
  9254. sqlParameter[0].Value = userId;
  9255. sqlParameter[1].Value = date1;
  9256. sqlParameter[2].Value = date2;
  9257. sqlParameter[3].Direction = ParameterDirection.Output;
  9258. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9259. string res = sqlParameter[3].Value.ToString();
  9260. var res_obj = new
  9261. {
  9262. data = res
  9263. };
  9264. string ro_json = JsonConvert.SerializeObject(res_obj);
  9265. returnSuccess(ro_json);
  9266. }
  9267. else
  9268. {
  9269. SqlParameter[] sqlParameter ={
  9270. new SqlParameter("@userId", SqlDbType.Int,4),
  9271. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9272. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9273. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9274. };
  9275. sqlParameter[0].Value = userId;
  9276. sqlParameter[1].Value = date1;
  9277. sqlParameter[2].Value = date2;
  9278. sqlParameter[3].Direction = ParameterDirection.Output;
  9279. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9280. string res = sqlParameter[3].Value.ToString();
  9281. var res_obj = new
  9282. {
  9283. data = res
  9284. };
  9285. string ro_json = JsonConvert.SerializeObject(res_obj);
  9286. returnSuccess(ro_json);
  9287. }
  9288. //writeGridDataViewJson(dt.Rows.Count, dv);
  9289. }
  9290. public void get_order_list()
  9291. {
  9292. string strFields = GetPostString("paraFields");
  9293. string strOrder = GetPostString("paraOrder");
  9294. string strWhere = GetPostString("paraWhere");
  9295. string strPageSize = GetPostString("paraPageSize");
  9296. DataStruct dStruct = GetPostStruct();
  9297. dStruct.PageSize = int.Parse(strPageSize);
  9298. dStruct.Fileds = strFields;
  9299. dStruct.Order = strOrder;
  9300. dStruct.MainWhere = strWhere;
  9301. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9302. writeGridDataTableJson(dStruct.TotalCount, dt);
  9303. }
  9304. ////获取待开始订单列表
  9305. //public void get_wait_design_order_list()
  9306. //{
  9307. // string date_type = GetPostString("date_type");
  9308. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9309. // DataStruct dStruct = GetPostStruct();
  9310. // dStruct.PageSize = 1000;
  9311. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9312. // List<string> lw = new List<string>();
  9313. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9314. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9315. // dStruct.Order = "WaitDesignTime asc";
  9316. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9317. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9318. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9319. //}
  9320. //获取完成单量排名
  9321. public void get_finish_order_count_ranking()
  9322. {
  9323. /* string date_type = GetPostString("date_type");
  9324. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9325. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9326. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9327. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9328. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9329. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9330. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9331. writeGridDataTableJson(0, new DataTable());
  9332. }
  9333. public void get_finish_order_amount_ranking()
  9334. {
  9335. /*string date_type = GetPostString("date_type");
  9336. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9337. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9338. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9339. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9340. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9341. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9342. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9343. writeGridDataTableJson(0, new DataTable());
  9344. }
  9345. public void get_finish_refund_count_ranking()
  9346. {
  9347. string date_type = GetPostString("date_type");
  9348. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9349. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9350. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9351. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9352. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9353. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9354. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9355. writeGridDataTableJson(dt.Rows.Count, dt);
  9356. }
  9357. public void get_finish_refund_amount_ranking()
  9358. {
  9359. string date_type = GetPostString("date_type");
  9360. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9361. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9362. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9363. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9364. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9365. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9366. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9367. writeGridDataTableJson(dt.Rows.Count, dt);
  9368. }
  9369. public void set_erp_finishorder_director()
  9370. {
  9371. if (UrlPostParmsCheck("ctid"))
  9372. {
  9373. string eid = GetPostString("ctid");
  9374. CeErpTradeCell entity = null;
  9375. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9376. if (entity != null)
  9377. {
  9378. entity.OrderState = 8;
  9379. entity.Update();
  9380. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9381. returnSuccessMsg("操作成功!");
  9382. return;
  9383. }
  9384. returnErrorMsg("找不到记录");
  9385. }
  9386. }
  9387. public void get_erp_placeregistlist()
  9388. {
  9389. DataStruct dStruct = GetPostStruct();
  9390. List<string> lw = new List<string>();
  9391. string outsid = GetPostString("outsid");
  9392. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9393. string memo = GetPostString("memo");
  9394. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9395. string filename = GetPostString("filename");
  9396. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9397. string islate = GetPostString("islate");
  9398. if (islate.Length > 0)
  9399. {
  9400. if (islate == "1")
  9401. lw.Add(string.Format("OutLate>0"));
  9402. else
  9403. lw.Add(string.Format("OutLate=0"));
  9404. }
  9405. string placedate1 = GetPostString("placedate1");
  9406. string placedate2 = GetPostString("placedate2");
  9407. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9408. if (dw.Length > 0) lw.Add(dw);
  9409. string deliveryDate1 = GetPostString("deliverydate1");
  9410. string deliveryDate2 = GetPostString("deliverydate2");
  9411. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9412. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9413. dStruct.Order = "ID desc";
  9414. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9415. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9416. writeGridDataTableJson(dStruct.TotalCount, dt);
  9417. }
  9418. public void ins_erp_placeregist()
  9419. {
  9420. if (UrlPostParmsCheck("id"))
  9421. {
  9422. string eid = GetPostString("id");
  9423. CeErpPlaceRegister entity = null;
  9424. if (eid == "0")//新增
  9425. {
  9426. entity = new CeErpPlaceRegister();
  9427. string xdTime = GetPostString("placeTime");
  9428. if (xdTime.Length > 0)
  9429. {
  9430. entity.PlactTime = Convert.ToDateTime(xdTime);
  9431. }
  9432. string fhTime = GetPostString("deliveryTime");
  9433. if (fhTime.Length > 0)
  9434. {
  9435. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9436. }
  9437. string preTime = GetPostString("preOutTime");
  9438. if (preTime.Length > 0)
  9439. {
  9440. entity.PreOutTime = Convert.ToDateTime(preTime);
  9441. }
  9442. entity.DeliveryCount = GetPostInt("deliveryCount");
  9443. entity.ReceiveCount = GetPostInt("receiveCount");
  9444. entity.OutSid = GetPostString("outSid");
  9445. entity.FileName = GetPostString("fileName");
  9446. entity.Memo = GetPostString("memo");
  9447. entity.AddUserId = CurrentUser.UserID;
  9448. entity.CreateTime = DateTime.Now;
  9449. entity.Img = GetPostString("img");
  9450. entity.Supplier = GetPostInt("supplier");
  9451. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9452. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9453. {
  9454. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9455. DateTime dt2 = (DateTime)entity.PreOutTime;
  9456. TimeSpan span = dt1.Subtract(dt2);
  9457. if (span.Days > 0)
  9458. {
  9459. entity.OutLate = span.Days;
  9460. }
  9461. }
  9462. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9463. entity.Create();
  9464. returnSuccessMsg("添加成功!");
  9465. return;
  9466. }
  9467. else //修改
  9468. {
  9469. entity = CeErpPlaceRegister.Get(eid);
  9470. if (entity != null)
  9471. {
  9472. string xdTime = GetPostString("placeTime");
  9473. if (xdTime.Length > 0)
  9474. {
  9475. entity.PlactTime = Convert.ToDateTime(xdTime);
  9476. }
  9477. string fhTime = GetPostString("deliveryTime");
  9478. if (fhTime.Length > 0)
  9479. {
  9480. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9481. }
  9482. string preTime = GetPostString("preOutTime");
  9483. if (preTime.Length > 0)
  9484. {
  9485. entity.PreOutTime = Convert.ToDateTime(preTime);
  9486. }
  9487. entity.DeliveryCount = GetPostInt("deliveryCount");
  9488. entity.ReceiveCount = GetPostInt("receiveCount");
  9489. if (entity.DeliveryCount == entity.ReceiveCount)
  9490. {
  9491. entity.CurState = "已完成";
  9492. }
  9493. else
  9494. {
  9495. entity.CurState = "未完成";
  9496. }
  9497. entity.OutSid = GetPostString("outSid");
  9498. entity.FileName = GetPostString("fileName");
  9499. entity.Memo = GetPostString("memo");
  9500. entity.Img = GetPostString("img");
  9501. entity.Supplier = GetPostInt("supplier");
  9502. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9503. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9504. {
  9505. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9506. DateTime dt2 = (DateTime)entity.PreOutTime;
  9507. TimeSpan span = dt1.Subtract(dt2);
  9508. if (span.Days > 0)
  9509. {
  9510. entity.OutLate = span.Days;
  9511. }
  9512. }
  9513. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9514. entity.Update();
  9515. returnSuccessMsg("修改成功");
  9516. return;
  9517. }
  9518. returnErrorMsg("找不到对应的记录");
  9519. return;
  9520. }
  9521. }
  9522. returnErrorMsg("缺少必要参数");
  9523. }
  9524. public void del_erp_placeregist()
  9525. {
  9526. string eid = GetPostString("id");
  9527. CeErpPlaceRegister.Del(eid);
  9528. returnSuccessMsg("删除成功!");
  9529. return;
  9530. }
  9531. public void ins_erp_placeregistbyorder()
  9532. {
  9533. string ctid = GetPostString("ctid");
  9534. if (ctid.Length > 0)
  9535. {
  9536. StringBuilder sql = new StringBuilder();
  9537. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9538. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9539. if (dt.Rows.Count > 0)
  9540. {
  9541. foreach (DataRow dr in dt.Rows)
  9542. {
  9543. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9544. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9545. entity.AddUserId = CurrentUser.UserID;
  9546. entity.tid = dr["tid"].ToString();
  9547. entity.Did = Convert.ToString(dr["ctid"]);
  9548. entity.splitTag = dr["SplitTag"].ToString();
  9549. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9550. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9551. if (pre_ctid.Length > 0)
  9552. {
  9553. sellmemo = sellmemo.Replace(pre_ctid, "");
  9554. }
  9555. sellmemo = sellmemo.Replace("[", "");
  9556. sellmemo = sellmemo.Replace("]", "");
  9557. entity.FileName = sellmemo;
  9558. string count = dr["ProductCount"].ToString();
  9559. int usecount = commonHelper.getIntCountFromString(count);
  9560. entity.DeliveryCount = usecount;
  9561. entity.CurState = "未完成";
  9562. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9563. {
  9564. entity.Supplier = 24;//dl手提袋定制
  9565. }
  9566. else
  9567. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9568. entity.CreateTime = DateTime.Now;
  9569. entity.Create();
  9570. }
  9571. returnSuccessMsg("操作成功");
  9572. return;
  9573. }
  9574. returnErrorMsg("没有找到对应订单");
  9575. return;
  9576. }
  9577. returnErrorMsg("缺少订单编号");
  9578. return;
  9579. }
  9580. public void get_erp_persuadelist()
  9581. {
  9582. DataStruct dStruct = GetPostStruct();
  9583. List<string> lw = new List<string>();
  9584. string ctid = GetPostString("ctid");
  9585. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9586. string shopname = GetPostString("shopname");
  9587. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9588. string buyernick = GetPostString("buyer_nick");
  9589. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9590. string customer = GetPostString("customer");
  9591. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9592. string returndate1 = GetPostString("returndate1");
  9593. string returndate2 = GetPostString("returndate2");
  9594. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9595. if (dw.Length > 0) lw.Add(dw);
  9596. string finishDate1 = GetPostString("finishdate1");
  9597. string finishDate2 = GetPostString("finishdate2");
  9598. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9599. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9600. string persuadetype = GetPostString("persuadetype");
  9601. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9602. string returnvstate = GetPostString("returnvstate");
  9603. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9604. dStruct.Order = "created desc";
  9605. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9606. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9607. writeGridDataTableJson(dStruct.TotalCount, dt);
  9608. }
  9609. public void upd_erp_returnpersuadeback()
  9610. {
  9611. if (UrlPostParmsCheck("ID"))
  9612. {
  9613. int eid = GetPostInt("ID");
  9614. CeErpPersuade entity = null;
  9615. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9616. if (entity != null)
  9617. {
  9618. entity.backreason = GetPostString("reason");
  9619. entity.pstate = 2;
  9620. entity.verifytime = DateTime.Now;
  9621. entity.verifyuserid = CurrentUser.UserID;
  9622. entity.Update();
  9623. returnSuccessMsg("退回成功!");
  9624. return;
  9625. }
  9626. returnErrorMsg("找不到订单记录");
  9627. }
  9628. }
  9629. public void upd_erp_returnpersuadeverify()
  9630. {
  9631. if (UrlPostParmsCheck("ID"))
  9632. {
  9633. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9634. {
  9635. returnErrorMsg("暂无权限审核");
  9636. return;
  9637. }
  9638. int eid = GetPostInt("ID");
  9639. CeErpPersuade entity = null;
  9640. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9641. if (entity != null)
  9642. {
  9643. entity.pstate = 1;
  9644. entity.verifytime = DateTime.Now;
  9645. entity.verifyuserid = CurrentUser.UserID;
  9646. entity.Update();
  9647. returnSuccessMsg("审核成功!");
  9648. return;
  9649. }
  9650. returnErrorMsg("找不到订单记录");
  9651. }
  9652. }
  9653. public void del_erp_persuade()
  9654. {
  9655. if (UrlPostParmsCheck("ID"))
  9656. {
  9657. int eid = GetPostInt("ID");
  9658. CeErpPersuade.Del(eid);
  9659. returnSuccessMsg("操作成功");
  9660. return;
  9661. }
  9662. }
  9663. public void get_erp_oldcustoupload()
  9664. {
  9665. DataStruct dStruct = GetPostStruct();
  9666. List<string> lw = new List<string>();
  9667. string buyernick = GetPostString("buyer_nick");
  9668. if (buyernick.Length > 0)
  9669. {
  9670. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9671. }
  9672. else
  9673. return;
  9674. dStruct.Order = "pay_time desc";
  9675. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9676. DataTable dt = null;
  9677. dt = WebCache.GetData("view_erptradecell", dStruct);
  9678. writeGridDataTableJson(dStruct.TotalCount, dt);
  9679. }
  9680. public void get_erp_checkorderlist()
  9681. {
  9682. DataStruct dStruct = GetPostStruct();
  9683. List<string> lw = new List<string>();
  9684. string tid = GetPostString("ctid");
  9685. if (tid.Length > 0)
  9686. {
  9687. string select_tid = getTidByCtid(tid);
  9688. lw.Add(string.Format("tid='{0}'", select_tid));
  9689. }
  9690. string shopname = GetPostString("shopname");
  9691. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9692. string buyernick = GetPostString("buyer_nick");
  9693. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9694. string customer = GetPostString("customer");
  9695. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9696. string design = GetPostString("design");
  9697. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9698. string orderState = GetPostString("orderState");
  9699. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9700. string address = GetPostString("address");
  9701. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9702. string sellermemo = GetPostString("seller_memo");
  9703. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9704. string supplier = GetPostString("supplier");
  9705. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9706. {
  9707. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9708. }
  9709. else
  9710. {
  9711. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9712. }
  9713. string date1 = GetPostString("date1");
  9714. string date2 = GetPostString("date2");
  9715. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9716. if (dw.Length > 0) lw.Add(dw);
  9717. string placedate1 = GetPostString("placedate1");
  9718. string placedate2 = GetPostString("placedate2");
  9719. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9720. if (fdw.Length > 0) lw.Add(fdw);
  9721. string price1 = GetPostString("price1");
  9722. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9723. string price2 = GetPostString("price2");
  9724. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9725. string checkst = GetPostString("checkstate");
  9726. if (checkst.Length > 0 && "10".Equals(checkst))
  9727. {
  9728. lw.Add(string.Format("CheckOut>0"));
  9729. }
  9730. else
  9731. {
  9732. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9733. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9734. }
  9735. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9736. {
  9737. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9738. }
  9739. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9740. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9741. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9742. writeGridDataTableJson(dStruct.TotalCount, dt);
  9743. }
  9744. public void ins_erp_startCheck()
  9745. {
  9746. if (UrlPostParmsCheck("ctid"))
  9747. {
  9748. string eid = GetPostString("ctid");
  9749. CeErpTradeCell entity = null;
  9750. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9751. if (entity != null)
  9752. {
  9753. entity.MemoOpt = 4;
  9754. entity.UpdateTime = DateTime.Now;
  9755. entity.Update();
  9756. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9757. CeErpSukuraData.createInfo(entity.ctid, 6);
  9758. returnSuccessMsg("操作成功!");
  9759. return;
  9760. }
  9761. returnErrorMsg("找不到记录");
  9762. }
  9763. }
  9764. public void upd_erp_sendXlw()
  9765. {
  9766. if (UrlPostParmsCheck("ctid"))
  9767. {
  9768. string eid = GetPostString("ctid");
  9769. CeErpTradeCell entity = null;
  9770. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9771. if (entity != null)
  9772. {
  9773. if (entity.IsSendGift == 1)
  9774. {
  9775. returnErrorMsg("请勿重复标记");
  9776. return;
  9777. }
  9778. entity.IsSendGift = 1;
  9779. entity.Update();
  9780. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9781. returnSuccessMsg("操作成功!");
  9782. return;
  9783. }
  9784. returnErrorMsg("找不到记录");
  9785. }
  9786. }
  9787. public void cancel_sendXlw()
  9788. {
  9789. if (UrlPostParmsCheck("ctid"))
  9790. {
  9791. string eid = GetPostString("ctid");
  9792. CeErpTradeCell entity = null;
  9793. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9794. if (entity != null)
  9795. {
  9796. if (entity.IsSendGift == 0)
  9797. {
  9798. returnErrorMsg("未标记小礼物");
  9799. return;
  9800. }
  9801. entity.IsSendGift = 0;
  9802. entity.Update();
  9803. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9804. returnSuccessMsg("操作成功!");
  9805. return;
  9806. }
  9807. returnErrorMsg("找不到记录");
  9808. }
  9809. }
  9810. public void get_erp_designbill()
  9811. {
  9812. DataStruct dStruct = GetPostStruct();
  9813. List<string> lw = new List<string>();
  9814. int isMy = GetInt("my");
  9815. if (isMy == 1)
  9816. {
  9817. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9818. }
  9819. string tid = GetPostString("tid");
  9820. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9821. string userName = GetPostString("design");
  9822. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9823. string price1 = GetPostString("price1");
  9824. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9825. string price2 = GetPostString("price2");
  9826. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9827. string rePrice1 = GetPostString("rePrice1");
  9828. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9829. string rePrice2 = GetPostString("rePrice2");
  9830. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9831. string designerType = GetPostString("designerType");
  9832. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9833. string orderState = GetPostString("orderState");
  9834. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9835. string endTime1 = GetPostString("endTime1");
  9836. string endTime2 = GetPostString("endTime2");
  9837. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9838. if (dw.Length > 0) lw.Add(dw);
  9839. string isDk = GetPostString("isDk");
  9840. if (isDk == "1")
  9841. {
  9842. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9843. }
  9844. else if (isDk == "0")
  9845. {
  9846. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9847. }
  9848. dStruct.Order = "oid, create_time desc";
  9849. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9850. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9851. writeGridDataTableJson(dStruct.TotalCount, dt);
  9852. }
  9853. public void upd_erp_designerbill()
  9854. {
  9855. if (UrlPostParmsCheck("ID"))
  9856. {
  9857. string eid = GetPostString("ID");
  9858. CeErpDesignerBill entity = null;
  9859. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9860. if (entity != null)
  9861. {
  9862. if (GetPostDouble("designerpirce") > 0)
  9863. {
  9864. entity.realPrice = GetPostDouble("designerpirce");
  9865. entity.update_time = DateTime.Now;
  9866. entity.update_u_id = CurrentUser.UserID;
  9867. entity.update_u_name = CurrentUser.UserName;
  9868. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9869. entity.Update();
  9870. returnSuccessMsg("操作成功!");
  9871. return;
  9872. }
  9873. else
  9874. {
  9875. entity.price = GetPostDouble("price");
  9876. entity.update_time = DateTime.Now;
  9877. entity.update_u_id = CurrentUser.UserID;
  9878. entity.update_u_name = CurrentUser.UserName;
  9879. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9880. entity.Update();
  9881. returnSuccessMsg("操作成功!");
  9882. return;
  9883. }
  9884. }
  9885. returnErrorMsg("找不到记录");
  9886. }
  9887. }
  9888. public void audit_erp_designerbill()
  9889. {
  9890. if (UrlPostParmsCheck("ID"))
  9891. {
  9892. string eid = GetPostString("ID");
  9893. CeErpDesignerBill entity = null;
  9894. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9895. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9896. if (entity != null)
  9897. {
  9898. entity.realPrice = GetPostDouble("designerpirce");
  9899. entity.update_time = DateTime.Now;
  9900. entity.update_u_id = CurrentUser.UserID;
  9901. entity.update_u_name = CurrentUser.UserName;
  9902. entity.isAudit = 1;
  9903. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9904. entity.Update();
  9905. if (orderEntity != null)
  9906. {
  9907. orderEntity.IsReadTag = 3;
  9908. orderEntity.Update();
  9909. }
  9910. returnSuccessMsg("操作成功!");
  9911. return;
  9912. }
  9913. returnErrorMsg("找不到记录");
  9914. }
  9915. }
  9916. public void all_audit_erp_designerbill()
  9917. {
  9918. if (UrlPostParmsCheck("idList"))
  9919. {
  9920. string[] list = GetPostString("idList").Split(',');
  9921. CeErpDesignerBill entity = null;
  9922. for (int i = 0; i < list.Length; i++)
  9923. {
  9924. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9925. if (entity == null) return;
  9926. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9927. if (orderEntity == null) return;
  9928. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9929. entity.update_time = DateTime.Now;
  9930. entity.update_u_id = CurrentUser.UserID;
  9931. entity.update_u_name = CurrentUser.UserName;
  9932. entity.isAudit = 1;
  9933. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9934. entity.Update();
  9935. orderEntity.IsReadTag = 3;
  9936. orderEntity.Update();
  9937. }
  9938. returnSuccessMsg("操作成功!");
  9939. return;
  9940. }
  9941. }
  9942. public void get_erp_sameorders()
  9943. {
  9944. if (UrlPostParmsCheck("ctid"))
  9945. {
  9946. string eid = GetPostString("ctid");
  9947. CeErpTradeCell entity = null;
  9948. entity = CeErpTradeCell.GetByCtid(eid);
  9949. if (entity != null)
  9950. {
  9951. StringBuilder sql = new StringBuilder();
  9952. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9953. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9954. var res = new
  9955. {
  9956. data = dt.Rows.Count
  9957. };
  9958. string ro_jsond = JsonConvert.SerializeObject(res);
  9959. returnSuccess(ro_jsond);
  9960. return;
  9961. }
  9962. returnErrorMsg("未找到订单");
  9963. return;
  9964. }
  9965. returnErrorMsg("缺少必要的参数");
  9966. }
  9967. public void get_erp_islasthavesameorder()
  9968. {
  9969. if (UrlPostParmsCheck("ctid"))
  9970. {
  9971. string eid = GetPostString("ctid");
  9972. string[] ctidList = eid.Split(',');
  9973. StringBuilder sql = new StringBuilder();
  9974. string tisCtid = "";
  9975. foreach (string ctid in ctidList)
  9976. {
  9977. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9978. if (entity != null)
  9979. {
  9980. sql = new StringBuilder();
  9981. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9982. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9983. if (dth.Rows.Count > 0)
  9984. {
  9985. tisCtid += entity.ctid;
  9986. tisCtid += ",";
  9987. }
  9988. }
  9989. }
  9990. if (tisCtid.Length > 0)
  9991. {
  9992. var res = new
  9993. {
  9994. data = tisCtid
  9995. };
  9996. string ro_jsond = JsonConvert.SerializeObject(res);
  9997. returnSuccess(ro_jsond);
  9998. }
  9999. else
  10000. {
  10001. var res = new
  10002. {
  10003. data = ""
  10004. };
  10005. string ro_jsond = JsonConvert.SerializeObject(res);
  10006. returnSuccess(ro_jsond);
  10007. }
  10008. return;
  10009. }
  10010. returnErrorMsg("缺少必要的参数");
  10011. }
  10012. public void file_client_down_url()
  10013. {
  10014. if (!UrlPostParmsCheck("userId"))
  10015. {
  10016. returnErrorMsg("缺少必要的参数");
  10017. }
  10018. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  10019. }
  10020. public void checkout_form_data()
  10021. {
  10022. if (!UrlPostParmsCheck("tid"))
  10023. {
  10024. returnErrorMsg("缺少必要的参数");
  10025. }
  10026. string tid = GetPostString("tid");
  10027. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  10028. if (ceErpOrderFormData != null)
  10029. {
  10030. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  10031. returnSuccess(ro_jsond);
  10032. return;
  10033. }
  10034. returnErrorMsg("尚未有文件!");
  10035. }
  10036. public void back_supplier_audit()
  10037. {
  10038. int userId = CurrentUser.UserID;
  10039. StringBuilder sql = new StringBuilder();
  10040. 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);
  10041. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10042. if (dt.Rows.Count > 0)
  10043. {
  10044. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10045. }
  10046. else
  10047. {
  10048. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10049. }
  10050. }
  10051. public void back_supplier_query()
  10052. {
  10053. string eid = GetPostString("ctid");
  10054. if (eid != "")
  10055. {
  10056. StringBuilder sql = new StringBuilder();
  10057. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  10058. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10059. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10060. }
  10061. else
  10062. {
  10063. returnErrorMsg("找不到订单记录");
  10064. return;
  10065. }
  10066. }
  10067. public void verified_to_order()
  10068. {
  10069. int userId = CurrentUser.UserID;
  10070. StringBuilder sql = new StringBuilder();
  10071. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  10072. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10073. if (dt.Rows.Count > 0)
  10074. {
  10075. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10076. }
  10077. else
  10078. {
  10079. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10080. }
  10081. }
  10082. public void upd_supplier_audit()
  10083. {
  10084. if (UrlPostParmsCheck("ctid"))
  10085. {
  10086. string eid = GetPostString("ctid");
  10087. string reason = GetPostString("returnreason");
  10088. CeErpTradeCell entity = null;
  10089. CeWithdraw withdraw = null;
  10090. withdraw = CeWithdraw.GetByTid(eid);
  10091. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  10092. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  10093. {
  10094. if (withdraw != null)
  10095. {
  10096. if (!withdraw.userid.Equals(CurrentUser.UserID))
  10097. {
  10098. returnSuccessMsg("您没有权限操作!");
  10099. return;
  10100. }
  10101. else
  10102. {
  10103. if (reason.Equals("1"))
  10104. {
  10105. if (entity.OrderState == -1)
  10106. {
  10107. if (entity.FinishPlaceTime == null)
  10108. {
  10109. entity.OrderState = 2;
  10110. }
  10111. else
  10112. {
  10113. entity.OrderState = 6;
  10114. }
  10115. //配件单直接到下单部
  10116. if (entity.IsSample == 4)
  10117. {
  10118. entity.OrderState = 5;
  10119. }
  10120. }
  10121. entity.Update();
  10122. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10123. if (withdraw != null)
  10124. {
  10125. withdraw.status = int.Parse(reason);
  10126. withdraw.Update();
  10127. }
  10128. returnSuccessMsg("操作成功!");
  10129. return;
  10130. }
  10131. else
  10132. {
  10133. withdraw.status = int.Parse(reason);
  10134. withdraw.acknowledgingtime = DateTime.Now;
  10135. withdraw.Update();
  10136. returnSuccessMsg("查看详细请点击线下订单查询");
  10137. return;
  10138. }
  10139. }
  10140. }
  10141. // 第一个字符是 'N'
  10142. }
  10143. if (eid[0] != 'N')
  10144. {
  10145. }
  10146. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  10147. {
  10148. entity.IsVerifyToSupplier = false;
  10149. entity.IsReturn = 1;
  10150. entity.ReturnTime = DateTime.Now;
  10151. entity.ReturnReason = reason;
  10152. if (entity.OrderState == 6)
  10153. {
  10154. entity.OrderState = 5;
  10155. }
  10156. entity.Update();
  10157. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  10158. if (withdraw != null)
  10159. {
  10160. withdraw.status = int.Parse(reason);
  10161. withdraw.Update();
  10162. }
  10163. returnSuccessMsg("操作成功!");
  10164. return;
  10165. }
  10166. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  10167. {
  10168. ;
  10169. if (withdraw != null)
  10170. {
  10171. withdraw.status = int.Parse(reason);
  10172. withdraw.acknowledgingtime = DateTime.Now;
  10173. withdraw.Update();
  10174. returnSuccessMsg("供应商取消撤回!");
  10175. return;
  10176. }
  10177. }
  10178. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  10179. {
  10180. if (entity.OrderState == -1)
  10181. {
  10182. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  10183. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10184. /*if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  10185. {
  10186. returnErrorMsg("台湾客户需填写身份证!");
  10187. return;
  10188. }*/
  10189. if (commonHelper.isFarAddress(ceErpTrade.receiver_state) && ceErpTrade.delivery_paymant == 0 && entity.IsSF != 2)
  10190. {
  10191. returnErrorMsg("偏远地区需要填写物流费!");
  10192. return;
  10193. }
  10194. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  10195. {
  10196. returnErrorMsg("订单spu没有确认无法通过审核!");
  10197. return;
  10198. }
  10199. if (entity.FinishPlaceTime == null)
  10200. {
  10201. entity.OrderState = 2;
  10202. }
  10203. else
  10204. {
  10205. entity.OrderState = 3;
  10206. }
  10207. commonHelper.getCytPrice(entity);
  10208. if ((entity.OtherMemo.Contains("老客户") || entity.OtherMemo.Contains("老顾客")) && entity.OtherMemo.Contains("改稿"))
  10209. {
  10210. tmcHelper.dealOldCustomerEntityTag(ref entity, ceErpTrade);
  10211. }
  10212. if (entity.IsSample > 1 || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物"))
  10213. {
  10214. entity.OrderState = 6;
  10215. }
  10216. if (entity.IsSample == 4)
  10217. {
  10218. entity.OrderState = 5;
  10219. }
  10220. }
  10221. entity.Update();
  10222. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10223. if (withdraw != null)
  10224. {
  10225. withdraw.status = int.Parse(reason);
  10226. withdraw.Update();
  10227. }
  10228. returnSuccessMsg("操作成功!");
  10229. return;
  10230. }
  10231. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10232. {
  10233. if (withdraw == null)
  10234. {
  10235. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10236. return;
  10237. }
  10238. }
  10239. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10240. {
  10241. if (withdraw != null)
  10242. {
  10243. withdraw.status = int.Parse(reason);
  10244. withdraw.acknowledgingtime = DateTime.Now;
  10245. withdraw.Update();
  10246. returnSuccessMsg("查看详细请点击线下订单查询");
  10247. return;
  10248. }
  10249. }
  10250. return;
  10251. }
  10252. }
  10253. //校验报价
  10254. public void refund_order_tip()
  10255. {
  10256. int userid = CurrentUser.UserID;
  10257. int sectionId = CurrentUser.UserPost.OrgID;
  10258. StringBuilder sql = new StringBuilder();
  10259. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10260. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10261. List<string> ids = new List<string>();
  10262. if (dth.Rows.Count > 0)
  10263. {
  10264. foreach (DataRow dr in dth.Rows)
  10265. {
  10266. ids.Add(dr["ID"].ToString());
  10267. }
  10268. try
  10269. {
  10270. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10271. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10272. }
  10273. catch (Exception ex)
  10274. {
  10275. }
  10276. }
  10277. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10278. }
  10279. public void refund_order_Design()
  10280. {
  10281. int userid = CurrentUser.UserID;
  10282. int sectionId = CurrentUser.UserPost.OrgID;
  10283. StringBuilder sql = new StringBuilder();
  10284. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10285. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10286. List<string> ids = new List<string>();
  10287. if (dth.Rows.Count > 0)
  10288. {
  10289. foreach (DataRow dr in dth.Rows)
  10290. {
  10291. ids.Add(dr["ID"].ToString());
  10292. }
  10293. try
  10294. {
  10295. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10296. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10297. }
  10298. catch (Exception ex)
  10299. {
  10300. }
  10301. }
  10302. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10303. }
  10304. public void change_order_info()
  10305. {
  10306. int userid = CurrentUser.UserID;
  10307. StringBuilder sql = new StringBuilder();
  10308. 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);
  10309. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10310. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10311. }
  10312. public void size_order_tip()
  10313. {
  10314. int userid = CurrentUser.UserID;
  10315. StringBuilder sql = new StringBuilder();
  10316. sql.AppendFormat("select top 1 * from CE_ErpMessageTip c where (c.userId = '{0}' ) and c.isVisit = 0 and c.type in (3,4);", userid);
  10317. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10318. List<string> ids = new List<string>();
  10319. if (dth.Rows.Count > 0)
  10320. {
  10321. foreach (DataRow dr in dth.Rows)
  10322. {
  10323. ids.Add(dr["ID"].ToString());
  10324. }
  10325. try
  10326. {
  10327. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10328. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10329. }
  10330. catch (Exception ex)
  10331. {
  10332. }
  10333. }
  10334. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10335. }
  10336. public void change_win_mome()
  10337. {
  10338. if (UrlPostParmsCheck("id,ctid"))
  10339. {
  10340. string id = GetPostString("id");
  10341. string ctid = GetPostString("ctid");
  10342. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10343. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10344. if (ce == null || ceErpMessageTip == null)
  10345. {
  10346. returnSuccessMsg("未找到对应的订单!");
  10347. return;
  10348. }
  10349. if (ce.OrderState >= 5)
  10350. {
  10351. ceErpMessageTip.isVisit = true;
  10352. ceErpMessageTip.Update();
  10353. returnSuccessMsg("已上传文件无法修改!");
  10354. return;
  10355. }
  10356. int type = GetPostInt("type");
  10357. string content = GetPostString("content");
  10358. if (type == 0)
  10359. {
  10360. content = content.Replace("(", "(");
  10361. content = content.Replace(")", ")");
  10362. string check = MidStrEx(content, "(", ")").Trim();
  10363. if (string.IsNullOrEmpty(check))
  10364. {
  10365. returnSuccessMsg("文件名格式不正确");
  10366. return;
  10367. }
  10368. }
  10369. ce.seller_memo = content;
  10370. ce.Update();
  10371. ceErpMessageTip.isVisit = true;
  10372. ceErpMessageTip.Update();
  10373. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10374. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10375. ApiVo apiVo = new ApiVo();
  10376. apiVo.orderNumber = ce.ctid;
  10377. apiVo.actionName = "demandDesign";
  10378. apiVo.orderRemarks = content;
  10379. apiVo.demandExamine = type + 1;
  10380. designHelper.API_WorkCore(apiVo);//demandDesign
  10381. returnSuccessMsg("修改成功!");
  10382. }
  10383. }
  10384. public static string MidStrEx(string sourse, string startstr, string endstr)
  10385. {
  10386. string result = string.Empty;
  10387. int startindex, endindex;
  10388. try
  10389. {
  10390. startindex = sourse.IndexOf(startstr);
  10391. if (startindex == -1)
  10392. return result;
  10393. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10394. endindex = tmpstr.IndexOf(endstr);
  10395. if (endindex == -1)
  10396. return result;
  10397. result = tmpstr.Remove(endindex);
  10398. }
  10399. catch (Exception ex)
  10400. {
  10401. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10402. }
  10403. return result;
  10404. }
  10405. public void refund_order_list()
  10406. {
  10407. int userid = CurrentUser.UserID;
  10408. int sectionId = CurrentUser.UserPost.OrgID;
  10409. StringBuilder sql = new StringBuilder();
  10410. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10411. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10412. DataStruct dStruct = GetPostStruct();
  10413. DataTable dt = null;
  10414. List<string> ids = new List<string>();
  10415. List<string> tids = new List<string>();
  10416. if (dth.Rows.Count > 0)
  10417. {
  10418. foreach (DataRow dr in dth.Rows)
  10419. {
  10420. tids.Add("'" + dr["tid"].ToString() + "'");
  10421. ids.Add(dr["id"].ToString());
  10422. }
  10423. try
  10424. {
  10425. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10426. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10427. List<string> lw = new List<string>();
  10428. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10429. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10430. dt = WebCache.GetData("view_orderlist", dStruct);
  10431. }
  10432. catch (Exception ex)
  10433. {
  10434. }
  10435. }
  10436. writeGridDataTableJson(dStruct.TotalCount, dt);
  10437. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10438. }
  10439. //新增
  10440. public void order_batch_downloads()
  10441. {
  10442. string ceid = GetPostString("tid");
  10443. String[] tid = ceid.Split(',');
  10444. order_batch_caiyingtong(tid);
  10445. /* (string success, string errors) = UploadFiles(tid);
  10446. returnSuccessMsg(success + errors);*/
  10447. return;
  10448. }
  10449. //报价接口
  10450. public void Get_To_Quote()
  10451. {
  10452. string ceid = GetPostString("ctid");
  10453. if (ceid != null)
  10454. {
  10455. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10456. if (entity != null)
  10457. {
  10458. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10459. {
  10460. return;
  10461. }
  10462. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10463. double price = 0;
  10464. if (cp == null)
  10465. {
  10466. JObject jsonObject12 = new JObject
  10467. {
  10468. { "UserId", "77886" },
  10469. { "Pwd", "lt666888" },
  10470. { "Filename", entity.seller_memo }
  10471. };
  10472. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10473. JObject jsonObjects1 = JObject.Parse(response1);
  10474. string ms1g = (string)jsonObjects1["msg"];
  10475. if (ms1g == "报价成功")
  10476. {
  10477. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10478. string data = (string)jsonObject1["price"];
  10479. 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 + "');";
  10480. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10481. returnSuccessMsg("获取报价成功:" + data);
  10482. price = Convert.ToDouble(data);
  10483. }
  10484. else
  10485. {
  10486. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10487. return;
  10488. }
  10489. }
  10490. String[] beizhu = entity.seller_memo.Split('-');
  10491. String chanp = "";
  10492. if (beizhu.Length > 0)
  10493. {
  10494. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10495. }
  10496. else
  10497. {
  10498. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10499. }
  10500. JObject jsonObject = new JObject
  10501. {
  10502. { "UserId", "77886" },
  10503. { "Pwd", "lt666888" },
  10504. { "Filename", chanp }
  10505. };
  10506. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10507. JObject jsonObjects = JObject.Parse(response);
  10508. string msg = (string)jsonObjects["msg"];
  10509. if (msg == "报价成功")
  10510. {
  10511. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10512. string data = (string)jsonObject1["price"];
  10513. 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 + "');";
  10514. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10515. returnSuccessMsg("获取报价成功:" + data);
  10516. price = Convert.ToDouble(data);
  10517. }
  10518. else
  10519. {
  10520. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10521. return;
  10522. }
  10523. if (price > 0)
  10524. {
  10525. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10526. if (ceErpTradeCellExtend == null)
  10527. {
  10528. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10529. ceErpTradeCellExtend.ctid = entity.ctid;
  10530. ceErpTradeCellExtend.payment_cyt = price;
  10531. ceErpTradeCellExtend.Create();
  10532. }
  10533. else
  10534. {
  10535. ceErpTradeCellExtend.payment_cyt = price;
  10536. ceErpTradeCellExtend.Update();
  10537. }
  10538. }
  10539. return;
  10540. }
  10541. }
  10542. else
  10543. {
  10544. returnErrorMsg("请至少选择一条数据");
  10545. return;
  10546. }
  10547. }
  10548. //新增
  10549. public void order_To_Supplier()
  10550. {
  10551. string ceid = GetPostString("tid");
  10552. String[] tid = ceid.Split(',');
  10553. if (tid.Length > 0)
  10554. {
  10555. try
  10556. {
  10557. for (int i = 0; i < tid.Length; i++)
  10558. {
  10559. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10560. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10561. entity.SupplierId = suid;
  10562. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10563. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10564. entity.Update();
  10565. }
  10566. }
  10567. catch (Exception ex)
  10568. {
  10569. returnErrorMsg("自动匹配供应商失败");
  10570. return;
  10571. }
  10572. }
  10573. else
  10574. {
  10575. returnErrorMsg("请至少选择一条数据");
  10576. return;
  10577. }
  10578. returnSuccessMsg("自动匹配供应商成功");
  10579. return;
  10580. }
  10581. public (string, string) UploadFiles(string[] urls)
  10582. {
  10583. string success = "";
  10584. string errors = "";
  10585. int userid = CurrentUser.UserID;
  10586. foreach (string url in urls)
  10587. {
  10588. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10589. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10590. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10591. {
  10592. JObject jsonObject = new JObject
  10593. {
  10594. { "Userid", "77886" },
  10595. { "pwd", "cyt86435015" },
  10596. { "content", base64FileContent },
  10597. { "ext", Path.GetExtension(fileName) }
  10598. };
  10599. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10600. JObject jsonObjects = JObject.Parse(response);
  10601. string msg = (string)jsonObjects["msg"];
  10602. if (msg.Equals("上传成功"))
  10603. {
  10604. success += url + " 上传成功";
  10605. }
  10606. else
  10607. {
  10608. errors += url + " 上传失败";
  10609. }
  10610. }
  10611. else
  10612. {
  10613. errors += url + " 格式出现问题";
  10614. }
  10615. }
  10616. if (urls.Length == 0)
  10617. {
  10618. return (success, errors);
  10619. }
  10620. return (success, errors);
  10621. }
  10622. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10623. {
  10624. return true; //总是接受
  10625. }
  10626. public static string HttpPost(string url, string param = null)
  10627. {
  10628. HttpWebRequest request;
  10629. //如果是发送HTTPS请求
  10630. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10631. {
  10632. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10633. request = WebRequest.Create(url) as HttpWebRequest;
  10634. request.ProtocolVersion = HttpVersion.Version10;
  10635. }
  10636. else
  10637. {
  10638. request = WebRequest.Create(url) as HttpWebRequest;
  10639. }
  10640. request.Method = "POST";
  10641. request.ContentType = "application/json";
  10642. request.Accept = "*/*";
  10643. request.Timeout = 120000;
  10644. request.AllowAutoRedirect = false;
  10645. StreamWriter requestStream = null;
  10646. WebResponse response = null;
  10647. string responseStr = null;
  10648. try
  10649. {
  10650. requestStream = new StreamWriter(request.GetRequestStream());
  10651. requestStream.Write(param);
  10652. requestStream.Close();
  10653. response = request.GetResponse();
  10654. if (response != null)
  10655. {
  10656. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10657. responseStr = reader.ReadToEnd();
  10658. reader.Close();
  10659. }
  10660. }
  10661. catch (Exception ex)
  10662. {
  10663. return ex.Message;
  10664. }
  10665. finally
  10666. {
  10667. request = null;
  10668. requestStream = null;
  10669. response = null;
  10670. }
  10671. return responseStr;
  10672. }
  10673. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10674. {
  10675. string base64FileContent;
  10676. string fileName;
  10677. using (WebClient webClient = new WebClient())
  10678. {
  10679. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10680. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10681. {
  10682. using (Stream stream = response.GetResponseStream())
  10683. {
  10684. using (MemoryStream memoryStream = new MemoryStream())
  10685. {
  10686. stream.CopyTo(memoryStream);
  10687. byte[] fileBytes = memoryStream.ToArray();
  10688. base64FileContent = Convert.ToBase64String(fileBytes);
  10689. fileName = response.Headers["Content-Disposition"];
  10690. if (!string.IsNullOrEmpty(fileName))
  10691. {
  10692. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10693. if (index >= 0)
  10694. {
  10695. fileName = fileName.Substring(index + 9).Trim('\"');
  10696. }
  10697. }
  10698. else
  10699. {
  10700. fileName = Path.GetFileName(downloadUrl);
  10701. }
  10702. }
  10703. }
  10704. }
  10705. }
  10706. return (fileName, base64FileContent);
  10707. }
  10708. //新增
  10709. public void order_batch_caiyingtong(string[] downloadUrls)
  10710. {
  10711. try
  10712. {
  10713. //遍历文件
  10714. DataStruct dStruct = GetPostStruct();
  10715. DataTable dt = null;
  10716. int userid = CurrentUser.UserID;
  10717. List<string> ids = new List<string>();//失败组
  10718. List<string> tids = new List<string>();
  10719. using (WebClient webClient = new WebClient())
  10720. {
  10721. foreach (var url in downloadUrls)
  10722. {
  10723. try
  10724. {
  10725. tids.Add("'" + url + "'");
  10726. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10727. if (entity != null)
  10728. {
  10729. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10730. if (cp == null)
  10731. {
  10732. JObject jsonObject = new JObject
  10733. {
  10734. { "Userid", "77886" },
  10735. { "pwd", "lt666888" },
  10736. { "Filename",entity.seller_memo }
  10737. };
  10738. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10739. JObject jsonObjects = JObject.Parse(response);
  10740. string msg = (string)jsonObjects["msg"];
  10741. if (msg == "报价成功")
  10742. {
  10743. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10744. DownloadAndConvertToBase64(url1);
  10745. }
  10746. else
  10747. {
  10748. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10749. }
  10750. }
  10751. else
  10752. {
  10753. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10754. JObject jsonObject = new JObject
  10755. {
  10756. { "Userid", "77886" },
  10757. { "pwd", "lt666888" },
  10758. { "Filename",chanp }
  10759. };
  10760. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10761. JObject jsonObjects = JObject.Parse(response);
  10762. string msg = (string)jsonObjects["msg"];
  10763. if (msg == "报价成功")
  10764. {
  10765. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10766. DownloadAndConvertToBase64(url1);
  10767. }
  10768. else
  10769. {
  10770. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10771. }
  10772. }
  10773. }
  10774. // 上传文件到FTP
  10775. }
  10776. catch (Exception ex)
  10777. {
  10778. Console.WriteLine($"An error occurred: {ex.Message}");
  10779. }
  10780. }
  10781. List<string> lw = new List<string>();
  10782. lw.Add(string.Format("( OrderState < 6 )"));
  10783. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10784. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10785. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10786. if (dt.Rows.Count > 0)
  10787. {
  10788. foreach (DataRow dr in dt.Rows)
  10789. {
  10790. ids.Add(dr["ctid"].ToString());
  10791. }
  10792. }
  10793. String ErrorMsgs = "";
  10794. foreach (String id in ids)
  10795. {
  10796. ErrorMsgs += id + ",";
  10797. }
  10798. if (ErrorMsgs.Length > 1)
  10799. {
  10800. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10801. }
  10802. if (ErrorMsgs.Length < 1)
  10803. {
  10804. ErrorMsgs = "上传成功";
  10805. returnSuccessMsg(ErrorMsgs);
  10806. }
  10807. else
  10808. {
  10809. returnErrorMsg("以下订单" + ErrorMsgs);
  10810. }
  10811. }
  10812. // 删除文件夹及其内容
  10813. /* Directory.Delete(localDirectory, true);*/
  10814. }
  10815. catch { }
  10816. }
  10817. public void get_center_data()
  10818. {
  10819. int userId = CurrentUser.UserID;
  10820. string postCode = CurrentUser.UserPost.Post.Code;
  10821. List<string> lw = new List<string>();
  10822. List<string> ww = new List<string>();
  10823. DateTime currentTime = DateTime.Now;
  10824. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10825. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10826. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10827. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10828. string sql = " SELECT ";
  10829. string startTime = "2023-10-01 11:22:31";
  10830. //设计
  10831. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10832. {
  10833. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10834. 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));
  10835. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10836. 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));
  10837. }
  10838. //客服
  10839. else if (postCode == "CustomerService" || postCode == "Director")
  10840. {
  10841. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10842. 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));
  10843. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10844. 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));
  10845. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10846. 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));
  10847. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10848. 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));
  10849. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10850. 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));
  10851. }
  10852. //售后
  10853. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10854. {
  10855. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10856. 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));
  10857. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10858. 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));
  10859. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10860. 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));
  10861. }
  10862. //下单部
  10863. else if (postCode == "Place" || postCode == "PlaceMr")
  10864. {
  10865. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10866. 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));
  10867. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10868. 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));
  10869. }
  10870. //车间
  10871. else if (postCode == "Supplier")
  10872. {
  10873. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10874. 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));
  10875. }
  10876. DataTable dt = new DataTable();
  10877. if (lw.Count > 0)
  10878. {
  10879. sql += string.Join(" , ", lw);
  10880. sql += " FROM ";
  10881. sql += string.Join(" , ", ww);
  10882. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10883. }
  10884. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10885. }
  10886. public void get_center_data_list()
  10887. {
  10888. int userId = CurrentUser.UserID;
  10889. string postCode = CurrentUser.UserPost.Post.Code;
  10890. string shopIds = CurrentUser.User.pemShop;
  10891. DataStruct dStruct = GetPostStruct();
  10892. List<string> lw = new List<string>();
  10893. DateTime currentTime = DateTime.Now;
  10894. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10895. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10896. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10897. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10898. string startTime = "2023-10-01 11:22:31";
  10899. int order_type = GetPostInt("order_type");
  10900. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10901. {
  10902. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10903. if (order_type == 0)
  10904. {
  10905. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10906. }
  10907. else if (order_type == 3)
  10908. {
  10909. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10910. }
  10911. else
  10912. {
  10913. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10914. }
  10915. }
  10916. //客服
  10917. if (postCode == "CustomerService" || postCode == "Director")
  10918. {
  10919. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10920. if (order_type == 0)
  10921. {
  10922. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10923. }
  10924. else if (order_type == 1)
  10925. {
  10926. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10927. }
  10928. else if (order_type == 2)
  10929. {
  10930. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10931. }
  10932. else if (order_type == 3)
  10933. {
  10934. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10935. }
  10936. else if (order_type == 4)
  10937. {
  10938. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10939. }
  10940. else
  10941. {
  10942. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10943. }
  10944. }
  10945. //售后
  10946. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10947. {
  10948. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10949. if (shopIds != "")
  10950. {
  10951. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10952. }
  10953. if (order_type == 2)
  10954. {
  10955. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10956. }
  10957. else if (order_type == 4)
  10958. {
  10959. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10960. }
  10961. else if (order_type == 5)
  10962. {
  10963. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10964. }
  10965. else
  10966. {
  10967. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10968. }
  10969. }
  10970. //下单部
  10971. if (postCode == "Place" || postCode == "PlaceMr")
  10972. {
  10973. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10974. if (shopIds != "")
  10975. {
  10976. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10977. }
  10978. else if (order_type == 1)
  10979. {
  10980. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10981. }
  10982. else if (order_type == 2)
  10983. {
  10984. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10985. }
  10986. else
  10987. {
  10988. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10989. }
  10990. }
  10991. //车间
  10992. if (postCode == "Supplier")
  10993. {
  10994. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10995. if (order_type == 5)
  10996. {
  10997. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10998. }
  10999. else
  11000. {
  11001. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  11002. }
  11003. }
  11004. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11005. dStruct.Fileds = "tid,ctid";
  11006. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  11007. writeGridDataTableJson(dStruct.TotalCount, dt);
  11008. }
  11009. public void aftersale_audit_master()
  11010. {
  11011. if (UrlPostParmsCheck("ctid"))
  11012. {
  11013. string ctid = GetPostString("ctid");
  11014. if (ctid.Length > 0)
  11015. {
  11016. bool result = aftersale_data_change(ctid);
  11017. if (result)
  11018. {
  11019. returnSuccessMsg("修改成功!");
  11020. return;
  11021. }
  11022. }
  11023. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11024. }
  11025. }
  11026. public void aftersale_documentary_finish()
  11027. {
  11028. if (UrlPostParmsCheck("ctid"))
  11029. {
  11030. string ctid = GetPostString("ctid");
  11031. if (ctid.Length > 0)
  11032. {
  11033. List<string> list = new List<string>();
  11034. string[] ctid_list = ctid.Split(',');
  11035. foreach (var item in ctid_list)
  11036. {
  11037. try
  11038. {
  11039. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(item);
  11040. if (ceErpTradeAfterSaleExtend == null)
  11041. {
  11042. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11043. ceErpTradeAfterSaleExtend.tid = item;
  11044. }
  11045. ceErpTradeAfterSaleExtend.AfterSalSend = 1;
  11046. if (ceErpTradeAfterSaleExtend.ID > 0)
  11047. {
  11048. ceErpTradeAfterSaleExtend.Update();
  11049. }
  11050. else
  11051. {
  11052. ceErpTradeAfterSaleExtend.Create();
  11053. }
  11054. LogHelper.addLog(item, CurrentUser.UserID, "跟单完成", 6, 4);
  11055. }
  11056. catch (Exception ex)
  11057. {
  11058. list.Add(item);
  11059. }
  11060. }
  11061. if (list.Count > 0)
  11062. {
  11063. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  11064. return;
  11065. }
  11066. returnSuccessMsg("修改成功!");
  11067. return;
  11068. }
  11069. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11070. }
  11071. }
  11072. public void aftersale_batch_audit_master()
  11073. {
  11074. if (UrlPostParmsCheck("ctids"))
  11075. {
  11076. string ctids = GetPostString("ctids");
  11077. if (ctids.Length > 0)
  11078. {
  11079. List<string> list = new List<string>();
  11080. string[] ctid_list = ctids.Split(',');
  11081. foreach (var item in ctid_list)
  11082. {
  11083. bool result = aftersale_data_change(item);
  11084. if (!result)
  11085. {
  11086. list.Add(item);
  11087. }
  11088. }
  11089. if (list.Count > 0)
  11090. {
  11091. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  11092. return;
  11093. }
  11094. returnSuccessMsg("修改成功!");
  11095. return;
  11096. }
  11097. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11098. }
  11099. }
  11100. public bool aftersale_data_change(string ctid)
  11101. {
  11102. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11103. if (ceErpTradeCell != null)
  11104. {
  11105. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  11106. ceErpTradeCell.AfterSaleSupplierState = 0;
  11107. StringBuilder sql = new StringBuilder();
  11108. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  11109. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11110. CeErpTradeResponsible.DelByTid(ctid, 0);
  11111. 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 == "不理赔")
  11112. {
  11113. CeErpTradeResponsible.DelByTid(ctid, -1);
  11114. ceErpTradeCell.AfterSaleSupplierState = 1;
  11115. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11116. ceErpTradeCell.AfterSaleState = 4;
  11117. }
  11118. else
  11119. {
  11120. ceErpTradeCell.AfterSaleState = 3;
  11121. }
  11122. bool needCyt = false;
  11123. if (dt != null)
  11124. {
  11125. if (dt.Rows.Count == 1)
  11126. {
  11127. bool isEnd = false;
  11128. foreach (DataRow dr in dt.Rows)
  11129. {
  11130. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  11131. {
  11132. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11133. isEnd = true;
  11134. }
  11135. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  11136. {
  11137. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11138. isEnd = true;
  11139. }
  11140. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11141. {
  11142. needCyt = true;
  11143. }
  11144. }
  11145. if (isEnd)
  11146. {
  11147. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11148. ceErpTradeCell.AfterSaleState = 4;
  11149. ceErpTradeCell.AfterSaleSupplierState = 1;
  11150. }
  11151. }
  11152. else
  11153. {
  11154. bool isAll = true;
  11155. foreach (DataRow dr in dt.Rows)
  11156. {
  11157. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  11158. {
  11159. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11160. continue;
  11161. }
  11162. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  11163. {
  11164. string path = "";
  11165. int OrgID = 0;
  11166. if (!Convert.IsDBNull(dr["OrgPath"]))
  11167. {
  11168. path = dr["OrgPath"].ToString();
  11169. }
  11170. if (!Convert.IsDBNull(dr["OrgID"]))
  11171. {
  11172. OrgID = Convert.ToInt32(dr["OrgID"]);
  11173. }
  11174. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  11175. {
  11176. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11177. continue;
  11178. }
  11179. }
  11180. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11181. {
  11182. needCyt = true;
  11183. }
  11184. isAll = false;
  11185. }
  11186. if (isAll)
  11187. {
  11188. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11189. ceErpTradeCell.AfterSaleState = 4;
  11190. ceErpTradeCell.AfterSaleSupplierState = 1;
  11191. }
  11192. }
  11193. }
  11194. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  11195. {
  11196. commonHelper.sendCytAfterSale(ceErpTradeCell);
  11197. }
  11198. if (ceErpTradeCell.AfterSaleState == 4)
  11199. {
  11200. ApiVo apiVo = new ApiVo();
  11201. apiVo.orderNumber = ceErpTradeCell.ctid;
  11202. apiVo.actionName = "afterOver";
  11203. designHelper.API_WorkCore(apiVo); //afterOver
  11204. }
  11205. ceErpTradeCell.Update();
  11206. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  11207. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  11208. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  11209. return true;
  11210. }
  11211. return false;
  11212. }
  11213. public void get_erp_wechatorder()
  11214. {
  11215. DataStruct dStruct = GetPostStruct();
  11216. List<string> lw = new List<string>();
  11217. string tid = GetPostString("tid");
  11218. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11219. string shopname = GetPostString("shopname");
  11220. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11221. string buyernick = GetPostString("buyer_nick");
  11222. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11223. string customer = GetPostString("customer");
  11224. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11225. string returndate1 = GetPostString("returndate1");
  11226. string returndate2 = GetPostString("returndate2");
  11227. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11228. if (dw.Length > 0) lw.Add(dw);
  11229. string finishDate1 = GetPostString("finishdate1");
  11230. string finishDate2 = GetPostString("finishdate2");
  11231. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11232. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11233. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11234. dStruct.Order = "created desc";
  11235. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11236. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  11237. writeGridDataTableJson(dStruct.TotalCount, dt);
  11238. }
  11239. public void get_erp_wechatlist_sumprice()
  11240. {
  11241. DataStruct dStruct = GetPostStruct();
  11242. List<string> lw = new List<string>();
  11243. string tid = GetPostString("tid");
  11244. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11245. string shopname = GetPostString("shopname");
  11246. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11247. string buyernick = GetPostString("buyer_nick");
  11248. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11249. string customer = GetPostString("customer");
  11250. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11251. string returndate1 = GetPostString("returndate1");
  11252. string returndate2 = GetPostString("returndate2");
  11253. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11254. if (dw.Length > 0) lw.Add(dw);
  11255. string finishDate1 = GetPostString("finishdate1");
  11256. string finishDate2 = GetPostString("finishdate2");
  11257. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11258. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11259. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11260. string mainWhere = string.Join(" and ", lw.ToArray());
  11261. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  11262. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  11263. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  11264. decimal total = 0;
  11265. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  11266. {
  11267. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  11268. }
  11269. var res = new
  11270. {
  11271. data = total
  11272. };
  11273. string ro_jsond = JsonConvert.SerializeObject(res);
  11274. returnSuccess(ro_jsond);
  11275. return;
  11276. }
  11277. public void get_erp_qr_waitdeliverylist()
  11278. {
  11279. DataStruct dStruct = GetPostStruct();
  11280. List<string> lw = new List<string>();
  11281. string tid = GetPostString("ctid");
  11282. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  11283. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11284. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  11285. var res_objz = new
  11286. {
  11287. restype = 1,
  11288. data = dt
  11289. };
  11290. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  11291. returnSuccess(ro_jsonz);
  11292. }
  11293. public void get_erp_yield_list()
  11294. {
  11295. DataStruct dStruct = GetPostStruct();
  11296. List<string> lw = new List<string>();
  11297. string tid = GetPostString("ctid");
  11298. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11299. string shopname = GetPostString("shopname");
  11300. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11301. string buyernick = GetPostString("buyer_nick");
  11302. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11303. //if (tid.Length == 0 && buyernick.Length == 0)
  11304. //{
  11305. // lw.Add(string.Format("IsRefund<={0}", 1));
  11306. //}
  11307. string customer = GetPostString("customer");
  11308. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11309. string design = GetPostString("design");
  11310. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11311. string orderState = GetPostString("orderState");
  11312. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11313. string address = GetPostString("address");
  11314. 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));
  11315. string sellermemo = GetPostString("seller_memo");
  11316. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11317. string supplier = GetPostString("supplier");
  11318. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11319. string OrderArea = GetPostString("order_area");
  11320. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11321. string placedate1 = GetPostString("placedate1");
  11322. string placedate2 = GetPostString("placedate2");
  11323. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11324. if (fdw.Length > 0) lw.Add(fdw);
  11325. string price1 = GetPostString("price1");
  11326. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11327. string price2 = GetPostString("price2");
  11328. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11329. string unusualCon = GetPostString("unusualcon");
  11330. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11331. string posTag = CurrentUser.UserPost.Post.Code;
  11332. if (posTag == "Supplier")
  11333. {
  11334. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11335. }
  11336. lw.Add(string.Format("OrderState = 6 "));
  11337. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11338. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11339. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11340. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11341. writeGridDataTableJson(dStruct.TotalCount, dt);
  11342. }
  11343. public void change_erp_sup_state()
  11344. {
  11345. if (UrlPostParmsCheck("ctid"))
  11346. {
  11347. string ctid = GetPostString("ctid");
  11348. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11349. if (ceErpTradeCell != null)
  11350. {
  11351. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11352. if (ceErpTradeCellExtend == null)
  11353. {
  11354. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11355. ceErpTradeCellExtend.ctid = ctid;
  11356. ceErpTradeCellExtend.SupState = 1;
  11357. ceErpTradeCellExtend.Create();
  11358. }
  11359. else
  11360. {
  11361. ceErpTradeCellExtend.SupState = 1;
  11362. ceErpTradeCellExtend.Update();
  11363. }
  11364. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11365. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11366. return;
  11367. }
  11368. returnErrorMsg("找不到订单");
  11369. }
  11370. }
  11371. public void supplier_all_downs()
  11372. {
  11373. if (UrlPostParmsCheck("tids"))
  11374. {
  11375. string tids = GetPostString("tids");
  11376. if (tids != null && tids.Length > 0)
  11377. {
  11378. StringBuilder sql = new StringBuilder();
  11379. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11380. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11381. sql = new StringBuilder();
  11382. 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, "下载设计文件");
  11383. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11384. string[] list = tids.Split(',');
  11385. foreach (string ctid in list)
  11386. {
  11387. CeErpSukuraData.createInfo(ctid, 3);
  11388. }
  11389. designHelper.api_approveDesign(tids); //approveDesign
  11390. returnSuccessMsg("下载成功!");
  11391. return;
  11392. }
  11393. returnErrorMsg("下载订单更新失败");
  11394. }
  11395. }
  11396. public void uploaderFileSuccess()
  11397. {
  11398. if (UrlPostParmsCheck("fileName"))
  11399. {
  11400. string fileName = GetPostString("fileName");
  11401. ApiVo apiVo = new ApiVo();
  11402. apiVo.orderNumber = fileName;
  11403. apiVo.actionName = "finishDesign";
  11404. designHelper.API_WorkCore(apiVo);//finishDesign
  11405. returnSuccessMsg("");
  11406. }
  11407. }
  11408. public void get_sample2_order()
  11409. {
  11410. if (UrlPostParmsCheck("ctid"))
  11411. {
  11412. string ctid = GetPostString("ctid");
  11413. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11414. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11415. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11416. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11417. double total = 0.0;
  11418. double order_price = 0.0;
  11419. if (dt_bu.Rows.Count > 0)
  11420. {
  11421. foreach (DataRow dr in dt_bu.Rows)
  11422. {
  11423. total += Convert.ToDouble(dr["payment"]);
  11424. }
  11425. }
  11426. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11427. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11428. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11429. string tid = ctid.Replace("S_", "");
  11430. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11431. double paymant = 0.0;
  11432. if (entity != null)
  11433. {
  11434. paymant = entity.payment;
  11435. }
  11436. string return_reason = "";
  11437. if (dt_after != null && dt_after.Rows.Count > 0)
  11438. {
  11439. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11440. }
  11441. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11442. }
  11443. }
  11444. public void get_erp_design_status()
  11445. {
  11446. string designName = GetPostString("designName");
  11447. DataStruct dStruct = GetPostStruct();
  11448. if (designName.Length > 0)
  11449. {
  11450. 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";
  11451. sql_user += " and Name like '%" + designName + "%'";
  11452. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11453. List<string> ids_list = new List<string>();
  11454. if (user_table.Rows.Count > 0)
  11455. {
  11456. foreach (DataRow item in user_table.Rows)
  11457. {
  11458. ids_list.Add(item["id"].ToString());
  11459. string ids_s = item["TeamIds"].ToString();
  11460. if (ids_s.Length > 0)
  11461. {
  11462. ids_list.AddRange(ids_s.Split(','));
  11463. }
  11464. }
  11465. }
  11466. HashSet<string> set = new HashSet<string>(ids_list);
  11467. ids_list = set.ToList();
  11468. if (ids_list.Count > 0)
  11469. {
  11470. 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));
  11471. dStruct.MainWhere = sql;
  11472. DataTable dt = null;
  11473. dt = WebCache.GetData("view_ErpUser", dStruct);
  11474. writeGridDataTableJson(dStruct.TotalCount, dt);
  11475. }
  11476. }
  11477. }
  11478. public void change_erp_order_price()
  11479. {
  11480. string ctid = GetPostString("ctid");
  11481. double price = GetPostDouble("price");
  11482. if (ctid.Length > 0)
  11483. {
  11484. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11485. if (ceErpTradeCellExtend == null)
  11486. {
  11487. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11488. ceErpTradeCellExtend.ctid = ctid;
  11489. ceErpTradeCellExtend.payment_cyt = price;
  11490. ceErpTradeCellExtend.Create();
  11491. }
  11492. else
  11493. {
  11494. ceErpTradeCellExtend.payment_cyt = price;
  11495. ceErpTradeCellExtend.Update();
  11496. }
  11497. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11498. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11499. {
  11500. ceErpDataSendOrderInfo.isSync = false;
  11501. ceErpDataSendOrderInfo.Update();
  11502. }
  11503. if (ceErpDataSendOrderInfo == null)
  11504. {
  11505. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11506. ceErpDataSendOrderInfo.isSync = false;
  11507. ceErpDataSendOrderInfo.ctid = ctid;
  11508. ceErpDataSendOrderInfo.Create();
  11509. }
  11510. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11511. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11512. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11513. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11514. {
  11515. dataSendOrderBean dataSendOrderBean = null;
  11516. foreach (DataRow item in dth.Rows)
  11517. {
  11518. try
  11519. {
  11520. dataSendOrderBean = new dataSendOrderBean();
  11521. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11522. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11523. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11524. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11525. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11526. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11527. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11528. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11529. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11530. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11531. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11532. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11533. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11534. if (result != null)
  11535. {
  11536. if ("0".Equals(result.errcode))
  11537. {
  11538. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11539. }
  11540. else
  11541. {
  11542. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11543. }
  11544. }
  11545. }
  11546. catch (Exception ex)
  11547. {
  11548. }
  11549. }
  11550. }
  11551. returnSuccessMsg("修改成功!");
  11552. return;
  11553. }
  11554. returnErrorMsg("找不到订单");
  11555. }
  11556. public void find_he_together()
  11557. {
  11558. string ctid = GetPostString("ctid");
  11559. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11560. List<string> list = new List<string>();
  11561. if (ceErpTradeCell != null)
  11562. {
  11563. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11564. {
  11565. 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);
  11566. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11567. if (table != null && table.Rows.Count > 0)
  11568. {
  11569. foreach (TableRow row in table.Rows)
  11570. {
  11571. }
  11572. }
  11573. }
  11574. }
  11575. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11576. }
  11577. //不统计
  11578. List<int> no_suppliers = new List<int>()
  11579. {
  11580. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11581. };
  11582. List<int> no_shop = new List<int>()
  11583. {
  11584. 136,114,34,96
  11585. };
  11586. public void get_place_order_data()
  11587. {
  11588. string date1 = GetPostString("date1");
  11589. string date2 = GetPostString("date2");
  11590. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11591. DateTime start = DateTime.Parse(starttime);
  11592. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11593. DateTime end = DateTime.Parse(endtime);
  11594. if (date1 != null && date1.Length > 0)
  11595. {
  11596. DateTime dateTime = DateTime.Parse(date1);
  11597. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11598. start = DateTime.Parse(starttime);
  11599. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11600. end = DateTime.Parse(endtime);
  11601. }
  11602. if (date2 != null && date2.Length > 0)
  11603. {
  11604. DateTime dateTime = DateTime.Parse(date2);
  11605. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11606. end = DateTime.Parse(endtime);
  11607. }
  11608. string startMonthDate = commonHelper.FirstDayOfMonth(DateTime.Now).ToString("yyyy-MM-dd 00:00:00");
  11609. string endMonthDate = commonHelper.LastDayOfMonth(DateTime.Now).ToString("yyyy-MM-dd 23:59:59");
  11610. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,UnusualTime,FinishPlaceTime,OrderState,FinishDeliveryTime,AfterSaleState=0,AfterSaleReason = '',delivery=0,shopId,UnusualTag from view_ErpTradeCell where ( ( FinishPlaceTime BETWEEN '{0}' AND '{1}' ) OR ( OrderState = 6 AND UnusualTag = 5 AND IsRefund <= 1 ) ) AND IsSample = 0 and SupplierId > 0 ", starttime, endtime);
  11611. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11612. sql = string.Format("SELECT SupplierId, ProductId, seller_memo, ProductCount, ProductName, payment, SupplierName, UnusualTime, FinishPlaceTime, OrderState, FinishDeliveryTime, AfterSaleState,AfterSaleReason,delivery=0,shopId,UnusualTag FROM view_ErpTradeCell WHERE ( HandleTime BETWEEN '{0}' AND '{1}' ) AND IsSample = 0 AND SupplierId > 0 AND FinishPlaceTime IS NOT NULL", startMonthDate, endMonthDate);
  11613. DataTable afterSaleData = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11614. data.Merge(afterSaleData);
  11615. sql = string.Format("SELECT SupplierId, ProductId, seller_memo, ProductCount, ProductName, payment, SupplierName, UnusualTime, FinishPlaceTime, OrderState, FinishDeliveryTime, AfterSaleState=0,AfterSaleReason = '',delivery=1,shopId,UnusualTag FROM view_ErpTradeCell WHERE orderstate = 6 AND IsSample = 0 AND SupplierId > 0 AND FinishPlaceTime > '2025-11-01 00:00:31.000' AND IsRefund <= 1 AND LEN( ProductName ) > 0 AND SupplierId not in (86,10,105,86)", startMonthDate, endMonthDate);
  11616. DataTable deliveryData = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11617. data.Merge(deliveryData);
  11618. //不干胶-----1,卡片-----29
  11619. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11620. foreach (DataRow row in data.Rows)
  11621. {
  11622. int productId = Convert.ToInt32(row["ProductId"]);
  11623. int shopId = Convert.ToInt32(row["shopId"]);
  11624. string ProductName = row["ProductName"].ToString();
  11625. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11626. if (no_suppliers.Contains(supplierId))
  11627. {
  11628. continue;
  11629. }
  11630. string seller_memo = row["seller_memo"].ToString();
  11631. bool ispj = commonHelper.placeDataIsPeijian(seller_memo);//是否配件单
  11632. if (ispj)
  11633. {
  11634. continue;
  11635. }
  11636. seller_memo = seller_memo.Replace("UV", "uv");
  11637. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11638. //吊牌归到卡片
  11639. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11640. seller_memo = seller_memo.Replace("卡套", "卡片");
  11641. seller_memo = seller_memo.Replace("封套", "卡片");
  11642. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11643. seller_memo = seller_memo.Replace("腰封", "卡片");
  11644. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11645. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11646. seller_memo = seller_memo.Replace("横幅", "条幅");
  11647. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11648. string map_key = commonHelper.placeDataGetMapKey(seller_memo, supplierId);
  11649. string type = commonHelper.placeDataGetMapKey(seller_memo, supplierId);
  11650. if (map_key == "")
  11651. {
  11652. type = ProductName;
  11653. map_key = ProductName;
  11654. }
  11655. if ("其他".Equals(map_key) && commonHelper.suppliers.ContainsKey(supplierId))
  11656. {
  11657. map_key = commonHelper.suppliers[supplierId];
  11658. }
  11659. map_key += "_" + row["SupplierName"].ToString();
  11660. Dictionary<string, int> map = null;
  11661. if (other_map.ContainsKey(map_key))
  11662. {
  11663. other_map.TryGetValue(map_key, out map);
  11664. }
  11665. else
  11666. {
  11667. map = new Dictionary<string, int>();
  11668. map.Add("dayDev", 0);//当天出货
  11669. map.Add("dayTotal", 0);//下单总数
  11670. map.Add("payTotal", 0);//500以上
  11671. map.Add("today", 0);//当天出货数量
  11672. map.Add("unusua", 0);//异常数
  11673. map.Add("aftersale", 0);//异常数
  11674. map.Add("deliveryNum", 0);//待发货数
  11675. other_map.Add(map_key, map);
  11676. other_map.TryGetValue(map_key, out map);
  11677. }
  11678. int afterSaleState = Convert.ToInt32(row["AfterSaleState"]);
  11679. int delivery = Convert.ToInt32(row["delivery"]);
  11680. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11681. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11682. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11683. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11684. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11685. //GD-CYT-----64
  11686. bool istoday = commonHelper.placeDataIsToday(row, type);
  11687. if (afterSaleState == 0 && delivery == 0)
  11688. {
  11689. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11690. {
  11691. map["dayTotal"]++;
  11692. }
  11693. if (Convert.ToDecimal(row["payment"]) >= 500)
  11694. {
  11695. map["payTotal"]++;
  11696. }
  11697. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11698. {
  11699. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11700. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11701. {
  11702. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11703. {
  11704. map["today"]++;
  11705. }
  11706. }
  11707. else
  11708. {
  11709. if (supplierId == 80 || supplierId == 126)
  11710. {
  11711. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11712. {
  11713. map["today"]++;
  11714. }
  11715. }
  11716. else if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11717. {
  11718. map["today"]++;
  11719. }
  11720. }
  11721. }
  11722. if (istoday)
  11723. {
  11724. map["dayDev"]++;
  11725. }
  11726. }
  11727. else if (delivery == 0)
  11728. {
  11729. if (row["AfterSaleReason"].ToString().Contains("车间责任"))
  11730. {
  11731. map["aftersale"]++;
  11732. }
  11733. }
  11734. else
  11735. {
  11736. map["deliveryNum"]++;
  11737. if (no_shop.Contains(shopId))
  11738. {
  11739. continue;
  11740. }
  11741. if (!Convert.IsDBNull(row["UnusualTag"]) && Convert.ToInt32(row["UnusualTag"]) == 5)
  11742. {
  11743. map["unusua"]++;
  11744. }
  11745. continue;
  11746. }
  11747. }
  11748. DataTable dt = new DataTable();
  11749. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11750. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11751. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11752. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11753. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11754. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11755. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11756. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11757. dt.Columns.Add(new DataColumn("aftersale", typeof(string)));
  11758. dt.Columns.Add(new DataColumn("deliveryNum", typeof(string)));
  11759. other_map.Keys.ForEach(key =>
  11760. {
  11761. DataRow dr = dt.NewRow();
  11762. Dictionary<string, int> map = other_map[key];
  11763. string[] key_list = key.Split('_');
  11764. dr[0] = key_list[0];
  11765. dr[1] = key_list[1];
  11766. if (key_list.Length > 2)
  11767. {
  11768. dr[1] += "(" + key_list[2] + ")";
  11769. }
  11770. dr[2] = map["dayTotal"];
  11771. dr[3] = map["payTotal"];
  11772. dr[4] = map["today"];
  11773. dr[5] = map["unusua"];
  11774. dr[6] = map["dayDev"];
  11775. double rate = 0.00;
  11776. if (map["dayDev"] > 0)
  11777. {
  11778. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11779. }
  11780. dr[7] = rate.ToString();
  11781. dr[8] = map["aftersale"];
  11782. dr[9] = map["deliveryNum"];
  11783. dt.Rows.Add(dr);
  11784. });
  11785. DataView dv = new DataView(dt);
  11786. dv.Sort = "SupplierName";
  11787. //dv.Sort = "ProductName desc";
  11788. DataTable dtNew = dv.ToTable();
  11789. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11790. }
  11791. public void get_place_all_order_data()
  11792. {
  11793. string date1 = GetPostString("date1");
  11794. string date2 = GetPostString("date2");
  11795. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11796. DateTime start = DateTime.Parse(starttime);
  11797. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11798. DateTime end = DateTime.Parse(endtime);
  11799. if (date1 != null && date1.Length > 0)
  11800. {
  11801. DateTime dateTime = DateTime.Parse(date1);
  11802. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11803. start = DateTime.Parse(starttime);
  11804. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11805. end = DateTime.Parse(endtime);
  11806. }
  11807. if (date2 != null && date2.Length > 0)
  11808. {
  11809. DateTime dateTime = DateTime.Parse(date2);
  11810. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11811. end = DateTime.Parse(endtime);
  11812. }
  11813. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11814. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,FinishPlaceTime,OrderState,FinishDeliveryTime from view_ErpTradeCell where ( FinishDeliveryTime BETWEEN '{0}' AND '{1}' ) AND IsSample = 0 and SupplierId > 0 ", starttime, endtime);
  11815. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11816. string timer_sql = string.Format("select * from CE_ErpSupplierProductTime");
  11817. DataTable timer_data = DbHelper.DbConn.ExecuteDataset(timer_sql).Tables[0];
  11818. Dictionary<int, List<CeErpSupplierProductTime>> timer_map = new Dictionary<int, List<CeErpSupplierProductTime>>();
  11819. foreach (DataRow datarow in timer_data.Rows)
  11820. {
  11821. List<CeErpSupplierProductTime> list = null;
  11822. int supplierId = Convert.ToInt32(datarow["SupplierId"]);
  11823. if (timer_map.ContainsKey(supplierId))
  11824. {
  11825. timer_map.TryGetValue(supplierId, out list);
  11826. }
  11827. else
  11828. {
  11829. list = new List<CeErpSupplierProductTime>();
  11830. timer_map.Add(supplierId, list);
  11831. timer_map.TryGetValue(supplierId, out list);
  11832. }
  11833. CeErpSupplierProductTime ceErpSupplierProductTime = new CeErpSupplierProductTime();
  11834. ceErpSupplierProductTime.quantity = Convert.ToInt32(datarow["quantity"]);
  11835. ceErpSupplierProductTime.dayDeadLine = datarow["dayDeadLine"].ToString();
  11836. ceErpSupplierProductTime.deadLine = datarow["deadLine"].ToString();
  11837. ceErpSupplierProductTime.productId = datarow["productId"].ToString();
  11838. ceErpSupplierProductTime.craft = datarow["craft"].ToString();
  11839. ceErpSupplierProductTime.sendDay = Convert.ToInt32(datarow["sendDay"]);
  11840. list.Add(ceErpSupplierProductTime);
  11841. }
  11842. foreach (DataRow row in data.Rows)
  11843. {
  11844. //存储数据
  11845. int productId = Convert.ToInt32(row["ProductId"]);
  11846. string ProductName = row["ProductName"].ToString();
  11847. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11848. if (no_suppliers.Contains(supplierId))
  11849. {
  11850. continue;
  11851. }
  11852. string seller_memo = row["seller_memo"].ToString();
  11853. bool ispj = commonHelper.placeDataIsPeijian(seller_memo);//是否配件单
  11854. if (ispj)
  11855. {
  11856. continue;
  11857. }
  11858. seller_memo = seller_memo.Replace("UV", "uv");
  11859. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11860. //吊牌归到卡片
  11861. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11862. seller_memo = seller_memo.Replace("卡套", "卡片");
  11863. seller_memo = seller_memo.Replace("封套", "卡片");
  11864. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11865. seller_memo = seller_memo.Replace("腰封", "卡片");
  11866. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11867. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11868. seller_memo = seller_memo.Replace("横幅", "条幅");
  11869. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11870. string map_key = commonHelper.placeDataGetMapKey(seller_memo, supplierId);
  11871. string type = commonHelper.placeDataGetMapKey(seller_memo, supplierId);
  11872. if (map_key == "")
  11873. {
  11874. type = ProductName;
  11875. map_key = ProductName;
  11876. }
  11877. if ("其他".Equals(map_key) && commonHelper.suppliers.ContainsKey(supplierId))
  11878. {
  11879. map_key = commonHelper.suppliers[supplierId];
  11880. }
  11881. map_key += "_" + row["SupplierName"].ToString();
  11882. Dictionary<string, int> map = null;
  11883. if (other_map.ContainsKey(map_key))
  11884. {
  11885. other_map.TryGetValue(map_key, out map);
  11886. }
  11887. else
  11888. {
  11889. map = new Dictionary<string, int>();
  11890. map.Add("all", 0);//全部
  11891. map.Add("unusua", 0);//异常数
  11892. map.Add("normal", 0);//正常数
  11893. map.Add("noMatch", 0);//未匹配
  11894. other_map.Add(map_key, map);
  11895. other_map.TryGetValue(map_key, out map);
  11896. }
  11897. //处理是否超时
  11898. string finishPlaceTime = row["FinishPlaceTime"].ToString();
  11899. string sellmer_mome = row["seller_memo"].ToString();
  11900. string txtCount = row["ProductCount"].ToString();
  11901. string FinishDeliveryTime = row["FinishDeliveryTime"].ToString();
  11902. map["all"]++;
  11903. if (string.IsNullOrEmpty(finishPlaceTime))
  11904. {
  11905. map["noMatch"]++;
  11906. continue;
  11907. }
  11908. if (string.IsNullOrEmpty(FinishDeliveryTime))
  11909. {
  11910. map["noMatch"]++;
  11911. continue;
  11912. }
  11913. if (!timer_map.ContainsKey(supplierId))
  11914. {
  11915. map["noMatch"]++;
  11916. continue;
  11917. }
  11918. List<CeErpSupplierProductTime> lists = timer_map[supplierId];
  11919. if (lists.Count > 0)
  11920. {
  11921. bool isComplate = false;
  11922. string[] productIds = null;
  11923. foreach (CeErpSupplierProductTime ceErpSupplierProductTime in lists)
  11924. {
  11925. string[] crafts = { };
  11926. if (string.IsNullOrEmpty(ceErpSupplierProductTime.productId))
  11927. {
  11928. continue;
  11929. }
  11930. if (ceErpSupplierProductTime.quantity > 0)
  11931. {
  11932. int quantity = commonHelper.handleProductCount(txtCount, true);
  11933. //订单数量大于写入的数量则跳过
  11934. if (quantity > ceErpSupplierProductTime.quantity)
  11935. {
  11936. continue;
  11937. }
  11938. }
  11939. productIds = ceErpSupplierProductTime.productId.Split(',');
  11940. if (productIds.Contains(productId.ToString()))
  11941. {
  11942. string textCraft = ceErpSupplierProductTime.craft;
  11943. textCraft = textCraft.Replace(",", ",");//统一格式
  11944. if (!string.IsNullOrEmpty(textCraft))
  11945. {
  11946. crafts = textCraft.Split(',');
  11947. }
  11948. if (crafts.Length > 0)
  11949. {
  11950. bool isinCraft = false;
  11951. for (int i = 0; i < crafts.Length; i++)
  11952. {
  11953. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  11954. {
  11955. isinCraft = true;
  11956. break;
  11957. }
  11958. }
  11959. //有写工艺并且备注中没匹配中则跳过
  11960. if (!isinCraft)
  11961. {
  11962. continue;
  11963. }
  11964. }
  11965. DateTime deadLine = DateTime.Parse(ceErpSupplierProductTime.deadLine);
  11966. DateTime dayDeadLine = DateTime.Parse(ceErpSupplierProductTime.dayDeadLine);
  11967. int sendDay = ceErpSupplierProductTime.sendDay;
  11968. //订单发货时间
  11969. DateTime placeTime = DateTime.Parse(finishPlaceTime);
  11970. DateTime sendtime = DateTime.Now;//预计发货时间
  11971. DateTime dateTime = DateTime.Parse(FinishDeliveryTime);//实际发货时间
  11972. //下单时间小于当日发货时间则不用判断
  11973. //当日发货必须发货
  11974. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  11975. {
  11976. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59"));
  11977. }
  11978. else if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  11979. {
  11980. //在截稿时间之前下单的可以减去一天时间
  11981. sendDay = Math.Max(1, sendDay - 1);
  11982. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 00:00:00")).AddDays(sendDay);
  11983. }
  11984. else
  11985. {
  11986. sendDay = Math.Max(1, sendDay - 1);
  11987. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59")).AddDays(sendDay);
  11988. }
  11989. isComplate = true;
  11990. //判断有没有到发货日期大于0还没到发货时间
  11991. if (DateTime.Compare(sendtime.Date, dateTime.Date) < 0)
  11992. {
  11993. //匹配到就不要继续匹配了
  11994. map["unusua"]++;
  11995. break;
  11996. }
  11997. else
  11998. {
  11999. map["normal"]++;
  12000. break;
  12001. }
  12002. }
  12003. }
  12004. if (!isComplate)
  12005. {
  12006. map["noMatch"]++;
  12007. continue;
  12008. }
  12009. }
  12010. else
  12011. {
  12012. map["noMatch"]++;
  12013. }
  12014. }
  12015. DataTable dt = new DataTable();
  12016. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  12017. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  12018. dt.Columns.Add(new DataColumn("all", typeof(string)));
  12019. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  12020. dt.Columns.Add(new DataColumn("normal", typeof(string)));
  12021. dt.Columns.Add(new DataColumn("noMatch", typeof(string)));
  12022. dt.Columns.Add(new DataColumn("shipmentRate", typeof(string)));
  12023. other_map.Keys.ForEach(key =>
  12024. {
  12025. DataRow dr = dt.NewRow();
  12026. Dictionary<string, int> map = other_map[key];
  12027. string[] key_list = key.Split('_');
  12028. dr[0] = key_list[0];
  12029. dr[1] = key_list[1];
  12030. if (key_list.Length > 2)
  12031. {
  12032. dr[1] += "(" + key_list[2] + ")";
  12033. }
  12034. dr[2] = map["all"];
  12035. dr[3] = map["unusua"];
  12036. dr[4] = map["normal"];
  12037. dr[5] = map["noMatch"];
  12038. double rate = 0.00;
  12039. if (map["all"] > 0)
  12040. {
  12041. rate = Math.Round(((Convert.ToDouble(map["normal"]) + Convert.ToDouble(map["noMatch"])) / Convert.ToDouble(map["all"])), 2) * 100;
  12042. }
  12043. dr[6] = rate.ToString();
  12044. dt.Rows.Add(dr);
  12045. });
  12046. DataView dv = new DataView(dt);
  12047. dv.Sort = "SupplierName";
  12048. //dv.Sort = "ProductName desc";
  12049. DataTable dtNew = dv.ToTable();
  12050. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  12051. }
  12052. public void check_order_desing_info()
  12053. {
  12054. string ctid = GetPostString("ctid");
  12055. if (!string.IsNullOrEmpty(ctid))
  12056. {
  12057. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12058. if (ceErpTradeCell != null)
  12059. {
  12060. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  12061. returnSuccess(JsonConvert.SerializeObject(new { response }));
  12062. return;
  12063. }
  12064. returnErrorMsg("找不到订单");
  12065. return;
  12066. }
  12067. returnErrorMsg("找不到订单");
  12068. }
  12069. public void get_timeout_detail()
  12070. {
  12071. string poscode = CurrentUser.UserPost.Post.Code;
  12072. DataStruct dStruct = GetPostStruct();
  12073. List<string> lw = new List<string>();
  12074. string id = GetPostString("id");
  12075. string pay_date1 = GetPostString("pay_date1");
  12076. string pay_date2 = GetPostString("pay_date2");
  12077. int type = GetPostInt("type");
  12078. if (type == 0)
  12079. {
  12080. if (pay_date1.Length > 0)
  12081. {
  12082. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  12083. }
  12084. if (pay_date2.Length > 0)
  12085. {
  12086. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  12087. }
  12088. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  12089. }
  12090. if (type == 1)
  12091. {
  12092. if (pay_date1.Length > 0)
  12093. {
  12094. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  12095. }
  12096. if (pay_date2.Length > 0)
  12097. {
  12098. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  12099. }
  12100. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  12101. }
  12102. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12103. DataTable dt = null;
  12104. dt = WebCache.GetData("view_orderlist", dStruct);
  12105. writeGridDataTableJson(dStruct.TotalCount, dt);
  12106. }
  12107. public void saveUrgentChargePrice()
  12108. {
  12109. string ctid = GetPostString("ctid");
  12110. if (!string.IsNullOrEmpty(ctid))
  12111. {
  12112. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12113. if (ceErpTradeCell != null)
  12114. {
  12115. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  12116. if (prices <= 100)
  12117. {
  12118. returnErrorMsg("此订单金额不足100元,无法加急。");
  12119. return;
  12120. }
  12121. double price = GetPostDouble("price");
  12122. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  12123. if (ceErpTradeCellExtend == null)
  12124. {
  12125. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12126. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  12127. }
  12128. ceErpTradeCellExtend.urgentCharge = price;
  12129. if (ceErpTradeCellExtend.ID > 0)
  12130. {
  12131. ceErpTradeCellExtend.Update();
  12132. }
  12133. else
  12134. {
  12135. ceErpTradeCellExtend.Save();
  12136. }
  12137. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  12138. returnSuccessMsg("修改成功!");
  12139. return;
  12140. }
  12141. returnErrorMsg("找不到订单");
  12142. return;
  12143. }
  12144. returnErrorMsg("找不到订单");
  12145. }
  12146. public void finish_erp_order()
  12147. {
  12148. string ctid = GetPostString("ctid");
  12149. if (!string.IsNullOrEmpty(ctid))
  12150. {
  12151. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  12152. {
  12153. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12154. if (ceErpTradeCell != null)
  12155. {
  12156. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  12157. ceErpTradeCell.Update();
  12158. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  12159. returnSuccessMsg("修改成功!");
  12160. return;
  12161. }
  12162. }
  12163. }
  12164. returnErrorMsg("找不到订单");
  12165. }
  12166. public void get_trade_order_list()
  12167. {
  12168. string tid = GetPostString("tid");
  12169. if (!string.IsNullOrEmpty(tid))
  12170. {
  12171. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  12172. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12173. writeGridDataTableJson(data.Rows.Count, data);
  12174. return;
  12175. }
  12176. returnErrorMsg("找不到订单");
  12177. }
  12178. public void save_cell_spu()
  12179. {
  12180. string ctid = GetPostString("ctid");
  12181. string spu_id = GetPostString("spu_id");
  12182. if (!string.IsNullOrEmpty(ctid))
  12183. {
  12184. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12185. if (ceErpTradeCellExtend == null)
  12186. {
  12187. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12188. ceErpTradeCellExtend.ctid = ctid;
  12189. }
  12190. ceErpTradeCellExtend.spu_id = spu_id;
  12191. if (!string.IsNullOrEmpty(spu_id))
  12192. {
  12193. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12194. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  12195. }
  12196. if (ceErpTradeCellExtend.ID == 0)
  12197. {
  12198. ceErpTradeCellExtend.Create();
  12199. }
  12200. else
  12201. {
  12202. ceErpTradeCellExtend.Update();
  12203. }
  12204. returnSuccessMsg("修改成功!");
  12205. return;
  12206. }
  12207. returnErrorMsg("找不到订单");
  12208. }
  12209. public void change_express_info()
  12210. {
  12211. string ctid = GetPostString("ctid");
  12212. string transNo = GetPostString("transNo");
  12213. string transCom = GetPostString("transCom");
  12214. if (!string.IsNullOrEmpty(ctid))
  12215. {
  12216. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12217. if (ceErpTradeCellExtend == null)
  12218. {
  12219. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12220. ceErpTradeCellExtend.ctid = ctid;
  12221. }
  12222. ceErpTradeCellExtend.modExpressNo = transNo;
  12223. ceErpTradeCellExtend.modExpressCom = transCom;
  12224. ceErpTradeCellExtend.readMod = 2;
  12225. if (ceErpTradeCellExtend.ID == 0)
  12226. {
  12227. ceErpTradeCellExtend.Create();
  12228. }
  12229. else
  12230. {
  12231. ceErpTradeCellExtend.Update();
  12232. }
  12233. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  12234. returnSuccessMsg("修改成功!");
  12235. return;
  12236. }
  12237. returnErrorMsg("找不到订单");
  12238. }
  12239. public void get_change_express_list()
  12240. {
  12241. DataStruct dStruct = GetPostStruct();
  12242. List<string> lw = new List<string>();
  12243. int st = 2;
  12244. string tid = GetPostString("ctid");
  12245. if (tid.Length > 0)
  12246. {
  12247. string select_tid = getTidByCtid(tid);
  12248. lw.Add(string.Format("tid='{0}'", select_tid));
  12249. }
  12250. string shopname = GetPostString("shopname");
  12251. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12252. string buyernick = GetPostString("buyer_nick");
  12253. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12254. string sellermemo = GetPostString("seller_memo");
  12255. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12256. string supplier = GetPostString("supplier");
  12257. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12258. string customer = GetPostString("customer");
  12259. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12260. string design = GetPostString("design");
  12261. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12262. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12263. string poscode = CurrentUser.UserPost.Post.Code;
  12264. if (poscode != "SysAdmin")
  12265. {
  12266. string shopid = CurrentUser.User.pemShop;
  12267. lw.Add(string.Format("shopId in ({0})", shopid));
  12268. }
  12269. lw.Add("readMod = 2");
  12270. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12271. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  12272. writeGridDataTableJson(dStruct.TotalCount, dt);
  12273. }
  12274. public void deal_express_complete()
  12275. {
  12276. string ctid = GetPostString("ctid");
  12277. if (!string.IsNullOrEmpty(ctid))
  12278. {
  12279. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12280. if (ceErpTradeCellExtend == null)
  12281. {
  12282. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12283. ceErpTradeCellExtend.ctid = ctid;
  12284. }
  12285. ceErpTradeCellExtend.readMod = 1;
  12286. if (ceErpTradeCellExtend.ID == 0)
  12287. {
  12288. ceErpTradeCellExtend.Create();
  12289. }
  12290. else
  12291. {
  12292. ceErpTradeCellExtend.Update();
  12293. }
  12294. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  12295. returnSuccessMsg("修改成功!");
  12296. return;
  12297. }
  12298. returnErrorMsg("找不到订单");
  12299. }
  12300. public void aftersale_return_visit()
  12301. {
  12302. string ctid = GetPostString("ctid");
  12303. if (!string.IsNullOrEmpty(ctid))
  12304. {
  12305. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12306. if (ceErpTradeCellExtend == null)
  12307. {
  12308. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12309. ceErpTradeCellExtend.ctid = ctid;
  12310. }
  12311. ceErpTradeCellExtend.returnVisit = 1;
  12312. if (ceErpTradeCellExtend.ID == 0)
  12313. {
  12314. ceErpTradeCellExtend.Create();
  12315. }
  12316. else
  12317. {
  12318. ceErpTradeCellExtend.Update();
  12319. }
  12320. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12321. if (ceErpTradeAfterSaleExtend != null)
  12322. {
  12323. ceErpTradeAfterSaleExtend.TextResult = "";
  12324. ceErpTradeAfterSaleExtend.Update();
  12325. }
  12326. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  12327. returnSuccessMsg("修改成功!");
  12328. return;
  12329. }
  12330. returnErrorMsg("找不到订单");
  12331. }
  12332. public void orderPlaceInfo()
  12333. {
  12334. string ctids = GetPostString("ctids");
  12335. string[] list = ctids.Split(',');
  12336. foreach (string ctid in list)
  12337. {
  12338. CeErpSukuraData.createInfo(ctid, 3);
  12339. }
  12340. StringBuilder sql = new StringBuilder();
  12341. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  12342. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  12343. designHelper.api_approveDesign(ctids); //approveDesign
  12344. returnSuccessMsg("");
  12345. }
  12346. public void get_issue_list()
  12347. {
  12348. DataStruct dStruct = GetPostStruct();
  12349. List<string> lw = new List<string>();
  12350. int st = 2;
  12351. string tid = GetPostString("ctid");
  12352. if (tid.Length > 0)
  12353. {
  12354. string select_tid = getTidByCtid(tid);
  12355. lw.Add(string.Format("tid='{0}'", select_tid));
  12356. }
  12357. string shopname = GetPostString("shopname");
  12358. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12359. string buyernick = GetPostString("buyer_nick");
  12360. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12361. string sellermemo = GetPostString("seller_memo");
  12362. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12363. string supplier = GetPostString("supplier");
  12364. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12365. string customer = GetPostString("customer");
  12366. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12367. string design = GetPostString("design");
  12368. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12369. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12370. string poscode = CurrentUser.UserPost.Post.Code;
  12371. if (poscode != "SysAdmin")
  12372. {
  12373. string shopid = CurrentUser.User.pemShop;
  12374. lw.Add(string.Format("shopId in ({0})", shopid));
  12375. }
  12376. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  12377. {
  12378. lw.Add("IssueState = 1");
  12379. }
  12380. else
  12381. {
  12382. string iisstate = GetPostString("iisstate");
  12383. if ("1".Equals(iisstate))
  12384. {
  12385. lw.Add("IssueState =1");
  12386. }
  12387. else if ("2".Equals(iisstate))
  12388. {
  12389. lw.Add("IssueState = 2");
  12390. }
  12391. else
  12392. {
  12393. lw.Add("IssueState > 0");
  12394. }
  12395. }
  12396. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12397. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  12398. writeGridDataTableJson(dStruct.TotalCount, dt);
  12399. }
  12400. public void saveIssueContent()
  12401. {
  12402. string ctid = GetPostString("ctid");
  12403. if (!string.IsNullOrEmpty(ctid))
  12404. {
  12405. string content = GetPostString("content");
  12406. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12407. if (ceErpTradeAfterSaleExtend == null)
  12408. {
  12409. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  12410. ceErpTradeAfterSaleExtend.tid = ctid;
  12411. }
  12412. ceErpTradeAfterSaleExtend.IssueContent = content;
  12413. ceErpTradeAfterSaleExtend.IssueState = 1;
  12414. if (ceErpTradeAfterSaleExtend.ID > 0)
  12415. {
  12416. ceErpTradeAfterSaleExtend.Update();
  12417. }
  12418. else
  12419. {
  12420. ceErpTradeAfterSaleExtend.Create();
  12421. }
  12422. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  12423. returnSuccessMsg("添加成功!");
  12424. return;
  12425. }
  12426. returnErrorMsg("找不到订单");
  12427. }
  12428. public void dealIssueContent()
  12429. {
  12430. string ctid = GetPostString("ctid");
  12431. if (!string.IsNullOrEmpty(ctid))
  12432. {
  12433. string content = GetPostString("content");
  12434. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12435. if (ceErpTradeAfterSaleExtend != null)
  12436. {
  12437. ceErpTradeAfterSaleExtend.IssueState = 2;
  12438. ceErpTradeAfterSaleExtend.Update();
  12439. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  12440. returnSuccessMsg("修改完成!");
  12441. return;
  12442. }
  12443. }
  12444. returnErrorMsg("找不到订单");
  12445. }
  12446. public void set_tid_attachments()
  12447. {
  12448. string tid = GetPostString("tid");
  12449. string atta = GetPostString("atta");
  12450. if (!string.IsNullOrEmpty(tid))
  12451. {
  12452. if (string.IsNullOrEmpty(atta))
  12453. {
  12454. returnErrorMsg("文件地址为空");
  12455. return;
  12456. }
  12457. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12458. if (ceErpTradeCell != null)
  12459. {
  12460. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12461. if (ceErpTrade == null)
  12462. {
  12463. returnErrorMsg("找不到订单");
  12464. return;
  12465. }
  12466. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12467. bool isSend = false;
  12468. if (dt != null && dt.Rows.Count > 0)
  12469. {
  12470. foreach (DataRow row in dt.Rows)
  12471. {
  12472. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12473. {
  12474. isSend = true;
  12475. }
  12476. }
  12477. if (isSend)
  12478. {
  12479. returnErrorMsg("已发货无法修改");
  12480. return;
  12481. }
  12482. ceErpTrade.Attachments = atta;
  12483. ceErpTrade.Update();
  12484. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12485. returnSuccessMsg("上传成功!");
  12486. return;
  12487. }
  12488. }
  12489. }
  12490. returnErrorMsg("找不到订单");
  12491. }
  12492. public void get_tid_attachments()
  12493. {
  12494. string tid = GetPostString("tid");
  12495. if (!string.IsNullOrEmpty(tid))
  12496. {
  12497. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12498. if (ceErpTradeCell != null)
  12499. {
  12500. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12501. if (ceErpTrade == null)
  12502. {
  12503. returnErrorMsg("找不到订单");
  12504. return;
  12505. }
  12506. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12507. return;
  12508. }
  12509. }
  12510. returnErrorMsg("找不到订单");
  12511. }
  12512. public void check_erp_sameorders()
  12513. {
  12514. if (UrlPostParmsCheck("ctid"))
  12515. {
  12516. string eid = GetPostString("ctid");
  12517. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12518. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12519. if (entity != null && ceErpTrade != null)
  12520. {
  12521. if (entity.OrderState > 6)
  12522. {
  12523. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12524. return;
  12525. }
  12526. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12527. List<string> ids = new List<string>();
  12528. if (dt != null && dt.Rows.Count > 1)
  12529. {
  12530. bool needhe = true;
  12531. foreach (DataRow dr in dt.Rows)
  12532. {
  12533. ids.Add("'" + dr["ctid"] + "'");
  12534. /* //备注有合包
  12535. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12536. {
  12537. needhe = true;
  12538. }
  12539. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12540. {
  12541. needhe = true;
  12542. }
  12543. //顺丰快递
  12544. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12545. {
  12546. needhe = true;
  12547. }*/
  12548. }
  12549. if (!needhe)
  12550. {
  12551. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12552. return;
  12553. }
  12554. StringBuilder sql = new StringBuilder();
  12555. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12556. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12557. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12558. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12559. foreach (DataRow dr in dt.Rows)
  12560. {
  12561. dr["dstate"] = 0;
  12562. dr["dnumber"] = 0;
  12563. foreach (DataRow row in dt1.Rows)
  12564. {
  12565. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12566. {
  12567. dr["dstate"] = 2;
  12568. dr["default"] = 1;
  12569. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12570. }
  12571. }
  12572. if (eid.Equals(dr["ctid"].ToString()))
  12573. {
  12574. dr["dstate"] = 1;
  12575. dr["default"] = 1;
  12576. }
  12577. }
  12578. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12579. return;
  12580. }
  12581. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12582. return;
  12583. }
  12584. returnErrorMsg("未找到订单");
  12585. return;
  12586. }
  12587. returnErrorMsg("缺少必要的参数");
  12588. }
  12589. public void get_mark_number()
  12590. {
  12591. string eid = GetPostString("ctid");
  12592. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12593. if (entity != null)
  12594. {
  12595. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12596. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12597. int current = 1;
  12598. if (ceErpDeliverMark == null)
  12599. {
  12600. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12601. List<string> ids = new List<string>();
  12602. if (dt != null && dt.Rows.Count > 1)
  12603. {
  12604. foreach (DataRow dr in dt.Rows)
  12605. {
  12606. ids.Add("'" + dr["ctid"] + "'");
  12607. }
  12608. //查询已有的编号
  12609. StringBuilder sql = new StringBuilder();
  12610. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12611. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12612. if (dt1 == null || dt1.Rows.Count == 0)
  12613. {
  12614. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12615. List<int> list_number = new List<int>();
  12616. foreach (DataRow row in numbers.Rows)
  12617. {
  12618. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12619. }
  12620. //查询空余编号
  12621. for (int i = 0; i < list_number.Count + 2; i++)
  12622. {
  12623. if (!list_number.Contains(current))
  12624. {
  12625. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12626. //防止查询过程中有新数据生成
  12627. if (ceErpDeliverMark1 == null)
  12628. {
  12629. break;
  12630. }
  12631. }
  12632. current++;
  12633. }
  12634. }
  12635. else
  12636. {
  12637. foreach (DataRow row in dt1.Rows)
  12638. {
  12639. current = Convert.ToInt32(row["markNumber"]);
  12640. }
  12641. }
  12642. ceErpDeliverMark = new CeErpDeliverMark();
  12643. ceErpDeliverMark.ctid = eid;
  12644. ceErpDeliverMark.createtime = DateTime.Now;
  12645. if (ceErpTrade != null)
  12646. {
  12647. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12648. }
  12649. ceErpDeliverMark.markNumber = current;
  12650. ceErpDeliverMark.Create();
  12651. }
  12652. }
  12653. else
  12654. {
  12655. current = ceErpDeliverMark.markNumber;
  12656. }
  12657. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12658. return;
  12659. }
  12660. }
  12661. public void aftersaleCytSend()
  12662. {
  12663. string ctid = GetPostString("ctid");
  12664. if (!string.IsNullOrEmpty(ctid))
  12665. {
  12666. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12667. if (ceErpTradeCell != null)
  12668. {
  12669. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12670. }
  12671. returnSuccessMsg("推送成功");
  12672. return;
  12673. }
  12674. returnErrorMsg("缺少必要的参数");
  12675. }
  12676. public void packOrderInfo()
  12677. {
  12678. string ctids = GetPostString("ctids");
  12679. if (!string.IsNullOrEmpty(ctids))
  12680. {
  12681. string[] ctid_list = ctids.Split(',');
  12682. if (ctid_list.Length > 100)
  12683. {
  12684. returnErrorMsg("单次下载次数不能超过100个");
  12685. return;
  12686. }
  12687. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12688. StringBuilder sql = new StringBuilder();
  12689. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12690. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12691. int supplierId = 0;
  12692. StringBuilder insterSql = new StringBuilder();
  12693. for (int i = 0; i < dt.Rows.Count; i++)
  12694. {
  12695. DataRow row = dt.Rows[i];
  12696. if (i == 0)
  12697. {
  12698. supplierId = Convert.ToInt32(row["SupplierId"]);
  12699. }
  12700. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12701. {
  12702. returnErrorMsg("同车间的订单才能一起打包");
  12703. return;
  12704. }
  12705. int orderState = Convert.ToInt32(row["OrderState"]);
  12706. if (orderState != 5)
  12707. {
  12708. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12709. return;
  12710. }
  12711. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12712. }
  12713. CeErpPackData ceErpPackData = new CeErpPackData();
  12714. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  12715. ceErpPackData.supplierId = supplierId;
  12716. ceErpPackData.createtime = DateTime.Now;
  12717. ceErpPackData.createBy = CurrentUser.UserID;
  12718. ceErpPackData.createName = CurrentUser.UserName;
  12719. ceErpPackData.Create();
  12720. if (ceErpPackData.ID > 0)
  12721. {
  12722. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12723. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12724. }
  12725. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12726. returnSuccessMsg("打包成功");
  12727. return;
  12728. }
  12729. returnErrorMsg("缺少必要的参数");
  12730. }
  12731. public void rePackOrderInfo()
  12732. {
  12733. string id = GetPostString("id");
  12734. if (!string.IsNullOrEmpty(id))
  12735. {
  12736. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12737. if (ceErpPackData == null)
  12738. {
  12739. returnSuccessMsg("查无数据");
  12740. return;
  12741. }
  12742. ceErpPackData.upStatus = 0;
  12743. ceErpPackData.message = "";
  12744. ceErpPackData.Update();
  12745. returnSuccessMsg("打包成功");
  12746. return;
  12747. }
  12748. returnErrorMsg("缺少必要的参数");
  12749. }
  12750. public void backPackOrderInfo()
  12751. {
  12752. string id = GetPostString("id");
  12753. if (!string.IsNullOrEmpty(id))
  12754. {
  12755. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12756. if (ceErpPackData == null)
  12757. {
  12758. returnSuccessMsg("查无数据");
  12759. return;
  12760. }
  12761. ceErpPackData.upStatus = 4;
  12762. ceErpPackData.Update();
  12763. List<string> list = new List<string>();
  12764. StringBuilder sql = new StringBuilder();
  12765. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  12766. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12767. for (int i = 0; i < dt.Rows.Count; i++)
  12768. {
  12769. DataRow row = dt.Rows[i];
  12770. list.Add("'" + row["ctid"].ToString() + "'");
  12771. }
  12772. string textCtids = string.Join(",", list);
  12773. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=5,IsVerifyToSupplier=0,IsReturn=1,ReturnTime=GETDATE(),ReturnReason='无法打包' where ctid in ({0}) and OrderState=6", textCtids));
  12774. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", textCtids, (int)OrderState.下单完成, 0, "无法打包退回"));
  12775. returnSuccessMsg("退回成功");
  12776. return;
  12777. }
  12778. returnErrorMsg("缺少必要的参数");
  12779. }
  12780. public void addPackDownNum()
  12781. {
  12782. string id = GetPostString("id");
  12783. if (!string.IsNullOrEmpty(id))
  12784. {
  12785. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12786. returnSuccessMsg("下载成功");
  12787. return;
  12788. }
  12789. returnErrorMsg("缺少必要的参数");
  12790. }
  12791. public void get_pack_list()
  12792. {
  12793. DataStruct dStruct = GetPostStruct();
  12794. List<string> lw = new List<string>();
  12795. string supplier = GetPostString("supplier");
  12796. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12797. string posTag = CurrentUser.UserPost.Post.Code;
  12798. if (posTag == "Supplier")
  12799. {
  12800. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12801. }
  12802. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12803. dStruct.Order = "createtime desc";
  12804. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12805. writeGridDataTableJson(dStruct.TotalCount, dt);
  12806. }
  12807. public void get_pack_order_list()
  12808. {
  12809. string packId = GetPostString("packId");
  12810. if (string.IsNullOrEmpty(packId))
  12811. {
  12812. returnErrorMsg("缺少必要的参数");
  12813. return;
  12814. }
  12815. StringBuilder sql = new StringBuilder();
  12816. sql.AppendFormat("select c.ctid,c.seller_memo,i.message from CE_ErpPackDataItem i left join CE_ErpTradeCell c on i.ctid=c.ctid where i.packId = {0}", packId);
  12817. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12818. if (dt == null || dt.Rows.Count == 0)
  12819. {
  12820. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12821. return;
  12822. }
  12823. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12824. return;
  12825. }
  12826. public void get_supplier_product_time_list()
  12827. {
  12828. DataStruct dStruct = GetPostStruct();
  12829. List<string> lw = new List<string>();
  12830. string txtKey = GetPostString("txtKey");
  12831. if (txtKey.Length > 0)
  12832. {
  12833. lw.Add(string.Format("(supplierName = '{0}' or productName like '%{0}%')", txtKey));
  12834. }
  12835. string posTag = CurrentUser.UserPost.Post.Code;
  12836. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12837. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12838. writeGridDataTableJson(dStruct.TotalCount, dt);
  12839. }
  12840. public void saveSupplierProductTime()
  12841. {
  12842. string productId = GetPostString("productId");
  12843. if (string.IsNullOrEmpty(productId))
  12844. {
  12845. returnErrorMsg("缺少必要的参数");
  12846. return;
  12847. }
  12848. string productName = GetPostString("productName");
  12849. int supplierId = GetPostInt("supplierId");
  12850. if (supplierId == 0)
  12851. {
  12852. returnErrorMsg("缺少必要的参数");
  12853. return;
  12854. }
  12855. int quantity = GetPostInt("quantity");
  12856. int sendDay = GetPostInt("sendTime");
  12857. string supplierName = GetPostString("supplierName");
  12858. string craft = GetPostString("craft");
  12859. string deadLine = GetPostString("deadLine");
  12860. string dayDeadLine = GetPostString("dayDeadLine");
  12861. try
  12862. {
  12863. int eid = GetPostInt("eid");
  12864. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12865. if (ceErpSupplierProductTime == null)
  12866. {
  12867. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12868. }
  12869. ceErpSupplierProductTime.productId = productId;
  12870. ceErpSupplierProductTime.productName = productName;
  12871. ceErpSupplierProductTime.supplierId = supplierId;
  12872. ceErpSupplierProductTime.supplierName = supplierName;
  12873. ceErpSupplierProductTime.craft = craft;
  12874. ceErpSupplierProductTime.sendDay = sendDay;
  12875. ceErpSupplierProductTime.quantity = quantity;
  12876. if (!string.IsNullOrEmpty(deadLine))
  12877. {
  12878. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12879. }
  12880. if (!string.IsNullOrEmpty(dayDeadLine))
  12881. {
  12882. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12883. }
  12884. if (ceErpSupplierProductTime.ID == 0)
  12885. {
  12886. ceErpSupplierProductTime.Save();
  12887. }
  12888. else
  12889. {
  12890. ceErpSupplierProductTime.Update();
  12891. }
  12892. }
  12893. catch (Exception e)
  12894. {
  12895. }
  12896. returnSuccessMsg("保存成功");
  12897. return;
  12898. }
  12899. public void delSupplierProductTime()
  12900. {
  12901. int eid = GetPostInt("eid");
  12902. if (eid > 0)
  12903. {
  12904. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12905. if (ceErpSupplierProductTime == null)
  12906. {
  12907. returnErrorMsg("查无数据");
  12908. return;
  12909. }
  12910. ceErpSupplierProductTime.Delete();
  12911. returnSuccessMsg("保存成功");
  12912. return;
  12913. }
  12914. returnErrorMsg("缺少必要的参数");
  12915. }
  12916. public void getExpressInfo()
  12917. {
  12918. string ctid = GetPostString("ctid");
  12919. if (!string.IsNullOrEmpty(ctid))
  12920. {
  12921. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12922. if (ceErpTradeCell != null)
  12923. {
  12924. string outSid = ceErpTradeCell.OutSid;
  12925. if (outSid.Length > 0)
  12926. {
  12927. string sql = string.Format("SELECT out_sid FROM [dbo].[CE_ErpExpressInfo] WHERE (out_sid in ({0}) or tid = '{1}') and ISNULL(DATALENGTH(postData), 0)>0;", "'" + outSid.Replace(",", "','") + "'", ceErpTradeCell.tid);
  12928. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12929. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12930. return;
  12931. }
  12932. }
  12933. returnErrorMsg("查无记录");
  12934. return;
  12935. }
  12936. returnErrorMsg("缺少必要的参数");
  12937. }
  12938. public void getExpressPostData()
  12939. {
  12940. string express = GetPostString("express");
  12941. if (!string.IsNullOrEmpty(express))
  12942. {
  12943. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12944. if (ceErpExpressInfo != null)
  12945. {
  12946. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12947. return;
  12948. }
  12949. }
  12950. returnErrorMsg("缺少必要的参数");
  12951. }
  12952. public void checkSupplierOrder()
  12953. {
  12954. string ctids = GetPostString("ctids");
  12955. if (ctids != null)
  12956. {
  12957. List<string> list = new List<string>();
  12958. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  12959. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12960. for (int i = 0; i < dt.Rows.Count; i++)
  12961. {
  12962. DataRow row = dt.Rows[i];
  12963. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  12964. {
  12965. continue;
  12966. }
  12967. list.Add(row["seller_memo"].ToString());
  12968. }
  12969. if (list.Count > 0)
  12970. {
  12971. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", "'" + ctids.Replace(",", "','") + "'", (int)OrderState.下单完成, CurrentUser.UserID, "点击下载按钮"));
  12972. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  12973. return;
  12974. }
  12975. }
  12976. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  12977. return;
  12978. }
  12979. public void addPersonId()
  12980. {
  12981. string tid = GetPostString("tid");
  12982. string personId = GetPostString("personId");
  12983. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12984. if (ceErpTrade != null)
  12985. {
  12986. ceErpTrade.receiver_zip = personId;
  12987. ceErpTrade.Update();
  12988. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  12989. returnSuccessMsg("保存成功");
  12990. return;
  12991. }
  12992. returnErrorMsg("缺少必要的参数");
  12993. }
  12994. public void addDeliveryPaymant()
  12995. {
  12996. string tid = GetPostString("tid");
  12997. string paymant = GetPostString("paymant");
  12998. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12999. if (ceErpTrade != null)
  13000. {
  13001. if (!string.IsNullOrEmpty(paymant))
  13002. {
  13003. ceErpTrade.delivery_paymant = Convert.ToDouble(paymant);
  13004. }
  13005. ceErpTrade.Update();
  13006. LogHelper.addLog(tid, CurrentUser.UserID, "偏远物流费:" + paymant, 6);
  13007. returnSuccessMsg("保存成功");
  13008. return;
  13009. }
  13010. returnErrorMsg("缺少必要的参数");
  13011. }
  13012. public void saveCellFile()
  13013. {
  13014. string tid = GetPostString("tid");
  13015. string ctid = GetPostString("ctid");
  13016. string urls = GetPostString("urls");
  13017. string type = GetPostString("type");
  13018. string del = GetPostString("del");
  13019. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  13020. {
  13021. if (tradeCellFile == TradeCellFile.AUTH_FILE)
  13022. {
  13023. ctid = tid;
  13024. }
  13025. if ("1".Equals(del))
  13026. {
  13027. CeErpTradeCellFile.delByCtid(tid, ctid, tradeCellFile.ToString());
  13028. }
  13029. string[] list = urls.Split(',');
  13030. if (!string.IsNullOrEmpty(urls) && list.Length > 0)
  13031. {
  13032. foreach (string item in list)
  13033. {
  13034. CeErpTradeCellFile ceErpTradeCellFile = new CeErpTradeCellFile(tid, ctid, item, tradeCellFile.ToString());
  13035. ceErpTradeCellFile.Create();
  13036. LogHelper.addLog(ctid, CurrentUser.UserID, "上传客户文件:" + item, 6);
  13037. }
  13038. }
  13039. returnSuccessMsg("保存成功");
  13040. return;
  13041. }
  13042. returnErrorMsg("缺少必要的参数");
  13043. }
  13044. public void getCellFile()
  13045. {
  13046. string tid = GetPostString("tid");
  13047. string ctid = GetPostString("ctid");
  13048. string type = GetPostString("type");
  13049. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  13050. {
  13051. if (tradeCellFile == TradeCellFile.AUTH_FILE)
  13052. {
  13053. ctid = tid;
  13054. }
  13055. string sql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeCellFile] WHERE isDel=0 and tid='{0}' and ctid='{1}' and type='{2}';", tid, ctid, tradeCellFile);
  13056. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13057. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  13058. return;
  13059. }
  13060. returnErrorMsg("缺少必要的参数");
  13061. }
  13062. public void delCellFile()
  13063. {
  13064. string id = GetPostString("id");
  13065. if (string.IsNullOrEmpty(id))
  13066. {
  13067. returnErrorMsg("缺少必要的参数");
  13068. return;
  13069. }
  13070. CeErpTradeCellFile ceErpTradeCellFile = CeErpTradeCellFile.Get(id);
  13071. CeErpTradeCellFile.delByID(id);
  13072. LogHelper.addLog(ceErpTradeCellFile.ctid, CurrentUser.UserID, "删除客户文件", 6);
  13073. returnSuccessMsg("保存成功");
  13074. }
  13075. public void getInvoiceOrder()
  13076. {
  13077. string tid = GetPostString("tid");
  13078. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  13079. List<string> tids = new List<string>();
  13080. if (!string.IsNullOrEmpty(ceErpTrade.buyer_nick) && !string.IsNullOrEmpty(ceErpTrade.buyer_id))
  13081. {
  13082. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WHERE buyer_id = '{0}' AND seller_nick = '{1}' order by pay_time desc;", ceErpTrade.buyer_id, ceErpTrade.seller_nick);
  13083. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13084. foreach (DataRow dr in dt.Rows)
  13085. {
  13086. tids.Add("'" + dr["tid"].ToString() + "'");
  13087. }
  13088. }
  13089. else
  13090. {
  13091. tids.Add("'" + ceErpTrade.tid + "'");
  13092. }
  13093. DataTable cell_dt = new DataTable();
  13094. if (tids.Count > 0)
  13095. {
  13096. cell_dt = DbHelper.DbConn.ExecuteDataset(string.Format("SELECT * FROM [dbo].[CE_ErpTradeCell] WHERE tid in ({0});", string.Join(",", tids))).Tables[0];
  13097. }
  13098. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(cell_dt));
  13099. return;
  13100. }
  13101. public void getOrderLogInfo()
  13102. {
  13103. string ctid = GetPostString("ctid");
  13104. if (!string.IsNullOrEmpty(ctid))
  13105. {
  13106. StringBuilder sql = new StringBuilder();
  13107. sql.AppendFormat("select * from view_erptradelog where tid='{0}' order by id;", ctid);
  13108. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  13109. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(ds.Tables[0])) + "}");
  13110. return;
  13111. }
  13112. returnErrorMsg("缺少必要的参数");
  13113. }
  13114. public void setCellTeampId()
  13115. {
  13116. string ctid = GetPostString("ctid");
  13117. string tempId = GetPostString("tempId");
  13118. if (!string.IsNullOrEmpty(ctid))
  13119. {
  13120. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  13121. if (ceErpTradeCellExtend == null)
  13122. {
  13123. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  13124. ceErpTradeCellExtend.ctid = ctid;
  13125. }
  13126. ceErpTradeCellExtend.tempId = tempId;
  13127. if (ceErpTradeCellExtend.ID > 0)
  13128. {
  13129. ceErpTradeCellExtend.Update();
  13130. }
  13131. else
  13132. {
  13133. ceErpTradeCellExtend.Create();
  13134. }
  13135. designHelper.API_sendTempInfo(ctid, tempId);
  13136. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "修改模板id" + tempId, 6);
  13137. returnSuccessMsg("保存成功");
  13138. return;
  13139. }
  13140. returnErrorMsg("缺少必要的参数");
  13141. }
  13142. public void saveJointorder()
  13143. {
  13144. string ctid = GetPostString("ctid");
  13145. if (!string.IsNullOrEmpty(ctid))
  13146. {
  13147. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  13148. if (ceErpTradeCellExtend == null)
  13149. {
  13150. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  13151. ceErpTradeCellExtend.ctid = ctid;
  13152. }
  13153. if (ceErpTradeCellExtend.IsJoint == 1)
  13154. {
  13155. ceErpTradeCellExtend.IsJoint = 0;
  13156. }
  13157. else
  13158. {
  13159. ceErpTradeCellExtend.IsJoint = 1;
  13160. }
  13161. if (ceErpTradeCellExtend.ID > 0)
  13162. {
  13163. ceErpTradeCellExtend.Update();
  13164. }
  13165. else
  13166. {
  13167. ceErpTradeCellExtend.Create();
  13168. }
  13169. returnSuccessMsg("保存成功");
  13170. return;
  13171. }
  13172. returnErrorMsg("缺少必要的参数");
  13173. }
  13174. public void applyOrderBack()
  13175. {
  13176. string ctid = GetPostString("ctid");
  13177. string reason = GetPostString("reason");
  13178. if (!string.IsNullOrEmpty(ctid))
  13179. {
  13180. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13181. if (ceErpTradeCell == null)
  13182. {
  13183. returnErrorMsg("找不到订单");
  13184. return;
  13185. }
  13186. if (ceErpTradeCell.OrderState != 5 && ceErpTradeCell.OrderState != 6)
  13187. {
  13188. returnErrorMsg("待下单已下单才能申请");
  13189. return;
  13190. }
  13191. //下单后24小时后无法申请
  13192. if (ceErpTradeCell.OrderState == 6 && ceErpTradeCell.FinishPlaceTime != null)
  13193. {
  13194. DateTime now = DateTime.Now;
  13195. if (!string.IsNullOrEmpty(ceErpTradeCell.FinishPlaceTime.ToString()) && DateTime.Compare(DateTime.Parse(ceErpTradeCell.FinishPlaceTime.ToString()), now.AddHours(-24)) < 0)
  13196. {
  13197. returnErrorMsg("下单后24小时后无法申请");
  13198. return;
  13199. }
  13200. }
  13201. string sql = string.Format("select Con,UserId from CE_ErpTradeLog where tid = '{0}'", ceErpTradeCell.ctid);
  13202. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13203. if (dataTable != null && dataTable.Rows.Count > 0)
  13204. {
  13205. foreach (DataRow row in dataTable.Rows)
  13206. {
  13207. if (row["Con"].ToString().Contains("拒绝打回"))
  13208. {
  13209. returnErrorMsg("被拒绝过无法继续申请");
  13210. return;
  13211. }
  13212. }
  13213. }
  13214. ceErpTradeCell.IsReturn = 4;
  13215. ceErpTradeCell.Update();
  13216. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请打回:" + reason, ceErpTradeCell.OrderState);
  13217. returnSuccessMsg("保存成功");
  13218. return;
  13219. }
  13220. returnErrorMsg("缺少必要的参数");
  13221. }
  13222. public void cancelApplyOrderBack()
  13223. {
  13224. string ctid = GetPostString("ctid");
  13225. if (!string.IsNullOrEmpty(ctid))
  13226. {
  13227. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13228. if (ceErpTradeCell == null)
  13229. {
  13230. returnErrorMsg("找不到订单");
  13231. return;
  13232. }
  13233. if (ceErpTradeCell.IsReturn != 4)
  13234. {
  13235. returnErrorMsg("订单未在申请阶段");
  13236. return;
  13237. }
  13238. ceErpTradeCell.IsReturn = 0;
  13239. ceErpTradeCell.Update();
  13240. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "取消申请打回", ceErpTradeCell.OrderState);
  13241. returnSuccessMsg("保存成功");
  13242. return;
  13243. }
  13244. returnErrorMsg("缺少必要的参数");
  13245. }
  13246. public void get_erp_applybackorderlist()
  13247. {
  13248. DataStruct dStruct = GetPostStruct();
  13249. List<string> lw = new List<string>();
  13250. string tid = GetPostString("ctid");
  13251. if (tid.Length > 0)
  13252. {
  13253. string select_tid = getTidByCtid(tid);
  13254. lw.Add(string.Format("tid='{0}'", select_tid));
  13255. }
  13256. string shopname = GetPostString("shopname");
  13257. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  13258. string buyernick = GetPostString("buyer_nick");
  13259. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  13260. string customer = GetPostString("customer");
  13261. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  13262. string design = GetPostString("design");
  13263. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  13264. string orderState = GetPostString("orderState");
  13265. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  13266. string supplier = GetPostString("supplier");
  13267. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  13268. string sellermemo = GetPostString("seller_memo");
  13269. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  13270. string otherMemo = GetPostString("otherMemo");
  13271. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  13272. string address = GetPostString("address");
  13273. 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));
  13274. string date1 = GetPostString("date1");
  13275. string date2 = GetPostString("date2");
  13276. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  13277. if (dw.Length > 0) lw.Add(dw);
  13278. string price1 = GetPostString("price1");
  13279. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  13280. string price2 = GetPostString("price2");
  13281. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  13282. if (CurrentUser.UserPost.Post.Code == "Supplier")
  13283. {
  13284. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  13285. lw.Add(string.Format("OrderState = 6"));
  13286. }
  13287. else if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  13288. {
  13289. lw.Add("OrderState in (5,6) ");
  13290. }
  13291. lw.Add(string.Format("IsReturn = 4"));
  13292. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  13293. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  13294. string pagesize = GetPostString("pagesize");
  13295. if (pagesize != null)
  13296. {
  13297. dStruct.PageSize = 200;
  13298. }
  13299. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  13300. writeGridDataTableJson(dStruct.TotalCount, dt);
  13301. }
  13302. public void refuseBackOrder()
  13303. {
  13304. string ctid = GetPostString("ctid");
  13305. if (!string.IsNullOrEmpty(ctid))
  13306. {
  13307. string reason = GetPostString("returnreason");
  13308. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13309. if (ceErpTradeCell == null)
  13310. {
  13311. returnErrorMsg("找不到订单");
  13312. return;
  13313. }
  13314. string sql = string.Format("select Con,UserId from CE_ErpTradeLog where tid = '{0}' order by ID desc", ceErpTradeCell.ctid);
  13315. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13316. int userId = 0;
  13317. if (dataTable != null && dataTable.Rows.Count > 0)
  13318. {
  13319. foreach (DataRow row in dataTable.Rows)
  13320. {
  13321. if (row["Con"].ToString().Contains("申请打回:"))
  13322. {
  13323. userId = Convert.ToInt32(row["UserId"]);
  13324. }
  13325. }
  13326. }
  13327. if (userId > 0)
  13328. {
  13329. CeErpMessageTip ct = new CeErpMessageTip();
  13330. ct.tid = ceErpTradeCell.ctid;
  13331. ct.sectionId = 0;
  13332. ct.userId = userId;
  13333. ct.type = 4;
  13334. ct.isVisit = false;
  13335. ct.content = ceErpTradeCell.ctid + ",申请打回被拒绝:" + reason;
  13336. ct.Create();
  13337. }
  13338. ceErpTradeCell.IsReturn = 0;
  13339. ceErpTradeCell.Update();
  13340. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "拒绝打回:" + reason, ceErpTradeCell.OrderState);
  13341. returnSuccessMsg("保存成功");
  13342. return;
  13343. }
  13344. returnErrorMsg("缺少必要的参数");
  13345. }
  13346. public void passApplyBack()
  13347. {
  13348. if (UrlPostParmsCheck("ctid"))
  13349. {
  13350. string eid = GetPostString("ctid");
  13351. CeErpTradeCell entity = null;
  13352. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  13353. string userpost = CurrentUser.UserPost.Post.Code;
  13354. if (entity != null)
  13355. {
  13356. string message = "操作成功!";
  13357. string isDown = "";
  13358. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  13359. {
  13360. message = eid + "订单有被点击下载。请注意沟通是否已下载完!";
  13361. isDown = "被点击下载";
  13362. }
  13363. bool isPlace = false;
  13364. if (entity.OrderState > 6)
  13365. {
  13366. returnErrorMsg("已发货无法打回!");
  13367. return;
  13368. }
  13369. if (entity.OrderState == 6)
  13370. {
  13371. isPlace = true;
  13372. }
  13373. bool isNeedUpdateCell2 = false;
  13374. if (entity.OrderState >= 6)
  13375. {
  13376. isNeedUpdateCell2 = true;
  13377. }
  13378. int returnTag = 2;
  13379. if (userpost == "Supplier")
  13380. {
  13381. returnTag = 1;
  13382. }
  13383. int toType = GetPostInt("totype");
  13384. string fromType = "3";
  13385. if (entity.OrderState < 5)
  13386. {
  13387. fromType = "3";
  13388. }
  13389. else
  13390. {
  13391. fromType = "4";
  13392. }
  13393. if (entity.IsXianHuo == 0)
  13394. {
  13395. if (returnTag == 2)
  13396. {
  13397. if (toType == 1)
  13398. {
  13399. entity.OrderState = 0;
  13400. entity.ReturnUserType = 1;
  13401. string clearman = GetPostString("clearman");
  13402. if (!string.IsNullOrEmpty(clearman))
  13403. {
  13404. entity.DesignUserId = 0;
  13405. }
  13406. }
  13407. else
  13408. {
  13409. entity.OrderState = 3;
  13410. entity.ReturnUserType = 2;
  13411. }
  13412. entity.IsReadTag = 1;
  13413. }
  13414. else if (returnTag == 1)
  13415. {
  13416. entity.OrderState = 5;
  13417. }
  13418. entity.IsVerifyToSupplier = false;
  13419. }
  13420. if (entity.IsXianHuo == 1)
  13421. {
  13422. entity.OrderState = 5;
  13423. }
  13424. entity.IsVerifyToSupplier = false;
  13425. entity.IsHaveNewOrder = 0;
  13426. entity.UnusualTag = 0;
  13427. entity.UnusualTime = null;
  13428. entity.UnusualCon = "";
  13429. entity.IsReturn = returnTag;
  13430. entity.ReturnTime = DateTime.Now;
  13431. entity.UpdateTime = DateTime.Now;
  13432. entity.ReturnReason = GetPostString("returnreason");
  13433. entity.Update();
  13434. if (entity.OrderState == 3)
  13435. {
  13436. ApiVo apiVo = new ApiVo();
  13437. apiVo.orderNumber = entity.ctid;
  13438. apiVo.actionName = "rebutDesign";
  13439. apiVo.orderRemarks = entity.ReturnReason;
  13440. designHelper.API_WorkCore(apiVo);//rebutDesign
  13441. }
  13442. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason + isDown, entity.OrderState);
  13443. if (isPlace)
  13444. {
  13445. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  13446. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  13447. if (dth != null && dth.Rows.Count > 0)
  13448. {
  13449. dataSendOrderBean dataSendOrderBean = null;
  13450. foreach (DataRow item in dth.Rows)
  13451. {
  13452. try
  13453. {
  13454. dataSendOrderBean = new dataSendOrderBean();
  13455. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  13456. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  13457. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  13458. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  13459. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  13460. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  13461. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  13462. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  13463. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  13464. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  13465. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  13466. dataSendOrderBean.Radio1723534706288 = "打回";
  13467. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  13468. if (result != null)
  13469. {
  13470. if ("0".Equals(result.errcode))
  13471. {
  13472. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  13473. }
  13474. else
  13475. {
  13476. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  13477. }
  13478. }
  13479. }
  13480. catch (Exception ex)
  13481. {
  13482. }
  13483. }
  13484. }
  13485. }
  13486. returnSuccessMsg(message);
  13487. return;
  13488. }
  13489. returnErrorMsg("找不到订单记录");
  13490. }
  13491. }
  13492. public void getApplyBackCount()
  13493. {
  13494. string sql = string.Format("SELECT top 1 ctid FROM [dbo].[CE_ErpTradeCell]");
  13495. List<string> lw = new List<string>();
  13496. lw.Add("IsReturn = 4");
  13497. if (CurrentUser.UserPost.Post.Code == "Supplier")
  13498. {
  13499. lw.Add("OrderState = 6");
  13500. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  13501. }
  13502. else if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  13503. {
  13504. lw.Add("OrderState = 5");
  13505. }
  13506. else
  13507. {
  13508. ReturnSuccess("{" + string.Format("\"data\":{0}", "0") + "}");
  13509. return;
  13510. }
  13511. sql += " where " + string.Join(" and ", lw.ToArray());
  13512. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13513. List<string> list = new List<string>();
  13514. if (dataTable != null && dataTable.Rows.Count > 0)
  13515. {
  13516. foreach (DataRow row in dataTable.Rows)
  13517. {
  13518. list.Add(row["ctid"].ToString());
  13519. }
  13520. }
  13521. ReturnSuccess("{" + string.Format("\"data\":{0}", "\"" + string.Join(",", list) + "\"") + "}");
  13522. return;
  13523. }
  13524. public void getSysPrice()
  13525. {
  13526. string ctid = GetPostString("ctid");
  13527. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13528. if (ceErpTradeCell.ProductId == 0)
  13529. {
  13530. returnSuccessMsg("没有产品id");
  13531. }
  13532. dataHelper.get_sys_price(ceErpTradeCell);
  13533. returnSuccessMsg("保存成功");
  13534. }
  13535. public void saveAssignLog(string reason, CeErpTradeCell ce)
  13536. {
  13537. if (ce != null)
  13538. {
  13539. CeErpAssignLog ceErpAssignLog = new CeErpAssignLog();
  13540. ceErpAssignLog.ctid = ce.ctid;
  13541. ceErpAssignLog.userid = CurrentUser.UserID;
  13542. ceErpAssignLog.seller_memo = ce.seller_memo;
  13543. ceErpAssignLog.reason = reason;
  13544. ceErpAssignLog.Save();
  13545. }
  13546. }
  13547. public void get_erp_assignLog()
  13548. {
  13549. DataStruct dStruct = GetPostStruct();
  13550. List<string> lw = new List<string>();
  13551. string tid = GetPostString("ctid");
  13552. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  13553. string apdate2 = GetPostString("apdate2");
  13554. string apdate1 = GetPostString("apdate1");
  13555. string dwap = GetDateMinuteWhere("createtime", apdate1, apdate2);
  13556. if (dwap.Length > 0) lw.Add(dwap);
  13557. dStruct.Order = " createtime desc";
  13558. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  13559. DataTable dt = WebCache.GetData("view_ErpAssignLog", dStruct);
  13560. writeGridDataTableJson(dStruct.TotalCount, dt);
  13561. }
  13562. public void change_upfile_status()
  13563. {
  13564. int id = GetPostInt("id");
  13565. CeErpUpFileSupplier ceErpUpFileSupplier = CeErpUpFileSupplier.Get(id);
  13566. if (ceErpUpFileSupplier != null)
  13567. {
  13568. ceErpUpFileSupplier.isOpen = !ceErpUpFileSupplier.isOpen;
  13569. ceErpUpFileSupplier.Update();
  13570. }
  13571. returnSuccessMsg("保存成功");
  13572. }
  13573. public void test_seller_memo_upfile()
  13574. {
  13575. string ctid = GetPostString("ctid");
  13576. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  13577. if (ce == null)
  13578. {
  13579. returnErrorMsg("查无订单");
  13580. return;
  13581. }
  13582. int supplierId = getsupplierId(ce);
  13583. if (supplierId > 0)
  13584. {
  13585. CeErpSupplier ceErpSupplier = CeErpSupplier.Get(supplierId);
  13586. if (ceErpSupplier != null)
  13587. {
  13588. returnSuccessMsg(ceErpSupplier.ComName);
  13589. return;
  13590. }
  13591. }
  13592. returnErrorMsg("未匹配到车间");
  13593. return;
  13594. }
  13595. private int getsupplierId(CeErpTradeCell entity)
  13596. {
  13597. int supplierId = 0;
  13598. StringBuilder sql = new StringBuilder();
  13599. sql.AppendFormat("select * from CE_ErpUpFileSupplier where isOpen = 1");
  13600. DataTable cellEx = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  13601. int num = getProductCount(entity.seller_memo);
  13602. foreach (DataRow row in cellEx.Rows)
  13603. {
  13604. bool isIn = true;
  13605. //判断材质工艺都要符合
  13606. if (!Convert.IsDBNull(row["seller_memo"]) && !string.IsNullOrEmpty(row["seller_memo"].ToString()))
  13607. {
  13608. string memo = row["seller_memo"].ToString();
  13609. string[] memolist = memo.Split('+');
  13610. for (int i = 0; i < memolist.Length; i++)
  13611. {
  13612. if (!Regex.IsMatch(entity.seller_memo, memolist[i].Replace("/", "|")))
  13613. {
  13614. isIn = false;
  13615. }
  13616. }
  13617. }
  13618. if (!isIn)
  13619. {
  13620. continue;
  13621. }
  13622. //判断金额符不符合
  13623. if (!Convert.IsDBNull(row["payment"]) && !string.IsNullOrEmpty(row["payment"].ToString()))
  13624. {
  13625. string payment = row["payment"].ToString();
  13626. string[] paymentList = payment.Split('-');
  13627. if (!string.IsNullOrEmpty(paymentList[0]))
  13628. {
  13629. if (entity.payment < Convert.ToDouble(paymentList[0]))
  13630. {
  13631. continue;
  13632. }
  13633. }
  13634. if (!string.IsNullOrEmpty(paymentList[1]))
  13635. {
  13636. if (entity.payment > Convert.ToDouble(paymentList[1]))
  13637. {
  13638. continue;
  13639. }
  13640. }
  13641. }
  13642. if (!Convert.IsDBNull(row["size"]) && !string.IsNullOrEmpty(row["size"].ToString()))
  13643. {
  13644. string pattern = @"\b(\d{1,5}[x\*]\d{1,5}(mm|cm))\b";
  13645. string memo = entity.seller_memo.Replace("MM", "mm").Replace("CM", "cm");
  13646. Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
  13647. MatchCollection matches = reg.Matches(memo);//设定要查找的字符串
  13648. double width = 0;
  13649. double height = 0;
  13650. try
  13651. {
  13652. if (matches[0].Success)
  13653. {
  13654. string sizematches = matches[0].Groups[0].Value;
  13655. sizematches = sizematches.Replace("mm", "");
  13656. sizematches = sizematches.Replace("cm", "");
  13657. string[] size_list = sizematches.Split('x');
  13658. if (size_list.Length > 1)
  13659. {
  13660. width = Convert.ToDouble(size_list[0]);
  13661. height = Convert.ToDouble(size_list[1]);
  13662. }
  13663. }
  13664. }
  13665. catch (Exception ex)
  13666. {
  13667. }
  13668. string size = row["size"].ToString();
  13669. string[] sizeList = size.Split('-');
  13670. if (!string.IsNullOrEmpty(sizeList[0]))
  13671. {
  13672. string[] sizeItemList = sizeList[0].Split('x');
  13673. //第一个尺寸格式不正确
  13674. if (sizeItemList.Length < 2)
  13675. {
  13676. continue;
  13677. }
  13678. double sizeWidth = Convert.ToDouble(sizeItemList[0]);
  13679. double sizeheight = Convert.ToDouble(sizeItemList[1]);
  13680. //备注尺寸要大于第一个尺寸
  13681. if (!((width > sizeWidth && height > sizeheight) || (width > sizeheight && height > sizeWidth)))
  13682. {
  13683. continue;
  13684. }
  13685. }
  13686. if (!string.IsNullOrEmpty(sizeList[1]))
  13687. {
  13688. string[] sizeItemList = sizeList[1].Split('x');
  13689. //第二个尺寸格式不正确
  13690. if (sizeItemList.Length < 2)
  13691. {
  13692. continue;
  13693. }
  13694. double sizeWidth = Convert.ToDouble(sizeItemList[0]);
  13695. double sizeheight = Convert.ToDouble(sizeItemList[1]);
  13696. //备注尺寸要大于第二个尺寸
  13697. if (!((width < sizeWidth && height < sizeheight) || (width < sizeheight && height < sizeWidth)))
  13698. {
  13699. continue;
  13700. }
  13701. }
  13702. }
  13703. //判断数量是否符合
  13704. if (!Convert.IsDBNull(row["number"]) && !string.IsNullOrEmpty(row["number"].ToString()))
  13705. {
  13706. string numberText = row["number"].ToString();
  13707. string[] numberTextList = numberText.Split('-');
  13708. int number = 0;
  13709. if (!string.IsNullOrEmpty(numberTextList[0]))
  13710. {
  13711. number = Convert.ToInt32(numberTextList[0]);
  13712. if (number > num)
  13713. {
  13714. continue;
  13715. }
  13716. }
  13717. if (!string.IsNullOrEmpty(numberTextList[1]))
  13718. {
  13719. number = Convert.ToInt32(numberTextList[1]);
  13720. if (number < num)
  13721. {
  13722. continue;
  13723. }
  13724. }
  13725. }
  13726. //判断店铺符不符合
  13727. if (!Convert.IsDBNull(row["shopIds"]) && !string.IsNullOrEmpty(row["shopIds"].ToString()))
  13728. {
  13729. List<string> shopids = row["shopIds"].ToString().Split(',').ToList();
  13730. if (!shopids.Contains(entity.ShopId.ToString()))
  13731. {
  13732. continue;
  13733. }
  13734. }
  13735. //地区不符合
  13736. if (!Convert.IsDBNull(row["address"]) && !string.IsNullOrEmpty(row["address"].ToString()))
  13737. {
  13738. if (!Regex.IsMatch(entity.seller_memo, row["address"].ToString().Replace("、", "|")))
  13739. {
  13740. continue;
  13741. }
  13742. }
  13743. //限制条件
  13744. if (!Convert.IsDBNull(row["filterText"]) && !string.IsNullOrEmpty(row["filterText"].ToString()))
  13745. {
  13746. if (Regex.IsMatch(entity.seller_memo, row["filterText"].ToString().Replace("/", "|")))
  13747. {
  13748. continue;
  13749. }
  13750. }
  13751. supplierId = Convert.ToInt32(row["supplierId"]);
  13752. break;
  13753. }
  13754. return supplierId;
  13755. }
  13756. public static int getProductCount(string txt)
  13757. {
  13758. // 提取"个"或"张"前面的数字
  13759. int unit = 0;
  13760. try
  13761. {
  13762. string unitPattern = @"(\d+)(?=个|张|本|套|件|卷|劵|条|箱 )";
  13763. System.Text.RegularExpressions.Match unitMatch = Regex.Match(txt, unitPattern);
  13764. string unitNum = unitMatch.Success ? unitMatch.Groups[1].Value : "1";
  13765. if (!int.TryParse(unitNum, out unit))
  13766. {
  13767. return 0;
  13768. }
  13769. }
  13770. catch (Exception ex)
  13771. {
  13772. }
  13773. return unit;
  13774. }
  13775. public void setNegotiateInfo()
  13776. {
  13777. string ctid = GetPostString("ctid");
  13778. string negotiate = GetPostString("negotiate");
  13779. if (!string.IsNullOrEmpty(ctid))
  13780. {
  13781. CeErpTradeCellExtend ce = CeErpTradeCellExtend.getByTid(ctid);
  13782. if (ce == null)
  13783. {
  13784. ce = new CeErpTradeCellExtend();
  13785. ce.ctid = ctid;
  13786. }
  13787. ce.negotiate = negotiate + "-" + CurrentUser.UserName;
  13788. if (ce.ID > 0)
  13789. {
  13790. ce.Update();
  13791. }
  13792. else
  13793. {
  13794. ce.Create();
  13795. }
  13796. LogHelper.addLog(ce.ctid, CurrentUser.UserID, "协商内容:" + negotiate, 0, 1);
  13797. returnSuccessMsg("保存成功");
  13798. }
  13799. }
  13800. }
  13801. }