sync.order.cs 639 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845
  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. namespace SiteCore.Handler
  50. {
  51. public partial class sync
  52. {
  53. public void get_erp_orderlist()
  54. {
  55. string poscode = CurrentUser.UserPost.Post.Code;
  56. DataStruct dStruct = GetPostStruct();
  57. //jiemiUtils.ossFileDecrypt("C:\\Users\\231010\\Downloads\\uv特殊工艺价格(1).xls");
  58. //apiHelper.Api_SyncOrderByTime("598825");
  59. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  60. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  61. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  62. //banniuApiHelper.sendLogisticsInfo(null);
  63. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  64. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  65. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2811249339088067154");
  66. //int sid = commonHelper.autoDistributeToSupplier(entity);
  67. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  68. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1750324509000,\"deliveryType\":\"OFFLINE\",\"discountFee\":60.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1750867200000,\"lines\":[{\"latestDeliveryTime\":1750867200000,\"mark2\":[],\"num\":12,\"outerId\":\"XCCBTFB\",\"payment\":300.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/490100363/O1CN01QY84g81EYIfY4eEq2_!!490100363.jpg\",\"platServiceFee\":0.0,\"price\":30.0,\"refOlId\":\"2618419802494137080\",\"refSkuId\":\"0\",\"refSpuId\":\"703805468317\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":25.0,\"singleFee\":25.0,\"spuOuterId\":\"XCCBTFB\",\"standards\":\"\",\"status\":\"NOT_SHIPPED\",\"title\":\"摆摊广告布定制推车贴纸三轮小吃车展示招牌喷绘夜市地摊帆布海报\",\"totalFee\":300.0,\"totalPrice\":360.0,\"totalSellPrice\":300.0}],\"logisticsOrderNo\":\"\",\"mark2\":[],\"modifyTime\":1750397934000,\"openBuyerId\":\"AAHnRHraABkUZRHgSx2jBZ8l\",\"openBuyerNick\":\"t**\",\"openSellerNick\":\"琳19890725\",\"orderSource\":\"SYNC\",\"orderTime\":1750324223000,\"payTime\":1750324505000,\"payment\":300.0,\"platServiceFee\":0.0,\"posCode\":\"guliang\",\"posId\":598696,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0},\"receivedPayment\":0.0,\"receiverCity\":\"三亚市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"吉阳区\",\"receiverId\":\"d882d22254b88b1ed1b3d6d4645179dd$\",\"receiverState\":\"海南省\",\"receiverTown\":\"河东区街道\",\"refOid\":\"2618419802494137080\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"422x35cm-1张-帆布-摆摊布米白-打孔模切-tb908253750- 拾柒-100-送10米麻绳,200x35cm-1张-帆布-摆摊布米白-打孔模切-tb908253750- 拾柒-100-送10米麻绳,400x73cm-1张-帆布-摆摊布米白-打孔模切-tb908253750- 拾柒-100-送10米麻绳\",\"serviceFee\":0.0,\"status\":\"NOT_SHIPPED\",\"totalFee\":300.0,\"totalPrice\":360.0,\"totalSellPrice\":300.0,\"type\":\"SALE\"}}");
  69. //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}}");
  70. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  71. //commonHelper.loginGetOrder(2152);
  72. //string res = apiHelper.API_GetWaybill("YTO-PDD-CYT", "250703-469248284251412");
  73. List<string> lw = new List<string>();
  74. string tid = GetPostString("ctid");
  75. string date1 = GetPostString("date1");
  76. //12-1 修改
  77. string urgent = GetPostString("urgent");
  78. string back = GetPostString("back");
  79. string offlineSearch = GetPostString("offlineSearch");
  80. int paramsCount = 0;
  81. if (!string.IsNullOrWhiteSpace(urgent))
  82. {
  83. if (urgent.Equals("true"))
  84. {
  85. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  86. }
  87. }
  88. if (!string.IsNullOrWhiteSpace(back))
  89. {
  90. if (back.Equals("true"))
  91. {
  92. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  93. }
  94. }
  95. if (!string.IsNullOrWhiteSpace(offlineSearch))
  96. {
  97. if (offlineSearch.Equals("true"))
  98. {
  99. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  100. }
  101. }
  102. //end
  103. string date2 = GetPostString("date2");
  104. string buyernick = GetPostString("buyer_nick");
  105. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  106. {
  107. if (tid.Length <= 0 && buyernick.Length <= 0)
  108. {
  109. return;
  110. }
  111. }
  112. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  113. {
  114. if (tid.Length > 0)
  115. {
  116. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  117. if (ceErpTradeCell != null)
  118. {
  119. tid = ceErpTradeCell.tid;
  120. }
  121. List<string> select_tid = getTidByCtidMore(tid);
  122. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  123. }
  124. if (buyernick.Length > 0)
  125. {
  126. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  127. }
  128. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  129. if (dw.Length > 0)
  130. {
  131. lw.Add(dw);
  132. }
  133. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  134. {
  135. string usershop = CurrentUser.User.pemShop;
  136. lw.Add(string.Format("ShopId in ({0})", usershop));
  137. }
  138. }
  139. else
  140. {
  141. if (ex_psize == 0)
  142. {
  143. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  144. }
  145. if (PKey != "admin" && poscode != "SysAdmin")
  146. {
  147. string usershop = CurrentUser.User.pemShop;
  148. lw.Add(string.Format("ShopId in ({0})", usershop));
  149. paramsCount++;
  150. }
  151. }
  152. string uploaddate1 = GetPostString("uploaddate1");
  153. string uploaddate2 = GetPostString("uploaddate2");
  154. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  155. if (update.Length > 0) lw.Add(update);
  156. string deliverydate1 = GetPostString("deliverydate1");
  157. string deliverydate2 = GetPostString("deliverydate2");
  158. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  159. if (deliverydate.Length > 0)
  160. {
  161. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  162. };
  163. string shopname = GetPostString("shopname");
  164. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  165. string addwechat = GetPostString("addwechat");
  166. if (addwechat.Length > 0)
  167. {
  168. int addWt = Convert.ToInt32(addwechat);
  169. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  170. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  171. }
  172. string customer = GetPostString("customer");
  173. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  174. string design = GetPostString("design");
  175. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  176. string orderState = GetPostString("orderState");
  177. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  178. string address = GetPostString("address");
  179. 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));
  180. string sellermemo = GetPostString("seller_memo");
  181. if (sellermemo.Length > 0)
  182. {
  183. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  184. }
  185. string backReason = GetPostString("backReason");
  186. if (backReason.Length > 0)
  187. {
  188. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  189. }
  190. string apdate1 = GetPostString("apdate1");
  191. string apdate2 = GetPostString("apdate2");
  192. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  193. if (dwap.Length > 0) lw.Add(dwap);
  194. string price1 = GetPostString("price1");
  195. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  196. string price2 = GetPostString("price2");
  197. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  198. string isoldcustomer = GetPostString("isoldcus");
  199. string spudata = GetPostString("spudata");
  200. if ("0".Equals(spudata))
  201. {
  202. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  203. }
  204. if ("1".Equals(spudata))
  205. {
  206. lw.Add(string.Format("spu_id <> ''"));
  207. }
  208. string finishdate1 = GetPostString("finishdate1");
  209. string finishdate2 = GetPostString("finishdate2");
  210. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  211. bool isFinish = false;
  212. if (finishdate.Length > 0)
  213. {
  214. lw.Add(finishdate);
  215. isFinish = true;
  216. paramsCount++;
  217. }
  218. if (isoldcustomer.Length > 0)
  219. {
  220. if ("2".Equals(isoldcustomer))
  221. {
  222. lw.Add(string.Format("VipCustomer=1"));
  223. }
  224. else
  225. {
  226. lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  227. }
  228. }
  229. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  230. if (ex_psize > 0)
  231. {
  232. int UserID = CurrentUser.UserID;
  233. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  234. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  235. {
  236. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  237. }
  238. dStruct.Order = "pay_time desc";
  239. }
  240. string isNew = GetPostString("isNew");
  241. if (isNew == "true")
  242. {
  243. lw.Add(string.Format("IsNew = {0}", 1));
  244. }
  245. string overtime = GetPostString("overtime");
  246. if (overtime == "1")
  247. {
  248. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  249. }
  250. String usePost = CurrentUser.UserPost.Post.Code;
  251. if (usePost.Equals("Operation") == true)
  252. {
  253. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  254. }
  255. else
  256. {
  257. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  258. }
  259. //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";
  260. if (dStruct.PageSize == 100000)
  261. {
  262. dStruct.Order = "";
  263. }
  264. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  265. DataTable dt = null;
  266. string tablename = "view_orderlist";
  267. if (isFinish)
  268. {
  269. tablename = "view_orderlist_end";
  270. }
  271. dt = WebCache.GetData(tablename, dStruct);
  272. if (dt != null && dt.Rows.Count > 0)
  273. {
  274. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  275. foreach (DataRow dr in dt.Rows)
  276. {
  277. try
  278. {
  279. if (dr["refund_fees"] != null)
  280. {
  281. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  282. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  283. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  284. if (payment == refund_fees)
  285. {
  286. dr["refund_fees"] = Math.Round(refund_fees, 2);
  287. }
  288. else if (refund_fees == total_fee)
  289. {
  290. dr["refund_fees"] = payment;
  291. }
  292. else
  293. {
  294. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  295. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  296. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  297. }
  298. }
  299. // 对象操作
  300. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  301. ceErpTradeCell.ctid = dr["ctid"].ToString();
  302. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  303. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  304. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  305. if (dStruct.PageSize != 100000)
  306. {
  307. if (dr["DispatchSort"].ToString() == "2")
  308. {
  309. dr["gongchuang"] = 200;
  310. }
  311. else if ("外协".Equals(dr["ToType"].ToString()))
  312. {
  313. dr["gongchuang"] = 200;
  314. }
  315. else if ("内部".Equals(dr["ToType"].ToString()))
  316. {
  317. dr["gongchuang"] = -1;
  318. }
  319. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  320. {
  321. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  322. dr["gongchuang"] = response.code;
  323. }
  324. }
  325. }
  326. catch (NullReferenceException ex)
  327. {
  328. // 处理空引用异常
  329. dr["refund_fees"] = "0.00";
  330. }
  331. }
  332. }
  333. writeGridDataTableJson(dStruct.TotalCount, dt);
  334. }
  335. public void get_erp_orderlist_sumprice()
  336. {
  337. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  338. return;
  339. List<string> lw = new List<string>();
  340. string tid = GetPostString("ctid");
  341. string date1 = GetPostString("date1");
  342. string date2 = GetPostString("date2");
  343. if (tid.Length > 0 || date1.Length > 0)
  344. {
  345. lw.Add(string.Format("ctid like '%{0}%'", tid));
  346. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  347. if (dw.Length > 0) lw.Add(dw);
  348. }
  349. else
  350. {
  351. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  352. }
  353. string shopname = GetPostString("shopname");
  354. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  355. string buyernick = GetPostString("buyer_nick");
  356. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  357. string customer = GetPostString("customer");
  358. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  359. string design = GetPostString("design");
  360. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  361. string orderState = GetPostString("orderState");
  362. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  363. string address = GetPostString("address");
  364. 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));
  365. string sellermemo = GetPostString("seller_memo");
  366. if (sellermemo.Length > 0)
  367. {
  368. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  369. }
  370. string apdate1 = GetPostString("apdate1");
  371. string apdate2 = GetPostString("apdate2");
  372. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  373. if (dwap.Length > 0) lw.Add(dwap);
  374. string price1 = GetPostString("price1");
  375. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  376. string price2 = GetPostString("price2");
  377. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  378. string isoldcustomer = GetPostString("isoldcus");
  379. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  380. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  381. if (PKey != "admin")
  382. {
  383. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  384. lw.Add(string.Format("shopId in ({0})", usershop));
  385. }
  386. //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";
  387. string mainWhere = string.Join(" and ", lw.ToArray());
  388. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  389. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  390. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  391. decimal total = 0;
  392. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  393. {
  394. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  395. }
  396. var res = new
  397. {
  398. data = total
  399. };
  400. string ro_jsond = JsonConvert.SerializeObject(res);
  401. returnSuccess(ro_jsond);
  402. return;
  403. }
  404. public void get_erp_CustomerServiceGather()
  405. {
  406. string userWhere = "", orderWhere = "";
  407. List<string> lw = new List<string>();
  408. string customer = GetPostString("customer");
  409. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  410. string shopname = GetPostString("shopname");
  411. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  412. string date1 = GetPostString("date1");
  413. string date2 = GetPostString("date2");
  414. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  415. if (dw.Length > 0) lw.Add(dw);
  416. orderWhere = string.Join(" and ", lw.ToArray());
  417. 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 " +
  418. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  419. "left join " +
  420. "( " +
  421. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  422. ") as b on a.ID = b.CustomerUserId " +
  423. "left join " +
  424. "( " +
  425. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  426. ") as d on a.ID = d.CustomerUserId " +
  427. "left join " +
  428. "( " +
  429. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  430. ") as e on a.ID = e.CustomerUserId " +
  431. "left join " +
  432. "( " +
  433. " select CustomerUserId, RefundCount, RefundSum from " +
  434. " ( " +
  435. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  436. " from CE_ErpTradeRefund a " +
  437. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  438. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  439. " group by CustomerUserId " +
  440. " ) as a " +
  441. ") as f on a.ID = f.CustomerUserId " +
  442. "where a.PostCode = 'CustomerService'",
  443. userWhere, orderWhere);
  444. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  445. writeGridDataTableJson(dt.Rows.Count, dt);
  446. //writeGridDataTableJson(dt.Rows.Count, dt);
  447. }
  448. //设计汇总
  449. public void get_erp_DesignerGather()
  450. {
  451. string userWhere = "", orderWhere = "";
  452. List<string> lw = new List<string>();
  453. string Designer = GetPostString("designer");
  454. int org = GetPostInt("org");
  455. if (Designer.Length > 0)
  456. {
  457. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  458. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  459. }
  460. else if (org > 0)
  461. {
  462. userWhere = string.Format(" where OrgID ={0}", org);
  463. }
  464. string shopname = GetPostString("shopname");
  465. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  466. string state = GetPostString("state");
  467. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  468. string OrderArea = GetPostString("order_area");
  469. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  470. string date1 = GetPostString("date1");
  471. string date2 = GetPostString("date2");
  472. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  473. if (dw.Length > 0) lw.Add(dw);
  474. string UpDate1 = GetPostString("UpDate1");
  475. string UpDate2 = GetPostString("UpDate2");
  476. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  477. if (dw.Length > 0) lw.Add(dw);
  478. orderWhere = string.Join(" and ", lw.ToArray());
  479. 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 (" +
  480. "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 " +
  481. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  482. "left join " +
  483. "( " +
  484. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  485. ") as b on a.ID = b.DesignUserId " +
  486. "left join " +
  487. "( " +
  488. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  489. ") as d on a.ID = d.DesignUserId " +
  490. "left join " +
  491. "( " +
  492. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  493. ") as e on a.ID = e.DesignUserId " +
  494. "left join " +
  495. "( " +
  496. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  497. ") as g on a.ID = g.DesignUserId " +
  498. "left join " +
  499. "( " +
  500. " select CustomerUserId, RefundCount, RefundSum from " +
  501. " ( " +
  502. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  503. " from CE_ErpTradeRefund a " +
  504. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  505. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  506. " group by CustomerUserId " +
  507. " ) as a " +
  508. ") as f on a.ID = f.CustomerUserId " +
  509. "where a.PostCode = 'Designer') as z",
  510. userWhere, orderWhere);
  511. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  512. writeGridDataTableJson(dt.Rows.Count, dt);
  513. }
  514. //删除tradecell的订单
  515. public void del_erp_cellorder()
  516. {
  517. if (UrlPostParmsCheck("ctid"))
  518. {
  519. string eid = GetPostString("ctid");
  520. CeErpTradeCell.DelByCtid(eid);
  521. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  522. returnSuccessMsg("删除成功");
  523. }
  524. }
  525. public void clear_erp_refundstate()
  526. {
  527. if (UrlPostParmsCheck("ids"))
  528. {
  529. string eids = GetPostString("ids");
  530. string[] ctidList = eids.Split(',');
  531. foreach (string ctid in ctidList)
  532. {
  533. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  534. if (entity != null)
  535. {
  536. entity.IsRefund = 0;
  537. entity.Update();
  538. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  539. }
  540. else
  541. continue;
  542. }
  543. returnSuccessMsg("操作成功");
  544. return;
  545. }
  546. returnErrorMsg("缺少必要参数");
  547. }
  548. public void set_erp_urgency()
  549. {
  550. if (UrlPostParmsCheck("ctid"))
  551. {
  552. string eid = GetPostString("ctid");
  553. CeErpTradeCell entity = null;
  554. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  555. if (entity != null)
  556. {
  557. double prices = commonHelper.calculationPrice(entity);
  558. if (prices <= 100)
  559. {
  560. returnErrorMsg("此订单金额不足100元,无法加急。");
  561. return;
  562. }
  563. string utime = GetPostString("urgencytime");
  564. if (utime.Length > 0)
  565. {
  566. entity.UrgencyTime = Convert.ToDateTime(utime);
  567. }
  568. else
  569. {
  570. returnErrorMsg("请选择加急时间");
  571. return;
  572. }
  573. if (entity.OrderState <= 4)
  574. {
  575. //entity.seller_memo = entity.seller_memo + "-加急";
  576. string smemo = entity.seller_memo;
  577. int kindex = smemo.IndexOf(")");
  578. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  579. if (lastoneStr != "-")
  580. {
  581. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  582. }
  583. string prememo = smemo.Substring(0, kindex + 2);
  584. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  585. int lastkindex = lastmemo.IndexOf("(");
  586. DateTime urgtime = Convert.ToDateTime(utime);
  587. string newlastmemo = "";
  588. if (lastkindex == 0)
  589. {
  590. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  591. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  592. }
  593. else
  594. {
  595. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  596. }
  597. entity.seller_memo = prememo + newlastmemo;
  598. }
  599. entity.IsUrgency = true;
  600. entity.UpdateTime = DateTime.Now;
  601. entity.Update();
  602. ApiVo apiVo = new ApiVo();
  603. apiVo.orderNumber = entity.ctid;
  604. apiVo.actionName = "changeDesign";
  605. apiVo.orderRemarks = entity.seller_memo;
  606. apiVo.remarkSign = 3;
  607. designHelper.API_WorkCore(apiVo); //changeDesign
  608. CeErpSukuraData.createInfo(entity.ctid, 7);
  609. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  610. returnSuccessMsg("设置成功!");
  611. return;
  612. }
  613. returnErrorMsg("找不到记录");
  614. }
  615. }
  616. public void set_erp_reset()
  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. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  626. {
  627. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  628. {
  629. returnErrorMsg("财务要求已下单已发货无法重置");
  630. return;
  631. }
  632. }
  633. entity.IsUrgency = false;
  634. entity.seller_memo = "";
  635. entity.OtherMemo = "";
  636. entity.OrderState = 0;
  637. entity.IsReturn = 0;
  638. //entity.IsRefund = 0;
  639. entity.MemoOpt = 0;
  640. entity.AfterSaleState = 0;
  641. entity.AfterSaleResponsible = "";
  642. entity.AfterSaleUserId = 0;
  643. entity.IsNeedBill = 0;
  644. entity.CustomerUserId = 0;
  645. entity.DesignUserId = 0;
  646. entity.SupplierId = 0;
  647. entity.PlaceUserId = 0;
  648. entity.ptid = "";
  649. entity.IsSample = 0;
  650. entity.IsXianHuo = 0;
  651. entity.isDianziOrder = 0;
  652. entity.DispatchSort = 0;
  653. entity.FinishPlaceTime = null;
  654. entity.Update();
  655. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  656. if (trade != null)
  657. {
  658. trade.seller_memo = "";
  659. trade.Update();
  660. }
  661. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  662. returnSuccessMsg("重置成功!");
  663. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  664. if (desginBill != null)
  665. {
  666. desginBill.isDel = 1;
  667. desginBill.Update();
  668. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  669. }
  670. ApiVo apiVo = new ApiVo();
  671. apiVo.orderNumber = entity.ctid;
  672. apiVo.actionName = "resetDesign";
  673. designHelper.API_WorkCore(apiVo);//resetDesign
  674. return;
  675. }
  676. returnErrorMsg("找不到记录");
  677. }
  678. }
  679. public void save_erp_sellermemo()
  680. {
  681. if (UrlPostParmsCheck("ctid"))
  682. {
  683. string ctid = GetPostString("ctid");
  684. CeErpTradeCell entity = null;
  685. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  686. if (entity != null)
  687. {
  688. string memo = GetPostString("seller_memo");
  689. memo = memo.Replace(" ", "");
  690. if (memo.Contains("补差"))
  691. {
  692. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  693. return;
  694. }
  695. List<string> bitList = new List<string>
  696. {
  697. "\\","/",":","*","?", "\"","<" ,">","|"
  698. };
  699. bool isIn = false;
  700. foreach (string bit in bitList)
  701. {
  702. if (memo.Contains(bit))
  703. {
  704. isIn = true;
  705. }
  706. }
  707. if (isIn)
  708. {
  709. returnErrorMsg("不能使用 一些符合作为文件名");
  710. return;
  711. }
  712. if (entity.seller_memo != memo)
  713. {
  714. if (entity.IsSample == 2)
  715. {
  716. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  717. return;
  718. }
  719. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  720. {
  721. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  722. {
  723. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  724. return;
  725. }
  726. /*if (CurrentUser.UserPost.Post.Code != "Place")
  727. {
  728. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  729. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  730. {
  731. returnErrorMsg("售前系统订单无法再此修改!");
  732. return;
  733. }
  734. }*/
  735. }
  736. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  737. }
  738. commonHelper.getCytPrice(entity);
  739. int memoopt = GetPostInt("MemoOpt");
  740. Boolean ismemoopt = false;
  741. if (memoopt > 0)
  742. {
  743. string stropt = "";
  744. if (memoopt == 1)
  745. {
  746. stropt = "“改稿”";
  747. ismemoopt = true;
  748. }
  749. else if (memoopt == 2)
  750. {
  751. stropt = "“定稿”";
  752. }
  753. else if (memoopt == 3)
  754. {
  755. stropt = "“查货”";
  756. CeErpSukuraData.createInfo(entity.ctid, 6);
  757. }
  758. entity.MemoOpt = Convert.ToInt32(memoopt);
  759. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  760. }
  761. if (entity.OrderState < 5)
  762. {
  763. memo = memo.Replace("(", "(");
  764. memo = memo.Replace(")", ")");
  765. }
  766. if (entity.OrderState < 3)
  767. {
  768. entity.DispatchSort = 0;
  769. }
  770. entity.seller_memo = memo;
  771. entity.UpdateTime = DateTime.Now;
  772. entity.Update();
  773. ApiVo apiVo = new ApiVo();
  774. apiVo.orderNumber = entity.ctid;
  775. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  776. apiVo.orderRemarks = memo;
  777. apiVo.remarkSign = memoopt;
  778. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  779. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  780. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  781. {
  782. dataHelper.api_orderBack(entity.ctid, "0", "");
  783. }
  784. if (entity.seller_memo.Contains("改稿"))
  785. {
  786. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  787. }
  788. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  789. returnSuccessMsg("保存成功!");
  790. return;
  791. }
  792. returnErrorMsg("找不到记录");
  793. }
  794. }
  795. public void ins_erp_checkorder()
  796. {
  797. if (UrlPostParmsCheck("ctid"))
  798. {
  799. string ctid = GetPostString("ctid");
  800. CeErpTradeCell entity = null;
  801. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  802. if (entity != null)
  803. {
  804. if (entity.OrderState < 6)
  805. {
  806. returnErrorMsg("下单完成后才可查货");
  807. return;
  808. }
  809. /*if (entity.OrderState > 6)
  810. {
  811. returnErrorMsg("订单已发货");
  812. return;
  813. }*/
  814. if (entity.FinishPlaceTime != null)
  815. {
  816. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  817. {
  818. returnErrorMsg("下单时间不足,无法查货");
  819. return;
  820. }
  821. }
  822. entity.MemoOpt = 3;
  823. entity.CheckOrderTime = DateTime.Now;
  824. entity.UpdateTime = DateTime.Now;
  825. entity.Update();
  826. CeErpSukuraData.createInfo(entity.ctid, 6);
  827. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  828. returnSuccessMsg("操作成功!");
  829. return;
  830. }
  831. returnErrorMsg("找不到记录");
  832. }
  833. }
  834. public void save_erp_othermemo()
  835. {
  836. if (UrlPostParmsCheck("ctid"))
  837. {
  838. string ctid = GetPostString("ctid");
  839. CeErpTradeCell entity = null;
  840. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  841. if (entity != null)
  842. {
  843. entity.OtherMemo = GetPostString("otherMemo");
  844. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  845. {
  846. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  847. StringBuilder sql = new StringBuilder();
  848. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  849. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  850. if (dt != null && dt.Rows.Count > 0)
  851. {
  852. foreach (DataRow dr in dt.Rows)
  853. {
  854. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  855. {
  856. //品类一直
  857. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  858. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  859. if (ceErpSampleCustomer == null)
  860. {
  861. ceErpSampleCustomer = new CeErpSampleCustomer();
  862. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  863. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  864. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  865. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  866. ceErpSampleCustomer.shopId = entity.ShopId;
  867. }
  868. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  869. ceErpSampleCustomer.lastTid = entity.tid;
  870. if (ceErpSampleCustomer.ID > 0)
  871. {
  872. ceErpSampleCustomer.Update();
  873. }
  874. else
  875. {
  876. ceErpSampleCustomer.Create();
  877. }
  878. }
  879. }
  880. }
  881. }
  882. //if (entity.IsOldCustomer == 1)
  883. //{
  884. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  885. //{
  886. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  887. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  888. //}
  889. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  890. //{
  891. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  892. // {
  893. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  894. // {
  895. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  896. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  897. // }
  898. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  899. // {
  900. // entity.OrderState = 2;
  901. // entity.DesignUserId = 0;
  902. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  903. // }
  904. // else
  905. // {
  906. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  907. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  908. // }
  909. // }
  910. //}
  911. //}
  912. entity.UpdateTime = DateTime.Now;
  913. entity.Update();
  914. returnSuccessMsg("保存成功!");
  915. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  916. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  917. if (entity.OtherMemo.Contains("改稿"))
  918. {
  919. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  920. }
  921. return;
  922. }
  923. returnErrorMsg("找不到记录");
  924. }
  925. }
  926. public void save_erp_customermemo()
  927. {
  928. if (UrlPostParmsCheck("ctid"))
  929. {
  930. string ctid = GetPostString("ctid");
  931. CeErpTradeCell entity = null;
  932. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  933. if (entity != null)
  934. {
  935. entity.UpdateTime = DateTime.Now;
  936. entity.CustomerMemo = GetPostString("CustomerMemo");
  937. entity.Update();
  938. ApiVo apiVo = new ApiVo();
  939. apiVo.orderNumber = entity.ctid;
  940. apiVo.actionName = "followRemarks";
  941. apiVo.orderRemarks = entity.CustomerMemo;
  942. designHelper.API_WorkCore(apiVo);//followRemarks
  943. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  944. returnSuccessMsg("保存成功!");
  945. return;
  946. }
  947. returnErrorMsg("找不到记录");
  948. }
  949. }
  950. public void upd_erp_addmemotag()
  951. {
  952. if (UrlPostParmsCheck("ctid"))
  953. {
  954. ;
  955. string eid = GetPostString("ctid");
  956. string sfTagstr = GetPostString("memotag");
  957. CeErpTradeCell entity = null;
  958. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  959. if (entity != null)
  960. {
  961. ApiVo apiVo = new ApiVo();
  962. if (entity.OrderState == 0)
  963. {
  964. returnErrorMsg("请先领单");
  965. return;
  966. }
  967. //撤销顺丰
  968. if (sfTagstr == "撤销顺丰")
  969. {
  970. entity.IsSF = 0;
  971. string reMsg = "";
  972. string oldmemo = entity.seller_memo;
  973. if (entity.OrderState < 5)
  974. {
  975. oldmemo = oldmemo.Replace("顺丰到付", "");
  976. oldmemo = oldmemo.Replace("顺丰寄付", "");
  977. entity.seller_memo = oldmemo;
  978. }
  979. else
  980. {
  981. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  982. {
  983. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  984. }
  985. }
  986. entity.Update();
  987. apiVo.orderNumber = entity.ctid;
  988. apiVo.actionName = "orderRemarks";
  989. apiVo.orderRemarks = entity.seller_memo;
  990. apiVo.isSf = entity.IsSF.ToString();
  991. designHelper.API_WorkCore(apiVo);//orderRemarks
  992. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  993. returnSuccessMsg("撤销成功!" + reMsg);
  994. return;
  995. }
  996. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  997. {
  998. //string oldmemo = entity.seller_memo;
  999. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  1000. string sfStr = GetPostString("memotag");
  1001. string smemo = entity.seller_memo;
  1002. int kindex = smemo.IndexOf(")");
  1003. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  1004. if (lastoneStr != "-")
  1005. {
  1006. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  1007. }
  1008. string prememo = smemo.Substring(0, kindex + 2);
  1009. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  1010. int lastkindex = lastmemo.IndexOf("(");
  1011. string newlastmemo = "";
  1012. if (lastkindex == 0)
  1013. {
  1014. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1015. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1016. }
  1017. else
  1018. {
  1019. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1020. }
  1021. entity.seller_memo = prememo + newlastmemo;
  1022. }
  1023. string sfTagMSg = "";
  1024. if (sfTagstr == "顺丰寄付")
  1025. {
  1026. entity.IsSF = 1;
  1027. sfTagMSg = "顺丰寄付";
  1028. }
  1029. else if (sfTagstr == "顺丰到付")
  1030. {
  1031. entity.IsSF = 2;
  1032. sfTagMSg = "顺丰到付";
  1033. }
  1034. entity.Update();
  1035. apiVo = new ApiVo();
  1036. apiVo.orderNumber = entity.ctid;
  1037. apiVo.actionName = "orderRemarks";
  1038. apiVo.orderRemarks = entity.seller_memo;
  1039. apiVo.isSf = entity.IsSF.ToString();
  1040. designHelper.API_WorkCore(apiVo);//orderRemarks
  1041. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1042. returnSuccessMsg("标记成功!");
  1043. return;
  1044. }
  1045. returnErrorMsg("找不到记录");
  1046. }
  1047. }
  1048. public void upd_erp_ordertag()
  1049. {
  1050. if (UrlPostParmsCheck("ctid"))
  1051. {
  1052. string eid = GetPostString("ctid");
  1053. CeErpTradeCell entity = null;
  1054. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1055. if (entity != null)
  1056. {
  1057. int tag = GetPostInt("wechattag");
  1058. //if(tag==4 && entity.IsSample == 2)
  1059. //{
  1060. // returnErrorMsg("补差价单不能标记微信单");
  1061. // return;
  1062. //}
  1063. entity.wechatTag = tag;
  1064. entity.Update();
  1065. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1066. if (tag == 1)
  1067. {
  1068. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1069. if (cash == null)
  1070. {
  1071. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1072. cash = new CeErpReturnCash();
  1073. cash.tid = entity.tid;
  1074. cash.seller_nick = main.seller_nick;
  1075. cash.payment = trade.payment;
  1076. cash.buyer_nick = main.buyer_nick;
  1077. cash.cashstate = 0;
  1078. cash.rtype = "微信返现";
  1079. cash.returnprice = 0;
  1080. cash.created = DateTime.Now;
  1081. cash.con = "订单标记微信单";
  1082. cash.img = "";
  1083. cash.applyuserid = CurrentUser.UserID;
  1084. cash.Create();
  1085. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1086. }
  1087. else
  1088. {
  1089. cash.cashstate = 0;
  1090. cash.Update();
  1091. }
  1092. CeErpSukuraData.createInfo(entity.ctid, 9);
  1093. }
  1094. else if (tag == 2)
  1095. {
  1096. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1097. if (cash == null)
  1098. {
  1099. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1100. cash = new CeErpReturnCash();
  1101. cash.tid = entity.tid;
  1102. cash.seller_nick = main.seller_nick;
  1103. cash.payment = trade.payment;
  1104. cash.buyer_nick = main.buyer_nick;
  1105. cash.cashstate = 0;
  1106. cash.rtype = "推购返现";
  1107. cash.returnprice = 5;
  1108. cash.created = DateTime.Now;
  1109. cash.con = "订单标记推购单";
  1110. cash.img = "";
  1111. cash.applyuserid = CurrentUser.UserID;
  1112. cash.Create();
  1113. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1114. }
  1115. else
  1116. {
  1117. cash.cashstate = 0;
  1118. cash.Update();
  1119. }
  1120. CeErpSukuraData.createInfo(entity.ctid, 9);
  1121. }
  1122. else if (tag == 3)
  1123. {
  1124. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1125. if (pers == null)
  1126. {
  1127. pers = new CeErpPersuade();
  1128. pers.ctid = entity.ctid;
  1129. pers.pstate = 0;
  1130. pers.created = DateTime.Now;
  1131. pers.applyuserid = CurrentUser.UserID;
  1132. pers.Create();
  1133. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1134. }
  1135. else
  1136. {
  1137. pers.pstate = 0;
  1138. pers.Update();
  1139. }
  1140. }
  1141. else if (tag == 4 || tag == 5)
  1142. {
  1143. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1144. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1145. if (pers == null)
  1146. {
  1147. pers = CeErpStayGoods.GetByTid(entity.tid);
  1148. }
  1149. if (pers == null)
  1150. {
  1151. pers = new CeErpStayGoods();
  1152. pers.t_id = entity.tid;
  1153. pers.ctid = entity.ctid;
  1154. pers.status = "待审核";
  1155. pers.audit_type = 0;
  1156. if (tag == 4)
  1157. {
  1158. pers.stay_type = "微信推购";
  1159. }
  1160. else
  1161. {
  1162. pers.stay_type = "旺旺推购";
  1163. }
  1164. if (entity.IsXianHuo == 0)
  1165. {
  1166. pers.product_id = entity.ProductId;
  1167. }
  1168. pers.wangwang = main.buyer_nick;
  1169. pers.shop_name = main.seller_nick;
  1170. pers.creata_time = DateTime.Now;
  1171. pers.create_u_id = CurrentUser.UserID;
  1172. pers.create_u_name = CurrentUser.UserName;
  1173. pers.Create();
  1174. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1175. }
  1176. else
  1177. {
  1178. pers.ctid = entity.ctid;
  1179. pers.audit_type = 0;
  1180. pers.Update();
  1181. }
  1182. CeErpSukuraData.createInfo(entity.ctid, 10);
  1183. }
  1184. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1185. returnSuccessMsg("标记成功!");
  1186. return;
  1187. }
  1188. returnErrorMsg("找不到记录");
  1189. }
  1190. }
  1191. public void upd_erp_ordertag_cancel()
  1192. {
  1193. if (UrlPostParmsCheck("ctid"))
  1194. {
  1195. string eid = GetPostString("ctid");
  1196. CeErpTradeCell entity = null;
  1197. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1198. if (entity != null)
  1199. {
  1200. entity.wechatTag = 0;
  1201. entity.Update();
  1202. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1203. if (pers != null)
  1204. {
  1205. pers.status = "取消推购";
  1206. pers.audit_type = 3;
  1207. pers.Update();
  1208. }
  1209. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1210. returnSuccessMsg("标记成功!");
  1211. return;
  1212. }
  1213. returnErrorMsg("找不到记录");
  1214. }
  1215. }
  1216. public void upd_erp_addweichattag()
  1217. {
  1218. if (UrlPostParmsCheck("ctid"))
  1219. {
  1220. ;
  1221. string eid = GetPostString("ctid");
  1222. CeErpTradeCell entity = null;
  1223. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1224. if (entity != null)
  1225. {
  1226. if (entity.IsAddWechat > 0)
  1227. {
  1228. returnErrorMsg("此单已经标记过了");
  1229. return;
  1230. }
  1231. 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);
  1232. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1233. if (dt.Rows.Count > 0)
  1234. {
  1235. entity.IsAddWechat = 2;
  1236. }
  1237. else
  1238. {
  1239. entity.IsAddWechat = 1;
  1240. }
  1241. entity.Update();
  1242. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1243. returnSuccessMsg("标记成功!");
  1244. return;
  1245. }
  1246. returnErrorMsg("找不到记录");
  1247. }
  1248. }
  1249. public void upd_erp_getmyorder()
  1250. {
  1251. if (UrlPostParmsCheck("ctid"))
  1252. {
  1253. ;
  1254. string eid = GetPostString("ctid");
  1255. CeErpTradeCell entity = null;
  1256. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1257. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1258. if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1259. {
  1260. returnErrorMsg("台湾客户需填写身份证号!");
  1261. return;
  1262. }
  1263. if (entity != null)
  1264. {
  1265. if (entity.ctid.IndexOf("C") != -1)
  1266. {
  1267. StringBuilder sql = new StringBuilder();
  1268. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1269. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1270. if (dt.Rows.Count > 0)
  1271. {
  1272. decimal total = 0;
  1273. foreach (DataRow dr in dt.Rows)
  1274. {
  1275. total += Convert.ToDecimal(dr["payment"]);
  1276. }
  1277. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1278. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1279. {
  1280. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1281. return;
  1282. }
  1283. }
  1284. }
  1285. if (entity.OrderState == -1)
  1286. {
  1287. returnErrorMsg("待审核订单无法领取!");
  1288. return;
  1289. }
  1290. entity.CustomerUserId = CurrentUser.UserID;
  1291. if (entity.OrderState < 2)
  1292. {
  1293. entity.OrderState = 2;
  1294. if (entity.ShopId != 0)
  1295. {
  1296. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1297. }
  1298. }
  1299. entity.UpdateTime = DateTime.Now;
  1300. entity.Update();
  1301. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1302. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1303. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1304. {
  1305. dataHelper.api_orderBack(entity.ctid, "0", "");
  1306. }
  1307. returnSuccessMsg("领单成功!");
  1308. return;
  1309. }
  1310. returnErrorMsg("找不到记录");
  1311. }
  1312. }
  1313. public void getmyorder_from_init()
  1314. {
  1315. if (UrlPostParmsCheck("ctid"))
  1316. {
  1317. string eid = GetPostString("ctid");
  1318. CeErpTradeCell entity = null;
  1319. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1320. if (entity != null)
  1321. {
  1322. string sellerMemo = GetPostString("sellerMemo");
  1323. if (sellerMemo.Length > 0)
  1324. {
  1325. entity.seller_memo = sellerMemo;
  1326. }
  1327. string oterhMemo = GetPostString("otherMemo");
  1328. if (oterhMemo.Length > 0)
  1329. {
  1330. entity.OtherMemo = oterhMemo;
  1331. }
  1332. int urg = GetPostInt("urgency");
  1333. entity.IsUrgency = (urg == 1 ? true : false);
  1334. int wechat = GetPostInt("wechat");
  1335. int command = GetPostInt("command");
  1336. if (wechat == 1)
  1337. {
  1338. entity.wechatTag = 1;
  1339. }
  1340. if (command == 1)
  1341. {
  1342. entity.wechatTag = 2;
  1343. }
  1344. string pPro = GetPostString("pprofession");
  1345. if (pPro.Length > 0)
  1346. {
  1347. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1348. string spro = GetPostString("profession");
  1349. if (spro.Length > 0)
  1350. {
  1351. entity.ProfessionId = Convert.ToInt32(spro);
  1352. }
  1353. }
  1354. string proId = GetPostString("productId");
  1355. if (proId.Length > 0)
  1356. {
  1357. entity.ProductId = Convert.ToInt32(proId);
  1358. }
  1359. entity.Material = GetPostString("material");
  1360. entity.Craft = GetPostString("craft");
  1361. entity.CustomerUserId = CurrentUser.UserID;
  1362. if (entity.OrderState < 2)
  1363. {
  1364. entity.OrderState = 2;
  1365. if (entity.ShopId != 0)
  1366. {
  1367. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1368. }
  1369. }
  1370. entity.Update();
  1371. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1372. returnSuccessMsg("领单成功!");
  1373. return;
  1374. }
  1375. returnErrorMsg("找不到记录");
  1376. }
  1377. }
  1378. public void upd_erp_setrelationorder()
  1379. {
  1380. if (UrlPostParmsCheck("ctid"))
  1381. {
  1382. ;
  1383. string eid = GetPostString("ctid");
  1384. string ftid = GetPostString("ftid");
  1385. CeErpTradeCell entity = null;
  1386. CeErpTradeCell fentity = null;
  1387. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1388. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1389. if (fentity == null)
  1390. {
  1391. returnErrorMsg("找不到关联的主订单");
  1392. return;
  1393. }
  1394. if (entity != null)
  1395. {
  1396. if (entity.OrderState >= 5)
  1397. {
  1398. returnErrorMsg("本单已经设计完成无法关联");
  1399. return;
  1400. }
  1401. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1402. {
  1403. returnErrorMsg("线下单续审核后才能关联!");
  1404. return;
  1405. }
  1406. entity.ptid = ftid;
  1407. entity.OrderState = fentity.OrderState;
  1408. //entity.status = fentity.status;
  1409. entity.CustomerUserId = fentity.CustomerUserId;
  1410. entity.DesignUserId = fentity.DesignUserId;
  1411. entity.seller_memo = "补差价单:" + ftid;
  1412. entity.IsSample = 2;
  1413. entity.Update();
  1414. ApiVo apiVo = new ApiVo();
  1415. apiVo.orderNumber = ftid;
  1416. apiVo.payment = entity.payment;
  1417. apiVo.actionName = "repairDesign";
  1418. designHelper.API_WorkCore(apiVo);//repairDesign
  1419. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1420. returnSuccessMsg("关联成功!");
  1421. return;
  1422. }
  1423. else
  1424. returnErrorMsg("找不到记录");
  1425. }
  1426. }
  1427. public void download_erp_neworder()
  1428. {
  1429. string seller = GetPostString("seller_nick");
  1430. string tid = GetPostString("tid");
  1431. if (seller.Length <= 0 || tid.Length <= 0)
  1432. {
  1433. returnErrorMsg("数据错误");
  1434. }
  1435. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1436. //{
  1437. // returnErrorMsg("找不到店铺Sessionkey");
  1438. //}
  1439. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1440. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1441. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1442. if (res.IndexOf("refOid") == -1)
  1443. {
  1444. returnErrorMsg("下载订单数据失败");
  1445. return;
  1446. }
  1447. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1448. returnSuccessMsg("下载完成");
  1449. //tmcHelper.createNewOrder(res);
  1450. //CeErpTrade entr = null;
  1451. //entr = CeErpTrade.Get(tid);
  1452. //if (entr != null)
  1453. //{
  1454. // returnSuccess("下载成功");
  1455. // //下载成功之后,Cell表生成对应的订单;
  1456. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1457. //}
  1458. //else
  1459. //{
  1460. // returnErrorMsg("下载失败或者创建订单失败");
  1461. //}
  1462. }
  1463. public void set_erp_atersale()
  1464. {
  1465. if (UrlPostParmsCheck("ctid"))
  1466. {
  1467. string eid = GetPostString("ctid");
  1468. string reason = GetPostString("AfterSaleReason");
  1469. CeErpTradeCell entity = null;
  1470. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1471. if (entity != null)
  1472. {
  1473. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1474. {
  1475. returnErrorMsg("此订单已经在售后");
  1476. return;
  1477. }
  1478. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1479. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1480. entity.AfterSaleTime = DateTime.Now;
  1481. entity.Update();
  1482. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1483. returnSuccessMsg("转售后成功!");
  1484. return;
  1485. }
  1486. returnErrorMsg("找不到记录");
  1487. }
  1488. }
  1489. public void set_erp_withdraw()
  1490. {
  1491. if (UrlPostParmsCheck("ctid"))
  1492. {
  1493. try
  1494. {
  1495. string eid = GetPostString("ctid");//商品id
  1496. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1497. CeWithdraw ceWithdrawSelect = null;
  1498. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1499. if (ceWithdrawSelect != null)
  1500. {
  1501. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1502. {
  1503. ceWithdrawSelect.status = -1;
  1504. ceWithdrawSelect.Update();
  1505. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1506. returnSuccessMsg("重新发起审核成功");
  1507. return;
  1508. }
  1509. else
  1510. {
  1511. returnSuccessMsg("请勿重复申请!");
  1512. return;
  1513. }
  1514. }
  1515. else
  1516. {
  1517. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1518. if (string.IsNullOrEmpty(CustomerUserId))
  1519. {
  1520. CustomerUserId = "-1";
  1521. }
  1522. int Userid = CurrentUser.UserID;//用户id
  1523. CeWithdraw ceWithdraw = new CeWithdraw();
  1524. ceWithdraw.tid = eid;
  1525. ceWithdraw.userid = Userid;
  1526. ceWithdraw.providerid = CustomerUserId;
  1527. ceWithdraw.status = 3;
  1528. ceWithdraw.creationtime = DateTime.Now;
  1529. ceWithdraw.Create();
  1530. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1531. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1532. return;
  1533. }
  1534. }
  1535. catch
  1536. {
  1537. returnErrorMsg("申请撤回订单失败");
  1538. return;
  1539. }
  1540. }
  1541. }
  1542. public void ins_erp_billinfo()
  1543. {
  1544. if (UrlPostParmsCheck("ctid"))
  1545. {
  1546. string eid = GetPostString("ctid");
  1547. CeErpTradeCell entity = null;
  1548. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1549. if (entity != null)
  1550. {
  1551. CeErpBill bill = CeErpBill.GetByTid(eid);
  1552. bool isHave = false;
  1553. if (bill != null)
  1554. {
  1555. isHave = true;
  1556. if (bill.state != 4)
  1557. {
  1558. returnErrorMsg("此单已经申请过发票了");
  1559. return;
  1560. }
  1561. }
  1562. if (entity.IsNeedBill == 0)
  1563. {
  1564. entity.IsNeedBill = 1;
  1565. }
  1566. entity.Update();
  1567. string errjson = "";
  1568. try
  1569. {
  1570. CeErpBill bill_entity = new CeErpBill();
  1571. bill_entity.tid = entity.tid;
  1572. bill_entity.title = GetPostString("title");
  1573. string taxstr = GetPostString("tax");
  1574. taxstr = taxstr.Replace(" ", "");
  1575. bill_entity.tax = taxstr;
  1576. bill_entity.bank = GetPostString("bank");
  1577. string bankacstr = GetPostString("bankac");
  1578. bankacstr = bankacstr.Replace(" ", "");
  1579. bill_entity.bankac = bankacstr;
  1580. bill_entity.address = GetPostString("address");
  1581. bill_entity.phone = GetPostString("phone");
  1582. bill_entity.price = GetPostString("price");
  1583. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1584. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1585. {
  1586. billCount += 1;
  1587. }
  1588. string prebill = "ltb";
  1589. for (int idx = 1; idx <= billCount; idx++)
  1590. {
  1591. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1592. string billoid = prebill + idx + dtstr;
  1593. bill_entity.billOrderId += billoid;
  1594. if (idx < billCount)
  1595. {
  1596. bill_entity.billOrderId += ",";
  1597. }
  1598. }
  1599. bill_entity.productId = GetPostInt("ProductName");
  1600. bill_entity.num = GetPostInt("num");
  1601. bill_entity.unit = GetPostString("unit");
  1602. bill_entity.type = GetPostString("type");
  1603. bill_entity.sendType = GetPostString("SendType");
  1604. bill_entity.email = GetPostString("email");
  1605. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1606. bill_entity.shopName = GetPostString("ShopName");
  1607. bill_entity.applymemo = GetPostString("applyMemo");
  1608. bill_entity.createTime = DateTime.Now;
  1609. bill_entity.state = 0;
  1610. bill_entity.userId = CurrentUser.UserID;
  1611. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1612. bill_entity.Create();
  1613. }
  1614. catch (Exception ex)
  1615. {
  1616. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1617. returnErrorMsg("创建发票出错!");
  1618. return;
  1619. }
  1620. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1621. returnSuccessMsg("发票申请成功!");
  1622. return;
  1623. }
  1624. returnErrorMsg("找不到记录");
  1625. }
  1626. }
  1627. public void ins_erp_neworder()
  1628. {
  1629. if (UrlPostParmsCheck("receiver_name"))
  1630. {
  1631. CeErpTrade entity = new CeErpTrade();
  1632. string plat_form = GetPostString("platform");
  1633. string preStr = "N_";
  1634. if (plat_form == "拼多多")
  1635. {
  1636. preStr = "P_";
  1637. }
  1638. else if (plat_form == "阿里巴巴")
  1639. {
  1640. preStr = "A_";
  1641. }
  1642. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1643. entity.seller_nick = GetPostString("seller_nick");
  1644. entity.buyer_nick = GetPostString("buyer_nick");
  1645. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1646. entity.total_fee = entity.payment;
  1647. entity.pay_time = DateTime.Now;
  1648. entity.status = "NOT_SHIPPED";
  1649. entity.receiver_name = GetPostString("receiver_name");
  1650. entity.receiver_mobile = GetPostString("receiver_mobile");
  1651. entity.receiver_state = GetPostString("receiver_state");
  1652. entity.receiver_city = GetPostString("receiver_city");
  1653. entity.receiver_district = GetPostString("receiver_district");
  1654. entity.receiver_address = GetPostString("receiver_address");
  1655. if (entity.receiver_state == "" || entity.receiver_city == "")
  1656. {
  1657. returnErrorMsg("收件地址不能为空");
  1658. return;
  1659. }
  1660. int shopId = 0;
  1661. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1662. if (nShop != null)
  1663. {
  1664. shopId = nShop.ID;
  1665. }
  1666. if (shopId != 34 && entity.payment == 0)
  1667. {
  1668. returnErrorMsg("公司自用的单金额才能为0");
  1669. return;
  1670. }
  1671. entity.Create();
  1672. CeErpTradeCell entitycell = new CeErpTradeCell();
  1673. entitycell.ctid = entity.tid;
  1674. entitycell.tid = entity.tid;
  1675. entitycell.ShopId = shopId;
  1676. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1677. entitycell.OrderState = 0;
  1678. entitycell.pay_time = entity.pay_time;
  1679. entitycell.IsOffLineOrder = 1;
  1680. entitycell.Create();
  1681. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1682. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1683. return;
  1684. }
  1685. }
  1686. public void ins_erp_neworder2()
  1687. {
  1688. if (UrlPostParmsCheck("receiver_name"))
  1689. {
  1690. //string plat_form = GetPostString("platform");
  1691. string preStr = "X_";
  1692. string memo = GetPostString("memo");
  1693. string productId = GetPostString("productId");
  1694. string primg = GetPostString("proofimg");
  1695. string sellerNick = GetPostString("seller_nick");
  1696. string addFrom = GetPostString("addfrom");
  1697. if (addFrom == "1")
  1698. {
  1699. preStr = "N_";
  1700. }
  1701. int shopId = 0;
  1702. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1703. if (nShop != null)
  1704. {
  1705. shopId = nShop.ID;
  1706. }
  1707. else
  1708. {
  1709. returnErrorMsg("找不到对应店铺");
  1710. return;
  1711. }
  1712. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1713. {
  1714. returnErrorMsg("必须上传付款凭证");
  1715. return;
  1716. }
  1717. CeErpTrade entity = new CeErpTrade();
  1718. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1719. entity.seller_nick = sellerNick;
  1720. entity.buyer_nick = GetPostString("buyer_nick");
  1721. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1722. entity.total_fee = entity.payment;
  1723. entity.pay_time = DateTime.Now;
  1724. entity.status = "NOT_SHIPPED";
  1725. entity.receiver_name = GetPostString("receiver_name");
  1726. entity.receiver_mobile = GetPostString("receiver_mobile");
  1727. entity.receiver_state = GetPostString("receiver_state");
  1728. entity.receiver_city = GetPostString("receiver_city");
  1729. entity.receiver_district = GetPostString("receiver_district");
  1730. entity.receiver_address = GetPostString("receiver_address");
  1731. entity.seller_memo = memo;
  1732. entity.orderFrom = 20;
  1733. entity.orderType = 15;
  1734. if (entity.receiver_state == "" || entity.receiver_city == "")
  1735. {
  1736. returnErrorMsg("收件地址不能为空");
  1737. return;
  1738. }
  1739. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1740. {
  1741. returnErrorMsg("公司自用的单金额才能为0");
  1742. return;
  1743. }
  1744. entity.Create();
  1745. string toWhere = GetPostString("towhere");
  1746. CeErpTradeCell entitycell = new CeErpTradeCell();
  1747. entitycell.ctid = entity.tid;
  1748. //唯一标识
  1749. entitycell.OrderSn = entity.tid;
  1750. string orderSn = dataHelper.getSaleOrderSn();
  1751. if (orderSn != "")
  1752. {
  1753. entitycell.OrderSn = orderSn;
  1754. }
  1755. entitycell.tid = entity.tid;
  1756. //if (preStr == "X_")
  1757. //{
  1758. entitycell.IsOffLineOrder = 1;
  1759. //}
  1760. entitycell.CustomerUserId = CurrentUser.UserID;
  1761. entitycell.PayProofImg = primg;
  1762. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1763. entitycell.ProductId = Convert.ToInt32(productId);
  1764. entitycell.ShopId = shopId;
  1765. entitycell.UpdateTime = DateTime.Now;
  1766. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1767. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1768. {
  1769. entitycell.IsXianHuo = 1;
  1770. }
  1771. entitycell.pay_time = entity.pay_time;
  1772. if (toWhere == "1")
  1773. {
  1774. entitycell.OrderState = 2;
  1775. }
  1776. else
  1777. {
  1778. entitycell.OrderState = 6;
  1779. entitycell.FinishPlaceTime = entitycell.pay_time;
  1780. }
  1781. if (shopId == 94)
  1782. {
  1783. entitycell.OrderState = 4;
  1784. entitycell.WaitDesignTime = entitycell.pay_time;
  1785. entitycell.StartDesignTime = entitycell.pay_time;
  1786. entitycell.DesignUserId = 218;
  1787. }
  1788. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1789. {
  1790. entitycell.OrderState = -1;//修改12-5
  1791. CeWithdraw ceWithdraw = new CeWithdraw();
  1792. ceWithdraw.tid = entity.tid;
  1793. ceWithdraw.providerid = "-1";
  1794. ceWithdraw.status = -1;
  1795. ceWithdraw.creationtime = DateTime.Now;
  1796. ceWithdraw.userid = 1337;
  1797. ceWithdraw.Create();
  1798. }
  1799. entitycell.Create();
  1800. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1801. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1802. {
  1803. addPlaceRegist(entitycell, CurrentUser.UserID);
  1804. }
  1805. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1806. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1807. return;
  1808. }
  1809. }
  1810. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1811. {
  1812. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1813. entity.PlactTime = tradecell.pay_time;
  1814. entity.AddUserId = userid;
  1815. entity.FileName = tradecell.seller_memo;
  1816. entity.Supplier = 24;
  1817. entity.CreateTime = DateTime.Now;
  1818. entity.Did = tradecell.ctid;
  1819. entity.tid = tradecell.tid;
  1820. entity.splitTag = tradecell.SplitTag;
  1821. entity.CurState = "未完成";
  1822. entity.Create();
  1823. }
  1824. public void get_erp_offlinelist()
  1825. {
  1826. DataStruct dStruct = GetPostStruct();
  1827. List<string> lw = new List<string>();
  1828. string tid = GetPostString("ctid");
  1829. string date1 = GetPostString("date1");
  1830. string date2 = GetPostString("date2");
  1831. if (tid.Length > 0 || date1.Length > 0)
  1832. {
  1833. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1834. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1835. if (dw.Length > 0) lw.Add(dw);
  1836. }
  1837. else
  1838. {
  1839. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1840. }
  1841. string shopname = GetPostString("shopname");
  1842. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1843. string buyernick = GetPostString("buyer_nick");
  1844. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1845. string customer = GetPostString("customer");
  1846. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1847. string design = GetPostString("design");
  1848. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1849. string orderState = GetPostString("orderState");
  1850. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1851. string address = GetPostString("address");
  1852. 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));
  1853. string sellermemo = GetPostString("seller_memo");
  1854. if (sellermemo.Length > 0)
  1855. {
  1856. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1857. }
  1858. string price1 = GetPostString("price1");
  1859. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1860. string price2 = GetPostString("price2");
  1861. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1862. //if (PKey != "admin")
  1863. //{
  1864. // string usershop = CurrentUser.User.pemShop;
  1865. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1866. //}
  1867. //if (ex_psize > 0)
  1868. //{
  1869. dStruct.Order = "pay_time desc";
  1870. //}
  1871. //else
  1872. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1873. lw.Add(string.Format("IsOffLineOrder=1"));
  1874. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1875. DataTable dt = null;
  1876. dt = WebCache.GetData("view_erptradecell", dStruct);
  1877. writeGridDataTableJson(dStruct.TotalCount, dt);
  1878. }
  1879. public void get_erp_returncashrecord()
  1880. {
  1881. DataStruct dStruct = GetPostStruct();
  1882. List<string> lw = new List<string>();
  1883. string tid = GetPostString("ctid");
  1884. if (tid.Length > 0)
  1885. {
  1886. lw.Add(string.Format("tid like '%{0}%'", tid));
  1887. dStruct.Order = "id desc";
  1888. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1889. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1890. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1891. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1892. return;
  1893. }
  1894. returnErrorMsg("id数据错误!");
  1895. }
  1896. public void ins_erp_returncashrecord()
  1897. {
  1898. if (UrlPostParmsCheck("tid"))
  1899. {
  1900. string tid = GetPostString("tid");
  1901. string retype = GetPostString("type");
  1902. StringBuilder sql = new StringBuilder();
  1903. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1904. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1905. if (dt.Rows.Count > 0)
  1906. {
  1907. returnErrorMsg("相同返现类型记录已存在");
  1908. return;
  1909. }
  1910. CeErpReturnCash entity = new CeErpReturnCash();
  1911. entity.tid = tid;
  1912. entity.seller_nick = GetPostString("seller_nick");
  1913. string pment = GetPostString("payment");
  1914. if (pment.Length > 0)
  1915. {
  1916. entity.payment = Convert.ToDouble(pment);
  1917. }
  1918. entity.buyer_nick = GetPostString("buyer_nick");
  1919. entity.cashstate = 0;
  1920. entity.rtype = retype;
  1921. string rPrice = GetPostString("returnprice");
  1922. if (rPrice.Length > 0)
  1923. {
  1924. entity.returnprice = Convert.ToDouble(rPrice);
  1925. }
  1926. entity.created = DateTime.Now;
  1927. entity.con = GetPostString("con");
  1928. entity.img = GetPostString("img");
  1929. entity.applyuserid = CurrentUser.UserID;
  1930. entity.Create();
  1931. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1932. returnSuccessMsg("操作成功!");
  1933. return;
  1934. }
  1935. }
  1936. public void set_erp_predelivery()
  1937. {
  1938. if (UrlPostParmsCheck("ctid"))
  1939. {
  1940. string eid = GetPostString("ctid");
  1941. CeErpTradeCell entity = null;
  1942. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1943. if (entity != null)
  1944. {
  1945. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1946. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1947. //{
  1948. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1949. // return;
  1950. //}
  1951. entity.IsPreDelivery = 1;
  1952. entity.Update();
  1953. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1954. returnSuccessMsg("预发货成功!");
  1955. return;
  1956. //string shop = GetPostString("seller_nick");
  1957. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1958. //string comName = GetPostString("comName");
  1959. //string comCode = GetPostString("comCode");
  1960. //string outSid = GetPostString("outSid");//运单号
  1961. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1962. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1963. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1964. //string apires = "";
  1965. //if (deliveryType == "虚拟发货")
  1966. //{
  1967. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1968. //}
  1969. //else
  1970. //{
  1971. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1972. //}
  1973. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1974. ////{
  1975. //if (apires.IndexOf("发货成功") != -1)
  1976. //{
  1977. // if (deliveryType != "虚拟发货")
  1978. // {
  1979. // //还要插入快递信息到 快递信息表
  1980. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1981. // exinfo.tid = eid;
  1982. // exinfo.out_sid = outSid;
  1983. // exinfo.company_code = comCode;
  1984. // exinfo.company_name = comName;
  1985. // exinfo.delivery_memo = deliveryMemo;
  1986. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1987. // exinfo.deliveryType = deliveryType;
  1988. // exinfo.Create();
  1989. // }
  1990. // returnSuccessMsg("发货成功!");
  1991. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1992. //}
  1993. //else
  1994. //{
  1995. // returnErrorMsg("淘宝发货失败!!");
  1996. //}
  1997. //return;
  1998. }
  1999. returnErrorMsg("找不到订单记录");
  2000. }
  2001. }
  2002. public void get_erp_unusuallist()
  2003. {
  2004. DataStruct dStruct = GetPostStruct();
  2005. List<string> lw = new List<string>();
  2006. string tid = GetPostString("ctid");
  2007. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  2008. string shopname = GetPostString("shopname");
  2009. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2010. string buyernick = GetPostString("buyer_nick");
  2011. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2012. string ResponsibleMan = GetPostString("responsible");
  2013. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2014. string date1 = GetPostString("date1");
  2015. string date2 = GetPostString("date2");
  2016. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2017. if (dw.Length > 0) lw.Add(dw);
  2018. string price1 = GetPostString("price1");
  2019. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2020. string price2 = GetPostString("price2");
  2021. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2022. string orderState = GetPostString("orderState");
  2023. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2024. string sellermemo = GetPostString("seller_memo");
  2025. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2026. lw.Add(string.Format("UnusualTag > 0"));
  2027. lw.Add(string.Format("IsRefund<={0}", 1));
  2028. dStruct.Order = "pay_time desc";
  2029. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2030. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2031. writeGridDataTableJson(dStruct.TotalCount, dt);
  2032. }
  2033. public void set_erp_unusualtonomal()
  2034. {
  2035. if (UrlPostParmsCheck("ctid"))
  2036. {
  2037. string eid = GetPostString("ctid");
  2038. CeErpTradeCell entity = null;
  2039. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2040. if (entity != null)
  2041. {
  2042. entity.UnusualTag = -1;
  2043. entity.Update();
  2044. returnSuccessMsg("忽略成功!");
  2045. return;
  2046. }
  2047. returnErrorMsg("找不到记录");
  2048. }
  2049. }
  2050. public void ins_erp_unusualreason()
  2051. {
  2052. if (UrlPostParmsCheck("ctid"))
  2053. {
  2054. string eid = GetPostString("ctid");
  2055. CeErpTradeCell entity = null;
  2056. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2057. if (entity != null)
  2058. {
  2059. entity.MemoOpt = 4;
  2060. entity.UnusualCon = GetPostString("con");
  2061. entity.Update();
  2062. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2063. if (trade != null)
  2064. {
  2065. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2066. }
  2067. //查货是否超时
  2068. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2069. if (ceErpTradeCellExtend == null)
  2070. {
  2071. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2072. ceErpTradeCellExtend.ctid = entity.ctid;
  2073. }
  2074. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2075. {
  2076. ceErpTradeCellExtend.CheckOut += 1;
  2077. }
  2078. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2079. if (ceErpTradeCellExtend.ID > 0)
  2080. {
  2081. ceErpTradeCellExtend.Update();
  2082. }
  2083. else
  2084. {
  2085. ceErpTradeCellExtend.Create();
  2086. }
  2087. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2088. returnSuccessMsg("操作成功!");
  2089. return;
  2090. }
  2091. returnErrorMsg("找不到记录");
  2092. }
  2093. }
  2094. public void upd_erp_sampleorder()
  2095. {
  2096. if (UrlPostParmsCheck("ctid"))
  2097. {
  2098. string eid = GetPostString("ctid");
  2099. string[] eArr = eid.Split(',');
  2100. if (eArr.Length > 1)
  2101. {
  2102. List<string> eLst = new List<string>();
  2103. for (int i = 0; i < eArr.Length; i++)
  2104. {
  2105. eLst.Add("'" + eArr[i] + "'");
  2106. }
  2107. eid = string.Join(",", eLst.ToArray());
  2108. }
  2109. else
  2110. {
  2111. eid = "'" + eid + "'";
  2112. }
  2113. StringBuilder sql = new StringBuilder();
  2114. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2115. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2116. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2117. if (dt.Rows.Count > 0)
  2118. {
  2119. string errmsg = "";
  2120. foreach (DataRow dr in dt.Rows)
  2121. {
  2122. StringBuilder sqlsb = new StringBuilder();
  2123. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2124. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2125. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2126. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2127. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2128. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2129. {
  2130. continue;
  2131. }
  2132. else
  2133. {
  2134. string emsg = commonHelper.KeepChinese(apires);
  2135. errmsg += emsg;
  2136. }
  2137. }
  2138. if (errmsg.Length > 0)
  2139. {
  2140. returnErrorMsg(errmsg);
  2141. return;
  2142. }
  2143. returnSuccessMsg("操作成功");
  2144. return;
  2145. }
  2146. returnErrorMsg("找不到记录");
  2147. }
  2148. }
  2149. public void upd_erp_transcustomer()
  2150. {
  2151. if (UrlPostParmsCheck("ctid"))
  2152. {
  2153. string eid = GetPostString("ctid");
  2154. int userid = GetPostInt("CustomerUserId");
  2155. CeErpTradeCell entity = null;
  2156. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2157. if (entity != null)
  2158. {
  2159. //string[] mlist = entity.seller_memo.Split('-');
  2160. //string sql = "select * from view_erpuser where id=" + userid;
  2161. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2162. //if (dt != null && dt.Rows.Count > 0)
  2163. //{
  2164. // string nmemo = "";
  2165. // for(int i = 0; i < mlist.Length - 1; i++)
  2166. // {
  2167. // nmemo += mlist[i];
  2168. // nmemo += "-";
  2169. // }
  2170. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2171. // entity.seller_memo = nmemo;
  2172. //}
  2173. entity.CustomerUserId = userid;
  2174. entity.Update();
  2175. returnSuccessMsg("操作成功!");
  2176. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2177. return;
  2178. }
  2179. returnErrorMsg("找不到记录");
  2180. }
  2181. }
  2182. public void upd_erp_transdesigner()
  2183. {
  2184. if (UrlPostParmsCheck("ctid"))
  2185. {
  2186. string eids = GetPostString("ctid");
  2187. string[] ctidList = eids.Split(',');
  2188. int userid = GetPostInt("DesignUserId");
  2189. foreach (string ctid in ctidList)
  2190. {
  2191. CeErpTradeCell entity = null;
  2192. CeErpDesignerBill entitys = null;
  2193. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2194. entitys = CeErpDesignerBill.GetByTid(ctid);
  2195. if (entity != null)
  2196. {
  2197. if (entity.OrderState > 4)
  2198. {
  2199. continue;
  2200. }
  2201. //存在退款不能流转
  2202. if (entity.IsRefund > 0)
  2203. {
  2204. continue;
  2205. }
  2206. entity.DesignUserId = userid;
  2207. entity.WaitDesignTime = DateTime.Now;
  2208. entity.Update();
  2209. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2210. }
  2211. }
  2212. returnSuccessMsg("操作成功!");
  2213. }
  2214. }
  2215. public void upd_erp_distributedesigner()
  2216. {
  2217. if (UrlPostParmsCheck("ctid"))
  2218. {
  2219. string eid = GetPostString("ctid");
  2220. int userid = GetPostInt("DesignUserId");
  2221. string[] idlist = eid.Split(',');
  2222. if (idlist.Length <= 0)
  2223. {
  2224. returnErrorMsg("订单不能为空");
  2225. return;
  2226. }
  2227. foreach (string ctid in idlist)
  2228. {
  2229. CeErpTradeCell entity = null;
  2230. CeErpDesignerBill entitys = null;
  2231. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2232. else continue;
  2233. if (entity != null)
  2234. {
  2235. if (userid == 2125 || userid == 3542)
  2236. { }
  2237. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2238. {
  2239. returnErrorMsg("金额错误的订单无法指派");
  2240. return;
  2241. }
  2242. if (entity.OrderState >= 5)
  2243. {
  2244. returnErrorMsg("已经设计完成无法指派");
  2245. return;
  2246. }
  2247. if (entity.OrderState == -1)
  2248. {
  2249. returnErrorMsg("审核中的订单无法指派");
  2250. return;
  2251. }
  2252. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2253. {
  2254. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2255. return;
  2256. }
  2257. //157赖橙帆 159林晨 73 静之颖
  2258. if (entity.OrderState > 3 && entity.DispatchSort == 2 && userid != 3542 && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Summarize" && CurrentUser.UserID != 157 && CurrentUser.UserID != 159 && CurrentUser.UserID != 1479 && CurrentUser.UserID != 73)
  2259. {
  2260. returnErrorMsg("指派设计共创无法再次指派!");
  2261. return;
  2262. }
  2263. entity.OrderState = 3;
  2264. if (entity.SupplierId == 0)
  2265. {
  2266. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2267. entity.SupplierId = suid;
  2268. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2269. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2270. }
  2271. if (userid == 2125 && entity.seller_memo != "")
  2272. {
  2273. apiDesign.API_GetPrintData_CreateOrder(entity);
  2274. }
  2275. if (userid == 3542 && entity.seller_memo != "")
  2276. {
  2277. string userPost = CurrentUser.UserPost.Post.Code;
  2278. if (CurrentUser.UserID == 73)
  2279. {
  2280. userPost = "SysAdmin";
  2281. }
  2282. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2283. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2284. if (response.msg != "设计共创:成功")
  2285. {
  2286. returnErrorMsg(response.msg);
  2287. return;
  2288. }
  2289. entity.DispatchSort = 2;
  2290. }
  2291. else
  2292. {
  2293. if (entity.DispatchSort == 2)
  2294. {
  2295. ApiVo apiVo = new ApiVo();
  2296. apiVo.actionName = "closeDesign";
  2297. apiVo.orderNumber = entity.ctid;
  2298. designHelper.API_WorkCore(apiVo);//closeDesign
  2299. }
  2300. entity.DispatchSort = 0;
  2301. }
  2302. entity.DesignUserId = userid;
  2303. entity.WaitDesignTime = DateTime.Now;
  2304. entity.UpdateTime = DateTime.Now;
  2305. entity.Update();
  2306. string name = commonHelper.getUserNameById(userid);
  2307. commonHelper.UpdateRelationOrder(entity.ctid);
  2308. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2309. }
  2310. }
  2311. returnSuccessMsg("操作成功!");
  2312. return;
  2313. }
  2314. }
  2315. public string getTidByCtid(string ctid)
  2316. {
  2317. string tid = "";
  2318. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2319. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2320. if (dataTable != null && dataTable.Rows.Count > 0)
  2321. {
  2322. tid = dataTable.Rows[0]["tid"].ToString();
  2323. }
  2324. return tid;
  2325. }
  2326. public List<string> getTidByCtidMore(string ctid)
  2327. {
  2328. 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);
  2329. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2330. List<string> list = new List<string>();
  2331. if (dataTable != null && dataTable.Rows.Count > 0)
  2332. {
  2333. foreach (DataRow item in dataTable.Rows)
  2334. {
  2335. list.Add("'" + item["tid"].ToString() + "'");
  2336. }
  2337. }
  2338. return list;
  2339. }
  2340. public List<string> getTidByCtidLike(string ctid)
  2341. {
  2342. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2343. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2344. List<string> list = new List<string>();
  2345. if (dataTable != null && dataTable.Rows.Count > 0)
  2346. {
  2347. foreach (DataRow item in dataTable.Rows)
  2348. {
  2349. list.Add("'" + item["tid"].ToString() + "'");
  2350. }
  2351. }
  2352. return list;
  2353. }
  2354. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2355. {
  2356. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2357. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2358. List<string> list = new List<string>();
  2359. if (dataTable != null && dataTable.Rows.Count > 0)
  2360. {
  2361. foreach (DataRow item in dataTable.Rows)
  2362. {
  2363. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2364. {
  2365. continue;
  2366. }
  2367. list.Add("'" + item["receiverId"].ToString() + "'");
  2368. }
  2369. }
  2370. return list;
  2371. }
  2372. public void get_erp_myorderlist()
  2373. {
  2374. DataStruct dStruct = GetPostStruct();
  2375. List<string> lw = new List<string>();
  2376. string tid = GetPostString("ctid");
  2377. if (tid.Length > 0)
  2378. {
  2379. string select_tid = getTidByCtid(tid);
  2380. lw.Add(string.Format("tid='{0}'", select_tid));
  2381. }
  2382. else
  2383. {
  2384. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2385. }
  2386. //12-1 修改
  2387. string urgent = GetPostString("urgent");
  2388. string back = GetPostString("back");
  2389. string offlineSearch = GetPostString("offlineSearch");
  2390. if (!string.IsNullOrWhiteSpace(urgent))
  2391. {
  2392. if (urgent.Equals("true"))
  2393. {
  2394. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2395. }
  2396. }
  2397. if (!string.IsNullOrWhiteSpace(back))
  2398. {
  2399. if (back.Equals("true"))
  2400. {
  2401. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2402. }
  2403. }
  2404. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2405. {
  2406. if (offlineSearch.Equals("true"))
  2407. {
  2408. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2409. }
  2410. }
  2411. //end
  2412. string shopname = GetPostString("shopname");
  2413. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2414. string buyernick = GetPostString("buyer_nick");
  2415. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2416. string design = GetPostString("design");
  2417. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2418. string orderState = GetPostString("orderState");
  2419. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2420. string sellermemo = GetPostString("seller_memo");
  2421. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2422. string date1 = GetPostString("date1");
  2423. string date2 = GetPostString("date2");
  2424. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2425. if (dw.Length > 0) lw.Add(dw);
  2426. string price1 = GetPostString("price1");
  2427. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2428. string price2 = GetPostString("price2");
  2429. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2430. string urgency = GetPostString("urgency");
  2431. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2432. string after = GetPostString("after");
  2433. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2434. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2435. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2436. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2437. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2438. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2439. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2440. if (dt != null && dt.Rows.Count > 0)
  2441. {
  2442. foreach (DataRow dr in dt.Rows)
  2443. {
  2444. try
  2445. {
  2446. // 对象操作
  2447. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2448. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2449. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2450. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2451. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2452. if (dStruct.PageSize != 100000)
  2453. {
  2454. if (dr["DispatchSort"].ToString() == "2")
  2455. {
  2456. dr["gongchuang"] = 200;
  2457. }
  2458. else if ("外协".Equals(dr["ToType"].ToString()))
  2459. {
  2460. dr["gongchuang"] = 200;
  2461. }
  2462. else if ("内部".Equals(dr["ToType"].ToString()))
  2463. {
  2464. dr["gongchuang"] = -1;
  2465. }
  2466. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2467. {
  2468. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2469. dr["gongchuang"] = response.code;
  2470. }
  2471. }
  2472. }
  2473. catch (NullReferenceException ex)
  2474. {
  2475. }
  2476. }
  2477. }
  2478. writeGridDataTableJson(dStruct.TotalCount, dt);
  2479. }
  2480. public void get_erp_myreturnorderlist()
  2481. {
  2482. DataStruct dStruct = GetPostStruct();
  2483. List<string> lw = new List<string>();
  2484. string tid = GetPostString("ctid");
  2485. if (tid.Length > 0)
  2486. {
  2487. string select_tid = getTidByCtid(tid);
  2488. lw.Add(string.Format("tid='{0}'", select_tid));
  2489. }
  2490. else
  2491. {
  2492. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2493. }
  2494. string shopname = GetPostString("shopname");
  2495. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2496. string buyernick = GetPostString("buyer_nick");
  2497. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2498. string design = GetPostString("design");
  2499. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2500. string orderState = GetPostString("orderState");
  2501. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2502. string sellermemo = GetPostString("seller_memo");
  2503. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2504. string date1 = GetPostString("date1");
  2505. string date2 = GetPostString("date2");
  2506. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2507. if (dw.Length > 0) lw.Add(dw);
  2508. string price1 = GetPostString("price1");
  2509. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2510. string price2 = GetPostString("price2");
  2511. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2512. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2513. {
  2514. lw.Add(string.Format("CusOrgID = 94"));
  2515. }
  2516. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2517. {
  2518. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2519. }
  2520. else
  2521. {
  2522. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2523. }
  2524. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2525. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2526. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2527. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2528. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2529. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2530. if (dt != null && dt.Rows.Count > 0)
  2531. {
  2532. foreach (DataRow dr in dt.Rows)
  2533. {
  2534. try
  2535. {
  2536. // 对象操作
  2537. if (dStruct.PageSize != 100000)
  2538. {
  2539. if (dr["DispatchSort"].ToString() == "2")
  2540. {
  2541. dr["gongchuang"] = 200;
  2542. }
  2543. else if ("外协".Equals(dr["ToType"].ToString()))
  2544. {
  2545. dr["gongchuang"] = 200;
  2546. }
  2547. else if ("内部".Equals(dr["ToType"].ToString()))
  2548. {
  2549. dr["gongchuang"] = -1;
  2550. }
  2551. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2552. {
  2553. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2554. dr["gongchuang"] = response.code;
  2555. }
  2556. }
  2557. }
  2558. catch (NullReferenceException ex)
  2559. {
  2560. // 处理空引用异常
  2561. }
  2562. }
  2563. }
  2564. writeGridDataTableJson(dStruct.TotalCount, dt);
  2565. }
  2566. public void get_erp_myorderlist_pregather()
  2567. {
  2568. string date1 = GetPostString("date1");
  2569. string date2 = GetPostString("date2");
  2570. int userId = CurrentUser.UserID; //客服id
  2571. string orderWhere = "";
  2572. List<string> lw = new List<string>();
  2573. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2574. if (dw.Length > 0) lw.Add(dw);
  2575. lw.Add(string.Format("CustomerUserId={0}", userId));
  2576. lw.Add(string.Format("OrderState<9"));
  2577. orderWhere = string.Join(" and ", lw.ToArray());
  2578. string orderWhere2 = "";
  2579. List<string> lw2 = new List<string>();
  2580. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2581. if (dw2.Length > 0) lw2.Add(dw2);
  2582. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2583. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2584. string sql = string.Format("select *" +
  2585. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2586. "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 " +
  2587. "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 " +
  2588. "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");
  2589. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2590. //writeGridDataTableJson(dt.Rows.Count, dt);
  2591. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2592. }
  2593. public void upd_erp_publishorder()
  2594. {
  2595. if (UrlPostParmsCheck("ctid"))
  2596. {
  2597. string eid = GetPostString("ctid");
  2598. CeErpTradeCell entity = null;
  2599. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2600. if (entity != null)
  2601. {
  2602. entity.OrderState = 0; //发布后,变为待抢单
  2603. entity.Update();
  2604. commonHelper.UpdateRelationOrder(entity.ctid);
  2605. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2606. returnSuccessMsg("发布成功!");
  2607. return;
  2608. }
  2609. returnErrorMsg("找不到记录");
  2610. }
  2611. }
  2612. public void get_erp_my_tiporder()
  2613. {
  2614. StringBuilder sql = new StringBuilder();
  2615. int userId = 0;
  2616. if (CurrentUser != null) userId = CurrentUser.UserID;
  2617. string posCode = CurrentUser.UserPost.Post.Code;
  2618. string isTipedAfterSaleVerify = GetPostString("af");
  2619. DataTable dt = new DataTable();
  2620. if (posCode != "Supplier")
  2621. {
  2622. if (posCode == "CustomerService" || posCode == "Director")
  2623. {
  2624. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2625. }
  2626. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2627. {
  2628. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2629. }
  2630. else
  2631. {
  2632. string teamIds = CurrentUser.User.TeamIds;
  2633. if (teamIds == "")
  2634. {
  2635. teamIds = "0";
  2636. }
  2637. 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);
  2638. }
  2639. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2640. }
  2641. if (dt.Rows.Count <= 0)
  2642. {
  2643. string key = "aftersale_order_" + userId;
  2644. if (RedisHelper.HasKey(key))
  2645. {
  2646. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2647. dt.Columns.Add("ctid", typeof(string));
  2648. dt.Columns.Add("IsReadTag", typeof(int));
  2649. foreach (var i in list)
  2650. {
  2651. DataRow data = dt.NewRow();
  2652. data["ctid"] = i;
  2653. data["IsReadTag"] = 4;
  2654. dt.Rows.Add(data);
  2655. }
  2656. RedisHelper.StringDelete(key);
  2657. }
  2658. }
  2659. if (dt.Rows.Count <= 0)
  2660. {
  2661. sql = new StringBuilder();
  2662. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2663. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2664. }
  2665. if (posCode == "Supplier")
  2666. {
  2667. string ids = CurrentUser.User.pemVend;
  2668. if (ids != null && ids.Length > 0)
  2669. {
  2670. string[] ids_list = ids.Split(',');
  2671. foreach (var item in ids_list)
  2672. {
  2673. string key = "return_order_" + item;
  2674. if (RedisHelper.HasKey(key))
  2675. {
  2676. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2677. dt.Columns.Add("ctid", typeof(string));
  2678. dt.Columns.Add("IsReadTag", typeof(int));
  2679. foreach (var i in list)
  2680. {
  2681. DataRow data = dt.NewRow();
  2682. data["ctid"] = i;
  2683. data["IsReadTag"] = 1;
  2684. dt.Rows.Add(data);
  2685. }
  2686. RedisHelper.StringDelete(key);
  2687. }
  2688. }
  2689. }
  2690. if (dt.Rows.Count <= 0)
  2691. {
  2692. sql = new StringBuilder();
  2693. 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);
  2694. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2695. }
  2696. }
  2697. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2698. }
  2699. public void reset_erp_tiporder()
  2700. {
  2701. string ids = GetPostString("ids");
  2702. string[] ctidList = ids.Split(',');
  2703. foreach (string ctid in ctidList)
  2704. {
  2705. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2706. if (enty != null)
  2707. {
  2708. enty.IsReadTag = 0;
  2709. enty.Update();
  2710. }
  2711. }
  2712. returnSuccessMsg("成功!");
  2713. return;
  2714. }
  2715. public void get_erp_designlist()
  2716. {
  2717. DataStruct dStruct = GetPostStruct();
  2718. List<string> lw = new List<string>();
  2719. string tid = GetPostString("ctid");
  2720. if (tid.Length > 0)
  2721. {
  2722. string select_tid = getTidByCtid(tid);
  2723. lw.Add(string.Format("tid='{0}'", select_tid));
  2724. }
  2725. string shopname = GetPostString("shopname");
  2726. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2727. string buyernick = GetPostString("buyer_nick");
  2728. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2729. string customer = GetPostString("customer");
  2730. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2731. string design = GetPostString("design");
  2732. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2733. string orderState = GetPostString("orderState");
  2734. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2735. lw.Add(string.Format("OrderState<6"));
  2736. string address = GetPostString("address");
  2737. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2738. string sellermemo = GetPostString("seller_memo");
  2739. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2740. string date1 = GetPostString("date1");
  2741. string date2 = GetPostString("date2");
  2742. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2743. if (dw.Length > 0) lw.Add(dw);
  2744. string apdate1 = GetPostString("apdate1");
  2745. string apdate2 = GetPostString("apdate2");
  2746. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2747. if (dwap.Length > 0) lw.Add(dwap);
  2748. string price1 = GetPostString("price1");
  2749. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2750. string price2 = GetPostString("price2");
  2751. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2752. string designTime = GetPostString("designtime");
  2753. if (designTime.Length > 0)
  2754. {
  2755. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2756. }
  2757. string usershop = CurrentUser.User.pemShop;
  2758. if (usershop.Length > 0)
  2759. {
  2760. lw.Add(string.Format("shopId in ({0})", usershop));
  2761. }
  2762. int myOrgid = CurrentUser.UserPost.OrgID;
  2763. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2764. if (myOrgCode.IndexOf("Designer") != -1)
  2765. {
  2766. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2767. {
  2768. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2769. }
  2770. else
  2771. {
  2772. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2773. }
  2774. }
  2775. else
  2776. {
  2777. string orgId = GetPostString("designerhd");
  2778. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2779. }
  2780. if (tid.Length > 0 || buyernick.Length > 0)
  2781. {
  2782. lw.Add(string.Format("OrderState >= 3"));
  2783. }
  2784. else
  2785. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2786. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2787. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2788. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2789. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2790. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2791. if (dt != null && dt.Rows.Count > 0)
  2792. {
  2793. foreach (DataRow dr in dt.Rows)
  2794. {
  2795. try
  2796. {
  2797. // 对象操作
  2798. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2799. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2800. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2801. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2802. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2803. if (dStruct.PageSize != 100000)
  2804. {
  2805. if (dr["DispatchSort"].ToString() == "2")
  2806. {
  2807. dr["gongchuang"] = 200;
  2808. }
  2809. else if ("外协".Equals(dr["ToType"].ToString()))
  2810. {
  2811. dr["gongchuang"] = 200;
  2812. }
  2813. else if ("内部".Equals(dr["ToType"].ToString()))
  2814. {
  2815. dr["gongchuang"] = -1;
  2816. }
  2817. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2818. {
  2819. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2820. dr["gongchuang"] = response.code;
  2821. }
  2822. }
  2823. }
  2824. catch (NullReferenceException ex)
  2825. {
  2826. }
  2827. }
  2828. }
  2829. writeGridDataTableJson(dStruct.TotalCount, dt);
  2830. }
  2831. public void get_erp_mydesignlist()
  2832. {
  2833. DataStruct dStruct = GetPostStruct();
  2834. List<string> lw = new List<string>();
  2835. string tid = GetPostString("ctid");
  2836. if (tid.Length > 0)
  2837. {
  2838. string select_tid = getTidByCtid(tid);
  2839. lw.Add(string.Format("tid='{0}'", select_tid));
  2840. }
  2841. string shopname = GetPostString("shopname");
  2842. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2843. string buyernick = GetPostString("buyer_nick");
  2844. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2845. string customer = GetPostString("customer");
  2846. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2847. string orderState = GetPostString("orderState");
  2848. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2849. //lw.Add(string.Format("OrderState<6"));
  2850. string date1 = GetPostString("date1");
  2851. string date2 = GetPostString("date2");
  2852. string dw = GetDateWhere("pay_time", date1, date2);
  2853. if (dw.Length > 0) lw.Add(dw);
  2854. string apdate1 = GetPostString("apdate1");
  2855. string apdate2 = GetPostString("apdate2");
  2856. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2857. if (dwap.Length > 0) lw.Add(dwap);
  2858. string price1 = GetPostString("price1");
  2859. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2860. string price2 = GetPostString("price2");
  2861. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2862. string olddownload = GetPostString("olddown");
  2863. if (olddownload == "1")
  2864. {
  2865. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2866. }
  2867. else if (olddownload == "2")
  2868. {
  2869. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2870. }
  2871. string sellermemo = GetPostString("seller_memo");
  2872. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2873. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2874. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2875. {
  2876. if (CurrentUser.User.TeamIds.Length > 0)
  2877. {
  2878. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2879. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2880. else
  2881. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2882. }
  2883. else
  2884. {
  2885. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2886. }
  2887. }
  2888. if (tid.Length <= 0)
  2889. {
  2890. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2891. }
  2892. lw.Add(string.Format("IsReturn!=3"));
  2893. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2894. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2895. string teamids = CurrentUser.User.TeamIds.ToString();
  2896. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2897. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2898. if (dt != null && dt.Rows.Count > 0)
  2899. {
  2900. foreach (DataRow dr in dt.Rows)
  2901. {
  2902. try
  2903. {
  2904. // 对象操作
  2905. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2906. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2907. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2908. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2909. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2910. if (dStruct.PageSize != 100000)
  2911. {
  2912. if (dr["DispatchSort"].ToString() == "2")
  2913. {
  2914. dr["gongchuang"] = 200;
  2915. }
  2916. else if ("外协".Equals(dr["ToType"].ToString()))
  2917. {
  2918. dr["gongchuang"] = 200;
  2919. }
  2920. else if ("内部".Equals(dr["ToType"].ToString()))
  2921. {
  2922. dr["gongchuang"] = -1;
  2923. }
  2924. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2925. {
  2926. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2927. dr["gongchuang"] = response.code;
  2928. }
  2929. }
  2930. }
  2931. catch (NullReferenceException ex)
  2932. {
  2933. }
  2934. }
  2935. }
  2936. writeGridDataTableJson(dStruct.TotalCount, dt);
  2937. }
  2938. public void set_erp_startdesign()
  2939. {
  2940. if (UrlPostParmsCheck("ctid"))
  2941. {
  2942. string eid = GetPostString("ctid");
  2943. CeErpTradeCell entity = null;
  2944. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2945. if (entity != null)
  2946. {
  2947. if (entity.OrderState != 3)
  2948. {
  2949. returnErrorMsg("请刷新,订单已经设计了");
  2950. return;
  2951. }
  2952. entity.StartDesignTime = DateTime.Now;
  2953. entity.OrderState = 4;
  2954. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2955. {
  2956. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2957. entity.SupplierId = suid;
  2958. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2959. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2960. }
  2961. entity.UpdateTime = DateTime.Now;
  2962. //entity.MakeSupplier = suname;
  2963. entity.Update();
  2964. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2965. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2966. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2967. commonHelper.getCytPrice(entity);
  2968. returnSuccessMsg("操作成功!");
  2969. return;
  2970. }
  2971. returnErrorMsg("找不到记录");
  2972. }
  2973. }
  2974. public void ins_erp_designselfmemo()
  2975. {
  2976. if (UrlPostParmsCheck("ctid"))
  2977. {
  2978. string eid = GetPostString("ctid");
  2979. string con = GetPostString("con");
  2980. CeErpTradeCell entity = null;
  2981. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2982. if (entity != null)
  2983. {
  2984. entity.DesignSelfMemo = con;
  2985. entity.Update();
  2986. returnSuccessMsg("操作成功!");
  2987. return;
  2988. }
  2989. returnErrorMsg("找不到记录");
  2990. }
  2991. }
  2992. public void ins_erp_designprice()
  2993. {
  2994. if (UrlPostParmsCheck("ctid"))
  2995. {
  2996. string eid = GetPostString("ctid");
  2997. int uid = CurrentUser.UserID;
  2998. string userName = CurrentUser.UserName;
  2999. CeErpTradeCell entity = null;
  3000. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  3001. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3002. if (entitys == null)
  3003. {
  3004. entitys = new CeErpDesignerBill();
  3005. }
  3006. if (entity != null)
  3007. {
  3008. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3009. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3010. entity.StartDesignTime = DateTime.Now;
  3011. entity.OrderState = 4;
  3012. string suname = "";
  3013. if (entity.SupplierId == 0)
  3014. {
  3015. int sid = commonHelper.autoDistributeToSupplier(entity);
  3016. entity.SupplierId = sid;
  3017. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3018. }
  3019. entity.Update();
  3020. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3021. if (ceErpUserPost != null)
  3022. {
  3023. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3024. if (ceErpPost != null)
  3025. {
  3026. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3027. {
  3028. entitys.tid = entity.ctid;
  3029. entitys.oid = entity.tid;
  3030. entitys.uid = uid;
  3031. entitys.userName = userName;
  3032. entitys.designerType = 1;
  3033. entitys.designerTypeText = "内部设计师";
  3034. entitys.price = Convert.ToDouble(GetPostString("price"));
  3035. entitys.designNum = GetPostInt("designNum");
  3036. entitys.modifyNum = GetPostInt("modifyNum");
  3037. entitys.designSize = GetPostString("designSize");
  3038. entitys.modifySize = GetPostString("modifySize");
  3039. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3040. {
  3041. entitys.create_time = DateTime.Now;
  3042. entitys.create_u_id = uid;
  3043. entitys.create_u_name = userName;
  3044. entitys.Save();
  3045. }
  3046. else
  3047. {
  3048. entitys.update_time = DateTime.Now;
  3049. entitys.update_u_id = uid;
  3050. entitys.update_u_name = userName;
  3051. entitys.Update();
  3052. }
  3053. }
  3054. }
  3055. }
  3056. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3057. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3058. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3059. if (suname != "")
  3060. {
  3061. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3062. }
  3063. commonHelper.getCytPrice(entity);
  3064. returnSuccessMsg("操作成功!");
  3065. return;
  3066. }
  3067. returnErrorMsg("找不到记录");
  3068. }
  3069. }
  3070. public void upload_erp_filecomplete()
  3071. {
  3072. if (UrlPostParmsCheck("ctid"))
  3073. {
  3074. string eid = GetPostString("ctid");
  3075. CeErpTradeCell entity = null;
  3076. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3077. if (entity != null)
  3078. {
  3079. entity.OrderState = 5; //设计完成
  3080. entity.Update();
  3081. returnSuccessMsg(eid + "上传成功,设计完成!");
  3082. return;
  3083. }
  3084. returnErrorMsg("找不到订单记录");
  3085. }
  3086. }
  3087. public void get_erp_designovertimelist()
  3088. {
  3089. DataStruct dStruct = GetPostStruct();
  3090. List<string> lw = new List<string>();
  3091. string tid = GetPostString("ctid");
  3092. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3093. string shopname = GetPostString("shopname");
  3094. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3095. string buyernick = GetPostString("buyer_nick");
  3096. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3097. string ResponsibleMan = GetPostString("responsible");
  3098. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3099. string date1 = GetPostString("date1");
  3100. string date2 = GetPostString("date2");
  3101. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3102. if (dw.Length > 0) lw.Add(dw);
  3103. string price1 = GetPostString("price1");
  3104. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3105. string price2 = GetPostString("price2");
  3106. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3107. string orderState = GetPostString("orderState");
  3108. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3109. string sellermemo = GetPostString("seller_memo");
  3110. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3111. lw.Add(string.Format("UnusualTag=3"));
  3112. lw.Add(string.Format("IsRefund<={0}", 1));
  3113. dStruct.Order = "WaitDesignTime desc";
  3114. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3115. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3116. writeGridDataTableJson(dStruct.TotalCount, dt);
  3117. }
  3118. //设计管理 获取抢单大厅列表
  3119. public void get_erp_grabinglist()
  3120. {
  3121. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3122. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3123. bool oldOrder = false;
  3124. if (org != null)
  3125. {
  3126. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3127. }
  3128. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3129. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3130. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3131. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3132. //先处理订单数据
  3133. if (dt.Rows.Count > 0)
  3134. {
  3135. Dictionary<string, int> design = null;
  3136. int count = 0;
  3137. foreach (DataRow row in dt.Rows)
  3138. {
  3139. if (map.ContainsKey(row["ShopId"].ToString()))
  3140. {
  3141. map.TryGetValue(row["ShopId"].ToString(), out design);
  3142. }
  3143. else
  3144. {
  3145. design = new Dictionary<string, int>();
  3146. }
  3147. if (design.ContainsKey(row["ProductId"].ToString()))
  3148. {
  3149. design.TryGetValue(row["ProductId"].ToString(), out count);
  3150. }
  3151. count++;
  3152. design[row["ProductId"].ToString()] = count;
  3153. map[row["ShopId"].ToString()] = design;
  3154. }
  3155. }
  3156. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3157. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3158. //把店铺排序和技能排序分类
  3159. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3160. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3161. if (design_dt.Rows.Count > 0)
  3162. {
  3163. Dictionary<string, string> design = null;
  3164. List<string> shopIds = null;
  3165. foreach (DataRow row in design_dt.Rows)
  3166. {
  3167. if ("0".Equals(row["designId"].ToString()))
  3168. {
  3169. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3170. {
  3171. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3172. }
  3173. else
  3174. {
  3175. shopIds = new List<string>();
  3176. }
  3177. shopIds.Add(row["shopId"].ToString());
  3178. shop_orders[row["orders"].ToString()] = shopIds;
  3179. }
  3180. else
  3181. {
  3182. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3183. {
  3184. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3185. }
  3186. else
  3187. {
  3188. design = new Dictionary<string, string>();
  3189. }
  3190. design[row["orders"].ToString()] = row["designId"].ToString();
  3191. design_orders[row["shopId"].ToString()] = design;
  3192. }
  3193. }
  3194. //处理成key value后根据key排序
  3195. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3196. foreach (List<string> val in shop_orders.Values)
  3197. {
  3198. if (val != null)
  3199. {
  3200. foreach (string key in val)
  3201. {
  3202. if (design_orders.ContainsKey(key.ToString()))
  3203. {
  3204. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3205. }
  3206. }
  3207. }
  3208. }
  3209. }
  3210. //校验哪个优先级有订单
  3211. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3212. foreach (string key in shop_orders.Keys)
  3213. {
  3214. List<string> ids = null;
  3215. shop_orders.TryGetValue(key, out ids);
  3216. //id为shopid
  3217. foreach (string id in ids)
  3218. {
  3219. Dictionary<string, int> list = null;
  3220. Dictionary<string, string> desing = null;
  3221. map.TryGetValue(id, out list);
  3222. design_orders.TryGetValue(id, out desing);
  3223. if (list != null && desing != null)
  3224. {
  3225. foreach (var item in desing)
  3226. {
  3227. int count = 0;
  3228. if (list.ContainsKey(item.Value))
  3229. {
  3230. list.TryGetValue(item.Value, out count);
  3231. if (count > 0)
  3232. {
  3233. designIds[id] = item.Value;
  3234. break;
  3235. }
  3236. }
  3237. }
  3238. }
  3239. }
  3240. if (designIds.Count > 0)
  3241. {
  3242. break;
  3243. }
  3244. }
  3245. DataTable table = new DataTable();
  3246. table.Columns.Add("tid", typeof(string));
  3247. table.Columns.Add("ctid", typeof(string));
  3248. table.Columns.Add("seller_nick", typeof(string));
  3249. table.Columns.Add("productName", typeof(string));
  3250. table.Columns.Add("pay_time", typeof(string));
  3251. table.Columns.Add("seller_memo", typeof(string));
  3252. if (designIds.Count > 0)
  3253. {
  3254. string shopId = "";
  3255. string productId = "";
  3256. foreach (var designInfo in designIds)
  3257. {
  3258. shopId = designInfo.Key;
  3259. productId = designInfo.Value;
  3260. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3261. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3262. if (dt.Rows.Count > 0)
  3263. {
  3264. foreach (DataRow row in dt.Rows)
  3265. {
  3266. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3267. {
  3268. DataRow data = table.NewRow();
  3269. data["ctid"] = row["ctid"].ToString();
  3270. data["tid"] = row["tid"].ToString();
  3271. data["seller_nick"] = ceErpShop.ShopName;
  3272. data["pay_time"] = row["pay_time"].ToString();
  3273. data["seller_memo"] = row["seller_memo"].ToString();
  3274. data["productName"] = ceErpProduct.PType;
  3275. table.Rows.Add(data);
  3276. }
  3277. }
  3278. }
  3279. }
  3280. }
  3281. writeGridDataTableJson(table.Rows.Count, table);
  3282. }
  3283. private object rushLockObject = new object();
  3284. public void set_erp_grabingorder()
  3285. {
  3286. if (UrlPostParmsCheck("ctid"))
  3287. {
  3288. int total = CurrentUser.User.Person.Total;
  3289. int userId = CurrentUser.User.ID;
  3290. int noFinish = CurrentUser.User.Person.NoFinish;
  3291. int finalization = CurrentUser.User.Person.Finalization;
  3292. string eids = GetPostString("ctid");
  3293. string key = "RushKey_" + userId;
  3294. int count = 0;
  3295. if (erpRedis.RedisHelper.KeyExists(key))
  3296. {
  3297. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3298. if (redisCount != null)
  3299. {
  3300. count = Convert.ToInt32(redisCount);
  3301. }
  3302. }
  3303. if (count >= total)
  3304. {
  3305. returnErrorMsg("半小时内已经抢" + total + "单");
  3306. return;
  3307. }
  3308. string[] ctidlist = eids.Split(',');
  3309. if (count + ctidlist.Length > total)
  3310. {
  3311. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3312. return;
  3313. }
  3314. int itag = 0;
  3315. lock (rushLockObject)
  3316. {
  3317. if (ctidlist.Length > 0)
  3318. {
  3319. string[] dtList = new string[ctidlist.Length];
  3320. for (int i = 0; i < ctidlist.Length; i++)
  3321. {
  3322. dtList[i] = "'" + ctidlist[i] + "'";
  3323. }
  3324. 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"));
  3325. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3326. if (dt_user.Rows.Count > 0)
  3327. {
  3328. int doing = 0;//未定稿
  3329. int finish = 0;//已完成
  3330. foreach (DataRow dr in dt_user.Rows)
  3331. {
  3332. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3333. {
  3334. doing++;
  3335. }
  3336. else
  3337. {
  3338. finish++;
  3339. }
  3340. }
  3341. if (doing >= noFinish)
  3342. {
  3343. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3344. return;
  3345. }
  3346. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3347. {
  3348. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3349. return;
  3350. }
  3351. }
  3352. //校验选择单子状态
  3353. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3354. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3355. if (dt.Rows.Count > 0)
  3356. {
  3357. List<string> list = new List<string>();
  3358. foreach (DataRow dr in dt.Rows)
  3359. {
  3360. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3361. {
  3362. list.Add(dr["ctid"].ToString());
  3363. }
  3364. }
  3365. if (list.Count > 0)
  3366. {
  3367. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3368. return;
  3369. }
  3370. }
  3371. foreach (string ctid in ctidlist)
  3372. {
  3373. CeErpTradeCell entity = null;
  3374. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3375. if (entity != null)
  3376. {
  3377. entity.OrderState = 3;
  3378. entity.DesignUserId = CurrentUser.UserID;
  3379. entity.WaitDesignTime = DateTime.Now;
  3380. entity.StartDesignTime = DateTime.Now;
  3381. entity.Update();
  3382. commonHelper.UpdateRelationOrder(entity.ctid);
  3383. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3384. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3385. itag++;
  3386. }
  3387. }
  3388. }
  3389. }
  3390. count += ctidlist.Length;
  3391. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3392. if (itag == 0)
  3393. returnErrorMsg("没有找到相关订单");
  3394. else
  3395. returnSuccessMsg("抢单成功!");
  3396. return;
  3397. }
  3398. }
  3399. public void get_erp_waitorderlist()
  3400. {
  3401. DataStruct dStruct = GetPostStruct();
  3402. List<string> lw = new List<string>();
  3403. string tid = GetPostString("ctid");
  3404. if (tid.Length > 0)
  3405. {
  3406. string select_tid = getTidByCtid(tid);
  3407. lw.Add(string.Format("tid='{0}'", select_tid));
  3408. }
  3409. string shopname = GetPostString("shopname");
  3410. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3411. string buyernick = GetPostString("buyer_nick");
  3412. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3413. string customer = GetPostString("customer");
  3414. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3415. string design = GetPostString("design");
  3416. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3417. string orderState = GetPostString("orderState");
  3418. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3419. string supplier = GetPostString("supplier");
  3420. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3421. string sellermemo = GetPostString("seller_memo");
  3422. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3423. string otherMemo = GetPostString("otherMemo");
  3424. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3425. string address = GetPostString("address");
  3426. 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));
  3427. string date1 = GetPostString("date1");
  3428. string date2 = GetPostString("date2");
  3429. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3430. if (dw.Length > 0) lw.Add(dw);
  3431. string price1 = GetPostString("price1");
  3432. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3433. string price2 = GetPostString("price2");
  3434. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3435. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3436. lw.Add(string.Format("IsSample != 2 "));
  3437. lw.Add(string.Format("OrderState = 5 "));
  3438. lw.Add(string.Format("IsRefund<={0}", 1));
  3439. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3440. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3441. string pagesize = GetPostString("pagesize");
  3442. if (pagesize != null)
  3443. {
  3444. dStruct.PageSize = 200;
  3445. }
  3446. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3447. List<string> tids = new List<string>();
  3448. if (dt != null)
  3449. {
  3450. dt.Columns.Add("compenPrice", typeof(double));
  3451. foreach (DataRow dr in dt.Rows)
  3452. {
  3453. if (Convert.IsDBNull(dr["compenPrice"]))
  3454. {
  3455. dr["compenPrice"] = 0;
  3456. }
  3457. tids.Add("'" + dr["tid"].ToString() + "'");
  3458. 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();
  3459. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3460. {
  3461. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3462. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3463. entity.SupplierId = suid;
  3464. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3465. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3466. entity.Update();
  3467. }
  3468. }
  3469. }
  3470. if (tids.Count > 0)
  3471. {
  3472. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3473. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3474. if (dt_price != null && dt_price.Rows.Count > 0)
  3475. {
  3476. foreach (DataRow dr in dt_price.Rows)
  3477. {
  3478. foreach (DataRow row in dt.Rows)
  3479. {
  3480. if (row["tid"].Equals(dr["ptid"]))
  3481. {
  3482. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3483. break;
  3484. }
  3485. }
  3486. }
  3487. }
  3488. }
  3489. writeGridDataTableJson(dStruct.TotalCount, dt);
  3490. }
  3491. public void get_erp_supplierwaitorderlist()
  3492. {
  3493. DataStruct dStruct = GetPostStruct();
  3494. List<string> lw = new List<string>();
  3495. string tid = GetPostString("ctid");
  3496. if (tid.Length > 0)
  3497. {
  3498. string select_tid = getTidByCtid(tid);
  3499. lw.Add(string.Format("tid='{0}'", select_tid));
  3500. }
  3501. string shopname = GetPostString("shopname");
  3502. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3503. string sellermemo = GetPostString("seller_memo");
  3504. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3505. string date1 = GetPostString("date1");
  3506. string date2 = GetPostString("date2");
  3507. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3508. if (dw.Length > 0) lw.Add(dw);
  3509. lw.Add(string.Format("OrderState = 5 "));
  3510. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3511. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3512. {
  3513. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3514. }
  3515. string supplier = GetPostString("supplier");
  3516. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3517. {
  3518. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3519. }
  3520. lw.Add(string.Format("IsRefund<={0}", 1));
  3521. dStruct.Order = "FinishDesignTime desc";
  3522. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3523. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3524. if (dt != null)
  3525. {
  3526. foreach (DataRow dr in dt.Rows)
  3527. {
  3528. 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();
  3529. }
  3530. }
  3531. writeGridDataTableJson(dStruct.TotalCount, dt);
  3532. }
  3533. public void upd_erp_verifytosupplier()
  3534. {
  3535. if (UrlPostParmsCheck("ctid"))
  3536. {
  3537. string eids = GetPostString("ctid");
  3538. CeErpTradeCell entity = null;
  3539. string[] eidsList = eids.Split(',');
  3540. if (eidsList.Length <= 0)
  3541. {
  3542. returnErrorMsg("订单号不能空");
  3543. return;
  3544. }
  3545. List<string> tLst = new List<string>();
  3546. foreach (string ctidstr in eidsList)
  3547. {
  3548. tLst.Add("'" + ctidstr + "'");
  3549. CeErpDataSendOrderInfo.createObject(ctidstr);
  3550. }
  3551. string needtids = string.Join(",", tLst.ToArray());
  3552. StringBuilder sql = new StringBuilder();
  3553. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3554. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1},IsHaveNewOrder=0 where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3555. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3556. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3557. returnSuccessMsg("操作成功!");
  3558. return;
  3559. /**foreach (string ctidstr in eidsList)
  3560. {
  3561. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3562. if (entity != null)
  3563. {
  3564. if (entity.SupplierId == 0)
  3565. {
  3566. continue;
  3567. }
  3568. entity.IsVerifyToSupplier = true;
  3569. if (entity.IsReturn == 1) //1是供应商打回
  3570. {
  3571. entity.IsReturn = 0;
  3572. }
  3573. entity.FinishPlaceTime = DateTime.Now;
  3574. entity.PlaceUserId = CurrentUser.UserID;
  3575. entity.Update();
  3576. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3577. }
  3578. }
  3579. returnSuccessMsg("操作成功!");
  3580. return;**/
  3581. }
  3582. }
  3583. public void upd_erp_supplierback()
  3584. {
  3585. if (UrlPostParmsCheck("ctid"))
  3586. {
  3587. string eid = GetPostString("ctid");
  3588. string reason = GetPostString("returnreason");
  3589. CeErpTradeCell entity = null;
  3590. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3591. if (entity != null)
  3592. {
  3593. string message = "操作成功!";
  3594. string isDown = "";
  3595. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3596. {
  3597. message = "订单有被点击下载。请注意沟通是否已下载完!";
  3598. isDown = "被点击下载";
  3599. }
  3600. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3601. {
  3602. string key = "return_order_" + entity.SupplierId;
  3603. List<string> list = new List<string>();
  3604. if (RedisHelper.HasKey(key))
  3605. {
  3606. object data = RedisHelper.StringGet(key);
  3607. list = Convert.ToString(data).Split(',').ToList();
  3608. }
  3609. list.Add(eid);
  3610. RedisHelper.StringSet(key, string.Join(",", list));
  3611. }
  3612. entity.IsVerifyToSupplier = false;
  3613. entity.IsReturn = 1;
  3614. entity.IsHaveNewOrder = 0;
  3615. entity.ReturnTime = DateTime.Now;
  3616. entity.ReturnReason = reason;
  3617. if (entity.OrderState == 6)
  3618. {
  3619. entity.OrderState = 5;
  3620. }
  3621. entity.Update();
  3622. CeErpSukuraData.createInfo(entity.ctid, 5);
  3623. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3624. returnSuccessMsg(message);
  3625. return;
  3626. }
  3627. returnErrorMsg("找不到订单记录");
  3628. }
  3629. }
  3630. public void upd_erp_toaftersaleorder()
  3631. {
  3632. if (UrlPostParmsCheck("ctid"))
  3633. {
  3634. string eid = GetPostString("ctid");
  3635. string reason = GetPostString("returnreason");
  3636. CeErpTradeCell entity = null;
  3637. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3638. if (entity != null)
  3639. {
  3640. if (entity.isAfterSaleOrder != 1)
  3641. {
  3642. returnErrorMsg("带S的售后单才能打回给售后");
  3643. return;
  3644. }
  3645. if (entity.OrderState >= 5)
  3646. {
  3647. returnErrorMsg("已经设计完成了不能打回给售后");
  3648. return;
  3649. }
  3650. entity.OrderState = 0;
  3651. entity.IsReturn = 3;
  3652. entity.ReturnTime = DateTime.Now;
  3653. entity.UpdateTime = DateTime.Now;
  3654. entity.ReturnReason = reason;
  3655. entity.Update();
  3656. CeErpSukuraData.createInfo(entity.ctid, 5);
  3657. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3658. returnSuccessMsg("操作成功!");
  3659. return;
  3660. }
  3661. returnErrorMsg("找不到订单记录");
  3662. }
  3663. }
  3664. public void upd_erp_aftersaletodesign()
  3665. {
  3666. if (UrlPostParmsCheck("ctid"))
  3667. {
  3668. string eid = GetPostString("ctid");
  3669. CeErpTradeCell entity = null;
  3670. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3671. if (entity != null)
  3672. {
  3673. entity.OrderState = 3;
  3674. entity.IsReturn = 0;
  3675. entity.UpdateTime = DateTime.Now;
  3676. entity.Update();
  3677. CeErpSukuraData.createInfo(entity.ctid, 5);
  3678. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3679. returnSuccessMsg("操作成功!");
  3680. return;
  3681. }
  3682. returnErrorMsg("找不到订单记录");
  3683. }
  3684. }
  3685. public void assign_erp_supplier()
  3686. {
  3687. if (UrlPostParmsCheck("ctid"))
  3688. {
  3689. string eids = GetPostString("ctid");
  3690. int sid = GetPostInt("SupplierName");
  3691. string fromTag = GetPostString("tag");
  3692. string[] eidList = eids.Split(',');
  3693. if (eidList.Length <= 0)
  3694. {
  3695. returnErrorMsg("指派不能为空");
  3696. return;
  3697. }
  3698. string errMsg = "";
  3699. string suname = commonHelper.getSupplierNameById(sid);
  3700. foreach (string ctid in eidList)
  3701. {
  3702. CeErpTradeCell entity = null;
  3703. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3704. if (entity != null)
  3705. {
  3706. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3707. {
  3708. errMsg += (ctid + "指派失败!!!");
  3709. continue;
  3710. }
  3711. entity.SupplierId = sid;
  3712. entity.Update();
  3713. commonHelper.UpdateRelationOrder(entity.ctid);
  3714. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3715. if (entity.OrderState >= 6)
  3716. {
  3717. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3718. //{
  3719. // string msl = entity.MakeSupplier;
  3720. // string[] mslist = msl.Split(',');
  3721. // 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);
  3722. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3723. //}
  3724. //else
  3725. //{
  3726. StringBuilder sql = new StringBuilder();
  3727. 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);
  3728. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3729. //}
  3730. }
  3731. }
  3732. else
  3733. {
  3734. continue;
  3735. }
  3736. }
  3737. if (errMsg.Length > 0)
  3738. {
  3739. returnErrorMsg(errMsg);
  3740. return;
  3741. }
  3742. returnSuccessMsg("操作成功!");
  3743. return;
  3744. }
  3745. }
  3746. public void assign_erp_makesupplier()
  3747. {
  3748. if (UrlPostParmsCheck("ctid"))
  3749. {
  3750. string eids = GetPostString("ctid");
  3751. string sname = GetPostString("SupplierName");
  3752. string[] eidList = eids.Split(',');
  3753. if (eidList.Length <= 0)
  3754. {
  3755. returnErrorMsg("指派不能为空");
  3756. return;
  3757. }
  3758. List<string> tLst = new List<string>();
  3759. foreach (string ctid in eidList)
  3760. {
  3761. CeErpTradeCell entity = null;
  3762. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3763. if (entity != null)
  3764. {
  3765. entity.MakeSupplier = sname;
  3766. entity.Update();
  3767. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3768. tLst.Add("'" + ctid + "'");
  3769. }
  3770. else
  3771. {
  3772. continue;
  3773. }
  3774. }
  3775. string ctids = string.Join(",", tLst.ToArray());
  3776. StringBuilder sql2 = new StringBuilder();
  3777. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3778. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3779. returnSuccessMsg("操作成功!");
  3780. return;
  3781. }
  3782. }
  3783. public void ins_erp_returnreason()
  3784. {
  3785. if (UrlPostParmsCheck("ctid"))
  3786. {
  3787. string eid = GetPostString("ctid");
  3788. CeErpTradeCell entity = null;
  3789. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3790. string userpost = CurrentUser.UserPost.Post.Code;
  3791. if (entity != null)
  3792. {
  3793. bool isPlace = false;
  3794. if (entity.OrderState > 6)
  3795. {
  3796. returnErrorMsg("已发货无法打回!");
  3797. return;
  3798. }
  3799. if (entity.OrderState == 6)
  3800. {
  3801. isPlace = true;
  3802. }
  3803. bool isNeedUpdateCell2 = false;
  3804. if (entity.OrderState >= 6)
  3805. {
  3806. isNeedUpdateCell2 = true;
  3807. }
  3808. int returnTag = 2;
  3809. if (userpost == "Supplier")
  3810. {
  3811. returnTag = 1;
  3812. }
  3813. int toType = GetPostInt("totype");
  3814. string fromType = "3";
  3815. if (entity.OrderState < 5)
  3816. {
  3817. fromType = "3";
  3818. }
  3819. else
  3820. {
  3821. fromType = "4";
  3822. }
  3823. if (entity.IsXianHuo == 0)
  3824. {
  3825. if (returnTag == 2)
  3826. {
  3827. if (toType == 1)
  3828. {
  3829. entity.OrderState = 0;
  3830. entity.ReturnUserType = 1;
  3831. string clearman = GetPostString("clearman");
  3832. if (!string.IsNullOrEmpty(clearman))
  3833. {
  3834. entity.DesignUserId = 0;
  3835. }
  3836. }
  3837. else
  3838. {
  3839. entity.OrderState = 3;
  3840. entity.ReturnUserType = 2;
  3841. }
  3842. entity.IsReadTag = 1;
  3843. }
  3844. else if (returnTag == 1)
  3845. {
  3846. entity.OrderState = 5;
  3847. }
  3848. entity.IsVerifyToSupplier = false;
  3849. }
  3850. if (entity.IsXianHuo == 1)
  3851. {
  3852. entity.OrderState = 5;
  3853. }
  3854. entity.UnusualTag = 0;
  3855. entity.UnusualTime = null;
  3856. entity.UnusualCon = "";
  3857. entity.IsReturn = returnTag;
  3858. entity.ReturnTime = DateTime.Now;
  3859. entity.UpdateTime = DateTime.Now;
  3860. entity.ReturnReason = GetPostString("returnreason");
  3861. entity.Update();
  3862. if (entity.OrderState == 3)
  3863. {
  3864. ApiVo apiVo = new ApiVo();
  3865. apiVo.orderNumber = entity.ctid;
  3866. apiVo.actionName = "rebutDesign";
  3867. apiVo.orderRemarks = entity.ReturnReason;
  3868. designHelper.API_WorkCore(apiVo);//rebutDesign
  3869. }
  3870. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3871. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3872. {
  3873. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3874. }
  3875. CeErpSukuraData.createInfo(entity.ctid, 5);
  3876. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3877. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3878. if (isPlace)
  3879. {
  3880. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3881. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3882. if (dth != null && dth.Rows.Count > 0)
  3883. {
  3884. dataSendOrderBean dataSendOrderBean = null;
  3885. foreach (DataRow item in dth.Rows)
  3886. {
  3887. try
  3888. {
  3889. dataSendOrderBean = new dataSendOrderBean();
  3890. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3891. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3892. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3893. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3894. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3895. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3896. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3897. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3898. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3899. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3900. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3901. dataSendOrderBean.Radio1723534706288 = "打回";
  3902. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3903. if (result != null)
  3904. {
  3905. if ("0".Equals(result.errcode))
  3906. {
  3907. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3908. }
  3909. else
  3910. {
  3911. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3912. }
  3913. }
  3914. }
  3915. catch (Exception ex)
  3916. {
  3917. }
  3918. }
  3919. }
  3920. }
  3921. if (isNeedUpdateCell2)
  3922. {
  3923. if (entity.MakeSupplier.IndexOf(",") != -1)
  3924. {
  3925. StringBuilder sql2 = new StringBuilder();
  3926. 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);
  3927. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3928. }
  3929. else
  3930. {
  3931. StringBuilder sql2 = new StringBuilder();
  3932. 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);
  3933. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3934. }
  3935. }
  3936. returnSuccessMsg("操作成功!");
  3937. return;
  3938. }
  3939. returnErrorMsg("找不到订单记录");
  3940. }
  3941. }
  3942. public void cyt_erp_returnreason()
  3943. {
  3944. if (UrlPostParmsCheck("ctid"))
  3945. {
  3946. string eid = GetPostString("ctid");
  3947. CeErpTradeCell entity = null;
  3948. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3949. string userpost = CurrentUser.UserPost.Post.Code;
  3950. if (entity != null)
  3951. {
  3952. if (entity.OrderState > 6)
  3953. {
  3954. returnErrorMsg("已发货无法打回!");
  3955. return;
  3956. }
  3957. JObject jsonObject = new JObject
  3958. {
  3959. { "Userid", "77886" },
  3960. { "Pwd", "lt666888" },
  3961. { "LTOrderId",eid }
  3962. };
  3963. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3964. JObject jsonObjects = JObject.Parse(response);
  3965. string msg = (string)jsonObjects["msg"];
  3966. if (msg != "取消成功")
  3967. {
  3968. returnErrorMsg(msg);
  3969. return;
  3970. }
  3971. bool isNeedUpdateCell2 = false;
  3972. if (entity.OrderState >= 6)
  3973. {
  3974. isNeedUpdateCell2 = true;
  3975. }
  3976. int returnTag = 2;
  3977. if (userpost == "Supplier")
  3978. {
  3979. returnTag = 1;
  3980. }
  3981. if (entity.IsXianHuo == 0)
  3982. {
  3983. if (returnTag == 2)
  3984. {
  3985. int toType = GetPostInt("totype");
  3986. if (toType == 1)
  3987. {
  3988. entity.OrderState = 0;
  3989. entity.ReturnUserType = 1;
  3990. }
  3991. else
  3992. {
  3993. entity.OrderState = 4;
  3994. entity.ReturnUserType = 2;
  3995. }
  3996. entity.IsReadTag = 1;
  3997. }
  3998. else if (returnTag == 1)
  3999. {
  4000. entity.OrderState = 5;
  4001. }
  4002. entity.IsVerifyToSupplier = false;
  4003. }
  4004. entity.UnusualTag = 0;
  4005. entity.UnusualTime = null;
  4006. entity.UnusualCon = "";
  4007. entity.IsReturn = returnTag;
  4008. entity.ReturnTime = DateTime.Now;
  4009. entity.ReturnReason = GetPostString("returnreason");
  4010. entity.Update();
  4011. if (entity.OrderState == 4)
  4012. {
  4013. ApiVo apiVo = new ApiVo();
  4014. apiVo.orderNumber = entity.ctid;
  4015. apiVo.actionName = "rebutDesign";
  4016. apiVo.orderRemarks = entity.ReturnReason;
  4017. designHelper.API_WorkCore(apiVo);//rebutDesign
  4018. }
  4019. CeErpSukuraData.createInfo(entity.ctid, 5);
  4020. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4021. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4022. if (isNeedUpdateCell2)
  4023. {
  4024. if (entity.MakeSupplier.IndexOf(",") != -1)
  4025. {
  4026. StringBuilder sql2 = new StringBuilder();
  4027. 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);
  4028. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4029. }
  4030. else
  4031. {
  4032. StringBuilder sql2 = new StringBuilder();
  4033. 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);
  4034. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4035. }
  4036. }
  4037. returnSuccessMsg("操作成功!");
  4038. return;
  4039. }
  4040. returnErrorMsg("找不到订单记录");
  4041. }
  4042. }
  4043. public void upd_erp_xianhuoreturntag()
  4044. {
  4045. if (UrlPostParmsCheck("ctid"))
  4046. {
  4047. string eids = GetPostString("ctid");
  4048. string[] ctids = eids.Split(',');
  4049. foreach (string ctid in ctids)
  4050. {
  4051. CeErpTradeCell entity = null;
  4052. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4053. if (entity != null)
  4054. {
  4055. entity.IsReturn = 0;
  4056. entity.Update();
  4057. CeErpSukuraData.createInfo(entity.ctid, 5);
  4058. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4059. }
  4060. }
  4061. returnSuccessMsg("操作成功!");
  4062. return;
  4063. }
  4064. }
  4065. public void get_erp_waitdeliverylist()
  4066. {
  4067. DataStruct dStruct = GetPostStruct();
  4068. List<string> lw = new List<string>();
  4069. string tid = GetPostString("ctid");
  4070. if (tid.Length > 0)
  4071. {
  4072. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4073. if (tid.Length > 5)
  4074. {
  4075. List<string> tids = getTidByCtidLike(tid);
  4076. if (tids.Count > 0 && tids.Count < 10)
  4077. {
  4078. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4079. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4080. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4081. {
  4082. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4083. }*/
  4084. }
  4085. }
  4086. lw.Add(tid_sql);
  4087. }
  4088. string shopname = GetPostString("shopname");
  4089. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4090. string buyernick = GetPostString("buyer_nick");
  4091. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4092. //if (tid.Length == 0 && buyernick.Length == 0)
  4093. //{
  4094. // lw.Add(string.Format("IsRefund<={0}", 1));
  4095. //}
  4096. string customer = GetPostString("customer");
  4097. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4098. string design = GetPostString("design");
  4099. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4100. string orderState = GetPostString("orderState");
  4101. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4102. string address = GetPostString("address");
  4103. 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));
  4104. string sellermemo = GetPostString("seller_memo");
  4105. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4106. string supplier = GetPostString("supplier");
  4107. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4108. string OrderArea = GetPostString("order_area");
  4109. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4110. string placedate1 = GetPostString("placedate1");
  4111. string placedate2 = GetPostString("placedate2");
  4112. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4113. if (fdw.Length > 0) lw.Add(fdw);
  4114. string price1 = GetPostString("price1");
  4115. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4116. string price2 = GetPostString("price2");
  4117. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4118. string unusualCon = GetPostString("unusualcon");
  4119. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4120. string otherMemo = GetPostString("otherMemo");
  4121. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4122. string posTag = CurrentUser.UserPost.Post.Code;
  4123. if (posTag == "Supplier")
  4124. {
  4125. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4126. }
  4127. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4128. lw.Add(string.Format("type != 'PDD' "));
  4129. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4130. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4131. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4132. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4133. writeGridDataTableJson(dStruct.TotalCount, dt);
  4134. }
  4135. public void get_erp_changedeliverylist()
  4136. {
  4137. DataStruct dStruct = GetPostStruct();
  4138. List<string> lw = new List<string>();
  4139. string tid = GetPostString("ctid");
  4140. if (tid.Length > 0)
  4141. {
  4142. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4143. if (tid.Length > 5)
  4144. {
  4145. List<string> tids = getTidByCtidLike(tid);
  4146. if (tids.Count > 0 && tids.Count < 10)
  4147. {
  4148. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4149. }
  4150. }
  4151. lw.Add(tid_sql);
  4152. }
  4153. string shopname = GetPostString("shopname");
  4154. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4155. string buyernick = GetPostString("buyer_nick");
  4156. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4157. //if (tid.Length == 0 && buyernick.Length == 0)
  4158. //{
  4159. // lw.Add(string.Format("IsRefund<={0}", 1));
  4160. //}
  4161. string customer = GetPostString("customer");
  4162. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4163. string design = GetPostString("design");
  4164. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4165. string orderState = GetPostString("orderState");
  4166. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4167. string address = GetPostString("address");
  4168. 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));
  4169. string sellermemo = GetPostString("seller_memo");
  4170. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4171. string supplier = GetPostString("supplier");
  4172. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4173. string OrderArea = GetPostString("order_area");
  4174. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4175. string placedate1 = GetPostString("placedate1");
  4176. string placedate2 = GetPostString("placedate2");
  4177. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4178. if (fdw.Length > 0) lw.Add(fdw);
  4179. string price1 = GetPostString("price1");
  4180. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4181. string price2 = GetPostString("price2");
  4182. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4183. string unusualCon = GetPostString("unusualcon");
  4184. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4185. string otherMemo = GetPostString("otherMemo");
  4186. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4187. string posTag = CurrentUser.UserPost.Post.Code;
  4188. if (posTag == "Supplier")
  4189. {
  4190. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4191. }
  4192. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4193. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4194. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4195. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4196. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4197. /*if (tid.Length > 0)
  4198. {
  4199. List<string> tids = new List<string>();
  4200. if (dt != null && dt.Rows.Count > 0)
  4201. {
  4202. foreach (DataRow item in dt.Rows)
  4203. {
  4204. tids.Add("'" + item["tid"] + "'");
  4205. }
  4206. }
  4207. if (tids.Count > 0)
  4208. {
  4209. lw.RemoveAt(0);
  4210. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4211. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4212. dt = WebCache.GetData("view_erptradecell", dStruct);
  4213. }
  4214. }*/
  4215. writeGridDataTableJson(dStruct.TotalCount, dt);
  4216. }
  4217. public void get_erp_pddderiving()
  4218. {
  4219. DataStruct dStruct = GetPostStruct();
  4220. List<string> lw = new List<string>();
  4221. string tid = GetPostString("ctid");
  4222. if (tid.Length > 0)
  4223. {
  4224. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4225. if (tid.Length > 5)
  4226. {
  4227. List<string> tids = getTidByCtidLike(tid);
  4228. if (tids.Count > 0 && tids.Count < 10)
  4229. {
  4230. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4231. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4232. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4233. {
  4234. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4235. }*/
  4236. }
  4237. }
  4238. lw.Add(tid_sql);
  4239. }
  4240. string shopname = GetPostString("shopname");
  4241. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4242. string buyernick = GetPostString("buyer_nick");
  4243. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4244. //if (tid.Length == 0 && buyernick.Length == 0)
  4245. //{
  4246. // lw.Add(string.Format("IsRefund<={0}", 1));
  4247. //}
  4248. string customer = GetPostString("customer");
  4249. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4250. string design = GetPostString("design");
  4251. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4252. string orderState = GetPostString("orderState");
  4253. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4254. string address = GetPostString("address");
  4255. 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));
  4256. string sellermemo = GetPostString("seller_memo");
  4257. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4258. string supplier = GetPostString("supplier");
  4259. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4260. string OrderArea = GetPostString("order_area");
  4261. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4262. string placedate1 = GetPostString("placedate1");
  4263. string placedate2 = GetPostString("placedate2");
  4264. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4265. if (fdw.Length > 0) lw.Add(fdw);
  4266. string price1 = GetPostString("price1");
  4267. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4268. string price2 = GetPostString("price2");
  4269. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4270. string unusualCon = GetPostString("unusualcon");
  4271. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4272. string posTag = CurrentUser.UserPost.Post.Code;
  4273. if (posTag == "Supplier")
  4274. {
  4275. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4276. }
  4277. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4278. lw.Add(string.Format("type = 'PDD' "));
  4279. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4280. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4281. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4282. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4283. /*if (tid.Length > 0)
  4284. {
  4285. List<string> tids = new List<string>();
  4286. if (dt != null && dt.Rows.Count > 0)
  4287. {
  4288. foreach (DataRow item in dt.Rows)
  4289. {
  4290. tids.Add("'" + item["tid"] + "'");
  4291. }
  4292. }
  4293. if (tids.Count > 0)
  4294. {
  4295. lw.RemoveAt(0);
  4296. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4297. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4298. dt = WebCache.GetData("view_erptradecell", dStruct);
  4299. }
  4300. }*/
  4301. writeGridDataTableJson(dStruct.TotalCount, dt);
  4302. }
  4303. public void get_erp_jdderiving()
  4304. {
  4305. DataStruct dStruct = GetPostStruct();
  4306. List<string> lw = new List<string>();
  4307. string tid = GetPostString("ctid");
  4308. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4309. string shopname = GetPostString("shopname");
  4310. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4311. string buyernick = GetPostString("buyer_nick");
  4312. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4313. //if (tid.Length == 0 && buyernick.Length == 0)
  4314. //{
  4315. // lw.Add(string.Format("IsRefund<={0}", 1));
  4316. //}
  4317. string customer = GetPostString("customer");
  4318. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4319. string design = GetPostString("design");
  4320. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4321. string orderState = GetPostString("orderState");
  4322. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4323. string address = GetPostString("address");
  4324. 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));
  4325. string sellermemo = GetPostString("seller_memo");
  4326. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4327. string supplier = GetPostString("supplier");
  4328. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4329. string OrderArea = GetPostString("order_area");
  4330. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4331. string placedate1 = GetPostString("placedate1");
  4332. string placedate2 = GetPostString("placedate2");
  4333. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4334. if (fdw.Length > 0) lw.Add(fdw);
  4335. string price1 = GetPostString("price1");
  4336. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4337. string price2 = GetPostString("price2");
  4338. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4339. string unusualCon = GetPostString("unusualcon");
  4340. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4341. string posTag = CurrentUser.UserPost.Post.Code;
  4342. if (posTag == "Supplier")
  4343. {
  4344. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4345. }
  4346. lw.Add(string.Format("OrderState = 6 "));
  4347. lw.Add(string.Format("type = 'JD' "));
  4348. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4349. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4350. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4351. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4352. writeGridDataTableJson(dStruct.TotalCount, dt);
  4353. }
  4354. public void get_erp_demoorderlist()
  4355. {
  4356. DataStruct dStruct = GetPostStruct();
  4357. List<string> lw = new List<string>();
  4358. string tid = GetPostString("ctid");
  4359. if (tid.Length > 0)
  4360. {
  4361. string select_tid = getTidByCtid(tid);
  4362. lw.Add(string.Format("tid='{0}'", select_tid));
  4363. }
  4364. string shopname = GetPostString("shopname");
  4365. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4366. string buyernick = GetPostString("buyer_nick");
  4367. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4368. string customer = GetPostString("customer");
  4369. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4370. string design = GetPostString("design");
  4371. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4372. string orderState = GetPostString("orderState");
  4373. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4374. string address = GetPostString("address");
  4375. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4376. string sellermemo = GetPostString("seller_memo");
  4377. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4378. string supplier = GetPostString("supplier");
  4379. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4380. string OrderArea = GetPostString("order_area");
  4381. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4382. string date1 = GetPostString("date1");
  4383. string date2 = GetPostString("date2");
  4384. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4385. if (dw.Length > 0) lw.Add(dw);
  4386. string price1 = GetPostString("price1");
  4387. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4388. string price2 = GetPostString("price2");
  4389. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4390. string posTag = CurrentUser.UserPost.Post.Code;
  4391. if (posTag == "Supplier")
  4392. {
  4393. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4394. }
  4395. //lw.Add(string.Format("OrderState = 6 "));
  4396. lw.Add(string.Format("IsSample={0}", 3));
  4397. lw.Add(string.Format("IsRefund<={0}", 1));
  4398. dStruct.Order = "pay_time desc";
  4399. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4400. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4401. writeGridDataTableJson(dStruct.TotalCount, dt);
  4402. }
  4403. public void save_erp_checkmemo()
  4404. {
  4405. if (UrlPostParmsCheck("ctid"))
  4406. {
  4407. string ctid = GetPostString("ctid");
  4408. CeErpTradeCell entity = null;
  4409. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4410. if (entity != null)
  4411. {
  4412. entity.CheckMemo = GetPostString("CheckMemo");
  4413. entity.Update();
  4414. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4415. if (trade != null)
  4416. {
  4417. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4418. }
  4419. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4420. returnSuccessMsg("保存成功!");
  4421. return;
  4422. }
  4423. returnErrorMsg("找不到记录");
  4424. }
  4425. }
  4426. public void get_erp_returnlist()
  4427. {
  4428. DataStruct dStruct = GetPostStruct();
  4429. List<string> lw = new List<string>();
  4430. string tid = GetPostString("ctid");
  4431. if (tid.Length > 0)
  4432. {
  4433. string select_tid = getTidByCtid(tid);
  4434. lw.Add(string.Format("tid='{0}'", select_tid));
  4435. }
  4436. string shopname = GetPostString("shopname");
  4437. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4438. string buyernick = GetPostString("buyer_nick");
  4439. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4440. string customer = GetPostString("customer");
  4441. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4442. string design = GetPostString("design");
  4443. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4444. string orderState = GetPostString("orderState");
  4445. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4446. string address = GetPostString("address");
  4447. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4448. string sellermemo = GetPostString("seller_memo");
  4449. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4450. string supplier = GetPostString("supplier");
  4451. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4452. string date1 = GetPostString("date1");
  4453. string date2 = GetPostString("date2");
  4454. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4455. if (dw.Length > 0) lw.Add(dw);
  4456. string bdate1 = GetPostString("backdate1");
  4457. string bdate2 = GetPostString("backdate2");
  4458. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4459. if (dw_back.Length > 0) lw.Add(dw_back);
  4460. string price1 = GetPostString("price1");
  4461. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4462. string price2 = GetPostString("price2");
  4463. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4464. lw.Add(string.Format("IsReturn>0"));
  4465. lw.Add(string.Format("IsXianHuo=0"));
  4466. lw.Add(string.Format("IsReturn!=3"));
  4467. string backtype = GetPostString("backtype");
  4468. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4469. dStruct.Order = "FinishDesignTime desc";
  4470. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4471. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4472. writeGridDataTableJson(dStruct.TotalCount, dt);
  4473. }
  4474. public void get_erp_today_sumreturn()
  4475. {
  4476. DataStruct dStruct = GetPostStruct();
  4477. List<string> lw = new List<string>();
  4478. string bdate1 = GetPostString("returnTimeS");
  4479. string bdate2 = GetPostString("returnTimeE");
  4480. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4481. if (dw_back.Length > 0) lw.Add(dw_back);
  4482. lw.Add(string.Format("IsReturn=0"));
  4483. lw.Add(string.Format("IsXianHuo=0"));
  4484. string mainWhere = string.Join(" and ", lw.ToArray());
  4485. string sql = "";
  4486. if (dw_back.Length > 0)
  4487. {
  4488. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4489. }
  4490. else
  4491. {
  4492. 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 + "'";
  4493. }
  4494. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4495. decimal total = 0, today_finish = 0;
  4496. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4497. {
  4498. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4499. }
  4500. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4501. {
  4502. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4503. }
  4504. var res = new
  4505. {
  4506. data = total,
  4507. data1 = today_finish,
  4508. };
  4509. string ro_jsond = JsonConvert.SerializeObject(res);
  4510. returnSuccess(ro_jsond);
  4511. return;
  4512. }
  4513. public void get_erp_allreturnlist()
  4514. {
  4515. DataStruct dStruct = GetPostStruct();
  4516. List<string> lw = new List<string>();
  4517. string tid = GetPostString("ctid");
  4518. if (tid.Length > 0)
  4519. {
  4520. string select_tid = getTidByCtid(tid);
  4521. lw.Add(string.Format("tid='{0}'", select_tid));
  4522. }
  4523. string shopname = GetPostString("shopname");
  4524. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4525. string buyernick = GetPostString("buyer_nick");
  4526. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4527. string customer = GetPostString("customer");
  4528. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4529. string design = GetPostString("design");
  4530. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4531. string orderState = GetPostString("orderState");
  4532. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4533. string address = GetPostString("address");
  4534. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4535. string sellermemo = GetPostString("seller_memo");
  4536. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4537. string supplier = GetPostString("supplier");
  4538. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4539. string date1 = GetPostString("date1");
  4540. string date2 = GetPostString("date2");
  4541. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4542. if (dw.Length > 0) lw.Add(dw);
  4543. string bdate1 = GetPostString("backdate1");
  4544. string bdate2 = GetPostString("backdate2");
  4545. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4546. if (dw_back.Length > 0) lw.Add(dw_back);
  4547. string price1 = GetPostString("price1");
  4548. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4549. string price2 = GetPostString("price2");
  4550. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4551. string backreason = GetPostString("backreason");
  4552. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4553. lw.Add(string.Format("IsXianHuo=0"));
  4554. lw.Add(string.Format("ReturnTime != ''"));
  4555. string backtype = GetPostString("backtype");
  4556. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4557. dStruct.Order = "FinishDesignTime desc";
  4558. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4559. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4560. writeGridDataTableJson(dStruct.TotalCount, dt);
  4561. }
  4562. public void get_erp_aftersalereturnlist()
  4563. {
  4564. DataStruct dStruct = GetPostStruct();
  4565. List<string> lw = new List<string>();
  4566. string tid = GetPostString("ctid");
  4567. if (tid.Length > 0)
  4568. {
  4569. string select_tid = getTidByCtid(tid);
  4570. lw.Add(string.Format("tid='{0}'", select_tid));
  4571. }
  4572. string shopname = GetPostString("shopname");
  4573. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4574. string buyernick = GetPostString("buyer_nick");
  4575. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4576. string customer = GetPostString("customer");
  4577. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4578. string design = GetPostString("design");
  4579. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4580. string orderState = GetPostString("orderState");
  4581. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4582. string address = GetPostString("address");
  4583. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4584. string sellermemo = GetPostString("seller_memo");
  4585. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4586. string supplier = GetPostString("supplier");
  4587. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4588. string date1 = GetPostString("date1");
  4589. string date2 = GetPostString("date2");
  4590. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4591. if (dw.Length > 0) lw.Add(dw);
  4592. string bdate1 = GetPostString("backdate1");
  4593. string bdate2 = GetPostString("backdate2");
  4594. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4595. if (dw_back.Length > 0) lw.Add(dw_back);
  4596. string price1 = GetPostString("price1");
  4597. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4598. string price2 = GetPostString("price2");
  4599. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4600. lw.Add(string.Format("IsReturn=3"));
  4601. string backtype = GetPostString("backtype");
  4602. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4603. string backreason = GetPostString("backreason");
  4604. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4605. dStruct.Order = "ReturnTime desc";
  4606. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4607. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4608. writeGridDataTableJson(dStruct.TotalCount, dt);
  4609. }
  4610. public void get_erp_xianhuoreturnlist()
  4611. {
  4612. DataStruct dStruct = GetPostStruct();
  4613. List<string> lw = new List<string>();
  4614. string tid = GetPostString("ctid");
  4615. if (tid.Length > 0)
  4616. {
  4617. string select_tid = getTidByCtid(tid);
  4618. lw.Add(string.Format("tid='{0}'", select_tid));
  4619. }
  4620. string shopname = GetPostString("shopname");
  4621. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4622. string buyernick = GetPostString("buyer_nick");
  4623. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4624. string customer = GetPostString("customer");
  4625. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4626. string design = GetPostString("design");
  4627. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4628. string orderState = GetPostString("orderState");
  4629. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4630. string address = GetPostString("address");
  4631. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4632. string sellermemo = GetPostString("seller_memo");
  4633. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4634. string supplier = GetPostString("supplier");
  4635. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4636. string OrderArea = GetPostString("order_area");
  4637. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4638. string date1 = GetPostString("date1");
  4639. string date2 = GetPostString("date2");
  4640. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4641. if (dw.Length > 0) lw.Add(dw);
  4642. string price1 = GetPostString("price1");
  4643. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4644. string price2 = GetPostString("price2");
  4645. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4646. string posTag = CurrentUser.UserPost.Post.Code;
  4647. if (posTag == "Supplier")
  4648. {
  4649. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4650. }
  4651. lw.Add(string.Format("OrderState=6 "));
  4652. lw.Add(string.Format("IsXianHuo=1 "));
  4653. lw.Add(string.Format("IsReturn>0 "));
  4654. lw.Add(string.Format("IsReturn!=3"));
  4655. lw.Add(string.Format("IsRefund<={0}", 1));
  4656. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4657. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4658. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4659. writeGridDataTableJson(dStruct.TotalCount, dt);
  4660. }
  4661. public void set_erp_orderdelivery()
  4662. {
  4663. if (UrlPostParmsCheck("ctid"))
  4664. {
  4665. string eid = GetPostString("ctid");
  4666. CeErpTradeCell entity = null;
  4667. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4668. if (entity != null)
  4669. {
  4670. if (entity.OrderState >= 7)
  4671. {
  4672. returnErrorMsg("此单已发货,无需重复发货");
  4673. return;
  4674. }
  4675. if (entity.OrderState != 6)
  4676. {
  4677. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4678. return;
  4679. }
  4680. string shop = GetPostString("seller_nick");
  4681. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4682. string comName = GetPostString("comName");
  4683. string comCode = GetPostString("comCode");
  4684. string outSid = GetPostString("outSid");
  4685. string deliveryType = GetPostString("deliveryType");
  4686. string deliveryMemo = GetPostString("deliveryMemo");
  4687. outSid = outSid.Trim();
  4688. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4689. if (mainEn == null)
  4690. {
  4691. returnErrorMsg("找不到原始订单记录");
  4692. return;
  4693. }
  4694. bool isInitOrderDeliv = false;
  4695. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4696. {
  4697. isInitOrderDeliv = true;
  4698. }
  4699. string apires = "";
  4700. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4701. 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)
  4702. {
  4703. apires = "发货成功true";
  4704. }
  4705. else
  4706. {
  4707. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4708. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4709. }
  4710. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4711. {
  4712. entity.OrderState = 7;//发货后订单已发货
  4713. entity.OutSid = outSid;
  4714. entity.MemoOpt = 0;
  4715. entity.UpdateTime = DateTime.Now;
  4716. entity.FinishDeliveryTime = DateTime.Now;
  4717. entity.Update();
  4718. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4719. commonHelper.UpdateRelationOrder(entity.ctid);
  4720. //还要插入快递信息到 快递信息表
  4721. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4722. exinfo.tid = eid;
  4723. exinfo.out_sid = outSid;
  4724. exinfo.company_code = comCode;
  4725. exinfo.company_name = comName;
  4726. exinfo.delivery_memo = deliveryMemo;
  4727. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4728. exinfo.deliveryType = deliveryType;
  4729. exinfo.Create();
  4730. returnSuccessMsg("发货操作成功!");
  4731. commonHelper.UpdateRelationOrder(entity.ctid);
  4732. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4733. CeErpSukuraData.createInfo(entity.ctid, 4);
  4734. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  4735. {
  4736. commonHelper.sendCytExpress(exinfo);
  4737. }
  4738. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4739. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4740. }
  4741. else
  4742. {
  4743. string errmsg = commonHelper.KeepChinese(apires);
  4744. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4745. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4746. }
  4747. return;
  4748. }
  4749. returnErrorMsg("找不到订单记录");
  4750. }
  4751. }
  4752. public void set_erp_multidelivery()
  4753. {
  4754. string eids = GetPostString("tids");
  4755. string[] eidList = eids.Split(',');
  4756. if (eidList.Length <= 0)
  4757. {
  4758. returnErrorMsg("发货不能为空");
  4759. return;
  4760. }
  4761. foreach (string ctid in eidList)
  4762. {
  4763. if (ctid.Length <= 0) continue;
  4764. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4765. if (expInfo != null)
  4766. {
  4767. StringBuilder sql = new StringBuilder();
  4768. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4769. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4770. if (dt.Rows.Count > 0)
  4771. {
  4772. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4773. {
  4774. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4775. expInfo.state = "异常";
  4776. expInfo.isMultiDelivery = 1;
  4777. expInfo.Update();
  4778. continue;
  4779. }
  4780. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4781. {
  4782. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4783. expInfo.state = "异常";
  4784. expInfo.Update();
  4785. continue;
  4786. }
  4787. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4788. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4789. bool isInitOrderDeliv = false;
  4790. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4791. {
  4792. isInitOrderDeliv = true;
  4793. expInfo.isMultiDelivery = 1;
  4794. }
  4795. if (ctid.IndexOf("N") != -1)
  4796. {
  4797. StringBuilder sqlbucha = new StringBuilder();
  4798. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4799. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4800. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4801. commonHelper.UpdateRelationOrder(ctid);
  4802. expInfo.delivery_memo = "发货成功";
  4803. expInfo.state = "发货成功";
  4804. expInfo.isMultiDelivery = 1;
  4805. expInfo.Update();
  4806. }
  4807. else
  4808. {
  4809. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4810. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4811. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4812. {
  4813. expInfo.delivery_memo = "发货成功";
  4814. expInfo.state = "发货成功";
  4815. expInfo.isMultiDelivery = 1;
  4816. expInfo.Update();
  4817. commonHelper.UpdateRelationOrder(ctid);
  4818. CeErpSukuraData.createInfo(ctid, 4);
  4819. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4820. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4821. }
  4822. else
  4823. {
  4824. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4825. expInfo.state = "异常";
  4826. expInfo.Update();
  4827. }
  4828. }
  4829. }
  4830. }
  4831. }
  4832. returnSuccessMsg("操作完成");
  4833. }
  4834. public void reset_erp_memoopt()
  4835. {
  4836. if (UrlPostParmsCheck("ctid"))
  4837. {
  4838. string eid = GetPostString("ctid");
  4839. CeErpTradeCell entity = null;
  4840. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4841. if (entity != null)
  4842. {
  4843. string stropt = "";
  4844. if (entity.MemoOpt == 1)
  4845. {
  4846. stropt = "“改稿”";
  4847. }
  4848. else if (entity.MemoOpt == 2)
  4849. {
  4850. stropt = "“定稿”";
  4851. }
  4852. else if (entity.MemoOpt == 3)
  4853. {
  4854. stropt = "“完成查货”";
  4855. CeErpSukuraData.createInfo(entity.ctid, 6);
  4856. }
  4857. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4858. entity.UpdateTime = DateTime.Now;
  4859. entity.MemoOpt = 0;
  4860. entity.Update();
  4861. returnSuccessMsg("操作成功!");
  4862. return;
  4863. }
  4864. returnErrorMsg("找不到记录");
  4865. }
  4866. }
  4867. public void get_erp_deliveryunusual()
  4868. {
  4869. DataStruct dStruct = GetPostStruct();
  4870. List<string> lw = new List<string>();
  4871. string tid = GetPostString("ctid");
  4872. if (tid.Length > 0)
  4873. {
  4874. string select_tid = getTidByCtid(tid);
  4875. lw.Add(string.Format("tid='{0}'", select_tid));
  4876. }
  4877. string shopname = GetPostString("shopname");
  4878. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4879. string buyernick = GetPostString("buyer_nick");
  4880. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4881. string customer = GetPostString("customer");
  4882. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4883. string design = GetPostString("design");
  4884. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4885. string sellermemo = GetPostString("seller_memo");
  4886. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4887. string supplier = GetPostString("supplier");
  4888. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4889. string date1 = GetPostString("date1");
  4890. string date2 = GetPostString("date2");
  4891. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4892. if (dw.Length > 0) lw.Add(dw);
  4893. string placedate1 = GetPostString("placedate1");
  4894. string placedate2 = GetPostString("placedate2");
  4895. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4896. if (dw_place.Length > 0) lw.Add(dw_place);
  4897. string price1 = GetPostString("price1");
  4898. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4899. string price2 = GetPostString("price2");
  4900. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4901. string unusualCon = GetPostString("unusualcon");
  4902. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4903. string posTag = CurrentUser.UserPost.Post.Code;
  4904. if (posTag == "Supplier")
  4905. {
  4906. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4907. }
  4908. lw.Add(string.Format("OrderState = 6"));
  4909. lw.Add(string.Format("UnusualTag = 5"));
  4910. lw.Add(string.Format("IsRefund<={0}", 1));
  4911. dStruct.Order = "FinishPlaceTime desc";
  4912. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4913. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4914. writeGridDataTableJson(dStruct.TotalCount, dt);
  4915. }
  4916. public void get_erp_deliveryedlist()
  4917. {
  4918. DataStruct dStruct = GetPostStruct();
  4919. List<string> lw = new List<string>();
  4920. string tid = GetPostString("ctid");
  4921. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4922. string shopname = GetPostString("shopname");
  4923. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4924. string buyernick = GetPostString("buyer_nick");
  4925. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4926. string customer = GetPostString("customer");
  4927. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4928. string design = GetPostString("design");
  4929. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4930. string sellermemo = GetPostString("seller_memo");
  4931. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4932. string logistics = GetPostString("logistics");
  4933. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4934. string date1 = GetPostString("date1");
  4935. string date2 = GetPostString("date2");
  4936. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4937. //if (dw.Length > 0) lw.Add(dw);
  4938. string placedate1 = GetPostString("placedate1");
  4939. string placedate2 = GetPostString("placedate2");
  4940. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4941. if (fdw.Length > 0) lw.Add(fdw);
  4942. string devdate1 = GetPostString("deliverydate1");
  4943. string devdate2 = GetPostString("deliverydate2");
  4944. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4945. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4946. string price1 = GetPostString("price1");
  4947. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4948. string price2 = GetPostString("price2");
  4949. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4950. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4951. {
  4952. if (tid.Length > 0)
  4953. {
  4954. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4955. if (tid.Length > 5)
  4956. {
  4957. List<string> tids = getTidByCtidLike(tid);
  4958. if (tids.Count > 0 && tids.Count < 10)
  4959. {
  4960. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4961. }
  4962. }
  4963. lw.Add(tid_sql);
  4964. }
  4965. if (buyernick.Length > 0)
  4966. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4967. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4968. if (dw.Length > 0) lw.Add(dw);
  4969. }
  4970. else
  4971. {
  4972. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  4973. }
  4974. string posTag = CurrentUser.UserPost.Post.Code;
  4975. if (posTag == "Supplier")
  4976. {
  4977. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4978. }
  4979. else
  4980. {
  4981. string supplier = GetPostString("supplier");
  4982. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4983. }
  4984. lw.Add(string.Format(" OrderState IN (7, 8)"));
  4985. lw.Add(string.Format("type != 'PDD' "));
  4986. lw.Add(string.Format("IsRefund!={0}", 2));
  4987. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4988. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4989. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4990. /*if (tid.Length > 0)
  4991. {
  4992. List<string> tids = new List<string>();
  4993. if (dt != null && dt.Rows.Count > 0)
  4994. {
  4995. foreach (DataRow item in dt.Rows)
  4996. {
  4997. tids.Add("'" + item["tid"] + "'");
  4998. }
  4999. }
  5000. if (tids.Count > 0)
  5001. {
  5002. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5003. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5004. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5005. dt = WebCache.GetData("view_erptradecell", dStruct);
  5006. }
  5007. }*/
  5008. if (dt != null)
  5009. {
  5010. foreach (DataRow dr in dt.Rows)
  5011. {
  5012. 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();
  5013. }
  5014. }
  5015. writeGridDataTableJson(dStruct.TotalCount, dt);
  5016. }
  5017. public void get_erp_pdddeliveryed()
  5018. {
  5019. DataStruct dStruct = GetPostStruct();
  5020. List<string> lw = new List<string>();
  5021. string tid = GetPostString("ctid");
  5022. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5023. string shopname = GetPostString("shopname");
  5024. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5025. string buyernick = GetPostString("buyer_nick");
  5026. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5027. string customer = GetPostString("customer");
  5028. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5029. string design = GetPostString("design");
  5030. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5031. string sellermemo = GetPostString("seller_memo");
  5032. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5033. string logistics = GetPostString("logistics");
  5034. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5035. string date1 = GetPostString("date1");
  5036. string date2 = GetPostString("date2");
  5037. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5038. //if (dw.Length > 0) lw.Add(dw);
  5039. string placedate1 = GetPostString("placedate1");
  5040. string placedate2 = GetPostString("placedate2");
  5041. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5042. if (fdw.Length > 0) lw.Add(fdw);
  5043. string devdate1 = GetPostString("deliverydate1");
  5044. string devdate2 = GetPostString("deliverydate2");
  5045. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5046. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5047. string price1 = GetPostString("price1");
  5048. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5049. string price2 = GetPostString("price2");
  5050. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5051. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5052. {
  5053. if (tid.Length > 0)
  5054. {
  5055. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5056. if (tid.Length > 5)
  5057. {
  5058. List<string> tids = getTidByCtidLike(tid);
  5059. if (tids.Count > 0 && tids.Count < 10)
  5060. {
  5061. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5062. }
  5063. }
  5064. lw.Add(tid_sql);
  5065. }
  5066. if (buyernick.Length > 0)
  5067. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5068. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5069. if (dw.Length > 0) lw.Add(dw);
  5070. }
  5071. else
  5072. {
  5073. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5074. }
  5075. string posTag = CurrentUser.UserPost.Post.Code;
  5076. if (posTag == "Supplier")
  5077. {
  5078. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5079. }
  5080. else
  5081. {
  5082. string supplier = GetPostString("supplier");
  5083. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5084. }
  5085. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5086. lw.Add(string.Format("type = 'PDD' "));
  5087. lw.Add(string.Format("IsRefund!={0}", 2));
  5088. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5089. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5090. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5091. /* if (tid.Length > 0)
  5092. {
  5093. List<string> tids = new List<string>();
  5094. if (dt != null && dt.Rows.Count > 0)
  5095. {
  5096. foreach (DataRow item in dt.Rows)
  5097. {
  5098. tids.Add("'" + item["tid"] + "'");
  5099. }
  5100. }
  5101. if (tids.Count > 0)
  5102. {
  5103. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5104. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5105. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5106. dt = WebCache.GetData("view_erptradecell", dStruct);
  5107. }
  5108. }*/
  5109. foreach (DataRow dr in dt.Rows)
  5110. {
  5111. 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();
  5112. }
  5113. writeGridDataTableJson(dStruct.TotalCount, dt);
  5114. }
  5115. public void get_erp_jddeliveryed()
  5116. {
  5117. DataStruct dStruct = GetPostStruct();
  5118. List<string> lw = new List<string>();
  5119. string tid = GetPostString("ctid");
  5120. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5121. string shopname = GetPostString("shopname");
  5122. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5123. string buyernick = GetPostString("buyer_nick");
  5124. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5125. string customer = GetPostString("customer");
  5126. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5127. string design = GetPostString("design");
  5128. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5129. string sellermemo = GetPostString("seller_memo");
  5130. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5131. string date1 = GetPostString("date1");
  5132. string date2 = GetPostString("date2");
  5133. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5134. //if (dw.Length > 0) lw.Add(dw);
  5135. string placedate1 = GetPostString("placedate1");
  5136. string placedate2 = GetPostString("placedate2");
  5137. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5138. if (fdw.Length > 0) lw.Add(fdw);
  5139. string devdate1 = GetPostString("deliverydate1");
  5140. string devdate2 = GetPostString("deliverydate2");
  5141. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5142. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5143. string price1 = GetPostString("price1");
  5144. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5145. string price2 = GetPostString("price2");
  5146. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5147. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5148. {
  5149. if (tid.Length > 0)
  5150. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5151. if (buyernick.Length > 0)
  5152. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5153. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5154. if (dw.Length > 0) lw.Add(dw);
  5155. }
  5156. else
  5157. {
  5158. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5159. }
  5160. string posTag = CurrentUser.UserPost.Post.Code;
  5161. if (posTag == "Supplier")
  5162. {
  5163. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5164. }
  5165. else
  5166. {
  5167. string supplier = GetPostString("supplier");
  5168. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5169. }
  5170. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5171. lw.Add(string.Format("type = 'JD' "));
  5172. lw.Add(string.Format("IsRefund!={0}", 2));
  5173. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5174. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5175. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5176. foreach (DataRow dr in dt.Rows)
  5177. {
  5178. 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();
  5179. }
  5180. writeGridDataTableJson(dStruct.TotalCount, dt);
  5181. }
  5182. public void get_erp_allplacelist()
  5183. {
  5184. DataStruct dStruct = GetPostStruct();
  5185. List<string> lw = new List<string>();
  5186. string tid = GetPostString("ctid");
  5187. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5188. string shopname = GetPostString("shopname");
  5189. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5190. string buyernick = GetPostString("buyer_nick");
  5191. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5192. string customer = GetPostString("customer");
  5193. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5194. string design = GetPostString("design");
  5195. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5196. string sellermemo = GetPostString("seller_memo");
  5197. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5198. string supplier = GetPostString("supplier");
  5199. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5200. string date1 = GetPostString("date1");
  5201. string date2 = GetPostString("date2");
  5202. string pldate1 = GetPostString("placedate1");
  5203. string pldate2 = GetPostString("placedate2");
  5204. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5205. //if (dw.Length > 0) lw.Add(dw);
  5206. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5207. {
  5208. if (tid.Length > 0)
  5209. {
  5210. string select_tid = getTidByCtid(tid);
  5211. lw.Add(string.Format("tid='{0}'", select_tid));
  5212. }
  5213. if (buyernick.Length > 0)
  5214. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5215. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5216. if (dw.Length > 0) lw.Add(dw);
  5217. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5218. if (dw_place.Length > 0) lw.Add(dw_place);
  5219. }
  5220. else
  5221. {
  5222. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5223. {
  5224. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5225. }
  5226. }
  5227. string price1 = GetPostString("price1");
  5228. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5229. string price2 = GetPostString("price2");
  5230. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5231. string posTag = CurrentUser.UserPost.Post.Code;
  5232. if (posTag == "Supplier")
  5233. {
  5234. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5235. }
  5236. lw.Add(string.Format("OrderState >= 6"));
  5237. lw.Add(string.Format("IsSample != 2 "));
  5238. //lw.Add(string.Format("isDianziOrder = 0 "));
  5239. lw.Add(string.Format("SupplierId > 0 "));
  5240. //lw.Add(string.Format("IsRefund<={0}", 1));
  5241. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5242. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5243. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5244. foreach (DataRow dr in dt.Rows)
  5245. {
  5246. 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();
  5247. }
  5248. writeGridDataTableJson(dStruct.TotalCount, dt);
  5249. }
  5250. public void get_erp_financeallplacelist()
  5251. {
  5252. DataStruct dStruct = GetPostStruct();
  5253. List<string> lw = new List<string>();
  5254. string tid = GetPostString("ctid");
  5255. string shopname = GetPostString("shopname");
  5256. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5257. string buyernick = GetPostString("buyer_nick");
  5258. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5259. string customer = GetPostString("customer");
  5260. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5261. string design = GetPostString("design");
  5262. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5263. string sellermemo = GetPostString("seller_memo");
  5264. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5265. string supplier = GetPostString("supplier");
  5266. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5267. string date1 = GetPostString("date1");
  5268. string date2 = GetPostString("date2");
  5269. string pldate1 = GetPostString("placedate1");
  5270. string pldate2 = GetPostString("placedate2");
  5271. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5272. {
  5273. if (tid.Length > 0)
  5274. {
  5275. string select_tid = getTidByCtid(tid);
  5276. lw.Add(string.Format("tid='{0}'", select_tid));
  5277. }
  5278. if (buyernick.Length > 0)
  5279. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5280. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5281. if (dw.Length > 0) lw.Add(dw);
  5282. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5283. if (dw_place.Length > 0) lw.Add(dw_place);
  5284. }
  5285. else
  5286. {
  5287. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5288. {
  5289. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5290. }
  5291. }
  5292. string price1 = GetPostString("price1");
  5293. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5294. string price2 = GetPostString("price2");
  5295. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5296. string posTag = CurrentUser.UserPost.Post.Code;
  5297. if (posTag == "Supplier")
  5298. {
  5299. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5300. }
  5301. //lw.Add(string.Format("OrderState >= 6"));
  5302. lw.Add(string.Format("IsSample != 2 "));
  5303. lw.Add(string.Format("isDianziOrder = 0 "));
  5304. //lw.Add(string.Format("IsRefund<={0}", 1));
  5305. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5306. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5307. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5308. foreach (DataRow dr in dt.Rows)
  5309. {
  5310. 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();
  5311. }
  5312. writeGridDataTableJson(dStruct.TotalCount, dt);
  5313. }
  5314. public void get_erp_expresslist()
  5315. {
  5316. int listtype = GetInt("ltype");
  5317. DataStruct dStruct = GetPostStruct();
  5318. List<string> lw = new List<string>();
  5319. string tid = GetPostString("tid");
  5320. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5321. string outsid = GetPostString("out_sid");
  5322. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5323. string importer = GetPostString("ImportUserName");
  5324. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5325. string file = GetPostString("import_file");
  5326. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5327. string printman = GetPostString("printman");
  5328. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5329. string date1 = GetPostString("date1");
  5330. string date2 = GetPostString("date2");
  5331. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5332. if (dw.Length > 0) lw.Add(dw);
  5333. string fdate1 = GetPostString("finishdate1");
  5334. string fdate2 = GetPostString("finishdate2");
  5335. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5336. if (fdw.Length > 0) lw.Add(fdw);
  5337. string supplierId = GetPostString("supplierId");
  5338. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5339. if (listtype == 1)
  5340. {
  5341. lw.Add(string.Format("importUserId !=0"));
  5342. }
  5343. string posTag = CurrentUser.UserPost.Post.Code;
  5344. if (posTag == "Supplier")
  5345. {
  5346. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5347. }
  5348. if (dStruct.PageSize != 100000)
  5349. {
  5350. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5351. }
  5352. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5353. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5354. writeGridDataTableJson(dStruct.TotalCount, dt);
  5355. }
  5356. public void set_erp_buchaorderdelivery()
  5357. {
  5358. if (UrlPostParmsCheck("ctid"))
  5359. {
  5360. string eid = GetPostString("ctid");
  5361. CeErpTradeCell entity = null;
  5362. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5363. if (entity != null)
  5364. {
  5365. if (entity.IsSample != 2)
  5366. {
  5367. returnErrorMsg("补差价单才能标记为已发货");
  5368. return;
  5369. }
  5370. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5371. entity.OrderState = 7;
  5372. entity.Update();
  5373. returnSuccessMsg("操作成功!");
  5374. return;
  5375. }
  5376. returnErrorMsg("找不到记录");
  5377. }
  5378. }
  5379. public void get_stdtemplates()
  5380. {
  5381. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5382. //string res = taobaoHelper.test();
  5383. string res = apiHelper.API_PrintTemplate();
  5384. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5385. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5386. {
  5387. int sidx = res.IndexOf("error_code");
  5388. int eidx = res.IndexOf("success");
  5389. string msg = res.Substring(sidx, eidx - sidx);
  5390. returnErrorMsg(msg);
  5391. return;
  5392. }
  5393. if (res.Length <= 0)
  5394. {
  5395. returnErrorMsg("模板数据为空!");
  5396. return;
  5397. }
  5398. ReturnSuccess(res);
  5399. }
  5400. public void cancel_print_order()
  5401. {
  5402. if (UrlPostParmsCheck("ctid"))
  5403. {
  5404. string ctid = GetPostString("ctid");
  5405. CeErpTradeCell entity = null;
  5406. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5407. if (entity != null)
  5408. {
  5409. string res = "";
  5410. string code = entity.LastBillWaybillCode;
  5411. if (code == "")
  5412. {
  5413. code = entity.OutSid;
  5414. }
  5415. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5416. XLog.SaveLog(0, "取消面单" + res);
  5417. }
  5418. }
  5419. }
  5420. public void set_erp_printwaybill()
  5421. {
  5422. if (UrlPostParmsCheck("ctid"))
  5423. {
  5424. string ctid = GetPostString("ctid");
  5425. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5426. string cpName = GetPostString("cpname");
  5427. string isTogether = GetPostString("together");
  5428. string printType = GetPostString("printType");
  5429. //var res_obj = new
  5430. //{
  5431. // restype = 1,
  5432. // 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\"}"
  5433. //};
  5434. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5435. //ReturnSuccess(ro_json);
  5436. //return;
  5437. bool isUseLastWayBillCode = false;
  5438. CeErpTradeCell entity = null;
  5439. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5440. if (entity != null)
  5441. {
  5442. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5443. {
  5444. isUseLastWayBillCode = true;
  5445. }
  5446. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5447. {
  5448. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5449. return;
  5450. }
  5451. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5452. {
  5453. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5454. return;
  5455. }
  5456. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5457. {
  5458. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5459. return;
  5460. }
  5461. }
  5462. string res = "";
  5463. Api_waybill_code_response_Obj fullObj = null;
  5464. string pData_str = "";
  5465. string curUseWayBillCode = "";
  5466. if (isUseLastWayBillCode == false)
  5467. {
  5468. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5469. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5470. if (res.IndexOf("failure") != -1)
  5471. {
  5472. //int idx = res.IndexOf("sub_message");
  5473. //int idx2 = res.IndexOf("flag");
  5474. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5475. string errMsgNeed = commonHelper.KeepChinese(res);
  5476. var res_objd = new
  5477. {
  5478. restype = 0,
  5479. data = "获取面单失败" + errMsgNeed
  5480. };
  5481. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5482. returnSuccess(ro_jsond);
  5483. if (res.IndexOf("停发") != -1)
  5484. {
  5485. entity.UnusualCon = "物流停发";
  5486. entity.Update();
  5487. }
  5488. //returnErrorMsg("获取面单失败,"+emsg);
  5489. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5490. return;
  5491. }
  5492. else if (res.IndexOf("errorMsg") != -1)
  5493. {
  5494. //int idx = res.IndexOf("errorMsg");
  5495. //int idx2 = res.IndexOf("}]}");
  5496. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5497. string errMsgNeed = commonHelper.KeepChinese(res);
  5498. var res_objf = new
  5499. {
  5500. restype = 0,
  5501. data = "获取面单失败2" + errMsgNeed
  5502. };
  5503. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5504. if (res.IndexOf("停发") != -1)
  5505. {
  5506. entity.UnusualCon = "物流停发";
  5507. entity.Update();
  5508. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5509. if (trade != null)
  5510. {
  5511. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5512. }
  5513. }
  5514. returnSuccess(ro_jsonf);
  5515. //returnErrorMsg("获取面单失败," + emsg);
  5516. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5517. return;
  5518. }
  5519. try
  5520. {
  5521. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5522. //res = res.Replace(" ", "");
  5523. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5524. }
  5525. catch (Exception ex)
  5526. {
  5527. XLog.SaveLog(0, "生成fullObj" + res);
  5528. var res_objf = new
  5529. {
  5530. restype = 0,
  5531. data = "生成fullObj发生错误" + ex.Message
  5532. };
  5533. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5534. returnSuccess(ro_jsonf);
  5535. return;
  5536. }
  5537. if (fullObj.response.data.content.Count > 0)
  5538. {
  5539. ContentItem codeObj = fullObj.response.data.content[0];
  5540. if (cpCode.IndexOf("SFFQ-") != -1)
  5541. {
  5542. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5543. }
  5544. else
  5545. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5546. curUseWayBillCode = codeObj.waybillCode;
  5547. }
  5548. else
  5549. {
  5550. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5551. var res_objf = new
  5552. {
  5553. restype = 0,
  5554. data = "生成fullObj找不到快递单号waybillCode"
  5555. };
  5556. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5557. returnSuccess(ro_jsonf);
  5558. return;
  5559. }
  5560. }
  5561. else
  5562. {
  5563. //使用上次打印的快递单号
  5564. if (cpCode == "SFFQ-LY")
  5565. {
  5566. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5567. }
  5568. else
  5569. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5570. curUseWayBillCode = entity.LastBillWaybillCode;
  5571. }
  5572. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5573. {
  5574. var res_obje = new
  5575. {
  5576. restype = 0,
  5577. data = "获取加密打印数据失败"
  5578. };
  5579. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5580. returnSuccess(ro_jsone);
  5581. entity.LastBillCpCode = cpCode;
  5582. entity.LastBillWaybillCode = curUseWayBillCode;
  5583. entity.Update();
  5584. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5585. //returnErrorMsg("获取加密打印数据失败");
  5586. return;
  5587. }
  5588. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5589. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5590. string btnType = "";
  5591. string errorMsg = "";
  5592. if (entity != null)
  5593. {
  5594. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5595. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5596. //cpcode是 YTO-CAINIAO
  5597. //string comCode = cpCode.Split('-')[0].ToString();
  5598. string apires = "";
  5599. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5600. //isTogether=2是新的合包弹窗
  5601. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5602. {
  5603. if (ctid.IndexOf("N") != -1)
  5604. {
  5605. apires = "发货成功";
  5606. }
  5607. else
  5608. {
  5609. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5610. }
  5611. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5612. //打单后发货
  5613. StringBuilder sql = new StringBuilder();
  5614. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5615. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5616. {
  5617. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5618. }
  5619. else
  5620. {
  5621. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5622. }
  5623. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5624. foreach (DataRow row in dt.Rows)
  5625. {
  5626. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5627. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5628. {
  5629. try
  5630. {
  5631. btnType = "待发货";
  5632. entity.OutSid = curUseWayBillCode;
  5633. entity.OrderState = 7;
  5634. entity.IsUrgency = false;
  5635. entity.LastBillCpCode = "";
  5636. entity.LastBillWaybillCode = "";
  5637. entity.FinishDeliveryTime = DateTime.Now;
  5638. entity.IsReturn = 0;
  5639. entity.MemoOpt = 0;
  5640. entity.UpdateTime = DateTime.Now;
  5641. entity.Update();
  5642. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5643. //还要插入快递信息到 快递信息表
  5644. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5645. exinfo.tid = entity.ctid;
  5646. exinfo.out_sid = curUseWayBillCode;
  5647. exinfo.company_code = cpCode;
  5648. exinfo.company_name = cpName;
  5649. exinfo.supplierUserName = supplierName;
  5650. exinfo.deliveryType = "发货成功";
  5651. exinfo.print_time = DateTime.Now;
  5652. exinfo.printUser = CurrentUser.UserName;
  5653. exinfo.postData = pData_str;
  5654. exinfo.Create();
  5655. commonHelper.UpdateRelationOrder(entity.ctid);
  5656. CeErpSukuraData.createInfo(ctid, 4);
  5657. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5658. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5659. {
  5660. commonHelper.sendCytExpress(exinfo);
  5661. }
  5662. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5663. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5664. }
  5665. catch (Exception ex)
  5666. {
  5667. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5668. }
  5669. }
  5670. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5671. {
  5672. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5673. if (entity.OrderState == 6)
  5674. {
  5675. entity.OrderState = 7;
  5676. }
  5677. entity.UpdateTime = DateTime.Now;
  5678. entity.FinishDeliveryTime = DateTime.Now;
  5679. btnType = "已发货";
  5680. entity.Update();
  5681. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5682. exinfo.tid = entity.ctid;
  5683. exinfo.out_sid = curUseWayBillCode;
  5684. exinfo.company_code = cpCode;
  5685. exinfo.company_name = cpName;
  5686. exinfo.supplierUserName = supplierName;
  5687. exinfo.deliveryType = "发货成功";
  5688. exinfo.print_time = DateTime.Now;
  5689. exinfo.printUser = CurrentUser.UserName;
  5690. exinfo.postData = pData_str;
  5691. exinfo.Create();
  5692. commonHelper.UpdateRelationOrder(entity.ctid);
  5693. CeErpSukuraData.createInfo(entity.ctid, 4);
  5694. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5695. {
  5696. commonHelper.sendCytExpress(exinfo);
  5697. }
  5698. //不处理
  5699. }
  5700. else
  5701. {
  5702. entity.UpdateTime = DateTime.Now;
  5703. entity.LastBillCpCode = cpCode;
  5704. entity.LastBillWaybillCode = curUseWayBillCode;
  5705. entity.Update();
  5706. string errmsg = commonHelper.KeepChinese(apires);
  5707. var res_objz = new
  5708. {
  5709. restype = 0,
  5710. data = "打单后发货失败"
  5711. };
  5712. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5713. returnSuccess(ro_jsonz);
  5714. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5715. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5716. return;
  5717. }
  5718. }
  5719. }
  5720. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5721. {
  5722. string ctids = GetPostString("ctids");
  5723. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5724. List<string> list = new List<string>();
  5725. List<string> send_list = new List<string>();
  5726. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5727. CeErpTrade ceErpTrade = new CeErpTrade();
  5728. //可合包的合并一起发货
  5729. if (dt == null && string.IsNullOrEmpty(ctids))
  5730. {
  5731. var res_objz = new
  5732. {
  5733. restype = 0,
  5734. data = "打单后发货失败"
  5735. };
  5736. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5737. returnSuccess(ro_jsonz);
  5738. return;
  5739. }
  5740. if (!string.IsNullOrEmpty(ctids))
  5741. {
  5742. StringBuilder sql = new StringBuilder();
  5743. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5744. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5745. }
  5746. foreach (DataRow row in dt.Rows)
  5747. {
  5748. list.Add("'" + row["ctid"] + "'");
  5749. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5750. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5751. if (ctid.IndexOf("N") != -1)
  5752. {
  5753. apires = "发货成功";
  5754. }
  5755. else
  5756. {
  5757. if (!send_list.Contains(ceErpTrade.tid))
  5758. {
  5759. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5760. }
  5761. else
  5762. {
  5763. apires = "发货成功";
  5764. }
  5765. }
  5766. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5767. {
  5768. send_list.Add(ceErpTrade.tid);
  5769. try
  5770. {
  5771. btnType = "待发货";
  5772. ceErpTradeCell.OutSid = curUseWayBillCode;
  5773. ceErpTradeCell.OrderState = 7;
  5774. ceErpTradeCell.IsUrgency = false;
  5775. ceErpTradeCell.LastBillCpCode = "";
  5776. ceErpTradeCell.LastBillWaybillCode = "";
  5777. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5778. ceErpTradeCell.IsReturn = 0;
  5779. ceErpTradeCell.MemoOpt = 0;
  5780. ceErpTradeCell.UpdateTime = DateTime.Now;
  5781. ceErpTradeCell.Update();
  5782. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5783. //还要插入快递信息到 快递信息表
  5784. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5785. exinfo.tid = ceErpTradeCell.ctid;
  5786. exinfo.out_sid = curUseWayBillCode;
  5787. exinfo.company_code = cpCode;
  5788. exinfo.company_name = cpName;
  5789. exinfo.supplierUserName = supplierName;
  5790. exinfo.deliveryType = "发货成功";
  5791. exinfo.print_time = DateTime.Now;
  5792. exinfo.printUser = CurrentUser.UserName;
  5793. exinfo.postData = pData_str;
  5794. exinfo.Create();
  5795. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5796. CeErpSukuraData.createInfo(ctid, 4);
  5797. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5798. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80)
  5799. {
  5800. commonHelper.sendCytExpress(exinfo);
  5801. }
  5802. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5803. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5804. }
  5805. catch (Exception ex)
  5806. {
  5807. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5808. }
  5809. }
  5810. else
  5811. {
  5812. ceErpTradeCell.UpdateTime = DateTime.Now;
  5813. ceErpTradeCell.LastBillCpCode = cpCode;
  5814. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5815. ceErpTradeCell.Update();
  5816. string errmsg = commonHelper.KeepChinese(apires);
  5817. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5818. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5819. }
  5820. }
  5821. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5822. }
  5823. }
  5824. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5825. var res_obj = new
  5826. {
  5827. restype = 1,
  5828. data = pData_str,
  5829. errorMsg
  5830. };
  5831. string ro_json = JsonConvert.SerializeObject(res_obj);
  5832. ReturnSuccess(ro_json);
  5833. return;
  5834. }
  5835. }
  5836. private string GetUTF8String(byte[] vs)
  5837. {
  5838. throw new NotImplementedException();
  5839. }
  5840. public void set_erp_printwaybill_cn()
  5841. {
  5842. if (UrlPostParmsCheck("ctid"))
  5843. {
  5844. string ctid = GetPostString("ctid");
  5845. string cpCode = GetPostString("cpcode");
  5846. string cpName = GetPostString("cpname");
  5847. string tempUrl = GetPostString("tempurl");
  5848. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5849. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5850. //string res = taobaoHelper.test();
  5851. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5852. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5853. {
  5854. int sidx = res.IndexOf("errorMsg");
  5855. int eidx = res.IndexOf("}");
  5856. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5857. var res_objzxx = new
  5858. {
  5859. restype = 0,
  5860. data = msg
  5861. };
  5862. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5863. returnSuccess(ro_jsonzxx);
  5864. //returnErrorMsg(msg);
  5865. return;
  5866. }
  5867. int idx = res.IndexOf("waybillCode");
  5868. int idx2 = res.IndexOf("printData");
  5869. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5870. string eid = GetPostString("ctid");
  5871. CeErpTradeCell entity = null;
  5872. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5873. if (entity != null)
  5874. {
  5875. string osid = entity.OutSid;
  5876. entity.OutSid = osid + "," + outsid;
  5877. entity.FinishDeliveryTime = DateTime.Now;
  5878. entity.OrderState = 7;
  5879. entity.UpdateTime = DateTime.Now;
  5880. entity.IsReturn = 0;
  5881. entity.Update();
  5882. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5883. exinfo.tid = entity.ctid;
  5884. exinfo.out_sid = outsid;
  5885. exinfo.company_code = cpCode;
  5886. exinfo.company_name = cpName;
  5887. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5888. exinfo.deliveryType = "发货成功";
  5889. exinfo.print_time = DateTime.Now;
  5890. exinfo.printUser = CurrentUser.UserName;
  5891. exinfo.Create();
  5892. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5893. {
  5894. commonHelper.sendCytExpress(exinfo);
  5895. }
  5896. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5897. }
  5898. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5899. var res_objz = new
  5900. {
  5901. restype = 1,
  5902. data = res
  5903. };
  5904. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5905. returnSuccess(ro_jsonz);
  5906. //ReturnSuccess(res);
  5907. }
  5908. }
  5909. ////打单,打印面单 获取面单号
  5910. //public void set_erp_printwaybill()
  5911. //{
  5912. // if (UrlPostParmsCheck("ctid"))
  5913. // {
  5914. // string ctid = GetPostString("ctid");
  5915. // string cpCode = GetPostString("cpcode");
  5916. // string tempUrl = GetPostString("tempurl");
  5917. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5918. // //string res = taobaoHelper.test();
  5919. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5920. // if (res.IndexOf("error_response") != -1)
  5921. // {
  5922. // int sidx = res.IndexOf("sub_msg");
  5923. // int eidx = res.IndexOf("request_id");
  5924. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5925. // returnErrorMsg(msg);
  5926. // return;
  5927. // }
  5928. // int idx = res.IndexOf("waybill_code");
  5929. // int idx2 = res.IndexOf("}]}");
  5930. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5931. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5932. // ReturnSuccess(res);
  5933. // }
  5934. //}
  5935. public void cancel_erp_aftersale()
  5936. {
  5937. if (UrlPostParmsCheck("ctid"))
  5938. {
  5939. string eid = GetPostString("ctid");
  5940. CeErpTradeCell entity = null;
  5941. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5942. if (entity != null)
  5943. {
  5944. //有过处理的售后,取消也不能删除 售 字,保留
  5945. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5946. {
  5947. entity.AfterSaleState = 4;
  5948. }
  5949. else
  5950. entity.AfterSaleState = 0;
  5951. entity.UpdateTime = DateTime.Now;
  5952. entity.Update();
  5953. returnSuccessMsg("操作成功!");
  5954. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5955. return;
  5956. }
  5957. returnErrorMsg("找不到订单记录");
  5958. }
  5959. }
  5960. public void get_erp_aftersalelist()
  5961. {
  5962. DataStruct dStruct = GetPostStruct();
  5963. List<string> lw = new List<string>();
  5964. int st = GetInt("st");
  5965. string tid = GetPostString("ctid");
  5966. if (st == 3)
  5967. {
  5968. if (tid.Length > 0)
  5969. {
  5970. string select_tid = getTidByCtid(tid);
  5971. lw.Add(string.Format("tid='{0}'", select_tid));
  5972. }
  5973. }
  5974. else
  5975. {
  5976. if (tid.Length > 0)
  5977. {
  5978. string select_tid = getTidByCtid(tid);
  5979. lw.Add(string.Format("tid='{0}'", select_tid));
  5980. }
  5981. }
  5982. string shopname = GetPostString("shopname");
  5983. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5984. string buyernick = GetPostString("buyer_nick");
  5985. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5986. string sellermemo = GetPostString("seller_memo");
  5987. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5988. string orderState = GetPostString("orderState");
  5989. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5990. string afterState = GetPostString("afterstate");
  5991. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5992. string date1 = GetPostString("date1");
  5993. string date2 = GetPostString("date2");
  5994. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5995. if (dw.Length > 0) lw.Add(dw);
  5996. string price1 = GetPostString("price1");
  5997. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5998. string price2 = GetPostString("price2");
  5999. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6000. //lw.Add(string.Format("IsRefund!={0}", 1));
  6001. string reason = GetPostString("reason");
  6002. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6003. string method = GetPostString("method");
  6004. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6005. string handler = GetPostString("handler");
  6006. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6007. string handledate1 = GetPostString("handledate1");
  6008. string handledate2 = GetPostString("handledate2");
  6009. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6010. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6011. string finish1 = GetPostString("finishdate1");
  6012. string finish2 = GetPostString("finishdate2");
  6013. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6014. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6015. string afterdate1 = GetPostString("afterdate1");
  6016. string afterdate2 = GetPostString("afterdate2");
  6017. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6018. if (afterDate.Length > 0) lw.Add(afterDate);
  6019. string supplier = GetPostString("supplier");
  6020. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6021. string responsible = GetPostString("responsibleman");
  6022. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6023. string customer = GetPostString("customer");
  6024. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6025. string design = GetPostString("design");
  6026. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6027. string afterMemoType = GetPostString("aftermemotype");
  6028. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6029. string posCode = CurrentUser.UserPost.Post.Code;
  6030. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6031. //{
  6032. // string vstate = GetPostString("vstate");
  6033. // if (vstate.Length > 0)
  6034. // {
  6035. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6036. // }
  6037. // if (posCode == "Supplier")
  6038. // {
  6039. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6040. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6041. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6042. // }
  6043. // else
  6044. // {
  6045. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6046. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6047. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6048. // {
  6049. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6050. // }
  6051. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6052. // {
  6053. // int orgid = CurrentUser.UserPost.OrgID;
  6054. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6055. // }
  6056. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6057. // {
  6058. // string shopid = CurrentUser.User.pemShop;
  6059. // lw.Add(string.Format("shopId in ({0})", shopid));
  6060. // }
  6061. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6062. // //{
  6063. // // int org_id = CurrentUser.UserPost.OrgID;
  6064. // // lw.Add(string.Format("OrgID={0}", org_id));
  6065. // //}
  6066. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6067. // }
  6068. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6069. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6070. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6071. //}
  6072. if (st == 5)
  6073. {
  6074. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6075. {
  6076. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6077. {
  6078. string shopid = CurrentUser.User.pemShop;
  6079. lw.Add(string.Format("shopId in ({0})", shopid));
  6080. }
  6081. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6082. {
  6083. int mrOrgid = CurrentUser.UserPost.OrgID;
  6084. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6085. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6086. }
  6087. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6088. //{
  6089. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6090. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6091. //}
  6092. else
  6093. {
  6094. string userIdStr = "";
  6095. if (posCode == "CustomerService")
  6096. {
  6097. userIdStr = CurrentUser.UserID + "_k";
  6098. }
  6099. else if (posCode == "Designer" || posCode == "wxDesigner")
  6100. {
  6101. userIdStr = CurrentUser.UserID + "_s";
  6102. }
  6103. else if (posCode == "Place")
  6104. {
  6105. userIdStr = CurrentUser.UserID + "_x";
  6106. }
  6107. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6108. }
  6109. }
  6110. string placedate1 = GetPostString("placedate1");
  6111. string placedate2 = GetPostString("placedate2");
  6112. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6113. if (dwplace.Length > 0) lw.Add(dwplace);
  6114. string supState = GetPostString("supState");
  6115. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6116. string searchType = GetPostString("searchType");
  6117. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6118. {
  6119. lw.Add(string.Format("BackNum>1"));
  6120. }
  6121. lw.Add(string.Format("AfterSaleState>0"));
  6122. if (ex_psize > 0)
  6123. {
  6124. if (CurrentUser.UserPost.Post.Code == "Finance")
  6125. dStruct.Order = "pay_time desc";
  6126. else
  6127. dStruct.Order = "HandleTime desc";
  6128. }
  6129. else
  6130. dStruct.Order = "HandleTime desc";
  6131. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6132. DataTable dt = WebCache.GetData("view_test", dStruct);
  6133. writeGridDataTableJson(dStruct.TotalCount, dt);
  6134. }
  6135. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6136. //{
  6137. // lw.Add(string.Format("AfterSaleState=4"));
  6138. // string code = CurrentUser.UserPost.Post.Code;
  6139. // if (code == "CustomerService")
  6140. // {
  6141. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6142. // }
  6143. // else if (code == "Designer" || code == "DesignerMr")
  6144. // {
  6145. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6146. // }
  6147. // else if (code == "Place" || code == "PlaceMr")
  6148. // {
  6149. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6150. // }
  6151. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6152. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6153. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6154. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6155. //}
  6156. //else //处理中的售后,待处理和处理中合并
  6157. //{
  6158. // if (afterState.Length <= 0)
  6159. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6160. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6161. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6162. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6163. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6164. //}
  6165. }
  6166. public void get_erp_disagreeftersalelist()
  6167. {
  6168. DataStruct dStruct = GetPostStruct();
  6169. List<string> lw = new List<string>();
  6170. int st = 2;
  6171. string tid = GetPostString("ctid");
  6172. if (tid.Length > 0)
  6173. {
  6174. string select_tid = getTidByCtid(tid);
  6175. lw.Add(string.Format("tid='{0}'", select_tid));
  6176. }
  6177. string shopname = GetPostString("shopname");
  6178. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6179. string buyernick = GetPostString("buyer_nick");
  6180. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6181. string sellermemo = GetPostString("seller_memo");
  6182. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6183. string orderState = GetPostString("orderState");
  6184. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6185. string afterState = GetPostString("afterstate");
  6186. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6187. string date1 = GetPostString("date1");
  6188. string date2 = GetPostString("date2");
  6189. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6190. if (dw.Length > 0) lw.Add(dw);
  6191. string price1 = GetPostString("price1");
  6192. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6193. string price2 = GetPostString("price2");
  6194. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6195. //lw.Add(string.Format("IsRefund!={0}", 1));
  6196. string reason = GetPostString("reason");
  6197. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6198. string method = GetPostString("method");
  6199. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6200. string handler = GetPostString("handler");
  6201. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6202. string handledate1 = GetPostString("handledate1");
  6203. string handledate2 = GetPostString("handledate2");
  6204. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6205. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6206. string afterdate1 = GetPostString("afterdate1");
  6207. string afterdate2 = GetPostString("afterdate2");
  6208. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6209. if (afterDate.Length > 0) lw.Add(afterDate);
  6210. string backdate1 = GetPostString("backdate1");
  6211. string backdate2 = GetPostString("backdate2");
  6212. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6213. if (backDate.Length > 0) lw.Add(backDate);
  6214. string supplier = GetPostString("supplier");
  6215. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6216. string responsible = GetPostString("responsibleman");
  6217. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6218. string customer = GetPostString("customer");
  6219. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6220. string design = GetPostString("design");
  6221. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6222. string afterSaleMemo = GetPostString("afterSaleMemo");
  6223. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6224. string afterMemoType = GetPostString("aftermemotype");
  6225. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6226. string aftersakereason = GetPostString("aftersakereason");
  6227. if (aftersakereason.Length > 0)
  6228. {
  6229. if (aftersakereason == "1")
  6230. {
  6231. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6232. }
  6233. if (aftersakereason == "2")
  6234. {
  6235. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6236. }
  6237. }
  6238. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6239. string poscode = CurrentUser.UserPost.Post.Code;
  6240. if (poscode != "SysAdmin")
  6241. {
  6242. string shopid = CurrentUser.User.pemShop;
  6243. lw.Add(string.Format("shopId in ({0})", shopid));
  6244. }
  6245. string searchType = GetPostString("searchType");
  6246. if (searchType == "wait")
  6247. {
  6248. lw.Add(string.Format("HandleTime is null"));
  6249. }
  6250. if (searchType == "handling")
  6251. {
  6252. lw.Add(string.Format("HandleTime is not null "));
  6253. }
  6254. if (searchType == "back" || searchType == "puBack")
  6255. {
  6256. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6257. }
  6258. if (searchType == "reBack")
  6259. {
  6260. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6261. }
  6262. if (searchType == "moreBack")
  6263. {
  6264. lw.Add(string.Format("backNum > 1"));
  6265. }
  6266. lw.Add(string.Format("(AfterSaleState=5)"));
  6267. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6268. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6269. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6270. writeGridDataTableJson(dStruct.TotalCount, dt);
  6271. }
  6272. public void get_erp_handlingaftersalelist()
  6273. {
  6274. DataStruct dStruct = GetPostStruct();
  6275. List<string> lw = new List<string>();
  6276. int st = 2;
  6277. string tid = GetPostString("ctid");
  6278. if (tid.Length > 0)
  6279. {
  6280. string select_tid = getTidByCtid(tid);
  6281. lw.Add(string.Format("tid='{0}'", select_tid));
  6282. }
  6283. string shopname = GetPostString("shopname");
  6284. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6285. string buyernick = GetPostString("buyer_nick");
  6286. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6287. string sellermemo = GetPostString("seller_memo");
  6288. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6289. string orderState = GetPostString("orderState");
  6290. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6291. string afterState = GetPostString("afterstate");
  6292. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6293. string date1 = GetPostString("date1");
  6294. string date2 = GetPostString("date2");
  6295. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6296. if (dw.Length > 0) lw.Add(dw);
  6297. string price1 = GetPostString("price1");
  6298. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6299. string price2 = GetPostString("price2");
  6300. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6301. //lw.Add(string.Format("IsRefund!={0}", 1));
  6302. string reason = GetPostString("reason");
  6303. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6304. string method = GetPostString("method");
  6305. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6306. string handler = GetPostString("handler");
  6307. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6308. string handledate1 = GetPostString("handledate1");
  6309. string handledate2 = GetPostString("handledate2");
  6310. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6311. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6312. string afterdate1 = GetPostString("afterdate1");
  6313. string afterdate2 = GetPostString("afterdate2");
  6314. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6315. if (afterDate.Length > 0) lw.Add(afterDate);
  6316. string supplier = GetPostString("supplier");
  6317. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6318. string responsible = GetPostString("responsibleman");
  6319. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6320. string customer = GetPostString("customer");
  6321. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6322. string design = GetPostString("design");
  6323. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6324. string afterSaleMemo = GetPostString("afterSaleMemo");
  6325. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6326. string afterMemoType = GetPostString("aftermemotype");
  6327. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6328. string afterresult = GetPostString("afterresult");
  6329. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6330. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6331. string poscode = CurrentUser.UserPost.Post.Code;
  6332. if (poscode != "SysAdmin")
  6333. {
  6334. string shopid = CurrentUser.User.pemShop;
  6335. lw.Add(string.Format("shopId in ({0})", shopid));
  6336. }
  6337. string searchType = GetPostString("searchType");
  6338. if (searchType == "wait")
  6339. {
  6340. lw.Add(string.Format("HandleTime is null"));
  6341. }
  6342. if (searchType == "documentary")
  6343. {
  6344. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6345. }
  6346. if (searchType == "handling")
  6347. {
  6348. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6349. }
  6350. if (searchType == "back" || searchType == "puBack")
  6351. {
  6352. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6353. }
  6354. if (searchType == "reBack")
  6355. {
  6356. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6357. }
  6358. if (afterState.Length <= 0)
  6359. {
  6360. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6361. }
  6362. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6363. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6364. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6365. writeGridDataTableJson(dStruct.TotalCount, dt);
  6366. }
  6367. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6368. //public void get_erp_back_handlingaftersalelist()
  6369. //{
  6370. // DataStruct dStruct = GetPostStruct();
  6371. // List<string> lw = new List<string>();
  6372. // string tid = GetPostString("ctid");
  6373. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6374. // string shopname = GetPostString("shopname");
  6375. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6376. // string buyernick = GetPostString("buyer_nick");
  6377. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6378. // string sellermemo = GetPostString("seller_memo");
  6379. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6380. // string orderState = GetPostString("orderState");
  6381. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6382. // string afterState = GetPostString("afterstate");
  6383. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6384. // string date1 = GetPostString("date1");
  6385. // string date2 = GetPostString("date2");
  6386. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6387. // if (dw.Length > 0) lw.Add(dw);
  6388. // string price1 = GetPostString("price1");
  6389. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6390. // string price2 = GetPostString("price2");
  6391. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6392. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6393. // string reason = GetPostString("reason");
  6394. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6395. // string method = GetPostString("method");
  6396. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6397. // string handler = GetPostString("handler");
  6398. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6399. // string handledate1 = GetPostString("handledate1");
  6400. // string handledate2 = GetPostString("handledate2");
  6401. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6402. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6403. // string afterdate1 = GetPostString("afterdate1");
  6404. // string afterdate2 = GetPostString("afterdate2");
  6405. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6406. // if (afterDate.Length > 0) lw.Add(afterDate);
  6407. // string supplier = GetPostString("supplier");
  6408. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6409. // string responsible = GetPostString("responsibleman");
  6410. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6411. // string customer = GetPostString("customer");
  6412. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6413. // string design = GetPostString("design");
  6414. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6415. // string afterMemoType = GetPostString("aftermemotype");
  6416. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6417. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6418. // if (afterState.Length <= 0)
  6419. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6420. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6421. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6422. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6423. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6424. //}
  6425. public void get_erp_aftersaleverifylist()
  6426. {
  6427. DataStruct dStruct = GetPostStruct();
  6428. List<string> lw = new List<string>();
  6429. string tid = GetPostString("ctid");
  6430. if (tid.Length > 0)
  6431. {
  6432. string select_tid = getTidByCtid(tid);
  6433. lw.Add(string.Format("otid='{0}'", select_tid));
  6434. }
  6435. string shopname = GetPostString("shopname");
  6436. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6437. string buyernick = GetPostString("buyer_nick");
  6438. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6439. string sellermemo = GetPostString("seller_memo");
  6440. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6441. string orderState = GetPostString("orderState");
  6442. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6443. //lw.Add(string.Format("IsRefund!={0}", 1));
  6444. string reason = GetPostString("reason");
  6445. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6446. string method = GetPostString("method");
  6447. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6448. string handler = GetPostString("handler");
  6449. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6450. string handledate1 = GetPostString("handledate1");
  6451. string handledate2 = GetPostString("handledate2");
  6452. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6453. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6454. string finish1 = GetPostString("finishdate1");
  6455. string finish2 = GetPostString("finishdate2");
  6456. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6457. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6458. string supplier = GetPostString("supplier");
  6459. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6460. string responsible = GetPostString("responsibleman");
  6461. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6462. string posCode = CurrentUser.UserPost.Post.Code;
  6463. string vstate = GetPostString("vstate");
  6464. if (vstate.Length > 0)
  6465. {
  6466. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6467. }
  6468. if (posCode == "Supplier")
  6469. {
  6470. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6471. lw.Add(string.Format("VerifyState = 0"));
  6472. lw.Add("type = 1");
  6473. lw.Add(string.Format("AfterSaleState={0}", 3));
  6474. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6475. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6476. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6477. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6478. writeGridDataTableJson(dStruct.TotalCount, dt);
  6479. }
  6480. else if (posCode == "logistics")
  6481. {
  6482. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6483. lw.Add(string.Format("VerifyState = 0"));
  6484. lw.Add("type = 2");
  6485. lw.Add(string.Format("AfterSaleState={0}", 3));
  6486. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6487. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6488. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6489. writeGridDataTableJson(dStruct.TotalCount, dt);
  6490. }
  6491. else
  6492. {
  6493. lw.Add(string.Format("(AfterSaleState = 3)"));
  6494. string reasonState = GetPostString("reasonState");
  6495. lw.Add("type = 0");
  6496. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6497. || posCode == "Summarize" || posCode == "Finance")
  6498. {
  6499. if (reasonState == "2")
  6500. {
  6501. lw.Add("VerifyState = 3");
  6502. }
  6503. else if (reasonState == "1")
  6504. {
  6505. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6506. }
  6507. else
  6508. {
  6509. lw.Add("VerifyState in (0,3)");
  6510. }
  6511. //不加条件,可以看全部
  6512. }
  6513. 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")
  6514. {
  6515. int orgid = CurrentUser.UserPost.OrgID;
  6516. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6517. if (string.IsNullOrEmpty(manageOrgId))
  6518. {
  6519. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6520. }
  6521. else
  6522. {
  6523. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6524. }
  6525. if (reasonState == "1")
  6526. {
  6527. lw.Add("VerifyState = 3");
  6528. }
  6529. else if (reasonState == "2")
  6530. {
  6531. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6532. }
  6533. else
  6534. {
  6535. }
  6536. }
  6537. else
  6538. {
  6539. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6540. }
  6541. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6542. //{
  6543. // int org_id = CurrentUser.UserPost.OrgID;
  6544. // lw.Add(string.Format("OrgID={0}", org_id));
  6545. //}
  6546. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6547. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6548. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6549. writeGridDataTableJson(dStruct.TotalCount, dt);
  6550. }
  6551. }
  6552. public void get_erp_finishaftersalelist()
  6553. {
  6554. DataStruct dStruct = GetPostStruct();
  6555. List<string> lw = new List<string>();
  6556. int st = 4;
  6557. string tid = GetPostString("ctid");
  6558. if (tid.Length > 0)
  6559. {
  6560. string select_tid = getTidByCtid(tid);
  6561. lw.Add(string.Format("otid='{0}'", select_tid));
  6562. }
  6563. string shopname = GetPostString("shopname");
  6564. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6565. //lw.Add(string.Format("IsRefund!={0}", 1));
  6566. string reason = GetPostString("reason");
  6567. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6568. string method = GetPostString("method");
  6569. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6570. string buyernick = GetPostString("buyer_nick");
  6571. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6572. string handler = GetPostString("handler");
  6573. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6574. string handledate1 = GetPostString("handledate1");
  6575. string handledate2 = GetPostString("handledate2");
  6576. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6577. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6578. string finish1 = GetPostString("finishdate1");
  6579. string finish2 = GetPostString("finishdate2");
  6580. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6581. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6582. string supplier = GetPostString("supplier");
  6583. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6584. string responsible = GetPostString("responsibleman");
  6585. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6586. string vstate = GetPostString("vstate");
  6587. if (vstate.Length > 0)
  6588. {
  6589. if ("3".Equals(vstate))
  6590. {
  6591. lw.Add(string.Format("IsTem=1"));
  6592. }
  6593. else
  6594. {
  6595. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6596. }
  6597. }
  6598. lw.Add(string.Format("AfterSaleState=4"));
  6599. string code = CurrentUser.UserPost.Post.Code;
  6600. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6601. {
  6602. //不加条件,可以看全部
  6603. }
  6604. else if (code == "Supplier")
  6605. {
  6606. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6607. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6608. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6609. }
  6610. else if (code == "logistics")
  6611. {
  6612. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6613. lw.Add("type = 2");
  6614. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6615. }
  6616. 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")
  6617. {
  6618. int orgid = CurrentUser.UserPost.OrgID;
  6619. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6620. if (string.IsNullOrEmpty(manageOrgIds))
  6621. {
  6622. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6623. }
  6624. else
  6625. {
  6626. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6627. }
  6628. }
  6629. else
  6630. {
  6631. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6632. }
  6633. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6634. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6635. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6636. writeGridDataTableJson(dStruct.TotalCount, dt);
  6637. }
  6638. public void handle_erp_aftersale()
  6639. {
  6640. if (UrlPostParmsCheck("ctid"))
  6641. {
  6642. string eid = GetPostString("ctid");
  6643. string responStr = GetPostString("AfterSaleResponsible");
  6644. if (responStr.Length <= 0)
  6645. {
  6646. returnErrorMsg("售后责任人不能为空");
  6647. return;
  6648. }
  6649. bool isDesign = false;
  6650. double designFree = 0.00;
  6651. int responsibleId = 0;
  6652. CeErpTradeCell entity = null;
  6653. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6654. if (entity != null)
  6655. {
  6656. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6657. string afterMethod = GetPostString("AfterSaleMethod");
  6658. if (isNeedNewOrder == 1)
  6659. {
  6660. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6661. bool ishav = true;
  6662. if (newentity == null)
  6663. {
  6664. newentity = entity.Clone() as CeErpTradeCell;
  6665. ishav = false;
  6666. newentity.ctid = "S_" + entity.ctid;
  6667. newentity.OrderState = 0;
  6668. //唯一标识
  6669. newentity.OrderSn = newentity.ctid;
  6670. string orderSn = dataHelper.getSaleOrderSn();
  6671. if (orderSn != "")
  6672. {
  6673. newentity.OrderSn = orderSn;
  6674. }
  6675. }
  6676. newentity.UpdateTime = DateTime.Now;
  6677. newentity.AfterSaleState = 0;
  6678. newentity.AfterSaleMethod = afterMethod;
  6679. if (!ishav)
  6680. {
  6681. string memo_str = newentity.seller_memo;
  6682. memo_str = memo_str.Replace("(", "(");
  6683. memo_str = memo_str.Replace(")", ")");
  6684. int sIndex = memo_str.IndexOf("(");
  6685. int eIndex = memo_str.IndexOf(")");
  6686. if (sIndex == -1 || eIndex == -1)
  6687. {
  6688. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6689. return;
  6690. }
  6691. string first = memo_str.Substring(0, sIndex + 1);
  6692. string memoCtid = newentity.OrderSn;
  6693. //if (memoCtid.IndexOf("C") != -1)
  6694. //{
  6695. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6696. //if (CIdx.IndexOf("+") != -1)
  6697. //{
  6698. //CIdx = "C" + CIdx.Split('+')[1];
  6699. //}
  6700. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6701. //}
  6702. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6703. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6704. string newMemo = first + memoCtid + last;
  6705. newentity.seller_memo = newMemo;
  6706. newentity.FinishPlaceTime = null;
  6707. newentity.UnusualTag = 0;
  6708. newentity.UnusualCon = "";
  6709. newentity.UnusualTime = null;
  6710. newentity.AfterSaleMemo = "";
  6711. newentity.AfterSaleMethod = afterMethod;
  6712. newentity.AfterSalePreTime = null;
  6713. newentity.AfterSaleReason = "";
  6714. newentity.AfterSaleResponsible = "";
  6715. newentity.AfterSaleState = 0;
  6716. newentity.AfterSaleTime = null;
  6717. newentity.AfterSaleUserId = 0;
  6718. newentity.AfterSaleSupplierState = 0;
  6719. newentity.LastBillWaybillCode = "";
  6720. newentity.LastBillCpCode = "";
  6721. newentity.FinishAfterSaleTime = null;
  6722. newentity.HandleTime = null;
  6723. newentity.IsSF = 0;
  6724. newentity.IsOldCustomer = 0;
  6725. newentity.UrgencyTime = null;
  6726. newentity.ResponsibleUserId = "";
  6727. newentity.IsVerifyToSupplier = false;
  6728. newentity.payment = 0;
  6729. newentity.CheckMemo = "";
  6730. newentity.OutSid = "";
  6731. newentity.CheckOrderTime = null;
  6732. newentity.MemoOpt = 0;
  6733. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6734. }
  6735. newentity.isAfterSaleOrder = 1;
  6736. newentity.IsRefund = 0;
  6737. string receiveMobile = GetPostString("receiver_mobile");
  6738. if (receiveMobile.Length > 0)
  6739. {
  6740. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6741. if (trade != null)
  6742. {
  6743. trade.receiver_name = GetPostString("receiver_name");
  6744. trade.receiver_mobile = receiveMobile;
  6745. trade.receiver_state = GetPostString("receiver_state");
  6746. trade.receiver_city = GetPostString("receiver_city");
  6747. trade.receiver_district = GetPostString("receiver_district");
  6748. trade.receiver_address = GetPostString("receiver_address");
  6749. newentity.IsOffLineOrder = 1;
  6750. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6751. }
  6752. }
  6753. string st = GetPostString("ToState");
  6754. if (st.Length > 0)
  6755. {
  6756. if (newentity.OrderState <= 3)
  6757. {
  6758. newentity.WaitDesignTime = DateTime.Now;
  6759. newentity.StartDesignTime = null;
  6760. newentity.FinishDesignTime = null;
  6761. newentity.OrderState = 3;
  6762. if (st == "下单员")
  6763. {
  6764. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6765. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6766. {
  6767. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6768. }
  6769. }
  6770. else
  6771. {
  6772. newentity.WaitDesignTime = DateTime.Now;
  6773. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6774. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6775. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6776. {
  6777. DataRow user = dt1.Rows[0];
  6778. //找主管
  6779. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6780. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6781. if (dt != null && dt.Rows.Count > 0)
  6782. {
  6783. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6784. newentity.DesignUserId = designMr;
  6785. string key = "aftersale_order_" + designMr;
  6786. if (RedisHelper.HasKey(key))
  6787. {
  6788. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6789. list.Add(newentity.ctid);
  6790. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6791. }
  6792. }
  6793. //账号正常
  6794. if (user["State"].ToString() == "0")
  6795. {
  6796. newentity.DesignUserId = entity.DesignUserId;
  6797. string key = "aftersale_order_" + entity.DesignUserId;
  6798. if (RedisHelper.HasKey(key))
  6799. {
  6800. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6801. list.Add(newentity.ctid);
  6802. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6803. }
  6804. }
  6805. }
  6806. }
  6807. }
  6808. if (entity.IsXianHuo == 1)
  6809. {
  6810. newentity.OrderState = 6;
  6811. entity.FinishPlaceTime = DateTime.Now;
  6812. }
  6813. }
  6814. if (ishav)
  6815. {
  6816. newentity.Update();
  6817. }
  6818. else
  6819. {
  6820. newentity.Create();
  6821. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6822. newCellExtend.ctid = newentity.ctid;
  6823. newCellExtend.orderFrom = 20;
  6824. newCellExtend.orderType = 30;
  6825. if (st == "下单员")
  6826. {
  6827. }
  6828. else
  6829. {
  6830. newCellExtend.ReprintTime = DateTime.Now;
  6831. }
  6832. newCellExtend.Create();
  6833. }
  6834. if (st != "下单员")
  6835. {
  6836. if (entity.DispatchSort == 2)
  6837. {
  6838. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6839. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6840. }
  6841. }
  6842. }
  6843. //处理售后扩展
  6844. string resIdStr = GetPostString("ResponsibleUserId");
  6845. string refundFees = GetPostString("refundFrees");
  6846. int IsComplain = GetPostInt("isComplain");
  6847. int IsBad = GetPostInt("isBad");
  6848. string IsOriginal = GetPostString("isOriginal");
  6849. double diffResultPrice = GetPostDouble("diffResultPrice");
  6850. string textResult = GetPostString("textResult");
  6851. string supplierResponsible = GetPostString("supplierResponsible");
  6852. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6853. if (ceErpTradeAfterSaleExtend == null)
  6854. {
  6855. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6856. ceErpTradeAfterSaleExtend.tid = eid;
  6857. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6858. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6859. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6860. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6861. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6862. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6863. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6864. ceErpTradeAfterSaleExtend.Create();
  6865. }
  6866. else
  6867. {
  6868. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6869. {
  6870. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6871. }
  6872. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6873. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6874. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6875. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6876. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6877. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6878. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6879. ceErpTradeAfterSaleExtend.Update();
  6880. }
  6881. int gysid = GetPostInt("ResponsibleSupId");
  6882. if (entity.AfterSaleUserId == 0)
  6883. {
  6884. entity.AfterSaleUserId = CurrentUser.UserID;
  6885. }
  6886. entity.ResponsibleUserId = resIdStr;
  6887. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6888. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6889. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6890. {
  6891. CeErpTradeResponsible.DelByTid(eid, -1);
  6892. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6893. int backNum = 0;
  6894. if (number != null)
  6895. {
  6896. backNum = number.BackNum;
  6897. }
  6898. char[] separator = { ',' };
  6899. string[] sArray = resIdStr.Split(separator);
  6900. string[] refundFreeList = { };
  6901. if (refundFees.Length > 0)
  6902. {
  6903. refundFreeList = refundFees.Split(separator);
  6904. }
  6905. int index = -1;
  6906. foreach (string i in sArray)
  6907. {
  6908. index++;
  6909. if (i.Length <= 0) continue;
  6910. char[] separator2 = { '_' };
  6911. string idstr = i.Split(separator2)[0];
  6912. string idtype = i.Split(separator2)[1];
  6913. double refudFree = 0;
  6914. if (refundFreeList.Length > 0)
  6915. {
  6916. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6917. }
  6918. if (idtype == "s")
  6919. {
  6920. isDesign = true;
  6921. designFree = refudFree;
  6922. }
  6923. int userId = Convert.ToInt32(idstr);
  6924. int type = 0;
  6925. if (idtype == "g")
  6926. {
  6927. type = 1;
  6928. }
  6929. if (idtype == "w")
  6930. {
  6931. type = 2;
  6932. }
  6933. if (idtype == "t")
  6934. {
  6935. type = 3;
  6936. }
  6937. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6938. if (ceErpTradeResponsible == null)
  6939. {
  6940. ceErpTradeResponsible = new CeErpTradeResponsible();
  6941. ceErpTradeResponsible.tid = eid;
  6942. ceErpTradeResponsible.UserId = userId;
  6943. ceErpTradeResponsible.createdTime = DateTime.Now;
  6944. ceErpTradeResponsible.type = type;
  6945. if (type == 1)
  6946. {
  6947. ceErpTradeResponsible.IsSup = 1;
  6948. }
  6949. if (type == 2)
  6950. {
  6951. ceErpTradeResponsible.IsFlow = 1;
  6952. }
  6953. }
  6954. ceErpTradeResponsible.RefundFee = refudFree;
  6955. ceErpTradeResponsible.VerifyState = 0;
  6956. if (userId == 2125 || idtype == "w")
  6957. {
  6958. ceErpTradeResponsible.VerifyState = 1;
  6959. }
  6960. if (idtype == "w" && userId == 101)
  6961. {
  6962. ceErpTradeResponsible.VerifyState = 0;
  6963. }
  6964. if (ceErpTradeResponsible.ID > 0)
  6965. {
  6966. ceErpTradeResponsible.Update();
  6967. }
  6968. else
  6969. {
  6970. ceErpTradeResponsible.Create();
  6971. }
  6972. if (isDesign)
  6973. {
  6974. responsibleId = ceErpTradeResponsible.ID;
  6975. }
  6976. }
  6977. CeErpTradeResponsible.NumByTid(backNum, eid);
  6978. }
  6979. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6980. if (ceErpTradeCellExtend != null)
  6981. {
  6982. ceErpTradeCellExtend.returnVisit = 0;
  6983. ceErpTradeCellExtend.Update();
  6984. }
  6985. if (entity.HandleTime != null)
  6986. {
  6987. if (entity.AfterSaleState == 1)
  6988. {
  6989. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6990. }
  6991. else
  6992. {
  6993. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6994. }
  6995. }
  6996. else
  6997. {
  6998. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6999. entity.HandleTime = DateTime.Now;
  7000. }
  7001. bool isCompale = false;
  7002. if (entity.AfterSaleState == 5)
  7003. {
  7004. isCompale = true;
  7005. entity.AfterSaleState = 3;
  7006. }
  7007. entity.AfterSaleSupplierState = 0;
  7008. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7009. {
  7010. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7011. }
  7012. string sImgs = GetPostString("img");
  7013. entity.AfterSaleSupplierImg = sImgs;
  7014. entity.supRefundType = GetPostString("supRefundType");
  7015. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7016. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7017. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7018. entity.AfterSaleMemoType = GetPostString("MemoType");
  7019. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7020. {
  7021. //entity.AfterSaleSupplierState = 2;
  7022. }
  7023. string df = GetPostString("DeductFee");
  7024. if (df == "")
  7025. {
  7026. df = "0";
  7027. }
  7028. string rf = GetPostString("RefundFee");
  7029. if (rf == "")
  7030. {
  7031. rf = "0";
  7032. }
  7033. string pm = GetPostString("AfterSalePayment");
  7034. if (pm == "")
  7035. {
  7036. pm = "0";
  7037. }
  7038. entity.AfterSalePayment = Convert.ToDouble(pm);
  7039. entity.DeductFee = Convert.ToDouble(df);
  7040. entity.RefundFee = Convert.ToDouble(rf);
  7041. entity.UpdateTime = DateTime.Now;
  7042. entity.Update();
  7043. string toState = GetPostString("ToState");
  7044. string original = GetPostString("isOriginal");
  7045. ApiVo apiVo = new ApiVo();
  7046. apiVo.orderNumber = entity.ctid;
  7047. apiVo.actionName = "afterDesign";
  7048. apiVo.orderRemarks = entity.AfterSaleMethod;
  7049. apiVo.reasonRemarks = entity.AfterSaleReason;
  7050. apiVo.isDesign = isDesign;
  7051. apiVo.designFree = designFree;
  7052. apiVo.responsibleId = responsibleId;
  7053. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7054. if (toState == "设计师")
  7055. {
  7056. apiVo.isOriginal = Convert.ToBoolean(original);
  7057. }
  7058. designHelper.API_WorkCore(apiVo);//afterDesign
  7059. CeErpMethod methodSql = new CeErpMethod();
  7060. methodSql.con = entity.AfterSaleMethod;
  7061. methodSql.addTime = DateTime.Now;
  7062. methodSql.Create();
  7063. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7064. CeErpMethod.ExecuteNonQuery(delsql);
  7065. if (isCompale)
  7066. {
  7067. aftersale_data_change(entity.ctid);
  7068. }
  7069. returnSuccessMsg("操作成功!");
  7070. return;
  7071. }
  7072. returnErrorMsg("找不到订单记录");
  7073. }
  7074. }
  7075. public void ins_erp_toresponsible()
  7076. {
  7077. if (UrlPostParmsCheck("ctid"))
  7078. {
  7079. string eid = GetPostString("ctid");
  7080. CeErpTradeCell entity = null;
  7081. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7082. if (entity != null)
  7083. {
  7084. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7085. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7086. {
  7087. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7088. return;
  7089. }
  7090. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7091. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7092. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7093. if (entity.AfterSalePreTime == null)
  7094. {
  7095. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7096. {
  7097. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7098. }
  7099. }
  7100. entity.AfterSalePreTime = DateTime.Now;
  7101. //预完成给售后主管审核客户问题直接完成
  7102. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7103. {
  7104. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7105. {
  7106. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7107. }
  7108. }
  7109. ceErpTradeAfterSaleExtend.Update();
  7110. entity.AfterSaleState = 2;
  7111. entity.UpdateTime = DateTime.Now;
  7112. entity.Update();
  7113. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7114. aftersale_data_change(entity.ctid);
  7115. returnSuccessMsg("操作成功!");
  7116. return;
  7117. }
  7118. returnErrorMsg("找不到订单记录");
  7119. }
  7120. }
  7121. public void cancel_erp_aftersaleanddelnew()
  7122. {
  7123. if (UrlPostParmsCheck("ctid"))
  7124. {
  7125. string eid = GetPostString("ctid");
  7126. CeErpTradeCell entity = null;
  7127. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7128. if (entity != null)
  7129. {
  7130. entity.AfterSaleState = 0;
  7131. entity.AfterSaleReason = "";
  7132. entity.AfterSaleMethod = "";
  7133. entity.AfterSaleMemo = "";
  7134. entity.AfterSaleResponsible = "";
  7135. entity.ResponsibleUserId = "";
  7136. entity.DeductFee = 0;
  7137. entity.RefundFee = 0;
  7138. entity.IsArbitrate = 0;
  7139. CeErpTradeResponsible.DelByTid(eid, -1);
  7140. entity.Update();
  7141. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7142. if (after != null)
  7143. {
  7144. if (after.OrderState < 5)
  7145. CeErpTradeCell.DelByCtid("S_" + eid);
  7146. }
  7147. returnSuccessMsg("操作成功!");
  7148. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7149. return;
  7150. }
  7151. returnErrorMsg("找不到订单记录");
  7152. }
  7153. }
  7154. public void get_erp_aftersale_pregather()
  7155. {
  7156. List<string> lw = new List<string>();
  7157. int st = GetInt("st");
  7158. string tid = GetPostString("ctid");
  7159. if (tid.Length > 0)
  7160. {
  7161. string select_tid = getTidByCtid(tid);
  7162. lw.Add(string.Format("tid='{0}'", select_tid));
  7163. }
  7164. string shopname = GetPostString("shopname");
  7165. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7166. string buyernick = GetPostString("buyer_nick");
  7167. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7168. string sellermemo = GetPostString("seller_memo");
  7169. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7170. string orderState = GetPostString("orderState");
  7171. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7172. string reason = GetPostString("reason");
  7173. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7174. string method = GetPostString("method");
  7175. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7176. string handler = GetPostString("handler");
  7177. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7178. string handledate1 = GetPostString("handledate1");
  7179. string handledate2 = GetPostString("handledate2");
  7180. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7181. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7182. string supplier = GetPostString("supplier");
  7183. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7184. string responsible = GetPostString("responsibleman");
  7185. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7186. string customer = GetPostString("customer");
  7187. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7188. string design = GetPostString("design");
  7189. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7190. string afterMemoType = GetPostString("aftermemotype");
  7191. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7192. string afterSaleMemo = GetPostString("afterSaleMemo");
  7193. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7194. string afterresult = GetPostString("afterresult");
  7195. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7196. string poscode = CurrentUser.UserPost.Post.Code;
  7197. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7198. {
  7199. string shopid = CurrentUser.User.pemShop;
  7200. lw.Add(string.Format("shopId in ({0})", shopid));
  7201. }
  7202. var mainwhere = string.Join(" and ", lw.ToArray());
  7203. string ro_json = "";
  7204. string type = GetPostString("gather_type");
  7205. int number = 0;
  7206. if (poscode == "AfterSale")
  7207. {
  7208. //处理中
  7209. if (type == "Handling")
  7210. {
  7211. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7212. DataTable dt = null;
  7213. try
  7214. {
  7215. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7216. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7217. }
  7218. catch (Exception e)
  7219. {
  7220. dt = new DataTable();
  7221. }
  7222. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7223. return;
  7224. }
  7225. if (type == "Wait")
  7226. {
  7227. //待处理
  7228. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7229. DataTable dt1 = null;
  7230. try
  7231. {
  7232. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7233. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7234. }
  7235. catch (Exception e)
  7236. {
  7237. dt1 = new DataTable();
  7238. }
  7239. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7240. return;
  7241. }
  7242. if (type == "back")
  7243. {
  7244. //打回
  7245. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7246. DataTable dt2 = null;
  7247. try
  7248. {
  7249. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7250. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7251. }
  7252. catch (Exception e)
  7253. {
  7254. dt2 = new DataTable();
  7255. }
  7256. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7257. return;
  7258. }
  7259. if (type == "preCompletion")
  7260. {
  7261. //预完成
  7262. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7263. DataTable dt3 = null;
  7264. try
  7265. {
  7266. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7267. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7268. }
  7269. catch (Exception e)
  7270. {
  7271. dt3 = new DataTable();
  7272. }
  7273. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7274. return;
  7275. }
  7276. if (type == "documentary")
  7277. {
  7278. //跟单中
  7279. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('重印-转设计师','重印-转下单员') " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7280. DataTable dt4 = null;
  7281. try
  7282. {
  7283. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7284. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7285. }
  7286. catch (Exception e)
  7287. {
  7288. dt4 = new DataTable();
  7289. }
  7290. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7291. return;
  7292. }
  7293. if (type == "reBack")
  7294. {
  7295. //被打回
  7296. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7297. DataTable dt1 = null;
  7298. try
  7299. {
  7300. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7301. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7302. }
  7303. catch (Exception e)
  7304. {
  7305. dt1 = new DataTable();
  7306. }
  7307. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7308. return;
  7309. }
  7310. }
  7311. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7312. {
  7313. if (type == "puBack")
  7314. {
  7315. //退回
  7316. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7317. DataTable dt = null;
  7318. try
  7319. {
  7320. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7321. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7322. }
  7323. catch (Exception e)
  7324. {
  7325. dt = new DataTable();
  7326. }
  7327. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7328. return;
  7329. }
  7330. if (type == "reBack")
  7331. {
  7332. //打回
  7333. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7334. DataTable dt1 = null;
  7335. try
  7336. {
  7337. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7338. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7339. }
  7340. catch (Exception e)
  7341. {
  7342. dt1 = new DataTable();
  7343. }
  7344. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7345. return;
  7346. }
  7347. if (type == "examEd")
  7348. {
  7349. //已审核
  7350. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7351. DataTable dt2 = null;
  7352. try
  7353. {
  7354. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7355. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7356. }
  7357. catch (Exception e)
  7358. {
  7359. dt2 = new DataTable();
  7360. }
  7361. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7362. return;
  7363. }
  7364. if (type == "waitExam")
  7365. {
  7366. //待审核
  7367. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7368. DataTable dt3 = null;
  7369. try
  7370. {
  7371. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7372. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7373. }
  7374. catch (Exception e)
  7375. {
  7376. dt3 = new DataTable();
  7377. }
  7378. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7379. return;
  7380. }
  7381. if (type == "Handling")
  7382. {
  7383. //处理中
  7384. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7385. DataTable dt4 = null;
  7386. try
  7387. {
  7388. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7389. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7390. }
  7391. catch (Exception e)
  7392. {
  7393. dt4 = new DataTable();
  7394. }
  7395. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7396. return;
  7397. }
  7398. if (type == "Wait")
  7399. {
  7400. //待处理
  7401. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7402. DataTable dt5 = null;
  7403. try
  7404. {
  7405. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7406. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7407. }
  7408. catch (Exception e)
  7409. {
  7410. dt5 = new DataTable();
  7411. }
  7412. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7413. return;
  7414. }
  7415. if (type == "documentary")
  7416. {
  7417. //跟单中
  7418. string sql6 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7419. DataTable dt6 = null;
  7420. try
  7421. {
  7422. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7423. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7424. }
  7425. catch (Exception e)
  7426. {
  7427. dt6 = new DataTable();
  7428. }
  7429. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7430. return;
  7431. }
  7432. }
  7433. returnSuccess(ro_json);
  7434. }
  7435. public void end_erp_aftersale()
  7436. {
  7437. if (UrlPostParmsCheck("ctid"))
  7438. {
  7439. string eid = GetPostString("ctid");
  7440. CeErpTradeCell entity = null;
  7441. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7442. if (entity != null)
  7443. {
  7444. string stype = GetPostString("stype");
  7445. string typeStr = stype;
  7446. entity.AfterSaleState = 4;
  7447. entity.FinishAfterSaleTime = DateTime.Now;
  7448. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7449. entity.Update();
  7450. ApiVo apiVo = new ApiVo();
  7451. apiVo.orderNumber = entity.ctid;
  7452. apiVo.actionName = "afterOver";
  7453. designHelper.API_WorkCore(apiVo); //afterOver
  7454. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7455. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7456. CeErpSukuraData.createInfo(entity.ctid, 8);
  7457. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7458. returnSuccessMsg("操作成功!");
  7459. return;
  7460. }
  7461. returnErrorMsg("找不到订单记录");
  7462. }
  7463. }
  7464. public void ins_erp_finishaftersale()
  7465. {
  7466. if (UrlPostParmsCheck("id"))
  7467. {
  7468. string eid = GetPostString("id");
  7469. CeErpTradeResponsible entity = null;
  7470. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7471. if (entity != null)
  7472. {
  7473. entity.VerifyState = 1;
  7474. entity.VerifyTime = DateTime.Now;
  7475. entity.Update();
  7476. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7477. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7478. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7479. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7480. if (dt.Rows.Count <= 0)
  7481. {
  7482. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7483. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7484. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7485. CeErpSukuraData.createInfo(entity.tid, 8);
  7486. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7487. {
  7488. CeErpDesignerBill.Del(entity.tid);
  7489. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7490. }
  7491. }
  7492. returnSuccessMsg("操作成功!");
  7493. return;
  7494. }
  7495. returnErrorMsg("找不到订单记录");
  7496. }
  7497. }
  7498. public void upd_erp_arbitrateaftersale()
  7499. {
  7500. if (UrlPostParmsCheck("id"))
  7501. {
  7502. string eid = GetPostString("id");
  7503. CeErpTradeResponsible entity = null;
  7504. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7505. if (entity != null)
  7506. {
  7507. entity.IsArbitrate = 1;
  7508. entity.ArbitradeMemo = GetPostString("reason");
  7509. entity.VerifyState = 2;
  7510. entity.Update();
  7511. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7512. if (tradecell != null)
  7513. {
  7514. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7515. tradecell.IsArbitrate = 1;
  7516. tradecell.Update();
  7517. }
  7518. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7519. returnSuccessMsg("操作成功!");
  7520. return;
  7521. }
  7522. returnErrorMsg("找不到订单记录");
  7523. }
  7524. }
  7525. public void upd_erp_backaftersale()
  7526. {
  7527. if (UrlPostParmsCheck("tid"))
  7528. {
  7529. string eid = GetPostString("tid");
  7530. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7531. int backNum = 0;
  7532. if (number != null)
  7533. {
  7534. backNum = number.BackNum;
  7535. }
  7536. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7537. CeErpTradeCell entity = null;
  7538. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7539. if (entity != null)
  7540. {
  7541. entity.AfterSaleBackReason = GetPostString("backreason");
  7542. entity.AfterSaleState = 1;
  7543. entity.AfterSaleSupplierState = 0;
  7544. entity.UpdateTime = DateTime.Now;
  7545. entity.Update();
  7546. returnSuccessMsg("操作成功!");
  7547. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7548. return;
  7549. }
  7550. returnErrorMsg("找不到订单记录");
  7551. }
  7552. }
  7553. public void get_erp_supplieraftersalelist()
  7554. {
  7555. DataStruct dStruct = GetPostStruct();
  7556. List<string> lw = new List<string>();
  7557. string tid = GetPostString("ctid");
  7558. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7559. string shopname = GetPostString("shopname");
  7560. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7561. string buyernick = GetPostString("buyer_nick");
  7562. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7563. string sellermemo = GetPostString("seller_memo");
  7564. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7565. string orderState = GetPostString("orderState");
  7566. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7567. string afterState = GetPostString("afterstate");
  7568. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7569. string date1 = GetPostString("date1");
  7570. string date2 = GetPostString("date2");
  7571. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7572. if (dw.Length > 0) lw.Add(dw);
  7573. string price1 = GetPostString("price1");
  7574. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7575. string price2 = GetPostString("price2");
  7576. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7577. string reason = GetPostString("reason");
  7578. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7579. string method = GetPostString("method");
  7580. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7581. string handledate1 = GetPostString("handledate1");
  7582. string handledate2 = GetPostString("handledate2");
  7583. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7584. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7585. string handler = GetPostString("handler");
  7586. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7587. string afterdate1 = GetPostString("afterdate1");
  7588. string afterdate2 = GetPostString("afterdate2");
  7589. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7590. if (afterDate.Length > 0) lw.Add(afterDate);
  7591. string customer = GetPostString("customer");
  7592. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7593. string design = GetPostString("design");
  7594. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7595. string afterMemoType = GetPostString("aftermemotype");
  7596. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7597. string vstate = GetPostString("vstate");
  7598. if (vstate.Length > 0)
  7599. {
  7600. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7601. }
  7602. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7603. string supplier = GetPostString("supplier");
  7604. int supid = commonHelper.getSupplierIDByName(supplier);
  7605. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7606. string posCode = CurrentUser.UserPost.Post.Code;
  7607. if (posCode == "Supplier")
  7608. {
  7609. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7610. }
  7611. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7612. {
  7613. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7614. }
  7615. else
  7616. {
  7617. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7618. }
  7619. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7620. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7621. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7622. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7623. writeGridDataTableJson(dStruct.TotalCount, dt);
  7624. }
  7625. public void upd_erp_supverifyaftersale()
  7626. {
  7627. if (UrlPostParmsCheck("id"))
  7628. {
  7629. string id = GetPostString("id");
  7630. int st = GetPostInt("afterstate");
  7631. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7632. CeErpTradeCell entity = null;
  7633. if (ceErpTradeResponsible != null)
  7634. {
  7635. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7636. }
  7637. string afmemo = GetPostString("supmemo");
  7638. string image = GetPostString("image");
  7639. if (entity != null)
  7640. {
  7641. entity.AfterSaleSupplierState = st;
  7642. entity.AfterSaleSupplierMemo = afmemo;
  7643. if (st == 1)
  7644. {
  7645. ceErpTradeResponsible.VerifyState = 1;
  7646. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7647. ceErpTradeResponsible.Update();
  7648. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7649. if (isAll)
  7650. {
  7651. entity.AfterSaleState = 4;
  7652. entity.FinishAfterSaleTime = DateTime.Now;
  7653. }
  7654. }
  7655. else
  7656. {
  7657. CeErpTradeResponsible.dateByTid(entity.ctid);
  7658. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7659. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7660. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7661. if (num <= 1)
  7662. {
  7663. entity.AfterSaleState = 1;
  7664. }
  7665. else
  7666. {
  7667. entity.AfterSaleState = 5;
  7668. }
  7669. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7670. if (ceErpTradeAfterSaleExtend != null)
  7671. {
  7672. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7673. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7674. ceErpTradeAfterSaleExtend.Update();
  7675. }
  7676. else
  7677. {
  7678. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7679. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7680. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7681. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7682. ceErpTradeAfterSaleExtend.Create();
  7683. }
  7684. }
  7685. if (entity.AfterSaleState == 4)
  7686. {
  7687. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7688. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7689. {
  7690. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7691. }
  7692. ApiVo apiVo = new ApiVo();
  7693. apiVo.orderNumber = entity.ctid;
  7694. apiVo.actionName = "afterOver";
  7695. designHelper.API_WorkCore(apiVo); //afterOver
  7696. }
  7697. entity.UpdateTime = DateTime.Now;
  7698. entity.Update();
  7699. returnSuccessMsg("操作成功!");
  7700. CeErpSukuraData.createInfo(entity.ctid, 8);
  7701. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7702. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7703. return;
  7704. }
  7705. returnErrorMsg("找不到订单记录");
  7706. }
  7707. }
  7708. public void upd_erp_masteraftersale()
  7709. {
  7710. if (UrlPostParmsCheck("id"))
  7711. {
  7712. string id = GetPostString("id");
  7713. int st = GetPostInt("afterstate");
  7714. string afmemo = GetPostString("supmemo");
  7715. string image = GetPostString("image");
  7716. string textResult = GetPostString("textResult");
  7717. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7718. if (ceErpTradeResponsible != null)
  7719. {
  7720. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7721. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7722. ceErpTradeResponsible.Update();
  7723. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7724. if (entity != null)
  7725. {
  7726. entity.AfterSaleSupplierState = st;
  7727. entity.AfterSaleSupplierMemo = afmemo;
  7728. if (st == 1)
  7729. {
  7730. }
  7731. else
  7732. {
  7733. CeErpTradeResponsible.dateByTid(entity.ctid);
  7734. //退回到售后
  7735. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7736. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7737. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7738. if (num <= 1)
  7739. {
  7740. entity.AfterSaleState = 1;
  7741. }
  7742. else
  7743. {
  7744. entity.AfterSaleState = 5;
  7745. }
  7746. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7747. if (ceErpTradeAfterSaleExtend != null)
  7748. {
  7749. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7750. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7751. ceErpTradeAfterSaleExtend.Update();
  7752. }
  7753. else
  7754. {
  7755. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7756. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7757. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7758. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7759. ceErpTradeAfterSaleExtend.Create();
  7760. }
  7761. }
  7762. entity.UpdateTime = DateTime.Now;
  7763. entity.Update();
  7764. returnSuccessMsg("操作成功!");
  7765. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7766. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7767. return;
  7768. }
  7769. }
  7770. returnErrorMsg("找不到订单记录");
  7771. }
  7772. }
  7773. public void upd_erp_personaftersale()
  7774. {
  7775. if (UrlPostParmsCheck("id"))
  7776. {
  7777. //林小连
  7778. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7779. {
  7780. upd_erp_masteraftersale();
  7781. return;
  7782. }
  7783. string id = GetPostString("id");
  7784. int st = GetPostInt("afterstate");
  7785. string afmemo = GetPostString("supmemo");
  7786. string image = GetPostString("image");
  7787. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7788. if (ceErpTradeResponsible != null)
  7789. {
  7790. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7791. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7792. ceErpTradeResponsible.Update();
  7793. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7794. if (entity != null)
  7795. {
  7796. entity.AfterSaleSupplierMemo = afmemo;
  7797. entity.AfterSaleSupplierState = st;
  7798. if (st == 1)
  7799. {
  7800. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7801. if (isAll)
  7802. {
  7803. entity.AfterSaleState = 4;
  7804. entity.FinishAfterSaleTime = DateTime.Now;
  7805. }
  7806. }
  7807. else
  7808. {
  7809. CeErpTradeResponsible.dateByTid(entity.ctid);
  7810. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7811. if (ceErpTradeAfterSaleExtend != null)
  7812. {
  7813. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7814. ceErpTradeAfterSaleExtend.Update();
  7815. }
  7816. else
  7817. {
  7818. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7819. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7820. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7821. ceErpTradeAfterSaleExtend.Create();
  7822. }
  7823. //退回到主管
  7824. //entity.AfterSaleState = 2;
  7825. }
  7826. if (entity.AfterSaleState == 4)
  7827. {
  7828. ApiVo apiVo = new ApiVo();
  7829. apiVo.orderNumber = entity.ctid;
  7830. apiVo.actionName = "afterOver";
  7831. designHelper.API_WorkCore(apiVo); //afterOver
  7832. }
  7833. entity.UpdateTime = DateTime.Now;
  7834. entity.Update();
  7835. returnSuccessMsg("操作成功!");
  7836. CeErpSukuraData.createInfo(entity.ctid, 8);
  7837. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7838. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7839. return;
  7840. }
  7841. }
  7842. returnErrorMsg("找不到订单记录");
  7843. }
  7844. }
  7845. public void set_erp_supplierrefundtag()
  7846. {
  7847. if (UrlPostParmsCheck("ctid"))
  7848. {
  7849. string eid = GetPostString("ctid");
  7850. CeErpTradeCell entity = null;
  7851. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7852. if (entity != null)
  7853. {
  7854. entity.IsSupplierRefund = GetPostInt("tag");
  7855. entity.Update();
  7856. returnSuccessMsg("操作成功!");
  7857. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7858. return;
  7859. }
  7860. returnErrorMsg("找不到订单记录");
  7861. }
  7862. }
  7863. public void get_erp_refundlist()
  7864. {
  7865. DataStruct dStruct = GetPostStruct();
  7866. List<string> lw = new List<string>();
  7867. string tid = GetPostString("tid");
  7868. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7869. //string rid = GetPostString("refund_id");
  7870. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7871. string shopname = GetPostString("shopname");
  7872. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7873. string buyernick = GetPostString("buyer_nick");
  7874. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7875. string customer = GetPostString("customer");
  7876. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7877. string design = GetPostString("design");
  7878. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7879. string sellermemo = GetPostString("seller_memo");
  7880. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7881. //string date1 = GetPostString("date1");
  7882. //string date2 = GetPostString("date2");
  7883. //string dateType = GetPostString("dateType");
  7884. //if (dateType.Length > 0)
  7885. //{
  7886. // if (dateType == "1001") dateType = "0";
  7887. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7888. // if (searchDT.Count == 2)
  7889. // {
  7890. // date1 = searchDT[0].ToString();
  7891. // date2 = searchDT[1].ToString();
  7892. // }
  7893. //}
  7894. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7895. //if (dw.Length > 0) lw.Add(dw);
  7896. string redate1 = GetPostString("refunddate1");
  7897. string redate2 = GetPostString("refunddate2");
  7898. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7899. if (dwdate.Length > 0) lw.Add(dwdate);
  7900. string price1 = GetPostString("price1");
  7901. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7902. string price2 = GetPostString("price2");
  7903. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7904. string ispartrefund = GetPostString("ispartrefund");
  7905. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7906. string refundState = GetPostString("refundvstate");
  7907. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7908. int st = GetInt("st");
  7909. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7910. {
  7911. string responsible = GetPostString("responsibleman");
  7912. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7913. lw.Add(string.Format("RefundState>={0}", st));
  7914. string code = CurrentUser.UserPost.Post.Code;
  7915. if (code == "CustomerService")
  7916. {
  7917. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7918. }
  7919. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7920. {
  7921. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7922. }
  7923. else if (code == "Place" || code == "PlaceMr")
  7924. {
  7925. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7926. }
  7927. dStruct.Order = "RefundState asc,created desc";
  7928. }
  7929. else if (st == 10)
  7930. {
  7931. string responsible = GetPostString("responsibleman");
  7932. if (responsible == "空白")
  7933. {
  7934. lw.Add(string.Format("ResponsibleUserName = ''"));
  7935. }
  7936. else if (responsible.Length > 0)
  7937. {
  7938. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7939. }
  7940. lw.Add(string.Format("RefundState>=0"));
  7941. dStruct.Order = "created desc";
  7942. }
  7943. else
  7944. {
  7945. string responsible = GetPostString("responsibleman");
  7946. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7947. lw.Add(string.Format("RefundState={0}", st));
  7948. dStruct.Order = "created desc";
  7949. }
  7950. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7951. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7952. dt.Columns.Add("refund_fees");
  7953. foreach (DataRow dr in dt.Rows)
  7954. {
  7955. String status = dr["status"].ToString();
  7956. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7957. {
  7958. dr["refund_fees"] = dr["refund_fee"];
  7959. }
  7960. else
  7961. {
  7962. dr["refund_fees"] = "0.0";
  7963. }
  7964. }
  7965. writeGridDataTableJson(dStruct.TotalCount, dt);
  7966. }
  7967. public void get_erp_refunddesignlist()
  7968. {
  7969. DataStruct dStruct = GetPostStruct();
  7970. List<string> lw = new List<string>();
  7971. string tid = GetPostString("tid");
  7972. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7973. string shopname = GetPostString("shopname");
  7974. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7975. string buyernick = GetPostString("buyer_nick");
  7976. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7977. string customer = GetPostString("customer");
  7978. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7979. string design = GetPostString("design");
  7980. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7981. string sellermemo = GetPostString("seller_memo");
  7982. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7983. string redate1 = GetPostString("refunddate1");
  7984. string redate2 = GetPostString("refunddate2");
  7985. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7986. if (dwdate.Length > 0) lw.Add(dwdate);
  7987. string price1 = GetPostString("price1");
  7988. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7989. string price2 = GetPostString("price2");
  7990. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7991. string ispartrefund = GetPostString("ispartrefund");
  7992. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7993. string designerorg = GetPostString("designerorg");
  7994. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7995. string refundState = GetPostString("refundState");
  7996. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7997. int myOrgid = CurrentUser.UserPost.OrgID;
  7998. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7999. if ("Designer".Equals(myOrgCode))//设计师能看到的
  8000. {
  8001. if (CurrentUser.User.TeamIds.Length > 0)
  8002. {
  8003. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  8004. }
  8005. else
  8006. {
  8007. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8008. }
  8009. }
  8010. else if ("SysAdmin".Equals(myOrgCode))
  8011. {
  8012. }
  8013. else
  8014. {
  8015. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8016. {
  8017. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8018. }
  8019. else
  8020. {
  8021. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8022. }
  8023. }
  8024. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8025. dStruct.Order = "created desc";
  8026. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8027. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8028. dt.Columns.Add("refund_fees");
  8029. foreach (DataRow dr in dt.Rows)
  8030. {
  8031. String status = dr["status"].ToString();
  8032. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8033. {
  8034. dr["refund_fees"] = dr["refund_fee"];
  8035. }
  8036. else
  8037. {
  8038. dr["refund_fees"] = "0.0";
  8039. }
  8040. }
  8041. writeGridDataTableJson(dStruct.TotalCount, dt);
  8042. }
  8043. public void handle_erp_refundtag()
  8044. {
  8045. if (UrlPostParmsCheck("refund_id"))
  8046. {
  8047. string eid = GetPostString("refund_id");
  8048. string respMan = GetPostString("ResponsibleName");
  8049. if (respMan.Length <= 0)
  8050. {
  8051. returnErrorMsg("责任人不能为空");
  8052. return;
  8053. }
  8054. CeErpTradeRefund entity = null;
  8055. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8056. if (entity != null)
  8057. {
  8058. entity.ResponsibleUserName = respMan;
  8059. string userid = GetPostString("ResponsibleUserId");
  8060. if (userid.Length > 0)
  8061. {
  8062. entity.ResponsibleUserId = userid;
  8063. }
  8064. entity.Memo = GetPostString("Memo");
  8065. if (respMan.IndexOf("客服") != -1 ||
  8066. respMan.IndexOf("设计师") != -1 ||
  8067. respMan.IndexOf("下单员") != -1)
  8068. {
  8069. entity.RefundState = 2;
  8070. }
  8071. else
  8072. {
  8073. entity.RefundState = 3;
  8074. }
  8075. entity.modified = DateTime.Now;
  8076. entity.Update();
  8077. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8078. returnSuccessMsg("操作成功!");
  8079. return;
  8080. }
  8081. returnErrorMsg("找不到订单记录");
  8082. }
  8083. }
  8084. public void handle_erp_designrefundtag()
  8085. {
  8086. if (UrlPostParmsCheck("refund_id"))
  8087. {
  8088. string eid = GetPostString("refund_id");
  8089. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8090. if (ceErpTradeCellExtend == null)
  8091. {
  8092. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8093. ceErpTradeCellExtend.ctid = eid;
  8094. }
  8095. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8096. if (ceErpTradeCellExtend.ID > 0)
  8097. {
  8098. ceErpTradeCellExtend.Update();
  8099. }
  8100. else
  8101. {
  8102. ceErpTradeCellExtend.Create();
  8103. }
  8104. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8105. returnSuccessMsg("操作成功!");
  8106. return;
  8107. }
  8108. returnErrorMsg("找不到订单记录");
  8109. }
  8110. public void upd_erp_refundverify()
  8111. {
  8112. if (UrlPostParmsCheck("refund_id"))
  8113. {
  8114. string eid = GetPostString("refund_id");
  8115. CeErpTradeRefund entity = null;
  8116. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8117. if (entity != null)
  8118. {
  8119. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8120. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8121. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8122. {
  8123. entity.RefundState = 2;
  8124. }
  8125. else
  8126. {
  8127. entity.RefundState = 3;
  8128. }
  8129. entity.Update();
  8130. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8131. returnSuccessMsg("操作成功!");
  8132. return;
  8133. }
  8134. returnErrorMsg("找不到订单记录");
  8135. }
  8136. }
  8137. public void upd_erp_refundapprove()
  8138. {
  8139. if (UrlPostParmsCheck("refund_id"))
  8140. {
  8141. string eid = GetPostString("refund_id");
  8142. CeErpTradeRefund entity = null;
  8143. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8144. if (entity != null)
  8145. {
  8146. int apr = GetPostInt("approve");
  8147. if (apr == 0)
  8148. {
  8149. entity.RefundState = 1;
  8150. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8151. }
  8152. else if (apr == 1)
  8153. {
  8154. entity.RefundState = 3;
  8155. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8156. }
  8157. entity.modified = DateTime.Now;
  8158. entity.Update();
  8159. returnSuccessMsg("操作成功!");
  8160. return;
  8161. }
  8162. returnErrorMsg("找不到订单记录");
  8163. }
  8164. }
  8165. public void get_erp_billlist()
  8166. {
  8167. DataStruct dStruct = GetPostStruct();
  8168. List<string> lw = new List<string>();
  8169. string title = GetPostString("title");
  8170. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8171. string tid = GetPostString("tid");
  8172. string tids = GetPostString("tids");
  8173. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8174. if (tids.Length > 0)
  8175. {
  8176. tids = "'" + tids + "'";
  8177. tids = tids.Replace(",", "','");
  8178. lw.Add(string.Format("tid in ({0})", tids));
  8179. }
  8180. string shopname = GetPostString("shopname");
  8181. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8182. string buyernick = GetPostString("buyer_nick");
  8183. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8184. string customer = GetPostString("customer");
  8185. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8186. string date1 = GetPostString("date1");
  8187. string date2 = GetPostString("date2");
  8188. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8189. if (dw.Length > 0) lw.Add(dw);
  8190. string price1 = GetPostString("price1");
  8191. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8192. string price2 = GetPostString("price2");
  8193. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8194. string returndate1 = GetPostString("returndate1");
  8195. string returndate2 = GetPostString("returndate2");
  8196. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8197. if (dw1.Length > 0) lw.Add(dw1);
  8198. string billtype = GetPostString("billtype");
  8199. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8200. string billstate = GetPostString("billstate");
  8201. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8202. string usershop = CurrentUser.User.pemShop;
  8203. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8204. dStruct.Order = "createTime desc";
  8205. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8206. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8207. //foreach (DataRow dr in dt.Rows)
  8208. //{
  8209. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8210. //}
  8211. writeGridDataTableJson(dStruct.TotalCount, dt);
  8212. }
  8213. public void modify_erp_billinfo()
  8214. {
  8215. if (UrlPostParmsCheck("ID"))
  8216. {
  8217. string eid = GetPostString("ID");
  8218. CeErpBill bill_entity = null;
  8219. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8220. if (bill_entity != null)
  8221. {
  8222. bill_entity.tid = GetPostString("tid");
  8223. bill_entity.title = GetPostString("title");
  8224. bill_entity.tax = GetPostString("tax");
  8225. bill_entity.bank = GetPostString("bank");
  8226. bill_entity.bankac = GetPostString("bankac");
  8227. bill_entity.address = GetPostString("address");
  8228. bill_entity.phone = GetPostString("phone");
  8229. bill_entity.price = GetPostString("price");
  8230. bill_entity.productId = GetPostInt("ProductName");
  8231. bill_entity.num = GetPostInt("num");
  8232. bill_entity.unit = GetPostString("unit");
  8233. bill_entity.type = GetPostString("type");
  8234. bill_entity.sendType = GetPostString("SendType");
  8235. bill_entity.email = GetPostString("email");
  8236. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8237. bill_entity.shopName = GetPostString("ShopName");
  8238. bill_entity.applymemo = GetPostString("applymemo");
  8239. bill_entity.modifyTime = DateTime.Now;
  8240. bill_entity.createTime = DateTime.Now;
  8241. bill_entity.state = 0;
  8242. bill_entity.Update();
  8243. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8244. returnSuccessMsg("发票修改成功!");
  8245. return;
  8246. }
  8247. returnErrorMsg("找不到对应记录");
  8248. }
  8249. }
  8250. public void set_erp_invoicing()
  8251. {
  8252. if (UrlPostParmsCheck("id"))
  8253. {
  8254. try
  8255. {
  8256. string eid = GetPostString("id");
  8257. CeErpBill bill_entity = null;
  8258. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8259. if (bill_entity != null)
  8260. {
  8261. int ComId = GetPostInt("ComId");
  8262. //string memo = GetPostString("Memo");
  8263. int allInfo = GetPostInt("allinfo");
  8264. string clert = CurrentUser.User.Name;
  8265. //string detailValue = GetPostString("detailvalue");
  8266. string billId = bill_entity.billOrderId;
  8267. string[] billIdList = billId.Split(',');
  8268. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8269. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8270. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8271. {
  8272. billCount += 1;
  8273. }
  8274. if (billId.Length <= 0 || billIdList.Length != billCount)
  8275. {
  8276. bill_entity.billOrderId = "";
  8277. string prebill = "ltb";
  8278. for (int idx = 1; idx <= billCount; idx++)
  8279. {
  8280. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8281. string billoid = prebill + idx + dtstr;
  8282. bill_entity.billOrderId += billoid;
  8283. if (idx < billCount)
  8284. {
  8285. bill_entity.billOrderId += ",";
  8286. }
  8287. }
  8288. }
  8289. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8290. if (bill_entity.state == 5)
  8291. {
  8292. string errMsg = bill_entity.failerror;
  8293. string[] errlist = errMsg.Split('|');
  8294. string[] errTags = new string[errlist.Length];
  8295. for (int itag = 0; itag < errlist.Length; itag++)
  8296. {
  8297. if (errlist[itag].Length <= 0) continue;
  8298. errTags[itag] = errlist[itag].Split('&')[0];
  8299. }
  8300. for (int iii = 0; iii < errTags.Length; iii++)
  8301. {
  8302. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8303. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8304. if (billOrderList.Length >= erroBillOrderTag)
  8305. {
  8306. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8307. if (needModifyBillId.Length <= 19)
  8308. {
  8309. needModifyBillId = needModifyBillId + "1";
  8310. }
  8311. else
  8312. {
  8313. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8314. last = last + 1;
  8315. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8316. }
  8317. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8318. }
  8319. }
  8320. }
  8321. bool isHaveBillSucces = false;
  8322. string totalRes = "";
  8323. bill_entity.failerror = "";
  8324. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8325. {
  8326. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8327. totalRes += res;
  8328. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8329. {
  8330. isHaveBillSucces = true;
  8331. bill_entity.comId = ComId;
  8332. bill_entity.state = 1;
  8333. bill_entity.executeTime = DateTime.Now;
  8334. bill_entity.executeUser = clert;
  8335. }
  8336. else
  8337. {
  8338. bill_entity.state = 5;
  8339. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8340. }
  8341. }
  8342. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8343. bill_entity.Update();
  8344. if (isHaveBillSucces)
  8345. {
  8346. StringBuilder sql = new StringBuilder();
  8347. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8348. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8349. }
  8350. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8351. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8352. {
  8353. returnErrorMsg("开票失败");
  8354. }
  8355. else
  8356. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8357. return;
  8358. }
  8359. returnErrorMsg("找不到对应记录");
  8360. }
  8361. catch (Exception ex)
  8362. {
  8363. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8364. returnErrorMsg("操作失败");
  8365. }
  8366. }
  8367. }
  8368. public void get_erp_invoicing_back()
  8369. {
  8370. if (UrlPostParmsCheck("id"))
  8371. {
  8372. try
  8373. {
  8374. string id = GetPostString("id");
  8375. CeErpBill entiy = CeErpBill.Get(id);
  8376. if (entiy != null)
  8377. {
  8378. if (entiy.state == 0)
  8379. {
  8380. returnErrorMsg("发票还未开具");
  8381. return;
  8382. }
  8383. string[] billOrderList = entiy.billOrderId.Split(',');
  8384. int iTag = 0;
  8385. entiy.fplsh = "";
  8386. entiy.fpdm = "";
  8387. entiy.fphm = "";
  8388. foreach (string billOrderId in billOrderList)
  8389. {
  8390. iTag++;
  8391. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8392. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8393. {
  8394. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8395. try
  8396. {
  8397. Invoicing_get_response_Obj iObj = null;
  8398. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8399. if (iObj != null)
  8400. {
  8401. entiy.state = 2;
  8402. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8403. entiy.fpdm += iObj.list[0].c_fpdm;
  8404. entiy.fphm += iObj.list[0].c_fphm;
  8405. if (iTag < billOrderList.Length)
  8406. {
  8407. entiy.fplsh += ",";
  8408. entiy.fpdm += ",";
  8409. entiy.fphm += ",";
  8410. }
  8411. entiy.Update();
  8412. }
  8413. StringBuilder sql = new StringBuilder();
  8414. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8415. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8416. returnSuccessMsg("开票成功");
  8417. }
  8418. catch (Exception ex)
  8419. {
  8420. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8421. }
  8422. return;
  8423. }
  8424. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8425. {
  8426. var res_obj = new
  8427. {
  8428. data = "开票中"
  8429. };
  8430. string ro_json = JsonConvert.SerializeObject(res_obj);
  8431. returnSuccess(ro_json);
  8432. return;
  8433. }
  8434. else
  8435. {
  8436. int eidx = res.IndexOf("c_resultmsg");
  8437. int lidx = res.IndexOf("c_status");
  8438. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8439. entiy.state = 5;
  8440. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8441. entiy.Update();
  8442. returnErrorMsg("开票失败");
  8443. return;
  8444. }
  8445. }
  8446. }
  8447. }
  8448. catch (Exception ex)
  8449. {
  8450. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8451. }
  8452. return;
  8453. }
  8454. }
  8455. public void get_erp_invoicing()
  8456. {
  8457. if (UrlPostParmsCheck("id"))
  8458. {
  8459. try
  8460. {
  8461. string id = GetPostString("id");
  8462. CeErpBill entiy = CeErpBill.Get(id);
  8463. if (entiy != null)
  8464. {
  8465. if (entiy.state == 0)
  8466. {
  8467. returnErrorMsg("发票还未开具");
  8468. return;
  8469. }
  8470. if (entiy.sendType == "纸质发票")
  8471. {
  8472. if (entiy.img.Length <= 0)
  8473. {
  8474. returnErrorMsg("查无纸质发票");
  8475. return;
  8476. }
  8477. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8478. returnSuccess(returnres);
  8479. return;
  8480. }
  8481. string[] billOrderList = entiy.billOrderId.Split(',');
  8482. int iTag = 0;
  8483. string fpUrl = "";
  8484. entiy.fplsh = "";
  8485. entiy.fpdm = "";
  8486. entiy.fphm = "";
  8487. foreach (string billOrderId in billOrderList)
  8488. {
  8489. iTag++;
  8490. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8491. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8492. {
  8493. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8494. Invoicing_get_response_Obj iObj = null;
  8495. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8496. if (iObj != null)
  8497. {
  8498. //entiy.state = 2;
  8499. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8500. entiy.fpdm += iObj.list[0].c_fpdm;
  8501. entiy.fphm += iObj.list[0].c_fphm;
  8502. if (iTag < billOrderList.Length)
  8503. {
  8504. entiy.fplsh += ",";
  8505. entiy.fpdm += ",";
  8506. entiy.fphm += ",";
  8507. }
  8508. entiy.Update();
  8509. fpUrl += iObj.list[0].c_url + ",";
  8510. }
  8511. //returnSuccess(res);
  8512. StringBuilder sql = new StringBuilder();
  8513. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8514. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8515. }
  8516. else
  8517. {
  8518. int eidx = res.IndexOf("c_resultmsg");
  8519. //int lidx = res.IndexOf("c_status");
  8520. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8521. //开票失败
  8522. entiy.state = 5;
  8523. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8524. entiy.Update();
  8525. returnErrorMsg("开票失败");
  8526. return;
  8527. }
  8528. }
  8529. var returnObj = new
  8530. {
  8531. data = fpUrl
  8532. };
  8533. string ro_json = JsonConvert.SerializeObject(returnObj);
  8534. returnSuccess(ro_json);
  8535. }
  8536. }
  8537. catch (Exception ex)
  8538. {
  8539. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8540. }
  8541. return;
  8542. }
  8543. }
  8544. public void save_erp_billimg()
  8545. {
  8546. if (UrlPostParmsCheck("id"))
  8547. {
  8548. string eid = GetPostString("id");
  8549. CeErpBill bill_entity = null;
  8550. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8551. if (bill_entity != null)
  8552. {
  8553. bill_entity.img = GetPostString("img");
  8554. bill_entity.executeTime = DateTime.Now;
  8555. bill_entity.state = 2;
  8556. bill_entity.Update();
  8557. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8558. returnSuccessMsg("保存成功");
  8559. }
  8560. return;
  8561. }
  8562. }
  8563. public void upd_erp_billreturnback()
  8564. {
  8565. if (UrlPostParmsCheck("id"))
  8566. {
  8567. int eid = GetPostInt("id");
  8568. CeErpBill bill_entity = null;
  8569. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8570. if (bill_entity != null)
  8571. {
  8572. bill_entity.state = 3;
  8573. bill_entity.returnReason = GetPostString("reason");
  8574. bill_entity.Update();
  8575. returnSuccessMsg("驳回成功!");
  8576. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8577. }
  8578. return;
  8579. }
  8580. }
  8581. public void cancel_erp_bill()
  8582. {
  8583. if (UrlPostParmsCheck("id"))
  8584. {
  8585. int eid = GetPostInt("id");
  8586. int detailValue = GetPostInt("detailvalue");
  8587. CeErpBill bill_entity = null;
  8588. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8589. string cres = "";
  8590. string gres = "";
  8591. if (bill_entity != null)
  8592. {
  8593. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8594. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8595. {
  8596. int iTag = 0;
  8597. bill_entity.fplsh = "";
  8598. bill_entity.fpdm = "";
  8599. bill_entity.fphm = "";
  8600. foreach (string billOrderId in billOrderList)
  8601. {
  8602. iTag++;
  8603. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8604. if (gres.IndexOf("success") != -1)
  8605. {
  8606. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8607. Invoicing_get_response_Obj iObj = null;
  8608. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8609. if (iObj != null)
  8610. {
  8611. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8612. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8613. bill_entity.fphm += iObj.list[0].c_fphm;
  8614. if (iTag < billOrderList.Length)
  8615. {
  8616. bill_entity.fplsh += ",";
  8617. bill_entity.fpdm += ",";
  8618. bill_entity.fphm += ",";
  8619. }
  8620. bill_entity.Update();
  8621. }
  8622. }
  8623. else
  8624. {
  8625. returnErrorMsg(gres);
  8626. return;
  8627. }
  8628. }
  8629. }
  8630. if (bill_entity.sendType == "纸质发票")
  8631. {
  8632. //作废
  8633. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8634. //if (DateTime.Now.Month == extime.Month)
  8635. //{
  8636. //cres = taobaoHelper.cancel_invoicing(eid);
  8637. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8638. //{
  8639. bill_entity.state = 4;//已作废
  8640. bill_entity.Update();
  8641. returnSuccessMsg("发票已作废");
  8642. return;
  8643. //}
  8644. //else
  8645. //{
  8646. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8647. // bill_entity.Update();
  8648. // returnErrorMsg(cres);
  8649. // return;
  8650. //}
  8651. //}
  8652. //else
  8653. //{
  8654. // returnErrorMsg("纸质发票只能作废本月的发票");
  8655. // return;
  8656. //}
  8657. }
  8658. //红冲
  8659. int redTag = 0;
  8660. string[] fpdmList = bill_entity.fpdm.Split(',');
  8661. string[] fphmList = bill_entity.fphm.Split(',');
  8662. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8663. {
  8664. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8665. return;
  8666. }
  8667. foreach (string billOrderId in billOrderList)
  8668. {
  8669. redTag++;
  8670. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8671. cres += onecres;
  8672. cres += ",";
  8673. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8674. {
  8675. bill_entity.state = 4;//已作废
  8676. //bill_entity.Update();
  8677. //returnSuccessMsg("发票已红冲");
  8678. }
  8679. else if (onecres.IndexOf("重复冲红") != -1)
  8680. {
  8681. bill_entity.state = 4;//已作废
  8682. //bill_entity.Update();
  8683. //returnSuccessMsg("发票已红冲");
  8684. }
  8685. else
  8686. {
  8687. string errmsg = commonHelper.KeepChinese(onecres);
  8688. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8689. }
  8690. }
  8691. bill_entity.Update();
  8692. if (cres.IndexOf("失败") != -1)
  8693. returnErrorMsg("红冲失败");
  8694. else
  8695. returnSuccessMsg("发票已红冲");
  8696. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8697. return;
  8698. }
  8699. return;
  8700. }
  8701. }
  8702. public void del_erp_billorder()
  8703. {
  8704. if (UrlPostParmsCheck("id"))
  8705. {
  8706. string eid = GetPostString("id");
  8707. CeErpBill.Del(eid);
  8708. CeErpBill bill = CeErpBill.Get(eid);
  8709. if (bill != null)
  8710. {
  8711. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8712. }
  8713. returnSuccessMsg("删除成功");
  8714. }
  8715. }
  8716. public void finish_erp_bill()
  8717. {
  8718. if (UrlPostParmsCheck("ids"))
  8719. {
  8720. string eids = GetPostString("ids");
  8721. string[] list = eids.Split(',');
  8722. foreach (string eid in list)
  8723. {
  8724. CeErpBill bill = CeErpBill.Get(eid);
  8725. if (bill != null)
  8726. {
  8727. bill.state = 2;
  8728. bill.Update();
  8729. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8730. }
  8731. }
  8732. returnSuccessMsg("操作成功");
  8733. }
  8734. }
  8735. public void get_erp_returncash()
  8736. {
  8737. DataStruct dStruct = GetPostStruct();
  8738. List<string> lw = new List<string>();
  8739. string tid = GetPostString("tid");
  8740. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8741. string shopname = GetPostString("shopname");
  8742. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8743. string buyernick = GetPostString("buyer_nick");
  8744. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8745. string customer = GetPostString("customer");
  8746. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8747. string returndate1 = GetPostString("returndate1");
  8748. string returndate2 = GetPostString("returndate2");
  8749. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8750. if (dw.Length > 0) lw.Add(dw);
  8751. string finishDate1 = GetPostString("finishdate1");
  8752. string finishDate2 = GetPostString("finishdate2");
  8753. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8754. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8755. string returntype = GetPostString("returntype");
  8756. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8757. string returnvstate = GetPostString("returnvstate");
  8758. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8759. dStruct.Order = "created desc";
  8760. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8761. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8762. writeGridDataTableJson(dStruct.TotalCount, dt);
  8763. }
  8764. public void get_erp_staygoods()
  8765. {
  8766. DataStruct dStruct = GetPostStruct();
  8767. List<string> lw = new List<string>();
  8768. string tid = GetPostString("tid");
  8769. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8770. string shopname = GetPostString("shopname");
  8771. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8772. string wangwang = GetPostString("wangwang");
  8773. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8774. string customer = GetPostString("customer");
  8775. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8776. string returndate1 = GetPostString("returndate1");
  8777. string returndate2 = GetPostString("returndate2");
  8778. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8779. if (dw.Length > 0) lw.Add(dw);
  8780. string finishDate1 = GetPostString("finishdate1");
  8781. string finishDate2 = GetPostString("finishdate2");
  8782. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8783. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8784. string returnvstate = GetPostString("returnvstate");
  8785. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8786. string persuadetype = GetPostString("persuadetype");
  8787. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8788. string customerOrg = GetPostString("customerOrg");
  8789. if (customerOrg.Length > 0)
  8790. {
  8791. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8792. }
  8793. dStruct.Order = "creata_time desc";
  8794. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8795. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8796. writeGridDataTableJson(dStruct.TotalCount, dt);
  8797. }
  8798. public void upd_erp_staygoods()
  8799. {
  8800. if (UrlPostParmsCheck("id"))
  8801. {
  8802. int eid = GetPostInt("id");
  8803. CeErpStayGoods entity = null;
  8804. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8805. if (entity != null)
  8806. {
  8807. entity.audit_type = 1;
  8808. entity.audit_time = DateTime.Now;
  8809. entity.audit_u_id = CurrentUser.UserID;
  8810. entity.audit_u_name = CurrentUser.UserName;
  8811. entity.Update();
  8812. returnSuccessMsg("审核成功!");
  8813. return;
  8814. }
  8815. returnErrorMsg("找不到订单记录");
  8816. }
  8817. }
  8818. public void upd_erp_stayGoodsback()
  8819. {
  8820. if (UrlPostParmsCheck("id"))
  8821. {
  8822. int eid = GetPostInt("id");
  8823. CeErpStayGoods entity = null;
  8824. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8825. if (entity != null)
  8826. {
  8827. entity.audit_text = GetPostString("reason");
  8828. entity.audit_type = 2;
  8829. entity.audit_time = DateTime.Now;
  8830. entity.audit_u_id = CurrentUser.UserID;
  8831. entity.audit_u_name = CurrentUser.UserName;
  8832. entity.Update();
  8833. returnSuccessMsg("退回成功!");
  8834. return;
  8835. }
  8836. returnErrorMsg("找不到订单记录");
  8837. }
  8838. }
  8839. public void upd_erp_returncashverify()
  8840. {
  8841. if (UrlPostParmsCheck("ID"))
  8842. {
  8843. int eid = GetPostInt("ID");
  8844. CeErpReturnCash entity = null;
  8845. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8846. if (entity != null)
  8847. {
  8848. entity.cashstate = 1;
  8849. entity.verifytime = DateTime.Now;
  8850. entity.verifyuserid = CurrentUser.UserID;
  8851. entity.Update();
  8852. returnSuccessMsg("审核成功!");
  8853. return;
  8854. }
  8855. returnErrorMsg("找不到订单记录");
  8856. }
  8857. }
  8858. public void upd_all_erp_returncashverify()
  8859. {
  8860. if (UrlPostParmsCheck("ID"))
  8861. {
  8862. String[] list = GetPostString("ID").Split(',');
  8863. CeErpReturnCash entity = null;
  8864. for (int i = 0; i < list.Length; i++)
  8865. {
  8866. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8867. if (entity != null)
  8868. {
  8869. if (entity.cashstate == 1)
  8870. {
  8871. returnErrorMsg("已审核过的订单不需要在审核!");
  8872. return;
  8873. }
  8874. entity.cashstate = 1;
  8875. entity.verifytime = DateTime.Now;
  8876. entity.verifyuserid = CurrentUser.UserID;
  8877. entity.Update();
  8878. }
  8879. }
  8880. returnSuccessMsg("审核成功!");
  8881. return;
  8882. }
  8883. }
  8884. public void upd_erp_returncashback()
  8885. {
  8886. if (UrlPostParmsCheck("ID"))
  8887. {
  8888. int eid = GetPostInt("ID");
  8889. CeErpReturnCash entity = null;
  8890. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8891. if (entity != null)
  8892. {
  8893. entity.backreason = GetPostString("reason");
  8894. entity.cashstate = 2;
  8895. entity.verifytime = DateTime.Now;
  8896. entity.verifyuserid = CurrentUser.UserID;
  8897. entity.Update();
  8898. returnSuccessMsg("退回成功!");
  8899. return;
  8900. }
  8901. returnErrorMsg("找不到订单记录");
  8902. }
  8903. }
  8904. public void upd_erp_returnprice()
  8905. {
  8906. if (UrlPostParmsCheck("ID"))
  8907. {
  8908. int eid = GetPostInt("ID");
  8909. CeErpReturnCash entity = null;
  8910. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8911. if (entity != null)
  8912. {
  8913. if (entity.cashstate == 1)
  8914. {
  8915. returnErrorMsg("审核通过了不能改");
  8916. return;
  8917. }
  8918. entity.returnprice = GetPostDouble("returnprice");
  8919. entity.Update();
  8920. returnSuccessMsg("修改成功!");
  8921. return;
  8922. }
  8923. returnErrorMsg("找不到订单记录");
  8924. }
  8925. }
  8926. public void del_erp_returncash()
  8927. {
  8928. if (UrlPostParmsCheck("ID"))
  8929. {
  8930. int eid = GetPostInt("ID");
  8931. CeErpReturnCash.Del(eid);
  8932. returnSuccessMsg("操作成功");
  8933. return;
  8934. }
  8935. }
  8936. public void test_for_do_sql()
  8937. {
  8938. string sql = GetPostString("sqlstr");
  8939. if (sql.Length > 0)
  8940. {
  8941. try
  8942. {
  8943. DbHelper.DbConn.ExecuteNonQuery(sql);
  8944. var res_obj = new
  8945. {
  8946. data = "成功",
  8947. };
  8948. string ro_json = JsonConvert.SerializeObject(res_obj);
  8949. returnSuccess(ro_json);
  8950. }
  8951. catch (Exception ex)
  8952. {
  8953. var res_obj = new
  8954. {
  8955. data = ex.Message,
  8956. };
  8957. string ro_json = JsonConvert.SerializeObject(res_obj);
  8958. returnSuccess(ro_json);
  8959. }
  8960. }
  8961. }
  8962. public void get_user_info()
  8963. {
  8964. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8965. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8966. }
  8967. public void get_total_data()
  8968. {
  8969. int userId = CurrentUser.UserID;
  8970. string sql = "";
  8971. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8972. {
  8973. 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);
  8974. }
  8975. else
  8976. {
  8977. 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 " +
  8978. "(select ID from CE_ErpUser where ID = {0}) d " +
  8979. "left join " +
  8980. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8981. ") a on d.ID = a.id left join " +
  8982. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8983. ") b on a.id = b.id1 left join" +
  8984. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8985. ") c on a.id = c.id2;", userId);
  8986. }
  8987. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8988. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8989. }
  8990. public void get_date_area_total_data2()
  8991. {
  8992. int userId = CurrentUser.UserID;
  8993. string date_type = GetPostString("timetype");
  8994. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8995. string sql = "";
  8996. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8997. {
  8998. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8999. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  9000. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9001. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9002. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9003. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  9004. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9005. ") a on e.ID = a.id left join " +
  9006. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9007. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9008. ") b on a.id = b.id1 " +
  9009. "left join " +
  9010. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9011. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9012. ") c on a.id = c.id2 " +
  9013. "left join " +
  9014. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9015. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9016. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9017. }
  9018. else
  9019. {
  9020. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9021. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9022. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9023. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9024. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9025. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9026. ") a on e.ID = a.id left join " +
  9027. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9028. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9029. ") c on a.id = c.id2 " +
  9030. "left join " +
  9031. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9032. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9033. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9034. }
  9035. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9036. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9037. }
  9038. public void get_date_area_total_data()
  9039. {
  9040. int userId = CurrentUser.UserID;
  9041. string date_type = GetPostString("timetype");
  9042. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9043. string date1 = searchDT[0].ToString();
  9044. string date2 = searchDT[1].ToString();
  9045. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9046. {
  9047. SqlParameter[] sqlParameter ={
  9048. new SqlParameter("@userId", SqlDbType.Int,4),
  9049. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9050. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9051. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9052. };
  9053. sqlParameter[0].Value = userId;
  9054. sqlParameter[1].Value = date1;
  9055. sqlParameter[2].Value = date2;
  9056. sqlParameter[3].Direction = ParameterDirection.Output;
  9057. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9058. string res = sqlParameter[3].Value.ToString();
  9059. var res_obj = new
  9060. {
  9061. data = res
  9062. };
  9063. string ro_json = JsonConvert.SerializeObject(res_obj);
  9064. returnSuccess(ro_json);
  9065. }
  9066. else
  9067. {
  9068. SqlParameter[] sqlParameter ={
  9069. new SqlParameter("@userId", SqlDbType.Int,4),
  9070. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9071. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9072. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9073. };
  9074. sqlParameter[0].Value = userId;
  9075. sqlParameter[1].Value = date1;
  9076. sqlParameter[2].Value = date2;
  9077. sqlParameter[3].Direction = ParameterDirection.Output;
  9078. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9079. string res = sqlParameter[3].Value.ToString();
  9080. var res_obj = new
  9081. {
  9082. data = res
  9083. };
  9084. string ro_json = JsonConvert.SerializeObject(res_obj);
  9085. returnSuccess(ro_json);
  9086. }
  9087. //writeGridDataViewJson(dt.Rows.Count, dv);
  9088. }
  9089. public void get_order_list()
  9090. {
  9091. string strFields = GetPostString("paraFields");
  9092. string strOrder = GetPostString("paraOrder");
  9093. string strWhere = GetPostString("paraWhere");
  9094. string strPageSize = GetPostString("paraPageSize");
  9095. DataStruct dStruct = GetPostStruct();
  9096. dStruct.PageSize = int.Parse(strPageSize);
  9097. dStruct.Fileds = strFields;
  9098. dStruct.Order = strOrder;
  9099. dStruct.MainWhere = strWhere;
  9100. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9101. writeGridDataTableJson(dStruct.TotalCount, dt);
  9102. }
  9103. ////获取待开始订单列表
  9104. //public void get_wait_design_order_list()
  9105. //{
  9106. // string date_type = GetPostString("date_type");
  9107. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9108. // DataStruct dStruct = GetPostStruct();
  9109. // dStruct.PageSize = 1000;
  9110. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9111. // List<string> lw = new List<string>();
  9112. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9113. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9114. // dStruct.Order = "WaitDesignTime asc";
  9115. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9116. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9117. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9118. //}
  9119. //获取完成单量排名
  9120. public void get_finish_order_count_ranking()
  9121. {
  9122. /* string date_type = GetPostString("date_type");
  9123. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9124. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9125. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9126. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9127. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9128. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9129. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9130. writeGridDataTableJson(0, new DataTable());
  9131. }
  9132. public void get_finish_order_amount_ranking()
  9133. {
  9134. /*string date_type = GetPostString("date_type");
  9135. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9136. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9137. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9138. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9139. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9140. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9141. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9142. writeGridDataTableJson(0, new DataTable());
  9143. }
  9144. public void get_finish_refund_count_ranking()
  9145. {
  9146. string date_type = GetPostString("date_type");
  9147. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9148. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9149. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9150. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9151. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9152. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9153. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9154. writeGridDataTableJson(dt.Rows.Count, dt);
  9155. }
  9156. public void get_finish_refund_amount_ranking()
  9157. {
  9158. string date_type = GetPostString("date_type");
  9159. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9160. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9161. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9162. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9163. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9164. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9165. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9166. writeGridDataTableJson(dt.Rows.Count, dt);
  9167. }
  9168. public void set_erp_finishorder_director()
  9169. {
  9170. if (UrlPostParmsCheck("ctid"))
  9171. {
  9172. string eid = GetPostString("ctid");
  9173. CeErpTradeCell entity = null;
  9174. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9175. if (entity != null)
  9176. {
  9177. entity.OrderState = 8;
  9178. entity.Update();
  9179. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9180. returnSuccessMsg("操作成功!");
  9181. return;
  9182. }
  9183. returnErrorMsg("找不到记录");
  9184. }
  9185. }
  9186. public void get_erp_placeregistlist()
  9187. {
  9188. DataStruct dStruct = GetPostStruct();
  9189. List<string> lw = new List<string>();
  9190. string outsid = GetPostString("outsid");
  9191. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9192. string memo = GetPostString("memo");
  9193. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9194. string filename = GetPostString("filename");
  9195. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9196. string islate = GetPostString("islate");
  9197. if (islate.Length > 0)
  9198. {
  9199. if (islate == "1")
  9200. lw.Add(string.Format("OutLate>0"));
  9201. else
  9202. lw.Add(string.Format("OutLate=0"));
  9203. }
  9204. string placedate1 = GetPostString("placedate1");
  9205. string placedate2 = GetPostString("placedate2");
  9206. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9207. if (dw.Length > 0) lw.Add(dw);
  9208. string deliveryDate1 = GetPostString("deliverydate1");
  9209. string deliveryDate2 = GetPostString("deliverydate2");
  9210. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9211. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9212. dStruct.Order = "ID desc";
  9213. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9214. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9215. writeGridDataTableJson(dStruct.TotalCount, dt);
  9216. }
  9217. public void ins_erp_placeregist()
  9218. {
  9219. if (UrlPostParmsCheck("id"))
  9220. {
  9221. string eid = GetPostString("id");
  9222. CeErpPlaceRegister entity = null;
  9223. if (eid == "0")//新增
  9224. {
  9225. entity = new CeErpPlaceRegister();
  9226. string xdTime = GetPostString("placeTime");
  9227. if (xdTime.Length > 0)
  9228. {
  9229. entity.PlactTime = Convert.ToDateTime(xdTime);
  9230. }
  9231. string fhTime = GetPostString("deliveryTime");
  9232. if (fhTime.Length > 0)
  9233. {
  9234. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9235. }
  9236. string preTime = GetPostString("preOutTime");
  9237. if (preTime.Length > 0)
  9238. {
  9239. entity.PreOutTime = Convert.ToDateTime(preTime);
  9240. }
  9241. entity.DeliveryCount = GetPostInt("deliveryCount");
  9242. entity.ReceiveCount = GetPostInt("receiveCount");
  9243. entity.OutSid = GetPostString("outSid");
  9244. entity.FileName = GetPostString("fileName");
  9245. entity.Memo = GetPostString("memo");
  9246. entity.AddUserId = CurrentUser.UserID;
  9247. entity.CreateTime = DateTime.Now;
  9248. entity.Img = GetPostString("img");
  9249. entity.Supplier = GetPostInt("supplier");
  9250. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9251. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9252. {
  9253. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9254. DateTime dt2 = (DateTime)entity.PreOutTime;
  9255. TimeSpan span = dt1.Subtract(dt2);
  9256. if (span.Days > 0)
  9257. {
  9258. entity.OutLate = span.Days;
  9259. }
  9260. }
  9261. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9262. entity.Create();
  9263. returnSuccessMsg("添加成功!");
  9264. return;
  9265. }
  9266. else //修改
  9267. {
  9268. entity = CeErpPlaceRegister.Get(eid);
  9269. if (entity != null)
  9270. {
  9271. string xdTime = GetPostString("placeTime");
  9272. if (xdTime.Length > 0)
  9273. {
  9274. entity.PlactTime = Convert.ToDateTime(xdTime);
  9275. }
  9276. string fhTime = GetPostString("deliveryTime");
  9277. if (fhTime.Length > 0)
  9278. {
  9279. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9280. }
  9281. string preTime = GetPostString("preOutTime");
  9282. if (preTime.Length > 0)
  9283. {
  9284. entity.PreOutTime = Convert.ToDateTime(preTime);
  9285. }
  9286. entity.DeliveryCount = GetPostInt("deliveryCount");
  9287. entity.ReceiveCount = GetPostInt("receiveCount");
  9288. if (entity.DeliveryCount == entity.ReceiveCount)
  9289. {
  9290. entity.CurState = "已完成";
  9291. }
  9292. else
  9293. {
  9294. entity.CurState = "未完成";
  9295. }
  9296. entity.OutSid = GetPostString("outSid");
  9297. entity.FileName = GetPostString("fileName");
  9298. entity.Memo = GetPostString("memo");
  9299. entity.Img = GetPostString("img");
  9300. entity.Supplier = GetPostInt("supplier");
  9301. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9302. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9303. {
  9304. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9305. DateTime dt2 = (DateTime)entity.PreOutTime;
  9306. TimeSpan span = dt1.Subtract(dt2);
  9307. if (span.Days > 0)
  9308. {
  9309. entity.OutLate = span.Days;
  9310. }
  9311. }
  9312. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9313. entity.Update();
  9314. returnSuccessMsg("修改成功");
  9315. return;
  9316. }
  9317. returnErrorMsg("找不到对应的记录");
  9318. return;
  9319. }
  9320. }
  9321. returnErrorMsg("缺少必要参数");
  9322. }
  9323. public void del_erp_placeregist()
  9324. {
  9325. string eid = GetPostString("id");
  9326. CeErpPlaceRegister.Del(eid);
  9327. returnSuccessMsg("删除成功!");
  9328. return;
  9329. }
  9330. public void ins_erp_placeregistbyorder()
  9331. {
  9332. string ctid = GetPostString("ctid");
  9333. if (ctid.Length > 0)
  9334. {
  9335. StringBuilder sql = new StringBuilder();
  9336. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9337. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9338. if (dt.Rows.Count > 0)
  9339. {
  9340. foreach (DataRow dr in dt.Rows)
  9341. {
  9342. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9343. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9344. entity.AddUserId = CurrentUser.UserID;
  9345. entity.tid = dr["tid"].ToString();
  9346. entity.Did = Convert.ToString(dr["ctid"]);
  9347. entity.splitTag = dr["SplitTag"].ToString();
  9348. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9349. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9350. if (pre_ctid.Length > 0)
  9351. {
  9352. sellmemo = sellmemo.Replace(pre_ctid, "");
  9353. }
  9354. sellmemo = sellmemo.Replace("[", "");
  9355. sellmemo = sellmemo.Replace("]", "");
  9356. entity.FileName = sellmemo;
  9357. string count = dr["ProductCount"].ToString();
  9358. int usecount = commonHelper.getIntCountFromString(count);
  9359. entity.DeliveryCount = usecount;
  9360. entity.CurState = "未完成";
  9361. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9362. {
  9363. entity.Supplier = 24;//dl手提袋定制
  9364. }
  9365. else
  9366. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9367. entity.CreateTime = DateTime.Now;
  9368. entity.Create();
  9369. }
  9370. returnSuccessMsg("操作成功");
  9371. return;
  9372. }
  9373. returnErrorMsg("没有找到对应订单");
  9374. return;
  9375. }
  9376. returnErrorMsg("缺少订单编号");
  9377. return;
  9378. }
  9379. public void get_erp_persuadelist()
  9380. {
  9381. DataStruct dStruct = GetPostStruct();
  9382. List<string> lw = new List<string>();
  9383. string ctid = GetPostString("ctid");
  9384. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9385. string shopname = GetPostString("shopname");
  9386. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9387. string buyernick = GetPostString("buyer_nick");
  9388. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9389. string customer = GetPostString("customer");
  9390. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9391. string returndate1 = GetPostString("returndate1");
  9392. string returndate2 = GetPostString("returndate2");
  9393. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9394. if (dw.Length > 0) lw.Add(dw);
  9395. string finishDate1 = GetPostString("finishdate1");
  9396. string finishDate2 = GetPostString("finishdate2");
  9397. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9398. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9399. string persuadetype = GetPostString("persuadetype");
  9400. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9401. string returnvstate = GetPostString("returnvstate");
  9402. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9403. dStruct.Order = "created desc";
  9404. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9405. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9406. writeGridDataTableJson(dStruct.TotalCount, dt);
  9407. }
  9408. public void upd_erp_returnpersuadeback()
  9409. {
  9410. if (UrlPostParmsCheck("ID"))
  9411. {
  9412. int eid = GetPostInt("ID");
  9413. CeErpPersuade entity = null;
  9414. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9415. if (entity != null)
  9416. {
  9417. entity.backreason = GetPostString("reason");
  9418. entity.pstate = 2;
  9419. entity.verifytime = DateTime.Now;
  9420. entity.verifyuserid = CurrentUser.UserID;
  9421. entity.Update();
  9422. returnSuccessMsg("退回成功!");
  9423. return;
  9424. }
  9425. returnErrorMsg("找不到订单记录");
  9426. }
  9427. }
  9428. public void upd_erp_returnpersuadeverify()
  9429. {
  9430. if (UrlPostParmsCheck("ID"))
  9431. {
  9432. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9433. {
  9434. returnErrorMsg("暂无权限审核");
  9435. return;
  9436. }
  9437. int eid = GetPostInt("ID");
  9438. CeErpPersuade entity = null;
  9439. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9440. if (entity != null)
  9441. {
  9442. entity.pstate = 1;
  9443. entity.verifytime = DateTime.Now;
  9444. entity.verifyuserid = CurrentUser.UserID;
  9445. entity.Update();
  9446. returnSuccessMsg("审核成功!");
  9447. return;
  9448. }
  9449. returnErrorMsg("找不到订单记录");
  9450. }
  9451. }
  9452. public void del_erp_persuade()
  9453. {
  9454. if (UrlPostParmsCheck("ID"))
  9455. {
  9456. int eid = GetPostInt("ID");
  9457. CeErpPersuade.Del(eid);
  9458. returnSuccessMsg("操作成功");
  9459. return;
  9460. }
  9461. }
  9462. public void get_erp_oldcustoupload()
  9463. {
  9464. DataStruct dStruct = GetPostStruct();
  9465. List<string> lw = new List<string>();
  9466. string buyernick = GetPostString("buyer_nick");
  9467. if (buyernick.Length > 0)
  9468. {
  9469. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9470. }
  9471. else
  9472. return;
  9473. dStruct.Order = "pay_time desc";
  9474. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9475. DataTable dt = null;
  9476. dt = WebCache.GetData("view_erptradecell", dStruct);
  9477. writeGridDataTableJson(dStruct.TotalCount, dt);
  9478. }
  9479. public void get_erp_checkorderlist()
  9480. {
  9481. DataStruct dStruct = GetPostStruct();
  9482. List<string> lw = new List<string>();
  9483. string tid = GetPostString("ctid");
  9484. if (tid.Length > 0)
  9485. {
  9486. string select_tid = getTidByCtid(tid);
  9487. lw.Add(string.Format("tid='{0}'", select_tid));
  9488. }
  9489. string shopname = GetPostString("shopname");
  9490. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9491. string buyernick = GetPostString("buyer_nick");
  9492. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9493. string customer = GetPostString("customer");
  9494. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9495. string design = GetPostString("design");
  9496. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9497. string orderState = GetPostString("orderState");
  9498. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9499. string address = GetPostString("address");
  9500. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9501. string sellermemo = GetPostString("seller_memo");
  9502. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9503. string supplier = GetPostString("supplier");
  9504. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9505. {
  9506. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9507. }
  9508. else
  9509. {
  9510. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9511. }
  9512. string date1 = GetPostString("date1");
  9513. string date2 = GetPostString("date2");
  9514. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9515. if (dw.Length > 0) lw.Add(dw);
  9516. string placedate1 = GetPostString("placedate1");
  9517. string placedate2 = GetPostString("placedate2");
  9518. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9519. if (fdw.Length > 0) lw.Add(fdw);
  9520. string price1 = GetPostString("price1");
  9521. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9522. string price2 = GetPostString("price2");
  9523. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9524. string checkst = GetPostString("checkstate");
  9525. if (checkst.Length > 0 && "10".Equals(checkst))
  9526. {
  9527. lw.Add(string.Format("CheckOut>0"));
  9528. }
  9529. else
  9530. {
  9531. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9532. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9533. }
  9534. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9535. {
  9536. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9537. }
  9538. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9539. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9540. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9541. writeGridDataTableJson(dStruct.TotalCount, dt);
  9542. }
  9543. public void ins_erp_startCheck()
  9544. {
  9545. if (UrlPostParmsCheck("ctid"))
  9546. {
  9547. string eid = GetPostString("ctid");
  9548. CeErpTradeCell entity = null;
  9549. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9550. if (entity != null)
  9551. {
  9552. entity.MemoOpt = 4;
  9553. entity.UpdateTime = DateTime.Now;
  9554. entity.Update();
  9555. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9556. CeErpSukuraData.createInfo(entity.ctid, 6);
  9557. returnSuccessMsg("操作成功!");
  9558. return;
  9559. }
  9560. returnErrorMsg("找不到记录");
  9561. }
  9562. }
  9563. public void upd_erp_sendXlw()
  9564. {
  9565. if (UrlPostParmsCheck("ctid"))
  9566. {
  9567. string eid = GetPostString("ctid");
  9568. CeErpTradeCell entity = null;
  9569. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9570. if (entity != null)
  9571. {
  9572. if (entity.IsSendGift == 1)
  9573. {
  9574. returnErrorMsg("请勿重复标记");
  9575. return;
  9576. }
  9577. entity.IsSendGift = 1;
  9578. entity.Update();
  9579. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9580. returnSuccessMsg("操作成功!");
  9581. return;
  9582. }
  9583. returnErrorMsg("找不到记录");
  9584. }
  9585. }
  9586. public void cancel_sendXlw()
  9587. {
  9588. if (UrlPostParmsCheck("ctid"))
  9589. {
  9590. string eid = GetPostString("ctid");
  9591. CeErpTradeCell entity = null;
  9592. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9593. if (entity != null)
  9594. {
  9595. if (entity.IsSendGift == 0)
  9596. {
  9597. returnErrorMsg("未标记小礼物");
  9598. return;
  9599. }
  9600. entity.IsSendGift = 0;
  9601. entity.Update();
  9602. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9603. returnSuccessMsg("操作成功!");
  9604. return;
  9605. }
  9606. returnErrorMsg("找不到记录");
  9607. }
  9608. }
  9609. public void get_erp_designbill()
  9610. {
  9611. DataStruct dStruct = GetPostStruct();
  9612. List<string> lw = new List<string>();
  9613. int isMy = GetInt("my");
  9614. if (isMy == 1)
  9615. {
  9616. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9617. }
  9618. string tid = GetPostString("tid");
  9619. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9620. string userName = GetPostString("design");
  9621. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9622. string price1 = GetPostString("price1");
  9623. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9624. string price2 = GetPostString("price2");
  9625. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9626. string rePrice1 = GetPostString("rePrice1");
  9627. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9628. string rePrice2 = GetPostString("rePrice2");
  9629. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9630. string designerType = GetPostString("designerType");
  9631. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9632. string orderState = GetPostString("orderState");
  9633. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9634. string endTime1 = GetPostString("endTime1");
  9635. string endTime2 = GetPostString("endTime2");
  9636. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9637. if (dw.Length > 0) lw.Add(dw);
  9638. string isDk = GetPostString("isDk");
  9639. if (isDk == "1")
  9640. {
  9641. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9642. }
  9643. else if (isDk == "0")
  9644. {
  9645. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9646. }
  9647. dStruct.Order = "oid, create_time desc";
  9648. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9649. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9650. writeGridDataTableJson(dStruct.TotalCount, dt);
  9651. }
  9652. public void upd_erp_designerbill()
  9653. {
  9654. if (UrlPostParmsCheck("ID"))
  9655. {
  9656. string eid = GetPostString("ID");
  9657. CeErpDesignerBill entity = null;
  9658. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9659. if (entity != null)
  9660. {
  9661. if (GetPostDouble("designerpirce") > 0)
  9662. {
  9663. entity.realPrice = GetPostDouble("designerpirce");
  9664. entity.update_time = DateTime.Now;
  9665. entity.update_u_id = CurrentUser.UserID;
  9666. entity.update_u_name = CurrentUser.UserName;
  9667. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9668. entity.Update();
  9669. returnSuccessMsg("操作成功!");
  9670. return;
  9671. }
  9672. else
  9673. {
  9674. entity.price = GetPostDouble("price");
  9675. entity.update_time = DateTime.Now;
  9676. entity.update_u_id = CurrentUser.UserID;
  9677. entity.update_u_name = CurrentUser.UserName;
  9678. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9679. entity.Update();
  9680. returnSuccessMsg("操作成功!");
  9681. return;
  9682. }
  9683. }
  9684. returnErrorMsg("找不到记录");
  9685. }
  9686. }
  9687. public void audit_erp_designerbill()
  9688. {
  9689. if (UrlPostParmsCheck("ID"))
  9690. {
  9691. string eid = GetPostString("ID");
  9692. CeErpDesignerBill entity = null;
  9693. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9694. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9695. if (entity != null)
  9696. {
  9697. entity.realPrice = GetPostDouble("designerpirce");
  9698. entity.update_time = DateTime.Now;
  9699. entity.update_u_id = CurrentUser.UserID;
  9700. entity.update_u_name = CurrentUser.UserName;
  9701. entity.isAudit = 1;
  9702. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9703. entity.Update();
  9704. if (orderEntity != null)
  9705. {
  9706. orderEntity.IsReadTag = 3;
  9707. orderEntity.Update();
  9708. }
  9709. returnSuccessMsg("操作成功!");
  9710. return;
  9711. }
  9712. returnErrorMsg("找不到记录");
  9713. }
  9714. }
  9715. public void all_audit_erp_designerbill()
  9716. {
  9717. if (UrlPostParmsCheck("idList"))
  9718. {
  9719. string[] list = GetPostString("idList").Split(',');
  9720. CeErpDesignerBill entity = null;
  9721. for (int i = 0; i < list.Length; i++)
  9722. {
  9723. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9724. if (entity == null) return;
  9725. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9726. if (orderEntity == null) return;
  9727. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9728. entity.update_time = DateTime.Now;
  9729. entity.update_u_id = CurrentUser.UserID;
  9730. entity.update_u_name = CurrentUser.UserName;
  9731. entity.isAudit = 1;
  9732. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9733. entity.Update();
  9734. orderEntity.IsReadTag = 3;
  9735. orderEntity.Update();
  9736. }
  9737. returnSuccessMsg("操作成功!");
  9738. return;
  9739. }
  9740. }
  9741. public void get_erp_sameorders()
  9742. {
  9743. if (UrlPostParmsCheck("ctid"))
  9744. {
  9745. string eid = GetPostString("ctid");
  9746. CeErpTradeCell entity = null;
  9747. entity = CeErpTradeCell.GetByCtid(eid);
  9748. if (entity != null)
  9749. {
  9750. StringBuilder sql = new StringBuilder();
  9751. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9752. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9753. var res = new
  9754. {
  9755. data = dt.Rows.Count
  9756. };
  9757. string ro_jsond = JsonConvert.SerializeObject(res);
  9758. returnSuccess(ro_jsond);
  9759. return;
  9760. }
  9761. returnErrorMsg("未找到订单");
  9762. return;
  9763. }
  9764. returnErrorMsg("缺少必要的参数");
  9765. }
  9766. public void get_erp_islasthavesameorder()
  9767. {
  9768. if (UrlPostParmsCheck("ctid"))
  9769. {
  9770. string eid = GetPostString("ctid");
  9771. string[] ctidList = eid.Split(',');
  9772. StringBuilder sql = new StringBuilder();
  9773. string tisCtid = "";
  9774. foreach (string ctid in ctidList)
  9775. {
  9776. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9777. if (entity != null)
  9778. {
  9779. sql = new StringBuilder();
  9780. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9781. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9782. if (dth.Rows.Count > 0)
  9783. {
  9784. tisCtid += entity.ctid;
  9785. tisCtid += ",";
  9786. }
  9787. }
  9788. }
  9789. if (tisCtid.Length > 0)
  9790. {
  9791. var res = new
  9792. {
  9793. data = tisCtid
  9794. };
  9795. string ro_jsond = JsonConvert.SerializeObject(res);
  9796. returnSuccess(ro_jsond);
  9797. }
  9798. else
  9799. {
  9800. var res = new
  9801. {
  9802. data = ""
  9803. };
  9804. string ro_jsond = JsonConvert.SerializeObject(res);
  9805. returnSuccess(ro_jsond);
  9806. }
  9807. return;
  9808. }
  9809. returnErrorMsg("缺少必要的参数");
  9810. }
  9811. public void file_client_down_url()
  9812. {
  9813. if (!UrlPostParmsCheck("userId"))
  9814. {
  9815. returnErrorMsg("缺少必要的参数");
  9816. }
  9817. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9818. }
  9819. public void checkout_form_data()
  9820. {
  9821. if (!UrlPostParmsCheck("tid"))
  9822. {
  9823. returnErrorMsg("缺少必要的参数");
  9824. }
  9825. string tid = GetPostString("tid");
  9826. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9827. if (ceErpOrderFormData != null)
  9828. {
  9829. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9830. returnSuccess(ro_jsond);
  9831. return;
  9832. }
  9833. returnErrorMsg("尚未有文件!");
  9834. }
  9835. public void back_supplier_audit()
  9836. {
  9837. int userId = CurrentUser.UserID;
  9838. StringBuilder sql = new StringBuilder();
  9839. 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);
  9840. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9841. if (dt.Rows.Count > 0)
  9842. {
  9843. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9844. }
  9845. else
  9846. {
  9847. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9848. }
  9849. }
  9850. public void back_supplier_query()
  9851. {
  9852. string eid = GetPostString("ctid");
  9853. if (eid != "")
  9854. {
  9855. StringBuilder sql = new StringBuilder();
  9856. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9857. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9858. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9859. }
  9860. else
  9861. {
  9862. returnErrorMsg("找不到订单记录");
  9863. return;
  9864. }
  9865. }
  9866. public void verified_to_order()
  9867. {
  9868. int userId = CurrentUser.UserID;
  9869. StringBuilder sql = new StringBuilder();
  9870. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9871. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9872. if (dt.Rows.Count > 0)
  9873. {
  9874. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9875. }
  9876. else
  9877. {
  9878. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9879. }
  9880. }
  9881. public void upd_supplier_audit()
  9882. {
  9883. if (UrlPostParmsCheck("ctid"))
  9884. {
  9885. string eid = GetPostString("ctid");
  9886. string reason = GetPostString("returnreason");
  9887. CeErpTradeCell entity = null;
  9888. CeWithdraw withdraw = null;
  9889. withdraw = CeWithdraw.GetByTid(eid);
  9890. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9891. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9892. {
  9893. if (withdraw != null)
  9894. {
  9895. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9896. {
  9897. returnSuccessMsg("您没有权限操作!");
  9898. return;
  9899. }
  9900. else
  9901. {
  9902. if (reason.Equals("1"))
  9903. {
  9904. if (entity.OrderState == -1)
  9905. {
  9906. if (entity.FinishPlaceTime == null)
  9907. {
  9908. entity.OrderState = 2;
  9909. }
  9910. else
  9911. {
  9912. entity.OrderState = 6;
  9913. }
  9914. }
  9915. entity.Update();
  9916. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9917. if (withdraw != null)
  9918. {
  9919. withdraw.status = int.Parse(reason);
  9920. withdraw.Update();
  9921. }
  9922. returnSuccessMsg("操作成功!");
  9923. return;
  9924. }
  9925. else
  9926. {
  9927. withdraw.status = int.Parse(reason);
  9928. withdraw.acknowledgingtime = DateTime.Now;
  9929. withdraw.Update();
  9930. returnSuccessMsg("查看详细请点击线下订单查询");
  9931. return;
  9932. }
  9933. }
  9934. }
  9935. // 第一个字符是 'N'
  9936. }
  9937. if (eid[0] != 'N')
  9938. {
  9939. }
  9940. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9941. {
  9942. entity.IsVerifyToSupplier = false;
  9943. entity.IsReturn = 1;
  9944. entity.ReturnTime = DateTime.Now;
  9945. entity.ReturnReason = reason;
  9946. if (entity.OrderState == 6)
  9947. {
  9948. entity.OrderState = 5;
  9949. }
  9950. entity.Update();
  9951. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9952. if (withdraw != null)
  9953. {
  9954. withdraw.status = int.Parse(reason);
  9955. withdraw.Update();
  9956. }
  9957. returnSuccessMsg("操作成功!");
  9958. return;
  9959. }
  9960. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9961. {
  9962. ;
  9963. if (withdraw != null)
  9964. {
  9965. withdraw.status = int.Parse(reason);
  9966. withdraw.acknowledgingtime = DateTime.Now;
  9967. withdraw.Update();
  9968. returnSuccessMsg("供应商取消撤回!");
  9969. return;
  9970. }
  9971. }
  9972. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9973. {
  9974. if (entity.OrderState == -1)
  9975. {
  9976. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  9977. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9978. if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  9979. {
  9980. returnErrorMsg("台湾客户需填写身份证!");
  9981. return;
  9982. }
  9983. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9984. {
  9985. returnErrorMsg("订单spu没有确认无法通过审核!");
  9986. return;
  9987. }
  9988. if (entity.FinishPlaceTime == null)
  9989. {
  9990. entity.OrderState = 2;
  9991. }
  9992. else
  9993. {
  9994. entity.OrderState = 3;
  9995. }
  9996. commonHelper.getCytPrice(entity);
  9997. }
  9998. entity.Update();
  9999. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10000. if (withdraw != null)
  10001. {
  10002. withdraw.status = int.Parse(reason);
  10003. withdraw.Update();
  10004. }
  10005. returnSuccessMsg("操作成功!");
  10006. return;
  10007. }
  10008. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10009. {
  10010. if (withdraw == null)
  10011. {
  10012. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10013. return;
  10014. }
  10015. }
  10016. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10017. {
  10018. if (withdraw != null)
  10019. {
  10020. withdraw.status = int.Parse(reason);
  10021. withdraw.acknowledgingtime = DateTime.Now;
  10022. withdraw.Update();
  10023. returnSuccessMsg("查看详细请点击线下订单查询");
  10024. return;
  10025. }
  10026. }
  10027. return;
  10028. }
  10029. }
  10030. //校验报价
  10031. public void refund_order_tip()
  10032. {
  10033. int userid = CurrentUser.UserID;
  10034. int sectionId = CurrentUser.UserPost.OrgID;
  10035. StringBuilder sql = new StringBuilder();
  10036. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10037. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10038. List<string> ids = new List<string>();
  10039. if (dth.Rows.Count > 0)
  10040. {
  10041. foreach (DataRow dr in dth.Rows)
  10042. {
  10043. ids.Add(dr["ID"].ToString());
  10044. }
  10045. try
  10046. {
  10047. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10048. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10049. }
  10050. catch (Exception ex)
  10051. {
  10052. }
  10053. }
  10054. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10055. }
  10056. public void refund_order_Design()
  10057. {
  10058. int userid = CurrentUser.UserID;
  10059. int sectionId = CurrentUser.UserPost.OrgID;
  10060. StringBuilder sql = new StringBuilder();
  10061. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10062. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10063. List<string> ids = new List<string>();
  10064. if (dth.Rows.Count > 0)
  10065. {
  10066. foreach (DataRow dr in dth.Rows)
  10067. {
  10068. ids.Add(dr["ID"].ToString());
  10069. }
  10070. try
  10071. {
  10072. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10073. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10074. }
  10075. catch (Exception ex)
  10076. {
  10077. }
  10078. }
  10079. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10080. }
  10081. public void change_order_info()
  10082. {
  10083. int userid = CurrentUser.UserID;
  10084. StringBuilder sql = new StringBuilder();
  10085. 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);
  10086. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10087. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10088. }
  10089. public void change_win_mome()
  10090. {
  10091. if (UrlPostParmsCheck("id,ctid"))
  10092. {
  10093. string id = GetPostString("id");
  10094. string ctid = GetPostString("ctid");
  10095. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10096. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10097. if (ce == null || ceErpMessageTip == null)
  10098. {
  10099. returnSuccessMsg("未找到对应的订单!");
  10100. return;
  10101. }
  10102. if (ce.OrderState >= 5)
  10103. {
  10104. ceErpMessageTip.isVisit = true;
  10105. ceErpMessageTip.Update();
  10106. returnSuccessMsg("已上传文件无法修改!");
  10107. return;
  10108. }
  10109. int type = GetPostInt("type");
  10110. string content = GetPostString("content");
  10111. if (type == 0)
  10112. {
  10113. content = content.Replace("(", "(");
  10114. content = content.Replace(")", ")");
  10115. string check = MidStrEx(content, "(", ")").Trim();
  10116. if (string.IsNullOrEmpty(check))
  10117. {
  10118. returnSuccessMsg("文件名格式不正确");
  10119. return;
  10120. }
  10121. }
  10122. ce.seller_memo = content;
  10123. ce.Update();
  10124. ceErpMessageTip.isVisit = true;
  10125. ceErpMessageTip.Update();
  10126. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10127. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10128. ApiVo apiVo = new ApiVo();
  10129. apiVo.orderNumber = ce.ctid;
  10130. apiVo.actionName = "demandDesign";
  10131. apiVo.orderRemarks = content;
  10132. apiVo.demandExamine = type + 1;
  10133. designHelper.API_WorkCore(apiVo);//demandDesign
  10134. returnSuccessMsg("修改成功!");
  10135. }
  10136. }
  10137. public static string MidStrEx(string sourse, string startstr, string endstr)
  10138. {
  10139. string result = string.Empty;
  10140. int startindex, endindex;
  10141. try
  10142. {
  10143. startindex = sourse.IndexOf(startstr);
  10144. if (startindex == -1)
  10145. return result;
  10146. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10147. endindex = tmpstr.IndexOf(endstr);
  10148. if (endindex == -1)
  10149. return result;
  10150. result = tmpstr.Remove(endindex);
  10151. }
  10152. catch (Exception ex)
  10153. {
  10154. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10155. }
  10156. return result;
  10157. }
  10158. public void refund_order_list()
  10159. {
  10160. int userid = CurrentUser.UserID;
  10161. int sectionId = CurrentUser.UserPost.OrgID;
  10162. StringBuilder sql = new StringBuilder();
  10163. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10164. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10165. DataStruct dStruct = GetPostStruct();
  10166. DataTable dt = null;
  10167. List<string> ids = new List<string>();
  10168. List<string> tids = new List<string>();
  10169. if (dth.Rows.Count > 0)
  10170. {
  10171. foreach (DataRow dr in dth.Rows)
  10172. {
  10173. tids.Add("'" + dr["tid"].ToString() + "'");
  10174. ids.Add(dr["id"].ToString());
  10175. }
  10176. try
  10177. {
  10178. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10179. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10180. List<string> lw = new List<string>();
  10181. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10182. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10183. dt = WebCache.GetData("view_orderlist", dStruct);
  10184. }
  10185. catch (Exception ex)
  10186. {
  10187. }
  10188. }
  10189. writeGridDataTableJson(dStruct.TotalCount, dt);
  10190. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10191. }
  10192. //新增
  10193. public void order_batch_downloads()
  10194. {
  10195. string ceid = GetPostString("tid");
  10196. String[] tid = ceid.Split(',');
  10197. order_batch_caiyingtong(tid);
  10198. /* (string success, string errors) = UploadFiles(tid);
  10199. returnSuccessMsg(success + errors);*/
  10200. return;
  10201. }
  10202. //报价接口
  10203. public void Get_To_Quote()
  10204. {
  10205. string ceid = GetPostString("ctid");
  10206. if (ceid != null)
  10207. {
  10208. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10209. if (entity != null)
  10210. {
  10211. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10212. {
  10213. return;
  10214. }
  10215. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10216. double price = 0;
  10217. if (cp == null)
  10218. {
  10219. JObject jsonObject12 = new JObject
  10220. {
  10221. { "UserId", "77886" },
  10222. { "Pwd", "lt666888" },
  10223. { "Filename", entity.seller_memo }
  10224. };
  10225. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10226. JObject jsonObjects1 = JObject.Parse(response1);
  10227. string ms1g = (string)jsonObjects1["msg"];
  10228. if (ms1g == "报价成功")
  10229. {
  10230. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10231. string data = (string)jsonObject1["price"];
  10232. 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 + "');";
  10233. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10234. returnSuccessMsg("获取报价成功:" + data);
  10235. price = Convert.ToDouble(data);
  10236. }
  10237. else
  10238. {
  10239. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10240. return;
  10241. }
  10242. }
  10243. String[] beizhu = entity.seller_memo.Split('-');
  10244. String chanp = "";
  10245. if (beizhu.Length > 0)
  10246. {
  10247. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10248. }
  10249. else
  10250. {
  10251. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10252. }
  10253. JObject jsonObject = new JObject
  10254. {
  10255. { "UserId", "77886" },
  10256. { "Pwd", "lt666888" },
  10257. { "Filename", chanp }
  10258. };
  10259. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10260. JObject jsonObjects = JObject.Parse(response);
  10261. string msg = (string)jsonObjects["msg"];
  10262. if (msg == "报价成功")
  10263. {
  10264. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10265. string data = (string)jsonObject1["price"];
  10266. 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 + "');";
  10267. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10268. returnSuccessMsg("获取报价成功:" + data);
  10269. price = Convert.ToDouble(data);
  10270. }
  10271. else
  10272. {
  10273. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10274. return;
  10275. }
  10276. if (price > 0)
  10277. {
  10278. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10279. if (ceErpTradeCellExtend == null)
  10280. {
  10281. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10282. ceErpTradeCellExtend.ctid = entity.ctid;
  10283. ceErpTradeCellExtend.payment_cyt = price;
  10284. ceErpTradeCellExtend.Create();
  10285. }
  10286. else
  10287. {
  10288. ceErpTradeCellExtend.payment_cyt = price;
  10289. ceErpTradeCellExtend.Update();
  10290. }
  10291. }
  10292. return;
  10293. }
  10294. }
  10295. else
  10296. {
  10297. returnErrorMsg("请至少选择一条数据");
  10298. return;
  10299. }
  10300. }
  10301. //新增
  10302. public void order_To_Supplier()
  10303. {
  10304. string ceid = GetPostString("tid");
  10305. String[] tid = ceid.Split(',');
  10306. if (tid.Length > 0)
  10307. {
  10308. try
  10309. {
  10310. for (int i = 0; i < tid.Length; i++)
  10311. {
  10312. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10313. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10314. entity.SupplierId = suid;
  10315. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10316. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10317. entity.Update();
  10318. }
  10319. }
  10320. catch (Exception ex)
  10321. {
  10322. returnErrorMsg("自动匹配供应商失败");
  10323. return;
  10324. }
  10325. }
  10326. else
  10327. {
  10328. returnErrorMsg("请至少选择一条数据");
  10329. return;
  10330. }
  10331. returnSuccessMsg("自动匹配供应商成功");
  10332. return;
  10333. }
  10334. public (string, string) UploadFiles(string[] urls)
  10335. {
  10336. string success = "";
  10337. string errors = "";
  10338. int userid = CurrentUser.UserID;
  10339. foreach (string url in urls)
  10340. {
  10341. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10342. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10343. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10344. {
  10345. JObject jsonObject = new JObject
  10346. {
  10347. { "Userid", "77886" },
  10348. { "pwd", "cyt86435015" },
  10349. { "content", base64FileContent },
  10350. { "ext", Path.GetExtension(fileName) }
  10351. };
  10352. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10353. JObject jsonObjects = JObject.Parse(response);
  10354. string msg = (string)jsonObjects["msg"];
  10355. if (msg.Equals("上传成功"))
  10356. {
  10357. success += url + " 上传成功";
  10358. }
  10359. else
  10360. {
  10361. errors += url + " 上传失败";
  10362. }
  10363. }
  10364. else
  10365. {
  10366. errors += url + " 格式出现问题";
  10367. }
  10368. }
  10369. if (urls.Length == 0)
  10370. {
  10371. return (success, errors);
  10372. }
  10373. return (success, errors);
  10374. }
  10375. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10376. {
  10377. return true; //总是接受
  10378. }
  10379. public static string HttpPost(string url, string param = null)
  10380. {
  10381. HttpWebRequest request;
  10382. //如果是发送HTTPS请求
  10383. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10384. {
  10385. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10386. request = WebRequest.Create(url) as HttpWebRequest;
  10387. request.ProtocolVersion = HttpVersion.Version10;
  10388. }
  10389. else
  10390. {
  10391. request = WebRequest.Create(url) as HttpWebRequest;
  10392. }
  10393. request.Method = "POST";
  10394. request.ContentType = "application/json";
  10395. request.Accept = "*/*";
  10396. request.Timeout = 120000;
  10397. request.AllowAutoRedirect = false;
  10398. StreamWriter requestStream = null;
  10399. WebResponse response = null;
  10400. string responseStr = null;
  10401. try
  10402. {
  10403. requestStream = new StreamWriter(request.GetRequestStream());
  10404. requestStream.Write(param);
  10405. requestStream.Close();
  10406. response = request.GetResponse();
  10407. if (response != null)
  10408. {
  10409. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10410. responseStr = reader.ReadToEnd();
  10411. reader.Close();
  10412. }
  10413. }
  10414. catch (Exception ex)
  10415. {
  10416. return ex.Message;
  10417. }
  10418. finally
  10419. {
  10420. request = null;
  10421. requestStream = null;
  10422. response = null;
  10423. }
  10424. return responseStr;
  10425. }
  10426. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10427. {
  10428. string base64FileContent;
  10429. string fileName;
  10430. using (WebClient webClient = new WebClient())
  10431. {
  10432. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10433. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10434. {
  10435. using (Stream stream = response.GetResponseStream())
  10436. {
  10437. using (MemoryStream memoryStream = new MemoryStream())
  10438. {
  10439. stream.CopyTo(memoryStream);
  10440. byte[] fileBytes = memoryStream.ToArray();
  10441. base64FileContent = Convert.ToBase64String(fileBytes);
  10442. fileName = response.Headers["Content-Disposition"];
  10443. if (!string.IsNullOrEmpty(fileName))
  10444. {
  10445. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10446. if (index >= 0)
  10447. {
  10448. fileName = fileName.Substring(index + 9).Trim('\"');
  10449. }
  10450. }
  10451. else
  10452. {
  10453. fileName = Path.GetFileName(downloadUrl);
  10454. }
  10455. }
  10456. }
  10457. }
  10458. }
  10459. return (fileName, base64FileContent);
  10460. }
  10461. //新增
  10462. public void order_batch_caiyingtong(string[] downloadUrls)
  10463. {
  10464. try
  10465. {
  10466. //遍历文件
  10467. DataStruct dStruct = GetPostStruct();
  10468. DataTable dt = null;
  10469. int userid = CurrentUser.UserID;
  10470. List<string> ids = new List<string>();//失败组
  10471. List<string> tids = new List<string>();
  10472. using (WebClient webClient = new WebClient())
  10473. {
  10474. foreach (var url in downloadUrls)
  10475. {
  10476. try
  10477. {
  10478. tids.Add("'" + url + "'");
  10479. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10480. if (entity != null)
  10481. {
  10482. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10483. if (cp == null)
  10484. {
  10485. JObject jsonObject = new JObject
  10486. {
  10487. { "Userid", "77886" },
  10488. { "pwd", "lt666888" },
  10489. { "Filename",entity.seller_memo }
  10490. };
  10491. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10492. JObject jsonObjects = JObject.Parse(response);
  10493. string msg = (string)jsonObjects["msg"];
  10494. if (msg == "报价成功")
  10495. {
  10496. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10497. DownloadAndConvertToBase64(url1);
  10498. }
  10499. else
  10500. {
  10501. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10502. }
  10503. }
  10504. else
  10505. {
  10506. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10507. JObject jsonObject = new JObject
  10508. {
  10509. { "Userid", "77886" },
  10510. { "pwd", "lt666888" },
  10511. { "Filename",chanp }
  10512. };
  10513. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10514. JObject jsonObjects = JObject.Parse(response);
  10515. string msg = (string)jsonObjects["msg"];
  10516. if (msg == "报价成功")
  10517. {
  10518. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10519. DownloadAndConvertToBase64(url1);
  10520. }
  10521. else
  10522. {
  10523. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10524. }
  10525. }
  10526. }
  10527. // 上传文件到FTP
  10528. }
  10529. catch (Exception ex)
  10530. {
  10531. Console.WriteLine($"An error occurred: {ex.Message}");
  10532. }
  10533. }
  10534. List<string> lw = new List<string>();
  10535. lw.Add(string.Format("( OrderState < 6 )"));
  10536. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10537. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10538. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10539. if (dt.Rows.Count > 0)
  10540. {
  10541. foreach (DataRow dr in dt.Rows)
  10542. {
  10543. ids.Add(dr["ctid"].ToString());
  10544. }
  10545. }
  10546. String ErrorMsgs = "";
  10547. foreach (String id in ids)
  10548. {
  10549. ErrorMsgs += id + ",";
  10550. }
  10551. if (ErrorMsgs.Length > 1)
  10552. {
  10553. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10554. }
  10555. if (ErrorMsgs.Length < 1)
  10556. {
  10557. ErrorMsgs = "上传成功";
  10558. returnSuccessMsg(ErrorMsgs);
  10559. }
  10560. else
  10561. {
  10562. returnErrorMsg("以下订单" + ErrorMsgs);
  10563. }
  10564. }
  10565. // 删除文件夹及其内容
  10566. /* Directory.Delete(localDirectory, true);*/
  10567. }
  10568. catch { }
  10569. }
  10570. public void get_center_data()
  10571. {
  10572. int userId = CurrentUser.UserID;
  10573. string postCode = CurrentUser.UserPost.Post.Code;
  10574. List<string> lw = new List<string>();
  10575. List<string> ww = new List<string>();
  10576. DateTime currentTime = DateTime.Now;
  10577. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10578. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10579. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10580. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10581. string sql = " SELECT ";
  10582. string startTime = "2023-10-01 11:22:31";
  10583. //设计
  10584. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10585. {
  10586. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10587. 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));
  10588. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10589. 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));
  10590. }
  10591. //客服
  10592. else if (postCode == "CustomerService" || postCode == "Director")
  10593. {
  10594. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10595. 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));
  10596. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10597. 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));
  10598. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10599. 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));
  10600. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10601. 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));
  10602. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10603. 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));
  10604. }
  10605. //售后
  10606. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10607. {
  10608. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10609. 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));
  10610. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10611. 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));
  10612. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10613. 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));
  10614. }
  10615. //下单部
  10616. else if (postCode == "Place" || postCode == "PlaceMr")
  10617. {
  10618. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10619. 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));
  10620. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10621. 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));
  10622. }
  10623. //车间
  10624. else if (postCode == "Supplier")
  10625. {
  10626. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10627. 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));
  10628. }
  10629. DataTable dt = new DataTable();
  10630. if (lw.Count > 0)
  10631. {
  10632. sql += string.Join(" , ", lw);
  10633. sql += " FROM ";
  10634. sql += string.Join(" , ", ww);
  10635. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10636. }
  10637. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10638. }
  10639. public void get_center_data_list()
  10640. {
  10641. int userId = CurrentUser.UserID;
  10642. string postCode = CurrentUser.UserPost.Post.Code;
  10643. string shopIds = CurrentUser.User.pemShop;
  10644. DataStruct dStruct = GetPostStruct();
  10645. List<string> lw = new List<string>();
  10646. DateTime currentTime = DateTime.Now;
  10647. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10648. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10649. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10650. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10651. string startTime = "2023-10-01 11:22:31";
  10652. int order_type = GetPostInt("order_type");
  10653. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10654. {
  10655. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10656. if (order_type == 0)
  10657. {
  10658. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10659. }
  10660. else if (order_type == 3)
  10661. {
  10662. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10663. }
  10664. else
  10665. {
  10666. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10667. }
  10668. }
  10669. //客服
  10670. if (postCode == "CustomerService" || postCode == "Director")
  10671. {
  10672. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10673. if (order_type == 0)
  10674. {
  10675. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10676. }
  10677. else if (order_type == 1)
  10678. {
  10679. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10680. }
  10681. else if (order_type == 2)
  10682. {
  10683. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10684. }
  10685. else if (order_type == 3)
  10686. {
  10687. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10688. }
  10689. else if (order_type == 4)
  10690. {
  10691. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10692. }
  10693. else
  10694. {
  10695. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10696. }
  10697. }
  10698. //售后
  10699. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10700. {
  10701. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10702. if (shopIds != "")
  10703. {
  10704. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10705. }
  10706. if (order_type == 2)
  10707. {
  10708. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10709. }
  10710. else if (order_type == 4)
  10711. {
  10712. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10713. }
  10714. else if (order_type == 5)
  10715. {
  10716. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10717. }
  10718. else
  10719. {
  10720. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10721. }
  10722. }
  10723. //下单部
  10724. if (postCode == "Place" || postCode == "PlaceMr")
  10725. {
  10726. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10727. if (shopIds != "")
  10728. {
  10729. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10730. }
  10731. else if (order_type == 1)
  10732. {
  10733. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10734. }
  10735. else if (order_type == 2)
  10736. {
  10737. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10738. }
  10739. else
  10740. {
  10741. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10742. }
  10743. }
  10744. //车间
  10745. if (postCode == "Supplier")
  10746. {
  10747. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10748. if (order_type == 5)
  10749. {
  10750. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10751. }
  10752. else
  10753. {
  10754. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10755. }
  10756. }
  10757. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10758. dStruct.Fileds = "tid,ctid";
  10759. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10760. writeGridDataTableJson(dStruct.TotalCount, dt);
  10761. }
  10762. public void aftersale_audit_master()
  10763. {
  10764. if (UrlPostParmsCheck("ctid"))
  10765. {
  10766. string ctid = GetPostString("ctid");
  10767. if (ctid.Length > 0)
  10768. {
  10769. bool result = aftersale_data_change(ctid);
  10770. if (result)
  10771. {
  10772. returnSuccessMsg("修改成功!");
  10773. return;
  10774. }
  10775. }
  10776. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10777. }
  10778. }
  10779. public void aftersale_batch_audit_master()
  10780. {
  10781. if (UrlPostParmsCheck("ctids"))
  10782. {
  10783. string ctids = GetPostString("ctids");
  10784. if (ctids.Length > 0)
  10785. {
  10786. List<string> list = new List<string>();
  10787. string[] ctid_list = ctids.Split(',');
  10788. foreach (var item in ctid_list)
  10789. {
  10790. bool result = aftersale_data_change(item);
  10791. if (!result)
  10792. {
  10793. list.Add(item);
  10794. }
  10795. }
  10796. if (list.Count > 0)
  10797. {
  10798. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10799. return;
  10800. }
  10801. returnSuccessMsg("修改成功!");
  10802. return;
  10803. }
  10804. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10805. }
  10806. }
  10807. public bool aftersale_data_change(string ctid)
  10808. {
  10809. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10810. if (ceErpTradeCell != null)
  10811. {
  10812. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10813. ceErpTradeCell.AfterSaleSupplierState = 0;
  10814. StringBuilder sql = new StringBuilder();
  10815. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10816. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10817. CeErpTradeResponsible.DelByTid(ctid, 0);
  10818. 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 == "不理赔")
  10819. {
  10820. CeErpTradeResponsible.DelByTid(ctid, 1);
  10821. ceErpTradeCell.AfterSaleSupplierState = 1;
  10822. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10823. ceErpTradeCell.AfterSaleState = 4;
  10824. }
  10825. else
  10826. {
  10827. ceErpTradeCell.AfterSaleState = 3;
  10828. }
  10829. bool needCyt = false;
  10830. if (dt != null)
  10831. {
  10832. if (dt.Rows.Count == 1)
  10833. {
  10834. bool isEnd = false;
  10835. foreach (DataRow dr in dt.Rows)
  10836. {
  10837. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10838. {
  10839. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10840. isEnd = true;
  10841. }
  10842. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10843. {
  10844. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10845. isEnd = true;
  10846. }
  10847. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10848. {
  10849. needCyt = true;
  10850. }
  10851. }
  10852. if (isEnd)
  10853. {
  10854. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10855. ceErpTradeCell.AfterSaleState = 4;
  10856. ceErpTradeCell.AfterSaleSupplierState = 1;
  10857. }
  10858. }
  10859. else
  10860. {
  10861. bool isAll = true;
  10862. foreach (DataRow dr in dt.Rows)
  10863. {
  10864. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10865. {
  10866. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10867. continue;
  10868. }
  10869. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10870. {
  10871. string path = "";
  10872. int OrgID = 0;
  10873. if (!Convert.IsDBNull(dr["OrgPath"]))
  10874. {
  10875. path = dr["OrgPath"].ToString();
  10876. }
  10877. if (!Convert.IsDBNull(dr["OrgID"]))
  10878. {
  10879. OrgID = Convert.ToInt32(dr["OrgID"]);
  10880. }
  10881. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10882. {
  10883. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10884. continue;
  10885. }
  10886. }
  10887. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10888. {
  10889. needCyt = true;
  10890. }
  10891. isAll = false;
  10892. }
  10893. if (isAll)
  10894. {
  10895. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10896. ceErpTradeCell.AfterSaleState = 4;
  10897. ceErpTradeCell.AfterSaleSupplierState = 1;
  10898. }
  10899. }
  10900. }
  10901. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10902. {
  10903. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10904. }
  10905. if (ceErpTradeCell.AfterSaleState == 4)
  10906. {
  10907. ApiVo apiVo = new ApiVo();
  10908. apiVo.orderNumber = ceErpTradeCell.ctid;
  10909. apiVo.actionName = "afterOver";
  10910. designHelper.API_WorkCore(apiVo); //afterOver
  10911. }
  10912. ceErpTradeCell.Update();
  10913. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10914. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10915. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10916. return true;
  10917. }
  10918. return false;
  10919. }
  10920. public void get_erp_wechatorder()
  10921. {
  10922. DataStruct dStruct = GetPostStruct();
  10923. List<string> lw = new List<string>();
  10924. string tid = GetPostString("tid");
  10925. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10926. string shopname = GetPostString("shopname");
  10927. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10928. string buyernick = GetPostString("buyer_nick");
  10929. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10930. string customer = GetPostString("customer");
  10931. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10932. string returndate1 = GetPostString("returndate1");
  10933. string returndate2 = GetPostString("returndate2");
  10934. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10935. if (dw.Length > 0) lw.Add(dw);
  10936. string finishDate1 = GetPostString("finishdate1");
  10937. string finishDate2 = GetPostString("finishdate2");
  10938. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10939. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10940. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10941. dStruct.Order = "created desc";
  10942. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10943. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10944. writeGridDataTableJson(dStruct.TotalCount, dt);
  10945. }
  10946. public void get_erp_wechatlist_sumprice()
  10947. {
  10948. DataStruct dStruct = GetPostStruct();
  10949. List<string> lw = new List<string>();
  10950. string tid = GetPostString("tid");
  10951. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10952. string shopname = GetPostString("shopname");
  10953. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10954. string buyernick = GetPostString("buyer_nick");
  10955. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10956. string customer = GetPostString("customer");
  10957. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10958. string returndate1 = GetPostString("returndate1");
  10959. string returndate2 = GetPostString("returndate2");
  10960. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10961. if (dw.Length > 0) lw.Add(dw);
  10962. string finishDate1 = GetPostString("finishdate1");
  10963. string finishDate2 = GetPostString("finishdate2");
  10964. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10965. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10966. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10967. string mainWhere = string.Join(" and ", lw.ToArray());
  10968. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10969. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10970. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10971. decimal total = 0;
  10972. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10973. {
  10974. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10975. }
  10976. var res = new
  10977. {
  10978. data = total
  10979. };
  10980. string ro_jsond = JsonConvert.SerializeObject(res);
  10981. returnSuccess(ro_jsond);
  10982. return;
  10983. }
  10984. public void get_erp_qr_waitdeliverylist()
  10985. {
  10986. DataStruct dStruct = GetPostStruct();
  10987. List<string> lw = new List<string>();
  10988. string tid = GetPostString("ctid");
  10989. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10990. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10991. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10992. var res_objz = new
  10993. {
  10994. restype = 1,
  10995. data = dt
  10996. };
  10997. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10998. returnSuccess(ro_jsonz);
  10999. }
  11000. public void get_erp_yield_list()
  11001. {
  11002. DataStruct dStruct = GetPostStruct();
  11003. List<string> lw = new List<string>();
  11004. string tid = GetPostString("ctid");
  11005. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11006. string shopname = GetPostString("shopname");
  11007. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11008. string buyernick = GetPostString("buyer_nick");
  11009. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11010. //if (tid.Length == 0 && buyernick.Length == 0)
  11011. //{
  11012. // lw.Add(string.Format("IsRefund<={0}", 1));
  11013. //}
  11014. string customer = GetPostString("customer");
  11015. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11016. string design = GetPostString("design");
  11017. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11018. string orderState = GetPostString("orderState");
  11019. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11020. string address = GetPostString("address");
  11021. 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));
  11022. string sellermemo = GetPostString("seller_memo");
  11023. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11024. string supplier = GetPostString("supplier");
  11025. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11026. string OrderArea = GetPostString("order_area");
  11027. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11028. string placedate1 = GetPostString("placedate1");
  11029. string placedate2 = GetPostString("placedate2");
  11030. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11031. if (fdw.Length > 0) lw.Add(fdw);
  11032. string price1 = GetPostString("price1");
  11033. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11034. string price2 = GetPostString("price2");
  11035. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11036. string unusualCon = GetPostString("unusualcon");
  11037. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11038. string posTag = CurrentUser.UserPost.Post.Code;
  11039. if (posTag == "Supplier")
  11040. {
  11041. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11042. }
  11043. lw.Add(string.Format("OrderState = 6 "));
  11044. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11045. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11046. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11047. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11048. writeGridDataTableJson(dStruct.TotalCount, dt);
  11049. }
  11050. public void change_erp_sup_state()
  11051. {
  11052. if (UrlPostParmsCheck("ctid"))
  11053. {
  11054. string ctid = GetPostString("ctid");
  11055. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11056. if (ceErpTradeCell != null)
  11057. {
  11058. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11059. if (ceErpTradeCellExtend == null)
  11060. {
  11061. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11062. ceErpTradeCellExtend.ctid = ctid;
  11063. ceErpTradeCellExtend.SupState = 1;
  11064. ceErpTradeCellExtend.Create();
  11065. }
  11066. else
  11067. {
  11068. ceErpTradeCellExtend.SupState = 1;
  11069. ceErpTradeCellExtend.Update();
  11070. }
  11071. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11072. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11073. return;
  11074. }
  11075. returnErrorMsg("找不到订单");
  11076. }
  11077. }
  11078. public void supplier_all_downs()
  11079. {
  11080. if (UrlPostParmsCheck("tids"))
  11081. {
  11082. string tids = GetPostString("tids");
  11083. if (tids != null && tids.Length > 0)
  11084. {
  11085. StringBuilder sql = new StringBuilder();
  11086. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11087. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11088. sql = new StringBuilder();
  11089. 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, "下载设计文件");
  11090. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11091. string[] list = tids.Split(',');
  11092. foreach (string ctid in list)
  11093. {
  11094. CeErpSukuraData.createInfo(ctid, 3);
  11095. }
  11096. designHelper.api_approveDesign(tids); //approveDesign
  11097. returnSuccessMsg("下载成功!");
  11098. return;
  11099. }
  11100. returnErrorMsg("下载订单更新失败");
  11101. }
  11102. }
  11103. public void uploaderFileSuccess()
  11104. {
  11105. if (UrlPostParmsCheck("fileName"))
  11106. {
  11107. string fileName = GetPostString("fileName");
  11108. ApiVo apiVo = new ApiVo();
  11109. apiVo.orderNumber = fileName;
  11110. apiVo.actionName = "finishDesign";
  11111. designHelper.API_WorkCore(apiVo);//finishDesign
  11112. returnSuccessMsg("");
  11113. }
  11114. }
  11115. public void get_sample2_order()
  11116. {
  11117. if (UrlPostParmsCheck("ctid"))
  11118. {
  11119. string ctid = GetPostString("ctid");
  11120. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11121. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11122. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11123. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11124. double total = 0.0;
  11125. double order_price = 0.0;
  11126. if (dt_bu.Rows.Count > 0)
  11127. {
  11128. foreach (DataRow dr in dt_bu.Rows)
  11129. {
  11130. total += Convert.ToDouble(dr["payment"]);
  11131. }
  11132. }
  11133. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11134. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11135. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11136. string tid = ctid.Replace("S_", "");
  11137. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11138. double paymant = 0.0;
  11139. if (entity != null)
  11140. {
  11141. paymant = entity.payment;
  11142. }
  11143. string return_reason = "";
  11144. if (dt_after != null && dt_after.Rows.Count > 0)
  11145. {
  11146. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11147. }
  11148. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11149. }
  11150. }
  11151. public void get_erp_design_status()
  11152. {
  11153. string designName = GetPostString("designName");
  11154. DataStruct dStruct = GetPostStruct();
  11155. if (designName.Length > 0)
  11156. {
  11157. 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";
  11158. sql_user += " and Name like '%" + designName + "%'";
  11159. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11160. List<string> ids_list = new List<string>();
  11161. if (user_table.Rows.Count > 0)
  11162. {
  11163. foreach (DataRow item in user_table.Rows)
  11164. {
  11165. ids_list.Add(item["id"].ToString());
  11166. string ids_s = item["TeamIds"].ToString();
  11167. if (ids_s.Length > 0)
  11168. {
  11169. ids_list.AddRange(ids_s.Split(','));
  11170. }
  11171. }
  11172. }
  11173. HashSet<string> set = new HashSet<string>(ids_list);
  11174. ids_list = set.ToList();
  11175. if (ids_list.Count > 0)
  11176. {
  11177. 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));
  11178. dStruct.MainWhere = sql;
  11179. DataTable dt = null;
  11180. dt = WebCache.GetData("view_ErpUser", dStruct);
  11181. writeGridDataTableJson(dStruct.TotalCount, dt);
  11182. }
  11183. }
  11184. }
  11185. public void change_erp_order_price()
  11186. {
  11187. string ctid = GetPostString("ctid");
  11188. double price = GetPostDouble("price");
  11189. if (ctid.Length > 0)
  11190. {
  11191. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11192. if (ceErpTradeCellExtend == null)
  11193. {
  11194. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11195. ceErpTradeCellExtend.ctid = ctid;
  11196. ceErpTradeCellExtend.payment_cyt = price;
  11197. ceErpTradeCellExtend.Create();
  11198. }
  11199. else
  11200. {
  11201. ceErpTradeCellExtend.payment_cyt = price;
  11202. ceErpTradeCellExtend.Update();
  11203. }
  11204. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11205. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11206. {
  11207. ceErpDataSendOrderInfo.isSync = false;
  11208. ceErpDataSendOrderInfo.Update();
  11209. }
  11210. if (ceErpDataSendOrderInfo == null)
  11211. {
  11212. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11213. ceErpDataSendOrderInfo.isSync = false;
  11214. ceErpDataSendOrderInfo.ctid = ctid;
  11215. ceErpDataSendOrderInfo.Create();
  11216. }
  11217. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11218. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11219. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11220. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11221. {
  11222. dataSendOrderBean dataSendOrderBean = null;
  11223. foreach (DataRow item in dth.Rows)
  11224. {
  11225. try
  11226. {
  11227. dataSendOrderBean = new dataSendOrderBean();
  11228. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11229. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11230. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11231. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11232. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11233. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11234. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11235. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11236. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11237. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11238. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11239. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11240. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11241. if (result != null)
  11242. {
  11243. if ("0".Equals(result.errcode))
  11244. {
  11245. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11246. }
  11247. else
  11248. {
  11249. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11250. }
  11251. }
  11252. }
  11253. catch (Exception ex)
  11254. {
  11255. }
  11256. }
  11257. }
  11258. returnSuccessMsg("修改成功!");
  11259. return;
  11260. }
  11261. returnErrorMsg("找不到订单");
  11262. }
  11263. public void find_he_together()
  11264. {
  11265. string ctid = GetPostString("ctid");
  11266. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11267. List<string> list = new List<string>();
  11268. if (ceErpTradeCell != null)
  11269. {
  11270. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11271. {
  11272. 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);
  11273. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11274. if (table != null && table.Rows.Count > 0)
  11275. {
  11276. foreach (TableRow row in table.Rows)
  11277. {
  11278. }
  11279. }
  11280. }
  11281. }
  11282. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11283. }
  11284. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11285. {
  11286. //chy----19
  11287. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11288. //GD-CYT-----64
  11289. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11290. //ZHX----3
  11291. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11292. //JK----97
  11293. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11294. //ZT----70
  11295. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11296. //LHCY-----98
  11297. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11298. //XD-----90
  11299. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11300. //CYCY-----14
  11301. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11302. };
  11303. //其他改名
  11304. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11305. {
  11306. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11307. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11308. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11309. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11310. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11311. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11312. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11313. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11314. };
  11315. //不统计
  11316. List<int> no_suppliers = new List<int>()
  11317. {
  11318. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11319. };
  11320. //配件单
  11321. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11322. {
  11323. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11324. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11325. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11326. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11327. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11328. {"旗杆",new List<string>(){ "班旗" } },
  11329. {"牙签",new List<string>(){ "不干胶" } }
  11330. };
  11331. public void get_place_order_data()
  11332. {
  11333. string date1 = GetPostString("date1");
  11334. string date2 = GetPostString("date2");
  11335. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11336. DateTime start = DateTime.Parse(starttime);
  11337. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11338. DateTime end = DateTime.Parse(endtime);
  11339. if (date1 != null && date1.Length > 0)
  11340. {
  11341. DateTime dateTime = DateTime.Parse(date1);
  11342. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11343. start = DateTime.Parse(starttime);
  11344. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11345. end = DateTime.Parse(endtime);
  11346. }
  11347. if (date2 != null && date2.Length > 0)
  11348. {
  11349. DateTime dateTime = DateTime.Parse(date2);
  11350. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11351. end = DateTime.Parse(endtime);
  11352. }
  11353. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,UnusualTime,FinishPlaceTime,OrderState,FinishDeliveryTime from view_ErpTradeCell where ( ( FinishPlaceTime BETWEEN '{0}' AND '{1}' ) OR ( OrderState = 6 AND UnusualTag = 5 AND IsRefund <= 1 ) ) AND IsSample = 0 and SupplierName is not null ", starttime, endtime);
  11354. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11355. //不干胶-----1,卡片-----29
  11356. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11357. foreach (DataRow row in data.Rows)
  11358. {
  11359. int productId = Convert.ToInt32(row["ProductId"]);
  11360. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11361. if (no_suppliers.Contains(supplierId))
  11362. {
  11363. continue;
  11364. }
  11365. string seller_memo = row["seller_memo"].ToString();
  11366. bool ispj = false;//是否配件单
  11367. bool isfirst = true;//第一个配
  11368. maps.Keys.ForEach(key =>
  11369. {
  11370. //备注包含配件
  11371. if (seller_memo.Contains(key) && isfirst)
  11372. {
  11373. List<string> list = maps[key];
  11374. ispj = true;
  11375. isfirst = false;
  11376. for (int i = 0; i < list.Count; i++)
  11377. {
  11378. if (seller_memo.Contains(list[i]))
  11379. {
  11380. ispj = false;
  11381. break;
  11382. }
  11383. }
  11384. }
  11385. });
  11386. if (ispj)
  11387. {
  11388. continue;
  11389. }
  11390. seller_memo = seller_memo.Replace("UV", "uv");
  11391. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11392. //吊牌归到卡片
  11393. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11394. seller_memo = seller_memo.Replace("卡套", "卡片");
  11395. seller_memo = seller_memo.Replace("封套", "卡片");
  11396. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11397. seller_memo = seller_memo.Replace("腰封", "卡片");
  11398. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11399. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11400. seller_memo = seller_memo.Replace("横幅", "条幅");
  11401. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11402. string map_key = "";
  11403. string type = "";
  11404. if (supplierMap.ContainsKey(supplierId))
  11405. {
  11406. foreach (var kvp in supplierMap[supplierId])
  11407. {
  11408. if (seller_memo.Contains(kvp.Key))
  11409. {
  11410. map_key = kvp.Value;
  11411. type = kvp.Value;
  11412. break;
  11413. }
  11414. }
  11415. }
  11416. if (map_key == "")
  11417. {
  11418. type = "其他";
  11419. map_key = "其他";
  11420. }
  11421. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11422. {
  11423. map_key = suppliers[supplierId];
  11424. }
  11425. if (supplierId == 70)
  11426. {
  11427. supplierId = 70;
  11428. }
  11429. map_key += "_" + row["SupplierName"].ToString();
  11430. Dictionary<string, int> map = null;
  11431. if (other_map.ContainsKey(map_key))
  11432. {
  11433. other_map.TryGetValue(map_key, out map);
  11434. }
  11435. else
  11436. {
  11437. map = new Dictionary<string, int>();
  11438. map.Add("dayDev", 0);//当天出货
  11439. map.Add("dayTotal", 0);//下单总数
  11440. map.Add("payTotal", 0);//500以上
  11441. map.Add("today", 0);//当天出货数量
  11442. map.Add("unusua", 0);//异常数
  11443. other_map.Add(map_key, map);
  11444. other_map.TryGetValue(map_key, out map);
  11445. }
  11446. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11447. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11448. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11449. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11450. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11451. {
  11452. map["dayTotal"]++;
  11453. if (supplierId == 97)
  11454. {
  11455. supplierId = 97;
  11456. }
  11457. }
  11458. if (Convert.ToDecimal(row["payment"]) >= 500)
  11459. {
  11460. map["payTotal"]++;
  11461. }
  11462. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11463. {
  11464. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11465. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11466. {
  11467. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11468. {
  11469. map["today"]++;
  11470. }
  11471. }
  11472. else
  11473. {
  11474. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11475. {
  11476. map["today"]++;
  11477. }
  11478. else
  11479. {
  11480. if (supplierId == 119)
  11481. {
  11482. Debug.WriteLine(row["seller_memo"].ToString());
  11483. }
  11484. }
  11485. }
  11486. }
  11487. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11488. {
  11489. map["unusua"]++;
  11490. }
  11491. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11492. //GD-CYT-----64
  11493. DateTime two = palceTimeStart.AddHours(14);
  11494. DateTime three = palceTimeStart.AddHours(15);
  11495. DateTime four = palceTimeStart.AddHours(16);
  11496. DateTime six = palceTimeStart.AddHours(18);
  11497. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11498. {
  11499. //下午四点前 500-1000
  11500. string count = row["ProductCount"].ToString();
  11501. if (count != null && count.Length > 0)
  11502. {
  11503. int productCount = commonHelper.getPlaceProductCount(count);
  11504. if (productCount >= 500 && productCount <= 1000)
  11505. {
  11506. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11507. {
  11508. map["dayDev"]++;
  11509. }
  11510. }
  11511. }
  11512. }
  11513. //UV
  11514. else if ("uv".Equals(type))
  11515. {
  11516. //ZT----70
  11517. //ZHX----3
  11518. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11519. {
  11520. map["dayDev"]++;
  11521. }
  11522. //JK----97
  11523. //HZX----105
  11524. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11525. {
  11526. map["dayDev"]++;
  11527. }
  11528. }
  11529. //帆布---52|条幅---27
  11530. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11531. {
  11532. //LHCY-----98
  11533. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11534. {
  11535. map["dayDev"]++;
  11536. }
  11537. }
  11538. //条幅
  11539. else if ("条幅".Equals(type))
  11540. {
  11541. //XD-----90
  11542. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11543. {
  11544. map["dayDev"]++;
  11545. }
  11546. }
  11547. //桌布
  11548. else if ("桌布".Equals(type))
  11549. {
  11550. //XD-----90
  11551. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11552. {
  11553. map["dayDev"]++;
  11554. }
  11555. }
  11556. //DL---10
  11557. //AYTW---119
  11558. //FS-CYT-DY ----80
  11559. //JK----97
  11560. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11561. {
  11562. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11563. {
  11564. map["dayDev"]++;
  11565. }
  11566. }
  11567. // QC---121
  11568. else if (supplierId == 121)
  11569. {
  11570. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  11571. {
  11572. map["dayDev"]++;
  11573. }
  11574. }
  11575. }
  11576. DataTable dt = new DataTable();
  11577. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11578. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11579. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11580. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11581. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11582. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11583. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11584. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11585. other_map.Keys.ForEach(key =>
  11586. {
  11587. DataRow dr = dt.NewRow();
  11588. Dictionary<string, int> map = other_map[key];
  11589. string[] key_list = key.Split('_');
  11590. dr[0] = key_list[0];
  11591. dr[1] = key_list[1];
  11592. if (key_list.Length > 2)
  11593. {
  11594. dr[1] += "(" + key_list[2] + ")";
  11595. }
  11596. dr[2] = map["dayTotal"];
  11597. dr[3] = map["payTotal"];
  11598. dr[4] = map["today"];
  11599. dr[5] = map["unusua"];
  11600. dr[6] = map["dayDev"];
  11601. double rate = 0.00;
  11602. if (map["dayDev"] > 0)
  11603. {
  11604. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11605. }
  11606. dr[7] = rate.ToString();
  11607. dt.Rows.Add(dr);
  11608. });
  11609. DataView dv = new DataView(dt);
  11610. dv.Sort = "SupplierName";
  11611. //dv.Sort = "AllOrder desc";
  11612. DataTable dtNew = dv.ToTable();
  11613. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11614. }
  11615. public void check_order_desing_info()
  11616. {
  11617. string ctid = GetPostString("ctid");
  11618. if (!string.IsNullOrEmpty(ctid))
  11619. {
  11620. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11621. if (ceErpTradeCell != null)
  11622. {
  11623. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11624. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11625. return;
  11626. }
  11627. returnErrorMsg("找不到订单");
  11628. return;
  11629. }
  11630. returnErrorMsg("找不到订单");
  11631. }
  11632. public void get_timeout_detail()
  11633. {
  11634. string poscode = CurrentUser.UserPost.Post.Code;
  11635. DataStruct dStruct = GetPostStruct();
  11636. List<string> lw = new List<string>();
  11637. string id = GetPostString("id");
  11638. string pay_date1 = GetPostString("pay_date1");
  11639. string pay_date2 = GetPostString("pay_date2");
  11640. int type = GetPostInt("type");
  11641. if (type == 0)
  11642. {
  11643. if (pay_date1.Length > 0)
  11644. {
  11645. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11646. }
  11647. if (pay_date2.Length > 0)
  11648. {
  11649. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11650. }
  11651. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11652. }
  11653. if (type == 1)
  11654. {
  11655. if (pay_date1.Length > 0)
  11656. {
  11657. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11658. }
  11659. if (pay_date2.Length > 0)
  11660. {
  11661. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11662. }
  11663. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11664. }
  11665. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11666. DataTable dt = null;
  11667. dt = WebCache.GetData("view_orderlist", dStruct);
  11668. writeGridDataTableJson(dStruct.TotalCount, dt);
  11669. }
  11670. public void saveUrgentChargePrice()
  11671. {
  11672. string ctid = GetPostString("ctid");
  11673. if (!string.IsNullOrEmpty(ctid))
  11674. {
  11675. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11676. if (ceErpTradeCell != null)
  11677. {
  11678. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11679. if (prices <= 100)
  11680. {
  11681. returnErrorMsg("此订单金额不足100元,无法加急。");
  11682. return;
  11683. }
  11684. double price = GetPostDouble("price");
  11685. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11686. if (ceErpTradeCellExtend == null)
  11687. {
  11688. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11689. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11690. }
  11691. ceErpTradeCellExtend.urgentCharge = price;
  11692. if (ceErpTradeCellExtend.ID > 0)
  11693. {
  11694. ceErpTradeCellExtend.Update();
  11695. }
  11696. else
  11697. {
  11698. ceErpTradeCellExtend.Save();
  11699. }
  11700. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11701. returnSuccessMsg("修改成功!");
  11702. return;
  11703. }
  11704. returnErrorMsg("找不到订单");
  11705. return;
  11706. }
  11707. returnErrorMsg("找不到订单");
  11708. }
  11709. public void finish_erp_order()
  11710. {
  11711. string ctid = GetPostString("ctid");
  11712. if (!string.IsNullOrEmpty(ctid))
  11713. {
  11714. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11715. {
  11716. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11717. if (ceErpTradeCell != null)
  11718. {
  11719. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11720. ceErpTradeCell.Update();
  11721. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11722. returnSuccessMsg("修改成功!");
  11723. return;
  11724. }
  11725. }
  11726. }
  11727. returnErrorMsg("找不到订单");
  11728. }
  11729. public void get_trade_order_list()
  11730. {
  11731. string tid = GetPostString("tid");
  11732. if (!string.IsNullOrEmpty(tid))
  11733. {
  11734. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11735. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11736. writeGridDataTableJson(data.Rows.Count, data);
  11737. return;
  11738. }
  11739. returnErrorMsg("找不到订单");
  11740. }
  11741. public void save_cell_spu()
  11742. {
  11743. string ctid = GetPostString("ctid");
  11744. string spu_id = GetPostString("spu_id");
  11745. if (!string.IsNullOrEmpty(ctid))
  11746. {
  11747. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11748. if (ceErpTradeCellExtend == null)
  11749. {
  11750. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11751. ceErpTradeCellExtend.ctid = ctid;
  11752. }
  11753. ceErpTradeCellExtend.spu_id = spu_id;
  11754. if (!string.IsNullOrEmpty(spu_id))
  11755. {
  11756. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11757. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  11758. }
  11759. if (ceErpTradeCellExtend.ID == 0)
  11760. {
  11761. ceErpTradeCellExtend.Create();
  11762. }
  11763. else
  11764. {
  11765. ceErpTradeCellExtend.Update();
  11766. }
  11767. returnSuccessMsg("修改成功!");
  11768. return;
  11769. }
  11770. returnErrorMsg("找不到订单");
  11771. }
  11772. public void change_express_info()
  11773. {
  11774. string ctid = GetPostString("ctid");
  11775. string transNo = GetPostString("transNo");
  11776. string transCom = GetPostString("transCom");
  11777. if (!string.IsNullOrEmpty(ctid))
  11778. {
  11779. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11780. if (ceErpTradeCellExtend == null)
  11781. {
  11782. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11783. ceErpTradeCellExtend.ctid = ctid;
  11784. }
  11785. ceErpTradeCellExtend.modExpressNo = transNo;
  11786. ceErpTradeCellExtend.modExpressCom = transCom;
  11787. ceErpTradeCellExtend.readMod = 2;
  11788. if (ceErpTradeCellExtend.ID == 0)
  11789. {
  11790. ceErpTradeCellExtend.Create();
  11791. }
  11792. else
  11793. {
  11794. ceErpTradeCellExtend.Update();
  11795. }
  11796. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11797. returnSuccessMsg("修改成功!");
  11798. return;
  11799. }
  11800. returnErrorMsg("找不到订单");
  11801. }
  11802. public void get_change_express_list()
  11803. {
  11804. DataStruct dStruct = GetPostStruct();
  11805. List<string> lw = new List<string>();
  11806. int st = 2;
  11807. string tid = GetPostString("ctid");
  11808. if (tid.Length > 0)
  11809. {
  11810. string select_tid = getTidByCtid(tid);
  11811. lw.Add(string.Format("tid='{0}'", select_tid));
  11812. }
  11813. string shopname = GetPostString("shopname");
  11814. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11815. string buyernick = GetPostString("buyer_nick");
  11816. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11817. string sellermemo = GetPostString("seller_memo");
  11818. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11819. string supplier = GetPostString("supplier");
  11820. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11821. string customer = GetPostString("customer");
  11822. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11823. string design = GetPostString("design");
  11824. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11825. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11826. string poscode = CurrentUser.UserPost.Post.Code;
  11827. if (poscode != "SysAdmin")
  11828. {
  11829. string shopid = CurrentUser.User.pemShop;
  11830. lw.Add(string.Format("shopId in ({0})", shopid));
  11831. }
  11832. lw.Add("readMod = 2");
  11833. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11834. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11835. writeGridDataTableJson(dStruct.TotalCount, dt);
  11836. }
  11837. public void deal_express_complete()
  11838. {
  11839. string ctid = GetPostString("ctid");
  11840. if (!string.IsNullOrEmpty(ctid))
  11841. {
  11842. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11843. if (ceErpTradeCellExtend == null)
  11844. {
  11845. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11846. ceErpTradeCellExtend.ctid = ctid;
  11847. }
  11848. ceErpTradeCellExtend.readMod = 1;
  11849. if (ceErpTradeCellExtend.ID == 0)
  11850. {
  11851. ceErpTradeCellExtend.Create();
  11852. }
  11853. else
  11854. {
  11855. ceErpTradeCellExtend.Update();
  11856. }
  11857. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11858. returnSuccessMsg("修改成功!");
  11859. return;
  11860. }
  11861. returnErrorMsg("找不到订单");
  11862. }
  11863. public void aftersale_return_visit()
  11864. {
  11865. string ctid = GetPostString("ctid");
  11866. if (!string.IsNullOrEmpty(ctid))
  11867. {
  11868. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11869. if (ceErpTradeCellExtend == null)
  11870. {
  11871. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11872. ceErpTradeCellExtend.ctid = ctid;
  11873. }
  11874. ceErpTradeCellExtend.returnVisit = 1;
  11875. if (ceErpTradeCellExtend.ID == 0)
  11876. {
  11877. ceErpTradeCellExtend.Create();
  11878. }
  11879. else
  11880. {
  11881. ceErpTradeCellExtend.Update();
  11882. }
  11883. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11884. if (ceErpTradeAfterSaleExtend != null)
  11885. {
  11886. ceErpTradeAfterSaleExtend.TextResult = "";
  11887. ceErpTradeAfterSaleExtend.Update();
  11888. }
  11889. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11890. returnSuccessMsg("修改成功!");
  11891. return;
  11892. }
  11893. returnErrorMsg("找不到订单");
  11894. }
  11895. public void orderPlaceInfo()
  11896. {
  11897. string ctids = GetPostString("ctids");
  11898. string[] list = ctids.Split(',');
  11899. foreach (string ctid in list)
  11900. {
  11901. CeErpSukuraData.createInfo(ctid, 3);
  11902. }
  11903. StringBuilder sql = new StringBuilder();
  11904. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11905. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11906. designHelper.api_approveDesign(ctids); //approveDesign
  11907. returnSuccessMsg("");
  11908. }
  11909. public void get_issue_list()
  11910. {
  11911. DataStruct dStruct = GetPostStruct();
  11912. List<string> lw = new List<string>();
  11913. int st = 2;
  11914. string tid = GetPostString("ctid");
  11915. if (tid.Length > 0)
  11916. {
  11917. string select_tid = getTidByCtid(tid);
  11918. lw.Add(string.Format("tid='{0}'", select_tid));
  11919. }
  11920. string shopname = GetPostString("shopname");
  11921. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11922. string buyernick = GetPostString("buyer_nick");
  11923. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11924. string sellermemo = GetPostString("seller_memo");
  11925. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11926. string supplier = GetPostString("supplier");
  11927. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11928. string customer = GetPostString("customer");
  11929. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11930. string design = GetPostString("design");
  11931. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11932. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11933. string poscode = CurrentUser.UserPost.Post.Code;
  11934. if (poscode != "SysAdmin")
  11935. {
  11936. string shopid = CurrentUser.User.pemShop;
  11937. lw.Add(string.Format("shopId in ({0})", shopid));
  11938. }
  11939. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  11940. {
  11941. lw.Add("IssueState = 1");
  11942. }
  11943. lw.Add("IssueState > 0");
  11944. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11945. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11946. writeGridDataTableJson(dStruct.TotalCount, dt);
  11947. }
  11948. public void saveIssueContent()
  11949. {
  11950. string ctid = GetPostString("ctid");
  11951. if (!string.IsNullOrEmpty(ctid))
  11952. {
  11953. string content = GetPostString("content");
  11954. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11955. if (ceErpTradeAfterSaleExtend == null)
  11956. {
  11957. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11958. ceErpTradeAfterSaleExtend.tid = ctid;
  11959. }
  11960. ceErpTradeAfterSaleExtend.IssueContent = content;
  11961. ceErpTradeAfterSaleExtend.IssueState = 1;
  11962. if (ceErpTradeAfterSaleExtend.ID > 0)
  11963. {
  11964. ceErpTradeAfterSaleExtend.Update();
  11965. }
  11966. else
  11967. {
  11968. ceErpTradeAfterSaleExtend.Create();
  11969. }
  11970. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11971. returnSuccessMsg("添加成功!");
  11972. return;
  11973. }
  11974. returnErrorMsg("找不到订单");
  11975. }
  11976. public void dealIssueContent()
  11977. {
  11978. string ctid = GetPostString("ctid");
  11979. if (!string.IsNullOrEmpty(ctid))
  11980. {
  11981. string content = GetPostString("content");
  11982. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11983. if (ceErpTradeAfterSaleExtend != null)
  11984. {
  11985. ceErpTradeAfterSaleExtend.IssueState = 2;
  11986. ceErpTradeAfterSaleExtend.Update();
  11987. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11988. returnSuccessMsg("修改完成!");
  11989. return;
  11990. }
  11991. }
  11992. returnErrorMsg("找不到订单");
  11993. }
  11994. public void set_tid_attachments()
  11995. {
  11996. string tid = GetPostString("tid");
  11997. string atta = GetPostString("atta");
  11998. if (!string.IsNullOrEmpty(tid))
  11999. {
  12000. if (string.IsNullOrEmpty(atta))
  12001. {
  12002. returnErrorMsg("文件地址为空");
  12003. return;
  12004. }
  12005. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12006. if (ceErpTradeCell != null)
  12007. {
  12008. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12009. if (ceErpTrade == null)
  12010. {
  12011. returnErrorMsg("找不到订单");
  12012. return;
  12013. }
  12014. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12015. bool isSend = false;
  12016. if (dt != null && dt.Rows.Count > 0)
  12017. {
  12018. foreach (DataRow row in dt.Rows)
  12019. {
  12020. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12021. {
  12022. isSend = true;
  12023. }
  12024. }
  12025. if (isSend)
  12026. {
  12027. returnErrorMsg("已发货无法修改");
  12028. return;
  12029. }
  12030. ceErpTrade.Attachments = atta;
  12031. ceErpTrade.Update();
  12032. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12033. returnSuccessMsg("上传成功!");
  12034. return;
  12035. }
  12036. }
  12037. }
  12038. returnErrorMsg("找不到订单");
  12039. }
  12040. public void get_tid_attachments()
  12041. {
  12042. string tid = GetPostString("tid");
  12043. if (!string.IsNullOrEmpty(tid))
  12044. {
  12045. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12046. if (ceErpTradeCell != null)
  12047. {
  12048. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12049. if (ceErpTrade == null)
  12050. {
  12051. returnErrorMsg("找不到订单");
  12052. return;
  12053. }
  12054. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12055. return;
  12056. }
  12057. }
  12058. returnErrorMsg("找不到订单");
  12059. }
  12060. public void check_erp_sameorders()
  12061. {
  12062. if (UrlPostParmsCheck("ctid"))
  12063. {
  12064. string eid = GetPostString("ctid");
  12065. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12066. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12067. if (entity != null && ceErpTrade != null)
  12068. {
  12069. if (entity.OrderState > 6)
  12070. {
  12071. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12072. return;
  12073. }
  12074. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12075. List<string> ids = new List<string>();
  12076. if (dt != null && dt.Rows.Count > 1)
  12077. {
  12078. bool needhe = true;
  12079. foreach (DataRow dr in dt.Rows)
  12080. {
  12081. ids.Add("'" + dr["ctid"] + "'");
  12082. /* //备注有合包
  12083. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12084. {
  12085. needhe = true;
  12086. }
  12087. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12088. {
  12089. needhe = true;
  12090. }
  12091. //顺丰快递
  12092. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12093. {
  12094. needhe = true;
  12095. }*/
  12096. }
  12097. if (!needhe)
  12098. {
  12099. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12100. return;
  12101. }
  12102. StringBuilder sql = new StringBuilder();
  12103. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12104. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12105. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12106. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12107. foreach (DataRow dr in dt.Rows)
  12108. {
  12109. dr["dstate"] = 0;
  12110. dr["dnumber"] = 0;
  12111. foreach (DataRow row in dt1.Rows)
  12112. {
  12113. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12114. {
  12115. dr["dstate"] = 2;
  12116. dr["default"] = 1;
  12117. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12118. }
  12119. }
  12120. if (eid.Equals(dr["ctid"].ToString()))
  12121. {
  12122. dr["dstate"] = 1;
  12123. dr["default"] = 1;
  12124. }
  12125. }
  12126. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12127. return;
  12128. }
  12129. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12130. return;
  12131. }
  12132. returnErrorMsg("未找到订单");
  12133. return;
  12134. }
  12135. returnErrorMsg("缺少必要的参数");
  12136. }
  12137. public void get_mark_number()
  12138. {
  12139. string eid = GetPostString("ctid");
  12140. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12141. if (entity != null)
  12142. {
  12143. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12144. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12145. int current = 1;
  12146. if (ceErpDeliverMark == null)
  12147. {
  12148. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12149. List<string> ids = new List<string>();
  12150. if (dt != null && dt.Rows.Count > 1)
  12151. {
  12152. foreach (DataRow dr in dt.Rows)
  12153. {
  12154. ids.Add("'" + dr["ctid"] + "'");
  12155. }
  12156. //查询已有的编号
  12157. StringBuilder sql = new StringBuilder();
  12158. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12159. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12160. if (dt1 == null || dt1.Rows.Count == 0)
  12161. {
  12162. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12163. List<int> list_number = new List<int>();
  12164. foreach (DataRow row in numbers.Rows)
  12165. {
  12166. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12167. }
  12168. //查询空余编号
  12169. for (int i = 0; i < list_number.Count + 2; i++)
  12170. {
  12171. if (!list_number.Contains(current))
  12172. {
  12173. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12174. //防止查询过程中有新数据生成
  12175. if (ceErpDeliverMark1 == null)
  12176. {
  12177. break;
  12178. }
  12179. }
  12180. current++;
  12181. }
  12182. }
  12183. else
  12184. {
  12185. foreach (DataRow row in dt1.Rows)
  12186. {
  12187. current = Convert.ToInt32(row["markNumber"]);
  12188. }
  12189. }
  12190. ceErpDeliverMark = new CeErpDeliverMark();
  12191. ceErpDeliverMark.ctid = eid;
  12192. ceErpDeliverMark.createtime = DateTime.Now;
  12193. if (ceErpTrade != null)
  12194. {
  12195. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12196. }
  12197. ceErpDeliverMark.markNumber = current;
  12198. ceErpDeliverMark.Create();
  12199. }
  12200. }
  12201. else
  12202. {
  12203. current = ceErpDeliverMark.markNumber;
  12204. }
  12205. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12206. return;
  12207. }
  12208. }
  12209. public void aftersaleCytSend()
  12210. {
  12211. string ctid = GetPostString("ctid");
  12212. if (!string.IsNullOrEmpty(ctid))
  12213. {
  12214. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12215. if (ceErpTradeCell != null)
  12216. {
  12217. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12218. }
  12219. returnSuccessMsg("推送成功");
  12220. return;
  12221. }
  12222. returnErrorMsg("缺少必要的参数");
  12223. }
  12224. public void packOrderInfo()
  12225. {
  12226. string ctids = GetPostString("ctids");
  12227. if (!string.IsNullOrEmpty(ctids))
  12228. {
  12229. string[] ctid_list = ctids.Split(',');
  12230. if (ctid_list.Length > 20)
  12231. {
  12232. returnErrorMsg("单次下载次数不能超过20个");
  12233. return;
  12234. }
  12235. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12236. StringBuilder sql = new StringBuilder();
  12237. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12238. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12239. int supplierId = 0;
  12240. StringBuilder insterSql = new StringBuilder();
  12241. for (int i = 0; i < dt.Rows.Count; i++)
  12242. {
  12243. DataRow row = dt.Rows[i];
  12244. if (i == 0)
  12245. {
  12246. supplierId = Convert.ToInt32(row["SupplierId"]);
  12247. }
  12248. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12249. {
  12250. returnErrorMsg("同车间的订单才能一起打包");
  12251. return;
  12252. }
  12253. int orderState = Convert.ToInt32(row["OrderState"]);
  12254. if (orderState != 5)
  12255. {
  12256. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12257. return;
  12258. }
  12259. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12260. }
  12261. CeErpPackData ceErpPackData = new CeErpPackData();
  12262. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  12263. ceErpPackData.supplierId = supplierId;
  12264. ceErpPackData.createtime = DateTime.Now;
  12265. ceErpPackData.createBy = CurrentUser.UserID;
  12266. ceErpPackData.createName = CurrentUser.UserName;
  12267. ceErpPackData.Create();
  12268. if (ceErpPackData.ID > 0)
  12269. {
  12270. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12271. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12272. }
  12273. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12274. returnSuccessMsg("打包成功");
  12275. return;
  12276. }
  12277. returnErrorMsg("缺少必要的参数");
  12278. }
  12279. public void rePackOrderInfo()
  12280. {
  12281. string id = GetPostString("id");
  12282. if (!string.IsNullOrEmpty(id))
  12283. {
  12284. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12285. if (ceErpPackData == null)
  12286. {
  12287. returnSuccessMsg("查无数据");
  12288. return;
  12289. }
  12290. ceErpPackData.upStatus = 0;
  12291. ceErpPackData.message = "";
  12292. ceErpPackData.Update();
  12293. returnSuccessMsg("打包成功");
  12294. return;
  12295. }
  12296. returnErrorMsg("缺少必要的参数");
  12297. }
  12298. public void backPackOrderInfo()
  12299. {
  12300. string id = GetPostString("id");
  12301. if (!string.IsNullOrEmpty(id))
  12302. {
  12303. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12304. if (ceErpPackData == null)
  12305. {
  12306. returnSuccessMsg("查无数据");
  12307. return;
  12308. }
  12309. ceErpPackData.upStatus = 4;
  12310. ceErpPackData.Update();
  12311. List<string> list = new List<string>();
  12312. StringBuilder sql = new StringBuilder();
  12313. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  12314. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12315. for (int i = 0; i < dt.Rows.Count; i++)
  12316. {
  12317. DataRow row = dt.Rows[i];
  12318. list.Add("'" + row["ctid"].ToString() + "'");
  12319. }
  12320. string textCtids = string.Join(",", list);
  12321. 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));
  12322. 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, "无法打包退回"));
  12323. returnSuccessMsg("退回成功");
  12324. return;
  12325. }
  12326. returnErrorMsg("缺少必要的参数");
  12327. }
  12328. public void addPackDownNum()
  12329. {
  12330. string id = GetPostString("id");
  12331. if (!string.IsNullOrEmpty(id))
  12332. {
  12333. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12334. returnSuccessMsg("下载成功");
  12335. return;
  12336. }
  12337. returnErrorMsg("缺少必要的参数");
  12338. }
  12339. public void get_pack_list()
  12340. {
  12341. DataStruct dStruct = GetPostStruct();
  12342. List<string> lw = new List<string>();
  12343. string supplier = GetPostString("supplier");
  12344. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12345. string posTag = CurrentUser.UserPost.Post.Code;
  12346. if (posTag == "Supplier")
  12347. {
  12348. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12349. }
  12350. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12351. dStruct.Order = "createtime desc";
  12352. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12353. writeGridDataTableJson(dStruct.TotalCount, dt);
  12354. }
  12355. public void get_pack_order_list()
  12356. {
  12357. string packId = GetPostString("packId");
  12358. if (string.IsNullOrEmpty(packId))
  12359. {
  12360. returnErrorMsg("缺少必要的参数");
  12361. return;
  12362. }
  12363. StringBuilder sql = new StringBuilder();
  12364. 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);
  12365. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12366. if (dt == null || dt.Rows.Count == 0)
  12367. {
  12368. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12369. return;
  12370. }
  12371. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12372. return;
  12373. }
  12374. public void get_supplier_product_time_list()
  12375. {
  12376. DataStruct dStruct = GetPostStruct();
  12377. List<string> lw = new List<string>();
  12378. string supplier = GetPostString("supplier");
  12379. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12380. string posTag = CurrentUser.UserPost.Post.Code;
  12381. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12382. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12383. writeGridDataTableJson(dStruct.TotalCount, dt);
  12384. }
  12385. public void saveSupplierProductTime()
  12386. {
  12387. string productId = GetPostString("productId");
  12388. if (string.IsNullOrEmpty(productId))
  12389. {
  12390. returnErrorMsg("缺少必要的参数");
  12391. return;
  12392. }
  12393. string productName = GetPostString("productName");
  12394. int supplierId = GetPostInt("supplierId");
  12395. if (supplierId == 0)
  12396. {
  12397. returnErrorMsg("缺少必要的参数");
  12398. return;
  12399. }
  12400. int quantity = GetPostInt("quantity");
  12401. int sendDay = GetPostInt("sendTime");
  12402. string supplierName = GetPostString("supplierName");
  12403. string craft = GetPostString("craft");
  12404. string deadLine = GetPostString("deadLine");
  12405. string dayDeadLine = GetPostString("dayDeadLine");
  12406. try
  12407. {
  12408. int eid = GetPostInt("eid");
  12409. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12410. if (ceErpSupplierProductTime == null)
  12411. {
  12412. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12413. }
  12414. ceErpSupplierProductTime.productId = productId;
  12415. ceErpSupplierProductTime.productName = productName;
  12416. ceErpSupplierProductTime.supplierId = supplierId;
  12417. ceErpSupplierProductTime.supplierName = supplierName;
  12418. ceErpSupplierProductTime.craft = craft;
  12419. ceErpSupplierProductTime.sendDay = sendDay;
  12420. ceErpSupplierProductTime.quantity = quantity;
  12421. if (!string.IsNullOrEmpty(deadLine))
  12422. {
  12423. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12424. }
  12425. if (!string.IsNullOrEmpty(dayDeadLine))
  12426. {
  12427. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12428. }
  12429. if (ceErpSupplierProductTime.ID == 0)
  12430. {
  12431. ceErpSupplierProductTime.Save();
  12432. }
  12433. else
  12434. {
  12435. ceErpSupplierProductTime.Update();
  12436. }
  12437. }
  12438. catch (Exception e)
  12439. {
  12440. }
  12441. returnSuccessMsg("保存成功");
  12442. return;
  12443. }
  12444. public void delSupplierProductTime()
  12445. {
  12446. int eid = GetPostInt("eid");
  12447. if (eid > 0)
  12448. {
  12449. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12450. if (ceErpSupplierProductTime == null)
  12451. {
  12452. returnErrorMsg("查无数据");
  12453. return;
  12454. }
  12455. ceErpSupplierProductTime.Delete();
  12456. returnSuccessMsg("保存成功");
  12457. return;
  12458. }
  12459. returnErrorMsg("缺少必要的参数");
  12460. }
  12461. public void getExpressInfo()
  12462. {
  12463. string ctid = GetPostString("ctid");
  12464. if (!string.IsNullOrEmpty(ctid))
  12465. {
  12466. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12467. if (ceErpTradeCell != null)
  12468. {
  12469. string outSid = ceErpTradeCell.OutSid;
  12470. if (outSid.Length > 0)
  12471. {
  12472. 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);
  12473. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12474. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12475. return;
  12476. }
  12477. }
  12478. returnErrorMsg("查无记录");
  12479. return;
  12480. }
  12481. returnErrorMsg("缺少必要的参数");
  12482. }
  12483. public void getExpressPostData()
  12484. {
  12485. string express = GetPostString("express");
  12486. if (!string.IsNullOrEmpty(express))
  12487. {
  12488. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12489. if (ceErpExpressInfo != null)
  12490. {
  12491. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12492. return;
  12493. }
  12494. }
  12495. returnErrorMsg("缺少必要的参数");
  12496. }
  12497. public void checkSupplierOrder()
  12498. {
  12499. string ctids = GetPostString("ctids");
  12500. if (ctids != null)
  12501. {
  12502. List<string> list = new List<string>();
  12503. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  12504. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12505. for (int i = 0; i < dt.Rows.Count; i++)
  12506. {
  12507. DataRow row = dt.Rows[i];
  12508. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  12509. {
  12510. continue;
  12511. }
  12512. list.Add(row["seller_memo"].ToString());
  12513. }
  12514. if (list.Count > 0)
  12515. {
  12516. 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, "点击下载按钮"));
  12517. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  12518. return;
  12519. }
  12520. }
  12521. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  12522. return;
  12523. }
  12524. public void addPersonId()
  12525. {
  12526. string tid = GetPostString("tid");
  12527. string personId = GetPostString("personId");
  12528. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12529. if (ceErpTrade != null)
  12530. {
  12531. ceErpTrade.receiver_zip = personId;
  12532. ceErpTrade.Update();
  12533. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  12534. returnSuccessMsg("保存成功");
  12535. return;
  12536. }
  12537. returnErrorMsg("缺少必要的参数");
  12538. }
  12539. }
  12540. }