sync.order.cs 610 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191
  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. namespace SiteCore.Handler
  47. {
  48. public partial class sync
  49. {
  50. public void get_erp_orderlist()
  51. {
  52. string poscode = CurrentUser.UserPost.Post.Code;
  53. DataStruct dStruct = GetPostStruct();
  54. //apiHelper.Api_SyncOrderByTime("598825");
  55. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  56. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  57. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  58. //banniuApiHelper.sendLogisticsInfo(null);
  59. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  60. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  61. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2484048723252587257");
  62. //int sid = commonHelper.autoDistributeToSupplier(entity);
  63. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  64. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1744213772000,\"deliveryType\":\"OFFLINE\",\"discountFee\":0.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1744818568000,\"lines\":[{\"mark2\":[],\"num\":1,\"outerId\":\"\",\"payment\":270.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i2/2214103531955/O1CN01DdUiJW1QJRIWIiuyV_!!0-item_pic.jpg\",\"platServiceFee\":0.0,\"price\":30.0,\"refOlId\":\"4295347347682697938\",\"refSkuId\":\"0\",\"refSpuId\":\"795632307774\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":30.0,\"singleFee\":270.0,\"spuOuterId\":\"\",\"standards\":\"\",\"status\":\"NOT_SHIPPED\",\"title\":\"【优惠价】纸质书签定制古风可手写硬卡纸制作来图定做创意卡片打印logo高档异形卡书法古典标签小卡印刷中国风文创设计\",\"totalFee\":270.0,\"totalPrice\":30.0,\"totalSellPrice\":30.0}],\"logisticsOrderNo\":\"\",\"mark2\":[],\"modifyTime\":1744213828000,\"openBuyerId\":\"AAHnRHraABkUZRPgSx30RW3E\",\"openBuyerNick\":\"s**\",\"openSellerNick\":\"福同鑫旗舰店\",\"orderSource\":\"SYNC\",\"orderTime\":1744212346000,\"payTime\":1744213768000,\"payment\":270.0,\"platServiceFee\":0.0,\"posCode\":\"futongxin\",\"posId\":613307,\"postFee\":240.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0},\"receivedPayment\":0.0,\"receiverCity\":\"成都市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"成华区\",\"receiverId\":\"d3709f8bce7faa8f6cc4587ff26feb66$\",\"receiverState\":\"四川省\",\"receiverTown\":\"猛追湾街道\",\"refOid\":\"4295347347682697938\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"40x110mm-1000张-卡片-300克铜板纸-双面印刷覆哑膜直角裁切-summer67821-条条-打孔配流苏\",\"serviceFee\":0.0,\"status\":\"NOT_SHIPPED\",\"totalFee\":270.0,\"totalPrice\":30.0,\"totalSellPrice\":30.0,\"type\":\"SALE\"}}");
  65. //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}}");
  66. List<string> lw = new List<string>();
  67. string tid = GetPostString("ctid");
  68. string date1 = GetPostString("date1");
  69. //12-1 修改
  70. string urgent = GetPostString("urgent");
  71. string back = GetPostString("back");
  72. string offlineSearch = GetPostString("offlineSearch");
  73. int paramsCount = 0;
  74. if (!string.IsNullOrWhiteSpace(urgent))
  75. {
  76. if (urgent.Equals("true"))
  77. {
  78. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  79. }
  80. }
  81. if (!string.IsNullOrWhiteSpace(back))
  82. {
  83. if (back.Equals("true"))
  84. {
  85. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  86. }
  87. }
  88. if (!string.IsNullOrWhiteSpace(offlineSearch))
  89. {
  90. if (offlineSearch.Equals("true"))
  91. {
  92. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  93. }
  94. }
  95. //end
  96. string date2 = GetPostString("date2");
  97. string buyernick = GetPostString("buyer_nick");
  98. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  99. {
  100. if (tid.Length <= 0 && buyernick.Length <= 0)
  101. {
  102. return;
  103. }
  104. }
  105. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  106. {
  107. if (tid.Length > 0)
  108. {
  109. string select_tid = getTidByCtid(tid);
  110. lw.Add(string.Format("tid='{0}'", select_tid));
  111. }
  112. if (buyernick.Length > 0)
  113. {
  114. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  115. }
  116. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  117. if (dw.Length > 0)
  118. {
  119. lw.Add(dw);
  120. }
  121. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  122. {
  123. string usershop = CurrentUser.User.pemShop;
  124. lw.Add(string.Format("ShopId in ({0})", usershop));
  125. }
  126. }
  127. else
  128. {
  129. if (ex_psize == 0)
  130. {
  131. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  132. }
  133. if (PKey != "admin")
  134. {
  135. string usershop = CurrentUser.User.pemShop;
  136. lw.Add(string.Format("ShopId in ({0})", usershop));
  137. paramsCount++;
  138. }
  139. }
  140. string uploaddate1 = GetPostString("uploaddate1");
  141. string uploaddate2 = GetPostString("uploaddate2");
  142. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  143. if (update.Length > 0) lw.Add(update);
  144. string deliverydate1 = GetPostString("deliverydate1");
  145. string deliverydate2 = GetPostString("deliverydate2");
  146. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  147. if (deliverydate.Length > 0)
  148. {
  149. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  150. };
  151. string shopname = GetPostString("shopname");
  152. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  153. string addwechat = GetPostString("addwechat");
  154. if (addwechat.Length > 0)
  155. {
  156. int addWt = Convert.ToInt32(addwechat);
  157. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  158. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  159. }
  160. string customer = GetPostString("customer");
  161. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  162. string design = GetPostString("design");
  163. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  164. string orderState = GetPostString("orderState");
  165. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  166. string address = GetPostString("address");
  167. 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));
  168. string sellermemo = GetPostString("seller_memo");
  169. if (sellermemo.Length > 0)
  170. {
  171. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  172. }
  173. string backReason = GetPostString("backReason");
  174. if (backReason.Length > 0)
  175. {
  176. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  177. }
  178. string apdate1 = GetPostString("apdate1");
  179. string apdate2 = GetPostString("apdate2");
  180. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  181. if (dwap.Length > 0) lw.Add(dwap);
  182. string price1 = GetPostString("price1");
  183. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  184. string price2 = GetPostString("price2");
  185. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  186. string isoldcustomer = GetPostString("isoldcus");
  187. string finishdate1 = GetPostString("finishdate1");
  188. string finishdate2 = GetPostString("finishdate2");
  189. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  190. bool isFinish = false;
  191. if (finishdate.Length > 0)
  192. {
  193. lw.Add(finishdate);
  194. isFinish = true;
  195. paramsCount++;
  196. }
  197. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  198. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  199. if (ex_psize > 0)
  200. {
  201. int UserID = CurrentUser.UserID;
  202. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  203. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  204. {
  205. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  206. }
  207. dStruct.Order = "pay_time desc";
  208. }
  209. string isNew = GetPostString("isNew");
  210. if (isNew == "true")
  211. {
  212. lw.Add(string.Format("IsNew = {0}", 1));
  213. }
  214. string overtime = GetPostString("overtime");
  215. if (overtime == "1")
  216. {
  217. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  218. }
  219. String usePost = CurrentUser.UserPost.Post.Code;
  220. if (usePost.Equals("Operation") == true)
  221. {
  222. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  223. }
  224. else
  225. {
  226. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  227. }
  228. //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";
  229. if (dStruct.PageSize == 100000)
  230. {
  231. dStruct.Order = "";
  232. }
  233. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  234. DataTable dt = null;
  235. string tablename = "view_orderlist";
  236. if (isFinish)
  237. {
  238. tablename = "view_orderlist_end";
  239. }
  240. dt = WebCache.GetData(tablename, dStruct);
  241. if (dt != null && dt.Rows.Count > 0)
  242. {
  243. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  244. foreach (DataRow dr in dt.Rows)
  245. {
  246. try
  247. {
  248. if (dr["refund_fees"] != null)
  249. {
  250. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  251. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  252. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  253. if (payment == refund_fees)
  254. {
  255. dr["refund_fees"] = Math.Round(refund_fees, 2);
  256. }
  257. else if (refund_fees == total_fee)
  258. {
  259. dr["refund_fees"] = payment;
  260. }
  261. else
  262. {
  263. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  264. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  265. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  266. }
  267. }
  268. // 对象操作
  269. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  270. ceErpTradeCell.ctid = dr["ctid"].ToString();
  271. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  272. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  273. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  274. if (dStruct.PageSize != 100000)
  275. {
  276. if (dr["DispatchSort"].ToString() == "2")
  277. {
  278. dr["gongchuang"] = 200;
  279. }
  280. else
  281. {
  282. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  283. dr["gongchuang"] = response.code;
  284. }
  285. }
  286. }
  287. catch (NullReferenceException ex)
  288. {
  289. // 处理空引用异常
  290. dr["refund_fees"] = "0.00";
  291. }
  292. }
  293. }
  294. writeGridDataTableJson(dStruct.TotalCount, dt);
  295. }
  296. public void get_erp_orderlist_sumprice()
  297. {
  298. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  299. return;
  300. List<string> lw = new List<string>();
  301. string tid = GetPostString("ctid");
  302. string date1 = GetPostString("date1");
  303. string date2 = GetPostString("date2");
  304. if (tid.Length > 0 || date1.Length > 0)
  305. {
  306. lw.Add(string.Format("ctid like '%{0}%'", tid));
  307. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  308. if (dw.Length > 0) lw.Add(dw);
  309. }
  310. else
  311. {
  312. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  313. }
  314. string shopname = GetPostString("shopname");
  315. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  316. string buyernick = GetPostString("buyer_nick");
  317. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  318. string customer = GetPostString("customer");
  319. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  320. string design = GetPostString("design");
  321. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  322. string orderState = GetPostString("orderState");
  323. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  324. string address = GetPostString("address");
  325. 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));
  326. string sellermemo = GetPostString("seller_memo");
  327. if (sellermemo.Length > 0)
  328. {
  329. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  330. }
  331. string apdate1 = GetPostString("apdate1");
  332. string apdate2 = GetPostString("apdate2");
  333. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  334. if (dwap.Length > 0) lw.Add(dwap);
  335. string price1 = GetPostString("price1");
  336. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  337. string price2 = GetPostString("price2");
  338. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  339. string isoldcustomer = GetPostString("isoldcus");
  340. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  341. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  342. if (PKey != "admin")
  343. {
  344. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  345. lw.Add(string.Format("shopId in ({0})", usershop));
  346. }
  347. //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";
  348. string mainWhere = string.Join(" and ", lw.ToArray());
  349. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  350. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  351. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  352. decimal total = 0;
  353. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  354. {
  355. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  356. }
  357. var res = new
  358. {
  359. data = total
  360. };
  361. string ro_jsond = JsonConvert.SerializeObject(res);
  362. returnSuccess(ro_jsond);
  363. return;
  364. }
  365. public void get_erp_CustomerServiceGather()
  366. {
  367. string userWhere = "", orderWhere = "";
  368. List<string> lw = new List<string>();
  369. string customer = GetPostString("customer");
  370. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  371. string shopname = GetPostString("shopname");
  372. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  373. string date1 = GetPostString("date1");
  374. string date2 = GetPostString("date2");
  375. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  376. if (dw.Length > 0) lw.Add(dw);
  377. orderWhere = string.Join(" and ", lw.ToArray());
  378. 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 " +
  379. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  380. "left join " +
  381. "( " +
  382. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  383. ") as b on a.ID = b.CustomerUserId " +
  384. "left join " +
  385. "( " +
  386. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  387. ") as d on a.ID = d.CustomerUserId " +
  388. "left join " +
  389. "( " +
  390. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  391. ") as e on a.ID = e.CustomerUserId " +
  392. "left join " +
  393. "( " +
  394. " select CustomerUserId, RefundCount, RefundSum from " +
  395. " ( " +
  396. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  397. " from CE_ErpTradeRefund a " +
  398. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  399. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  400. " group by CustomerUserId " +
  401. " ) as a " +
  402. ") as f on a.ID = f.CustomerUserId " +
  403. "where a.PostCode = 'CustomerService'",
  404. userWhere, orderWhere);
  405. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  406. writeGridDataTableJson(dt.Rows.Count, dt);
  407. //writeGridDataTableJson(dt.Rows.Count, dt);
  408. }
  409. //设计汇总
  410. public void get_erp_DesignerGather()
  411. {
  412. string userWhere = "", orderWhere = "";
  413. List<string> lw = new List<string>();
  414. string Designer = GetPostString("designer");
  415. int org = GetPostInt("org");
  416. if (Designer.Length > 0)
  417. {
  418. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  419. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  420. }
  421. else if (org > 0)
  422. {
  423. userWhere = string.Format(" where OrgID ={0}", org);
  424. }
  425. string shopname = GetPostString("shopname");
  426. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  427. string state = GetPostString("state");
  428. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  429. string OrderArea = GetPostString("order_area");
  430. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  431. string date1 = GetPostString("date1");
  432. string date2 = GetPostString("date2");
  433. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  434. if (dw.Length > 0) lw.Add(dw);
  435. string UpDate1 = GetPostString("UpDate1");
  436. string UpDate2 = GetPostString("UpDate2");
  437. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  438. if (dw.Length > 0) lw.Add(dw);
  439. orderWhere = string.Join(" and ", lw.ToArray());
  440. 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 (" +
  441. "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 " +
  442. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  443. "left join " +
  444. "( " +
  445. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  446. ") as b on a.ID = b.DesignUserId " +
  447. "left join " +
  448. "( " +
  449. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  450. ") as d on a.ID = d.DesignUserId " +
  451. "left join " +
  452. "( " +
  453. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  454. ") as e on a.ID = e.DesignUserId " +
  455. "left join " +
  456. "( " +
  457. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  458. ") as g on a.ID = g.DesignUserId " +
  459. "left join " +
  460. "( " +
  461. " select CustomerUserId, RefundCount, RefundSum from " +
  462. " ( " +
  463. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  464. " from CE_ErpTradeRefund a " +
  465. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  466. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  467. " group by CustomerUserId " +
  468. " ) as a " +
  469. ") as f on a.ID = f.CustomerUserId " +
  470. "where a.PostCode = 'Designer') as z",
  471. userWhere, orderWhere);
  472. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  473. writeGridDataTableJson(dt.Rows.Count, dt);
  474. }
  475. //删除tradecell的订单
  476. public void del_erp_cellorder()
  477. {
  478. if (UrlPostParmsCheck("ctid"))
  479. {
  480. string eid = GetPostString("ctid");
  481. CeErpTradeCell.DelByCtid(eid);
  482. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  483. returnSuccessMsg("删除成功");
  484. }
  485. }
  486. public void clear_erp_refundstate()
  487. {
  488. if (UrlPostParmsCheck("ids"))
  489. {
  490. string eids = GetPostString("ids");
  491. string[] ctidList = eids.Split(',');
  492. foreach (string ctid in ctidList)
  493. {
  494. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  495. if (entity != null)
  496. {
  497. entity.IsRefund = 0;
  498. entity.Update();
  499. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  500. }
  501. else
  502. continue;
  503. }
  504. returnSuccessMsg("操作成功");
  505. return;
  506. }
  507. returnErrorMsg("缺少必要参数");
  508. }
  509. public void set_erp_urgency()
  510. {
  511. if (UrlPostParmsCheck("ctid"))
  512. {
  513. string eid = GetPostString("ctid");
  514. CeErpTradeCell entity = null;
  515. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  516. if (entity != null)
  517. {
  518. string utime = GetPostString("urgencytime");
  519. if (utime.Length > 0)
  520. {
  521. entity.UrgencyTime = Convert.ToDateTime(utime);
  522. }
  523. else
  524. {
  525. returnErrorMsg("请选择加急时间");
  526. return;
  527. }
  528. if (entity.OrderState <= 4)
  529. {
  530. //entity.seller_memo = entity.seller_memo + "-加急";
  531. string smemo = entity.seller_memo;
  532. int kindex = smemo.IndexOf(")");
  533. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  534. if (lastoneStr != "-")
  535. {
  536. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  537. }
  538. string prememo = smemo.Substring(0, kindex + 2);
  539. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  540. int lastkindex = lastmemo.IndexOf("(");
  541. DateTime urgtime = Convert.ToDateTime(utime);
  542. string newlastmemo = "";
  543. if (lastkindex == 0)
  544. {
  545. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  546. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  547. }
  548. else
  549. {
  550. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  551. }
  552. entity.seller_memo = prememo + newlastmemo;
  553. }
  554. entity.IsUrgency = true;
  555. entity.UpdateTime = DateTime.Now;
  556. entity.Update();
  557. ApiVo apiVo = new ApiVo();
  558. apiVo.orderNumber = entity.ctid;
  559. apiVo.actionName = "changeDesign";
  560. apiVo.orderRemarks = entity.seller_memo;
  561. apiVo.remarkSign = 3;
  562. designHelper.API_WorkCore(apiVo); //changeDesign
  563. CeErpSukuraData.createInfo(entity.ctid, 7);
  564. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  565. returnSuccessMsg("设置成功!");
  566. return;
  567. }
  568. returnErrorMsg("找不到记录");
  569. }
  570. }
  571. public void set_erp_reset()
  572. {
  573. if (UrlPostParmsCheck("ctid"))
  574. {
  575. string eid = GetPostString("ctid");
  576. CeErpTradeCell entity = null;
  577. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  578. if (entity != null)
  579. {
  580. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  581. {
  582. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  583. {
  584. returnErrorMsg("财务要求已下单已发货无法重置");
  585. return;
  586. }
  587. }
  588. entity.IsUrgency = false;
  589. entity.seller_memo = "";
  590. entity.OtherMemo = "";
  591. entity.OrderState = 0;
  592. entity.IsReturn = 0;
  593. //entity.IsRefund = 0;
  594. entity.MemoOpt = 0;
  595. entity.AfterSaleState = 0;
  596. entity.AfterSaleResponsible = "";
  597. entity.AfterSaleUserId = 0;
  598. entity.IsNeedBill = 0;
  599. entity.CustomerUserId = 0;
  600. entity.DesignUserId = 0;
  601. entity.SupplierId = 0;
  602. entity.PlaceUserId = 0;
  603. entity.ptid = "";
  604. entity.IsSample = 0;
  605. entity.IsXianHuo = 0;
  606. entity.isDianziOrder = 0;
  607. entity.DispatchSort = 0;
  608. entity.FinishPlaceTime = null;
  609. entity.Update();
  610. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  611. if (trade != null)
  612. {
  613. trade.seller_memo = "";
  614. trade.Update();
  615. }
  616. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  617. returnSuccessMsg("重置成功!");
  618. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  619. if (desginBill != null)
  620. {
  621. desginBill.isDel = 1;
  622. desginBill.Update();
  623. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  624. }
  625. ApiVo apiVo = new ApiVo();
  626. apiVo.orderNumber = entity.ctid;
  627. apiVo.actionName = "resetDesign";
  628. designHelper.API_WorkCore(apiVo);//resetDesign
  629. return;
  630. }
  631. returnErrorMsg("找不到记录");
  632. }
  633. }
  634. public void save_erp_sellermemo()
  635. {
  636. if (UrlPostParmsCheck("ctid"))
  637. {
  638. string ctid = GetPostString("ctid");
  639. CeErpTradeCell entity = null;
  640. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  641. if (entity != null)
  642. {
  643. string memo = GetPostString("seller_memo");
  644. memo = memo.Replace(" ", "");
  645. if (memo.Contains("补差"))
  646. {
  647. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  648. return;
  649. }
  650. if (entity.seller_memo != memo)
  651. {
  652. if (entity.IsSample == 2)
  653. {
  654. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  655. return;
  656. }
  657. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  658. {
  659. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  660. {
  661. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  662. return;
  663. }
  664. }
  665. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  666. }
  667. commonHelper.getCytPrice(entity);
  668. int memoopt = GetPostInt("MemoOpt");
  669. Boolean ismemoopt = false;
  670. if (memoopt > 0)
  671. {
  672. string stropt = "";
  673. if (memoopt == 1)
  674. {
  675. stropt = "“改稿”";
  676. ismemoopt = true;
  677. }
  678. else if (memoopt == 2)
  679. {
  680. stropt = "“定稿”";
  681. }
  682. else if (memoopt == 3)
  683. {
  684. stropt = "“查货”";
  685. CeErpSukuraData.createInfo(entity.ctid, 6);
  686. }
  687. entity.MemoOpt = Convert.ToInt32(memoopt);
  688. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  689. }
  690. if (entity.OrderState < 5)
  691. {
  692. memo = memo.Replace("(", "(");
  693. memo = memo.Replace(")", ")");
  694. }
  695. entity.seller_memo = memo;
  696. entity.UpdateTime = DateTime.Now;
  697. entity.Update();
  698. ApiVo apiVo = new ApiVo();
  699. apiVo.orderNumber = entity.ctid;
  700. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  701. apiVo.orderRemarks = memo;
  702. apiVo.remarkSign = memoopt;
  703. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  704. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  705. returnSuccessMsg("保存成功!");
  706. return;
  707. }
  708. returnErrorMsg("找不到记录");
  709. }
  710. }
  711. public void ins_erp_checkorder()
  712. {
  713. if (UrlPostParmsCheck("ctid"))
  714. {
  715. string ctid = GetPostString("ctid");
  716. CeErpTradeCell entity = null;
  717. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  718. if (entity != null)
  719. {
  720. if (entity.OrderState < 6)
  721. {
  722. returnErrorMsg("下单完成后才可查货");
  723. return;
  724. }
  725. /*if (entity.OrderState > 6)
  726. {
  727. returnErrorMsg("订单已发货");
  728. return;
  729. }*/
  730. if (entity.FinishPlaceTime != null)
  731. {
  732. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  733. {
  734. returnErrorMsg("下单时间不足,无法查货");
  735. return;
  736. }
  737. }
  738. entity.MemoOpt = 3;
  739. entity.CheckOrderTime = DateTime.Now;
  740. entity.UpdateTime = DateTime.Now;
  741. entity.Update();
  742. CeErpSukuraData.createInfo(entity.ctid, 6);
  743. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  744. returnSuccessMsg("操作成功!");
  745. return;
  746. }
  747. returnErrorMsg("找不到记录");
  748. }
  749. }
  750. public void save_erp_othermemo()
  751. {
  752. if (UrlPostParmsCheck("ctid"))
  753. {
  754. string ctid = GetPostString("ctid");
  755. CeErpTradeCell entity = null;
  756. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  757. if (entity != null)
  758. {
  759. entity.OtherMemo = GetPostString("otherMemo");
  760. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  761. {
  762. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  763. StringBuilder sql = new StringBuilder();
  764. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  765. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  766. if (dt != null && dt.Rows.Count > 0)
  767. {
  768. foreach (DataRow dr in dt.Rows)
  769. {
  770. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  771. {
  772. //品类一直
  773. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  774. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  775. if (ceErpSampleCustomer == null)
  776. {
  777. ceErpSampleCustomer = new CeErpSampleCustomer();
  778. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  779. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  780. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  781. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  782. ceErpSampleCustomer.shopId = entity.ShopId;
  783. }
  784. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  785. ceErpSampleCustomer.lastTid = entity.tid;
  786. if (ceErpSampleCustomer.ID > 0)
  787. {
  788. ceErpSampleCustomer.Update();
  789. }
  790. else
  791. {
  792. ceErpSampleCustomer.Create();
  793. }
  794. }
  795. }
  796. }
  797. }
  798. //if (entity.IsOldCustomer == 1)
  799. //{
  800. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  801. //{
  802. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  803. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  804. //}
  805. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  806. //{
  807. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  808. // {
  809. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  810. // {
  811. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  812. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  813. // }
  814. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  815. // {
  816. // entity.OrderState = 2;
  817. // entity.DesignUserId = 0;
  818. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  819. // }
  820. // else
  821. // {
  822. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  823. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  824. // }
  825. // }
  826. //}
  827. //}
  828. entity.Update();
  829. returnSuccessMsg("保存成功!");
  830. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  831. return;
  832. }
  833. returnErrorMsg("找不到记录");
  834. }
  835. }
  836. public void save_erp_customermemo()
  837. {
  838. if (UrlPostParmsCheck("ctid"))
  839. {
  840. string ctid = GetPostString("ctid");
  841. CeErpTradeCell entity = null;
  842. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  843. if (entity != null)
  844. {
  845. entity.CustomerMemo = GetPostString("CustomerMemo");
  846. entity.Update();
  847. ApiVo apiVo = new ApiVo();
  848. apiVo.orderNumber = entity.ctid;
  849. apiVo.actionName = "followRemarks";
  850. apiVo.orderRemarks = entity.CustomerMemo;
  851. designHelper.API_WorkCore(apiVo);//followRemarks
  852. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  853. returnSuccessMsg("保存成功!");
  854. return;
  855. }
  856. returnErrorMsg("找不到记录");
  857. }
  858. }
  859. public void upd_erp_addmemotag()
  860. {
  861. if (UrlPostParmsCheck("ctid"))
  862. {
  863. ;
  864. string eid = GetPostString("ctid");
  865. string sfTagstr = GetPostString("memotag");
  866. CeErpTradeCell entity = null;
  867. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  868. if (entity != null)
  869. {
  870. ApiVo apiVo = new ApiVo();
  871. if (entity.OrderState == 0)
  872. {
  873. returnErrorMsg("请先领单");
  874. return;
  875. }
  876. //撤销顺丰
  877. if (sfTagstr == "撤销顺丰")
  878. {
  879. entity.IsSF = 0;
  880. string reMsg = "";
  881. string oldmemo = entity.seller_memo;
  882. if (entity.OrderState < 5)
  883. {
  884. oldmemo = oldmemo.Replace("顺丰到付", "");
  885. oldmemo = oldmemo.Replace("顺丰寄付", "");
  886. entity.seller_memo = oldmemo;
  887. }
  888. else
  889. {
  890. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  891. {
  892. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  893. }
  894. }
  895. entity.Update();
  896. apiVo.orderNumber = entity.ctid;
  897. apiVo.actionName = "orderRemarks";
  898. apiVo.orderRemarks = entity.seller_memo;
  899. apiVo.isSf = entity.IsSF.ToString();
  900. designHelper.API_WorkCore(apiVo);//orderRemarks
  901. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  902. returnSuccessMsg("撤销成功!" + reMsg);
  903. return;
  904. }
  905. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  906. {
  907. //string oldmemo = entity.seller_memo;
  908. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  909. string sfStr = GetPostString("memotag");
  910. string smemo = entity.seller_memo;
  911. int kindex = smemo.IndexOf(")");
  912. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  913. if (lastoneStr != "-")
  914. {
  915. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  916. }
  917. string prememo = smemo.Substring(0, kindex + 2);
  918. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  919. int lastkindex = lastmemo.IndexOf("(");
  920. string newlastmemo = "";
  921. if (lastkindex == 0)
  922. {
  923. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  924. newlastmemo = "(" + sfStr + "." + useLastmemo;
  925. }
  926. else
  927. {
  928. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  929. }
  930. entity.seller_memo = prememo + newlastmemo;
  931. }
  932. string sfTagMSg = "";
  933. if (sfTagstr == "顺丰寄付")
  934. {
  935. entity.IsSF = 1;
  936. sfTagMSg = "顺丰寄付";
  937. }
  938. else if (sfTagstr == "顺丰到付")
  939. {
  940. entity.IsSF = 2;
  941. sfTagMSg = "顺丰到付";
  942. }
  943. entity.Update();
  944. apiVo = new ApiVo();
  945. apiVo.orderNumber = entity.ctid;
  946. apiVo.actionName = "orderRemarks";
  947. apiVo.orderRemarks = entity.seller_memo;
  948. apiVo.isSf = entity.IsSF.ToString();
  949. designHelper.API_WorkCore(apiVo);//orderRemarks
  950. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  951. returnSuccessMsg("标记成功!");
  952. return;
  953. }
  954. returnErrorMsg("找不到记录");
  955. }
  956. }
  957. public void upd_erp_ordertag()
  958. {
  959. if (UrlPostParmsCheck("ctid"))
  960. {
  961. string eid = GetPostString("ctid");
  962. CeErpTradeCell entity = null;
  963. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  964. if (entity != null)
  965. {
  966. int tag = GetPostInt("wechattag");
  967. //if(tag==4 && entity.IsSample == 2)
  968. //{
  969. // returnErrorMsg("补差价单不能标记微信单");
  970. // return;
  971. //}
  972. entity.wechatTag = tag;
  973. entity.Update();
  974. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  975. if (tag == 1)
  976. {
  977. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  978. if (cash == null)
  979. {
  980. CeErpTrade main = CeErpTrade.Get(entity.tid);
  981. cash = new CeErpReturnCash();
  982. cash.tid = entity.tid;
  983. cash.seller_nick = main.seller_nick;
  984. cash.payment = trade.payment;
  985. cash.buyer_nick = main.buyer_nick;
  986. cash.cashstate = 0;
  987. cash.rtype = "微信返现";
  988. cash.returnprice = 0;
  989. cash.created = DateTime.Now;
  990. cash.con = "订单标记微信单";
  991. cash.img = "";
  992. cash.applyuserid = CurrentUser.UserID;
  993. cash.Create();
  994. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  995. }
  996. else
  997. {
  998. cash.cashstate = 0;
  999. cash.Update();
  1000. }
  1001. CeErpSukuraData.createInfo(entity.ctid, 9);
  1002. }
  1003. else if (tag == 2)
  1004. {
  1005. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1006. if (cash == null)
  1007. {
  1008. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1009. cash = new CeErpReturnCash();
  1010. cash.tid = entity.tid;
  1011. cash.seller_nick = main.seller_nick;
  1012. cash.payment = trade.payment;
  1013. cash.buyer_nick = main.buyer_nick;
  1014. cash.cashstate = 0;
  1015. cash.rtype = "推购返现";
  1016. cash.returnprice = 5;
  1017. cash.created = DateTime.Now;
  1018. cash.con = "订单标记推购单";
  1019. cash.img = "";
  1020. cash.applyuserid = CurrentUser.UserID;
  1021. cash.Create();
  1022. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1023. }
  1024. else
  1025. {
  1026. cash.cashstate = 0;
  1027. cash.Update();
  1028. }
  1029. CeErpSukuraData.createInfo(entity.ctid, 9);
  1030. }
  1031. else if (tag == 3)
  1032. {
  1033. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1034. if (pers == null)
  1035. {
  1036. pers = new CeErpPersuade();
  1037. pers.ctid = entity.ctid;
  1038. pers.pstate = 0;
  1039. pers.created = DateTime.Now;
  1040. pers.applyuserid = CurrentUser.UserID;
  1041. pers.Create();
  1042. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1043. }
  1044. else
  1045. {
  1046. pers.pstate = 0;
  1047. pers.Update();
  1048. }
  1049. }
  1050. else if (tag == 4 || tag == 5)
  1051. {
  1052. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1053. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1054. if (pers == null)
  1055. {
  1056. pers = new CeErpStayGoods();
  1057. pers.t_id = entity.tid;
  1058. pers.status = "待审核";
  1059. pers.audit_type = 0;
  1060. if (tag == 4)
  1061. {
  1062. pers.stay_type = "微信推购";
  1063. }
  1064. else
  1065. {
  1066. pers.stay_type = "旺旺推购";
  1067. }
  1068. if (entity.IsXianHuo == 0)
  1069. {
  1070. pers.product_id = entity.ProductId;
  1071. }
  1072. pers.wangwang = main.buyer_nick;
  1073. pers.shop_name = main.seller_nick;
  1074. pers.creata_time = DateTime.Now;
  1075. pers.create_u_id = CurrentUser.UserID;
  1076. pers.create_u_name = CurrentUser.UserName;
  1077. pers.Create();
  1078. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1079. }
  1080. else
  1081. {
  1082. pers.audit_type = 0;
  1083. pers.Update();
  1084. }
  1085. CeErpSukuraData.createInfo(entity.ctid, 10);
  1086. }
  1087. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1088. returnSuccessMsg("标记成功!");
  1089. return;
  1090. }
  1091. returnErrorMsg("找不到记录");
  1092. }
  1093. }
  1094. public void upd_erp_ordertag_cancel()
  1095. {
  1096. if (UrlPostParmsCheck("ctid"))
  1097. {
  1098. string eid = GetPostString("ctid");
  1099. CeErpTradeCell entity = null;
  1100. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1101. if (entity != null)
  1102. {
  1103. entity.wechatTag = 0;
  1104. entity.Update();
  1105. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1106. if (pers != null)
  1107. {
  1108. pers.status = "取消推购";
  1109. pers.audit_type = 3;
  1110. pers.Update();
  1111. }
  1112. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1113. returnSuccessMsg("标记成功!");
  1114. return;
  1115. }
  1116. returnErrorMsg("找不到记录");
  1117. }
  1118. }
  1119. public void upd_erp_addweichattag()
  1120. {
  1121. if (UrlPostParmsCheck("ctid"))
  1122. {
  1123. ;
  1124. string eid = GetPostString("ctid");
  1125. CeErpTradeCell entity = null;
  1126. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1127. if (entity != null)
  1128. {
  1129. if (entity.IsAddWechat > 0)
  1130. {
  1131. returnErrorMsg("此单已经标记过了");
  1132. return;
  1133. }
  1134. 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);
  1135. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1136. if (dt.Rows.Count > 0)
  1137. {
  1138. entity.IsAddWechat = 2;
  1139. }
  1140. else
  1141. {
  1142. entity.IsAddWechat = 1;
  1143. }
  1144. entity.Update();
  1145. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1146. returnSuccessMsg("标记成功!");
  1147. return;
  1148. }
  1149. returnErrorMsg("找不到记录");
  1150. }
  1151. }
  1152. public void upd_erp_getmyorder()
  1153. {
  1154. if (UrlPostParmsCheck("ctid"))
  1155. {
  1156. ;
  1157. string eid = GetPostString("ctid");
  1158. CeErpTradeCell entity = null;
  1159. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1160. if (entity != null)
  1161. {
  1162. if (entity.ctid.IndexOf("C") != -1)
  1163. {
  1164. StringBuilder sql = new StringBuilder();
  1165. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1166. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1167. if (dt.Rows.Count > 0)
  1168. {
  1169. decimal total = 0;
  1170. foreach (DataRow dr in dt.Rows)
  1171. {
  1172. total += Convert.ToDecimal(dr["payment"]);
  1173. }
  1174. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1175. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1176. {
  1177. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1178. return;
  1179. }
  1180. }
  1181. }
  1182. if (entity.OrderState == -1)
  1183. {
  1184. returnErrorMsg("待审核订单无法领取!");
  1185. return;
  1186. }
  1187. entity.CustomerUserId = CurrentUser.UserID;
  1188. if (entity.OrderState < 2)
  1189. {
  1190. entity.OrderState = 2;
  1191. if (entity.ShopId != 0)
  1192. {
  1193. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1194. }
  1195. }
  1196. entity.UpdateTime = DateTime.Now;
  1197. entity.Update();
  1198. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1199. returnSuccessMsg("领单成功!");
  1200. return;
  1201. }
  1202. returnErrorMsg("找不到记录");
  1203. }
  1204. }
  1205. public void getmyorder_from_init()
  1206. {
  1207. if (UrlPostParmsCheck("ctid"))
  1208. {
  1209. string eid = GetPostString("ctid");
  1210. CeErpTradeCell entity = null;
  1211. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1212. if (entity != null)
  1213. {
  1214. string sellerMemo = GetPostString("sellerMemo");
  1215. if (sellerMemo.Length > 0)
  1216. {
  1217. entity.seller_memo = sellerMemo;
  1218. }
  1219. string oterhMemo = GetPostString("otherMemo");
  1220. if (oterhMemo.Length > 0)
  1221. {
  1222. entity.OtherMemo = oterhMemo;
  1223. }
  1224. int urg = GetPostInt("urgency");
  1225. entity.IsUrgency = (urg == 1 ? true : false);
  1226. int wechat = GetPostInt("wechat");
  1227. int command = GetPostInt("command");
  1228. if (wechat == 1)
  1229. {
  1230. entity.wechatTag = 1;
  1231. }
  1232. if (command == 1)
  1233. {
  1234. entity.wechatTag = 2;
  1235. }
  1236. string pPro = GetPostString("pprofession");
  1237. if (pPro.Length > 0)
  1238. {
  1239. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1240. string spro = GetPostString("profession");
  1241. if (spro.Length > 0)
  1242. {
  1243. entity.ProfessionId = Convert.ToInt32(spro);
  1244. }
  1245. }
  1246. string proId = GetPostString("productId");
  1247. if (proId.Length > 0)
  1248. {
  1249. entity.ProductId = Convert.ToInt32(proId);
  1250. }
  1251. entity.Material = GetPostString("material");
  1252. entity.Craft = GetPostString("craft");
  1253. entity.CustomerUserId = CurrentUser.UserID;
  1254. if (entity.OrderState < 2)
  1255. {
  1256. entity.OrderState = 2;
  1257. if (entity.ShopId != 0)
  1258. {
  1259. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1260. }
  1261. }
  1262. entity.Update();
  1263. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1264. returnSuccessMsg("领单成功!");
  1265. return;
  1266. }
  1267. returnErrorMsg("找不到记录");
  1268. }
  1269. }
  1270. public void upd_erp_setrelationorder()
  1271. {
  1272. if (UrlPostParmsCheck("ctid"))
  1273. {
  1274. ;
  1275. string eid = GetPostString("ctid");
  1276. string ftid = GetPostString("ftid");
  1277. CeErpTradeCell entity = null;
  1278. CeErpTradeCell fentity = null;
  1279. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1280. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1281. if (fentity == null)
  1282. {
  1283. returnErrorMsg("找不到关联的主订单");
  1284. return;
  1285. }
  1286. if (entity != null)
  1287. {
  1288. if (entity.OrderState >= 5)
  1289. {
  1290. returnErrorMsg("本单已经设计完成无法关联");
  1291. return;
  1292. }
  1293. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1294. {
  1295. returnErrorMsg("线下单续审核后才能关联!");
  1296. return;
  1297. }
  1298. entity.ptid = ftid;
  1299. entity.OrderState = fentity.OrderState;
  1300. //entity.status = fentity.status;
  1301. entity.CustomerUserId = fentity.CustomerUserId;
  1302. entity.DesignUserId = fentity.DesignUserId;
  1303. entity.seller_memo = "补差价单:" + ftid;
  1304. entity.IsSample = 2;
  1305. entity.Update();
  1306. ApiVo apiVo = new ApiVo();
  1307. apiVo.orderNumber = ftid;
  1308. apiVo.payment = entity.payment;
  1309. apiVo.actionName = "repairDesign";
  1310. designHelper.API_WorkCore(apiVo);//repairDesign
  1311. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1312. returnSuccessMsg("关联成功!");
  1313. return;
  1314. }
  1315. else
  1316. returnErrorMsg("找不到记录");
  1317. }
  1318. }
  1319. public void download_erp_neworder()
  1320. {
  1321. string seller = GetPostString("seller_nick");
  1322. string tid = GetPostString("tid");
  1323. if (seller.Length <= 0 || tid.Length <= 0)
  1324. {
  1325. returnErrorMsg("数据错误");
  1326. }
  1327. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1328. //{
  1329. // returnErrorMsg("找不到店铺Sessionkey");
  1330. //}
  1331. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1332. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1333. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1334. if (res.IndexOf("refOid") == -1)
  1335. {
  1336. returnErrorMsg("下载订单数据失败");
  1337. return;
  1338. }
  1339. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1340. returnSuccessMsg("下载完成");
  1341. //tmcHelper.createNewOrder(res);
  1342. //CeErpTrade entr = null;
  1343. //entr = CeErpTrade.Get(tid);
  1344. //if (entr != null)
  1345. //{
  1346. // returnSuccess("下载成功");
  1347. // //下载成功之后,Cell表生成对应的订单;
  1348. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1349. //}
  1350. //else
  1351. //{
  1352. // returnErrorMsg("下载失败或者创建订单失败");
  1353. //}
  1354. }
  1355. public void set_erp_atersale()
  1356. {
  1357. if (UrlPostParmsCheck("ctid"))
  1358. {
  1359. string eid = GetPostString("ctid");
  1360. string reason = GetPostString("AfterSaleReason");
  1361. CeErpTradeCell entity = null;
  1362. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1363. if (entity != null)
  1364. {
  1365. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1366. {
  1367. returnErrorMsg("此订单已经在售后");
  1368. return;
  1369. }
  1370. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1371. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1372. entity.AfterSaleTime = DateTime.Now;
  1373. entity.Update();
  1374. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1375. returnSuccessMsg("转售后成功!");
  1376. return;
  1377. }
  1378. returnErrorMsg("找不到记录");
  1379. }
  1380. }
  1381. public void set_erp_withdraw()
  1382. {
  1383. if (UrlPostParmsCheck("ctid"))
  1384. {
  1385. try
  1386. {
  1387. string eid = GetPostString("ctid");//商品id
  1388. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1389. CeWithdraw ceWithdrawSelect = null;
  1390. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1391. if (ceWithdrawSelect != null)
  1392. {
  1393. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1394. {
  1395. ceWithdrawSelect.status = -1;
  1396. ceWithdrawSelect.Update();
  1397. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1398. returnSuccessMsg("重新发起审核成功");
  1399. return;
  1400. }
  1401. else
  1402. {
  1403. returnSuccessMsg("请勿重复申请!");
  1404. return;
  1405. }
  1406. }
  1407. else
  1408. {
  1409. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1410. if (string.IsNullOrEmpty(CustomerUserId))
  1411. {
  1412. CustomerUserId = "-1";
  1413. }
  1414. int Userid = CurrentUser.UserID;//用户id
  1415. CeWithdraw ceWithdraw = new CeWithdraw();
  1416. ceWithdraw.tid = eid;
  1417. ceWithdraw.userid = Userid;
  1418. ceWithdraw.providerid = CustomerUserId;
  1419. ceWithdraw.status = 3;
  1420. ceWithdraw.creationtime = DateTime.Now;
  1421. ceWithdraw.Create();
  1422. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1423. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1424. return;
  1425. }
  1426. }
  1427. catch
  1428. {
  1429. returnErrorMsg("申请撤回订单失败");
  1430. return;
  1431. }
  1432. }
  1433. }
  1434. public void ins_erp_billinfo()
  1435. {
  1436. if (UrlPostParmsCheck("ctid"))
  1437. {
  1438. string eid = GetPostString("ctid");
  1439. CeErpTradeCell entity = null;
  1440. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1441. if (entity != null)
  1442. {
  1443. CeErpBill bill = CeErpBill.GetByTid(eid);
  1444. bool isHave = false;
  1445. if (bill != null)
  1446. {
  1447. isHave = true;
  1448. if (bill.state != 4)
  1449. {
  1450. returnErrorMsg("此单已经申请过发票了");
  1451. return;
  1452. }
  1453. }
  1454. if (entity.IsNeedBill == 0)
  1455. {
  1456. entity.IsNeedBill = 1;
  1457. }
  1458. entity.Update();
  1459. string errjson = "";
  1460. try
  1461. {
  1462. CeErpBill bill_entity = new CeErpBill();
  1463. bill_entity.tid = entity.tid;
  1464. bill_entity.title = GetPostString("title");
  1465. string taxstr = GetPostString("tax");
  1466. taxstr = taxstr.Replace(" ", "");
  1467. bill_entity.tax = taxstr;
  1468. bill_entity.bank = GetPostString("bank");
  1469. string bankacstr = GetPostString("bankac");
  1470. bankacstr = bankacstr.Replace(" ", "");
  1471. bill_entity.bankac = bankacstr;
  1472. bill_entity.address = GetPostString("address");
  1473. bill_entity.phone = GetPostString("phone");
  1474. bill_entity.price = GetPostString("price");
  1475. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1476. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1477. {
  1478. billCount += 1;
  1479. }
  1480. string prebill = "ltb";
  1481. for (int idx = 1; idx <= billCount; idx++)
  1482. {
  1483. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1484. string billoid = prebill + idx + dtstr;
  1485. bill_entity.billOrderId += billoid;
  1486. if (idx < billCount)
  1487. {
  1488. bill_entity.billOrderId += ",";
  1489. }
  1490. }
  1491. bill_entity.productId = GetPostInt("ProductName");
  1492. bill_entity.num = GetPostInt("num");
  1493. bill_entity.unit = GetPostString("unit");
  1494. bill_entity.type = GetPostString("type");
  1495. bill_entity.sendType = GetPostString("SendType");
  1496. bill_entity.email = GetPostString("email");
  1497. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1498. bill_entity.shopName = GetPostString("ShopName");
  1499. bill_entity.applymemo = GetPostString("applyMemo");
  1500. bill_entity.createTime = DateTime.Now;
  1501. bill_entity.state = 0;
  1502. bill_entity.userId = CurrentUser.UserID;
  1503. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1504. bill_entity.Create();
  1505. }
  1506. catch (Exception ex)
  1507. {
  1508. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1509. returnErrorMsg("创建发票出错!");
  1510. return;
  1511. }
  1512. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1513. returnSuccessMsg("发票申请成功!");
  1514. return;
  1515. }
  1516. returnErrorMsg("找不到记录");
  1517. }
  1518. }
  1519. public void ins_erp_neworder()
  1520. {
  1521. if (UrlPostParmsCheck("receiver_name"))
  1522. {
  1523. CeErpTrade entity = new CeErpTrade();
  1524. string plat_form = GetPostString("platform");
  1525. string preStr = "N_";
  1526. if (plat_form == "拼多多")
  1527. {
  1528. preStr = "P_";
  1529. }
  1530. else if (plat_form == "阿里巴巴")
  1531. {
  1532. preStr = "A_";
  1533. }
  1534. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1535. entity.seller_nick = GetPostString("seller_nick");
  1536. entity.buyer_nick = GetPostString("buyer_nick");
  1537. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1538. entity.total_fee = entity.payment;
  1539. entity.pay_time = DateTime.Now;
  1540. entity.status = "NOT_SHIPPED";
  1541. entity.receiver_name = GetPostString("receiver_name");
  1542. entity.receiver_mobile = GetPostString("receiver_mobile");
  1543. entity.receiver_state = GetPostString("receiver_state");
  1544. entity.receiver_city = GetPostString("receiver_city");
  1545. entity.receiver_district = GetPostString("receiver_district");
  1546. entity.receiver_address = GetPostString("receiver_address");
  1547. if (entity.receiver_state == "" || entity.receiver_city == "")
  1548. {
  1549. returnErrorMsg("收件地址不能为空");
  1550. return;
  1551. }
  1552. int shopId = 0;
  1553. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1554. if (nShop != null)
  1555. {
  1556. shopId = nShop.ID;
  1557. }
  1558. if (shopId != 34 && entity.payment == 0)
  1559. {
  1560. returnErrorMsg("公司自用的单金额才能为0");
  1561. return;
  1562. }
  1563. entity.Create();
  1564. CeErpTradeCell entitycell = new CeErpTradeCell();
  1565. entitycell.ctid = entity.tid;
  1566. entitycell.tid = entity.tid;
  1567. entitycell.ShopId = shopId;
  1568. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1569. entitycell.OrderState = 0;
  1570. entitycell.pay_time = entity.pay_time;
  1571. entitycell.IsOffLineOrder = 1;
  1572. entitycell.Create();
  1573. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1574. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1575. return;
  1576. }
  1577. }
  1578. public void ins_erp_neworder2()
  1579. {
  1580. if (UrlPostParmsCheck("receiver_name"))
  1581. {
  1582. //string plat_form = GetPostString("platform");
  1583. string preStr = "X_";
  1584. string memo = GetPostString("memo");
  1585. string productId = GetPostString("productId");
  1586. string primg = GetPostString("proofimg");
  1587. string sellerNick = GetPostString("seller_nick");
  1588. string addFrom = GetPostString("addfrom");
  1589. if (addFrom == "1")
  1590. {
  1591. preStr = "N_";
  1592. }
  1593. int shopId = 0;
  1594. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1595. if (nShop != null)
  1596. {
  1597. shopId = nShop.ID;
  1598. }
  1599. else
  1600. {
  1601. returnErrorMsg("找不到对应店铺");
  1602. return;
  1603. }
  1604. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1605. {
  1606. returnErrorMsg("必须上传付款凭证");
  1607. return;
  1608. }
  1609. CeErpTrade entity = new CeErpTrade();
  1610. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1611. entity.seller_nick = sellerNick;
  1612. entity.buyer_nick = GetPostString("buyer_nick");
  1613. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1614. entity.total_fee = entity.payment;
  1615. entity.pay_time = DateTime.Now;
  1616. entity.status = "NOT_SHIPPED";
  1617. entity.receiver_name = GetPostString("receiver_name");
  1618. entity.receiver_mobile = GetPostString("receiver_mobile");
  1619. entity.receiver_state = GetPostString("receiver_state");
  1620. entity.receiver_city = GetPostString("receiver_city");
  1621. entity.receiver_district = GetPostString("receiver_district");
  1622. entity.receiver_address = GetPostString("receiver_address");
  1623. entity.seller_memo = memo;
  1624. entity.orderFrom = 20;
  1625. entity.orderType = 15;
  1626. if (entity.receiver_state == "" || entity.receiver_city == "")
  1627. {
  1628. returnErrorMsg("收件地址不能为空");
  1629. return;
  1630. }
  1631. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1632. {
  1633. returnErrorMsg("公司自用的单金额才能为0");
  1634. return;
  1635. }
  1636. entity.Create();
  1637. string toWhere = GetPostString("towhere");
  1638. CeErpTradeCell entitycell = new CeErpTradeCell();
  1639. entitycell.ctid = entity.tid;
  1640. //唯一标识
  1641. entitycell.OrderSn = entity.tid;
  1642. string orderSn = dataHelper.getSaleOrderSn();
  1643. if (orderSn != "")
  1644. {
  1645. entitycell.OrderSn = orderSn;
  1646. }
  1647. entitycell.tid = entity.tid;
  1648. //if (preStr == "X_")
  1649. //{
  1650. entitycell.IsOffLineOrder = 1;
  1651. //}
  1652. entitycell.CustomerUserId = CurrentUser.UserID;
  1653. entitycell.PayProofImg = primg;
  1654. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1655. entitycell.ProductId = Convert.ToInt32(productId);
  1656. entitycell.ShopId = shopId;
  1657. entitycell.UpdateTime = DateTime.Now;
  1658. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1659. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1660. {
  1661. entitycell.IsXianHuo = 1;
  1662. }
  1663. entitycell.pay_time = entity.pay_time;
  1664. if (toWhere == "1")
  1665. {
  1666. entitycell.OrderState = 2;
  1667. }
  1668. else
  1669. {
  1670. entitycell.OrderState = 6;
  1671. entitycell.FinishPlaceTime = entitycell.pay_time;
  1672. }
  1673. if (shopId == 94)
  1674. {
  1675. entitycell.OrderState = 4;
  1676. entitycell.WaitDesignTime = entitycell.pay_time;
  1677. entitycell.StartDesignTime = entitycell.pay_time;
  1678. entitycell.DesignUserId = 218;
  1679. }
  1680. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1681. {
  1682. entitycell.OrderState = -1;//修改12-5
  1683. CeWithdraw ceWithdraw = new CeWithdraw();
  1684. ceWithdraw.tid = entity.tid;
  1685. ceWithdraw.providerid = "-1";
  1686. ceWithdraw.status = -1;
  1687. ceWithdraw.creationtime = DateTime.Now;
  1688. ceWithdraw.userid = 1337;
  1689. ceWithdraw.Create();
  1690. }
  1691. entitycell.Create();
  1692. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1693. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1694. {
  1695. addPlaceRegist(entitycell, CurrentUser.UserID);
  1696. }
  1697. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1698. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1699. return;
  1700. }
  1701. }
  1702. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1703. {
  1704. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1705. entity.PlactTime = tradecell.pay_time;
  1706. entity.AddUserId = userid;
  1707. entity.FileName = tradecell.seller_memo;
  1708. entity.Supplier = 24;
  1709. entity.CreateTime = DateTime.Now;
  1710. entity.Did = tradecell.ctid;
  1711. entity.tid = tradecell.tid;
  1712. entity.splitTag = tradecell.SplitTag;
  1713. entity.CurState = "未完成";
  1714. entity.Create();
  1715. }
  1716. public void get_erp_offlinelist()
  1717. {
  1718. DataStruct dStruct = GetPostStruct();
  1719. List<string> lw = new List<string>();
  1720. string tid = GetPostString("ctid");
  1721. string date1 = GetPostString("date1");
  1722. string date2 = GetPostString("date2");
  1723. if (tid.Length > 0 || date1.Length > 0)
  1724. {
  1725. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1726. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1727. if (dw.Length > 0) lw.Add(dw);
  1728. }
  1729. else
  1730. {
  1731. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1732. }
  1733. string shopname = GetPostString("shopname");
  1734. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1735. string buyernick = GetPostString("buyer_nick");
  1736. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1737. string customer = GetPostString("customer");
  1738. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1739. string design = GetPostString("design");
  1740. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1741. string orderState = GetPostString("orderState");
  1742. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1743. string address = GetPostString("address");
  1744. 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));
  1745. string sellermemo = GetPostString("seller_memo");
  1746. if (sellermemo.Length > 0)
  1747. {
  1748. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1749. }
  1750. string price1 = GetPostString("price1");
  1751. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1752. string price2 = GetPostString("price2");
  1753. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1754. //if (PKey != "admin")
  1755. //{
  1756. // string usershop = CurrentUser.User.pemShop;
  1757. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1758. //}
  1759. //if (ex_psize > 0)
  1760. //{
  1761. dStruct.Order = "pay_time desc";
  1762. //}
  1763. //else
  1764. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1765. lw.Add(string.Format("IsOffLineOrder=1"));
  1766. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1767. DataTable dt = null;
  1768. dt = WebCache.GetData("view_erptradecell", dStruct);
  1769. writeGridDataTableJson(dStruct.TotalCount, dt);
  1770. }
  1771. public void get_erp_returncashrecord()
  1772. {
  1773. DataStruct dStruct = GetPostStruct();
  1774. List<string> lw = new List<string>();
  1775. string tid = GetPostString("ctid");
  1776. if (tid.Length > 0)
  1777. {
  1778. lw.Add(string.Format("tid like '%{0}%'", tid));
  1779. dStruct.Order = "id desc";
  1780. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1781. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1782. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1783. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1784. return;
  1785. }
  1786. returnErrorMsg("id数据错误!");
  1787. }
  1788. public void ins_erp_returncashrecord()
  1789. {
  1790. if (UrlPostParmsCheck("tid"))
  1791. {
  1792. string tid = GetPostString("tid");
  1793. string retype = GetPostString("type");
  1794. StringBuilder sql = new StringBuilder();
  1795. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1796. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1797. if (dt.Rows.Count > 0)
  1798. {
  1799. returnErrorMsg("相同返现类型记录已存在");
  1800. return;
  1801. }
  1802. CeErpReturnCash entity = new CeErpReturnCash();
  1803. entity.tid = tid;
  1804. entity.seller_nick = GetPostString("seller_nick");
  1805. string pment = GetPostString("payment");
  1806. if (pment.Length > 0)
  1807. {
  1808. entity.payment = Convert.ToDouble(pment);
  1809. }
  1810. entity.buyer_nick = GetPostString("buyer_nick");
  1811. entity.cashstate = 0;
  1812. entity.rtype = retype;
  1813. string rPrice = GetPostString("returnprice");
  1814. if (rPrice.Length > 0)
  1815. {
  1816. entity.returnprice = Convert.ToDouble(rPrice);
  1817. }
  1818. entity.created = DateTime.Now;
  1819. entity.con = GetPostString("con");
  1820. entity.img = GetPostString("img");
  1821. entity.applyuserid = CurrentUser.UserID;
  1822. entity.Create();
  1823. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1824. returnSuccessMsg("操作成功!");
  1825. return;
  1826. }
  1827. }
  1828. public void set_erp_predelivery()
  1829. {
  1830. if (UrlPostParmsCheck("ctid"))
  1831. {
  1832. string eid = GetPostString("ctid");
  1833. CeErpTradeCell entity = null;
  1834. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1835. if (entity != null)
  1836. {
  1837. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1838. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1839. //{
  1840. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1841. // return;
  1842. //}
  1843. entity.IsPreDelivery = 1;
  1844. entity.Update();
  1845. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1846. returnSuccessMsg("预发货成功!");
  1847. return;
  1848. //string shop = GetPostString("seller_nick");
  1849. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1850. //string comName = GetPostString("comName");
  1851. //string comCode = GetPostString("comCode");
  1852. //string outSid = GetPostString("outSid");//运单号
  1853. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1854. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1855. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1856. //string apires = "";
  1857. //if (deliveryType == "虚拟发货")
  1858. //{
  1859. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1860. //}
  1861. //else
  1862. //{
  1863. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1864. //}
  1865. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1866. ////{
  1867. //if (apires.IndexOf("发货成功") != -1)
  1868. //{
  1869. // if (deliveryType != "虚拟发货")
  1870. // {
  1871. // //还要插入快递信息到 快递信息表
  1872. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1873. // exinfo.tid = eid;
  1874. // exinfo.out_sid = outSid;
  1875. // exinfo.company_code = comCode;
  1876. // exinfo.company_name = comName;
  1877. // exinfo.delivery_memo = deliveryMemo;
  1878. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1879. // exinfo.deliveryType = deliveryType;
  1880. // exinfo.Create();
  1881. // }
  1882. // returnSuccessMsg("发货成功!");
  1883. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1884. //}
  1885. //else
  1886. //{
  1887. // returnErrorMsg("淘宝发货失败!!");
  1888. //}
  1889. //return;
  1890. }
  1891. returnErrorMsg("找不到订单记录");
  1892. }
  1893. }
  1894. public void get_erp_unusuallist()
  1895. {
  1896. DataStruct dStruct = GetPostStruct();
  1897. List<string> lw = new List<string>();
  1898. string tid = GetPostString("ctid");
  1899. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1900. string shopname = GetPostString("shopname");
  1901. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1902. string buyernick = GetPostString("buyer_nick");
  1903. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1904. string ResponsibleMan = GetPostString("responsible");
  1905. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1906. string date1 = GetPostString("date1");
  1907. string date2 = GetPostString("date2");
  1908. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1909. if (dw.Length > 0) lw.Add(dw);
  1910. string price1 = GetPostString("price1");
  1911. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1912. string price2 = GetPostString("price2");
  1913. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1914. string orderState = GetPostString("orderState");
  1915. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  1916. string sellermemo = GetPostString("seller_memo");
  1917. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1918. lw.Add(string.Format("UnusualTag > 0"));
  1919. lw.Add(string.Format("IsRefund<={0}", 1));
  1920. dStruct.Order = "pay_time desc";
  1921. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1922. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  1923. writeGridDataTableJson(dStruct.TotalCount, dt);
  1924. }
  1925. public void set_erp_unusualtonomal()
  1926. {
  1927. if (UrlPostParmsCheck("ctid"))
  1928. {
  1929. string eid = GetPostString("ctid");
  1930. CeErpTradeCell entity = null;
  1931. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1932. if (entity != null)
  1933. {
  1934. entity.UnusualTag = -1;
  1935. entity.Update();
  1936. returnSuccessMsg("忽略成功!");
  1937. return;
  1938. }
  1939. returnErrorMsg("找不到记录");
  1940. }
  1941. }
  1942. public void ins_erp_unusualreason()
  1943. {
  1944. if (UrlPostParmsCheck("ctid"))
  1945. {
  1946. string eid = GetPostString("ctid");
  1947. CeErpTradeCell entity = null;
  1948. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1949. if (entity != null)
  1950. {
  1951. entity.MemoOpt = 4;
  1952. entity.UnusualCon = GetPostString("con");
  1953. entity.Update();
  1954. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1955. if (trade != null)
  1956. {
  1957. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  1958. }
  1959. //查货是否超时
  1960. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1961. if (ceErpTradeCellExtend == null)
  1962. {
  1963. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  1964. ceErpTradeCellExtend.ctid = entity.ctid;
  1965. }
  1966. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  1967. {
  1968. ceErpTradeCellExtend.CheckOut += 1;
  1969. }
  1970. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  1971. if (ceErpTradeCellExtend.ID > 0)
  1972. {
  1973. ceErpTradeCellExtend.Update();
  1974. }
  1975. else
  1976. {
  1977. ceErpTradeCellExtend.Create();
  1978. }
  1979. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  1980. returnSuccessMsg("操作成功!");
  1981. return;
  1982. }
  1983. returnErrorMsg("找不到记录");
  1984. }
  1985. }
  1986. public void upd_erp_sampleorder()
  1987. {
  1988. if (UrlPostParmsCheck("ctid"))
  1989. {
  1990. string eid = GetPostString("ctid");
  1991. string[] eArr = eid.Split(',');
  1992. if (eArr.Length > 1)
  1993. {
  1994. List<string> eLst = new List<string>();
  1995. for (int i = 0; i < eArr.Length; i++)
  1996. {
  1997. eLst.Add("'" + eArr[i] + "'");
  1998. }
  1999. eid = string.Join(",", eLst.ToArray());
  2000. }
  2001. else
  2002. {
  2003. eid = "'" + eid + "'";
  2004. }
  2005. StringBuilder sql = new StringBuilder();
  2006. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2007. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2008. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2009. if (dt.Rows.Count > 0)
  2010. {
  2011. string errmsg = "";
  2012. foreach (DataRow dr in dt.Rows)
  2013. {
  2014. StringBuilder sqlsb = new StringBuilder();
  2015. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2016. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2017. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2018. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2019. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2020. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2021. {
  2022. continue;
  2023. }
  2024. else
  2025. {
  2026. string emsg = commonHelper.KeepChinese(apires);
  2027. errmsg += emsg;
  2028. }
  2029. }
  2030. if (errmsg.Length > 0)
  2031. {
  2032. returnErrorMsg(errmsg);
  2033. return;
  2034. }
  2035. returnSuccessMsg("操作成功");
  2036. return;
  2037. }
  2038. returnErrorMsg("找不到记录");
  2039. }
  2040. }
  2041. public void upd_erp_transcustomer()
  2042. {
  2043. if (UrlPostParmsCheck("ctid"))
  2044. {
  2045. string eid = GetPostString("ctid");
  2046. int userid = GetPostInt("CustomerUserId");
  2047. CeErpTradeCell entity = null;
  2048. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2049. if (entity != null)
  2050. {
  2051. //string[] mlist = entity.seller_memo.Split('-');
  2052. //string sql = "select * from view_erpuser where id=" + userid;
  2053. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2054. //if (dt != null && dt.Rows.Count > 0)
  2055. //{
  2056. // string nmemo = "";
  2057. // for(int i = 0; i < mlist.Length - 1; i++)
  2058. // {
  2059. // nmemo += mlist[i];
  2060. // nmemo += "-";
  2061. // }
  2062. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2063. // entity.seller_memo = nmemo;
  2064. //}
  2065. entity.CustomerUserId = userid;
  2066. entity.Update();
  2067. returnSuccessMsg("操作成功!");
  2068. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2069. return;
  2070. }
  2071. returnErrorMsg("找不到记录");
  2072. }
  2073. }
  2074. public void upd_erp_transdesigner()
  2075. {
  2076. if (UrlPostParmsCheck("ctid"))
  2077. {
  2078. string eids = GetPostString("ctid");
  2079. string[] ctidList = eids.Split(',');
  2080. int userid = GetPostInt("DesignUserId");
  2081. foreach (string ctid in ctidList)
  2082. {
  2083. CeErpTradeCell entity = null;
  2084. CeErpDesignerBill entitys = null;
  2085. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2086. entitys = CeErpDesignerBill.GetByTid(ctid);
  2087. if (entity != null)
  2088. {
  2089. if (entity.OrderState > 4)
  2090. {
  2091. continue;
  2092. }
  2093. //存在退款不能流转
  2094. if (entity.IsRefund > 0)
  2095. {
  2096. continue;
  2097. }
  2098. entity.DesignUserId = userid;
  2099. entity.WaitDesignTime = DateTime.Now;
  2100. entity.Update();
  2101. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2102. }
  2103. }
  2104. returnSuccessMsg("操作成功!");
  2105. }
  2106. }
  2107. public void upd_erp_distributedesigner()
  2108. {
  2109. if (UrlPostParmsCheck("ctid"))
  2110. {
  2111. string eid = GetPostString("ctid");
  2112. int userid = GetPostInt("DesignUserId");
  2113. string[] idlist = eid.Split(',');
  2114. if (idlist.Length <= 0)
  2115. {
  2116. returnErrorMsg("订单不能为空");
  2117. return;
  2118. }
  2119. foreach (string ctid in idlist)
  2120. {
  2121. CeErpTradeCell entity = null;
  2122. CeErpDesignerBill entitys = null;
  2123. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2124. else continue;
  2125. if (entity != null)
  2126. {
  2127. if (userid == 2125 || userid == 3542)
  2128. { }
  2129. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2130. {
  2131. returnErrorMsg("金额错误的订单无法指派");
  2132. return;
  2133. }
  2134. if (entity.OrderState >= 5)
  2135. {
  2136. returnErrorMsg("已经设计完成无法指派");
  2137. return;
  2138. }
  2139. if (entity.OrderState == -1)
  2140. {
  2141. returnErrorMsg("审核中的订单无法指派");
  2142. return;
  2143. }
  2144. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2145. {
  2146. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2147. return;
  2148. }
  2149. //157赖橙帆 159林晨
  2150. 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)
  2151. {
  2152. returnErrorMsg("指派设计共创无法再次指派!");
  2153. return;
  2154. }
  2155. entity.OrderState = 3;
  2156. CeErpUserPost userEntity = CeErpUserPost.GetByUserID(userid);
  2157. if (entity.ctid.IndexOf("S_") == -1 && userEntity.OrgID == 10)
  2158. {
  2159. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2160. entity.SupplierId = suid;
  2161. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2162. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2163. }
  2164. if (userid == 2125 && entity.seller_memo != "")
  2165. {
  2166. apiDesign.API_GetPrintData_CreateOrder(entity);
  2167. }
  2168. if (userid == 3542 && entity.seller_memo != "")
  2169. {
  2170. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, CurrentUser.UserPost.Post.Code);
  2171. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2172. if (response.msg != "设计共创:成功")
  2173. {
  2174. returnErrorMsg(response.msg);
  2175. return;
  2176. }
  2177. entity.DispatchSort = 2;
  2178. }
  2179. else
  2180. {
  2181. if (entity.DispatchSort == 2)
  2182. {
  2183. ApiVo apiVo = new ApiVo();
  2184. apiVo.actionName = "closeDesign";
  2185. apiVo.orderNumber = entity.ctid;
  2186. designHelper.API_WorkCore(apiVo);//closeDesign
  2187. }
  2188. entity.DispatchSort = 0;
  2189. }
  2190. entity.DesignUserId = userid;
  2191. entity.WaitDesignTime = DateTime.Now;
  2192. entity.UpdateTime = DateTime.Now;
  2193. entity.Update();
  2194. string name = commonHelper.getUserNameById(userid);
  2195. commonHelper.UpdateRelationOrder(entity.ctid);
  2196. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2197. }
  2198. }
  2199. returnSuccessMsg("操作成功!");
  2200. return;
  2201. }
  2202. }
  2203. public string getTidByCtid(string ctid)
  2204. {
  2205. string tid = "";
  2206. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2207. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2208. if (dataTable != null && dataTable.Rows.Count > 0)
  2209. {
  2210. tid = dataTable.Rows[0]["tid"].ToString();
  2211. }
  2212. return tid;
  2213. }
  2214. public List<string> getTidByCtidLike(string ctid)
  2215. {
  2216. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2217. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2218. List<string> list = new List<string>();
  2219. if (dataTable != null && dataTable.Rows.Count > 0)
  2220. {
  2221. foreach (DataRow item in dataTable.Rows)
  2222. {
  2223. list.Add("'" + item["tid"].ToString() + "'");
  2224. }
  2225. }
  2226. return list;
  2227. }
  2228. public void get_erp_myorderlist()
  2229. {
  2230. DataStruct dStruct = GetPostStruct();
  2231. List<string> lw = new List<string>();
  2232. string tid = GetPostString("ctid");
  2233. if (tid.Length > 0)
  2234. {
  2235. string select_tid = getTidByCtid(tid);
  2236. lw.Add(string.Format("tid='{0}'", select_tid));
  2237. }
  2238. else
  2239. {
  2240. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2241. }
  2242. //12-1 修改
  2243. string urgent = GetPostString("urgent");
  2244. string back = GetPostString("back");
  2245. string offlineSearch = GetPostString("offlineSearch");
  2246. if (!string.IsNullOrWhiteSpace(urgent))
  2247. {
  2248. if (urgent.Equals("true"))
  2249. {
  2250. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2251. }
  2252. }
  2253. if (!string.IsNullOrWhiteSpace(back))
  2254. {
  2255. if (back.Equals("true"))
  2256. {
  2257. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2258. }
  2259. }
  2260. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2261. {
  2262. if (offlineSearch.Equals("true"))
  2263. {
  2264. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2265. }
  2266. }
  2267. //end
  2268. string shopname = GetPostString("shopname");
  2269. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2270. string buyernick = GetPostString("buyer_nick");
  2271. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2272. string design = GetPostString("design");
  2273. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2274. string orderState = GetPostString("orderState");
  2275. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2276. string sellermemo = GetPostString("seller_memo");
  2277. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2278. string date1 = GetPostString("date1");
  2279. string date2 = GetPostString("date2");
  2280. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2281. if (dw.Length > 0) lw.Add(dw);
  2282. string price1 = GetPostString("price1");
  2283. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2284. string price2 = GetPostString("price2");
  2285. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2286. string urgency = GetPostString("urgency");
  2287. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2288. string after = GetPostString("after");
  2289. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2290. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2291. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2292. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2293. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2294. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2295. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2296. if (dt != null && dt.Rows.Count > 0)
  2297. {
  2298. foreach (DataRow dr in dt.Rows)
  2299. {
  2300. try
  2301. {
  2302. // 对象操作
  2303. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2304. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2305. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2306. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2307. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2308. if (dStruct.PageSize != 100000)
  2309. {
  2310. if (dr["DispatchSort"].ToString() == "2")
  2311. {
  2312. dr["gongchuang"] = 200;
  2313. }
  2314. else
  2315. {
  2316. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  2317. dr["gongchuang"] = response.code;
  2318. }
  2319. }
  2320. }
  2321. catch (NullReferenceException ex)
  2322. {
  2323. }
  2324. }
  2325. }
  2326. writeGridDataTableJson(dStruct.TotalCount, dt);
  2327. }
  2328. public void get_erp_myreturnorderlist()
  2329. {
  2330. DataStruct dStruct = GetPostStruct();
  2331. List<string> lw = new List<string>();
  2332. string tid = GetPostString("ctid");
  2333. if (tid.Length > 0)
  2334. {
  2335. string select_tid = getTidByCtid(tid);
  2336. lw.Add(string.Format("tid='{0}'", select_tid));
  2337. }
  2338. else
  2339. {
  2340. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2341. }
  2342. string shopname = GetPostString("shopname");
  2343. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2344. string buyernick = GetPostString("buyer_nick");
  2345. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2346. string design = GetPostString("design");
  2347. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2348. string orderState = GetPostString("orderState");
  2349. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2350. string sellermemo = GetPostString("seller_memo");
  2351. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2352. string date1 = GetPostString("date1");
  2353. string date2 = GetPostString("date2");
  2354. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2355. if (dw.Length > 0) lw.Add(dw);
  2356. string price1 = GetPostString("price1");
  2357. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2358. string price2 = GetPostString("price2");
  2359. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2360. if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2361. {
  2362. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2363. }
  2364. else
  2365. {
  2366. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2367. }
  2368. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2369. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2370. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2371. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2372. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2373. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2374. if (dt != null && dt.Rows.Count > 0)
  2375. {
  2376. foreach (DataRow dr in dt.Rows)
  2377. {
  2378. try
  2379. {
  2380. // 对象操作
  2381. if (dStruct.PageSize != 100000)
  2382. {
  2383. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  2384. dr["gongchuang"] = response.code;
  2385. }
  2386. }
  2387. catch (NullReferenceException ex)
  2388. {
  2389. // 处理空引用异常
  2390. }
  2391. }
  2392. }
  2393. writeGridDataTableJson(dStruct.TotalCount, dt);
  2394. }
  2395. public void get_erp_myorderlist_pregather()
  2396. {
  2397. string date1 = GetPostString("date1");
  2398. string date2 = GetPostString("date2");
  2399. int userId = CurrentUser.UserID; //客服id
  2400. string orderWhere = "";
  2401. List<string> lw = new List<string>();
  2402. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2403. if (dw.Length > 0) lw.Add(dw);
  2404. lw.Add(string.Format("CustomerUserId={0}", userId));
  2405. lw.Add(string.Format("OrderState<9"));
  2406. orderWhere = string.Join(" and ", lw.ToArray());
  2407. string orderWhere2 = "";
  2408. List<string> lw2 = new List<string>();
  2409. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2410. if (dw2.Length > 0) lw2.Add(dw2);
  2411. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2412. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2413. string sql = string.Format("select *" +
  2414. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2415. "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 " +
  2416. "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 " +
  2417. "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");
  2418. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2419. //writeGridDataTableJson(dt.Rows.Count, dt);
  2420. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2421. }
  2422. public void upd_erp_publishorder()
  2423. {
  2424. if (UrlPostParmsCheck("ctid"))
  2425. {
  2426. string eid = GetPostString("ctid");
  2427. CeErpTradeCell entity = null;
  2428. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2429. if (entity != null)
  2430. {
  2431. entity.OrderState = 0; //发布后,变为待抢单
  2432. entity.Update();
  2433. commonHelper.UpdateRelationOrder(entity.ctid);
  2434. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2435. returnSuccessMsg("发布成功!");
  2436. return;
  2437. }
  2438. returnErrorMsg("找不到记录");
  2439. }
  2440. }
  2441. public void get_erp_my_tiporder()
  2442. {
  2443. StringBuilder sql = new StringBuilder();
  2444. int userId = 0;
  2445. if (CurrentUser != null) userId = CurrentUser.UserID;
  2446. string posCode = CurrentUser.UserPost.Post.Code;
  2447. string isTipedAfterSaleVerify = GetPostString("af");
  2448. DataTable dt = new DataTable();
  2449. if (posCode != "Supplier")
  2450. {
  2451. if (posCode == "CustomerService" || posCode == "Director")
  2452. {
  2453. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2454. }
  2455. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2456. {
  2457. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2458. }
  2459. else
  2460. {
  2461. string teamIds = CurrentUser.User.TeamIds;
  2462. if (teamIds == "")
  2463. {
  2464. teamIds = "0";
  2465. }
  2466. 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);
  2467. }
  2468. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2469. }
  2470. if (dt.Rows.Count <= 0)
  2471. {
  2472. string key = "aftersale_order_" + userId;
  2473. if (RedisHelper.HasKey(key))
  2474. {
  2475. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2476. dt.Columns.Add("ctid", typeof(string));
  2477. dt.Columns.Add("IsReadTag", typeof(int));
  2478. foreach (var i in list)
  2479. {
  2480. DataRow data = dt.NewRow();
  2481. data["ctid"] = i;
  2482. data["IsReadTag"] = 4;
  2483. dt.Rows.Add(data);
  2484. }
  2485. RedisHelper.StringDelete(key);
  2486. }
  2487. }
  2488. if (dt.Rows.Count <= 0)
  2489. {
  2490. sql = new StringBuilder();
  2491. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2492. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2493. }
  2494. if (posCode == "Supplier")
  2495. {
  2496. string ids = CurrentUser.User.pemVend;
  2497. if (ids != null && ids.Length > 0)
  2498. {
  2499. string[] ids_list = ids.Split(',');
  2500. foreach (var item in ids_list)
  2501. {
  2502. string key = "return_order_" + item;
  2503. if (RedisHelper.HasKey(key))
  2504. {
  2505. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2506. dt.Columns.Add("ctid", typeof(string));
  2507. dt.Columns.Add("IsReadTag", typeof(int));
  2508. foreach (var i in list)
  2509. {
  2510. DataRow data = dt.NewRow();
  2511. data["ctid"] = i;
  2512. data["IsReadTag"] = 1;
  2513. dt.Rows.Add(data);
  2514. }
  2515. RedisHelper.StringDelete(key);
  2516. }
  2517. }
  2518. }
  2519. if (dt.Rows.Count <= 0)
  2520. {
  2521. sql = new StringBuilder();
  2522. 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);
  2523. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2524. }
  2525. }
  2526. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2527. }
  2528. public void reset_erp_tiporder()
  2529. {
  2530. string ids = GetPostString("ids");
  2531. string[] ctidList = ids.Split(',');
  2532. foreach (string ctid in ctidList)
  2533. {
  2534. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2535. if (enty != null)
  2536. {
  2537. enty.IsReadTag = 0;
  2538. enty.Update();
  2539. }
  2540. }
  2541. returnSuccessMsg("成功!");
  2542. return;
  2543. }
  2544. public void get_erp_designlist()
  2545. {
  2546. DataStruct dStruct = GetPostStruct();
  2547. List<string> lw = new List<string>();
  2548. string tid = GetPostString("ctid");
  2549. if (tid.Length > 0)
  2550. {
  2551. string select_tid = getTidByCtid(tid);
  2552. lw.Add(string.Format("tid='{0}'", select_tid));
  2553. }
  2554. string shopname = GetPostString("shopname");
  2555. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2556. string buyernick = GetPostString("buyer_nick");
  2557. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2558. string customer = GetPostString("customer");
  2559. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2560. string design = GetPostString("design");
  2561. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2562. string orderState = GetPostString("orderState");
  2563. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2564. lw.Add(string.Format("OrderState<6"));
  2565. string address = GetPostString("address");
  2566. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2567. string sellermemo = GetPostString("seller_memo");
  2568. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2569. string date1 = GetPostString("date1");
  2570. string date2 = GetPostString("date2");
  2571. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2572. if (dw.Length > 0) lw.Add(dw);
  2573. string apdate1 = GetPostString("apdate1");
  2574. string apdate2 = GetPostString("apdate2");
  2575. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2576. if (dwap.Length > 0) lw.Add(dwap);
  2577. string price1 = GetPostString("price1");
  2578. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2579. string price2 = GetPostString("price2");
  2580. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2581. string designTime = GetPostString("designtime");
  2582. if (designTime.Length > 0)
  2583. {
  2584. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2585. }
  2586. string usershop = CurrentUser.User.pemShop;
  2587. if (usershop.Length > 0)
  2588. {
  2589. lw.Add(string.Format("shopId in ({0})", usershop));
  2590. }
  2591. int myOrgid = CurrentUser.UserPost.OrgID;
  2592. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2593. if (myOrgCode.IndexOf("Designer") != -1)
  2594. {
  2595. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2596. {
  2597. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2598. }
  2599. else
  2600. {
  2601. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2602. }
  2603. }
  2604. else
  2605. {
  2606. string orgId = GetPostString("designerhd");
  2607. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2608. }
  2609. if (tid.Length > 0 || buyernick.Length > 0)
  2610. {
  2611. lw.Add(string.Format("OrderState >= 3"));
  2612. }
  2613. else
  2614. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2615. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2616. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2617. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2618. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2619. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2620. if (dt != null && dt.Rows.Count > 0)
  2621. {
  2622. foreach (DataRow dr in dt.Rows)
  2623. {
  2624. try
  2625. {
  2626. // 对象操作
  2627. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2628. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2629. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2630. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2631. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2632. if (dStruct.PageSize != 100000)
  2633. {
  2634. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  2635. dr["gongchuang"] = response.code;
  2636. }
  2637. }
  2638. catch (NullReferenceException ex)
  2639. {
  2640. }
  2641. }
  2642. }
  2643. writeGridDataTableJson(dStruct.TotalCount, dt);
  2644. }
  2645. public void get_erp_mydesignlist()
  2646. {
  2647. DataStruct dStruct = GetPostStruct();
  2648. List<string> lw = new List<string>();
  2649. string tid = GetPostString("ctid");
  2650. if (tid.Length > 0)
  2651. {
  2652. string select_tid = getTidByCtid(tid);
  2653. lw.Add(string.Format("tid='{0}'", select_tid));
  2654. }
  2655. string shopname = GetPostString("shopname");
  2656. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2657. string buyernick = GetPostString("buyer_nick");
  2658. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2659. string customer = GetPostString("customer");
  2660. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2661. string orderState = GetPostString("orderState");
  2662. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2663. //lw.Add(string.Format("OrderState<6"));
  2664. string date1 = GetPostString("date1");
  2665. string date2 = GetPostString("date2");
  2666. string dw = GetDateWhere("pay_time", date1, date2);
  2667. if (dw.Length > 0) lw.Add(dw);
  2668. string apdate1 = GetPostString("apdate1");
  2669. string apdate2 = GetPostString("apdate2");
  2670. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2671. if (dwap.Length > 0) lw.Add(dwap);
  2672. string price1 = GetPostString("price1");
  2673. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2674. string price2 = GetPostString("price2");
  2675. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2676. string olddownload = GetPostString("olddown");
  2677. if (olddownload == "1")
  2678. {
  2679. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2680. }
  2681. else if (olddownload == "2")
  2682. {
  2683. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2684. }
  2685. string sellermemo = GetPostString("seller_memo");
  2686. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2687. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2688. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2689. {
  2690. if (CurrentUser.User.TeamIds.Length > 0)
  2691. {
  2692. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2693. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2694. else
  2695. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2696. }
  2697. else
  2698. {
  2699. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2700. }
  2701. }
  2702. if (tid.Length <= 0)
  2703. {
  2704. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2705. }
  2706. lw.Add(string.Format("IsReturn!=3"));
  2707. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2708. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2709. string teamids = CurrentUser.User.TeamIds.ToString();
  2710. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2711. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2712. if (dt != null && dt.Rows.Count > 0)
  2713. {
  2714. foreach (DataRow dr in dt.Rows)
  2715. {
  2716. try
  2717. {
  2718. // 对象操作
  2719. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2720. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2721. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2722. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2723. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2724. if (dStruct.PageSize != 100000)
  2725. {
  2726. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString());
  2727. dr["gongchuang"] = response.code;
  2728. }
  2729. }
  2730. catch (NullReferenceException ex)
  2731. {
  2732. }
  2733. }
  2734. }
  2735. writeGridDataTableJson(dStruct.TotalCount, dt);
  2736. }
  2737. public void set_erp_startdesign()
  2738. {
  2739. if (UrlPostParmsCheck("ctid"))
  2740. {
  2741. string eid = GetPostString("ctid");
  2742. CeErpTradeCell entity = null;
  2743. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2744. if (entity != null)
  2745. {
  2746. if (entity.OrderState != 3)
  2747. {
  2748. returnErrorMsg("请刷新,订单已经设计了");
  2749. return;
  2750. }
  2751. entity.StartDesignTime = DateTime.Now;
  2752. entity.OrderState = 4;
  2753. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2754. {
  2755. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2756. entity.SupplierId = suid;
  2757. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2758. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2759. }
  2760. entity.UpdateTime = DateTime.Now;
  2761. //entity.MakeSupplier = suname;
  2762. entity.Update();
  2763. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2764. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2765. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2766. commonHelper.getCytPrice(entity);
  2767. returnSuccessMsg("操作成功!");
  2768. return;
  2769. }
  2770. returnErrorMsg("找不到记录");
  2771. }
  2772. }
  2773. public void ins_erp_designselfmemo()
  2774. {
  2775. if (UrlPostParmsCheck("ctid"))
  2776. {
  2777. string eid = GetPostString("ctid");
  2778. string con = GetPostString("con");
  2779. CeErpTradeCell entity = null;
  2780. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2781. if (entity != null)
  2782. {
  2783. entity.DesignSelfMemo = con;
  2784. entity.Update();
  2785. returnSuccessMsg("操作成功!");
  2786. return;
  2787. }
  2788. returnErrorMsg("找不到记录");
  2789. }
  2790. }
  2791. public void ins_erp_designprice()
  2792. {
  2793. if (UrlPostParmsCheck("ctid"))
  2794. {
  2795. string eid = GetPostString("ctid");
  2796. int uid = CurrentUser.UserID;
  2797. string userName = CurrentUser.UserName;
  2798. CeErpTradeCell entity = null;
  2799. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2800. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2801. if (entitys == null)
  2802. {
  2803. entitys = new CeErpDesignerBill();
  2804. }
  2805. if (entity != null)
  2806. {
  2807. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2808. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2809. entity.StartDesignTime = DateTime.Now;
  2810. entity.OrderState = 4;
  2811. string suname = "";
  2812. if (entity.SupplierId == 0)
  2813. {
  2814. int sid = commonHelper.autoDistributeToSupplier(entity);
  2815. entity.SupplierId = sid;
  2816. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2817. }
  2818. entity.Update();
  2819. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  2820. if (ceErpUserPost != null)
  2821. {
  2822. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  2823. if (ceErpPost != null)
  2824. {
  2825. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  2826. {
  2827. entitys.tid = entity.ctid;
  2828. entitys.oid = entity.tid;
  2829. entitys.uid = uid;
  2830. entitys.userName = userName;
  2831. entitys.designerType = 1;
  2832. entitys.designerTypeText = "内部设计师";
  2833. entitys.price = Convert.ToDouble(GetPostString("price"));
  2834. entitys.designNum = GetPostInt("designNum");
  2835. entitys.modifyNum = GetPostInt("modifyNum");
  2836. entitys.designSize = GetPostString("designSize");
  2837. entitys.modifySize = GetPostString("modifySize");
  2838. if (CeErpDesignerBill.GetByTid("ctid") == null)
  2839. {
  2840. entitys.create_time = DateTime.Now;
  2841. entitys.create_u_id = uid;
  2842. entitys.create_u_name = userName;
  2843. entitys.Save();
  2844. }
  2845. else
  2846. {
  2847. entitys.update_time = DateTime.Now;
  2848. entitys.update_u_id = uid;
  2849. entitys.update_u_name = userName;
  2850. entitys.Update();
  2851. }
  2852. }
  2853. }
  2854. }
  2855. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2856. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2857. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  2858. if (suname != "")
  2859. {
  2860. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2861. }
  2862. commonHelper.getCytPrice(entity);
  2863. returnSuccessMsg("操作成功!");
  2864. return;
  2865. }
  2866. returnErrorMsg("找不到记录");
  2867. }
  2868. }
  2869. public void upload_erp_filecomplete()
  2870. {
  2871. if (UrlPostParmsCheck("ctid"))
  2872. {
  2873. string eid = GetPostString("ctid");
  2874. CeErpTradeCell entity = null;
  2875. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2876. if (entity != null)
  2877. {
  2878. entity.OrderState = 5; //设计完成
  2879. entity.Update();
  2880. returnSuccessMsg(eid + "上传成功,设计完成!");
  2881. return;
  2882. }
  2883. returnErrorMsg("找不到订单记录");
  2884. }
  2885. }
  2886. public void get_erp_designovertimelist()
  2887. {
  2888. DataStruct dStruct = GetPostStruct();
  2889. List<string> lw = new List<string>();
  2890. string tid = GetPostString("ctid");
  2891. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  2892. string shopname = GetPostString("shopname");
  2893. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2894. string buyernick = GetPostString("buyer_nick");
  2895. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2896. string ResponsibleMan = GetPostString("responsible");
  2897. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2898. string date1 = GetPostString("date1");
  2899. string date2 = GetPostString("date2");
  2900. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2901. if (dw.Length > 0) lw.Add(dw);
  2902. string price1 = GetPostString("price1");
  2903. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2904. string price2 = GetPostString("price2");
  2905. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2906. string orderState = GetPostString("orderState");
  2907. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2908. string sellermemo = GetPostString("seller_memo");
  2909. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2910. lw.Add(string.Format("UnusualTag=3"));
  2911. lw.Add(string.Format("IsRefund<={0}", 1));
  2912. dStruct.Order = "WaitDesignTime desc";
  2913. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2914. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2915. writeGridDataTableJson(dStruct.TotalCount, dt);
  2916. }
  2917. //设计管理 获取抢单大厅列表
  2918. public void get_erp_grabinglist()
  2919. {
  2920. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  2921. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  2922. bool oldOrder = false;
  2923. if (org != null)
  2924. {
  2925. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  2926. }
  2927. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  2928. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  2929. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2930. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  2931. //先处理订单数据
  2932. if (dt.Rows.Count > 0)
  2933. {
  2934. Dictionary<string, int> design = null;
  2935. int count = 0;
  2936. foreach (DataRow row in dt.Rows)
  2937. {
  2938. if (map.ContainsKey(row["ShopId"].ToString()))
  2939. {
  2940. map.TryGetValue(row["ShopId"].ToString(), out design);
  2941. }
  2942. else
  2943. {
  2944. design = new Dictionary<string, int>();
  2945. }
  2946. if (design.ContainsKey(row["ProductId"].ToString()))
  2947. {
  2948. design.TryGetValue(row["ProductId"].ToString(), out count);
  2949. }
  2950. count++;
  2951. design[row["ProductId"].ToString()] = count;
  2952. map[row["ShopId"].ToString()] = design;
  2953. }
  2954. }
  2955. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  2956. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2957. //把店铺排序和技能排序分类
  2958. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  2959. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  2960. if (design_dt.Rows.Count > 0)
  2961. {
  2962. Dictionary<string, string> design = null;
  2963. List<string> shopIds = null;
  2964. foreach (DataRow row in design_dt.Rows)
  2965. {
  2966. if ("0".Equals(row["designId"].ToString()))
  2967. {
  2968. if (shop_orders.ContainsKey(row["orders"].ToString()))
  2969. {
  2970. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  2971. }
  2972. else
  2973. {
  2974. shopIds = new List<string>();
  2975. }
  2976. shopIds.Add(row["shopId"].ToString());
  2977. shop_orders[row["orders"].ToString()] = shopIds;
  2978. }
  2979. else
  2980. {
  2981. if (design_orders.ContainsKey(row["shopId"].ToString()))
  2982. {
  2983. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  2984. }
  2985. else
  2986. {
  2987. design = new Dictionary<string, string>();
  2988. }
  2989. design[row["orders"].ToString()] = row["designId"].ToString();
  2990. design_orders[row["shopId"].ToString()] = design;
  2991. }
  2992. }
  2993. //处理成key value后根据key排序
  2994. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  2995. foreach (List<string> val in shop_orders.Values)
  2996. {
  2997. if (val != null)
  2998. {
  2999. foreach (string key in val)
  3000. {
  3001. if (design_orders.ContainsKey(key.ToString()))
  3002. {
  3003. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3004. }
  3005. }
  3006. }
  3007. }
  3008. }
  3009. //校验哪个优先级有订单
  3010. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3011. foreach (string key in shop_orders.Keys)
  3012. {
  3013. List<string> ids = null;
  3014. shop_orders.TryGetValue(key, out ids);
  3015. //id为shopid
  3016. foreach (string id in ids)
  3017. {
  3018. Dictionary<string, int> list = null;
  3019. Dictionary<string, string> desing = null;
  3020. map.TryGetValue(id, out list);
  3021. design_orders.TryGetValue(id, out desing);
  3022. if (list != null && desing != null)
  3023. {
  3024. foreach (var item in desing)
  3025. {
  3026. int count = 0;
  3027. if (list.ContainsKey(item.Value))
  3028. {
  3029. list.TryGetValue(item.Value, out count);
  3030. if (count > 0)
  3031. {
  3032. designIds[id] = item.Value;
  3033. break;
  3034. }
  3035. }
  3036. }
  3037. }
  3038. }
  3039. if (designIds.Count > 0)
  3040. {
  3041. break;
  3042. }
  3043. }
  3044. DataTable table = new DataTable();
  3045. table.Columns.Add("tid", typeof(string));
  3046. table.Columns.Add("ctid", typeof(string));
  3047. table.Columns.Add("seller_nick", typeof(string));
  3048. table.Columns.Add("productName", typeof(string));
  3049. table.Columns.Add("pay_time", typeof(string));
  3050. table.Columns.Add("seller_memo", typeof(string));
  3051. if (designIds.Count > 0)
  3052. {
  3053. string shopId = "";
  3054. string productId = "";
  3055. foreach (var designInfo in designIds)
  3056. {
  3057. shopId = designInfo.Key;
  3058. productId = designInfo.Value;
  3059. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3060. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3061. if (dt.Rows.Count > 0)
  3062. {
  3063. foreach (DataRow row in dt.Rows)
  3064. {
  3065. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3066. {
  3067. DataRow data = table.NewRow();
  3068. data["ctid"] = row["ctid"].ToString();
  3069. data["tid"] = row["tid"].ToString();
  3070. data["seller_nick"] = ceErpShop.ShopName;
  3071. data["pay_time"] = row["pay_time"].ToString();
  3072. data["seller_memo"] = row["seller_memo"].ToString();
  3073. data["productName"] = ceErpProduct.PType;
  3074. table.Rows.Add(data);
  3075. }
  3076. }
  3077. }
  3078. }
  3079. }
  3080. writeGridDataTableJson(table.Rows.Count, table);
  3081. }
  3082. private object rushLockObject = new object();
  3083. public void set_erp_grabingorder()
  3084. {
  3085. if (UrlPostParmsCheck("ctid"))
  3086. {
  3087. int total = CurrentUser.User.Person.Total;
  3088. int userId = CurrentUser.User.ID;
  3089. int noFinish = CurrentUser.User.Person.NoFinish;
  3090. int finalization = CurrentUser.User.Person.Finalization;
  3091. string eids = GetPostString("ctid");
  3092. string key = "RushKey_" + userId;
  3093. int count = 0;
  3094. if (erpRedis.RedisHelper.KeyExists(key))
  3095. {
  3096. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3097. if (redisCount != null)
  3098. {
  3099. count = Convert.ToInt32(redisCount);
  3100. }
  3101. }
  3102. if (count >= total)
  3103. {
  3104. returnErrorMsg("半小时内已经抢" + total + "单");
  3105. return;
  3106. }
  3107. string[] ctidlist = eids.Split(',');
  3108. if (count + ctidlist.Length > total)
  3109. {
  3110. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3111. return;
  3112. }
  3113. int itag = 0;
  3114. lock (rushLockObject)
  3115. {
  3116. if (ctidlist.Length > 0)
  3117. {
  3118. string[] dtList = new string[ctidlist.Length];
  3119. for (int i = 0; i < ctidlist.Length; i++)
  3120. {
  3121. dtList[i] = "'" + ctidlist[i] + "'";
  3122. }
  3123. 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"));
  3124. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3125. if (dt_user.Rows.Count > 0)
  3126. {
  3127. int doing = 0;//未定稿
  3128. int finish = 0;//已完成
  3129. foreach (DataRow dr in dt_user.Rows)
  3130. {
  3131. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3132. {
  3133. doing++;
  3134. }
  3135. else
  3136. {
  3137. finish++;
  3138. }
  3139. }
  3140. if (doing >= noFinish)
  3141. {
  3142. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3143. return;
  3144. }
  3145. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3146. {
  3147. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3148. return;
  3149. }
  3150. }
  3151. //校验选择单子状态
  3152. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3153. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3154. if (dt.Rows.Count > 0)
  3155. {
  3156. List<string> list = new List<string>();
  3157. foreach (DataRow dr in dt.Rows)
  3158. {
  3159. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3160. {
  3161. list.Add(dr["ctid"].ToString());
  3162. }
  3163. }
  3164. if (list.Count > 0)
  3165. {
  3166. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3167. return;
  3168. }
  3169. }
  3170. foreach (string ctid in ctidlist)
  3171. {
  3172. CeErpTradeCell entity = null;
  3173. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3174. if (entity != null)
  3175. {
  3176. entity.OrderState = 3;
  3177. entity.DesignUserId = CurrentUser.UserID;
  3178. entity.WaitDesignTime = DateTime.Now;
  3179. entity.StartDesignTime = DateTime.Now;
  3180. entity.Update();
  3181. commonHelper.UpdateRelationOrder(entity.ctid);
  3182. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3183. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3184. itag++;
  3185. }
  3186. }
  3187. }
  3188. }
  3189. count += ctidlist.Length;
  3190. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3191. if (itag == 0)
  3192. returnErrorMsg("没有找到相关订单");
  3193. else
  3194. returnSuccessMsg("抢单成功!");
  3195. return;
  3196. }
  3197. }
  3198. public void get_erp_waitorderlist()
  3199. {
  3200. DataStruct dStruct = GetPostStruct();
  3201. List<string> lw = new List<string>();
  3202. string tid = GetPostString("ctid");
  3203. if (tid.Length > 0)
  3204. {
  3205. string select_tid = getTidByCtid(tid);
  3206. lw.Add(string.Format("tid='{0}'", select_tid));
  3207. }
  3208. string shopname = GetPostString("shopname");
  3209. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3210. string buyernick = GetPostString("buyer_nick");
  3211. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3212. string customer = GetPostString("customer");
  3213. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3214. string design = GetPostString("design");
  3215. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3216. string orderState = GetPostString("orderState");
  3217. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3218. string supplier = GetPostString("supplier");
  3219. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3220. string sellermemo = GetPostString("seller_memo");
  3221. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3222. string otherMemo = GetPostString("otherMemo");
  3223. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3224. string address = GetPostString("address");
  3225. 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));
  3226. string date1 = GetPostString("date1");
  3227. string date2 = GetPostString("date2");
  3228. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3229. if (dw.Length > 0) lw.Add(dw);
  3230. string price1 = GetPostString("price1");
  3231. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3232. string price2 = GetPostString("price2");
  3233. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3234. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3235. lw.Add(string.Format("IsSample != 2 "));
  3236. lw.Add(string.Format("OrderState = 5 "));
  3237. lw.Add(string.Format("IsRefund<={0}", 1));
  3238. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3239. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3240. string pagesize = GetPostString("pagesize");
  3241. if (pagesize != null)
  3242. {
  3243. dStruct.PageSize = 200;
  3244. }
  3245. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3246. if (dt != null)
  3247. {
  3248. foreach (DataRow dr in dt.Rows)
  3249. {
  3250. 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();
  3251. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3252. {
  3253. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3254. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3255. entity.SupplierId = suid;
  3256. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3257. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3258. entity.Update();
  3259. }
  3260. }
  3261. }
  3262. writeGridDataTableJson(dStruct.TotalCount, dt);
  3263. }
  3264. public void get_erp_supplierwaitorderlist()
  3265. {
  3266. DataStruct dStruct = GetPostStruct();
  3267. List<string> lw = new List<string>();
  3268. string tid = GetPostString("ctid");
  3269. if (tid.Length > 0)
  3270. {
  3271. string select_tid = getTidByCtid(tid);
  3272. lw.Add(string.Format("tid='{0}'", select_tid));
  3273. }
  3274. string shopname = GetPostString("shopname");
  3275. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3276. string sellermemo = GetPostString("seller_memo");
  3277. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3278. string date1 = GetPostString("date1");
  3279. string date2 = GetPostString("date2");
  3280. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3281. if (dw.Length > 0) lw.Add(dw);
  3282. lw.Add(string.Format("OrderState = 5 "));
  3283. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3284. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3285. {
  3286. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3287. }
  3288. string supplier = GetPostString("supplier");
  3289. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3290. {
  3291. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3292. }
  3293. lw.Add(string.Format("IsRefund<={0}", 1));
  3294. dStruct.Order = "FinishDesignTime desc";
  3295. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3296. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3297. if (dt != null)
  3298. {
  3299. foreach (DataRow dr in dt.Rows)
  3300. {
  3301. 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();
  3302. }
  3303. }
  3304. writeGridDataTableJson(dStruct.TotalCount, dt);
  3305. }
  3306. public void upd_erp_verifytosupplier()
  3307. {
  3308. if (UrlPostParmsCheck("ctid"))
  3309. {
  3310. string eids = GetPostString("ctid");
  3311. CeErpTradeCell entity = null;
  3312. string[] eidsList = eids.Split(',');
  3313. if (eidsList.Length <= 0)
  3314. {
  3315. returnErrorMsg("订单号不能空");
  3316. return;
  3317. }
  3318. List<string> tLst = new List<string>();
  3319. foreach (string ctidstr in eidsList)
  3320. {
  3321. tLst.Add("'" + ctidstr + "'");
  3322. CeErpDataSendOrderInfo.createObject(ctidstr);
  3323. }
  3324. string needtids = string.Join(",", tLst.ToArray());
  3325. StringBuilder sql = new StringBuilder();
  3326. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3327. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1} where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3328. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3329. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3330. returnSuccessMsg("操作成功!");
  3331. return;
  3332. /**foreach (string ctidstr in eidsList)
  3333. {
  3334. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3335. if (entity != null)
  3336. {
  3337. if (entity.SupplierId == 0)
  3338. {
  3339. continue;
  3340. }
  3341. entity.IsVerifyToSupplier = true;
  3342. if (entity.IsReturn == 1) //1是供应商打回
  3343. {
  3344. entity.IsReturn = 0;
  3345. }
  3346. entity.FinishPlaceTime = DateTime.Now;
  3347. entity.PlaceUserId = CurrentUser.UserID;
  3348. entity.Update();
  3349. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3350. }
  3351. }
  3352. returnSuccessMsg("操作成功!");
  3353. return;**/
  3354. }
  3355. }
  3356. public void upd_erp_supplierback()
  3357. {
  3358. if (UrlPostParmsCheck("ctid"))
  3359. {
  3360. string eid = GetPostString("ctid");
  3361. string reason = GetPostString("returnreason");
  3362. CeErpTradeCell entity = null;
  3363. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3364. if (entity != null)
  3365. {
  3366. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3367. {
  3368. string key = "return_order_" + entity.SupplierId;
  3369. List<string> list = new List<string>();
  3370. if (RedisHelper.HasKey(key))
  3371. {
  3372. object data = RedisHelper.StringGet(key);
  3373. list = Convert.ToString(data).Split(',').ToList();
  3374. }
  3375. list.Add(eid);
  3376. RedisHelper.StringSet(key, string.Join(",", list));
  3377. }
  3378. entity.IsVerifyToSupplier = false;
  3379. entity.IsReturn = 1;
  3380. entity.ReturnTime = DateTime.Now;
  3381. entity.ReturnReason = reason;
  3382. if (entity.OrderState == 6)
  3383. {
  3384. entity.OrderState = 5;
  3385. }
  3386. entity.Update();
  3387. CeErpSukuraData.createInfo(entity.ctid, 5);
  3388. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3389. returnSuccessMsg("操作成功!");
  3390. return;
  3391. }
  3392. returnErrorMsg("找不到订单记录");
  3393. }
  3394. }
  3395. public void upd_erp_toaftersaleorder()
  3396. {
  3397. if (UrlPostParmsCheck("ctid"))
  3398. {
  3399. string eid = GetPostString("ctid");
  3400. string reason = GetPostString("returnreason");
  3401. CeErpTradeCell entity = null;
  3402. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3403. if (entity != null)
  3404. {
  3405. if (entity.isAfterSaleOrder != 1)
  3406. {
  3407. returnErrorMsg("带S的售后单才能打回给售后");
  3408. return;
  3409. }
  3410. if (entity.OrderState >= 5)
  3411. {
  3412. returnErrorMsg("已经设计完成了不能打回给售后");
  3413. return;
  3414. }
  3415. entity.OrderState = 0;
  3416. entity.IsReturn = 3;
  3417. entity.ReturnTime = DateTime.Now;
  3418. entity.UpdateTime = DateTime.Now;
  3419. entity.ReturnReason = reason;
  3420. entity.Update();
  3421. CeErpSukuraData.createInfo(entity.ctid, 5);
  3422. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3423. returnSuccessMsg("操作成功!");
  3424. return;
  3425. }
  3426. returnErrorMsg("找不到订单记录");
  3427. }
  3428. }
  3429. public void upd_erp_aftersaletodesign()
  3430. {
  3431. if (UrlPostParmsCheck("ctid"))
  3432. {
  3433. string eid = GetPostString("ctid");
  3434. CeErpTradeCell entity = null;
  3435. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3436. if (entity != null)
  3437. {
  3438. entity.OrderState = 3;
  3439. entity.IsReturn = 0;
  3440. entity.UpdateTime = DateTime.Now;
  3441. entity.Update();
  3442. CeErpSukuraData.createInfo(entity.ctid, 5);
  3443. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3444. returnSuccessMsg("操作成功!");
  3445. return;
  3446. }
  3447. returnErrorMsg("找不到订单记录");
  3448. }
  3449. }
  3450. public void assign_erp_supplier()
  3451. {
  3452. if (UrlPostParmsCheck("ctid"))
  3453. {
  3454. string eids = GetPostString("ctid");
  3455. int sid = GetPostInt("SupplierName");
  3456. string fromTag = GetPostString("tag");
  3457. string[] eidList = eids.Split(',');
  3458. if (eidList.Length <= 0)
  3459. {
  3460. returnErrorMsg("指派不能为空");
  3461. return;
  3462. }
  3463. string errMsg = "";
  3464. string suname = commonHelper.getSupplierNameById(sid);
  3465. foreach (string ctid in eidList)
  3466. {
  3467. CeErpTradeCell entity = null;
  3468. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3469. if (entity != null)
  3470. {
  3471. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3472. {
  3473. errMsg += (ctid + "指派失败!!!");
  3474. continue;
  3475. }
  3476. entity.SupplierId = sid;
  3477. entity.Update();
  3478. commonHelper.UpdateRelationOrder(entity.ctid);
  3479. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3480. if (entity.OrderState >= 6)
  3481. {
  3482. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3483. //{
  3484. // string msl = entity.MakeSupplier;
  3485. // string[] mslist = msl.Split(',');
  3486. // 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);
  3487. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3488. //}
  3489. //else
  3490. //{
  3491. StringBuilder sql = new StringBuilder();
  3492. 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);
  3493. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3494. //}
  3495. }
  3496. }
  3497. else
  3498. {
  3499. continue;
  3500. }
  3501. }
  3502. if (errMsg.Length > 0)
  3503. {
  3504. returnErrorMsg(errMsg);
  3505. return;
  3506. }
  3507. returnSuccessMsg("操作成功!");
  3508. return;
  3509. }
  3510. }
  3511. public void assign_erp_makesupplier()
  3512. {
  3513. if (UrlPostParmsCheck("ctid"))
  3514. {
  3515. string eids = GetPostString("ctid");
  3516. string sname = GetPostString("SupplierName");
  3517. string[] eidList = eids.Split(',');
  3518. if (eidList.Length <= 0)
  3519. {
  3520. returnErrorMsg("指派不能为空");
  3521. return;
  3522. }
  3523. List<string> tLst = new List<string>();
  3524. foreach (string ctid in eidList)
  3525. {
  3526. CeErpTradeCell entity = null;
  3527. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3528. if (entity != null)
  3529. {
  3530. entity.MakeSupplier = sname;
  3531. entity.Update();
  3532. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3533. tLst.Add("'" + ctid + "'");
  3534. }
  3535. else
  3536. {
  3537. continue;
  3538. }
  3539. }
  3540. string ctids = string.Join(",", tLst.ToArray());
  3541. StringBuilder sql2 = new StringBuilder();
  3542. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3543. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3544. returnSuccessMsg("操作成功!");
  3545. return;
  3546. }
  3547. }
  3548. public void ins_erp_returnreason()
  3549. {
  3550. if (UrlPostParmsCheck("ctid"))
  3551. {
  3552. string eid = GetPostString("ctid");
  3553. CeErpTradeCell entity = null;
  3554. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3555. string userpost = CurrentUser.UserPost.Post.Code;
  3556. if (entity != null)
  3557. {
  3558. bool isPlace = false;
  3559. if (entity.OrderState > 6)
  3560. {
  3561. returnErrorMsg("已发货无法打回!");
  3562. return;
  3563. }
  3564. if (entity.OrderState == 6)
  3565. {
  3566. isPlace = true;
  3567. }
  3568. bool isNeedUpdateCell2 = false;
  3569. if (entity.OrderState >= 6)
  3570. {
  3571. isNeedUpdateCell2 = true;
  3572. }
  3573. int returnTag = 2;
  3574. if (userpost == "Supplier")
  3575. {
  3576. returnTag = 1;
  3577. }
  3578. int toType = GetPostInt("totype");
  3579. string fromType = "3";
  3580. if (entity.OrderState < 5)
  3581. {
  3582. fromType = "3";
  3583. }
  3584. else
  3585. {
  3586. fromType = "4";
  3587. }
  3588. if (entity.IsXianHuo == 0)
  3589. {
  3590. if (returnTag == 2)
  3591. {
  3592. if (toType == 1)
  3593. {
  3594. entity.OrderState = 0;
  3595. entity.ReturnUserType = 1;
  3596. string clearman = GetPostString("clearman");
  3597. if (!string.IsNullOrEmpty(clearman))
  3598. {
  3599. entity.DesignUserId = 0;
  3600. }
  3601. }
  3602. else
  3603. {
  3604. entity.OrderState = 3;
  3605. entity.ReturnUserType = 2;
  3606. }
  3607. entity.IsReadTag = 1;
  3608. }
  3609. else if (returnTag == 1)
  3610. {
  3611. entity.OrderState = 5;
  3612. }
  3613. entity.IsVerifyToSupplier = false;
  3614. }
  3615. if (entity.IsXianHuo == 1)
  3616. {
  3617. entity.OrderState = 5;
  3618. }
  3619. entity.UnusualTag = 0;
  3620. entity.UnusualTime = null;
  3621. entity.UnusualCon = "";
  3622. entity.IsReturn = returnTag;
  3623. entity.ReturnTime = DateTime.Now;
  3624. entity.UpdateTime = DateTime.Now;
  3625. entity.ReturnReason = GetPostString("returnreason");
  3626. entity.Update();
  3627. if (entity.OrderState == 3)
  3628. {
  3629. ApiVo apiVo = new ApiVo();
  3630. apiVo.orderNumber = entity.ctid;
  3631. apiVo.actionName = "rebutDesign";
  3632. apiVo.orderRemarks = entity.ReturnReason;
  3633. designHelper.API_WorkCore(apiVo);//rebutDesign
  3634. }
  3635. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3636. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3637. {
  3638. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3639. }
  3640. CeErpSukuraData.createInfo(entity.ctid, 5);
  3641. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3642. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3643. if (isPlace)
  3644. {
  3645. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3646. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3647. if (dth != null && dth.Rows.Count > 0)
  3648. {
  3649. dataSendOrderBean dataSendOrderBean = null;
  3650. foreach (DataRow item in dth.Rows)
  3651. {
  3652. try
  3653. {
  3654. dataSendOrderBean = new dataSendOrderBean();
  3655. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3656. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3657. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3658. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3659. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3660. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3661. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3662. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3663. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3664. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3665. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3666. dataSendOrderBean.Radio1723534706288 = "打回";
  3667. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3668. if (result != null)
  3669. {
  3670. if ("0".Equals(result.errcode))
  3671. {
  3672. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3673. }
  3674. else
  3675. {
  3676. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3677. }
  3678. }
  3679. }
  3680. catch (Exception ex)
  3681. {
  3682. }
  3683. }
  3684. }
  3685. }
  3686. if (isNeedUpdateCell2)
  3687. {
  3688. if (entity.MakeSupplier.IndexOf(",") != -1)
  3689. {
  3690. StringBuilder sql2 = new StringBuilder();
  3691. 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);
  3692. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3693. }
  3694. else
  3695. {
  3696. StringBuilder sql2 = new StringBuilder();
  3697. 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);
  3698. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3699. }
  3700. }
  3701. returnSuccessMsg("操作成功!");
  3702. return;
  3703. }
  3704. returnErrorMsg("找不到订单记录");
  3705. }
  3706. }
  3707. public void cyt_erp_returnreason()
  3708. {
  3709. if (UrlPostParmsCheck("ctid"))
  3710. {
  3711. string eid = GetPostString("ctid");
  3712. CeErpTradeCell entity = null;
  3713. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3714. string userpost = CurrentUser.UserPost.Post.Code;
  3715. if (entity != null)
  3716. {
  3717. if (entity.OrderState > 6)
  3718. {
  3719. returnErrorMsg("已发货无法打回!");
  3720. return;
  3721. }
  3722. JObject jsonObject = new JObject
  3723. {
  3724. { "Userid", "77886" },
  3725. { "Pwd", "lt666888" },
  3726. { "LTOrderId",eid }
  3727. };
  3728. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3729. JObject jsonObjects = JObject.Parse(response);
  3730. string msg = (string)jsonObjects["msg"];
  3731. if (msg != "取消成功")
  3732. {
  3733. returnErrorMsg(msg);
  3734. return;
  3735. }
  3736. bool isNeedUpdateCell2 = false;
  3737. if (entity.OrderState >= 6)
  3738. {
  3739. isNeedUpdateCell2 = true;
  3740. }
  3741. int returnTag = 2;
  3742. if (userpost == "Supplier")
  3743. {
  3744. returnTag = 1;
  3745. }
  3746. if (entity.IsXianHuo == 0)
  3747. {
  3748. if (returnTag == 2)
  3749. {
  3750. int toType = GetPostInt("totype");
  3751. if (toType == 1)
  3752. {
  3753. entity.OrderState = 0;
  3754. entity.ReturnUserType = 1;
  3755. }
  3756. else
  3757. {
  3758. entity.OrderState = 4;
  3759. entity.ReturnUserType = 2;
  3760. }
  3761. entity.IsReadTag = 1;
  3762. }
  3763. else if (returnTag == 1)
  3764. {
  3765. entity.OrderState = 5;
  3766. }
  3767. entity.IsVerifyToSupplier = false;
  3768. }
  3769. entity.UnusualTag = 0;
  3770. entity.UnusualTime = null;
  3771. entity.UnusualCon = "";
  3772. entity.IsReturn = returnTag;
  3773. entity.ReturnTime = DateTime.Now;
  3774. entity.ReturnReason = GetPostString("returnreason");
  3775. entity.Update();
  3776. if (entity.OrderState == 4)
  3777. {
  3778. ApiVo apiVo = new ApiVo();
  3779. apiVo.orderNumber = entity.ctid;
  3780. apiVo.actionName = "rebutDesign";
  3781. apiVo.orderRemarks = entity.ReturnReason;
  3782. designHelper.API_WorkCore(apiVo);//rebutDesign
  3783. }
  3784. CeErpSukuraData.createInfo(entity.ctid, 5);
  3785. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3786. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3787. if (isNeedUpdateCell2)
  3788. {
  3789. if (entity.MakeSupplier.IndexOf(",") != -1)
  3790. {
  3791. StringBuilder sql2 = new StringBuilder();
  3792. 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);
  3793. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3794. }
  3795. else
  3796. {
  3797. StringBuilder sql2 = new StringBuilder();
  3798. 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);
  3799. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3800. }
  3801. }
  3802. returnSuccessMsg("操作成功!");
  3803. return;
  3804. }
  3805. returnErrorMsg("找不到订单记录");
  3806. }
  3807. }
  3808. public void upd_erp_xianhuoreturntag()
  3809. {
  3810. if (UrlPostParmsCheck("ctid"))
  3811. {
  3812. string eids = GetPostString("ctid");
  3813. string[] ctids = eids.Split(',');
  3814. foreach (string ctid in ctids)
  3815. {
  3816. CeErpTradeCell entity = null;
  3817. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3818. if (entity != null)
  3819. {
  3820. entity.IsReturn = 0;
  3821. entity.Update();
  3822. CeErpSukuraData.createInfo(entity.ctid, 5);
  3823. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  3824. }
  3825. }
  3826. returnSuccessMsg("操作成功!");
  3827. return;
  3828. }
  3829. }
  3830. public void get_erp_waitdeliverylist()
  3831. {
  3832. DataStruct dStruct = GetPostStruct();
  3833. List<string> lw = new List<string>();
  3834. string tid = GetPostString("ctid");
  3835. if (tid.Length > 0)
  3836. {
  3837. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3838. if (tid.Length > 5)
  3839. {
  3840. List<string> tids = getTidByCtidLike(tid);
  3841. if (tids.Count > 0 && tids.Count < 10)
  3842. {
  3843. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3844. }
  3845. }
  3846. lw.Add(tid_sql);
  3847. }
  3848. string shopname = GetPostString("shopname");
  3849. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3850. string buyernick = GetPostString("buyer_nick");
  3851. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3852. //if (tid.Length == 0 && buyernick.Length == 0)
  3853. //{
  3854. // lw.Add(string.Format("IsRefund<={0}", 1));
  3855. //}
  3856. string customer = GetPostString("customer");
  3857. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3858. string design = GetPostString("design");
  3859. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3860. string orderState = GetPostString("orderState");
  3861. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3862. string address = GetPostString("address");
  3863. 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));
  3864. string sellermemo = GetPostString("seller_memo");
  3865. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3866. string supplier = GetPostString("supplier");
  3867. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3868. string OrderArea = GetPostString("order_area");
  3869. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3870. string placedate1 = GetPostString("placedate1");
  3871. string placedate2 = GetPostString("placedate2");
  3872. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  3873. if (fdw.Length > 0) lw.Add(fdw);
  3874. string price1 = GetPostString("price1");
  3875. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3876. string price2 = GetPostString("price2");
  3877. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3878. string unusualCon = GetPostString("unusualcon");
  3879. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  3880. string otherMemo = GetPostString("otherMemo");
  3881. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3882. string posTag = CurrentUser.UserPost.Post.Code;
  3883. if (posTag == "Supplier")
  3884. {
  3885. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3886. }
  3887. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  3888. lw.Add(string.Format("type != 'PDD' "));
  3889. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  3890. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  3891. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3892. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3893. writeGridDataTableJson(dStruct.TotalCount, dt);
  3894. }
  3895. public void get_erp_changedeliverylist()
  3896. {
  3897. DataStruct dStruct = GetPostStruct();
  3898. List<string> lw = new List<string>();
  3899. string tid = GetPostString("ctid");
  3900. if (tid.Length > 0)
  3901. {
  3902. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3903. if (tid.Length > 5)
  3904. {
  3905. List<string> tids = getTidByCtidLike(tid);
  3906. if (tids.Count > 0 && tids.Count < 10)
  3907. {
  3908. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3909. }
  3910. }
  3911. lw.Add(tid_sql);
  3912. }
  3913. string shopname = GetPostString("shopname");
  3914. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3915. string buyernick = GetPostString("buyer_nick");
  3916. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3917. //if (tid.Length == 0 && buyernick.Length == 0)
  3918. //{
  3919. // lw.Add(string.Format("IsRefund<={0}", 1));
  3920. //}
  3921. string customer = GetPostString("customer");
  3922. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3923. string design = GetPostString("design");
  3924. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3925. string orderState = GetPostString("orderState");
  3926. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3927. string address = GetPostString("address");
  3928. 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));
  3929. string sellermemo = GetPostString("seller_memo");
  3930. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3931. string supplier = GetPostString("supplier");
  3932. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3933. string OrderArea = GetPostString("order_area");
  3934. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  3935. string placedate1 = GetPostString("placedate1");
  3936. string placedate2 = GetPostString("placedate2");
  3937. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  3938. if (fdw.Length > 0) lw.Add(fdw);
  3939. string price1 = GetPostString("price1");
  3940. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3941. string price2 = GetPostString("price2");
  3942. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3943. string unusualCon = GetPostString("unusualcon");
  3944. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  3945. string otherMemo = GetPostString("otherMemo");
  3946. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3947. string posTag = CurrentUser.UserPost.Post.Code;
  3948. if (posTag == "Supplier")
  3949. {
  3950. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3951. }
  3952. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  3953. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  3954. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  3955. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3956. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3957. /*if (tid.Length > 0)
  3958. {
  3959. List<string> tids = new List<string>();
  3960. if (dt != null && dt.Rows.Count > 0)
  3961. {
  3962. foreach (DataRow item in dt.Rows)
  3963. {
  3964. tids.Add("'" + item["tid"] + "'");
  3965. }
  3966. }
  3967. if (tids.Count > 0)
  3968. {
  3969. lw.RemoveAt(0);
  3970. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  3971. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3972. dt = WebCache.GetData("view_erptradecell", dStruct);
  3973. }
  3974. }*/
  3975. writeGridDataTableJson(dStruct.TotalCount, dt);
  3976. }
  3977. public void get_erp_pddderiving()
  3978. {
  3979. DataStruct dStruct = GetPostStruct();
  3980. List<string> lw = new List<string>();
  3981. string tid = GetPostString("ctid");
  3982. if (tid.Length > 0)
  3983. {
  3984. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3985. if (tid.Length > 5)
  3986. {
  3987. List<string> tids = getTidByCtidLike(tid);
  3988. if (tids.Count > 0 && tids.Count < 10)
  3989. {
  3990. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3991. }
  3992. }
  3993. lw.Add(tid_sql);
  3994. }
  3995. string shopname = GetPostString("shopname");
  3996. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3997. string buyernick = GetPostString("buyer_nick");
  3998. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3999. //if (tid.Length == 0 && buyernick.Length == 0)
  4000. //{
  4001. // lw.Add(string.Format("IsRefund<={0}", 1));
  4002. //}
  4003. string customer = GetPostString("customer");
  4004. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4005. string design = GetPostString("design");
  4006. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4007. string orderState = GetPostString("orderState");
  4008. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4009. string address = GetPostString("address");
  4010. 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));
  4011. string sellermemo = GetPostString("seller_memo");
  4012. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4013. string supplier = GetPostString("supplier");
  4014. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4015. string OrderArea = GetPostString("order_area");
  4016. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4017. string placedate1 = GetPostString("placedate1");
  4018. string placedate2 = GetPostString("placedate2");
  4019. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4020. if (fdw.Length > 0) lw.Add(fdw);
  4021. string price1 = GetPostString("price1");
  4022. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4023. string price2 = GetPostString("price2");
  4024. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4025. string unusualCon = GetPostString("unusualcon");
  4026. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4027. string posTag = CurrentUser.UserPost.Post.Code;
  4028. if (posTag == "Supplier")
  4029. {
  4030. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4031. }
  4032. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4033. lw.Add(string.Format("type = 'PDD' "));
  4034. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4035. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4036. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4037. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4038. /*if (tid.Length > 0)
  4039. {
  4040. List<string> tids = new List<string>();
  4041. if (dt != null && dt.Rows.Count > 0)
  4042. {
  4043. foreach (DataRow item in dt.Rows)
  4044. {
  4045. tids.Add("'" + item["tid"] + "'");
  4046. }
  4047. }
  4048. if (tids.Count > 0)
  4049. {
  4050. lw.RemoveAt(0);
  4051. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4052. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4053. dt = WebCache.GetData("view_erptradecell", dStruct);
  4054. }
  4055. }*/
  4056. writeGridDataTableJson(dStruct.TotalCount, dt);
  4057. }
  4058. public void get_erp_jdderiving()
  4059. {
  4060. DataStruct dStruct = GetPostStruct();
  4061. List<string> lw = new List<string>();
  4062. string tid = GetPostString("ctid");
  4063. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4064. string shopname = GetPostString("shopname");
  4065. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4066. string buyernick = GetPostString("buyer_nick");
  4067. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4068. //if (tid.Length == 0 && buyernick.Length == 0)
  4069. //{
  4070. // lw.Add(string.Format("IsRefund<={0}", 1));
  4071. //}
  4072. string customer = GetPostString("customer");
  4073. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4074. string design = GetPostString("design");
  4075. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4076. string orderState = GetPostString("orderState");
  4077. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4078. string address = GetPostString("address");
  4079. 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));
  4080. string sellermemo = GetPostString("seller_memo");
  4081. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4082. string supplier = GetPostString("supplier");
  4083. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4084. string OrderArea = GetPostString("order_area");
  4085. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4086. string placedate1 = GetPostString("placedate1");
  4087. string placedate2 = GetPostString("placedate2");
  4088. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4089. if (fdw.Length > 0) lw.Add(fdw);
  4090. string price1 = GetPostString("price1");
  4091. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4092. string price2 = GetPostString("price2");
  4093. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4094. string unusualCon = GetPostString("unusualcon");
  4095. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4096. string posTag = CurrentUser.UserPost.Post.Code;
  4097. if (posTag == "Supplier")
  4098. {
  4099. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4100. }
  4101. lw.Add(string.Format("OrderState = 6 "));
  4102. lw.Add(string.Format("type = 'JD' "));
  4103. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4104. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4105. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4106. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4107. writeGridDataTableJson(dStruct.TotalCount, dt);
  4108. }
  4109. public void get_erp_demoorderlist()
  4110. {
  4111. DataStruct dStruct = GetPostStruct();
  4112. List<string> lw = new List<string>();
  4113. string tid = GetPostString("ctid");
  4114. if (tid.Length > 0)
  4115. {
  4116. string select_tid = getTidByCtid(tid);
  4117. lw.Add(string.Format("tid='{0}'", select_tid));
  4118. }
  4119. string shopname = GetPostString("shopname");
  4120. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4121. string buyernick = GetPostString("buyer_nick");
  4122. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4123. string customer = GetPostString("customer");
  4124. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4125. string design = GetPostString("design");
  4126. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4127. string orderState = GetPostString("orderState");
  4128. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4129. string address = GetPostString("address");
  4130. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4131. string sellermemo = GetPostString("seller_memo");
  4132. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4133. string supplier = GetPostString("supplier");
  4134. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4135. string OrderArea = GetPostString("order_area");
  4136. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4137. string date1 = GetPostString("date1");
  4138. string date2 = GetPostString("date2");
  4139. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4140. if (dw.Length > 0) lw.Add(dw);
  4141. string price1 = GetPostString("price1");
  4142. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4143. string price2 = GetPostString("price2");
  4144. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4145. string posTag = CurrentUser.UserPost.Post.Code;
  4146. if (posTag == "Supplier")
  4147. {
  4148. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4149. }
  4150. //lw.Add(string.Format("OrderState = 6 "));
  4151. lw.Add(string.Format("IsSample={0}", 3));
  4152. lw.Add(string.Format("IsRefund<={0}", 1));
  4153. dStruct.Order = "pay_time desc";
  4154. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4155. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4156. writeGridDataTableJson(dStruct.TotalCount, dt);
  4157. }
  4158. public void save_erp_checkmemo()
  4159. {
  4160. if (UrlPostParmsCheck("ctid"))
  4161. {
  4162. string ctid = GetPostString("ctid");
  4163. CeErpTradeCell entity = null;
  4164. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4165. if (entity != null)
  4166. {
  4167. entity.CheckMemo = GetPostString("CheckMemo");
  4168. entity.Update();
  4169. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4170. if (trade != null)
  4171. {
  4172. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4173. }
  4174. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4175. returnSuccessMsg("保存成功!");
  4176. return;
  4177. }
  4178. returnErrorMsg("找不到记录");
  4179. }
  4180. }
  4181. public void get_erp_returnlist()
  4182. {
  4183. DataStruct dStruct = GetPostStruct();
  4184. List<string> lw = new List<string>();
  4185. string tid = GetPostString("ctid");
  4186. if (tid.Length > 0)
  4187. {
  4188. string select_tid = getTidByCtid(tid);
  4189. lw.Add(string.Format("tid='{0}'", select_tid));
  4190. }
  4191. string shopname = GetPostString("shopname");
  4192. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4193. string buyernick = GetPostString("buyer_nick");
  4194. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4195. string customer = GetPostString("customer");
  4196. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4197. string design = GetPostString("design");
  4198. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4199. string orderState = GetPostString("orderState");
  4200. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4201. string address = GetPostString("address");
  4202. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4203. string sellermemo = GetPostString("seller_memo");
  4204. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4205. string supplier = GetPostString("supplier");
  4206. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4207. string date1 = GetPostString("date1");
  4208. string date2 = GetPostString("date2");
  4209. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4210. if (dw.Length > 0) lw.Add(dw);
  4211. string bdate1 = GetPostString("backdate1");
  4212. string bdate2 = GetPostString("backdate2");
  4213. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4214. if (dw_back.Length > 0) lw.Add(dw_back);
  4215. string price1 = GetPostString("price1");
  4216. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4217. string price2 = GetPostString("price2");
  4218. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4219. lw.Add(string.Format("IsReturn>0"));
  4220. lw.Add(string.Format("IsXianHuo=0"));
  4221. lw.Add(string.Format("IsReturn!=3"));
  4222. string backtype = GetPostString("backtype");
  4223. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4224. dStruct.Order = "FinishDesignTime desc";
  4225. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4226. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4227. writeGridDataTableJson(dStruct.TotalCount, dt);
  4228. }
  4229. public void get_erp_today_sumreturn()
  4230. {
  4231. DataStruct dStruct = GetPostStruct();
  4232. List<string> lw = new List<string>();
  4233. string bdate1 = GetPostString("returnTimeS");
  4234. string bdate2 = GetPostString("returnTimeE");
  4235. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4236. if (dw_back.Length > 0) lw.Add(dw_back);
  4237. lw.Add(string.Format("IsReturn=0"));
  4238. lw.Add(string.Format("IsXianHuo=0"));
  4239. string mainWhere = string.Join(" and ", lw.ToArray());
  4240. string sql = "";
  4241. if (dw_back.Length > 0)
  4242. {
  4243. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4244. }
  4245. else
  4246. {
  4247. 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 + "'";
  4248. }
  4249. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4250. decimal total = 0, today_finish = 0;
  4251. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4252. {
  4253. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4254. }
  4255. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4256. {
  4257. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4258. }
  4259. var res = new
  4260. {
  4261. data = total,
  4262. data1 = today_finish,
  4263. };
  4264. string ro_jsond = JsonConvert.SerializeObject(res);
  4265. returnSuccess(ro_jsond);
  4266. return;
  4267. }
  4268. public void get_erp_allreturnlist()
  4269. {
  4270. DataStruct dStruct = GetPostStruct();
  4271. List<string> lw = new List<string>();
  4272. string tid = GetPostString("ctid");
  4273. if (tid.Length > 0)
  4274. {
  4275. string select_tid = getTidByCtid(tid);
  4276. lw.Add(string.Format("tid='{0}'", select_tid));
  4277. }
  4278. string shopname = GetPostString("shopname");
  4279. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4280. string buyernick = GetPostString("buyer_nick");
  4281. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4282. string customer = GetPostString("customer");
  4283. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4284. string design = GetPostString("design");
  4285. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4286. string orderState = GetPostString("orderState");
  4287. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4288. string address = GetPostString("address");
  4289. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4290. string sellermemo = GetPostString("seller_memo");
  4291. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4292. string supplier = GetPostString("supplier");
  4293. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4294. string date1 = GetPostString("date1");
  4295. string date2 = GetPostString("date2");
  4296. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4297. if (dw.Length > 0) lw.Add(dw);
  4298. string bdate1 = GetPostString("backdate1");
  4299. string bdate2 = GetPostString("backdate2");
  4300. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4301. if (dw_back.Length > 0) lw.Add(dw_back);
  4302. string price1 = GetPostString("price1");
  4303. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4304. string price2 = GetPostString("price2");
  4305. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4306. string backreason = GetPostString("backreason");
  4307. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4308. lw.Add(string.Format("IsXianHuo=0"));
  4309. lw.Add(string.Format("ReturnTime != ''"));
  4310. string backtype = GetPostString("backtype");
  4311. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4312. dStruct.Order = "FinishDesignTime desc";
  4313. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4314. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4315. writeGridDataTableJson(dStruct.TotalCount, dt);
  4316. }
  4317. public void get_erp_aftersalereturnlist()
  4318. {
  4319. DataStruct dStruct = GetPostStruct();
  4320. List<string> lw = new List<string>();
  4321. string tid = GetPostString("ctid");
  4322. if (tid.Length > 0)
  4323. {
  4324. string select_tid = getTidByCtid(tid);
  4325. lw.Add(string.Format("tid='{0}'", select_tid));
  4326. }
  4327. string shopname = GetPostString("shopname");
  4328. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4329. string buyernick = GetPostString("buyer_nick");
  4330. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4331. string customer = GetPostString("customer");
  4332. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4333. string design = GetPostString("design");
  4334. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4335. string orderState = GetPostString("orderState");
  4336. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4337. string address = GetPostString("address");
  4338. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4339. string sellermemo = GetPostString("seller_memo");
  4340. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4341. string supplier = GetPostString("supplier");
  4342. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4343. string date1 = GetPostString("date1");
  4344. string date2 = GetPostString("date2");
  4345. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4346. if (dw.Length > 0) lw.Add(dw);
  4347. string bdate1 = GetPostString("backdate1");
  4348. string bdate2 = GetPostString("backdate2");
  4349. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4350. if (dw_back.Length > 0) lw.Add(dw_back);
  4351. string price1 = GetPostString("price1");
  4352. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4353. string price2 = GetPostString("price2");
  4354. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4355. lw.Add(string.Format("IsReturn=3"));
  4356. string backtype = GetPostString("backtype");
  4357. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4358. string backreason = GetPostString("backreason");
  4359. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4360. dStruct.Order = "ReturnTime desc";
  4361. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4362. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4363. writeGridDataTableJson(dStruct.TotalCount, dt);
  4364. }
  4365. public void get_erp_xianhuoreturnlist()
  4366. {
  4367. DataStruct dStruct = GetPostStruct();
  4368. List<string> lw = new List<string>();
  4369. string tid = GetPostString("ctid");
  4370. if (tid.Length > 0)
  4371. {
  4372. string select_tid = getTidByCtid(tid);
  4373. lw.Add(string.Format("tid='{0}'", select_tid));
  4374. }
  4375. string shopname = GetPostString("shopname");
  4376. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4377. string buyernick = GetPostString("buyer_nick");
  4378. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4379. string customer = GetPostString("customer");
  4380. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4381. string design = GetPostString("design");
  4382. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4383. string orderState = GetPostString("orderState");
  4384. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4385. string address = GetPostString("address");
  4386. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4387. string sellermemo = GetPostString("seller_memo");
  4388. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4389. string supplier = GetPostString("supplier");
  4390. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4391. string OrderArea = GetPostString("order_area");
  4392. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4393. string date1 = GetPostString("date1");
  4394. string date2 = GetPostString("date2");
  4395. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4396. if (dw.Length > 0) lw.Add(dw);
  4397. string price1 = GetPostString("price1");
  4398. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4399. string price2 = GetPostString("price2");
  4400. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4401. string posTag = CurrentUser.UserPost.Post.Code;
  4402. if (posTag == "Supplier")
  4403. {
  4404. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4405. }
  4406. lw.Add(string.Format("OrderState=6 "));
  4407. lw.Add(string.Format("IsXianHuo=1 "));
  4408. lw.Add(string.Format("IsReturn>0 "));
  4409. lw.Add(string.Format("IsReturn!=3"));
  4410. lw.Add(string.Format("IsRefund<={0}", 1));
  4411. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4412. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4413. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4414. writeGridDataTableJson(dStruct.TotalCount, dt);
  4415. }
  4416. public void set_erp_orderdelivery()
  4417. {
  4418. if (UrlPostParmsCheck("ctid"))
  4419. {
  4420. string eid = GetPostString("ctid");
  4421. CeErpTradeCell entity = null;
  4422. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4423. if (entity != null)
  4424. {
  4425. if (entity.OrderState >= 7)
  4426. {
  4427. returnErrorMsg("此单已发货,无需重复发货");
  4428. return;
  4429. }
  4430. if (entity.OrderState != 6)
  4431. {
  4432. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4433. return;
  4434. }
  4435. string shop = GetPostString("seller_nick");
  4436. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4437. string comName = GetPostString("comName");
  4438. string comCode = GetPostString("comCode");
  4439. string outSid = GetPostString("outSid");
  4440. string deliveryType = GetPostString("deliveryType");
  4441. string deliveryMemo = GetPostString("deliveryMemo");
  4442. outSid = outSid.Trim();
  4443. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4444. if (mainEn == null)
  4445. {
  4446. returnErrorMsg("找不到原始订单记录");
  4447. return;
  4448. }
  4449. bool isInitOrderDeliv = false;
  4450. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4451. {
  4452. isInitOrderDeliv = true;
  4453. }
  4454. string apires = "";
  4455. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4456. 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)
  4457. {
  4458. apires = "发货成功true";
  4459. }
  4460. else
  4461. {
  4462. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4463. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4464. }
  4465. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4466. {
  4467. entity.OrderState = 7;//发货后订单已发货
  4468. entity.OutSid = outSid;
  4469. entity.MemoOpt = 0;
  4470. entity.UpdateTime = DateTime.Now;
  4471. entity.FinishDeliveryTime = DateTime.Now;
  4472. entity.Update();
  4473. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4474. commonHelper.UpdateRelationOrder(entity.ctid);
  4475. //还要插入快递信息到 快递信息表
  4476. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4477. exinfo.tid = eid;
  4478. exinfo.out_sid = outSid;
  4479. exinfo.company_code = comCode;
  4480. exinfo.company_name = comName;
  4481. exinfo.delivery_memo = deliveryMemo;
  4482. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4483. exinfo.deliveryType = deliveryType;
  4484. exinfo.Create();
  4485. returnSuccessMsg("发货操作成功!");
  4486. commonHelper.UpdateRelationOrder(entity.ctid);
  4487. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4488. CeErpSukuraData.createInfo(entity.ctid, 4);
  4489. if (entity.SupplierId == 64)
  4490. {
  4491. commonHelper.sendCytExpress(exinfo);
  4492. }
  4493. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4494. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4495. }
  4496. else
  4497. {
  4498. string errmsg = commonHelper.KeepChinese(apires);
  4499. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4500. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4501. }
  4502. return;
  4503. }
  4504. returnErrorMsg("找不到订单记录");
  4505. }
  4506. }
  4507. public void set_erp_multidelivery()
  4508. {
  4509. string eids = GetPostString("tids");
  4510. string[] eidList = eids.Split(',');
  4511. if (eidList.Length <= 0)
  4512. {
  4513. returnErrorMsg("发货不能为空");
  4514. return;
  4515. }
  4516. foreach (string ctid in eidList)
  4517. {
  4518. if (ctid.Length <= 0) continue;
  4519. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4520. if (expInfo != null)
  4521. {
  4522. StringBuilder sql = new StringBuilder();
  4523. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4524. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4525. if (dt.Rows.Count > 0)
  4526. {
  4527. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4528. {
  4529. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4530. expInfo.state = "异常";
  4531. expInfo.isMultiDelivery = 1;
  4532. expInfo.Update();
  4533. continue;
  4534. }
  4535. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4536. {
  4537. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4538. expInfo.state = "异常";
  4539. expInfo.Update();
  4540. continue;
  4541. }
  4542. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4543. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4544. bool isInitOrderDeliv = false;
  4545. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4546. {
  4547. isInitOrderDeliv = true;
  4548. expInfo.isMultiDelivery = 1;
  4549. }
  4550. if (ctid.IndexOf("N") != -1)
  4551. {
  4552. StringBuilder sqlbucha = new StringBuilder();
  4553. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4554. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4555. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4556. commonHelper.UpdateRelationOrder(ctid);
  4557. expInfo.delivery_memo = "发货成功";
  4558. expInfo.state = "发货成功";
  4559. expInfo.isMultiDelivery = 1;
  4560. expInfo.Update();
  4561. }
  4562. else
  4563. {
  4564. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4565. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4566. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4567. {
  4568. expInfo.delivery_memo = "发货成功";
  4569. expInfo.state = "发货成功";
  4570. expInfo.isMultiDelivery = 1;
  4571. expInfo.Update();
  4572. commonHelper.UpdateRelationOrder(ctid);
  4573. CeErpSukuraData.createInfo(ctid, 4);
  4574. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4575. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4576. }
  4577. else
  4578. {
  4579. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4580. expInfo.state = "异常";
  4581. expInfo.Update();
  4582. }
  4583. }
  4584. }
  4585. }
  4586. }
  4587. returnSuccessMsg("操作完成");
  4588. }
  4589. public void reset_erp_memoopt()
  4590. {
  4591. if (UrlPostParmsCheck("ctid"))
  4592. {
  4593. string eid = GetPostString("ctid");
  4594. CeErpTradeCell entity = null;
  4595. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4596. if (entity != null)
  4597. {
  4598. string stropt = "";
  4599. if (entity.MemoOpt == 1)
  4600. {
  4601. stropt = "“改稿”";
  4602. }
  4603. else if (entity.MemoOpt == 2)
  4604. {
  4605. stropt = "“定稿”";
  4606. }
  4607. else if (entity.MemoOpt == 3)
  4608. {
  4609. stropt = "“完成查货”";
  4610. CeErpSukuraData.createInfo(entity.ctid, 6);
  4611. }
  4612. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4613. entity.UpdateTime = DateTime.Now;
  4614. entity.MemoOpt = 0;
  4615. entity.Update();
  4616. returnSuccessMsg("操作成功!");
  4617. return;
  4618. }
  4619. returnErrorMsg("找不到记录");
  4620. }
  4621. }
  4622. public void get_erp_deliveryunusual()
  4623. {
  4624. DataStruct dStruct = GetPostStruct();
  4625. List<string> lw = new List<string>();
  4626. string tid = GetPostString("ctid");
  4627. if (tid.Length > 0)
  4628. {
  4629. string select_tid = getTidByCtid(tid);
  4630. lw.Add(string.Format("tid='{0}'", select_tid));
  4631. }
  4632. string shopname = GetPostString("shopname");
  4633. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4634. string buyernick = GetPostString("buyer_nick");
  4635. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4636. string customer = GetPostString("customer");
  4637. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4638. string design = GetPostString("design");
  4639. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4640. string sellermemo = GetPostString("seller_memo");
  4641. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4642. string supplier = GetPostString("supplier");
  4643. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4644. string date1 = GetPostString("date1");
  4645. string date2 = GetPostString("date2");
  4646. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4647. if (dw.Length > 0) lw.Add(dw);
  4648. string placedate1 = GetPostString("placedate1");
  4649. string placedate2 = GetPostString("placedate2");
  4650. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4651. if (dw_place.Length > 0) lw.Add(dw_place);
  4652. string price1 = GetPostString("price1");
  4653. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4654. string price2 = GetPostString("price2");
  4655. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4656. string unusualCon = GetPostString("unusualcon");
  4657. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4658. string posTag = CurrentUser.UserPost.Post.Code;
  4659. if (posTag == "Supplier")
  4660. {
  4661. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4662. }
  4663. lw.Add(string.Format("OrderState = 6"));
  4664. lw.Add(string.Format("UnusualTag = 5"));
  4665. lw.Add(string.Format("IsRefund<={0}", 1));
  4666. dStruct.Order = "FinishPlaceTime desc";
  4667. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4668. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4669. writeGridDataTableJson(dStruct.TotalCount, dt);
  4670. }
  4671. public void get_erp_deliveryedlist()
  4672. {
  4673. DataStruct dStruct = GetPostStruct();
  4674. List<string> lw = new List<string>();
  4675. string tid = GetPostString("ctid");
  4676. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4677. string shopname = GetPostString("shopname");
  4678. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4679. string buyernick = GetPostString("buyer_nick");
  4680. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4681. string customer = GetPostString("customer");
  4682. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4683. string design = GetPostString("design");
  4684. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4685. string sellermemo = GetPostString("seller_memo");
  4686. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4687. string logistics = GetPostString("logistics");
  4688. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4689. string date1 = GetPostString("date1");
  4690. string date2 = GetPostString("date2");
  4691. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4692. //if (dw.Length > 0) lw.Add(dw);
  4693. string placedate1 = GetPostString("placedate1");
  4694. string placedate2 = GetPostString("placedate2");
  4695. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4696. if (fdw.Length > 0) lw.Add(fdw);
  4697. string devdate1 = GetPostString("deliverydate1");
  4698. string devdate2 = GetPostString("deliverydate2");
  4699. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4700. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4701. string price1 = GetPostString("price1");
  4702. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4703. string price2 = GetPostString("price2");
  4704. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4705. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4706. {
  4707. if (tid.Length > 0)
  4708. {
  4709. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4710. if (tid.Length > 5)
  4711. {
  4712. List<string> tids = getTidByCtidLike(tid);
  4713. if (tids.Count > 0 && tids.Count < 10)
  4714. {
  4715. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4716. }
  4717. }
  4718. lw.Add(tid_sql);
  4719. }
  4720. if (buyernick.Length > 0)
  4721. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4722. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4723. if (dw.Length > 0) lw.Add(dw);
  4724. }
  4725. else
  4726. {
  4727. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4728. }
  4729. string posTag = CurrentUser.UserPost.Post.Code;
  4730. if (posTag == "Supplier")
  4731. {
  4732. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4733. }
  4734. else
  4735. {
  4736. string supplier = GetPostString("supplier");
  4737. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4738. }
  4739. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4740. lw.Add(string.Format("type != 'PDD' "));
  4741. lw.Add(string.Format("IsRefund!={0}", 2));
  4742. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4743. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4744. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4745. /*if (tid.Length > 0)
  4746. {
  4747. List<string> tids = new List<string>();
  4748. if (dt != null && dt.Rows.Count > 0)
  4749. {
  4750. foreach (DataRow item in dt.Rows)
  4751. {
  4752. tids.Add("'" + item["tid"] + "'");
  4753. }
  4754. }
  4755. if (tids.Count > 0)
  4756. {
  4757. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4758. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4759. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4760. dt = WebCache.GetData("view_erptradecell", dStruct);
  4761. }
  4762. }*/
  4763. if (dt != null)
  4764. {
  4765. foreach (DataRow dr in dt.Rows)
  4766. {
  4767. 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();
  4768. }
  4769. }
  4770. writeGridDataTableJson(dStruct.TotalCount, dt);
  4771. }
  4772. public void get_erp_pdddeliveryed()
  4773. {
  4774. DataStruct dStruct = GetPostStruct();
  4775. List<string> lw = new List<string>();
  4776. string tid = GetPostString("ctid");
  4777. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4778. string shopname = GetPostString("shopname");
  4779. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4780. string buyernick = GetPostString("buyer_nick");
  4781. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4782. string customer = GetPostString("customer");
  4783. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4784. string design = GetPostString("design");
  4785. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4786. string sellermemo = GetPostString("seller_memo");
  4787. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4788. string logistics = GetPostString("logistics");
  4789. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4790. string date1 = GetPostString("date1");
  4791. string date2 = GetPostString("date2");
  4792. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4793. //if (dw.Length > 0) lw.Add(dw);
  4794. string placedate1 = GetPostString("placedate1");
  4795. string placedate2 = GetPostString("placedate2");
  4796. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4797. if (fdw.Length > 0) lw.Add(fdw);
  4798. string devdate1 = GetPostString("deliverydate1");
  4799. string devdate2 = GetPostString("deliverydate2");
  4800. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4801. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4802. string price1 = GetPostString("price1");
  4803. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4804. string price2 = GetPostString("price2");
  4805. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4806. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4807. {
  4808. if (tid.Length > 0)
  4809. {
  4810. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4811. if (tid.Length > 5)
  4812. {
  4813. List<string> tids = getTidByCtidLike(tid);
  4814. if (tids.Count > 0 && tids.Count < 10)
  4815. {
  4816. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4817. }
  4818. }
  4819. lw.Add(tid_sql);
  4820. }
  4821. if (buyernick.Length > 0)
  4822. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4823. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4824. if (dw.Length > 0) lw.Add(dw);
  4825. }
  4826. else
  4827. {
  4828. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4829. }
  4830. string posTag = CurrentUser.UserPost.Post.Code;
  4831. if (posTag == "Supplier")
  4832. {
  4833. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4834. }
  4835. else
  4836. {
  4837. string supplier = GetPostString("supplier");
  4838. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4839. }
  4840. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4841. lw.Add(string.Format("type = 'PDD' "));
  4842. lw.Add(string.Format("IsRefund!={0}", 2));
  4843. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4844. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4845. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4846. /* if (tid.Length > 0)
  4847. {
  4848. List<string> tids = new List<string>();
  4849. if (dt != null && dt.Rows.Count > 0)
  4850. {
  4851. foreach (DataRow item in dt.Rows)
  4852. {
  4853. tids.Add("'" + item["tid"] + "'");
  4854. }
  4855. }
  4856. if (tids.Count > 0)
  4857. {
  4858. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4859. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4860. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4861. dt = WebCache.GetData("view_erptradecell", dStruct);
  4862. }
  4863. }*/
  4864. foreach (DataRow dr in dt.Rows)
  4865. {
  4866. 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();
  4867. }
  4868. writeGridDataTableJson(dStruct.TotalCount, dt);
  4869. }
  4870. public void get_erp_jddeliveryed()
  4871. {
  4872. DataStruct dStruct = GetPostStruct();
  4873. List<string> lw = new List<string>();
  4874. string tid = GetPostString("ctid");
  4875. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4876. string shopname = GetPostString("shopname");
  4877. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4878. string buyernick = GetPostString("buyer_nick");
  4879. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4880. string customer = GetPostString("customer");
  4881. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4882. string design = GetPostString("design");
  4883. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4884. string sellermemo = GetPostString("seller_memo");
  4885. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4886. string date1 = GetPostString("date1");
  4887. string date2 = GetPostString("date2");
  4888. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4889. //if (dw.Length > 0) lw.Add(dw);
  4890. string placedate1 = GetPostString("placedate1");
  4891. string placedate2 = GetPostString("placedate2");
  4892. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4893. if (fdw.Length > 0) lw.Add(fdw);
  4894. string devdate1 = GetPostString("deliverydate1");
  4895. string devdate2 = GetPostString("deliverydate2");
  4896. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4897. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4898. string price1 = GetPostString("price1");
  4899. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4900. string price2 = GetPostString("price2");
  4901. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4902. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4903. {
  4904. if (tid.Length > 0)
  4905. lw.Add(string.Format("ctid like '%{0}%'", tid));
  4906. if (buyernick.Length > 0)
  4907. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4908. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4909. if (dw.Length > 0) lw.Add(dw);
  4910. }
  4911. else
  4912. {
  4913. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4914. }
  4915. string posTag = CurrentUser.UserPost.Post.Code;
  4916. if (posTag == "Supplier")
  4917. {
  4918. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4919. }
  4920. else
  4921. {
  4922. string supplier = GetPostString("supplier");
  4923. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4924. }
  4925. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4926. lw.Add(string.Format("type = 'JD' "));
  4927. lw.Add(string.Format("IsRefund!={0}", 2));
  4928. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4929. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4930. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4931. foreach (DataRow dr in dt.Rows)
  4932. {
  4933. 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();
  4934. }
  4935. writeGridDataTableJson(dStruct.TotalCount, dt);
  4936. }
  4937. public void get_erp_allplacelist()
  4938. {
  4939. DataStruct dStruct = GetPostStruct();
  4940. List<string> lw = new List<string>();
  4941. string tid = GetPostString("ctid");
  4942. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  4943. string shopname = GetPostString("shopname");
  4944. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4945. string buyernick = GetPostString("buyer_nick");
  4946. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4947. string customer = GetPostString("customer");
  4948. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4949. string design = GetPostString("design");
  4950. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4951. string sellermemo = GetPostString("seller_memo");
  4952. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4953. string supplier = GetPostString("supplier");
  4954. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  4955. string date1 = GetPostString("date1");
  4956. string date2 = GetPostString("date2");
  4957. string pldate1 = GetPostString("placedate1");
  4958. string pldate2 = GetPostString("placedate2");
  4959. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4960. //if (dw.Length > 0) lw.Add(dw);
  4961. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  4962. {
  4963. if (tid.Length > 0)
  4964. {
  4965. string select_tid = getTidByCtid(tid);
  4966. lw.Add(string.Format("tid='{0}'", select_tid));
  4967. }
  4968. if (buyernick.Length > 0)
  4969. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4970. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4971. if (dw.Length > 0) lw.Add(dw);
  4972. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  4973. if (dw_place.Length > 0) lw.Add(dw_place);
  4974. }
  4975. else
  4976. {
  4977. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  4978. {
  4979. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4980. }
  4981. }
  4982. string price1 = GetPostString("price1");
  4983. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4984. string price2 = GetPostString("price2");
  4985. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4986. string posTag = CurrentUser.UserPost.Post.Code;
  4987. if (posTag == "Supplier")
  4988. {
  4989. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4990. }
  4991. lw.Add(string.Format("OrderState >= 6"));
  4992. lw.Add(string.Format("IsSample != 2 "));
  4993. //lw.Add(string.Format("isDianziOrder = 0 "));
  4994. lw.Add(string.Format("SupplierId > 0 "));
  4995. //lw.Add(string.Format("IsRefund<={0}", 1));
  4996. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4997. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4998. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  4999. foreach (DataRow dr in dt.Rows)
  5000. {
  5001. 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();
  5002. }
  5003. writeGridDataTableJson(dStruct.TotalCount, dt);
  5004. }
  5005. public void get_erp_financeallplacelist()
  5006. {
  5007. DataStruct dStruct = GetPostStruct();
  5008. List<string> lw = new List<string>();
  5009. string tid = GetPostString("ctid");
  5010. string shopname = GetPostString("shopname");
  5011. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5012. string buyernick = GetPostString("buyer_nick");
  5013. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5014. string customer = GetPostString("customer");
  5015. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5016. string design = GetPostString("design");
  5017. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5018. string sellermemo = GetPostString("seller_memo");
  5019. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5020. string supplier = GetPostString("supplier");
  5021. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5022. string date1 = GetPostString("date1");
  5023. string date2 = GetPostString("date2");
  5024. string pldate1 = GetPostString("placedate1");
  5025. string pldate2 = GetPostString("placedate2");
  5026. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5027. {
  5028. if (tid.Length > 0)
  5029. {
  5030. string select_tid = getTidByCtid(tid);
  5031. lw.Add(string.Format("tid='{0}'", select_tid));
  5032. }
  5033. if (buyernick.Length > 0)
  5034. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5035. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5036. if (dw.Length > 0) lw.Add(dw);
  5037. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5038. if (dw_place.Length > 0) lw.Add(dw_place);
  5039. }
  5040. else
  5041. {
  5042. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5043. {
  5044. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5045. }
  5046. }
  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. string posTag = CurrentUser.UserPost.Post.Code;
  5052. if (posTag == "Supplier")
  5053. {
  5054. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5055. }
  5056. //lw.Add(string.Format("OrderState >= 6"));
  5057. lw.Add(string.Format("IsSample != 2 "));
  5058. lw.Add(string.Format("isDianziOrder = 0 "));
  5059. //lw.Add(string.Format("IsRefund<={0}", 1));
  5060. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5061. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5062. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5063. foreach (DataRow dr in dt.Rows)
  5064. {
  5065. 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();
  5066. }
  5067. writeGridDataTableJson(dStruct.TotalCount, dt);
  5068. }
  5069. public void get_erp_expresslist()
  5070. {
  5071. int listtype = GetInt("ltype");
  5072. DataStruct dStruct = GetPostStruct();
  5073. List<string> lw = new List<string>();
  5074. string tid = GetPostString("tid");
  5075. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5076. string outsid = GetPostString("out_sid");
  5077. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5078. string importer = GetPostString("ImportUserName");
  5079. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5080. string file = GetPostString("import_file");
  5081. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5082. string printman = GetPostString("printman");
  5083. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5084. string date1 = GetPostString("date1");
  5085. string date2 = GetPostString("date2");
  5086. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5087. if (dw.Length > 0) lw.Add(dw);
  5088. string fdate1 = GetPostString("finishdate1");
  5089. string fdate2 = GetPostString("finishdate2");
  5090. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5091. if (fdw.Length > 0) lw.Add(fdw);
  5092. string supplierId = GetPostString("supplierId");
  5093. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5094. if (listtype == 1)
  5095. {
  5096. lw.Add(string.Format("importUserId !=0"));
  5097. }
  5098. string posTag = CurrentUser.UserPost.Post.Code;
  5099. if (posTag == "Supplier")
  5100. {
  5101. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5102. }
  5103. if (dStruct.PageSize != 100000)
  5104. {
  5105. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5106. }
  5107. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5108. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5109. writeGridDataTableJson(dStruct.TotalCount, dt);
  5110. }
  5111. public void set_erp_buchaorderdelivery()
  5112. {
  5113. if (UrlPostParmsCheck("ctid"))
  5114. {
  5115. string eid = GetPostString("ctid");
  5116. CeErpTradeCell entity = null;
  5117. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5118. if (entity != null)
  5119. {
  5120. if (entity.IsSample != 2)
  5121. {
  5122. returnErrorMsg("补差价单才能标记为已发货");
  5123. return;
  5124. }
  5125. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5126. entity.OrderState = 7;
  5127. entity.Update();
  5128. returnSuccessMsg("操作成功!");
  5129. return;
  5130. }
  5131. returnErrorMsg("找不到记录");
  5132. }
  5133. }
  5134. public void get_stdtemplates()
  5135. {
  5136. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5137. //string res = taobaoHelper.test();
  5138. string res = apiHelper.API_PrintTemplate();
  5139. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5140. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5141. {
  5142. int sidx = res.IndexOf("error_code");
  5143. int eidx = res.IndexOf("success");
  5144. string msg = res.Substring(sidx, eidx - sidx);
  5145. returnErrorMsg(msg);
  5146. return;
  5147. }
  5148. if (res.Length <= 0)
  5149. {
  5150. returnErrorMsg("模板数据为空!");
  5151. return;
  5152. }
  5153. ReturnSuccess(res);
  5154. }
  5155. public void cancel_print_order()
  5156. {
  5157. if (UrlPostParmsCheck("ctid"))
  5158. {
  5159. string ctid = GetPostString("ctid");
  5160. CeErpTradeCell entity = null;
  5161. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5162. if (entity != null)
  5163. {
  5164. string res = "";
  5165. string code = entity.LastBillWaybillCode;
  5166. if (code == "")
  5167. {
  5168. code = entity.OutSid;
  5169. }
  5170. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5171. XLog.SaveLog(0, "取消面单" + res);
  5172. }
  5173. }
  5174. }
  5175. public void set_erp_printwaybill()
  5176. {
  5177. if (UrlPostParmsCheck("ctid"))
  5178. {
  5179. string ctid = GetPostString("ctid");
  5180. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5181. string cpName = GetPostString("cpname");
  5182. string isTogether = GetPostString("together");
  5183. //var res_obj = new
  5184. //{
  5185. // restype = 1,
  5186. // 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\"}"
  5187. //};
  5188. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5189. //ReturnSuccess(ro_json);
  5190. //return;
  5191. bool isUseLastWayBillCode = false;
  5192. CeErpTradeCell entity = null;
  5193. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5194. if (entity != null)
  5195. {
  5196. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5197. {
  5198. isUseLastWayBillCode = true;
  5199. }
  5200. if (entity.OrderState == 7 && "2".Equals(isTogether))
  5201. {
  5202. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5203. return;
  5204. }
  5205. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5206. {
  5207. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5208. return;
  5209. }
  5210. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5211. {
  5212. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5213. return;
  5214. }
  5215. }
  5216. string res = "";
  5217. Api_waybill_code_response_Obj fullObj = null;
  5218. string pData_str = "";
  5219. string curUseWayBillCode = "";
  5220. if (isUseLastWayBillCode == false)
  5221. {
  5222. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5223. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5224. if (res.IndexOf("failure") != -1)
  5225. {
  5226. //int idx = res.IndexOf("sub_message");
  5227. //int idx2 = res.IndexOf("flag");
  5228. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5229. string errMsgNeed = commonHelper.KeepChinese(res);
  5230. var res_objd = new
  5231. {
  5232. restype = 0,
  5233. data = "获取面单失败" + errMsgNeed
  5234. };
  5235. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5236. returnSuccess(ro_jsond);
  5237. if (res.IndexOf("停发") != -1)
  5238. {
  5239. entity.UnusualCon = "物流停发";
  5240. entity.Update();
  5241. }
  5242. //returnErrorMsg("获取面单失败,"+emsg);
  5243. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5244. return;
  5245. }
  5246. else if (res.IndexOf("errorMsg") != -1)
  5247. {
  5248. //int idx = res.IndexOf("errorMsg");
  5249. //int idx2 = res.IndexOf("}]}");
  5250. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5251. string errMsgNeed = commonHelper.KeepChinese(res);
  5252. var res_objf = new
  5253. {
  5254. restype = 0,
  5255. data = "获取面单失败2" + errMsgNeed
  5256. };
  5257. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5258. if (res.IndexOf("停发") != -1)
  5259. {
  5260. entity.UnusualCon = "物流停发";
  5261. entity.Update();
  5262. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5263. if (trade != null)
  5264. {
  5265. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5266. }
  5267. }
  5268. returnSuccess(ro_jsonf);
  5269. //returnErrorMsg("获取面单失败," + emsg);
  5270. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5271. return;
  5272. }
  5273. try
  5274. {
  5275. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5276. //res = res.Replace(" ", "");
  5277. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5278. }
  5279. catch (Exception ex)
  5280. {
  5281. XLog.SaveLog(0, "生成fullObj" + res);
  5282. var res_objf = new
  5283. {
  5284. restype = 0,
  5285. data = "生成fullObj发生错误" + ex.Message
  5286. };
  5287. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5288. returnSuccess(ro_jsonf);
  5289. return;
  5290. }
  5291. if (fullObj.response.data.content.Count > 0)
  5292. {
  5293. ContentItem codeObj = fullObj.response.data.content[0];
  5294. if (cpCode.IndexOf("SFFQ-") != -1)
  5295. {
  5296. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5297. }
  5298. else
  5299. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5300. curUseWayBillCode = codeObj.waybillCode;
  5301. }
  5302. else
  5303. {
  5304. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5305. var res_objf = new
  5306. {
  5307. restype = 0,
  5308. data = "生成fullObj找不到快递单号waybillCode"
  5309. };
  5310. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5311. returnSuccess(ro_jsonf);
  5312. return;
  5313. }
  5314. }
  5315. else
  5316. {
  5317. //使用上次打印的快递单号
  5318. if (cpCode == "SFFQ-LY")
  5319. {
  5320. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5321. }
  5322. else
  5323. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5324. curUseWayBillCode = entity.LastBillWaybillCode;
  5325. }
  5326. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5327. {
  5328. var res_obje = new
  5329. {
  5330. restype = 0,
  5331. data = "获取加密打印数据失败"
  5332. };
  5333. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5334. returnSuccess(ro_jsone);
  5335. entity.LastBillCpCode = cpCode;
  5336. entity.LastBillWaybillCode = curUseWayBillCode;
  5337. entity.Update();
  5338. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5339. //returnErrorMsg("获取加密打印数据失败");
  5340. return;
  5341. }
  5342. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5343. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5344. string btnType = "";
  5345. string errorMsg = "";
  5346. if (entity != null)
  5347. {
  5348. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5349. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5350. //cpcode是 YTO-CAINIAO
  5351. //string comCode = cpCode.Split('-')[0].ToString();
  5352. string apires = "";
  5353. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5354. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1)
  5355. {
  5356. if (ctid.IndexOf("N") != -1)
  5357. {
  5358. apires = "发货成功";
  5359. }
  5360. else
  5361. {
  5362. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5363. }
  5364. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5365. //打单后发货
  5366. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5367. {
  5368. try
  5369. {
  5370. btnType = "待发货";
  5371. entity.OutSid = curUseWayBillCode;
  5372. entity.OrderState = 7;
  5373. entity.IsUrgency = false;
  5374. entity.LastBillCpCode = "";
  5375. entity.LastBillWaybillCode = "";
  5376. entity.FinishDeliveryTime = DateTime.Now;
  5377. entity.IsReturn = 0;
  5378. entity.MemoOpt = 0;
  5379. entity.UpdateTime = DateTime.Now;
  5380. entity.Update();
  5381. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5382. //还要插入快递信息到 快递信息表
  5383. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5384. exinfo.tid = entity.ctid;
  5385. exinfo.out_sid = curUseWayBillCode;
  5386. exinfo.company_code = cpCode;
  5387. exinfo.company_name = cpName;
  5388. exinfo.supplierUserName = supplierName;
  5389. exinfo.deliveryType = "发货成功";
  5390. exinfo.print_time = DateTime.Now;
  5391. exinfo.printUser = CurrentUser.UserName;
  5392. exinfo.postData = pData_str;
  5393. exinfo.Create();
  5394. commonHelper.UpdateRelationOrder(entity.ctid);
  5395. CeErpSukuraData.createInfo(ctid, 4);
  5396. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5397. if (entity.SupplierId == 64)
  5398. {
  5399. commonHelper.sendCytExpress(exinfo);
  5400. }
  5401. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5402. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5403. StringBuilder sqlsb = new StringBuilder();
  5404. sqlsb.AppendFormat("update ce_erptradecell with(rowlock) set OrderState=7,OutSid='{2}',FinishDeliveryTime=GETDATE(),UpdateTime=GETDATE(),IsReturn=0,MemoOpt=0 where tid='{0}' and OrderState=6 and SupplierId={1}", entity.tid, entity.SupplierId, curUseWayBillCode);
  5405. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5406. }
  5407. catch (Exception ex)
  5408. {
  5409. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5410. }
  5411. }
  5412. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5413. {
  5414. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5415. if (entity.OrderState == 6)
  5416. {
  5417. entity.OrderState = 7;
  5418. }
  5419. entity.UpdateTime = DateTime.Now;
  5420. entity.FinishDeliveryTime = DateTime.Now;
  5421. btnType = "已发货";
  5422. entity.Update();
  5423. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5424. exinfo.tid = entity.ctid;
  5425. exinfo.out_sid = curUseWayBillCode;
  5426. exinfo.company_code = cpCode;
  5427. exinfo.company_name = cpName;
  5428. exinfo.supplierUserName = supplierName;
  5429. exinfo.deliveryType = "发货成功";
  5430. exinfo.print_time = DateTime.Now;
  5431. exinfo.printUser = CurrentUser.UserName;
  5432. exinfo.postData = pData_str;
  5433. exinfo.Create();
  5434. commonHelper.UpdateRelationOrder(entity.ctid);
  5435. CeErpSukuraData.createInfo(entity.ctid, 4);
  5436. if (entity.SupplierId == 64)
  5437. {
  5438. commonHelper.sendCytExpress(exinfo);
  5439. }
  5440. if (!string.IsNullOrEmpty(isTogether))
  5441. {
  5442. if (Convert.ToInt32(isTogether) > 0)
  5443. {
  5444. StringBuilder sqlsb = new StringBuilder();
  5445. sqlsb.AppendFormat("update ce_erptradecell with(rowlock) set OrderState=7,OutSid='{2}',FinishDeliveryTime=GETDATE(),UpdateTime=GETDATE() where tid='{0}' and OrderState=6 and SupplierId={1}", entity.tid, entity.SupplierId, curUseWayBillCode);
  5446. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5447. }
  5448. }
  5449. //不处理
  5450. }
  5451. else
  5452. {
  5453. entity.UpdateTime = DateTime.Now;
  5454. entity.LastBillCpCode = cpCode;
  5455. entity.LastBillWaybillCode = curUseWayBillCode;
  5456. entity.Update();
  5457. string errmsg = commonHelper.KeepChinese(apires);
  5458. var res_objz = new
  5459. {
  5460. restype = 0,
  5461. data = "打单后发货失败"
  5462. };
  5463. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5464. returnSuccess(ro_jsonz);
  5465. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5466. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5467. return;
  5468. }
  5469. }
  5470. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5471. {
  5472. StringBuilder allSql = new StringBuilder();
  5473. allSql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,tid from view_ErpTradeCell where SupplierId={0} and orderstate=6", entity.SupplierId);
  5474. if (string.IsNullOrEmpty(mainEn.receiverId))
  5475. {
  5476. allSql.AppendFormat(" and (tid='{0}');", entity.tid);
  5477. }
  5478. else
  5479. {
  5480. //查询同车间同状态下的收货地址相同的单子
  5481. allSql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}') );", entity.tid, mainEn.receiverId, entity.IsSF);
  5482. }
  5483. DataTable dt = DbHelper.DbConn.ExecuteDataset(allSql.ToString()).Tables[0];
  5484. List<string> list = new List<string>();
  5485. List<string> send_list = new List<string>();
  5486. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5487. CeErpTrade ceErpTrade = new CeErpTrade();
  5488. foreach (DataRow row in dt.Rows)
  5489. {
  5490. list.Add("'" + row["ctid"] + "'");
  5491. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5492. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5493. if (ctid.IndexOf("N") != -1)
  5494. {
  5495. apires = "发货成功";
  5496. }
  5497. else
  5498. {
  5499. if (!send_list.Contains(ceErpTrade.tid))
  5500. {
  5501. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5502. }
  5503. else
  5504. {
  5505. apires = "发货成功";
  5506. }
  5507. }
  5508. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5509. {
  5510. send_list.Add(ceErpTrade.tid);
  5511. try
  5512. {
  5513. btnType = "待发货";
  5514. ceErpTradeCell.OutSid = curUseWayBillCode;
  5515. ceErpTradeCell.OrderState = 7;
  5516. ceErpTradeCell.IsUrgency = false;
  5517. ceErpTradeCell.LastBillCpCode = "";
  5518. ceErpTradeCell.LastBillWaybillCode = "";
  5519. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5520. ceErpTradeCell.IsReturn = 0;
  5521. ceErpTradeCell.MemoOpt = 0;
  5522. ceErpTradeCell.UpdateTime = DateTime.Now;
  5523. ceErpTradeCell.Update();
  5524. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5525. //还要插入快递信息到 快递信息表
  5526. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5527. exinfo.tid = ceErpTradeCell.ctid;
  5528. exinfo.out_sid = curUseWayBillCode;
  5529. exinfo.company_code = cpCode;
  5530. exinfo.company_name = cpName;
  5531. exinfo.supplierUserName = supplierName;
  5532. exinfo.deliveryType = "发货成功";
  5533. exinfo.print_time = DateTime.Now;
  5534. exinfo.printUser = CurrentUser.UserName;
  5535. exinfo.postData = pData_str;
  5536. exinfo.Create();
  5537. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5538. CeErpSukuraData.createInfo(ctid, 4);
  5539. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5540. if (ceErpTradeCell.SupplierId == 64)
  5541. {
  5542. commonHelper.sendCytExpress(exinfo);
  5543. }
  5544. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5545. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5546. }
  5547. catch (Exception ex)
  5548. {
  5549. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5550. }
  5551. }
  5552. else
  5553. {
  5554. ceErpTradeCell.UpdateTime = DateTime.Now;
  5555. ceErpTradeCell.LastBillCpCode = cpCode;
  5556. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5557. ceErpTradeCell.Update();
  5558. string errmsg = commonHelper.KeepChinese(apires);
  5559. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5560. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5561. }
  5562. }
  5563. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5564. }
  5565. }
  5566. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5567. var res_obj = new
  5568. {
  5569. restype = 1,
  5570. data = pData_str,
  5571. errorMsg
  5572. };
  5573. string ro_json = JsonConvert.SerializeObject(res_obj);
  5574. ReturnSuccess(ro_json);
  5575. return;
  5576. }
  5577. }
  5578. private string GetUTF8String(byte[] vs)
  5579. {
  5580. throw new NotImplementedException();
  5581. }
  5582. public void set_erp_printwaybill_cn()
  5583. {
  5584. if (UrlPostParmsCheck("ctid"))
  5585. {
  5586. string ctid = GetPostString("ctid");
  5587. string cpCode = GetPostString("cpcode");
  5588. string cpName = GetPostString("cpname");
  5589. string tempUrl = GetPostString("tempurl");
  5590. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5591. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5592. //string res = taobaoHelper.test();
  5593. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5594. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5595. {
  5596. int sidx = res.IndexOf("errorMsg");
  5597. int eidx = res.IndexOf("}");
  5598. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5599. var res_objzxx = new
  5600. {
  5601. restype = 0,
  5602. data = msg
  5603. };
  5604. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5605. returnSuccess(ro_jsonzxx);
  5606. //returnErrorMsg(msg);
  5607. return;
  5608. }
  5609. int idx = res.IndexOf("waybillCode");
  5610. int idx2 = res.IndexOf("printData");
  5611. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5612. string eid = GetPostString("ctid");
  5613. CeErpTradeCell entity = null;
  5614. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5615. if (entity != null)
  5616. {
  5617. string osid = entity.OutSid;
  5618. entity.OutSid = osid + "," + outsid;
  5619. entity.FinishDeliveryTime = DateTime.Now;
  5620. entity.OrderState = 7;
  5621. entity.UpdateTime = DateTime.Now;
  5622. entity.IsReturn = 0;
  5623. entity.Update();
  5624. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5625. exinfo.tid = entity.ctid;
  5626. exinfo.out_sid = outsid;
  5627. exinfo.company_code = cpCode;
  5628. exinfo.company_name = cpName;
  5629. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5630. exinfo.deliveryType = "发货成功";
  5631. exinfo.print_time = DateTime.Now;
  5632. exinfo.printUser = CurrentUser.UserName;
  5633. exinfo.Create();
  5634. if (entity.SupplierId == 64)
  5635. {
  5636. commonHelper.sendCytExpress(exinfo);
  5637. }
  5638. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5639. }
  5640. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5641. var res_objz = new
  5642. {
  5643. restype = 1,
  5644. data = res
  5645. };
  5646. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5647. returnSuccess(ro_jsonz);
  5648. //ReturnSuccess(res);
  5649. }
  5650. }
  5651. ////打单,打印面单 获取面单号
  5652. //public void set_erp_printwaybill()
  5653. //{
  5654. // if (UrlPostParmsCheck("ctid"))
  5655. // {
  5656. // string ctid = GetPostString("ctid");
  5657. // string cpCode = GetPostString("cpcode");
  5658. // string tempUrl = GetPostString("tempurl");
  5659. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5660. // //string res = taobaoHelper.test();
  5661. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5662. // if (res.IndexOf("error_response") != -1)
  5663. // {
  5664. // int sidx = res.IndexOf("sub_msg");
  5665. // int eidx = res.IndexOf("request_id");
  5666. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5667. // returnErrorMsg(msg);
  5668. // return;
  5669. // }
  5670. // int idx = res.IndexOf("waybill_code");
  5671. // int idx2 = res.IndexOf("}]}");
  5672. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5673. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5674. // ReturnSuccess(res);
  5675. // }
  5676. //}
  5677. public void cancel_erp_aftersale()
  5678. {
  5679. if (UrlPostParmsCheck("ctid"))
  5680. {
  5681. string eid = GetPostString("ctid");
  5682. CeErpTradeCell entity = null;
  5683. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5684. if (entity != null)
  5685. {
  5686. //有过处理的售后,取消也不能删除 售 字,保留
  5687. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5688. {
  5689. entity.AfterSaleState = 4;
  5690. }
  5691. else
  5692. entity.AfterSaleState = 0;
  5693. entity.UpdateTime = DateTime.Now;
  5694. entity.Update();
  5695. returnSuccessMsg("操作成功!");
  5696. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5697. return;
  5698. }
  5699. returnErrorMsg("找不到订单记录");
  5700. }
  5701. }
  5702. public void get_erp_aftersalelist()
  5703. {
  5704. DataStruct dStruct = GetPostStruct();
  5705. List<string> lw = new List<string>();
  5706. int st = GetInt("st");
  5707. string tid = GetPostString("ctid");
  5708. if (st == 3)
  5709. {
  5710. if (tid.Length > 0)
  5711. {
  5712. string select_tid = getTidByCtid(tid);
  5713. lw.Add(string.Format("tid='{0}'", select_tid));
  5714. }
  5715. }
  5716. else
  5717. {
  5718. if (tid.Length > 0)
  5719. {
  5720. string select_tid = getTidByCtid(tid);
  5721. lw.Add(string.Format("tid='{0}'", select_tid));
  5722. }
  5723. }
  5724. string shopname = GetPostString("shopname");
  5725. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5726. string buyernick = GetPostString("buyer_nick");
  5727. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5728. string sellermemo = GetPostString("seller_memo");
  5729. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5730. string orderState = GetPostString("orderState");
  5731. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5732. string afterState = GetPostString("afterstate");
  5733. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5734. string date1 = GetPostString("date1");
  5735. string date2 = GetPostString("date2");
  5736. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5737. if (dw.Length > 0) lw.Add(dw);
  5738. string price1 = GetPostString("price1");
  5739. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5740. string price2 = GetPostString("price2");
  5741. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5742. //lw.Add(string.Format("IsRefund!={0}", 1));
  5743. string reason = GetPostString("reason");
  5744. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5745. string method = GetPostString("method");
  5746. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5747. string handler = GetPostString("handler");
  5748. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5749. string handledate1 = GetPostString("handledate1");
  5750. string handledate2 = GetPostString("handledate2");
  5751. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5752. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5753. string finish1 = GetPostString("finishdate1");
  5754. string finish2 = GetPostString("finishdate2");
  5755. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5756. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5757. string afterdate1 = GetPostString("afterdate1");
  5758. string afterdate2 = GetPostString("afterdate2");
  5759. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5760. if (afterDate.Length > 0) lw.Add(afterDate);
  5761. string supplier = GetPostString("supplier");
  5762. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5763. string responsible = GetPostString("responsibleman");
  5764. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5765. string customer = GetPostString("customer");
  5766. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5767. string design = GetPostString("design");
  5768. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5769. string afterMemoType = GetPostString("aftermemotype");
  5770. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5771. string posCode = CurrentUser.UserPost.Post.Code;
  5772. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  5773. //{
  5774. // string vstate = GetPostString("vstate");
  5775. // if (vstate.Length > 0)
  5776. // {
  5777. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5778. // }
  5779. // if (posCode == "Supplier")
  5780. // {
  5781. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5782. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5783. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5784. // }
  5785. // else
  5786. // {
  5787. // lw.Add(string.Format("AfterSaleState = {0}", st));
  5788. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  5789. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  5790. // {
  5791. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  5792. // }
  5793. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  5794. // {
  5795. // int orgid = CurrentUser.UserPost.OrgID;
  5796. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  5797. // }
  5798. // else if (CurrentUser.UserPost.Post.Code == "Director")
  5799. // {
  5800. // string shopid = CurrentUser.User.pemShop;
  5801. // lw.Add(string.Format("shopId in ({0})", shopid));
  5802. // }
  5803. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5804. // //{
  5805. // // int org_id = CurrentUser.UserPost.OrgID;
  5806. // // lw.Add(string.Format("OrgID={0}", org_id));
  5807. // //}
  5808. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  5809. // }
  5810. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5811. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5812. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5813. //}
  5814. if (st == 5)
  5815. {
  5816. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  5817. {
  5818. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  5819. {
  5820. string shopid = CurrentUser.User.pemShop;
  5821. lw.Add(string.Format("shopId in ({0})", shopid));
  5822. }
  5823. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  5824. {
  5825. int mrOrgid = CurrentUser.UserPost.OrgID;
  5826. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  5827. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  5828. }
  5829. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  5830. //{
  5831. // int mrOrgid = CurrentUser.UserPost.OrgID;
  5832. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  5833. //}
  5834. else
  5835. {
  5836. string userIdStr = "";
  5837. if (posCode == "CustomerService")
  5838. {
  5839. userIdStr = CurrentUser.UserID + "_k";
  5840. }
  5841. else if (posCode == "Designer" || posCode == "wxDesigner")
  5842. {
  5843. userIdStr = CurrentUser.UserID + "_s";
  5844. }
  5845. else if (posCode == "Place")
  5846. {
  5847. userIdStr = CurrentUser.UserID + "_x";
  5848. }
  5849. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  5850. }
  5851. }
  5852. string placedate1 = GetPostString("placedate1");
  5853. string placedate2 = GetPostString("placedate2");
  5854. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5855. if (dwplace.Length > 0) lw.Add(dwplace);
  5856. string supState = GetPostString("supState");
  5857. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  5858. string searchType = GetPostString("searchType");
  5859. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  5860. {
  5861. lw.Add(string.Format("BackNum>1"));
  5862. }
  5863. lw.Add(string.Format("AfterSaleState>0"));
  5864. if (ex_psize > 0)
  5865. {
  5866. if (CurrentUser.UserPost.Post.Code == "Finance")
  5867. dStruct.Order = "pay_time desc";
  5868. else
  5869. dStruct.Order = "HandleTime desc";
  5870. }
  5871. else
  5872. dStruct.Order = "HandleTime desc";
  5873. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5874. DataTable dt = WebCache.GetData("view_test", dStruct);
  5875. writeGridDataTableJson(dStruct.TotalCount, dt);
  5876. }
  5877. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  5878. //{
  5879. // lw.Add(string.Format("AfterSaleState=4"));
  5880. // string code = CurrentUser.UserPost.Post.Code;
  5881. // if (code == "CustomerService")
  5882. // {
  5883. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  5884. // }
  5885. // else if (code == "Designer" || code == "DesignerMr")
  5886. // {
  5887. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  5888. // }
  5889. // else if (code == "Place" || code == "PlaceMr")
  5890. // {
  5891. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  5892. // }
  5893. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  5894. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5895. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5896. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5897. //}
  5898. //else //处理中的售后,待处理和处理中合并
  5899. //{
  5900. // if (afterState.Length <= 0)
  5901. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  5902. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  5903. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5904. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5905. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5906. //}
  5907. }
  5908. public void get_erp_disagreeftersalelist()
  5909. {
  5910. DataStruct dStruct = GetPostStruct();
  5911. List<string> lw = new List<string>();
  5912. int st = 2;
  5913. string tid = GetPostString("ctid");
  5914. if (tid.Length > 0)
  5915. {
  5916. string select_tid = getTidByCtid(tid);
  5917. lw.Add(string.Format("tid='{0}'", select_tid));
  5918. }
  5919. string shopname = GetPostString("shopname");
  5920. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5921. string buyernick = GetPostString("buyer_nick");
  5922. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5923. string sellermemo = GetPostString("seller_memo");
  5924. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5925. string orderState = GetPostString("orderState");
  5926. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  5927. string afterState = GetPostString("afterstate");
  5928. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5929. string date1 = GetPostString("date1");
  5930. string date2 = GetPostString("date2");
  5931. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5932. if (dw.Length > 0) lw.Add(dw);
  5933. string price1 = GetPostString("price1");
  5934. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5935. string price2 = GetPostString("price2");
  5936. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5937. //lw.Add(string.Format("IsRefund!={0}", 1));
  5938. string reason = GetPostString("reason");
  5939. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5940. string method = GetPostString("method");
  5941. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5942. string handler = GetPostString("handler");
  5943. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5944. string handledate1 = GetPostString("handledate1");
  5945. string handledate2 = GetPostString("handledate2");
  5946. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5947. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5948. string afterdate1 = GetPostString("afterdate1");
  5949. string afterdate2 = GetPostString("afterdate2");
  5950. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5951. if (afterDate.Length > 0) lw.Add(afterDate);
  5952. string backdate1 = GetPostString("backdate1");
  5953. string backdate2 = GetPostString("backdate2");
  5954. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  5955. if (backDate.Length > 0) lw.Add(backDate);
  5956. string supplier = GetPostString("supplier");
  5957. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5958. string responsible = GetPostString("responsibleman");
  5959. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5960. string customer = GetPostString("customer");
  5961. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5962. string design = GetPostString("design");
  5963. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5964. string afterSaleMemo = GetPostString("afterSaleMemo");
  5965. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  5966. string afterMemoType = GetPostString("aftermemotype");
  5967. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5968. string aftersakereason = GetPostString("aftersakereason");
  5969. if (aftersakereason.Length > 0)
  5970. {
  5971. if (aftersakereason == "1")
  5972. {
  5973. lw.Add(string.Format("AfterSaleResSupId > 0"));
  5974. }
  5975. if (aftersakereason == "2")
  5976. {
  5977. lw.Add(string.Format("AfterSaleResSupId = 0"));
  5978. }
  5979. }
  5980. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  5981. string poscode = CurrentUser.UserPost.Post.Code;
  5982. if (poscode != "SysAdmin")
  5983. {
  5984. string shopid = CurrentUser.User.pemShop;
  5985. lw.Add(string.Format("shopId in ({0})", shopid));
  5986. }
  5987. string searchType = GetPostString("searchType");
  5988. if (searchType == "wait")
  5989. {
  5990. lw.Add(string.Format("HandleTime is null"));
  5991. }
  5992. if (searchType == "handling")
  5993. {
  5994. lw.Add(string.Format("HandleTime is not null "));
  5995. }
  5996. if (searchType == "back" || searchType == "puBack")
  5997. {
  5998. lw.Add(string.Format("AfterSaleBackReason != ''"));
  5999. }
  6000. if (searchType == "reBack")
  6001. {
  6002. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6003. }
  6004. if (searchType == "moreBack")
  6005. {
  6006. lw.Add(string.Format("backNum > 1"));
  6007. }
  6008. lw.Add(string.Format("(AfterSaleState=5)"));
  6009. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6010. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6011. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6012. writeGridDataTableJson(dStruct.TotalCount, dt);
  6013. }
  6014. public void get_erp_handlingaftersalelist()
  6015. {
  6016. DataStruct dStruct = GetPostStruct();
  6017. List<string> lw = new List<string>();
  6018. int st = 2;
  6019. string tid = GetPostString("ctid");
  6020. if (tid.Length > 0)
  6021. {
  6022. string select_tid = getTidByCtid(tid);
  6023. lw.Add(string.Format("tid='{0}'", select_tid));
  6024. }
  6025. string shopname = GetPostString("shopname");
  6026. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6027. string buyernick = GetPostString("buyer_nick");
  6028. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6029. string sellermemo = GetPostString("seller_memo");
  6030. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6031. string orderState = GetPostString("orderState");
  6032. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6033. string afterState = GetPostString("afterstate");
  6034. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6035. string date1 = GetPostString("date1");
  6036. string date2 = GetPostString("date2");
  6037. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6038. if (dw.Length > 0) lw.Add(dw);
  6039. string price1 = GetPostString("price1");
  6040. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6041. string price2 = GetPostString("price2");
  6042. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6043. //lw.Add(string.Format("IsRefund!={0}", 1));
  6044. string reason = GetPostString("reason");
  6045. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6046. string method = GetPostString("method");
  6047. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6048. string handler = GetPostString("handler");
  6049. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6050. string handledate1 = GetPostString("handledate1");
  6051. string handledate2 = GetPostString("handledate2");
  6052. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6053. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6054. string afterdate1 = GetPostString("afterdate1");
  6055. string afterdate2 = GetPostString("afterdate2");
  6056. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6057. if (afterDate.Length > 0) lw.Add(afterDate);
  6058. string supplier = GetPostString("supplier");
  6059. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6060. string responsible = GetPostString("responsibleman");
  6061. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6062. string customer = GetPostString("customer");
  6063. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6064. string design = GetPostString("design");
  6065. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6066. string afterSaleMemo = GetPostString("afterSaleMemo");
  6067. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6068. string afterMemoType = GetPostString("aftermemotype");
  6069. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6070. string afterresult = GetPostString("afterresult");
  6071. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6072. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6073. string poscode = CurrentUser.UserPost.Post.Code;
  6074. if (poscode != "SysAdmin")
  6075. {
  6076. string shopid = CurrentUser.User.pemShop;
  6077. lw.Add(string.Format("shopId in ({0})", shopid));
  6078. }
  6079. string searchType = GetPostString("searchType");
  6080. if (searchType == "wait")
  6081. {
  6082. lw.Add(string.Format("HandleTime is null"));
  6083. }
  6084. if (searchType == "documentary")
  6085. {
  6086. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6087. }
  6088. if (searchType == "handling")
  6089. {
  6090. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6091. }
  6092. if (searchType == "back" || searchType == "puBack")
  6093. {
  6094. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6095. }
  6096. if (searchType == "reBack")
  6097. {
  6098. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6099. }
  6100. if (afterState.Length <= 0)
  6101. {
  6102. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6103. }
  6104. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6105. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6106. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6107. writeGridDataTableJson(dStruct.TotalCount, dt);
  6108. }
  6109. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6110. //public void get_erp_back_handlingaftersalelist()
  6111. //{
  6112. // DataStruct dStruct = GetPostStruct();
  6113. // List<string> lw = new List<string>();
  6114. // string tid = GetPostString("ctid");
  6115. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6116. // string shopname = GetPostString("shopname");
  6117. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6118. // string buyernick = GetPostString("buyer_nick");
  6119. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6120. // string sellermemo = GetPostString("seller_memo");
  6121. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6122. // string orderState = GetPostString("orderState");
  6123. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6124. // string afterState = GetPostString("afterstate");
  6125. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6126. // string date1 = GetPostString("date1");
  6127. // string date2 = GetPostString("date2");
  6128. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6129. // if (dw.Length > 0) lw.Add(dw);
  6130. // string price1 = GetPostString("price1");
  6131. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6132. // string price2 = GetPostString("price2");
  6133. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6134. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6135. // string reason = GetPostString("reason");
  6136. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6137. // string method = GetPostString("method");
  6138. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6139. // string handler = GetPostString("handler");
  6140. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6141. // string handledate1 = GetPostString("handledate1");
  6142. // string handledate2 = GetPostString("handledate2");
  6143. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6144. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6145. // string afterdate1 = GetPostString("afterdate1");
  6146. // string afterdate2 = GetPostString("afterdate2");
  6147. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6148. // if (afterDate.Length > 0) lw.Add(afterDate);
  6149. // string supplier = GetPostString("supplier");
  6150. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6151. // string responsible = GetPostString("responsibleman");
  6152. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6153. // string customer = GetPostString("customer");
  6154. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6155. // string design = GetPostString("design");
  6156. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6157. // string afterMemoType = GetPostString("aftermemotype");
  6158. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6159. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6160. // if (afterState.Length <= 0)
  6161. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6162. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6163. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6164. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6165. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6166. //}
  6167. public void get_erp_aftersaleverifylist()
  6168. {
  6169. DataStruct dStruct = GetPostStruct();
  6170. List<string> lw = new List<string>();
  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. //lw.Add(string.Format("IsRefund!={0}", 1));
  6186. string reason = GetPostString("reason");
  6187. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6188. string method = GetPostString("method");
  6189. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6190. string handler = GetPostString("handler");
  6191. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6192. string handledate1 = GetPostString("handledate1");
  6193. string handledate2 = GetPostString("handledate2");
  6194. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6195. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6196. string finish1 = GetPostString("finishdate1");
  6197. string finish2 = GetPostString("finishdate2");
  6198. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6199. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6200. string supplier = GetPostString("supplier");
  6201. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6202. string responsible = GetPostString("responsibleman");
  6203. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6204. string posCode = CurrentUser.UserPost.Post.Code;
  6205. string vstate = GetPostString("vstate");
  6206. if (vstate.Length > 0)
  6207. {
  6208. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6209. }
  6210. if (posCode == "Supplier")
  6211. {
  6212. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6213. lw.Add(string.Format("VerifyState = 0"));
  6214. lw.Add("type = 1");
  6215. lw.Add(string.Format("AfterSaleState={0}", 3));
  6216. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6217. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6218. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6219. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6220. writeGridDataTableJson(dStruct.TotalCount, dt);
  6221. }
  6222. else if (posCode == "logistics")
  6223. {
  6224. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6225. lw.Add(string.Format("VerifyState = 0"));
  6226. lw.Add("type = 2");
  6227. lw.Add(string.Format("AfterSaleState={0}", 3));
  6228. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6229. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6230. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6231. writeGridDataTableJson(dStruct.TotalCount, dt);
  6232. }
  6233. else
  6234. {
  6235. lw.Add(string.Format("(AfterSaleState = 3)"));
  6236. string reasonState = GetPostString("reasonState");
  6237. lw.Add("type = 0");
  6238. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6239. || posCode == "Summarize" || posCode == "Finance")
  6240. {
  6241. if (reasonState == "2")
  6242. {
  6243. lw.Add("VerifyState = 3");
  6244. }
  6245. else if (reasonState == "1")
  6246. {
  6247. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6248. }
  6249. else
  6250. {
  6251. lw.Add("VerifyState in (0,3)");
  6252. }
  6253. //不加条件,可以看全部
  6254. }
  6255. 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")
  6256. {
  6257. int orgid = CurrentUser.UserPost.OrgID;
  6258. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6259. if (string.IsNullOrEmpty(manageOrgId))
  6260. {
  6261. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6262. }
  6263. else
  6264. {
  6265. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6266. }
  6267. if (reasonState == "1")
  6268. {
  6269. lw.Add("VerifyState = 3");
  6270. }
  6271. else if (reasonState == "2")
  6272. {
  6273. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6274. }
  6275. else
  6276. {
  6277. }
  6278. }
  6279. else
  6280. {
  6281. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6282. }
  6283. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6284. //{
  6285. // int org_id = CurrentUser.UserPost.OrgID;
  6286. // lw.Add(string.Format("OrgID={0}", org_id));
  6287. //}
  6288. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6289. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6290. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6291. writeGridDataTableJson(dStruct.TotalCount, dt);
  6292. }
  6293. }
  6294. public void get_erp_finishaftersalelist()
  6295. {
  6296. DataStruct dStruct = GetPostStruct();
  6297. List<string> lw = new List<string>();
  6298. int st = 4;
  6299. string tid = GetPostString("ctid");
  6300. if (tid.Length > 0)
  6301. {
  6302. string select_tid = getTidByCtid(tid);
  6303. lw.Add(string.Format("tid='{0}'", select_tid));
  6304. }
  6305. string shopname = GetPostString("shopname");
  6306. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6307. //lw.Add(string.Format("IsRefund!={0}", 1));
  6308. string reason = GetPostString("reason");
  6309. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6310. string method = GetPostString("method");
  6311. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6312. string buyernick = GetPostString("buyer_nick");
  6313. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6314. string handler = GetPostString("handler");
  6315. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6316. string handledate1 = GetPostString("handledate1");
  6317. string handledate2 = GetPostString("handledate2");
  6318. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6319. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6320. string finish1 = GetPostString("finishdate1");
  6321. string finish2 = GetPostString("finishdate2");
  6322. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6323. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6324. string supplier = GetPostString("supplier");
  6325. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6326. string responsible = GetPostString("responsibleman");
  6327. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6328. string vstate = GetPostString("vstate");
  6329. if (vstate.Length > 0)
  6330. {
  6331. if ("3".Equals(vstate))
  6332. {
  6333. lw.Add(string.Format("IsTem=1"));
  6334. }
  6335. else
  6336. {
  6337. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6338. }
  6339. }
  6340. lw.Add(string.Format("AfterSaleState=4"));
  6341. string code = CurrentUser.UserPost.Post.Code;
  6342. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6343. {
  6344. //不加条件,可以看全部
  6345. }
  6346. else if (code == "Supplier")
  6347. {
  6348. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6349. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6350. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6351. }
  6352. else if (code == "logistics")
  6353. {
  6354. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6355. lw.Add("type = 2");
  6356. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6357. }
  6358. 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")
  6359. {
  6360. int orgid = CurrentUser.UserPost.OrgID;
  6361. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6362. if (string.IsNullOrEmpty(manageOrgIds))
  6363. {
  6364. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6365. }
  6366. else
  6367. {
  6368. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6369. }
  6370. }
  6371. else
  6372. {
  6373. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6374. }
  6375. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6376. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6377. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6378. writeGridDataTableJson(dStruct.TotalCount, dt);
  6379. }
  6380. public void handle_erp_aftersale()
  6381. {
  6382. if (UrlPostParmsCheck("ctid"))
  6383. {
  6384. string eid = GetPostString("ctid");
  6385. string responStr = GetPostString("AfterSaleResponsible");
  6386. if (responStr.Length <= 0)
  6387. {
  6388. returnErrorMsg("售后责任人不能为空");
  6389. return;
  6390. }
  6391. bool isDesign = false;
  6392. double designFree = 0.00;
  6393. int responsibleId = 0;
  6394. CeErpTradeCell entity = null;
  6395. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6396. if (entity != null)
  6397. {
  6398. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6399. string afterMethod = GetPostString("AfterSaleMethod");
  6400. if (isNeedNewOrder == 1)
  6401. {
  6402. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6403. bool ishav = true;
  6404. if (newentity == null)
  6405. {
  6406. newentity = entity.Clone() as CeErpTradeCell;
  6407. ishav = false;
  6408. newentity.ctid = "S_" + entity.ctid;
  6409. newentity.OrderState = 0;
  6410. //唯一标识
  6411. newentity.OrderSn = newentity.ctid;
  6412. string orderSn = dataHelper.getSaleOrderSn();
  6413. if (orderSn != "")
  6414. {
  6415. newentity.OrderSn = orderSn;
  6416. }
  6417. }
  6418. newentity.UpdateTime = DateTime.Now;
  6419. newentity.AfterSaleState = 0;
  6420. newentity.AfterSaleMethod = afterMethod;
  6421. if (!ishav)
  6422. {
  6423. string memo_str = newentity.seller_memo;
  6424. memo_str = memo_str.Replace("(", "(");
  6425. memo_str = memo_str.Replace(")", ")");
  6426. int sIndex = memo_str.IndexOf("(");
  6427. int eIndex = memo_str.IndexOf(")");
  6428. if (sIndex == -1 || eIndex == -1)
  6429. {
  6430. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6431. return;
  6432. }
  6433. string first = memo_str.Substring(0, sIndex + 1);
  6434. string memoCtid = newentity.OrderSn;
  6435. //if (memoCtid.IndexOf("C") != -1)
  6436. //{
  6437. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6438. //if (CIdx.IndexOf("+") != -1)
  6439. //{
  6440. //CIdx = "C" + CIdx.Split('+')[1];
  6441. //}
  6442. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6443. //}
  6444. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6445. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6446. string newMemo = first + memoCtid + last;
  6447. newentity.seller_memo = newMemo;
  6448. newentity.FinishPlaceTime = null;
  6449. newentity.UnusualTag = 0;
  6450. newentity.UnusualCon = "";
  6451. newentity.UnusualTime = null;
  6452. newentity.AfterSaleMemo = "";
  6453. newentity.AfterSaleMethod = afterMethod;
  6454. newentity.AfterSalePreTime = null;
  6455. newentity.AfterSaleReason = "";
  6456. newentity.AfterSaleResponsible = "";
  6457. newentity.AfterSaleState = 0;
  6458. newentity.AfterSaleTime = null;
  6459. newentity.AfterSaleUserId = 0;
  6460. newentity.AfterSaleSupplierState = 0;
  6461. newentity.LastBillWaybillCode = "";
  6462. newentity.LastBillCpCode = "";
  6463. newentity.FinishAfterSaleTime = null;
  6464. newentity.HandleTime = null;
  6465. newentity.IsSF = 0;
  6466. newentity.IsOldCustomer = 0;
  6467. newentity.UrgencyTime = null;
  6468. newentity.ResponsibleUserId = "";
  6469. newentity.IsVerifyToSupplier = false;
  6470. newentity.payment = 0;
  6471. newentity.CheckMemo = "";
  6472. newentity.OutSid = "";
  6473. newentity.CheckOrderTime = null;
  6474. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6475. }
  6476. newentity.isAfterSaleOrder = 1;
  6477. newentity.IsRefund = 0;
  6478. string receiveMobile = GetPostString("receiver_mobile");
  6479. if (receiveMobile.Length > 0)
  6480. {
  6481. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6482. if (trade != null)
  6483. {
  6484. trade.receiver_name = GetPostString("receiver_name");
  6485. trade.receiver_mobile = receiveMobile;
  6486. trade.receiver_state = GetPostString("receiver_state");
  6487. trade.receiver_city = GetPostString("receiver_city");
  6488. trade.receiver_district = GetPostString("receiver_district");
  6489. trade.receiver_address = GetPostString("receiver_address");
  6490. newentity.IsOffLineOrder = 1;
  6491. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6492. }
  6493. }
  6494. string st = GetPostString("ToState");
  6495. if (st.Length > 0)
  6496. {
  6497. if (newentity.OrderState <= 3)
  6498. {
  6499. newentity.WaitDesignTime = DateTime.Now;
  6500. newentity.StartDesignTime = null;
  6501. newentity.FinishDesignTime = null;
  6502. newentity.OrderState = 3;
  6503. if (st == "下单员")
  6504. {
  6505. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6506. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6507. {
  6508. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6509. }
  6510. }
  6511. else
  6512. {
  6513. newentity.WaitDesignTime = DateTime.Now;
  6514. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6515. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6516. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6517. {
  6518. DataRow user = dt1.Rows[0];
  6519. //找主管
  6520. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6521. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6522. if (dt != null && dt.Rows.Count > 0)
  6523. {
  6524. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6525. newentity.DesignUserId = designMr;
  6526. string key = "aftersale_order_" + designMr;
  6527. if (RedisHelper.HasKey(key))
  6528. {
  6529. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6530. list.Add(newentity.ctid);
  6531. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6532. }
  6533. }
  6534. //账号正常
  6535. if (user["State"].ToString() == "0")
  6536. {
  6537. newentity.DesignUserId = entity.DesignUserId;
  6538. string key = "aftersale_order_" + entity.DesignUserId;
  6539. if (RedisHelper.HasKey(key))
  6540. {
  6541. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6542. list.Add(newentity.ctid);
  6543. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6544. }
  6545. }
  6546. }
  6547. }
  6548. }
  6549. if (entity.IsXianHuo == 1)
  6550. {
  6551. newentity.OrderState = 6;
  6552. entity.FinishPlaceTime = DateTime.Now;
  6553. }
  6554. }
  6555. if (ishav)
  6556. {
  6557. newentity.Update();
  6558. }
  6559. else
  6560. {
  6561. newentity.Create();
  6562. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6563. newCellExtend.ctid = newentity.ctid;
  6564. newCellExtend.orderFrom = 20;
  6565. newCellExtend.orderType = 30;
  6566. if (st == "下单员")
  6567. {
  6568. }
  6569. else
  6570. {
  6571. newCellExtend.ReprintTime = DateTime.Now;
  6572. }
  6573. newCellExtend.Create();
  6574. }
  6575. if (st != "下单员")
  6576. {
  6577. designHelper.API_GetPrintData_CreateOrder(newentity);
  6578. }
  6579. }
  6580. //处理售后扩展
  6581. string resIdStr = GetPostString("ResponsibleUserId");
  6582. string refundFees = GetPostString("refundFrees");
  6583. int IsComplain = GetPostInt("isComplain");
  6584. int IsBad = GetPostInt("isBad");
  6585. string IsOriginal = GetPostString("isOriginal");
  6586. double diffResultPrice = GetPostDouble("diffResultPrice");
  6587. string textResult = GetPostString("textResult");
  6588. string supplierResponsible = GetPostString("supplierResponsible");
  6589. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6590. if (ceErpTradeAfterSaleExtend == null)
  6591. {
  6592. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6593. ceErpTradeAfterSaleExtend.tid = eid;
  6594. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6595. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6596. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6597. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6598. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6599. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6600. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6601. ceErpTradeAfterSaleExtend.Create();
  6602. }
  6603. else
  6604. {
  6605. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6606. {
  6607. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6608. }
  6609. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6610. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6611. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6612. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6613. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6614. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6615. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6616. ceErpTradeAfterSaleExtend.Update();
  6617. }
  6618. int gysid = GetPostInt("ResponsibleSupId");
  6619. if (entity.AfterSaleUserId == 0)
  6620. {
  6621. entity.AfterSaleUserId = CurrentUser.UserID;
  6622. }
  6623. entity.ResponsibleUserId = resIdStr;
  6624. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6625. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6626. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6627. {
  6628. CeErpTradeResponsible.DelByTid(eid, -1);
  6629. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6630. int backNum = 0;
  6631. if (number != null)
  6632. {
  6633. backNum = number.BackNum;
  6634. }
  6635. char[] separator = { ',' };
  6636. string[] sArray = resIdStr.Split(separator);
  6637. string[] refundFreeList = { };
  6638. if (refundFees.Length > 0)
  6639. {
  6640. refundFreeList = refundFees.Split(separator);
  6641. }
  6642. int index = -1;
  6643. foreach (string i in sArray)
  6644. {
  6645. index++;
  6646. if (i.Length <= 0) continue;
  6647. char[] separator2 = { '_' };
  6648. string idstr = i.Split(separator2)[0];
  6649. string idtype = i.Split(separator2)[1];
  6650. double refudFree = 0;
  6651. if (refundFreeList.Length > 0)
  6652. {
  6653. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6654. }
  6655. if (idtype == "s")
  6656. {
  6657. isDesign = true;
  6658. designFree = refudFree;
  6659. }
  6660. int userId = Convert.ToInt32(idstr);
  6661. int type = 0;
  6662. if (idtype == "g")
  6663. {
  6664. type = 1;
  6665. }
  6666. if (idtype == "w")
  6667. {
  6668. type = 2;
  6669. }
  6670. if (idtype == "t")
  6671. {
  6672. type = 3;
  6673. }
  6674. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6675. if (ceErpTradeResponsible == null)
  6676. {
  6677. ceErpTradeResponsible = new CeErpTradeResponsible();
  6678. ceErpTradeResponsible.tid = eid;
  6679. ceErpTradeResponsible.UserId = userId;
  6680. ceErpTradeResponsible.createdTime = DateTime.Now;
  6681. ceErpTradeResponsible.type = type;
  6682. if (type == 1)
  6683. {
  6684. ceErpTradeResponsible.IsSup = 1;
  6685. }
  6686. if (type == 2)
  6687. {
  6688. ceErpTradeResponsible.IsFlow = 1;
  6689. }
  6690. }
  6691. ceErpTradeResponsible.RefundFee = refudFree;
  6692. ceErpTradeResponsible.VerifyState = 0;
  6693. if (userId == 2125 || idtype == "w")
  6694. {
  6695. ceErpTradeResponsible.VerifyState = 1;
  6696. }
  6697. if (idtype == "w" && userId == 101)
  6698. {
  6699. ceErpTradeResponsible.VerifyState = 0;
  6700. }
  6701. if (ceErpTradeResponsible.ID > 0)
  6702. {
  6703. ceErpTradeResponsible.Update();
  6704. }
  6705. else
  6706. {
  6707. ceErpTradeResponsible.Create();
  6708. }
  6709. if (isDesign)
  6710. {
  6711. responsibleId = ceErpTradeResponsible.ID;
  6712. }
  6713. }
  6714. CeErpTradeResponsible.NumByTid(backNum, eid);
  6715. }
  6716. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6717. if (ceErpTradeCellExtend != null)
  6718. {
  6719. ceErpTradeCellExtend.returnVisit = 0;
  6720. ceErpTradeCellExtend.Update();
  6721. }
  6722. if (entity.HandleTime != null)
  6723. {
  6724. if (entity.AfterSaleState == 1)
  6725. {
  6726. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6727. }
  6728. else
  6729. {
  6730. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6731. }
  6732. }
  6733. else
  6734. {
  6735. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6736. entity.HandleTime = DateTime.Now;
  6737. }
  6738. bool isCompale = false;
  6739. if (entity.AfterSaleState == 5)
  6740. {
  6741. isCompale = true;
  6742. entity.AfterSaleState = 3;
  6743. }
  6744. entity.AfterSaleSupplierState = 0;
  6745. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6746. {
  6747. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6748. }
  6749. string sImgs = GetPostString("img");
  6750. entity.AfterSaleSupplierImg = sImgs;
  6751. entity.supRefundType = GetPostString("supRefundType");
  6752. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6753. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6754. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6755. entity.AfterSaleMemoType = GetPostString("MemoType");
  6756. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6757. {
  6758. //entity.AfterSaleSupplierState = 2;
  6759. }
  6760. string df = GetPostString("DeductFee");
  6761. if (df == "")
  6762. {
  6763. df = "0";
  6764. }
  6765. string rf = GetPostString("RefundFee");
  6766. if (rf == "")
  6767. {
  6768. rf = "0";
  6769. }
  6770. string pm = GetPostString("AfterSalePayment");
  6771. if (pm == "")
  6772. {
  6773. pm = "0";
  6774. }
  6775. entity.AfterSalePayment = Convert.ToDouble(pm);
  6776. entity.DeductFee = Convert.ToDouble(df);
  6777. entity.RefundFee = Convert.ToDouble(rf);
  6778. entity.UpdateTime = DateTime.Now;
  6779. entity.Update();
  6780. string toState = GetPostString("ToState");
  6781. string original = GetPostString("isOriginal");
  6782. ApiVo apiVo = new ApiVo();
  6783. apiVo.orderNumber = entity.ctid;
  6784. apiVo.actionName = "afterDesign";
  6785. apiVo.orderRemarks = entity.AfterSaleMethod;
  6786. apiVo.reasonRemarks = entity.AfterSaleReason;
  6787. apiVo.isDesign = isDesign;
  6788. apiVo.designFree = designFree;
  6789. apiVo.responsibleId = responsibleId;
  6790. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6791. if (toState == "设计师")
  6792. {
  6793. apiVo.isOriginal = Convert.ToBoolean(original);
  6794. }
  6795. designHelper.API_WorkCore(apiVo);//afterDesign
  6796. CeErpMethod methodSql = new CeErpMethod();
  6797. methodSql.con = entity.AfterSaleMethod;
  6798. methodSql.addTime = DateTime.Now;
  6799. methodSql.Create();
  6800. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  6801. CeErpMethod.ExecuteNonQuery(delsql);
  6802. if (isCompale)
  6803. {
  6804. aftersale_data_change(entity.ctid);
  6805. }
  6806. returnSuccessMsg("操作成功!");
  6807. return;
  6808. }
  6809. returnErrorMsg("找不到订单记录");
  6810. }
  6811. }
  6812. public void ins_erp_toresponsible()
  6813. {
  6814. if (UrlPostParmsCheck("ctid"))
  6815. {
  6816. string eid = GetPostString("ctid");
  6817. CeErpTradeCell entity = null;
  6818. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6819. if (entity != null)
  6820. {
  6821. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  6822. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  6823. {
  6824. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  6825. return;
  6826. }
  6827. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  6828. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  6829. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  6830. if (entity.AfterSalePreTime == null)
  6831. {
  6832. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  6833. {
  6834. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  6835. }
  6836. }
  6837. entity.AfterSalePreTime = DateTime.Now;
  6838. //预完成给售后主管审核客户问题直接完成
  6839. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  6840. {
  6841. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  6842. {
  6843. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  6844. }
  6845. }
  6846. ceErpTradeAfterSaleExtend.Update();
  6847. entity.AfterSaleState = 2;
  6848. entity.UpdateTime = DateTime.Now;
  6849. entity.Update();
  6850. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  6851. aftersale_data_change(entity.ctid);
  6852. returnSuccessMsg("操作成功!");
  6853. return;
  6854. }
  6855. returnErrorMsg("找不到订单记录");
  6856. }
  6857. }
  6858. public void cancel_erp_aftersaleanddelnew()
  6859. {
  6860. if (UrlPostParmsCheck("ctid"))
  6861. {
  6862. string eid = GetPostString("ctid");
  6863. CeErpTradeCell entity = null;
  6864. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6865. if (entity != null)
  6866. {
  6867. entity.AfterSaleState = 0;
  6868. entity.AfterSaleReason = "";
  6869. entity.AfterSaleMethod = "";
  6870. entity.AfterSaleMemo = "";
  6871. entity.AfterSaleResponsible = "";
  6872. entity.ResponsibleUserId = "";
  6873. entity.DeductFee = 0;
  6874. entity.RefundFee = 0;
  6875. entity.IsArbitrate = 0;
  6876. CeErpTradeResponsible.DelByTid(eid, -1);
  6877. entity.Update();
  6878. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  6879. if (after != null)
  6880. {
  6881. if (after.OrderState < 5)
  6882. CeErpTradeCell.DelByCtid("S_" + eid);
  6883. }
  6884. returnSuccessMsg("操作成功!");
  6885. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  6886. return;
  6887. }
  6888. returnErrorMsg("找不到订单记录");
  6889. }
  6890. }
  6891. public void get_erp_aftersale_pregather()
  6892. {
  6893. List<string> lw = new List<string>();
  6894. int st = GetInt("st");
  6895. string tid = GetPostString("ctid");
  6896. if (tid.Length > 0)
  6897. {
  6898. string select_tid = getTidByCtid(tid);
  6899. lw.Add(string.Format("tid='{0}'", select_tid));
  6900. }
  6901. string shopname = GetPostString("shopname");
  6902. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6903. string buyernick = GetPostString("buyer_nick");
  6904. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6905. string sellermemo = GetPostString("seller_memo");
  6906. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6907. string orderState = GetPostString("orderState");
  6908. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6909. string reason = GetPostString("reason");
  6910. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6911. string method = GetPostString("method");
  6912. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6913. string handler = GetPostString("handler");
  6914. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6915. string handledate1 = GetPostString("handledate1");
  6916. string handledate2 = GetPostString("handledate2");
  6917. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6918. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6919. string supplier = GetPostString("supplier");
  6920. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6921. string responsible = GetPostString("responsibleman");
  6922. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6923. string customer = GetPostString("customer");
  6924. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6925. string design = GetPostString("design");
  6926. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6927. string afterMemoType = GetPostString("aftermemotype");
  6928. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6929. string afterSaleMemo = GetPostString("afterSaleMemo");
  6930. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6931. string afterresult = GetPostString("afterresult");
  6932. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  6933. string poscode = CurrentUser.UserPost.Post.Code;
  6934. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  6935. {
  6936. string shopid = CurrentUser.User.pemShop;
  6937. lw.Add(string.Format("shopId in ({0})", shopid));
  6938. }
  6939. var mainwhere = string.Join(" and ", lw.ToArray());
  6940. string ro_json = "";
  6941. string type = GetPostString("gather_type");
  6942. int number = 0;
  6943. if (poscode == "AfterSale")
  6944. {
  6945. //处理中
  6946. if (type == "Handling")
  6947. {
  6948. 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) : ""));
  6949. DataTable dt = null;
  6950. try
  6951. {
  6952. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6953. number = Convert.ToInt32(dt.Rows[0]["number"]);
  6954. }
  6955. catch (Exception e)
  6956. {
  6957. dt = new DataTable();
  6958. }
  6959. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  6960. return;
  6961. }
  6962. if (type == "Wait")
  6963. {
  6964. //待处理
  6965. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6966. DataTable dt1 = null;
  6967. try
  6968. {
  6969. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6970. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  6971. }
  6972. catch (Exception e)
  6973. {
  6974. dt1 = new DataTable();
  6975. }
  6976. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  6977. return;
  6978. }
  6979. if (type == "back")
  6980. {
  6981. //打回
  6982. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  6983. DataTable dt2 = null;
  6984. try
  6985. {
  6986. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  6987. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  6988. }
  6989. catch (Exception e)
  6990. {
  6991. dt2 = new DataTable();
  6992. }
  6993. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  6994. return;
  6995. }
  6996. if (type == "preCompletion")
  6997. {
  6998. //预完成
  6999. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7000. DataTable dt3 = null;
  7001. try
  7002. {
  7003. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7004. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7005. }
  7006. catch (Exception e)
  7007. {
  7008. dt3 = new DataTable();
  7009. }
  7010. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7011. return;
  7012. }
  7013. if (type == "documentary")
  7014. {
  7015. //跟单中
  7016. 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) : ""));
  7017. DataTable dt4 = null;
  7018. try
  7019. {
  7020. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7021. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7022. }
  7023. catch (Exception e)
  7024. {
  7025. dt4 = new DataTable();
  7026. }
  7027. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7028. return;
  7029. }
  7030. if (type == "reBack")
  7031. {
  7032. //被打回
  7033. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7034. DataTable dt1 = null;
  7035. try
  7036. {
  7037. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7038. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7039. }
  7040. catch (Exception e)
  7041. {
  7042. dt1 = new DataTable();
  7043. }
  7044. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7045. return;
  7046. }
  7047. }
  7048. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7049. {
  7050. if (type == "puBack")
  7051. {
  7052. //退回
  7053. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7054. DataTable dt = null;
  7055. try
  7056. {
  7057. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7058. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7059. }
  7060. catch (Exception e)
  7061. {
  7062. dt = new DataTable();
  7063. }
  7064. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7065. return;
  7066. }
  7067. if (type == "reBack")
  7068. {
  7069. //打回
  7070. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7071. DataTable dt1 = null;
  7072. try
  7073. {
  7074. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7075. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7076. }
  7077. catch (Exception e)
  7078. {
  7079. dt1 = new DataTable();
  7080. }
  7081. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7082. return;
  7083. }
  7084. if (type == "examEd")
  7085. {
  7086. //已审核
  7087. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7088. DataTable dt2 = null;
  7089. try
  7090. {
  7091. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7092. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7093. }
  7094. catch (Exception e)
  7095. {
  7096. dt2 = new DataTable();
  7097. }
  7098. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7099. return;
  7100. }
  7101. if (type == "waitExam")
  7102. {
  7103. //待审核
  7104. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7105. DataTable dt3 = null;
  7106. try
  7107. {
  7108. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7109. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7110. }
  7111. catch (Exception e)
  7112. {
  7113. dt3 = new DataTable();
  7114. }
  7115. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7116. return;
  7117. }
  7118. if (type == "Handling")
  7119. {
  7120. //处理中
  7121. 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) : ""));
  7122. DataTable dt4 = null;
  7123. try
  7124. {
  7125. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7126. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7127. }
  7128. catch (Exception e)
  7129. {
  7130. dt4 = new DataTable();
  7131. }
  7132. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7133. return;
  7134. }
  7135. if (type == "Wait")
  7136. {
  7137. //待处理
  7138. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7139. DataTable dt5 = null;
  7140. try
  7141. {
  7142. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7143. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7144. }
  7145. catch (Exception e)
  7146. {
  7147. dt5 = new DataTable();
  7148. }
  7149. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7150. return;
  7151. }
  7152. if (type == "documentary")
  7153. {
  7154. //跟单中
  7155. 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) : ""));
  7156. DataTable dt6 = null;
  7157. try
  7158. {
  7159. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7160. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7161. }
  7162. catch (Exception e)
  7163. {
  7164. dt6 = new DataTable();
  7165. }
  7166. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7167. return;
  7168. }
  7169. }
  7170. returnSuccess(ro_json);
  7171. }
  7172. public void end_erp_aftersale()
  7173. {
  7174. if (UrlPostParmsCheck("ctid"))
  7175. {
  7176. string eid = GetPostString("ctid");
  7177. CeErpTradeCell entity = null;
  7178. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7179. if (entity != null)
  7180. {
  7181. string stype = GetPostString("stype");
  7182. string typeStr = stype;
  7183. entity.AfterSaleState = 4;
  7184. entity.FinishAfterSaleTime = DateTime.Now;
  7185. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7186. entity.Update();
  7187. ApiVo apiVo = new ApiVo();
  7188. apiVo.orderNumber = entity.ctid;
  7189. apiVo.actionName = "afterOver";
  7190. designHelper.API_WorkCore(apiVo); //afterOver
  7191. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7192. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7193. CeErpSukuraData.createInfo(entity.ctid, 8);
  7194. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7195. returnSuccessMsg("操作成功!");
  7196. return;
  7197. }
  7198. returnErrorMsg("找不到订单记录");
  7199. }
  7200. }
  7201. public void ins_erp_finishaftersale()
  7202. {
  7203. if (UrlPostParmsCheck("id"))
  7204. {
  7205. string eid = GetPostString("id");
  7206. CeErpTradeResponsible entity = null;
  7207. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7208. if (entity != null)
  7209. {
  7210. entity.VerifyState = 1;
  7211. entity.VerifyTime = DateTime.Now;
  7212. entity.Update();
  7213. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7214. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7215. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7216. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7217. if (dt.Rows.Count <= 0)
  7218. {
  7219. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7220. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7221. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7222. CeErpSukuraData.createInfo(entity.tid, 8);
  7223. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7224. {
  7225. CeErpDesignerBill.Del(entity.tid);
  7226. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7227. }
  7228. }
  7229. returnSuccessMsg("操作成功!");
  7230. return;
  7231. }
  7232. returnErrorMsg("找不到订单记录");
  7233. }
  7234. }
  7235. public void upd_erp_arbitrateaftersale()
  7236. {
  7237. if (UrlPostParmsCheck("id"))
  7238. {
  7239. string eid = GetPostString("id");
  7240. CeErpTradeResponsible entity = null;
  7241. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7242. if (entity != null)
  7243. {
  7244. entity.IsArbitrate = 1;
  7245. entity.ArbitradeMemo = GetPostString("reason");
  7246. entity.VerifyState = 2;
  7247. entity.Update();
  7248. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7249. if (tradecell != null)
  7250. {
  7251. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7252. tradecell.IsArbitrate = 1;
  7253. tradecell.Update();
  7254. }
  7255. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7256. returnSuccessMsg("操作成功!");
  7257. return;
  7258. }
  7259. returnErrorMsg("找不到订单记录");
  7260. }
  7261. }
  7262. public void upd_erp_backaftersale()
  7263. {
  7264. if (UrlPostParmsCheck("tid"))
  7265. {
  7266. string eid = GetPostString("tid");
  7267. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7268. int backNum = 0;
  7269. if (number != null)
  7270. {
  7271. backNum = number.BackNum;
  7272. }
  7273. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7274. CeErpTradeCell entity = null;
  7275. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7276. if (entity != null)
  7277. {
  7278. entity.AfterSaleBackReason = GetPostString("backreason");
  7279. entity.AfterSaleState = 1;
  7280. entity.AfterSaleSupplierState = 0;
  7281. entity.UpdateTime = DateTime.Now;
  7282. entity.Update();
  7283. returnSuccessMsg("操作成功!");
  7284. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7285. return;
  7286. }
  7287. returnErrorMsg("找不到订单记录");
  7288. }
  7289. }
  7290. public void get_erp_supplieraftersalelist()
  7291. {
  7292. DataStruct dStruct = GetPostStruct();
  7293. List<string> lw = new List<string>();
  7294. string tid = GetPostString("ctid");
  7295. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7296. string shopname = GetPostString("shopname");
  7297. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7298. string buyernick = GetPostString("buyer_nick");
  7299. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7300. string sellermemo = GetPostString("seller_memo");
  7301. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7302. string orderState = GetPostString("orderState");
  7303. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7304. string afterState = GetPostString("afterstate");
  7305. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7306. string date1 = GetPostString("date1");
  7307. string date2 = GetPostString("date2");
  7308. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7309. if (dw.Length > 0) lw.Add(dw);
  7310. string price1 = GetPostString("price1");
  7311. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7312. string price2 = GetPostString("price2");
  7313. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7314. string reason = GetPostString("reason");
  7315. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7316. string method = GetPostString("method");
  7317. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7318. string handledate1 = GetPostString("handledate1");
  7319. string handledate2 = GetPostString("handledate2");
  7320. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7321. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7322. string handler = GetPostString("handler");
  7323. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7324. string afterdate1 = GetPostString("afterdate1");
  7325. string afterdate2 = GetPostString("afterdate2");
  7326. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7327. if (afterDate.Length > 0) lw.Add(afterDate);
  7328. string customer = GetPostString("customer");
  7329. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7330. string design = GetPostString("design");
  7331. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7332. string afterMemoType = GetPostString("aftermemotype");
  7333. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7334. string vstate = GetPostString("vstate");
  7335. if (vstate.Length > 0)
  7336. {
  7337. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7338. }
  7339. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7340. string supplier = GetPostString("supplier");
  7341. int supid = commonHelper.getSupplierIDByName(supplier);
  7342. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7343. string posCode = CurrentUser.UserPost.Post.Code;
  7344. if (posCode == "Supplier")
  7345. {
  7346. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7347. }
  7348. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7349. {
  7350. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7351. }
  7352. else
  7353. {
  7354. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7355. }
  7356. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7357. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7358. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7359. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7360. writeGridDataTableJson(dStruct.TotalCount, dt);
  7361. }
  7362. public void upd_erp_supverifyaftersale()
  7363. {
  7364. if (UrlPostParmsCheck("id"))
  7365. {
  7366. string id = GetPostString("id");
  7367. int st = GetPostInt("afterstate");
  7368. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7369. CeErpTradeCell entity = null;
  7370. if (ceErpTradeResponsible != null)
  7371. {
  7372. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7373. }
  7374. string afmemo = GetPostString("supmemo");
  7375. string image = GetPostString("image");
  7376. if (entity != null)
  7377. {
  7378. entity.AfterSaleSupplierState = st;
  7379. entity.AfterSaleSupplierMemo = afmemo;
  7380. if (st == 1)
  7381. {
  7382. ceErpTradeResponsible.VerifyState = 1;
  7383. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7384. ceErpTradeResponsible.Update();
  7385. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7386. if (isAll)
  7387. {
  7388. entity.AfterSaleState = 4;
  7389. entity.FinishAfterSaleTime = DateTime.Now;
  7390. }
  7391. }
  7392. else
  7393. {
  7394. CeErpTradeResponsible.dateByTid(entity.ctid);
  7395. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7396. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7397. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7398. if (num <= 1)
  7399. {
  7400. entity.AfterSaleState = 1;
  7401. }
  7402. else
  7403. {
  7404. entity.AfterSaleState = 5;
  7405. }
  7406. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7407. if (ceErpTradeAfterSaleExtend != null)
  7408. {
  7409. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7410. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7411. ceErpTradeAfterSaleExtend.Update();
  7412. }
  7413. else
  7414. {
  7415. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7416. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7417. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7418. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7419. ceErpTradeAfterSaleExtend.Create();
  7420. }
  7421. }
  7422. if (entity.AfterSaleState == 4)
  7423. {
  7424. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7425. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7426. {
  7427. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7428. }
  7429. ApiVo apiVo = new ApiVo();
  7430. apiVo.orderNumber = entity.ctid;
  7431. apiVo.actionName = "afterOver";
  7432. designHelper.API_WorkCore(apiVo); //afterOver
  7433. }
  7434. entity.UpdateTime = DateTime.Now;
  7435. entity.Update();
  7436. returnSuccessMsg("操作成功!");
  7437. CeErpSukuraData.createInfo(entity.ctid, 8);
  7438. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7439. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7440. return;
  7441. }
  7442. returnErrorMsg("找不到订单记录");
  7443. }
  7444. }
  7445. public void upd_erp_masteraftersale()
  7446. {
  7447. if (UrlPostParmsCheck("id"))
  7448. {
  7449. string id = GetPostString("id");
  7450. int st = GetPostInt("afterstate");
  7451. string afmemo = GetPostString("supmemo");
  7452. string image = GetPostString("image");
  7453. string textResult = GetPostString("textResult");
  7454. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7455. if (ceErpTradeResponsible != null)
  7456. {
  7457. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7458. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7459. ceErpTradeResponsible.Update();
  7460. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7461. if (entity != null)
  7462. {
  7463. entity.AfterSaleSupplierState = st;
  7464. entity.AfterSaleSupplierMemo = afmemo;
  7465. if (st == 1)
  7466. {
  7467. }
  7468. else
  7469. {
  7470. CeErpTradeResponsible.dateByTid(entity.ctid);
  7471. //退回到售后
  7472. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7473. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7474. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7475. if (num <= 1)
  7476. {
  7477. entity.AfterSaleState = 1;
  7478. }
  7479. else
  7480. {
  7481. entity.AfterSaleState = 5;
  7482. }
  7483. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7484. if (ceErpTradeAfterSaleExtend != null)
  7485. {
  7486. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7487. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7488. ceErpTradeAfterSaleExtend.Update();
  7489. }
  7490. else
  7491. {
  7492. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7493. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7494. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7495. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7496. ceErpTradeAfterSaleExtend.Create();
  7497. }
  7498. }
  7499. entity.UpdateTime = DateTime.Now;
  7500. entity.Update();
  7501. returnSuccessMsg("操作成功!");
  7502. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7503. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7504. return;
  7505. }
  7506. }
  7507. returnErrorMsg("找不到订单记录");
  7508. }
  7509. }
  7510. public void upd_erp_personaftersale()
  7511. {
  7512. if (UrlPostParmsCheck("id"))
  7513. {
  7514. string id = GetPostString("id");
  7515. int st = GetPostInt("afterstate");
  7516. string afmemo = GetPostString("supmemo");
  7517. string image = GetPostString("image");
  7518. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7519. if (ceErpTradeResponsible != null)
  7520. {
  7521. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7522. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7523. ceErpTradeResponsible.Update();
  7524. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7525. if (entity != null)
  7526. {
  7527. entity.AfterSaleSupplierMemo = afmemo;
  7528. entity.AfterSaleSupplierState = st;
  7529. if (st == 1)
  7530. {
  7531. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7532. if (isAll)
  7533. {
  7534. entity.AfterSaleState = 4;
  7535. entity.FinishAfterSaleTime = DateTime.Now;
  7536. }
  7537. }
  7538. else
  7539. {
  7540. CeErpTradeResponsible.dateByTid(entity.ctid);
  7541. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7542. if (ceErpTradeAfterSaleExtend != null)
  7543. {
  7544. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7545. ceErpTradeAfterSaleExtend.Update();
  7546. }
  7547. else
  7548. {
  7549. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7550. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7551. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7552. ceErpTradeAfterSaleExtend.Create();
  7553. }
  7554. //退回到主管
  7555. //entity.AfterSaleState = 2;
  7556. }
  7557. if (entity.AfterSaleState == 4)
  7558. {
  7559. ApiVo apiVo = new ApiVo();
  7560. apiVo.orderNumber = entity.ctid;
  7561. apiVo.actionName = "afterOver";
  7562. designHelper.API_WorkCore(apiVo); //afterOver
  7563. }
  7564. entity.UpdateTime = DateTime.Now;
  7565. entity.Update();
  7566. returnSuccessMsg("操作成功!");
  7567. CeErpSukuraData.createInfo(entity.ctid, 8);
  7568. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7569. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7570. return;
  7571. }
  7572. }
  7573. returnErrorMsg("找不到订单记录");
  7574. }
  7575. }
  7576. public void set_erp_supplierrefundtag()
  7577. {
  7578. if (UrlPostParmsCheck("ctid"))
  7579. {
  7580. string eid = GetPostString("ctid");
  7581. CeErpTradeCell entity = null;
  7582. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7583. if (entity != null)
  7584. {
  7585. entity.IsSupplierRefund = GetPostInt("tag");
  7586. entity.Update();
  7587. returnSuccessMsg("操作成功!");
  7588. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7589. return;
  7590. }
  7591. returnErrorMsg("找不到订单记录");
  7592. }
  7593. }
  7594. public void get_erp_refundlist()
  7595. {
  7596. DataStruct dStruct = GetPostStruct();
  7597. List<string> lw = new List<string>();
  7598. string tid = GetPostString("tid");
  7599. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7600. //string rid = GetPostString("refund_id");
  7601. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7602. string shopname = GetPostString("shopname");
  7603. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7604. string buyernick = GetPostString("buyer_nick");
  7605. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7606. string customer = GetPostString("customer");
  7607. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7608. string design = GetPostString("design");
  7609. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7610. string sellermemo = GetPostString("seller_memo");
  7611. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7612. //string date1 = GetPostString("date1");
  7613. //string date2 = GetPostString("date2");
  7614. //string dateType = GetPostString("dateType");
  7615. //if (dateType.Length > 0)
  7616. //{
  7617. // if (dateType == "1001") dateType = "0";
  7618. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7619. // if (searchDT.Count == 2)
  7620. // {
  7621. // date1 = searchDT[0].ToString();
  7622. // date2 = searchDT[1].ToString();
  7623. // }
  7624. //}
  7625. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7626. //if (dw.Length > 0) lw.Add(dw);
  7627. string redate1 = GetPostString("refunddate1");
  7628. string redate2 = GetPostString("refunddate2");
  7629. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7630. if (dwdate.Length > 0) lw.Add(dwdate);
  7631. string price1 = GetPostString("price1");
  7632. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7633. string price2 = GetPostString("price2");
  7634. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7635. string ispartrefund = GetPostString("ispartrefund");
  7636. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7637. string refundState = GetPostString("refundvstate");
  7638. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7639. int st = GetInt("st");
  7640. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7641. {
  7642. string responsible = GetPostString("responsibleman");
  7643. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7644. lw.Add(string.Format("RefundState>={0}", st));
  7645. string code = CurrentUser.UserPost.Post.Code;
  7646. if (code == "CustomerService")
  7647. {
  7648. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7649. }
  7650. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7651. {
  7652. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7653. }
  7654. else if (code == "Place" || code == "PlaceMr")
  7655. {
  7656. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7657. }
  7658. dStruct.Order = "RefundState asc,created desc";
  7659. }
  7660. else if (st == 10)
  7661. {
  7662. string responsible = GetPostString("responsibleman");
  7663. if (responsible == "空白")
  7664. {
  7665. lw.Add(string.Format("ResponsibleUserName = ''"));
  7666. }
  7667. else if (responsible.Length > 0)
  7668. {
  7669. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7670. }
  7671. lw.Add(string.Format("RefundState>=0"));
  7672. dStruct.Order = "created desc";
  7673. }
  7674. else
  7675. {
  7676. string responsible = GetPostString("responsibleman");
  7677. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7678. lw.Add(string.Format("RefundState={0}", st));
  7679. dStruct.Order = "created desc";
  7680. }
  7681. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7682. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7683. dt.Columns.Add("refund_fees");
  7684. foreach (DataRow dr in dt.Rows)
  7685. {
  7686. String status = dr["status"].ToString();
  7687. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7688. {
  7689. dr["refund_fees"] = dr["refund_fee"];
  7690. }
  7691. else
  7692. {
  7693. dr["refund_fees"] = "0.0";
  7694. }
  7695. }
  7696. writeGridDataTableJson(dStruct.TotalCount, dt);
  7697. }
  7698. public void get_erp_refunddesignlist()
  7699. {
  7700. DataStruct dStruct = GetPostStruct();
  7701. List<string> lw = new List<string>();
  7702. string tid = GetPostString("tid");
  7703. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7704. string shopname = GetPostString("shopname");
  7705. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7706. string buyernick = GetPostString("buyer_nick");
  7707. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7708. string customer = GetPostString("customer");
  7709. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7710. string design = GetPostString("design");
  7711. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7712. string sellermemo = GetPostString("seller_memo");
  7713. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7714. string redate1 = GetPostString("refunddate1");
  7715. string redate2 = GetPostString("refunddate2");
  7716. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7717. if (dwdate.Length > 0) lw.Add(dwdate);
  7718. string price1 = GetPostString("price1");
  7719. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7720. string price2 = GetPostString("price2");
  7721. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7722. string ispartrefund = GetPostString("ispartrefund");
  7723. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7724. string designerorg = GetPostString("designerorg");
  7725. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7726. string refundState = GetPostString("refundState");
  7727. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7728. int myOrgid = CurrentUser.UserPost.OrgID;
  7729. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7730. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7731. {
  7732. if (CurrentUser.User.TeamIds.Length > 0)
  7733. {
  7734. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7735. }
  7736. else
  7737. {
  7738. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7739. }
  7740. }
  7741. else if ("SysAdmin".Equals(myOrgCode))
  7742. {
  7743. }
  7744. else
  7745. {
  7746. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7747. {
  7748. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7749. }
  7750. else
  7751. {
  7752. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7753. }
  7754. }
  7755. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7756. dStruct.Order = "created desc";
  7757. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7758. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7759. dt.Columns.Add("refund_fees");
  7760. foreach (DataRow dr in dt.Rows)
  7761. {
  7762. String status = dr["status"].ToString();
  7763. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7764. {
  7765. dr["refund_fees"] = dr["refund_fee"];
  7766. }
  7767. else
  7768. {
  7769. dr["refund_fees"] = "0.0";
  7770. }
  7771. }
  7772. writeGridDataTableJson(dStruct.TotalCount, dt);
  7773. }
  7774. public void handle_erp_refundtag()
  7775. {
  7776. if (UrlPostParmsCheck("refund_id"))
  7777. {
  7778. string eid = GetPostString("refund_id");
  7779. string respMan = GetPostString("ResponsibleName");
  7780. if (respMan.Length <= 0)
  7781. {
  7782. returnErrorMsg("责任人不能为空");
  7783. return;
  7784. }
  7785. CeErpTradeRefund entity = null;
  7786. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7787. if (entity != null)
  7788. {
  7789. entity.ResponsibleUserName = respMan;
  7790. string userid = GetPostString("ResponsibleUserId");
  7791. if (userid.Length > 0)
  7792. {
  7793. entity.ResponsibleUserId = userid;
  7794. }
  7795. entity.Memo = GetPostString("Memo");
  7796. if (respMan.IndexOf("客服") != -1 ||
  7797. respMan.IndexOf("设计师") != -1 ||
  7798. respMan.IndexOf("下单员") != -1)
  7799. {
  7800. entity.RefundState = 2;
  7801. }
  7802. else
  7803. {
  7804. entity.RefundState = 3;
  7805. }
  7806. entity.modified = DateTime.Now;
  7807. entity.Update();
  7808. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  7809. returnSuccessMsg("操作成功!");
  7810. return;
  7811. }
  7812. returnErrorMsg("找不到订单记录");
  7813. }
  7814. }
  7815. public void handle_erp_designrefundtag()
  7816. {
  7817. if (UrlPostParmsCheck("refund_id"))
  7818. {
  7819. string eid = GetPostString("refund_id");
  7820. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  7821. if (ceErpTradeCellExtend == null)
  7822. {
  7823. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  7824. ceErpTradeCellExtend.ctid = eid;
  7825. }
  7826. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  7827. if (ceErpTradeCellExtend.ID > 0)
  7828. {
  7829. ceErpTradeCellExtend.Update();
  7830. }
  7831. else
  7832. {
  7833. ceErpTradeCellExtend.Create();
  7834. }
  7835. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  7836. returnSuccessMsg("操作成功!");
  7837. return;
  7838. }
  7839. returnErrorMsg("找不到订单记录");
  7840. }
  7841. public void upd_erp_refundverify()
  7842. {
  7843. if (UrlPostParmsCheck("refund_id"))
  7844. {
  7845. string eid = GetPostString("refund_id");
  7846. CeErpTradeRefund entity = null;
  7847. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7848. if (entity != null)
  7849. {
  7850. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  7851. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  7852. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  7853. {
  7854. entity.RefundState = 2;
  7855. }
  7856. else
  7857. {
  7858. entity.RefundState = 3;
  7859. }
  7860. entity.Update();
  7861. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  7862. returnSuccessMsg("操作成功!");
  7863. return;
  7864. }
  7865. returnErrorMsg("找不到订单记录");
  7866. }
  7867. }
  7868. public void upd_erp_refundapprove()
  7869. {
  7870. if (UrlPostParmsCheck("refund_id"))
  7871. {
  7872. string eid = GetPostString("refund_id");
  7873. CeErpTradeRefund entity = null;
  7874. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7875. if (entity != null)
  7876. {
  7877. int apr = GetPostInt("approve");
  7878. if (apr == 0)
  7879. {
  7880. entity.RefundState = 1;
  7881. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  7882. }
  7883. else if (apr == 1)
  7884. {
  7885. entity.RefundState = 3;
  7886. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  7887. }
  7888. entity.modified = DateTime.Now;
  7889. entity.Update();
  7890. returnSuccessMsg("操作成功!");
  7891. return;
  7892. }
  7893. returnErrorMsg("找不到订单记录");
  7894. }
  7895. }
  7896. public void get_erp_billlist()
  7897. {
  7898. DataStruct dStruct = GetPostStruct();
  7899. List<string> lw = new List<string>();
  7900. string title = GetPostString("title");
  7901. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  7902. string tid = GetPostString("tid");
  7903. string tids = GetPostString("tids");
  7904. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7905. if (tids.Length > 0)
  7906. {
  7907. tids = "'" + tids + "'";
  7908. tids = tids.Replace(",", "','");
  7909. lw.Add(string.Format("tid in ({0})", tids));
  7910. }
  7911. string shopname = GetPostString("shopname");
  7912. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7913. string buyernick = GetPostString("buyer_nick");
  7914. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7915. string customer = GetPostString("customer");
  7916. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7917. string date1 = GetPostString("date1");
  7918. string date2 = GetPostString("date2");
  7919. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7920. if (dw.Length > 0) lw.Add(dw);
  7921. string price1 = GetPostString("price1");
  7922. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7923. string price2 = GetPostString("price2");
  7924. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7925. string returndate1 = GetPostString("returndate1");
  7926. string returndate2 = GetPostString("returndate2");
  7927. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  7928. if (dw1.Length > 0) lw.Add(dw1);
  7929. string billtype = GetPostString("billtype");
  7930. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  7931. string billstate = GetPostString("billstate");
  7932. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  7933. string usershop = CurrentUser.User.pemShop;
  7934. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  7935. dStruct.Order = "createTime desc";
  7936. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7937. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  7938. //foreach (DataRow dr in dt.Rows)
  7939. //{
  7940. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  7941. //}
  7942. writeGridDataTableJson(dStruct.TotalCount, dt);
  7943. }
  7944. public void modify_erp_billinfo()
  7945. {
  7946. if (UrlPostParmsCheck("ID"))
  7947. {
  7948. string eid = GetPostString("ID");
  7949. CeErpBill bill_entity = null;
  7950. if (eid != "") bill_entity = CeErpBill.Get(eid);
  7951. if (bill_entity != null)
  7952. {
  7953. bill_entity.tid = GetPostString("tid");
  7954. bill_entity.title = GetPostString("title");
  7955. bill_entity.tax = GetPostString("tax");
  7956. bill_entity.bank = GetPostString("bank");
  7957. bill_entity.bankac = GetPostString("bankac");
  7958. bill_entity.address = GetPostString("address");
  7959. bill_entity.phone = GetPostString("phone");
  7960. bill_entity.price = GetPostString("price");
  7961. bill_entity.productId = GetPostInt("ProductName");
  7962. bill_entity.num = GetPostInt("num");
  7963. bill_entity.unit = GetPostString("unit");
  7964. bill_entity.type = GetPostString("type");
  7965. bill_entity.sendType = GetPostString("SendType");
  7966. bill_entity.email = GetPostString("email");
  7967. bill_entity.buyer_nick = GetPostString("buyer_nick");
  7968. bill_entity.shopName = GetPostString("ShopName");
  7969. bill_entity.applymemo = GetPostString("applymemo");
  7970. bill_entity.modifyTime = DateTime.Now;
  7971. bill_entity.createTime = DateTime.Now;
  7972. bill_entity.state = 0;
  7973. bill_entity.Update();
  7974. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  7975. returnSuccessMsg("发票修改成功!");
  7976. return;
  7977. }
  7978. returnErrorMsg("找不到对应记录");
  7979. }
  7980. }
  7981. public void set_erp_invoicing()
  7982. {
  7983. if (UrlPostParmsCheck("id"))
  7984. {
  7985. try
  7986. {
  7987. string eid = GetPostString("id");
  7988. CeErpBill bill_entity = null;
  7989. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  7990. if (bill_entity != null)
  7991. {
  7992. int ComId = GetPostInt("ComId");
  7993. //string memo = GetPostString("Memo");
  7994. int allInfo = GetPostInt("allinfo");
  7995. string clert = CurrentUser.User.Name;
  7996. //string detailValue = GetPostString("detailvalue");
  7997. string billId = bill_entity.billOrderId;
  7998. string[] billIdList = billId.Split(',');
  7999. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8000. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8001. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8002. {
  8003. billCount += 1;
  8004. }
  8005. if (billId.Length <= 0 || billIdList.Length != billCount)
  8006. {
  8007. bill_entity.billOrderId = "";
  8008. string prebill = "ltb";
  8009. for (int idx = 1; idx <= billCount; idx++)
  8010. {
  8011. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8012. string billoid = prebill + idx + dtstr;
  8013. bill_entity.billOrderId += billoid;
  8014. if (idx < billCount)
  8015. {
  8016. bill_entity.billOrderId += ",";
  8017. }
  8018. }
  8019. }
  8020. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8021. if (bill_entity.state == 5)
  8022. {
  8023. string errMsg = bill_entity.failerror;
  8024. string[] errlist = errMsg.Split('|');
  8025. string[] errTags = new string[errlist.Length];
  8026. for (int itag = 0; itag < errlist.Length; itag++)
  8027. {
  8028. if (errlist[itag].Length <= 0) continue;
  8029. errTags[itag] = errlist[itag].Split('&')[0];
  8030. }
  8031. for (int iii = 0; iii < errTags.Length; iii++)
  8032. {
  8033. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8034. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8035. if (billOrderList.Length >= erroBillOrderTag)
  8036. {
  8037. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8038. if (needModifyBillId.Length <= 19)
  8039. {
  8040. needModifyBillId = needModifyBillId + "1";
  8041. }
  8042. else
  8043. {
  8044. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8045. last = last + 1;
  8046. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8047. }
  8048. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8049. }
  8050. }
  8051. }
  8052. bool isHaveBillSucces = false;
  8053. string totalRes = "";
  8054. bill_entity.failerror = "";
  8055. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8056. {
  8057. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8058. totalRes += res;
  8059. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8060. {
  8061. isHaveBillSucces = true;
  8062. bill_entity.comId = ComId;
  8063. bill_entity.state = 1;
  8064. bill_entity.executeTime = DateTime.Now;
  8065. bill_entity.executeUser = clert;
  8066. }
  8067. else
  8068. {
  8069. bill_entity.state = 5;
  8070. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8071. }
  8072. }
  8073. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8074. bill_entity.Update();
  8075. if (isHaveBillSucces)
  8076. {
  8077. StringBuilder sql = new StringBuilder();
  8078. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8079. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8080. }
  8081. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8082. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8083. {
  8084. returnErrorMsg("开票失败");
  8085. }
  8086. else
  8087. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8088. return;
  8089. }
  8090. returnErrorMsg("找不到对应记录");
  8091. }
  8092. catch (Exception ex)
  8093. {
  8094. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8095. returnErrorMsg("操作失败");
  8096. }
  8097. }
  8098. }
  8099. public void get_erp_invoicing_back()
  8100. {
  8101. if (UrlPostParmsCheck("id"))
  8102. {
  8103. try
  8104. {
  8105. string id = GetPostString("id");
  8106. CeErpBill entiy = CeErpBill.Get(id);
  8107. if (entiy != null)
  8108. {
  8109. if (entiy.state == 0)
  8110. {
  8111. returnErrorMsg("发票还未开具");
  8112. return;
  8113. }
  8114. string[] billOrderList = entiy.billOrderId.Split(',');
  8115. int iTag = 0;
  8116. entiy.fplsh = "";
  8117. entiy.fpdm = "";
  8118. entiy.fphm = "";
  8119. foreach (string billOrderId in billOrderList)
  8120. {
  8121. iTag++;
  8122. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8123. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8124. {
  8125. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8126. try
  8127. {
  8128. Invoicing_get_response_Obj iObj = null;
  8129. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8130. if (iObj != null)
  8131. {
  8132. entiy.state = 2;
  8133. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8134. entiy.fpdm += iObj.list[0].c_fpdm;
  8135. entiy.fphm += iObj.list[0].c_fphm;
  8136. if (iTag < billOrderList.Length)
  8137. {
  8138. entiy.fplsh += ",";
  8139. entiy.fpdm += ",";
  8140. entiy.fphm += ",";
  8141. }
  8142. entiy.Update();
  8143. }
  8144. StringBuilder sql = new StringBuilder();
  8145. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8146. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8147. returnSuccessMsg("开票成功");
  8148. }
  8149. catch (Exception ex)
  8150. {
  8151. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8152. }
  8153. return;
  8154. }
  8155. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8156. {
  8157. var res_obj = new
  8158. {
  8159. data = "开票中"
  8160. };
  8161. string ro_json = JsonConvert.SerializeObject(res_obj);
  8162. returnSuccess(ro_json);
  8163. return;
  8164. }
  8165. else
  8166. {
  8167. int eidx = res.IndexOf("c_resultmsg");
  8168. int lidx = res.IndexOf("c_status");
  8169. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8170. entiy.state = 5;
  8171. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8172. entiy.Update();
  8173. returnErrorMsg("开票失败");
  8174. return;
  8175. }
  8176. }
  8177. }
  8178. }
  8179. catch (Exception ex)
  8180. {
  8181. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8182. }
  8183. return;
  8184. }
  8185. }
  8186. public void get_erp_invoicing()
  8187. {
  8188. if (UrlPostParmsCheck("id"))
  8189. {
  8190. try
  8191. {
  8192. string id = GetPostString("id");
  8193. CeErpBill entiy = CeErpBill.Get(id);
  8194. if (entiy != null)
  8195. {
  8196. if (entiy.state == 0)
  8197. {
  8198. returnErrorMsg("发票还未开具");
  8199. return;
  8200. }
  8201. if (entiy.sendType == "纸质发票")
  8202. {
  8203. if (entiy.img.Length <= 0)
  8204. {
  8205. returnErrorMsg("查无纸质发票");
  8206. return;
  8207. }
  8208. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8209. returnSuccess(returnres);
  8210. return;
  8211. }
  8212. string[] billOrderList = entiy.billOrderId.Split(',');
  8213. int iTag = 0;
  8214. string fpUrl = "";
  8215. entiy.fplsh = "";
  8216. entiy.fpdm = "";
  8217. entiy.fphm = "";
  8218. foreach (string billOrderId in billOrderList)
  8219. {
  8220. iTag++;
  8221. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8222. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8223. {
  8224. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8225. Invoicing_get_response_Obj iObj = null;
  8226. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8227. if (iObj != null)
  8228. {
  8229. //entiy.state = 2;
  8230. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8231. entiy.fpdm += iObj.list[0].c_fpdm;
  8232. entiy.fphm += iObj.list[0].c_fphm;
  8233. if (iTag < billOrderList.Length)
  8234. {
  8235. entiy.fplsh += ",";
  8236. entiy.fpdm += ",";
  8237. entiy.fphm += ",";
  8238. }
  8239. entiy.Update();
  8240. fpUrl += iObj.list[0].c_url + ",";
  8241. }
  8242. //returnSuccess(res);
  8243. StringBuilder sql = new StringBuilder();
  8244. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8245. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8246. }
  8247. else
  8248. {
  8249. int eidx = res.IndexOf("c_resultmsg");
  8250. //int lidx = res.IndexOf("c_status");
  8251. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8252. //开票失败
  8253. entiy.state = 5;
  8254. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8255. entiy.Update();
  8256. returnErrorMsg("开票失败");
  8257. return;
  8258. }
  8259. }
  8260. var returnObj = new
  8261. {
  8262. data = fpUrl
  8263. };
  8264. string ro_json = JsonConvert.SerializeObject(returnObj);
  8265. returnSuccess(ro_json);
  8266. }
  8267. }
  8268. catch (Exception ex)
  8269. {
  8270. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8271. }
  8272. return;
  8273. }
  8274. }
  8275. public void save_erp_billimg()
  8276. {
  8277. if (UrlPostParmsCheck("id"))
  8278. {
  8279. string eid = GetPostString("id");
  8280. CeErpBill bill_entity = null;
  8281. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8282. if (bill_entity != null)
  8283. {
  8284. bill_entity.img = GetPostString("img");
  8285. bill_entity.executeTime = DateTime.Now;
  8286. bill_entity.state = 2;
  8287. bill_entity.Update();
  8288. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8289. returnSuccessMsg("保存成功");
  8290. }
  8291. return;
  8292. }
  8293. }
  8294. public void upd_erp_billreturnback()
  8295. {
  8296. if (UrlPostParmsCheck("id"))
  8297. {
  8298. int eid = GetPostInt("id");
  8299. CeErpBill bill_entity = null;
  8300. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8301. if (bill_entity != null)
  8302. {
  8303. bill_entity.state = 3;
  8304. bill_entity.returnReason = GetPostString("reason");
  8305. bill_entity.Update();
  8306. returnSuccessMsg("驳回成功!");
  8307. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8308. }
  8309. return;
  8310. }
  8311. }
  8312. public void cancel_erp_bill()
  8313. {
  8314. if (UrlPostParmsCheck("id"))
  8315. {
  8316. int eid = GetPostInt("id");
  8317. int detailValue = GetPostInt("detailvalue");
  8318. CeErpBill bill_entity = null;
  8319. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8320. string cres = "";
  8321. string gres = "";
  8322. if (bill_entity != null)
  8323. {
  8324. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8325. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8326. {
  8327. int iTag = 0;
  8328. bill_entity.fplsh = "";
  8329. bill_entity.fpdm = "";
  8330. bill_entity.fphm = "";
  8331. foreach (string billOrderId in billOrderList)
  8332. {
  8333. iTag++;
  8334. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8335. if (gres.IndexOf("success") != -1)
  8336. {
  8337. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8338. Invoicing_get_response_Obj iObj = null;
  8339. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8340. if (iObj != null)
  8341. {
  8342. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8343. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8344. bill_entity.fphm += iObj.list[0].c_fphm;
  8345. if (iTag < billOrderList.Length)
  8346. {
  8347. bill_entity.fplsh += ",";
  8348. bill_entity.fpdm += ",";
  8349. bill_entity.fphm += ",";
  8350. }
  8351. bill_entity.Update();
  8352. }
  8353. }
  8354. else
  8355. {
  8356. returnErrorMsg(gres);
  8357. return;
  8358. }
  8359. }
  8360. }
  8361. if (bill_entity.sendType == "纸质发票")
  8362. {
  8363. //作废
  8364. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8365. //if (DateTime.Now.Month == extime.Month)
  8366. //{
  8367. //cres = taobaoHelper.cancel_invoicing(eid);
  8368. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8369. //{
  8370. bill_entity.state = 4;//已作废
  8371. bill_entity.Update();
  8372. returnSuccessMsg("发票已作废");
  8373. return;
  8374. //}
  8375. //else
  8376. //{
  8377. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8378. // bill_entity.Update();
  8379. // returnErrorMsg(cres);
  8380. // return;
  8381. //}
  8382. //}
  8383. //else
  8384. //{
  8385. // returnErrorMsg("纸质发票只能作废本月的发票");
  8386. // return;
  8387. //}
  8388. }
  8389. //红冲
  8390. int redTag = 0;
  8391. string[] fpdmList = bill_entity.fpdm.Split(',');
  8392. string[] fphmList = bill_entity.fphm.Split(',');
  8393. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8394. {
  8395. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8396. return;
  8397. }
  8398. foreach (string billOrderId in billOrderList)
  8399. {
  8400. redTag++;
  8401. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8402. cres += onecres;
  8403. cres += ",";
  8404. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8405. {
  8406. bill_entity.state = 4;//已作废
  8407. //bill_entity.Update();
  8408. //returnSuccessMsg("发票已红冲");
  8409. }
  8410. else if (onecres.IndexOf("重复冲红") != -1)
  8411. {
  8412. bill_entity.state = 4;//已作废
  8413. //bill_entity.Update();
  8414. //returnSuccessMsg("发票已红冲");
  8415. }
  8416. else
  8417. {
  8418. string errmsg = commonHelper.KeepChinese(onecres);
  8419. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8420. }
  8421. }
  8422. bill_entity.Update();
  8423. if (cres.IndexOf("失败") != -1)
  8424. returnErrorMsg("红冲失败");
  8425. else
  8426. returnSuccessMsg("发票已红冲");
  8427. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8428. return;
  8429. }
  8430. return;
  8431. }
  8432. }
  8433. public void del_erp_billorder()
  8434. {
  8435. if (UrlPostParmsCheck("id"))
  8436. {
  8437. string eid = GetPostString("id");
  8438. CeErpBill.Del(eid);
  8439. CeErpBill bill = CeErpBill.Get(eid);
  8440. if (bill != null)
  8441. {
  8442. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8443. }
  8444. returnSuccessMsg("删除成功");
  8445. }
  8446. }
  8447. public void finish_erp_bill()
  8448. {
  8449. if (UrlPostParmsCheck("ids"))
  8450. {
  8451. string eids = GetPostString("ids");
  8452. string[] list = eids.Split(',');
  8453. foreach (string eid in list)
  8454. {
  8455. CeErpBill bill = CeErpBill.Get(eid);
  8456. if (bill != null)
  8457. {
  8458. bill.state = 2;
  8459. bill.Update();
  8460. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8461. }
  8462. }
  8463. returnSuccessMsg("操作成功");
  8464. }
  8465. }
  8466. public void get_erp_returncash()
  8467. {
  8468. DataStruct dStruct = GetPostStruct();
  8469. List<string> lw = new List<string>();
  8470. string tid = GetPostString("tid");
  8471. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8472. string shopname = GetPostString("shopname");
  8473. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8474. string buyernick = GetPostString("buyer_nick");
  8475. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8476. string customer = GetPostString("customer");
  8477. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8478. string returndate1 = GetPostString("returndate1");
  8479. string returndate2 = GetPostString("returndate2");
  8480. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8481. if (dw.Length > 0) lw.Add(dw);
  8482. string finishDate1 = GetPostString("finishdate1");
  8483. string finishDate2 = GetPostString("finishdate2");
  8484. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8485. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8486. string returntype = GetPostString("returntype");
  8487. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8488. string returnvstate = GetPostString("returnvstate");
  8489. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8490. dStruct.Order = "created desc";
  8491. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8492. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8493. writeGridDataTableJson(dStruct.TotalCount, dt);
  8494. }
  8495. public void get_erp_staygoods()
  8496. {
  8497. DataStruct dStruct = GetPostStruct();
  8498. List<string> lw = new List<string>();
  8499. string tid = GetPostString("tid");
  8500. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8501. string shopname = GetPostString("shopname");
  8502. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8503. string wangwang = GetPostString("wangwang");
  8504. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8505. string customer = GetPostString("customer");
  8506. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8507. string returndate1 = GetPostString("returndate1");
  8508. string returndate2 = GetPostString("returndate2");
  8509. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8510. if (dw.Length > 0) lw.Add(dw);
  8511. string finishDate1 = GetPostString("finishdate1");
  8512. string finishDate2 = GetPostString("finishdate2");
  8513. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8514. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8515. string returnvstate = GetPostString("returnvstate");
  8516. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8517. string persuadetype = GetPostString("persuadetype");
  8518. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8519. string customerOrg = GetPostString("customerOrg");
  8520. if (customerOrg.Length > 0)
  8521. {
  8522. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8523. }
  8524. dStruct.Order = "creata_time desc";
  8525. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8526. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8527. writeGridDataTableJson(dStruct.TotalCount, dt);
  8528. }
  8529. public void upd_erp_staygoods()
  8530. {
  8531. if (UrlPostParmsCheck("id"))
  8532. {
  8533. int eid = GetPostInt("id");
  8534. CeErpStayGoods entity = null;
  8535. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8536. if (entity != null)
  8537. {
  8538. entity.audit_type = 1;
  8539. entity.audit_time = DateTime.Now;
  8540. entity.audit_u_id = CurrentUser.UserID;
  8541. entity.audit_u_name = CurrentUser.UserName;
  8542. entity.Update();
  8543. returnSuccessMsg("审核成功!");
  8544. return;
  8545. }
  8546. returnErrorMsg("找不到订单记录");
  8547. }
  8548. }
  8549. public void upd_erp_stayGoodsback()
  8550. {
  8551. if (UrlPostParmsCheck("id"))
  8552. {
  8553. int eid = GetPostInt("id");
  8554. CeErpStayGoods entity = null;
  8555. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8556. if (entity != null)
  8557. {
  8558. entity.audit_text = GetPostString("reason");
  8559. entity.audit_type = 2;
  8560. entity.audit_time = DateTime.Now;
  8561. entity.audit_u_id = CurrentUser.UserID;
  8562. entity.audit_u_name = CurrentUser.UserName;
  8563. entity.Update();
  8564. returnSuccessMsg("退回成功!");
  8565. return;
  8566. }
  8567. returnErrorMsg("找不到订单记录");
  8568. }
  8569. }
  8570. public void upd_erp_returncashverify()
  8571. {
  8572. if (UrlPostParmsCheck("ID"))
  8573. {
  8574. int eid = GetPostInt("ID");
  8575. CeErpReturnCash entity = null;
  8576. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8577. if (entity != null)
  8578. {
  8579. entity.cashstate = 1;
  8580. entity.verifytime = DateTime.Now;
  8581. entity.verifyuserid = CurrentUser.UserID;
  8582. entity.Update();
  8583. returnSuccessMsg("审核成功!");
  8584. return;
  8585. }
  8586. returnErrorMsg("找不到订单记录");
  8587. }
  8588. }
  8589. public void upd_all_erp_returncashverify()
  8590. {
  8591. if (UrlPostParmsCheck("ID"))
  8592. {
  8593. String[] list = GetPostString("ID").Split(',');
  8594. CeErpReturnCash entity = null;
  8595. for (int i = 0; i < list.Length; i++)
  8596. {
  8597. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8598. if (entity != null)
  8599. {
  8600. if (entity.cashstate == 1)
  8601. {
  8602. returnErrorMsg("已审核过的订单不需要在审核!");
  8603. return;
  8604. }
  8605. entity.cashstate = 1;
  8606. entity.verifytime = DateTime.Now;
  8607. entity.verifyuserid = CurrentUser.UserID;
  8608. entity.Update();
  8609. }
  8610. }
  8611. returnSuccessMsg("审核成功!");
  8612. return;
  8613. }
  8614. }
  8615. public void upd_erp_returncashback()
  8616. {
  8617. if (UrlPostParmsCheck("ID"))
  8618. {
  8619. int eid = GetPostInt("ID");
  8620. CeErpReturnCash entity = null;
  8621. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8622. if (entity != null)
  8623. {
  8624. entity.backreason = GetPostString("reason");
  8625. entity.cashstate = 2;
  8626. entity.verifytime = DateTime.Now;
  8627. entity.verifyuserid = CurrentUser.UserID;
  8628. entity.Update();
  8629. returnSuccessMsg("退回成功!");
  8630. return;
  8631. }
  8632. returnErrorMsg("找不到订单记录");
  8633. }
  8634. }
  8635. public void upd_erp_returnprice()
  8636. {
  8637. if (UrlPostParmsCheck("ID"))
  8638. {
  8639. int eid = GetPostInt("ID");
  8640. CeErpReturnCash entity = null;
  8641. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8642. if (entity != null)
  8643. {
  8644. if (entity.cashstate == 1)
  8645. {
  8646. returnErrorMsg("审核通过了不能改");
  8647. return;
  8648. }
  8649. entity.returnprice = GetPostDouble("returnprice");
  8650. entity.Update();
  8651. returnSuccessMsg("修改成功!");
  8652. return;
  8653. }
  8654. returnErrorMsg("找不到订单记录");
  8655. }
  8656. }
  8657. public void del_erp_returncash()
  8658. {
  8659. if (UrlPostParmsCheck("ID"))
  8660. {
  8661. int eid = GetPostInt("ID");
  8662. CeErpReturnCash.Del(eid);
  8663. returnSuccessMsg("操作成功");
  8664. return;
  8665. }
  8666. }
  8667. public void test_for_do_sql()
  8668. {
  8669. string sql = GetPostString("sqlstr");
  8670. if (sql.Length > 0)
  8671. {
  8672. try
  8673. {
  8674. DbHelper.DbConn.ExecuteNonQuery(sql);
  8675. var res_obj = new
  8676. {
  8677. data = "成功",
  8678. };
  8679. string ro_json = JsonConvert.SerializeObject(res_obj);
  8680. returnSuccess(ro_json);
  8681. }
  8682. catch (Exception ex)
  8683. {
  8684. var res_obj = new
  8685. {
  8686. data = ex.Message,
  8687. };
  8688. string ro_json = JsonConvert.SerializeObject(res_obj);
  8689. returnSuccess(ro_json);
  8690. }
  8691. }
  8692. }
  8693. public void get_user_info()
  8694. {
  8695. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8696. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8697. }
  8698. public void get_total_data()
  8699. {
  8700. int userId = CurrentUser.UserID;
  8701. string sql = "";
  8702. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8703. {
  8704. 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);
  8705. }
  8706. else
  8707. {
  8708. 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 " +
  8709. "(select ID from CE_ErpUser where ID = {0}) d " +
  8710. "left join " +
  8711. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8712. ") a on d.ID = a.id left join " +
  8713. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8714. ") b on a.id = b.id1 left join" +
  8715. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8716. ") c on a.id = c.id2;", userId);
  8717. }
  8718. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8719. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8720. }
  8721. public void get_date_area_total_data2()
  8722. {
  8723. int userId = CurrentUser.UserID;
  8724. string date_type = GetPostString("timetype");
  8725. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8726. string sql = "";
  8727. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8728. {
  8729. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8730. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8731. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8732. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8733. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8734. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8735. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8736. ") a on e.ID = a.id left join " +
  8737. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8738. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8739. ") b on a.id = b.id1 " +
  8740. "left join " +
  8741. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8742. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8743. ") c on a.id = c.id2 " +
  8744. "left join " +
  8745. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8746. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8747. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8748. }
  8749. else
  8750. {
  8751. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8752. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8753. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8754. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8755. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8756. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8757. ") a on e.ID = a.id left join " +
  8758. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8759. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8760. ") c on a.id = c.id2 " +
  8761. "left join " +
  8762. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8763. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8764. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8765. }
  8766. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8767. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8768. }
  8769. public void get_date_area_total_data()
  8770. {
  8771. int userId = CurrentUser.UserID;
  8772. string date_type = GetPostString("timetype");
  8773. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8774. string date1 = searchDT[0].ToString();
  8775. string date2 = searchDT[1].ToString();
  8776. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8777. {
  8778. SqlParameter[] sqlParameter ={
  8779. new SqlParameter("@userId", SqlDbType.Int,4),
  8780. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8781. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8782. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8783. };
  8784. sqlParameter[0].Value = userId;
  8785. sqlParameter[1].Value = date1;
  8786. sqlParameter[2].Value = date2;
  8787. sqlParameter[3].Direction = ParameterDirection.Output;
  8788. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8789. string res = sqlParameter[3].Value.ToString();
  8790. var res_obj = new
  8791. {
  8792. data = res
  8793. };
  8794. string ro_json = JsonConvert.SerializeObject(res_obj);
  8795. returnSuccess(ro_json);
  8796. }
  8797. else
  8798. {
  8799. SqlParameter[] sqlParameter ={
  8800. new SqlParameter("@userId", SqlDbType.Int,4),
  8801. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8802. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8803. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8804. };
  8805. sqlParameter[0].Value = userId;
  8806. sqlParameter[1].Value = date1;
  8807. sqlParameter[2].Value = date2;
  8808. sqlParameter[3].Direction = ParameterDirection.Output;
  8809. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  8810. string res = sqlParameter[3].Value.ToString();
  8811. var res_obj = new
  8812. {
  8813. data = res
  8814. };
  8815. string ro_json = JsonConvert.SerializeObject(res_obj);
  8816. returnSuccess(ro_json);
  8817. }
  8818. //writeGridDataViewJson(dt.Rows.Count, dv);
  8819. }
  8820. public void get_order_list()
  8821. {
  8822. string strFields = GetPostString("paraFields");
  8823. string strOrder = GetPostString("paraOrder");
  8824. string strWhere = GetPostString("paraWhere");
  8825. string strPageSize = GetPostString("paraPageSize");
  8826. DataStruct dStruct = GetPostStruct();
  8827. dStruct.PageSize = int.Parse(strPageSize);
  8828. dStruct.Fileds = strFields;
  8829. dStruct.Order = strOrder;
  8830. dStruct.MainWhere = strWhere;
  8831. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8832. writeGridDataTableJson(dStruct.TotalCount, dt);
  8833. }
  8834. ////获取待开始订单列表
  8835. //public void get_wait_design_order_list()
  8836. //{
  8837. // string date_type = GetPostString("date_type");
  8838. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8839. // DataStruct dStruct = GetPostStruct();
  8840. // dStruct.PageSize = 1000;
  8841. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  8842. // List<string> lw = new List<string>();
  8843. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  8844. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  8845. // dStruct.Order = "WaitDesignTime asc";
  8846. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8847. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8848. // writeGridDataTableJson(dStruct.TotalCount, dt);
  8849. //}
  8850. //获取完成单量排名
  8851. public void get_finish_order_count_ranking()
  8852. {
  8853. /* string date_type = GetPostString("date_type");
  8854. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8855. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  8856. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8857. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  8858. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  8859. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8860. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  8861. writeGridDataTableJson(0, new DataTable());
  8862. }
  8863. public void get_finish_order_amount_ranking()
  8864. {
  8865. /*string date_type = GetPostString("date_type");
  8866. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8867. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  8868. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8869. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  8870. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  8871. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8872. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  8873. writeGridDataTableJson(0, new DataTable());
  8874. }
  8875. public void get_finish_refund_count_ranking()
  8876. {
  8877. string date_type = GetPostString("date_type");
  8878. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8879. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  8880. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8881. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  8882. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  8883. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8884. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8885. writeGridDataTableJson(dt.Rows.Count, dt);
  8886. }
  8887. public void get_finish_refund_amount_ranking()
  8888. {
  8889. string date_type = GetPostString("date_type");
  8890. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8891. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  8892. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  8893. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  8894. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  8895. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  8896. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8897. writeGridDataTableJson(dt.Rows.Count, dt);
  8898. }
  8899. public void set_erp_finishorder_director()
  8900. {
  8901. if (UrlPostParmsCheck("ctid"))
  8902. {
  8903. string eid = GetPostString("ctid");
  8904. CeErpTradeCell entity = null;
  8905. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  8906. if (entity != null)
  8907. {
  8908. entity.OrderState = 8;
  8909. entity.Update();
  8910. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  8911. returnSuccessMsg("操作成功!");
  8912. return;
  8913. }
  8914. returnErrorMsg("找不到记录");
  8915. }
  8916. }
  8917. public void get_erp_placeregistlist()
  8918. {
  8919. DataStruct dStruct = GetPostStruct();
  8920. List<string> lw = new List<string>();
  8921. string outsid = GetPostString("outsid");
  8922. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  8923. string memo = GetPostString("memo");
  8924. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  8925. string filename = GetPostString("filename");
  8926. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  8927. string islate = GetPostString("islate");
  8928. if (islate.Length > 0)
  8929. {
  8930. if (islate == "1")
  8931. lw.Add(string.Format("OutLate>0"));
  8932. else
  8933. lw.Add(string.Format("OutLate=0"));
  8934. }
  8935. string placedate1 = GetPostString("placedate1");
  8936. string placedate2 = GetPostString("placedate2");
  8937. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  8938. if (dw.Length > 0) lw.Add(dw);
  8939. string deliveryDate1 = GetPostString("deliverydate1");
  8940. string deliveryDate2 = GetPostString("deliverydate2");
  8941. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  8942. if (dw_deli.Length > 0) lw.Add(dw_deli);
  8943. dStruct.Order = "ID desc";
  8944. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8945. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  8946. writeGridDataTableJson(dStruct.TotalCount, dt);
  8947. }
  8948. public void ins_erp_placeregist()
  8949. {
  8950. if (UrlPostParmsCheck("id"))
  8951. {
  8952. string eid = GetPostString("id");
  8953. CeErpPlaceRegister entity = null;
  8954. if (eid == "0")//新增
  8955. {
  8956. entity = new CeErpPlaceRegister();
  8957. string xdTime = GetPostString("placeTime");
  8958. if (xdTime.Length > 0)
  8959. {
  8960. entity.PlactTime = Convert.ToDateTime(xdTime);
  8961. }
  8962. string fhTime = GetPostString("deliveryTime");
  8963. if (fhTime.Length > 0)
  8964. {
  8965. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  8966. }
  8967. string preTime = GetPostString("preOutTime");
  8968. if (preTime.Length > 0)
  8969. {
  8970. entity.PreOutTime = Convert.ToDateTime(preTime);
  8971. }
  8972. entity.DeliveryCount = GetPostInt("deliveryCount");
  8973. entity.ReceiveCount = GetPostInt("receiveCount");
  8974. entity.OutSid = GetPostString("outSid");
  8975. entity.FileName = GetPostString("fileName");
  8976. entity.Memo = GetPostString("memo");
  8977. entity.AddUserId = CurrentUser.UserID;
  8978. entity.CreateTime = DateTime.Now;
  8979. entity.Img = GetPostString("img");
  8980. entity.Supplier = GetPostInt("supplier");
  8981. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  8982. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  8983. {
  8984. DateTime dt1 = (DateTime)entity.DeliveryTime;
  8985. DateTime dt2 = (DateTime)entity.PreOutTime;
  8986. TimeSpan span = dt1.Subtract(dt2);
  8987. if (span.Days > 0)
  8988. {
  8989. entity.OutLate = span.Days;
  8990. }
  8991. }
  8992. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  8993. entity.Create();
  8994. returnSuccessMsg("添加成功!");
  8995. return;
  8996. }
  8997. else //修改
  8998. {
  8999. entity = CeErpPlaceRegister.Get(eid);
  9000. if (entity != null)
  9001. {
  9002. string xdTime = GetPostString("placeTime");
  9003. if (xdTime.Length > 0)
  9004. {
  9005. entity.PlactTime = Convert.ToDateTime(xdTime);
  9006. }
  9007. string fhTime = GetPostString("deliveryTime");
  9008. if (fhTime.Length > 0)
  9009. {
  9010. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9011. }
  9012. string preTime = GetPostString("preOutTime");
  9013. if (preTime.Length > 0)
  9014. {
  9015. entity.PreOutTime = Convert.ToDateTime(preTime);
  9016. }
  9017. entity.DeliveryCount = GetPostInt("deliveryCount");
  9018. entity.ReceiveCount = GetPostInt("receiveCount");
  9019. if (entity.DeliveryCount == entity.ReceiveCount)
  9020. {
  9021. entity.CurState = "已完成";
  9022. }
  9023. else
  9024. {
  9025. entity.CurState = "未完成";
  9026. }
  9027. entity.OutSid = GetPostString("outSid");
  9028. entity.FileName = GetPostString("fileName");
  9029. entity.Memo = GetPostString("memo");
  9030. entity.Img = GetPostString("img");
  9031. entity.Supplier = GetPostInt("supplier");
  9032. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9033. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9034. {
  9035. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9036. DateTime dt2 = (DateTime)entity.PreOutTime;
  9037. TimeSpan span = dt1.Subtract(dt2);
  9038. if (span.Days > 0)
  9039. {
  9040. entity.OutLate = span.Days;
  9041. }
  9042. }
  9043. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9044. entity.Update();
  9045. returnSuccessMsg("修改成功");
  9046. return;
  9047. }
  9048. returnErrorMsg("找不到对应的记录");
  9049. return;
  9050. }
  9051. }
  9052. returnErrorMsg("缺少必要参数");
  9053. }
  9054. public void del_erp_placeregist()
  9055. {
  9056. string eid = GetPostString("id");
  9057. CeErpPlaceRegister.Del(eid);
  9058. returnSuccessMsg("删除成功!");
  9059. return;
  9060. }
  9061. public void ins_erp_placeregistbyorder()
  9062. {
  9063. string ctid = GetPostString("ctid");
  9064. if (ctid.Length > 0)
  9065. {
  9066. StringBuilder sql = new StringBuilder();
  9067. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9068. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9069. if (dt.Rows.Count > 0)
  9070. {
  9071. foreach (DataRow dr in dt.Rows)
  9072. {
  9073. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9074. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9075. entity.AddUserId = CurrentUser.UserID;
  9076. entity.tid = dr["tid"].ToString();
  9077. entity.Did = Convert.ToString(dr["ctid"]);
  9078. entity.splitTag = dr["SplitTag"].ToString();
  9079. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9080. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9081. if (pre_ctid.Length > 0)
  9082. {
  9083. sellmemo = sellmemo.Replace(pre_ctid, "");
  9084. }
  9085. sellmemo = sellmemo.Replace("[", "");
  9086. sellmemo = sellmemo.Replace("]", "");
  9087. entity.FileName = sellmemo;
  9088. string count = dr["ProductCount"].ToString();
  9089. int usecount = commonHelper.getIntCountFromString(count);
  9090. entity.DeliveryCount = usecount;
  9091. entity.CurState = "未完成";
  9092. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9093. {
  9094. entity.Supplier = 24;//dl手提袋定制
  9095. }
  9096. else
  9097. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9098. entity.CreateTime = DateTime.Now;
  9099. entity.Create();
  9100. }
  9101. returnSuccessMsg("操作成功");
  9102. return;
  9103. }
  9104. returnErrorMsg("没有找到对应订单");
  9105. return;
  9106. }
  9107. returnErrorMsg("缺少订单编号");
  9108. return;
  9109. }
  9110. public void get_erp_persuadelist()
  9111. {
  9112. DataStruct dStruct = GetPostStruct();
  9113. List<string> lw = new List<string>();
  9114. string ctid = GetPostString("ctid");
  9115. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9116. string shopname = GetPostString("shopname");
  9117. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9118. string buyernick = GetPostString("buyer_nick");
  9119. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9120. string customer = GetPostString("customer");
  9121. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9122. string returndate1 = GetPostString("returndate1");
  9123. string returndate2 = GetPostString("returndate2");
  9124. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9125. if (dw.Length > 0) lw.Add(dw);
  9126. string finishDate1 = GetPostString("finishdate1");
  9127. string finishDate2 = GetPostString("finishdate2");
  9128. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9129. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9130. string persuadetype = GetPostString("persuadetype");
  9131. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9132. string returnvstate = GetPostString("returnvstate");
  9133. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9134. dStruct.Order = "created desc";
  9135. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9136. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9137. writeGridDataTableJson(dStruct.TotalCount, dt);
  9138. }
  9139. public void upd_erp_returnpersuadeback()
  9140. {
  9141. if (UrlPostParmsCheck("ID"))
  9142. {
  9143. int eid = GetPostInt("ID");
  9144. CeErpPersuade entity = null;
  9145. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9146. if (entity != null)
  9147. {
  9148. entity.backreason = GetPostString("reason");
  9149. entity.pstate = 2;
  9150. entity.verifytime = DateTime.Now;
  9151. entity.verifyuserid = CurrentUser.UserID;
  9152. entity.Update();
  9153. returnSuccessMsg("退回成功!");
  9154. return;
  9155. }
  9156. returnErrorMsg("找不到订单记录");
  9157. }
  9158. }
  9159. public void upd_erp_returnpersuadeverify()
  9160. {
  9161. if (UrlPostParmsCheck("ID"))
  9162. {
  9163. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9164. {
  9165. returnErrorMsg("暂无权限审核");
  9166. return;
  9167. }
  9168. int eid = GetPostInt("ID");
  9169. CeErpPersuade entity = null;
  9170. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9171. if (entity != null)
  9172. {
  9173. entity.pstate = 1;
  9174. entity.verifytime = DateTime.Now;
  9175. entity.verifyuserid = CurrentUser.UserID;
  9176. entity.Update();
  9177. returnSuccessMsg("审核成功!");
  9178. return;
  9179. }
  9180. returnErrorMsg("找不到订单记录");
  9181. }
  9182. }
  9183. public void del_erp_persuade()
  9184. {
  9185. if (UrlPostParmsCheck("ID"))
  9186. {
  9187. int eid = GetPostInt("ID");
  9188. CeErpPersuade.Del(eid);
  9189. returnSuccessMsg("操作成功");
  9190. return;
  9191. }
  9192. }
  9193. public void get_erp_oldcustoupload()
  9194. {
  9195. DataStruct dStruct = GetPostStruct();
  9196. List<string> lw = new List<string>();
  9197. string buyernick = GetPostString("buyer_nick");
  9198. if (buyernick.Length > 0)
  9199. {
  9200. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9201. }
  9202. else
  9203. return;
  9204. dStruct.Order = "pay_time desc";
  9205. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9206. DataTable dt = null;
  9207. dt = WebCache.GetData("view_erptradecell", dStruct);
  9208. writeGridDataTableJson(dStruct.TotalCount, dt);
  9209. }
  9210. public void get_erp_checkorderlist()
  9211. {
  9212. DataStruct dStruct = GetPostStruct();
  9213. List<string> lw = new List<string>();
  9214. string tid = GetPostString("ctid");
  9215. if (tid.Length > 0)
  9216. {
  9217. string select_tid = getTidByCtid(tid);
  9218. lw.Add(string.Format("tid='{0}'", select_tid));
  9219. }
  9220. string shopname = GetPostString("shopname");
  9221. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9222. string buyernick = GetPostString("buyer_nick");
  9223. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9224. string customer = GetPostString("customer");
  9225. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9226. string design = GetPostString("design");
  9227. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9228. string orderState = GetPostString("orderState");
  9229. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9230. string address = GetPostString("address");
  9231. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9232. string sellermemo = GetPostString("seller_memo");
  9233. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9234. string supplier = GetPostString("supplier");
  9235. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9236. {
  9237. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9238. }
  9239. else
  9240. {
  9241. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9242. }
  9243. string date1 = GetPostString("date1");
  9244. string date2 = GetPostString("date2");
  9245. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9246. if (dw.Length > 0) lw.Add(dw);
  9247. string placedate1 = GetPostString("placedate1");
  9248. string placedate2 = GetPostString("placedate2");
  9249. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9250. if (fdw.Length > 0) lw.Add(fdw);
  9251. string price1 = GetPostString("price1");
  9252. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9253. string price2 = GetPostString("price2");
  9254. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9255. string checkst = GetPostString("checkstate");
  9256. if (checkst.Length > 0 && "10".Equals(checkst))
  9257. {
  9258. lw.Add(string.Format("CheckOut>0"));
  9259. }
  9260. else
  9261. {
  9262. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9263. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9264. }
  9265. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9266. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9267. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9268. writeGridDataTableJson(dStruct.TotalCount, dt);
  9269. }
  9270. public void ins_erp_startCheck()
  9271. {
  9272. if (UrlPostParmsCheck("ctid"))
  9273. {
  9274. string eid = GetPostString("ctid");
  9275. CeErpTradeCell entity = null;
  9276. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9277. if (entity != null)
  9278. {
  9279. entity.MemoOpt = 4;
  9280. entity.UpdateTime = DateTime.Now;
  9281. entity.Update();
  9282. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9283. CeErpSukuraData.createInfo(entity.ctid, 6);
  9284. returnSuccessMsg("操作成功!");
  9285. return;
  9286. }
  9287. returnErrorMsg("找不到记录");
  9288. }
  9289. }
  9290. public void upd_erp_sendXlw()
  9291. {
  9292. if (UrlPostParmsCheck("ctid"))
  9293. {
  9294. string eid = GetPostString("ctid");
  9295. CeErpTradeCell entity = null;
  9296. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9297. if (entity != null)
  9298. {
  9299. if (entity.IsSendGift == 1)
  9300. {
  9301. returnErrorMsg("请勿重复标记");
  9302. return;
  9303. }
  9304. entity.IsSendGift = 1;
  9305. entity.Update();
  9306. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9307. returnSuccessMsg("操作成功!");
  9308. return;
  9309. }
  9310. returnErrorMsg("找不到记录");
  9311. }
  9312. }
  9313. public void cancel_sendXlw()
  9314. {
  9315. if (UrlPostParmsCheck("ctid"))
  9316. {
  9317. string eid = GetPostString("ctid");
  9318. CeErpTradeCell entity = null;
  9319. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9320. if (entity != null)
  9321. {
  9322. if (entity.IsSendGift == 0)
  9323. {
  9324. returnErrorMsg("未标记小礼物");
  9325. return;
  9326. }
  9327. entity.IsSendGift = 0;
  9328. entity.Update();
  9329. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9330. returnSuccessMsg("操作成功!");
  9331. return;
  9332. }
  9333. returnErrorMsg("找不到记录");
  9334. }
  9335. }
  9336. public void get_erp_designbill()
  9337. {
  9338. DataStruct dStruct = GetPostStruct();
  9339. List<string> lw = new List<string>();
  9340. int isMy = GetInt("my");
  9341. if (isMy == 1)
  9342. {
  9343. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9344. }
  9345. string tid = GetPostString("tid");
  9346. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9347. string userName = GetPostString("design");
  9348. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9349. string price1 = GetPostString("price1");
  9350. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9351. string price2 = GetPostString("price2");
  9352. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9353. string rePrice1 = GetPostString("rePrice1");
  9354. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9355. string rePrice2 = GetPostString("rePrice2");
  9356. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9357. string designerType = GetPostString("designerType");
  9358. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9359. string orderState = GetPostString("orderState");
  9360. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9361. string endTime1 = GetPostString("endTime1");
  9362. string endTime2 = GetPostString("endTime2");
  9363. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9364. if (dw.Length > 0) lw.Add(dw);
  9365. string isDk = GetPostString("isDk");
  9366. if (isDk == "1")
  9367. {
  9368. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9369. }
  9370. else if (isDk == "0")
  9371. {
  9372. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9373. }
  9374. dStruct.Order = "oid, create_time desc";
  9375. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9376. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9377. writeGridDataTableJson(dStruct.TotalCount, dt);
  9378. }
  9379. public void upd_erp_designerbill()
  9380. {
  9381. if (UrlPostParmsCheck("ID"))
  9382. {
  9383. string eid = GetPostString("ID");
  9384. CeErpDesignerBill entity = null;
  9385. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9386. if (entity != null)
  9387. {
  9388. if (GetPostDouble("designerpirce") > 0)
  9389. {
  9390. entity.realPrice = GetPostDouble("designerpirce");
  9391. entity.update_time = DateTime.Now;
  9392. entity.update_u_id = CurrentUser.UserID;
  9393. entity.update_u_name = CurrentUser.UserName;
  9394. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9395. entity.Update();
  9396. returnSuccessMsg("操作成功!");
  9397. return;
  9398. }
  9399. else
  9400. {
  9401. entity.price = GetPostDouble("price");
  9402. entity.update_time = DateTime.Now;
  9403. entity.update_u_id = CurrentUser.UserID;
  9404. entity.update_u_name = CurrentUser.UserName;
  9405. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9406. entity.Update();
  9407. returnSuccessMsg("操作成功!");
  9408. return;
  9409. }
  9410. }
  9411. returnErrorMsg("找不到记录");
  9412. }
  9413. }
  9414. public void audit_erp_designerbill()
  9415. {
  9416. if (UrlPostParmsCheck("ID"))
  9417. {
  9418. string eid = GetPostString("ID");
  9419. CeErpDesignerBill entity = null;
  9420. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9421. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9422. if (entity != null)
  9423. {
  9424. entity.realPrice = GetPostDouble("designerpirce");
  9425. entity.update_time = DateTime.Now;
  9426. entity.update_u_id = CurrentUser.UserID;
  9427. entity.update_u_name = CurrentUser.UserName;
  9428. entity.isAudit = 1;
  9429. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9430. entity.Update();
  9431. if (orderEntity != null)
  9432. {
  9433. orderEntity.IsReadTag = 3;
  9434. orderEntity.Update();
  9435. }
  9436. returnSuccessMsg("操作成功!");
  9437. return;
  9438. }
  9439. returnErrorMsg("找不到记录");
  9440. }
  9441. }
  9442. public void all_audit_erp_designerbill()
  9443. {
  9444. if (UrlPostParmsCheck("idList"))
  9445. {
  9446. string[] list = GetPostString("idList").Split(',');
  9447. CeErpDesignerBill entity = null;
  9448. for (int i = 0; i < list.Length; i++)
  9449. {
  9450. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9451. if (entity == null) return;
  9452. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9453. if (orderEntity == null) return;
  9454. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9455. entity.update_time = DateTime.Now;
  9456. entity.update_u_id = CurrentUser.UserID;
  9457. entity.update_u_name = CurrentUser.UserName;
  9458. entity.isAudit = 1;
  9459. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9460. entity.Update();
  9461. orderEntity.IsReadTag = 3;
  9462. orderEntity.Update();
  9463. }
  9464. returnSuccessMsg("操作成功!");
  9465. return;
  9466. }
  9467. }
  9468. public void get_erp_sameorders()
  9469. {
  9470. if (UrlPostParmsCheck("ctid"))
  9471. {
  9472. string eid = GetPostString("ctid");
  9473. CeErpTradeCell entity = null;
  9474. entity = CeErpTradeCell.GetByCtid(eid);
  9475. if (entity != null)
  9476. {
  9477. StringBuilder sql = new StringBuilder();
  9478. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9479. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9480. var res = new
  9481. {
  9482. data = dt.Rows.Count
  9483. };
  9484. string ro_jsond = JsonConvert.SerializeObject(res);
  9485. returnSuccess(ro_jsond);
  9486. return;
  9487. }
  9488. returnErrorMsg("未找到订单");
  9489. return;
  9490. }
  9491. returnErrorMsg("缺少必要的参数");
  9492. }
  9493. public void get_erp_islasthavesameorder()
  9494. {
  9495. if (UrlPostParmsCheck("ctid"))
  9496. {
  9497. string eid = GetPostString("ctid");
  9498. string[] ctidList = eid.Split(',');
  9499. StringBuilder sql = new StringBuilder();
  9500. string tisCtid = "";
  9501. foreach (string ctid in ctidList)
  9502. {
  9503. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9504. if (entity != null)
  9505. {
  9506. sql = new StringBuilder();
  9507. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9508. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9509. if (dth.Rows.Count > 0)
  9510. {
  9511. tisCtid += entity.ctid;
  9512. tisCtid += ",";
  9513. }
  9514. }
  9515. }
  9516. if (tisCtid.Length > 0)
  9517. {
  9518. var res = new
  9519. {
  9520. data = tisCtid
  9521. };
  9522. string ro_jsond = JsonConvert.SerializeObject(res);
  9523. returnSuccess(ro_jsond);
  9524. }
  9525. else
  9526. {
  9527. var res = new
  9528. {
  9529. data = ""
  9530. };
  9531. string ro_jsond = JsonConvert.SerializeObject(res);
  9532. returnSuccess(ro_jsond);
  9533. }
  9534. return;
  9535. }
  9536. returnErrorMsg("缺少必要的参数");
  9537. }
  9538. public void file_client_down_url()
  9539. {
  9540. if (!UrlPostParmsCheck("userId"))
  9541. {
  9542. returnErrorMsg("缺少必要的参数");
  9543. }
  9544. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9545. }
  9546. public void checkout_form_data()
  9547. {
  9548. if (!UrlPostParmsCheck("tid"))
  9549. {
  9550. returnErrorMsg("缺少必要的参数");
  9551. }
  9552. string tid = GetPostString("tid");
  9553. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9554. if (ceErpOrderFormData != null)
  9555. {
  9556. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9557. returnSuccess(ro_jsond);
  9558. return;
  9559. }
  9560. returnErrorMsg("尚未有文件!");
  9561. }
  9562. public void back_supplier_audit()
  9563. {
  9564. int userId = CurrentUser.UserID;
  9565. StringBuilder sql = new StringBuilder();
  9566. 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);
  9567. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9568. if (dt.Rows.Count > 0)
  9569. {
  9570. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9571. }
  9572. else
  9573. {
  9574. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9575. }
  9576. }
  9577. public void back_supplier_query()
  9578. {
  9579. string eid = GetPostString("ctid");
  9580. if (eid != "")
  9581. {
  9582. StringBuilder sql = new StringBuilder();
  9583. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9584. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9585. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9586. }
  9587. else
  9588. {
  9589. returnErrorMsg("找不到订单记录");
  9590. return;
  9591. }
  9592. }
  9593. public void verified_to_order()
  9594. {
  9595. int userId = CurrentUser.UserID;
  9596. StringBuilder sql = new StringBuilder();
  9597. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9598. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9599. if (dt.Rows.Count > 0)
  9600. {
  9601. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9602. }
  9603. else
  9604. {
  9605. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9606. }
  9607. }
  9608. public void upd_supplier_audit()
  9609. {
  9610. if (UrlPostParmsCheck("ctid"))
  9611. {
  9612. string eid = GetPostString("ctid");
  9613. string reason = GetPostString("returnreason");
  9614. CeErpTradeCell entity = null;
  9615. CeWithdraw withdraw = null;
  9616. withdraw = CeWithdraw.GetByTid(eid);
  9617. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9618. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9619. {
  9620. if (withdraw != null)
  9621. {
  9622. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9623. {
  9624. returnSuccessMsg("您没有权限操作!");
  9625. return;
  9626. }
  9627. else
  9628. {
  9629. if (reason.Equals("1"))
  9630. {
  9631. if (entity.OrderState == -1)
  9632. {
  9633. if (entity.FinishPlaceTime == null)
  9634. {
  9635. entity.OrderState = 2;
  9636. }
  9637. else
  9638. {
  9639. entity.OrderState = 6;
  9640. }
  9641. }
  9642. entity.Update();
  9643. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9644. if (withdraw != null)
  9645. {
  9646. withdraw.status = int.Parse(reason);
  9647. withdraw.Update();
  9648. }
  9649. returnSuccessMsg("操作成功!");
  9650. return;
  9651. }
  9652. else
  9653. {
  9654. withdraw.status = int.Parse(reason);
  9655. withdraw.acknowledgingtime = DateTime.Now;
  9656. withdraw.Update();
  9657. returnSuccessMsg("查看详细请点击线下订单查询");
  9658. return;
  9659. }
  9660. }
  9661. }
  9662. // 第一个字符是 'N'
  9663. }
  9664. if (eid[0] != 'N')
  9665. {
  9666. }
  9667. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9668. {
  9669. entity.IsVerifyToSupplier = false;
  9670. entity.IsReturn = 1;
  9671. entity.ReturnTime = DateTime.Now;
  9672. entity.ReturnReason = reason;
  9673. if (entity.OrderState == 6)
  9674. {
  9675. entity.OrderState = 5;
  9676. }
  9677. entity.Update();
  9678. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9679. if (withdraw != null)
  9680. {
  9681. withdraw.status = int.Parse(reason);
  9682. withdraw.Update();
  9683. }
  9684. returnSuccessMsg("操作成功!");
  9685. return;
  9686. }
  9687. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9688. {
  9689. ;
  9690. if (withdraw != null)
  9691. {
  9692. withdraw.status = int.Parse(reason);
  9693. withdraw.acknowledgingtime = DateTime.Now;
  9694. withdraw.Update();
  9695. returnSuccessMsg("供应商取消撤回!");
  9696. return;
  9697. }
  9698. }
  9699. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9700. {
  9701. if (entity.OrderState == -1)
  9702. {
  9703. if (entity.FinishPlaceTime == null)
  9704. {
  9705. entity.OrderState = 2;
  9706. }
  9707. else
  9708. {
  9709. entity.OrderState = 3;
  9710. }
  9711. commonHelper.getCytPrice(entity);
  9712. }
  9713. entity.Update();
  9714. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9715. if (withdraw != null)
  9716. {
  9717. withdraw.status = int.Parse(reason);
  9718. withdraw.Update();
  9719. }
  9720. returnSuccessMsg("操作成功!");
  9721. return;
  9722. }
  9723. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9724. {
  9725. if (withdraw == null)
  9726. {
  9727. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9728. return;
  9729. }
  9730. }
  9731. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9732. {
  9733. if (withdraw != null)
  9734. {
  9735. withdraw.status = int.Parse(reason);
  9736. withdraw.acknowledgingtime = DateTime.Now;
  9737. withdraw.Update();
  9738. returnSuccessMsg("查看详细请点击线下订单查询");
  9739. return;
  9740. }
  9741. }
  9742. return;
  9743. }
  9744. }
  9745. //校验报价
  9746. public void refund_order_tip()
  9747. {
  9748. int userid = CurrentUser.UserID;
  9749. int sectionId = CurrentUser.UserPost.OrgID;
  9750. StringBuilder sql = new StringBuilder();
  9751. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9752. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9753. List<string> ids = new List<string>();
  9754. if (dth.Rows.Count > 0)
  9755. {
  9756. foreach (DataRow dr in dth.Rows)
  9757. {
  9758. ids.Add(dr["ID"].ToString());
  9759. }
  9760. try
  9761. {
  9762. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9763. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9764. }
  9765. catch (Exception ex)
  9766. {
  9767. }
  9768. }
  9769. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9770. }
  9771. public void refund_order_Design()
  9772. {
  9773. int userid = CurrentUser.UserID;
  9774. int sectionId = CurrentUser.UserPost.OrgID;
  9775. StringBuilder sql = new StringBuilder();
  9776. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9777. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9778. List<string> ids = new List<string>();
  9779. if (dth.Rows.Count > 0)
  9780. {
  9781. foreach (DataRow dr in dth.Rows)
  9782. {
  9783. ids.Add(dr["ID"].ToString());
  9784. }
  9785. try
  9786. {
  9787. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9788. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9789. }
  9790. catch (Exception ex)
  9791. {
  9792. }
  9793. }
  9794. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9795. }
  9796. public void change_order_info()
  9797. {
  9798. int userid = CurrentUser.UserID;
  9799. StringBuilder sql = new StringBuilder();
  9800. 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);
  9801. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9802. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  9803. }
  9804. public void change_win_mome()
  9805. {
  9806. if (UrlPostParmsCheck("id,ctid"))
  9807. {
  9808. string id = GetPostString("id");
  9809. string ctid = GetPostString("ctid");
  9810. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  9811. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  9812. if (ce == null || ceErpMessageTip == null)
  9813. {
  9814. returnSuccessMsg("未找到对应的订单!");
  9815. return;
  9816. }
  9817. if (ce.OrderState >= 5)
  9818. {
  9819. returnSuccessMsg("已上传文件无法修改!");
  9820. return;
  9821. }
  9822. int type = GetPostInt("type");
  9823. string content = GetPostString("content");
  9824. if (type == 0)
  9825. {
  9826. content = content.Replace("(", "(");
  9827. content = content.Replace(")", ")");
  9828. string check = MidStrEx(content, "(", ")").Trim();
  9829. if (string.IsNullOrEmpty(check))
  9830. {
  9831. returnSuccessMsg("文件名格式不正确");
  9832. return;
  9833. }
  9834. }
  9835. ce.seller_memo = content;
  9836. ce.Update();
  9837. ceErpMessageTip.isVisit = true;
  9838. ceErpMessageTip.Update();
  9839. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  9840. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  9841. ApiVo apiVo = new ApiVo();
  9842. apiVo.orderNumber = ce.ctid;
  9843. apiVo.actionName = "demandDesign";
  9844. apiVo.orderRemarks = content;
  9845. apiVo.demandExamine = type + 1;
  9846. designHelper.API_WorkCore(apiVo);//demandDesign
  9847. returnSuccessMsg("修改成功!");
  9848. }
  9849. }
  9850. public static string MidStrEx(string sourse, string startstr, string endstr)
  9851. {
  9852. string result = string.Empty;
  9853. int startindex, endindex;
  9854. try
  9855. {
  9856. startindex = sourse.IndexOf(startstr);
  9857. if (startindex == -1)
  9858. return result;
  9859. string tmpstr = sourse.Substring(startindex + startstr.Length);
  9860. endindex = tmpstr.IndexOf(endstr);
  9861. if (endindex == -1)
  9862. return result;
  9863. result = tmpstr.Remove(endindex);
  9864. }
  9865. catch (Exception ex)
  9866. {
  9867. Console.WriteLine("MidStrEx Err:" + ex.Message);
  9868. }
  9869. return result;
  9870. }
  9871. public void refund_order_list()
  9872. {
  9873. int userid = CurrentUser.UserID;
  9874. int sectionId = CurrentUser.UserPost.OrgID;
  9875. StringBuilder sql = new StringBuilder();
  9876. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  9877. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9878. DataStruct dStruct = GetPostStruct();
  9879. DataTable dt = null;
  9880. List<string> ids = new List<string>();
  9881. List<string> tids = new List<string>();
  9882. if (dth.Rows.Count > 0)
  9883. {
  9884. foreach (DataRow dr in dth.Rows)
  9885. {
  9886. tids.Add("'" + dr["tid"].ToString() + "'");
  9887. ids.Add(dr["id"].ToString());
  9888. }
  9889. try
  9890. {
  9891. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  9892. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9893. List<string> lw = new List<string>();
  9894. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  9895. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9896. dt = WebCache.GetData("view_orderlist", dStruct);
  9897. }
  9898. catch (Exception ex)
  9899. {
  9900. }
  9901. }
  9902. writeGridDataTableJson(dStruct.TotalCount, dt);
  9903. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  9904. }
  9905. //新增
  9906. public void order_batch_downloads()
  9907. {
  9908. string ceid = GetPostString("tid");
  9909. String[] tid = ceid.Split(',');
  9910. order_batch_caiyingtong(tid);
  9911. /* (string success, string errors) = UploadFiles(tid);
  9912. returnSuccessMsg(success + errors);*/
  9913. return;
  9914. }
  9915. //报价接口
  9916. public void Get_To_Quote()
  9917. {
  9918. string ceid = GetPostString("ctid");
  9919. if (ceid != null)
  9920. {
  9921. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  9922. if (entity != null)
  9923. {
  9924. if (entity.seller_memo.IndexOf("种子纸") > -1)
  9925. {
  9926. return;
  9927. }
  9928. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  9929. double price = 0;
  9930. if (cp == null)
  9931. {
  9932. JObject jsonObject12 = new JObject
  9933. {
  9934. { "UserId", "77886" },
  9935. { "Pwd", "lt666888" },
  9936. { "Filename", entity.seller_memo }
  9937. };
  9938. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  9939. JObject jsonObjects1 = JObject.Parse(response1);
  9940. string ms1g = (string)jsonObjects1["msg"];
  9941. if (ms1g == "报价成功")
  9942. {
  9943. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  9944. string data = (string)jsonObject1["price"];
  9945. 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 + "');";
  9946. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9947. returnSuccessMsg("获取报价成功:" + data);
  9948. price = Convert.ToDouble(data);
  9949. }
  9950. else
  9951. {
  9952. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  9953. return;
  9954. }
  9955. }
  9956. String[] beizhu = entity.seller_memo.Split('-');
  9957. String chanp = "";
  9958. if (beizhu.Length > 0)
  9959. {
  9960. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  9961. }
  9962. else
  9963. {
  9964. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  9965. }
  9966. JObject jsonObject = new JObject
  9967. {
  9968. { "UserId", "77886" },
  9969. { "Pwd", "lt666888" },
  9970. { "Filename", chanp }
  9971. };
  9972. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  9973. JObject jsonObjects = JObject.Parse(response);
  9974. string msg = (string)jsonObjects["msg"];
  9975. if (msg == "报价成功")
  9976. {
  9977. JObject jsonObject1 = (JObject)jsonObjects["data"];
  9978. string data = (string)jsonObject1["price"];
  9979. 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 + "');";
  9980. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9981. returnSuccessMsg("获取报价成功:" + data);
  9982. price = Convert.ToDouble(data);
  9983. }
  9984. else
  9985. {
  9986. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  9987. return;
  9988. }
  9989. if (price > 0)
  9990. {
  9991. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9992. if (ceErpTradeCellExtend == null)
  9993. {
  9994. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  9995. ceErpTradeCellExtend.ctid = entity.ctid;
  9996. ceErpTradeCellExtend.payment_cyt = price;
  9997. ceErpTradeCellExtend.Create();
  9998. }
  9999. else
  10000. {
  10001. ceErpTradeCellExtend.payment_cyt = price;
  10002. ceErpTradeCellExtend.Update();
  10003. }
  10004. }
  10005. return;
  10006. }
  10007. }
  10008. else
  10009. {
  10010. returnErrorMsg("请至少选择一条数据");
  10011. return;
  10012. }
  10013. }
  10014. //新增
  10015. public void order_To_Supplier()
  10016. {
  10017. string ceid = GetPostString("tid");
  10018. String[] tid = ceid.Split(',');
  10019. if (tid.Length > 0)
  10020. {
  10021. try
  10022. {
  10023. for (int i = 0; i < tid.Length; i++)
  10024. {
  10025. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10026. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10027. entity.SupplierId = suid;
  10028. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10029. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10030. entity.Update();
  10031. }
  10032. }
  10033. catch (Exception ex)
  10034. {
  10035. returnErrorMsg("自动匹配供应商失败");
  10036. return;
  10037. }
  10038. }
  10039. else
  10040. {
  10041. returnErrorMsg("请至少选择一条数据");
  10042. return;
  10043. }
  10044. returnSuccessMsg("自动匹配供应商成功");
  10045. return;
  10046. }
  10047. public (string, string) UploadFiles(string[] urls)
  10048. {
  10049. string success = "";
  10050. string errors = "";
  10051. int userid = CurrentUser.UserID;
  10052. foreach (string url in urls)
  10053. {
  10054. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10055. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10056. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10057. {
  10058. JObject jsonObject = new JObject
  10059. {
  10060. { "Userid", "77886" },
  10061. { "pwd", "cyt86435015" },
  10062. { "content", base64FileContent },
  10063. { "ext", Path.GetExtension(fileName) }
  10064. };
  10065. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10066. JObject jsonObjects = JObject.Parse(response);
  10067. string msg = (string)jsonObjects["msg"];
  10068. if (msg.Equals("上传成功"))
  10069. {
  10070. success += url + " 上传成功";
  10071. }
  10072. else
  10073. {
  10074. errors += url + " 上传失败";
  10075. }
  10076. }
  10077. else
  10078. {
  10079. errors += url + " 格式出现问题";
  10080. }
  10081. }
  10082. if (urls.Length == 0)
  10083. {
  10084. return (success, errors);
  10085. }
  10086. return (success, errors);
  10087. }
  10088. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10089. {
  10090. return true; //总是接受
  10091. }
  10092. public static string HttpPost(string url, string param = null)
  10093. {
  10094. HttpWebRequest request;
  10095. //如果是发送HTTPS请求
  10096. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10097. {
  10098. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10099. request = WebRequest.Create(url) as HttpWebRequest;
  10100. request.ProtocolVersion = HttpVersion.Version10;
  10101. }
  10102. else
  10103. {
  10104. request = WebRequest.Create(url) as HttpWebRequest;
  10105. }
  10106. request.Method = "POST";
  10107. request.ContentType = "application/json";
  10108. request.Accept = "*/*";
  10109. request.Timeout = 120000;
  10110. request.AllowAutoRedirect = false;
  10111. StreamWriter requestStream = null;
  10112. WebResponse response = null;
  10113. string responseStr = null;
  10114. try
  10115. {
  10116. requestStream = new StreamWriter(request.GetRequestStream());
  10117. requestStream.Write(param);
  10118. requestStream.Close();
  10119. response = request.GetResponse();
  10120. if (response != null)
  10121. {
  10122. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10123. responseStr = reader.ReadToEnd();
  10124. reader.Close();
  10125. }
  10126. }
  10127. catch (Exception ex)
  10128. {
  10129. return ex.Message;
  10130. }
  10131. finally
  10132. {
  10133. request = null;
  10134. requestStream = null;
  10135. response = null;
  10136. }
  10137. return responseStr;
  10138. }
  10139. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10140. {
  10141. string base64FileContent;
  10142. string fileName;
  10143. using (WebClient webClient = new WebClient())
  10144. {
  10145. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10146. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10147. {
  10148. using (Stream stream = response.GetResponseStream())
  10149. {
  10150. using (MemoryStream memoryStream = new MemoryStream())
  10151. {
  10152. stream.CopyTo(memoryStream);
  10153. byte[] fileBytes = memoryStream.ToArray();
  10154. base64FileContent = Convert.ToBase64String(fileBytes);
  10155. fileName = response.Headers["Content-Disposition"];
  10156. if (!string.IsNullOrEmpty(fileName))
  10157. {
  10158. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10159. if (index >= 0)
  10160. {
  10161. fileName = fileName.Substring(index + 9).Trim('\"');
  10162. }
  10163. }
  10164. else
  10165. {
  10166. fileName = Path.GetFileName(downloadUrl);
  10167. }
  10168. }
  10169. }
  10170. }
  10171. }
  10172. return (fileName, base64FileContent);
  10173. }
  10174. //新增
  10175. public void order_batch_caiyingtong(string[] downloadUrls)
  10176. {
  10177. try
  10178. {
  10179. //遍历文件
  10180. DataStruct dStruct = GetPostStruct();
  10181. DataTable dt = null;
  10182. int userid = CurrentUser.UserID;
  10183. List<string> ids = new List<string>();//失败组
  10184. List<string> tids = new List<string>();
  10185. using (WebClient webClient = new WebClient())
  10186. {
  10187. foreach (var url in downloadUrls)
  10188. {
  10189. try
  10190. {
  10191. tids.Add("'" + url + "'");
  10192. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10193. if (entity != null)
  10194. {
  10195. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10196. if (cp == null)
  10197. {
  10198. JObject jsonObject = new JObject
  10199. {
  10200. { "Userid", "77886" },
  10201. { "pwd", "lt666888" },
  10202. { "Filename",entity.seller_memo }
  10203. };
  10204. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10205. JObject jsonObjects = JObject.Parse(response);
  10206. string msg = (string)jsonObjects["msg"];
  10207. if (msg == "报价成功")
  10208. {
  10209. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10210. DownloadAndConvertToBase64(url1);
  10211. }
  10212. else
  10213. {
  10214. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10215. }
  10216. }
  10217. else
  10218. {
  10219. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10220. JObject jsonObject = new JObject
  10221. {
  10222. { "Userid", "77886" },
  10223. { "pwd", "lt666888" },
  10224. { "Filename",chanp }
  10225. };
  10226. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10227. JObject jsonObjects = JObject.Parse(response);
  10228. string msg = (string)jsonObjects["msg"];
  10229. if (msg == "报价成功")
  10230. {
  10231. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10232. DownloadAndConvertToBase64(url1);
  10233. }
  10234. else
  10235. {
  10236. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10237. }
  10238. }
  10239. }
  10240. // 上传文件到FTP
  10241. }
  10242. catch (Exception ex)
  10243. {
  10244. Console.WriteLine($"An error occurred: {ex.Message}");
  10245. }
  10246. }
  10247. List<string> lw = new List<string>();
  10248. lw.Add(string.Format("( OrderState < 6 )"));
  10249. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10250. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10251. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10252. if (dt.Rows.Count > 0)
  10253. {
  10254. foreach (DataRow dr in dt.Rows)
  10255. {
  10256. ids.Add(dr["ctid"].ToString());
  10257. }
  10258. }
  10259. String ErrorMsgs = "";
  10260. foreach (String id in ids)
  10261. {
  10262. ErrorMsgs += id + ",";
  10263. }
  10264. if (ErrorMsgs.Length > 1)
  10265. {
  10266. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10267. }
  10268. if (ErrorMsgs.Length < 1)
  10269. {
  10270. ErrorMsgs = "上传成功";
  10271. returnSuccessMsg(ErrorMsgs);
  10272. }
  10273. else
  10274. {
  10275. returnErrorMsg("以下订单" + ErrorMsgs);
  10276. }
  10277. }
  10278. // 删除文件夹及其内容
  10279. /* Directory.Delete(localDirectory, true);*/
  10280. }
  10281. catch { }
  10282. }
  10283. public void get_center_data()
  10284. {
  10285. int userId = CurrentUser.UserID;
  10286. string postCode = CurrentUser.UserPost.Post.Code;
  10287. List<string> lw = new List<string>();
  10288. List<string> ww = new List<string>();
  10289. DateTime currentTime = DateTime.Now;
  10290. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10291. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10292. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10293. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10294. string sql = " SELECT ";
  10295. string startTime = "2023-10-01 11:22:31";
  10296. //设计
  10297. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10298. {
  10299. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10300. 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));
  10301. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10302. 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));
  10303. }
  10304. //客服
  10305. else if (postCode == "CustomerService" || postCode == "Director")
  10306. {
  10307. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10308. 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));
  10309. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10310. 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));
  10311. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10312. 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));
  10313. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10314. 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));
  10315. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10316. 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));
  10317. }
  10318. //售后
  10319. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10320. {
  10321. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10322. 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));
  10323. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10324. 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));
  10325. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10326. 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));
  10327. }
  10328. //下单部
  10329. else if (postCode == "Place" || postCode == "PlaceMr")
  10330. {
  10331. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10332. 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));
  10333. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10334. 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));
  10335. }
  10336. //车间
  10337. else if (postCode == "Supplier")
  10338. {
  10339. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10340. 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));
  10341. }
  10342. DataTable dt = new DataTable();
  10343. if (lw.Count > 0)
  10344. {
  10345. sql += string.Join(" , ", lw);
  10346. sql += " FROM ";
  10347. sql += string.Join(" , ", ww);
  10348. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10349. }
  10350. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10351. }
  10352. public void get_center_data_list()
  10353. {
  10354. int userId = CurrentUser.UserID;
  10355. string postCode = CurrentUser.UserPost.Post.Code;
  10356. string shopIds = CurrentUser.User.pemShop;
  10357. DataStruct dStruct = GetPostStruct();
  10358. List<string> lw = new List<string>();
  10359. DateTime currentTime = DateTime.Now;
  10360. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10361. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10362. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10363. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10364. string startTime = "2023-10-01 11:22:31";
  10365. int order_type = GetPostInt("order_type");
  10366. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10367. {
  10368. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10369. if (order_type == 0)
  10370. {
  10371. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10372. }
  10373. else if (order_type == 3)
  10374. {
  10375. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10376. }
  10377. else
  10378. {
  10379. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10380. }
  10381. }
  10382. //客服
  10383. if (postCode == "CustomerService" || postCode == "Director")
  10384. {
  10385. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10386. if (order_type == 0)
  10387. {
  10388. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10389. }
  10390. else if (order_type == 1)
  10391. {
  10392. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10393. }
  10394. else if (order_type == 2)
  10395. {
  10396. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10397. }
  10398. else if (order_type == 3)
  10399. {
  10400. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10401. }
  10402. else if (order_type == 4)
  10403. {
  10404. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10405. }
  10406. else
  10407. {
  10408. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10409. }
  10410. }
  10411. //售后
  10412. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10413. {
  10414. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10415. if (shopIds != "")
  10416. {
  10417. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10418. }
  10419. if (order_type == 2)
  10420. {
  10421. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10422. }
  10423. else if (order_type == 4)
  10424. {
  10425. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10426. }
  10427. else if (order_type == 5)
  10428. {
  10429. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10430. }
  10431. else
  10432. {
  10433. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10434. }
  10435. }
  10436. //下单部
  10437. if (postCode == "Place" || postCode == "PlaceMr")
  10438. {
  10439. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10440. if (shopIds != "")
  10441. {
  10442. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10443. }
  10444. else if (order_type == 1)
  10445. {
  10446. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10447. }
  10448. else if (order_type == 2)
  10449. {
  10450. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10451. }
  10452. else
  10453. {
  10454. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10455. }
  10456. }
  10457. //车间
  10458. if (postCode == "Supplier")
  10459. {
  10460. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10461. if (order_type == 5)
  10462. {
  10463. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10464. }
  10465. else
  10466. {
  10467. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10468. }
  10469. }
  10470. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10471. dStruct.Fileds = "tid,ctid";
  10472. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10473. writeGridDataTableJson(dStruct.TotalCount, dt);
  10474. }
  10475. public void aftersale_audit_master()
  10476. {
  10477. if (UrlPostParmsCheck("ctid"))
  10478. {
  10479. string ctid = GetPostString("ctid");
  10480. if (ctid.Length > 0)
  10481. {
  10482. bool result = aftersale_data_change(ctid);
  10483. if (result)
  10484. {
  10485. returnSuccessMsg("修改成功!");
  10486. return;
  10487. }
  10488. }
  10489. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10490. }
  10491. }
  10492. public void aftersale_batch_audit_master()
  10493. {
  10494. if (UrlPostParmsCheck("ctids"))
  10495. {
  10496. string ctids = GetPostString("ctids");
  10497. if (ctids.Length > 0)
  10498. {
  10499. List<string> list = new List<string>();
  10500. string[] ctid_list = ctids.Split(',');
  10501. foreach (var item in ctid_list)
  10502. {
  10503. bool result = aftersale_data_change(item);
  10504. if (!result)
  10505. {
  10506. list.Add(item);
  10507. }
  10508. }
  10509. if (list.Count > 0)
  10510. {
  10511. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10512. return;
  10513. }
  10514. returnSuccessMsg("修改成功!");
  10515. return;
  10516. }
  10517. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10518. }
  10519. }
  10520. public bool aftersale_data_change(string ctid)
  10521. {
  10522. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10523. if (ceErpTradeCell != null)
  10524. {
  10525. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10526. ceErpTradeCell.AfterSaleSupplierState = 0;
  10527. StringBuilder sql = new StringBuilder();
  10528. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10529. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10530. CeErpTradeResponsible.DelByTid(ctid, 0);
  10531. 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 == "不理赔")
  10532. {
  10533. CeErpTradeResponsible.DelByTid(ctid, 1);
  10534. ceErpTradeCell.AfterSaleSupplierState = 1;
  10535. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10536. ceErpTradeCell.AfterSaleState = 4;
  10537. }
  10538. else
  10539. {
  10540. ceErpTradeCell.AfterSaleState = 3;
  10541. }
  10542. bool needCyt = false;
  10543. if (dt != null)
  10544. {
  10545. if (dt.Rows.Count == 1)
  10546. {
  10547. bool isEnd = false;
  10548. foreach (DataRow dr in dt.Rows)
  10549. {
  10550. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10551. {
  10552. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10553. isEnd = true;
  10554. }
  10555. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10556. {
  10557. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10558. isEnd = true;
  10559. }
  10560. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10561. {
  10562. needCyt = true;
  10563. }
  10564. }
  10565. if (isEnd)
  10566. {
  10567. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10568. ceErpTradeCell.AfterSaleState = 4;
  10569. ceErpTradeCell.AfterSaleSupplierState = 1;
  10570. }
  10571. }
  10572. else
  10573. {
  10574. bool isAll = true;
  10575. foreach (DataRow dr in dt.Rows)
  10576. {
  10577. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10578. {
  10579. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10580. continue;
  10581. }
  10582. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10583. {
  10584. string path = "";
  10585. int OrgID = 0;
  10586. if (!Convert.IsDBNull(dr["OrgPath"]))
  10587. {
  10588. path = dr["OrgPath"].ToString();
  10589. }
  10590. if (!Convert.IsDBNull(dr["OrgID"]))
  10591. {
  10592. OrgID = Convert.ToInt32(dr["OrgID"]);
  10593. }
  10594. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10595. {
  10596. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10597. continue;
  10598. }
  10599. }
  10600. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10601. {
  10602. needCyt = true;
  10603. }
  10604. isAll = false;
  10605. }
  10606. if (isAll)
  10607. {
  10608. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10609. ceErpTradeCell.AfterSaleState = 4;
  10610. ceErpTradeCell.AfterSaleSupplierState = 1;
  10611. }
  10612. }
  10613. }
  10614. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10615. {
  10616. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10617. }
  10618. if (ceErpTradeCell.AfterSaleState == 4)
  10619. {
  10620. ApiVo apiVo = new ApiVo();
  10621. apiVo.orderNumber = ceErpTradeCell.ctid;
  10622. apiVo.actionName = "afterOver";
  10623. designHelper.API_WorkCore(apiVo); //afterOver
  10624. }
  10625. ceErpTradeCell.Update();
  10626. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10627. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10628. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10629. return true;
  10630. }
  10631. return false;
  10632. }
  10633. public void get_erp_wechatorder()
  10634. {
  10635. DataStruct dStruct = GetPostStruct();
  10636. List<string> lw = new List<string>();
  10637. string tid = GetPostString("tid");
  10638. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10639. string shopname = GetPostString("shopname");
  10640. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10641. string buyernick = GetPostString("buyer_nick");
  10642. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10643. string customer = GetPostString("customer");
  10644. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10645. string returndate1 = GetPostString("returndate1");
  10646. string returndate2 = GetPostString("returndate2");
  10647. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10648. if (dw.Length > 0) lw.Add(dw);
  10649. string finishDate1 = GetPostString("finishdate1");
  10650. string finishDate2 = GetPostString("finishdate2");
  10651. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10652. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10653. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10654. dStruct.Order = "created desc";
  10655. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10656. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10657. writeGridDataTableJson(dStruct.TotalCount, dt);
  10658. }
  10659. public void get_erp_wechatlist_sumprice()
  10660. {
  10661. DataStruct dStruct = GetPostStruct();
  10662. List<string> lw = new List<string>();
  10663. string tid = GetPostString("tid");
  10664. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10665. string shopname = GetPostString("shopname");
  10666. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10667. string buyernick = GetPostString("buyer_nick");
  10668. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10669. string customer = GetPostString("customer");
  10670. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10671. string returndate1 = GetPostString("returndate1");
  10672. string returndate2 = GetPostString("returndate2");
  10673. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10674. if (dw.Length > 0) lw.Add(dw);
  10675. string finishDate1 = GetPostString("finishdate1");
  10676. string finishDate2 = GetPostString("finishdate2");
  10677. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10678. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10679. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10680. string mainWhere = string.Join(" and ", lw.ToArray());
  10681. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10682. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10683. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10684. decimal total = 0;
  10685. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10686. {
  10687. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10688. }
  10689. var res = new
  10690. {
  10691. data = total
  10692. };
  10693. string ro_jsond = JsonConvert.SerializeObject(res);
  10694. returnSuccess(ro_jsond);
  10695. return;
  10696. }
  10697. public void get_erp_qr_waitdeliverylist()
  10698. {
  10699. DataStruct dStruct = GetPostStruct();
  10700. List<string> lw = new List<string>();
  10701. string tid = GetPostString("ctid");
  10702. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10703. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10704. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10705. var res_objz = new
  10706. {
  10707. restype = 1,
  10708. data = dt
  10709. };
  10710. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10711. returnSuccess(ro_jsonz);
  10712. }
  10713. public void get_erp_yield_list()
  10714. {
  10715. DataStruct dStruct = GetPostStruct();
  10716. List<string> lw = new List<string>();
  10717. string tid = GetPostString("ctid");
  10718. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10719. string shopname = GetPostString("shopname");
  10720. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10721. string buyernick = GetPostString("buyer_nick");
  10722. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10723. //if (tid.Length == 0 && buyernick.Length == 0)
  10724. //{
  10725. // lw.Add(string.Format("IsRefund<={0}", 1));
  10726. //}
  10727. string customer = GetPostString("customer");
  10728. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10729. string design = GetPostString("design");
  10730. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10731. string orderState = GetPostString("orderState");
  10732. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10733. string address = GetPostString("address");
  10734. 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));
  10735. string sellermemo = GetPostString("seller_memo");
  10736. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10737. string supplier = GetPostString("supplier");
  10738. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10739. string OrderArea = GetPostString("order_area");
  10740. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10741. string placedate1 = GetPostString("placedate1");
  10742. string placedate2 = GetPostString("placedate2");
  10743. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10744. if (fdw.Length > 0) lw.Add(fdw);
  10745. string price1 = GetPostString("price1");
  10746. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10747. string price2 = GetPostString("price2");
  10748. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10749. string unusualCon = GetPostString("unusualcon");
  10750. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10751. string posTag = CurrentUser.UserPost.Post.Code;
  10752. if (posTag == "Supplier")
  10753. {
  10754. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10755. }
  10756. lw.Add(string.Format("OrderState = 6 "));
  10757. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10758. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10759. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10760. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10761. writeGridDataTableJson(dStruct.TotalCount, dt);
  10762. }
  10763. public void change_erp_sup_state()
  10764. {
  10765. if (UrlPostParmsCheck("ctid"))
  10766. {
  10767. string ctid = GetPostString("ctid");
  10768. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10769. if (ceErpTradeCell != null)
  10770. {
  10771. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10772. if (ceErpTradeCellExtend == null)
  10773. {
  10774. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10775. ceErpTradeCellExtend.ctid = ctid;
  10776. ceErpTradeCellExtend.SupState = 1;
  10777. ceErpTradeCellExtend.Create();
  10778. }
  10779. else
  10780. {
  10781. ceErpTradeCellExtend.SupState = 1;
  10782. ceErpTradeCellExtend.Update();
  10783. }
  10784. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10785. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10786. return;
  10787. }
  10788. returnErrorMsg("找不到订单");
  10789. }
  10790. }
  10791. public void supplier_all_downs()
  10792. {
  10793. if (UrlPostParmsCheck("tids"))
  10794. {
  10795. string tids = GetPostString("tids");
  10796. if (tids != null && tids.Length > 0)
  10797. {
  10798. StringBuilder sql = new StringBuilder();
  10799. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  10800. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10801. sql = new StringBuilder();
  10802. 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, "下载设计文件");
  10803. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10804. string[] list = tids.Split(',');
  10805. foreach (string ctid in list)
  10806. {
  10807. CeErpSukuraData.createInfo(ctid, 3);
  10808. }
  10809. designHelper.api_approveDesign(tids); //approveDesign
  10810. returnSuccessMsg("下载成功!");
  10811. return;
  10812. }
  10813. returnErrorMsg("下载订单更新失败");
  10814. }
  10815. }
  10816. public void uploaderFileSuccess()
  10817. {
  10818. if (UrlPostParmsCheck("fileName"))
  10819. {
  10820. string fileName = GetPostString("fileName");
  10821. ApiVo apiVo = new ApiVo();
  10822. apiVo.orderNumber = fileName;
  10823. apiVo.actionName = "finishDesign";
  10824. designHelper.API_WorkCore(apiVo);//finishDesign
  10825. returnSuccessMsg("");
  10826. }
  10827. }
  10828. public void get_sample2_order()
  10829. {
  10830. if (UrlPostParmsCheck("ctid"))
  10831. {
  10832. string ctid = GetPostString("ctid");
  10833. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10834. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  10835. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  10836. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  10837. double total = 0.0;
  10838. double order_price = 0.0;
  10839. if (dt_bu.Rows.Count > 0)
  10840. {
  10841. foreach (DataRow dr in dt_bu.Rows)
  10842. {
  10843. total += Convert.ToDouble(dr["payment"]);
  10844. }
  10845. }
  10846. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  10847. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  10848. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  10849. string tid = ctid.Replace("S_", "");
  10850. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  10851. double paymant = 0.0;
  10852. if (entity != null)
  10853. {
  10854. paymant = entity.payment;
  10855. }
  10856. string return_reason = "";
  10857. if (dt_after != null && dt_after.Rows.Count > 0)
  10858. {
  10859. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  10860. }
  10861. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  10862. }
  10863. }
  10864. public void get_erp_design_status()
  10865. {
  10866. string designName = GetPostString("designName");
  10867. DataStruct dStruct = GetPostStruct();
  10868. if (designName.Length > 0)
  10869. {
  10870. 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";
  10871. sql_user += " and Name like '%" + designName + "%'";
  10872. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  10873. List<string> ids_list = new List<string>();
  10874. if (user_table.Rows.Count > 0)
  10875. {
  10876. foreach (DataRow item in user_table.Rows)
  10877. {
  10878. ids_list.Add(item["id"].ToString());
  10879. string ids_s = item["TeamIds"].ToString();
  10880. if (ids_s.Length > 0)
  10881. {
  10882. ids_list.AddRange(ids_s.Split(','));
  10883. }
  10884. }
  10885. }
  10886. HashSet<string> set = new HashSet<string>(ids_list);
  10887. ids_list = set.ToList();
  10888. if (ids_list.Count > 0)
  10889. {
  10890. 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));
  10891. dStruct.MainWhere = sql;
  10892. DataTable dt = null;
  10893. dt = WebCache.GetData("view_ErpUser", dStruct);
  10894. writeGridDataTableJson(dStruct.TotalCount, dt);
  10895. }
  10896. }
  10897. }
  10898. public void change_erp_order_price()
  10899. {
  10900. string ctid = GetPostString("ctid");
  10901. double price = GetPostDouble("price");
  10902. if (ctid.Length > 0)
  10903. {
  10904. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10905. if (ceErpTradeCellExtend == null)
  10906. {
  10907. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10908. ceErpTradeCellExtend.ctid = ctid;
  10909. ceErpTradeCellExtend.payment_cyt = price;
  10910. ceErpTradeCellExtend.Create();
  10911. }
  10912. else
  10913. {
  10914. ceErpTradeCellExtend.payment_cyt = price;
  10915. ceErpTradeCellExtend.Update();
  10916. }
  10917. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  10918. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  10919. {
  10920. ceErpDataSendOrderInfo.isSync = false;
  10921. ceErpDataSendOrderInfo.Update();
  10922. }
  10923. if (ceErpDataSendOrderInfo == null)
  10924. {
  10925. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  10926. ceErpDataSendOrderInfo.isSync = false;
  10927. ceErpDataSendOrderInfo.ctid = ctid;
  10928. ceErpDataSendOrderInfo.Create();
  10929. }
  10930. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  10931. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  10932. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10933. if (dth != null && dth.Rows.Count > 0)
  10934. {
  10935. dataSendOrderBean dataSendOrderBean = null;
  10936. foreach (DataRow item in dth.Rows)
  10937. {
  10938. try
  10939. {
  10940. dataSendOrderBean = new dataSendOrderBean();
  10941. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  10942. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  10943. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  10944. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  10945. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  10946. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  10947. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  10948. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  10949. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  10950. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  10951. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  10952. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  10953. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  10954. if (result != null)
  10955. {
  10956. if ("0".Equals(result.errcode))
  10957. {
  10958. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  10959. }
  10960. else
  10961. {
  10962. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  10963. }
  10964. }
  10965. }
  10966. catch (Exception ex)
  10967. {
  10968. }
  10969. }
  10970. }
  10971. returnSuccessMsg("修改成功!");
  10972. return;
  10973. }
  10974. returnErrorMsg("找不到订单");
  10975. }
  10976. public void find_he_together()
  10977. {
  10978. string ctid = GetPostString("ctid");
  10979. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10980. List<string> list = new List<string>();
  10981. if (ceErpTradeCell != null)
  10982. {
  10983. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  10984. {
  10985. 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);
  10986. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10987. if (table != null && table.Rows.Count > 0)
  10988. {
  10989. foreach (TableRow row in table.Rows)
  10990. {
  10991. }
  10992. }
  10993. }
  10994. }
  10995. returnSuccess(JsonConvert.SerializeObject(new { list }));
  10996. }
  10997. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  10998. {
  10999. //chy----19
  11000. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11001. //GD-CYT-----64
  11002. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11003. //ZHX----3
  11004. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11005. //JK----97
  11006. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11007. //ZT----70
  11008. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11009. //LHCY-----98
  11010. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11011. //XD-----90
  11012. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11013. //CYCY-----14
  11014. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11015. };
  11016. //其他改名
  11017. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11018. {
  11019. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11020. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11021. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11022. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11023. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11024. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11025. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11026. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11027. };
  11028. //不统计
  11029. List<int> no_suppliers = new List<int>()
  11030. {
  11031. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11032. };
  11033. //配件单
  11034. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11035. {
  11036. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11037. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11038. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11039. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11040. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11041. {"旗杆",new List<string>(){ "班旗" } },
  11042. {"牙签",new List<string>(){ "不干胶" } }
  11043. };
  11044. public void get_place_order_data()
  11045. {
  11046. string date1 = GetPostString("date1");
  11047. string date2 = GetPostString("date2");
  11048. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11049. DateTime start = DateTime.Parse(starttime);
  11050. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11051. DateTime end = DateTime.Parse(endtime);
  11052. if (date1 != null && date1.Length > 0)
  11053. {
  11054. DateTime dateTime = DateTime.Parse(date1);
  11055. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11056. start = DateTime.Parse(starttime);
  11057. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11058. end = DateTime.Parse(endtime);
  11059. }
  11060. if (date2 != null && date2.Length > 0)
  11061. {
  11062. DateTime dateTime = DateTime.Parse(date2);
  11063. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11064. end = DateTime.Parse(endtime);
  11065. }
  11066. 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);
  11067. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11068. //不干胶-----1,卡片-----29
  11069. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11070. foreach (DataRow row in data.Rows)
  11071. {
  11072. int productId = Convert.ToInt32(row["ProductId"]);
  11073. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11074. if (no_suppliers.Contains(supplierId))
  11075. {
  11076. continue;
  11077. }
  11078. string seller_memo = row["seller_memo"].ToString();
  11079. bool ispj = false;//是否配件单
  11080. bool isfirst = true;//第一个配
  11081. maps.Keys.ForEach(key =>
  11082. {
  11083. //备注包含配件
  11084. if (seller_memo.Contains(key) && isfirst)
  11085. {
  11086. List<string> list = maps[key];
  11087. ispj = true;
  11088. isfirst = false;
  11089. for (int i = 0; i < list.Count; i++)
  11090. {
  11091. if (seller_memo.Contains(list[i]))
  11092. {
  11093. ispj = false;
  11094. break;
  11095. }
  11096. }
  11097. }
  11098. });
  11099. if (ispj)
  11100. {
  11101. continue;
  11102. }
  11103. seller_memo = seller_memo.Replace("UV", "uv");
  11104. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11105. //吊牌归到卡片
  11106. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11107. seller_memo = seller_memo.Replace("卡套", "卡片");
  11108. seller_memo = seller_memo.Replace("封套", "卡片");
  11109. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11110. seller_memo = seller_memo.Replace("腰封", "卡片");
  11111. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11112. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11113. seller_memo = seller_memo.Replace("横幅", "条幅");
  11114. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11115. string map_key = "";
  11116. string type = "";
  11117. if (supplierMap.ContainsKey(supplierId))
  11118. {
  11119. foreach (var kvp in supplierMap[supplierId])
  11120. {
  11121. if (seller_memo.Contains(kvp.Key))
  11122. {
  11123. map_key = kvp.Value;
  11124. type = kvp.Value;
  11125. break;
  11126. }
  11127. }
  11128. }
  11129. if (map_key == "")
  11130. {
  11131. type = "其他";
  11132. map_key = "其他";
  11133. }
  11134. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11135. {
  11136. map_key = suppliers[supplierId];
  11137. }
  11138. if (supplierId == 70)
  11139. {
  11140. supplierId = 70;
  11141. }
  11142. map_key += "_" + row["SupplierName"].ToString();
  11143. Dictionary<string, int> map = null;
  11144. if (other_map.ContainsKey(map_key))
  11145. {
  11146. other_map.TryGetValue(map_key, out map);
  11147. }
  11148. else
  11149. {
  11150. map = new Dictionary<string, int>();
  11151. map.Add("dayDev", 0);//当天出货
  11152. map.Add("dayTotal", 0);//下单总数
  11153. map.Add("payTotal", 0);//500以上
  11154. map.Add("today", 0);//当天出货数量
  11155. map.Add("unusua", 0);//异常数
  11156. other_map.Add(map_key, map);
  11157. other_map.TryGetValue(map_key, out map);
  11158. }
  11159. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11160. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11161. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11162. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11163. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11164. {
  11165. map["dayTotal"]++;
  11166. if (supplierId == 97)
  11167. {
  11168. supplierId = 97;
  11169. }
  11170. }
  11171. if (Convert.ToDecimal(row["payment"]) >= 500)
  11172. {
  11173. map["payTotal"]++;
  11174. }
  11175. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11176. {
  11177. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11178. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11179. {
  11180. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11181. {
  11182. map["today"]++;
  11183. }
  11184. }
  11185. else
  11186. {
  11187. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11188. {
  11189. map["today"]++;
  11190. }
  11191. else
  11192. {
  11193. if (supplierId == 119)
  11194. {
  11195. Debug.WriteLine(row["seller_memo"].ToString());
  11196. }
  11197. }
  11198. }
  11199. }
  11200. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11201. {
  11202. map["unusua"]++;
  11203. }
  11204. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11205. //GD-CYT-----64
  11206. DateTime two = palceTimeStart.AddHours(14);
  11207. DateTime three = palceTimeStart.AddHours(15);
  11208. DateTime four = palceTimeStart.AddHours(16);
  11209. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11210. {
  11211. //下午四点前 500-1000
  11212. string count = row["ProductCount"].ToString();
  11213. if (count != null && count.Length > 0)
  11214. {
  11215. int productCount = commonHelper.getPlaceProductCount(count);
  11216. if (productCount >= 500 && productCount <= 1000)
  11217. {
  11218. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11219. {
  11220. map["dayDev"]++;
  11221. }
  11222. }
  11223. }
  11224. }
  11225. //UV
  11226. else if ("uv".Equals(type))
  11227. {
  11228. //ZT----70
  11229. //ZHX----3
  11230. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11231. {
  11232. map["dayDev"]++;
  11233. }
  11234. //JK----97
  11235. //HZX----105
  11236. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11237. {
  11238. map["dayDev"]++;
  11239. if (supplierId == 97)
  11240. {
  11241. supplierId = 97;
  11242. }
  11243. }
  11244. }
  11245. //帆布---52|条幅---27
  11246. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11247. {
  11248. //LHCY-----98
  11249. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11250. {
  11251. map["dayDev"]++;
  11252. }
  11253. }
  11254. //条幅
  11255. else if ("条幅".Equals(type))
  11256. {
  11257. //XD-----90
  11258. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11259. {
  11260. map["dayDev"]++;
  11261. }
  11262. }
  11263. //桌布
  11264. else if ("桌布".Equals(type))
  11265. {
  11266. //XD-----90
  11267. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11268. {
  11269. map["dayDev"]++;
  11270. }
  11271. }
  11272. //DL---10
  11273. //AYTW---119
  11274. //FS-CYT-DY ----80
  11275. //JK----97
  11276. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11277. {
  11278. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11279. {
  11280. map["dayDev"]++;
  11281. }
  11282. }
  11283. }
  11284. DataTable dt = new DataTable();
  11285. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11286. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11287. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11288. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11289. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11290. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11291. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11292. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11293. other_map.Keys.ForEach(key =>
  11294. {
  11295. DataRow dr = dt.NewRow();
  11296. Dictionary<string, int> map = other_map[key];
  11297. string[] key_list = key.Split('_');
  11298. dr[0] = key_list[0];
  11299. dr[1] = key_list[1];
  11300. if (key_list.Length > 2)
  11301. {
  11302. dr[1] += "(" + key_list[2] + ")";
  11303. }
  11304. dr[2] = map["dayTotal"];
  11305. dr[3] = map["payTotal"];
  11306. dr[4] = map["today"];
  11307. dr[5] = map["unusua"];
  11308. dr[6] = map["dayDev"];
  11309. double rate = 0.00;
  11310. if (map["dayDev"] > 0)
  11311. {
  11312. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11313. }
  11314. dr[7] = rate.ToString();
  11315. dt.Rows.Add(dr);
  11316. });
  11317. DataView dv = new DataView(dt);
  11318. dv.Sort = "SupplierName";
  11319. //dv.Sort = "AllOrder desc";
  11320. DataTable dtNew = dv.ToTable();
  11321. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11322. }
  11323. public void check_order_desing_info()
  11324. {
  11325. string ctid = GetPostString("ctid");
  11326. if (!string.IsNullOrEmpty(ctid))
  11327. {
  11328. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11329. if (ceErpTradeCell != null)
  11330. {
  11331. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11332. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11333. return;
  11334. }
  11335. returnErrorMsg("找不到订单");
  11336. return;
  11337. }
  11338. returnErrorMsg("找不到订单");
  11339. }
  11340. public void get_timeout_detail()
  11341. {
  11342. string poscode = CurrentUser.UserPost.Post.Code;
  11343. DataStruct dStruct = GetPostStruct();
  11344. List<string> lw = new List<string>();
  11345. string id = GetPostString("id");
  11346. string pay_date1 = GetPostString("pay_date1");
  11347. string pay_date2 = GetPostString("pay_date2");
  11348. int type = GetPostInt("type");
  11349. if (type == 0)
  11350. {
  11351. if (pay_date1.Length > 0)
  11352. {
  11353. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11354. }
  11355. if (pay_date2.Length > 0)
  11356. {
  11357. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11358. }
  11359. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11360. }
  11361. if (type == 1)
  11362. {
  11363. if (pay_date1.Length > 0)
  11364. {
  11365. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11366. }
  11367. if (pay_date2.Length > 0)
  11368. {
  11369. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11370. }
  11371. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11372. }
  11373. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11374. DataTable dt = null;
  11375. dt = WebCache.GetData("view_orderlist", dStruct);
  11376. writeGridDataTableJson(dStruct.TotalCount, dt);
  11377. }
  11378. public void saveUrgentChargePrice()
  11379. {
  11380. string ctid = GetPostString("ctid");
  11381. if (!string.IsNullOrEmpty(ctid))
  11382. {
  11383. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11384. if (ceErpTradeCell != null)
  11385. {
  11386. double price = GetPostDouble("price");
  11387. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11388. if (ceErpTradeCellExtend == null)
  11389. {
  11390. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11391. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11392. }
  11393. ceErpTradeCellExtend.urgentCharge = price;
  11394. if (ceErpTradeCellExtend.ID > 0)
  11395. {
  11396. ceErpTradeCellExtend.Update();
  11397. }
  11398. else
  11399. {
  11400. ceErpTradeCellExtend.Save();
  11401. }
  11402. returnSuccessMsg("修改成功!");
  11403. return;
  11404. }
  11405. returnErrorMsg("找不到订单");
  11406. return;
  11407. }
  11408. returnErrorMsg("找不到订单");
  11409. }
  11410. public void finish_erp_order()
  11411. {
  11412. string ctid = GetPostString("ctid");
  11413. if (!string.IsNullOrEmpty(ctid))
  11414. {
  11415. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11416. {
  11417. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11418. if (ceErpTradeCell != null)
  11419. {
  11420. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11421. ceErpTradeCell.Update();
  11422. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11423. returnSuccessMsg("修改成功!");
  11424. return;
  11425. }
  11426. }
  11427. }
  11428. returnErrorMsg("找不到订单");
  11429. }
  11430. public void get_trade_order_list()
  11431. {
  11432. string tid = GetPostString("tid");
  11433. if (!string.IsNullOrEmpty(tid))
  11434. {
  11435. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11436. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11437. writeGridDataTableJson(data.Rows.Count, data);
  11438. return;
  11439. }
  11440. returnErrorMsg("找不到订单");
  11441. }
  11442. public void save_cell_spu()
  11443. {
  11444. string ctid = GetPostString("ctid");
  11445. string spu_id = GetPostString("spu_id");
  11446. if (!string.IsNullOrEmpty(ctid))
  11447. {
  11448. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11449. if (ceErpTradeCellExtend == null)
  11450. {
  11451. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11452. ceErpTradeCellExtend.ctid = ctid;
  11453. }
  11454. ceErpTradeCellExtend.spu_id = spu_id;
  11455. if (ceErpTradeCellExtend.ID == 0)
  11456. {
  11457. ceErpTradeCellExtend.Create();
  11458. }
  11459. else
  11460. {
  11461. ceErpTradeCellExtend.Update();
  11462. }
  11463. returnSuccessMsg("修改成功!");
  11464. return;
  11465. }
  11466. returnErrorMsg("找不到订单");
  11467. }
  11468. public void change_express_info()
  11469. {
  11470. string ctid = GetPostString("ctid");
  11471. string transNo = GetPostString("transNo");
  11472. string transCom = GetPostString("transCom");
  11473. if (!string.IsNullOrEmpty(ctid))
  11474. {
  11475. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11476. if (ceErpTradeCellExtend == null)
  11477. {
  11478. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11479. ceErpTradeCellExtend.ctid = ctid;
  11480. }
  11481. ceErpTradeCellExtend.modExpressNo = transNo;
  11482. ceErpTradeCellExtend.modExpressCom = transCom;
  11483. ceErpTradeCellExtend.readMod = 2;
  11484. if (ceErpTradeCellExtend.ID == 0)
  11485. {
  11486. ceErpTradeCellExtend.Create();
  11487. }
  11488. else
  11489. {
  11490. ceErpTradeCellExtend.Update();
  11491. }
  11492. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11493. returnSuccessMsg("修改成功!");
  11494. return;
  11495. }
  11496. returnErrorMsg("找不到订单");
  11497. }
  11498. public void get_change_express_list()
  11499. {
  11500. DataStruct dStruct = GetPostStruct();
  11501. List<string> lw = new List<string>();
  11502. int st = 2;
  11503. string tid = GetPostString("ctid");
  11504. if (tid.Length > 0)
  11505. {
  11506. string select_tid = getTidByCtid(tid);
  11507. lw.Add(string.Format("tid='{0}'", select_tid));
  11508. }
  11509. string shopname = GetPostString("shopname");
  11510. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11511. string buyernick = GetPostString("buyer_nick");
  11512. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11513. string sellermemo = GetPostString("seller_memo");
  11514. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11515. string supplier = GetPostString("supplier");
  11516. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11517. string customer = GetPostString("customer");
  11518. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11519. string design = GetPostString("design");
  11520. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11521. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11522. string poscode = CurrentUser.UserPost.Post.Code;
  11523. if (poscode != "SysAdmin")
  11524. {
  11525. string shopid = CurrentUser.User.pemShop;
  11526. lw.Add(string.Format("shopId in ({0})", shopid));
  11527. }
  11528. lw.Add("readMod = 2");
  11529. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11530. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11531. writeGridDataTableJson(dStruct.TotalCount, dt);
  11532. }
  11533. public void deal_express_complete()
  11534. {
  11535. string ctid = GetPostString("ctid");
  11536. if (!string.IsNullOrEmpty(ctid))
  11537. {
  11538. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11539. if (ceErpTradeCellExtend == null)
  11540. {
  11541. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11542. ceErpTradeCellExtend.ctid = ctid;
  11543. }
  11544. ceErpTradeCellExtend.readMod = 1;
  11545. if (ceErpTradeCellExtend.ID == 0)
  11546. {
  11547. ceErpTradeCellExtend.Create();
  11548. }
  11549. else
  11550. {
  11551. ceErpTradeCellExtend.Update();
  11552. }
  11553. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11554. returnSuccessMsg("修改成功!");
  11555. return;
  11556. }
  11557. returnErrorMsg("找不到订单");
  11558. }
  11559. public void aftersale_return_visit()
  11560. {
  11561. string ctid = GetPostString("ctid");
  11562. if (!string.IsNullOrEmpty(ctid))
  11563. {
  11564. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11565. if (ceErpTradeCellExtend == null)
  11566. {
  11567. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11568. ceErpTradeCellExtend.ctid = ctid;
  11569. }
  11570. ceErpTradeCellExtend.returnVisit = 1;
  11571. if (ceErpTradeCellExtend.ID == 0)
  11572. {
  11573. ceErpTradeCellExtend.Create();
  11574. }
  11575. else
  11576. {
  11577. ceErpTradeCellExtend.Update();
  11578. }
  11579. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11580. if (ceErpTradeAfterSaleExtend != null)
  11581. {
  11582. ceErpTradeAfterSaleExtend.TextResult = "";
  11583. ceErpTradeAfterSaleExtend.Update();
  11584. }
  11585. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11586. returnSuccessMsg("修改成功!");
  11587. return;
  11588. }
  11589. returnErrorMsg("找不到订单");
  11590. }
  11591. public void orderPlaceInfo()
  11592. {
  11593. string ctids = GetPostString("ctids");
  11594. string[] list = ctids.Split(',');
  11595. foreach (string ctid in list)
  11596. {
  11597. CeErpSukuraData.createInfo(ctid, 3);
  11598. }
  11599. StringBuilder sql = new StringBuilder();
  11600. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11601. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11602. designHelper.api_approveDesign(ctids); //approveDesign
  11603. returnSuccessMsg("");
  11604. }
  11605. public void get_issue_list()
  11606. {
  11607. DataStruct dStruct = GetPostStruct();
  11608. List<string> lw = new List<string>();
  11609. int st = 2;
  11610. string tid = GetPostString("ctid");
  11611. if (tid.Length > 0)
  11612. {
  11613. string select_tid = getTidByCtid(tid);
  11614. lw.Add(string.Format("tid='{0}'", select_tid));
  11615. }
  11616. string shopname = GetPostString("shopname");
  11617. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11618. string buyernick = GetPostString("buyer_nick");
  11619. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11620. string sellermemo = GetPostString("seller_memo");
  11621. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11622. string supplier = GetPostString("supplier");
  11623. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11624. string customer = GetPostString("customer");
  11625. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11626. string design = GetPostString("design");
  11627. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11628. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11629. string poscode = CurrentUser.UserPost.Post.Code;
  11630. if (poscode != "SysAdmin")
  11631. {
  11632. string shopid = CurrentUser.User.pemShop;
  11633. lw.Add(string.Format("shopId in ({0})", shopid));
  11634. }
  11635. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode))
  11636. {
  11637. lw.Add("IssueState = 1");
  11638. }
  11639. lw.Add("IssueState > 0");
  11640. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11641. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11642. writeGridDataTableJson(dStruct.TotalCount, dt);
  11643. }
  11644. public void saveIssueContent()
  11645. {
  11646. string ctid = GetPostString("ctid");
  11647. if (!string.IsNullOrEmpty(ctid))
  11648. {
  11649. string content = GetPostString("content");
  11650. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11651. if (ceErpTradeAfterSaleExtend == null)
  11652. {
  11653. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11654. ceErpTradeAfterSaleExtend.tid = ctid;
  11655. }
  11656. ceErpTradeAfterSaleExtend.IssueContent = content;
  11657. ceErpTradeAfterSaleExtend.IssueState = 1;
  11658. if (ceErpTradeAfterSaleExtend.ID > 0)
  11659. {
  11660. ceErpTradeAfterSaleExtend.Update();
  11661. }
  11662. else
  11663. {
  11664. ceErpTradeAfterSaleExtend.Create();
  11665. }
  11666. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11667. returnSuccessMsg("添加成功!");
  11668. return;
  11669. }
  11670. returnErrorMsg("找不到订单");
  11671. }
  11672. public void dealIssueContent()
  11673. {
  11674. string ctid = GetPostString("ctid");
  11675. if (!string.IsNullOrEmpty(ctid))
  11676. {
  11677. string content = GetPostString("content");
  11678. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11679. if (ceErpTradeAfterSaleExtend != null)
  11680. {
  11681. ceErpTradeAfterSaleExtend.IssueState = 2;
  11682. ceErpTradeAfterSaleExtend.Update();
  11683. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11684. returnSuccessMsg("修改完成!");
  11685. return;
  11686. }
  11687. }
  11688. returnErrorMsg("找不到订单");
  11689. }
  11690. public void set_tid_attachments()
  11691. {
  11692. string tid = GetPostString("tid");
  11693. string atta = GetPostString("atta");
  11694. if (!string.IsNullOrEmpty(tid))
  11695. {
  11696. if (string.IsNullOrEmpty(atta))
  11697. {
  11698. returnErrorMsg("文件地址为空");
  11699. return;
  11700. }
  11701. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11702. if (ceErpTradeCell != null)
  11703. {
  11704. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11705. if (ceErpTrade == null)
  11706. {
  11707. returnErrorMsg("找不到订单");
  11708. return;
  11709. }
  11710. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11711. bool isSend = false;
  11712. if (dt != null && dt.Rows.Count > 0)
  11713. {
  11714. foreach (DataRow row in dt.Rows)
  11715. {
  11716. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11717. {
  11718. isSend = true;
  11719. }
  11720. }
  11721. if (isSend)
  11722. {
  11723. returnErrorMsg("已发货无法修改");
  11724. return;
  11725. }
  11726. ceErpTrade.Attachments = atta;
  11727. ceErpTrade.Update();
  11728. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址", 6);
  11729. returnSuccessMsg("上传成功!");
  11730. return;
  11731. }
  11732. }
  11733. }
  11734. returnErrorMsg("找不到订单");
  11735. }
  11736. public void get_tid_attachments()
  11737. {
  11738. string tid = GetPostString("tid");
  11739. if (!string.IsNullOrEmpty(tid))
  11740. {
  11741. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11742. if (ceErpTradeCell != null)
  11743. {
  11744. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11745. if (ceErpTrade == null)
  11746. {
  11747. returnErrorMsg("找不到订单");
  11748. return;
  11749. }
  11750. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  11751. return;
  11752. }
  11753. }
  11754. returnErrorMsg("找不到订单");
  11755. }
  11756. public void check_erp_sameorders()
  11757. {
  11758. if (UrlPostParmsCheck("ctid"))
  11759. {
  11760. string eid = GetPostString("ctid");
  11761. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11762. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11763. if (entity != null && ceErpTrade != null)
  11764. {
  11765. if (entity.OrderState > 6)
  11766. {
  11767. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11768. return;
  11769. }
  11770. StringBuilder sql = new StringBuilder();
  11771. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo from view_ErpTradeCell where SupplierId={0} and orderstate=6", entity.SupplierId);
  11772. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  11773. {
  11774. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  11775. }
  11776. else
  11777. {
  11778. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  11779. }
  11780. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11781. List<string> ids = new List<string>();
  11782. if (dt != null && dt.Rows.Count > 1)
  11783. {
  11784. bool needhe = true;
  11785. foreach (DataRow dr in dt.Rows)
  11786. {
  11787. ids.Add("'" + dr["ctid"] + "'");
  11788. /* //备注有合包
  11789. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  11790. {
  11791. needhe = true;
  11792. }
  11793. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  11794. {
  11795. needhe = true;
  11796. }
  11797. //顺丰快递
  11798. if (Convert.ToInt32(dr["IsSF"]) > 0)
  11799. {
  11800. needhe = true;
  11801. }*/
  11802. }
  11803. if (!needhe)
  11804. {
  11805. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11806. return;
  11807. }
  11808. sql = new StringBuilder();
  11809. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  11810. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  11811. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  11812. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11813. foreach (DataRow dr in dt.Rows)
  11814. {
  11815. dr["dstate"] = 0;
  11816. dr["dnumber"] = 0;
  11817. foreach (DataRow row in dt1.Rows)
  11818. {
  11819. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  11820. {
  11821. dr["dstate"] = 2;
  11822. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  11823. }
  11824. }
  11825. if (eid.Equals(dr["ctid"].ToString()))
  11826. {
  11827. dr["dstate"] = 1;
  11828. }
  11829. }
  11830. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  11831. return;
  11832. }
  11833. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11834. return;
  11835. }
  11836. returnErrorMsg("未找到订单");
  11837. return;
  11838. }
  11839. returnErrorMsg("缺少必要的参数");
  11840. }
  11841. public void get_mark_number()
  11842. {
  11843. string eid = GetPostString("ctid");
  11844. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11845. if (entity != null)
  11846. {
  11847. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11848. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  11849. int current = 1;
  11850. if (ceErpDeliverMark == null)
  11851. {
  11852. StringBuilder sql = new StringBuilder();
  11853. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo from view_ErpTradeCell where SupplierId={0} and orderstate=6", entity.SupplierId);
  11854. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  11855. {
  11856. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  11857. }
  11858. else
  11859. {
  11860. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  11861. }
  11862. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11863. List<string> ids = new List<string>();
  11864. if (dt != null && dt.Rows.Count > 1)
  11865. {
  11866. foreach (DataRow dr in dt.Rows)
  11867. {
  11868. ids.Add("'" + dr["ctid"] + "'");
  11869. }
  11870. //查询已有的编号
  11871. sql = new StringBuilder();
  11872. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  11873. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11874. if (dt1 == null || dt1.Rows.Count == 0)
  11875. {
  11876. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  11877. List<int> list_number = new List<int>();
  11878. foreach (DataRow row in numbers.Rows)
  11879. {
  11880. list_number.Add(Convert.ToInt32(row["markNumber"]));
  11881. }
  11882. //查询空余编号
  11883. for (int i = 0; i < list_number.Count + 2; i++)
  11884. {
  11885. if (!list_number.Contains(current))
  11886. {
  11887. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  11888. //防止查询过程中有新数据生成
  11889. if (ceErpDeliverMark1 == null)
  11890. {
  11891. break;
  11892. }
  11893. }
  11894. current++;
  11895. }
  11896. }
  11897. else
  11898. {
  11899. foreach (DataRow row in dt1.Rows)
  11900. {
  11901. current = Convert.ToInt32(row["markNumber"]);
  11902. }
  11903. }
  11904. ceErpDeliverMark = new CeErpDeliverMark();
  11905. ceErpDeliverMark.ctid = eid;
  11906. ceErpDeliverMark.createtime = DateTime.Now;
  11907. if (ceErpTrade != null)
  11908. {
  11909. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  11910. }
  11911. ceErpDeliverMark.markNumber = current;
  11912. ceErpDeliverMark.Create();
  11913. }
  11914. }
  11915. else
  11916. {
  11917. current = ceErpDeliverMark.markNumber;
  11918. }
  11919. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  11920. return;
  11921. }
  11922. }
  11923. }
  11924. }